]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-search-dialog.c
contact-search-dialog: rely on the factory to prepare TP_CONNECTION_FEATURE_AVATAR_RE...
[empathy.git] / libempathy-gtk / empathy-contact-search-dialog.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * empathy-contact-search-dialog.c
4  *
5  * Copyright (C) 2010-2011 Collabora Ltd.
6  *
7  * The code contained in this file is free software; you can redistribute
8  * it and/or modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either version
10  * 2.1 of the License, or (at your option) any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this code; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  * Authors:
22  *     Danielle Madeley <danielle.madeley@collabora.co.uk>
23  *     Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
24  */
25 #include "config.h"
26
27 #include <glib/gi18n-lib.h>
28
29 #include <telepathy-glib/telepathy-glib.h>
30
31 #include <libempathy/empathy-contact-manager.h>
32 #include <libempathy/empathy-tp-contact-factory.h>
33
34 #include <libempathy-gtk/empathy-account-chooser.h>
35 #include <libempathy-gtk/empathy-cell-renderer-text.h>
36 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
37 #include <libempathy-gtk/empathy-contact-dialogs.h>
38 #include <libempathy-gtk/empathy-images.h>
39
40 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
41 #include <libempathy/empathy-debug.h>
42
43 #include "empathy-contact-search-dialog.h"
44
45 #define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_SEARCH_DIALOG, EmpathyContactSearchDialogPrivate))
46
47 G_DEFINE_TYPE (EmpathyContactSearchDialog, empathy_contact_search_dialog, GTK_TYPE_DIALOG);
48
49 enum
50 {
51    NAME_COLUMN,
52    LOGIN_COLUMN,
53    N_COLUMNS
54 };
55
56 enum {
57    PAGE_SEARCH_RESULTS,
58    PAGE_NO_MATCH
59 };
60
61 typedef struct _EmpathyContactSearchDialogPrivate EmpathyContactSearchDialogPrivate;
62 struct _EmpathyContactSearchDialogPrivate
63 {
64   TpContactSearch *searcher;
65   GtkListStore *store;
66
67   GtkWidget *chooser;
68   GtkWidget *notebook;
69   GtkWidget *tree_view;
70   GtkWidget *spinner;
71   GtkWidget *add_button;
72   GtkWidget *find_button;
73   GtkWidget *no_contact_found;
74   GtkWidget *search_entry;
75   /* GtkWidget *server_entry; */
76 };
77
78 static void
79 empathy_contact_search_dialog_dispose (GObject *self)
80 {
81   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
82
83   tp_clear_object (&priv->searcher);
84
85   G_OBJECT_CLASS (empathy_contact_search_dialog_parent_class)->dispose (self);
86 }
87
88 static void
89 on_searcher_reset (GObject *source_object,
90     GAsyncResult *result,
91     gpointer user_data)
92 {
93   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
94   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
95   TpContactSearch *searcher = TP_CONTACT_SEARCH (source_object);
96   GError *error = NULL;
97   GHashTable *search;
98   const gchar *search_criteria;
99
100   tp_contact_search_reset_finish (searcher, result, &error);
101   if (error != NULL)
102     {
103       DEBUG ("Failed to reset the TpContactSearch: %s", error->message);
104       g_error_free (error);
105       return;
106     }
107
108   search = g_hash_table_new (g_str_hash, g_str_equal);
109
110   search_criteria = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
111
112   if (tp_strv_contains (tp_contact_search_get_search_keys (searcher), ""))
113     g_hash_table_insert (search, "", (gpointer) search_criteria);
114   else
115     g_hash_table_insert (search, "fn", (gpointer) search_criteria);
116
117   gtk_list_store_clear (priv->store);
118   tp_contact_search_start (priv->searcher, search);
119
120   g_hash_table_destroy (search);
121 }
122
123 static void
124 empathy_contact_search_dialog_do_search (EmpathyContactSearchDialog *self)
125 {
126   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
127
128   tp_contact_search_reset_async (priv->searcher,
129       NULL, /* gtk_entry_get_text (GTK_ENTRY (priv->server_entry)), */
130       0,
131       on_searcher_reset,
132       self);
133 }
134
135 static void
136 on_get_contact_factory_get_from_id_cb (TpConnection *connection,
137     EmpathyContact *contact,
138     const GError *error,
139     gpointer user_data,
140     GObject *object)
141 {
142     EmpathyContactManager *manager = empathy_contact_manager_dup_singleton ();
143
144     if (error != NULL)
145       {
146         g_warning ("Error while getting the contact: %s", error->message);
147         return;
148       }
149
150     empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager), contact, "");
151 }
152
153 static void
154 add_selected_contact (EmpathyContactSearchDialog *self)
155 {
156   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
157   GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
158   TpConnection *conn;
159   GtkTreeIter iter;
160   GtkTreeModel *model;
161   gboolean sel;
162   gchar *id;
163
164   conn = empathy_account_chooser_get_connection (EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
165
166   sel = gtk_tree_selection_get_selected (selection, &model, &iter);
167   g_return_if_fail (sel == TRUE);
168
169   gtk_tree_model_get (model, &iter, LOGIN_COLUMN, &id, -1);
170
171   DEBUG ("Requested to add contact: %s", id);
172
173   empathy_tp_contact_factory_get_from_id (conn, id,
174       on_get_contact_factory_get_from_id_cb, NULL,
175       NULL, NULL);
176
177   /* Close the dialog */
178   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
179 }
180
181 static void
182 empathy_contact_search_dialog_response (GtkDialog *self,
183     gint response)
184 {
185   switch (response)
186     {
187       case GTK_RESPONSE_APPLY:
188         add_selected_contact (EMPATHY_CONTACT_SEARCH_DIALOG (self));
189         break;
190       default:
191         gtk_widget_destroy (GTK_WIDGET (self));
192         break;
193     }
194 }
195
196 static void
197 empathy_contact_search_dialog_class_init (
198     EmpathyContactSearchDialogClass *klass)
199 {
200   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
201   GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
202
203   gobject_class->dispose = empathy_contact_search_dialog_dispose;
204
205   dialog_class->response = empathy_contact_search_dialog_response;
206
207   g_type_class_add_private (gobject_class,
208       sizeof (EmpathyContactSearchDialogPrivate));
209 }
210
211 static void
212 _on_search_state_changed_cb (TpContactSearch *searcher,
213     GParamSpec *pspec,
214     gpointer user_data)
215 {
216   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
217   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
218   TpChannelContactSearchState state;
219
220   g_object_get (searcher, "state", &state, NULL);
221
222   DEBUG ("new search status: %d", state);
223
224   if (state == TP_CHANNEL_CONTACT_SEARCH_STATE_IN_PROGRESS)
225     {
226       gtk_widget_show (priv->spinner);
227       gtk_spinner_start (GTK_SPINNER (priv->spinner));
228     }
229   else
230     {
231       gtk_widget_hide (priv->spinner);
232       gtk_spinner_stop (GTK_SPINNER (priv->spinner));
233     }
234
235   if (state == TP_CHANNEL_CONTACT_SEARCH_STATE_NOT_STARTED
236       || state == TP_CHANNEL_CONTACT_SEARCH_STATE_IN_PROGRESS)
237     {
238       gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
239           PAGE_SEARCH_RESULTS);
240     }
241   else
242     {
243       GtkTreeIter help_iter;
244
245       if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
246           &help_iter))
247         {
248           /* No results found, display a helpful message. */
249           gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
250               PAGE_NO_MATCH);
251         }
252     }
253 }
254
255 static void
256 _search_results_received (TpContactSearch *searcher,
257     GList *results,
258     EmpathyContactSearchDialog *self)
259 {
260   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
261   const TpContactInfoField *name;
262   GList *l;
263
264   for (l = results; l != NULL; l = l->next)
265     {
266       TpContactSearchResult *result = l->data;
267       GtkTreeIter iter;
268
269       gtk_list_store_append (priv->store, &iter);
270
271       name = tp_contact_search_result_get_field (result, "fn");
272
273       gtk_list_store_set (priv->store, &iter,
274           NAME_COLUMN, name ? name->field_value[0] : NULL,
275           LOGIN_COLUMN, tp_contact_search_result_get_identifier (result),
276           -1);
277     }
278 }
279
280 static void
281 on_searcher_created (GObject *source_object,
282     GAsyncResult *result,
283     gpointer user_data)
284 {
285   EmpathyContactSearchDialog *self;
286   EmpathyContactSearchDialogPrivate *priv;
287   GError *error = NULL;
288
289   if (EMPATHY_IS_CONTACT_SEARCH_DIALOG (user_data) == FALSE)
290     /* This happens if the dialog is closed before the callback is called */
291     return;
292
293   self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
294   priv = GET_PRIVATE (self);
295
296   priv->searcher = tp_contact_search_new_finish (result, &error);
297   if (error != NULL)
298     {
299       DEBUG ("Failed to create a TpContactSearch: %s", error->message);
300       g_error_free (error);
301       return;
302     }
303
304   g_signal_connect (priv->searcher, "search-results-received",
305       G_CALLBACK (_search_results_received), self);
306   g_signal_connect (priv->searcher, "notify::state",
307       G_CALLBACK (_on_search_state_changed_cb), self);
308
309   gtk_widget_set_sensitive (priv->find_button, TRUE);
310 }
311
312 static void
313 on_selection_changed (GtkTreeSelection *selection,
314     gpointer user_data)
315 {
316   EmpathyContactSearchDialog *self;
317   EmpathyContactSearchDialogPrivate *priv;
318   gboolean sel;
319
320   self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
321   priv = GET_PRIVATE (self);
322   sel = gtk_tree_selection_get_selected (selection, NULL, NULL);
323
324   gtk_widget_set_sensitive (priv->add_button, sel);
325 }
326
327
328 static void
329 _account_chooser_changed (EmpathyAccountChooser *chooser,
330     EmpathyContactSearchDialog *self)
331 {
332   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
333   TpAccount *account = empathy_account_chooser_get_account (chooser);
334   TpConnection *conn = empathy_account_chooser_get_connection (chooser);
335   TpCapabilities *caps = tp_connection_get_capabilities (conn);
336   gboolean can_cs, can_set_limit, can_set_server;
337
338   can_cs = tp_capabilities_supports_contact_search (caps,
339       &can_set_limit, &can_set_server);
340   DEBUG ("The server supports cs|limit|server: %s|%s|%s",
341       can_cs ? "yes" : "no",
342       can_set_limit ? "yes" : "no",
343       can_set_server ? "yes" : "no");
344
345   /* gtk_widget_set_sensitive (priv->server_entry, can_set_server); */
346   gtk_widget_set_sensitive (priv->find_button, FALSE);
347
348   DEBUG ("New account is %s", tp_proxy_get_object_path (account));
349
350   tp_clear_object (&priv->searcher);
351   tp_contact_search_new_async (account,
352       NULL, /* gtk_entry_get_text (GTK_ENTRY (priv->server_entry)), */
353       0,
354       on_searcher_created, self);
355 }
356
357 static void
358 _on_button_search_clicked (GtkWidget *widget,
359     EmpathyContactSearchDialog *self)
360 {
361   empathy_contact_search_dialog_do_search (self);
362 }
363
364 #if 0
365 static void
366 on_server_changed_cb (GtkEditable *editable,
367     gpointer user_data)
368 {
369   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
370   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
371
372   g_return_if_fail (priv->searcher != NULL);
373
374   tp_contact_search_reset_async (priv->searcher,
375       gtk_entry_get_text (GTK_ENTRY (editable)),
376       0,
377       on_searcher_reset,
378       self);
379 }
380 #endif
381
382 static void
383 empathy_account_chooser_filter_supports_contact_search (
384     TpAccount *account,
385     EmpathyAccountChooserFilterResultCallback callback,
386     gpointer callback_data,
387     gpointer user_data)
388 {
389   TpConnection *connection;
390   gboolean supported = FALSE;
391   TpCapabilities *caps;
392
393   connection = tp_account_get_connection (account);
394   if (connection == NULL)
395       goto out;
396
397   caps = tp_connection_get_capabilities (connection);
398   if (caps == NULL)
399       goto out;
400
401   supported = tp_capabilities_supports_contact_search (caps, NULL, NULL);
402
403 out:
404   callback (supported, callback_data);
405 }
406
407 static void
408 contact_search_dialog_row_activated_cb (GtkTreeView *tv,
409     GtkTreePath *path,
410     GtkTreeViewColumn *column,
411     EmpathyContactSearchDialog *self)
412 {
413   /* just emit the same response as the Add Button */
414   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_APPLY);
415 }
416
417 static void
418 on_profile_button_got_contact_cb (TpConnection *connection,
419     EmpathyContact *contact,
420     const GError *error,
421     gpointer user_data,
422     GObject *object)
423 {
424  if (error != NULL)
425    {
426      g_warning ("Error while getting the contact: %s", error->message);
427      return;
428    }
429
430   empathy_contact_information_dialog_show (contact, NULL);
431 }
432
433 static void
434 on_profile_button_clicked_cb (EmpathyCellRendererActivatable *cell,
435     const gchar *path_string,
436     EmpathyContactSearchDialog *self)
437 {
438   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
439   TpConnection *conn;
440   GtkTreeIter iter;
441   GtkTreeModel *model;
442   gboolean valid;
443   gchar *id;
444
445   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree_view));
446
447   conn = empathy_account_chooser_get_connection (
448       EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
449
450   valid = gtk_tree_model_get_iter_from_string (model, &iter, path_string);
451   g_return_if_fail (valid == TRUE);
452
453   gtk_tree_model_get (model, &iter, LOGIN_COLUMN, &id, -1);
454
455   DEBUG ("Requested to show profile for contact: %s", id);
456
457   empathy_tp_contact_factory_get_from_id (conn, id,
458       on_profile_button_got_contact_cb, NULL,
459       NULL, NULL);
460 }
461
462 static void
463 empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
464 {
465   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
466   GtkWidget *vbox, *hbox, *scrolled_window, *label;
467   GtkCellRenderer *cell;
468   GtkTreeViewColumn *col;
469   GtkTreeSelection *selection;
470   GtkSizeGroup *size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
471   gchar *tmp;
472
473   /* Title */
474   gtk_window_set_title (GTK_WINDOW (self), _("Search contacts"));
475
476   vbox = gtk_vbox_new (FALSE, 3);
477   gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
478
479   /* Account chooser */
480   hbox = gtk_hbox_new (FALSE, 6);
481   label = gtk_label_new (_("Account:"));
482   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
483   gtk_size_group_add_widget (size_group, label);
484
485   priv->chooser = empathy_account_chooser_new ();
486   empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (priv->chooser),
487       empathy_account_chooser_filter_supports_contact_search, NULL);
488   gtk_box_pack_start (GTK_BOX (hbox), priv->chooser, TRUE, TRUE, 0);
489   g_signal_connect (priv->chooser, "changed",
490       G_CALLBACK (_account_chooser_changed), self);
491
492   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
493
494 #if 0
495   /* Server entry */
496   priv->server_entry = gtk_entry_new ();
497   gtk_box_pack_start (GTK_BOX (vbox), priv->server_entry, FALSE, TRUE, 6);
498   g_signal_connect (GTK_EDITABLE (priv->server_entry), "changed",
499       G_CALLBACK (on_server_changed_cb), self);
500 #endif
501
502   /* Search input */
503   hbox = gtk_hbox_new (FALSE, 6);
504   label = gtk_label_new (_("Search: "));
505   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
506   gtk_size_group_add_widget (size_group, label);
507
508   priv->search_entry = gtk_entry_new ();
509   gtk_box_pack_start (GTK_BOX (hbox), priv->search_entry, TRUE, TRUE, 0);
510   g_signal_connect (priv->search_entry, "activate",
511       G_CALLBACK (_on_button_search_clicked), self);
512
513   priv->find_button = gtk_button_new_from_stock (GTK_STOCK_FIND);
514   g_signal_connect (priv->find_button, "clicked",
515       G_CALLBACK (_on_button_search_clicked), self);
516   gtk_box_pack_end (GTK_BOX (hbox), priv->find_button, FALSE, TRUE, 0);
517
518   priv->spinner = gtk_spinner_new ();
519   gtk_box_pack_end (GTK_BOX (hbox), priv->spinner, FALSE, TRUE, 0);
520   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
521
522   /* Search results */
523   priv->store = gtk_list_store_new (N_COLUMNS,
524                                     G_TYPE_STRING,  /* Name */
525                                     G_TYPE_STRING); /* Login */
526
527   priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->store));
528   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
529   gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
530
531   g_signal_connect (priv->tree_view, "row-activated",
532       G_CALLBACK (contact_search_dialog_row_activated_cb), self);
533   g_signal_connect (selection, "changed",
534       G_CALLBACK (on_selection_changed), self);
535
536   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
537
538   col = gtk_tree_view_column_new ();
539
540   cell = empathy_cell_renderer_text_new ();
541   gtk_tree_view_column_pack_start (col, cell, TRUE);
542   /* EmpathyCellRendererText displays "name" above and "status" below.
543    * We want the login above since it'll always be available, and the
544    * name below since we won't always have it. */
545   gtk_tree_view_column_add_attribute (col, cell,
546       "name", LOGIN_COLUMN);
547   gtk_tree_view_column_add_attribute (col, cell,
548       "status", NAME_COLUMN);
549
550   cell = empathy_cell_renderer_activatable_new ();
551   gtk_tree_view_column_pack_end (col, cell, FALSE);
552   g_object_set (cell, "stock-id", EMPATHY_IMAGE_CONTACT_INFORMATION, NULL);
553   g_signal_connect (cell, "path-activated",
554       G_CALLBACK (on_profile_button_clicked_cb), self);
555
556   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), col);
557
558   gtk_dialog_add_button (GTK_DIALOG (self),
559       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
560
561   priv->add_button = gtk_dialog_add_button (GTK_DIALOG (self),
562       _("_Add Contact"), GTK_RESPONSE_APPLY);
563   gtk_widget_set_sensitive (priv->add_button, FALSE);
564   gtk_button_set_image (GTK_BUTTON (priv->add_button),
565       gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON));
566
567   /* Pack the dialog */
568   priv->notebook = gtk_notebook_new ();
569   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
570   g_object_set (priv->notebook, "margin", 6, NULL);
571
572   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
573   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
574       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
575
576   gtk_container_add (GTK_CONTAINER (scrolled_window), priv->tree_view);
577
578   priv->no_contact_found = gtk_label_new (NULL);
579   tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
580       _("No contacts found"));
581   gtk_label_set_markup (GTK_LABEL (priv->no_contact_found), tmp);
582   g_free (tmp);
583
584   gtk_label_set_ellipsize (GTK_LABEL (priv->no_contact_found),
585       PANGO_ELLIPSIZE_END);
586
587   gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), scrolled_window,
588       NULL);
589   gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
590       priv->no_contact_found, NULL);
591
592   gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 3);
593
594   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
595           GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
596
597   gtk_window_set_default_size (GTK_WINDOW (self), 200, 400);
598   gtk_widget_show_all (vbox);
599   gtk_widget_hide (priv->spinner);
600 }
601
602 GtkWidget *
603 empathy_contact_search_dialog_new (GtkWindow *parent)
604 {
605   GtkWidget *self;
606
607   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
608
609   self = g_object_new (EMPATHY_TYPE_CONTACT_SEARCH_DIALOG, NULL);
610
611   if (parent != NULL)
612     {
613       gtk_window_set_transient_for (GTK_WINDOW (self), parent);
614     }
615
616   return self;
617 }