]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-search-dialog.c
b563622c38a90269d005ef30056b6e66449f9629
[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 "libempathy/empathy-utils.h"
30 #include "libempathy/empathy-client-factory.h"
31
32 #include "empathy-account-chooser.h"
33 #include "empathy-cell-renderer-text.h"
34 #include "empathy-cell-renderer-activatable.h"
35 #include "empathy-individual-information-dialog.h"
36 #include "empathy-images.h"
37
38 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
39 #include "libempathy/empathy-debug.h"
40
41 #include "empathy-contact-search-dialog.h"
42
43 #define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_SEARCH_DIALOG, EmpathyContactSearchDialogPrivate))
44
45 G_DEFINE_TYPE (EmpathyContactSearchDialog, empathy_contact_search_dialog, GTK_TYPE_DIALOG);
46
47 enum
48 {
49    NAME_COLUMN,
50    LOGIN_COLUMN,
51    N_COLUMNS
52 };
53
54 enum {
55    PAGE_SEARCH_RESULTS,
56    PAGE_NO_MATCH
57 };
58
59 typedef struct _EmpathyContactSearchDialogPrivate EmpathyContactSearchDialogPrivate;
60 struct _EmpathyContactSearchDialogPrivate
61 {
62   TpContactSearch *searcher;
63   GtkListStore *store;
64
65   GtkWidget *chooser;
66   GtkWidget *notebook;
67   GtkWidget *tree_view;
68   GtkWidget *spinner;
69   GtkWidget *add_button;
70   GtkWidget *find_button;
71   GtkWidget *no_contact_found;
72   GtkWidget *search_entry;
73   /* GtkWidget *server_entry; */
74   GtkWidget *message;
75   GtkWidget *message_window;
76   GtkWidget *message_label;
77 };
78
79 static void
80 empathy_contact_search_dialog_dispose (GObject *self)
81 {
82   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
83
84   tp_clear_object (&priv->searcher);
85
86   G_OBJECT_CLASS (empathy_contact_search_dialog_parent_class)->dispose (self);
87 }
88
89 static void
90 on_searcher_reset (GObject *source_object,
91     GAsyncResult *result,
92     gpointer user_data)
93 {
94   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
95   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
96   TpContactSearch *searcher = TP_CONTACT_SEARCH (source_object);
97   GError *error = NULL;
98   GHashTable *search;
99   const gchar *search_criteria;
100
101   tp_contact_search_reset_finish (searcher, result, &error);
102   if (error != NULL)
103     {
104       DEBUG ("Failed to reset the TpContactSearch: %s", error->message);
105       g_error_free (error);
106       return;
107     }
108
109   search = g_hash_table_new (g_str_hash, g_str_equal);
110
111   search_criteria = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
112
113   if (tp_strv_contains (tp_contact_search_get_search_keys (searcher), ""))
114     g_hash_table_insert (search, "", (gpointer) search_criteria);
115   else
116     g_hash_table_insert (search, "fn", (gpointer) search_criteria);
117
118   gtk_list_store_clear (priv->store);
119   tp_contact_search_start (priv->searcher, search);
120
121   g_hash_table_unref (search);
122 }
123
124 static void
125 empathy_contact_search_dialog_do_search (EmpathyContactSearchDialog *self)
126 {
127   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
128
129   tp_contact_search_reset_async (priv->searcher,
130       NULL, /* gtk_entry_get_text (GTK_ENTRY (priv->server_entry)), */
131       0,
132       on_searcher_reset,
133       self);
134 }
135
136 static void
137 on_get_contact_factory_get_from_id_cb (GObject *source,
138     GAsyncResult *result,
139     gpointer user_data)
140 {
141   gchar *message = user_data;
142   GError *error = NULL;
143   EmpathyContact *contact;
144
145   contact = empathy_client_factory_dup_contact_by_id_finish (
146       EMPATHY_CLIENT_FACTORY (source), result, &error);
147   if (contact == NULL)
148     {
149       g_warning ("Error while getting the contact: %s", error->message);
150       g_error_free (error);
151       goto out;
152     }
153
154   empathy_contact_add_to_contact_list (contact, message);
155   g_object_unref (contact);
156
157 out:
158   g_free (message);
159 }
160
161 static void
162 add_selected_contact (EmpathyContactSearchDialog *self)
163 {
164   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
165   GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
166   TpConnection *conn;
167   GtkTreeIter iter;
168   GtkTreeModel *model;
169   GtkTextBuffer *buffer;
170   GtkTextIter start, end;
171   gchar *message;
172   gboolean sel;
173   gchar *id;
174   EmpathyClientFactory *factory;
175
176   conn = empathy_account_chooser_get_connection (EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
177
178   sel = gtk_tree_selection_get_selected (selection, &model, &iter);
179   g_return_if_fail (sel == TRUE);
180
181   gtk_tree_model_get (model, &iter, LOGIN_COLUMN, &id, -1);
182
183   DEBUG ("Requested to add contact: %s", id);
184
185   buffer = gtk_text_view_get_buffer GTK_TEXT_VIEW (priv->message);
186   gtk_text_buffer_get_start_iter (buffer, &start);
187   gtk_text_buffer_get_end_iter (buffer, &end);
188   message = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
189
190   factory = empathy_client_factory_dup ();
191
192   empathy_client_factory_dup_contact_by_id_async (factory, conn, id,
193       on_get_contact_factory_get_from_id_cb, message);
194
195   g_object_unref (factory);
196
197   /* Close the dialog */
198   gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
199 }
200
201 static void
202 empathy_contact_search_dialog_response (GtkDialog *self,
203     gint response)
204 {
205   switch (response)
206     {
207       case GTK_RESPONSE_APPLY:
208         add_selected_contact (EMPATHY_CONTACT_SEARCH_DIALOG (self));
209         break;
210       default:
211         gtk_widget_destroy (GTK_WIDGET (self));
212         break;
213     }
214 }
215
216 static void
217 empathy_contact_search_dialog_class_init (
218     EmpathyContactSearchDialogClass *klass)
219 {
220   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
221   GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
222
223   gobject_class->dispose = empathy_contact_search_dialog_dispose;
224
225   dialog_class->response = empathy_contact_search_dialog_response;
226
227   g_type_class_add_private (gobject_class,
228       sizeof (EmpathyContactSearchDialogPrivate));
229 }
230
231 static void
232 _on_search_state_changed_cb (TpContactSearch *searcher,
233     GParamSpec *pspec,
234     gpointer user_data)
235 {
236   EmpathyContactSearchDialog *self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
237   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
238   TpChannelContactSearchState state;
239
240   g_object_get (searcher, "state", &state, NULL);
241
242   DEBUG ("new search status: %d", state);
243
244   if (state == TP_CHANNEL_CONTACT_SEARCH_STATE_IN_PROGRESS)
245     {
246       gtk_widget_show (priv->spinner);
247       gtk_spinner_start (GTK_SPINNER (priv->spinner));
248     }
249   else
250     {
251       gtk_widget_hide (priv->spinner);
252       gtk_spinner_stop (GTK_SPINNER (priv->spinner));
253     }
254
255   if (state == TP_CHANNEL_CONTACT_SEARCH_STATE_NOT_STARTED
256       || state == TP_CHANNEL_CONTACT_SEARCH_STATE_IN_PROGRESS)
257     {
258       gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
259           PAGE_SEARCH_RESULTS);
260     }
261   else
262     {
263       GtkTreeIter help_iter;
264
265       if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store),
266           &help_iter))
267         {
268           /* No results found, display a helpful message. */
269           gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
270               PAGE_NO_MATCH);
271         }
272     }
273 }
274
275 static void
276 _search_results_received (TpContactSearch *searcher,
277     GList *results,
278     EmpathyContactSearchDialog *self)
279 {
280   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
281   const TpContactInfoField *name;
282   GList *l;
283
284   for (l = results; l != NULL; l = l->next)
285     {
286       TpContactSearchResult *result = l->data;
287
288       name = tp_contact_search_result_get_field (result, "fn");
289
290       gtk_list_store_insert_with_values (priv->store, NULL, -1,
291           NAME_COLUMN, name ? name->field_value[0] : NULL,
292           LOGIN_COLUMN, tp_contact_search_result_get_identifier (result),
293           -1);
294     }
295 }
296
297 static void
298 on_searcher_created (GObject *source_object,
299     GAsyncResult *result,
300     gpointer user_data)
301 {
302   EmpathyContactSearchDialog *self;
303   EmpathyContactSearchDialogPrivate *priv;
304   GError *error = NULL;
305
306   if (EMPATHY_IS_CONTACT_SEARCH_DIALOG (user_data) == FALSE)
307     /* This happens if the dialog is closed before the callback is called */
308     return;
309
310   self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
311   priv = GET_PRIVATE (self);
312
313   priv->searcher = tp_contact_search_new_finish (result, &error);
314   if (error != NULL)
315     {
316       DEBUG ("Failed to create a TpContactSearch: %s", error->message);
317       g_error_free (error);
318       return;
319     }
320
321   g_signal_connect (priv->searcher, "search-results-received",
322       G_CALLBACK (_search_results_received), self);
323   g_signal_connect (priv->searcher, "notify::state",
324       G_CALLBACK (_on_search_state_changed_cb), self);
325
326   gtk_widget_set_sensitive (priv->find_button, TRUE);
327 }
328
329 static void
330 on_selection_changed (GtkTreeSelection *selection,
331     gpointer user_data)
332 {
333   EmpathyContactSearchDialog *self;
334   EmpathyContactSearchDialogPrivate *priv;
335   gboolean sel;
336
337   self = EMPATHY_CONTACT_SEARCH_DIALOG (user_data);
338   priv = GET_PRIVATE (self);
339   sel = gtk_tree_selection_get_selected (selection, NULL, NULL);
340
341   gtk_widget_set_sensitive (priv->add_button, sel);
342 }
343
344 static void
345 check_request_message_available (EmpathyContactSearchDialog *self,
346     TpConnection *conn)
347 {
348   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
349
350   gtk_widget_set_visible (priv->message_window,
351       tp_connection_get_can_change_contact_list (conn));
352   gtk_widget_set_visible (priv->message_label,
353       tp_connection_get_can_change_contact_list (conn));
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 (GObject *source,
450     GAsyncResult *result,
451     gpointer user_data)
452 {
453   GError *error = NULL;
454   EmpathyContact *contact;
455   FolksIndividual *individual;
456
457   contact = empathy_client_factory_dup_contact_by_id_finish (
458         EMPATHY_CLIENT_FACTORY (source), result, &error);
459   if (contact == NULL)
460     {
461       g_warning ("Error while getting the contact: %s", error->message);
462       g_error_free (error);
463       return;
464     }
465
466   individual = empathy_ensure_individual_from_tp_contact (
467     empathy_contact_get_tp_contact (contact));
468
469   empathy_display_individual_info (individual);
470
471   g_object_unref (contact);
472   g_object_unref (individual);
473 }
474
475 static void
476 on_profile_button_clicked_cb (EmpathyCellRendererActivatable *cell,
477     const gchar *path_string,
478     EmpathyContactSearchDialog *self)
479 {
480   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
481   TpConnection *conn;
482   GtkTreeIter iter;
483   GtkTreeModel *model;
484   gboolean valid;
485   gchar *id;
486   EmpathyClientFactory *factory;
487
488   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree_view));
489
490   conn = empathy_account_chooser_get_connection (
491       EMPATHY_ACCOUNT_CHOOSER (priv->chooser));
492
493   valid = gtk_tree_model_get_iter_from_string (model, &iter, path_string);
494   g_return_if_fail (valid == TRUE);
495
496   gtk_tree_model_get (model, &iter, LOGIN_COLUMN, &id, -1);
497
498   DEBUG ("Requested to show profile for contact: %s", id);
499
500   factory = empathy_client_factory_dup ();
501
502   empathy_client_factory_dup_contact_by_id_async (factory, conn, id,
503       on_profile_button_got_contact_cb, self);
504
505   g_object_unref (factory);
506 }
507
508 static void
509 empathy_contact_search_dialog_init (EmpathyContactSearchDialog *self)
510 {
511   EmpathyContactSearchDialogPrivate *priv = GET_PRIVATE (self);
512   GtkWidget *vbox, *hbox, *scrolled_window, *label;
513   GtkCellRenderer *cell;
514   GtkTreeViewColumn *col;
515   GtkTreeSelection *selection;
516   GtkSizeGroup *size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
517   gchar *tmp;
518
519   /* Title */
520   gtk_window_set_title (GTK_WINDOW (self), _("Search contacts"));
521
522   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
523   gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
524
525   /* Account chooser */
526   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
527   label = gtk_label_new (_("Account:"));
528   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
529   gtk_size_group_add_widget (size_group, label);
530
531   priv->chooser = empathy_account_chooser_new ();
532   empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (priv->chooser),
533       empathy_account_chooser_filter_supports_contact_search, NULL);
534   gtk_box_pack_start (GTK_BOX (hbox), priv->chooser, TRUE, TRUE, 0);
535   g_signal_connect (priv->chooser, "changed",
536       G_CALLBACK (_account_chooser_changed), self);
537
538   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
539
540 #if 0
541   /* Server entry */
542   priv->server_entry = gtk_entry_new ();
543   gtk_box_pack_start (GTK_BOX (vbox), priv->server_entry, FALSE, TRUE, 6);
544   g_signal_connect (GTK_EDITABLE (priv->server_entry), "changed",
545       G_CALLBACK (on_server_changed_cb), self);
546 #endif
547
548   /* Search input */
549   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
550   label = gtk_label_new (_("Search: "));
551   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
552   gtk_size_group_add_widget (size_group, label);
553
554   priv->search_entry = gtk_entry_new ();
555   gtk_box_pack_start (GTK_BOX (hbox), priv->search_entry, TRUE, TRUE, 0);
556   g_signal_connect (priv->search_entry, "activate",
557       G_CALLBACK (_on_button_search_clicked), self);
558
559   priv->find_button = gtk_button_new_from_stock (GTK_STOCK_FIND);
560   g_signal_connect (priv->find_button, "clicked",
561       G_CALLBACK (_on_button_search_clicked), self);
562   gtk_box_pack_end (GTK_BOX (hbox), priv->find_button, FALSE, TRUE, 0);
563
564   priv->spinner = gtk_spinner_new ();
565   gtk_box_pack_end (GTK_BOX (hbox), priv->spinner, FALSE, TRUE, 0);
566   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
567
568   /* Search results */
569   priv->store = gtk_list_store_new (N_COLUMNS,
570                                     G_TYPE_STRING,  /* Name */
571                                     G_TYPE_STRING); /* Login */
572
573   priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->store));
574   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
575   gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
576
577   g_signal_connect (priv->tree_view, "row-activated",
578       G_CALLBACK (contact_search_dialog_row_activated_cb), self);
579   g_signal_connect (selection, "changed",
580       G_CALLBACK (on_selection_changed), self);
581
582   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
583
584   col = gtk_tree_view_column_new ();
585
586   cell = empathy_cell_renderer_text_new ();
587   gtk_tree_view_column_pack_start (col, cell, TRUE);
588   /* EmpathyCellRendererText displays "name" above and "status" below.
589    * We want the login above since it'll always be available, and the
590    * name below since we won't always have it. */
591   gtk_tree_view_column_add_attribute (col, cell,
592       "name", LOGIN_COLUMN);
593   gtk_tree_view_column_add_attribute (col, cell,
594       "status", NAME_COLUMN);
595
596   cell = empathy_cell_renderer_activatable_new ();
597   gtk_tree_view_column_pack_end (col, cell, FALSE);
598   g_object_set (cell, "stock-id", EMPATHY_IMAGE_CONTACT_INFORMATION, NULL);
599   g_signal_connect (cell, "path-activated",
600       G_CALLBACK (on_profile_button_clicked_cb), self);
601
602   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), col);
603
604   gtk_dialog_add_button (GTK_DIALOG (self),
605       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
606
607   priv->add_button = gtk_dialog_add_button (GTK_DIALOG (self),
608       _("_Add Contact"), GTK_RESPONSE_APPLY);
609   gtk_widget_set_sensitive (priv->add_button, FALSE);
610   gtk_button_set_image (GTK_BUTTON (priv->add_button),
611       gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON));
612
613   /* Pack the dialog */
614   priv->notebook = gtk_notebook_new ();
615   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
616   g_object_set (priv->notebook, "margin", 6, NULL);
617
618   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
619   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
620       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
621
622   gtk_container_add (GTK_CONTAINER (scrolled_window), priv->tree_view);
623
624   priv->no_contact_found = gtk_label_new (NULL);
625   tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
626       _("No contacts found"));
627   gtk_label_set_markup (GTK_LABEL (priv->no_contact_found), tmp);
628   g_free (tmp);
629
630   gtk_label_set_ellipsize (GTK_LABEL (priv->no_contact_found),
631       PANGO_ELLIPSIZE_END);
632
633   gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), scrolled_window,
634       NULL);
635   gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
636       priv->no_contact_found, NULL);
637
638   gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 3);
639
640   /* Request message textview */
641   priv->message_label = gtk_label_new (
642        _("Your message introducing yourself:"));
643   gtk_misc_set_alignment (GTK_MISC (priv->message_label), 0, 0.5);
644
645   priv->message = gtk_text_view_new ();
646   gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->message),
647       GTK_WRAP_WORD_CHAR);
648   gtk_text_buffer_set_text (
649       gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->message)),
650       _("Please let me see when you're online. Thanks!"), -1);
651
652   priv->message_window = gtk_scrolled_window_new (NULL, NULL);
653   gtk_scrolled_window_set_shadow_type (
654       GTK_SCROLLED_WINDOW (priv->message_window),
655       GTK_SHADOW_ETCHED_IN);
656   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->message_window),
657       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
658
659   gtk_container_add (GTK_CONTAINER (priv->message_window), priv->message);
660
661   gtk_box_pack_start (GTK_BOX (vbox), priv->message_label, FALSE, TRUE, 3);
662   gtk_box_pack_start (GTK_BOX (vbox), priv->message_window, FALSE, TRUE, 3);
663
664   gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (
665           GTK_DIALOG (self))), vbox, TRUE, TRUE, 0);
666
667   gtk_window_set_default_size (GTK_WINDOW (self), 200, 400);
668   gtk_widget_show_all (vbox);
669   gtk_widget_hide (priv->spinner);
670   g_object_unref (size_group);
671 }
672
673 GtkWidget *
674 empathy_contact_search_dialog_new (GtkWindow *parent)
675 {
676   GtkWidget *self;
677
678   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
679
680   self = g_object_new (EMPATHY_TYPE_CONTACT_SEARCH_DIALOG, NULL);
681
682   if (parent != NULL)
683     {
684       gtk_window_set_transient_for (GTK_WINDOW (self), parent);
685     }
686
687   return self;
688 }