[geary] Remember print dir and reuse when printing again. Bug 713573.



commit 7787af3aac5fc3fbf549aa80ab5f6877303abf98
Author: Michael James Gratton <mike vee net>
Date:   Fri Feb 24 11:49:05 2017 +1100

    Remember print dir and reuse when printing again. Bug 713573.
    
    * src/client/conversation-viewer/conversation-email.vala
      (ConversationEmail): Save config object as a class field, use that to
      get and set the print directory when printing. Also set the default
      print filename based on the email's subject.

 desktop/org.gnome.Geary.gschema.xml                |    7 ++++
 src/client/application/geary-config.vala           |    6 ++++
 .../conversation-viewer/conversation-email.vala    |   30 +++++++++++++++++++-
 3 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/desktop/org.gnome.Geary.gschema.xml b/desktop/org.gnome.Geary.gschema.xml
index 4bcd5d8..b747873 100644
--- a/desktop/org.gnome.Geary.gschema.xml
+++ b/desktop/org.gnome.Geary.gschema.xml
@@ -2,6 +2,12 @@
 
 <schema id="org.gnome.Geary" path="/org/gnome/Geary/">
 
+    <key name="print-directory" type="s">
+        <default>''</default>
+        <summary>Default print output directory</summary>
+        <description>Location used when printing to a file</description>
+    </key>
+
     <key name="window-maximize" type="b">
         <default>false</default>
         <summary>maximize window</summary>
@@ -121,6 +127,7 @@
         <summary>Whether we migrated the old settings</summary>
         <description>False to check for the old 'org.yorba.geary'-schema and copy its values</description>
     </key>
+
 </schema>
 
 </schemalist>
diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala
index 060d3ef..a492c7c 100644
--- a/src/client/application/geary-config.vala
+++ b/src/client/application/geary-config.vala
@@ -9,6 +9,7 @@
  */
 public class Configuration {
 
+    public const string PRINT_DIR_KEY = "print-directory";
     public const string WINDOW_WIDTH_KEY = "window-width";
     public const string WINDOW_HEIGHT_KEY = "window-height";
     public const string WINDOW_MAXIMIZE_KEY = "window-maximize";
@@ -62,6 +63,11 @@ public class Configuration {
         }
     }
 
+    public string? print_dir {
+        owned get { return settings.get_string(PRINT_DIR_KEY); }
+        set { settings.set_string(PRINT_DIR_KEY, value); }
+    }
+
     public int window_width {
         get { return settings.get_int(WINDOW_WIDTH_KEY); }
     }
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index 434e8d4..a369ff3 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -260,6 +260,8 @@ public class ConversationEmail : Gtk.Box {
     // Contacts for the email's account
     private Geary.ContactStore contact_store;
 
+    private Configuration config;
+
     // Message view with selected text, if any
     private ConversationMessage? body_selection_message = null;
 
@@ -363,6 +365,7 @@ public class ConversationEmail : Gtk.Box {
                              bool is_draft) {
         this.email = email;
         this.contact_store = contact_store;
+        this.config = config;
 
         if (is_sent) {
             get_style_context().add_class(SENT_CLASS);
@@ -736,12 +739,37 @@ public class ConversationEmail : Gtk.Box {
     private void print() {
         // XXX This isn't anywhere near good enough - headers aren't
         // being printed.
+
+        Gtk.Window? window = get_toplevel() as Gtk.Window;
         WebKit.PrintOperation op = new WebKit.PrintOperation(
             this.primary_message.web_view
         );
-        Gtk.Window? window = get_toplevel() as Gtk.Window;
+        Gtk.PrintSettings settings = new Gtk.PrintSettings();
+
+        if (!Geary.String.is_empty(this.config.print_dir)) {
+            settings.set(Gtk.PRINT_SETTINGS_OUTPUT_DIR, this.config.print_dir);
         }
+
+        if (this.email.subject != null) {
+            string file_name = Geary.String.reduce_whitespace(this.email.subject.value);
+            file_name = file_name.replace("/", "_");
+            if (file_name.char_count() > 128) {
+                file_name = Geary.String.safe_byte_substring(file_name, 128);
+            }
+
+            if (!Geary.String.is_empty(file_name)) {
+                settings.set(Gtk.PRINT_SETTINGS_OUTPUT_BASENAME, file_name);
+            }
+        }
+
+        op.set_print_settings(settings);
         op.run_dialog(window);
+
+        string? file_uri = op.get_print_settings().get(Gtk.PRINT_SETTINGS_OUTPUT_URI);
+        if (!Geary.String.is_empty(file_uri)) {
+            File print_file = File.new_for_uri(file_uri);
+            this.config.print_dir = print_file.get_parent().get_path();
+        }
     }
 
     private void on_flag_remote_images(ConversationMessage view) {


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