diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-06-27 17:25:34 +0200 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-06-27 17:25:34 +0200 |
commit | 93db8c38f2252cb4d506d90721446c0ad524ca3b (patch) | |
tree | 225d98b0f8256eeae44ed5dd92821a2096919ba2 /src/messages-service.c | |
parent | 1caa3be43ec40c7fb1bbb37a585555fe2526dc57 (diff) | |
download | ayatana-indicator-messages-93db8c38f2252cb4d506d90721446c0ad524ca3b.tar.gz ayatana-indicator-messages-93db8c38f2252cb4d506d90721446c0ad524ca3b.tar.bz2 ayatana-indicator-messages-93db8c38f2252cb4d506d90721446c0ad524ca3b.zip |
Add draws-attention flag to source actions
AppSections watch those flags for associated sources and mux them into a
draws-attention property for the whole section.
Diffstat (limited to 'src/messages-service.c')
-rw-r--r-- | src/messages-service.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/messages-service.c b/src/messages-service.c index 8a08423..209abe5 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -73,6 +73,31 @@ actions_changed (GObject *object, g_free (id); } + +static gboolean +app_section_draws_attention (gpointer key, + gpointer value, + gpointer user_data) +{ + AppSection *section = value; + return app_section_get_draws_attention (section); +} + +static void +draws_attention_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + GSimpleAction *clear; + gboolean attention; + + clear = G_SIMPLE_ACTION (g_simple_action_group_lookup (actions, "clear")); + g_return_if_fail (clear != NULL); + + attention = g_hash_table_find (applications, app_section_draws_attention, NULL) != NULL; + g_simple_action_set_enabled (clear, attention); +} + static AppSection * add_application (const gchar *desktop_id) { @@ -98,6 +123,8 @@ add_application (const gchar *desktop_id) g_action_muxer_insert (action_muxer, id, app_section_get_actions (section)); g_signal_connect (section, "notify::actions", G_CALLBACK (actions_changed), NULL); + g_signal_connect (section, "notify::draws-attention", + G_CALLBACK (draws_attention_changed), NULL); /* TODO insert it at the right position (alphabetically by application name) */ menuitem = g_menu_item_new_section (NULL, app_section_get_menu (section)); @@ -132,6 +159,9 @@ remove_application (const char *desktop_id) if (pos >= 0) g_menu_remove (menu, pos); g_action_muxer_remove (action_muxer, id); + + g_signal_handlers_disconnect_by_func (section, actions_changed, NULL); + g_signal_handlers_disconnect_by_func (section, draws_attention_changed, NULL); } else { g_warning ("could not remove '%s', it's not registered", desktop_id); @@ -211,15 +241,6 @@ change_status (GSimpleAction *action, } static void -clear_action_handler (MessageServiceDbus *msd, - gboolean attention, - gpointer user_data) -{ - GSimpleAction *action = user_data; - g_simple_action_set_enabled (action, attention); -} - -static void register_application (MessageServiceDbus *msd, const gchar *sender, const gchar *desktop_id, @@ -336,10 +357,6 @@ main (int argc, char ** argv) action_muxer = g_action_muxer_new (); g_action_muxer_insert (action_muxer, NULL, G_ACTION_GROUP (actions)); - g_signal_connect (dbus_interface, MESSAGE_SERVICE_DBUS_SIGNAL_ATTENTION_CHANGED, - G_CALLBACK(clear_action_handler), - g_action_map_lookup_action (G_ACTION_MAP (actions), "clear")); - g_signal_connect (dbus_interface, MESSAGE_SERVICE_DBUS_SIGNAL_REGISTER_APPLICATION, G_CALLBACK (register_application), NULL); g_signal_connect (dbus_interface, MESSAGE_SERVICE_DBUS_SIGNAL_UNREGISTER_APPLICATION, |