]> 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 47bec719e2feb06660109a87cce91a2992a5fd75..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-contact-manager.h>
-#include <libempathy/empathy-tp-contact-factory.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"
 
@@ -74,6 +73,8 @@ struct _EmpathyContactSearchDialogPrivate
   GtkWidget *search_entry;
   /* GtkWidget *server_entry; */
   GtkWidget *message;
+  GtkWidget *message_window;
+  GtkWidget *message_label;
 };
 
 static void
@@ -118,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
@@ -134,23 +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)
 {
-    EmpathyContactManager *manager = empathy_contact_manager_dup_singleton ();
-    const gchar *message = user_data;
+  gchar *message = user_data;
+  GError *error = NULL;
+  EmpathyContact *contact;
+
+  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;
+    }
 
-    if (error != NULL)
-      {
-        g_warning ("Error while getting the contact: %s", error->message);
-        return;
-      }
+  empathy_contact_add_to_contact_list (contact, message);
+  g_object_unref (contact);
 
-    empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager), contact,
-        message);
+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);
@@ -335,6 +342,17 @@ on_selection_changed (GtkTreeSelection *selection,
   gtk_widget_set_sensitive (priv->add_button, sel);
 }
 
+static void
+check_request_message_available (EmpathyContactSearchDialog *self,
+    TpConnection *conn)
+{
+  EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
+
+  gtk_widget_set_visible (priv->message_window,
+      tp_connection_get_can_change_contact_list (conn));
+  gtk_widget_set_visible (priv->message_label,
+      tp_connection_get_can_change_contact_list (conn));
+}
 
 static void
 _account_chooser_changed (EmpathyAccountChooser *chooser,
@@ -363,6 +381,9 @@ _account_chooser_changed (EmpathyAccountChooser *chooser,
       NULL, /* gtk_entry_get_text (GTK_ENTRY (priv->server_entry)), */
       0,
       on_searcher_created, self);
+
+  /* Make the request message textview sensitive if it can be used */
+  check_request_message_available (self, conn);
 }
 
 static void
@@ -426,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_display_individual_info (individual);
 
-  empathy_contact_information_dialog_show (contact, NULL);
+  g_object_unref (contact);
+  g_object_unref (individual);
 }
 
 static void
@@ -452,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));
 
@@ -465,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
@@ -484,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);
@@ -511,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);
@@ -603,8 +639,9 @@ empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
   gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 3);
 
   /* Request message textview */
-  label = gtk_label_new (_("Your message introducing yourself:"));
-  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+  priv->message_label = gtk_label_new (
+       _("Your message introducing yourself:"));
+  gtk_misc_set_alignment (GTK_MISC (priv->message_label), 0, 0.5);
 
   priv->message = gtk_text_view_new ();
   gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->message),
@@ -613,16 +650,17 @@ empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
       gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->message)),
       _("Please let me see when you're online. Thanks!"), -1);
 
-  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
+  priv->message_window = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_shadow_type (
+      GTK_SCROLLED_WINDOW (priv->message_window),
       GTK_SHADOW_ETCHED_IN);
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->message_window),
       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 
-  gtk_container_add (GTK_CONTAINER (scrolled_window), priv->message);
+  gtk_container_add (GTK_CONTAINER (priv->message_window), priv->message);
 
-  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 3);
-  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, FALSE, TRUE, 3);
+  gtk_box_pack_start (GTK_BOX (vbox), priv->message_label, FALSE, TRUE, 3);
+  gtk_box_pack_start (GTK_BOX (vbox), priv->message_window, FALSE, TRUE, 3);
 
   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
           GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
@@ -630,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 *