Skip to content

Commit

Permalink
Port to GtkApplication framework.
Browse files Browse the repository at this point in the history
    This includes the *.desktop file rename and corrections.

    Closes #115

    MAP added 8/24/2019: Resolve small conflict introduced by PR #124
  • Loading branch information
postiffm committed Aug 29, 2019
1 parent 72a06c2 commit 93cfd6d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion desktop/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
applicationdir = $(datadir)/applications

application_DATA = bibledit-desktop.desktop
application_DATA = org.bibleditdesktop.desktop

EXTRA_DIST = *
CLEANFILES = *~
Expand Down
File renamed without changes.
55 changes: 43 additions & 12 deletions src/bibledit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ VCS *vcs;
Concordance *concordance;
ReferenceBibles *refbibles;
CrossReferences *crossrefs;
static MainWindow *mainwindow;

// Forward declarations
static void startup_callback (GtkApplication *app, gpointer data);
static void shutdown_callback (GtkApplication *app, gpointer data);
static void activate_callback (GtkApplication *app, gpointer data);

int main(int argc, char *argv[])
{
Expand All @@ -89,18 +95,36 @@ int main(int argc, char *argv[])
// The type system is now initialised automatically.
// g_type_init();
// Initialize GTK
gtk_init(&argc, &argv);
// gtk_init is called internally by GtkApplication
// gtk_init(&argc, &argv);

GtkApplication *app;
app = gtk_application_new ("org.bibleditdesktop",
G_APPLICATION_HANDLES_COMMAND_LINE);
g_signal_connect (app, "activate", G_CALLBACK (activate_callback), NULL);
g_signal_connect (app, "startup", G_CALLBACK (startup_callback), argv);
g_signal_connect (app, "shutdown", G_CALLBACK (shutdown_callback), NULL);

options = new Options(argc, argv);

g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
delete Directories; // must be last because other objects rely on it
return 0;
}

static void startup_callback (GtkApplication *app, gpointer data)
{
char **argv = (char**) data;

// Create a new directories 'factory' and initialize it with argv[0]
Directories = new directories(argv[0]);

// Check whether it is fine to start the program.
// If not, quit the program normally. Must come
// after the Directories object is initialized.
if (!check_bibledit_startup_okay(argc, argv)) {
return 0;
if (!check_bibledit_startup_okay ()) {
exit (0);
}

#ifdef WIN32
Expand Down Expand Up @@ -147,7 +171,7 @@ int main(int argc, char *argv[])
dup2(stdout_copy, 1);
dup2(stderr_copy, 2);
perror("bibledit.cpp:main:dup(1) call failed");
return 1;
exit (1);
}
}

Expand Down Expand Up @@ -230,17 +254,20 @@ int main(int argc, char *argv[])
&error);
if (error) {
gw_error("Error loading the GTK stylesheet file: bibledit-desktop.css");
return 1;
exit (1);
}
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
GTK_STYLE_PROVIDER (css_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gw_message("Loaded the GTK stylesheet");

// Start the gui.
MainWindow *mainwindow = new MainWindow(accelerator_group, settings, urltransport, vcs);
gw_message("Finished initialization...running gtk_main");
gtk_main();
mainwindow = new MainWindow (accelerator_group, settings, urltransport, vcs);
gw_message("Finished initialization...");
}

static void shutdown_callback (GtkApplication *app, gpointer data)
{
delete mainwindow;

// Remove lockfile
Expand All @@ -267,12 +294,16 @@ int main(int argc, char *argv[])
delete versifications;
delete booklocalizations;
delete settings;
delete Directories; // must be last, because above rely on it
if (concordance) { delete concordance; }
if (refbibles) { delete refbibles; }

// Quit.
return 0;
}

static void activate_callback (GtkApplication *app, gpointer data)
{
GtkWindow *window;

window = gtk_application_get_active_window (app);
gtk_window_present (window);
}


Expand Down
6 changes: 4 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ navigation(0), httpd(0)

// GUI build.

window_main = gtk_window_new(GTK_WINDOW_TOPLEVEL);
window_main = gtk_application_window_new (
GTK_APPLICATION (g_application_get_default ()));

// Size and position of window and screen layout.
ScreenLayoutDimensions * dimensions = new ScreenLayoutDimensions (window_main);
Expand Down Expand Up @@ -6221,7 +6222,8 @@ void MainWindow::initiate_shutdown()
shutting_down = true;

// Shut down after a delay.
g_timeout_add(10, GSourceFunc(gtk_main_quit), NULL);
g_timeout_add (10, GSourceFunc (g_application_quit),
g_application_get_default ());
}


Expand Down
2 changes: 1 addition & 1 deletion src/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
int global_debug_level;
int debug_msg_no;

bool check_bibledit_startup_okay (int argc, char *argv[])
bool check_bibledit_startup_okay ()
// Returns true if it is okay to start bibledit.
{
// Do not run as root (does not apply to Windows).
Expand Down
2 changes: 1 addition & 1 deletion src/startup.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#include <glib.h>
#include <gtk/gtk.h>

bool check_bibledit_startup_okay (int argc, char *argv[]);
bool check_bibledit_startup_okay ();

#endif

0 comments on commit 93cfd6d

Please sign in to comment.