[geary/wip/730682-refine-convo-list: 8/12] Manage changing conversation counts from MainWindow, not GearyController.



commit d1c1a4a23ce44a4eb70a7f4de43946fd2d4e8aa0
Author: Michael James Gratton <mike vee net>
Date:   Sun Oct 15 07:46:53 2017 +1030

    Manage changing conversation counts from MainWindow, not GearyController.

 src/client/application/geary-controller.vala       |   38 +------------------
 src/client/components/main-window.vala             |   36 ++++++++++++++++++
 .../conversation-list/conversation-list-model.vala |    5 ++-
 .../conversation-list/conversation-list.vala       |    4 ++-
 4 files changed, 44 insertions(+), 39 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 735e2bf..bc99e2f 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -138,12 +138,7 @@ public class GearyController : Geary.BaseObject {
      * Fired when the currently selected folder has changed.
      */
     public signal void folder_selected(Geary.Folder? folder);
-    
-    /**
-     * Fired when the number of conversations changes.
-     */
-    public signal void conversation_count_changed(int count);
-    
+
     /**
      * Fired when the search text is changed according to the controller.  This accounts
      * for a brief typmatic delay.
@@ -1454,11 +1449,7 @@ public class GearyController : Geary.BaseObject {
         
         current_conversations.scan_error.connect(on_scan_error);
         current_conversations.seed_completed.connect(on_seed_completed);
-        current_conversations.seed_completed.connect(on_conversation_count_changed);
-        current_conversations.scan_completed.connect(on_conversation_count_changed);
-        current_conversations.conversations_added.connect(on_conversation_count_changed);
-        current_conversations.conversations_removed.connect(on_conversation_count_changed);
-        
+
         if (!current_conversations.is_monitoring)
             yield current_conversations.start_monitoring_async(conversation_cancellable);
         
@@ -1480,31 +1471,6 @@ public class GearyController : Geary.BaseObject {
         }
     }
 
-    private void on_conversation_count_changed() {
-        if (this.current_conversations != null) {
-            ConversationViewer viewer = this.main_window.conversation_viewer;
-            int count = this.current_conversations.get_conversation_count();
-            if (count == 0) {
-                // Let the user know if there's no available conversations
-                if (this.current_folder is Geary.SearchFolder) {
-                    viewer.show_empty_search();
-                } else {
-                    viewer.show_empty_folder();
-                }
-                enable_message_buttons(false);
-            } else {
-                // When not doing autoselect, we never get
-                // conversations_selected firing from the convo list,
-                // so we need to stop the loading spinner here
-                if (!this.application.config.autoselect) {
-                    viewer.show_none_selected();
-                    enable_message_buttons(false);
-                }
-            }
-            conversation_count_changed(count);
-        }
-    }
-
     private void on_libnotify_invoked(Geary.Folder? folder, Geary.Email? email) {
         new_messages_monitor.clear_all_new_messages();
         
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index c734351..c333b6a 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -285,6 +285,15 @@ public class MainWindow : Gtk.ApplicationWindow {
             this.progress_monitor.remove(old_model.conversations.progress_monitor);
         }
 
+        Geary.App.ConversationMonitor? old_monitor = (this.conversation_list != null)
+            ? this.conversation_list.model.monitor : null;
+        if (old_monitor != null) {
+            old_monitor.seed_completed.disconnect(on_conversation_count_changed);
+            old_monitor.scan_completed.disconnect(on_conversation_count_changed);
+            old_monitor.conversations_added.disconnect(on_conversation_count_changed);
+            old_monitor.conversations_removed.disconnect(on_conversation_count_changed);
+        }
+
         Geary.App.ConversationMonitor? new_monitor =
             this.application.controller.current_conversations;
 
@@ -296,6 +305,10 @@ public class MainWindow : Gtk.ApplicationWindow {
             this.conversation_list_view.set_model(new_model);
 
             this.conversation_list.bind_model(new_monitor);
+            new_monitor.seed_completed.connect(on_conversation_count_changed);
+            new_monitor.scan_completed.connect(on_conversation_count_changed);
+            new_monitor.conversations_added.connect(on_conversation_count_changed);
+            new_monitor.conversations_removed.connect(on_conversation_count_changed);
         }
 
         if (old_model != null) {
@@ -476,6 +489,29 @@ public class MainWindow : Gtk.ApplicationWindow {
         }
     }
 
+    private void on_conversation_count_changed() {
+        if (this.application.controller.current_conversations != null) {
+            int count = this.application.controller.current_conversations.get_conversation_count();
+            if (count == 0) {
+                // Let the user know if there's no available conversations
+                if (this.current_folder is Geary.SearchFolder) {
+                    this.conversation_viewer.show_empty_search();
+                } else {
+                    this.conversation_viewer.show_empty_folder();
+                }
+                this.application.controller.enable_message_buttons(false);
+            } else {
+                // When not doing autoselect, we never get
+                // conversations_selected firing from the convo list,
+                // so we need to stop the loading spinner here
+                if (!this.application.config.autoselect) {
+                    this.conversation_viewer.show_none_selected();
+                    this.application.controller.enable_message_buttons(false);
+                }
+            }
+        }
+    }
+
     [GtkCallback]
     private bool on_key_release_event(Gdk.EventKey event) {
         check_shift_event(event);
diff --git a/src/client/conversation-list/conversation-list-model.vala 
b/src/client/conversation-list/conversation-list-model.vala
index 802c102..c164958 100644
--- a/src/client/conversation-list/conversation-list-model.vala
+++ b/src/client/conversation-list/conversation-list-model.vala
@@ -18,14 +18,15 @@
 public class ConversationListModel : Geary.BaseObject, GLib.ListModel {
 
 
+    /** The source of conversations for this model. */
+    public Geary.App.ConversationMonitor monitor { get; private set; }
+
     // The model's native sort order
     private static int model_sort(Geary.App.Conversation a, Geary.App.Conversation b) {
         return compare_conversation_descending(a, b);
     }
 
 
-    private Geary.App.ConversationMonitor monitor;
-
     // Backing store for this model. We can't just derive from this
     // directly since GLib.ListStore is a compact class.
     private ListStore conversations = new ListStore(typeof(Geary.App.Conversation));
diff --git a/src/client/conversation-list/conversation-list.vala 
b/src/client/conversation-list/conversation-list.vala
index ddb2735..525cd55 100644
--- a/src/client/conversation-list/conversation-list.vala
+++ b/src/client/conversation-list/conversation-list.vala
@@ -14,9 +14,11 @@ public class ConversationList : Gtk.ListBox {
 
     private const string CLASS = "geary-conversation-list";
 
+    /** Underlying model for this list */
+    public ConversationListModel? model { get; private set; default=null; }
+
     private Configuration config;
 
-    private ConversationListModel? model = null;
 
 
     /** Fired when a user changes the list's selection. */


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