]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-widget.c
Merge branch 'sasl'
[empathy.git] / libempathy-gtk / empathy-contact-widget.c
index 82a5ac703bd976f85aea77b6a82b241db01eec77..26713ebe421c34dbadf5f8f2f2b9dd00bba97bd1 100644 (file)
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
 #include <champlain/champlain.h>
 #include <champlain-gtk/champlain-gtk.h>
 #endif
 
 #include <telepathy-glib/account.h>
 #include <telepathy-glib/util.h>
+#include <telepathy-glib/interfaces.h>
 
 #include <libempathy/empathy-tp-contact-factory.h>
 #include <libempathy/empathy-contact-manager.h>
@@ -46,9 +47,9 @@
 #include "empathy-account-chooser.h"
 #include "empathy-avatar-chooser.h"
 #include "empathy-avatar-image.h"
+#include "empathy-groups-widget.h"
 #include "empathy-ui-utils.h"
 #include "empathy-string-parser.h"
-#include "empathy-kludge-label.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
 #include <libempathy/empathy-debug.h>
@@ -77,7 +78,6 @@
 
 typedef struct
 {
-  EmpathyTpContactFactory *factory;
   EmpathyContactManager *manager;
   EmpathyContact *contact;
   EmpathyContactWidgetFlags flags;
@@ -95,7 +95,6 @@ typedef struct
   GtkWidget *widget_id;
   GtkWidget *widget_alias;
   GtkWidget *label_alias;
-  GtkWidget *entry_alias;
   GtkWidget *hbox_presence;
   GtkWidget *image_state;
   GtkWidget *label_status;
@@ -108,22 +107,22 @@ typedef struct
   GtkWidget *subvbox_location;
   GtkWidget *table_location;
   GtkWidget *label_location;
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
   GtkWidget *viewport_map;
   GtkWidget *map_view_embed;
   ChamplainView *map_view;
 #endif
 
   /* Groups */
-  GtkWidget *vbox_groups;
-  GtkWidget *entry_group;
-  GtkWidget *button_group;
-  GtkWidget *treeview_groups;
+  GtkWidget *groups_widget;
 
   /* Details */
   GtkWidget *vbox_details;
   GtkWidget *table_details;
   GtkWidget *hbox_details_requested;
+  GtkWidget *spinner_details;
+  GList *details_to_set;
+  GCancellable *details_cancellable;
 
   /* Client */
   GtkWidget *vbox_client;
@@ -147,327 +146,520 @@ enum
   COL_COUNT
 };
 
-static void
-contact_widget_details_setup (EmpathyContactWidget *information)
+static gboolean
+field_value_is_empty (TpContactInfoField *field)
 {
-  /* FIXME: Needs new telepathy spec */
-  gtk_widget_hide (information->vbox_details);
-}
+  guint i;
 
-static void
-contact_widget_details_update (EmpathyContactWidget *information)
-{
-  /* FIXME: Needs new telepathy spec */
-}
+  if (field->field_value == NULL)
+    return TRUE;
 
-static void
-contact_widget_client_update (EmpathyContactWidget *information)
-{
-  /* FIXME: Needs new telepathy spec */
+  /* Field is empty if all its values are empty */
+  for (i = 0; field->field_value[i] != NULL; i++)
+    {
+      if (!tp_str_empty (field->field_value[i]))
+        return FALSE;
+    }
+
+  return TRUE;
 }
 
 static void
