[geary/mjog/mutiple-main-windows] Ensure the inbox of the first account is selected on app startup



commit fbc47a1f990401cbafa37d02f352679f5be8b788
Author: Michael Gratton <mike vee net>
Date:   Mon Nov 18 21:43:48 2019 +1100

    Ensure the inbox of the first account is selected on app startup

 src/client/application/application-controller.vala | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 9473943d..6ae7869a 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -234,6 +234,30 @@ internal class Application.Controller : Geary.BaseObject {
             warning("Error opening Geary.Engine instance: %s", e.message);
         }
 
+        // Since the accounts may still be loading folders, when the
+        // main window first opens no folder might be available to be
+        // selected. Add look for the inbox and if not found, add a
+        // listener here as a once off for when it is loaded.
+        var config = get_first_account();
+        if (config != null) {
+            var first = this.accounts.get(config);
+            if (first != null) {
+                var inbox = first.account.get_special_folder(INBOX);
+                if (inbox != null) {
+                    application.get_active_main_window().select_folder.begin(
+                        inbox, true
+                    );
+
+                } else {
+                    // Connect after so the folder is added to any
+                    // open main windows first.
+                    first.account.folders_available_unavailable.connect_after(
+                        on_folders_first_available
+                    );
+                }
+            }
+        }
+
         // Expunge any deleted accounts in the background, so we're
         // not blocking the app continuing to open.
         this.expunge_accounts.begin();
@@ -1439,6 +1463,37 @@ internal class Application.Controller : Geary.BaseObject {
         }
     }
 
+    private void on_folders_first_available(
+        Geary.Account account,
+        Gee.BidirSortedSet<Geary.Folder>? available,
+        Gee.BidirSortedSet<Geary.Folder>? unavailable
+    ) {
+        debug("XXX folders first loaded");
+        bool inbox_found = false;
+        if (available != null) {
+            foreach (Geary.Folder folder in available) {
+                debug("XXX folder: %s/%s",
+                      folder.get_display_name(),
+                      folder.special_folder_type.to_string());
+                if (Controller.should_add_folder(available, folder) &&
+                    folder.special_folder_type == INBOX) {
+                    debug("XXX found inbox");
+                    inbox_found = true;
+                    this.application.get_active_main_window().select_folder.begin(
+                        folder, true
+                    );
+                }
+            }
+        }
+
+        if (inbox_found) {
+            // The handler has done its job, so disconnect it
+            account.folders_available_unavailable.disconnect(
+                on_folders_first_available
+            );
+        }
+    }
+
     private bool should_notify_new_messages(Geary.Folder folder) {
         // A monitored folder must be selected to squelch notifications;
         // if conversation list is at top of display, don't display


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