[geary/wip/765516-gtk-widget-conversation-viewer: 37/78] Ensure ConversationMessage.web_view load stops when message load cancelled.



commit ca153fb0baf6648b7d3a23c20781976c1729eb5b
Author: Michael James Gratton <mike vee net>
Date:   Mon Apr 18 12:17:04 2016 +1000

    Ensure ConversationMessage.web_view load stops when message load cancelled.
    
    * src/client/conversation-viewer/conversation-message.vala: Load message
      body from ::start_loading, pass the cancellable through so the web_view
      load can be stopped. Make ::load_message_body async so the UI can be
      updated before attempting the page load.

 .../conversation-viewer/conversation-message.vala  |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index c8ebdef..f3ac510 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -205,8 +205,6 @@ public class ConversationMessage : Gtk.Box {
         body_box.set_has_tooltip(true); // Used to show link URLs
         body_box.pack_start(web_view, true, true, 0);
 
-        load_message_body();
-
         // if (email.from != null && email.from.contains_normalized(current_account_information.email)) {
         //  // XXX set a RO property?
         //  get_style_context().add_class("sent");
@@ -243,6 +241,7 @@ public class ConversationMessage : Gtk.Box {
     }
 
     public async void start_loading(Cancellable load_cancelled) {
+        yield load_message_body(load_cancelled);
         yield load_attachments(email.attachments, load_cancelled);
     }
 
@@ -423,7 +422,7 @@ public class ConversationMessage : Gtk.Box {
         //            Geary.SpecialFolderType.SENT.get_display_name()));
     }
 
-    private void load_message_body() {
+    private async void load_message_body(Cancellable load_cancelled) {
         bool load_images = false;
         string? body_text = null;
         try {
@@ -436,8 +435,8 @@ public class ConversationMessage : Gtk.Box {
             debug("Could not get message text. %s", err.message);
         }
 
-        body_text = clean_html_markup(body_text ?? "", message, out remote_images);
-        if (remote_images) {
+        body_text = clean_html_markup(body_text ?? "", message, out load_images);
+        if (load_images) {
             Geary.Contact contact =
                 contact_store.get_by_rfc822(email.get_primary_originator());
             bool always_load = contact != null && contact.always_load_remote_images();
@@ -448,6 +447,7 @@ public class ConversationMessage : Gtk.Box {
             }
         }
 
+        load_cancelled.cancelled.connect(() => { web_view.stop_loading(); });
         web_view.notify["load-status"].connect((source, param) => {
                 if (web_view.load_status == WebKit.LoadStatus.FINISHED) {
                     if (load_images) {
@@ -478,10 +478,10 @@ public class ConversationMessage : Gtk.Box {
                 }
             });
 
-        // Only load it after we've hooked up the load-status signal above
+        // Only load it after we've hooked up the signals above
         web_view.load_string(body_text, "text/html", "UTF8", "");
     }
-    
+
     // This delegate is called from within Geary.RFC822.Message.get_body while assembling the plain
     // or HTML document when a non-text MIME part is encountered within a multipart/mixed container.
     // If this returns null, the MIME part is dropped from the final returned document; otherwise,


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