[geary/wip/789924-network-transition-redux: 7/10] Make GenericAccount's local and remote properties internal.



commit 59a52bde3e7fb3e18330a09faeb453e1a51aeef5
Author: Michael James Gratton <mike vee net>
Date:   Fri Jan 19 08:44:08 2018 +1100

    Make GenericAccount's local and remote properties internal.
    
    This allows removing MinimalFolder's copy of the account's Imap.Account
    since it can access it from the account, and will allow the remote to
    instance to change as the server becomes available/unavailable.
    
    * src/engine/imap-engine/imap-engine-generic-account.vala
      (GenericAccount): Make both remote and local properties internally
      accessible.
    
    * src/engine/imap-engine/imap-engine-minimal-folder.vala (MinimalFolder):
      Remove remote property and ctor arg, update call sites to access it from
      via GenericAccount instead. Update subclasses and ctor call sites.

 .../gmail/imap-engine-gmail-account.vala           |   13 ++-----
 .../gmail/imap-engine-gmail-all-mail-folder.vala   |    9 +++--
 .../gmail/imap-engine-gmail-drafts-folder.vala     |   11 +++---
 .../gmail/imap-engine-gmail-folder.vala            |    9 +++--
 .../gmail/imap-engine-gmail-spam-trash-folder.vala |    7 ++--
 .../imap-engine/imap-engine-generic-account.vala   |   25 ++++++---------
 .../imap-engine/imap-engine-generic-folder.vala    |    7 ++--
 .../imap-engine/imap-engine-minimal-folder.vala    |   33 ++++++++-----------
 .../other/imap-engine-other-account.vala           |    2 +-
 .../other/imap-engine-other-folder.vala            |    7 ++--
 .../outlook/imap-engine-outlook-account.vala       |    4 +-
 .../outlook/imap-engine-outlook-drafts-folder.vala |    7 ++--
 .../outlook/imap-engine-outlook-folder.vala        |    7 ++--
 .../yahoo/imap-engine-yahoo-account.vala           |    2 +-
 .../yahoo/imap-engine-yahoo-folder.vala            |    7 ++--
 15 files changed, 72 insertions(+), 78 deletions(-)
---
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 bdebded..971b2cb 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
@@ -49,21 +49,17 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
 
         switch (special_folder_type) {
             case SpecialFolderType.ALL_MAIL:
-                return new GmailAllMailFolder(this, this.remote, local_folder,
-                    special_folder_type);
+                return new GmailAllMailFolder(this, local_folder, special_folder_type);
 
             case SpecialFolderType.DRAFTS:
-                return new GmailDraftsFolder(this, this.remote, local_folder,
-                    special_folder_type);
+                return new GmailDraftsFolder(this, local_folder, special_folder_type);
 
             case SpecialFolderType.SPAM:
             case SpecialFolderType.TRASH:
-                return new GmailSpamTrashFolder(this, this.remote, local_folder,
-                    special_folder_type);
+                return new GmailSpamTrashFolder(this, local_folder, special_folder_type);
 
             default:
-                return new GmailFolder(this, this.remote, local_folder,
-                    special_folder_type);
+                return new GmailFolder(this, local_folder, special_folder_type);
         }
     }
 
@@ -71,4 +67,3 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
         return new GmailSearchFolder(this);
     }
 }
