[geary] Remember attachments dir and reuse adding/saving attachments and images.



commit 527399be76d9a97de87f2f33a3ac19cbb1fd6900
Author: Michael James Gratton <mike vee net>
Date:   Fri Feb 24 12:06:42 2017 +1100

    Remember attachments dir and reuse adding/saving attachments and images.
    
    * src/client/application/geary-controller.vala (GearyController): Replace
      use of last_save_directory with new attachments_dir property on the
      configuration object.
    
    * src/client/dialogs/attachment-dialog.vala (AttachmentDialog): Replace
      current_folder with use of last_save_directory with new attachments_dir
      property on the configuration object. Add config object as ctor param
      and object field, update call sites.

 desktop/org.gnome.Geary.gschema.xml          |    6 +++
 src/client/application/geary-config.vala     |    6 +++
 src/client/application/geary-controller.vala |   10 +++---
 src/client/composer/composer-widget.vala     |    5 ++-
 src/client/dialogs/attachment-dialog.vala    |   46 +++++++++++++++-----------
 5 files changed, 47 insertions(+), 26 deletions(-)
---
diff --git a/desktop/org.gnome.Geary.gschema.xml b/desktop/org.gnome.Geary.gschema.xml
index b747873..17147f4 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="attachments-directory" type="s">
+        <default>''</default>
+        <summary>Default attachments directory</summary>
+        <description>Location used when opening and saving attachments</description>
+    </key>
+
     <key name="print-directory" type="s">
         <default>''</default>
         <summary>Default print output directory</summary>
diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala
index a492c7c..f83b4de 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 ATTACHMENTS_DIR_KEY = "attachments-directory";
     public const string PRINT_DIR_KEY = "print-directory";
     public const string WINDOW_WIDTH_KEY = "window-width";
     public const string WINDOW_HEIGHT_KEY = "window-height";
@@ -63,6 +64,11 @@ public class Configuration {
         }
     }
 
