[gdm] Simplify the handling of dialog state



commit 0bcbd48cfcc58b9472b1d10315b80e1fe0675990
Author: William Jon McCann <jmccann redhat com>
Date:   Tue Jun 22 19:00:21 2010 -0400

    Simplify the handling of dialog state
    
    Should fix https://bugzilla.gnome.org/show_bug.cgi?id=622431
    
    Cherry picked from 7e0720dfc8504c81015baf0b27c9c93ce9f0a702

 gui/simple-greeter/gdm-greeter-login-window.c |  130 ++++++++++++-------------
 1 files changed, 61 insertions(+), 69 deletions(-)
---
diff --git a/gui/simple-greeter/gdm-greeter-login-window.c b/gui/simple-greeter/gdm-greeter-login-window.c
index 6390fa9..7f96396 100644
--- a/gui/simple-greeter/gdm-greeter-login-window.c
+++ b/gui/simple-greeter/gdm-greeter-login-window.c
@@ -88,8 +88,9 @@
 
 enum {
         MODE_UNDEFINED = 0,
+        MODE_TIMED_LOGIN,
         MODE_SELECTION,
-        MODE_AUTHENTICATION
+        MODE_AUTHENTICATION,
 };
 
 enum {
@@ -113,10 +114,11 @@ struct GdmGreeterLoginWindowPrivate
         gboolean         banner_message_enabled;
         guint            gconf_cnxn;
 
+        guint            last_mode;
         guint            dialog_mode;
 
         gboolean         user_list_disabled;
-        gboolean         show_cancel_button;
+        guint            num_queries;
 
         gboolean         timed_login_already_enabled;
         gboolean         timed_login_enabled;
@@ -438,21 +440,42 @@ user_chooser_has_no_user (GdmGreeterLoginWindow *login_window)
 }
 
 static void
