diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2010-07-07 18:17:14 +0800 |
---|---|---|
committer | Travis Reitter <treitter@gmail.com> | 2010-07-22 00:04:29 +0800 |
commit | 7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0 (patch) | |
tree | 6ed97526bf3fd7cadf8390dd94ff79f806ca0116 | |
parent | da5ec3c2bf5f816cff03932d23aec183beb18ee5 (diff) | |
download | gsoc2013-empathy-7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0.tar gsoc2013-empathy-7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0.tar.gz gsoc2013-empathy-7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0.tar.bz2 gsoc2013-empathy-7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0.tar.lz gsoc2013-empathy-7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0.tar.xz gsoc2013-empathy-7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0.tar.zst gsoc2013-empathy-7e4dfd33eb0fe4e87aef3a0b6c8dbc94c540e7b0.zip |
Add a link between EmpathyContact and FolksPersona
EmpathyContact should eventually just be a thin wrapper over FolksPersona.
-rw-r--r-- | libempathy/empathy-contact.c | 95 | ||||
-rw-r--r-- | libempathy/empathy-contact.h | 4 | ||||
-rw-r--r-- | libempathy/empathy-individual-manager.c | 3 |
3 files changed, 102 insertions, 0 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index 7e9961f1c..64235ea9a 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -29,6 +29,9 @@ #include <telepathy-glib/interfaces.h> #include <telepathy-glib/util.h> +#include <folks/folks.h> +#include <folks/folks-telepathy.h> + #if HAVE_GEOCLUE #include <geoclue/geoclue-geocode.h> #endif @@ -46,6 +49,7 @@ typedef struct { TpContact *tp_contact; TpAccount *account; + FolksPersona *persona; gchar *id; gchar *name; EmpathyAvatar *avatar; @@ -90,6 +94,7 @@ enum PROP_0, PROP_TP_CONTACT, PROP_ACCOUNT, + PROP_PERSONA, PROP_ID, PROP_NAME, PROP_AVATAR, @@ -173,6 +178,10 @@ contact_dispose (GObject *object) g_object_unref (priv->account); priv->account = NULL; + if (priv->persona) + g_object_unref (priv->persona); + priv->persona = NULL; + if (priv->avatar != NULL) { empathy_avatar_unref (priv->avatar); @@ -217,6 +226,14 @@ empathy_contact_class_init (EmpathyContactClass *class) G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, + PROP_PERSONA, + g_param_spec_object ("persona", + "Persona", + "The FolksPersona associated with the contact", + FOLKS_TYPE_PERSONA, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_ID, g_param_spec_string ("id", "Contact id", @@ -388,6 +405,9 @@ contact_get_property (GObject *object, case PROP_ACCOUNT: g_value_set_object (value, empathy_contact_get_account (contact)); break; + case PROP_PERSONA: + g_value_set_object (value, empathy_contact_get_persona (contact)); + break; case PROP_ID: g_value_set_string (value, empathy_contact_get_id (contact)); break; @@ -436,6 +456,9 @@ contact_set_property (GObject *object, g_assert (priv->account == NULL); priv->account = g_value_dup_object (value); break; + case PROP_PERSONA: + empathy_contact_set_persona (contact, g_value_get_object (value)); + break; case PROP_ID: empathy_contact_set_id (contact, g_value_get_string (value)); break; @@ -710,6 +733,78 @@ empathy_contact_get_account (EmpathyContact *contact) return priv->account; } +FolksPersona * +empathy_contact_get_persona (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + if (priv->persona == NULL && priv->tp_contact != NULL) + { + /* FIXME: This is disgustingly slow */ + /* Query for the persona */ + EmpathyIndividualManager *manager; + GList *individuals, *l; + + manager = empathy_individual_manager_dup_singleton (); + individuals = empathy_individual_manager_get_members (manager); + + for (l = individuals; l != NULL; l = l->next) + { + GList *personas, *j; + FolksIndividual *individual = FOLKS_INDIVIDUAL (l->data); + + personas = folks_individual_get_personas (individual); + for (j = personas; j != NULL; j = j->next) + { + TpfPersona *persona = j->data; + + if (TPF_IS_PERSONA (persona)) + { + TpContact *tp_contact = tpf_persona_get_contact (persona); + + if (tp_contact == priv->tp_contact) + { + /* Found the right persona */ + priv->persona = g_object_ref (persona); + goto finished; + } + } + } + } + +finished: + g_list_free (individuals); + g_object_unref (manager); + } + + return priv->persona; +} + +void +empathy_contact_set_persona (EmpathyContact *contact, + FolksPersona *persona) +{ + EmpathyContactPriv *priv; + + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + g_return_if_fail (FOLKS_IS_PERSONA (persona)); + + priv = GET_PRIV (contact); + + if (persona == priv->persona) + return; + + if (priv->persona != NULL) + g_object_unref (priv->persona); + priv->persona = g_object_ref (persona); + + g_object_notify (G_OBJECT (contact), "persona"); +} + TpConnection * empathy_contact_get_connection (EmpathyContact *contact) { diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h index b5f24d0c5..a5b58ce64 100644 --- a/libempathy/empathy-contact.h +++ b/libempathy/empathy-contact.h @@ -27,6 +27,7 @@ #include <telepathy-glib/contact.h> #include <telepathy-glib/account.h> #include <telepathy-logger/entity.h> +#include <folks/folks.h> G_BEGIN_DECLS @@ -85,6 +86,9 @@ EmpathyAvatar * empathy_contact_get_avatar (EmpathyContact *contact); void empathy_contact_set_avatar (EmpathyContact *contact, EmpathyAvatar *avatar); TpAccount * empathy_contact_get_account (EmpathyContact *contact); +FolksPersona * empathy_contact_get_persona (EmpathyContact *contact); +void empathy_contact_set_persona (EmpathyContact *contact, + FolksPersona *persona); TpConnection * empathy_contact_get_connection (EmpathyContact *contact); TpConnectionPresenceType empathy_contact_get_presence (EmpathyContact *contact); void empathy_contact_set_presence (EmpathyContact *contact, diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c index 218dddaa6..9eeb5d3c8 100644 --- a/libempathy/empathy-individual-manager.c +++ b/libempathy/empathy-individual-manager.c @@ -282,6 +282,9 @@ aggregator_add_persona_from_details_cb (GObject *source, g_clear_error (&error); } + /* Set the contact's persona */ + empathy_contact_set_persona (contact, persona); + /* We can unref the contact now */ g_object_unref (contact); g_object_unref (persona); |