[geary/wip/730682-refine-convo-list: 27/37] Fix a bunch of crashes.



commit eccf2d04ed65ef06eefefe14288a4c9160a4e992
Author: Michael James Gratton <mike vee net>
Date:   Mon Dec 11 13:52:48 2017 +1100

    Fix a bunch of crashes.

 src/client/components/main-window.vala             |   21 +++---
 .../conversation-list/conversation-list-item.vala  |   75 +++++++++++++-------
 src/client/conversation-list/preview-loader.vala   |    9 ++-
 3 files changed, 67 insertions(+), 38 deletions(-)
---
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index b64f26b..bf444df 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -293,14 +293,16 @@ public class MainWindow : Gtk.ApplicationWindow {
     }
 
     private void on_conversation_monitor_changed() {
-        ConversationListStore? old_model = this.conversation_list_view.get_model();
-        if (old_model != null) {
-            this.progress_monitor.remove(old_model.preview_monitor);
-            this.progress_monitor.remove(old_model.conversations.progress_monitor);
+        // 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);
         }
 
-        Geary.App.ConversationMonitor? old_monitor = (this.conversation_list != null)
-            ? this.conversation_list.model.monitor : null;
+        ConversationListModel? old_model = this.conversation_list.model;
+        Geary.App.ConversationMonitor? old_monitor = (old_model != null)
+            ? old_model.monitor : null;
         if (old_monitor != null) {
             old_monitor.scan_error.disconnect(on_scan_error);
             old_monitor.seed_completed.disconnect(on_seed_completed);
@@ -312,14 +314,15 @@ 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);
 
             new_monitor.scan_error.connect(on_scan_error);
@@ -330,9 +333,9 @@ public class MainWindow : Gtk.ApplicationWindow {
             new_monitor.conversations_removed.connect(on_conversation_count_changed);
         }
 
-        if (old_model != null) {
+        if (old_store != null) {
             // Must be destroyed, but only after it has been replaced.
-            old_model.destroy();
+            old_store.destroy();
         }
     }
 
diff --git a/src/client/conversation-list/conversation-list-item.vala 
b/src/client/conversation-list/conversation-list-item.vala
index af3b1e8..b07afc2 100644
--- a/src/client/conversation-list/conversation-list-item.vala
+++ b/src/client/conversation-list/conversation-list-item.vala
@@ -98,6 +98,7 @@ public class ConversationListItem : Gtk.Grid {
     private Gee.List<Geary.RFC822.MailboxAddress> account_addresses;
     private bool use_to;
     private PreviewLoader preview_loader;
+    private Cancellable preview_cancellable = new Cancellable();
     private Configuration config;
 
     public ConversationListItem(Geary.App.Conversation conversation,
@@ -111,15 +112,28 @@ public class ConversationListItem : Gtk.Grid {
         this.preview_loader = preview_loader;
         this.config = config;
 
-        this.conversation.appended.connect(() => { update(); });
-        this.conversation.trimmed.connect(() => { update(); });
-        this.conversation.email_flags_changed.connect(() => { update(); });
+        this.conversation.appended.connect(() => {
+                update();
+            });
+        this.conversation.trimmed.connect(() => {
+                if (this.conversation.get_count() > 0) {
+                    update();
+                }
+            });
+        this.conversation.email_flags_changed.connect(() => {
+                update();
+            });
 
         this.config.notify["clock-format"].connect(() => { update(); });
         this.config.notify["display-preview"].connect(() => { update(); });
         update();
     }
 
+    public override void destroy() {
+        this.preview_cancellable.cancel();
+        base.destroy();
+    }
+
     private void update() {
         Gtk.StyleContext style = get_style_context();
 
@@ -149,29 +163,38 @@ public class ConversationListItem : Gtk.Grid {
             Geary.App.Conversation.Location.ANYWHERE
         );
 
-        string subject_markup = this.conversation.is_unread() ? "<b>%s</b>" : "%s";
-        subject_markup = Markup.printf_escaped(
-            subject_markup,
-            Geary.String.reduce_whitespace(EmailUtil.strip_subject_prefixes(preview_message))
-        );
-        this.subject.set_markup(subject_markup);
-        if (preview_message.subject != null) {
-            this.subject.set_tooltip_text(
-                Geary.String.reduce_whitespace(preview_message.subject.to_string())
-            );
-        }
-
-        if (this.config.display_preview) {
-            // XXX load & format preview here
-            this.preview_loader.load.begin(preview_message, (obj, ret) => {
-                    string? preview_text = this.preview_loader.load.end(ret);
-                    if (preview_text != null) {
-                        this.preview.set_text(preview_text);
-                    }
-                });
-            this.preview.show();
-        } else {
-            this.preview.hide();
+        if (preview_message != null) {
+            Pango.AttrList attrs = new Pango.AttrList();
+            if (this.conversation.is_unread()) {
+                attrs.insert(Pango.attr_weight_new(Pango.Weight.BOLD));
+            }
+            this.subject.set_attributes(attrs);
+            this.subject.set_text(Geary.String.reduce_whitespace(
+                EmailUtil.strip_subject_prefixes(preview_message)
+            ));
+            string? tooltip_text = null;
+            if (preview_message.subject != null) {
+                tooltip_text = Geary.String.reduce_whitespace(
+                    preview_message.subject.to_string()
+                );
+            }
+            this.subject.set_tooltip_text(tooltip_text);
+
+
+            if (this.config.display_preview) {
+                this.preview_loader.load.begin(
+                    preview_message,
+                    this.preview_cancellable,
+                    (obj, ret) => {
+                        string? preview_text = this.preview_loader.load.end(ret);
+                        if (preview_text != null) {
+                            this.preview.set_text(preview_text);
+                        }
+                    });
+                this.preview.show();
+            } else {
+                this.preview.hide();
+            }
         }
 
         // conversation list store sorts by date-received, so
diff --git a/src/client/conversation-list/preview-loader.vala 
b/src/client/conversation-list/preview-loader.vala
index 29d3445..ccbab67 100644
--- a/src/client/conversation-list/preview-loader.vala
+++ b/src/client/conversation-list/preview-loader.vala
@@ -31,7 +31,7 @@ public class PreviewLoader : Geary.BaseObject {
         this.loading_local_only = false;
     }
 
-    public async string? load(Geary.Email target) {
+    public async string? load(Geary.Email target, Cancellable load_cancellable) {
         Gee.Collection<Geary.EmailIdentifier> pending = new Gee.HashSet<Geary.EmailIdentifier>();
         pending.add(target.id);
 
@@ -50,9 +50,12 @@ public class PreviewLoader : Geary.BaseObject {
                 debug("Unable to fetch preview: %s", err.message);
         }
 
-        Geary.Email? loaded = Geary.Collection.get_first(emails);
+        Geary.Email? loaded = null;
+        if (emails != null) {
+            loaded = Geary.Collection.get_first(emails);
+        }
         string? preview = null;
-        if (loaded != null) {
+        if (loaded != null && !load_cancellable.is_cancelled()) {
             preview = Geary.String.reduce_whitespace(loaded.get_preview_as_string());
         }
         return preview;


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