]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-blocking-dialog.c
1ec60b0ace0db1bad1026e3b38dcf7a2531baffd
[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   guint block_account_changed;
51
52   GtkListStore *blocked_contacts;
53   GtkListStore *completion_contacts;
54   GtkTreeSelection *selection;
55
56   GtkWidget *account_chooser;
57   GtkWidget *add_button;
58   GtkWidget *add_contact_entry;
59   GtkWidget *info_bar;
60   GtkWidget *info_bar_label;
61   GtkWidget *remove_button;
62
63   TpConnection *current_conn;
64 };
65
66 enum /* blocked-contacts columns */
67 {
68   COL_BLOCKED_IDENTIFIER,
69   COL_BLOCKED_CONTACT,
70   N_BLOCKED_COLUMNS
71 };
72
73 enum /* completion_contacts columns */
74 {
75   COL_COMPLETION_IDENTIFIER,
76   COL_COMPLETION_TEXT,
77   N_COMPLETION_COLUMNS
78 };
79
80 static const char *
81 get_pretty_conn_name (TpConnection *conn)
82 {
83   return tp_proxy_get_object_path (conn) + strlen (TP_CONN_OBJECT_PATH_BASE);
84 }
85
86 static void
87 contact_blocking_dialog_filter_account_chooser (TpAccount *account,
88     EmpathyAccountChooserFilterResultCallback callback,
89     gpointer callback_data,
90     gpointer user_data)
91 {
92   TpConnection *conn = tp_account_get_connection (account);
93   gboolean enable;
94
95   enable =
96     conn != NULL &&
97     tp_proxy_has_interface_by_id (conn,
98       TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING);
99
100   callback (enable, callback_data);
101 }
102
103 static void contact_blocking_dialog_account_changed (GtkWidget *,
104     EmpathyContactBlockingDialog *);
105
106 static void
107 contact_blocking_dialog_refilter_account_chooser (
108     EmpathyContactBlockingDialog *self)
109 {
110   EmpathyAccountChooser *chooser =
111     EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
112   TpConnection *conn;
113   gboolean enabled;
114
115   DEBUG ("Refiltering account chooser");
116
117   /* set the filter to refilter the account chooser */
118   self->priv->block_account_changed++;
119   empathy_account_chooser_set_filter (chooser,
120       contact_blocking_dialog_filter_account_chooser, self);
121   self->priv->block_account_changed--;
122
123   conn = empathy_account_chooser_get_connection (chooser);
124   enabled = (empathy_account_chooser_get_account (chooser) != NULL &&
125              conn != NULL &&
126              tp_proxy_has_interface_by_id (conn,
127                TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING));
128
129   if (!enabled)
130     DEBUG ("No account selected");
131
132   gtk_widget_set_sensitive (self->priv->add_button, enabled);
133   gtk_widget_set_sensitive (self->priv->add_contact_entry, enabled);
134
135   contact_blocking_dialog_account_changed (self->priv->account_chooser, self);
136 }
137
138 static void
139 contact_blocking_dialog_add_blocked (
140     EmpathyContactBlockingDialog *self,
141     GPtrArray *blocked)
142 {
143   EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
144   guint i;
145
146   if (blocked == NULL)
147     return;
148
149   for (i = 0; i < blocked->len; i++)
150     {
151       TpContact *contact = g_ptr_array_index (blocked, i);
152
153       gtk_list_store_insert_with_values (priv->blocked_contacts, NULL, -1,
154           COL_BLOCKED_IDENTIFIER, tp_contact_get_identifier (contact),
155           COL_BLOCKED_CONTACT, contact,
156           -1);
157     }
158 }
159
160 static void
161 blocked_contacts_changed_cb (TpConnection *conn,
162     GPtrArray *added,
163     GPtrArray *removed,
164     EmpathyContactBlockingDialog *self)
165 {
166   GtkTreeModel *model = GTK_TREE_MODEL (self->priv->blocked_contacts);
167   GtkTreeIter iter;
168   gboolean valid;
169
170   DEBUG ("blocked contacts changed on %s: %u added, %u removed",
171       get_pretty_conn_name (conn), added->len, removed->len);
172
173   /* add contacts */
174   contact_blocking_dialog_add_blocked (self, added);
175
176   /* remove contacts */
177   valid = gtk_tree_model_get_iter_first (model, &iter);
178   while (valid)
179     {
180       TpContact *contact;
181
182       gtk_tree_model_get (model, &iter,
183           COL_BLOCKED_CONTACT, &contact,
184           -1);
185
186       if (tp_g_ptr_array_contains (removed, contact))
187         valid = gtk_list_store_remove (self->priv->blocked_contacts, &iter);
188       else
189         valid = gtk_tree_model_iter_next (model, &iter);
190
191       g_object_unref (contact);
192     }
193 }
194
195 static void
196 contact_blocking_dialog_connection_status_changed (TpAccount *account,
197     guint old_status,
198     guint new_status,
199     guint reason,
200     const char *dbus_reason,
201     GHashTable *details,
202     EmpathyContactBlockingDialog *self)
203 {
204   TpConnection *conn = tp_account_get_connection (account);
205
206   switch (new_status)
207     {
208       case TP_CONNECTION_STATUS_DISCONNECTED:
209         DEBUG ("Connection %s invalidated", get_pretty_conn_name (conn));
210
211         contact_blocking_dialog_refilter_account_chooser (self);
212         break;
213
214       case TP_CONNECTION_STATUS_CONNECTING:
215         break;
216
217       case TP_CONNECTION_STATUS_CONNECTED:
218         DEBUG ("Connection %s reconnected", get_pretty_conn_name (conn));
219
220         contact_blocking_dialog_refilter_account_chooser (self);
221     }
222 }
223
224 static void
225 contact_blocking_dialog_am_prepared (GObject *am,
226     GAsyncResult *result,
227     gpointer user_data)
228 {
229   EmpathyContactBlockingDialog *self = user_data;
230   GList *accounts, *ptr;
231   GError *error = NULL;
232
233   if (!tp_proxy_prepare_finish (am, result, &error))
234     {
235       g_critical ("Could not prepare Account Manager: %s", error->message);
236       g_error_free (error);
237       return;
238     }
239
240   accounts = tp_account_manager_get_valid_accounts (TP_ACCOUNT_MANAGER (am));
241
242   for (ptr = accounts; ptr != NULL; ptr = ptr->next)
243     {
244       TpAccount *account = ptr->data;
245
246       tp_g_signal_connect_object (account, "status-changed",
247           G_CALLBACK (contact_blocking_dialog_connection_status_changed),
248           self, 0);
249
250       contact_blocking_dialog_refilter_account_chooser (self);
251     }
252
253   g_list_free (accounts);
254 }
255
256 static void
257 contact_blocking_dialog_set_error (EmpathyContactBlockingDialog *self,
258     const GError *error)
259 {
260   const char *msg = NULL;
261
262   if (error->domain == TP_ERRORS)
263     {
264       if (error->code == TP_ERROR_INVALID_HANDLE)
265         msg = _("Unknown or invalid identifier");
266       else if (error->code == TP_ERROR_NOT_AVAILABLE)
267         msg = _("Contact blocking temporarily unavailable");
268       else if (error->code == TP_ERROR_NOT_CAPABLE)
269         msg = _("Contact blocking unavailable");
270       else if (error->code == TP_ERROR_PERMISSION_DENIED)
271         msg = _("Permission Denied");
272     }
273
274   if (msg == NULL)
275     msg = _("Could not block contact");
276
277   gtk_label_set_text (GTK_LABEL (self->priv->info_bar_label), msg);
278   gtk_widget_show (self->priv->info_bar);
279 }
280
281 static void
282 block_cb (GObject *source,
283     GAsyncResult *result,
284     gpointer user_data)
285 {
286   EmpathyContactBlockingDialog *self = user_data;
287   GError *error = NULL;
288
289   if (!tp_contact_block_finish (TP_CONTACT (source), result,
290         &error))
291     {
292       DEBUG ("Error blocking contacts: %s", error->message);
293
294       contact_blocking_dialog_set_error (
295           EMPATHY_CONTACT_BLOCKING_DIALOG (self), error);
296
297       g_error_free (error);
298       return;
299     }
300
301   DEBUG ("Contact blocked");
302 }
303
304 static void
305 block_contact_got_contact(TpConnection *conn,
306     guint n_contacts,
307     TpContact * const *contacts,
308     const gchar * const *requested_ids,
309     GHashTable *failed_id_errors,
310     const GError *error,
311     gpointer user_data,
312     GObject *weak_object)
313 {
314   EmpathyContactBlockingDialog *self =
315     EMPATHY_CONTACT_BLOCKING_DIALOG (weak_object);
316   gchar *id = user_data;
317
318   if (error != NULL)
319     goto error;
320
321   error = g_hash_table_lookup (failed_id_errors, id);
322   if (error != NULL)
323     goto error;
324
325   tp_contact_block_async (contacts[0], FALSE, block_cb, self);
326   goto finally;
327
328 error:
329   DEBUG ("Error getting contact on %s: %s",
330       get_pretty_conn_name (conn), error->message);
331
332   contact_blocking_dialog_set_error (
333       EMPATHY_CONTACT_BLOCKING_DIALOG (self), error);
334
335 finally:
336   g_free (id);
337 }
338
339 static void
340 contact_blocking_dialog_add_contact (GtkWidget *widget,
341     EmpathyContactBlockingDialog *self)
342 {
343   TpConnection *conn = empathy_account_chooser_get_connection (
344       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
345   const char *identifiers[2] = { NULL, };
346
347   identifiers[0] = gtk_entry_get_text (
348       GTK_ENTRY (self->priv->add_contact_entry));
349
350   DEBUG ("Looking up handle for '%s' on %s",
351       identifiers[0], get_pretty_conn_name (conn));
352
353   tp_connection_get_contacts_by_id (conn, 1, identifiers,
354       0, NULL, block_contact_got_contact,
355       g_strdup (identifiers[0]), NULL, G_OBJECT (self));
356
357   gtk_entry_set_text (GTK_ENTRY (self->priv->add_contact_entry), "");
358   gtk_widget_hide (self->priv->info_bar);
359 }
360
361 static void
362 unblock_cb (GObject *source,
363     GAsyncResult *result,
364     gpointer user_data)
365 {
366   EmpathyContactBlockingDialog *self = user_data;
367   GError *error = NULL;
368
369   if (!tp_connection_unblock_contacts_finish (TP_CONNECTION (source), result,
370         &error))
371     {
372       DEBUG ("Error unblocking contacts: %s", error->message);
373
374       contact_blocking_dialog_set_error (
375           EMPATHY_CONTACT_BLOCKING_DIALOG (self), error);
376
377       g_error_free (error);
378       return;
379     }
380
381   DEBUG ("Contacts unblocked");
382 }
383
384 static void
385 contact_blocking_dialog_remove_contacts (GtkWidget *button,
386     EmpathyContactBlockingDialog *self)
387 {
388   TpConnection *conn = empathy_account_chooser_get_connection (
389       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
390   GtkTreeModel *model;
391   GList *rows, *ptr;
392   GPtrArray *contacts;
393
394   rows = gtk_tree_selection_get_selected_rows (self->priv->selection, &model);
395
396   contacts = g_ptr_array_new_with_free_func (g_object_unref);
397
398   for (ptr = rows; ptr != NULL; ptr = ptr->next)
399     {
400       GtkTreePath *path = ptr->data;
401       GtkTreeIter iter;
402       TpContact *contact;
403
404       if (!gtk_tree_model_get_iter (model, &iter, path))
405         continue;
406
407       gtk_tree_model_get (model, &iter,
408           COL_BLOCKED_CONTACT, &contact,
409           -1);
410
411       g_ptr_array_add (contacts, contact);
412
413       gtk_tree_path_free (path);
414     }
415
416   g_list_free (rows);
417
418   if (contacts->len > 0)
419     {
420       DEBUG ("Unblocking %u contacts", contacts->len);
421
422       tp_connection_unblock_contacts_async (conn, contacts->len,
423           (TpContact * const *) contacts->pdata, unblock_cb, self);
424     }
425
426   g_ptr_array_unref (contacts);
427 }
428
429 static void
430 contact_blocking_dialog_account_changed (GtkWidget *account_chooser,
431     EmpathyContactBlockingDialog *self)
432 {
433   TpConnection *conn = empathy_account_chooser_get_connection (
434       EMPATHY_ACCOUNT_CHOOSER (account_chooser));
435   GPtrArray *blocked;
436   EmpathyContactManager *contact_manager;
437   EmpathyTpContactList *contact_list;
438   GList *members, *ptr;
439
440   if (self->priv->block_account_changed > 0)
441     return;
442
443   if (conn == self->priv->current_conn)
444     return;
445
446   /* clear the lists of contacts */
447   gtk_list_store_clear (self->priv->blocked_contacts);
448   gtk_list_store_clear (self->priv->completion_contacts);
449
450   if (self->priv->current_conn != NULL)
451     {
452       g_signal_handlers_disconnect_by_func (self->priv->current_conn,
453           blocked_contacts_changed_cb, self);
454
455       g_clear_object (&self->priv->current_conn);
456     }
457
458   if (conn == NULL)
459     return;
460
461   DEBUG ("Account changed: %s", get_pretty_conn_name (conn));
462
463   self->priv->current_conn = g_object_ref (conn);
464
465   tp_g_signal_connect_object (conn, "blocked-contacts-changed",
466       G_CALLBACK (blocked_contacts_changed_cb), self, 0);
467
468   blocked = tp_connection_get_blocked_contacts (conn);
469
470   DEBUG ("%u contacts blocked on %s",
471       blocked != NULL ? blocked->len : 0, get_pretty_conn_name (conn));
472
473   contact_blocking_dialog_add_blocked (self, blocked);
474
475   /* load the completion list */
476   g_return_if_fail (empathy_contact_manager_initialized ());
477
478   DEBUG ("Loading contacts");
479
480   contact_manager = empathy_contact_manager_dup_singleton ();
481   contact_list = empathy_contact_manager_get_list (contact_manager, conn);
482   members = empathy_contact_list_get_members (
483       EMPATHY_CONTACT_LIST (contact_list));
484
485   for (ptr = members; ptr != NULL; ptr = ptr->next)
486     {
487       EmpathyContact *contact = ptr->data;
488       gchar *tmpstr;
489
490       tmpstr = g_strdup_printf ("%s (%s)",
491           empathy_contact_get_alias (contact),
492           empathy_contact_get_id (contact));
493
494       gtk_list_store_insert_with_values (self->priv->completion_contacts,
495           NULL, -1,
496           COL_COMPLETION_IDENTIFIER, empathy_contact_get_id (contact),
497           COL_COMPLETION_TEXT, tmpstr,
498           -1);
499
500       g_free (tmpstr);
501       g_object_unref (contact);
502     }
503
504   g_list_free (members);
505   g_object_unref (contact_manager);
506 }
507
508 static void
509 contact_blocking_dialog_view_selection_changed (GtkTreeSelection *selection,
510     EmpathyContactBlockingDialog *self)
511 {
512   GList *rows = gtk_tree_selection_get_selected_rows (selection, NULL);
513
514   /* update the sensitivity of the remove button */
515   gtk_widget_set_sensitive (self->priv->remove_button, rows != NULL);
516
517   g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
518   g_list_free (rows);
519 }
520
521 static gboolean
522 contact_selector_dialog_match_func (GtkEntryCompletion *completion,
523     const gchar *key,
524     GtkTreeIter *iter,
525     gpointer user_data)
526 {
527   GtkTreeModel *model;
528   gchar *str, *lower;
529   gboolean v = FALSE;
530
531   model = gtk_entry_completion_get_model (completion);
532   if (model == NULL || iter == NULL)
533     return FALSE;
534
535   gtk_tree_model_get (model, iter, COL_COMPLETION_TEXT, &str, -1);
536   lower = g_utf8_strdown (str, -1);
537   if (strstr (lower, key))
538     {
539       DEBUG ("Key %s is matching name **%s**", key, str);
540       v = TRUE;
541       goto out;
542     }
543   g_free (str);
544   g_free (lower);
545
546   gtk_tree_model_get (model, iter, COL_COMPLETION_IDENTIFIER, &str, -1);
547   lower = g_utf8_strdown (str, -1);
548   if (strstr (lower, key))
549     {
550       DEBUG ("Key %s is matching ID **%s**", key, str);
551       v = TRUE;
552       goto out;
553     }
554
555 out:
556   g_free (str);
557   g_free (lower);
558
559   return v;
560 }
561
562 static gboolean
563 contact_selector_dialog_match_selected_cb (GtkEntryCompletion *widget,
564     GtkTreeModel *model,
565     GtkTreeIter *iter,
566     EmpathyContactBlockingDialog *self)
567 {
568   gchar *id;
569
570   if (iter == NULL || model == NULL)
571     return FALSE;
572
573   gtk_tree_model_get (model, iter, COL_COMPLETION_IDENTIFIER, &id, -1);
574   gtk_entry_set_text (GTK_ENTRY (self->priv->add_contact_entry), id);
575
576   DEBUG ("Got selected match **%s**", id);
577
578   g_free (id);
579
580   return TRUE;
581 }
582
583 static void
584 contact_blocking_dialog_dispose (GObject *self)
585 {
586   EmpathyContactBlockingDialogPrivate *priv = GET_PRIVATE (self);
587
588   g_clear_object (&priv->current_conn);
589
590   G_OBJECT_CLASS (empathy_contact_blocking_dialog_parent_class)->dispose (self);
591 }
592
593 static void
594 empathy_contact_blocking_dialog_class_init (
595     EmpathyContactBlockingDialogClass *klass)
596 {
597   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
598
599   gobject_class->dispose = contact_blocking_dialog_dispose;
600
601   g_type_class_add_private (gobject_class,
602       sizeof (EmpathyContactBlockingDialogPrivate));
603 }
604
605 static void
606 empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self)
607 {
608   GtkBuilder *gui;
609   char *filename;
610   GtkWidget *contents;
611   GtkWidget *account_hbox, *blocked_contacts_view, *blocked_contacts_sw,
612       *remove_toolbar;
613   GtkEntryCompletion *completion;
614   TpAccountManager *am;
615   GtkStyleContext *context;
616   TpSimpleClientFactory *factory;
617
618   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
619       EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG,
620       EmpathyContactBlockingDialogPrivate);
621
622   gtk_window_set_title (GTK_WINDOW (self), _("Edit Blocked Contacts"));
623   gtk_dialog_add_button (GTK_DIALOG (self),
624       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
625
626   filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui",
627       "libempathy-gtk");
628
629   gui = empathy_builder_get_file (filename,
630       "contents", &contents,
631       "account-hbox", &account_hbox,
632       "add-button", &self->priv->add_button,
633       "add-contact-entry", &self->priv->add_contact_entry,
634       "blocked-contacts", &self->priv->blocked_contacts,
635       "blocked-contacts-sw", &blocked_contacts_sw,
636       "blocked-contacts-view", &blocked_contacts_view,
637       "remove-button", &self->priv->remove_button,
638       "remove-toolbar", &remove_toolbar,
639       NULL);
640
641   empathy_builder_connect (gui, self,
642       "add-button", "clicked", contact_blocking_dialog_add_contact,
643       "add-contact-entry", "activate", contact_blocking_dialog_add_contact,
644       "remove-button", "clicked", contact_blocking_dialog_remove_contacts,
645       NULL);
646
647   /* join the remove toolbar to the treeview */
648   context = gtk_widget_get_style_context (blocked_contacts_sw);
649   gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
650   context = gtk_widget_get_style_context (remove_toolbar);
651   gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
652
653   /* add the contents to the dialog */
654   gtk_container_add (
655       GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))),
656       contents);
657   gtk_widget_show (contents);
658
659   /* set up the tree selection */
660   self->priv->selection = gtk_tree_view_get_selection (
661       GTK_TREE_VIEW (blocked_contacts_view));
662   gtk_tree_selection_set_mode (self->priv->selection, GTK_SELECTION_MULTIPLE);
663   g_signal_connect (self->priv->selection, "changed",
664       G_CALLBACK (contact_blocking_dialog_view_selection_changed), self);
665
666   /* build the contact entry */
667   self->priv->completion_contacts = gtk_list_store_new (N_COMPLETION_COLUMNS,
668       G_TYPE_STRING, /* id */
669       G_TYPE_STRING, /* text */
670       TP_TYPE_CONTACT); /* contact */
671
672   completion = gtk_entry_completion_new ();
673   gtk_entry_completion_set_model (completion,
674       GTK_TREE_MODEL (self->priv->completion_contacts));
675   gtk_entry_completion_set_text_column (completion, COL_COMPLETION_TEXT);
676   gtk_entry_completion_set_match_func (completion,
677       contact_selector_dialog_match_func,
678       NULL, NULL);
679   g_signal_connect (completion, "match-selected",
680         G_CALLBACK (contact_selector_dialog_match_selected_cb),
681         self);
682   gtk_entry_set_completion (GTK_ENTRY (self->priv->add_contact_entry),
683       completion);
684   g_object_unref (completion);
685   g_object_unref (self->priv->completion_contacts);
686
687   /* add the account chooser */
688   self->priv->account_chooser = empathy_account_chooser_new ();
689   contact_blocking_dialog_refilter_account_chooser (self);
690   g_signal_connect (self->priv->account_chooser, "changed",
691       G_CALLBACK (contact_blocking_dialog_account_changed), self);
692
693   gtk_box_pack_start (GTK_BOX (account_hbox), self->priv->account_chooser,
694       TRUE, TRUE, 0);
695   gtk_widget_show (self->priv->account_chooser);
696
697   /* add an error warning info bar */
698   self->priv->info_bar = gtk_info_bar_new ();
699   gtk_box_pack_start (GTK_BOX (contents), self->priv->info_bar, FALSE, TRUE, 0);
700   gtk_info_bar_set_message_type (GTK_INFO_BAR (self->priv->info_bar),
701       GTK_MESSAGE_ERROR);
702
703   self->priv->info_bar_label = gtk_label_new ("");
704   gtk_container_add (GTK_CONTAINER (
705         gtk_info_bar_get_content_area (GTK_INFO_BAR (self->priv->info_bar))),
706       self->priv->info_bar_label);
707   gtk_widget_show (self->priv->info_bar_label);
708
709   /* prepare the account manager */
710   am = tp_account_manager_dup ();
711
712   factory = tp_proxy_get_factory (am);
713   tp_simple_client_factory_add_connection_features_varargs (factory,
714       TP_CONNECTION_FEATURE_CONTACT_BLOCKING, NULL);
715
716   tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self);
717   g_object_unref (am);
718
719   g_free (filename);
720   g_object_unref (gui);
721 }
722
723 GtkWidget *
724 empathy_contact_blocking_dialog_new (GtkWindow *parent)
725 {
726   GtkWidget *self = g_object_new (EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG,
727       NULL);
728
729   if (parent != NULL)
730     {
731       gtk_window_set_transient_for (GTK_WINDOW (self), parent);
732     }
733
734   return self;
735 }