]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-search-dialog.c
tp-file: remove EmpathyTpFile
[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   GtkWidget *message;
77   GtkWidget *message_window;
78   GtkWidget *message_label;
79 };
80
81 static void
82 empathy_contact_search_dialog_dispose (GObject *self)
83 {
84   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
85
86   tp_clear_object (&priv->searcher);
87
88   G_OBJECT_CLASS (empathy_contact_search_dialog_parent_class)->dispose (self);
89 }
90
91 static void
92 on_searcher_reset (GObject *source_object,
93     GAsyncResult *result,
94     gpointer user_data)
95 {
96   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
97   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
98   TpContactSearch *searcher = TP_CONTACT_SEARCH (source_object);
99   GError *error = NULL;
100   GHashTable *search;
101   const gchar *search_criteria;
102
103   tp_contact_search_reset_finish (searcher, result, &error);
104   if (error != NULL)
105     {
106       DEBUG ("Failed to reset the TpContactSearch: %s", error->message);
107       g_error_free (error);
108       return;
109     }
110
111   search = g_hash_table_new (g_str_hash, g_str_equal);
112
113   search_criteria = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
114
115   if (tp_strv_contains (tp_contact_search_get_search_keys (searcher), ""))
116     g_hash_table_insert (search, "", (gpointer) search_criteria);
117   else
118     g_hash_table_insert (search, "fn", (gpointer) search_criteria);
119
120   gtk_list_store_clear (priv->store);
121   tp_contact_search_start (priv->searcher, search);
122
123   g_hash_table_destroy (search);
124 }
125
126 static void
127 empathy_contact_search_dialog_do_search (EmpathyContactSearchDialog *self)
128 {
129   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
130
131   tp_contact_search_reset_async (priv->searcher,
132       NULL, /* gtk_entry_get_text (GTK_ENTRY (priv->server_entry)), */
133       0,
134       on_searcher_reset,
135       self);
136 }
137
138 static void
139 on_get_contact_factory_get_from_id_cb (TpConnection *connection,
140     EmpathyContact *contact,
141     const GError *error,
142     gpointer user_data,
143     GObject *object)
144 {
145     EmpathyContactManager *manager = empathy_contact_manager_dup_singleton ();
146     const gchar *message = user_data;
147
148     if (error != NULL)
149       {
150         g_warning ("Error while getting the contact: %s", error->message);
151         return;
152       }
153
154     empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager), contact,
155         message);
156 }
157
158 static void
159 add_selected_contact (EmpathyContactSearchDialog *self)
160 {
161   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
162   GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
163   TpConnection *conn;
164   GtkTreeIter iter;
165   GtkTreeModel *model;
166   GtkTextBuffer *buffer;
167   GtkTextIter start, end;
168   gchar *message;
169   gboolean sel;
170   gchar *id;
171
172   conn = empathy_account_chooser_get_connection (EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
173
174   sel = gtk_tree_selection_get_selected (selection, &model, &iter);
175   g_return_if_fail (sel == TRUE);
176
177   gtk_tree_model_get (model, &iter, LOGIN_COLUMN, &id, -1);
178
179   DEBUG ("Requested to add contact: %s", id);
180
181   buffer = gtk_text_view_get_buffer GTK_TEXT_VIEW (priv->message);
182   gtk_text_buffer_get_start_iter (buffer, &start);
183   gtk_text_buffer_get_end_iter (buffer, &end);
184   message = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
185
186   empathy_tp_contact_factory_get_from_id (conn, id,
187       on_get_contact_factory_get_from_id_cb,
188       message, g_free, NULL);
189
190   /* Close the dialog */
191   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
192 }
193
194 static void
195 empathy_contact_search_dialog_response (GtkDialog *self,
196     gint response)
197 {
198   switch (response)
199     {
200       case GTK_RESPONSE_APPLY:
201         add_selected_contact (EMPATHY_CONTACT_SEARCH_DIALOG (self));
202         break;
203       default:
204         gtk_widget_destroy (GTK_WIDGET (self));
205         break;
206     }
207 }
208
209 static void
210 empathy_contact_search_dialog_class_init (
211     EmpathyContactSearchDialogClass *klass)
212 {
213   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
214   GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
215
216   gobject_class->dispose = empathy_contact_search_dialog_dispose;
217
218   dialog_class->response = empathy_contact_search_dialog_response;
219
220   g_type_class_add_private (gobject_class,
221       sizeof (EmpathyContactSearchDialogPrivate));
222 }
223
224 static void
225 _on_search_state_changed_cb (TpContactSearch *searcher,
226     GParamSpec *pspec,
227     gpointer user_data)
228 {
229   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
230   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
231   TpChannelContactSearchState state;
232
233   g_object_get (searcher, "state", &state, NULL);
234
235   DEBUG ("new search status: %d", state);
236
237   if (state == TP_CHANNEL_CONTACT_SEARCH_STATE_IN_PROGRESS)
238     {
239       gtk_widget_show (priv->spinner);
240       gtk_spinner_start (GTK_SPINNER (priv->spinner));
241     }
242   else
243     {
244       gtk_widget_hide (priv->spinner);
245       gtk_spinner_stop (GTK_SPINNER (priv->spinner));
246     }
247
248   if (state == TP_CHANNEL_CONTACT_SEARCH_STATE_NOT_STARTED
249       || state == TP_CHANNEL_CONTACT_SEARCH_STATE_IN_PROGRESS)
250     {
251       gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
252           PAGE_SEARCH_RESULTS);
253     }
254   else
255     {
256       GtkTreeIter help_iter;
257
258       if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
259           &help_iter))
260         {
261           /* No results found, display a helpful message. */
262           gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
263               PAGE_NO_MATCH);
264         }
265     }
266 }
267
268 static void
269 _search_results_received (TpContactSearch *searcher,
270     GList *results,
271     EmpathyContactSearchDialog *self)
272 {
273   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
274   const TpContactInfoField *name;
275   GList *l;
276
277   for (l = results; l != NULL; l = l->next)
278     {
279       TpContactSearchResult *result = l->data;
280       GtkTreeIter iter;
281
282       gtk_list_store_append (priv->store, &iter);
283
284       name = tp_contact_search_result_get_field (result, "fn");
285
286       gtk_list_store_set (priv->store, &iter,
287           NAME_COLUMN, name ? name->field_value[0] : NULL,
288           LOGIN_COLUMN, tp_contact_search_result_get_identifier (result),
289           -1);
290     }
291 }
292
293 static void
294 on_searcher_created (GObject *source_object,
295     GAsyncResult *result,
296     gpointer user_data)
297 {
298   EmpathyContactSearchDialog *self;
299   EmpathyContactSearchDialogPrivate *priv;
300   GError *error = NULL;
301
302   if (EMPATHY_IS_CONTACT_SEARCH_DIALOG (user_data) == FALSE)
303     /* This happens if the dialog is closed before the callback is called */
304     return;
305
306   self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
307   priv = GET_PRIVATE (self);
308
309   priv->searcher = tp_contact_search_new_finish (result, &error);
310   if (error != NULL)
311     {
312       DEBUG ("Failed to create a TpContactSearch: %s", error->message);
313       g_error_free (error);
314       return;
315     }
316
317   g_signal_connect (priv->searcher, "search-results-received",
318       G_CALLBACK (_search_results_received), self);
319   g_signal_connect (priv->searcher, "notify::state",
320       G_CALLBACK (_on_search_state_changed_cb), self);
321
322   gtk_widget_set_sensitive (priv->find_button, TRUE);
323 }
324
325 static void
326 on_selection_changed (GtkTreeSelection *selection,
327     gpointer user_data)
328 {
329   EmpathyContactSearchDialog *self;
330   EmpathyContactSearchDialogPrivate *priv;
331   gboolean sel;
332
333   self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
334   priv = GET_PRIVATE (self);
335   sel = gtk_tree_selection_get_selected (selection, NULL, NULL);
336
337   gtk_widget_set_sensitive (priv->add_button, sel);
338 }
339
340 static void
341 check_request_message_available (EmpathyContactSearchDialog *self,
342     TpConnection *conn)
343 {
344   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
345   EmpathyContactManager *manager = empathy_contact_manager_dup_singleton ();
346   EmpathyContactListFlags flags;
347
348   flags = empathy_contact_manager_get_flags_for_connection (manager, conn);
349
350   gtk_widget_set_visible (priv->message_window,
351       flags & EMPATHY_CONTACT_LIST_MESSAGE_ADD);
352   gtk_widget_set_visible (priv->message_label,
353       flags & EMPATHY_CONTACT_LIST_MESSAGE_ADD);
354 }
355
356 static void
357 _account_chooser_changed (EmpathyAccountChooser *chooser,
358     EmpathyContactSearchDialog *self)
359 {
360   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
361   TpAccount *account = empathy_account_chooser_get_account (chooser);
362   TpConnection *conn = empathy_account_chooser_get_connection (chooser);
363   TpCapabilities *caps = tp_connection_get_capabilities (conn);
364   gboolean can_cs, can_set_limit, can_set_server;
365
366   can_cs = tp_capabilities_supports_contact_search (caps,
367       &can_set_limit, &can_set_server);
368   DEBUG ("The server supports cs|limit|server: %s|%s|%s",
369       can_cs ? "yes" : "no",
370       can_set_limit ? "yes" : "no",
371       can_set_server ? "yes" : "no");
372
373   /* gtk_widget_set_sensitive (priv->server_entry, can_set_server); */
374   gtk_widget_set_sensitive (priv->find_button, FALSE);
375
376   DEBUG ("New account is %s", tp_proxy_get_object_path (account));
377
378   tp_clear_object (&priv->searcher);
379   tp_contact_search_new_async (account,
380       NULL, /* gtk_entry_get_text (GTK_ENTRY (priv->server_entry)), */
381       0,
382       on_searcher_created, self);
383
384   /* Make the request message textview sensitive if it can be used */
385   check_request_message_available (self, conn);
386 }
387
388 static void
389 _on_button_search_clicked (GtkWidget *widget,
390     EmpathyContactSearchDialog *self)
391 {
392   empathy_contact_search_dialog_do_search (self);
393 }
394
395 #if 0
396 static void
397 on_server_changed_cb (GtkEditable *editable,
398     gpointer user_data)
399 {
400   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
401   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
402
403   g_return_if_fail (priv->searcher != NULL);
404
405   tp_contact_search_reset_async (priv->searcher,
406       gtk_entry_get_text (GTK_ENTRY (editable)),
407       0,
408       on_searcher_reset,
409       self);
410 }
411 #endif
412
413 static void
414 empathy_account_chooser_filter_supports_contact_search (
415     TpAccount *account,
416     EmpathyAccountChooserFilterResultCallback callback,
417     gpointer callback_data,
418     gpointer user_data)
419 {
420   TpConnection *connection;
421   gboolean supported = FALSE;
422   TpCapabilities *caps;
423
424   connection = tp_account_get_connection (account);
425   if (connection == NULL)
426       goto out;
427
428   caps = tp_connection_get_capabilities (connection);
429   if (caps == NULL)
430       goto out;
431
432   supported = tp_capabilities_supports_contact_search (caps, NULL, NULL);
433
434 out:
435   callback (supported, callback_data);
436 }
437
438 static void
439 contact_search_dialog_row_activated_cb (GtkTreeView *tv,
440     GtkTreePath *path,
441     GtkTreeViewColumn *column,
442     EmpathyContactSearchDialog *self)
443 {
444   /* just emit the same response as the Add Button */
445   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_APPLY);
446 }
447
448 static void
449 on_profile_button_got_contact_cb (TpConnection *connection,
450     EmpathyContact *contact,
451     const GError *error,
452     gpointer user_data,
453     GObject *object)
454 {
455  if (error != NULL)
456    {
457      g_warning ("Error while getting the contact: %s", error->message);
458      return;
459    }
460
461   empathy_contact_information_dialog_show (contact, NULL);
462 }
463
464 static void
465 on_profile_button_clicked_cb (EmpathyCellRendererActivatable *cell,
466     const gchar *path_string,
467     EmpathyContactSearchDialog *self)
468 {
469   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
470   TpConnection *conn;
471   GtkTreeIter iter;
472   GtkTreeModel *model;
473   gboolean valid;
474   gchar *id;
475
476   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree_view));
477
478   conn = empathy_account_chooser_get_connection (
479       EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
480
481   valid = gtk_tree_model_get_iter_from_string (model, &iter, path_string);
482   g_return_if_fail (valid == TRUE);
483
484   gtk_tree_model_get (model, &iter, LOGIN_COLUMN, &id, -1);
485
486   DEBUG ("Requested to show profile for contact: %s", id);
487
488   empathy_tp_contact_factory_get_from_id (conn, id,
489       on_profile_button_got_contact_cb, NULL,
490       NULL, NULL);
491 }
492
493 static void
494 empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
495 {
496   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
497   GtkWidget *vbox, *hbox, *scrolled_window, *label;
498   GtkCellRenderer *cell;
499   GtkTreeViewColumn *col;
500   GtkTreeSelection *selection;
501   GtkSizeGroup *size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
502   gchar *tmp;
503
504   /* Title */
505   gtk_window_set_title (GTK_WINDOW (self), _("Search contacts"));
506
507   vbox = gtk_vbox_new (FALSE, 3);
508   gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
509
510   /* Account chooser */
511   hbox = gtk_hbox_new (FALSE, 6);
512   label = gtk_label_new (_("Account:"));
513   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
514   gtk_size_group_add_widget (size_group, label);
515
516   priv->chooser = empathy_account_chooser_new ();
517   empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (priv->chooser),
518       empathy_account_chooser_filter_supports_contact_search, NULL);
519   gtk_box_pack_start (GTK_BOX (hbox), priv->chooser, TRUE, TRUE, 0);
520   g_signal_connect (priv->chooser, "changed",
521       G_CALLBACK (_account_chooser_changed), self);
522
523   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
524
525 #if 0
526   /* Server entry */
527   priv->server_entry = gtk_entry_new ();
528   gtk_box_pack_start (GTK_BOX (vbox), priv->server_entry, FALSE, TRUE, 6);
529   g_signal_connect (GTK_EDITABLE (priv->server_entry), "changed",
530       G_CALLBACK (on_server_changed_cb), self);
531 #endif
532
533   /* Search input */
534   hbox = gtk_hbox_new (FALSE, 6);
535   label = gtk_label_new (_("Search: "));
536   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
537   gtk_size_group_add_widget (size_group, label);
538
539   priv->search_entry = gtk_entry_new ();
540   gtk_box_pack_start (GTK_BOX (hbox), priv->search_entry, TRUE, TRUE, 0);
541   g_signal_connect (priv->search_entry, "activate",
542       G_CALLBACK (_on_button_search_clicked), self);
543
544   priv->find_button = gtk_button_new_from_stock (GTK_STOCK_FIND);
545   g_signal_connect (priv->find_button, "clicked",
546       G_CALLBACK (_on_button_search_clicked), self);
547   gtk_box_pack_end (GTK_BOX (hbox), priv->find_button, FALSE, TRUE, 0);
548
549   priv->spinner = gtk_spinner_new ();
550   gtk_box_pack_end (GTK_BOX (hbox), priv->spinner, FALSE, TRUE, 0);
551   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
552
553   /* Search results */
554   priv->store = gtk_list_store_new (N_COLUMNS,
555                                     G_TYPE_STRING,  /* Name */
556                                     G_TYPE_STRING); /* Login */
557
558   priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->store));
559   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
560   gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
561
562   g_signal_connect (priv->tree_view, "row-activated",
563       G_CALLBACK (contact_search_dialog_row_activated_cb), self);
564   g_signal_connect (selection, "changed",
565       G_CALLBACK (on_selection_changed), self);
566
567   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
568
569   col = gtk_tree_view_column_new ();
570
571   cell = empathy_cell_renderer_text_new ();
572   gtk_tree_view_column_pack_start (col, cell, TRUE);
573   /* EmpathyCellRendererText displays "name" above and "status" below.
574    * We want the login above since it'll always be available, and the
575    * name below since we won't always have it. */
576   gtk_tree_view_column_add_attribute (col, cell,
577       "name", LOGIN_COLUMN);
578   gtk_tree_view_column_add_attribute (col, cell,
579       "status", NAME_COLUMN);
580
581   cell = empathy_cell_renderer_activatable_new ();
582   gtk_tree_view_column_pack_end (col, cell, FALSE);
583   g_object_set (cell, "stock-id", EMPATHY_IMAGE_CONTACT_INFORMATION, NULL);
584   g_signal_connect (cell, "path-activated",
585       G_CALLBACK (on_profile_button_clicked_cb), self);
586
587   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), col);
588
589   gtk_dialog_add_button (GTK_DIALOG (self),
590       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
591
592   priv->add_button = gtk_dialog_add_button (GTK_DIALOG (self),
593       _("_Add Contact"), GTK_RESPONSE_APPLY);
594   gtk_widget_set_sensitive (priv->add_button, FALSE);
595   gtk_button_set_image (GTK_BUTTON (priv->add_button),
596       gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON));
597
598   /* Pack the dialog */
599   priv->notebook = gtk_notebook_new ();
600   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
601   g_object_set (priv->notebook, "margin", 6, NULL);
602
603   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
604   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
605       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
606
607   gtk_container_add (GTK_CONTAINER (scrolled_window), priv->tree_view);
608
609   priv->no_contact_found = gtk_label_new (NULL);
610   tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
611       _("No contacts found"));
612   gtk_label_set_markup (GTK_LABEL (priv->no_contact_found), tmp);
613   g_free (tmp);
614
615   gtk_label_set_ellipsize (GTK_LABEL (priv->no_contact_found),
616       PANGO_ELLIPSIZE_END);
617
618   gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), scrolled_window,
619       NULL);
620   gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
621       priv->no_contact_found, NULL);
622
623   gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 3);
624
625   /* Request message textview */
626   priv->message_label = gtk_label_new (
627        _("Your message introducing yourself:"));
628   gtk_misc_set_alignment (GTK_MISC (priv->message_label), 0, 0.5);
629
630   priv->message = gtk_text_view_new ();
631   gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->message),
632       GTK_WRAP_WORD_CHAR);
633   gtk_text_buffer_set_text (
634       gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->message)),
635       _("Please let me see when you're online. Thanks!"), -1);
636
637   priv->message_window = gtk_scrolled_window_new (NULL, NULL);
638   gtk_scrolled_window_set_shadow_type (
639       GTK_SCROLLED_WINDOW (priv->message_window),
640       GTK_SHADOW_ETCHED_IN);
641   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->message_window),
642       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
643
644   gtk_container_add (GTK_CONTAINER (priv->message_window), priv->message);
645
646   gtk_box_pack_start (GTK_BOX (vbox), priv->message_label, FALSE, TRUE, 3);
647   gtk_box_pack_start (GTK_BOX (vbox), priv->message_window, FALSE, TRUE, 3);
648
649   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
650           GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
651
652   gtk_window_set_default_size (GTK_WINDOW (self), 200, 400);
653   gtk_widget_show_all (vbox);
654   gtk_widget_hide (priv->spinner);
655 }
656
657 GtkWidget *
658 empathy_contact_search_dialog_new (GtkWindow *parent)
659 {
660   GtkWidget *self;
661
662   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
663
664   self = g_object_new (EMPATHY_TYPE_CONTACT_SEARCH_DIALOG, NULL);
665
666   if (parent != NULL)
667     {
668       gtk_window_set_transient_for (GTK_WINDOW (self), parent);
669     }
670
671   return self;
672 }