[Commits] [SCM] claws branch, master, updated. 3.14.0-100-g437668c

holger at claws-mail.org holger at claws-mail.org
Thu Sep 29 22:28:44 CEST 2016


The branch, master has been updated
       via  437668c7f0207b6ea6f9c1467e15411a0903c8ca (commit)
      from  8dc0092094239d785c272cfbbf5a74b7035a183d (commit)

Summary of changes:
 configure.ac                                      |   28 ++---
 src/plugins/notification/Makefile.am              |    4 +-
 src/plugins/notification/notification_indicator.c |  138 ++++++++++-----------
 src/plugins/notification/notification_indicator.h |    1 +
 src/plugins/notification/notification_plugin.c    |    3 +
 src/plugins/notification/notification_prefs.c     |   90 +-------------
 6 files changed, 86 insertions(+), 178 deletions(-)


- Log -----------------------------------------------------------------
commit 437668c7f0207b6ea6f9c1467e15411a0903c8ca
Author: Holger Berndt <berndth at gmx.de>
Date:   Thu Sep 29 22:21:02 2016 +0200

    Notification plugin: Port from libindicate to unity/messaging menu
    
    This is a slightly modified version of the patch from Sebastien Noel,
    fixes bug #2665

diff --git a/configure.ac b/configure.ac
index 9333edc..9ba8bbe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1083,7 +1083,8 @@ dnl Archive:		libarchive
 dnl Fancy:		Webkit, curl, optionally libsoup-gnome
 dnl Gdata:		libgdata
 dnl Libravatar:		libcurl
-dnl Notification:	optionally libnotify libindicate libcanberra_gtk hotkey
+dnl Notification:	optionally libnotify  unity/messaging-menu
+dnl 				   libcanberra_gtk hotkey
 dnl Pdf-Viewer:		libpoppler
 dnl Perl:		sed perl
 dnl PGP/Core:		libgpgme
@@ -1288,20 +1289,13 @@ fi
 AC_SUBST(libcanberra_gtk_CFLAGS)
 AC_SUBST(libcanberra_gtk_LIBS)
 
-dnl libindicate ****************************************************************
-dnl We support either 0.3+ or 0.5+ or 0.6+ or 0.7+
-LIBINDICATE_MODULE=indicate
-LIBINDICATE_REQUIRED=0.3.0
-
-PKG_CHECK_EXISTS(indicate-0.5 >= 0.5.0, LIBINDICATE_MODULE=indicate-0.5)
-PKG_CHECK_EXISTS(indicate-0.6 >= 0.6.0, LIBINDICATE_MODULE=indicate-0.6)
-PKG_CHECK_EXISTS(indicate-0.7 >= 0.7.0, LIBINDICATE_MODULE=indicate-0.7)
-PKG_CHECK_MODULES(libindicate, $LIBINDICATE_MODULE >= $LIBINDICATE_REQUIRED, HAVE_LIBINDICATE=yes, HAVE_LIBINDICATE=no)
-if test x"$HAVE_LIBINDICATE" = xyes; then
-	AC_DEFINE(NOTIFICATION_INDICATOR, 1, [Activate support for indicators])
+dnl unity/messaging-menu *******************************************************
+PKG_CHECK_MODULES(unity, unity messaging-menu, HAVE_UNITY=yes, HAVE_UNITY=no)
+if test x"$HAVE_UNITY" = xyes; then
+	AC_DEFINE(NOTIFICATION_INDICATOR, 1, [Activate support for unity and messaging-menu])
 fi
-AC_SUBST(libindicate_CFLAGS)
-AC_SUBST(libindicate_LIBS)
+AC_SUBST(unity_CFLAGS)
+AC_SUBST(unity_LIBS)
 
 dnl hotkeys ********************************************************************
 PKG_CHECK_MODULES(CM_NP_HOTKEY, [gio-2.0 >= 2.15.6 gio-unix-2.0 >= 2.15.6], HAVE_HOTKEYS=yes, HAVE_HOTKEYS=no)
@@ -1547,10 +1541,10 @@ if test x"$enable_notification_plugin" != xno; then
 		notification_missing_dependencies="$notification_missing_dependencies hotkeys"
 	fi
 	notification_features="$notification_features lcdproc"
