]> git.0d.be Git - empathy.git/blob - src/empathy-account-assistant.c
Updated Polish translation
[empathy.git] / src / empathy-account-assistant.c
1 /*
2  * Copyright (C) 2009 Collabora Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
19  */
20
21 /* empathy-account-assistant.c */
22
23 #include <glib/gi18n.h>
24 #include <telepathy-glib/util.h>
25 #include <gdk/gdkkeysyms.h>
26
27 #include "empathy-account-assistant.h"
28 #include "empathy-import-widget.h"
29 #include "empathy-import-utils.h"
30 #include "empathy-auto-salut-account-helper.h"
31
32 #include <libempathy/empathy-account-settings.h>
33 #include <libempathy/empathy-utils.h>
34
35 #include <libempathy-gtk/empathy-account-widget.h>
36 #include <libempathy-gtk/empathy-protocol-chooser.h>
37 #include <libempathy-gtk/empathy-ui-utils.h>
38 #include <libempathy-gtk/empathy-conf.h>
39
40 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
41 #include <libempathy/empathy-debug.h>
42
43 G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant,
44     GTK_TYPE_ASSISTANT)
45
46 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountAssistant)
47
48 typedef enum {
49   RESPONSE_IMPORT = 1,
50   RESPONSE_ENTER_ACCOUNT = 2,
51   RESPONSE_CREATE_ACCOUNT = 3,
52   RESPONSE_SALUT_ONLY = 4
53 } FirstPageResponse;
54
55 typedef enum {
56   RESPONSE_CREATE_AGAIN = 1,
57   RESPONSE_CREATE_STOP = 2
58 } CreateEnterPageResponse;
59
60 enum {
61   PAGE_INTRO = 0,
62   PAGE_IMPORT = 1,
63   PAGE_ENTER_CREATE = 2,
64   PAGE_SALUT = 3,
65 };
66
67 enum {
68   PROP_PARENT = 1,
69   PROP_CONNECTION_MGRS,
70 };
71
72 typedef struct {
73   FirstPageResponse first_resp;
74   CreateEnterPageResponse create_enter_resp;
75   gboolean enter_create_forward;
76   TpAccountManager *account_mgr;
77   EmpathyConnectionManagers *connection_mgrs;
78   gint current_page_id;
79
80   /* enter or create page */
81   GtkWidget *enter_or_create_page;
82   GtkWidget *current_account_widget;
83   EmpathyAccountWidget *current_widget_object;
84   GtkWidget *first_label;
85   GtkWidget *second_label;
86   GtkWidget *chooser;
87   GtkWidget *create_again_radio;
88   EmpathyAccountSettings *settings;
89   gboolean is_creating;
90
91   /* import page */
92   EmpathyImportWidget *iw;
93   GtkWidget *import_page;
94
95   /* salut page */
96   GtkWidget *salut_page;
97   EmpathyAccountSettings *salut_settings;
98   GtkWidget *salut_account_widget;
99   gboolean create_salut_account;
100   gboolean display_salut_page;
101
102   GtkWindow *parent_window;
103
104   gboolean dispose_run;
105 } EmpathyAccountAssistantPriv;
106
107 static GtkWidget * account_assistant_build_enter_or_create_page (
108     EmpathyAccountAssistant *self);
109 static void account_assistant_finish_enter_or_create_page (
110     EmpathyAccountAssistant *self,
111     gboolean is_enter);
112
113 static void do_constructed (GObject *object);
114
115 static GtkWidget *
116 build_error_vbox (const gchar *primary_message,
117     const gchar *secondary_message)
118 {
119   GtkWidget *main_vbox, *w, *hbox;
120   PangoAttrList *list;
121
122   main_vbox = gtk_vbox_new (FALSE, 12);
123   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
124   gtk_widget_show (main_vbox);
125
126   hbox = gtk_hbox_new (FALSE, 12);
127   gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
128   gtk_widget_show (hbox);
129
130   w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
131       GTK_ICON_SIZE_DIALOG);
132   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
133   gtk_widget_show (w);
134
135   w = gtk_label_new (primary_message);
136   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
137   list = pango_attr_list_new ();
138   pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_LARGE));
139   pango_attr_list_insert (list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
140   gtk_label_set_attributes (GTK_LABEL (w), list);
141   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
142   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
143   gtk_widget_show (w);
144
145   pango_attr_list_unref (list);
146
147   w = gtk_label_new (secondary_message);
148   gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
149   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
150   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
151   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
152   gtk_widget_show (w);
153
154   return main_vbox;
155 }
156
157 static GtkWidget *
158 account_assistant_build_error_page (EmpathyAccountAssistant *self,
159     GError *error, gint page_num)
160 {
161   GtkWidget *main_vbox, *w;
162   const char *primary_message;
163   gchar *secondary_message, *markup;
164   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
165
166   if (page_num == PAGE_IMPORT)
167     primary_message = _("There was an error while importing the accounts.");
168   else if (page_num >= PAGE_ENTER_CREATE &&
169       priv->first_resp == RESPONSE_ENTER_ACCOUNT)
170     primary_message = _("There was an error while parsing the account details.");
171   else if (page_num >= PAGE_ENTER_CREATE &&
172       priv->first_resp == RESPONSE_CREATE_ACCOUNT)
173     primary_message = _("There was an error while creating the account.");
174   else
175     primary_message = _("There was an error.");
176
177   markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>",
178       error->message);
179   secondary_message = g_strdup_printf (_("The error message was: %s"), markup);
180
181   main_vbox = build_error_vbox (primary_message, secondary_message);
182
183   w = gtk_label_new (_("You can either go back and try to enter your "
184           "accounts' details again or quit this assistant and add accounts "
185           "later from the Edit menu."));
186   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
187   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
188   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
189   gtk_widget_show (w);
190
191   g_free (markup);
192   g_free (secondary_message);
193   return main_vbox;
194 }
195
196 static void
197 account_assistant_back_button_clicked_cb (GtkButton *button,
198     EmpathyAccountAssistant *self)
199 {
200   gint page_num;
201
202   page_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
203           "page-num"));
204   gtk_assistant_remove_action_widget (GTK_ASSISTANT (self),
205       GTK_WIDGET (button));
206   gtk_assistant_set_current_page (GTK_ASSISTANT (self), page_num);
207 }
208
209 static void
210 account_assistant_present_error_page (EmpathyAccountAssistant *self,
211     GError *error, gint page_num)
212 {
213   GtkWidget *error_page, *back_button;
214   gint num;
215
216   error_page = account_assistant_build_error_page (self, error,
217       page_num);
218   num = gtk_assistant_append_page (GTK_ASSISTANT (self), error_page);
219   gtk_assistant_set_page_title (GTK_ASSISTANT (self), error_page,
220       _("An error occurred"));
221   gtk_assistant_set_page_type (GTK_ASSISTANT (self), error_page,
222       GTK_ASSISTANT_PAGE_SUMMARY);
223
224   back_button = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
225   gtk_assistant_add_action_widget (GTK_ASSISTANT (self), back_button);
226   g_object_set_data (G_OBJECT (back_button),
227       "page-num", GINT_TO_POINTER (page_num));
228   g_signal_connect (back_button, "clicked",
229       G_CALLBACK (account_assistant_back_button_clicked_cb), self);
230   gtk_widget_show (back_button);
231
232   gtk_assistant_set_current_page (GTK_ASSISTANT (self), num);
233 }
234
235 static void
236 update_create_page_buttons (EmpathyAccountAssistant *self)
237 {
238   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
239   GtkAssistantPageType type;
240
241   if (priv->display_salut_page ||
242       priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
243     type = GTK_ASSISTANT_PAGE_CONTENT;
244   else
245     type = GTK_ASSISTANT_PAGE_CONFIRM;
246
247   gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->enter_or_create_page,
248       type);
249 }
250
251 static void
252 account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
253 {
254   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
255   GtkWidget *page;
256   gint idx;
257
258   page = account_assistant_build_enter_or_create_page (self);
259   idx = gtk_assistant_append_page (GTK_ASSISTANT (self), page);
260   priv->enter_or_create_page = page;
261   update_create_page_buttons (self);
262
263   gtk_assistant_set_current_page (GTK_ASSISTANT (self), idx);
264
265   account_assistant_finish_enter_or_create_page (self,
266       priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
267       TRUE : FALSE);
268 }
269
270 static void
271 account_assistant_account_enabled_cb (GObject *source,
272     GAsyncResult *result,
273     gpointer user_data)
274 {
275   GError *error = NULL;
276   EmpathyAccountAssistant *self = user_data;
277   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
278   const gchar *protocol;
279   TpAccount *account = TP_ACCOUNT (source);
280   gint current_idx;
281   gboolean salut_created = FALSE;
282
283   tp_account_set_enabled_finish (account, result, &error);
284
285   if (error)
286     {
287       g_warning ("Error enabling an account: %s", error->message);
288       g_error_free (error);
289     }
290
291   protocol = tp_account_get_protocol (account);
292   if (!tp_strdiff (protocol, "local-xmpp"))
293     {
294       DEBUG ("Salut account has been created; update gconf key");
295
296       empathy_conf_set_bool (empathy_conf_get (),
297           EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
298           TRUE);
299
300       salut_created = TRUE;
301     }
302
303   empathy_connect_new_account (account, priv->account_mgr);
304
305   current_idx = gtk_assistant_get_current_page (GTK_ASSISTANT (self));
306   if (current_idx == PAGE_SALUT && !salut_created)
307     /* We are on the Salut page and aren't creating the salut account so don't
308      * terminate the assistant. */
309     return;
310
311   if (priv->create_enter_resp == RESPONSE_CREATE_STOP)
312     g_signal_emit_by_name (self, "close");
313   else
314     account_assistant_reset_enter_create_page (self);
315 }
316
317 static void
318 account_assistant_apply_account_cb (GObject *source,
319     GAsyncResult *result,
320     gpointer user_data)
321 {
322   GError *error = NULL;
323   EmpathyAccountAssistant *self = user_data;
324   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
325   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
326   TpAccount *account;
327
328   empathy_account_settings_apply_finish (settings, result, &error);
329
330   priv->is_creating = FALSE;
331
332   if (error != NULL)
333     {
334       account_assistant_present_error_page (self, error,
335           gtk_assistant_get_current_page (GTK_ASSISTANT (self)));
336       g_error_free (error);
337       return;
338     }
339
340   /* enable the newly created account */
341   account = empathy_account_settings_get_account (settings);
342   tp_account_set_enabled_async (account, TRUE,
343       account_assistant_account_enabled_cb, self);
344 }
345
346 static void
347 account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self,
348     EmpathyAccountSettings *settings)
349 {
350   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
351   gchar *display_name;
352
353   if (settings == NULL)
354     return;
355
356   priv->is_creating = TRUE;
357
358   /* set default display name */
359   display_name = empathy_account_widget_get_default_display_name (
360       priv->current_widget_object);
361
362   empathy_account_settings_set_display_name_async (settings,
363       display_name, NULL, NULL);
364
365   g_free (display_name);
366
367   empathy_account_settings_apply_async (settings,
368       account_assistant_apply_account_cb, self);
369 }
370
371 static void
372 account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object,
373     gboolean is_valid,
374     EmpathyAccountAssistant *self)
375 {
376   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
377
378   gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
379       priv->enter_or_create_page, is_valid);
380 }
381
382 static void
383 account_assistant_protocol_changed_cb (GtkComboBox *chooser,
384     EmpathyAccountAssistant *self)
385 {
386   TpConnectionManager *cm;
387   TpConnectionManagerProtocol *proto;
388   EmpathyAccountSettings *settings;
389   EmpathyAccountAssistantPriv *priv;
390   char *str;
391   GtkWidget *account_widget;
392   EmpathyAccountWidget *widget_object = NULL;
393   gboolean is_gtalk, is_facebook;
394   const gchar *name;
395
396   priv = GET_PRIV (self);
397
398   cm = empathy_protocol_chooser_dup_selected (
399       EMPATHY_PROTOCOL_CHOOSER (chooser), &proto, &is_gtalk, &is_facebook);
400
401   if (cm == NULL || proto == NULL)
402     /* we are not ready yet */
403     return;
404
405   /* Create account */
406   if (is_gtalk)
407     name = "gtalk";
408   else if (is_facebook)
409     name = "facebook";
410   else
411     name = proto->name;
412
413   /* To translator: %s is the protocol name */
414   str = g_strdup_printf (_("New %s account"),
415       empathy_protocol_name_to_display_name (name));
416
417   settings = empathy_account_settings_new (cm->name, proto->name, str);
418
419   if (is_gtalk)
420     empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
421       NULL, NULL);
422   else if (is_facebook)
423     empathy_account_settings_set_icon_name_async (settings, "im-facebook",
424       NULL, NULL);
425
426   if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
427     empathy_account_settings_set_boolean (settings, "register", TRUE);
428
429   widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
430   account_widget = empathy_account_widget_get_widget (widget_object);
431
432   if (priv->current_account_widget != NULL)
433     {
434       g_signal_handlers_disconnect_by_func (priv->current_widget_object,
435           account_assistant_handle_apply_cb, self);
436       gtk_widget_destroy (priv->current_account_widget);
437     }
438
439   priv->current_account_widget = account_widget;
440   priv->current_widget_object = widget_object;
441
442   if (priv->settings != NULL)
443     g_object_unref (priv->settings);
444
445   priv->settings = settings;
446
447   g_signal_connect (priv->current_widget_object, "handle-apply",
448       G_CALLBACK (account_assistant_handle_apply_cb), self);
449
450   if (empathy_account_settings_is_valid (settings))
451     {
452       gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
453           priv->enter_or_create_page, TRUE);
454     }
455
456   gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
457       FALSE, FALSE, 0);
458   gtk_widget_show (account_widget);
459
460   g_free (str);
461 }
462
463 static gboolean
464 account_assistant_chooser_enter_details_filter_func (
465     TpConnectionManager *cm,
466     TpConnectionManagerProtocol *protocol,
467     gboolean is_gtalk,
468     gboolean is_facebook,
469     gpointer user_data)
470 {
471   if (!tp_strdiff (protocol->name, "local-xmpp") ||
472       !tp_strdiff (protocol->name, "irc"))
473     return FALSE;
474
475   return TRUE;
476 }
477
478 static gboolean
479 account_assistant_chooser_create_account_filter_func (
480     TpConnectionManager *cm,
481     TpConnectionManagerProtocol *protocol,
482     gboolean is_gtalk,
483     gboolean is_facebook,
484     gpointer user_data)
485 {
486   if (is_gtalk || is_facebook)
487     return FALSE;
488
489   return tp_connection_manager_protocol_can_register (protocol);
490 }
491
492 static void
493 account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self,
494     gboolean is_enter)
495 {
496   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
497
498   if (is_enter)
499     {
500       gtk_label_set_label (GTK_LABEL (priv->first_label),
501           _("What kind of chat account do you have?"));
502       /*      gtk_label_set_label (GTK_LABEL (priv->second_label),
503           _("If you have other accounts to set up, you can do "
504               "that at any time from the Edit menu."));
505       */
506       gtk_label_set_label (GTK_LABEL (priv->second_label),
507           _("Do you have any other chat accounts you want to set up?"));
508       empathy_protocol_chooser_set_visible (
509           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
510           account_assistant_chooser_enter_details_filter_func, self);
511
512       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
513           priv->enter_or_create_page, _("Enter your account details"));
514     }
515   else
516     {
517       gtk_label_set_label (GTK_LABEL (priv->first_label),
518           _("What kind of chat account do you want to create?"));
519       /*      gtk_label_set_label (GTK_LABEL (priv->second_label),
520           _("You can register other accounts, or setup "
521               "an existing one at any time from the Edit menu."));
522       */
523       gtk_label_set_label (GTK_LABEL (priv->second_label),
524           _("Do you want to create other chat accounts?"));
525       empathy_protocol_chooser_set_visible (
526           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
527           account_assistant_chooser_create_account_filter_func, self);
528
529       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
530           priv->enter_or_create_page,
531           _("Enter the details for the new account"));
532     }
533
534   g_signal_connect (priv->chooser, "changed",
535       G_CALLBACK (account_assistant_protocol_changed_cb), self);
536
537   /* trigger show the first account widget */
538   account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self);
539 }
540
541 static gint
542 account_assistant_page_forward_func (gint current_page,
543     gpointer user_data)
544 {
545   EmpathyAccountAssistant *self = user_data;
546   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
547   gint retval;
548
549   retval = current_page;
550
551   if (current_page == PAGE_INTRO)
552     {
553       if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
554           priv->first_resp == RESPONSE_CREATE_ACCOUNT)
555         retval = PAGE_ENTER_CREATE;
556       else if (priv->first_resp == RESPONSE_IMPORT)
557         retval = PAGE_IMPORT;
558       else if (priv->first_resp == RESPONSE_SALUT_ONLY)
559         retval = PAGE_SALUT;
560     }
561   else if (current_page == PAGE_IMPORT)
562     {
563       if (priv->display_salut_page)
564         retval = PAGE_SALUT;
565       else
566         /* Don't go forward */
567         retval = -1;
568     }
569   else if (current_page == PAGE_SALUT)
570     {
571       /* Don't go forward */
572       retval = -1;
573     }
574   else if (current_page >= PAGE_ENTER_CREATE)
575     {
576       if (priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
577         {
578           priv->enter_create_forward = TRUE;
579           retval = current_page;
580         }
581       else if (priv->display_salut_page)
582         {
583           retval = PAGE_SALUT;
584         }
585       else
586         {
587           /* Don't go forward */
588           retval = -1;
589         }
590     }
591
592   return retval;
593 }
594
595 static void
596 update_intro_page_buttons (EmpathyAccountAssistant *self)
597 {
598   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
599   GtkWidget *intro_page;
600
601   intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self),
602       PAGE_INTRO);
603
604   if (priv->first_resp == RESPONSE_SALUT_ONLY &&
605       !priv->display_salut_page)
606     gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
607         GTK_ASSISTANT_PAGE_SUMMARY);
608   else
609     gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
610         GTK_ASSISTANT_PAGE_INTRO);
611 }
612
613 static void
614 account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
615     EmpathyAccountAssistant *self)
616 {
617   FirstPageResponse response;
618   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
619
620   response = GPOINTER_TO_INT (g_object_get_data
621       (G_OBJECT (button), "response"));
622
623   priv->first_resp = response;
624
625   update_intro_page_buttons (self);
626 }
627
628 static GtkWidget *
629 account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
630 {
631   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
632   GtkWidget *main_vbox, *hbox_1, *w, *vbox_1;
633   GtkWidget *radio = NULL;
634   GdkPixbuf *pix;
635   const gchar *str;
636
637   main_vbox = gtk_vbox_new (FALSE, 12);
638   gtk_widget_show (main_vbox);
639   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
640
641   hbox_1 = gtk_hbox_new (FALSE, 12);
642   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
643   gtk_widget_show (hbox_1);
644
645   w = gtk_label_new (
646       _("With Empathy you can chat with people "
647         "online nearby and with friends and colleagues "
648         "who use Google Talk, AIM, Windows Live "
649         "and many other chat programs. With a microphone "
650         "or a webcam you can also have audio or video calls."));
651   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
652   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
653   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
654   gtk_widget_show (w);
655
656   pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80);
657   w = gtk_image_new_from_pixbuf (pix);
658   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
659   gtk_widget_show (w);
660
661   g_object_unref (pix);
662
663   w = gtk_label_new (_("Do you have an account you've been using "
664           "with another chat program?"));
665   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
666   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
667   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
668   gtk_widget_show (w);
669
670   w = gtk_alignment_new (0, 0, 0, 0);
671   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
672   gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
673   gtk_widget_show (w);
674
675   vbox_1 = gtk_vbox_new (TRUE, 0);
676   gtk_container_add (GTK_CONTAINER (w), vbox_1);
677   gtk_widget_show (vbox_1);
678
679   if (empathy_import_accounts_to_import ())
680     {
681       hbox_1 = gtk_hbox_new (FALSE, 0);
682       gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0);
683       gtk_widget_show (hbox_1);
684
685       radio = gtk_radio_button_new_with_label (NULL,
686           _("Yes, import my account details from "));
687       gtk_box_pack_start (GTK_BOX (hbox_1), radio, TRUE, TRUE, 0);
688       g_object_set_data (G_OBJECT (radio), "response",
689           GINT_TO_POINTER (RESPONSE_IMPORT));
690       gtk_widget_show (radio);
691
692       w = gtk_combo_box_new_text ();
693       gtk_combo_box_append_text (GTK_COMBO_BOX (w), "Pidgin");
694       gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
695       gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0);
696       gtk_widget_show (w);
697
698       g_signal_connect (radio, "clicked",
699           G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
700       priv->first_resp = RESPONSE_IMPORT;
701     }
702   else
703     {
704       priv->first_resp = RESPONSE_ENTER_ACCOUNT;
705     }
706
707   str = _("Yes, I'll enter my account details now");
708
709   if (radio == NULL)
710     {
711       radio = gtk_radio_button_new_with_label (NULL, str);
712       w = radio;
713     }
714   else
715     {
716       w = gtk_radio_button_new_with_label_from_widget (
717           GTK_RADIO_BUTTON (radio), str);
718     }
719
720   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
721   g_object_set_data (G_OBJECT (w), "response",
722       GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
723   gtk_widget_show (w);
724
725   g_signal_connect (w, "clicked",
726       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
727
728   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
729       _("No, I want a new account"));
730   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
731   g_object_set_data (G_OBJECT (w), "response",
732       GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
733   gtk_widget_show (w);
734
735   g_signal_connect (w, "clicked",
736       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
737
738   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
739       _("No, I just want to see people online nearby for now"));
740   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
741   g_object_set_data (G_OBJECT (w), "response",
742       GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
743   gtk_widget_show (w);
744
745   g_signal_connect (w, "clicked",
746       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
747
748   return main_vbox;
749 }
750
751 static GtkWidget *
752 account_assistant_build_import_page (EmpathyAccountAssistant *self)
753 {
754   GtkWidget *main_vbox, *w, *import;
755   EmpathyImportWidget *iw;
756   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
757
758   main_vbox = gtk_vbox_new (FALSE, 12);
759   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
760   w = gtk_label_new (_("Select the accounts you want to import:"));
761   gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
762   gtk_widget_show (w);
763   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
764
765   w = gtk_alignment_new (0, 0, 0, 0);
766   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
767   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
768   gtk_widget_show (w);
769
770   /* NOTE: this is hardcoded as we support pidgin only */
771   iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN);
772   import = empathy_import_widget_get_widget (iw);
773   gtk_container_add (GTK_CONTAINER (w), import);
774   gtk_widget_show (import);
775
776   priv->iw = iw;
777
778   gtk_widget_show (main_vbox);
779
780   return main_vbox;
781 }
782
783 static void
784 account_assistant_radio_create_again_clicked_cb (GtkButton *button,
785     EmpathyAccountAssistant *self)
786 {
787   CreateEnterPageResponse response;
788   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
789
790   response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
791           "response"));
792
793   priv->create_enter_resp = response;
794
795   update_create_page_buttons (self);
796 }
797
798 static GtkWidget *
799 account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self)
800 {
801   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
802   GtkWidget *main_vbox, *w, *chooser, *vbox, *hbox, *radio;
803
804   main_vbox = gtk_vbox_new (FALSE, 12);
805   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
806   gtk_widget_show (main_vbox);
807
808   w = gtk_label_new (NULL);
809   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
810   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
811   gtk_widget_show (w);
812   priv->first_label = w;
813
814   w = gtk_alignment_new (0, 0, 0, 0);
815   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
816   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
817   gtk_widget_show (w);
818
819   chooser = empathy_protocol_chooser_new ();
820   gtk_container_add (GTK_CONTAINER (w), chooser);
821   gtk_widget_show (chooser);
822   priv->chooser = chooser;
823
824   vbox = gtk_vbox_new (FALSE, 6);
825   gtk_box_pack_end (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
826   gtk_widget_show (vbox);
827
828   w = gtk_label_new (NULL);
829   gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
830   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
831   gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
832   gtk_widget_show (w);
833   priv->second_label = w;
834
835   w = gtk_alignment_new (0, 0, 0, 0);
836   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
837   gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
838   gtk_widget_show (w);
839
840   hbox = gtk_hbox_new (FALSE, 6);
841   gtk_container_add (GTK_CONTAINER (w), hbox);
842   gtk_widget_show (hbox);
843
844   radio = gtk_radio_button_new_with_label (NULL, _("Yes"));
845   gtk_box_pack_start (GTK_BOX (hbox), radio, FALSE, FALSE, 0);
846   g_object_set_data (G_OBJECT (radio), "response",
847       GINT_TO_POINTER (RESPONSE_CREATE_AGAIN));
848   gtk_widget_show (radio);
849
850   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
851       _("No, that's all for now"));
852   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
853   g_object_set_data (G_OBJECT (w), "response",
854       GINT_TO_POINTER (RESPONSE_CREATE_STOP));
855   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
856   priv->create_enter_resp = RESPONSE_CREATE_STOP;
857   priv->create_again_radio = w;
858   gtk_widget_show (w);
859
860   g_signal_connect (w, "clicked",
861       G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
862   g_signal_connect (radio, "clicked",
863       G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
864
865   return main_vbox;
866 }
867
868 static void
869 account_assistant_close_cb (GtkAssistant *assistant,
870     gpointer user_data)
871 {
872   EmpathyAccountAssistantPriv *priv = GET_PRIV (assistant);
873
874   if (priv->is_creating)
875     return;
876
877   gtk_widget_destroy (GTK_WIDGET (assistant));
878 }
879
880 static void
881 impl_signal_apply (GtkAssistant *assistant)
882 {
883   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
884   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
885   gint current_page;
886
887   current_page = gtk_assistant_get_current_page (assistant);
888
889   if (current_page == PAGE_SALUT)
890     {
891       if (priv->create_salut_account)
892         account_assistant_apply_account_and_finish (self, priv->salut_settings);
893       return;
894     }
895   else if (current_page == PAGE_ENTER_CREATE &&
896       priv->settings != NULL &&
897       empathy_account_settings_is_valid (priv->settings))
898     {
899       account_assistant_apply_account_and_finish (self, priv->settings);
900     }
901 }
902
903 static void
904 impl_signal_cancel (GtkAssistant *assistant)
905 {
906   gtk_widget_destroy (GTK_WIDGET (assistant));
907 }
908
909 static void
910 impl_signal_prepare (GtkAssistant *assistant,
911     GtkWidget *current_page)
912 {
913   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
914   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
915   gint current_idx;
916
917   /* check from which page we are coming from */
918   switch (priv->current_page_id)
919     {
920       case PAGE_IMPORT:
921         empathy_import_widget_add_selected_accounts (priv->iw);
922         break;
923     }
924
925   current_idx = gtk_assistant_get_current_page (assistant);
926   priv->current_page_id = current_idx;
927
928   if (current_idx >= PAGE_ENTER_CREATE)
929     {
930       if (!priv->enter_create_forward && current_idx != PAGE_SALUT)
931         {
932           account_assistant_finish_enter_or_create_page (self,
933               priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
934               TRUE : FALSE);
935         }
936       else
937         {
938           priv->enter_create_forward = FALSE;
939         }
940
941       if (priv->settings != NULL &&
942           empathy_account_settings_is_valid (priv->settings))
943         {
944           account_assistant_apply_account_and_finish (self, priv->settings);
945           g_object_unref (priv->settings);
946           priv->settings = NULL;
947         }
948     }
949 }
950
951 static void
952 do_get_property (GObject *object,
953     guint property_id,
954     GValue *value,
955     GParamSpec *pspec)
956 {
957   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
958
959   switch (property_id)
960     {
961     case PROP_PARENT:
962       g_value_set_object (value, priv->parent_window);
963       break;
964     case PROP_CONNECTION_MGRS:
965       g_value_set_object (value, priv->connection_mgrs);
966       break;
967     default:
968       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
969     }
970 }
971
972 static void
973 do_set_property (GObject *object,
974     guint property_id,
975     const GValue *value,
976     GParamSpec *pspec)
977 {
978   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
979
980   switch (property_id)
981     {
982     case PROP_PARENT:
983       priv->parent_window = g_value_get_object (value);
984       break;
985     case PROP_CONNECTION_MGRS:
986       priv->connection_mgrs = g_value_dup_object (value);
987       break;
988     default:
989       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
990     }
991 }
992
993 static void
994 do_dispose (GObject *obj)
995 {
996   EmpathyAccountAssistantPriv *priv = GET_PRIV (obj);
997
998   if (priv->dispose_run)
999     return;
1000
1001   priv->dispose_run = TRUE;
1002
1003   if (priv->settings != NULL)
1004     {
1005       g_object_unref (priv->settings);
1006       priv->settings = NULL;
1007     }
1008
1009   g_object_unref (priv->account_mgr);
1010   priv->account_mgr = NULL;
1011
1012   g_object_unref (priv->connection_mgrs);
1013   priv->connection_mgrs = NULL;
1014
1015   if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL)
1016     G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj);
1017 }
1018
1019 static void
1020 empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
1021 {
1022   GObjectClass *oclass = G_OBJECT_CLASS (klass);
1023   GtkAssistantClass *gtkclass = GTK_ASSISTANT_CLASS (klass);
1024   GParamSpec *param_spec;
1025
1026   oclass->get_property = do_get_property;
1027   oclass->set_property = do_set_property;
1028   oclass->constructed = do_constructed;
1029   oclass->dispose = do_dispose;
1030
1031   gtkclass->apply = impl_signal_apply;
1032   gtkclass->prepare = impl_signal_prepare;
1033   gtkclass->cancel = impl_signal_cancel;
1034
1035   param_spec = g_param_spec_object ("parent-window",
1036       "parent-window", "The parent window",
1037       GTK_TYPE_WINDOW,
1038       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1039   g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1040
1041   param_spec = g_param_spec_object ("connection-managers",
1042       "connection-managers", "A EmpathyConnectionManagers",
1043       EMPATHY_TYPE_CONNECTION_MANAGERS,
1044       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1045   g_object_class_install_property (oclass, PROP_CONNECTION_MGRS, param_spec);
1046
1047   g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
1048 }
1049
1050 static void
1051 create_salut_check_box_toggled_cb (GtkWidget *widget,
1052     EmpathyAccountAssistant *self)
1053 {
1054   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1055   gboolean sensitive;
1056   gboolean page_valid;
1057
1058   sensitive = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
1059
1060   gtk_widget_set_sensitive (priv->salut_account_widget, sensitive);
1061
1062   if (!sensitive)
1063     {
1064       page_valid = TRUE;
1065       priv->create_salut_account = FALSE;
1066     }
1067   else
1068     {
1069       /* page is complete if the account is valid */
1070       page_valid = empathy_account_settings_is_valid (priv->salut_settings);
1071       priv->create_salut_account = TRUE;
1072     }
1073
1074   gtk_assistant_set_page_complete (GTK_ASSISTANT (self), priv->salut_page,
1075       page_valid);
1076 }
1077
1078 static void
1079 account_assistant_salut_handle_apply_cb (EmpathyAccountWidget *widget_object,
1080     gboolean is_valid,
1081     EmpathyAccountAssistant *self)
1082 {
1083   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1084
1085   gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
1086       priv->salut_page, is_valid);
1087 }
1088
1089 static GtkWidget *
1090 account_assistant_build_salut_page (EmpathyAccountAssistant *self)
1091 {
1092   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1093   GtkWidget *main_vbox, *hbox_1, *w;
1094   GdkPixbuf *pix;
1095   EmpathyAccountSettings *settings;
1096   GtkWidget *account_widget;
1097   EmpathyAccountWidget *widget_object;
1098   gchar *markup;
1099
1100   main_vbox = gtk_vbox_new (FALSE, 12);
1101   gtk_widget_show (main_vbox);
1102   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
1103
1104   hbox_1 = gtk_hbox_new (FALSE, 12);
1105   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
1106   gtk_widget_show (hbox_1);
1107
1108   w = gtk_label_new ("");
1109   markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1110       _("Empathy can automatically discover and chat with the people "
1111         "connected on the same network as you. "
1112         "If you want to use this feature, please check that the "
1113         "details below are correct. "
1114         "You can easily change these details later or disable this feature "
1115         "by using the 'Accounts' dialog"),
1116       _("Edit->Accounts"));
1117   gtk_label_set_markup (GTK_LABEL (w), markup);
1118   g_free (markup);
1119   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1120   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
1121   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
1122   gtk_widget_show (w);
1123
1124   pix = empathy_pixbuf_from_icon_name_sized ("im-local-xmpp", 80);
1125   w = gtk_image_new_from_pixbuf (pix);
1126   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
1127   gtk_widget_show (w);
1128
1129   g_object_unref (pix);
1130
1131   w = gtk_check_button_new_with_label (
1132       _("I don't want to enable this feature for now"));
1133   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
1134   g_signal_connect (w, "toggled",
1135       G_CALLBACK (create_salut_check_box_toggled_cb), self);
1136   gtk_widget_show (w);
1137
1138   w = gtk_alignment_new (0, 0, 0, 0);
1139   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
1140   gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
1141   gtk_widget_show (w);
1142
1143   settings = create_salut_account_settings ();
1144
1145   widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
1146   account_widget = empathy_account_widget_get_widget (widget_object);
1147
1148   priv->salut_settings = settings;
1149   priv->salut_account_widget = account_widget;
1150
1151   g_signal_connect (widget_object, "handle-apply",
1152       G_CALLBACK (account_assistant_salut_handle_apply_cb), self);
1153
1154   gtk_box_pack_start (GTK_BOX (main_vbox), account_widget,
1155       FALSE, FALSE, 0);
1156   gtk_widget_show (account_widget);
1157
1158   return main_vbox;
1159 }
1160
1161 static GtkWidget *
1162 account_assistant_build_salut_error_page (EmpathyAccountAssistant *self)
1163 {
1164   GtkWidget *vbox;
1165   gchar *markup;
1166
1167   markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1168       _("You won't be able to chat with people connected to your local "
1169         "network, as telepathy-salut is not installed. If you want to enable "
1170         "this feature, please install the telepathy-salut package and create "
1171         "a People Nearby account from the Accounts dialog"),
1172         _("Edit->Accounts"));
1173
1174   vbox = build_error_vbox (_("telepathy-salut not installed"), markup);
1175   g_free (markup);
1176   return vbox;
1177 }
1178
1179 static void
1180 account_mgr_prepare_cb (GObject *source_object,
1181     GAsyncResult *result,
1182     gpointer user_data)
1183 {
1184   EmpathyAccountAssistant *self = user_data;
1185   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1186   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1187   GError *error = NULL;
1188
1189   if (!tp_account_manager_prepare_finish (manager, result, &error))
1190     {
1191       DEBUG ("Failed to prepare account manager: %s", error->message);
1192       g_error_free (error);
1193       return;
1194     }
1195
1196   if (!should_create_salut_account (manager))
1197     {
1198       DEBUG ("No need to create a Salut account");
1199       priv->display_salut_page = FALSE;
1200
1201       update_intro_page_buttons (self);
1202
1203       gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->import_page,
1204           GTK_ASSISTANT_PAGE_CONFIRM);
1205
1206       update_create_page_buttons (self);
1207     }
1208 }
1209
1210 static void
1211 empathy_account_assistant_init (EmpathyAccountAssistant *self)
1212 {
1213   EmpathyAccountAssistantPriv *priv;
1214
1215   priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
1216       EmpathyAccountAssistantPriv);
1217   self->priv = priv;
1218
1219   priv->account_mgr = tp_account_manager_dup ();
1220 }
1221
1222 static void
1223 do_constructed (GObject *object)
1224 {
1225   GtkAssistant *assistant = GTK_ASSISTANT (object);
1226   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (object);
1227   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
1228   GtkWidget *page;
1229
1230   /* set us as transient for the parent window if any */
1231   if (priv->parent_window)
1232     gtk_window_set_transient_for (GTK_WINDOW (object),
1233         priv->parent_window);
1234
1235   /* set the dialog hint, so this will be centered over the parent window */
1236   gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
1237
1238   g_assert (priv->connection_mgrs != NULL);
1239   g_assert (empathy_connection_managers_is_ready (priv->connection_mgrs));
1240
1241   g_signal_connect (self, "close",
1242       G_CALLBACK (account_assistant_close_cb), NULL);
1243
1244   gtk_assistant_set_forward_page_func (assistant,
1245       account_assistant_page_forward_func, self, NULL);
1246
1247   /* first page (introduction) */
1248   page = account_assistant_build_introduction_page (self);
1249   gtk_assistant_append_page (assistant, page);
1250   gtk_assistant_set_page_title (assistant, page,
1251       _("Welcome to Empathy"));
1252   gtk_assistant_set_page_type (assistant, page,
1253       GTK_ASSISTANT_PAGE_INTRO);
1254   gtk_assistant_set_page_complete (assistant, page, TRUE);
1255
1256   /* second page (import accounts) */
1257   page = account_assistant_build_import_page (self);
1258   gtk_assistant_append_page (assistant, page);
1259   gtk_assistant_set_page_title (assistant, page,
1260       _("Import your existing accounts"));
1261   gtk_assistant_set_page_complete (assistant, page, TRUE);
1262   gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1263   priv->import_page = page;
1264
1265   /* third page (enter account details) */
1266   page = account_assistant_build_enter_or_create_page (self);
1267   gtk_assistant_append_page (assistant, page);
1268   gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1269   priv->enter_or_create_page = page;
1270
1271   /* fourth page (salut details) */
1272   if (empathy_connection_managers_get_cm (priv->connection_mgrs, "salut")
1273       != NULL)
1274     {
1275       page = account_assistant_build_salut_page (self);
1276       gtk_assistant_append_page (assistant, page);
1277       gtk_assistant_set_page_title (assistant, page,
1278           _("Please enter personal details"));
1279       gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
1280
1281       priv->create_salut_account = TRUE;
1282
1283       if (empathy_account_settings_is_valid (priv->salut_settings))
1284         {
1285           gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
1286               page, TRUE);
1287         }
1288     }
1289   else
1290     {
1291       page = account_assistant_build_salut_error_page (self);
1292       gtk_assistant_append_page (assistant, page);
1293       gtk_assistant_set_page_title (assistant, page, _("An error occurred"));
1294       gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_SUMMARY);
1295
1296       priv->create_salut_account = FALSE;
1297     }
1298
1299   priv->salut_page = page;
1300   priv->display_salut_page = TRUE;
1301
1302   tp_account_manager_prepare_async (priv->account_mgr, NULL,
1303       account_mgr_prepare_cb, self);
1304
1305   gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
1306 }
1307
1308 GtkWidget *
1309 empathy_account_assistant_show (GtkWindow *window,
1310     EmpathyConnectionManagers *connection_mgrs)
1311 {
1312   static GtkWidget *dialog = NULL;
1313
1314   if (dialog == NULL)
1315     {
1316       dialog =  g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT,
1317           "parent-window", window,
1318           "connection-managers", connection_mgrs,
1319           NULL);
1320       g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &dialog);
1321     }
1322
1323   gtk_window_present (GTK_WINDOW (dialog));
1324
1325   return dialog;
1326 }
1327
1328