summaryrefslogtreecommitdiff
path: root/telepathy-glib
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-09-26 14:28:40 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-09-26 16:30:46 +0100
commitaa407653e274480ae63b21017869e07de3a1aa4e (patch)
tree457aa101d5ddb7e5d50bcee1b805478067460967 /telepathy-glib
parente6ac4848a0e613087b024af9f4c21fec3ee509ef (diff)
downloadtelepathy-glib-aa407653e274480ae63b21017869e07de3a1aa4e.tar.gz
Make more use of tp_value_array_unpack, tp_value_array_build
As well as being less code, they're not flagged as deprecated. This requires a bit of extra copying, because there's no tp_value_array_unpack_dup() or tp_value_array_build_take(), but it seems worth it. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69849 Reviewed-by: Xavier Claessens <xavier.claessens@collabora.co.uk>
Diffstat (limited to 'telepathy-glib')
-rw-r--r--telepathy-glib/account.c52
-rw-r--r--telepathy-glib/base-connection.c36
-rw-r--r--telepathy-glib/capabilities.c15
-rw-r--r--telepathy-glib/presence-mixin.c87
-rw-r--r--telepathy-glib/room-info.c22
5 files changed, 92 insertions, 120 deletions
diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c
index 24dbd001a..0ad6d8305 100644
--- a/telepathy-glib/account.c
+++ b/telepathy-glib/account.c
@@ -631,6 +631,8 @@ _tp_account_update (TpAccount *account,
TpConnectionStatus old_s = priv->connection_status;
gboolean status_changed = FALSE;
gboolean presence_changed = FALSE;
+ const gchar *status;
+ const gchar *message;
tp_proxy_add_interfaces (proxy, tp_asv_get_strv (properties, "Interfaces"));
@@ -721,29 +723,30 @@ _tp_account_update (TpAccount *account,
presence_changed = TRUE;
arr = tp_asv_get_boxed (properties, "CurrentPresence",
TP_STRUCT_TYPE_SIMPLE_PRESENCE);
- priv->cur_presence = g_value_get_uint (g_value_array_get_nth (arr, 0));
+ tp_value_array_unpack (arr, 3,
+ &priv->cur_presence,
+ &status,
+ &message);
g_free (priv->cur_status);
- priv->cur_status = g_value_dup_string (g_value_array_get_nth (arr, 1));
-
+ priv->cur_status = g_strdup (status);
g_free (priv->cur_message);
- priv->cur_message = g_value_dup_string (g_value_array_get_nth (arr, 2));
+ priv->cur_message = g_strdup (message);
}
if (g_hash_table_lookup (properties, "RequestedPresence") != NULL)
{
arr = tp_asv_get_boxed (properties, "RequestedPresence",
TP_STRUCT_TYPE_SIMPLE_PRESENCE);
- priv->requested_presence =
- g_value_get_uint (g_value_array_get_nth (arr, 0));
+ tp_value_array_unpack (arr, 3,
+ &priv->requested_presence,
+ &status,
+ &message);
g_free (priv->requested_status);
- priv->requested_status =
- g_value_dup_string (g_value_array_get_nth (arr, 1));
-
+ priv->requested_status = g_strdup (status);
g_free (priv->requested_message);
- priv->requested_message =
- g_value_dup_string (g_value_array_get_nth (arr, 2));
+ priv->requested_message = g_strdup (message);
g_object_notify (G_OBJECT (account), "requested-presence-type");
g_object_notify (G_OBJECT (account), "requested-status");
@@ -754,16 +757,15 @@ _tp_account_update (TpAccount *account,
{
arr = tp_asv_get_boxed (properties, "AutomaticPresence",
TP_STRUCT_TYPE_SIMPLE_PRESENCE);
- priv->auto_presence =
- g_value_get_uint (g_value_array_get_nth (arr, 0));
+ tp_value_array_unpack (arr, 3,
+ &priv->auto_presence,
+ &status,
+ &message);
g_free (priv->auto_status);
- priv->auto_status =
- g_value_dup_string (g_value_array_get_nth (arr, 1));
-
+ priv->auto_status = g_strdup (status);
g_free (priv->auto_message);
- priv->auto_message =
- g_value_dup_string (g_value_array_get_nth (arr, 2));
+ priv->auto_message = g_strdup (message);
g_object_notify (G_OBJECT (account), "automatic-presence-type");
g_object_notify (G_OBJECT (account), "automatic-status");
@@ -3551,8 +3553,6 @@ _tp_account_got_avatar_cb (TpProxy *proxy,
GObject *weak_object)
{
GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
- GValueArray *avatar;
- GArray *res;
if (error != NULL)
{
@@ -3567,8 +3567,18 @@ _tp_account_got_avatar_cb (TpProxy *proxy,
}
else
{
+ GValueArray *avatar;
+ GArray *res;
+ const GArray *tmp;
+ const gchar *mime_type;
+
avatar = g_value_get_boxed (out_Value);
- res = g_value_dup_boxed (g_value_array_get_nth (avatar, 0));
+ tp_value_array_unpack (avatar, 2,
+ &tmp,
+ &mime_type);
+
+ res = g_array_sized_new (FALSE, FALSE, 1, tmp->len);
+ g_array_append_vals (res, tmp->data, tmp->len);
g_simple_async_result_set_op_res_gpointer (result, res,
(GDestroyNotify) g_array_unref);
}
diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c
index 20a79b8c0..20c444013 100644
--- a/telepathy-glib/base-connection.c
+++ b/telepathy-glib/base-connection.c
@@ -728,7 +728,7 @@ exportable_channel_get_old_info (TpExportableChannel *channel,
static GValueArray *
get_channel_details (GObject *obj)
{
- GValueArray *structure = g_value_array_new (2);
+ GValueArray *structure;
GHashTable *table;
GValue *value;
gchar *object_path;
@@ -737,12 +737,6 @@ get_channel_details (GObject *obj)
"object-path", &object_path,
NULL);
- g_value_array_append (structure, NULL);
- value = g_value_array_get_nth (structure, 0);
- g_value_init (value, DBUS_TYPE_G_OBJECT_PATH);
- g_value_take_boxed (value, object_path);
- object_path = NULL;
-
g_assert (TP_IS_EXPORTABLE_CHANNEL (obj) || TP_IS_CHANNEL_IFACE (obj));
if (TP_IS_EXPORTABLE_CHANNEL (obj))
@@ -769,10 +763,13 @@ get_channel_details (GObject *obj)
g_hash_table_insert (table, TP_PROP_CHANNEL_CHANNEL_TYPE, value);
}
- g_value_array_append (structure, NULL);
- value = g_value_array_get_nth (structure, 1);
- g_value_init (value, TP_HASH_TYPE_QUALIFIED_PROPERTY_VALUE_MAP);
- g_value_take_boxed (value, table);
+ structure = tp_value_array_build (2,
+ DBUS_TYPE_G_OBJECT_PATH, object_path,
+ TP_HASH_TYPE_QUALIFIED_PROPERTY_VALUE_MAP, table,
+ G_TYPE_INVALID);
+
+ g_free (object_path);
+ g_hash_table_unref (table);
return structure;
}
@@ -1458,20 +1455,11 @@ get_requestables_foreach (TpChannelManager *manager,
gpointer user_data)
{
GPtrArray *details = user_data;
- GValueArray *requestable = g_value_array_new (2);
- GValue *value;
-
- g_value_array_append (requestable, NULL);
- value = g_value_array_get_nth (requestable, 0);
- g_value_init (value, TP_HASH_TYPE_CHANNEL_CLASS);
- g_value_set_boxed (value, fixed_properties);
-
- g_value_array_append (requestable, NULL);
- value = g_value_array_get_nth (requestable, 1);
- g_value_init (value, G_TYPE_STRV);
- g_value_set_boxed (value, allowed_properties);
- g_ptr_array_add (details, requestable);
+ g_ptr_array_add (details, tp_value_array_build (2,
+ TP_HASH_TYPE_CHANNEL_CLASS, fixed_properties,
+ G_TYPE_STRV, allowed_properties,
+ G_TYPE_INVALID));
}
diff --git a/telepathy-glib/capabilities.c b/telepathy-glib/capabilities.c
index 4ddf368f3..d4557b44a 100644
--- a/telepathy-glib/capabilities.c
+++ b/telepathy-glib/capabilities.c
@@ -322,11 +322,14 @@ supports_simple_channel (TpCapabilities *self,
{
GValueArray *arr = g_ptr_array_index (self->priv->classes, i);
GHashTable *fixed;
+ const gchar * const *allowed;
const gchar *chan_type;
TpHandleType handle_type;
gboolean valid;
- fixed = g_value_get_boxed (g_value_array_get_nth (arr, 0));
+ tp_value_array_unpack (arr, 2,
+ &fixed,
+ &allowed);
if (g_hash_table_size (fixed) != 2)
continue;
@@ -439,8 +442,9 @@ tp_capabilities_supports_sms (TpCapabilities *self)
gboolean valid;
guint nb_fixed_props;
- fixed = g_value_get_boxed (g_value_array_get_nth (arr, 0));
- allowed = g_value_get_boxed (g_value_array_get_nth (arr, 1));
+ tp_value_array_unpack (arr, 2,
+ &fixed,
+ &allowed);
handle_type = tp_asv_get_uint32 (fixed,
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, &valid);
@@ -809,12 +813,15 @@ tp_capabilities_supports_tubes_common (TpCapabilities *self,
{
GValueArray *arr = g_ptr_array_index (self->priv->classes, i);
GHashTable *fixed;
+ const gchar * const *allowed;
const gchar *chan_type;
TpHandleType handle_type;
gboolean valid;
guint nb_fixed_props = 2;
- fixed = g_value_get_boxed (g_value_array_get_nth (arr, 0));
+ tp_value_array_unpack (arr, 2,
+ &fixed,
+ &allowed);
chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
if (tp_strdiff (chan_type, expected_channel_type))
diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c
index f3b3b8787..8bb5ac4e9 100644
--- a/telepathy-glib/presence-mixin.c
+++ b/telepathy-glib/presence-mixin.c
@@ -541,17 +541,11 @@ construct_presence_hash_foreach (
g_hash_table_insert (contact_status,
(gpointer) supported_statuses[status->index].name, parameters);
- vals = g_value_array_new (2);
-
- /* last-activity sucks and will probably be removed soon */
- g_value_array_append (vals, NULL);
- g_value_init (g_value_array_get_nth (vals, 0), G_TYPE_UINT);
- g_value_set_uint (g_value_array_get_nth (vals, 0), 0);
-
- g_value_array_append (vals, NULL);
- g_value_init (g_value_array_get_nth (vals, 1),
- TP_HASH_TYPE_MULTIPLE_STATUS_MAP);
- g_value_take_boxed (g_value_array_get_nth (vals, 1), contact_status);
+ vals = tp_value_array_build (2,
+ G_TYPE_UINT, 0,
+ TP_HASH_TYPE_MULTIPLE_STATUS_MAP, contact_status,
+ G_TYPE_INVALID);
+ g_hash_table_unref (contact_status);
g_hash_table_insert (presence_hash, GUINT_TO_POINTER (handle), vals);
}
@@ -850,34 +844,21 @@ tp_presence_mixin_get_statuses (TpSvcConnectionInterfacePresence *iface,
for (i=0; mixin_cls->statuses[i].name != NULL; i++)
{
+ GHashTable *args;
+
/* the spec says we include statuses here even if they're not available
* to set on yourself */
if (!check_status_available (obj, mixin_cls, i, NULL, FALSE))
continue;
- status = g_value_array_new (5);
-
- g_value_array_append (status, NULL);
- g_value_init (g_value_array_get_nth (status, 0), G_TYPE_UINT);
- g_value_set_uint (g_value_array_get_nth (status, 0),
- mixin_cls->statuses[i].presence_type);
-
- g_value_array_append (status, NULL);
- g_value_init (g_value_array_get_nth (status, 1), G_TYPE_BOOLEAN);
- g_value_set_boolean (g_value_array_get_nth (status, 1),
- mixin_cls->statuses[i].self);
-
- /* everything is exclusive */
- g_value_array_append (status, NULL);
- g_value_init (g_value_array_get_nth (status, 2), G_TYPE_BOOLEAN);
- g_value_set_boolean (g_value_array_get_nth (status, 2),
- TRUE);
-
- g_value_array_append (status, NULL);
- g_value_init (g_value_array_get_nth (status, 3),
- DBUS_TYPE_G_STRING_STRING_HASHTABLE);
- g_value_take_boxed (g_value_array_get_nth (status, 3),
- get_statuses_arguments (mixin_cls->statuses[i].optional_arguments));
+ args = get_statuses_arguments (mixin_cls->statuses[i].optional_arguments);
+ status = tp_value_array_build (4,
+ G_TYPE_UINT, (guint) mixin_cls->statuses[i].presence_type,
+ G_TYPE_BOOLEAN, mixin_cls->statuses[i].self,
+ G_TYPE_BOOLEAN, TRUE, /* exclusive */
+ DBUS_TYPE_G_STRING_STRING_HASHTABLE, args,
+ G_TYPE_INVALID);
+ g_hash_table_unref (args);
g_hash_table_insert (ret, (gchar *) mixin_cls->statuses[i].name,
status);
@@ -1284,21 +1265,11 @@ tp_presence_mixin_get_simple_presence_dbus_property (GObject *object,
}
}
- status = g_value_array_new (3);
-
- g_value_array_append (status, NULL);
- g_value_init (g_value_array_get_nth (status, 0), G_TYPE_UINT);
- g_value_set_uint (g_value_array_get_nth (status, 0),
- mixin_cls->statuses[i].presence_type);
-
- g_value_array_append (status, NULL);
- g_value_init (g_value_array_get_nth (status, 1), G_TYPE_BOOLEAN);
- g_value_set_boolean (g_value_array_get_nth (status, 1),
- mixin_cls->statuses[i].self);
-
- g_value_array_append (status, NULL);
- g_value_init (g_value_array_get_nth (status, 2), G_TYPE_BOOLEAN);
- g_value_set_boolean (g_value_array_get_nth (status, 2), message);
+ status = tp_value_array_build (3,
+ G_TYPE_UINT, (guint) mixin_cls->statuses[i].presence_type,
+ G_TYPE_BOOLEAN, mixin_cls->statuses[i].self,
+ G_TYPE_BOOLEAN, message,
+ G_TYPE_INVALID);
g_hash_table_insert (ret, (gchar *) mixin_cls->statuses[i].name,
status);
@@ -1425,19 +1396,11 @@ construct_simple_presence_value_array (TpPresenceStatus *status,
if (message == NULL)
message = "";
- presence = g_value_array_new (3);
-
- g_value_array_append (presence, NULL);
- g_value_init (g_value_array_get_nth (presence, 0), G_TYPE_UINT);
- g_value_set_uint (g_value_array_get_nth (presence, 0), status_type);
-
- g_value_array_append (presence, NULL);
- g_value_init (g_value_array_get_nth (presence, 1), G_TYPE_STRING);
- g_value_set_string (g_value_array_get_nth (presence, 1), status_name);
-
- g_value_array_append (presence, NULL);
- g_value_init (g_value_array_get_nth (presence, 2), G_TYPE_STRING);
- g_value_set_string (g_value_array_get_nth (presence, 2), message);
+ presence = tp_value_array_build (3,
+ G_TYPE_UINT, status_type,
+ G_TYPE_STRING, status_name,
+ G_TYPE_STRING, message,
+ G_TYPE_INVALID);
return presence;
}
diff --git a/telepathy-glib/room-info.c b/telepathy-glib/room-info.c
index 1843b1d0f..10942dcf6 100644
--- a/telepathy-glib/room-info.c
+++ b/telepathy-glib/room-info.c
@@ -25,6 +25,7 @@
#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/util.h>
/**
* SECTION: room-info
@@ -97,7 +98,8 @@ TpRoomInfo *
_tp_room_info_new (GValueArray *dbus_struct)
{
TpRoomInfo *room;
- GValue *v;
+ const gchar *channel_type;
+ GHashTable *info;
g_return_val_if_fail (dbus_struct != NULL, NULL);
g_return_val_if_fail (dbus_struct->n_values == 3, NULL);
@@ -107,14 +109,16 @@ _tp_room_info_new (GValueArray *dbus_struct)
room = g_object_new (TP_TYPE_ROOM_INFO,
NULL);
- v = g_value_array_get_nth (dbus_struct, 0);
- room->priv->handle = g_value_get_uint (v);
-
- v = g_value_array_get_nth (dbus_struct, 1);
- room->priv->channel_type = g_value_dup_string (v);
-
- v = g_value_array_get_nth (dbus_struct, 2);
- room->priv->info = g_value_dup_boxed (v);
+ tp_value_array_unpack (dbus_struct, 3,
+ &room->priv->handle,
+ &channel_type,
+ &info);
+ room->priv->channel_type = g_strdup (channel_type);
+ room->priv->info = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) tp_g_value_slice_free);
+ tp_g_hash_table_update (room->priv->info, info,
+ (GBoxedCopyFunc) g_strdup,
+ (GBoxedCopyFunc) tp_g_value_slice_dup);
return room;
}