-contact_widget_client_setup (EmpathyContactWidget *information)
+set_contact_info_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
-  /* FIXME: Needs new telepathy spec */
-  gtk_widget_hide (information->vbox_client);
+  GError *error = NULL;
+
+  if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
+        &error))
+    {
+      DEBUG ("SetContactInfo() failed: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  DEBUG ("SetContactInfo() succeeded");
 }
 
 static void
-contact_widget_cell_toggled (GtkCellRendererToggle *cell,
-                             gchar *path_string,
-                             EmpathyContactWidget *information)
+contact_widget_save (EmpathyContactWidget *information)
 {
-  GtkTreeView *view;
-  GtkTreeModel *model;
-  GtkListStore *store;
-  GtkTreePath *path;
-  GtkTreeIter iter;
-  gboolean enabled;
-  gchar *group;
-
-  view = GTK_TREE_VIEW (information->treeview_groups);
-  model = gtk_tree_view_get_model (view);
-  store = GTK_LIST_STORE (model);
-
-  path = gtk_tree_path_new_from_string (path_string);
-
-  gtk_tree_model_get_iter (model, &iter, path);
-  gtk_tree_model_get (model, &iter,
-      COL_ENABLED, &enabled,
-      COL_NAME, &group,
-      -1);
-
-  gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
-  gtk_tree_path_free (path);
-
-  if (group)
+  TpConnection *connection;
+  GList *l, *next;
+
+  connection = empathy_contact_get_connection (information->contact);
+
+  /* Remove empty fields */
+  for (l = information->details_to_set; l != NULL; l = next)
     {
-      if (enabled)
-        {
-          empathy_contact_list_remove_from_group (
-              EMPATHY_CONTACT_LIST (information->manager), information->contact,
-              group);
-        }
-      else
+      TpContactInfoField *field = l->data;
+
+      next = l->next;
+      if (field_value_is_empty (field))
         {
-          empathy_contact_list_add_to_group (
-              EMPATHY_CONTACT_LIST (information->manager), information->contact,
-              group);
+          DEBUG ("Drop empty field: %s", field->field_name);
+          tp_contact_info_field_free (field);
+          information->details_to_set =
+              g_list_delete_link (information->details_to_set, l);
         }
-      g_free (group);
+    }
+
+  if (information->details_to_set != NULL)
+    {
+      tp_connection_set_contact_info_async (connection,
+          information->details_to_set, set_contact_info_cb, NULL);
+      tp_contact_info_list_free (information->details_to_set);
+      information->details_to_set = NULL;
     }
 }
 
 static void
-contact_widget_model_populate_columns (EmpathyContactWidget *information)
+contact_widget_details_setup (EmpathyContactWidget *information)
 {
-  GtkTreeView *view;
-  GtkTreeModel *model;
-  GtkTreeViewColumn *column;
-  GtkCellRenderer  *renderer;
-  guint col_offset;
-
-  view = GTK_TREE_VIEW (information->treeview_groups);
-  model = gtk_tree_view_get_model (view);
-
-  renderer = gtk_cell_renderer_toggle_new ();
-  g_signal_connect (renderer, "toggled",
-      G_CALLBACK (contact_widget_cell_toggled), information);
-
-  column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
-      "active", COL_ENABLED, NULL);
-
-  gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
-  gtk_tree_view_column_set_fixed_width (column, 50);
-  gtk_tree_view_append_column (view, column);
-
-  renderer = gtk_cell_renderer_text_new ();
-  col_offset = gtk_tree_view_insert_column_with_attributes (view,
-      -1, _("Group"),
-      renderer,
-      "text", COL_NAME,
-      /* "editable", COL_EDITABLE, */
-      NULL);
-
-  g_object_set_data (G_OBJECT (renderer),
-      "column", GINT_TO_POINTER (COL_NAME));
+  gtk_widget_hide (information->vbox_details);
 
-  column = gtk_tree_view_get_column (view, col_offset - 1);
-  gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
-  gtk_tree_view_column_set_resizable (column,FALSE);
-  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
+  information->spinner_details = gtk_spinner_new ();
+  gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
+      information->spinner_details, TRUE, TRUE, 0);
+  gtk_widget_show (information->spinner_details);
 }
 
 static void
-contact_widget_model_setup (EmpathyContactWidget *information)
+contact_widget_details_changed_cb (GtkEntry *entry,
+    TpContactInfoField *field)
 {
-  GtkTreeView *view;
-  GtkListStore *store;
-  GtkTreeSelection *selection;
+  const gchar *strv[] = { NULL, NULL };
 
-  view = GTK_TREE_VIEW (information->treeview_groups);
+  strv[0] = gtk_entry_get_text (entry);
 
-  store = gtk_list_store_new (COL_COUNT,
-      G_TYPE_STRING,   /* name */
-      G_TYPE_BOOLEAN,  /* enabled */
-      G_TYPE_BOOLEAN); /* editable */
+  if (field->field_value != NULL)
+    g_strfreev (field->field_value);
+  field->field_value = g_strdupv ((GStrv) strv);
+}
 
-  gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
+static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
 
-  selection = gtk_tree_view_get_selection (view);
-  gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+typedef struct
+{
+  const gchar *field_name;
+  const gchar *title;
+  gboolean linkify;
+} InfoFieldData;
 
-  contact_widget_model_populate_columns (information);
+static InfoFieldData info_field_datas[] =
+{
+  { "fn",    N_("Full name:"),      FALSE },
+  { "tel",   N_("Phone number:"),   FALSE },
+  { "email", N_("E-mail address:"), TRUE },
+  { "url",   N_("Website:"),        TRUE },
+  { "bday",  N_("Birthday:"),       FALSE },
+  { NULL, NULL }
+};
 
-  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
-      COL_NAME, GTK_SORT_ASCENDING);
+static InfoFieldData *
+find_info_field_data (const gchar *field_name)
+{
+  guint i;
 
-  g_object_unref (store);
+  for (i = 0; info_field_datas[i].field_name != NULL; i++)
+    {
+      if (!tp_strdiff (info_field_datas[i].field_name, field_name))
+        return info_field_datas + i;
+    }
+  return NULL;
 }
 
