aboutsummaryrefslogtreecommitdiff
path: root/src/app-section.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-09-18 21:54:37 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-09-18 21:54:37 +0200
commit24ee0b6602960f35712adbf668099e06b8ebfb25 (patch)
treec927b8f3bd5208b2f1b518b2581fdd352e81fbb5 /src/app-section.c
parentda9fde78ca62bd0b05dfbee3e024fd776c29c373 (diff)
downloadayatana-indicator-messages-24ee0b6602960f35712adbf668099e06b8ebfb25.tar.gz
ayatana-indicator-messages-24ee0b6602960f35712adbf668099e06b8ebfb25.tar.bz2
ayatana-indicator-messages-24ee0b6602960f35712adbf668099e06b8ebfb25.zip
Set the global chat status more intelligently
Up until now, the global chat status was set every time an application called _set_status. Thus, global status really meant "status of the app that last changed the status". Now, the service remembers the chat status for each application and sets the global status as a combination of all of application statuses. If applications have different statuses, the menu items are shown in an inconsistent state. This is implemented in IdoMenuItem by making it accept state as an array of strings in addition to a single string. It is drawn inconsistent if the state contains the menu item's target value in addition to other values. When the global status is changed through the messaging menu, the service doesn't update the action immediately anymore. Instead, it notifies all applications about the change via the "status-changed" signal. Applications must call _set_state to acknowledge that they have indeed changed their state. This is consistent with libmessaging-menu's documentation and design. Also, the SetStatus D-Bus call was missing a "desktop-id" parameter to tell the menu which application changed status. Changing this doesn't break existing apps, as the D-Bus interface is considered private to indicator-messages.
Diffstat (limited to 'src/app-section.c')
-rw-r--r--src/app-section.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/app-section.c b/src/app-section.c
index 523e249..6aac52a 100644
--- a/src/app-section.c
+++ b/src/app-section.c
@@ -50,6 +50,7 @@ struct _AppSectionPrivate
gboolean draws_attention;
gboolean uses_chat_status;
+ gchar *chat_status;
guint name_watch_id;
};
@@ -60,6 +61,7 @@ enum {
PROP_ACTIONS,
PROP_DRAWS_ATTENTION,
PROP_USES_CHAT_STATUS,
+ PROP_CHAT_STATUS,
NUM_PROPERTIES
};
@@ -78,6 +80,7 @@ static void app_section_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec);
static void app_section_dispose (GObject *object);
+static void app_section_finalize (GObject *object);
static void activate_cb (GSimpleAction *action,
GVariant *param,
gpointer userdata);
@@ -118,6 +121,7 @@ app_section_class_init (AppSectionClass *klass)
object_class->get_property = app_section_get_property;
object_class->set_property = app_section_set_property;
object_class->dispose = app_section_dispose;
+ object_class->finalize = app_section_finalize;
properties[PROP_APPINFO] = g_param_spec_object ("app-info",
"AppInfo",
@@ -143,6 +147,13 @@ app_section_class_init (AppSectionClass *klass)
FALSE,
G_PARAM_READABLE);
+ properties[PROP_CHAT_STATUS] = g_param_spec_string ("chat-status",
+ "Chat status",
+ "Current chat status of the application",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
destroy_signal = g_signal_new ("destroy",
@@ -199,6 +210,10 @@ app_section_get_property (GObject *object,
g_value_set_boolean (value, app_section_get_uses_chat_status (self));
break;
+ case PROP_CHAT_STATUS:
+ g_value_set_string (value, app_section_get_status (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -218,6 +233,10 @@ app_section_set_property (GObject *object,
app_section_set_app_info (self, g_value_get_object (value));
break;
+ case PROP_CHAT_STATUS:
+ app_section_set_status (self, g_value_get_string (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -261,6 +280,16 @@ app_section_dispose (GObject *object)
G_OBJECT_CLASS (app_section_parent_class)->dispose (object);
}
+static void
+app_section_finalize (GObject *object)
+{
+ AppSection * self = APP_SECTION(object);
+
+ g_free (self->priv->chat_status);
+
+ G_OBJECT_CLASS (app_section_parent_class)->dispose (object);
+}
+
/* Respond to one of the shortcuts getting clicked on. */
static void
nick_activate_cb (GSimpleAction *action,
@@ -668,10 +697,12 @@ app_section_unset_object_path (AppSection *self)
}
priv->draws_attention = FALSE;
+ g_clear_pointer (&priv->chat_status, g_free);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DRAWS_ATTENTION]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USES_CHAT_STATUS]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CHAT_STATUS]);
g_action_group_change_action_state (G_ACTION_GROUP (priv->static_shortcuts),
"launch", g_variant_new_boolean (FALSE));
@@ -763,3 +794,23 @@ app_section_get_uses_chat_status (AppSection *self)
return priv->uses_chat_status;
}
+
+const gchar *
+app_section_get_status (AppSection *self)
+{
+ AppSectionPrivate * priv = self->priv;
+
+ return priv->chat_status;
+}
+
+void
+app_section_set_status (AppSection *self,
+ const gchar *status)
+{
+ AppSectionPrivate * priv = self->priv;
+
+ g_free (priv->chat_status);
+ priv->chat_status = g_strdup (status);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CHAT_STATUS]);
+}