[gnome-session/wip/cleanups: 9/15] Hook the separate end session dialog up



commit 8528f138ba6021744a9a9aab361ae345f3bd98c0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 11 23:39:12 2012 -0500

    Hook the separate end session dialog up
    
    We remove all the fallback dialog code paths from gsm-manager,
    and make gsm-shell fall back to the standalone end session dialog
    if it can't get a shell proxy.

 gnome-session/gsm-manager.c |  333 +-----------------------------------------
 gnome-session/gsm-shell.c   |   24 +++-
 2 files changed, 26 insertions(+), 331 deletions(-)
---
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index 8f2afe8..5d2b10c 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -59,7 +59,6 @@
 #include "gsm-logout-dialog.h"
 #include "gsm-fail-whale-dialog.h"
 #include "gsm-icon-names.h"
-#include "gsm-inhibit-dialog.h"
 #include "gsm-system.h"
 #include "gsm-session-save.h"
 #include "gsm-shell-extensions.h"
@@ -139,8 +138,6 @@ struct GsmManagerPrivate
         /* This is the action that will be done just before we exit */
         GsmManagerLogoutType    logout_type;
 
-        GtkWidget              *inhibit_dialog;
-
         /* List of clients which were disconnected due to disabled condition
          * and shouldn't be automatically restarted */
         GSList                 *condition_clients;
@@ -1050,13 +1047,6 @@ cancel_end_session (GsmManager *manager)
         /* switch back to running phase */
         g_debug ("GsmManager: Cancelling the end of session");
 
-        /* remove the dialog before we remove the inhibitors, else the dialog
-         * will activate itself automatically when the last inhibitor will be
-         * removed */
-        if (manager->priv->inhibit_dialog)
-                gtk_widget_destroy (GTK_WIDGET (manager->priv->inhibit_dialog));
-        manager->priv->inhibit_dialog = NULL;
-
         /* clear all JIT inhibitors */
         gsm_store_foreach_remove (manager->priv->inhibitors,
                                   (GsmStoreFunc)inhibitor_is_jit,
@@ -1163,127 +1153,6 @@ manager_attempt_suspend (GsmManager *manager)
 }
 
 static void
