[geary/wip/714922-multiple-addresses-2] More UI work



commit c87c57871be5d0aa70e5ed9f3996d35725b63c8e
Author: Jim Nelson <jim yorba org>
Date:   Tue Feb 10 18:28:34 2015 -0800

    More UI work

 .../account-dialog-edit-alternate-emails-pane.vala |   56 +++++++-
 src/client/accounts/account-dialog.vala            |    4 +-
 src/engine/api/geary-account-information.vala      |   27 ++++-
 ui/edit_alternate_emails.glade                     |   11 ++-
 ui/login.glade                                     |  150 ++++++++++----------
 5 files changed, 161 insertions(+), 87 deletions(-)
---
diff --git a/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala 
b/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala
index 64bb559..3e4dfd4 100644
--- a/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala
+++ b/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala
@@ -14,6 +14,7 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
             label = "<b>%s</b>".printf(mailbox.address);
             use_markup = true;
             ellipsize = Pango.EllipsizeMode.END;
+            xalign = 0.0f;
         }
     }
     
@@ -21,8 +22,6 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
     
     public bool changed { get; private set; default = false; }
     
-    public string? selected { get; private set; default = null; }
-    
     private Gtk.Label title_label;
     private Gtk.Entry email_entry;
     private Gtk.Button add_button;
@@ -30,12 +29,14 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
     private Gtk.ToolButton delete_button;
     private Gtk.Button cancel_button;
     private Gtk.Button save_button;
+    private ListItem? selected_item = null;
     
+    private Geary.AccountInformation? account_info = null;
     private Geary.RFC822.MailboxAddress? primary_mailbox = null;
     private Gee.HashSet<string> email_addresses = new Gee.HashSet<string>(
         Geary.String.stri_hash, Geary.String.stri_equal);
     
-    public signal void cancelled();
+    public signal void done();
     
     public AccountDialogEditAlternateEmailsPane(Gtk.Stack stack) {
         base (stack);
@@ -56,10 +57,14 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
         email_entry.bind_property("text", add_button, "sensitive", BindingFlags.SYNC_CREATE,
             transform_email_to_sensitive);
         bind_property("changed", save_button, "sensitive", BindingFlags.SYNC_CREATE);
-        bind_property("selected", delete_button, "sensitive", BindingFlags.SYNC_CREATE);
         
-        cancel_button.clicked.connect(() => { cancelled(); });
+        delete_button.sensitive = false;
+        
+        address_listbox.row_selected.connect(on_row_selected);
         add_button.clicked.connect(on_add_clicked);
+        delete_button.clicked.connect(on_delete_clicked);
+        cancel_button.clicked.connect(() => { done(); });
+        save_button.clicked.connect(on_save_clicked);
     }
     
     private bool transform_email_to_sensitive(Binding binding, Value source, ref Value target) {
@@ -69,8 +74,11 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
     }
     
     public void set_account(Geary.AccountInformation account_info) {
+        this.account_info = account_info;
+        
         email = account_info.email;
         primary_mailbox = account_info.get_primary_mailbox_address();
+        email_addresses.clear();
         changed = false;
         
         // reset/clear widgets
@@ -81,7 +89,7 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
         foreach (Gtk.Widget widget in address_listbox.get_children())
             address_listbox.remove(widget);
         
-        // Add all except for primary; this does not constitute a change per se
+        // Add all email addresses; add_email_address() silently drops the primary address
         foreach (string email_address in account_info.get_all_email_addresses())
             add_email_address(email_address, false);
     }
@@ -106,8 +114,44 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
             changed = true;
     }
     
+    private void remove_email_address(Geary.RFC822.MailboxAddress mailbox) {
+        if (!email_addresses.remove(mailbox.address))
+            return;
+        
+        foreach (Gtk.Widget widget in address_listbox.get_children()) {
+            Gtk.ListBoxRow row = (Gtk.ListBoxRow) widget;
+            ListItem item = (ListItem) row.get_child();
+            
+            if (item.mailbox.address == mailbox.address) {
+                address_listbox.remove(widget);
+                
+                changed = true;
+                
+                break;
+            }
+        }
+    }
+    
+    private void on_row_selected(Gtk.ListBoxRow? row) {
+        selected_item = (row != null) ? (ListItem) row.get_child() : null;
+        delete_button.sensitive = (selected_item != null);
+    }
+    
     private void on_add_clicked() {
         add_email_address(email_entry.text, true);
+        email_entry.text = "";
+    }
+    
+    private void on_delete_clicked() {
+        if (selected_item != null)
+            remove_email_address(selected_item.mailbox);
+    }
+    
+    private void on_save_clicked() {
+        foreach (string email_address in email_addresses)
+            account_info.add_alternate_email(email_address);
+        
+        done();
     }
 }
 
