]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-chooser.c
libempathy-gtk: fix uninitialized variable
[empathy.git] / libempathy-gtk / empathy-contact-chooser.c
index 01e4b6a8376237581fee956c6947a0b27d27629e..05dbe3449a21baa7bc89a2e8e821e22d93e700bf 100644 (file)
  */
 
 #include "config.h"
-
-#include <glib/gi18n.h>
-#include <folks/folks-telepathy.h>
-
 #include "empathy-contact-chooser.h"
 
-#include <libempathy/empathy-utils.h>
-
-#include <libempathy-gtk/empathy-individual-store-manager.h>
-#include <libempathy-gtk/empathy-individual-view.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
+#include "empathy-client-factory.h"
+#include "empathy-individual-store-manager.h"
+#include "empathy-individual-view.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 G_DEFINE_TYPE (EmpathyContactChooser,
     empathy_contact_chooser, GTK_TYPE_BOX);
@@ -207,33 +203,38 @@ contact_capabilities_changed (TpContact *contact,
 }
 
 static void
-get_contacts_cb (TpConnection *connection,
-    guint n_contacts,
-    TpContact * const *contacts,
-    const gchar * const *requested_ids,
-    GHashTable *failed_id_errors,
-    const GError *error,
-    gpointer user_data,
-    GObject *weak_object)
+get_contacts_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
-  EmpathyContactChooser *self =
-    (EmpathyContactChooser *) weak_object;
-  AddTemporaryIndividualCtx *ctx = user_data;
+  TpWeakRef *wr = user_data;
+  AddTemporaryIndividualCtx *ctx;
+  EmpathyContactChooser *self;
+  GError *error = NULL;
   FolksIndividual *individual;
   TpContact *contact;
+  EmpathyContact *emp_contact = NULL;
 
-  if (self->priv->add_temp_ctx != ctx)
-    /* another request has been started */
-    return;
+  self = tp_weak_ref_dup_object (wr);
+  if (self == NULL)
+    goto out;
 
-  if (n_contacts != 1)
-    return;
+  ctx = tp_weak_ref_get_user_data (wr);
+
+  emp_contact = empathy_client_factory_dup_contact_by_id_finish (
+        EMPATHY_CLIENT_FACTORY (source), result, &error);
+  if (emp_contact == NULL)
+    goto out;
+
+  contact = empathy_contact_get_tp_contact (emp_contact);
 
-  contact = contacts[0];
+  if (self->priv->add_temp_ctx != ctx)
+    /* another request has been started */
+    goto out;
 
-  individual =  empathy_create_individual_from_tp_contact (contact);
+  individual =  empathy_ensure_individual_from_tp_contact (contact);
   if (individual == NULL)
-    return;
+    goto out;
 
   /* tp-glib will unref the TpContact once we return from this callback
    * but folks expect us to keep a reference on the TpContact.
@@ -255,6 +256,11 @@ get_contacts_cb (TpConnection *connection,
         gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->view)),
         NULL, NULL))
     empathy_individual_view_select_first (self->priv->view);
+
+out:
+  g_clear_object (&emp_contact);
+  g_clear_object (&self);
+  tp_weak_ref_destroy (wr);
 }
 
 static void
@@ -272,26 +278,27 @@ add_temporary_individuals (EmpathyContactChooser *self,
   self->priv->add_temp_ctx = add_temporary_individual_ctx_new (self);
 
   /* Try to add an individual for each connected account */
-  accounts = tp_account_manager_get_valid_accounts (self->priv->account_mgr);
+  accounts = tp_account_manager_dup_valid_accounts (self->priv->account_mgr);
   for (l = accounts; l != NULL; l = g_list_next (l))
     {
       TpAccount *account = l->data;
       TpConnection *conn;
-      TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS,
-          TP_CONTACT_FEATURE_AVATAR_DATA,
-          TP_CONTACT_FEATURE_PRESENCE,
-          TP_CONTACT_FEATURE_CAPABILITIES };
+      EmpathyClientFactory *factory;
 
       conn = tp_account_get_connection (account);
       if (conn == NULL)
         continue;
 
-      tp_connection_get_contacts_by_id (conn, 1, &id, G_N_ELEMENTS (features),
-          features, get_contacts_cb, self->priv->add_temp_ctx, NULL,
-          G_OBJECT (self));
+      factory = empathy_client_factory_dup ();
+
+      empathy_client_factory_dup_contact_by_id_async (factory, conn, id,
+          get_contacts_cb,
+          tp_weak_ref_new (self, self->priv->add_temp_ctx, NULL));
+
+      g_object_unref (factory);
     }
 
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 }
 
 static void
@@ -305,7 +312,7 @@ search_text_changed (GtkEntry *entry,
 
   id = gtk_entry_get_text (entry);
 
-  self->priv->search_words = empathy_live_search_strip_utf8_string (id);
+  self->priv->search_words = tpaw_live_search_strip_utf8_string (id);
   self->priv->search_str = g_strdup (id);
 
   add_temporary_individuals (self, id);