-static void
-contact_widget_groups_populate_data (EmpathyContactWidget *information)
+static gint
+contact_info_field_name_cmp (const gchar *name1,
+    const gchar *name2)
+{
+  guint i;
+
+  if (!tp_strdiff (name1, name2))
+    return 0;
+
+  /* We use the order of info_field_datas */
+  for (i = 0; info_field_datas[i].field_name != NULL; i++)
+    {
+      if (!tp_strdiff (info_field_datas[i].field_name, name1))
+        return -1;
+      if (!tp_strdiff (info_field_datas[i].field_name, name2))
+        return +1;
+    }
+
+  return g_strcmp0 (name1, name2);
+}
+
+static gint
+contact_info_field_cmp (TpContactInfoField *field1,
+    TpContactInfoField *field2)
+{
+  return contact_info_field_name_cmp (field1->field_name, field2->field_name);
+}
+
+static gboolean
+field_name_in_field_list (GList *list,
+    const gchar *name)
 {
-  GtkTreeView *view;
-  GtkListStore *store;
-  GtkTreeIter iter;
-  GList *my_groups, *l;
-  GList *all_groups;
-
-  view = GTK_TREE_VIEW (information->treeview_groups);
-  store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
-  gtk_list_store_clear (store);
-
-  all_groups = empathy_contact_list_get_all_groups (
-      EMPATHY_CONTACT_LIST (information->manager));
-  my_groups = empathy_contact_list_get_groups (
-      EMPATHY_CONTACT_LIST (information->manager),
-      information->contact);
-
-  for (l = all_groups; l; l = l->next)
+  GList *l;
+
+  for (l = list; l != NULL; l = g_list_next (l))
     {
-      const gchar *group_str;
-      gboolean enabled;
+      TpContactInfoField *field = l->data;
+
+      if (!tp_strdiff (field->field_name, name))
+        return TRUE;
+    }
+
+  return FALSE;
+}
 
-      group_str = l->data;
+static TpContactInfoFieldSpec *
+get_spec_from_list (GList *list,
+    const gchar *name)
+{
+  GList *l;
 
-      enabled = g_list_find_custom (my_groups,
-          group_str, (GCompareFunc) strcmp) != NULL;
+  for (l = list; l != NULL; l = g_list_next (l))
+    {
+      TpContactInfoFieldSpec *spec = l->data;
 
-      gtk_list_store_append (store, &iter);
-      gtk_list_store_set (store, &iter,
-          COL_NAME, group_str,
-          COL_EDITABLE, TRUE,
-          COL_ENABLED, enabled,
-          -1);
+      if (!tp_strdiff (spec->name, name))
+        return spec;
     }
 
-  g_list_foreach (all_groups, (GFunc) g_free, NULL);
-  g_list_foreach (my_groups, (GFunc) g_free, NULL);
-  g_list_free (all_groups);
-  g_list_free (my_groups);
+  return NULL;
 }
 
