[buoh/cleanups: 2/2] BuohApplication: port to GtkApplication



commit 9da450b8934f136443d29ed32f7f7525c0c707fb
Author: Jan Tojnar <jtojnar gmail com>
Date:   Tue Jan 22 07:19:43 2019 +0100

    BuohApplication: port to GtkApplication

 src/buoh-application.c | 39 +++++++++++++++++++--------------------
 src/buoh-application.h |  6 ++----
 src/buoh-window.c      |  4 ----
 src/main.c             | 22 +++++++---------------
 4 files changed, 28 insertions(+), 43 deletions(-)
---
diff --git a/src/buoh-application.c b/src/buoh-application.c
index 4db5a43..813c7ea 100644
--- a/src/buoh-application.c
+++ b/src/buoh-application.c
@@ -42,11 +42,10 @@
 #include "buoh-comic-manager-date.h"
 
 struct _BuohApplication {
-        GObject       parent;
+        GtkApplication parent;
 
-        BuohWindow   *window;
-        GtkTreeModel *comic_list;
-        gchar        *datadir;
+        GtkTreeModel  *comic_list;
+        gchar         *datadir;
 };
 
 static void          buoh_application_init                   (BuohApplication         *buoh);
@@ -61,7 +60,7 @@ static void          buoh_application_save_comic_list        (GtkTreeModel
                                                               gpointer                 gdata);
 static void          buoh_application_create_user_dir        (BuohApplication         *buoh);
 
-G_DEFINE_TYPE (BuohApplication, buoh_application, G_TYPE_OBJECT)
+G_DEFINE_TYPE (BuohApplication, buoh_application, GTK_TYPE_APPLICATION)
 
 void
 buoh_debug (const gchar *format, ...)
@@ -399,8 +398,11 @@ static void
 buoh_application_class_init (BuohApplicationClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
+        GApplicationClass *app_class = G_APPLICATION_CLASS (klass);
 
         object_class->finalize = buoh_application_finalize;
+
+        app_class->activate = buoh_application_activate;
 }
 
 static void
@@ -432,7 +434,9 @@ buoh_application_get_instance (void)
         static BuohApplication *buoh = NULL;
 
         if (!buoh) {
-                buoh = g_object_new (BUOH_TYPE_APPLICATION, NULL);
+                buoh = g_object_new (BUOH_TYPE_APPLICATION,
+                                     "application-id", "org.gnome.buoh",
+                                     NULL);
         }
 
         return buoh;
@@ -445,26 +449,21 @@ buoh_application_new (void)
 }
 
 void
-buoh_application_exit (BuohApplication *buoh)
+buoh_application_activate (GApplication *buoh)
 {
         g_return_if_fail (BUOH_IS_APPLICATION (buoh));
 
-        g_object_unref (buoh);
-
-        gtk_main_quit ();
-
-        buoh_debug ("buoh exit");
-}
+        GList *list;
+        GtkWidget *window;
 
-void
-buoh_application_create_main_window (BuohApplication *buoh)
-{
-        g_return_if_fail (BUOH_IS_APPLICATION (buoh));
+        list = gtk_application_get_windows (GTK_APPLICATION (buoh));
 
-        if (buoh->window) {
-                gtk_window_present (GTK_WINDOW (buoh->window));
+        if (list) {
+                gtk_window_present (GTK_WINDOW (list->data));
         } else {
-                buoh->window = BUOH_WINDOW (buoh_window_new ());
+                window = buoh_window_new ();
+                gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (buoh));
+                gtk_widget_show (window);
         }
 }
 
diff --git a/src/buoh-application.h b/src/buoh-application.h
index b39c0ab..e4eff99 100644
--- a/src/buoh-application.h
+++ b/src/buoh-application.h
@@ -34,14 +34,12 @@ enum {
 };
 
 #define BUOH_TYPE_APPLICATION                  (buoh_application_get_type())
-G_DECLARE_FINAL_TYPE (BuohApplication, buoh_application, BUOH, APPLICATION, GObject)
+G_DECLARE_FINAL_TYPE (BuohApplication, buoh_application, BUOH, APPLICATION, GtkApplication)
 
 BuohApplication *buoh_application_get_instance       (void);
 BuohApplication *buoh_application_new                (void);
 
-void             buoh_application_exit               (BuohApplication *buoh);
-
-void             buoh_application_create_main_window (BuohApplication *buoh);
+void             buoh_application_activate           (GApplication    *buoh);
 GtkTreeModel    *buoh_application_get_comics_model   (BuohApplication *buoh);
 const gchar     *buoh_application_get_datadir        (BuohApplication *buoh);
 
diff --git a/src/buoh-window.c b/src/buoh-window.c
index ec0a5a1..03bad92 100644
--- a/src/buoh-window.c
+++ b/src/buoh-window.c
@@ -391,8 +391,6 @@ buoh_window_init (BuohWindow *buoh_window)
         buoh_window_update_zoom_mode (buoh_window);
 
         gtk_widget_grab_focus (GTK_WIDGET (buoh_window->view));
-
-        gtk_widget_show (GTK_WIDGET (buoh_window));
 }
 
 static void
@@ -429,8 +427,6 @@ buoh_window_finalize (GObject *object)
         if (G_OBJECT_CLASS (buoh_window_parent_class)->finalize) {
                 (* G_OBJECT_CLASS (buoh_window_parent_class)->finalize) (object);
         }
-
-        buoh_application_exit (buoh_application_get_instance ());
 }
 
 GtkWidget *
diff --git a/src/main.c b/src/main.c
index 7d1033e..c39e8b3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,25 +29,17 @@
 
 #include "buoh-application.h"
 
-gint
-main (gint argc, gchar **argv)
+int
+main (int argc, char *argv[])
 {
         BuohApplication *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");
+        gint status;
 
         buoh = buoh_application_new ();
-        buoh_application_create_main_window (buoh);
 
-        gtk_main ();
+        status = g_application_run (G_APPLICATION (buoh), argc, argv);
+
+        g_object_unref (buoh);
 
-        return 0;
+        return status;
 }


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