*
* 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) \
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)
{
contact_blocking_dialog_refilter_account_chooser (self);
}
- g_list_free (accounts);
+ g_list_free_full (accounts, g_object_unref);
}
static void
{
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");
}
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
{
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);
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;
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
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,
"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,