[geary/geary-0.13] Merge branch 'wip/244-save-sent-ui-missing' into 'master'



commit a5e7f928b89f75748dd08ecd0b358d5626cc9d91
Author: Michael Gratton <mike vee net>
Date:   Wed Feb 20 03:31:44 2019 +0000

    Merge branch 'wip/244-save-sent-ui-missing' into 'master'
    
    Add save sent email account pref UI back
    
    Closes #244
    
    See merge request GNOME/geary!120
    
    (cherry picked from commit 5e886534b1847b23df5081c9a0cef4bd1aac1142)
    
    54752902 Allow both accounts and services to have provider-specific defaults
    4d57ab9b Default Outlook accounts to not save sent mail
    45f53ef3 Add save sent email account option when needed

 src/client/accounts/accounts-editor-add-pane.vala  | 13 ++--
 .../accounts/accounts-editor-servers-pane.vala     | 75 +++++++++++++++++++++-
 src/client/accounts/accounts-manager.vala          |  3 -
 src/engine/api/geary-account-information.vala      | 49 ++++++--------
 src/engine/api/geary-service-information.vala      |  7 +-
 src/engine/api/geary-service-provider.vala         | 17 ++++-
 .../gmail/imap-engine-gmail-account.vala           |  4 ++
 .../outlook/imap-engine-outlook-account.vala       |  4 ++
 .../yahoo/imap-engine-yahoo-account.vala           |  4 ++
 .../engine/api/geary-account-information-test.vala | 36 +++++++++++
 10 files changed, 166 insertions(+), 46 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-add-pane.vala 
b/src/client/accounts/accounts-editor-add-pane.vala
index 75789bd1..6c9a61c3 100644
--- a/src/client/accounts/accounts-editor-add-pane.vala
+++ b/src/client/accounts/accounts-editor-add-pane.vala
@@ -309,8 +309,9 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
     }
 
     private Geary.ServiceInformation new_imap_service() {
-        Geary.ServiceInformation service =
-            new Geary.ServiceInformation(Geary.Protocol.IMAP);
+        Geary.ServiceInformation service = new Geary.ServiceInformation(
+            Geary.Protocol.IMAP, this.provider
+        );
 
         if (this.provider == Geary.ServiceProvider.OTHER) {
             service.credentials = new Geary.Credentials(
@@ -331,7 +332,6 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
                 service.port = service.get_default_port();
             }
         } else {
-            this.provider.setup_service(service);
             service.credentials = new Geary.Credentials(
                 Geary.Credentials.Method.PASSWORD,
                 this.email.value.get_text().strip(),
@@ -343,8 +343,9 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
     }
 
     private Geary.ServiceInformation new_smtp_service() {
-        Geary.ServiceInformation service =
-            new Geary.ServiceInformation(Geary.Protocol.SMTP);
+        Geary.ServiceInformation service = new Geary.ServiceInformation(
+            Geary.Protocol.SMTP, this.provider
+        );
 
         if (this.provider == Geary.ServiceProvider.OTHER) {
             service.credentials_requirement = this.smtp_auth.value.source;
@@ -369,8 +370,6 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
             if (service.port == 0) {
                 service.port = service.get_default_port();
             }
-        } else {
-            this.provider.setup_service(service);
         }
 
         return service;
diff --git a/src/client/accounts/accounts-editor-servers-pane.vala 
b/src/client/accounts/accounts-editor-servers-pane.vala
index db6f2af9..fe0ba338 100644
--- a/src/client/accounts/accounts-editor-servers-pane.vala
+++ b/src/client/accounts/accounts-editor-servers-pane.vala
@@ -77,6 +77,7 @@ internal class Accounts.EditorServersPane :
     private Gtk.Spinner apply_spinner;
 
     private SaveDraftsRow save_drafts;
+    private SaveSentRow save_sent;
 
     private ServiceLoginRow incoming_login;
     private ServicePasswordRow incoming_password;
@@ -118,6 +119,16 @@ internal class Accounts.EditorServersPane :
         );
         add_row(this.details_list, this.save_drafts);
 
+        this.save_sent = new SaveSentRow(
+            this.account, this.commands, this.op_cancellable
+        );
+        switch (account.service_provider) {
+        case YAHOO:
+        case OTHER:
+            add_row(this.details_list, this.save_sent);
+            break;
+        }
+
         // Receiving
 
         this.receiving_list.set_header_func(Editor.seperator_headers);
@@ -263,6 +274,10 @@ internal class Accounts.EditorServersPane :
                 has_changed = true;
             }
 
+            if (this.save_sent.value_changed) {
+                has_changed = true;
+            }
+
             if (has_changed) {
                 this.account.changed();
             }
@@ -274,9 +289,10 @@ internal class Accounts.EditorServersPane :
             // change something to re-enable it
             this.apply_button.set_sensitive(true);
 
-            // Undo save_drafts manually since it would have been
-            // updated already by the command
+            // Undo these manually since it would have been updated
+            // already by the command
             this.account.save_drafts = this.save_drafts.initial_value;
+            this.account.save_sent = this.save_sent.initial_value;
         }
     }
 