-
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-all-mail-folder.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-all-mail-folder.vala
index 9f9fb8b..5612fcd 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-all-mail-folder.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-all-mail-folder.vala
@@ -9,11 +9,12 @@
  */
 
 private class Geary.ImapEngine.GmailAllMailFolder : MinimalFolder, FolderSupport.Remove {
-    public GmailAllMailFolder(GmailAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public GmailAllMailFolder(GmailAccount account,
+                              ImapDB.Folder local_folder,
+                              SpecialFolderType special_folder_type) {
+        base(account, local_folder, special_folder_type);
     }
-    
+
     public async void remove_email_async(Gee.List<Geary.EmailIdentifier> email_ids,
         Cancellable? cancellable = null) throws Error {
         yield GmailFolder.true_remove_email_async(this, email_ids, cancellable);
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-drafts-folder.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-drafts-folder.vala
index 7b56ab9..e72643a 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-drafts-folder.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-drafts-folder.vala
@@ -11,17 +11,18 @@
 
 private class Geary.ImapEngine.GmailDraftsFolder : MinimalFolder, FolderSupport.Create,
     FolderSupport.Remove {
-    public GmailDraftsFolder(GmailAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public GmailDraftsFolder(GmailAccount account,
+                             ImapDB.Folder local_folder,
+                             SpecialFolderType special_folder_type) {
+        base (account, local_folder, special_folder_type);
     }
-    
+
     public new async Geary.EmailIdentifier? create_email_async(
         RFC822.Message rfc822, Geary.EmailFlags? flags, DateTime? date_received,
         Geary.EmailIdentifier? id, Cancellable? cancellable = null) throws Error {
         return yield base.create_email_async(rfc822, flags, date_received, id, cancellable);
     }
-    
+
     public async void remove_email_async(Gee.List<Geary.EmailIdentifier> email_ids,
         Cancellable? cancellable = null) throws Error {
         yield GmailFolder.true_remove_email_async(this, email_ids, cancellable);
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala
index cca2e00..ccaa582 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala
@@ -6,11 +6,12 @@
 
 private class Geary.ImapEngine.GmailFolder : MinimalFolder, FolderSupport.Archive,
     FolderSupport.Create, FolderSupport.Remove {
-    public GmailFolder(GmailAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public GmailFolder(GmailAccount account,
+                       ImapDB.Folder local_folder,
+                       SpecialFolderType special_folder_type) {
+        base (account, local_folder, special_folder_type);
     }
-    
+
     public new async Geary.EmailIdentifier? create_email_async(
         RFC822.Message rfc822, Geary.EmailFlags? flags, DateTime? date_received,
         Geary.EmailIdentifier? id, Cancellable? cancellable = null) throws Error {
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-spam-trash-folder.vala 
b/src/engine/imap-engine/gmail/imap-engine-gmail-spam-trash-folder.vala
index ec8461f..aa6ce5d 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-spam-trash-folder.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-spam-trash-folder.vala
@@ -11,9 +11,10 @@
 
 private class Geary.ImapEngine.GmailSpamTrashFolder : MinimalFolder, FolderSupport.Remove,
     FolderSupport.Empty {
-    public GmailSpamTrashFolder(GmailAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public GmailSpamTrashFolder(GmailAccount account,
+                                ImapDB.Folder local_folder,
+                                SpecialFolderType special_folder_type) {
+        base (account, local_folder, special_folder_type);
     }
 
     public async void remove_email_async(Gee.List<Geary.EmailIdentifier> email_ids,
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index a48ecd9..03816c8 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -1,6 +1,6 @@
 /*
  * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2017 Michael Gratton <mike vee net>
+ * Copyright 2017-2018 Michael Gratton <mike vee net>.
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later).  See the COPYING file in this distribution.
@@ -24,8 +24,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     private static Geary.FolderPath? outbox_path = null;
     private static Geary.FolderPath? search_path = null;
 
-    protected Imap.Account remote { get; private set; }
-    protected ImapDB.Account local { get; private set; }
+    internal Imap.Account remote { get; private set; }
+    internal ImapDB.Account local { get; private set; }
 
     private bool open = false;
     private Gee.HashMap<FolderPath, MinimalFolder> folder_map = new Gee.HashMap<
@@ -1085,24 +1085,19 @@ internal class Geary.ImapEngine.UpdateRemoteFolders : AccountOperation {
 internal class Geary.ImapEngine.RefreshFolderUnseen : FolderOperation {
 
 
-    private weak Imap.Account remote;
-
-
     internal RefreshFolderUnseen(MinimalFolder folder,
-                                 GenericAccount account,
-                                 Imap.Account remote) {
+                                 GenericAccount account) {
         base(account, folder);
-        this.remote = remote;
     }
 
     public override async void execute(Cancellable cancellable) throws Error {
         if (this.folder.get_open_state() == Geary.Folder.OpenState.CLOSED) {
-            Imap.Folder remote_folder = yield this.remote.fetch_folder_cached_async(
-                folder.path,
-                true,
-                cancellable
-            );
-
+            Imap.Folder remote_folder =
+                yield ((GenericAccount) this.account).remote.fetch_folder_cached_async(
+                    folder.path,
+                    true,
+                    cancellable
+                );
 
             // Although this is called when the folder is closed, we
             // can safely use local_folder since we are only using its
diff --git a/src/engine/imap-engine/imap-engine-generic-folder.vala 
b/src/engine/imap-engine/imap-engine-generic-folder.vala
index cd59b9b..5f802ed 100644
--- a/src/engine/imap-engine/imap-engine-generic-folder.vala
+++ b/src/engine/imap-engine/imap-engine-generic-folder.vala
@@ -10,9 +10,10 @@ private class Geary.ImapEngine.GenericFolder : MinimalFolder,
     Geary.FolderSupport.Create,
     Geary.FolderSupport.Empty {
 
-    public GenericFolder(GenericAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public GenericFolder(GenericAccount account,
+                         ImapDB.Folder local_folder,
+                         SpecialFolderType special_folder_type) {
+        base (account, local_folder, special_folder_type);
     }
 
     public async Geary.Revokable? archive_email_async(Gee.List<Geary.EmailIdentifier> email_ids,
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index 4037c76..e85f7ef 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -1,4 +1,6 @@
-/* Copyright 2016 Software Freedom Conservancy Inc.
+/*
+ * Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2018 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later).  See the COPYING file in this distribution.
@@ -61,9 +63,9 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     internal ReplayQueue replay_queue { get; private set; }
 
     private weak GenericAccount _account;
-    private Geary.AggregatedFolderProperties _properties = new Geary.AggregatedFolderProperties(
-        false, false);
-    private Imap.Account remote;
+    private Geary.AggregatedFolderProperties _properties =
+        new Geary.AggregatedFolderProperties(false, false);
+
     private Folder.OpenFlags open_flags = OpenFlags.NONE;
     private int open_count = 0;
     private bool remote_opened = false;
@@ -105,11 +107,9 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
 
     public MinimalFolder(GenericAccount account,
-                         Imap.Account remote,
                          ImapDB.Folder local_folder,
                          SpecialFolderType special_folder_type) {
         this._account = account;
-        this.remote = remote;
         this.remote_open_timer = new TimeoutManager.seconds(
             FORCE_OPEN_REMOTE_TIMEOUT_SEC, () => { start_open_remote(); }
         );
@@ -565,7 +565,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         if (!yield remote_semaphore.wait_for_result_async(cancellable))
             throw new EngineError.ALREADY_CLOSED("%s failed to open", to_string());
     }
-    
+
     public override async bool open_async(Geary.Folder.OpenFlags open_flags, Cancellable? cancellable = null)
         throws Error {
         if (open_count++ > 0) {
@@ -577,12 +577,9 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
                 start_open_remote();
             }
-            
-            debug("Not opening %s: already open", to_string());
-            
             return false;
         }
-        
+
         // first open gets to name the flags, but see note above
         this.open_flags = open_flags;
 
@@ -612,7 +609,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // second account Inbox they don't manipulate), no remote connection will ever be made,
         // meaning that folder normalization never happens and unsolicited notifications never
         // arrive
-        this.remote.ready.connect(on_remote_ready);
+        this._account.remote.ready.connect(on_remote_ready);
         if (open_flags.is_all_set(OpenFlags.NO_DELAY)) {
             start_open_remote();
         } else {
@@ -622,7 +619,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     }
 
     private void start_open_remote() {
-        if (!this.remote_opened && this.remote.is_ready) {
+        if (!this.remote_opened && this._account.remote.is_ready) {
             this.remote_opened = true;
             this.remote_open_timer.reset();
             this.open_remote_async.begin(null);
@@ -676,7 +673,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
 
             debug("Fetching information for remote folder %s", to_string());
             try {
-                opening_folder = yield this.remote.fetch_folder_cached_async(
+                opening_folder = yield this._account.remote.fetch_folder_cached_async(
                     path, false, cancellable
                 );
             } catch (EngineError.NOT_FOUND err) {
@@ -687,7 +684,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
                 // Use local STATUS data cache to be able to present
                 // something to the user at least. XXX get the attrs
                 // from somewhere for Bug 714775
-                opening_folder = this.remote.new_selectable_folder(
+                opening_folder = this._account.remote.new_selectable_folder(
                     path,
                     local_status,
                     new Imap.MailboxAttributes(new Gee.ArrayList<Geary.Imap.MailboxAttribute>())
@@ -1470,7 +1467,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         // we support IMAP CONDSTORE (Bug 713117).
         int chunk_size = FLAG_UPDATE_START_CHUNK;
         Geary.EmailIdentifier? lowest = null;
-        while (!this.open_cancellable.is_cancelled() && this.remote.is_ready) {
+        while (!this.open_cancellable.is_cancelled() && this._account.remote.is_ready) {
             Gee.List<Geary.Email>? list_local = yield list_email_by_id_async(
                 lowest, chunk_size,
                 Geary.Email.Field.FLAGS,
@@ -1525,9 +1522,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     private void on_refresh_unseen() {
         // We queue an account operation since the folder itself is
         // closed and hence does not have a connection to use for it.
-        RefreshFolderUnseen op = new RefreshFolderUnseen(
-            this, this._account, this.remote
-        );
+        RefreshFolderUnseen op = new RefreshFolderUnseen(this, this._account);
         try {
             this._account.queue_operation(op);
         } catch (Error err) {
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 829ce2d..4ee8097 100644
--- a/src/engine/imap-engine/other/imap-engine-other-account.vala
+++ b/src/engine/imap-engine/other/imap-engine-other-account.vala
@@ -18,6 +18,6 @@ private class Geary.ImapEngine.OtherAccount : Geary.ImapEngine.GenericAccount {
         else
             type = local_folder.get_properties().attrs.get_special_folder_type();
 
-        return new OtherFolder(this, this.remote, local_folder, type);
+        return new OtherFolder(this, local_folder, type);
     }
 }
diff --git a/src/engine/imap-engine/other/imap-engine-other-folder.vala 
b/src/engine/imap-engine/other/imap-engine-other-folder.vala
index 77d84dd..25d85f0 100644
--- a/src/engine/imap-engine/other/imap-engine-other-folder.vala
+++ b/src/engine/imap-engine/other/imap-engine-other-folder.vala
@@ -5,9 +5,10 @@
  */
 
 private class Geary.ImapEngine.OtherFolder : GenericFolder {
-    public OtherFolder(OtherAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public OtherFolder(OtherAccount account,
+                       ImapDB.Folder local_folder,
+                       SpecialFolderType special_folder_type) {
+        base (account, local_folder, special_folder_type);
     }
 
 }
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 6d68a00..d9a7f97 100644
--- a/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
+++ b/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
@@ -46,9 +46,9 @@ private class Geary.ImapEngine.OutlookAccount : Geary.ImapEngine.GenericAccount
             special_folder_type = local_folder.get_properties().attrs.get_special_folder_type();
 
         if (special_folder_type == Geary.SpecialFolderType.DRAFTS)
-            return new OutlookDraftsFolder(this, this.remote, local_folder, special_folder_type);
+            return new OutlookDraftsFolder(this, local_folder, special_folder_type);
 
-        return new OutlookFolder(this, this.remote, local_folder, special_folder_type);
+        return new OutlookFolder(this, local_folder, special_folder_type);
     }
 
 }
diff --git a/src/engine/imap-engine/outlook/imap-engine-outlook-drafts-folder.vala 
b/src/engine/imap-engine/outlook/imap-engine-outlook-drafts-folder.vala
index 3218664..a6a8ebd 100644
--- a/src/engine/imap-engine/outlook/imap-engine-outlook-drafts-folder.vala
+++ b/src/engine/imap-engine/outlook/imap-engine-outlook-drafts-folder.vala
@@ -12,8 +12,9 @@
  * saved at all.
  */
 private class Geary.ImapEngine.OutlookDraftsFolder : MinimalFolder {
-    public OutlookDraftsFolder(OutlookAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public OutlookDraftsFolder(OutlookAccount account,
+                               ImapDB.Folder local_folder,
+                               SpecialFolderType special_folder_type) {
+        base(account, local_folder, special_folder_type);
     }
 }
diff --git a/src/engine/imap-engine/outlook/imap-engine-outlook-folder.vala 
b/src/engine/imap-engine/outlook/imap-engine-outlook-folder.vala
index 4131fe8..4bf46b0 100644
--- a/src/engine/imap-engine/outlook/imap-engine-outlook-folder.vala
+++ b/src/engine/imap-engine/outlook/imap-engine-outlook-folder.vala
@@ -5,8 +5,9 @@
  */
 
 private class Geary.ImapEngine.OutlookFolder : GenericFolder {
-    public OutlookFolder(OutlookAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public OutlookFolder(OutlookAccount account,
+                         ImapDB.Folder local_folder,
+                         SpecialFolderType special_folder_type) {
+        base(account, local_folder, special_folder_type);
     }
 }
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 d7fd959..49333a9 100644
--- a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
+++ b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
@@ -42,6 +42,6 @@ private class Geary.ImapEngine.YahooAccount : Geary.ImapEngine.GenericAccount {
         Geary.FolderPath path = local_folder.get_path();
         SpecialFolderType special_folder_type = special_map.has_key(path) ? special_map.get(path)
             : Geary.SpecialFolderType.NONE;
-        return new YahooFolder(this, this.remote, local_folder, special_folder_type);
+        return new YahooFolder(this, local_folder, special_folder_type);
     }
 }
diff --git a/src/engine/imap-engine/yahoo/imap-engine-yahoo-folder.vala 
b/src/engine/imap-engine/yahoo/imap-engine-yahoo-folder.vala
index 5663faf..dc8481f 100644
--- a/src/engine/imap-engine/yahoo/imap-engine-yahoo-folder.vala
+++ b/src/engine/imap-engine/yahoo/imap-engine-yahoo-folder.vala
@@ -5,8 +5,9 @@
  */
 
 private class Geary.ImapEngine.YahooFolder : GenericFolder {
-    public YahooFolder(YahooAccount account, Imap.Account remote,
-        ImapDB.Folder local_folder, SpecialFolderType special_folder_type) {
-        base (account, remote, local_folder, special_folder_type);
+    public YahooFolder(YahooAccount account,
+                       ImapDB.Folder local_folder,
+                       SpecialFolderType special_folder_type) {
+        base (account, local_folder, special_folder_type);
     }
 }


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