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.
This commit is contained in:
parent
1f54f11715
commit
254d10782c
5 changed files with 109 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
36
src/client/application/application-folder-context.vala
Normal file
36
src/client/application/application-folder-context.vala
Normal file
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
53
src/client/plugin/plugin-folder-extension.vala
Normal file
53
src/client/plugin/plugin-folder-extension.vala
Normal file
|
|
@ -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;
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue