[geary/wip/720779-password-dialog] Clean up the password dialog



commit a18d82c32344da6d80344522f57f5ee5e328acd7
Author: Charles Lindsay <chaz yorba org>
Date:   Fri Jan 10 18:04:05 2014 -0800

    Clean up the password dialog
    
    We now assume it's only going to prompt for one password at a time,
    which simplifies things a great deal.

 src/client/application/secret-mediator.vala |   25 ++++---
 src/client/dialogs/password-dialog.vala     |   79 ++++++---------------
 ui/password-dialog.glade                    |  105 ++-------------------------
 3 files changed, 43 insertions(+), 166 deletions(-)
---
diff --git a/src/client/application/secret-mediator.vala b/src/client/application/secret-mediator.vala
index ef9f71c..5178f9b 100644
--- a/src/client/application/secret-mediator.vala
+++ b/src/client/application/secret-mediator.vala
@@ -65,12 +65,12 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
         Geary.AccountInformation account_information,
         out string? imap_password, out string? smtp_password,
         out bool imap_remember_password, out bool smtp_remember_password) throws Error {
-        bool first_try = !account_information.imap_credentials.is_complete() ||
-            (account_information.smtp_credentials != null &&
-            !account_information.smtp_credentials.is_complete());
+        // Our dialog doesn't support asking for both at once, even though this
+        // API would indicate it does.  We need to revamp the API.
+        assert(!services.has_imap() || !services.has_smtp());
         
-        PasswordDialog password_dialog = new PasswordDialog(account_information, first_try,
-            services);
+        PasswordDialog password_dialog = new PasswordDialog(services.has_smtp(),
+            account_information, services);
         
         if (!password_dialog.run()) {
             imap_password = null;
@@ -82,10 +82,17 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
         
         // password_dialog.password should never be null at this point. It will only be null when
         // password_dialog.run() returns false, in which case we have already returned.
-        imap_password = password_dialog.imap_password;
-        smtp_password = password_dialog.smtp_password;
-        imap_remember_password = password_dialog.remember_password;
-        smtp_remember_password = password_dialog.remember_password;
+        if (services.has_smtp()) {
+            imap_password = null;
+            imap_remember_password = false;
+            smtp_password = password_dialog.password;
+            smtp_remember_password = password_dialog.remember_password;
+        } else {
+            imap_password = password_dialog.password;
+            imap_remember_password = password_dialog.remember_password;
+            smtp_password = null;
+            smtp_remember_password = false;
+        }
         return true;
     }
 }
