[balsa/application-notification] Use GApplication features



commit a958f09bb75751151b8124ec19ff5835b40cf746
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Jun 20 17:30:51 2018 -0400

    Use GApplication features
    
            * src/main.c (balsa_startup_cb), (balsa_shutdown_cb),
            (balsa_activate_cb), (balsa_command_line_cb), (main): Use all the
            GApplication signals, instead of doing it all in the
            command-line handler.

 ChangeLog  |  7 ++++++
 src/main.c | 82 ++++++++++++++++++++++++++++++++------------------------------
 2 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f82b6907c..71060930a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-06-20  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       * src/main.c (balsa_startup_cb), (balsa_shutdown_cb),
+       (balsa_activate_cb), (balsa_command_line_cb), (main): Use all the
+       GApplication signals, instead of doing it all in the
+       command-line handler.
+
 2018-06-15  Peter Bloomfield  <pbloomfield bellsouth net>
 
        * src/mailbox-conf.c: Build with gpgme desabled.
diff --git a/src/main.c b/src/main.c
index 7e682997c..cf23fef09 100644
--- a/src/main.c
+++ b/src/main.c
@@ -55,10 +55,6 @@
 #include "libbalsa-gpgme-cb.h"
 #endif
 
-static void config_init(gboolean check_only);
-static void mailboxes_init(gboolean check_only);
-static void balsa_cleanup(void);
-
 /* We need separate variable for storing command line requests to check the
    mail because such selection cannot be stored in balsa_app and later
    saved to the configuration file.
@@ -469,10 +465,10 @@ balsa_check_open_compose_window(void)
 }
 
 /* -------------------------- main --------------------------------- */
-static int
-real_main(int argc, char *argv[])
+static void
+balsa_startup_cb(GApplication *application,
+           gpointer      user_data)
 {
-    GtkWidget *window;
     gchar *default_icon;
 
 #ifdef ENABLE_NLS
@@ -516,23 +512,12 @@ real_main(int argc, char *argv[])
         g_free(default_icon);
     }
 
-    signal( SIGPIPE, SIG_IGN );
-
-    window = balsa_window_new();
-    balsa_app.main_window = BALSA_WINDOW(window);
-    g_object_add_weak_pointer(G_OBJECT(window),
-                             (gpointer) &balsa_app.main_window);
-
-    /* load mailboxes */
-    config_load_sections();
-    mailboxes_init(cmd_get_stats);
-
     if (cmd_get_stats) {
         long unread, unsent;
         balsa_get_stats(&unread, &unsent);
         printf("Unread: %ld Unsent: %ld\n", unread, unsent);
         g_application_quit(G_APPLICATION(balsa_app.application));
-        return 0;
+        return;
     }
 
 #ifdef HAVE_GPGME
@@ -542,6 +527,30 @@ real_main(int argc, char *argv[])
         libbalsa_gpgme_check_crypto_engine(GPGME_PROTOCOL_CMS);
 #endif /* HAVE_GPGME */
 
+    accel_map_load();
+}
+
+static void
+balsa_shutdown_cb(void)
+{
+    balsa_app_destroy();
+
+    libbalsa_conf_drop_all();
+    accel_map_save();
+    libbalsa_imap_server_close_all_connections();
+}
+
+static void
+balsa_activate_cb(GApplication *application,
+            gpointer      user_data)
+{
+    GtkWidget *window;
+
+    window = balsa_window_new(GTK_APPLICATION(application));
+    balsa_app.main_window = BALSA_WINDOW(window);
+    g_object_add_weak_pointer(G_OBJECT(window),
+                             (gpointer) &balsa_app.main_window);
+
     balsa_check_open_compose_window();
 
     g_idle_add((GSourceFunc) scan_mailboxes_idle_cb, NULL);
@@ -562,22 +571,9 @@ real_main(int argc, char *argv[])
         g_idle_add((GSourceFunc) balsa_main_check_new_messages,
                    balsa_app.main_window);
 
-    accel_map_load();
-    gtk_main();
-
-    balsa_cleanup();
-    accel_map_save();
-
-    libbalsa_imap_server_close_all_connections();
-    return 0;
-}
-
-static void
-balsa_cleanup(void)
-{
-    balsa_app_destroy();
-
-    libbalsa_conf_drop_all();
+    /* load mailboxes */
+    config_load_sections();
+    mailboxes_init(cmd_get_stats);
 }
 
 /*
@@ -720,7 +716,7 @@ handle_remote(int argc, char **argv,
 }
 
 static int
-command_line_cb(GApplication            * application,
+balsa_command_line_cb(GApplication            * application,
                 GApplicationCommandLine * command_line,
                 gpointer                  user_data)
 {
@@ -743,8 +739,7 @@ command_line_cb(GApplication            * application,
              * handle the command line. */
             handle_remote(argc, argv, command_line);
         } else {
-            /* This is the primary instance; start up as usual. */
-            status = real_main(argc, argv);
+            g_application_activate(application);
         }
     } else if (status == 2) /* handled a "help" or "version" request */
         status = 0;
@@ -764,10 +759,17 @@ main(int argc, char **argv)
     balsa_app.application = application =
         gtk_application_new("org.desktop.Balsa",
                             G_APPLICATION_HANDLES_COMMAND_LINE);
-    g_signal_connect(application, "command-line",
-                     G_CALLBACK(command_line_cb), NULL);
     g_object_set(application, "register-session", TRUE, NULL);
 
+    g_signal_connect(application, "command-line",
+                     G_CALLBACK(balsa_command_line_cb), NULL);
+    g_signal_connect(application, "startup",
+                     G_CALLBACK(balsa_startup_cb), NULL);
+    g_signal_connect(application, "activate",
+                     G_CALLBACK(balsa_activate_cb), NULL);
+    g_signal_connect(application, "shutdown",
+                     G_CALLBACK(balsa_shutdown_cb), NULL);
+
     status = g_application_run(G_APPLICATION(application), argc, argv);
 
     g_object_unref(application);


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