telepathy-glib: future-account: add set_avatar
Jonny Lamb
jonny at kemper.freedesktop.org
Thu May 10 07:41:19 PDT 2012
Module: telepathy-glib
Branch: master
Commit: f1089e2afd634039ffc8a2f45e8dd932d4eec930
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=f1089e2afd634039ffc8a2f45e8dd932d4eec930
Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date: Fri Apr 27 15:41:17 2012 +0100
future-account: add set_avatar
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
docs/reference/telepathy-glib-sections.txt | 1 +
telepathy-glib/future-account.c | 93 ++++++++++++++++++++++++++++
telepathy-glib/future-account.h | 3 +
tests/dbus/future-account.c | 48 ++++++++++++++-
4 files changed, 144 insertions(+), 1 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 0936fec..6078009 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -5243,6 +5243,7 @@ tp_future_account_set_automatic_presence
tp_future_account_set_enabled
tp_future_account_set_connect_automatically
tp_future_account_add_supersedes
+tp_future_account_set_avatar
<SUBSECTION>
tp_future_account_set_parameter
tp_future_account_set_parameter_string
diff --git a/telepathy-glib/future-account.c b/telepathy-glib/future-account.c
index 67a1706..1301737 100644
--- a/telepathy-glib/future-account.c
+++ b/telepathy-glib/future-account.c
@@ -142,6 +142,8 @@ enum {
PROP_ENABLED,
PROP_CONNECT_AUTOMATICALLY,
PROP_SUPERSEDES,
+ PROP_AVATAR,
+ PROP_AVATAR_MIME_TYPE,
N_PROPS
};
@@ -263,6 +265,26 @@ tp_future_account_get_property (GObject *object,
}
}
break;
+ case PROP_AVATAR:
+ {
+ GValueArray *array = tp_asv_get_boxed (self->priv->properties,
+ TP_PROP_ACCOUNT_INTERFACE_AVATAR_AVATAR,
+ TP_STRUCT_TYPE_AVATAR);
+
+ if (array != NULL)
+ g_value_set_boxed (value, g_value_get_boxed (array->values));
+ }
+ break;
+ case PROP_AVATAR_MIME_TYPE:
+ {
+ GValueArray *array = tp_asv_get_boxed (self->priv->properties,
+ TP_PROP_ACCOUNT_INTERFACE_AVATAR_AVATAR,
+ TP_STRUCT_TYPE_AVATAR);
+
+ if (array != NULL)
+ g_value_set_string (value, g_value_get_string (array->values + 1));
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -583,6 +605,33 @@ tp_future_account_class_init (TpFutureAccountClass *klass)
"Accounts superseded by this one",
G_TYPE_STRV,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+ /**
+ * TpFutureAccount:avatar:
+ *
+ * The avatar set on the account. The avatar's mime type can be read
+ * in the #TpFutureAccount:avatar-mime-type property. To change this
+ * property, use tp_future_account_set_avatar().
+ */
+ g_object_class_install_property (object_class, PROP_AVATAR,
+ g_param_spec_boxed ("avatar",
+ "Avatar",
+ "The account's avatar data",
+ G_TYPE_ARRAY,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+ /**
+ * TpFutureAccount:avatar-mime-type
+ *
+ * The mime type of the #TpFutureAccount:avatar property. To change
+ * this property, use tp_future_account_set_avatar().
+ */
+ g_object_class_install_property (object_class, PROP_AVATAR_MIME_TYPE,
+ g_param_spec_string ("avatar-mime-type",
+ "Avatar mime type",
+ "The account's avatar's mime type",
+ NULL,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}
/**
@@ -850,6 +899,50 @@ tp_future_account_add_supersedes (TpFutureAccount *self,
}
/**
+ * tp_future_account_set_avatar:
+ * @self: a #TpFutureAccount
+ * @avatar: (allow-none) (array length=len) a new avatar to set; can
+ * be %NULL only if %len equals 0
+ * @len: the length of the new avatar
+ * @mime_type: (allow-none): the MIME type of the new avatar; can be %NULL
+ * only if @len equals 0
+ *
+ * Set the avatar of the account @self to @avatar. Use the
+ * #TpFutureAccount:avatar and #TpFutureAccount:avatar-mime-type
+ * properties to read the current avatar.
+ */
+void
+tp_future_account_set_avatar (TpFutureAccount *self,
+ const guchar *avatar,
+ gsize len,
+ const gchar *mime_type)
+{
+ TpFutureAccountPrivate *priv;
+ GArray *tmp;
+ GValueArray *arr;
+
+ g_return_if_fail (TP_IS_FUTURE_ACCOUNT (self));
+ g_return_if_fail (avatar != NULL || len == 0);
+ g_return_if_fail (mime_type != NULL || len == 0);
+
+ priv = self->priv;
+
+ tmp = g_array_new (FALSE, FALSE, sizeof (guchar));
+
+ if (len > 0)
+ g_array_append_vals (tmp, avatar, len);
+
+ arr = tp_value_array_build (2,
+ TP_TYPE_UCHAR_ARRAY, tmp,
+ G_TYPE_STRING, mime_type,
+ G_TYPE_INVALID);
+
+ tp_asv_take_boxed (priv->properties,
+ TP_PROP_ACCOUNT_INTERFACE_AVATAR_AVATAR,
+ TP_STRUCT_TYPE_AVATAR, arr);
+}
+
+/**
* tp_future_account_set_parameter:
* @self: a #TpFutureAccount
* @key: the parameter key
diff --git a/telepathy-glib/future-account.h b/telepathy-glib/future-account.h
index 2b2d05f..b32b174 100644
--- a/telepathy-glib/future-account.h
+++ b/telepathy-glib/future-account.h
@@ -88,6 +88,9 @@ void tp_future_account_set_connect_automatically (TpFutureAccount *self,
void tp_future_account_add_supersedes (TpFutureAccount *self,
const gchar *superseded_path);
+void tp_future_account_set_avatar (TpFutureAccount *self,
+ const guchar *avatar, gsize len, const gchar *mime_type);
+
/* parameters */
void tp_future_account_set_parameter (TpFutureAccount *self,
const gchar *key, GVariant *value);
diff --git a/tests/dbus/future-account.c b/tests/dbus/future-account.c
index 681f67d..2c065a8 100644
--- a/tests/dbus/future-account.c
+++ b/tests/dbus/future-account.c
@@ -9,6 +9,8 @@
#include "config.h"
+#include <string.h>
+
#include <telepathy-glib/future-account.h>
#include <telepathy-glib/interfaces.h>
@@ -180,6 +182,8 @@ test_properties (Test *test,
gchar *presence_status, *presence_message;
gboolean enabled, connect_automatically;
gchar **supersedes;
+ GArray *avatar;
+ gchar *mime_type;
test->account = tp_future_account_new (test->account_manager,
"gabble", "jabber");
@@ -302,6 +306,32 @@ test_properties (Test *test,
g_strfreev (supersedes);
g_hash_table_unref (props);
+
+ /* avatar */
+ avatar = g_array_new (FALSE, FALSE, sizeof (guchar));
+ g_array_append_vals (avatar, "hello world", strlen ("hello world") + 1);
+ tp_future_account_set_avatar (test->account,
+ (const guchar *) avatar->data, avatar->len, "image/lolz");
+ g_array_unref (avatar);
+ avatar = NULL;
+
+ g_object_get (test->account,
+ "properties", &props,
+ "avatar", &avatar,
+ "avatar-mime-type", &mime_type,
+ NULL);
+
+ g_assert_cmpstr (avatar->data, ==, "hello world");
+ g_assert_cmpuint (avatar->len, ==, strlen ("hello world") + 1);
+ g_assert_cmpstr (mime_type, ==, "image/lolz");
+
+ g_assert (tp_asv_get_boxed (props,
+ TP_PROP_ACCOUNT_INTERFACE_AVATAR_AVATAR,
+ TP_STRUCT_TYPE_AVATAR) != NULL);
+
+ g_hash_table_unref (props);
+ g_array_unref (avatar);
+ g_free (mime_type);
}
static void
@@ -311,6 +341,7 @@ test_create_succeed (Test *test,
TpAccount *account;
GValueArray *array;
GPtrArray *supersedes;
+ GArray *avatar;
test->account = tp_future_account_new (test->account_manager,
"gabble", "jabber");
@@ -335,6 +366,13 @@ test_create_succeed (Test *test,
tp_future_account_add_supersedes (test->account,
"/some/silly/account");
+ avatar = g_array_new (FALSE, FALSE, sizeof (guchar));
+ g_array_append_vals (avatar, "blue meth", strlen ("blue meth") + 1);
+ tp_future_account_set_avatar (test->account,
+ (const guchar *) avatar->data, avatar->len, "image/png");
+ g_array_unref (avatar);
+ avatar = NULL;
+
tp_future_account_create_account_async (test->account,
tp_tests_result_ready_cb, &test->result);
tp_tests_run_until_result (&test->result);
@@ -352,7 +390,7 @@ test_create_succeed (Test *test,
==, "walter at white.us");
g_assert_cmpstr (tp_asv_get_string (test->am->create_parameters, "password"),
==, "holly");
- g_assert_cmpuint (g_hash_table_size (test->am->create_properties), ==, 7);
+ g_assert_cmpuint (g_hash_table_size (test->am->create_properties), ==, 8);
g_assert_cmpstr (tp_asv_get_string (test->am->create_properties,
TP_PROP_ACCOUNT_ICON),
==, "gasmask");
@@ -393,6 +431,14 @@ test_create_succeed (Test *test,
g_assert_cmpstr (g_ptr_array_index (supersedes, 0), ==,
"/some/silly/account");
+ array = tp_asv_get_boxed (test->am->create_properties,
+ TP_PROP_ACCOUNT_INTERFACE_AVATAR_AVATAR,
+ TP_STRUCT_TYPE_AVATAR);
+ avatar = g_value_get_boxed (array->values);
+ g_assert_cmpstr (avatar->data, ==, "blue meth");
+ g_assert_cmpstr (g_value_get_string (array->values + 1), ==,
+ "image/png");
+
g_object_unref (account);
}
More information about the telepathy-commits
mailing list