-	if test x"$HAVE_LIBINDICATE" = xyes; then
-		notification_features="$notification_features libindicate"
+	if test x"$HAVE_UNITY" = xyes; then
+		notification_features="$notification_features unity/messaging-menu"
 	else
-		notification_missing_dependencies="$notification_missing_dependencies libindicate"
+		notification_missing_dependencies="$notification_missing_dependencies unity/messaging-menu"
 	fi
 	if test x"$HAVE_LIBNOTIFY" = xyes; then
 		notification_features="$notification_features libnotify"
diff --git a/src/plugins/notification/Makefile.am b/src/plugins/notification/Makefile.am
index 39fa2c0..1ce0e2c 100644
--- a/src/plugins/notification/Makefile.am
+++ b/src/plugins/notification/Makefile.am
@@ -93,7 +93,7 @@ notification_la_DEPENDENCIES = $(plugin_deps) \
 notification_la_LIBADD = $(plugin_ldadd) $(cygwin_export_lib) \
         $(GTK_LIBS)  \
 	$(libnotify_LIBS) \
-	$(libindicate_LIBS) \
+	$(unity_LIBS) \
 	$(libcanberra_gtk_LIBS) \
 	$(hotkey_lib_path)
 
@@ -103,7 +103,7 @@ notification_la_CPPFLAGS = \
 	$(GLIB_CFLAGS) \
 	$(GTK_CFLAGS) \
 	$(libnotify_CFLAGS) \
-	$(libindicate_CFLAGS) \
+	$(unity_CFLAGS) \
 	$(libcanberra_gtk_CFLAGS)
 
 clean-local:
diff --git a/src/plugins/notification/notification_indicator.c b/src/plugins/notification/notification_indicator.c
index 381eabc..083ff54 100644
--- a/src/plugins/notification/notification_indicator.c
+++ b/src/plugins/notification/notification_indicator.c
@@ -29,24 +29,41 @@
 #include "folder.h"
 #include "common/utils.h"
 
-#include <libindicate/server.h>
-#include <libindicate/indicator.h>
-#include <libindicate/indicator-messages.h>
+#include <messaging-menu.h>
+#include <unity.h>
 
-static IndicateServer *server = NULL;
-static GHashTable *indicators = NULL;
+#define CLAWS_DESKTOP_FILE "claws-mail.desktop"
+
+static MessagingMenuApp *mmapp = NULL;
+static gboolean mmapp_registered = FALSE;
+static UnityLauncherEntry *launcher = NULL;
 static gulong mainwin_state_changed_signal_id = 0;
 
