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