diff --git a/src/client/accounts/account-dialog.vala b/src/client/accounts/account-dialog.vala
index 1e48847..03c6036 100644
--- a/src/client/accounts/account-dialog.vala
+++ b/src/client/accounts/account-dialog.vala
@@ -47,7 +47,7 @@ public class AccountDialog : Gtk.Dialog {
         remove_confirm_pane.ok.connect(on_delete_account_confirmed);
         remove_confirm_pane.cancel.connect(on_cancel_back_to_list);
         remove_fail_pane.ok.connect(on_cancel_back_to_list);
-        edit_alternate_emails_pane.cancelled.connect(on_cancel_back_to_editor);
+        edit_alternate_emails_pane.done.connect(on_done_back_to_editor);
         
         // Set default page.
         account_list_pane.present();
@@ -211,7 +211,7 @@ public class AccountDialog : Gtk.Dialog {
         account_list_pane.present();
     }
     
-    private void on_cancel_back_to_editor() {
+    private void on_done_back_to_editor() {
         add_edit_pane.present();
     }
 }
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 1dde784..3d847da 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -155,9 +155,19 @@ public class Geary.AccountInformation : BaseObject {
         } finally {
             real_name = get_string_value(key_file, GROUP, REAL_NAME_KEY);
             nickname = get_string_value(key_file, GROUP, NICKNAME_KEY);
-            alternate_emails = get_string_list_value(key_file, GROUP, ALTERNATE_EMAILS_KEY);
-            if (alternate_emails.size == 0)
+            
+            // Store alternate emails in a list of case-insensitive strings
+            Gee.List<string> alt_email_list = get_string_list_value(key_file, GROUP, ALTERNATE_EMAILS_KEY);
+            if (alt_email_list.size == 0) {
                 alternate_emails = null;
+            } else {
+                alternate_emails = new Gee.ArrayList<string>(String.stri_equal);
+                foreach (string alt_email in alt_email_list) {
+                    if (!alternate_emails.contains(alt_email))
+                        alternate_emails.add(alt_email);
+                }
+            }
+            
             imap_credentials.user = get_string_value(key_file, GROUP, IMAP_USERNAME_KEY, email);
             imap_remember_password = get_bool_value(key_file, GROUP, IMAP_REMEMBER_PASSWORD_KEY, true);
             smtp_credentials.user = get_string_value(key_file, GROUP, SMTP_USERNAME_KEY, email);
@@ -286,6 +296,19 @@ public class Geary.AccountInformation : BaseObject {
     }
     
     /**
+     * Add an alternate email address to the account.
+     *
+     * Duplicates will be ignored.
+     */
+    public void add_alternate_email(string email) {
+        if (alternate_emails == null)
+            alternate_emails = new Gee.ArrayList<string>(String.stri_equal);
+        
+        if (!alternate_emails.contains(email))
+            alternate_emails.add(email);
+    }
+    
+    /**
      * Return whether this account allows setting the save_sent_mail option.
      * If not, save_sent_mail will always be true and setting it will be
      * ignored.
diff --git a/ui/edit_alternate_emails.glade b/ui/edit_alternate_emails.glade
index 9a43861..ee563d7 100644
--- a/ui/edit_alternate_emails.glade
+++ b/ui/edit_alternate_emails.glade
@@ -44,13 +44,20 @@
         </child>
         <child>
           <object class="GtkButton" id="add_button">
-            <property name="label" translatable="yes">_Add</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="can_default">True</property>
             <property name="has_default">True</property>
             <property name="receives_default">True</property>
             <property name="use_underline">True</property>
+            <child>
+              <object class="GtkImage" id="image1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="pixel_size">16</property>
+                <property name="icon_name">list-add-symbolic</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -146,7 +153,7 @@
         <property name="valign">end</property>
         <property name="margin_top">8</property>
         <property name="vexpand">False</property>
-        <property name="spacing">8</property>
+        <property name="spacing">6</property>
         <property name="homogeneous">True</property>
         <property name="layout_style">end</property>
         <child>
diff --git a/ui/login.glade b/ui/login.glade
index 8eb92e3..0f768ac 100644
--- a/ui/login.glade
+++ b/ui/login.glade
@@ -299,7 +299,7 @@
         </child>
         <child>
           <object class="GtkButton" id="button: edit_alternate_email">
-            <property name="label" translatable="yes">Add_itional email addresses…</property>
+            <property name="label" translatable="yes">Addi_tional email addresses…</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="use_underline">True</property>
@@ -854,80 +854,6 @@
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id="storage container">
-        <property name="can_focus">False</property>
-        <property name="margin_bottom">10</property>
-        <property name="orientation">vertical</property>
-        <child>
-          <object class="GtkLabel" id="label: storage">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_top">8</property>
-            <property name="xalign">0</property>
-            <property name="xpad">4</property>
-            <property name="ypad">6</property>
-            <property name="label" translatable="yes">Storage</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkGrid" id="grid3">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <child>
-              <object class="GtkLabel" id="label: sync">
-                <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">_Download mail</property>
-                <property name="use_underline">True</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkComboBoxText" id="combo: storage">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="active">0</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</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>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="fill">True</property>
-        <property name="position">4</property>
-      </packing>
-    </child>
-    <child>
       <object class="GtkBox" id="composer container">
         <property name="can_focus">False</property>
         <property name="margin_bottom">10</property>
@@ -1014,5 +940,79 @@
         <property name="position">4</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkBox" id="storage container">
+        <property name="can_focus">False</property>
+        <property name="margin_bottom">10</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel" id="label: storage">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_top">8</property>
+            <property name="xalign">0</property>
+            <property name="xpad">4</property>
+            <property name="ypad">6</property>
+            <property name="label" translatable="yes">Storage</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkLabel" id="label: sync">
+                <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">_Download mail</property>
+                <property name="use_underline">True</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="combo: storage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="active">0</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</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>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">4</property>
+      </packing>
+    </child>
   </object>
 </interface>


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