[geary/wip/imap-creds-721964] Add "use imap credentials" option to "other" acct



commit fc38172d10300783e21662b7a0714367aa14b7fe
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Feb 26 17:46:35 2014 -0800

    Add "use imap credentials" option to "other" acct
    
    This adds a "use imap credentials" checkbox to the "other" account
    creation dialog.  It's functional: it disables the smtp
    username/password fields when checked.  It's not perfect: it maybe
    should display the imap details in the disabled entries, or better yet
    just hide the entries altogether.

 src/client/accounts/add-edit-page.vala        |   54 +++++++++++++++++++-----
 src/engine/api/geary-account-information.vala |    9 ++++-
 ui/login.glade                                |   35 +++++++++++++---
 3 files changed, 79 insertions(+), 19 deletions(-)
---
diff --git a/src/client/accounts/add-edit-page.vala b/src/client/accounts/add-edit-page.vala
index cb333c0..69f9957 100644
--- a/src/client/accounts/add-edit-page.vala
+++ b/src/client/accounts/add-edit-page.vala
@@ -116,7 +116,12 @@ public class AddEditPage : Gtk.Box {
                 combo_smtp_encryption.active = Encryption.STARTTLS;
         }
     }
-
+    
+    public bool smtp_use_imap_credentials {
+        get { return check_smtp_use_imap_credentials.active; }
+        set { check_smtp_use_imap_credentials.active = value; }
+    }
+    
     public bool smtp_noauth {
         get { return check_smtp_noauth.active; }
         set { check_smtp_noauth.active = value; }
@@ -161,6 +166,7 @@ public class AddEditPage : Gtk.Box {
     private Gtk.Entry entry_smtp_username;
     private Gtk.Entry entry_smtp_password;
     private Gtk.ComboBox combo_smtp_encryption;
+    private Gtk.CheckButton check_smtp_use_imap_credentials;
     private Gtk.CheckButton check_smtp_noauth;
 
     private string smtp_username_store;
@@ -237,6 +243,7 @@ public class AddEditPage : Gtk.Box {
         entry_smtp_username = (Gtk.Entry) builder.get_object("entry: smtp username");
         entry_smtp_password = (Gtk.Entry) builder.get_object("entry: smtp password");
         combo_smtp_encryption = (Gtk.ComboBox) builder.get_object("combo: smtp encryption");
+        check_smtp_use_imap_credentials = (Gtk.CheckButton) builder.get_object("check: use imap 
credentials");
         check_smtp_noauth = (Gtk.CheckButton) builder.get_object("check: smtp no authentication");
 
         // Build list of service providers.
@@ -261,6 +268,8 @@ public class AddEditPage : Gtk.Box {
         entry_smtp_port.changed.connect(on_changed);
         entry_smtp_username.changed.connect(on_changed);
         entry_smtp_password.changed.connect(on_changed);
+        check_smtp_use_imap_credentials.toggled.connect(on_changed);
+        check_smtp_noauth.toggled.connect(on_changed);
         
         entry_email.changed.connect(on_email_changed);
         entry_password.changed.connect(on_password_changed);
@@ -268,7 +277,8 @@ public class AddEditPage : Gtk.Box {
         combo_imap_encryption.changed.connect(on_imap_encryption_changed);
         combo_smtp_encryption.changed.connect(on_smtp_encryption_changed);
         
-        check_smtp_noauth.toggled.connect(on_smtp_no_auth_changed);
+        check_smtp_use_imap_credentials.toggled.connect(on_smtp_auth_changed);
+        check_smtp_noauth.toggled.connect(on_smtp_auth_changed);
         
         entry_imap_port.insert_text.connect(on_port_insert_text);
         entry_smtp_port.insert_text.connect(on_port_insert_text);
@@ -300,6 +310,7 @@ public class AddEditPage : Gtk.Box {
             info.default_smtp_server_port,
             info.default_smtp_server_ssl,
             info.default_smtp_server_starttls,
+            info.default_smtp_use_imap_credentials,
             info.default_smtp_server_noauth,
             info.prefetch_period_days,
             result);
@@ -326,6 +337,7 @@ public class AddEditPage : Gtk.Box {
         uint16 initial_default_smtp_port = Geary.Smtp.ClientConnection.DEFAULT_PORT_SSL,
         bool initial_default_smtp_ssl = true,
         bool initial_default_smtp_starttls = false,
+        bool initial_default_smtp_use_imap_credentials = false,
         bool initial_default_smtp_noauth = false,
         int prefetch_period_days = Geary.AccountInformation.DEFAULT_PREFETCH_PERIOD_DAYS,
         Geary.Engine.ValidationResult result = Geary.Engine.ValidationResult.OK) {
@@ -357,6 +369,7 @@ public class AddEditPage : Gtk.Box {
         smtp_password = initial_smtp_password ?? "";
         smtp_ssl = initial_default_smtp_ssl;
         smtp_starttls = initial_default_smtp_starttls;
+        smtp_use_imap_credentials = initial_default_smtp_use_imap_credentials;
         smtp_noauth = initial_default_smtp_noauth;
         
         set_validation_result(result);
@@ -464,10 +477,12 @@ public class AddEditPage : Gtk.Box {
         edited_smtp_port = false;
     }
     
-    private void on_smtp_no_auth_changed() {
-        if (check_smtp_noauth.active) {
-            smtp_username_store = entry_smtp_username.text;
-            smtp_password_store = entry_smtp_password.text;
+    private void on_smtp_auth_changed() {
+        if (check_smtp_use_imap_credentials.active || check_smtp_noauth.active) {
+            if (!Geary.String.is_empty_or_whitespace(entry_smtp_username.text))
+                smtp_username_store = entry_smtp_username.text;
+            if (!Geary.String.is_empty_or_whitespace(entry_smtp_password.text))
+                smtp_password_store = entry_smtp_password.text;
             
             entry_smtp_username.text = "";
             entry_smtp_password.text = "";
@@ -475,8 +490,12 @@ public class AddEditPage : Gtk.Box {
             entry_smtp_username.sensitive = false;
             entry_smtp_password.sensitive = false;
         } else {
-            entry_smtp_username.text = smtp_username_store;
-            entry_smtp_password.text = smtp_password_store;
+            if (!Geary.String.is_empty_or_whitespace(smtp_username_store))
+                entry_smtp_username.text = smtp_username_store;
+            smtp_username_store = "";
+            if (!Geary.String.is_empty_or_whitespace(smtp_password_store))
+                entry_smtp_password.text = smtp_password_store;
+            smtp_password_store = "";
             
             entry_smtp_username.sensitive = true;
             entry_smtp_password.sensitive = true;
@@ -507,9 +526,11 @@ public class AddEditPage : Gtk.Box {
                     Geary.String.is_empty_or_whitespace(imap_username) ||
                     Geary.String.is_empty_or_whitespace(imap_password) ||
                     Geary.String.is_empty_or_whitespace(smtp_host) ||
-                    Geary.String.is_empty_or_whitespace(smtp_port.to_string()) ||
-                    Geary.String.is_empty_or_whitespace(smtp_username) && check_smtp_noauth.active == false 
||
-                    Geary.String.is_empty_or_whitespace(smtp_password) && check_smtp_noauth.active == false)
+                    Geary.String.is_empty_or_whitespace(smtp_port.to_string()))
+                    return false;
+                if ((Geary.String.is_empty_or_whitespace(smtp_username) ||
+                    Geary.String.is_empty_or_whitespace(smtp_password)) &&
+                    !(check_smtp_noauth.active || check_smtp_use_imap_credentials.active))
                     return false;
             break;
             
@@ -530,7 +551,9 @@ public class AddEditPage : Gtk.Box {
         fix_credentials_for_supported_provider();
         
         Geary.Credentials imap_credentials = new Geary.Credentials(imap_username.strip(), 
imap_password.strip());
-        Geary.Credentials smtp_credentials = new Geary.Credentials(smtp_username.strip(), 
smtp_password.strip());
+        Geary.Credentials smtp_credentials = new Geary.Credentials(
+            (smtp_use_imap_credentials ? imap_username.strip() : smtp_username.strip()),
+            (smtp_use_imap_credentials ? imap_password.strip() : smtp_password.strip()));
         
         try {
             Geary.AccountInformation original_account = 
Geary.Engine.instance.get_accounts().get(email_address);
@@ -563,6 +586,7 @@ public class AddEditPage : Gtk.Box {
         account_information.default_smtp_server_port = smtp_port;
         account_information.default_smtp_server_ssl = smtp_ssl;
         account_information.default_smtp_server_starttls = smtp_starttls;
+        account_information.default_smtp_use_imap_credentials = smtp_use_imap_credentials;
         account_information.default_smtp_server_noauth = smtp_noauth;
         account_information.prefetch_period_days = get_storage_length();
         
@@ -619,10 +643,15 @@ public class AddEditPage : Gtk.Box {
             entry_smtp_port.sensitive =
             entry_smtp_username.sensitive =
             combo_smtp_encryption.sensitive =
+            check_smtp_use_imap_credentials.sensitive =
             check_smtp_noauth.sensitive =
                 mode != PageMode.EDIT;
         
         if (smtp_noauth) {
+            check_smtp_use_imap_credentials.sensitive = false;
+            entry_smtp_username.sensitive = false;
+            entry_smtp_password.sensitive = false;
+        } else if (smtp_use_imap_credentials) {
             entry_smtp_username.sensitive = false;
             entry_smtp_password.sensitive = false;
         }
@@ -714,6 +743,7 @@ public class AddEditPage : Gtk.Box {
         
         entry_smtp_host.sensitive = sensitive;
         entry_smtp_port.sensitive = sensitive;
+        check_smtp_use_imap_credentials.sensitive = sensitive;
         entry_smtp_username.sensitive = sensitive;
         entry_smtp_password.sensitive = sensitive;
         combo_smtp_encryption.sensitive = sensitive;
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 6955ed1..4b8a80e 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -25,6 +25,7 @@ public class Geary.AccountInformation : BaseObject {
     private const string SMTP_PORT = "smtp_port";
     private const string SMTP_SSL = "smtp_ssl";
     private const string SMTP_STARTTLS = "smtp_starttls";
+    private const string SMTP_USE_IMAP_CREDENTIALS = "smtp_use_imap_credentials";
     private const string SMTP_NOAUTH = "smtp_noauth";
     private const string SAVE_SENT_MAIL_KEY = "save_sent_mail";
     private const string DRAFTS_FOLDER_KEY = "drafts_folder";
@@ -83,6 +84,7 @@ public class Geary.AccountInformation : BaseObject {
     public uint16 default_smtp_server_port  { get; set; }
     public bool default_smtp_server_ssl  { get; set; }
     public bool default_smtp_server_starttls { get; set; }
+    public bool default_smtp_use_imap_credentials { get; set; }
     public bool default_smtp_server_noauth { get; set; }
     
     public Geary.FolderPath? drafts_folder_path { get; set; default = null; }
@@ -144,11 +146,14 @@ public class Geary.AccountInformation : BaseObject {
                     Geary.Smtp.ClientConnection.DEFAULT_PORT_SSL);
                 default_smtp_server_ssl = get_bool_value(key_file, GROUP, SMTP_SSL, true);
                 default_smtp_server_starttls = get_bool_value(key_file, GROUP, SMTP_STARTTLS, false);
+                default_smtp_use_imap_credentials = get_bool_value(key_file, GROUP, 
SMTP_USE_IMAP_CREDENTIALS, false);
                 default_smtp_server_noauth = get_bool_value(key_file, GROUP, SMTP_NOAUTH, false);
                 
                 if (default_smtp_server_noauth) {
-                    // Make sure the SMTP credentials are unset.
                     smtp_credentials = null;
+                } else if (default_smtp_use_imap_credentials) {
+                    smtp_credentials.user = imap_credentials.user;
+                    smtp_credentials.pass = imap_credentials.pass;
                 }
             }
             
@@ -180,6 +185,7 @@ public class Geary.AccountInformation : BaseObject {
         default_smtp_server_port = from.default_smtp_server_port;
         default_smtp_server_ssl = from.default_smtp_server_ssl;
         default_smtp_server_starttls = from.default_smtp_server_starttls;
+        default_smtp_use_imap_credentials = from.default_smtp_use_imap_credentials;
         default_smtp_server_noauth = from.default_smtp_server_noauth;
         imap_credentials = from.imap_credentials;
         imap_remember_password = from.imap_remember_password;
@@ -586,6 +592,7 @@ public class Geary.AccountInformation : BaseObject {
             key_file.set_integer(GROUP, SMTP_PORT, default_smtp_server_port);
             key_file.set_boolean(GROUP, SMTP_SSL, default_smtp_server_ssl);
             key_file.set_boolean(GROUP, SMTP_STARTTLS, default_smtp_server_starttls);
+            key_file.set_boolean(GROUP, SMTP_USE_IMAP_CREDENTIALS, default_smtp_use_imap_credentials);
             key_file.set_boolean(GROUP, SMTP_NOAUTH, default_smtp_server_noauth);
         }
         
diff --git a/ui/login.glade b/ui/login.glade
index 9a62f67..9b87d81 100644
--- a/ui/login.glade
+++ b/ui/login.glade
@@ -259,12 +259,6 @@
           </packing>
         </child>
         <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
           <object class="GtkCheckButton" id="check: save_sent_mail">
             <property name="label" translatable="yes">_Save sent mail</property>
             <property name="visible">True</property>
@@ -282,6 +276,12 @@
             <property name="height">1</property>
           </packing>
         </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
       </object>
       <packing>
         <property name="expand">False</property>
@@ -689,6 +689,23 @@
               </object>
               <packing>
                 <property name="left_attach">1</property>
+                <property name="top_attach">15</property>
+                <property name="width">2</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="check: use imap credentials">
+                <property name="label" translatable="yes">Use IMAP cre_dentials</property>
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
                 <property name="top_attach">14</property>
                 <property name="width">2</property>
                 <property name="height">1</property>
@@ -757,6 +774,12 @@
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </object>
         </child>
       </object>


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