[geary/mjog/plugin-support: 11/13] Convert Libmessagingmenu to MessagingMenu plugin



commit 2637b6cabe055620917794d9e939f40f7678841f
Author: Michael Gratton <mike vee net>
Date:   Fri Sep 27 12:06:26 2019 +1000

    Convert Libmessagingmenu to MessagingMenu plugin

 meson.build                                        |  15 ---
 po/POTFILES.in                                     |   6 +-
 src/client/application/application-controller.vala |  23 -----
 src/client/meson.build                             |   8 --
 src/client/notification/libmessagingmenu.vala      |  94 ------------------
 .../notification/new-messages-indicator.vala       |  48 ----------
 src/client/notification/null-indicator.vala        |  15 ---
 src/client/plugin/meson.build                      |   3 +-
 src/client/plugin/messaging-menu/meson.build       |  44 +++++++++
 .../plugin/messaging-menu/messaging-menu.plugin.in |   5 +
 .../plugin/messaging-menu/messaging-menu.vala      | 106 +++++++++++++++++++++
 src/client/plugin/notification-badge/meson.build   |   3 +-
 12 files changed, 160 insertions(+), 210 deletions(-)
---
diff --git a/meson.build b/meson.build
index ce9a4100..61864e47 100644
--- a/meson.build
+++ b/meson.build
@@ -151,21 +151,6 @@ desktop_file_validate = find_program('desktop-file-validate', required: false)
 libmessagingmenu_dep = dependency('messaging-menu', version: '>= 12.10', required: false)
 libunity = dependency('unity', version: '>= 5.12.0', required: false)
 
