[Telepathy-commits] [telepathy-haze/master] Cache the acceptable mime types for a connection's avatar.
Will Thompson
will.thompson at collabora.co.uk
Tue Mar 24 05:44:01 PDT 2009
---
src/connection-avatars.c | 43 +++++++++++++++++++++++++++++--------------
src/connection.c | 6 ++++++
src/connection.h | 2 ++
3 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/src/connection-avatars.c b/src/connection-avatars.c
index bc4e761..df9c121 100644
--- a/src/connection-avatars.c
+++ b/src/connection-avatars.c
@@ -32,6 +32,34 @@
#include "connection.h"
#include "debug.h"
+static gchar **
+_get_acceptable_mime_types (HazeConnection *self)
+{
+ PurplePluginProtocolInfo *prpl_info = HAZE_CONNECTION_GET_PRPL_INFO (self);
+
+ g_return_val_if_fail (prpl_info->icon_spec.format != NULL, NULL);
+
+ if (self->acceptable_avatar_mime_types == NULL)
+ {
+ gchar **mime_types, **i;
+ gchar *format;
+
+ mime_types = g_strsplit (prpl_info->icon_spec.format, ",", 0);
+
+ for (i = mime_types; *i != NULL; i++)
+ {
+ format = *i;
+ /* FIXME: image/ico is not the correct mime type. */
+ *i = g_strconcat ("image/", format, NULL);
+ g_free (format);
+ }
+
+ self->acceptable_avatar_mime_types = mime_types;
+ }
+
+ return self->acceptable_avatar_mime_types;
+}
+
static void
haze_connection_get_avatar_requirements (TpSvcConnectionInterfaceAvatars *self,
DBusGMethodInvocation *context)
@@ -40,8 +68,6 @@ haze_connection_get_avatar_requirements (TpSvcConnectionInterfaceAvatars *self,
TpBaseConnection *base = TP_BASE_CONNECTION (conn);
PurplePluginProtocolInfo *prpl_info;
PurpleBuddyIconSpec *icon_spec;
- gchar **mime_types, **i;
- gchar *format;
TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context);
@@ -51,22 +77,11 @@ haze_connection_get_avatar_requirements (TpSvcConnectionInterfaceAvatars *self,
/* If the spec or the formats are null, this iface wasn't implemented. */
g_assert (icon_spec != NULL && icon_spec->format != NULL);
- mime_types = g_strsplit (icon_spec->format, ",", 0);
-
- for (i = mime_types; *i != NULL; i++)
- {
- format = *i;
- /* FIXME: image/ico is not the correct mime type. */
- *i = g_strconcat ("image/", format, NULL);
- g_free (format);
- }
-
tp_svc_connection_interface_avatars_return_from_get_avatar_requirements (
- context, (const gchar **) mime_types,
+ context, (const gchar **) _get_acceptable_mime_types (conn),
icon_spec->min_width, icon_spec->min_height,
icon_spec->max_width, icon_spec->max_height,
icon_spec->max_filesize);
- g_strfreev (mime_types);
}
static GArray *
diff --git a/src/connection.c b/src/connection.c
index 7ac8b9c..f7e47e2 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -480,6 +480,8 @@ haze_connection_constructor (GType type,
DEBUG ("Post-construction: (HazeConnection *)%p", self);
+ self->acceptable_avatar_mime_types = NULL;
+
priv->dispose_has_run = FALSE;
priv->disconnecting = FALSE;
@@ -520,9 +522,13 @@ haze_connection_dispose (GObject *object)
static void
haze_connection_finalize (GObject *object)
{
+ HazeConnection *self = HAZE_CONNECTION (object);
+
tp_contacts_mixin_finalize (object);
tp_presence_mixin_finalize (object);
+ g_strfreev (self->acceptable_avatar_mime_types);
+
G_OBJECT_CLASS (haze_connection_parent_class)->finalize (object);
}
diff --git a/src/connection.h b/src/connection.h
index 7bc3247..dda734b 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -66,6 +66,8 @@ struct _HazeConnection {
TpContactsMixin contacts;
TpPresenceMixin presence;
+ gchar **acceptable_avatar_mime_types;
+
gpointer priv;
};
--
1.5.6.5
More information about the telepathy-commits
mailing list