[Xfce4-commits] [apps/xfce4-notifyd] 02/02: panel-plugin: Make sure the status icon is always up-to-date

noreply at xfce.org noreply at xfce.org
Fri Dec 1 00:41:29 CET 2017


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-notifyd.

commit f13da27b0df45fb323c8cfb19f1df9f0fa9de080
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Fri Dec 1 00:40:47 2017 +0100

    panel-plugin: Make sure the status icon is always up-to-date
---
 panel-plugin/notification-plugin-log.c | 16 ++++---------
 panel-plugin/notification-plugin.c     | 41 +++++++++++++++++++++++++++++-----
 panel-plugin/notification-plugin.h     |  3 +++
 3 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/panel-plugin/notification-plugin-log.c b/panel-plugin/notification-plugin-log.c
index c4e74c6..098c745 100644
--- a/panel-plugin/notification-plugin-log.c
+++ b/panel-plugin/notification-plugin-log.c
@@ -50,12 +50,7 @@ notification_plugin_menu_item_activate (GtkWidget      *menuitem,
 
   muted = !gtk_switch_get_active (GTK_SWITCH (notification_plugin->do_not_disturb_switch));
   gtk_switch_set_active (GTK_SWITCH (notification_plugin->do_not_disturb_switch), muted);
-  if (muted)
-    gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
-                                  "notification-disabled-symbolic", GTK_ICON_SIZE_MENU);
-  else
-    gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
-                                  "notification-symbolic", GTK_ICON_SIZE_MENU);
+  notification_plugin_update_icon (notification_plugin, muted);
 }
 
 
@@ -103,6 +98,7 @@ notification_plugin_menu_populate (NotificationPlugin *notification_plugin)
   gchar *notify_log_icon_folder;
   gchar *notify_log_icon_path;
   int log_icon_size;
+  gboolean state;
 
   today = g_date_time_new_now_local ();
   timestamp = g_date_time_format (today, "%F");
@@ -133,12 +129,8 @@ notification_plugin_menu_populate (NotificationPlugin *notification_plugin)
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
   gtk_widget_show_all (mi);
   /* Reset the notification status icon since all items are now read */
-  if (xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE))
-    gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
-                                  "notification-disabled-symbolic", GTK_ICON_SIZE_MENU);
-  else
-    gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
-                                  "notification-symbolic", GTK_ICON_SIZE_MENU);
+  state = xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE);
+  notification_plugin_update_icon (notification_plugin, state);
   g_signal_connect (mi, "activate",
                     G_CALLBACK (notification_plugin_menu_item_activate), notification_plugin);
 
diff --git a/panel-plugin/notification-plugin.c b/panel-plugin/notification-plugin.c
index 5b7b1d4..42044f6 100644
--- a/panel-plugin/notification-plugin.c
+++ b/panel-plugin/notification-plugin.c
@@ -133,6 +133,35 @@ cb_menu_size_allocate (GtkWidget          *menu,
 
 
 
+void
+notification_plugin_update_icon (NotificationPlugin *notification_plugin,
+                                 gboolean state)
+{
+  if (state)
+    gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
+                                  "notification-disabled-symbolic", GTK_ICON_SIZE_MENU);
+  else
+    gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
+                                  "notification-symbolic", GTK_ICON_SIZE_MENU);
+}
+
+
+
+static void
+notification_plugin_dnd_updated (XfconfChannel *channel,
+                                 const gchar *property,
+                                 const GValue *value,
+                                 gpointer user_data)
+{
+  NotificationPlugin *notification_plugin = user_data;
+  gboolean state;
+
+  state = xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE);
+  notification_plugin_update_icon (notification_plugin, state);
+}
+
+
+
 static void
 notification_plugin_log_file_changed (GFileMonitor     *monitor,
                                        GFile            *file,
@@ -146,12 +175,10 @@ notification_plugin_log_file_changed (GFileMonitor     *monitor,
      there are new notifications */
   if (event_type == G_FILE_MONITOR_EVENT_DELETED)
   {
-    if (xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE))
-      gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
-                                    "notification-disabled-symbolic", GTK_ICON_SIZE_MENU);
-    else
-      gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
-                                    "notification-symbolic", GTK_ICON_SIZE_MENU);
+    gboolean state;
+
+    state = xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE);
+    notification_plugin_update_icon (notification_plugin, state);
   }
   else if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
   {
@@ -207,6 +234,8 @@ notification_plugin_new (XfcePanelPlugin *panel_plugin)
                     G_CALLBACK (cb_menu_deactivate), notification_plugin);
   g_signal_connect (notification_plugin->menu, "size-allocate",
                     G_CALLBACK (cb_menu_size_allocate), notification_plugin);
+  g_signal_connect (G_OBJECT (notification_plugin->channel), "property-changed::" "/do-not-disturb",
+                    G_CALLBACK (notification_plugin_dnd_updated), notification_plugin);
 
   /* start monitoring the log file for changes */
   notify_log_path = xfce_resource_lookup (XFCE_RESOURCE_CACHE, XFCE_NOTIFY_LOG_FILE);
diff --git a/panel-plugin/notification-plugin.h b/panel-plugin/notification-plugin.h
index 6152f4b..fd80622 100644
--- a/panel-plugin/notification-plugin.h
+++ b/panel-plugin/notification-plugin.h
@@ -52,6 +52,9 @@ typedef struct
 }
 NotificationPlugin;
 
+void notification_plugin_update_icon (NotificationPlugin *notification_plugin,
+                                      gboolean            state);
+
 G_END_DECLS
 
 #endif /* !__NOTIFICATION_PLUGIN_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list