]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-blocking-dialog.c
Merge remote-tracking branch 'glassrose/make-favorite-room-names-more-detailed-646526'
[empathy.git] / libempathy-gtk / empathy-contact-blocking-dialog.c
1 /*
2  * empathy-contact-blocking-dialog.c
3  *
4  * EmpathyContactBlockingDialog
5  *
6  * Copyright (C) 2011 Collabora Ltd.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk>
23  */
24 #include "config.h"
25
26 #include <glib/gi18n-lib.h>
27
28 #include <libempathy/empathy-utils.h>
29
30 #include <libempathy/empathy-contact-manager.h>
31 #include <libempathy/empathy-tp-contact-list.h>
32
33 #include <libempathy-gtk/empathy-account-chooser.h>
34 #include <libempathy-gtk/empathy-ui-utils.h>
35
36 #include "empathy-contact-blocking-dialog.h"
37
38 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
39 #include <libempathy/empathy-debug.h>
40
41 #define GET_PRIVATE(o) (EMPATHY_CONTACT_BLOCKING_DIALOG (o)->priv)
42 #define DECLARE_CALLBACK(func) \
43   static void func (GObject *, GAsyncResult *, gpointer);
44
45 G_DEFINE_TYPE (EmpathyContactBlockingDialog, empathy_contact_blocking_dialog,
46     GTK_TYPE_DIALOG);
47
48 struct _EmpathyContactBlockingDialogPrivate
49 {
50   /* a map of all active connections to their 'deny' channel */
51   GHashTable *channels; /* reffed TpConnection* -> reffed TpChannel* */
52
53   guint block_account_changed;
54
55   GtkListStore *blocked_contacts;
56   GtkListStore *completion_contacts;
57   GtkTreeSelection *selection;
58
59   GtkWidget *account_chooser;
60   GtkWidget *add_button;
61   GtkWidget *add_contact_entry;
62   GtkWidget *info_bar;
63   GtkWidget *info_bar_label;
64   GtkWidget *remove_button;
65 };
66
67 enum /* blocked-contacts columns */
68 {
69   COL_IDENTIFIER,
70   COL_HANDLE,
71   N_COLUMNS
72 };
73
74 static const char *
75 get_pretty_conn_name (TpConnection *conn)
76 {
77   return tp_proxy_get_object_path (conn) + strlen (TP_CONN_OBJECT_PATH_BASE);
78 }
79
80 static void
81 contact_blocking_dialog_filter_account_chooser (TpAccount *account,
82     EmpathyAccountChooserFilterResultCallback callback,
83     gpointer callback_data,
84     gpointer user_data)
85 {
86   EmpathyContactBlockingDialog *self = user_data;
87   TpConnection *conn = tp_account_get_connection (account);
88   gboolean enable;
89
90   enable =
91     conn != NULL &&
92     g_hash_table_lookup (self->priv->channels, conn) != NULL;
93
94   callback (enable, callback_data);
95 }
96
97 static void contact_blocking_dialog_account_changed (GtkWidget *,
98     EmpathyContactBlockingDialog *);
99
100 static void
101 contact_blocking_dialog_refilter_account_chooser (
102     EmpathyContactBlockingDialog *self)
103 {
104   EmpathyAccountChooser *chooser =
105     EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
106   TpConnection *conn;
107   gboolean enabled;
108
109   DEBUG ("Refiltering account chooser");
110
111   /* set the filter to refilter the account chooser */
112   self->priv->block_account_changed++;
113   empathy_account_chooser_set_filter (chooser,
114       contact_blocking_dialog_filter_account_chooser, self);
115   self->priv->block_account_changed--;
116
117   conn = empathy_account_chooser_get_connection (chooser);
118   enabled = (empathy_account_chooser_get_account (chooser) != NULL &&
119              conn != NULL &&
120              g_hash_table_lookup (self->priv->channels, conn) != NULL);
121
122   if (!enabled)
123     DEBUG ("No account selected");
124
125   gtk_widget_set_sensitive (self->priv->add_button, enabled);
126   gtk_widget_set_sensitive (self->priv->add_contact_entry, enabled);
127
128   contact_blocking_dialog_account_changed (self->priv->account_chooser, self);
129 }
130
131 static void contact_blocking_dialog_inspected_handles (TpConnection *,
132     const char **, const GError *, gpointer, GObject *);
133
134 static void
135 contact_blocking_dialog_add_contacts_to_list (
136     EmpathyContactBlockingDialog *self,
137     TpConnection *conn,
138     GArray *handles)
139 {
140   if (handles->len > 0)
141     tp_cli_connection_call_inspect_handles (conn, -1,
142         TP_HANDLE_TYPE_CONTACT, handles,
143         contact_blocking_dialog_inspected_handles,
144         g_boxed_copy (DBUS_TYPE_G_UINT_ARRAY, handles),
145         (GDestroyNotify) g_array_unref, G_OBJECT (self));
146 }
147
148 static void
149 contact_blocking_dialog_inspected_handles (TpConnection *conn,
150     const char **identifiers,
151     const GError *in_error,
152     gpointer user_data,
153     GObject *self)
154 {
155   EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
156   GArray *handles = user_data;
157   guint i;
158
159   if (in_error != NULL)
160     {
161       DEBUG ("Failed to inspect handles: %s", in_error->message);
162       return;
163     }
164
165   DEBUG ("Adding %u identifiers", handles->len);
166
167   for (i = 0; i < handles->len; i++)
168     {
169       const char *identifier = identifiers[i];
170       TpHandle handle = g_array_index (handles, TpHandle, i);
171
172       gtk_list_store_insert_with_values (priv->blocked_contacts, NULL, -1,
173           COL_IDENTIFIER, identifier,
174           COL_HANDLE, handle,
175           -1);
176     }
177 }
178
179 DECLARE_CALLBACK (contact_blocking_dialog_connection_prepared);
180
181 static void
182 contact_blocking_dialog_connection_status_changed (TpAccount *account,
183     guint old_status,
184     guint new_status,
185     guint reason,
186     const char *dbus_reason,
187     GHashTable *details,
188     EmpathyContactBlockingDialog *self)
189 {
190   TpConnection *conn = tp_account_get_connection (account);
191
192   switch (new_status)
193     {
194       case TP_CONNECTION_STATUS_DISCONNECTED:
195         DEBUG ("Connection %s invalidated", get_pretty_conn_name (conn));
196
197         /* remove the channel from the hash table */
198         g_hash_table_remove (self->priv->channels, conn);
199         contact_blocking_dialog_refilter_account_chooser (self);
200         break;
201
202       case TP_CONNECTION_STATUS_CONNECTING:
203         break;
204
205       case TP_CONNECTION_STATUS_CONNECTED:
206         DEBUG ("Connection %s reconnected", get_pretty_conn_name (conn));
207
208         tp_proxy_prepare_async (conn, NULL,
209             contact_blocking_dialog_connection_prepared, self);
210     }
211 }
212
213 static void
214 contact_blocking_dialog_deny_channel_members_changed (TpChannel *channel,
215     const char *message,
216     GArray *added,
217     GArray *removed,
218     GArray *local_pending,
219     GArray *remote_pending,
220     TpHandle actor,
221     guint reason,
222     EmpathyContactBlockingDialog *self)
223 {
224   TpConnection *conn = tp_channel_borrow_connection (channel);
225   GtkTreeModel *model = GTK_TREE_MODEL (self->priv->blocked_contacts);
226   GtkTreeIter iter;
227   TpIntset *removed_set;
228   gboolean valid;
229
230   /* we only care about changes to the selected connection */
231   /* FIXME: can we compare proxy pointers directly? */
232   if (tp_strdiff (
233         tp_proxy_get_object_path (tp_channel_borrow_connection (channel)),
234         tp_proxy_get_object_path (empathy_account_chooser_get_connection (
235             EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser)))))
236     return;
237
238   DEBUG ("deny list changed: %u added, %u removed", added->len, removed->len);
239
240   /* add contacts */
241   contact_blocking_dialog_add_contacts_to_list (self, conn, added);
242
243   /* remove contacts */
244   removed_set = tp_intset_from_array (removed);
245
246   valid = gtk_tree_model_get_iter_first (model, &iter);
247   while (valid)
248     {
249       TpHandle handle;
250
251       gtk_tree_model_get (model, &iter,
252           COL_HANDLE, &handle,
253           -1);
254
255       if (tp_intset_is_member (removed_set, handle))
256         valid = gtk_list_store_remove (self->priv->blocked_contacts, &iter);
257       else
258         valid = gtk_tree_model_iter_next (model, &iter);
259     }
260
261   tp_intset_destroy (removed_set);
262 }
263
264 DECLARE_CALLBACK (contact_blocking_dialog_connection_prepared);
265
266 static void
267 contact_blocking_dialog_am_prepared (GObject *am,
268     GAsyncResult *result,
269     gpointer user_data)
270 {
271   EmpathyContactBlockingDialog *self = user_data;
272   GList *accounts, *ptr;
273   GError *error = NULL;
274
275   if (!tp_proxy_prepare_finish (am, result, &error))
276     {
277       g_critical ("Could not prepare Account Manager: %s", error->message);
278       g_error_free (error);
279       return;
280     }
281
282   accounts = tp_account_manager_get_valid_accounts (TP_ACCOUNT_MANAGER (am));
283
284   for (ptr = accounts; ptr != NULL; ptr = ptr->next)
285     {
286       TpAccount *account = ptr->data;
287       TpConnection *conn;
288
289       tp_g_signal_connect_object (account, "status-changed",
290           G_CALLBACK (contact_blocking_dialog_connection_status_changed),
291           self, 0);
292
293       conn = tp_account_get_connection (TP_ACCOUNT (account));
294
295       if (conn != NULL)
296         {
297           tp_proxy_prepare_async (conn, NULL,
298               contact_blocking_dialog_connection_prepared, self);
299         }
300     }
301
302   g_list_free (accounts);
303 }
304
305 static void contact_blocking_dialog_got_deny_channel (TpConnection *,
306     gboolean, const char *, GHashTable *, const GError *, gpointer, GObject *);
307
308 static void
309 contact_blocking_dialog_connection_prepared (GObject *conn,
310     GAsyncResult *result,
311     gpointer user_data)
312 {
313   EmpathyContactBlockingDialog *self = user_data;
314   GHashTable *request;
315   GError *error = NULL;
316
317   if (!tp_proxy_prepare_finish (conn, result, &error))
318     {
319       DEBUG ("Failed to prepare connection: %s", error->message);
320       g_error_free (error);
321       return;
322     }
323
324   /* request the deny channel */
325   request = tp_asv_new (
326       TP_PROP_CHANNEL_CHANNEL_TYPE,
327       G_TYPE_STRING,
328       TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
329
330       TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
331       G_TYPE_UINT,
332       TP_HANDLE_TYPE_LIST,
333
334       TP_PROP_CHANNEL_TARGET_ID,
335       G_TYPE_STRING,
336       "deny",
337
338       NULL);
339
340   tp_cli_connection_interface_requests_call_ensure_channel (
341       TP_CONNECTION (conn), -1, request,
342       contact_blocking_dialog_got_deny_channel, NULL, NULL, G_OBJECT (self));
343
344   g_hash_table_destroy (request);
345 }
346
347 DECLARE_CALLBACK (contact_blocking_dialog_deny_channel_prepared);
348
349 static void
350 contact_blocking_dialog_got_deny_channel (TpConnection *conn,
351     gboolean yours,
352     const char *channel_path,
353     GHashTable *props,
354     const GError *in_error,
355     gpointer user_data,
356     GObject *self)
357 {
358   TpChannel *channel;
359   GError *error = NULL;
360
361   const GQuark features[] = {
362       TP_CHANNEL_FEATURE_CORE,
363       TP_CHANNEL_FEATURE_GROUP,
364       0 };
365
366   if (in_error != NULL)
367     {
368       DEBUG ("Failed to get 'deny' channel: %s", in_error->message);
369       return;
370     }
371
372   channel = tp_channel_new_from_properties (conn, channel_path, props, &error);
373
374   if (error != NULL)
375     {
376       DEBUG ("Failed to create channel proxy: %s", error->message);
377       g_error_free (error);
378       return;
379     }
380
381   tp_proxy_prepare_async (channel, features,
382       contact_blocking_dialog_deny_channel_prepared, self);
383 }
384
385 static void
386 contact_blocking_dialog_deny_channel_prepared (GObject *channel,
387     GAsyncResult *result,
388     gpointer user_data)
389 {
390   EmpathyContactBlockingDialog *self = user_data;
391   TpConnection *conn;
392   GError *error = NULL;
393
394   if (!tp_proxy_prepare_finish (channel, result, &error))
395     {
396       DEBUG ("Failed to prepare channel: %s", error->message);
397       g_error_free (error);
398       return;
399     }
400
401   conn = tp_channel_borrow_connection (TP_CHANNEL (channel));
402
403   DEBUG ("Channel prepared for connection %s", get_pretty_conn_name (conn));
404
405   g_hash_table_insert (self->priv->channels,
406       g_object_ref (conn), channel);
407   contact_blocking_dialog_refilter_account_chooser (self);
408
409   tp_g_signal_connect_object (channel, "group-members-changed",
410       G_CALLBACK (contact_blocking_dialog_deny_channel_members_changed),
411       self, 0);
412 }
413
414 static void
415 contact_blocking_dialog_set_error (EmpathyContactBlockingDialog *self,
416     const GError *error)
417 {
418   const char *msg = NULL;
419
420   if (error->domain == TP_ERRORS)
421     {
422       if (error->code == TP_ERROR_INVALID_HANDLE)
423         msg = _("Unknown or invalid identifier");
424       else if (error->code == TP_ERROR_NOT_AVAILABLE)
425         msg = _("Contact blocking temporarily unavailable");
426       else if (error->code == TP_ERROR_NOT_CAPABLE)
427         msg = _("Contact blocking unavailable");
428       else if (error->code == TP_ERROR_PERMISSION_DENIED)
429         msg = _("Permission Denied");
430     }
431
432   if (msg == NULL)
433     msg = _("Could not block contact");
434
435   gtk_label_set_text (GTK_LABEL (self->priv->info_bar_label), msg);
436   gtk_widget_show (self->priv->info_bar);
437 }
438
439 static void contact_blocking_dialog_add_contact_got_handle (TpConnection *,
440     const GArray *, const GError *, gpointer, GObject *);
441
442 static void
443 contact_blocking_dialog_add_contact (GtkWidget *widget,
444     EmpathyContactBlockingDialog *self)
445 {
446   TpConnection *conn = empathy_account_chooser_get_connection (
447       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
448   const char *identifiers[2] = { NULL, };
449
450   identifiers[0] = gtk_entry_get_text (
451       GTK_ENTRY (self->priv->add_contact_entry));
452
453   DEBUG ("Looking up handle for '%s'", identifiers[0]);
454
455   tp_cli_connection_call_request_handles (conn, -1,
456       TP_HANDLE_TYPE_CONTACT, identifiers,
457       contact_blocking_dialog_add_contact_got_handle,
458       NULL, NULL, G_OBJECT (self));
459
460   gtk_entry_set_text (GTK_ENTRY (self->priv->add_contact_entry), "");
461   gtk_widget_hide (self->priv->info_bar);
462 }
463
464 static void
465 contact_blocking_dialog_added_contact (TpChannel *, const GError *,
466     gpointer, GObject *);
467
468 static void
469 contact_blocking_dialog_add_contact_got_handle (TpConnection *conn,
470     const GArray *handles,
471     const GError *in_error,
472     gpointer user_data,
473     GObject *self)
474 {
475   EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
476   TpChannel *channel = g_hash_table_lookup (priv->channels, conn);
477
478   if (in_error != NULL)
479     {
480       DEBUG ("Error getting handle: %s", in_error->message);
481
482       contact_blocking_dialog_set_error (
483           EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
484
485       return;
486     }
487
488   g_return_if_fail (handles->len == 1);
489
490   DEBUG ("Adding handle %u to deny channel",
491       g_array_index (handles, TpHandle, 0));
492
493   tp_cli_channel_interface_group_call_add_members (channel, -1,
494       handles, "",
495       contact_blocking_dialog_added_contact, NULL, NULL, self);
496 }
497
498 static void
499 contact_blocking_dialog_added_contact (TpChannel *channel,
500     const GError *in_error,
501     gpointer user_data,
502     GObject *self)
503 {
504   if (in_error != NULL)
505     {
506       DEBUG ("Error adding contact to deny list: %s", in_error->message);
507
508       contact_blocking_dialog_set_error (
509           EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
510
511       return;
512     }
513
514   DEBUG ("Contact added");
515 }
516
517 static void
518 contact_blocking_dialog_removed_contacts (TpChannel *,
519     const GError *, gpointer, GObject *);
520
521 static void
522 contact_blocking_dialog_remove_contacts (GtkWidget *button,
523     EmpathyContactBlockingDialog *self)
524 {
525   TpConnection *conn = empathy_account_chooser_get_connection (
526       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
527   TpChannel *channel = g_hash_table_lookup (self->priv->channels, conn);
528   GtkTreeModel *model;
529   GList *rows, *ptr;
530   GArray *handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
531
532   rows = gtk_tree_selection_get_selected_rows (self->priv->selection, &model);
533
534   for (ptr = rows; ptr != NULL; ptr = ptr->next)
535     {
536       GtkTreePath *path = ptr->data;
537       GtkTreeIter iter;
538       TpHandle handle;
539
540       if (!gtk_tree_model_get_iter (model, &iter, path))
541         continue;
542
543       gtk_tree_model_get (model, &iter,
544           COL_HANDLE, &handle,
545           -1);
546
547       g_array_append_val (handles, handle);
548       gtk_tree_path_free (path);
549     }
550
551   g_list_free (rows);
552
553   if (handles->len > 0)
554     {
555       DEBUG ("Removing %u handles", handles->len);
556
557       tp_cli_channel_interface_group_call_remove_members (channel, -1,
558           handles, "",
559           contact_blocking_dialog_removed_contacts,
560           NULL, NULL, G_OBJECT (self));
561     }
562
563   g_array_unref (handles);
564 }
565
566 static void
567 contact_blocking_dialog_removed_contacts (TpChannel *channel,
568     const GError *in_error,
569     gpointer user_data,
570     GObject *self)
571 {
572   if (in_error != NULL)
573     {
574       DEBUG ("Error removing contacts from deny list: %s", in_error->message);
575
576       contact_blocking_dialog_set_error (
577           EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
578
579       return;
580     }
581
582   DEBUG ("Contacts removed");
583 }
584
585 static void
586 contact_blocking_dialog_account_changed (GtkWidget *account_chooser,
587     EmpathyContactBlockingDialog *self)
588 {
589   TpConnection *conn = empathy_account_chooser_get_connection (
590       EMPATHY_ACCOUNT_CHOOSER (account_chooser));
591   TpChannel *channel;
592   GArray *blocked;
593   EmpathyContactManager *contact_manager;
594   EmpathyTpContactList *contact_list;
595   GList *members, *ptr;
596
597   if (self->priv->block_account_changed > 0)
598     return;
599
600   /* clear the lists of contacts */
601   gtk_list_store_clear (self->priv->blocked_contacts);
602   gtk_list_store_clear (self->priv->completion_contacts);
603
604   if (conn == NULL)
605     return;
606
607   DEBUG ("Account changed: %s", get_pretty_conn_name (conn));
608
609   /* load the deny list */
610   channel = g_hash_table_lookup (self->priv->channels, conn);
611
612   if (channel == NULL)
613     return;
614
615   g_return_if_fail (TP_IS_CHANNEL (channel));
616
617   blocked = tp_intset_to_array (tp_channel_group_get_members (channel));
618
619   DEBUG ("%u contacts on blocked list", blocked->len);
620
621   contact_blocking_dialog_add_contacts_to_list (self, conn, blocked);
622   g_array_unref (blocked);
623
624   /* load the completion list */
625   g_return_if_fail (empathy_contact_manager_initialized ());
626
627   DEBUG ("Loading contacts");
628
629   contact_manager = empathy_contact_manager_dup_singleton ();
630   contact_list = empathy_contact_manager_get_list (contact_manager, conn);
631   members = empathy_contact_list_get_members (
632       EMPATHY_CONTACT_LIST (contact_list));
633
634   for (ptr = members; ptr != NULL; ptr = ptr->next)
635     {
636       EmpathyContact *contact = ptr->data;
637
638       gtk_list_store_insert_with_values (self->priv->completion_contacts,
639           NULL, -1,
640           COL_IDENTIFIER, empathy_contact_get_id (contact),
641           -1);
642
643       g_object_unref (contact);
644     }
645
646   g_list_free (members);
647   g_object_unref (contact_manager);
648 }
649
650 static void
651 contact_blocking_dialog_view_selection_changed (GtkTreeSelection *selection,
652     EmpathyContactBlockingDialog *self)
653 {
654   GList *rows = gtk_tree_selection_get_selected_rows (selection, NULL);
655
656   /* update the sensitivity of the remove button */
657   gtk_widget_set_sensitive (self->priv->remove_button, rows != NULL);
658
659   g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
660   g_list_free (rows);
661 }
662
663 static void
664 contact_blocking_dialog_dispose (GObject *self)
665 {
666   EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
667
668   tp_clear_pointer (&priv->channels, g_hash_table_destroy);
669
670   G_OBJECT_CLASS (empathy_contact_blocking_dialog_parent_class)->dispose (self);
671 }
672
673 static void
674 empathy_contact_blocking_dialog_class_init (
675     EmpathyContactBlockingDialogClass *klass)
676 {
677   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
678
679   gobject_class->dispose = contact_blocking_dialog_dispose;
680
681   g_type_class_add_private (gobject_class,
682       sizeof (EmpathyContactBlockingDialogPrivate));
683 }
684
685 static void
686 empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self)
687 {
688   GtkBuilder *gui;
689   char *filename;
690   GtkWidget *contents;
691   GtkWidget *account_hbox, *blocked_contacts_view;
692   GtkEntryCompletion *completion;
693   TpAccountManager *am;
694
695   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
696       EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG,
697       EmpathyContactBlockingDialogPrivate);
698
699   self->priv->channels = g_hash_table_new_full (NULL, NULL,
700       g_object_unref, g_object_unref);
701
702   gtk_window_set_title (GTK_WINDOW (self), _("Edit Blocked Contacts"));
703   gtk_dialog_add_button (GTK_DIALOG (self),
704       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
705
706   filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui",
707       "libempathy-gtk");
708
709   gui = empathy_builder_get_file (filename,
710       "contents", &contents,
711       "account-hbox", &account_hbox,
712       "add-button", &self->priv->add_button,
713       "add-contact-entry", &self->priv->add_contact_entry,
714       "blocked-contacts", &self->priv->blocked_contacts,
715       "blocked-contacts-view", &blocked_contacts_view,
716       "remove-button", &self->priv->remove_button,
717       NULL);
718
719   empathy_builder_connect (gui, self,
720       "add-button", "clicked", contact_blocking_dialog_add_contact,
721       "add-contact-entry", "activate", contact_blocking_dialog_add_contact,
722       "remove-button", "clicked", contact_blocking_dialog_remove_contacts,
723       NULL);
724
725   /* add the contents to the dialog */
726   gtk_container_add (
727       GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))),
728       contents);
729   gtk_widget_show (contents);
730
731   /* set up the tree selection */
732   self->priv->selection = gtk_tree_view_get_selection (
733       GTK_TREE_VIEW (blocked_contacts_view));
734   gtk_tree_selection_set_mode (self->priv->selection, GTK_SELECTION_MULTIPLE);
735   g_signal_connect (self->priv->selection, "changed",
736       G_CALLBACK (contact_blocking_dialog_view_selection_changed), self);
737
738   /* build the contact entry */
739   self->priv->completion_contacts = gtk_list_store_new (1, G_TYPE_STRING);
740   completion = gtk_entry_completion_new ();
741   gtk_entry_completion_set_model (completion,
742       GTK_TREE_MODEL (self->priv->completion_contacts));
743   gtk_entry_completion_set_text_column (completion, COL_IDENTIFIER);
744   gtk_entry_set_completion (GTK_ENTRY (self->priv->add_contact_entry),
745       completion);
746   g_object_unref (completion);
747   g_object_unref (self->priv->completion_contacts);
748
749   /* add the account chooser */
750   self->priv->account_chooser = empathy_account_chooser_new ();
751   contact_blocking_dialog_refilter_account_chooser (self);
752   g_signal_connect (self->priv->account_chooser, "changed",
753       G_CALLBACK (contact_blocking_dialog_account_changed), self);
754
755   gtk_box_pack_start (GTK_BOX (account_hbox), self->priv->account_chooser,
756       TRUE, TRUE, 0);
757   gtk_widget_show (self->priv->account_chooser);
758
759   /* add an error warning info bar */
760   self->priv->info_bar = gtk_info_bar_new ();
761   gtk_box_pack_start (GTK_BOX (contents), self->priv->info_bar, FALSE, TRUE, 0);
762   gtk_info_bar_set_message_type (GTK_INFO_BAR (self->priv->info_bar),
763       GTK_MESSAGE_ERROR);
764
765   self->priv->info_bar_label = gtk_label_new ("");
766   gtk_container_add (GTK_CONTAINER (
767         gtk_info_bar_get_content_area (GTK_INFO_BAR (self->priv->info_bar))),
768       self->priv->info_bar_label);
769   gtk_widget_show (self->priv->info_bar_label);
770
771   /* prepare the account manager */
772   am = tp_account_manager_dup ();
773   tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self);
774   g_object_unref (am);
775
776   g_free (filename);
777   g_object_unref (gui);
778 }
779
780 GtkWidget *
781 empathy_contact_blocking_dialog_new (GtkWindow *parent)
782 {
783   GtkWidget *self = g_object_new (EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG,
784       NULL);
785
786   if (parent != NULL)
787     {
788       gtk_window_set_transient_for (GTK_WINDOW (self), parent);
789     }
790
791   return self;
792 }