-static gboolean
-contact_widget_model_find_name_foreach (GtkTreeModel *model,
-                                        GtkTreePath *path,
-                                        GtkTreeIter *iter,
-                                        FindName *data)
+static guint
+contact_widget_details_update_edit (EmpathyContactWidget *information)
 {
-  gchar *name;
+  TpContact *contact;
+  TpConnection *connection;
+  GList *specs, *l;
+  guint n_rows = 0;
+  GList *info;
+  guint i;
 
-  gtk_tree_model_get (model, iter,
-      COL_NAME, &name,
-      -1);
+  g_assert (information->details_to_set == NULL);
 
-  if (!name)
-      return FALSE;
+  contact = empathy_contact_get_tp_contact (information->contact);
+  connection = tp_contact_get_connection (contact);
 
-  if (data->name && strcmp (data->name, name) == 0)
+  info = tp_contact_get_contact_info (contact);
+
+  specs = tp_connection_get_contact_info_supported_fields (connection);
+
+  /* Look at the fields set in our vCard */
+  for (l = info; l != NULL; l = l->next)
     {
-      data->found = TRUE;
-      data->found_iter = *iter;
+      TpContactInfoField *field = l->data;
 
-      g_free (name);
+      /* make a copy for the details_to_set list */
+      field = tp_contact_info_field_copy (field);
+      DEBUG ("Field %s is in our vCard", field->field_name);
 
-      return TRUE;
+      information->details_to_set = g_list_prepend (information->details_to_set,
+          field);
     }
 
-  g_free (name);
+  /* Add fields which are supported but not in the vCard */
+  for (i = 0; info_field_datas[i].field_name != NULL; i++)
+    {
+      TpContactInfoFieldSpec *spec;
+      TpContactInfoField *field;
 
-  return FALSE;
+      /* Check if the field was in the vCard */
+      if (field_name_in_field_list (information->details_to_set,
+            info_field_datas[i].field_name))
+        continue;
+
+      /* Check if the CM supports the field */
+      spec = get_spec_from_list (specs, info_field_datas[i].field_name);
+      if (spec == NULL)
+        continue;
+
+      /* add an empty field so user can set a value */
+      field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
+
+      information->details_to_set = g_list_prepend (information->details_to_set,
+          field);
+    }
+
+  /* Add widgets for supported fields */
+  information->details_to_set = g_list_sort (information->details_to_set,
+      (GCompareFunc) contact_info_field_cmp);
+
+  for (l = information->details_to_set; l != NULL; l= g_list_next (l))
+    {
+      TpContactInfoField *field = l->data;
+      InfoFieldData *field_data;
+      GtkWidget *w;
+
+      field_data = find_info_field_data (field->field_name);
+      if (field_data == NULL)
+        {
+          /* Empathy doesn't display this field so we can't change it.
+           * But we put it in the details_to_set list so it won't be erased
+           * when calling SetContactInfo (bgo #630427) */
+          DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
+          continue;
+        }
+
+      /* Add Title */
+      w = gtk_label_new (_(field_data->title));
+      gtk_table_attach (GTK_TABLE (information->table_details),
+          w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
+      gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+      gtk_widget_show (w);
+
+      /* Add Value */
+      w = gtk_entry_new ();
+      gtk_entry_set_text (GTK_ENTRY (w),
+          field->field_value[0] ? field->field_value[0] : "");
+      gtk_table_attach_defaults (GTK_TABLE (information->table_details),
+          w, 1, 2, n_rows, n_rows + 1);
+      gtk_widget_show (w);
+
+      g_signal_connect (w, "changed",
+        G_CALLBACK (contact_widget_details_changed_cb), field);
+
+      n_rows++;
+    }
+
+  g_list_free (specs);
+  g_list_free (info);
+
+  return n_rows;
 }
 
-static gboolean
-contact_widget_model_find_name (EmpathyContactWidget *information,
-                                const gchar *name,
-                                GtkTreeIter *iter)
+static guint
+contact_widget_details_update_show (EmpathyContactWidget *information)
 {
-  GtkTreeView *view;
-  GtkTreeModel *model;
-  FindName data;
+  TpContact *contact;
+  GList *info, *l;
+  guint n_rows = 0;
+
+  contact = empathy_contact_get_tp_contact (information->contact);
+  info = tp_contact_get_contact_info (contact);
+  info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
+  for (l = info; l != NULL; l = l->next)
+    {
+      TpContactInfoField *field = l->data;
+      InfoFieldData *field_data;
+      const gchar *value;
+      GtkWidget *w;
+
+      if (field->field_value == NULL || field->field_value[0] == NULL)
+        continue;
+
+      value = field->field_value[0];
+
+      field_data = find_info_field_data (field->field_name);
+      if (field_data == NULL)
+        {
+          DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
+          continue;
+        }
+
+      /* Add Title */
+      w = gtk_label_new (_(field_data->title));
+      gtk_table_attach (GTK_TABLE (information->table_details),
+          w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
+      gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+      gtk_widget_show (w);
+
+      /* Add Value */
+      w = gtk_label_new (value);
+      if (field_data->linkify)
+        {
+          gchar *markup;
+
+          markup = empathy_add_link_markup (value);
+          gtk_label_set_markup (GTK_LABEL (w), markup);
+          g_free (markup);
+        }
+
+      if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
+        gtk_label_set_selectable (GTK_LABEL (w), TRUE);
+
+      gtk_table_attach_defaults (GTK_TABLE (information->table_details),
+          w, 1, 2, n_rows, n_rows + 1);
+      gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+      gtk_widget_show (w);
+
+      n_rows++;
+    }
+  g_list_free (info);
 
-  if (EMP_STR_EMPTY (name))
-      return FALSE;
+  return n_rows;
+}
 
-  data.information = information;
-  data.name = name;
-  data.found = FALSE;
+static void
+contact_widget_details_notify_cb (EmpathyContactWidget *information)
+{
+  guint n_rows;
 
-  view = GTK_TREE_VIEW (information->treeview_groups);
-  model = gtk_tree_view_get_model (view);
+  gtk_container_foreach (GTK_CONTAINER (information->table_details),
+      (GtkCallback) gtk_widget_destroy, NULL);
 
-  gtk_tree_model_foreach (model,
-      (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
-      &data);
+  if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
+    n_rows = contact_widget_details_update_edit (information);
+  else
+    n_rows = contact_widget_details_update_show (information);
 
-  if (data.found == TRUE)
+  if (n_rows > 0)
     {
-      *iter = data.found_iter;
-      return TRUE;
+      gtk_widget_show (information->vbox_details);
+      gtk_widget_show (information->table_details);
+    }
+  else
+    {
+      gtk_widget_hide (information->vbox_details);
     }
 
-  return FALSE;
+  gtk_widget_hide (information->hbox_details_requested);
+  gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
 }
 
 static void
-contact_widget_entry_group_changed_cb (GtkEditable *editable,
-                                       EmpathyContactWidget *information)
+contact_widget_details_request_cb (GObject *object,
+    GAsyncResult *res,
+    gpointer user_data)
 {
-  GtkTreeIter iter;
-  const gchar *group;
+  TpContact *contact = TP_CONTACT (object);
+  EmpathyContactWidget *information = user_data;
+  GError *error = NULL;
 
-  group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
+  if (!tp_contact_request_contact_info_finish (contact, res, &error))
+    {
+      /* If the request got cancelled it could mean the contact widget is
+       * destroyed, so we should not dereference information */
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          g_clear_error (&error);
+          return;
+        }
 
-  if (contact_widget_model_find_name (information, group, &iter))
-      gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
+      gtk_widget_hide (information->vbox_details);
+      g_clear_error (&error);
+    }
   else
-      gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
-          !EMP_STR_EMPTY (group));
+    {
+      contact_widget_details_notify_cb (information);
+    }
+
+  /* If we are going to edit ContactInfo, we don't want live updates */
+  if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
+    {
+      g_signal_connect_swapped (contact, "notify::contact-info",
+          G_CALLBACK (contact_widget_details_notify_cb), information);
+    }
+
+  tp_clear_object (&information->details_cancellable);
 }
 
 static void
-contact_widget_entry_group_activate_cb (GtkEntry *entry,
-                                        EmpathyContactWidget  *information)
+contact_widget_details_feature_prepared_cb (GObject *object,
+    GAsyncResult *res,
+    gpointer user_data)
 {
-  gtk_widget_activate (GTK_WIDGET (information->button_group));
+  TpConnection *connection = TP_CONNECTION (object);
+  EmpathyContactWidget *information = user_data;
+  TpContact *contact;
+  TpContactInfoFlags flags;
+
+  if (!tp_proxy_prepare_finish (connection, res, NULL))
+    {
+      gtk_widget_hide (information->vbox_details);
+      return;
+    }
+
+  /* If we want to edit info, but connection does not support that, stop */
+  flags = tp_connection_get_contact_info_flags (connection);
+  if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
+      (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
+    {
+      gtk_widget_hide (information->vbox_details);
+      return;
+    }
+
+  /* Request the contact's info */
+  gtk_widget_show (information->vbox_details);
+  gtk_widget_show (information->hbox_details_requested);
+  gtk_widget_hide (information->table_details);
+  gtk_spinner_start (GTK_SPINNER (information->spinner_details));
+
+  contact = empathy_contact_get_tp_contact (information->contact);
+  g_assert (information->details_cancellable == NULL);
+  information->details_cancellable = g_cancellable_new ();
+  tp_contact_request_contact_info_async (contact,
+      information->details_cancellable, contact_widget_details_request_cb,
+      information);
 }
 
 static void
-contact_widget_button_group_clicked_cb (GtkButton *button,
-                                        EmpathyContactWidget *information)
+contact_widget_details_update (EmpathyContactWidget *information)
 {
-  GtkTreeView *view;
-  GtkListStore *store;
-  GtkTreeIter iter;
-  const gchar *group;
+  TpContact *tp_contact = NULL;
 
-  view = GTK_TREE_VIEW (information->treeview_groups);
-  store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
+  if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
+      (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
+    return;
 
-  group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
+  gtk_widget_hide (information->vbox_details);
 
-  gtk_list_store_append (store, &iter);
-  gtk_list_store_set (store, &iter,
-      COL_NAME, group,
-      COL_ENABLED, TRUE,
-      -1);
+  if (information->contact != NULL)
+    tp_contact = empathy_contact_get_tp_contact (information->contact);
 
-  empathy_contact_list_add_to_group (
-      EMPATHY_CONTACT_LIST (information->manager), information->contact,
-      group);
+  if (tp_contact != NULL)
+    {
+      GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
+      TpConnection *connection;
+
+      /* First, make sure the CONTACT_INFO feature is ready on the connection */
+      connection = tp_contact_get_connection (tp_contact);
+      tp_proxy_prepare_async (connection, features,
+          contact_widget_details_feature_prepared_cb, information);
+    }
 }
 
 static void
-contact_widget_groups_notify_cb (EmpathyContactWidget *information)
+contact_widget_client_update (EmpathyContactWidget *information)
 {
-  /* FIXME: not implemented */
+  /* FIXME: Needs new telepathy spec */
 }
 
 static void
-contact_widget_groups_setup (EmpathyContactWidget *information)
+contact_widget_client_setup (EmpathyContactWidget *information)
 {
-  if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
-    {
-      contact_widget_model_setup (information);
-    }
+  /* FIXME: Needs new telepathy spec */
+  gtk_widget_hide (information->vbox_client);
 }
 
 static void
 contact_widget_groups_update (EmpathyContactWidget *information)
 {
   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
-      information->contact)
+      information->contact != NULL)
     {
-      g_signal_connect_swapped (information->contact, "notify::groups",
-          G_CALLBACK (contact_widget_groups_notify_cb), information);
-      contact_widget_groups_populate_data (information);
+      FolksPersona *persona =
+          empathy_contact_get_persona (information->contact);
+
+      if (FOLKS_IS_GROUPABLE (persona))
+        {
+          empathy_groups_widget_set_groupable (
+              EMPATHY_GROUPS_WIDGET (information->groups_widget),
+              FOLKS_GROUPABLE (persona));
+          gtk_widget_show (information->groups_widget);
 
-      gtk_widget_show (information->vbox_groups);
+          return;
+        }
     }
-  else
-      gtk_widget_hide (information->vbox_groups);
+
+  /* In case of failure */
+  gtk_widget_hide (information->groups_widget);
 }
 
 /* Converts the Location's GHashTable's key to a user readable string */
@@ -594,14 +786,19 @@ contact_widget_location_update (EmpathyContactWidget *information)
       gchar *text;
       gint64 stamp;
       time_t time_;
+      gchar *tmp;
 
       stamp = g_value_get_int64 (value);
       time_ = stamp;
 
       user_date = empathy_time_to_string_relative (time_);
 
-      text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL);
+      tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
+      /* translators: format is "Location, $date" */
+      text = g_strdup_printf (_("%s, %s"), tmp, user_date);
+      g_free (tmp);
       gtk_label_set_markup (GTK_LABEL (information->label_location), text);