-adjust_other_login_visibility (GdmGreeterLoginWindow *login_window)
+maybe_show_cancel_button (GdmGreeterLoginWindow *login_window)
 {
-        if (! login_window->priv->user_chooser_loaded) {
-                return;
-        }
+        gboolean show;
 
-        if (login_window->priv->dialog_mode != MODE_SELECTION) {
-                return;
-        }
+        show = FALSE;
 
-        if (gdm_chooser_widget_get_number_of_items (GDM_CHOOSER_WIDGET (login_window->priv->user_chooser)) == 0) {
-                set_log_in_button_mode (login_window, LOGIN_BUTTON_ANSWER_QUERY);
-        } else {
-                set_log_in_button_mode (login_window, LOGIN_BUTTON_HIDDEN);
+        /* only show the cancel button if there is something to go
+           back to */
+
+        switch (login_window->priv->dialog_mode) {
+        case MODE_SELECTION:
+                /* should never have anything to return to from here */
+                show = FALSE;
+                break;
+        case MODE_TIMED_LOGIN:
+                /* should always have something to return to from here */
+                show = TRUE;
+                break;
+        case MODE_AUTHENTICATION:
+                if (login_window->priv->num_queries > 1) {
+                        /* if we are inside a pam conversation past
+                           the first step */
+                        show = TRUE;
+                } else {
+                        if (login_window->priv->user_list_disabled || user_chooser_has_no_user (login_window)) {
+                                show = FALSE;
+                        } else {
+                                show = TRUE;
+                        }
+                }
+                break;
+        default:
+                g_assert_not_reached ();
         }
+
+        show_widget (login_window, "cancel-button", show);
 }
 
 static void
@@ -468,48 +491,29 @@ switch_mode (GdmGreeterLoginWindow *login_window,
         /* we want to run this even if we're supposed to
            be in the mode already so that we reset everything
            to a known state */
-        login_window->priv->dialog_mode = number;
+        if (login_window->priv->dialog_mode != number) {
+                login_window->priv->last_mode = login_window->priv->dialog_mode;
+                login_window->priv->dialog_mode = number;
+        }
 
         default_name = NULL;
 
         switch (number) {
         case MODE_SELECTION:
                 set_log_in_button_mode (login_window, LOGIN_BUTTON_HIDDEN);
-
-                show_widget (login_window, "cancel-button", FALSE);
-
-                show_widget (login_window, "auth-input-box", FALSE);
-
-                /*
-                 * Although the cancel button is not shown in the selection
-                 * dialog, the show_cancel_button flag manages when the
-                 * cancel button is shown on subsequent PAM queries.  Set the
-                 * flag to true initially since the button should appear on
-                 * the first query, since the button takes the user back to
-                 * selection mode.
-                 */
-                login_window->priv->show_cancel_button = TRUE;
+                break;
+        case MODE_TIMED_LOGIN:
+                set_log_in_button_mode (login_window, LOGIN_BUTTON_TIMED_LOGIN);
                 break;
         case MODE_AUTHENTICATION:
-                default_name = "log-in-button";
+                set_log_in_button_mode (login_window, LOGIN_BUTTON_ANSWER_QUERY);
                 break;
         default:
                 g_assert_not_reached ();
         }
 
-        box = GTK_WIDGET (gtk_builder_get_object (login_window->priv->builder,
-                          "buttonbox"));
-        gtk_button_box_set_layout (GTK_BUTTON_BOX (box),
-                                   (number == MODE_SELECTION) ?
-                                    GTK_BUTTONBOX_SPREAD :
-                                    GTK_BUTTONBOX_END );
-
-        if (default_name != NULL) {
-                GtkWidget *widget;
-
-                widget = GTK_WIDGET (gtk_builder_get_object (login_window->priv->builder, default_name));
-                gtk_widget_grab_default (widget);
-        }
+        show_widget (login_window, "auth-input-box", FALSE);
+        maybe_show_cancel_button (login_window);
 
         /*
          * The rest of this function sets up the user list, so just return if
@@ -543,11 +547,14 @@ static void
 choose_user (GdmGreeterLoginWindow *login_window,
              const char            *user_name)
 {
+        guint mode;
+
         g_assert (user_name != NULL);
 
         g_signal_emit (G_OBJECT (login_window), signals[USER_SELECTED],
                        0, user_name);
 
+        mode = MODE_AUTHENTICATION;
         if (strcmp (user_name, GDM_USER_CHOOSER_USER_OTHER) == 0) {
                 g_signal_emit (login_window, signals[BEGIN_VERIFICATION], 0);
         } else if (strcmp (user_name, GDM_USER_CHOOSER_USER_GUEST) == 0) {
@@ -560,13 +567,13 @@ choose_user (GdmGreeterLoginWindow *login_window,
                 restart_timed_login_timeout (login_window);
 
                 /* just wait for the user to select language and stuff */
-                set_log_in_button_mode (login_window, LOGIN_BUTTON_TIMED_LOGIN);
+                mode = MODE_TIMED_LOGIN;
                 set_message (login_window, _("Select language and click Log In"));
         } else {
                 g_signal_emit (login_window, signals[BEGIN_VERIFICATION_FOR_USER], 0, user_name);
         }
 
-        switch_mode (login_window, MODE_AUTHENTICATION);
+        switch_mode (login_window, mode);
 }
 
 static void
