[gnome-session] shell: deduplicate shell signal logic



commit afa21fb4f0749c62dc625d1f709984234e220d89
Author: Ray Strode <rstrode redhat com>
Date:   Thu Mar 3 10:00:51 2016 -0500

    shell: deduplicate shell signal logic
    
    Anytime the shell sends us a signal about the end session dialog
    we need to do the same things:
    
    1) stop listening for new inhibitor updates
    2) stop any queued operations for redisplaying the inhibitor dialog
    3) emit the signal to on the gsm-shell object so other parts of the
    code can listen for.
    
    We currently have a separate signal handler for every signal, and
    they all do they same thing.  Well, they're supposed to anyway, some
    bits are erroneously missing from some of the handlers.
    
    This commit consolidates all the code, so we don't have it reimplemently
    badly in several places.

 gnome-session/gsm-manager.c |   66 ------------------------------
 gnome-session/gsm-shell.c   |   94 ++++++++++++------------------------------
 2 files changed, 27 insertions(+), 133 deletions(-)
---
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index 6e18f31..4b05e25 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -329,27 +329,6 @@ debug_clients (GsmManager *manager)
 }
 
 static gboolean
-_debug_inhibitor (const char    *id,
-                  GsmInhibitor  *inhibitor,
-                  GsmManager    *manager)
-{
-        g_debug ("GsmManager: Inhibitor app:%s client:%s bus-name:%s reason:%s",
-                 gsm_inhibitor_peek_app_id (inhibitor),
-                 gsm_inhibitor_peek_client_id (inhibitor),
-                 gsm_inhibitor_peek_bus_name (inhibitor),
-                 gsm_inhibitor_peek_reason (inhibitor));
-        return FALSE;
-}
-
-static void
-debug_inhibitors (GsmManager *manager)
-{
-        gsm_store_foreach (manager->priv->inhibitors,
-                           (GsmStoreFunc)_debug_inhibitor,
-                           manager);
-}
-
-static gboolean
 _find_by_cookie (const char   *id,
                  GsmInhibitor *inhibitor,
                  guint        *cookie_ap)
@@ -3075,51 +3054,6 @@ on_session_connection_closed (GDBusConnection *connection,
 }
 
 static gboolean
-inhibitor_has_bus_name (gpointer          key,
-                        GsmInhibitor     *inhibitor,
-                        RemoveClientData *data)
-{
-        gboolean    matches;
-        const char *bus_name_b;
-
-        bus_name_b = gsm_inhibitor_peek_bus_name (inhibitor);
-
-        matches = FALSE;
-        if (! IS_STRING_EMPTY (data->service_name) && ! IS_STRING_EMPTY (bus_name_b)) {
-                matches = (strcmp (data->service_name, bus_name_b) == 0);
-                if (matches) {
-                        g_debug ("GsmManager: removing inhibitor from %s for reason '%s' on connection %s",
-                                 gsm_inhibitor_peek_app_id (inhibitor),
-                                 gsm_inhibitor_peek_reason (inhibitor),
-                                 gsm_inhibitor_peek_bus_name (inhibitor));
-                }
-        }
-
-        return matches;
-}
-
-static void
-remove_inhibitors_for_connection (GsmManager *manager,
-                                  const char *service_name)
-{
-        RemoveClientData data;
-        guint count;
-
-        data.service_name = service_name;
-        data.manager = manager;
-
-        debug_inhibitors (manager);
-
-        count = gsm_store_foreach_remove (manager->priv->inhibitors,
-                                          (GsmStoreFunc)inhibitor_has_bus_name,
-                                          &data);
-        if (count > 0 &&
-            manager->priv->phase == GSM_MANAGER_PHASE_QUERY_END_SESSION) {
-                end_session_or_show_shell_dialog (manager);
-        }
-}
-
-static gboolean
 register_manager (GsmManager *manager)
 {
         GDBusConnection *connection;
diff --git a/gnome-session/gsm-shell.c b/gnome-session/gsm-shell.c
index 854ad30..ca2e291 100644
--- a/gnome-session/gsm-shell.c
+++ b/gnome-session/gsm-shell.c
@@ -328,23 +328,36 @@ on_open_finished (GObject *source,
 }
 
 static void
-on_end_session_dialog_closed (GsmShell *shell)
+on_end_session_dialog_dbus_signal (GDBusProxy *proxy,
+                                   gchar      *sender_name,
+                                   gchar      *signal_name,
+                                   GVariant   *parameters,
+                                   GsmShell   *shell)
 {
-        if (shell->priv->update_idle_id != 0) {
-                g_source_remove (shell->priv->update_idle_id);
-                shell->priv->update_idle_id = 0;
+        struct {
+                const char *name;
+                int         index;
+        } signal_map[] = {
+                { "Closed", END_SESSION_DIALOG_CLOSED },
+                { "Canceled", END_SESSION_DIALOG_CANCELED },
+                { "ConfirmedLogout", END_SESSION_DIALOG_CONFIRMED_LOGOUT },
+                { "ConfirmedReboot", END_SESSION_DIALOG_CONFIRMED_REBOOT },
+                { "ConfirmedShutdown", END_SESSION_DIALOG_CONFIRMED_SHUTDOWN },
+                { NULL, -1 }
+        };
+        int signal_index = -1;
+        int i;
+
+        for (i = 0; signal_map[i].name != NULL; i++) {
+                if (g_strcmp0 (signal_map[i].name, signal_name) == 0) {
+                        signal_index = signal_map[i].index;
+                        break;
+                }
         }
 
-        g_signal_handlers_disconnect_by_func (shell->priv->inhibitors,
-                                              G_CALLBACK (queue_end_session_dialog_update),
-                                              shell);
-
-        g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CLOSED], 0);
-}
+        if (signal_index == -1)
+                return;
 
