[geary/mjog/user-plugins: 15/26] FolderList.Tree: Remove use of a NotificationContext object



commit 18df9462160fb93fc53619942c536e41d08b69a8
Author: Michael Gratton <mike vee net>
Date:   Tue Mar 10 12:20:28 2020 +1100

    FolderList.Tree: Remove use of a NotificationContext object
    
    Since these are becoming per-plugin only, use folder signals to update
    for now.

 src/client/application/application-controller.vala |   3 -
 src/client/folder-list/folder-list-tree.vala       | 113 +++++++++++----------
 2 files changed, 60 insertions(+), 56 deletions(-)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index f4b6d5e4..556da0ad 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -862,9 +862,6 @@ internal class Application.Controller : Geary.BaseObject {
 
     internal void register_window(MainWindow window) {
         window.retry_service_problem.connect(on_retry_service_problem);
-        window.folder_list.set_new_messages_monitor(
-            this.notifications
-        );
     }
 
     internal void unregister_window(MainWindow window) {
diff --git a/src/client/folder-list/folder-list-tree.vala b/src/client/folder-list/folder-list-tree.vala
index f0a831d1..372ef90b 100644
--- a/src/client/folder-list/folder-list-tree.vala
+++ b/src/client/folder-list/folder-list-tree.vala
@@ -5,6 +5,8 @@
  */
 
 public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
+
+
     public const Gtk.TargetEntry[] TARGET_ENTRY_LIST = {
         { "application/x-geary-mail", Gtk.TargetFlags.SAME_APP, 0 }
     };
@@ -12,6 +14,12 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
     private const int INBOX_ORDINAL = -2; // First account branch is zero
     private const int SEARCH_ORDINAL = -1;
 
+    private const Geary.SpecialFolderType[] INTERESTING_FOLDERS = {
+        INBOX,
+        NONE
+    };
+
+
     public signal void folder_selected(Geary.Folder? folder);
     public signal void copy_conversation(Geary.Folder folder);
     public signal void move_conversation(Geary.Folder folder);
@@ -22,7 +30,7 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
         = new Gee.HashMap<Geary.Account, AccountBranch>();
     private InboxesBranch inboxes_branch = new InboxesBranch();
     private SearchBranch? search_branch = null;
-    private Application.NotificationContext? monitor = null;
+
 
     public Tree() {
         base(TARGET_ENTRY_LIST, Gdk.DragAction.COPY | Gdk.DragAction.MOVE, drop_handler);
@@ -39,10 +47,24 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
     }
 
     ~Tree() {
-        set_new_messages_monitor(null);
         base_unref();
     }
 
+    public void set_has_new(Geary.Folder folder, bool has_new) {
+        FolderEntry? entry = get_folder_entry(folder);
+        if (entry != null) {
+            entry.set_has_new(has_new);
+        }
+
+        if (folder.special_folder_type == INBOX &&
+            has_branch(inboxes_branch)) {
+            entry = inboxes_branch.get_entry_for_account(folder.account);
+            if (entry != null) {
+                entry.set_has_new(has_new);
+            }
+        }
+    }
+
     private void drop_handler(Gdk.DragContext context, Sidebar.Entry? entry,
         Gtk.SelectionData data, uint info, uint time) {
     }
@@ -63,35 +85,10 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
     }
 
     private void on_entry_selected(Sidebar.SelectableEntry selectable) {
-        AbstractFolderEntry? abstract_folder_entry = selectable as AbstractFolderEntry;
-        if (abstract_folder_entry != null) {
-            this.selected = abstract_folder_entry.folder;
-            folder_selected(abstract_folder_entry.folder);
-        }
-    }
-
-    private void on_new_messages_changed(Geary.Folder folder, int count) {
-        FolderEntry? entry = get_folder_entry(folder);
-        if (entry != null)
-            entry.set_has_new(count > 0);
-
-        if (has_branch(inboxes_branch)) {
-            InboxFolderEntry? inbox_entry = inboxes_branch.get_entry_for_account(folder.account);
-            if (inbox_entry != null)
-                inbox_entry.set_has_new(count > 0);
-        }
-    }
-
-    public void set_new_messages_monitor(Application.NotificationContext? monitor) {
-        if (this.monitor != null) {
-            this.monitor.new_messages_arrived.disconnect(on_new_messages_changed);
-            this.monitor.new_messages_retired.disconnect(on_new_messages_changed);
-        }
-
-        this.monitor = monitor;
-        if (this.monitor != null) {
-            this.monitor.new_messages_arrived.connect(on_new_messages_changed);
-            this.monitor.new_messages_retired.connect(on_new_messages_changed);
+        FolderEntry? entry = selectable as FolderEntry;
+        if (entry != null) {
+            this.selected = entry.folder;
+            folder_selected(entry.folder);
         }
     }
 
@@ -101,8 +98,11 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
     }
 
     public void add_folder(Geary.Folder folder) {
-        if (!account_branches.has_key(folder.account))
-            account_branches.set(folder.account, new AccountBranch(folder.account));
+        Geary.Account account = folder.account;
+        if (!account_branches.has_key(account)) {
+            this.account_branches.set(account, new AccountBranch(account));
+            account.information.notify["ordinal"].connect(on_ordinal_changed);
+        }
 
         AccountBranch account_branch = account_branches.get(folder.account);
         if (!has_branch(account_branch))
@@ -113,7 +113,7 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
         if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
             inboxes_branch.add_inbox(folder);
 
-        folder.account.information.notify["ordinal"].connect(on_ordinal_changed);
+        folder.email_locally_appended.connect(on_email_appended);
         account_branch.add_folder(folder);
     }
 
@@ -141,6 +141,7 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
         if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
             inboxes_branch.remove_inbox(folder.account);
 
+        folder.email_locally_appended.disconnect(on_email_appended);
         account_branch.remove_folder(folder);
     }
 
