]> git.0d.be Git - empathy.git/blob - src/empathy-account-assistant.c
Update simplified Chinese 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 <config.h>
24 #include <glib/gi18n-lib.h>
25 #include <telepathy-glib/util.h>
26 #include <gdk/gdkkeysyms.h>
27
28 #include "empathy-account-assistant.h"
29 #include "empathy-import-widget.h"
30 #include "empathy-import-utils.h"
31 #include "empathy-auto-salut-account-helper.h"
32
33 #include <libempathy/empathy-account-settings.h>
34 #include <libempathy/empathy-utils.h>
35
36 #include <libempathy-gtk/empathy-account-widget.h>
37 #include <libempathy-gtk/empathy-protocol-chooser.h>
38 #include <libempathy-gtk/empathy-ui-utils.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 typedef enum {
61   PAGE_INTRO = 0,
62   PAGE_IMPORT = 1,
63   PAGE_ENTER_CREATE = 2,
64   PAGE_SALUT = 3,
65 } PageID;
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   PageID 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       salut_created = TRUE;
295     }
296
297   empathy_connect_new_account (account, priv->account_mgr);
298
299   current_idx = gtk_assistant_get_current_page (GTK_ASSISTANT (self));
300   if (current_idx == PAGE_SALUT && !salut_created)
301     /* We are on the Salut page and aren't creating the salut account so don't
302      * terminate the assistant. */
303     return;
304
305   if (priv->create_enter_resp == RESPONSE_CREATE_STOP)
306     g_signal_emit_by_name (self, "close");
307   else
308     account_assistant_reset_enter_create_page (self);
309 }
310
311 static void
312 account_assistant_apply_account_cb (GObject *source,
313     GAsyncResult *result,
314     gpointer user_data)
315 {
316   GError *error = NULL;
317   EmpathyAccountAssistant *self = user_data;
318   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
319   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
320   TpAccount *account;
321
322   empathy_account_settings_apply_finish (settings, result, &error);
323
324   priv->is_creating = FALSE;
325
326   if (error != NULL)
327     {
328       account_assistant_present_error_page (self, error,
329           gtk_assistant_get_current_page (GTK_ASSISTANT (self)));
330       g_error_free (error);
331       return;
332     }
333
334   /* enable the newly created account */
335   account = empathy_account_settings_get_account (settings);
336   tp_account_set_enabled_async (account, TRUE,
337       account_assistant_account_enabled_cb, self);
338 }
339
340 static void
341 account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self,
342     EmpathyAccountSettings *settings,
343     gboolean set_display_name)
344 {
345   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
346
347   if (settings == NULL)
348     return;
349
350   priv->is_creating = TRUE;
351
352   if (set_display_name)
353     {
354       gchar *display_name;
355
356       display_name = empathy_account_widget_get_default_display_name (
357         priv->current_widget_object);
358
359       empathy_account_settings_set_display_name_async (settings,
360         display_name, NULL, NULL);
361
362       g_free (display_name);
363     }
364
365   empathy_account_settings_apply_async (settings,
366       account_assistant_apply_account_cb, self);
367 }
368
369 static void
370 account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object,
371     gboolean is_valid,
372     EmpathyAccountAssistant *self)
373 {
374   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
375
376   gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
377       priv->enter_or_create_page, is_valid);
378 }
379
380 static void
381 account_assistant_protocol_changed_cb (GtkComboBox *chooser,
382     EmpathyAccountAssistant *self)
383 {
384   TpConnectionManager *cm;
385   TpConnectionManagerProtocol *proto;
386   EmpathyAccountSettings *settings;
387   EmpathyAccountAssistantPriv *priv;
388   char *str;
389   GtkWidget *account_widget;
390   EmpathyAccountWidget *widget_object = NULL;
391   gboolean is_gtalk, is_facebook;
392   const gchar *name;
393
394   priv = GET_PRIV (self);
395
396   cm = empathy_protocol_chooser_dup_selected (
397       EMPATHY_PROTOCOL_CHOOSER (chooser), &proto, &is_gtalk, &is_facebook);
398
399   if (cm == NULL || proto == NULL)
400     /* we are not ready yet */
401     return;
402
403   /* Create account */
404   if (is_gtalk)
405     name = "gtalk";
406   else if (is_facebook)
407     name = "facebook";
408   else
409     name = proto->name;
410
411   /* To translator: %s is the protocol name */
412   str = g_strdup_printf (_("New %s account"),
413       empathy_protocol_name_to_display_name (name));
414
415   settings = empathy_account_settings_new (cm->name, proto->name, str);
416
417   if (is_gtalk)
418     {
419       gchar *fallback_servers[] = {
420           "talkx.l.google.com",
421           "talkx.l.google.com:443,oldssl",
422           "talkx.l.google.com:80",
423           NULL};
424
425       empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
426         NULL, NULL);
427
428       empathy_account_settings_set_string (settings, "server", NULL);
429       empathy_account_settings_set_strv (settings, "fallback-servers",
430           fallback_servers);
431     }
432   else if (is_facebook)
433     {
434       empathy_account_settings_set_icon_name_async (settings, "im-facebook",
435         NULL, NULL);
436
437       empathy_account_settings_set_string (settings, "server",
438           "chat.facebook.com");
439     }
440
441   if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
442     empathy_account_settings_set_boolean (settings, "register", TRUE);
443
444   widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
445   account_widget = empathy_account_widget_get_widget (widget_object);
446
447   if (priv->current_account_widget != NULL)
448     {
449       g_signal_handlers_disconnect_by_func (priv->current_widget_object,
450           account_assistant_handle_apply_cb, self);
451       gtk_widget_destroy (priv->current_account_widget);
452     }
453
454   priv->current_account_widget = account_widget;
455   priv->current_widget_object = widget_object;
456
457   if (priv->settings != NULL)
458     g_object_unref (priv->settings);
459
460   priv->settings = settings;
461
462   g_signal_connect (priv->current_widget_object, "handle-apply",
463       G_CALLBACK (account_assistant_handle_apply_cb), self);
464
465   if (empathy_account_settings_is_valid (settings))
466     {
467       gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
468           priv->enter_or_create_page, TRUE);
469     }
470
471   gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
472       FALSE, FALSE, 0);
473   gtk_widget_show (account_widget);
474
475   g_free (str);
476 }
477
478 static gboolean
479 account_assistant_chooser_enter_details_filter_func (
480     TpConnectionManager *cm,
481     TpConnectionManagerProtocol *protocol,
482     gboolean is_gtalk,
483     gboolean is_facebook,
484     gpointer user_data)
485 {
486   if (!tp_strdiff (protocol->name, "local-xmpp"))
487     return FALSE;
488
489   return TRUE;
490 }
491
492 static gboolean
493 account_assistant_chooser_create_account_filter_func (
494     TpConnectionManager *cm,
495     TpConnectionManagerProtocol *protocol,
496     gboolean is_gtalk,
497     gboolean is_facebook,
498     gpointer user_data)
499 {
500   if (is_gtalk || is_facebook)
501     return FALSE;
502
503   return tp_connection_manager_protocol_can_register (protocol);
504 }
505
506 static void
507 account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self,
508     gboolean is_enter)
509 {
510   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
511
512   if (is_enter)
513     {
514       gtk_label_set_label (GTK_LABEL (priv->first_label),
515           _("What kind of chat account do you have?"));
516       /*      gtk_label_set_label (GTK_LABEL (priv->second_label),
517           _("If you have other accounts to set up, you can do "
518               "that at any time from the Edit menu."));
519       */
520       gtk_label_set_label (GTK_LABEL (priv->second_label),
521           _("Do you have any other chat accounts you want to set up?"));
522       empathy_protocol_chooser_set_visible (
523           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
524           account_assistant_chooser_enter_details_filter_func, self);
525
526       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
527           priv->enter_or_create_page, _("Enter your account details"));
528     }
529   else
530     {
531       gtk_label_set_label (GTK_LABEL (priv->first_label),
532           _("What kind of chat account do you want to create?"));
533       /*      gtk_label_set_label (GTK_LABEL (priv->second_label),
534           _("You can register other accounts, or setup "
535               "an existing one at any time from the Edit menu."));
536       */
537       gtk_label_set_label (GTK_LABEL (priv->second_label),
538           _("Do you want to create other chat accounts?"));
539       empathy_protocol_chooser_set_visible (
540           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
541           account_assistant_chooser_create_account_filter_func, self);
542
543       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
544           priv->enter_or_create_page,
545           _("Enter the details for the new account"));
546     }
547
548   g_signal_connect (priv->chooser, "changed",
549       G_CALLBACK (account_assistant_protocol_changed_cb), self);
550
551   /* trigger show the first account widget */
552   account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self);
553 }
554
555 static gint
556 account_assistant_page_forward_func (gint current_page,
557     gpointer user_data)
558 {
559   EmpathyAccountAssistant *self = user_data;
560   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
561   gint retval;
562
563   retval = current_page;
564
565   if (current_page == PAGE_INTRO)
566     {
567       if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
568           priv->first_resp == RESPONSE_CREATE_ACCOUNT)
569         retval = PAGE_ENTER_CREATE;
570       else if (priv->first_resp == RESPONSE_IMPORT)
571         retval = PAGE_IMPORT;
572       else if (priv->first_resp == RESPONSE_SALUT_ONLY)
573         retval = PAGE_SALUT;
574     }
575   else if (current_page == PAGE_IMPORT)
576     {
577       if (priv->display_salut_page)
578         retval = PAGE_SALUT;
579       else
580         /* Don't go forward */
581         retval = -1;
582     }
583   else if (current_page == PAGE_SALUT)
584     {
585       /* Don't go forward */
586       retval = -1;
587     }
588   else if (current_page >= PAGE_ENTER_CREATE)
589     {
590       if (priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
591         {
592           priv->enter_create_forward = TRUE;
593           retval = current_page;
594         }
595       else if (priv->display_salut_page)
596         {
597           retval = PAGE_SALUT;
598         }
599       else
600         {
601           /* Don't go forward */
602           retval = -1;
603         }
604     }
605
606   return retval;
607 }
608
609 static void
610 update_intro_page_buttons (EmpathyAccountAssistant *self)
611 {
612   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
613   GtkWidget *intro_page;
614
615   intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self),
616       PAGE_INTRO);
617
618   if (priv->first_resp == RESPONSE_SALUT_ONLY &&
619       !priv->display_salut_page)
620     gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
621         GTK_ASSISTANT_PAGE_SUMMARY);
622   else
623     gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
624         GTK_ASSISTANT_PAGE_INTRO);
625 }
626
627 static void
628 account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
629     EmpathyAccountAssistant *self)
630 {
631   FirstPageResponse response;
632   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
633
634   response = GPOINTER_TO_INT (g_object_get_data
635       (G_OBJECT (button), "response"));
636
637   priv->first_resp = response;
638
639   update_intro_page_buttons (self);
640 }
641
642 static GtkWidget *
643 account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
644 {
645   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
646   GtkWidget *main_vbox, *hbox_1, *w, *vbox_1;
647   GtkWidget *radio = NULL;
648   GdkPixbuf *pix;
649   const gchar *str;
650
651   main_vbox = gtk_vbox_new (FALSE, 12);
652   gtk_widget_show (main_vbox);
653   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
654
655   hbox_1 = gtk_hbox_new (FALSE, 12);
656   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
657   gtk_widget_show (hbox_1);
658
659   w = gtk_label_new (
660       _("With Empathy you can chat with people "
661         "online nearby and with friends and colleagues "
662         "who use Google Talk, AIM, Windows Live "
663         "and many other chat programs. With a microphone "
664         "or a webcam you can also have audio or video calls."));
665   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
666   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
667   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
668   gtk_widget_show (w);
669
670   pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80);
671   w = gtk_image_new_from_pixbuf (pix);
672   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
673   gtk_widget_show (w);
674
675   g_object_unref (pix);
676
677   w = gtk_label_new (_("Do you have an account you've been using "
678           "with another chat program?"));
679   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
680   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
681   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
682   gtk_widget_show (w);
683
684   w = gtk_alignment_new (0, 0, 0, 0);
685   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
686   gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
687   gtk_widget_show (w);
688
689   vbox_1 = gtk_vbox_new (TRUE, 0);
690   gtk_container_add (GTK_CONTAINER (w), vbox_1);
691   gtk_widget_show (vbox_1);
692
693   if (empathy_import_accounts_to_import ())
694     {
695       hbox_1 = gtk_hbox_new (FALSE, 0);
696       gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0);
697       gtk_widget_show (hbox_1);
698
699       radio = gtk_radio_button_new_with_label (NULL,
700           _("Yes, import my account details from "));
701       gtk_box_pack_start (GTK_BOX (hbox_1), radio, TRUE, TRUE, 0);
702       g_object_set_data (G_OBJECT (radio), "response",
703           GINT_TO_POINTER (RESPONSE_IMPORT));
704       gtk_widget_show (radio);
705
706       w = gtk_combo_box_new_text ();
707       gtk_combo_box_append_text (GTK_COMBO_BOX (w), "Pidgin");
708       gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
709       gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0);
710       gtk_widget_show (w);
711
712       g_signal_connect (radio, "clicked",
713           G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
714       priv->first_resp = RESPONSE_IMPORT;
715     }
716   else
717     {
718       priv->first_resp = RESPONSE_ENTER_ACCOUNT;
719     }
720
721   str = _("Yes, I'll enter my account details now");
722
723   if (radio == NULL)
724     {
725       radio = gtk_radio_button_new_with_label (NULL, str);
726       w = radio;
727     }
728   else
729     {
730       w = gtk_radio_button_new_with_label_from_widget (
731           GTK_RADIO_BUTTON (radio), str);
732     }
733
734   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
735   g_object_set_data (G_OBJECT (w), "response",
736       GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
737   gtk_widget_show (w);
738
739   g_signal_connect (w, "clicked",
740       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
741
742   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
743       _("No, I want a new account"));
744   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
745   g_object_set_data (G_OBJECT (w), "response",
746       GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
747   gtk_widget_show (w);
748
749   g_signal_connect (w, "clicked",
750       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
751
752   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
753       _("No, I just want to see people online nearby for now"));
754   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
755   g_object_set_data (G_OBJECT (w), "response",
756       GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
757   gtk_widget_show (w);
758
759   g_signal_connect (w, "clicked",
760       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
761
762   return main_vbox;
763 }
764
765 static GtkWidget *
766 account_assistant_build_import_page (EmpathyAccountAssistant *self)
767 {
768   GtkWidget *main_vbox, *w, *import;
769   EmpathyImportWidget *iw;
770   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
771
772   main_vbox = gtk_vbox_new (FALSE, 12);
773   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
774   w = gtk_label_new (_("Select the accounts you want to import:"));
775   gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
776   gtk_widget_show (w);
777   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
778
779   w = gtk_alignment_new (0, 0, 0, 0);
780   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
781   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
782   gtk_widget_show (w);
783
784   /* NOTE: this is hardcoded as we support pidgin only */
785   iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN);
786   import = empathy_import_widget_get_widget (iw);
787   gtk_container_add (GTK_CONTAINER (w), import);
788   gtk_widget_show (import);
789
790   priv->iw = iw;
791
792   gtk_widget_show (main_vbox);
793
794   return main_vbox;
795 }
796
797 static void
798 account_assistant_radio_create_again_clicked_cb (GtkButton *button,
799     EmpathyAccountAssistant *self)
800 {
801   CreateEnterPageResponse response;
802   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
803
804   response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
805           "response"));
806
807   priv->create_enter_resp = response;
808
809   update_create_page_buttons (self);
810 }
811
812 static GtkWidget *
813 account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self)
814 {
815   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
816   GtkWidget *main_vbox, *w, *chooser, *vbox, *hbox, *radio;
817
818   main_vbox = gtk_vbox_new (FALSE, 12);
819   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
820   gtk_widget_show (main_vbox);
821
822   w = gtk_label_new (NULL);
823   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
824   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
825   gtk_widget_show (w);
826   priv->first_label = w;
827
828   w = gtk_alignment_new (0, 0, 0, 0);
829   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
830   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
831   gtk_widget_show (w);
832
833   chooser = empathy_protocol_chooser_new ();
834   gtk_container_add (GTK_CONTAINER (w), chooser);
835   gtk_widget_show (chooser);
836   priv->chooser = chooser;
837
838   vbox = gtk_vbox_new (FALSE, 6);
839   gtk_box_pack_end (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
840   gtk_widget_show (vbox);
841
842   w = gtk_label_new (NULL);
843   gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
844   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
845   gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
846   gtk_widget_show (w);
847   priv->second_label = w;
848
849   w = gtk_alignment_new (0, 0, 0, 0);
850   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
851   gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
852   gtk_widget_show (w);
853
854   hbox = gtk_hbox_new (FALSE, 6);
855   gtk_container_add (GTK_CONTAINER (w), hbox);
856   gtk_widget_show (hbox);
857
858   radio = gtk_radio_button_new_with_label (NULL, _("Yes"));
859   gtk_box_pack_start (GTK_BOX (hbox), radio, FALSE, FALSE, 0);
860   g_object_set_data (G_OBJECT (radio), "response",
861       GINT_TO_POINTER (RESPONSE_CREATE_AGAIN));
862   gtk_widget_show (radio);
863
864   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
865       _("No, that's all for now"));
866   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
867   g_object_set_data (G_OBJECT (w), "response",
868       GINT_TO_POINTER (RESPONSE_CREATE_STOP));
869   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
870   priv->create_enter_resp = RESPONSE_CREATE_STOP;
871   priv->create_again_radio = w;
872   gtk_widget_show (w);
873
874   g_signal_connect (w, "clicked",
875       G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
876   g_signal_connect (radio, "clicked",
877       G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
878
879   return main_vbox;
880 }
881
882 static void
883 account_assistant_close_cb (GtkAssistant *assistant,
884     gpointer user_data)
885 {
886   EmpathyAccountAssistantPriv *priv = GET_PRIV (assistant);
887
888   if (priv->is_creating)
889     return;
890
891   gtk_widget_destroy (GTK_WIDGET (assistant));
892 }
893
894 static void
895 impl_signal_apply (GtkAssistant *assistant)
896 {
897   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
898   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
899   gint current_page;
900
901   current_page = gtk_assistant_get_current_page (assistant);
902
903   if (current_page == PAGE_SALUT)
904     {
905       if (priv->create_salut_account)
906         /* create_salut_account_settings() already set the display name of the
907          * account so there is no need to set it again. */
908         account_assistant_apply_account_and_finish (self, priv->salut_settings,
909             FALSE);
910       return;
911     }
912   else if (current_page >= PAGE_ENTER_CREATE &&
913       priv->settings != NULL &&
914       empathy_account_settings_is_valid (priv->settings))
915     {
916       account_assistant_apply_account_and_finish (self, priv->settings, TRUE);
917       g_object_unref (priv->settings);
918       priv->settings = NULL;
919     }
920   else if (current_page == PAGE_IMPORT)
921     {
922       empathy_import_widget_add_selected_accounts (priv->iw);
923     }
924 }
925
926 static void
927 impl_signal_cancel (GtkAssistant *assistant)
928 {
929   gtk_widget_destroy (GTK_WIDGET (assistant));
930 }
931
932 static void
933 impl_signal_prepare (GtkAssistant *assistant,
934     GtkWidget *current_page)
935 {
936   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
937   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
938   gint current_idx;
939
940   /* check from which page we are coming from */
941   if (priv->current_page_id == PAGE_IMPORT)
942     empathy_import_widget_add_selected_accounts (priv->iw);
943
944   current_idx = gtk_assistant_get_current_page (assistant);
945   priv->current_page_id = current_idx;
946
947   if (current_idx >= PAGE_ENTER_CREATE)
948     {
949       if (!priv->enter_create_forward && current_idx != PAGE_SALUT)
950         {
951           account_assistant_finish_enter_or_create_page (self,
952               priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
953               TRUE : FALSE);
954         }
955       else
956         {
957           priv->enter_create_forward = FALSE;
958         }
959
960       if (priv->settings != NULL &&
961           empathy_account_settings_is_valid (priv->settings))
962         {
963           account_assistant_apply_account_and_finish (self, priv->settings,
964               TRUE);
965           g_object_unref (priv->settings);
966           priv->settings = NULL;
967         }
968     }
969 }
970
971 static void
972 do_get_property (GObject *object,
973     guint property_id,
974     GValue *value,
975     GParamSpec *pspec)
976 {
977   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
978
979   switch (property_id)
980     {
981     case PROP_PARENT:
982       g_value_set_object (value, priv->parent_window);
983       break;
984     case PROP_CONNECTION_MGRS:
985       g_value_set_object (value, priv->connection_mgrs);
986       break;
987     default:
988       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
989     }
990 }
991
992 static void
993 do_set_property (GObject *object,
994     guint property_id,
995     const GValue *value,
996     GParamSpec *pspec)
997 {
998   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
999
1000   switch (property_id)
1001     {
1002     case PROP_PARENT:
1003       priv->parent_window = g_value_get_object (value);
1004       break;
1005     case PROP_CONNECTION_MGRS:
1006       priv->connection_mgrs = g_value_dup_object (value);
1007       break;
1008     default:
1009       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1010     }
1011 }
1012
1013 static void
1014 do_dispose (GObject *obj)
1015 {
1016   EmpathyAccountAssistantPriv *priv = GET_PRIV (obj);
1017
1018   if (priv->dispose_run)
1019     return;
1020
1021   priv->dispose_run = TRUE;
1022
1023   if (priv->settings != NULL)
1024     {
1025       g_object_unref (priv->settings);
1026       priv->settings = NULL;
1027     }
1028
1029   g_object_unref (priv->account_mgr);
1030   priv->account_mgr = NULL;
1031
1032   g_object_unref (priv->connection_mgrs);
1033   priv->connection_mgrs = NULL;
1034
1035   if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL)
1036     G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj);
1037 }
1038
1039 static void
1040 empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
1041 {
1042   GObjectClass *oclass = G_OBJECT_CLASS (klass);
1043   GtkAssistantClass *gtkclass = GTK_ASSISTANT_CLASS (klass);
1044   GParamSpec *param_spec;
1045
1046   oclass->get_property = do_get_property;
1047   oclass->set_property = do_set_property;
1048   oclass->constructed = do_constructed;
1049   oclass->dispose = do_dispose;
1050
1051   gtkclass->apply = impl_signal_apply;
1052   gtkclass->prepare = impl_signal_prepare;
1053   gtkclass->cancel = impl_signal_cancel;
1054
1055   param_spec = g_param_spec_object ("parent-window",
1056       "parent-window", "The parent window",
1057       GTK_TYPE_WINDOW,
1058       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1059   g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1060
1061   param_spec = g_param_spec_object ("connection-managers",
1062       "connection-managers", "A EmpathyConnectionManagers",
1063       EMPATHY_TYPE_CONNECTION_MANAGERS,
1064       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1065   g_object_class_install_property (oclass, PROP_CONNECTION_MGRS, param_spec);
1066
1067   g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
1068 }
1069
1070 static void
1071 create_salut_check_box_toggled_cb (GtkWidget *widget,
1072     EmpathyAccountAssistant *self)
1073 {
1074   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1075   gboolean sensitive;
1076   gboolean page_valid;
1077
1078   sensitive = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
1079
1080   gtk_widget_set_sensitive (priv->salut_account_widget, sensitive);
1081
1082   if (!sensitive)
1083     {
1084       page_valid = TRUE;
1085       priv->create_salut_account = FALSE;
1086     }
1087   else
1088     {
1089       /* page is complete if the account is valid */
1090       page_valid = empathy_account_settings_is_valid (priv->salut_settings);
1091       priv->create_salut_account = TRUE;
1092     }
1093
1094   gtk_assistant_set_page_complete (GTK_ASSISTANT (self), priv->salut_page,
1095       page_valid);
1096 }
1097
1098 static void
1099 account_assistant_salut_handle_apply_cb (EmpathyAccountWidget *widget_object,
1100     gboolean is_valid,
1101     EmpathyAccountAssistant *self)
1102 {
1103   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1104
1105   gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
1106       priv->salut_page, is_valid);
1107 }
1108
1109 static GtkWidget *
1110 account_assistant_build_salut_page (EmpathyAccountAssistant *self)
1111 {
1112   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1113   GtkWidget *main_vbox, *hbox_1, *w;
1114   GdkPixbuf *pix;
1115   EmpathyAccountSettings *settings;
1116   GtkWidget *account_widget;
1117   EmpathyAccountWidget *widget_object;
1118   gchar *markup;
1119
1120   main_vbox = gtk_vbox_new (FALSE, 12);
1121   gtk_widget_show (main_vbox);
1122   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
1123
1124   hbox_1 = gtk_hbox_new (FALSE, 12);
1125   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
1126   gtk_widget_show (hbox_1);
1127
1128   w = gtk_label_new (NULL);
1129   markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1130       _("Empathy can automatically discover and chat with the people "
1131         "connected on the same network as you. "
1132         "If you want to use this feature, please check that the "
1133         "details below are correct. "
1134         "You can easily change these details later or disable this feature "
1135         "by using the 'Accounts' dialog"),
1136       _("Edit->Accounts"));
1137   gtk_label_set_markup (GTK_LABEL (w), markup);
1138   g_free (markup);
1139   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1140   gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
1141   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
1142   gtk_widget_show (w);
1143
1144   pix = empathy_pixbuf_from_icon_name_sized ("im-local-xmpp", 80);
1145   w = gtk_image_new_from_pixbuf (pix);
1146   gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
1147   gtk_widget_show (w);
1148
1149   g_object_unref (pix);
1150
1151   w = gtk_check_button_new_with_label (
1152       _("I don't want to enable this feature for now"));
1153   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
1154   g_signal_connect (w, "toggled",
1155       G_CALLBACK (create_salut_check_box_toggled_cb), self);
1156   gtk_widget_show (w);
1157
1158   w = gtk_alignment_new (0, 0, 0, 0);
1159   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
1160   gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
1161   gtk_widget_show (w);
1162
1163   settings = create_salut_account_settings ();
1164
1165   widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
1166   account_widget = empathy_account_widget_get_widget (widget_object);
1167
1168   priv->salut_settings = settings;
1169   priv->salut_account_widget = account_widget;
1170
1171   g_signal_connect (widget_object, "handle-apply",
1172       G_CALLBACK (account_assistant_salut_handle_apply_cb), self);
1173
1174   gtk_box_pack_start (GTK_BOX (main_vbox), account_widget,
1175       FALSE, FALSE, 0);
1176   gtk_widget_show (account_widget);
1177
1178   return main_vbox;
1179 }
1180
1181 static GtkWidget *
1182 account_assistant_build_salut_error_page (EmpathyAccountAssistant *self)
1183 {
1184   GtkWidget *vbox;
1185   gchar *markup;
1186
1187   markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1188       _("You won't be able to chat with people connected to your local "
1189         "network, as telepathy-salut is not installed. If you want to enable "
1190         "this feature, please install the telepathy-salut package and create "
1191         "a People Nearby account from the Accounts dialog"),
1192         _("Edit->Accounts"));
1193
1194   vbox = build_error_vbox (_("telepathy-salut not installed"), markup);
1195   g_free (markup);
1196   return vbox;
1197 }
1198
1199 static void
1200 account_mgr_prepare_cb (GObject *source_object,
1201     GAsyncResult *result,
1202     gpointer user_data)
1203 {
1204   EmpathyAccountAssistant *self = user_data;
1205   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1206   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1207   GError *error = NULL;
1208
1209   if (!tp_account_manager_prepare_finish (manager, result, &error))
1210     {
1211       DEBUG ("Failed to prepare account manager: %s", error->message);
1212       g_error_free (error);
1213       return;
1214     }
1215
1216   if (!should_create_salut_account (manager))
1217     {
1218       DEBUG ("No need to create a Salut account");
1219       priv->display_salut_page = FALSE;
1220
1221       update_intro_page_buttons (self);
1222
1223       gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->import_page,
1224           GTK_ASSISTANT_PAGE_CONFIRM);
1225
1226       update_create_page_buttons (self);
1227     }
1228 }
1229
1230 static void
1231 empathy_account_assistant_init (EmpathyAccountAssistant *self)
1232 {
1233   EmpathyAccountAssistantPriv *priv;
1234
1235   priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
1236       EmpathyAccountAssistantPriv);
1237   self->priv = priv;
1238
1239   gtk_window_set_title (GTK_WINDOW (self),
1240       _("Messaging and VoIP Accounts Assistant"));
1241
1242   priv->account_mgr = tp_account_manager_dup ();
1243 }
1244
1245 static void
1246 do_constructed (GObject *object)
1247 {
1248   GtkAssistant *assistant = GTK_ASSISTANT (object);
1249   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (object);
1250   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
1251   GtkWidget *page;
1252
1253   /* set us as transient for the parent window if any */
1254   if (priv->parent_window)
1255     gtk_window_set_transient_for (GTK_WINDOW (object),
1256         priv->parent_window);
1257
1258   /* set the dialog hint, so this will be centered over the parent window */
1259   gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
1260
1261   g_assert (priv->connection_mgrs != NULL);
1262   g_assert (empathy_connection_managers_is_ready (priv->connection_mgrs));
1263
1264   g_signal_connect (self, "close",
1265       G_CALLBACK (account_assistant_close_cb), NULL);
1266
1267   gtk_assistant_set_forward_page_func (assistant,
1268       account_assistant_page_forward_func, self, NULL);
1269
1270   /* first page (introduction) */
1271   page = account_assistant_build_introduction_page (self);
1272   gtk_assistant_append_page (assistant, page);
1273   gtk_assistant_set_page_title (assistant, page,
1274       _("Welcome to Empathy"));
1275   gtk_assistant_set_page_type (assistant, page,
1276       GTK_ASSISTANT_PAGE_INTRO);
1277   gtk_assistant_set_page_complete (assistant, page, TRUE);
1278
1279   /* second page (import accounts) */
1280   page = account_assistant_build_import_page (self);
1281   gtk_assistant_append_page (assistant, page);
1282   gtk_assistant_set_page_title (assistant, page,
1283       _("Import your existing accounts"));
1284   gtk_assistant_set_page_complete (assistant, page, TRUE);
1285   gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1286   priv->import_page = page;
1287
1288   /* third page (enter account details) */
1289   page = account_assistant_build_enter_or_create_page (self);
1290   gtk_assistant_append_page (assistant, page);
1291   gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1292   priv->enter_or_create_page = page;
1293
1294   /* fourth page (salut details) */
1295   if (empathy_connection_managers_get_cm (priv->connection_mgrs, "salut")
1296       != NULL)
1297     {
1298       page = account_assistant_build_salut_page (self);
1299       gtk_assistant_append_page (assistant, page);
1300       gtk_assistant_set_page_title (assistant, page,
1301           _("Please enter personal details"));
1302       gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
1303
1304       priv->create_salut_account = TRUE;
1305
1306       if (empathy_account_settings_is_valid (priv->salut_settings))
1307         {
1308           gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
1309               page, TRUE);
1310         }
1311     }
1312   else
1313     {
1314       page = account_assistant_build_salut_error_page (self);
1315       gtk_assistant_append_page (assistant, page);
1316       gtk_assistant_set_page_title (assistant, page, _("An error occurred"));
1317       gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_SUMMARY);
1318
1319       priv->create_salut_account = FALSE;
1320     }
1321
1322   priv->salut_page = page;
1323   priv->display_salut_page = TRUE;
1324
1325   tp_account_manager_prepare_async (priv->account_mgr, NULL,
1326       account_mgr_prepare_cb, self);
1327
1328   gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
1329 }
1330
1331 GtkWidget *
1332 empathy_account_assistant_show (GtkWindow *window,
1333     EmpathyConnectionManagers *connection_mgrs)
1334 {
1335   static GtkWidget *dialog = NULL;
1336
1337   if (dialog == NULL)
1338     {
1339       dialog = g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT,
1340           "parent-window", window,
1341           "connection-managers", connection_mgrs,
1342           NULL);
1343       g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &dialog);
1344     }
1345
1346   gtk_window_present (GTK_WINDOW (dialog));
1347
1348   return dialog;
1349 }
1350
1351