[simple-scan] Remove duplicated method simple-scan.get_temporary_filename.



commit cecc96e739c577f25d6b075fc7bf92144fd76f7d
Author: Stéphane Fillion <stphanef3724 gmail com>
Date:   Thu Apr 27 10:34:09 2017 -0400

    Remove duplicated method simple-scan.get_temporary_filename.
    
    Removed SimpleScan.get_temporary_filename as it duplicated
    UserInterface.get_temporary_filename. The emailing document feature had
    to be moved from simple-scan.vala to ui.vala. Email signal is no longer
    needed, so is removed.

 src/simple-scan.vala |   88 --------------------------------------------------
 src/ui.vala          |   77 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 71 insertions(+), 94 deletions(-)
---
diff --git a/src/simple-scan.vala b/src/simple-scan.vala
index 2ab83f0..6e34677 100644
--- a/src/simple-scan.vala
+++ b/src/simple-scan.vala
@@ -49,7 +49,6 @@ public class SimpleScan : Gtk.Application
         book = ui.book;
         ui.start_scan.connect (scan_cb);
         ui.stop_scan.connect (cancel_cb);
-        ui.email.connect (email_cb);
 
         scanner = Scanner.get_instance ();
         scanner.update_devices.connect (update_scan_devices_cb);
@@ -412,93 +411,6 @@ public class SimpleScan : Gtk.Application
         scanner.cancel ();
     }
 
-    private string? get_temporary_filename (string prefix, string extension)
-    {
-        /* NOTE: I'm not sure if this is a 100% safe strategy to use g_file_open_tmp(), close and
-         * use the filename but it appears to work in practise */
-
-        var filename = "%sXXXXXX.%s".printf (prefix, extension);
-        string path;
-        try
-        {
-            var fd = FileUtils.open_tmp (filename, out path);
-            Posix.close (fd);
-        }
-        catch (Error e)
-        {
-            warning ("Error saving email attachment: %s", e.message);
-            return null;
-        }
-
-        return path;
-    }
-
-    private void email_cb (UserInterface ui, string profile, int quality)
-    {
-        var saved = false;
-        var command_line = "xdg-email";
-
-        /* Save text files as PDFs */
-        if (profile == "text")
-        {
-            /* Open a temporary file */
-            var path = get_temporary_filename ("scan", "pdf");
-            if (path != null)
-            {
-                var file = File.new_for_path (path);
-                ui.show_progress_dialog ();
-                try
-                {
-                    book.save ("pdf", quality, file);
-                }
-                catch (Error e)
-                {
-                    ui.hide_progress_dialog ();
-                    warning ("Unable to save email file: %s", e.message);
-                    return;
-                }
-                command_line += " --attach %s".printf (path);
-            }
-        }
-        else
-        {
-            for (var i = 0; i < book.n_pages; i++)
-            {
-                var path = get_temporary_filename ("scan", "jpg");
-                if (path == null)
-                {
-                    saved = false;
-                    break;
-                }
-
-                var file = File.new_for_path (path);
-                try
-                {
-                    book.get_page (i).save ("jpeg", quality, file);
-                }
-                catch (Error e)
-                {
-                    warning ("Unable to save email file: %s", e.message);
-                    return;
-                }
-                command_line += " --attach %s".printf (path);
-
-                if (!saved)
-                    break;
-            }
-        }
-
-        debug ("Launching email client: %s", command_line);
-        try
-        {
-            Process.spawn_command_line_async (command_line);
-        }
-        catch (Error e)
-        {
-            warning ("Unable to start email: %s", e.message);
-        }
-    }
-
     private static void log_cb (string? log_domain, LogLevelFlags log_level, string message)
     {
         string prefix;
diff --git a/src/ui.vala b/src/ui.vala
index 29b2169..ad008a2 100644
--- a/src/ui.vala
+++ b/src/ui.vala
@@ -268,7 +268,6 @@ public class UserInterface : Gtk.ApplicationWindow
 
     public signal void start_scan (string? device, ScanOptions options);
     public signal void stop_scan ();
-    public signal void email (string profile, int quality);
 
     public UserInterface ()
     {
@@ -1460,12 +1459,79 @@ public class UserInterface : Gtk.ApplicationWindow
     [GtkCallback]
     private void email_button_clicked_cb (Gtk.Widget widget)
     {
-        email (document_hint, quality);
+        email_document ();
     }
 
     public void email_document_activate_cb ()
     {
-        email (document_hint, quality);
+        email_document ();
+    }
+
+
+    private void email_document ()
+    {
+        var saved = false;
+        var command_line = "xdg-email";
+
+        /* Save text files as PDFs */
+        if (document_hint == "text")
+        {
+            /* Open a temporary file */
+            var path = get_temporary_filename ("scan", "pdf");
+            if (path != null)
+            {
+                var file = File.new_for_path (path);
+                show_progress_dialog ();
+                try
+                {
+                    book.save ("pdf", quality, file);
+                }
+                catch (Error e)
+                {
+                    hide_progress_dialog ();
+                    warning ("Unable to save email file: %s", e.message);
+                    return;
+                }
+                command_line += " --attach %s".printf (path);
+            }
+        }
+        else
+        {
+            for (var i = 0; i < book.n_pages; i++)
+            {
+                var path = get_temporary_filename ("scan", "jpg");
+                if (path == null)
+                {
+                    saved = false;
+                    break;
+                }
+
+                var file = File.new_for_path (path);
+                try
+                {
+                    book.get_page (i).save ("jpeg", quality, file);
+                }
+                catch (Error e)
+                {
+                    warning ("Unable to save email file: %s", e.message);
+                    return;
+                }
+                command_line += " --attach %s".printf (path);
+
+                if (!saved)
+                    break;
+            }
+        }
+
+        debug ("Launching email client: %s", command_line);
+        try
+        {
+            Process.spawn_command_line_async (command_line);
+        }
+        catch (Error e)
+        {
+            warning ("Unable to start email: %s", e.message);
+        }
     }
 
     private void print_document ()
@@ -2319,11 +2385,10 @@ private class ProgressBarDialog : Gtk.Window
     }
 }
 
-// FIXME: Duplicated from simple-scan.vala
 private string? get_temporary_filename (string prefix, string extension)
 {
     /* NOTE: I'm not sure if this is a 100% safe strategy to use g_file_open_tmp(), close and
-     * use the filename but it appears to work in practise */
+     * use the filename but it appears to work in practice */
 
     var filename = "%sXXXXXX.%s".printf (prefix, extension);
     string path;
@@ -2334,7 +2399,7 @@ private string? get_temporary_filename (string prefix, string extension)
     }
     catch (Error e)
     {
-        warning ("Error saving email attachment: %s", e.message);
+        warning ("Error creating temporary file: %s", e.message);
         return null;
     }
 


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