+      g_free (user_date);
       g_free (text);
     }
 
@@ -669,7 +866,7 @@ contact_widget_location_update (EmpathyContactWidget *information)
       row++;
     }
 
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
   if (has_position &&
       !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
     {
@@ -691,7 +888,7 @@ contact_widget_location_update (EmpathyContactWidget *information)
       return;
     }
 
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
   if (display_map)
     {
       ClutterActor *marker;
@@ -713,7 +910,7 @@ contact_widget_location_update (EmpathyContactWidget *information)
       champlain_view_add_layer (information->map_view, layer);
 
       marker = champlain_marker_new_with_text (
-          empathy_contact_get_name (information->contact), NULL, NULL, NULL);
+          empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
       champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
       clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
 
@@ -871,6 +1068,32 @@ widget_avatar_button_press_event_cb (GtkWidget *widget,
   return FALSE;
 }
 
+static void
+set_avatar_cb (GObject *source,
+    GAsyncResult *res,
+    gpointer user_data)
+{
+  GError *error = NULL;
+
+  if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
+      DEBUG ("Failed to set Account.Avatar: %s", error->message);
+      g_error_free (error);
+  }
+}
+
+static void
+set_avatar_on_account (TpAccount *account,
+    const gchar *data,
+    gsize size,
+    const gchar *mime_type)
+{
+  DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
+      tp_proxy_get_object_path (account));
+
+  tp_account_set_avatar_async (account, (const guchar *) data, size,
+      mime_type, set_avatar_cb, NULL);
+}
+
 static void
 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
                                   EmpathyContactWidget *information)