+    public string? attachments_dir {
+        owned get { return settings.get_string(ATTACHMENTS_DIR_KEY); }
+        set { settings.set_string(ATTACHMENTS_DIR_KEY, value); }
+    }
+
     public string? print_dir {
         owned get { return settings.get_string(PRINT_DIR_KEY); }
         set { settings.set_string(PRINT_DIR_KEY, value); }
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index f9359f2..896084a 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -112,7 +112,6 @@ public class GearyController : Geary.BaseObject {
     private Gee.Set<Geary.App.Conversation> selected_conversations = new 
Gee.HashSet<Geary.App.Conversation>();
     private Geary.App.Conversation? last_deleted_conversation = null;
     private Gee.LinkedList<ComposerWidget> composer_widgets = new Gee.LinkedList<ComposerWidget>();
-    private File? last_save_directory = null;
     private NewMessagesMonitor? new_messages_monitor = null;
     private NewMessagesIndicator? new_messages_indicator = null;
     private UnityLauncher? unity_launcher = null;
@@ -2079,7 +2078,7 @@ public class GearyController : Geary.BaseObject {
             return;
         
         File dest_dir = File.new_for_path(filename);
-        this.last_save_directory = dest_dir;
+        this.application.config.attachments_dir = dest_dir.get_path();
 
         debug("Saving attachments to %s", dest_dir.get_path());
 
@@ -2124,7 +2123,7 @@ public class GearyController : Geary.BaseObject {
 
         if (accepted && !Geary.String.is_empty(accepted_filename)) {
             File destination = File.new_for_path(accepted_filename);
-            this.last_save_directory = destination.get_parent();
+            this.application.config.attachments_dir = destination.get_parent().get_path();
             yield write_buffer_to_file(buffer, destination);
         }
     }
@@ -2173,8 +2172,9 @@ public class GearyController : Geary.BaseObject {
             null
         );
 #endif
-        if (this.last_save_directory != null)
-            dialog.set_current_folder(this.last_save_directory.get_path());
+        string? dir = this.application.config.attachments_dir;
+        if (!Geary.String.is_empty(dir))
+            dialog.set_current_folder(dir);
         dialog.set_create_folders(true);
         dialog.set_local_only(false);
         return dialog;
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 3d356e4..d65b3cb 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -2216,7 +2216,7 @@ public class ComposerWidget : Gtk.EventBox {
     }
 
     private void on_add_attachment() {
-        AttachmentDialog dialog = new AttachmentDialog(this.container.top_window);
+        AttachmentDialog dialog = new AttachmentDialog(this.container.top_window, this.config);
         if (dialog.run() == Gtk.ResponseType.ACCEPT) {
             dialog.hide();
             foreach (File file in dialog.get_files()) {
@@ -2227,6 +2227,7 @@ public class ComposerWidget : Gtk.EventBox {
                     break;
                 }
             }
+
         }
         dialog.destroy();
     }
@@ -2236,7 +2237,7 @@ public class ComposerWidget : Gtk.EventBox {
     }
 
     private void on_insert_image(SimpleAction action, Variant? param) {
-        AttachmentDialog dialog = new AttachmentDialog(this.container.top_window);
+        AttachmentDialog dialog = new AttachmentDialog(this.container.top_window, this.config);
         Gtk.FileFilter filter = new Gtk.FileFilter();
         // Translators: This is the name of the file chooser filter
         // when inserting an image in the composer.
diff --git a/src/client/dialogs/attachment-dialog.vala b/src/client/dialogs/attachment-dialog.vala
index 80d455d..ecf1d68 100644
--- a/src/client/dialogs/attachment-dialog.vala
+++ b/src/client/dialogs/attachment-dialog.vala
@@ -5,40 +5,44 @@
  */
 
 public class AttachmentDialog : Object {
+
+    private const int PREVIEW_SIZE = 180;
+    private const int PREVIEW_PADDING = 3;
+
+    private Configuration config;
+
 #if GTK_3_20
     private Gtk.FileChooserNative? chooser = null;
 #else
     private Gtk.FileChooserDialog? chooser = null;
 #endif
-    private const int PREVIEW_SIZE = 180;
-    private const int PREVIEW_PADDING = 3;
-    
-    private static string? current_folder = null;
-    
-    private Gtk.Image preview_image;
-    
+
+    private Gtk.Image preview_image = new Gtk.Image();
+
     public delegate bool Attacher(File attachment_file, bool alert_errors = true);
 
-    public AttachmentDialog(Gtk.Window? parent) {
+    public AttachmentDialog(Gtk.Window? parent, Configuration config) {
+        this.config = config;
+
 #if GTK_3_20
-        chooser = new Gtk.FileChooserNative(_("Choose a file"), parent, Gtk.FileChooserAction.OPEN, 
_("_Attach"), Stock._CANCEL);
+        this.chooser = new Gtk.FileChooserNative(_("Choose a file"), parent, Gtk.FileChooserAction.OPEN, 
_("_Attach"), Stock._CANCEL);
 #else
-        chooser = new Gtk.FileChooserDialog(_("Choose a file"), parent, Gtk.FileChooserAction.OPEN, 
Stock._CANCEL, Gtk.ResponseType.CANCEL, _("_Attach"), Gtk.ResponseType.ACCEPT);
+        this.chooser = new Gtk.FileChooserDialog(_("Choose a file"), parent, Gtk.FileChooserAction.OPEN, 
Stock._CANCEL, Gtk.ResponseType.CANCEL, _("_Attach"), Gtk.ResponseType.ACCEPT);
 #endif
 
-        if (!Geary.String.is_empty(current_folder)) {
-            chooser.set_current_folder(current_folder);
+        string? dir = config.attachments_dir;
+        if (!Geary.String.is_empty(dir)) {
+            this.chooser.set_current_folder(dir);
         }
-        chooser.set_local_only(false);
-        chooser.set_select_multiple(true);
+        this.chooser.set_local_only(false);
+        this.chooser.set_select_multiple(true);
 
         // preview widget is not supported on Win32 (this will fallback to gtk file chooser)
         // and possibly by some org.freedesktop.portal.FileChooser (preview will be ignored).
-        preview_image = new Gtk.Image();
-        chooser.set_preview_widget(preview_image);
-        chooser.use_preview_label = false;
+        this.chooser.set_preview_widget(this.preview_image);
+        this.chooser.use_preview_label = false;
 
-        chooser.update_preview.connect(on_update_preview);
+        this.chooser.update_preview.connect(on_update_preview);
     }
 
     // XXX Once we depend on GTK+ 3.20 as a minimum, convert this
@@ -54,7 +58,11 @@ public class AttachmentDialog : Object {
     }
 
     public int run() {
-        return this.chooser.run();
+        int response = this.chooser.run();
+        if (response == Gtk.ResponseType.ACCEPT) {
+            this.config.attachments_dir = this.chooser.get_current_folder();
+        }
+        return response;
     }
 
     public void hide() {


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