[accounts-dialog] Some more rearrangement of the password dialog



commit 7ea17beebbecc3e780a1216669fb12538acc5398
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Mar 1 13:29:20 2010 -0500

    Some more rearrangement of the password dialog

 data/password-dialog.ui  |  131 ++++++++++++++++++++-------------------------
 src/um-password-dialog.c |  111 +++++++++++++++++++++++++++++++-------
 src/um-photo-dialog.c    |   31 +----------
 src/um-utils.c           |   29 ++++++++++
 src/um-utils.h           |    8 +++
 5 files changed, 187 insertions(+), 123 deletions(-)
---
diff --git a/data/password-dialog.ui b/data/password-dialog.ui
index b5e2c8c..000aa4b 100644
--- a/data/password-dialog.ui
+++ b/data/password-dialog.ui
@@ -56,45 +56,6 @@
                 <property name="column_spacing">10</property>
                 <property name="row_spacing">6</property>
                 <child>
-                  <object class="GtkHBox" id="hbox13">
-                    <property name="visible">True</property>
-                    <property name="spacing">9</property>
-                    <child>
-                      <object class="GtkAlignment" id="alignment1">
-                        <property name="visible">True</property>
-                        <property name="top_padding">6</property>
-                        <property name="bottom_padding">6</property>
-                        <child>
-                          <object class="UmStrengthBar" id="strength-indicator-progressbar">
-                            <property name="visible">True</property>
-                          </object>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="strength-indicator-label">
-                        <property name="visible">True</property>
-                        <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Fair</property>
-                      </object>
-                      <packing>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">6</property>
-                    <property name="bottom_attach">7</property>
-                  </packing>
-                </child>
-                <child>
                   <object class="GtkVBox" id="vbox14">
                     <property name="visible">True</property>
                     <property name="orientation">vertical</property>
@@ -162,21 +123,6 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="password-normal-strength-label">
-                    <property name="visible">True</property>
-                    <property name="xalign">1</property>
-                    <property name="label" translatable="yes">Strength:</property>
-                    <attributes>
-                      <attribute name="foreground" value="#555555555555"/>
-                    </attributes>
-                  </object>
-                  <packing>
-                    <property name="top_attach">6</property>
-                    <property name="bottom_attach">7</property>
-                    <property name="x_options">GTK_FILL</property>
-                  </packing>
-                </child>
-                <child>
                   <object class="GtkEntry" id="verify-entry">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
@@ -216,7 +162,6 @@
                         <property name="xalign">1</property>
                         <property name="label" translatable="yes">_New password:</property>
                         <property name="use_underline">True</property>
-                        <property name="mnemonic_widget">password-combo</property>
                         <attributes>
                           <attribute name="foreground" value="#555555555555"/>
                         </attributes>
@@ -250,9 +195,10 @@
                         <property name="visible">True</property>
                         <property name="spacing">6</property>
                         <child>
-                          <object class="GtkComboBoxEntry" id="password-combo">
+                          <object class="GtkEntry" id="password-entry">
                             <property name="visible">True</property>
-                            <property name="text_column">0</property>
+                            <property name="can_focus">True</property>
+                            <property name="visibility">False</property>
                           </object>
                           <packing>
                             <property name="position">0</property>
@@ -262,11 +208,12 @@
                           <object class="GtkButton" id="generate-again-button">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="tooltip_text" translatable="yes">Choose a generated password</property>
                             <child>
                               <object class="GtkImage" id="generate-again-image">
                                 <property name="visible">True</property>
-                                <property name="stock">gtk-refresh</property>
+                                <property name="stock">gtk-execute</property>
                               </object>
                             </child>
                           </object>
@@ -282,13 +229,36 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkCheckButton" id="show-password-checkbutton">
-                        <property name="label" translatable="yes">_Show password</property>
+                      <object class="GtkHBox" id="hbox13">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="draw_indicator">True</property>
+                        <property name="spacing">9</property>
+                        <child>
+                          <object class="GtkAlignment" id="alignment1">
+                            <property name="visible">True</property>
+                            <property name="top_padding">6</property>
+                            <property name="bottom_padding">6</property>
+                            <child>
+                              <object class="UmStrengthBar" id="strength-indicator">
+                                <property name="visible">True</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="strength-indicator-label">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Fair</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="position">1</property>
@@ -443,6 +413,25 @@
                     <property name="right_attach">2</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkCheckButton" id="show-password-checkbutton">
