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