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