[Xfce4-commits] [apps/xfce4-notifyd] 01/01: Improve the state machine for unread notifications
noreply at xfce.org
noreply at xfce.org
Tue Dec 5 00:07:40 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 6dfb7a3248844570259aa95df3ac205330648af7
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Tue Dec 5 00:07:32 2017 +0100
Improve the state machine for unread notifications
Previously changing from regular to DND mode cleared the
"new notifications" state.
---
panel-plugin/notification-plugin-log.c | 1 +
panel-plugin/notification-plugin.c | 59 ++++++++++++++++++----------------
panel-plugin/notification-plugin.h | 3 ++
3 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/panel-plugin/notification-plugin-log.c b/panel-plugin/notification-plugin-log.c
index a675cfb..27875e3 100644
--- a/panel-plugin/notification-plugin-log.c
+++ b/panel-plugin/notification-plugin-log.c
@@ -131,6 +131,7 @@ notification_plugin_menu_populate (NotificationPlugin *notification_plugin)
gtk_widget_show_all (mi);
/* Reset the notification status icon since all items are now read */
state = xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE);
+ notification_plugin->new_notifications = 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 42044f6..6902c93 100644
--- a/panel-plugin/notification-plugin.c
+++ b/panel-plugin/notification-plugin.c
@@ -137,12 +137,20 @@ void
notification_plugin_update_icon (NotificationPlugin *notification_plugin,
gboolean state)
{
- if (state)
+ const gchar *icon_name;
+
+ if (state && !notification_plugin->new_notifications)
gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
"notification-disabled-symbolic", GTK_ICON_SIZE_MENU);
- else
+ else if (!state && !notification_plugin->new_notifications)
gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
"notification-symbolic", GTK_ICON_SIZE_MENU);
+ else if (state && notification_plugin->new_notifications)
+ gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
+ "notification-disabled-new-symbolic", GTK_ICON_SIZE_MENU);
+ else if (!state && notification_plugin->new_notifications)
+ gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
+ "notification-new-symbolic", GTK_ICON_SIZE_MENU);
}
@@ -170,25 +178,17 @@ notification_plugin_log_file_changed (GFileMonitor *monitor,
gpointer user_data)
{
NotificationPlugin *notification_plugin = user_data;
+ gboolean state;
+ state = xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE);
/* If the log gets cleared, the file gets deleted so make sure not to indicate that
there are new notifications */
if (event_type == G_FILE_MONITOR_EVENT_DELETED)
- {
- gboolean state;
-
- state = xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE);
- notification_plugin_update_icon (notification_plugin, state);
- }
+ notification_plugin->new_notifications = FALSE;
else if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
- {
- 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-new-symbolic", GTK_ICON_SIZE_MENU);
- else
- gtk_image_set_from_icon_name (GTK_IMAGE (notification_plugin->image),
- "notification-new-symbolic", GTK_ICON_SIZE_MENU);
- }
+ notification_plugin->new_notifications = TRUE;
+
+ notification_plugin_update_icon (notification_plugin, state);
}
@@ -200,30 +200,33 @@ notification_plugin_new (XfcePanelPlugin *panel_plugin)
GFile *log_file;
GFileMonitor *log_file_monitor;
gchar *notify_log_path = NULL;
+ gboolean state;
- /* allocate memory for the plugin structure */
+ /* Allocate memory for the plugin structure */
notification_plugin = panel_slice_new0 (NotificationPlugin);
notification_plugin->plugin = panel_plugin;
- /* xfconf */
+ /* Initialize xfconf */
xfconf_init (NULL);
notification_plugin->channel = xfconf_channel_new ("xfce4-notifyd");
- /* create some panel widgets */
+ /* As the plugin is starting up we presume there are no new notifications */
+ notification_plugin->new_notifications = FALSE;
+
+ /* Create the panel widgets (image-button) */
xfce_panel_plugin_set_small (panel_plugin, TRUE);
notification_plugin->button = xfce_panel_create_toggle_button ();
gtk_widget_set_tooltip_text (GTK_WIDGET (notification_plugin->button), _("Notifications"));
- if (xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE))
- notification_plugin->image = gtk_image_new_from_icon_name ("notification-disabled-symbolic", GTK_ICON_SIZE_MENU);
- else
- notification_plugin->image = gtk_image_new_from_icon_name ("notification-symbolic", GTK_ICON_SIZE_MENU);
+ notification_plugin->image = gtk_image_new ();
+ state = xfconf_channel_get_bool (notification_plugin->channel, "/do-not-disturb", FALSE);
+ notification_plugin_update_icon (notification_plugin, state);
gtk_container_add (GTK_CONTAINER (notification_plugin->button), notification_plugin->image);
gtk_container_add (GTK_CONTAINER (panel_plugin), notification_plugin->button);
gtk_widget_show_all (GTK_WIDGET (notification_plugin->button));
gtk_widget_set_name (GTK_WIDGET (notification_plugin->button), "xfce4-notification-plugin");
- /* create the menu */
+ /* Create the menu */
notification_plugin->menu = notification_plugin_menu_new (notification_plugin);
gtk_menu_attach_to_widget (GTK_MENU (notification_plugin->menu), notification_plugin->button, NULL);
gtk_widget_set_name (GTK_WIDGET (notification_plugin->menu), "xfce4-notification-plugin-menu");
@@ -234,16 +237,18 @@ 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 */
+ /* Start monitoring the log file for changes */
notify_log_path = xfce_resource_lookup (XFCE_RESOURCE_CACHE, XFCE_NOTIFY_LOG_FILE);
log_file = g_file_new_for_path (notify_log_path);
log_file_monitor = g_file_monitor_file (log_file, G_FILE_MONITOR_NONE, NULL, NULL);
g_signal_connect (log_file_monitor, "changed",
G_CALLBACK (notification_plugin_log_file_changed), notification_plugin);
+ /* Start monitoring the "do not disturb" setting in xfconf */
+ g_signal_connect (G_OBJECT (notification_plugin->channel), "property-changed::" "/do-not-disturb",
+ G_CALLBACK (notification_plugin_dnd_updated), notification_plugin);
+
return notification_plugin;
}
diff --git a/panel-plugin/notification-plugin.h b/panel-plugin/notification-plugin.h
index fd80622..644c3ec 100644
--- a/panel-plugin/notification-plugin.h
+++ b/panel-plugin/notification-plugin.h
@@ -39,6 +39,9 @@ typedef struct
XfcePanelPlugin *plugin;
XfconfChannel *channel;
+ /* state */
+ gboolean new_notifications;
+
/* panel widgets */
GtkWidget *button;
GtkWidget *image;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list