@@ -626,6 +642,61 @@ private class Accounts.SaveDraftsRow :
 }
 
 
+private class Accounts.SaveSentRow :
+    AccountRow<EditorServersPane,Gtk.Switch> {
+
+
+    public bool value_changed {
+        get { return this.initial_value != this.value.state; }
+    }
+    public bool initial_value { get; private set; }
+
+    private Application.CommandStack commands;
+    private GLib.Cancellable? cancellable;
+
+
+    public SaveSentRow(Geary.AccountInformation account,
+                       Application.CommandStack commands,
+                       GLib.Cancellable? cancellable) {
+        Gtk.Switch value = new Gtk.Switch();
+        base(
+            account,
+            // Translators: This label describes an account
+            // preference.
+            _("Save sent email on server"),
+            value
+        );
+        update();
+        this.commands = commands;
+        this.cancellable = cancellable;
+        this.activatable = false;
+        this.initial_value = this.account.save_sent;
+        this.account.notify["save-sent"].connect(on_account_changed);
+        this.value.notify["active"].connect(on_activate);
+    }
+
+    public override void update() {
+        this.value.state = this.account.save_sent;
+    }
+
+    private void on_activate() {
+        if (this.value.state != this.account.save_sent) {
+            this.commands.execute.begin(
+                new Application.PropertyCommand<bool>(
+                    this.account, "save_sent", this.value.state
+                ),
+                this.cancellable
+            );
+        }
+    }
+
+    private void on_account_changed() {
+        update();
+    }
+
+}
+
+
 private class Accounts.ServiceHostRow :
     ServiceRow<EditorServersPane,Gtk.Entry>, ValidatingRow {
 
diff --git a/src/client/accounts/accounts-manager.vala b/src/client/accounts/accounts-manager.vala
index 8eb040db..426cb28a 100644
--- a/src/client/accounts/accounts-manager.vala
+++ b/src/client/accounts/accounts-manager.vala
@@ -602,9 +602,6 @@ public class Accounts.Manager : GLib.Object {
             } catch (GLib.KeyFileError err) {
                 throw new ConfigError.SYNTAX(err.message);
             }
-            account.service_provider.setup_service(account.incoming);
-            account.service_provider.setup_service(account.outgoing);
-
         } else {
             account.service_label = goa_mediator.get_service_label();
             try {
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 35b4a5fd..a3e68016 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -127,18 +127,18 @@ public class Geary.AccountInformation : BaseObject {
         get; set; default = DEFAULT_PREFETCH_PERIOD_DAYS;
     }
 
-    /**
-     * Specifies if the user has requested that sent mail be saved.
-     *
-     * Note that Geary will only actively push sent mail when this AND
-     * {@link allow_save_sent} are both true.
-     */
+    /** Specifies if sent email should be saved to the Sent folder. */
     public bool save_sent {
-        // If we aren't allowed to save sent mail due to account type, we want
-        // to return true here on the assumption that the account will save
-        // sent mail for us, and thus the user can't disable sent mail from
-        // being saved.
-        get { return (allow_save_sent() ? this._save_sent : true); }
+        get {
+            bool save = _save_sent;
+            switch (this.service_provider) {
+            case GMAIL:
+            case OUTLOOK:
+                save = false;
+                break;
+            }
+            return save;
+        }
         set { this._save_sent = value; }
     }
     private bool _save_sent = true;
@@ -152,16 +152,10 @@ public class Geary.AccountInformation : BaseObject {
     public CredentialsMediator mediator { get; private set; }
 
     /* Incoming email service configuration. */
-    public ServiceInformation incoming {
-        get; set;
-        default = new ServiceInformation(Protocol.IMAP);
-    }
+    public ServiceInformation incoming { get; set; }
 
     /* Outgoing email service configuration. */
-    public ServiceInformation outgoing {
-        get; set;
-        default = new ServiceInformation(Protocol.SMTP);
-    }
+    public ServiceInformation outgoing { get; set; }
 
     /** A lock that can be used to ensure saving is serialised. */
     public Nonblocking.Mutex write_lock {
@@ -253,6 +247,11 @@ public class Geary.AccountInformation : BaseObject {
         this.id = id;
         this.mediator = mediator;
         this.service_provider = provider;
+        this.incoming = new ServiceInformation(Protocol.IMAP, provider);
+        this.outgoing = new ServiceInformation(Protocol.SMTP, provider);
+
+        provider.set_account_defaults(this);
+
         append_sender(primary_mailbox);
     }
 
@@ -356,18 +355,6 @@ public class Geary.AccountInformation : BaseObject {
         return removed;
     }
 
-    /**
-     * Determines if {@link save_sent} property can be set.
-     *
-     * If not, that property will always be true and setting it will
-     * be ignored.
-     */
-    public bool allow_save_sent() {
-        // We should never push mail to Gmail, since its servers
-        // automatically push sent mail to the sent mail folder.
-        return this.service_provider != ServiceProvider.GMAIL;
-    }
-
     /**
      * Returns the configured path for a special folder type.
      *
diff --git a/src/engine/api/geary-service-information.vala b/src/engine/api/geary-service-information.vala
index e0df4abf..2028e040 100644
--- a/src/engine/api/geary-service-information.vala
+++ b/src/engine/api/geary-service-information.vala
@@ -116,7 +116,7 @@ public class Geary.ServiceInformation : GLib.Object {
     /**
      * Constructs a new configuration for a specific service.
      */
-    public ServiceInformation(Protocol proto) {
+    public ServiceInformation(Protocol proto, ServiceProvider provider) {
         this.protocol = proto;
         // Prefer TLS by RFC 8314, but use START_TLS for SMTP for the
         // moment while its still more widely deployed.
@@ -126,13 +126,16 @@ public class Geary.ServiceInformation : GLib.Object {
         this.credentials_requirement = (proto == Protocol.SMTP)
             ? Credentials.Requirement.USE_INCOMING
             : Credentials.Requirement.CUSTOM;
+
+        provider.set_service_defaults(this);
     }
 
     /**
      * Constructs a copy of the given service configuration.
      */
     public ServiceInformation.copy(ServiceInformation other) {
-        this(other.protocol);
+        // Use OTHER here to get blank defaults
+        this(other.protocol, ServiceInformation.OTHER);
         this.host = other.host;
         this.port = other.port;
         this.transport_security = other.transport_security;
diff --git a/src/engine/api/geary-service-provider.vala b/src/engine/api/geary-service-provider.vala
index 540526a6..4d6fd943 100644
--- a/src/engine/api/geary-service-provider.vala
+++ b/src/engine/api/geary-service-provider.vala
@@ -29,7 +29,22 @@ public enum Geary.ServiceProvider {
         );
     }
 
-    public void setup_service(ServiceInformation service) {
+
+    internal void set_account_defaults(AccountInformation service) {
+        switch (this) {
+        case GMAIL:
+            ImapEngine.GmailAccount.setup_account(service);
+            break;
+        case YAHOO:
+            ImapEngine.YahooAccount.setup_account(service);
+            break;
+        case OUTLOOK:
+            ImapEngine.OutlookAccount.setup_account(service);
+            break;
+        }
+    }
+
+    internal void set_service_defaults(ServiceInformation service) {
         switch (this) {
         case GMAIL:
             ImapEngine.GmailAccount.setup_service(service);
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
index f246e5b6..8e7b3acc 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
@@ -17,6 +17,10 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
     };
 
 
+    public static void setup_account(AccountInformation account) {
+        account.save_sent = false;
+    }
+
     public static void setup_service(ServiceInformation service) {
         switch (service.protocol) {
         case Protocol.IMAP:
diff --git a/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala 
b/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
index 8d7e162d..dca134d6 100644
--- a/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
+++ b/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
@@ -9,6 +9,10 @@
 private class Geary.ImapEngine.OutlookAccount : Geary.ImapEngine.GenericAccount {
 
 
+    public static void setup_account(AccountInformation account) {
+        account.save_sent = false;
+    }
+
     public static void setup_service(ServiceInformation service) {
         switch (service.protocol) {
         case Protocol.IMAP:
diff --git a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala 
b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
index a754bff0..edd24a3d 100644
--- a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
+++ b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
@@ -9,6 +9,10 @@
 private class Geary.ImapEngine.YahooAccount : Geary.ImapEngine.GenericAccount {
 
 
+    public static void setup_account(AccountInformation account) {
+        // noop
+    }
+
     public static void setup_service(ServiceInformation service) {
         switch (service.protocol) {
         case Protocol.IMAP:
diff --git a/test/engine/api/geary-account-information-test.vala 
b/test/engine/api/geary-account-information-test.vala
index 6ec75420..1323ffcf 100644
--- a/test/engine/api/geary-account-information-test.vala
+++ b/test/engine/api/geary-account-information-test.vala
@@ -10,9 +10,45 @@ class Geary.AccountInformationTest : TestCase {
 
     public AccountInformationTest() {
         base("Geary.AccountInformationTest");
+        add_test("test_save_sent_defaults", test_save_sent_defaults);
         add_test("test_sender_mailboxes", test_sender_mailboxes);
     }
 
+    public void test_save_sent_defaults() throws GLib.Error {
+        assert_true(
+            new AccountInformation(
+                "test",
+                ServiceProvider.OTHER,
+                new MockCredentialsMediator(),
+                new RFC822.MailboxAddress(null, "test1 example com")
+            ).save_sent
+        );
+        assert_false(
+            new AccountInformation(
+                "test",
+                ServiceProvider.GMAIL,
+                new MockCredentialsMediator(),
+                new RFC822.MailboxAddress(null, "test1 example com")
+            ).save_sent
+        );
+        assert_false(
+            new AccountInformation(
+                "test",
+                ServiceProvider.OUTLOOK,
+                new MockCredentialsMediator(),
+                new RFC822.MailboxAddress(null, "test1 example com")
+            ).save_sent
+        );
+        assert_true(
+            new AccountInformation(
+                "test",
+                ServiceProvider.YAHOO,
+                new MockCredentialsMediator(),
+                new RFC822.MailboxAddress(null, "test1 example com")
+            ).save_sent
+        );
+    }
+
     public void test_sender_mailboxes() throws GLib.Error {
         AccountInformation test = new AccountInformation(
             "test",


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