]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-blocking-dialog.c
Center the 'smiley images' inside the menu items
[empathy.git] / libempathy-gtk / empathy-contact-blocking-dialog.c
index c28362b7019fadb099232f3e3b2df03b8da7c4f7..cbd514f3aeddf5db894f523dca3217b228a1fdb5 100644 (file)
  *
  * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk>
  */
+
 #include "config.h"
+#include "empathy-contact-blocking-dialog.h"
 
 #include <glib/gi18n-lib.h>
+#include <tp-account-widgets/tpaw-builder.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
 
-#include <libempathy/empathy-utils.h>
-
-#include <libempathy/empathy-contact-manager.h>
-#include <libempathy/empathy-tp-contact-list.h>
-
-#include <libempathy-gtk/empathy-account-chooser.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
-
-#include "empathy-contact-blocking-dialog.h"
+#include "empathy-account-chooser.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 #define GET_PRIVATE(o) (EMPATHY_CONTACT_BLOCKING_DIALOG (o)->priv)
 #define DECLARE_CALLBACK(func) \
@@ -237,7 +235,7 @@ contact_blocking_dialog_am_prepared (GObject *am,
       return;
     }
 
-  accounts = tp_account_manager_get_valid_accounts (TP_ACCOUNT_MANAGER (am));
+  accounts = tp_account_manager_dup_valid_accounts (TP_ACCOUNT_MANAGER (am));
 
   for (ptr = accounts; ptr != NULL; ptr = ptr->next)
     {
@@ -250,7 +248,7 @@ contact_blocking_dialog_am_prepared (GObject *am,
       contact_blocking_dialog_refilter_account_chooser (self);
     }
 
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 }
 
 static void