@@ -878,12 +1101,37 @@ contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
   const gchar *data;
   gsize size;
   const gchar *mime_type;
+  TpAccount *account;
 
   empathy_avatar_chooser_get_image_data (
       EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
       &data, &size, &mime_type);
-  empathy_tp_contact_factory_set_avatar (information->factory,
-      data, size, mime_type);
+
+  account = empathy_contact_get_account (information->contact);
+  set_avatar_on_account (account, data, size, mime_type);
+}
+
+static void
+set_nickname_cb (GObject *source,
+    GAsyncResult *res,
+    gpointer user_data)
+{
+  GError *error = NULL;
+
+  if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
+    {
+      DEBUG ("Failed to set Account.Nickname: %s", error->message);
+      g_error_free (error);
+    }
+}
+
+static void
+set_alias_on_account (TpAccount *account,
+    const gchar *alias)
+{
+  DEBUG ("Set Account.Nickname to %s", alias);
+
+  tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
 }
 
 static gboolean
@@ -896,8 +1144,18 @@ contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
       const gchar *alias;
 
       alias = gtk_entry_get_text (GTK_ENTRY (editable));
-      empathy_tp_contact_factory_set_alias (information->factory,
-          information->contact, alias);
+
+      if (empathy_contact_is_user (information->contact))
+        {
+          TpAccount * account;
+
+          account = empathy_contact_get_account (information->contact);
+          set_alias_on_account (account, alias);
+        }
+      else
+        {
+          empathy_contact_set_alias (information->contact, alias);
+        }
     }
 
   return FALSE;