-do_inhibit_dialog_action (GdkDisplay *display,
-                          GsmManager *manager,
-                          int         action)
-{
-        switch (action) {
-        case GSM_LOGOUT_ACTION_SWITCH_USER:
-                manager_switch_user (display, manager);
-                break;
-        case GSM_LOGOUT_ACTION_HIBERNATE:
-                manager_attempt_hibernate (manager);
-                break;
-        case GSM_LOGOUT_ACTION_SLEEP:
-                manager_attempt_suspend (manager);
-                break;
-        case GSM_LOGOUT_ACTION_SHUTDOWN:
-        case GSM_LOGOUT_ACTION_REBOOT:
-        case GSM_LOGOUT_ACTION_LOGOUT:
-                manager->priv->logout_mode = GSM_MANAGER_LOGOUT_MODE_FORCE;
-                end_phase (manager);
-                break;
-        default:
-                g_assert_not_reached ();
-                break;
-        }
-}
-
-static void
-inhibit_dialog_response (GsmInhibitDialog *dialog,
-                         guint             response_id,
-                         GsmManager       *manager)
-{
-        GdkDisplay *display;
-        int action;
-
-        g_debug ("GsmManager: Inhibit dialog response: %d", response_id);
-
-        display = gtk_widget_get_display (GTK_WIDGET (dialog));
-
-        /* must destroy dialog before cancelling since we'll
-           remove JIT inhibitors and we don't want to trigger
-           action. */
-        g_object_get (dialog, "action", &action, NULL);
-        gtk_widget_destroy (GTK_WIDGET (dialog));
-        manager->priv->inhibit_dialog = NULL;
-
-        /* In case of dialog cancel, switch user, hibernate and
-         * suspend, we just perform the respective action and return,
-         * without shutting down the session. */
-        switch (response_id) {
-        case GTK_RESPONSE_CANCEL:
-        case GTK_RESPONSE_NONE:
-        case GTK_RESPONSE_DELETE_EVENT:
-                if (action == GSM_LOGOUT_ACTION_LOGOUT
-                    || action == GSM_LOGOUT_ACTION_SHUTDOWN
-                    || action == GSM_LOGOUT_ACTION_REBOOT) {
-                        cancel_end_session (manager);
-                }
-                break;
-        case GTK_RESPONSE_ACCEPT:
-                g_debug ("GsmManager: doing action %d", action);
-                do_inhibit_dialog_action (display, manager, action);
-                break;
-        default:
-                g_assert_not_reached ();
-                break;
-        }
-}
-
-static void
-end_session_or_show_fallback_dialog (GsmManager *manager)
-{
-        GsmLogoutAction action;
-
-        if (! gsm_manager_is_logout_inhibited (manager)) {
-                end_phase (manager);
-                return;
-        }
-
-        if (manager->priv->inhibit_dialog != NULL) {
-                g_debug ("GsmManager: inhibit dialog already up");
-                gtk_window_present (GTK_WINDOW (manager->priv->inhibit_dialog));
-                return;
-        }
-
-        switch (manager->priv->logout_type) {
-        case GSM_MANAGER_LOGOUT_LOGOUT:
-                action = GSM_LOGOUT_ACTION_LOGOUT;
-                break;
-        case GSM_MANAGER_LOGOUT_REBOOT:
-        case GSM_MANAGER_LOGOUT_REBOOT_INTERACT:
-        case GSM_MANAGER_LOGOUT_REBOOT_GDM:
-                action = GSM_LOGOUT_ACTION_REBOOT;
-                break;
-        case GSM_MANAGER_LOGOUT_SHUTDOWN:
-        case GSM_MANAGER_LOGOUT_SHUTDOWN_INTERACT:
-        case GSM_MANAGER_LOGOUT_SHUTDOWN_GDM:
-                action = GSM_LOGOUT_ACTION_SHUTDOWN;
-                break;
-        default:
-                g_warning ("Unexpected logout type %d when creating inhibit dialog",
-                           manager->priv->logout_type);
-                action = GSM_LOGOUT_ACTION_LOGOUT;
-                break;
-        }
-
-        /* Note: GSM_LOGOUT_ACTION_SHUTDOWN and GSM_LOGOUT_ACTION_REBOOT are
-         * actually handled the same way as GSM_LOGOUT_ACTION_LOGOUT in the
-         * inhibit dialog; the action, if the button is clicked, will be to
-         * simply go to the next phase. */
-        manager->priv->inhibit_dialog = gsm_inhibit_dialog_new (manager->priv->inhibitors,
-                                                                manager->priv->clients,
-                                                                action);
-
-        g_signal_connect (manager->priv->inhibit_dialog,
-                          "response",
-                          G_CALLBACK (inhibit_dialog_response),
-                          manager);
-        gtk_widget_show (manager->priv->inhibit_dialog);
-}
-
-static void
 end_session_or_show_shell_dialog (GsmManager *manager)
 {
         gboolean logout_prompt;
@@ -1358,7 +1227,7 @@ show_fallback_dialog (const char *title,
         gtk_window_set_icon_name (GTK_WINDOW (dialog), GSM_ICON_COMPUTER_FAIL);
 
         image = gtk_image_new_from_icon_name (GSM_ICON_COMPUTER_FAIL,
-                                              gsm_util_get_computer_fail_icon_size ());
+                                              4); //gsm_util_get_computer_fail_icon_size ());
         gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
 
         if (description) {
@@ -1420,12 +1289,7 @@ query_end_session_complete (GsmManager *manager)
                 manager->priv->query_timeout_id = 0;
         }
 
-        if (gsm_shell_is_running (manager->priv->shell)) {
-                end_session_or_show_shell_dialog (manager);
-        } else {
-                end_session_or_show_fallback_dialog (manager);
-        }
-
+        end_session_or_show_shell_dialog (manager);
 }
 
 static guint32
