[evolution/gnome-3-8] EShellBackend: Rework shutdown delay.



commit 87a77c8e61892d048b3b49a9a6a1741a4b92df54
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Apr 18 15:43:56 2013 -0400

    EShellBackend: Rework shutdown delay.
    
    Use g_signal_connect_data() to automatically release the EActivity when
    the signal handler is disconnected, and keep the handler ID internally.
    
    This is cleaner than using g_signal_handlers_disconnect_by_func().
    
    (cherry picked from commit 7a2673a359ed80ba3f3bcd569de108432da18e11)

 shell/e-shell-backend.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/shell/e-shell-backend.c b/shell/e-shell-backend.c
index f4aed9b..31e3809 100644
--- a/shell/e-shell-backend.c
+++ b/shell/e-shell-backend.c
@@ -60,6 +60,9 @@ struct _EShellBackendPrivate {
        gchar *data_dir;
        gchar *prefer_new_item;
 
+       /* This is set to delay shutdown. */
+       gulong notify_busy_handler_id;
+
        guint started   : 1;
 };
 
@@ -96,14 +99,13 @@ shell_backend_notify_busy_cb (EShellBackend *shell_backend,
                               GParamSpec *pspec,
                               EActivity *activity)
 {
-       /* Unreferencing the EActivity allows the shell to
-        * proceed with shutdown. */
        if (!e_shell_backend_is_busy (shell_backend)) {
-               g_signal_handlers_disconnect_by_func (
+               /* Disconnecting this signal handler will unreference the
+                * EActivity and allow the shell to proceed with shutdown. */
+               g_signal_handler_disconnect (
                        shell_backend,
-                       shell_backend_notify_busy_cb,
-                       activity);
-               g_object_unref (activity);
+                       shell_backend->priv->notify_busy_handler_id);
+               shell_backend->priv->notify_busy_handler_id = 0;
        }
 }
 
@@ -112,13 +114,18 @@ shell_backend_prepare_for_quit_cb (EShell *shell,
                                    EActivity *activity,
                                    EShellBackend *shell_backend)
 {
-       /* Referencing the EActivity delays shutdown; the
-        * reference count acts like a counting semaphore. */
-       if (e_shell_backend_is_busy (shell_backend))
-               g_signal_connect (
+       if (e_shell_backend_is_busy (shell_backend)) {
+               gulong handler_id;
+
+               /* Referencing the EActivity delays shutdown; the
+                * reference count acts like a counting semaphore. */
+               handler_id = g_signal_connect_data (
                        shell_backend, "notify::busy",
                        G_CALLBACK (shell_backend_notify_busy_cb),
-                       g_object_ref (activity));
+                       g_object_ref (activity),
+                       (GClosureNotify) g_object_unref, 0);
+               shell_backend->priv->notify_busy_handler_id = handler_id;
+       }
 }
 
 static GObject *
@@ -212,6 +219,12 @@ shell_backend_dispose (GObject *object)
                priv->prefer_new_item = NULL;
        }
 
+       if (priv->notify_busy_handler_id > 0) {
+               g_signal_handler_disconnect (
+                       object, priv->notify_busy_handler_id);
+               priv->notify_busy_handler_id = 0;
+       }
+
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_shell_backend_parent_class)->dispose (object);
 }


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