+                    <property name="label" translatable="yes">_Show password</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">6</property>
+                    <property name="bottom_attach">7</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
               </object>
               <packing>
                 <property name="position">0</property>
@@ -475,6 +464,8 @@
                 </child>
               </object>
               <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="position">0</property>
                 <property name="secondary">True</property>
               </packing>
@@ -525,6 +516,7 @@
             </child>
           </object>
           <packing>
+            <property name="expand">False</property>
             <property name="pack_type">end</property>
             <property name="position">0</property>
           </packing>
@@ -532,12 +524,5 @@
       </object>
     </child>
   </object>
-  <object class="GtkSizeGroup" id="sizegroup">
-    <widgets>
-      <widget name="password-normal-hint-label"/>
-      <widget name="password-normal-strength-label"/>
-      <widget name="password-normal-verify-label"/>
-      <widget name="password-normal-password-label"/>
-    </widgets>
-  </object>
+  <object class="GtkSizeGroup" id="sizegroup"/>
 </interface>
diff --git a/src/um-password-dialog.c b/src/um-password-dialog.c
index b8851ac..7fd70ad 100644
--- a/src/um-password-dialog.c
+++ b/src/um-password-dialog.c
@@ -50,8 +50,8 @@ struct _UmPasswordDialog {
         GtkWidget *strength_indicator_label;
         GtkWidget *normal_hint_entry;
         GtkWidget *normal_hint_label;
-        GtkWidget *generate_combo;
         GtkWidget *generate_button;
+        GtkWidget *generate_menu;
         GtkWidget *show_password_button;
         GtkWidget *ok_button;
 
@@ -65,6 +65,59 @@ struct _UmPasswordDialog {
 };
 
 static void
+generate_clicked (GtkButton        *button,
+                  UmPasswordDialog *um)
+{
+        gtk_menu_popup (GTK_MENU (um->generate_menu),
+                        NULL, NULL,
+                        (GtkMenuPositionFunc) popup_menu_below_button, um->generate_button,
+                        0, gtk_get_current_event_time ());
+}
+
+static void
+generate_expose (GtkWidget        *widget,
+                 GdkEventExpose   *event,
+                 UmPasswordDialog *um)
+{
+        GtkAllocation allocation;
+
+        if (!gtk_widget_is_sensitive (widget))
+                return;
+
+        gtk_widget_get_allocation (widget, &allocation);
+        gtk_paint_expander (gtk_widget_get_style (widget),
+                            gtk_widget_get_window (widget),
+                            gtk_widget_get_state (widget),
+                            NULL,
+                            widget,
+                            NULL,
+                            allocation.x + allocation.width,
+                            allocation.y + allocation.height,
+                            GTK_EXPANDER_EXPANDED);
+}
+
+static void
+activate_password_item (GtkMenuItem      *item,
+                        UmPasswordDialog *um)
+{
+        const char *password;
+
+        password = gtk_menu_item_get_label (item);
+
+        gtk_entry_set_text (GTK_ENTRY (um->password_entry), password);
+}
+
+static void generate_passwords (UmPasswordDialog *um);
+
+static void
+activate_generate_item (GtkMenuItem      *item,
+                        UmPasswordDialog *um)
+{
+        generate_passwords (um);
+        generate_clicked (GTK_BUTTON (um->generate_button), um);
+}
+
+static void
 generate_passwords (UmPasswordDialog *um)
 {
         gint min_len, max_len;
@@ -73,13 +126,16 @@ generate_passwords (UmPasswordDialog *um)
         GError *error;
         gchar **lines;
         gint i;
-        GtkListStore *store;
-        GtkTreeIter iter;
+        GtkWidget *item;
 
         min_len = 6;
         max_len = 12;
 
-        store = gtk_list_store_new (1, G_TYPE_STRING);
+        if (um->generate_menu) {
+                gtk_widget_destroy (um->generate_menu);
+        }
+
+        um->generate_menu = gtk_menu_new ();
 
         cmdline = g_strdup_printf ("apg -n 6 -M SNC -m %d -x %d", min_len, max_len);
         error = NULL;
@@ -96,10 +152,11 @@ generate_passwords (UmPasswordDialog *um)
                         if (lines[i][0] == 0)
                                 continue;
 
-                        gtk_list_store_append (store, &iter);
-                        gtk_list_store_set (store, &iter,
-                                            0, lines[i],
-                                            -1);
+                        item = gtk_menu_item_new_with_label (lines[i]);
+                        g_signal_connect (item, "activate",
+                                          G_CALLBACK (activate_password_item), um);
+                        gtk_widget_show (item);
+                        gtk_menu_shell_append (GTK_MENU_SHELL (um->generate_menu), item);
                 }
                 g_strfreev (lines);
         }
