[geary/wip/714104-refine-account-dialog] Save account config to disk when it changes



commit 01ac9df81a2f9dac13b96b1c688cf3de07673272
Author: Michael Gratton <mike vee net>
Date:   Sun Dec 9 19:14:35 2018 +1100

    Save account config to disk when it changes

 src/client/accounts/accounts-manager.vala    | 25 +++++++++++++++++++++++++
 src/client/application/geary-controller.vala | 17 -----------------
 2 files changed, 25 insertions(+), 17 deletions(-)
---
diff --git a/src/client/accounts/accounts-manager.vala b/src/client/accounts/accounts-manager.vala
index e9dc390d..be2db840 100644
--- a/src/client/accounts/accounts-manager.vala
+++ b/src/client/accounts/accounts-manager.vala
@@ -403,6 +403,7 @@ public class Accounts.Manager : GLib.Object {
         throws GLib.Error {
         this.accounts.unset(account.id);
         this.removed.add(account);
+        account.changed.disconnect(on_account_changed);
         yield save_account(account, cancellable);
         account_removed(account);
     }
@@ -434,6 +435,9 @@ public class Accounts.Manager : GLib.Object {
         }
     }
 
+    /**
+     * Saves an account's configuration data to disk.
+     */
     public async void save_account(Geary.AccountInformation info,
                                    GLib.Cancellable? cancellable)
         throws GLib.Error {
@@ -757,6 +761,7 @@ public class Accounts.Manager : GLib.Object {
         bool ret = false;
         if (was_added) {
             account_added(state.account, state.status);
+            account.changed.connect(on_account_changed);
             ret = true;
         } else if (state.status != existing_status) {
             account_status_changed(state.account, state.status);
@@ -774,6 +779,7 @@ public class Accounts.Manager : GLib.Object {
         bool ret = false;
         if (was_added) {
             account_added(state.account, state.status);
+            account.changed.connect(on_account_changed);
             ret = true;
         } else if (state.status != existing_status) {
             account_status_changed(state.account, state.status);
@@ -953,6 +959,25 @@ public class Accounts.Manager : GLib.Object {
         }
     }
 
+    private void on_account_changed(Geary.AccountInformation account) {
+        this.save_account.begin(
+            account, null,
+            (obj, res) => {
+                try {
+                    this.save_account.end(res);
+                } catch (GLib.Error err) {
+                    report_problem(
+                        new Geary.AccountProblemReport(
+                            Geary.ProblemType.GENERIC_ERROR,
+                            account,
+                            err
+                        )
+                    );
+                }
+            }
+        );
+    }
+
 }
 
 /**
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 38b937e0..46c9b850 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1461,23 +1461,6 @@ public class GearyController : Geary.BaseObject {
                 folder, this.accounts.get(info).cancellable
             );
         }
-
-        this.account_manager.save_account.begin(
-            info, null,
-            (obj, res) => {
-                try {
-                    this.account_manager.save_account.end(res);
-                } catch (GLib.Error err) {
-                    report_problem(
-                        new Geary.AccountProblemReport(
-                            Geary.ProblemType.GENERIC_ERROR,
-                            info,
-                            err
-                        )
-                    );
-                }
-            }
-        );
     }
 
     private void on_folders_available_unavailable(Geary.Account account,


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