[geary/mjog/email-templates: 13/15] Plugin.Composer: Support specifying a folder to save email



commit a576b78d29097e036a784d5bd4d9bc04fcf10988
Author: Michael Gratton <mike vee net>
Date:   Mon Apr 20 23:50:53 2020 +1000

    Plugin.Composer: Support specifying a folder to save email

 .../application/application-plugin-manager.vala    | 43 ++++++++++++++++++----
 src/client/plugin/plugin-composer.vala             | 10 +++++
 2 files changed, 45 insertions(+), 8 deletions(-)
---
diff --git a/src/client/application/application-plugin-manager.vala 
b/src/client/application/application-plugin-manager.vala
index 765af474..4db5fa5b 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -73,7 +73,9 @@ public class Application.PluginManager : GLib.Object {
             if (impl == null) {
                 throw new Plugin.Error.NOT_SUPPORTED("Not a valid account");
             }
-            return new ComposerImpl(this.backing, impl.backing, this.email);
+            return new ComposerImpl(
+                this.backing, impl.backing, this.folders, this.email
+            );
         }
 
         public void register_action(GLib.Action action) {
@@ -178,26 +180,24 @@ public class Application.PluginManager : GLib.Object {
 
         private Client application;
         private AccountContext account;
+        private FolderStoreFactory folders;
         private EmailStoreFactory email;
         private Geary.Email? to_load = null;
+        private Geary.Folder? save_location = null;
 
 
         public ComposerImpl(Client application,
                             AccountContext account,
+                            FolderStoreFactory folders,
                             EmailStoreFactory email) {
             this.application = application;
             this.account = account;
+            this.folders = folders;
             this.email = email;
         }
 
         public void show() {
-            if (this.to_load == null) {
-                this.application.controller.compose_new_email.begin();
-            } else {
-                this.application.controller.compose_with_context_email.begin(
-                    EDIT, this.to_load, null
-                );
-            }
+            this.show_impl.begin();
         }
 
         public async void edit_email(Plugin.EmailIdentifier to_load)
@@ -217,6 +217,33 @@ public class Application.PluginManager : GLib.Object {
                 this.to_load = Geary.Collection.first(email);
             }
         }
+
+        public void save_to_folder(Plugin.Folder? location) {
+            var folder = this.folders.get_engine_folder(location);
+            if (folder != null && folder.account == this.account.account) {
+                this.save_location = folder;
+            }
+        }
+
+        private async void show_impl() {
+            var controller = this.application.controller;
+            Composer.Widget? composer = null;
+            if (this.to_load == null) {
+                composer = yield controller.compose_new_email(
+                    null,
+                    this.save_location
+                );
+            } else {
+                composer = yield controller.compose_with_context_email(
+                    EDIT,
+                    this.to_load,
+                    null,
+                    this.save_location
+                );
+            }
+            //composer.can_send = this.can_send;
+        }
+
     }
 
 
diff --git a/src/client/plugin/plugin-composer.vala b/src/client/plugin/plugin-composer.vala
index c6980a64..9635f39b 100644
--- a/src/client/plugin/plugin-composer.vala
+++ b/src/client/plugin/plugin-composer.vala
@@ -32,4 +32,14 @@ public interface Plugin.Composer : Geary.BaseObject {
     public async abstract void edit_email(EmailIdentifier to_load)
         throws GLib.Error;
 
+    /**
+     * Sets the folder used to save the message being composed.
+     *
+     * Ensures email for both automatic and manual saving of the email
+     * in the composer is saved to the given folder. This must be
+     * called before calling {@link show}, and has no effect if called
+     * afterwards.
+     */
+    public abstract void save_to_folder(Plugin.Folder? location);
+
 }


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