[next] telepathy-glib: TpAccountRequest:avatar: change from GArray<guchar> to GBytes

Simon McVittie smcv at kemper.freedesktop.org
Tue Apr 8 12:11:43 PDT 2014


Module: telepathy-glib
Branch: next
Commit: 5778343c0b5af3d3ef14483a584da5e492d8e13e
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=5778343c0b5af3d3ef14483a584da5e492d8e13e

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Fri Apr  4 16:24:14 2014 +0100

TpAccountRequest:avatar: change from GArray<guchar> to GBytes

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77139
Reviewed-by: Xavier Claessens

---

 telepathy-glib/account-request.c |   11 +++++++----
 tests/dbus/account-request.c     |   17 ++++++++---------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/telepathy-glib/account-request.c b/telepathy-glib/account-request.c
index da3e1cf..1e349fe 100644
--- a/telepathy-glib/account-request.c
+++ b/telepathy-glib/account-request.c
@@ -285,7 +285,12 @@ tp_account_request_get_property (GObject *object,
             TP_STRUCT_TYPE_AVATAR);
 
         if (array != NULL)
-          g_value_set_boxed (value, g_value_get_boxed (array->values));
+          {
+            GArray *uchars = g_value_get_boxed (array->values);
+
+            g_value_take_boxed (value,
+                g_bytes_new (uchars->data, uchars->len));
+          }
       }
       break;
     case PROP_AVATAR_MIME_TYPE:
@@ -668,14 +673,12 @@ tp_account_request_class_init (TpAccountRequestClass *klass)
    * The avatar set on the account. The avatar's mime type can be read
    * in the #TpAccountRequest:avatar-mime-type property. To change this
    * property, use tp_account_request_set_avatar().
-   *
-   * Since: 0.19.1
    */
   g_object_class_install_property (object_class, PROP_AVATAR,
       g_param_spec_boxed ("avatar",
         "Avatar",
         "The account's avatar data",
-        G_TYPE_ARRAY,
+        G_TYPE_BYTES,
         G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
 
   /**
diff --git a/tests/dbus/account-request.c b/tests/dbus/account-request.c
index 5a6ddce..2e82289 100644
--- a/tests/dbus/account-request.c
+++ b/tests/dbus/account-request.c
@@ -202,7 +202,8 @@ test_properties (Test *test,
   gchar *presence_status, *presence_message;
   gboolean enabled, connect_automatically;
   gchar **supersedes;
-  GArray *avatar;
+  GBytes *avatar;
+  gsize len;
   gchar *mime_type;
   gboolean found;
   const gchar *s;
@@ -338,12 +339,9 @@ test_properties (Test *test,
   g_variant_unref (props);
 
   /* avatar */
-  avatar = g_array_new (FALSE, FALSE, sizeof (guchar));
-  g_array_append_vals (avatar, "hello world", strlen ("hello world") + 1);
   tp_account_request_set_avatar (test->ar,
-      (const guchar *) avatar->data, avatar->len, "image/lolz");
-  g_array_unref (avatar);
-  avatar = NULL;
+      (const guchar *) "hello world", strlen ("hello world") + 1,
+      "image/lolz");
 
   g_object_get (test->ar,
       "properties", &props,
@@ -351,8 +349,9 @@ test_properties (Test *test,
       "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 ((const gchar *) g_bytes_get_data (avatar, &len), ==,
+      "hello world");
+  g_assert_cmpuint (len, ==, strlen ("hello world") + 1);
   g_assert_cmpstr (mime_type, ==, "image/lolz");
 
   v = g_variant_lookup_value (props, TP_PROP_ACCOUNT_INTERFACE_AVATAR1_AVATAR,
@@ -361,7 +360,7 @@ test_properties (Test *test,
   g_variant_unref (v);
 
   g_variant_unref (props);
-  g_array_unref (avatar);
+  g_bytes_unref (avatar);
   g_free (mime_type);
 
   /* service */



More information about the telepathy-commits mailing list