]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-search-dialog.c
Updated Spanish Translation
[empathy.git] / libempathy-gtk / empathy-contact-search-dialog.c
index e0b7c441fb793959873825cc7f37d191597dd0f2..e5810597befb0fce6a78dd1673e0ad2be76ce89e 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"
 
@@ -55,7 +54,8 @@ enum
 
 enum {
    PAGE_SEARCH_RESULTS,
-   PAGE_NO_MATCH
+   PAGE_NO_MATCH,
+   PAGE_NOT_SUPPORTED,
 };
 
 typedef struct _EmpathyContactSearchDialogPrivate EmpathyContactSearchDialogPrivate;
@@ -70,7 +70,6 @@ struct _EmpathyContactSearchDialogPrivate
   GtkWidget *spinner;
   GtkWidget *add_button;
   GtkWidget *find_button;
-  GtkWidget *no_contact_found;
   GtkWidget *search_entry;
   /* GtkWidget *server_entry; */
   GtkWidget *message;
@@ -104,10 +103,16 @@ on_searcher_reset (GObject *source_object,
   if (error != NULL)
     {
       DEBUG ("Failed to reset the TpContactSearch: %s", error->message);
+      gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+          PAGE_NOT_SUPPORTED);
+
       g_error_free (error);
       return;
     }
 
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+      PAGE_SEARCH_RESULTS);
+
   search = g_hash_table_new (g_str_hash, g_str_equal);
 
   search_criteria = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
@@ -136,21 +141,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;
+
+  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_add_to_contact_list (contact, message);
+out:
+  g_free (message);
 }
 
 static void
@@ -166,6 +178,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 +194,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);
@@ -305,16 +321,23 @@ on_searcher_created (GObject *source_object,
   if (error != NULL)
     {
       DEBUG ("Failed to create a TpContactSearch: %s", error->message);
+      gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+          PAGE_NOT_SUPPORTED);
+
       g_error_free (error);
       return;
     }
 
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+      PAGE_SEARCH_RESULTS);
+
   g_signal_connect (priv->searcher, "search-results-received",
       G_CALLBACK (_search_results_received), self);
   g_signal_connect (priv->searcher, "notify::state",
       G_CALLBACK (_on_search_state_changed_cb), self);
 
   gtk_widget_set_sensitive (priv->find_button, TRUE);
+  gtk_widget_set_sensitive (priv->search_entry, TRUE);
 }
 
 static void
@@ -363,6 +386,7 @@ _account_chooser_changed (EmpathyAccountChooser *chooser,
 
   /* gtk_widget_set_sensitive (priv->server_entry, can_set_server); */
   gtk_widget_set_sensitive (priv->find_button, FALSE);
+  gtk_widget_set_sensitive (priv->search_entry, FALSE);
 
   DEBUG ("New account is %s", tp_proxy_get_object_path (account));
 
@@ -437,19 +461,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;
 
-  empathy_contact_information_dialog_show (contact, NULL);
+  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);
+
+  g_object_unref (contact);
+  g_object_unref (individual);
 }
 
 static void
@@ -463,6 +498,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));
 
@@ -476,9 +512,30 @@ 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
+append_message_page (EmpathyContactSearchDialog *self,
+    const gchar *message)
+{
+  EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
+  GtkWidget *label;
+  gchar *tmp;
+
+  label = gtk_label_new (NULL);
+  tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>", message);
+  gtk_label_set_markup (GTK_LABEL (label), tmp);
+  g_free (tmp);
+
+  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+
+  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), label, NULL);
 }
 
 static void
@@ -490,7 +547,6 @@ empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
   GtkTreeViewColumn *col;
   GtkTreeSelection *selection;
   GtkSizeGroup *size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-  gchar *tmp;
 
   /* Title */
   gtk_window_set_title (GTK_WINDOW (self), _("Search contacts"));
@@ -597,19 +653,11 @@ empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
 
   gtk_container_add (GTK_CONTAINER (scrolled_window), priv->tree_view);
 
-  priv->no_contact_found = gtk_label_new (NULL);
-  tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
-      _("No contacts found"));
-  gtk_label_set_markup (GTK_LABEL (priv->no_contact_found), tmp);
-  g_free (tmp);
-
-  gtk_label_set_ellipsize (GTK_LABEL (priv->no_contact_found),
-      PANGO_ELLIPSIZE_END);
-
   gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), scrolled_window,
       NULL);
-  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
-      priv->no_contact_found, NULL);
+
+  append_message_page (self, _("No contacts found"));
+  append_message_page (self, _("Contact search is not supported on this account"));
 
   gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 3);
 
@@ -643,6 +691,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 *