aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-contact.c
diff options
context:
space:
mode:
Diffstat (limited to 'libempathy/empathy-contact.c')
-rw-r--r--libempathy/empathy-contact.c70
1 files changed, 59 insertions, 11 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index 03ce8d28a..bad6ef470 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -830,17 +830,16 @@ static gchar *
contact_get_avatar_filename (EmpathyContact *contact,
const gchar *token)
{
- EmpathyContactPriv *priv = GET_PRIV (contact);
McAccount *account;
gchar *avatar_path;
gchar *avatar_file;
gchar *token_escaped;
gchar *contact_escaped;
- if (EMP_STR_EMPTY (priv->id))
+ if (EMP_STR_EMPTY (empathy_contact_get_id (contact)))
return NULL;
- contact_escaped = tp_escape_as_identifier (priv->id);
+ contact_escaped = tp_escape_as_identifier (empathy_contact_get_id (contact));
token_escaped = tp_escape_as_identifier (token);
account = empathy_contact_get_account (contact);
@@ -864,7 +863,7 @@ contact_get_avatar_filename (EmpathyContact *contact,
void
empathy_contact_load_avatar_data (EmpathyContact *contact,
- const guchar *data,
+ const guchar *data,
const gsize len,
const gchar *format,
const gchar *token)
@@ -880,13 +879,13 @@ empathy_contact_load_avatar_data (EmpathyContact *contact,
g_return_if_fail (!EMP_STR_EMPTY (token));
/* Load and set the avatar */
+ filename = contact_get_avatar_filename (contact, token);
avatar = empathy_avatar_new (g_memdup (data, len), len, g_strdup (format),
- g_strdup (token));
+ g_strdup (token), filename);
empathy_contact_set_avatar (contact, avatar);
empathy_avatar_unref (avatar);
/* Save to cache if not yet in it */
- filename = contact_get_avatar_filename (contact, token);
if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
{
if (!empathy_avatar_save_to_file (avatar, filename, &error))
@@ -898,7 +897,6 @@ empathy_contact_load_avatar_data (EmpathyContact *contact,
else
DEBUG ("Avatar saved to %s", filename);
}
- g_free (filename);
}
gboolean
@@ -929,13 +927,11 @@ empathy_contact_load_avatar_cache (EmpathyContact *contact,
if (data)
{
DEBUG ("Avatar loaded from %s", filename);
- avatar = empathy_avatar_new (data, len, NULL, g_strdup (token));
+ avatar = empathy_avatar_new (data, len, NULL, g_strdup (token), filename);
empathy_contact_set_avatar (contact, avatar);
empathy_avatar_unref (avatar);
}
- g_free (filename);
-
return data != NULL;
}
@@ -954,11 +950,25 @@ empathy_avatar_get_type (void)
return type_id;
}
+/**
+ * empathy_avatar_new:
+ * @data: the avatar data
+ * @len: the size of avatar data
+ * @format: the mime type of the avatar image
+ * @token: the token of the avatar
+ * @filename: the filename where the avatar is stored in cache
+ *
+ * Create a #EmpathyAvatar from the provided data. This function takes the
+ * ownership of @data, @format, @token and @filename.
+ *
+ * Returns: a new #EmpathyAvatar
+ */
EmpathyAvatar *
empathy_avatar_new (guchar *data,
gsize len,
gchar *format,
- gchar *token)
+ gchar *token,
+ gchar *filename)
{
EmpathyAvatar *avatar;
@@ -967,6 +977,7 @@ empathy_avatar_new (guchar *data,
avatar->len = len;
avatar->format = format;
avatar->token = token;
+ avatar->filename = filename;
avatar->refcount = 1;
return avatar;
@@ -1071,3 +1082,40 @@ empathy_contact_set_location (EmpathyContact *contact,
priv->location = g_hash_table_ref (location);
g_object_notify (G_OBJECT (contact), "location");
}
+
+/**
+ * empathy_contact_equal:
+ * @contact1: an #EmpathyContact
+ * @contact2: an #EmpathyContact
+ *
+ * Returns FALSE if one of the contacts is NULL but the other is not.
+ * Otherwise returns TRUE if both pointer are equal or if they bith
+ * refer to the same id.
+ * It's only necessary to call this function if your contact objects
+ * come from logs where contacts are created dynamically and comparing
+ * pointers is not enough.
+ */
+gboolean
+empathy_contact_equal (gconstpointer contact1,
+ gconstpointer contact2)
+{
+ EmpathyContact *c1;
+ EmpathyContact *c2;
+ const gchar *id1;
+ const gchar *id2;
+
+ if ((contact1 == NULL) != (contact2 == NULL)) {
+ return FALSE;
+ }
+ if (contact1 == contact2) {
+ return TRUE;
+ }
+ c1 = EMPATHY_CONTACT (contact1);
+ c2 = EMPATHY_CONTACT (contact2);
+ id1 = empathy_contact_get_id (c1);
+ id2 = empathy_contact_get_id (c2);
+ if (!tp_strdiff (id1, id2)) {
+ return TRUE;
+ }
+ return FALSE;
+}