[geary/wip/730682-refine-convo-list: 32/37] Hook up conversation list loading progress monitors to the main window.



commit c04c366a799de482f27dff221b9996b773701b96
Author: Michael James Gratton <mike vee net>
Date:   Mon Dec 11 16:17:13 2017 +1100

    Hook up conversation list loading progress monitors to the main window.
    
    * src/client/conversation-list/preview-loader.vala (PreviewLoader): Add a
      progress monitor to the class, update it as previews are loaded.
    
    * src/client/conversation-list/conversation-list-model.vala
      (ConversationListModel): Add a PreviewLoader construct property so it
      can be accessed from the main window. Update call sites.
    
    * src/client/components/main-window.vala
      (on_conversation_monitor_changed): Manage new progress monitors on
      ConversationListModel, remove ConversationListStore management.

 src/client/components/main-window.vala             |   32 +++++--------------
 .../conversation-list/conversation-list-model.vala |    7 ++++-
 .../conversation-list/conversation-list.vala       |    2 +-
 src/client/conversation-list/preview-loader.vala   |   11 +++++++
 4 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index bf444df..827664a 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -293,17 +293,12 @@ public class MainWindow : Gtk.ApplicationWindow {
     }
 
     private void on_conversation_monitor_changed() {
-        // Old list
-        ConversationListStore? old_store = this.conversation_list_view.get_model();
-        if (old_store != null) {
-            this.progress_monitor.remove(old_store.preview_monitor);
-            this.progress_monitor.remove(old_store.conversations.progress_monitor);
-        }
-
         ConversationListModel? old_model = this.conversation_list.model;
-        Geary.App.ConversationMonitor? old_monitor = (old_model != null)
-            ? old_model.monitor : null;
-        if (old_monitor != null) {
+        if (old_model != null) {
+            this.progress_monitor.remove(old_model.monitor.progress_monitor);
+            this.progress_monitor.remove(old_model.previews.progress);
+
+            Geary.App.ConversationMonitor? old_monitor = old_model.monitor;
             old_monitor.scan_error.disconnect(on_scan_error);
             old_monitor.seed_completed.disconnect(on_seed_completed);
             old_monitor.seed_completed.disconnect(on_conversation_count_changed);
@@ -315,15 +310,11 @@ public class MainWindow : Gtk.ApplicationWindow {
         Geary.App.ConversationMonitor? new_monitor =
             this.application.controller.current_conversations;
         if (new_monitor != null) {
-            // Old list
-            ConversationListStore new_model =
-                new ConversationListStore(new_monitor);
-            this.progress_monitor.add(new_monitor.progress_monitor);
-            this.progress_monitor.add(new_model.preview_monitor);
-            this.conversation_list_view.set_model(new_model);
-
-            // New list
             this.conversation_list.bind_model(new_monitor);
+            ConversationListModel new_model = this.conversation_list.model;
+
+            this.progress_monitor.add(new_model.monitor.progress_monitor);
+            this.progress_monitor.add(new_model.previews.progress);
 
             new_monitor.scan_error.connect(on_scan_error);
             new_monitor.seed_completed.connect(on_seed_completed);
@@ -332,11 +323,6 @@ public class MainWindow : Gtk.ApplicationWindow {
             new_monitor.conversations_added.connect(on_conversation_count_changed);
             new_monitor.conversations_removed.connect(on_conversation_count_changed);
         }
-
-        if (old_store != null) {
-            // Must be destroyed, but only after it has been replaced.
-            old_store.destroy();
-        }
     }
 
     private void on_folder_selected(Geary.Folder? folder) {
diff --git a/src/client/conversation-list/conversation-list-model.vala 
b/src/client/conversation-list/conversation-list-model.vala
index 65393e7..e0171b6 100644
--- a/src/client/conversation-list/conversation-list-model.vala
+++ b/src/client/conversation-list/conversation-list-model.vala
@@ -21,6 +21,9 @@ public class ConversationListModel : Geary.BaseObject, GLib.ListModel {
     /** The source of conversations for this model. */
     public Geary.App.ConversationMonitor monitor { get; private set; }
 
+    /** The preview loader for this model. */
+    public PreviewLoader previews { get; private set; }
+
     // Backing store for this model
     private Sequence<Geary.App.Conversation> conversations =
         new Sequence<Geary.App.Conversation>();
@@ -33,8 +36,10 @@ public class ConversationListModel : Geary.BaseObject, GLib.ListModel {
     /**
      * Constructs a new model for the conversation list.
      */
-    public ConversationListModel(Geary.App.ConversationMonitor monitor) {
+    public ConversationListModel(Geary.App.ConversationMonitor monitor,
+                                 PreviewLoader previews) {
         this.monitor = monitor;
+        this.previews = previews;
 
         // XXX Should only start loading when scan is completed
         //monitor.scan_completed.connect(on_scan_completed);
diff --git a/src/client/conversation-list/conversation-list.vala 
b/src/client/conversation-list/conversation-list.vala
index 80b4525..5565319 100644
--- a/src/client/conversation-list/conversation-list.vala
+++ b/src/client/conversation-list/conversation-list.vala
@@ -75,7 +75,7 @@ public class ConversationList : Gtk.ListBox {
                 loader.load_remote();
             });
 
-        this.model = new ConversationListModel(monitor);
+        this.model = new ConversationListModel(monitor, loader);
         this.model.items_changed.connect(on_model_items_changed);
 
         Gee.List<Geary.RFC822.MailboxAddress> account_addresses = 
displayed.account.information.get_all_mailboxes();
diff --git a/src/client/conversation-list/preview-loader.vala 
b/src/client/conversation-list/preview-loader.vala
index ccbab67..217a529 100644
--- a/src/client/conversation-list/preview-loader.vala
+++ b/src/client/conversation-list/preview-loader.vala
@@ -11,6 +11,15 @@
  */
 public class PreviewLoader : Geary.BaseObject {
 
+
+    public Geary.ProgressMonitor progress {
+        get;
+        private set;
+        default = new Geary.ReentrantProgressMonitor(
+            Geary.ProgressType.ACTIVITY
+        );
+    }
+
     // XXX Remove ALL and NONE when PREVIEW has been fixed. See Bug 714317.
     private const Geary.Email.Field WITH_PREVIEW_FIELDS =
         Geary.Email.Field.ENVELOPE | Geary.Email.Field.FLAGS |
@@ -32,6 +41,7 @@ public class PreviewLoader : Geary.BaseObject {
     }
 
     public async string? load(Geary.Email target, Cancellable load_cancellable) {
+        this.progress.notify_start();
         Gee.Collection<Geary.EmailIdentifier> pending = new Gee.HashSet<Geary.EmailIdentifier>();
         pending.add(target.id);
 
@@ -58,6 +68,7 @@ public class PreviewLoader : Geary.BaseObject {
         if (loaded != null && !load_cancellable.is_cancelled()) {
             preview = Geary.String.reduce_whitespace(loaded.get_preview_as_string());
         }
+        this.progress.notify_finish();
         return preview;
     }
 


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