aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-06-27 22:44:30 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-06-27 22:44:30 +0200
commitcc6cbf767baba6ab2b5f2ec32f0d9ff2a7f94cfa (patch)
treeedbd734c50a5842c9968720dd35ef221c3765222 /src
parentd1492d66b1bdb7e70a342454c4fde781f448b83e (diff)
downloadayatana-indicator-messages-cc6cbf767baba6ab2b5f2ec32f0d9ff2a7f94cfa.tar.gz
ayatana-indicator-messages-cc6cbf767baba6ab2b5f2ec32f0d9ff2a7f94cfa.tar.bz2
ayatana-indicator-messages-cc6cbf767baba6ab2b5f2ec32f0d9ff2a7f94cfa.zip
Sync chat status from and to clients
Diffstat (limited to 'src')
-rw-r--r--src/messages-service.c50
-rw-r--r--src/messages-service.xml9
2 files changed, 52 insertions, 7 deletions
diff --git a/src/messages-service.c b/src/messages-service.c
index ec36335..a12847f 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -246,10 +246,26 @@ radio_item_activate (GSimpleAction *action,
g_action_change_state (G_ACTION (action), parameter);
}
+static gboolean
+g_action_state_equal (GAction *action,
+ GVariant *value)
+{
+ GVariant *state;
+ gboolean eq;
+
+ state = g_action_get_state (action);
+ g_return_val_if_fail (state != NULL, FALSE);
+
+ eq = g_variant_equal (state, value);
+
+ g_variant_unref (state);
+ return eq;
+}
+
static void
-change_status (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+change_status_action (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
{
const gchar *status;
@@ -261,9 +277,11 @@ change_status (GSimpleAction *action,
g_str_equal (status, "invisible") ||
g_str_equal (status, "offline"));
- g_simple_action_set_state (action, value);
-
- g_message ("changing status to %s", g_variant_get_string (value, NULL));
+ if (!g_action_state_equal (G_ACTION (action), value)) {
+ g_message ("%s", status);
+ g_simple_action_set_state (action, value);
+ indicator_messages_service_emit_status_changed (messages_service, status);
+ }
}
static void
@@ -302,6 +320,22 @@ unregister_application (IndicatorMessagesService *service,
indicator_messages_service_complete_unregister_application (service, invocation);
}
+static void
+set_status (IndicatorMessagesService *service,
+ GDBusMethodInvocation *invocation,
+ const gchar *status_str,
+ gpointer user_data)
+{
+ GAction *status;
+
+ status = g_simple_action_group_lookup (actions, "status");
+ g_return_if_fail (status != NULL);
+
+ g_action_change_state (status, g_variant_new_string (status_str));
+
+ indicator_messages_service_complete_set_status (service, invocation);
+}
+
GSimpleActionGroup *
create_action_group ()
{
@@ -319,7 +353,7 @@ create_action_group ()
status = g_simple_action_new_stateful ("status", G_VARIANT_TYPE ("s"),
g_variant_new ("s", "offline"));
g_signal_connect (status, "activate", G_CALLBACK (radio_item_activate), NULL);
- g_signal_connect (status, "change-state", G_CALLBACK (change_status), NULL);
+ g_signal_connect (status, "change-state", G_CALLBACK (change_status_action), NULL);
clear = g_simple_action_new ("clear", NULL);
g_simple_action_set_enabled (clear, FALSE);
@@ -427,6 +461,8 @@ main (int argc, char ** argv)
G_CALLBACK (register_application), NULL);
g_signal_connect (messages_service, "handle-unregister-application",
G_CALLBACK (unregister_application), NULL);
+ g_signal_connect (messages_service, "handle-set-status",
+ G_CALLBACK (set_status), NULL);
menu = g_menu_new ();
status_items = create_status_section ();
diff --git a/src/messages-service.xml b/src/messages-service.xml
index 450d1fa..edd47c7 100644
--- a/src/messages-service.xml
+++ b/src/messages-service.xml
@@ -6,9 +6,18 @@
<arg type="s" name="desktop_id" direction="in" />
<arg type="o" name="menu_path" direction="in" />
</method>
+
<method name="UnregisterApplication">
<arg type="s" name="desktop_id" direction="in" />
</method>
+ <method name="SetStatus">
+ <arg type="s" name="status" direction="in" />
+ </method>
+
+ <signal name="StatusChanged">
+ <arg type="s" name="status" direction="in" />
+ </signal>
+
</interface>
</node>