@@ -2943,21 +2807,7 @@ request_suspend (GsmManager *manager)
                 return;
         }
 
-        if (manager->priv->inhibit_dialog != NULL) {
-                g_debug ("GsmManager: inhibit dialog already up");
-                gtk_window_present (GTK_WINDOW (manager->priv->inhibit_dialog));
-                return;
-        }
-
-        manager->priv->inhibit_dialog = gsm_inhibit_dialog_new (manager->priv->inhibitors,
-                                                                manager->priv->clients,
-                                                                GSM_LOGOUT_ACTION_SLEEP);
-
-        g_signal_connect (manager->priv->inhibit_dialog,
-                          "response",
-                          G_CALLBACK (inhibit_dialog_response),
-                          manager);
-        gtk_widget_show (manager->priv->inhibit_dialog);
+        /* FIXME inhibit suspend dialog ? */
 }
 
 static void
@@ -2971,21 +2821,7 @@ request_hibernate (GsmManager *manager)
                 return;
         }
 
-        if (manager->priv->inhibit_dialog != NULL) {
-                g_debug ("GsmManager: inhibit dialog already up");
-                gtk_window_present (GTK_WINDOW (manager->priv->inhibit_dialog));
-                return;
-        }
-
-        manager->priv->inhibit_dialog = gsm_inhibit_dialog_new (manager->priv->inhibitors,
-                                                                manager->priv->clients,
-                                                                GSM_LOGOUT_ACTION_HIBERNATE);
-
-        g_signal_connect (manager->priv->inhibit_dialog,
-                          "response",
-                          G_CALLBACK (inhibit_dialog_response),
-                          manager);
-        gtk_widget_show (manager->priv->inhibit_dialog);
+        /* FIXME inhibit suspend dialog ? */
 }
 
 
@@ -3019,127 +2855,9 @@ request_switch_user (GdkDisplay *display,
                 return;
         }
 
-        if (manager->priv->inhibit_dialog != NULL) {
-                g_debug ("GsmManager: inhibit dialog already up");
-                gtk_window_present (GTK_WINDOW (manager->priv->inhibit_dialog));
-                return;
-        }
-
-        manager->priv->inhibit_dialog = gsm_inhibit_dialog_new (manager->priv->inhibitors,
-                                                                manager->priv->clients,
-                                                                GSM_LOGOUT_ACTION_SWITCH_USER);
-
-        g_signal_connect (manager->priv->inhibit_dialog,
-                          "response",
-                          G_CALLBACK (inhibit_dialog_response),
-                          manager);
-        gtk_widget_show (manager->priv->inhibit_dialog);
+        /* FIXME: inhibit switch-user dialog ? */
 }
 
