[geary/wip/714104-refine-account-dialog: 179/180] Tidy up Account and derived class's constructors



commit 47e06c7c83bc611fc13913a7c7fd8d9d41fb9e9a
Author: Michael Gratton <mike vee net>
Date:   Sun Nov 18 23:18:21 2018 +1100

    Tidy up Account and derived class's constructors
    
    Get the account's id (renamed fron "name") from the account's config and
    construct the id internally. Construct the ImapDB.Account instance
    internally as well since it doesn't require any input from the engine.

 src/engine/api/geary-account.vala                  | 16 +++++---
 src/engine/api/geary-engine.vala                   | 47 +++++++---------------
 .../gmail/imap-engine-gmail-account.vala           |  6 +--
 .../imap-engine/imap-engine-generic-account.vala   | 24 +++++------
 .../other/imap-engine-other-account.vala           |  9 ++---
 .../outlook/imap-engine-outlook-account.vala       |  6 +--
 .../yahoo/imap-engine-yahoo-account.vala           |  6 +--
 test/engine/api/geary-account-mock.vala            | 12 ++----
 test/engine/app/app-conversation-monitor-test.vala |  2 +-
 .../engine/imap-engine/account-processor-test.vala |  2 +-
 10 files changed, 53 insertions(+), 77 deletions(-)
