[glib] GApplication: add g_application_quit()



commit ed519758997ca0fa40575722816be3121f106357
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Feb 20 21:41:35 2012 +0100

    GApplication: add g_application_quit()
    
    A long requested feature; this quits the application immediately,
    ignoring the hold count.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670485

 docs/reference/gio/gio-sections.txt |    1 +
 gio/gapplication.c                  |   29 +++++++++++++++++++++++++++++
 gio/gapplication.h                  |    2 ++
 gio/gio.symbols                     |    1 +
 4 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index c9ed66b..b72b37d 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -2897,6 +2897,7 @@ g_application_register
 <SUBSECTION>
 g_application_hold
 g_application_release
+g_application_quit
 <SUBSECTION>
 g_application_activate
 g_application_open
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 380634d..fe01d2a 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -211,6 +211,7 @@ struct _GApplicationPrivate
   guint              is_remote : 1;
   guint              did_startup : 1;
   guint              did_shutdown : 1;
+  guint              must_quit_now : 1;
 
   GRemoteActionGroup *remote_actions;
   GApplicationImpl   *impl;
@@ -1425,6 +1426,7 @@ g_application_run (GApplication  *application,
 
   g_return_val_if_fail (G_IS_APPLICATION (application), 1);
   g_return_val_if_fail (argc == 0 || argv != NULL, 1);
+  g_return_val_if_fail (!application->priv->must_quit_now, 1);
 
   arguments = g_new (gchar *, argc + 1);
   for (i = 0; i < argc; i++)
@@ -1488,6 +1490,9 @@ g_application_run (GApplication  *application,
 
   while (application->priv->use_count || application->priv->inactivity_timeout_id)
     {
+      if (application->priv->must_quit_now)
+        break;
+
       g_main_context_iteration (NULL, TRUE);
       status = 0;
     }
@@ -1694,5 +1699,29 @@ g_application_set_default (GApplication *application)
   default_app = application;
 }
 
+/**
+ * g_application_quit:
+ * @application: a #GApplication
+ *
+ * Immediately quits the application.
+ *
+ * Upon return to the mainloop, g_application_run() will return,
+ * calling only the 'shutdown' function before doing so.
+ *
+ * The hold count is ignored.
+ *
+ * The result of calling g_application_run() again after it returns is
+ * unspecified.
+ *
+ * Since: 2.32
+ **/
+void
+g_application_quit (GApplication *application)
+{
+  g_return_if_fail (G_IS_APPLICATION (application));
+
+  application->priv->must_quit_now = TRUE;
+}
+
 /* Epilogue {{{1 */
 /* vim:set foldmethod=marker: */
diff --git a/gio/gapplication.h b/gio/gapplication.h
index 20f90af..c6c63a5 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -138,6 +138,8 @@ int                     g_application_run                               (GApplic
                                                                          int                       argc,
                                                                          char                    **argv);
 
+void                    g_application_quit                              (GApplication             *application);
+
 GApplication *          g_application_get_default                       (void);
 void                    g_application_set_default                       (GApplication             *application);
 
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 9b609c1..23938fe 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -31,6 +31,7 @@ g_application_set_application_id
 g_application_set_default
 g_application_set_flags
 g_application_set_inactivity_timeout
+g_application_quit
 g_application_command_line_get_arguments
 g_application_command_line_get_cwd
 g_application_command_line_get_environ



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