@@ -596,14 +603,15 @@ reset_dialog (GdmGreeterLoginWindow *login_window,
 {
         GtkWidget  *entry;
         GtkWidget  *label;
+        guint       mode;
 
         g_debug ("GdmGreeterLoginWindow: Resetting dialog to mode %u", dialog_mode);
         set_busy (login_window);
         set_sensitive (login_window, FALSE);
 
-        if (dialog_mode == MODE_SELECTION) {
-                login_window->priv->show_cancel_button = FALSE;
+        login_window->priv->num_queries = 0;
 
+        if (dialog_mode == MODE_SELECTION) {
                 if (login_window->priv->timed_login_enabled) {
                         gdm_chooser_widget_set_item_timer (GDM_CHOOSER_WIDGET (login_window->priv->user_chooser),
                                                            GDM_USER_CHOOSER_USER_AUTO, 0);
@@ -636,6 +644,7 @@ reset_dialog (GdmGreeterLoginWindow *login_window,
         gtk_label_set_text (GTK_LABEL (label), "");
 
         if (login_window->priv->user_list_disabled || user_chooser_has_no_user (login_window)) {
+                /* If we don't have a user list jump straight to authenticate */
                 switch_mode (login_window, MODE_AUTHENTICATION);
         } else {
                 switch_mode (login_window, dialog_mode);
@@ -645,7 +654,6 @@ reset_dialog (GdmGreeterLoginWindow *login_window,
         set_ready (login_window);
         set_focus (GDM_GREETER_LOGIN_WINDOW (login_window));
         update_banner_message (login_window);
-        adjust_other_login_visibility (login_window);
 
         if (gdm_chooser_widget_get_number_of_items (GDM_CHOOSER_WIDGET (login_window->priv->user_chooser)) >= 1) {
                 gdm_chooser_widget_propagate_pending_key_events (GDM_CHOOSER_WIDGET (login_window->priv->user_chooser));
@@ -827,21 +835,6 @@ gdm_greeter_login_window_start_session_when_ready (GdmGreeterLoginWindow *login_
         }
 }
 
-static void
-_show_cancel_button (GdmGreeterLoginWindow *login_window)
-{
-        /*
-         * If show_cancel_button is false, this is because the face browser
-         * is disabled and the first query is showing.  It does not make sense
-         * to display the cancel button when showing the initial query and
-         * the face browser is disabled.  Set the flag to true so that the
-         * button is shown on following queries.
-         */
-        show_widget (login_window, "cancel-button",
-                     login_window->priv->show_cancel_button);
-        login_window->priv->show_cancel_button = TRUE;
-}
-
 gboolean
 gdm_greeter_login_window_info_query (GdmGreeterLoginWindow *login_window,
                                      const char            *text)
@@ -851,7 +844,8 @@ gdm_greeter_login_window_info_query (GdmGreeterLoginWindow *login_window,
 
         g_return_val_if_fail (GDM_IS_GREETER_LOGIN_WINDOW (login_window), FALSE);
 
-        _show_cancel_button (login_window);
+        login_window->priv->num_queries++;
+        maybe_show_cancel_button (login_window);
 
         g_debug ("GdmGreeterLoginWindow: info query: %s", text);
 
@@ -882,7 +876,8 @@ gdm_greeter_login_window_secret_info_query (GdmGreeterLoginWindow *login_window,
 
         g_return_val_if_fail (GDM_IS_GREETER_LOGIN_WINDOW (login_window), FALSE);
 
-        _show_cancel_button (login_window);
+        login_window->priv->num_queries++;
+        maybe_show_cancel_button (login_window);
 
         entry = GTK_WIDGET (gtk_builder_get_object (GDM_GREETER_LOGIN_WINDOW (login_window)->priv->builder, "auth-prompt-entry"));
         gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
@@ -978,7 +973,6 @@ on_user_chooser_visibility_changed (GdmGreeterLoginWindow *login_window)
 {
         g_debug ("GdmGreeterLoginWindow: Chooser visibility changed");
         update_banner_message (login_window);
-        adjust_other_login_visibility (login_window);
 }
 
 static void
@@ -988,11 +982,9 @@ on_users_loaded (GdmUserChooserWidget  *user_chooser,
         g_debug ("GdmGreeterLoginWindow: users loaded");
         login_window->priv->user_chooser_loaded = TRUE;
         update_banner_message (login_window);
-        adjust_other_login_visibility (login_window);
 
         if (user_chooser_has_no_user (login_window)) {
-                /* There's no face browser to show */
-                login_window->priv->show_cancel_button = FALSE;
+                /* jump straight to authenticate */
                 switch_mode (login_window, MODE_AUTHENTICATION);
 
                 g_debug ("Starting PAM conversation since no local users");
@@ -1007,6 +999,7 @@ on_user_chosen (GdmUserChooserWidget  *user_chooser,
                 GdmGreeterLoginWindow *login_window)
 {
         char *user_name;
+        guint mode;
 
         user_name = gdm_user_chooser_widget_get_chosen_user_name (GDM_USER_CHOOSER_WIDGET (login_window->priv->user_chooser));
         g_debug ("GdmGreeterLoginWindow: user chosen '%s'", user_name);
@@ -1016,7 +1009,6 @@ on_user_chosen (GdmUserChooserWidget  *user_chooser,
         }
 
         choose_user (login_window, user_name);
-
         g_free (user_name);
 }
 



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