-static void
-logout_dialog_response (GsmLogoutDialog *logout_dialog,
-                        guint            response_id,
-                        GsmManager      *manager)
-{
-        GdkDisplay *display;
-
-        /* We should only be here if mode has already have been set from
-         * show_fallback_shutdown/logout_dialog
-         */
-        g_assert (manager->priv->logout_mode == GSM_MANAGER_LOGOUT_MODE_NORMAL);
-
-        g_debug ("GsmManager: Logout dialog response: %d", response_id);
-
-        display = gtk_widget_get_display (GTK_WIDGET (logout_dialog));
-
-        gtk_widget_destroy (GTK_WIDGET (logout_dialog));
-
-        /* In case of dialog cancel, switch user, hibernate and
-         * suspend, we just perform the respective action and return,
-         * without shutting down the session. */
-        switch (response_id) {
-        case GTK_RESPONSE_CANCEL:
-        case GTK_RESPONSE_NONE:
-        case GTK_RESPONSE_DELETE_EVENT:
-                break;
-        case GSM_LOGOUT_RESPONSE_SWITCH_USER:
-                request_switch_user (display, manager);
-                break;
-        case GSM_LOGOUT_RESPONSE_HIBERNATE:
-                request_hibernate (manager);
-                break;
-        case GSM_LOGOUT_RESPONSE_SLEEP:
-                request_suspend (manager);
-                break;
-        case GSM_LOGOUT_RESPONSE_SHUTDOWN:
-                request_shutdown (manager);
-                break;
-        case GSM_LOGOUT_RESPONSE_REBOOT:
-                request_reboot (manager);
-                break;
-        case GSM_LOGOUT_RESPONSE_LOGOUT:
-                /* We've already gotten confirmation from the user so
-                 * initiate the logout in NO_CONFIRMATION mode.
-                 *
-                 * (it shouldn't matter whether we use NO_CONFIRMATION or stay
-                 * with NORMAL, unless the shell happens to start after the
-                 * user confirmed)
-                 */
-                request_logout (manager, GSM_MANAGER_LOGOUT_MODE_NO_CONFIRMATION);
-                break;
-        default:
-                g_assert_not_reached ();
-                break;
-        }
-}
-
-static void
-show_fallback_shutdown_dialog (GsmManager *manager,
-                               gboolean    is_reboot)
-{
-        GtkWidget *dialog;
-
-        if (manager->priv->phase >= GSM_MANAGER_PHASE_QUERY_END_SESSION) {
-                /* Already shutting down, nothing more to do */
-                return;
-        }
-
-        manager->priv->logout_mode = GSM_MANAGER_LOGOUT_MODE_NORMAL;
-
-        dialog = gsm_get_shutdown_dialog (gdk_screen_get_default (),
-                                          gtk_get_current_event_time (),
-                                          is_reboot ?
-                                          GSM_DIALOG_LOGOUT_TYPE_REBOOT :
-                                          GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN);
-
-        g_signal_connect (dialog,
-                          "response",
-                          G_CALLBACK (logout_dialog_response),
-                          manager);
-        gtk_widget_show (dialog);
-}
-
-static void
-show_fallback_logout_dialog (GsmManager *manager)
-{
-        GtkWidget *dialog;
-
-        if (manager->priv->phase >= GSM_MANAGER_PHASE_QUERY_END_SESSION) {
-                /* Already shutting down, nothing more to do */
-                return;
-        }
-
-        manager->priv->logout_mode = GSM_MANAGER_LOGOUT_MODE_NORMAL;
-
-        dialog = gsm_get_logout_dialog (gdk_screen_get_default (),
-                                        gtk_get_current_event_time ());
-
-        g_signal_connect (dialog,
-                          "response",
-                          G_CALLBACK (logout_dialog_response),
-                          manager);
-        gtk_widget_show (dialog);
-}
 
 static void
 disconnect_shell_dialog_signals (GsmManager *manager)
