[geary/wip/244-save-sent-ui-missing: 3/3] Add save sent email account option when needed



commit 45f53ef312b3bbde53fe24696a33a3f361ff862f
Author: Michael Gratton <mike vee net>
Date:   Wed Feb 20 14:07:13 2019 +1100

    Add save sent email account option when needed
    
    Save sent email was sadly forgotten during the account editor rewrite.
    This adds it back.
    
    Fixes #244

 .../accounts/accounts-editor-servers-pane.vala     | 75 +++++++++++++++++++++-
 1 file changed, 73 insertions(+), 2 deletions(-)
---
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 {
 


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