-static void
-on_end_session_dialog_canceled (GsmShell *shell)
-{
         if (shell->priv->update_idle_id != 0) {
                 g_source_remove (shell->priv->update_idle_id);
                 shell->priv->update_idle_id = 0;
@@ -354,60 +367,7 @@ on_end_session_dialog_canceled (GsmShell *shell)
                                               G_CALLBACK (queue_end_session_dialog_update),
                                               shell);
 
-        g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CANCELED], 0);
-}
-
-static void
-on_end_session_dialog_confirmed_logout (GsmShell *shell)
-{
-        if (shell->priv->update_idle_id != 0) {
-                g_source_remove (shell->priv->update_idle_id);
-                shell->priv->update_idle_id = 0;
-        }
-
-        g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CONFIRMED_LOGOUT], 0);
-}
-
-static void
-on_end_session_dialog_confirmed_shutdown (GsmShell *shell)
-{
-        if (shell->priv->update_idle_id != 0) {
-                g_source_remove (shell->priv->update_idle_id);
-                shell->priv->update_idle_id = 0;
-        }
-
-        g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CONFIRMED_SHUTDOWN], 0);
-}
-
-static void
-on_end_session_dialog_confirmed_reboot (GsmShell   *shell)
-{
-        if (shell->priv->update_idle_id != 0) {
-                g_source_remove (shell->priv->update_idle_id);
-                shell->priv->update_idle_id = 0;
-        }
-
-        g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CONFIRMED_REBOOT], 0);
-}
-
-static void
-on_end_session_dialog_dbus_signal (GDBusProxy *proxy,
-                                   gchar      *sender_name,
-                                   gchar      *signal_name,
-                                   GVariant   *parameters,
-                                   GsmShell   *shell)
-{
-        if (g_strcmp0 (signal_name, "Closed") == 0) {
-                on_end_session_dialog_closed (shell);
-        } else if (g_strcmp0 (signal_name, "Canceled") == 0) {
-                on_end_session_dialog_canceled (shell);
-        } else if (g_strcmp0 (signal_name ,"ConfirmedLogout") == 0) {
-                on_end_session_dialog_confirmed_logout (shell);
-        } else if (g_strcmp0 (signal_name ,"ConfirmedReboot") == 0) {
-                on_end_session_dialog_confirmed_reboot (shell);
-        } else if (g_strcmp0 (signal_name ,"ConfirmedShutdown") == 0) {
-                on_end_session_dialog_confirmed_shutdown (shell);
-        }
+        g_signal_emit (G_OBJECT (shell), signals[signal_index], 0);
 }
 
 static void


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