@@ -3271,9 +2989,6 @@ static void
 show_shell_end_session_dialog (GsmManager                   *manager,
                                GsmShellEndSessionDialogType  type)
 {
-        if (!gsm_shell_is_running (manager->priv->shell))
-                return;
-
         gsm_shell_open_end_session_dialog (manager->priv->shell,
                                            type,
                                            manager->priv->inhibitors);
@@ -3284,30 +2999,12 @@ static void
 user_logout (GsmManager           *manager,
              GsmManagerLogoutMode  mode)
 {
-        gboolean logout_prompt;
-        gboolean shell_running;
-
         if (manager->priv->phase >= GSM_MANAGER_PHASE_QUERY_END_SESSION) {
                 /* Already shutting down, nothing more to do */
                 return;
         }
 
-        shell_running = gsm_shell_is_running (manager->priv->shell);
-        logout_prompt = g_settings_get_boolean (manager->priv->settings,
-                                                KEY_LOGOUT_PROMPT);
-
-        /* If the shell isn't running, and this isn't a non-interative logout request,
-         * and the user has their settings configured to show a confirmation dialog for
-         * logout, then go ahead and show the fallback confirmation dialog now.
-         *
-         * If the shell is running, then the confirmation dialog and inhibitor dialog are
-         * combined, so we'll show it at a later stage in the logout process.
-         */
-        if (!shell_running && mode == GSM_MANAGER_LOGOUT_MODE_NORMAL && logout_prompt) {
-                show_fallback_logout_dialog (manager);
-        } else {
-                request_logout (manager, mode);
-        }
+        request_logout (manager, mode);
 }
 
 /*
@@ -3344,8 +3041,6 @@ gboolean
 gsm_manager_shutdown (GsmManager *manager,
                       GError    **error)
 {
-        gboolean shell_running;
-
         g_debug ("GsmManager: Shutdown called");
 
         g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);
@@ -3366,12 +3061,7 @@ gsm_manager_shutdown (GsmManager *manager,
                 return FALSE;
         }
 
-        shell_running = gsm_shell_is_running (manager->priv->shell);
-
-        if (!shell_running)
-                show_fallback_shutdown_dialog (manager, FALSE);
-        else
-                request_shutdown (manager);
+        request_shutdown (manager);
 
         return TRUE;
 }
@@ -3380,8 +3070,6 @@ gboolean
 gsm_manager_reboot (GsmManager  *manager,
                     GError     **error)
 {
-        gboolean shell_running;
-
         g_debug ("GsmManager: Reboot called");
 
         g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);
@@ -3402,12 +3090,7 @@ gsm_manager_reboot (GsmManager  *manager,
                 return FALSE;
         }
 
-        shell_running = gsm_shell_is_running (manager->priv->shell);
-
-        if (!shell_running)
-                show_fallback_shutdown_dialog (manager, TRUE);
-        else
-                request_reboot (manager);
+        request_reboot (manager);
 
         return TRUE;
 }
diff --git a/gnome-session/gsm-shell.c b/gnome-session/gsm-shell.c
index 87ff10b..00125d5 100644
--- a/gnome-session/gsm-shell.c
+++ b/gnome-session/gsm-shell.c
@@ -38,6 +38,8 @@
 #define SHELL_PATH      "/org/gnome/Shell"
 #define SHELL_INTERFACE "org.gnome.Shell"
 
+#define END_SESSION_DIALOG_NAME "org.gnome.SessionManager.EndSessionDialog"
+
 #define SHELL_END_SESSION_DIALOG_PATH      "/org/gnome/SessionManager/EndSessionDialog"
 #define SHELL_END_SESSION_DIALOG_INTERFACE "org.gnome.SessionManager.EndSessionDialog"
 
@@ -574,13 +576,17 @@ gsm_shell_open_end_session_dialog (GsmShell *shell,
         DBusGProxyCall  *call;
         GPtrArray *inhibitor_array;
         GError *error;
+        gboolean have_shell;
 
         error = NULL;
         if (!gsm_shell_ensure_connection (shell, &error)) {
                 g_warning ("Could not connect to the shell: %s",
                            error->message);
                 g_error_free (error);
-                return FALSE;
+                have_shell = FALSE;
+        }
+        else {
+                have_shell = TRUE;
         }
 
         if (shell->priv->end_session_open_call != NULL) {
@@ -593,11 +599,17 @@ gsm_shell_open_end_session_dialog (GsmShell *shell,
         if (shell->priv->end_session_dialog_proxy == NULL) {
                 DBusGProxy *proxy;
 
-                proxy = dbus_g_proxy_new_for_name (shell->priv->bus_connection,
-                                                   SHELL_NAME,
-                                                   SHELL_END_SESSION_DIALOG_PATH,
-                                                   SHELL_END_SESSION_DIALOG_INTERFACE);
-
+                if (have_shell) {
+                        proxy = dbus_g_proxy_new_for_name (shell->priv->bus_connection,
+                                                           SHELL_NAME,
+                                                           SHELL_END_SESSION_DIALOG_PATH,
+                                                           SHELL_END_SESSION_DIALOG_INTERFACE);
+                } else {
+                        proxy = dbus_g_proxy_new_for_name (shell->priv->bus_connection,
+                                                           END_SESSION_DIALOG_NAME,
+                                                           SHELL_END_SESSION_DIALOG_PATH,
+                                                           SHELL_END_SESSION_DIALOG_INTERFACE);
+                }
                 g_assert (proxy != NULL);
 
                 shell->priv->end_session_dialog_proxy = proxy;



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