From 58bb62e4b6f88e2f6688afe2e94ac0d954eacadf Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 27 Jun 2012 17:56:32 +0200 Subject: Make "Clear" work again --- src/app-section.c | 39 +++++++++++++++++++++++++++++++++++++++ src/app-section.h | 1 + src/messages-service.c | 14 +++++++++++--- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/app-section.c b/src/app-section.c index 35a842f..e7a2e1d 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -89,6 +89,7 @@ static void action_state_changed (GActionGroup *group, static void action_removed (GActionGroup *group, const gchar *action_name, gpointer user_data); +static gboolean action_draws_attention (GVariant *state); /* GObject Boilerplate */ G_DEFINE_TYPE (AppSection, app_section, G_TYPE_OBJECT); @@ -376,6 +377,44 @@ app_section_get_draws_attention (AppSection *self) return priv->draws_attention; } +void +app_section_clear_draws_attention (AppSection *self) +{ + AppSectionPrivate * priv = self->priv; + gchar **action_names; + gchar **it; + + if (priv->actions == NULL) + return; + + action_names = g_action_group_list_actions (priv->actions); + + for (it = action_names; *it; it++) { + GVariant *state; + + state = g_action_group_get_action_state (priv->actions, *it); + if (!state) + continue; + + /* clear draws-attention while preserving other state */ + if (action_draws_attention (state)) { + guint32 count; + gint64 time; + const gchar *str; + GVariant *new_state; + + g_variant_get (state, "(ux&sb)", &count, &time, &str, NULL); + + new_state = g_variant_new ("(uxsb)", count, time, str, FALSE); + g_action_group_change_action_state (priv->actions, *it, new_state); + } + + g_variant_unref (state); + } + + g_strfreev (action_names); +} + static void application_vanished (GDBusConnection *bus, const gchar *name, diff --git a/src/app-section.h b/src/app-section.h index 935f7a2..9b2c99d 100644 --- a/src/app-section.h +++ b/src/app-section.h @@ -57,6 +57,7 @@ GActionGroup * app_section_get_actions (AppSection *self); GMenuModel * app_section_get_menu (AppSection *appitem); GAppInfo * app_section_get_app_info (AppSection *appitem); gboolean app_section_get_draws_attention (AppSection *appitem); +void app_section_clear_draws_attention (AppSection *appitem); void app_section_set_object_path (AppSection *self, GDBusConnection *bus, const gchar *bus_name, diff --git a/src/messages-service.c b/src/messages-service.c index 209abe5..2fa36b2 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -215,13 +215,21 @@ service_shutdown (IndicatorService * service, gpointer user_data) g_main_loop_quit(mainloop); } +static void +app_section_remove_attention (gpointer key, + gpointer value, + gpointer user_data) +{ + AppSection *section = value; + app_section_clear_draws_attention (section); +} + static void clear_action_activate (GSimpleAction *simple, GVariant *param, gpointer user_data) { - MessageServiceDbus *msg_service = user_data; - message_service_dbus_set_attention(msg_service, FALSE); + g_hash_table_foreach (applications, app_section_remove_attention, NULL); } static void @@ -352,7 +360,7 @@ main (int argc, char ** argv) g_bus_get (G_BUS_TYPE_SESSION, NULL, got_bus, NULL); actions = g_simple_action_group_new (); - g_simple_action_group_add_entries (actions, entries, G_N_ELEMENTS (entries), dbus_interface); + g_simple_action_group_add_entries (actions, entries, G_N_ELEMENTS (entries), NULL); action_muxer = g_action_muxer_new (); g_action_muxer_insert (action_muxer, NULL, G_ACTION_GROUP (actions)); -- cgit v1.2.3