From 2b331fb9769be6b64e14c9bc7ef061c370e85a2d Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 25 Jan 2012 13:36:16 +0100 Subject: [PATCH] simple-account: add API to change the presence https://bugs.freedesktop.org/show_bug.cgi?id=45120 --- tests/lib/simple-account.c | 54 ++++++++++++++++++++++++++++++++++++++++--- tests/lib/simple-account.h | 8 +++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/tests/lib/simple-account.c b/tests/lib/simple-account.c index ce08468..7287df3 100644 --- a/tests/lib/simple-account.c +++ b/tests/lib/simple-account.c @@ -68,7 +68,9 @@ enum struct _TpTestsSimpleAccountPrivate { - gpointer unused; + TpConnectionPresenceType presence; + gchar *presence_status; + gchar *presence_msg; }; static void @@ -87,6 +89,10 @@ tp_tests_simple_account_init (TpTestsSimpleAccount *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TP_TESTS_TYPE_SIMPLE_ACCOUNT, TpTestsSimpleAccountPrivate); + + self->priv->presence = TP_CONNECTION_PRESENCE_TYPE_AWAY; + self->priv->presence_status = g_strdup ("currently-away"); + self->priv->presence_msg = g_strdup ("this is my CurrentPresence"); } /* you may have noticed this is not entirely realistic */ @@ -98,6 +104,7 @@ tp_tests_simple_account_get_property (GObject *object, GValue *value, GParamSpec *spec) { + TpTestsSimpleAccount *self = TP_TESTS_SIMPLE_ACCOUNT (object); GValue identifier = { 0, }; g_value_init (&identifier, G_TYPE_STRING); @@ -146,9 +153,9 @@ tp_tests_simple_account_get_property (GObject *object, break; case PROP_CURRENT_PRESENCE: g_value_take_boxed (value, tp_value_array_build (3, - G_TYPE_UINT, TP_CONNECTION_PRESENCE_TYPE_AWAY, - G_TYPE_STRING, "currently-away", - G_TYPE_STRING, "this is my CurrentPresence", + G_TYPE_UINT, self->priv->presence, + G_TYPE_STRING, self->priv->presence_status, + G_TYPE_STRING, self->priv->presence_msg, G_TYPE_INVALID)); break; case PROP_REQUESTED_PRESENCE: @@ -193,6 +200,17 @@ tp_tests_simple_account_get_property (GObject *object, g_value_unset (&identifier); } +static void +tp_tests_simple_account_finalize (GObject *object) +{ + TpTestsSimpleAccount *self = TP_TESTS_SIMPLE_ACCOUNT (object); + + g_free (self->priv->presence_status); + g_free (self->priv->presence_msg); + + G_OBJECT_CLASS (tp_tests_simple_account_parent_class)->finalize (object); +} + /** * This class currently only provides the minimum for * tp_account_prepare to succeed. This turns out to be only a working @@ -260,6 +278,7 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass) g_type_class_add_private (klass, sizeof (TpTestsSimpleAccountPrivate)); object_class->get_property = tp_tests_simple_account_get_property; + object_class->finalize = tp_tests_simple_account_finalize; param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces", "In this case we only implement Account, so none.", @@ -403,3 +422,30 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass) tp_dbus_properties_mixin_class_init (object_class, G_STRUCT_OFFSET (TpTestsSimpleAccountClass, dbus_props_class)); } + +void +tp_tests_simple_account_set_presence (TpTestsSimpleAccount *self, + TpConnectionPresenceType presence, + const gchar *status, + const gchar *message) +{ + GHashTable *props; + GValueArray *v; + + g_free (self->priv->presence_status); + g_free (self->priv->presence_msg); + + self->priv->presence = presence; + self->priv->presence_status = g_strdup (status); + self->priv->presence_msg = g_strdup (message); + + g_object_get (self, "current-presence", &v, NULL); + + props = tp_asv_new ( + "CurrentPresence", TP_STRUCT_TYPE_SIMPLE_PRESENCE, v, + NULL); + + tp_svc_account_emit_account_property_changed (self, props); + + g_boxed_free (TP_STRUCT_TYPE_SIMPLE_PRESENCE, v); +} diff --git a/tests/lib/simple-account.h b/tests/lib/simple-account.h index 7af263d..40f708c 100644 --- a/tests/lib/simple-account.h +++ b/tests/lib/simple-account.h @@ -12,8 +12,9 @@ #define __TP_TESTS_SIMPLE_ACCOUNT_H__ #include -#include +#include +#include G_BEGIN_DECLS @@ -51,6 +52,11 @@ GType tp_tests_simple_account_get_type (void); (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT, \ TpTestsSimpleAccountClass)) +void tp_tests_simple_account_set_presence (TpTestsSimpleAccount *self, + TpConnectionPresenceType presence, + const gchar *status, + const gchar *message); + G_END_DECLS #endif /* #ifndef __TP_TESTS_SIMPLE_ACCOUNT_H__ */ -- 1.7.7.6