[geary/mjog/plugin-support: 10/13] Convert UnityLauncher to NotificationBadge plugin



commit b54bbd42b5b677b32009b4728d51aa117c065b50
Author: Michael Gratton <mike vee net>
Date:   Fri Sep 27 11:20:45 2019 +1000

    Convert UnityLauncher to NotificationBadge plugin

 po/POTFILES.in                                     |  6 ++
 src/client/application/application-controller.vala |  3 -
 src/client/meson.build                             |  5 --
 src/client/notification/unity-launcher.vala        | 64 ----------------------
 src/client/plugin/meson.build                      |  1 +
 src/client/plugin/notification-badge/meson.build   | 30 ++++++++++
 .../notification-badge.plugin.in                   |  5 ++
 .../notification-badge/notification-badge.vala     | 55 +++++++++++++++++++
 8 files changed, 97 insertions(+), 72 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6452104b..a47b89b4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -77,8 +77,14 @@ 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/notification-badge/notification-badge.plugin.in
+src/client/plugin/notification-badge/notification-badge.vala
 src/client/plugin/plugin-notification.vala
 src/client/sidebar/sidebar-branch.vala
 src/client/sidebar/sidebar-common.vala
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 03d23bf9..38599bc3 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -146,7 +146,6 @@ public class Application.Controller : Geary.BaseObject {
     private Folks.IndividualAggregator folks;
     private Canberra.Context sound_context;
     private NewMessagesIndicator new_messages_indicator;
-    private UnityLauncher unity_launcher;
 
     private PluginManager plugin_manager;
 
@@ -314,8 +313,6 @@ public class Application.Controller : Geary.BaseObject {
         this.new_messages_indicator.composer_activated.connect(on_indicator_activated_composer);
         this.new_messages_indicator.inbox_activated.connect(on_indicator_activated_inbox);
 
-        this.unity_launcher = new UnityLauncher(this.plugin_manager.notifications);
-
         this.main_window.conversation_list_view.grab_focus();
 
         // initialize revokable
diff --git a/src/client/meson.build b/src/client/meson.build
index 015d28eb..2b1d7482 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -88,7 +88,6 @@ geary_client_vala_sources = files(
   'notification/libmessagingmenu.vala',
   'notification/new-messages-indicator.vala',
   'notification/null-indicator.vala',
-  'notification/unity-launcher.vala',
 
   'plugin/plugin-notification.vala',
 
@@ -146,10 +145,6 @@ if libmessagingmenu_dep.found()
   geary_client_dependencies += libmessagingmenu
   geary_client_vala_options += ['-D', 'HAVE_LIBMESSAGINGMENU']
 endif
-if libunity.found()
-  geary_client_dependencies += libunity
-  geary_client_vala_options += ['-D', 'HAVE_LIBUNITY']
-endif
 
 # Enable shared shecondary process if available.
 # See issues #558 and #559
diff --git a/src/client/plugin/meson.build b/src/client/plugin/meson.build
index 4826545b..3e588848 100644
--- a/src/client/plugin/meson.build
+++ b/src/client/plugin/meson.build
@@ -23,3 +23,4 @@ plugin_dependencies = [
 plugin_cflags = geary_c_options
 
 subdir('desktop-notifications')
+subdir('notification-badge')
diff --git a/src/client/plugin/notification-badge/meson.build 
b/src/client/plugin/notification-badge/meson.build
new file mode 100644
index 00000000..2dde74b2
--- /dev/null
+++ b/src/client/plugin/notification-badge/meson.build
@@ -0,0 +1,30 @@
+
+plugin_name = 'notification-badge'
+
+badge_dependencies = plugin_dependencies
+
+if libunity.found()
+  badge_dependencies += libunity
+
+  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: badge_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/notification-badge/notification-badge.plugin.in 
b/src/client/plugin/notification-badge/notification-badge.plugin.in
new file mode 100644
index 00000000..ca4fdfdf
--- /dev/null
+++ b/src/client/plugin/notification-badge/notification-badge.plugin.in
@@ -0,0 +1,5 @@
+[Plugin]
+Module=libnotification-badge.so
+Name=Notification Badge
+Description=Displays an application badge showing the number of unread messages
+Builtin=true
diff --git a/src/client/plugin/notification-badge/notification-badge.vala 
b/src/client/plugin/notification-badge/notification-badge.vala
new file mode 100644
index 00000000..26c043a8
--- /dev/null
+++ b/src/client/plugin/notification-badge/notification-badge.vala
@@ -0,0 +1,55 @@
+/*
+ * 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.NotificationBadge)
+    );
+}
+
+/** Updates Unity application badge with total new message count. */
+public class Plugin.NotificationBadge : Notification {
+
+
+    public override GearyApplication application {
+        get; construct set;
+    }
+
+    public override Application.NotificationContext context {
+        get; construct set;
+    }
+
+    private Unity.LauncherEntry? entry = null;
+
+    public override void activate() {
+        this.entry = Unity.LauncherEntry.get_for_desktop_id(
+            GearyApplication.APP_ID + ".desktop"
+        );
+        this.context.notify["total-new-messages"].connect(on_total_changed);
+        update_count();
+    }
+
+    public override void deactivate(bool is_shutdown) {
+        this.context.notify["total-new-messages"].disconnect(on_total_changed);
+        this.entry = null;
+    }
+
+    private void update_count() {
+        int count = this.context.total_new_messages;
+        this.entry.count = count;
+        this.entry.count_visible = (count > 0);
+    }
+
+    private void on_total_changed() {
+        update_count();
+    }
+
+}


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