diff --git a/desktop/org.gnome.Geary.gschema.xml b/desktop/org.gnome.Geary.gschema.xml index 4bcd5d89..b747873d 100644 --- a/desktop/org.gnome.Geary.gschema.xml +++ b/desktop/org.gnome.Geary.gschema.xml @@ -2,6 +2,12 @@ + + '' + Default print output directory + Location used when printing to a file + + false maximize window @@ -121,6 +127,7 @@ Whether we migrated the old settings False to check for the old 'org.yorba.geary'-schema and copy its values + diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala index 060d3ef4..a492c7ce 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 434e8d49..a369ff38 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) {