aboutsummaryrefslogtreecommitdiff
path: root/src/im-application-list.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2013-08-15 16:02:00 -0500
committerTed Gould <ted@gould.cx>2013-08-15 16:02:00 -0500
commit04aad431b226943042233a11aa98e30b9e82c820 (patch)
tree770402bb7cfaa760e4aca9a6ed5d7cb8d3c1c9f2 /src/im-application-list.c
parent190841b5d7262d9619c618e19bcb08e30968fd41 (diff)
downloadayatana-indicator-messages-04aad431b226943042233a11aa98e30b9e82c820.tar.gz
ayatana-indicator-messages-04aad431b226943042233a11aa98e30b9e82c820.tar.bz2
ayatana-indicator-messages-04aad431b226943042233a11aa98e30b9e82c820.zip
Setting the status of the menu based on the aggregate application status
Diffstat (limited to 'src/im-application-list.c')
-rw-r--r--src/im-application-list.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/im-application-list.c b/src/im-application-list.c
index 878e57f..b23923a 100644
--- a/src/im-application-list.c
+++ b/src/im-application-list.c
@@ -1026,15 +1026,56 @@ status_activated (GSimpleAction * action, GVariant * param, gpointer user_data)
return;
}
+#define STATUS_ID_OFFLINE (G_N_ELEMENTS(status_ids) - 1)
+static const gchar *status_ids[] = { "available", "away", "busy", "invisible", "offline" };
+
+static guint
+status2val (const gchar * string)
+{
+ if (string == NULL) return STATUS_ID_OFFLINE;
+
+ guint i;
+ for (i = 0; i < G_N_ELEMENTS(status_ids); i++) {
+ if (g_strcmp0(status_ids[i], string) == 0) {
+ break;
+ }
+ }
+
+ if (i > STATUS_ID_OFFLINE)
+ i = STATUS_ID_OFFLINE;
+
+ return i;
+}
+
void
im_application_list_set_status (ImApplicationList * list, const gchar * id, const gchar *status)
{
- g_return_if_fail (IM_IS_APPLICATION_LIST (list));
+ g_return_if_fail (IM_IS_APPLICATION_LIST (list));
- g_hash_table_insert(list->app_status, im_application_list_canonical_id(id), g_strdup(status));
+ g_hash_table_insert(list->app_status, im_application_list_canonical_id(id), g_strdup(status));
- /* TODO: Update status */
+ GVariant * action_state = NULL;
+ g_object_get(list->statusaction, "state", &action_state, NULL);
- return;
+ guint final_status = STATUS_ID_OFFLINE;
+
+ if (action_state != NULL) {
+ final_status = status2val(g_variant_get_string(action_state, NULL));
+ g_variant_unref(action_state);
+ }
+
+ GList * statuses = g_hash_table_get_values(list->app_status);
+ GList * statusentry;
+
+ for (statusentry = statuses; statusentry != NULL; statusentry = g_list_next(statusentry)) {
+ guint statusval = status2val((gchar *)statusentry->data);
+ final_status = MIN(final_status, statusval);
+ }
+
+ g_list_free(statuses);
+
+ g_simple_action_set_state(list->statusaction, g_variant_new_string(status_ids[final_status]));
+
+ return;
}