[buoh/application] Port to GApplication



commit b1980b1857cc3eb412c9b8c73a31cd7bf9825e05
Author: Jan Tojnar <jtojnar gmail com>
Date:   Fri Sep 14 15:40:38 2018 +0200

    Port to GApplication
    
    https://wiki.gnome.org/Initiatives/GnomeGoals/PortToGtkApplication

 src/buoh-window.c |  5 +++--
 src/buoh.c        | 11 ++++++++++-
 src/main.c        | 11 +++--------
 3 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/src/buoh-window.c b/src/buoh-window.c
index 20fc6c5..993e584 100644
--- a/src/buoh-window.c
+++ b/src/buoh-window.c
@@ -229,7 +229,7 @@ static const GtkToggleActionEntry menu_toggle_entries[] = {
           G_CALLBACK (buoh_window_cmd_view_zoom_fit_width) }
 };
 
-G_DEFINE_TYPE (BuohWindow, buoh_window, GTK_TYPE_WINDOW)
+G_DEFINE_TYPE (BuohWindow, buoh_window, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
 buoh_window_init (BuohWindow *buoh_window)
@@ -452,12 +452,13 @@ buoh_window_finalize (GObject *object)
 }
 
 GtkWidget *
-buoh_window_new (void)
+buoh_window_new (Buoh *application)
 {
         GtkWidget *buoh_window;
 
         buoh_window = GTK_WIDGET (g_object_new (BUOH_TYPE_WINDOW,
                                                 "type", GTK_WINDOW_TOPLEVEL,
+                                                "application", application,
                                                 "default-width", 600,
                                                 "default-height", 300,
                                                 NULL));
diff --git a/src/buoh.c b/src/buoh.c
index 6586027..db0d70a 100644
--- a/src/buoh.c
+++ b/src/buoh.c
@@ -469,7 +469,7 @@ buoh_create_main_window (Buoh *buoh)
         if (buoh->priv->window) {
                 gtk_window_present (GTK_WINDOW (buoh->priv->window));
         } else {
-                buoh->priv->window = BUOH_WINDOW (buoh_window_new ());
+                buoh->priv->window = BUOH_WINDOW (buoh_window_new (buoh));
         }
 }
 
@@ -488,3 +488,12 @@ buoh_get_datadir (Buoh *buoh)
 
         return buoh->priv->datadir;
 }
+
+static void
+activate (GtkApplication* app,
+          gpointer        user_data)
+{
+        GtkWidget *window;
+
+        window = buoh_create_main_window (buoh);
+}
diff --git a/src/main.c b/src/main.c
index 3658f35..e46718c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,22 +32,17 @@
 gint
 main (gint argc, gchar **argv)
 {
-        Buoh *buoh;
+        g_autoptr (Buoh) buoh;
 
         /* Initialize the i18n stuff */
         bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
         textdomain (GETTEXT_PACKAGE);
 
-        gtk_init (&argc, &argv);
-
         g_set_application_name (_("Buoh"));
-        gtk_window_set_default_icon_name ("buoh");
 
         buoh = buoh_new ();
-        buoh_create_main_window (buoh);
-
-        gtk_main ();
+        g_application_set_default (G_APPLICATION (buoh));
 
-        return 0;
+        return g_application_run (G_APPLICATION (buoh), argc, argv);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]