[geary/mjog/folder-actions: 1/7] plugins: Add support for folder plugins



commit 254d10782c13c8f6e1c75c7dda1e2402bc255318
Author: Michael Gratton <mike vee net>
Date:   Wed Mar 18 18:51:42 2020 +1100

    plugins: Add support for folder plugins
    
    Add new Plugin.FolderExtension plugin extenion interface, context
    object and context object implementation. Populate the context object
    when plugins implementing the extension are loaded, and destroy it
    on unload.

 po/POTFILES.in                                     |  2 +
 .../application/application-folder-context.vala    | 36 +++++++++++++++
 .../application/application-plugin-manager.vala    | 16 +++++++
 src/client/meson.build                             |  2 +
 src/client/plugin/plugin-folder-extension.vala     | 53 ++++++++++++++++++++++
 5 files changed, 109 insertions(+)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2859b0c0..9b29d4d7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -23,6 +23,7 @@ src/client/application/application-configuration.vala
 src/client/application/application-contact-store.vala
 src/client/application/application-contact.vala
 src/client/application/application-controller.vala
+src/client/application/application-folder-context.vala
 src/client/application/application-folder-store-factory.vala
 src/client/application/application-main-window.vala
 src/client/application/application-notification-context.vala
@@ -92,6 +93,7 @@ src/client/plugin/plugin-contact-store.vala
 src/client/plugin/plugin-email-store.vala
 src/client/plugin/plugin-email.vala
 src/client/plugin/plugin-error.vala
+src/client/plugin/plugin-folder-extension.vala
 src/client/plugin/plugin-folder-store.vala
 src/client/plugin/plugin-folder.vala
 src/client/plugin/plugin-notification-extension.vala
diff --git a/src/client/application/application-folder-context.vala 
b/src/client/application/application-folder-context.vala
new file mode 100644
index 00000000..28209afa
--- /dev/null
+++ b/src/client/application/application-folder-context.vala
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2020 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+/**
+ * Implementation of the folder extension context.
+ */
+internal class Application.FolderContext :
+    Geary.BaseObject, Plugin.FolderContext {
+
+
+    private unowned Client application;
+    private FolderStoreFactory folders_factory;
+    private Plugin.FolderStore folders;
+
+
+    internal FolderContext(Client application,
+                           FolderStoreFactory folders_factory) {
+        this.application = application;
+        this.folders_factory = folders_factory;
+        this.folders = folders_factory.new_folder_store();
+    }
+
+    public async Plugin.FolderStore get_folders()
+        throws Plugin.Error.PERMISSION_DENIED {
+        return this.folders;
+    }
+
+    internal void destroy() {
+        this.folders_factory.destroy_folder_store(this.folders);
+    }
+
+}
diff --git a/src/client/application/application-plugin-manager.vala 
b/src/client/application/application-plugin-manager.vala
index 180075eb..829d673c 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -231,6 +231,14 @@ public class Application.PluginManager : GLib.Object {
                 notification.notifications = context;
             }
 
+            var folder = plugin as Plugin.FolderExtension;
+            if (folder != null) {
+                folder.folders = new FolderContext(
+                    this.application,
+                    this.folders_factory
+                );
+            }
+
             if (do_activate) {
                 var plugin_context = new PluginContext(info, plugin);
                 plugin_context.activate.begin((obj, res) => {
@@ -296,6 +304,14 @@ public class Application.PluginManager : GLib.Object {
             }
         }
 
+        var folder = context.plugin as Plugin.FolderExtension;
+        if (folder != null) {
+            var folders = folder.folders as FolderContext;
+            if (folders != null) {
+                folders.destroy();
+            }
+        }
+
         plugin_deactivated(context.info, error);
         this.plugin_set.unset(context.info);
     }
diff --git a/src/client/meson.build b/src/client/meson.build
index 1ab46740..02a7eb9b 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -10,6 +10,7 @@ geary_client_vala_sources = files(
   'application/application-contact-store.vala',
   'application/application-contact.vala',
   'application/application-controller.vala',
+  'application/application-folder-context.vala',
   'application/application-folder-store-factory.vala',
   'application/application-main-window.vala',
   'application/application-notification-context.vala',
@@ -101,6 +102,7 @@ geary_client_vala_sources = files(
   'plugin/plugin-email-store.vala',
   'plugin/plugin-email.vala',
   'plugin/plugin-error.vala',
+  'plugin/plugin-folder-extension.vala',
   'plugin/plugin-folder-store.vala',
   'plugin/plugin-folder.vala',
   'plugin/plugin-notification-extension.vala',
diff --git a/src/client/plugin/plugin-folder-extension.vala b/src/client/plugin/plugin-folder-extension.vala
new file mode 100644
index 00000000..fc5ac372
--- /dev/null
+++ b/src/client/plugin/plugin-folder-extension.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2020 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+/**
+ * A plugin extension point for working with folders.
+ */
+public interface Plugin.FolderExtension : PluginBase {
+
+    /**
+     * Context object for accessing folders.
+     *
+     * This will be set during (or just after) plugin construction,
+     * before {@link PluginBase.activate} is called.
+     */
+    public abstract FolderContext folders {
+        get; set construct;
+    }
+
+}
+
+
+// XXX this should be an inner interface of FolderExtension, but
+// GNOME/vala#918 prevents that.
+
+/**
+ * Provides a context for folder plugins.
+ *
+ * The context provides an interface for folder plugins to
+ * interface with the Geary client application. Plugins that implement
+ * the plugins will be passed an instance of this class as the
+ * `context` property.
+ *
+ * @see Plugin.FolderExtension.folders
+ */
+public interface Plugin.FolderContext : Geary.BaseObject {
+
+
+    /**
+     * Returns a store to lookup folders.
+     *
+     * This method may prompt for permission before returning.
+     *
+     * @throws Error.PERMISSIONS if permission to access
+     * this resource was not given
+     */
+    public abstract async FolderStore get_folders()
+        throws Error.PERMISSION_DENIED;
+
+}


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