From 1dfd5a1855d2ec2b30461287c3fc5500d5e8815e Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Mon, 6 Apr 2020 14:09:55 +1000 Subject: [PATCH] Plugin.FolderPluginContext: Support registering special use folders Add `register_folder_used_as` and `unregister_folder_used_as`, implement both `Application.FolderContextPlugin`. --- .../application-folder-plugin-context.vala | 31 +++++++++++++++++++ .../plugin/plugin-folder-extension.vala | 19 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/client/application/application-folder-plugin-context.vala b/src/client/application/application-folder-plugin-context.vala index 1031e958..c4994693 100644 --- a/src/client/application/application-folder-plugin-context.vala +++ b/src/client/application/application-folder-plugin-context.vala @@ -64,6 +64,37 @@ internal class Application.FolderPluginContext : } } + public void register_folder_used_as(Plugin.Folder target, + string name, + string icon_name) throws Plugin.Error { + var context = this.folders_factory.get_folder_context(target); + if (context != null) { + try { + context.folder.set_used_as_custom(true); + } catch (Geary.EngineError err) { + throw new Plugin.Error.NOT_SUPPORTED( + "Failed to register folder use: %s", err.message + ); + } + context.display_name = name; + context.icon_name = icon_name; + } + } + + public void unregister_folder_used_as(Plugin.Folder target) + throws Plugin.Error { + var context = this.folders_factory.get_folder_context(target); + if (context != null) { + try { + context.folder.set_used_as_custom(false); + } catch (Geary.EngineError err) { + throw new Plugin.Error.NOT_SUPPORTED( + "Failed to unregister folder use: %s", err.message + ); + } + } + } + internal void destroy() { this.folders_factory.destroy_folder_store(this.folders); } diff --git a/src/client/plugin/plugin-folder-extension.vala b/src/client/plugin/plugin-folder-extension.vala index c90f0283..66b66df5 100644 --- a/src/client/plugin/plugin-folder-extension.vala +++ b/src/client/plugin/plugin-folder-extension.vala @@ -75,4 +75,23 @@ public interface Plugin.FolderContext : Geary.BaseObject { public abstract void remove_folder_info_bar(Folder selected, InfoBar infobar); + /** + * Registers a folder for a well-known use. + * + * This promotes a folder from a label to a special-use folder, + * causing it to appear with other special-use folders with the + * given name and icon. + */ + public abstract void register_folder_used_as(Folder target, + string name, + string icon_name) throws Error; + + /** + * Unregisters a folder for a well-known use. + * + * This demotes the folder from a special-use to an ordinary + * label. + */ + public abstract void unregister_folder_used_as(Folder target) throws Error; + }