[geary/mjog/mail-merge-plugin: 70/71] Plugin.MailMerge: Register folder with the engine rather than client




commit 096d6cb93927822249e4d26aae258411d7820d8b
Author: Michael Gratton <mike vee net>
Date:   Wed Aug 5 14:56:07 2020 +1000

    Plugin.MailMerge: Register folder with the engine rather than client
    
    Use new support for registering local folders with the engine to do
    just that for the merge folder, allowing the conversation monitor to
    successfully load and display email in the folder.

 .../plugin/mail-merge/mail-merge-folder.vala       | 15 ++++----
 src/client/plugin/mail-merge/mail-merge.vala       | 40 ++++++++++++++++------
 2 files changed, 37 insertions(+), 18 deletions(-)
---
diff --git a/src/client/plugin/mail-merge/mail-merge-folder.vala 
b/src/client/plugin/mail-merge/mail-merge-folder.vala
index c07e009f9..ea8903790 100644
--- a/src/client/plugin/mail-merge/mail-merge-folder.vala
+++ b/src/client/plugin/mail-merge/mail-merge-folder.vala
@@ -108,14 +108,11 @@ public class Plugin.MailMergeFolder : Geary.AbstractLocalFolder {
     }
     private Geary.FolderPath _path;
 
-    /**
-     * {@inheritDoc}
-     *
-     * This is always {@link Folder.SpecialUse.CUSTOM}
-     */
+    /** {@inheritDoc} */
     public override Geary.Folder.SpecialUse used_as {
-        get { return CUSTOM; }
+        get { return this._used_as; }
     }
+    Geary.Folder.SpecialUse _used_as = NONE;
 
     private Gee.Map<Geary.EmailIdentifier,Geary.Email> map =
         new Gee.HashMap<Geary.EmailIdentifier,Geary.Email>();
@@ -237,8 +234,10 @@ public class Plugin.MailMergeFolder : Geary.AbstractLocalFolder {
 
     public override void set_used_as_custom(bool enabled)
         throws Geary.EngineError.UNSUPPORTED {
-        throw new Geary.EngineError.UNSUPPORTED(
-            "Folder special use cannot be changed"
+        this._used_as = (
+            enabled
+            ? Geary.Folder.SpecialUse.CUSTOM
+            : Geary.Folder.SpecialUse.NONE
         );
     }
 
diff --git a/src/client/plugin/mail-merge/mail-merge.vala b/src/client/plugin/mail-merge/mail-merge.vala
index a30818bad..8797ae811 100644
--- a/src/client/plugin/mail-merge/mail-merge.vala
+++ b/src/client/plugin/mail-merge/mail-merge.vala
@@ -65,6 +65,8 @@ public class Plugin.MailMerge :
     private FolderStore? folder_store = null;
     private EmailStore? email_store = null;
 
+    private MailMergeFolder? merge_folder = null;
+
     private GLib.SimpleAction? edit_action = null;
     private GLib.SimpleAction? merge_action = null;
 
@@ -84,6 +86,7 @@ public class Plugin.MailMerge :
         ).add_all_to(this.folder_names);
 
         this.folder_store = yield this.folders.get_folder_store();
+        this.folder_store.folders_available.connect(on_folders_available);
 
         this.email_store = yield this.email.get_email_store();
         this.email_store.email_displayed.connect(on_email_displayed);
@@ -191,24 +194,18 @@ public class Plugin.MailMerge :
                         id.account
                     );
                     var email = Geary.Collection.first(emails);
-                    var merge_folder = new Plugin.MailMergeFolder(
+                    this.merge_folder = new Plugin.MailMergeFolder(
                         account_context.account,
                         account_context.account.local_folder_root,
                         this.client_plugins.to_engine_email(email),
                         csv
                     );
 
-                    var folder_context = new global::Application.FolderContext(
-                        merge_folder
-                    );
-                    folder_context.display_name = _("Mail Merge");
-                    folder_context.icon_name = "mail-outbox-symbolic";
-                    account_context.add_folders(
-                        Geary.Collection.single(folder_context)
+                    account_context.account.register_local_folder(
+                        this.merge_folder
                     );
-
                     var main = this.client_application.get_active_main_window();
-                    yield main.select_folder(merge_folder, true);
+                    yield main.select_folder(this.merge_folder, true);
                 }
             } catch (GLib.Error err) {
                 debug("Displaying merge folder failed: %s", err.message);
@@ -416,6 +413,29 @@ public class Plugin.MailMerge :
         this.update_composer.begin(registered);
     }
 
+    private void on_folders_available(Gee.Collection<Folder> available) {
+        foreach (var folder in available) {
+            var engine_folder = this.client_plugins.to_engine_folder(folder);
+            if (this.merge_folder == engine_folder) {
+                try {
+                    this.folders.register_folder_used_as(
+                        folder,
+                        // Translators: The name of the folder used to
+                        // display merged email
+                        _("Mail Merge"),
+                        "mail-outbox-symbolic"
+                    );
+                } catch (GLib.Error err) {
+                    warning(
+                        "Failed to register %s as merge folder: %s",
+                        folder.persistent_id,
+                        err.message
+                    );
+                }
+            }
+        }
+    }
+
     private void on_email_displayed(Email email) {
         this.update_email.begin(email);
     }


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