-if libmessagingmenu_dep.found()
-  # The libmessagingmenu dependency above determines if the lib is
-  # present, but since it uses a broken name for its VAPI we have to
-  # find that and the C libs separately.
-  libmessagingmenu = declare_dependency(
-    include_directories: include_directories(
-      libmessagingmenu_dep.get_pkgconfig_variable('includedir')
-    ),
-    dependencies: [
-      valac.find_library('MessagingMenu-1.0', dirs: [ '/usr/share/vala/vapi' ]),
-      cc.find_library('messaging-menu')
-    ],
-  )
-endif
-
 # Ensure SQLite was built correctly
 if not cc.has_header_symbol('sqlite3.h', 'SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER', dependencies: sqlite)
   error('SQLite3 is missing FTS3 tokenizer support. Please compile it with -DSQLITE_ENABLE_FTS3.\n'
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a47b89b4..aa20d8e4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -77,12 +77,10 @@ src/client/folder-list/folder-list-inboxes-branch.vala
 src/client/folder-list/folder-list-search-branch.vala
 src/client/folder-list/folder-list-special-grouping.vala
 src/client/folder-list/folder-list-tree.vala
-src/client/notification/in-app-notification.vala
-src/client/notification/libmessagingmenu.vala
-src/client/notification/new-messages-indicator.vala
-src/client/notification/null-indicator.vala
 src/client/plugin/desktop-notifications/desktop-notifications.plugin.in
 src/client/plugin/desktop-notifications/desktop-notifications.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
 src/client/plugin/notification-badge/notification-badge.vala
 src/client/plugin/plugin-notification.vala
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 38599bc3..85df6134 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -145,7 +145,6 @@ public class Application.Controller : Geary.BaseObject {
     private UpgradeDialog upgrade_dialog;
     private Folks.IndividualAggregator folks;
     private Canberra.Context sound_context;
-    private NewMessagesIndicator new_messages_indicator;
 
     private PluginManager plugin_manager;
 
@@ -305,14 +304,6 @@ public class Application.Controller : Geary.BaseObject {
             this.plugin_manager.notifications
         );
 
-        // New messages indicator (Ubuntuism)
-        this.new_messages_indicator = NewMessagesIndicator.create(
-            this.plugin_manager.notifications, this.application.config
-        );
-        this.new_messages_indicator.application_activated.connect(on_indicator_activated_application);
-        this.new_messages_indicator.composer_activated.connect(on_indicator_activated_composer);
-        this.new_messages_indicator.inbox_activated.connect(on_indicator_activated_inbox);
-
         this.main_window.conversation_list_view.grab_focus();
 
         // initialize revokable
@@ -1153,20 +1144,6 @@ public class Application.Controller : Geary.BaseObject {
         debug("Switched to %s", folder.to_string());
     }
 
-    private void on_indicator_activated_application(uint32 timestamp) {
-        this.main_window.present();
-    }
-
-    private void on_indicator_activated_composer(uint32 timestamp) {
-        on_indicator_activated_application(timestamp);
-        compose();
-    }
-
-    private void on_indicator_activated_inbox(Geary.Folder folder, uint32 timestamp) {
-        on_indicator_activated_application(timestamp);
-        main_window.folder_list.select_folder(folder);
-    }
-
     private void on_select_folder_completed(Object? source, AsyncResult result) {
         try {
             do_select_folder.end(result);
diff --git a/src/client/meson.build b/src/client/meson.build
index 2b1d7482..e1160fe4 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -85,9 +85,6 @@ geary_client_vala_sources = files(
   'folder-list/folder-list-special-grouping.vala',
 
   'notification/in-app-notification.vala',
-  'notification/libmessagingmenu.vala',
-  'notification/new-messages-indicator.vala',
-  'notification/null-indicator.vala',
 
   'plugin/plugin-notification.vala',
 
@@ -141,11 +138,6 @@ geary_client_dependencies = [
 
 geary_client_vala_options = geary_vala_options
 
-if libmessagingmenu_dep.found()
-  geary_client_dependencies += libmessagingmenu
-  geary_client_vala_options += ['-D', 'HAVE_LIBMESSAGINGMENU']
-endif
-
 # Enable shared shecondary process if available.
 # See issues #558 and #559
 webkit_version = webkit2gtk.version().split('.')
diff --git a/src/client/plugin/meson.build b/src/client/plugin/meson.build
index 3e588848..fee3524e 100644
--- a/src/client/plugin/meson.build
+++ b/src/client/plugin/meson.build
@@ -1,6 +1,6 @@
 #
 # Builds individual plugins. The client's plugin classes themselves
-# are built at the next directory back up the tree.
+# are built back up the tree.
 #
 
 plugin_dependencies = [
@@ -23,4 +23,5 @@ plugin_dependencies = [
 plugin_cflags = geary_c_options
 
 subdir('desktop-notifications')
+subdir('messaging-menu')
 subdir('notification-badge')
diff --git a/src/client/plugin/messaging-menu/meson.build b/src/client/plugin/messaging-menu/meson.build
new file mode 100644
index 00000000..0cc2b9c0
--- /dev/null
+++ b/src/client/plugin/messaging-menu/meson.build
@@ -0,0 +1,44 @@
+
+plugin_name = 'messaging-menu'
+
+if libmessagingmenu_dep.found()
+  messaging_menu_dependencies = plugin_dependencies
+
+  # The libmessagingmenu dependency in the root meson.build file
+  # determines if the lib is present, but since the library uses a
+  # broken name for its VAPI we have to fake it and find the C and
+  # Vala libs manually
+  messaging_menu_dependencies += declare_dependency(
+    include_directories: include_directories(
+      libmessagingmenu_dep.get_pkgconfig_variable('includedir')
+    ),
+    dependencies: [
+      valac.find_library('MessagingMenu-1.0', dirs: [ '/usr/share/vala/vapi' ]),
+      cc.find_library('messaging-menu'),
+    ]
+  )
+
+  plugin_src = join_paths(plugin_name + '.vala')
+  plugin_data = join_paths(plugin_name + '.plugin')
+  plugin_dest = join_paths(plugins_dir, plugin_name)
+
+  shared_module(
+    # Use a non-standard name for the lib since the standard one
+    # conflicts with libmessagingmenu and causes linking to fail
+    plugin_name + '-geary',
+    sources: plugin_src,
+    dependencies: messaging_menu_dependencies,
+    c_args: plugin_cflags,
+    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
+  )
+endif
diff --git a/src/client/plugin/messaging-menu/messaging-menu.plugin.in 
b/src/client/plugin/messaging-menu/messaging-menu.plugin.in
new file mode 100644
index 00000000..afa06422
--- /dev/null
+++ b/src/client/plugin/messaging-menu/messaging-menu.plugin.in
@@ -0,0 +1,5 @@
+[Plugin]
+Module=libmessaging-menu-geary.so
+Name=Messaging Menu
+Description=Displays Unity Messaging Menu notifications for new email
+Builtin=true
diff --git a/src/client/plugin/messaging-menu/messaging-menu.vala 
b/src/client/plugin/messaging-menu/messaging-menu.vala
new file mode 100644
index 00000000..c1d8883e
--- /dev/null
+++ b/src/client/plugin/messaging-menu/messaging-menu.vala
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2019 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.Notification),
+        typeof(Plugin.MessagingMenu)
+    );
+}
+
+/** Updates the Unity messaging menu when new mail arrives. */
+public class Plugin.MessagingMenu : Notification {
+
+
+    public override GearyApplication application {
+        get; construct set;
+    }
+
+    public override Application.NotificationContext context {
+        get; construct set;
+    }
+
+    private global::MessagingMenu.App? app = null;
+
+
+    public override void activate() {
+        this.app = new global::MessagingMenu.App(
+            "%s.desktop".printf(GearyApplication.APP_ID)
+        );
+        this.app.register();
+        this.app.activate_source.connect(on_activate_source);
+
+        this.context.folder_removed.connect(on_folder_removed);
+        this.context.new_messages_arrived.connect(on_new_messages_changed);
+        this.context.new_messages_retired.connect(on_new_messages_changed);
+    }
+
+    public override void deactivate(bool is_shutdown) {
+        this.context.folder_removed.disconnect(on_folder_removed);
+        this.context.new_messages_arrived.disconnect(on_new_messages_changed);
+        this.context.new_messages_retired.disconnect(on_new_messages_changed);
+
+        this.app.activate_source.disconnect(on_activate_source);
+        this.app.unregister();
+        this.app = null;
+    }
+
+    private string get_source_id(Geary.Folder folder) {
+        return "new-messages-id-%s-%s".printf(folder.account.information.id, folder.path.to_string());
+    }
+
+    private void on_activate_source(string source_id) {
+        foreach (Geary.Folder folder in this.context.get_folders()) {
+            if (source_id == get_source_id(folder)) {
+                this.application.show_folder.begin(folder);
+                break;
+            }
+        }
+    }
+
+    private void on_new_messages_changed(Geary.Folder folder, int count) {
+        if (count > 0) {
+            show_new_messages_count(folder, count);
+        } else {
+            remove_new_messages_count(folder);
+        }
+    }
+
+    private void on_folder_removed(Geary.Folder folder) {
+        remove_new_messages_count(folder);
+    }
+
+    private void show_new_messages_count(Geary.Folder folder, int count) {
+        if (this.context.should_notify_new_messages(folder)) {
+            string source_id = get_source_id(folder);
+
+            if (this.app.has_source(source_id)) {
+                this.app.set_source_count(source_id, count);
+            } else {
+                this.app.append_source_with_count(
+                    source_id,
+                    null,
+                    _("%s — New Messages").printf(folder.account.information.display_name),
+                    count);
+            }
+
+            this.app.draw_attention(source_id);
+        }
+    }
+
+    private void remove_new_messages_count(Geary.Folder folder) {
+        string source_id = get_source_id(folder);
+        if (this.app.has_source(source_id)) {
+            this.app.remove_attention(source_id);
+            this.app.remove_source(source_id);
+        }
+    }
+
+}
diff --git a/src/client/plugin/notification-badge/meson.build 
b/src/client/plugin/notification-badge/meson.build
index 2dde74b2..d4710c52 100644
--- a/src/client/plugin/notification-badge/meson.build
+++ b/src/client/plugin/notification-badge/meson.build
@@ -1,9 +1,8 @@
 
 plugin_name = 'notification-badge'
 
-badge_dependencies = plugin_dependencies
-
 if libunity.found()
+  badge_dependencies = plugin_dependencies
   badge_dependencies += libunity
 
   plugin_src = join_paths(plugin_name + '.vala')


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