]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-search-dialog.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy-gtk / empathy-contact-search-dialog.c
index 1dfb942e266fa62afd323b0ec679f9ca4474f82f..2696f5abbeb2fdb9a8af808e434745175bbeae2d 100644 (file)
  *     Danielle Madeley <danielle.madeley@collabora.co.uk>
  *     Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
  */
+
 #include "config.h"
+#include "empathy-contact-search-dialog.h"
 
 #include <glib/gi18n-lib.h>
 
-#include <telepathy-glib/telepathy-glib.h>
-
-#include <libempathy/empathy-tp-contact-factory.h>
-#include <libempathy/empathy-utils.h>
-
-#include <libempathy-gtk/empathy-account-chooser.h>
-#include <libempathy-gtk/empathy-cell-renderer-text.h>
-#include <libempathy-gtk/empathy-cell-renderer-activatable.h>
-#include <libempathy-gtk/empathy-contact-dialogs.h>
-#include <libempathy-gtk/empathy-images.h>
+#include "empathy-account-chooser.h"
+#include "empathy-cell-renderer-activatable.h"
+#include "empathy-cell-renderer-text.h"
+#include "empathy-client-factory.h"
+#include "empathy-images.h"
+#include "empathy-individual-information-dialog.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 #include "empathy-contact-search-dialog.h"
 
@@ -120,7 +119,7 @@ on_searcher_reset (GObject *source_object,
   gtk_list_store_clear (priv->store);
   tp_contact_search_start (priv->searcher, search);
 
-  g_hash_table_destroy (search);
+  g_hash_table_unref (search);
 }
 
 static void
@@ -136,21 +135,28 @@ empathy_contact_search_dialog_do_search (EmpathyContactSearchDialog *self)
 }
 
 static void
-on_get_contact_factory_get_from_id_cb (TpConnection *connection,
-    EmpathyContact *contact,
-    const GError *error,
-    gpointer user_data,
-    GObject *object)
+on_get_contact_factory_get_from_id_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
-    const gchar *message = user_data;
+  gchar *message = user_data;
+  GError *error = NULL;
+  EmpathyContact *contact;
 
-    if (error != NULL)
-      {
-        g_warning ("Error while getting the contact: %s", error->message);
-        return;
-      }
+  contact = empathy_client_factory_dup_contact_by_id_finish (
+      EMPATHY_CLIENT_FACTORY (source), result, &error);
+  if (contact == NULL)
+    {
+      g_warning ("Error while getting the contact: %s", error->message);
+      g_error_free (error);
+      goto out;
+    }
 
-    empathy_contact_add_to_contact_list (contact, message);
+  empathy_contact_add_to_contact_list (contact, message);
+  g_object_unref (contact);
+
+out:
+  g_free (message);
 }
 
 static void
@@ -166,6 +172,7 @@ add_selected_contact (EmpathyContactSearchDialog *self)
   gchar *message;
   gboolean sel;
   gchar *id;
+  EmpathyClientFactory *factory;
 
   conn = empathy_account_chooser_get_connection (EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
 
@@ -181,9 +188,12 @@ add_selected_contact (EmpathyContactSearchDialog *self)
   gtk_text_buffer_get_end_iter (buffer, &end);
   message = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
 
-  empathy_tp_contact_factory_get_from_id (conn, id,
-      on_get_contact_factory_get_from_id_cb,
-      message, g_free, NULL);
+  factory = empathy_client_factory_dup ();
+
+  empathy_client_factory_dup_contact_by_id_async (factory, conn, id,
+      on_get_contact_factory_get_from_id_cb, message);
+
+  g_object_unref (factory);
 
   /* Close the dialog */
   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
@@ -275,13 +285,10 @@ _search_results_received (TpContactSearch *searcher,
   for (l = results; l != NULL; l = l->next)
     {
       TpContactSearchResult *result = l->data;
-      GtkTreeIter iter;
-
-      gtk_list_store_append (priv->store, &iter);
 
       name = tp_contact_search_result_get_field (result, "fn");
 
-      gtk_list_store_set (priv->store, &iter,
+      gtk_list_store_insert_with_values (priv->store, NULL, -1,
           NAME_COLUMN, name ? name->field_value[0] : NULL,
           LOGIN_COLUMN, tp_contact_search_result_get_identifier (result),
           -1);
@@ -440,19 +447,30 @@ contact_search_dialog_row_activated_cb (GtkTreeView *tv,
 }
 
 static void
-on_profile_button_got_contact_cb (TpConnection *connection,
-    EmpathyContact *contact,
-    const GError *error,
-    gpointer user_data,
-    GObject *object)
+on_profile_button_got_contact_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
- if (error != NULL)
-   {
-     g_warning ("Error while getting the contact: %s", error->message);
-     return;
-   }
+  GError *error = NULL;
+  EmpathyContact *contact;
+  FolksIndividual *individual;
+
+  contact = empathy_client_factory_dup_contact_by_id_finish (
+        EMPATHY_CLIENT_FACTORY (source), result, &error);
+  if (contact == NULL)
+    {
+      g_warning ("Error while getting the contact: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  individual = empathy_ensure_individual_from_tp_contact (
+    empathy_contact_get_tp_contact (contact));
 
-  empathy_contact_information_dialog_show (contact, NULL);
+  empathy_display_individual_info (individual);
+
+  g_object_unref (contact);
+  g_object_unref (individual);
 }
 
 static void
@@ -466,6 +484,7 @@ on_profile_button_clicked_cb (EmpathyCellRendererActivatable *cell,
   GtkTreeModel *model;
   gboolean valid;
   gchar *id;
+  EmpathyClientFactory *factory;
 
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree_view));
 
@@ -479,9 +498,12 @@ on_profile_button_clicked_cb (EmpathyCellRendererActivatable *cell,
 
   DEBUG ("Requested to show profile for contact: %s", id);
 
-  empathy_tp_contact_factory_get_from_id (conn, id,
-      on_profile_button_got_contact_cb, NULL,
-      NULL, NULL);
+  factory = empathy_client_factory_dup ();
+
+  empathy_client_factory_dup_contact_by_id_async (factory, conn, id,
+      on_profile_button_got_contact_cb, self);
+
+  g_object_unref (factory);
 }
 
 static void
@@ -498,11 +520,11 @@ empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
   /* Title */
   gtk_window_set_title (GTK_WINDOW (self), _("Search contacts"));
 
-  vbox = gtk_vbox_new (FALSE, 3);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
   gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
 
   /* Account chooser */
-  hbox = gtk_hbox_new (FALSE, 6);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   label = gtk_label_new (_("Account:"));
   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
   gtk_size_group_add_widget (size_group, label);
@@ -525,7 +547,7 @@ empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
 #endif
 
   /* Search input */
-  hbox = gtk_hbox_new (FALSE, 6);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   label = gtk_label_new (_("Search: "));
   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
   gtk_size_group_add_widget (size_group, label);
@@ -646,6 +668,7 @@ empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
   gtk_window_set_default_size (GTK_WINDOW (self), 200, 400);
   gtk_widget_show_all (vbox);
   gtk_widget_hide (priv->spinner);
+  g_object_unref (size_group);
 }
 
 GtkWidget *