+static void show_claws_mail(MessagingMenuApp *mmapp, const gchar *id, gpointer data);
+
+void notification_indicator_setup(void)
+{
+  if(!mmapp) {
+    mmapp = messaging_menu_app_new(CLAWS_DESKTOP_FILE);
+  }
+  if(notify_config.indicator_enabled && !mmapp_registered) {
+    messaging_menu_app_register(MESSAGING_MENU_APP(mmapp));
+    g_signal_connect(mmapp, "activate-source", G_CALLBACK(show_claws_mail), NULL);
+    mmapp_registered = TRUE;
+  }
+  if(!launcher) {
+    launcher = unity_launcher_entry_get_for_desktop_id(CLAWS_DESKTOP_FILE);
+  }
+}
+
 void notification_indicator_destroy(void)
 {
-  if(indicators) {
-    g_hash_table_destroy(indicators);
-    indicators = NULL;
+  if(!launcher) {
+    unity_launcher_entry_set_count_visible(launcher, FALSE);
   }
-  if(server) {
-    indicate_server_hide(server);
-    g_object_unref(server);
-    server = NULL;
+  if(mmapp_registered) {
+    messaging_menu_app_unregister(mmapp);
+    mmapp_registered = FALSE;
   }
   if(mainwin_state_changed_signal_id != 0) {
     MainWindow *mainwin;
@@ -54,10 +71,9 @@ void notification_indicator_destroy(void)
       g_signal_handler_disconnect(mainwin->window, mainwin_state_changed_signal_id);
     mainwin_state_changed_signal_id = 0;
   }
-
 }
 
-static void show_claws_mail(IndicateIndicator *indicator, guint dummy, gpointer data)
+static void show_claws_mail(MessagingMenuApp *mmapp, const gchar *id, gpointer data)
 {
   MainWindow *mainwin;
 
@@ -75,43 +91,6 @@ static void show_claws_mail(IndicateIndicator *indicator, guint dummy, gpointer
   }
 }
 
-static void set_indicator_unread_count(IndicateIndicator *indicator, gint new, gint unread)
-{
-  gchar *count_str;
-
-  count_str = g_strdup_printf("%d / %d", new, unread);
-  indicate_indicator_set_property(indicator, INDICATE_INDICATOR_MESSAGES_PROP_COUNT, count_str);
-  g_free(count_str);
-}
-
-static void create_indicators(void)
-{
-  IndicateIndicator *indicator;
-  GList *cur_mb;
-
-  indicators = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
-
-  for(cur_mb = folder_get_list(); cur_mb; cur_mb = cur_mb->next) {
-    gchar *name;
-    Folder *folder = cur_mb->data;
-
-    if(!folder->name) {
-      debug_print("Notification plugin: Warning: Ignoring unnamed mailbox in indicator applet\n");
-      continue;
-    }
-    name = g_strdup(folder->name);
-
-    indicator = indicate_indicator_new();
-    indicate_indicator_set_property(indicator, INDICATE_INDICATOR_MESSAGES_PROP_NAME, name);
-    set_indicator_unread_count(indicator, 0, 0);
-    g_object_set_data(G_OBJECT(indicator), "new_msgs", GINT_TO_POINTER(0));
-    g_object_set_data(G_OBJECT(indicator), "unread_msgs", GINT_TO_POINTER(0));
-    g_signal_connect(indicator, "user-display", G_CALLBACK (show_claws_mail), folder);
-    indicate_indicator_show(indicator);
-    g_hash_table_insert(indicators, name, indicator);
-  }
-}
-
 static gboolean mainwin_state_event(GtkWidget *widget, GdkEventWindowState *event, gpointer user_data)
 {
   if(notify_config.indicator_hide_minimized) {
@@ -132,8 +111,8 @@ static gboolean mainwin_state_event(GtkWidget *widget, GdkEventWindowState *even
 
 void notification_update_indicator(void)
 {
-  GHashTableIter iter;
-  gpointer key, value;
+  GList *cur_mb;
+  gint total_message_count;
 
   if(!mainwin_state_changed_signal_id) {
     MainWindow *mainwin;
@@ -142,36 +121,45 @@ void notification_update_indicator(void)
       mainwin_state_changed_signal_id = g_signal_connect(G_OBJECT(mainwin->window), "window-state-event", G_CALLBACK(mainwin_state_event), NULL);
   }
 
-
   if(!notify_config.indicator_enabled)
     return;
 
-  if(!server) {
-    server = indicate_server_ref_default();
-    indicate_server_set_type (server, "message.mail");
-    indicate_server_set_desktop_file(server, get_desktop_file());
-    g_signal_connect(server, "server-display", G_CALLBACK(show_claws_mail), NULL);
-    indicate_server_show(server);
-  }
-
-  if(!indicators)
-    create_indicators();
-
+  total_message_count = 0;
   /* check accounts for new/unread counts */
-  g_hash_table_iter_init(&iter, indicators);
-  while(g_hash_table_iter_next(&iter, &key, &value)) {
+  for(cur_mb = folder_get_list(); cur_mb; cur_mb = cur_mb->next) {
+    Folder *folder = cur_mb->data;
     NotificationMsgCount count;
-    gchar *foldername = key;
-    IndicateIndicator *indicator = value;
 
-    notification_core_get_msg_count_of_foldername(foldername, &count);
+    if(!folder->name) {
+      debug_print("Notification plugin: Warning: Ignoring unnamed mailbox in indicator applet\n");
+      continue;
+    }
+    gchar *id = folder->name;
+    notification_core_get_msg_count_of_foldername(folder->name, &count);
+
+    total_message_count += count.unread_msgs;
 
-    set_indicator_unread_count(indicator, count.new_msgs, count.unread_msgs);
-    indicate_indicator_set_property(indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION,
-                                    (count.new_msgs > 0) ? "true" : "false");
-    g_object_set_data(G_OBJECT(indicator), "new_msgs", GINT_TO_POINTER(count.new_msgs));
-    g_object_set_data(G_OBJECT(indicator), "unread_msgs", GINT_TO_POINTER(count.unread_msgs));
+    if(count.new_msgs > 0) {
+      gchar *strcount = g_strdup_printf("%d / %d", count.new_msgs, count.unread_msgs);
+
+      if(messaging_menu_app_has_source(MESSAGING_MENU_APP(mmapp), id))
+        messaging_menu_app_set_source_string(MESSAGING_MENU_APP(mmapp), id, strcount);
+      else
+        messaging_menu_app_append_source_with_string(MESSAGING_MENU_APP(mmapp), id, NULL, id, strcount);
+
+      g_free(strcount);
+      messaging_menu_app_draw_attention(MESSAGING_MENU_APP(mmapp), id);
+    }
+    else {
+      if(messaging_menu_app_has_source(MESSAGING_MENU_APP(mmapp), id)) {
+        messaging_menu_app_remove_attention(MESSAGING_MENU_APP(mmapp), id);
+        messaging_menu_app_remove_source(MESSAGING_MENU_APP(mmapp), id);
+      }
+    }
   }
+
+  unity_launcher_entry_set_count(launcher, total_message_count);
+  unity_launcher_entry_set_count_visible(launcher, total_message_count > 0);
 }
 
 #endif /* NOTIFICATION_INDICATOR */
diff --git a/src/plugins/notification/notification_indicator.h b/src/plugins/notification/notification_indicator.h
index ab6db46..bc1be5e 100644
--- a/src/plugins/notification/notification_indicator.h
+++ b/src/plugins/notification/notification_indicator.h
@@ -28,6 +28,7 @@
 #include <glib.h>
 
 void notification_update_indicator(void);
+void notification_indicator_setup(void);
 void notification_indicator_destroy(void);
 
 #endif /* NOTIFICATION_INDICATOR */
diff --git a/src/plugins/notification/notification_plugin.c b/src/plugins/notification/notification_plugin.c
index 4b5be73..0da3c1f 100644
--- a/src/plugins/notification/notification_plugin.c
+++ b/src/plugins/notification/notification_plugin.c
@@ -328,6 +328,9 @@ gint plugin_init(gchar **error)
 
   notify_gtk_init();
 
+#ifdef NOTIFICATION_INDICATOR
+  notification_indicator_setup();
+#endif
 #ifdef NOTIFICATION_BANNER
   notification_update_banner();
 #endif
diff --git a/src/plugins/notification/notification_prefs.c b/src/plugins/notification/notification_prefs.c
index 9e2e229..8d5561e 100644
--- a/src/plugins/notification/notification_prefs.c
+++ b/src/plugins/notification/notification_prefs.c
@@ -165,7 +165,6 @@ typedef struct {
 	PrefsPage page;
 	GtkWidget *indicator_enabled;
 	GtkWidget *indicator_cont_enable;
-	GtkWidget *indicator_register;
 	GtkWidget *indicator_hide_minimized;
 }NotifyIndicatorPage;
 NotifyIndicatorPage indicator_page;
@@ -306,8 +305,8 @@ PrefParam
 #ifdef NOTIFICATION_INDICATOR
 				{	"indicator_enabled", "FALSE", &notify_config.indicator_enabled, P_BOOL,
 					NULL, NULL, NULL},
-                {   "indicator_hide_minimized", "FALSE", &notify_config.indicator_hide_minimized, P_BOOL,
-                    NULL, NULL, NULL},
+				{	"indicator_hide_minimized", "FALSE", &notify_config.indicator_hide_minimized, P_BOOL,
+					NULL, NULL, NULL},
 #endif /* NOTIFICATION_INDICATOR */
 #ifdef NOTIFICATION_HOTKEYS
                 {   "hotkeys_enabled", "FALSE", &notify_config.hotkeys_enabled, P_BOOL,
@@ -1787,69 +1786,6 @@ static void notify_trayicon_popup_enable_set_sensitivity(GtkToggleButton *bu,
 
 #ifdef NOTIFICATION_INDICATOR
 
-#define NOTIFICATION_INDICATOR_REGISTER_PATH ".config/indicators/messages/applications"
-
-static gboolean indicator_register_file_exists(void)
-{
-  gboolean retval;
-  gchar *filepath;
-  filepath = g_strconcat(get_home_dir(), "/" NOTIFICATION_INDICATOR_REGISTER_PATH "/claws-mail", NULL);
-  retval = is_file_exist(filepath);
-  g_free(filepath);
-  return retval;
-}
-
-static gboolean indicator_register_file_create(void)
-{
-  FILE *fp;
-  gchar *path, *filepath;
-  gboolean success;
-
-  /* make sure directory path exists */
-  path = g_strconcat(get_home_dir(), "/" NOTIFICATION_INDICATOR_REGISTER_PATH, NULL);
-  if(!is_dir_exist(path)) {
-    if(make_dir_hier(path) != -1)
-      debug_print("Notification plugin: Created directory '%s'\n", path);
-     else {
-       debug_print("Notification plugin: Error creating directory '%s'\n", path);
-       g_free(path);
-       return FALSE;
-     }
-  }
-
-  /* create register file */
-  filepath = g_strconcat(path, "/claws-mail", NULL);
-  g_free(path);
-  fp = fopen(filepath, "w");
-  success = (fp != NULL);
-  if(fp) {
-    fprintf(fp, "%s\n", get_desktop_file());
-    fclose(fp);
-    debug_print("Notification plugin: Created desktop indicator file '%s'\n", filepath);
-  }
-  else
-    debug_print("Notification plugin: Could not create desktop indicator file '%s'\n", filepath);
-  g_free(filepath);
-
-  return success;
-}
-
-static gboolean indicator_register_file_remove(void)
-{
-  gchar *filepath;
-  int retval;
-
-  filepath = g_strconcat(get_home_dir(), "/" NOTIFICATION_INDICATOR_REGISTER_PATH "/claws-mail", NULL);
-  retval = claws_unlink(filepath);
-  if(retval != -1)
-    debug_print("Notification plugin: Deleted file '%s'\n", filepath);
-  else
-    debug_print("Notification plugin: Error deleting file '%s'\n", filepath);
-  g_free(filepath);
-
-  return (retval != -1);
-}
-
 static void notify_create_indicator_page(PrefsPage *page, GtkWindow *window,
 		gpointer data)
 {
@@ -1881,12 +1817,6 @@ static void notify_create_indicator_page(PrefsPage *page, GtkWindow *window,
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), notify_config.indicator_hide_minimized);
 	indicator_page.indicator_hide_minimized = checkbox;
 
-	/* register */
-	ind_reg = gtk_check_button_new_with_label(_("Register Claws Mail"));
-	gtk_box_pack_start(GTK_BOX(indicator_page.indicator_cont_enable), ind_reg, FALSE, FALSE, 0);
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ind_reg), indicator_register_file_exists());
-	indicator_page.indicator_register = ind_reg;
-
 	notify_indicator_enable_set_sensitivity(GTK_TOGGLE_BUTTON(indicator_page.indicator_enabled), NULL);
 	gtk_widget_show_all(pvbox);
 	indicator_page.page.widget = pvbox;
@@ -1898,24 +1828,16 @@ static void notify_destroy_indicator_page(PrefsPage *page)
 
 static void notify_save_indicator(PrefsPage *page)
 {
-    gboolean ind_reg;
+	notification_indicator_destroy();
 
 	notify_config.indicator_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(indicator_page.indicator_enabled));
 
 	notify_config.indicator_hide_minimized = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(indicator_page.indicator_hide_minimized));
 
-	ind_reg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(indicator_page.indicator_register));
-	if(ind_reg) {
-	  if(!indicator_register_file_exists())
-	    indicator_register_file_create();
-	}
-	else {
-	  if(indicator_register_file_exists())
-	    indicator_register_file_remove();
+	if(notify_config.indicator_enabled) {
+	  notification_indicator_setup();
+	  notification_update_indicator();
 	}
-
-	notification_indicator_destroy();
-	notification_update_indicator();
 }
 
 static void notify_indicator_enable_set_sensitivity(GtkToggleButton *button,

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list