---
diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala
index 42f8323c..c471a79e 100644
--- a/src/engine/api/geary-account.vala
+++ b/src/engine/api/geary-account.vala
@@ -48,6 +48,9 @@ public abstract class Geary.Account : BaseObject {
     public Geary.ProgressMonitor opening_monitor { get; protected set; }
     public Geary.ProgressMonitor sending_monitor { get; protected set; }
 
+    protected string id { get; private set; }
+
+
     public signal void opened();
     
     public signal void closed();
@@ -157,12 +160,13 @@ public abstract class Geary.Account : BaseObject {
      */
     public signal void email_flags_changed(Geary.Folder folder,
         Gee.Map<Geary.EmailIdentifier, Geary.EmailFlags> map);
-    
-    private string name;
-    
-    protected Account(string name, AccountInformation information) {
-        this.name = name;
+
+
+    protected Account(AccountInformation information) {
         this.information = information;
+        this.id = "%s[%s]".printf(
+            information.id, information.service_provider.to_value()
+        );
     }
 
     /**
@@ -370,7 +374,7 @@ public abstract class Geary.Account : BaseObject {
      * Used only for debugging.  Should not be used for user-visible strings.
      */
     public virtual string to_string() {
-        return name;
+        return this.id;
     }
 
     /**
diff --git a/src/engine/api/geary-engine.vala b/src/engine/api/geary-engine.vala
index 9e20dd58..e540c12c 100644
--- a/src/engine/api/geary-engine.vala
+++ b/src/engine/api/geary-engine.vala
@@ -354,46 +354,29 @@ public class Geary.Engine : BaseObject {
      * Creates a Geary.Account from a Geary.AccountInformation (which is what
      * other methods in this interface deal in).
      */
-    public Geary.Account get_account_instance(AccountInformation account_information)
+    public Geary.Account get_account_instance(AccountInformation config)
         throws Error {
         check_opened();
 
-        if (account_instances.has_key(account_information.id))
-            return account_instances.get(account_information.id);
+        if (account_instances.has_key(config.id))
+            return account_instances.get(config.id);
 
-        ImapDB.Account local_account = new ImapDB.Account(account_information);
         Geary.Account account;
-        switch (account_information.service_provider) {
+        switch (config.service_provider) {
             case ServiceProvider.GMAIL:
-                account = new ImapEngine.GmailAccount(
-                    "Gmail:%s".printf(account_information.id),
-                    account_information,
-                    local_account
-                );
+                account = new ImapEngine.GmailAccount(config);
             break;
 
             case ServiceProvider.YAHOO:
-                account = new ImapEngine.YahooAccount(
-                    "Yahoo:%s".printf(account_information.id),
-                    account_information,
-                    local_account
-                );
+                account = new ImapEngine.YahooAccount(config);
             break;
 
             case ServiceProvider.OUTLOOK:
-                account = new ImapEngine.OutlookAccount(
-                    "Outlook:%s".printf(account_information.id),
-                    account_information,
-                    local_account
-                );
+                account = new ImapEngine.OutlookAccount(config);
             break;
 
             case ServiceProvider.OTHER:
-                account = new ImapEngine.OtherAccount(
-                    "Other:%s".printf(account_information.id),
-                    account_information,
-                    local_account
-                );
+                account = new ImapEngine.OtherAccount(config);
             break;
 
             default:
@@ -401,13 +384,14 @@ public class Geary.Engine : BaseObject {
         }
 
         Endpoint imap = get_shared_endpoint(
-            account_information.service_provider, account_information.imap
+            config.service_provider, config.imap
         );
         Endpoint smtp = get_shared_endpoint(
-            account_information.service_provider, account_information.smtp);
+            config.service_provider, config.smtp
+        );
         account.set_endpoints(imap, smtp);
 
-        account_instances.set(account_information.id, account);
+        account_instances.set(config.id, account);
         return account;
     }
 
@@ -446,12 +430,11 @@ public class Geary.Engine : BaseObject {
         if (this.accounts.has_key(account.id)) {
             account.untrusted_host.disconnect(on_untrusted_host);
 
-            // Removal *MUST* be done in the following order:
-            // 1. Send the account-unavailable signal.
-            // Account will be removed client side.
+            // Send the account-unavailable signal, account will be
+            // removed client side.
             account_unavailable(account);
 
-            // 2. Remove the account data from the engine.
+            // Then remove the account data from the engine.
             this.accounts.unset(account.id);
             this.account_instances.unset(account.id);
         }
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 0fac7b4f..f8d45d63 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
@@ -32,10 +32,8 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
     }
 
 
-    public GmailAccount(string name,
-                        Geary.AccountInformation account_information,
-                        ImapDB.Account local) {
-        base(name, account_information, local);
+    public GmailAccount(Geary.AccountInformation config) {
+        base(config);
     }
 
     protected override Geary.SpecialFolderType[] get_supported_special_folders() {
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 4a675c01..cb3208a4 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -56,26 +56,23 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
 
     private uint authentication_failures = 0;
 
-
     private Gee.Map<Geary.SpecialFolderType, Gee.List<string>> special_search_names =
         new Gee.HashMap<Geary.SpecialFolderType, Gee.List<string>>();
 
 
-    public GenericAccount(string name,
-                          Geary.AccountInformation information,
-                          ImapDB.Account local) {
-        base(name, information);
-        this.imap = new Imap.ClientService(information, information.imap);
+    public GenericAccount(AccountInformation config) {
+        base(config);
+        this.local = new ImapDB.Account(config);
+        this.local.contacts_loaded.connect(() => { contacts_loaded(); });
+
+        this.imap = new Imap.ClientService(config, config.imap);
         this.imap.min_pool_size = IMAP_MIN_POOL_SIZE;
         this.imap.ready.connect(on_pool_session_ready);
         this.imap.connection_failed.connect(on_pool_connection_failed);
         this.imap.login_failed.connect(on_pool_login_failed);
 
-        this.local = local;
-        this.local.contacts_loaded.connect(() => { contacts_loaded(); });
-
         this.smtp = new Smtp.ClientService(
-            information, information.smtp, new SmtpOutboxFolder(this, this.local)
+            config, config.smtp, new SmtpOutboxFolder(this, this.local)
         );
         this.smtp.email_sent.connect(on_email_sent);
         this.smtp.report_problem.connect(notify_report_problem);
@@ -120,8 +117,11 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         this.processor.operation_error.connect(on_operation_error);
 
         try {
-            yield local.open_async(information.data_dir, Engine.instance.resource_dir.get_child("sql"),
-                cancellable);
+            yield this.local.open_async(
+                information.data_dir,
+                Engine.instance.resource_dir.get_child("sql"),
+                cancellable
+            );
         } catch (Error err) {
             // convert database-open errors
             if (err is DatabaseError.CORRUPT)
diff --git a/src/engine/imap-engine/other/imap-engine-other-account.vala 
b/src/engine/imap-engine/other/imap-engine-other-account.vala
index ba0f98ea..85ff844a 100644
--- a/src/engine/imap-engine/other/imap-engine-other-account.vala
+++ b/src/engine/imap-engine/other/imap-engine-other-account.vala
@@ -1,4 +1,5 @@
-/* Copyright 2016 Software Freedom Conservancy Inc.
+/*
+ * Copyright 2016 Software Freedom Conservancy Inc.
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later).  See the COPYING file in this distribution.
@@ -6,10 +7,8 @@
 
 private class Geary.ImapEngine.OtherAccount : Geary.ImapEngine.GenericAccount {
 
-    public OtherAccount(string name,
-                        AccountInformation account_information,
-                        ImapDB.Account local) {
-        base (name, account_information, local);
+    public OtherAccount(AccountInformation config) {
+        base(config);
     }
 
     protected override MinimalFolder new_folder(ImapDB.Folder local_folder) {
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 379a89b9..3a9f17ea 100644
--- a/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
+++ b/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
@@ -25,10 +25,8 @@ private class Geary.ImapEngine.OutlookAccount : Geary.ImapEngine.GenericAccount
     }
 
 
-    public OutlookAccount(string name,
-                          AccountInformation account_information,
-                          ImapDB.Account local) {
-        base(name, account_information, local);
+    public OutlookAccount(AccountInformation config) {
+        base(config);
     }
 
     protected override MinimalFolder new_folder(ImapDB.Folder local_folder) {
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 0ca75e39..ddd9f40b 100644
--- a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
+++ b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
@@ -27,10 +27,8 @@ private class Geary.ImapEngine.YahooAccount : Geary.ImapEngine.GenericAccount {
     }
 
 
-    public YahooAccount(string name,
-                        AccountInformation account_information,
-                        ImapDB.Account local) {
-        base(name, account_information, local);
+    public YahooAccount(AccountInformation config) {
+        base(config);
 
         if (special_map == null) {
             special_map = new Gee.HashMap<Geary.FolderPath, Geary.SpecialFolderType>();
diff --git a/test/engine/api/geary-account-mock.vala b/test/engine/api/geary-account-mock.vala
index c0a2c1b6..205a19be 100644
--- a/test/engine/api/geary-account-mock.vala
+++ b/test/engine/api/geary-account-mock.vala
@@ -66,14 +66,10 @@ public class Geary.MockAccount : Account, MockObject {
     }
 
 
-    public MockAccount(string name, AccountInformation information) {
-        base(name, information);
-        this._incoming = new MockClientService(
-            this.information, this.information.imap
-        );
-        this._outgoing = new MockClientService(
-            this.information, this.information.smtp
-        );
+    public MockAccount(AccountInformation config) {
+        base(config);
+        this._incoming = new MockClientService(config, config.imap);
+        this._outgoing = new MockClientService(config, config.smtp);
     }
 
     public override async void open_async(Cancellable? cancellable = null) throws Error {
diff --git a/test/engine/app/app-conversation-monitor-test.vala 
b/test/engine/app/app-conversation-monitor-test.vala
index a641a8fb..f99037fb 100644
--- a/test/engine/app/app-conversation-monitor-test.vala
+++ b/test/engine/app/app-conversation-monitor-test.vala
@@ -34,7 +34,7 @@ class Geary.App.ConversationMonitorTest : TestCase {
             new MockServiceInformation(),
             new MockServiceInformation()
         );
-        this.account = new MockAccount("test", this.account_info);
+        this.account = new MockAccount(this.account_info);
         this.base_folder = new MockFolder(
             this.account,
             null,
diff --git a/test/engine/imap-engine/account-processor-test.vala 
b/test/engine/imap-engine/account-processor-test.vala
index d89483de..8c6f649c 100644
--- a/test/engine/imap-engine/account-processor-test.vala
+++ b/test/engine/imap-engine/account-processor-test.vala
@@ -75,7 +75,7 @@ public class Geary.ImapEngine.AccountProcessorTest : TestCase {
             new MockServiceInformation(),
             new MockServiceInformation()
         );
-        this.account = new Geary.MockAccount("test-account", this.info);
+        this.account = new Geary.MockAccount(this.info);
 
         this.succeeded = 0;
         this.failed = 0;


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