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