@@ -225,24 +226,6 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
         return ret;
     }
 
-    private void on_ordinal_changed() {
-        if (account_branches.size <= 1)
-            return;
-
-        // Remove branches where the ordinal doesn't match the graft position.
-        Gee.ArrayList<AccountBranch> branches_to_reorder = new Gee.ArrayList<AccountBranch>();
-        foreach (AccountBranch branch in account_branches.values) {
-            if (get_position_for_branch(branch) != branch.account.information.ordinal) {
-                prune(branch);
-                branches_to_reorder.add(branch);
-            }
-        }
-
-        // Re-add branches with new positions.
-        foreach (AccountBranch branch in branches_to_reorder)
-            graft(branch, branch.account.information.ordinal);
-    }
-
     public void set_search(Geary.Engine engine,
                            Geary.App.SearchFolder search_folder) {
         if (search_branch != null && has_branch(search_branch)) {
@@ -268,5 +251,29 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
             search_branch = null;
         }
     }
-}
+    private void on_ordinal_changed() {
+        if (account_branches.size <= 1)
+            return;
+
+        // Remove branches where the ordinal doesn't match the graft position.
+        Gee.ArrayList<AccountBranch> branches_to_reorder = new Gee.ArrayList<AccountBranch>();
+        foreach (AccountBranch branch in account_branches.values) {
+            if (get_position_for_branch(branch) != branch.account.information.ordinal) {
+                prune(branch);
+                branches_to_reorder.add(branch);
+            }
+        }
+
+        // Re-add branches with new positions.
+        foreach (AccountBranch branch in branches_to_reorder)
+            graft(branch, branch.account.information.ordinal);
+    }
 
+    private void on_email_appended(Geary.Folder folder,
+                                   Gee.Collection<Geary.EmailIdentifier> ids) {
+        if (folder.special_folder_type in INTERESTING_FOLDERS) {
+            set_has_new(folder, true);
+        }
+    }
+
+}


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