]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-blocking-dialog.c
Merge branch 'glassrose-contact-blocking-rebase'
[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       tp_g_signal_connect_object (account, "status-changed",
289           G_CALLBACK (contact_blocking_dialog_connection_status_changed),
290           self, 0);
291
292       conn = tp_account_get_connection (TP_ACCOUNT (account));
293
294       if (conn != NULL)
295         {
296           tp_proxy_prepare_async (conn, NULL,
297               contact_blocking_dialog_connection_prepared, self);
298         }
299     }
300
301   g_list_free (accounts);
302 }
303
304 static void contact_blocking_dialog_got_deny_channel (TpConnection *,
305     gboolean, const char *, GHashTable *, const GError *, gpointer, GObject *);
306
307 static void
308 contact_blocking_dialog_connection_prepared (GObject *conn,
309     GAsyncResult *result,
310     gpointer user_data)
311 {
312   EmpathyContactBlockingDialog *self = user_data;
313   GHashTable *request;
314   GError *error = NULL;
315
316   if (!tp_proxy_prepare_finish (conn, result, &error))
317     {
318       DEBUG ("Failed to prepare connection: %s", error->message);
319       g_error_free (error);
320       return;
321     }
322
323   /* request the deny channel */
324   request = tp_asv_new (
325       TP_PROP_CHANNEL_CHANNEL_TYPE,
326       G_TYPE_STRING,
327       TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
328
329       TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
330       G_TYPE_UINT,
331       TP_HANDLE_TYPE_LIST,
332
333       TP_PROP_CHANNEL_TARGET_ID,
334       G_TYPE_STRING,
335       "deny",
336
337       NULL);
338
339   tp_cli_connection_interface_requests_call_ensure_channel (
340       TP_CONNECTION (conn), -1, request,
341       contact_blocking_dialog_got_deny_channel, NULL, NULL, G_OBJECT (self));
342
343   g_hash_table_destroy (request);
344 }
345
346 DECLARE_CALLBACK (contact_blocking_dialog_deny_channel_prepared);
347
348 static void
349 contact_blocking_dialog_got_deny_channel (TpConnection *conn,
350     gboolean yours,
351     const char *channel_path,
352     GHashTable *props,
353     const GError *in_error,
354     gpointer user_data,
355     GObject *self)
356 {
357   TpChannel *channel;
358   GError *error = NULL;
359
360   const GQuark features[] = {
361       TP_CHANNEL_FEATURE_CORE,
362       TP_CHANNEL_FEATURE_GROUP,
363       0 };
364
365   if (in_error != NULL)
366     {
367       DEBUG ("Failed to get 'deny' channel: %s", in_error->message);
368       return;
369     }
370
371   channel = tp_channel_new_from_properties (conn, channel_path, props, &error);
372
373   if (error != NULL)
374     {
375       DEBUG ("Failed to create channel proxy: %s", error->message);
376       g_error_free (error);
377       return;
378     }
379
380   tp_proxy_prepare_async (channel, features,
381       contact_blocking_dialog_deny_channel_prepared, self);
382 }
383
384 static void
385 contact_blocking_dialog_deny_channel_prepared (GObject *channel,
386     GAsyncResult *result,
387     gpointer user_data)
388 {
389   EmpathyContactBlockingDialog *self = user_data;
390   TpConnection *conn;
391   GError *error = NULL;
392
393   if (!tp_proxy_prepare_finish (channel, result, &error))
394     {
395       DEBUG ("Failed to prepare channel: %s", error->message);
396       g_error_free (error);
397       return;
398     }
399
400   conn = tp_channel_borrow_connection (TP_CHANNEL (channel));
401
402   DEBUG ("Channel prepared for connection %s", get_pretty_conn_name (conn));
403
404   g_hash_table_insert (self->priv->channels,
405       g_object_ref (conn), channel);
406   contact_blocking_dialog_refilter_account_chooser (self);
407
408   tp_g_signal_connect_object (channel, "group-members-changed",
409       G_CALLBACK (contact_blocking_dialog_deny_channel_members_changed),
410       self, 0);
411 }
412
413 static void
414 contact_blocking_dialog_set_error (EmpathyContactBlockingDialog *self,
415     const GError *error)
416 {
417   const char *msg = NULL;
418
419   if (error->domain == TP_ERRORS)
420     {
421       if (error->code == TP_ERROR_INVALID_HANDLE)
422         msg = _("Unknown or invalid identifier");
423       else if (error->code == TP_ERROR_NOT_AVAILABLE)
424         msg = _("Contact blocking temporarily unavailable");
425       else if (error->code == TP_ERROR_NOT_CAPABLE)
426         msg = _("Contact blocking unavailable");
427       else if (error->code == TP_ERROR_PERMISSION_DENIED)
428         msg = _("Permission Denied");
429     }
430
431   if (msg == NULL)
432     msg = _("Could not block contact");
433
434   gtk_label_set_text (GTK_LABEL (self->priv->info_bar_label), msg);
435   gtk_widget_show (self->priv->info_bar);
436 }
437
438 static void contact_blocking_dialog_add_contact_got_handle (TpConnection *,
439     const GArray *, const GError *, gpointer, GObject *);
440
441 static void
442 contact_blocking_dialog_add_contact (GtkWidget *widget,
443     EmpathyContactBlockingDialog *self)
444 {
445   TpConnection *conn = empathy_account_chooser_get_connection (
446       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
447   const char *identifiers[2] = { NULL, };
448
449   identifiers[0] = gtk_entry_get_text (
450       GTK_ENTRY (self->priv->add_contact_entry));
451
452   DEBUG ("Looking up handle for '%s'", identifiers[0]);
453
454   tp_cli_connection_call_request_handles (conn, -1,
455       TP_HANDLE_TYPE_CONTACT, identifiers,
456       contact_blocking_dialog_add_contact_got_handle,
457       NULL, NULL, G_OBJECT (self));
458
459   gtk_entry_set_text (GTK_ENTRY (self->priv->add_contact_entry), "");
460   gtk_widget_hide (self->priv->info_bar);
461 }
462
463 static void
464 contact_blocking_dialog_added_contact (TpChannel *, const GError *,
465     gpointer, GObject *);
466
467 static void
468 contact_blocking_dialog_add_contact_got_handle (TpConnection *conn,
469     const GArray *handles,
470     const GError *in_error,
471     gpointer user_data,
472     GObject *self)
473 {
474   EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
475   TpChannel *channel = g_hash_table_lookup (priv->channels, conn);
476
477   if (in_error != NULL)
478     {
479       DEBUG ("Error getting handle: %s", in_error->message);
480
481       contact_blocking_dialog_set_error (
482           EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
483
484       return;
485     }
486
487   g_return_if_fail (handles->len == 1);
488
489   DEBUG ("Adding handle %u to deny channel",
490       g_array_index (handles, TpHandle, 0));
491
492   tp_cli_channel_interface_group_call_add_members (channel, -1,
493       handles, "",
494       contact_blocking_dialog_added_contact, NULL, NULL, self);
495 }
496
497 static void
498 contact_blocking_dialog_added_contact (TpChannel *channel,
499     const GError *in_error,
500     gpointer user_data,
501     GObject *self)
502 {
503   if (in_error != NULL)
504     {
505       DEBUG ("Error adding contact to deny list: %s", in_error->message);
506
507       contact_blocking_dialog_set_error (
508           EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
509
510       return;
511     }
512
513   DEBUG ("Contact added");
514 }
515
516 static void
517 contact_blocking_dialog_removed_contacts (TpChannel *,
518     const GError *, gpointer, GObject *);
519
520 static void
521 contact_blocking_dialog_remove_contacts (GtkWidget *button,
522     EmpathyContactBlockingDialog *self)
523 {
524   TpConnection *conn = empathy_account_chooser_get_connection (
525       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
526   TpChannel *channel = g_hash_table_lookup (self->priv->channels, conn);
527   GtkTreeModel *model;
528   GList *rows, *ptr;
529   GArray *handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
530
531   rows = gtk_tree_selection_get_selected_rows (self->priv->selection, &model);
532
533   for (ptr = rows; ptr != NULL; ptr = ptr->next)
534     {
535       GtkTreePath *path = ptr->data;
536       GtkTreeIter iter;
537       TpHandle handle;
538
539       if (!gtk_tree_model_get_iter (model, &iter, path))
540         continue;
541
542       gtk_tree_model_get (model, &iter,
543           COL_HANDLE, &handle,
544           -1);
545
546       g_array_append_val (handles, handle);
547       gtk_tree_path_free (path);
548     }
549
550   g_list_free (rows);
551
552   if (handles->len > 0)
553     {
554       DEBUG ("Removing %u handles", handles->len);
555
556       tp_cli_channel_interface_group_call_remove_members (channel, -1,
557           handles, "",
558           contact_blocking_dialog_removed_contacts,
559           NULL, NULL, G_OBJECT (self));
560     }
561
562   g_array_unref (handles);
563 }
564
565 static void
566 contact_blocking_dialog_removed_contacts (TpChannel *channel,
567     const GError *in_error,
568     gpointer user_data,
569     GObject *self)
570 {
571   if (in_error != NULL)
572     {
573       DEBUG ("Error removing contacts from deny list: %s", in_error->message);
574
575       contact_blocking_dialog_set_error (
576           EMPATHY_CONTACT_BLOCKING_DIALOG (self), in_error);
577
578       return;
579     }
580
581   DEBUG ("Contacts removed");
582 }
583
584 static void
585 contact_blocking_dialog_account_changed (GtkWidget *account_chooser,
586     EmpathyContactBlockingDialog *self)
587 {
588   TpConnection *conn = empathy_account_chooser_get_connection (
589       EMPATHY_ACCOUNT_CHOOSER (account_chooser));
590   TpChannel *channel;
591   GArray *blocked;
592   EmpathyContactManager *contact_manager;
593   EmpathyTpContactList *contact_list;
594   GList *members, *ptr;
595
596   if (self->priv->block_account_changed > 0)
597     return;
598
599   /* clear the lists of contacts */
600   gtk_list_store_clear (self->priv->blocked_contacts);
601   gtk_list_store_clear (self->priv->completion_contacts);
602
603   if (conn == NULL)
604     return;
605
606   DEBUG ("Account changed: %s", get_pretty_conn_name (conn));
607
608   /* load the deny list */
609   channel = g_hash_table_lookup (self->priv->channels, conn);
610
611   if (channel == NULL)
612     return;
613
614   g_return_if_fail (TP_IS_CHANNEL (channel));
615
616   blocked = tp_intset_to_array (tp_channel_group_get_members (channel));
617
618   DEBUG ("%u contacts on blocked list", blocked->len);
619
620   contact_blocking_dialog_add_contacts_to_list (self, conn, blocked);
621   g_array_unref (blocked);
622
623   /* load the completion list */
624   g_return_if_fail (empathy_contact_manager_initialized ());
625
626   DEBUG ("Loading contacts");
627
628   contact_manager = empathy_contact_manager_dup_singleton ();
629   contact_list = empathy_contact_manager_get_list (contact_manager, conn);
630   members = empathy_contact_list_get_members (
631       EMPATHY_CONTACT_LIST (contact_list));
632
633   for (ptr = members; ptr != NULL; ptr = ptr->next)
634     {
635       EmpathyContact *contact = ptr->data;
636
637       gtk_list_store_insert_with_values (self->priv->completion_contacts,
638           NULL, -1,
639           COL_IDENTIFIER, empathy_contact_get_id (contact),
640           -1);
641
642       g_object_unref (contact);
643     }
644
645   g_list_free (members);
646   g_object_unref (contact_manager);
647 }
648
649 static void
650 contact_blocking_dialog_view_selection_changed (GtkTreeSelection *selection,
651     EmpathyContactBlockingDialog *self)
652 {
653   GList *rows = gtk_tree_selection_get_selected_rows (selection, NULL);
654
655   /* update the sensitivity of the remove button */
656   gtk_widget_set_sensitive (self->priv->remove_button, rows != NULL);
657
658   g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
659   g_list_free (rows);
660 }
661
662 static void
663 contact_blocking_dialog_dispose (GObject *self)
664 {
665   EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
666
667   tp_clear_pointer (&priv->channels, g_hash_table_destroy);
668
669   G_OBJECT_CLASS (empathy_contact_blocking_dialog_parent_class)->dispose (self);
670 }
671
672 static void
673 empathy_contact_blocking_dialog_class_init (
674     EmpathyContactBlockingDialogClass *klass)
675 {
676   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
677
678   gobject_class->dispose = contact_blocking_dialog_dispose;
679
680   g_type_class_add_private (gobject_class,
681       sizeof (EmpathyContactBlockingDialogPrivate));
682 }
683
684 static void
685 empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self)
686 {
687   GtkBuilder *gui;
688   char *filename;
689   GtkWidget *contents;
690   GtkWidget *account_hbox, *blocked_contacts_view;
691   GtkEntryCompletion *completion;
692   TpAccountManager *am;
693
694   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
695       EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG,
696       EmpathyContactBlockingDialogPrivate);
697
698   self->priv->channels = g_hash_table_new_full (NULL, NULL,
699       g_object_unref, g_object_unref);
700
701   gtk_window_set_title (GTK_WINDOW (self), _("Edit Blocked Contacts"));
702   gtk_dialog_add_button (GTK_DIALOG (self),
703       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
704
705   filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui",
706       "libempathy-gtk");
707
708   gui = empathy_builder_get_file (filename,
709       "contents", &contents,
710       "account-hbox", &account_hbox,
711       "add-button", &self->priv->add_button,
712       "add-contact-entry", &self->priv->add_contact_entry,
713       "blocked-contacts", &self->priv->blocked_contacts,
714       "blocked-contacts-view", &blocked_contacts_view,
715       "remove-button", &self->priv->remove_button,
716       NULL);
717
718   empathy_builder_connect (gui, self,
719       "add-button", "clicked", contact_blocking_dialog_add_contact,
720       "add-contact-entry", "activate", contact_blocking_dialog_add_contact,
721       "remove-button", "clicked", contact_blocking_dialog_remove_contacts,
722       NULL);
723
724   /* add the contents to the dialog */
725   gtk_container_add (
726       GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))),
727       contents);
728   gtk_widget_show (contents);
729
730   /* set up the tree selection */
731   self->priv->selection = gtk_tree_view_get_selection (
732       GTK_TREE_VIEW (blocked_contacts_view));
733   gtk_tree_selection_set_mode (self->priv->selection, GTK_SELECTION_MULTIPLE);
734   g_signal_connect (self->priv->selection, "changed",
735       G_CALLBACK (contact_blocking_dialog_view_selection_changed), self);
736
737   /* build the contact entry */
738   self->priv->completion_contacts = gtk_list_store_new (1, G_TYPE_STRING);
739   completion = gtk_entry_completion_new ();
740   gtk_entry_completion_set_model (completion,
741       GTK_TREE_MODEL (self->priv->completion_contacts));
742   gtk_entry_completion_set_text_column (completion, COL_IDENTIFIER);
743   gtk_entry_set_completion (GTK_ENTRY (self->priv->add_contact_entry),
744       completion);
745   g_object_unref (completion);
746   g_object_unref (self->priv->completion_contacts);
747
748   /* add the account chooser */
749   self->priv->account_chooser = empathy_account_chooser_new ();
750   contact_blocking_dialog_refilter_account_chooser (self);
751   g_signal_connect (self->priv->account_chooser, "changed",
752       G_CALLBACK (contact_blocking_dialog_account_changed), self);
753
754   gtk_box_pack_start (GTK_BOX (account_hbox), self->priv->account_chooser,
755       TRUE, TRUE, 0);
756   gtk_widget_show (self->priv->account_chooser);
757
758   /* add an error warning info bar */
759   self->priv->info_bar = gtk_info_bar_new ();
760   gtk_box_pack_start (GTK_BOX (contents), self->priv->info_bar, FALSE, TRUE, 0);
761   gtk_info_bar_set_message_type (GTK_INFO_BAR (self->priv->info_bar),
762       GTK_MESSAGE_ERROR);
763
764   self->priv->info_bar_label = gtk_label_new ("");
765   gtk_container_add (GTK_CONTAINER (
766         gtk_info_bar_get_content_area (GTK_INFO_BAR (self->priv->info_bar))),
767       self->priv->info_bar_label);
768   gtk_widget_show (self->priv->info_bar_label);
769
770   /* prepare the account manager */
771   am = tp_account_manager_dup ();
772   tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self);
773   g_object_unref (am);
774
775   g_free (filename);
776   g_object_unref (gui);
777 }
778
779 GtkWidget *
780 empathy_contact_blocking_dialog_new (GtkWindow *parent)
781 {
782   GtkWidget *self = g_object_new (EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG,
783       NULL);
784
785   if (parent != NULL)
786     {
787       gtk_window_set_transient_for (GTK_WINDOW (self), parent);
788     }
789
790   return self;
791 }