aboutsummaryrefslogtreecommitdiff
path: root/src/im-application-list.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-12-04 20:44:44 +0000
committerTarmac <Unknown>2012-12-04 20:44:44 +0000
commit63bbb7ee308cdc74726469796dd7640322730ff9 (patch)
treecc4a159f49dc4e064ced7e0527a9b7fe21ab4b18 /src/im-application-list.c
parent734905667985506763ab023ffd9f2952f1a83f39 (diff)
parent69ee426c0e5d81b95b2907fc8cc1bd7ed2ef559c (diff)
downloadayatana-indicator-messages-63bbb7ee308cdc74726469796dd7640322730ff9.tar.gz
ayatana-indicator-messages-63bbb7ee308cdc74726469796dd7640322730ff9.tar.bz2
ayatana-indicator-messages-63bbb7ee308cdc74726469796dd7640322730ff9.zip
Change icon when there are any messages in the menu.
Approved by Renato Araujo Oliveira Filho.
Diffstat (limited to 'src/im-application-list.c')
-rw-r--r--src/im-application-list.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/im-application-list.c b/src/im-application-list.c
index 64b15e3..607b0fc 100644
--- a/src/im-application-list.c
+++ b/src/im-application-list.c
@@ -131,6 +131,47 @@ im_application_list_source_activated (GSimpleAction *action,
im_application_list_source_removed (app, source_id);
}
+static guint
+g_action_group_get_n_actions (GActionGroup *group)
+{
+ guint len;
+ gchar **actions;
+
+ actions = g_action_group_list_actions (group);
+ len = g_strv_length (actions);
+
+ g_strfreev (actions);
+ return len;
+}
+
+static gboolean
+application_draws_attention (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ Application *app = value;
+
+ return (g_action_group_get_n_actions (G_ACTION_GROUP (app->source_actions)) +
+ g_action_group_get_n_actions (G_ACTION_GROUP (app->message_actions))) > 0;
+}
+
+static void
+im_application_list_update_draws_attention (ImApplicationList *list)
+{
+ const gchar *icon_name;
+ GVariant *state;
+ GActionGroup *main_actions;
+
+ if (g_hash_table_find (list->applications, application_draws_attention, NULL))
+ icon_name = "indicator-messages-new";
+ else
+ icon_name = "indicator-messages";
+
+ main_actions = g_action_muxer_get_group (list->muxer, NULL);
+ state = g_variant_new ("(sssb)", "", icon_name, "Messages", TRUE);
+ g_action_group_change_action_state (main_actions, "messages", state);
+}
+
static void
im_application_list_message_removed (Application *app,
const gchar *id)
@@ -138,6 +179,8 @@ im_application_list_message_removed (Application *app,
g_simple_action_group_remove (app->message_actions, id);
g_action_muxer_remove (app->message_sub_actions, id);
+ im_application_list_update_draws_attention (app->list);
+
g_signal_emit (app->list, signals[MESSAGE_REMOVED], 0, app->id, id);
}
@@ -656,6 +699,8 @@ im_application_list_message_added (Application *app,
g_object_unref (action_group);
}
+ im_application_list_update_draws_attention (app->list);
+
g_signal_emit (app->list, signals[MESSAGE_ADDED], 0,
app->id, app_iconstr, id, iconstr, title,
subtitle, body, actions, time, draws_attention);
@@ -721,6 +766,8 @@ im_application_list_unset_remote (Application *app)
g_action_muxer_insert (app->actions, "msg", G_ACTION_GROUP (app->message_actions));
g_action_muxer_insert (app->actions, "msg-actions", G_ACTION_GROUP (app->message_sub_actions));
+ im_application_list_update_draws_attention (app->list);
+
if (was_running)
g_signal_emit (app->list, signals[APP_STOPPED], 0, app->id);
}