soc.2009.telepathy: 6096e7e1: Query supported avatar properties. Abili...
sttwister at soc.pidgin.im
sttwister at soc.pidgin.im
Mon Jun 15 17:40:34 EDT 2009
-----------------------------------------------------------------
Revision: 6096e7e177fd07998698e79b55f3d22cf2464812
Ancestor: a06152bb6b374adcad3d5098a59e7c2924f2f4fa
Author: sttwister at soc.pidgin.im
Date: 2009-06-15T21:35:09
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/6096e7e177fd07998698e79b55f3d22cf2464812
Modified files:
libpurple/protocols/telepathy/telepathy.c
ChangeLog:
Query supported avatar properties. Ability to set self avatar.
-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c f0f2944931582e922d924d5ace55955488f3aa52
+++ libpurple/protocols/telepathy/telepathy.c 70c6f82a75e34dbe2e905c21467989856cb28051
@@ -1110,6 +1110,92 @@ static void
}
static void
+get_avatar_properties_cb (TpProxy *proxy,
+ GHashTable *out_Properties,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ if (error != NULL)
+ {
+ purple_debug_error("telepathy", "Error getting avatar properties: %s\n", error->message);
+ }
+ else
+ {
+ telepathy_connection *data = user_data;
+ PurplePlugin *plugin = purple_connection_get_prpl(data->gc);
+ PurplePluginProtocolInfo *prpl_info = plugin->info->extra_info;
+
+
+ GHashTableIter iter;
+ gpointer key, value;
+
+ PurpleBuddyIconSpec icon_spec = NO_BUDDY_ICONS;
+ icon_spec.scale_rules = PURPLE_ICON_SCALE_SEND;
+
+ purple_debug_info("telepathy", "Got avatar properties!\n");
+
+ g_hash_table_iter_init(&iter, out_Properties);
+
+ /* iterate over all properties */
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ {
+ gchar *name = key;
+ GValue *val = value;
+
+ if (g_strcmp0("SupportedAvatarMIMETypes", name) == 0)
+ {
+ /* TODO: Somehow manage to unpack the damn array. Really... I can't get it to work! */
+
+ /* This parameter is of dbus type "as"
+ * It's exposed as a GValue holding a GPtrArray of (gchar *)s
+ * Or is it now??? wtf!?
+ */
+
+ /*
+ int i;
+ //GPtrArray *arr = value;
+ GPtrArray *arr = g_value_get_boxed(val);
+
+ for (i = 0; i < arr->len; ++i)
+ {
+ //GValue *val = g_ptr_array_index(arr, i);
+ //const gchar *mime_type = g_value_get_string(val);
+ const gchar *mime_type = g_ptr_array_index(arr, i);
+ purple_debug_info("telepathy", " %s\n", mime_type);
+ }
+ */
+
+ /* until then, default to the usual types */
+ icon_spec.format = "jpeg,png,gif";
+ }
+ else if (g_strcmp0("MinimumAvatarWidth", name) == 0)
+ {
+ icon_spec.min_width = g_value_get_uint(val);
+ }
+ else if (g_strcmp0("MinimumAvatarHeight", name) == 0)
+ {
+ icon_spec.min_height = g_value_get_uint(val);
+ }
+ else if (g_strcmp0("MaximumAvatarWidth", name) == 0)
+ {
+ icon_spec.max_width = g_value_get_uint(val);
+ }
+ else if (g_strcmp0("MaximumAvatarHeight", name) == 0)
+ {
+ icon_spec.max_height = g_value_get_uint(val);
+ }
+ else if (g_strcmp0("MaximumAvatarBytes", name) == 0)
+ {
+ icon_spec.max_filesize = g_value_get_uint(val);
+ }
+ }
+
+ prpl_info->icon_spec = icon_spec;
+ }
+}
+
+static void
connection_ready_cb (TpConnection *connection,
const GError *error,
gpointer user_data)
@@ -1150,6 +1236,9 @@ connection_ready_cb (TpConnection *conne
tp_cli_dbus_properties_call_get(connection, -1, TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "Channels", get_channels_cb, user_data, NULL, NULL);
+ /* query supported avatar formats */
+ tp_cli_dbus_properties_call_get_all(connection, -1, TP_IFACE_CONNECTION_INTERFACE_AVATARS, get_avatar_properties_cb, user_data, NULL, NULL);
+
/* this will be fired when an avatar for a buddy has been received */
tp_cli_connection_interface_avatars_connect_to_avatar_retrieved(connection,
avatar_retrieved_cb, data,
@@ -1577,6 +1666,66 @@ static void
}
static void
+set_avatar_cb (TpConnection *proxy,
+ const gchar *out_Token,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ if (error != NULL)
+ {
+ purple_debug_error("telepathy", "SetAvatar error: %s\n", error->message);
+ }
+}
+
+static void
+clear_avatar_cb (TpConnection *proxy,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ if (error != NULL)
+ {
+ purple_debug_error("telepathy", "ClearAvatar error: %s\n", error->message);
+ }
+}
+
+static void
+telepathy_set_buddy_icon (PurpleConnection *gc, PurpleStoredImage *img)
+{
+ telepathy_connection *data = purple_connection_get_protocol_data(gc);
+
+ guint size = purple_imgstore_get_size(img);
+ gchar *mime_type = g_strdup_printf("images/%s", purple_imgstore_get_extension(img));
+
+ /* different .jpg and .jpeg extensions correspond to the same MIME type */
+ if (g_strcmp0(mime_type, "images/jpg") == 0)
+ {
+ g_free(mime_type);
+ mime_type = "images/jpeg";
+ }
+
+ purple_debug_info("telepathy", "Setting icon (type: %s, size: %u)\n", mime_type, size);
+
+ if (size > 0)
+ {
+ /* copy the data to a new GArray */
+ GArray *array = g_array_sized_new(FALSE, FALSE, 1, size);
+ g_array_append_vals(array, purple_imgstore_get_data(img), size);
+
+ /* set the avatar */
+ tp_cli_connection_interface_avatars_call_set_avatar(data->connection, -1, array, mime_type, set_avatar_cb, data, NULL, NULL);
+
+ g_array_free(array, FALSE);
+ }
+ else
+ {
+ /* a 0-sized avatar means we should clear our avatar */
+ tp_cli_connection_interface_avatars_call_clear_avatar(data->connection, -1, clear_avatar_cb, data, NULL, NULL);
+ }
+}
+
+static void
telepathy_destroy(PurplePlugin *plugin)
{
purple_debug_info("telepathy", "Shutting down\n");
@@ -1641,7 +1790,7 @@ static PurplePluginProtocolInfo telepath
NULL, /* buddy_free */
NULL, /* convo_closed */
NULL, /* normalize */
- NULL, /* set_buddy_icon */
+ telepathy_set_buddy_icon, /* set_buddy_icon */
NULL, /* remove_group */
NULL, /* get_cb_real_name */
NULL, /* set_chat_topic */
More information about the Commits
mailing list