@@ -907,10 +1165,13 @@ static void
 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
                                   EmpathyAvatarChooser *avatar_chooser)
 {
-  TpConnection *connection;
+  TpAccount *account;
 
-  connection = empathy_account_chooser_get_connection (account_chooser);
-  g_object_set (avatar_chooser, "connection", connection, NULL);
+  account = empathy_account_chooser_get_account (account_chooser);
+  if (account == NULL)
+    return;
+
+  empathy_avatar_chooser_set_account (avatar_chooser, account);
 }
 
 static void
@@ -941,10 +1202,10 @@ contact_widget_name_notify_cb (EmpathyContactWidget *information)
 {
   if (GTK_IS_ENTRY (information->widget_alias))
       gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
-          empathy_contact_get_name (information->contact));
+          empathy_contact_get_alias (information->contact));
   else
       gtk_label_set_label (GTK_LABEL (information->widget_alias),
-          empathy_contact_get_name (information->contact));
+          empathy_contact_get_alias (information->contact));
 }
 
 static void
@@ -965,7 +1226,6 @@ contact_widget_presence_notify_cb (EmpathyContactWidget *information)
   gtk_widget_show (information->image_state);
 }
 
-#if HAVE_FAVOURITE_CONTACTS
 static void
 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
     EmpathyContact *contact,
@@ -978,26 +1238,38 @@ contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
             information->favourite_checkbox), is_favourite);
 }
-#endif
 
 static void
 contact_widget_remove_contact (EmpathyContactWidget *information)
 {
   if (information->contact)
     {
+      TpContact *tp_contact;
+
+      contact_widget_save (information);
+
       g_signal_handlers_disconnect_by_func (information->contact,
           contact_widget_name_notify_cb, information);
       g_signal_handlers_disconnect_by_func (information->contact,
           contact_widget_presence_notify_cb, information);
       g_signal_handlers_disconnect_by_func (information->contact,
           contact_widget_avatar_notify_cb, information);
-      g_signal_handlers_disconnect_by_func (information->contact,
-          contact_widget_groups_notify_cb, information);
+
+      tp_contact = empathy_contact_get_tp_contact (information->contact);
+      if (tp_contact != NULL)
+        {
+          g_signal_handlers_disconnect_by_func (tp_contact,
+              contact_widget_details_notify_cb, information);
+        }
 
       g_object_unref (information->contact);
-      g_object_unref (information->factory);
       information->contact = NULL;
-      information->factory = NULL;
+    }
+
+  if (information->details_cancellable != NULL)
+    {
+      g_cancellable_cancel (information->details_cancellable);
+      tp_clear_object (&information->details_cancellable);
     }
 }
 
@@ -1068,19 +1340,19 @@ contact_widget_contact_update (EmpathyContactWidget *information)
       contact_widget_presence_notify_cb (information);
       contact_widget_avatar_notify_cb (information);
 
