[geary/mjog/user-plugins: 24/26] Replace FolderList.Tree mail hooks with plugin
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/user-plugins: 24/26] Replace FolderList.Tree mail hooks with plugin
- Date: Tue, 17 Mar 2020 08:26:15 +0000 (UTC)
commit c72ce8d8daacade2f882a6cdcebbc444aaea08fb
Author: Michael Gratton <mike vee net>
Date: Wed Mar 11 12:21:30 2020 +1100
Replace FolderList.Tree mail hooks with plugin
Using a plugin to manage folder new mail highlighting so it works in the
same way as for other notifications.
po/POTFILES.in | 2 +
.../application/application-plugin-manager.vala | 1 +
src/client/folder-list/folder-list-tree.vala | 14 ----
.../folder-highlight/folder-highlight.plugin.in | 4 +
.../plugin/folder-highlight/folder-highlight.vala | 95 ++++++++++++++++++++++
src/client/plugin/folder-highlight/meson.build | 26 ++++++
src/client/plugin/meson.build | 1 +
7 files changed, 129 insertions(+), 14 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 10fdcaf5..2b5df3fd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -97,6 +97,8 @@ src/client/plugin/plugin-plugin-base.vala
src/client/plugin/plugin-trusted-etension.vala
src/client/plugin/desktop-notifications/desktop-notifications.plugin.in
src/client/plugin/desktop-notifications/desktop-notifications.vala
+src/client/plugin/folder-highlight/folder-highlight.plugin.in
+src/client/plugin/folder-highlight/folder-highlight.vala
src/client/plugin/messaging-menu/messaging-menu.plugin.in
src/client/plugin/messaging-menu/messaging-menu.vala
src/client/plugin/notification-badge/notification-badge.plugin.in
diff --git a/src/client/application/application-plugin-manager.vala
b/src/client/application/application-plugin-manager.vala
index bc2e809f..180075eb 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -15,6 +15,7 @@ public class Application.PluginManager : GLib.Object {
// application stats up
private const string[] AUTOLOAD_MODULES = {
"desktop-notifications",
+ "folder-highlight",
"notification-badge",
};
diff --git a/src/client/folder-list/folder-list-tree.vala b/src/client/folder-list/folder-list-tree.vala
index 372ef90b..bd562eac 100644
--- a/src/client/folder-list/folder-list-tree.vala
+++ b/src/client/folder-list/folder-list-tree.vala
@@ -14,11 +14,6 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
private const int INBOX_ORDINAL = -2; // First account branch is zero
private const int SEARCH_ORDINAL = -1;
- private const Geary.SpecialFolderType[] INTERESTING_FOLDERS = {
- INBOX,
- NONE
- };
-
public signal void folder_selected(Geary.Folder? folder);
public signal void copy_conversation(Geary.Folder folder);
@@ -113,7 +108,6 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
inboxes_branch.add_inbox(folder);
- folder.email_locally_appended.connect(on_email_appended);
account_branch.add_folder(folder);
}
@@ -141,7 +135,6 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
inboxes_branch.remove_inbox(folder.account);
- folder.email_locally_appended.disconnect(on_email_appended);
account_branch.remove_folder(folder);
}
@@ -269,11 +262,4 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
graft(branch, branch.account.information.ordinal);
}
- private void on_email_appended(Geary.Folder folder,
- Gee.Collection<Geary.EmailIdentifier> ids) {
- if (folder.special_folder_type in INTERESTING_FOLDERS) {
- set_has_new(folder, true);
- }
- }
-
}
diff --git a/src/client/plugin/folder-highlight/folder-highlight.plugin.in
b/src/client/plugin/folder-highlight/folder-highlight.plugin.in
new file mode 100644
index 00000000..f0ca9f97
--- /dev/null
+++ b/src/client/plugin/folder-highlight/folder-highlight.plugin.in
@@ -0,0 +1,4 @@
+[Plugin]
+Module=folder-highlight
+Name=Folder Highlight
+Description=Highlights folders that have newly delivered mail
diff --git a/src/client/plugin/folder-highlight/folder-highlight.vala
b/src/client/plugin/folder-highlight/folder-highlight.vala
new file mode 100644
index 00000000..398a1622
--- /dev/null
+++ b/src/client/plugin/folder-highlight/folder-highlight.vala
@@ -0,0 +1,95 @@
+/*
+ * Copyright © 2016 Software Freedom Conservancy Inc.
+ * Copyright © 2019-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.
+ */
+
+[ModuleInit]
+public void peas_register_types(TypeModule module) {
+ Peas.ObjectModule obj = module as Peas.ObjectModule;
+ obj.register_extension_type(
+ typeof(Plugin.PluginBase),
+ typeof(Plugin.FolderHighlight)
+ );
+}
+
+/**
+ * Manages highlighting folders that have newly delivered mail
+ */
+public class Plugin.FolderHighlight :
+ PluginBase, NotificationExtension, TrustedExtension {
+
+
+ private const Geary.SpecialFolderType[] MONITORED_TYPES = {
+ INBOX, NONE
+ };
+
+
+ public NotificationContext notifications {
+ get; construct set;
+ }
+
+ public global::Application.Client client_application {
+ get; construct set;
+ }
+
+ public global::Application.PluginManager client_plugins {
+ get; construct set;
+ }
+
+ public override async void activate() throws GLib.Error {
+ this.notifications.new_messages_arrived.connect(on_new_messages_arrived);
+ this.notifications.new_messages_retired.connect(on_new_messages_retired);
+
+ FolderStore folders = yield this.notifications.get_folders();
+ folders.folders_available.connect(
+ (folders) => check_folders(folders)
+ );
+ folders.folders_unavailable.connect(
+ (folders) => check_folders(folders)
+ );
+ folders.folders_type_changed.connect(
+ (folders) => check_folders(folders)
+ );
+ check_folders(folders.get_folders());
+ }
+
+ public override async void deactivate(bool is_shutdown) throws GLib.Error {
+ // no-op
+ }
+
+ private void check_folders(Gee.Collection<Folder> folders) {
+ foreach (Folder folder in folders) {
+ if (folder.folder_type in MONITORED_TYPES) {
+ this.notifications.start_monitoring_folder(folder);
+ } else {
+ this.notifications.stop_monitoring_folder(folder);
+ }
+ }
+ }
+
+ private void on_new_messages_arrived(Folder folder,
+ int total,
+ Gee.Collection<EmailIdentifier> added) {
+ Geary.Folder? engine = this.client_plugins.get_engine_folder(folder);
+ if (engine != null) {
+ foreach (global::Application.MainWindow window
+ in this.client_application.get_main_windows()) {
+ window.folder_list.set_has_new(engine, true);
+ }
+ }
+ }
+
+ private void on_new_messages_retired(Folder folder, int total) {
+ Geary.Folder? engine = this.client_plugins.get_engine_folder(folder);
+ if (engine != null) {
+ foreach (global::Application.MainWindow window
+ in this.client_application.get_main_windows()) {
+ window.folder_list.set_has_new(engine, false);
+ }
+ }
+ }
+
+}
diff --git a/src/client/plugin/folder-highlight/meson.build b/src/client/plugin/folder-highlight/meson.build
new file mode 100644
index 00000000..44ed29a2
--- /dev/null
+++ b/src/client/plugin/folder-highlight/meson.build
@@ -0,0 +1,26 @@
+
+plugin_name = 'folder-highlight'
+
+plugin_src = join_paths(plugin_name + '.vala')
+plugin_data = join_paths(plugin_name + '.plugin')
+plugin_dest = join_paths(plugins_dir, plugin_name)
+
+shared_module(
+ plugin_name,
+ sources: plugin_src,
+ dependencies: plugin_dependencies,
+ include_directories: config_h_dir,
+ vala_args: geary_vala_args,
+ c_args: plugin_c_args,
+ install: true,
+ install_dir: plugin_dest
+)
+
+i18n.merge_file(
+ input: plugin_data + '.in',
+ output: plugin_data,
+ type: 'desktop',
+ po_dir: po_dir,
+ install: true,
+ install_dir: plugin_dest
+)
diff --git a/src/client/plugin/meson.build b/src/client/plugin/meson.build
index 4a508340..a4198c6a 100644
--- a/src/client/plugin/meson.build
+++ b/src/client/plugin/meson.build
@@ -23,5 +23,6 @@ plugin_dependencies = [
plugin_c_args = geary_c_args
subdir('desktop-notifications')
+subdir('folder-highlight')
subdir('messaging-menu')
subdir('notification-badge')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]