[geary/mjog/account-command-stacks: 62/77] Move View Source implementation to ConversationEmail



commit 3fe13ea9f721cde6409ea0bb3e22aa3d193fbe8a
Author: Michael Gratton <mike vee net>
Date:   Tue Oct 29 12:39:22 2019 +1100

    Move View Source implementation to ConversationEmail
    
    The only place it is used is in ConversationEmail, so move it there from
    MainWindow and remove the signal.

 src/client/components/main-window.vala             | 27 -----------
 .../conversation-viewer/conversation-email.vala    | 53 +++++++++++++++++++---
 2 files changed, 47 insertions(+), 33 deletions(-)
---
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index f49ad80e..9ca7575b 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -1403,7 +1403,6 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         view.reply_all_message.connect(on_reply_all_message);
         view.reply_to_message.connect(on_reply_to_message);
         view.edit_draft.connect(on_edit_draft);
-        view.view_source.connect(on_view_source);
 
         Geary.App.Conversation conversation = this.conversation_viewer.current_list.conversation;
         bool in_selected_folder = (
@@ -1850,32 +1849,6 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         }
     }
 
-    private void on_view_source(ConversationEmail email_view) {
-        string source = (email_view.email.header.buffer.to_string() +
-                         email_view.email.body.buffer.to_string());
-        string temporary_filename;
-        try {
-            int temporary_handle = FileUtils.open_tmp("geary-message-XXXXXX.txt",
-                                                      out temporary_filename);
-            FileUtils.set_contents(temporary_filename, source);
-            FileUtils.close(temporary_handle);
-
-            // ensure this file is only readable by the user ... this
-            // needs to be done after the file is closed
-            FileUtils.chmod(temporary_filename, (int) (Posix.S_IRUSR | Posix.S_IWUSR));
-
-            string temporary_uri = Filename.to_uri(temporary_filename, null);
-            this.application.show_uri.begin(temporary_uri);
-        } catch (Error error) {
-            ErrorDialog dialog = new ErrorDialog(
-                this,
-                _("Failed to open default text editor."),
-                error.message
-            );
-            dialog.run();
-        }
-    }
-
     private void on_trash_message(ConversationEmail target_view) {
         Geary.Folder? source = this.selected_folder;
         if (source != null) {
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index 26fabe85..7b29e3fb 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -279,9 +279,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
     /** Fired the edit draft button is clicked. */
     public signal void edit_draft();
 
-    /** Fired when the view source action is activated. */
-    public signal void view_source();
-
     /** Fired when a internal link is activated */
     public signal void internal_link_activated(int y);
 
@@ -353,9 +350,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         add_action(ACTION_UNSTAR).activate.connect(() => {
                 mark_email(null, Geary.EmailFlags.FLAGGED);
             });
-        add_action(ACTION_VIEW_SOURCE).activate.connect(() => {
-                view_source();
-            });
+        add_action(ACTION_VIEW_SOURCE).activate.connect(on_view_source);
         insert_action_group("eml", message_actions);
 
         // Construct the view for the primary message, hook into it
@@ -807,6 +802,48 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         }
     }
 
+    private async void view_source() {
+        MainWindow? main = get_toplevel() as MainWindow;
+        if (main != null) {
+            Geary.Email email = this.email;
+            try {
+                yield Geary.Nonblocking.Concurrent.global.schedule_async(
+                    () => {
+                        string source = (
+                            email.header.buffer.to_string() +
+                            email.body.buffer.to_string()
+                        );
+                        string temporary_filename;
+                        int temporary_handle = GLib.FileUtils.open_tmp(
+                            "geary-message-XXXXXX.txt",
+                            out temporary_filename
+                        );
+                        GLib.FileUtils.set_contents(temporary_filename, source);
+                        GLib.FileUtils.close(temporary_handle);
+
+                        // ensure this file is only readable by the
+                        // user ... this needs to be done after the
+                        // file is closed
+                        GLib.FileUtils.chmod(
+                            temporary_filename,
+                            (int) (Posix.S_IRUSR | Posix.S_IWUSR)
+                        );
+
+                        string temporary_uri = GLib.Filename.to_uri(
+                            temporary_filename, null
+                        );
+                        main.application.show_uri.begin(temporary_uri);
+                    },
+                    null
+                );
+            } catch (GLib.Error error) {
+                main.application.controller.report_problem(
+                    new Geary.ProblemReport(error)
+                );
+            }
+        }
+    }
+
     private async void print() throws Error {
         Json.Builder builder = new Json.Builder();
         builder.begin_object();
@@ -959,6 +996,10 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         }
     }
 
+    private void on_view_source() {
+        this.view_source.begin();
+    }
+
     private void on_service_status_change() {
         if (this.message_body_state == FAILED &&
             !this.load_cancellable.is_cancelled() &&


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