-#if HAVE_FAVOURITE_CONTACTS
       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
         {
-          gboolean is_favourite;
-
-          is_favourite = empathy_contact_list_is_favourite (
-              EMPATHY_CONTACT_LIST (information->manager),
+          FolksPersona *persona = empathy_contact_get_persona (
               information->contact);
 
-          contact_widget_favourites_changed_cb (information->manager,
-              information->contact, is_favourite, information);
+          if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
+            {
+              gboolean is_favourite = folks_favourite_get_is_favourite (
+                  FOLKS_FAVOURITE (persona));
+              contact_widget_favourites_changed_cb (information->manager,
+                  information->contact, is_favourite, information);
+            }
         }
-#endif
 
       gtk_widget_show (information->label_alias);
       gtk_widget_show (information->widget_alias);
@@ -1105,13 +1377,7 @@ contact_widget_set_contact (EmpathyContactWidget *information,
 
   contact_widget_remove_contact (information);
   if (contact)
-    {
-      TpConnection *connection;
-
-      connection = empathy_contact_get_connection (contact);
-      information->contact = g_object_ref (contact);
-      information->factory = empathy_tp_contact_factory_dup_singleton (connection);
-    }
+    information->contact = g_object_ref (contact);
 
   /* set the selected account to be the account this contact came from */
   if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
@@ -1129,7 +1395,7 @@ contact_widget_set_contact (EmpathyContactWidget *information,
 }
 
 static void
-contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
+contact_widget_got_contact_cb (TpConnection *connection,
                                EmpathyContact *contact,
                                const GError *error,
                                gpointer user_data,
@@ -1149,7 +1415,6 @@ contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
 static void
 contact_widget_change_contact (EmpathyContactWidget *information)
 {
-  EmpathyTpContactFactory *factory;
   TpConnection *connection;
 
   connection = empathy_account_chooser_get_connection (
@@ -1157,7 +1422,6 @@ contact_widget_change_contact (EmpathyContactWidget *information)
   if (!connection)
       return;
 
-  factory = empathy_tp_contact_factory_dup_singleton (connection);
   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
     {
       const gchar *id;
@@ -1165,20 +1429,18 @@ contact_widget_change_contact (EmpathyContactWidget *information)
       id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
       if (!EMP_STR_EMPTY (id))
         {
-          empathy_tp_contact_factory_get_from_id (factory, id,
+          empathy_tp_contact_factory_get_from_id (connection, id,
               contact_widget_got_contact_cb, information, NULL,
               G_OBJECT (information->vbox_contact_widget));
         }
     }
   else
     {
-      empathy_tp_contact_factory_get_from_handle (factory,
+      empathy_tp_contact_factory_get_from_handle (connection,
           tp_connection_get_self_handle (connection),
           contact_widget_got_contact_cb, information, NULL,
           G_OBJECT (information->vbox_contact_widget));
     }
-
-  g_object_unref (factory);
 }
 
 static gboolean
@@ -1211,33 +1473,23 @@ contact_widget_id_focus_out_cb (GtkWidget *widget,
   return FALSE;
 }
 
-#if HAVE_FAVOURITE_CONTACTS
 static void
 favourite_toggled_cb (GtkToggleButton *button,
     EmpathyContactWidget *information)
 {
-  gboolean active;
-
-  active = gtk_toggle_button_get_active (button);
+  FolksPersona *persona = empathy_contact_get_persona (information->contact);
 
-  if (active)
+  if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
     {
-      empathy_contact_list_add_to_favourites (
-          EMPATHY_CONTACT_LIST (information->manager), information->contact);
-    }
-  else
-    {
-      empathy_contact_list_remove_from_favourites (
-          EMPATHY_CONTACT_LIST (information->manager), information->contact);
+      gboolean active = gtk_toggle_button_get_active (button);
+      folks_favourite_set_is_favourite (FOLKS_FAVOURITE (persona), active);
     }
 }
-#endif
 
 static void
 contact_widget_contact_setup (EmpathyContactWidget *information)
 {
-  /* Setup label_status as a KludgeLabel */
-  information->label_status = empathy_kludge_label_new ("");
+  information->label_status = gtk_label_new ("");
   gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
                                 PANGO_WRAP_WORD_CHAR);
   gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
@@ -1371,7 +1623,6 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
   }
   gtk_widget_show (information->widget_alias);
 
-#if HAVE_FAVOURITE_CONTACTS
   /* Favorite */
   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
     {
@@ -1390,7 +1641,6 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
 
       gtk_widget_show (information->favourite_checkbox);
     }
-#endif
 }
 
 static void
@@ -1447,13 +1697,10 @@ empathy_contact_widget_new (EmpathyContact *contact,
        "vbox_location", &information->vbox_location,
        "subvbox_location", &information->subvbox_location,
        "label_location", &information->label_location,
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
        "viewport_map", &information->viewport_map,
 #endif
-       "vbox_groups", &information->vbox_groups,
-       "entry_group", &information->entry_group,
-       "button_group", &information->button_group,
-       "treeview_groups", &information->treeview_groups,
+       "groups_widget", &information->groups_widget,
        "vbox_details", &information->vbox_details,
        "table_details", &information->table_details,
        "hbox_details_requested", &information->hbox_details_requested,
@@ -1465,9 +1712,6 @@ empathy_contact_widget_new (EmpathyContact *contact,
 
   empathy_builder_connect (gui, information,
       "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
-      "entry_group", "changed", contact_widget_entry_group_changed_cb,
-      "entry_group", "activate", contact_widget_entry_group_activate_cb,
-      "button_group", "clicked", contact_widget_button_group_clicked_cb,
       NULL);
   information->table_location = NULL;
 
@@ -1479,7 +1723,6 @@ empathy_contact_widget_new (EmpathyContact *contact,
 
   /* Create widgets */
   contact_widget_contact_setup (information);
-  contact_widget_groups_setup (information);
   contact_widget_details_setup (information);
   contact_widget_client_setup (information);