]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-contact-factory.c
Move avatar cache to ~/.cache and don't mix avatar from different contacts, tokens...
[empathy.git] / libempathy / empathy-tp-contact-factory.c
index eeb4ece71a0a0c1aa6b1faa4481e4cb9a8069674..fe68ed0a7d50d188f4ad4eb8442a097f5ee40649 100644 (file)
 #define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CONTACT
 #include "empathy-debug.h"
 
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
-                      EMPATHY_TYPE_TP_CONTACT_FACTORY, EmpathyTpContactFactoryPriv))
-
-struct _EmpathyTpContactFactoryPriv {
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpContactFactory)
+typedef struct {
        MissionControl *mc;
        McAccount      *account;
        TpConnection   *connection;
@@ -45,10 +43,7 @@ struct _EmpathyTpContactFactoryPriv {
        GList          *contacts;
        EmpathyContact *user;
        gpointer        token;
-};
-
-static void empathy_tp_contact_factory_class_init (EmpathyTpContactFactoryClass *klass);
-static void empathy_tp_contact_factory_init       (EmpathyTpContactFactory      *factory);
+} EmpathyTpContactFactoryPriv;
 
 G_DEFINE_TYPE (EmpathyTpContactFactory, empathy_tp_contact_factory, G_TYPE_OBJECT);
 
@@ -107,14 +102,18 @@ tp_contact_factory_presences_table_foreach (const gchar    *state_str,
                                            EmpathyContact *contact)
 {
        const GValue *message;
+       const gchar  *message_str = NULL;
 
        empathy_contact_set_presence (contact,
                                      empathy_presence_from_str (state_str));
        
        message = g_hash_table_lookup (presences_table, "message");
-       if (message != NULL) {
-               empathy_contact_set_presence_message (contact,
-                                                     g_value_get_string (message));
+       if (message) {
+               message_str = g_value_get_string (message);
+       }
+
+       if (!G_STR_EMPTY (message_str)) {
+               empathy_contact_set_presence_message (contact, message_str);
        } else {
                empathy_contact_set_presence_message (contact, NULL);
        }
@@ -139,7 +138,7 @@ tp_contact_factory_parse_presence_foreach (guint                    handle,
                              (GHFunc) tp_contact_factory_presences_table_foreach,
                              contact);
 
-       DEBUG ("Changing presence for contact %s (%d) to %s (%d)",
+       DEBUG ("Changing presence for contact %s (%d) to '%s' (%d)",
                empathy_contact_get_id (contact),
                handle,
                empathy_contact_get_presence_message (contact),
@@ -324,7 +323,6 @@ tp_contact_factory_avatar_retrieved_cb (TpConnection *connection,
                                        GObject      *tp_factory)
 {
        EmpathyContact *contact;
-       EmpathyAvatar  *avatar;
 
        contact = tp_contact_factory_find_by_handle (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
                                                     handle);
@@ -336,13 +334,11 @@ tp_contact_factory_avatar_retrieved_cb (TpConnection *connection,
                empathy_contact_get_id (contact),
                handle);
 
-       avatar = empathy_avatar_new (avatar_data->data,
-                                    avatar_data->len,
-                                    mime_type,
-                                    token);
-
-       empathy_contact_set_avatar (contact, avatar);
-       empathy_avatar_unref (avatar);
+       empathy_contact_load_avatar_data (contact,
+                                         avatar_data->data,
+                                         avatar_data->len,
+                                         mime_type,
+                                         token);
 }
 
 static void
@@ -382,11 +378,8 @@ tp_contact_factory_avatar_maybe_update (EmpathyTpContactFactory *tp_factory,
        }
 
        /* The avatar changed, search the new one in the cache */
-       avatar = empathy_avatar_new_from_cache (token);
-       if (avatar) {
+       if (empathy_contact_load_avatar_cache (contact, token)) {
                /* Got from cache, use it */
-               empathy_contact_set_avatar (contact, avatar);
-               empathy_avatar_unref (avatar);
                return TRUE;
        }
 
@@ -805,8 +798,6 @@ tp_contact_factory_got_self_handle_cb (TpConnection *proxy,
                                                handle_needed_contacts, tp_contact_factory_list_free,
                                                G_OBJECT (tp_factory));
 
-       tp_contact_factory_request_everything ((EmpathyTpContactFactory*) tp_factory,
-                                              id_needed);
        tp_cli_connection_call_inspect_handles (priv->connection,
                                                -1,
                                                TP_HANDLE_TYPE_CONTACT,
@@ -815,6 +806,9 @@ tp_contact_factory_got_self_handle_cb (TpConnection *proxy,
                                                id_needed_contacts, tp_contact_factory_list_free,
                                                G_OBJECT (tp_factory));
 
+       tp_contact_factory_request_everything ((EmpathyTpContactFactory*) tp_factory,
+                                              id_needed);
+
        g_array_free (handle_needed, TRUE);
        g_array_free (id_needed, TRUE);
 }
@@ -1272,8 +1266,10 @@ empathy_tp_contact_factory_class_init (EmpathyTpContactFactoryClass *klass)
 static void
 empathy_tp_contact_factory_init (EmpathyTpContactFactory *tp_factory)
 {
-       EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
+       EmpathyTpContactFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (tp_factory,
+               EMPATHY_TYPE_TP_CONTACT_FACTORY, EmpathyTpContactFactoryPriv);
 
+       tp_factory->priv = priv;
        priv->mc = empathy_mission_control_new ();
        priv->token = empathy_connect_to_account_status_changed (priv->mc,
                                                   G_CALLBACK (tp_contact_factory_status_changed_cb),