@@ -111,9 +168,15 @@ generate_passwords (UmPasswordDialog *um)
         g_free (output);
         g_free (err);
 
-        gtk_combo_box_set_model (GTK_COMBO_BOX (um->generate_combo),
-                                 GTK_TREE_MODEL (store));
-        gtk_combo_box_set_active (GTK_COMBO_BOX (um->generate_combo), 0);
+        item = gtk_separator_menu_item_new ();
+        gtk_widget_show (item);
+        gtk_menu_shell_append (GTK_MENU_SHELL (um->generate_menu), item);
+
+        item = gtk_menu_item_new_with_label (_("Regenerate passwords"));
+        g_signal_connect (item, "activate",
+                          G_CALLBACK (activate_generate_item), um);
+        gtk_widget_show (item);
+        gtk_menu_shell_append (GTK_MENU_SHELL (um->generate_menu), item);
 }
 
 /* This code is based on the Master Password dialog in Firefox
@@ -332,8 +395,9 @@ action_changed (GtkComboBox      *combo,
 
         active = gtk_combo_box_get_active (combo);
         if (active == 0) {
-                gtk_widget_set_sensitive (um->generate_combo, TRUE);
+                gtk_widget_set_sensitive (um->password_entry, TRUE);
                 gtk_widget_set_sensitive (um->generate_button, TRUE);
+                gtk_widget_set_has_tooltip (um->generate_button, TRUE);
                 gtk_widget_set_sensitive (um->verify_entry, TRUE);
                 gtk_widget_set_sensitive (um->old_password_entry, TRUE);
                 gtk_widget_set_sensitive (um->normal_hint_entry, TRUE);
@@ -344,8 +408,9 @@ action_changed (GtkComboBox      *combo,
                 update_sensitivity (um);
         }
         else {
-                gtk_widget_set_sensitive (um->generate_combo, FALSE);
+                gtk_widget_set_sensitive (um->password_entry, FALSE);
                 gtk_widget_set_sensitive (um->generate_button, FALSE);
+                gtk_widget_set_has_tooltip (um->generate_button, FALSE);
                 gtk_widget_set_sensitive (um->verify_entry, FALSE);
                 gtk_widget_set_sensitive (um->old_password_entry, FALSE);
                 gtk_widget_set_sensitive (um->normal_hint_entry, FALSE);
@@ -533,8 +598,10 @@ um_password_dialog_new (void)
         builder = gtk_builder_new ();
 
         error = NULL;
+#if 0
         filename = UIDIR "/password-dialog.ui";
         if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+#endif
                 filename = "../data/password-dialog.ui";
         if (!gtk_builder_add_from_file (builder, filename, &error)) {
                 g_error ("%s", error->message);
@@ -573,11 +640,7 @@ um_password_dialog_new (void)
                           G_CALLBACK (show_password_toggled), um);
         um->show_password_button = widget;
 
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "password-combo");
-        um->generate_combo = widget;
-
-        widget = gtk_bin_get_child (GTK_BIN (widget));
-
+        widget = (GtkWidget *) gtk_builder_get_object (builder, "password-entry");
         g_signal_connect (widget, "notify::text",
                           G_CALLBACK (password_entry_changed), um);
         gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
@@ -614,9 +677,15 @@ um_password_dialog_new (void)
 
 
         widget = (GtkWidget *) gtk_builder_get_object (builder, "generate-again-button");
-        g_signal_connect_swapped (widget, "clicked",
-                                  G_CALLBACK (generate_passwords), um);
+        g_signal_connect (widget, "clicked",
+                          G_CALLBACK (generate_clicked), um);
+#if 0
+        g_signal_connect (widget, "state-changed",
+                          G_CALLBACK (generate_state_changed), um);
+#endif
         um->generate_button = widget;
+        g_signal_connect_after (gtk_bin_get_child (GTK_BIN (widget)), "expose-event",
+                                G_CALLBACK (generate_expose), um);
 
         um->normal_hint_entry = (GtkWidget *) gtk_builder_get_object (builder, "normal-hint-entry");
 
@@ -628,7 +697,7 @@ um_password_dialog_new (void)
                           G_CALLBACK (entry_size_changed), widget);
         um->normal_hint_label = widget;
 
-        um->strength_indicator = (GtkWidget *) gtk_builder_get_object (builder, "strength-indicator-progressbar");
+        um->strength_indicator = (GtkWidget *) gtk_builder_get_object (builder, "strength-indicator");
 
         um->strength_indicator_label = (GtkWidget *) gtk_builder_get_object (builder, "strength-indicator-label");
 
diff --git a/src/um-photo-dialog.c b/src/um-photo-dialog.c
index 56c26a8..c95b520 100644
--- a/src/um-photo-dialog.c
+++ b/src/um-photo-dialog.c
@@ -37,6 +37,7 @@
 #include "um-photo-dialog.h"
 #include "um-user-manager.h"
 #include "um-crop-area.h"
+#include "um-utils.h"
 
 #define ROW_SPAN 6
 
@@ -456,40 +457,12 @@ out:
 }
 
 static void
-popup_icon_menu_position (GtkMenu *menu,
-                          gint *x,
-                          gint *y,
-                          gboolean *push_in,
-                          UmPhotoDialog *um)
-{
-        GtkRequisition menu_req;
-        GtkTextDirection direction;
-        GtkAllocation allocation;
-
-        gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
-
-        direction = gtk_widget_get_direction (um->popup_button);
-
-        gdk_window_get_origin (gtk_widget_get_window (um->popup_button), x, y);
-        gtk_widget_get_allocation (um->popup_button, &allocation);
-        *x += allocation.x;
-        *y += allocation.y + allocation.height;
-
-        if (direction == GTK_TEXT_DIR_LTR)
-                *x += MAX (allocation.width - menu_req.width, 0);
-        else if (menu_req.width > allocation.width)
-                *x -= menu_req.width - allocation.width;
-
-        *push_in = TRUE;
-}
-
-static void
 popup_icon_menu (GtkToggleButton *button, UmPhotoDialog *um)
 {
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) && !GTK_WIDGET_VISIBLE (um->photo_popup)) {
                 gtk_menu_popup (GTK_MENU (um->photo_popup),
                                 NULL, NULL,
-                                (GtkMenuPositionFunc) popup_icon_menu_position, um,
+                                (GtkMenuPositionFunc) popup_menu_below_button, um->popup_button,
                                 0, gtk_get_current_event_time ());
         } else {
                 gtk_menu_popdown (GTK_MENU (um->photo_popup));
diff --git a/src/um-utils.c b/src/um-utils.c
index 9360371..a9e1dc8 100644
--- a/src/um-utils.c
+++ b/src/um-utils.c
@@ -297,3 +297,32 @@ clear_entry_validation_error (GtkEntry *entry)
                                         GTK_ENTRY_ICON_SECONDARY,
                                         NULL);
 }
+
+void
+popup_menu_below_button (GtkMenu   *menu,
+                         gint      *x,
+                         gint      *y,
+                         gboolean  *push_in,
+                         GtkWidget *button)
+{
+        GtkRequisition menu_req;
+        GtkTextDirection direction;
+        GtkAllocation allocation;
+
+        gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
+
+        direction = gtk_widget_get_direction (button);
+
+        gdk_window_get_origin (gtk_widget_get_window (button), x, y);
+        gtk_widget_get_allocation (button, &allocation);
+        *x += allocation.x;
+        *y += allocation.y + allocation.height;
+
+        if (direction == GTK_TEXT_DIR_LTR)
+                *x += MAX (allocation.width - menu_req.width, 0);
+        else if (menu_req.width > allocation.width)
+                *x -= menu_req.width - allocation.width;
+
+        *push_in = TRUE;
+}
+
diff --git a/src/um-utils.h b/src/um-utils.h
index b11cdfd..c87cf58 100644
--- a/src/um-utils.h
+++ b/src/um-utils.h
@@ -36,6 +36,14 @@ gboolean show_tooltip_now                 (GtkWidget   *widget,
 void     set_entry_validation_error       (GtkEntry    *entry,
                                            const gchar *text);
 void     clear_entry_validation_error     (GtkEntry    *entry);
+
+void     popup_menu_below_button          (GtkMenu     *menu,
+                                           gint        *x,
+                                           gint        *y,
+                                           gboolean    *push_in,
+                                           GtkWidget   *button);
+
+
 G_END_DECLS
 
 #endif



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