@@ -259,7 +257,7 @@ contact_blocking_dialog_set_error (EmpathyContactBlockingDialog *self,
 {
   const char *msg = NULL;
 
-  if (error->domain == TP_ERRORS)
+  if (error->domain == TP_ERROR)
     {
       if (error->code == TP_ERROR_INVALID_HANDLE)
         msg = _("Unknown or invalid identifier");
@@ -302,38 +300,39 @@ block_cb (GObject *source,
 }
 
 static void
-block_contact_got_contact (TpConnection *conn,
-    guint n_contacts,
-    TpContact * const *contacts,
-    const gchar * const *requested_ids,
-    GHashTable *failed_id_errors,
-    const GError *error,
-    gpointer user_data,
-    GObject *weak_object)
+block_contact_got_contact (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
-  EmpathyContactBlockingDialog *self =
-    EMPATHY_CONTACT_BLOCKING_DIALOG (weak_object);
-  gchar *id = user_data;
+  EmpathyContactBlockingDialog *self;
+  TpConnection *conn =  TP_CONNECTION (source);
+  TpWeakRef *wr = user_data;
+  TpContact *contact;
+  GError *error = NULL;
 
-  if (error != NULL)
-    goto error;
+  self = tp_weak_ref_dup_object (wr);
+  if (self == NULL)
+    goto finally;
 
-  error = g_hash_table_lookup (failed_id_errors, id);
-  if (error != NULL)
-    goto error;
+  contact = tp_connection_dup_contact_by_id_finish (conn, result, &error);
+  if (contact == NULL)
+    {
+      DEBUG ("Error getting contact on %s: %s",
+          get_pretty_conn_name (conn), error->message);
 
-  tp_contact_block_async (contacts[0], FALSE, block_cb, self);
-  goto finally;
+      contact_blocking_dialog_set_error (
+          EMPATHY_CONTACT_BLOCKING_DIALOG (self), error);
 
-error:
-  DEBUG ("Error getting contact on %s: %s",
-      get_pretty_conn_name (conn), error->message);
+      g_error_free (error);
+      goto finally;
+    }
 
-  contact_blocking_dialog_set_error (
-      EMPATHY_CONTACT_BLOCKING_DIALOG (self), error);
+  tp_contact_block_async (contact, FALSE, block_cb, self);
+  g_object_unref (contact);
 
 finally:
-  g_free (id);
+  g_clear_object (&self);
+  tp_weak_ref_destroy (wr);
 }
 
 static void
@@ -342,17 +341,17 @@ contact_blocking_dialog_add_contact (GtkWidget *widget,
 {
   TpConnection *conn = empathy_account_chooser_get_connection (
       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
-  const char *identifiers[2] = { NULL, };
+  const char *identifier;
 
-  identifiers[0] = gtk_entry_get_text (
+  identifier = gtk_entry_get_text (
       GTK_ENTRY (self->priv->add_contact_entry));
 
   DEBUG ("Looking up handle for '%s' on %s",
-      identifiers[0], get_pretty_conn_name (conn));
+      identifier, get_pretty_conn_name (conn));
 
-  tp_connection_get_contacts_by_id (conn, 1, identifiers,
+  tp_connection_dup_contact_by_id_async (conn, identifier,
       0, NULL, block_contact_got_contact,
-      g_strdup (identifiers[0]), NULL, G_OBJECT (self));
+      tp_weak_ref_new (self, NULL, NULL));
 
   gtk_entry_set_text (GTK_ENTRY (self->priv->add_contact_entry), "");
   gtk_widget_hide (self->priv->info_bar);
@@ -433,9 +432,8 @@ contact_blocking_dialog_account_changed (GtkWidget *account_chooser,
   TpConnection *conn = empathy_account_chooser_get_connection (
       EMPATHY_ACCOUNT_CHOOSER (account_chooser));
   GPtrArray *blocked;
-  EmpathyContactManager *contact_manager;
-  EmpathyTpContactList *contact_list;
-  GList *members, *ptr;
+  GPtrArray *members;
+  guint i;
 
   if (self->priv->block_account_changed > 0)
     return;
@@ -472,37 +470,29 @@ contact_blocking_dialog_account_changed (GtkWidget *account_chooser,
 
   contact_blocking_dialog_add_blocked (self, blocked);
 
-  /* load the completion list */
-  g_return_if_fail (empathy_contact_manager_initialized ());
-
   DEBUG ("Loading contacts");
 
-  contact_manager = empathy_contact_manager_dup_singleton ();
-  contact_list = empathy_contact_manager_get_list (contact_manager, conn);
-  members = empathy_contact_list_get_members (
-      EMPATHY_CONTACT_LIST (contact_list));
+  members = tp_connection_dup_contact_list (conn);
 
-  for (ptr = members; ptr != NULL; ptr = ptr->next)
+  for (i = 0; i < members->len; i++)
     {
-      EmpathyContact *contact = ptr->data;
+      TpContact *contact = g_ptr_array_index (members, i);
       gchar *tmpstr;
 
       tmpstr = g_strdup_printf ("%s (%s)",
-          empathy_contact_get_alias (contact),
-          empathy_contact_get_id (contact));
+          tp_contact_get_alias (contact),
+          tp_contact_get_identifier (contact));
 
       gtk_list_store_insert_with_values (self->priv->completion_contacts,
           NULL, -1,
-          COL_COMPLETION_IDENTIFIER, empathy_contact_get_id (contact),
+          COL_COMPLETION_IDENTIFIER, tp_contact_get_identifier (contact),
           COL_COMPLETION_TEXT, tmpstr,
           -1);
 
       g_free (tmpstr);
-      g_object_unref (contact);
     }
 
-  g_list_free (members);
-  g_object_unref (contact_manager);
+  g_ptr_array_unref (members);
 }
 
 static void
@@ -626,7 +616,7 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self)
   filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui",
       "libempathy-gtk");
 
-  gui = empathy_builder_get_file (filename,
+  gui = tpaw_builder_get_file (filename,
       "contents", &contents,
       "account-hbox", &account_hbox,
       "add-button", &self->priv->add_button,
@@ -638,7 +628,7 @@ empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self)
       "remove-toolbar", &remove_toolbar,
       NULL);
 
-  empathy_builder_connect (gui, self,
+  tpaw_builder_connect (gui, self,
       "add-button", "clicked", contact_blocking_dialog_add_contact,
       "add-contact-entry", "activate", contact_blocking_dialog_add_contact,
       "remove-button", "clicked", contact_blocking_dialog_remove_contacts,