aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2010-07-08 00:01:59 +0800
committerTravis Reitter <treitter@gmail.com>2010-07-22 04:25:19 +0800
commite922ae799989e073cb6649578555ad686bcb0fc8 (patch)
treecf32a42153a0359bedd04618be8be2383b2ca276
parentd64a31579c0cdaa7013f5165f5111d57feb9b92e (diff)
downloadgsoc2013-empathy-e922ae799989e073cb6649578555ad686bcb0fc8.tar
gsoc2013-empathy-e922ae799989e073cb6649578555ad686bcb0fc8.tar.gz
gsoc2013-empathy-e922ae799989e073cb6649578555ad686bcb0fc8.tar.bz2
gsoc2013-empathy-e922ae799989e073cb6649578555ad686bcb0fc8.tar.lz
gsoc2013-empathy-e922ae799989e073cb6649578555ad686bcb0fc8.tar.xz
gsoc2013-empathy-e922ae799989e073cb6649578555ad686bcb0fc8.tar.zst
gsoc2013-empathy-e922ae799989e073cb6649578555ad686bcb0fc8.zip
Re-enable setting of groups for newly-added contacts
Changes to groups made while adding a contact need to be cached up until the contact's FolksPersona is set, when they can be flushed to the libfolks backend.
-rw-r--r--libempathy-gtk/empathy-contact-widget.c13
-rw-r--r--libempathy/empathy-contact.c47
-rw-r--r--libempathy/empathy-contact.h2
3 files changed, 51 insertions, 11 deletions
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index 77d22c915..4ff25b974 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -579,12 +579,7 @@ contact_widget_cell_toggled (GtkCellRendererToggle *cell,
if (group != NULL)
{
- FolksPersona *persona = empathy_contact_get_persona (
- information->contact);
-
- if (persona != NULL && FOLKS_IS_GROUPS (persona))
- folks_groups_change_group (FOLKS_GROUPS (persona), group, !was_enabled);
-
+ empathy_contact_change_group (information->contact, group, !was_enabled);
g_free (group);
}
}
@@ -791,7 +786,6 @@ contact_widget_button_group_clicked_cb (GtkButton *button,
GtkTreeView *view;
GtkListStore *store;
GtkTreeIter iter;
- FolksPersona *persona;
const gchar *group;
view = GTK_TREE_VIEW (information->treeview_groups);
@@ -805,10 +799,7 @@ contact_widget_button_group_clicked_cb (GtkButton *button,
COL_ENABLED, TRUE,
-1);
- persona = empathy_contact_get_persona (information->contact);
-
- if (persona != NULL && FOLKS_IS_GROUPS (persona))
- folks_groups_change_group (FOLKS_GROUPS (persona), group, TRUE);
+ empathy_contact_change_group (information->contact, group, TRUE);
}
static void
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index 20fe9862e..a5b799793 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -67,6 +67,7 @@ typedef struct {
* more fields by searching the address using geoclue.
*/
GHashTable *location;
+ GHashTable *groups;
} EmpathyContactPriv;
static void contact_finalize (GObject *object);
@@ -334,6 +335,7 @@ empathy_contact_init (EmpathyContact *contact)
contact->priv = priv;
priv->location = NULL;
+ priv->groups = NULL;
}
static void
@@ -345,6 +347,8 @@ contact_finalize (GObject *object)
DEBUG ("finalize: %p", object);
+ if (priv->groups != NULL)
+ g_hash_table_destroy (priv->groups);
g_free (priv->alias);
g_free (priv->id);
g_free (priv->presence_message);
@@ -649,6 +653,39 @@ empathy_contact_set_alias (EmpathyContact *contact,
g_object_unref (contact);
}
+void
+empathy_contact_change_group (EmpathyContact *contact, const gchar *group,
+ gboolean is_member)
+{
+ EmpathyContactPriv *priv;
+ FolksPersona *persona;
+
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+ g_return_if_fail (group != NULL);
+
+ priv = GET_PRIV (contact);
+
+ /* Normally pass through the changes to the persona */
+ persona = empathy_contact_get_persona (contact);
+ if (persona != NULL)
+ {
+ if (FOLKS_IS_GROUPS (persona))
+ folks_groups_change_group (FOLKS_GROUPS (persona), group, is_member);
+ return;
+ }
+
+ /* If the persona doesn't exist yet, we have to cache the changes until it
+ * does */
+ if (priv->groups == NULL)
+ {
+ priv->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+ NULL);
+ }
+
+ g_hash_table_insert (priv->groups, g_strdup (group),
+ GUINT_TO_POINTER (is_member));
+}
+
EmpathyAvatar *
empathy_contact_get_avatar (EmpathyContact *contact)
{
@@ -783,6 +820,16 @@ empathy_contact_set_persona (EmpathyContact *contact,
* empathy_contact_set_alias() before we had a persona; this happens when
* adding a contact. */
empathy_contact_set_alias (contact, priv->alias);
+
+ /* Set the persona's groups */
+ if (priv->groups != NULL)
+ {
+ if (FOLKS_IS_GROUPS (persona))
+ folks_groups_set_groups (FOLKS_GROUPS (persona), priv->groups);
+
+ g_hash_table_destroy (priv->groups);
+ priv->groups = NULL;
+ }
}
TpConnection *
diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h
index 7980ab252..3c923308b 100644
--- a/libempathy/empathy-contact.h
+++ b/libempathy/empathy-contact.h
@@ -81,6 +81,8 @@ const gchar * empathy_contact_get_id (EmpathyContact *contact);
void empathy_contact_set_id (EmpathyContact *contact, const gchar *id);
const gchar * empathy_contact_get_alias (EmpathyContact *contact);
void empathy_contact_set_alias (EmpathyContact *contact, const gchar *alias);
+void empathy_contact_change_group (EmpathyContact *contact, const gchar *group,
+ gboolean is_member);
EmpathyAvatar * empathy_contact_get_avatar (EmpathyContact *contact);
void empathy_contact_set_avatar (EmpathyContact *contact,
EmpathyAvatar *avatar);