diff --git a/src/client/dialogs/password-dialog.vala b/src/client/dialogs/password-dialog.vala
index ba04cca..06ab588 100644
--- a/src/client/dialogs/password-dialog.vala
+++ b/src/client/dialogs/password-dialog.vala
@@ -13,61 +13,46 @@ public class PasswordDialog {
     // strings, and Glade doesn't support the "larger" size attribute. See this bug report for
     // details: https://bugzilla.gnome.org/show_bug.cgi?id=679006
     private const string PRIMARY_TEXT_MARKUP = "<span weight=\"bold\" size=\"larger\">%s</span>";
-    private const string PRIMARY_TEXT_FIRST_TRY = _("Please enter your email password");
-    private const string PRIMARY_TEXT_REPEATED_TRY = _("Unable to login to email server");
+    private const string PRIMARY_TEXT_FIRST_TRY = _("Please enter your password");
     
     private Gtk.Dialog dialog;
-    private Gtk.Entry entry_imap_password;
+    private Gtk.Entry entry_password;
     private Gtk.CheckButton check_remember_password;
-    private Gtk.Entry entry_smtp_password;
     private Gtk.Button ok_button;
-    private Gtk.Grid grid_imap;
-    private Gtk.Grid grid_smtp;
-    private Gtk.Label label_imap;
-    private Geary.CredentialsMediator.ServiceFlag password_flags;
     
-    public string imap_password { get; private set; default = ""; }
-    public string smtp_password { get; private set; default = ""; }
+    public string password { get; private set; default = ""; }
     public bool remember_password { get; private set; }
     
-    public PasswordDialog(Geary.AccountInformation account_information, bool first_try,
+    public PasswordDialog(bool smtp, Geary.AccountInformation account_information,
         Geary.CredentialsMediator.ServiceFlag password_flags) {
-        this.password_flags = password_flags;
         Gtk.Builder builder = GearyApplication.instance.create_builder("password-dialog.glade");
         
-        // Load dialog
         dialog = (Gtk.Dialog) builder.get_object("PasswordDialog");
         dialog.set_type_hint(Gdk.WindowTypeHint.DIALOG);
         dialog.set_default_response(Gtk.ResponseType.OK);
         
-        // Load editable widgets
-        entry_imap_password = (Gtk.Entry) builder.get_object("entry: imap password");
-        entry_smtp_password = (Gtk.Entry) builder.get_object("entry: smtp password");
+        entry_password = (Gtk.Entry) builder.get_object("entry: password");
         check_remember_password = (Gtk.CheckButton) builder.get_object("check: remember_password");
         
-        grid_imap = (Gtk.Grid) builder.get_object("grid: imap");
-        label_imap = (Gtk.Label) builder.get_object("label: imap");
-        Gtk.Label label_imap_username = (Gtk.Label) builder.get_object("label: imap username");
-        
-        grid_smtp = (Gtk.Grid) builder.get_object("grid: smtp");
-        Gtk.Label label_smtp_username = (Gtk.Label) builder.get_object("label: smtp username");
+        Gtk.Label label_username = (Gtk.Label) builder.get_object("label: username");
+        Gtk.Label label_smtp = (Gtk.Label) builder.get_object("label: smtp");
         
         // Load translated text for labels with markup unsupported by glade.
         Gtk.Label primary_text_label = (Gtk.Label) builder.get_object("primary_text_label");
-        primary_text_label.set_markup(get_primary_text_markup(first_try));
+        primary_text_label.set_markup(PRIMARY_TEXT_MARKUP.printf(PRIMARY_TEXT_FIRST_TRY));
 
-        // Load initial values
-        label_imap_username.set_text(account_information.imap_credentials.user ?? "");
-        entry_imap_password.set_text(account_information.imap_credentials.pass ?? "");
-        
-        if (account_information.smtp_credentials != null) {
-            label_smtp_username.set_text(account_information.smtp_credentials.user ?? "");
-            entry_smtp_password.set_text(account_information.smtp_credentials.pass ?? "");
+        if (smtp) {
+            label_username.set_text(account_information.smtp_credentials.user ?? "");
+            entry_password.set_text(account_information.smtp_credentials.pass ?? "");
+        } else {
+            label_username.set_text(account_information.imap_credentials.user ?? "");
+            entry_password.set_text(account_information.imap_credentials.pass ?? "");
         }
+        check_remember_password.active = (smtp ? account_information.smtp_remember_password
+            : account_information.imap_remember_password);
+        if (smtp)
+            label_smtp.show();
         
-        check_remember_password.active = account_information.imap_remember_password;
-        
-        // Add action buttons
         Gtk.Button cancel_button = new Gtk.Button.from_stock(Stock._CANCEL);
         ok_button = new Gtk.Button.from_stock(Stock._OK);
         ok_button.can_default = true;
@@ -75,43 +60,21 @@ public class PasswordDialog {
         dialog.add_action_widget(ok_button, Gtk.ResponseType.OK);
         dialog.set_default_response(Gtk.ResponseType.OK);
         
-        // Setup listeners
         refresh_ok_button_sensitivity();
-        entry_imap_password.changed.connect(refresh_ok_button_sensitivity);
-        entry_smtp_password.changed.connect(refresh_ok_button_sensitivity);
-    }
-    
-    private string get_primary_text_markup(bool first_try) {
-        return PRIMARY_TEXT_MARKUP.printf(first_try ? PRIMARY_TEXT_FIRST_TRY : PRIMARY_TEXT_REPEATED_TRY);
+        entry_password.changed.connect(refresh_ok_button_sensitivity);
     }
     
     private void refresh_ok_button_sensitivity() {
-        ok_button.sensitive = !Geary.String.is_empty_or_whitespace(entry_imap_password.get_text()) ||
-            !Geary.String.is_empty_or_whitespace(entry_smtp_password.get_text());
+        ok_button.sensitive = !Geary.String.is_empty_or_whitespace(entry_password.get_text());
     }
     
     public bool run() {
         dialog.show();
         dialog.get_action_area().show_all();
         
-        if (password_flags.has_smtp()) {
-            grid_smtp.show();
-        }
-        
-        if (!password_flags.has_imap()) {
-            grid_imap.hide();
-            entry_smtp_password.grab_focus();
-        }
-        
-        if (password_flags.has_smtp() && password_flags.has_imap()) {
-            check_remember_password.label = _("_Remember passwords");
-            label_imap.show();
-        }
-        
         Gtk.ResponseType response = (Gtk.ResponseType) dialog.run();
         if (response == Gtk.ResponseType.OK) {
-            imap_password = entry_imap_password.get_text();
-            smtp_password = entry_smtp_password.get_text();
+            password = entry_password.get_text();
             remember_password = check_remember_password.active;
         }
         
diff --git a/ui/password-dialog.glade b/ui/password-dialog.glade
index 0dc6d03..131f065 100644
--- a/ui/password-dialog.glade
+++ b/ui/password-dialog.glade
@@ -57,107 +57,14 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkGrid" id="grid: imap">
+                  <object class="GtkGrid" id="grid">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="row_spacing">6</property>
                     <property name="column_spacing">12</property>
                     <child>
-                      <object class="GtkLabel" id="label for: imap username">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
-                        <property name="xpad">6</property>
-                        <property name="label" translatable="yes">Username:</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">1</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label for: imap password">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
-                        <property name="xpad">6</property>
-                        <property name="label" translatable="yes">_Password:</property>
-                        <property name="use_underline">True</property>
-                        <property name="mnemonic_widget">entry: imap password</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label: imap username">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="xalign">0</property>
-                        <property name="xpad">2</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">1</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkEntry" id="entry: imap password">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="hexpand">True</property>
-                        <property name="visibility">False</property>
-                        <property name="invisible_char">•</property>
-                        <property name="activates_default">True</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label: imap">
-                        <property name="can_focus">False</property>
-                        <property name="no_show_all">True</property>
-                        <property name="xalign">0</property>
-                        <property name="label" translatable="yes">IMAP Credentials</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">0</property>
-                        <property name="width">2</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkGrid" id="grid: smtp">
-                    <property name="can_focus">False</property>
-                    <property name="no_show_all">True</property>
-                    <property name="row_spacing">6</property>
-                    <property name="column_spacing">12</property>
-                    <child>
                       <object class="GtkLabel" id="label: smtp">
-                        <property name="visible">True</property>
+                        <property name="visible">False</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">SMTP Credentials</property>
@@ -173,7 +80,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label for: smtp username">
+                      <object class="GtkLabel" id="label for: username">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
@@ -188,7 +95,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label for: smtp password">
+                      <object class="GtkLabel" id="label for: password">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
@@ -203,7 +110,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label: smtp username">
+                      <object class="GtkLabel" id="label: username">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
@@ -217,7 +124,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkEntry" id="entry: smtp password">
+                      <object class="GtkEntry" id="entry: password">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="hexpand">True</property>


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