]> git.0d.be Git - empathy.git/blob - src/empathy-account-assistant.c
Report errors during creation
[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
26 #include "empathy-account-assistant.h"
27
28 #include <libempathy/empathy-account-settings.h>
29 #include <libempathy/empathy-utils.h>
30
31 #include <libempathy-gtk/empathy-account-widget.h>
32 #include <libempathy-gtk/empathy-protocol-chooser.h>
33 #include <libempathy-gtk/empathy-ui-utils.h>
34
35 G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant,
36     GTK_TYPE_ASSISTANT)
37
38 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountAssistant)
39
40 typedef enum {
41   RESPONSE_IMPORT = 1,
42   RESPONSE_ENTER_ACCOUNT = 2,
43   RESPONSE_CREATE_ACCOUNT = 3,
44   RESPONSE_SALUT_ONLY = 4
45 } FirstPageResponse;
46
47 enum {
48   PAGE_INTRO = 0,
49   PAGE_IMPORT = 1,
50   PAGE_ENTER_CREATE = 2,
51   PAGE_SALUT_ONLY = 3
52 };
53
54 enum {
55   PROP_PARENT = 1
56 };
57
58 typedef struct {
59   FirstPageResponse first_resp;
60
61   /* enter or create page */
62   GtkWidget *enter_or_create_page;
63   GtkWidget *current_account_widget;
64   EmpathyAccountWidget *current_widget_object;
65   GtkWidget *first_label;
66   GtkWidget *second_label;
67   GtkWidget *chooser;
68   EmpathyAccountSettings *settings;
69
70   GtkWindow *parent_window;
71 } EmpathyAccountAssistantPriv;
72
73 static GtkWidget *
74 account_assistant_build_error_page (EmpathyAccountAssistant *self,
75     GError *error, gint page_num)
76 {
77   GtkWidget *main_vbox, *w, *hbox;
78   GString *str;
79   char *message;
80   PangoAttrList *list;
81   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
82
83   main_vbox = gtk_vbox_new (FALSE, 12);
84   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
85   gtk_widget_show (main_vbox);
86
87   hbox = gtk_hbox_new (FALSE, 12);
88   gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
89   gtk_widget_show (hbox);
90
91   w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
92       GTK_ICON_SIZE_DIALOG);
93   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
94   gtk_widget_show (w);
95
96   /* translators: this is followed by the "while ..." strings some lines
97    * down this file.
98    */
99   str = g_string_new (_("There has been an error\n"));
100
101   if (page_num == PAGE_IMPORT)
102     /* translators: this follows the "There has been an error " string */
103     str = g_string_append (str, _("while importing the accounts."));
104   else if (page_num == PAGE_ENTER_CREATE &&
105       priv->first_resp == RESPONSE_ENTER_ACCOUNT)
106     /* translators: this follows the "There has been an error " string */
107     str = g_string_append (str, _("while parsing the account details."));
108   else if (page_num == PAGE_ENTER_CREATE &&
109       priv->first_resp == RESPONSE_CREATE_ACCOUNT)
110     /* translators: this follows the "There has been an error " string */
111     str = g_string_append (str, _("while creating the account."));
112
113   message = g_string_free (str, FALSE);
114
115   w = gtk_label_new (message);
116   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
117   list = pango_attr_list_new ();
118   pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_LARGE));
119   pango_attr_list_insert (list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
120   gtk_label_set_attributes (GTK_LABEL (w), list);
121   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
122   gtk_widget_show (w);
123
124   g_free (message);
125   pango_attr_list_unref (list);
126
127   message = g_markup_printf_escaped
128     (_("The error message was: <span style=\"italic\">%s</span>"),
129         error->message);
130   w = gtk_label_new (message);
131   gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
132   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
133   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
134   gtk_widget_show (w);
135
136   w = gtk_label_new (_("You can either go back and try to enter your "
137           "accounts' details\nagain or quit this wizard and add accounts "
138           "later from the Edit menu."));
139   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
140   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
141   gtk_widget_show (w);
142
143   return main_vbox;
144 }
145
146 static void
147 account_assistant_back_button_clicked_cb (GtkButton *button,
148     EmpathyAccountAssistant *self)
149 {
150   gint page_num;
151
152   page_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
153           "page-num"));
154   gtk_assistant_remove_action_widget (GTK_ASSISTANT (self),
155       GTK_WIDGET (button));
156   gtk_assistant_set_current_page (GTK_ASSISTANT (self), page_num);
157 }
158
159 static void
160 account_assistant_present_error_page (EmpathyAccountAssistant *self,
161     GError *error, gint page_num)
162 {
163   GtkWidget *error_page, *back_button;
164   gint num;
165
166   error_page = account_assistant_build_error_page (self, error,
167       page_num);
168   num = gtk_assistant_append_page (GTK_ASSISTANT (self), error_page);
169   gtk_assistant_set_page_title (GTK_ASSISTANT (self), error_page,
170       _("An error occurred"));
171   gtk_assistant_set_page_type (GTK_ASSISTANT (self), error_page,
172       GTK_ASSISTANT_PAGE_SUMMARY);
173
174   back_button = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
175   gtk_assistant_add_action_widget (GTK_ASSISTANT (self), back_button);
176   g_object_set_data (G_OBJECT (back_button),
177       "page-num", GINT_TO_POINTER (page_num));
178   g_signal_connect (back_button, "clicked",
179       G_CALLBACK (account_assistant_back_button_clicked_cb), self);
180   gtk_widget_show (back_button);
181
182   gtk_assistant_set_current_page (GTK_ASSISTANT (self), num);
183 }
184
185 static void
186 account_assistant_apply_account_cb (GObject *source,
187     GAsyncResult *result,
188     gpointer user_data)
189 {
190   GError *error = NULL;
191   EmpathyAccountAssistant *self = user_data;
192
193   empathy_account_settings_apply_finish (EMPATHY_ACCOUNT_SETTINGS (source),
194       result, &error);
195
196   if (error != NULL)
197     {
198       account_assistant_present_error_page (self, error, PAGE_ENTER_CREATE);
199       g_error_free (error);
200     }
201 }
202
203 static void
204 account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self)
205 {
206   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
207
208   if (priv->settings == NULL)
209     return;
210
211   empathy_account_settings_apply_async (priv->settings,
212       account_assistant_apply_account_cb, self);
213 }
214
215 static void
216 account_assistant_apply_cb (GtkAssistant *assistant,
217     gpointer user_data)
218 {
219   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
220   gint current_page;
221
222   current_page = gtk_assistant_get_current_page (assistant);
223
224   if (current_page == RESPONSE_ENTER_ACCOUNT)
225     account_assistant_apply_account_and_finish (self);
226 }
227
228 static void
229 account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object,
230     gboolean is_valid,
231     EmpathyAccountAssistant *self)
232 {
233   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
234
235   gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
236       priv->enter_or_create_page, is_valid);
237 }
238
239 static void
240 account_assistant_protocol_changed_cb (GtkComboBox *chooser,
241     EmpathyAccountAssistant *self)
242 {
243   TpConnectionManager *cm;
244   TpConnectionManagerProtocol *proto;
245   EmpathyAccountSettings *settings;
246   EmpathyAccountAssistantPriv *priv;
247   char *str;
248   GtkWidget *account_widget;
249   EmpathyAccountWidget *widget_object = NULL;
250
251   priv = GET_PRIV (self);
252
253   cm = empathy_protocol_chooser_dup_selected (
254       EMPATHY_PROTOCOL_CHOOSER (chooser), &proto);
255
256   if (cm == NULL || proto == NULL)
257     /* we are not ready yet */
258     return;
259
260   /* Create account */
261   /* To translator: %s is the protocol name */
262   str = g_strdup_printf (_("New %s account"), proto->name);
263
264   settings = empathy_account_settings_new (cm->name, proto->name, str);
265
266   if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
267     empathy_account_settings_set_boolean (settings, "register", TRUE);
268
269   account_widget = empathy_account_widget_simple_new_for_protocol
270     (proto->name, settings, &widget_object);
271
272   if (priv->current_account_widget != NULL)
273     {
274       g_signal_handlers_disconnect_by_func (priv->current_widget_object,
275           account_assistant_handle_apply_cb, self);
276       gtk_widget_destroy (priv->current_account_widget);
277     }
278
279   priv->current_account_widget = account_widget;
280   priv->current_widget_object = widget_object;
281
282   if (priv->settings != NULL)
283     g_object_unref (priv->settings);
284
285   priv->settings = settings;
286
287   g_signal_connect (priv->current_widget_object, "handle-apply",
288       G_CALLBACK (account_assistant_handle_apply_cb), self);
289
290   gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
291       FALSE, FALSE, 0);
292   gtk_widget_show (account_widget);
293
294   g_free (str);
295 }
296
297 static gboolean
298 account_assistant_chooser_enter_details_filter_func (
299     TpConnectionManager *cm,
300     TpConnectionManagerProtocol *protocol,
301     gpointer user_data)
302 {
303   if (!tp_strdiff (protocol->name, "local-xmpp") ||
304       !tp_strdiff (protocol->name, "irc"))
305     return FALSE;
306
307   return TRUE;
308 }
309
310 static gboolean
311 account_assistant_chooser_create_account_filter_func (
312     TpConnectionManager *cm,
313     TpConnectionManagerProtocol *protocol,
314     gpointer user_data)
315 {
316   return tp_connection_manager_protocol_can_register (protocol);
317 }
318
319 static void
320 account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self,
321     gboolean is_enter)
322 {
323   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
324   
325   if (is_enter)
326     {
327       gtk_label_set_label (GTK_LABEL (priv->first_label),
328           _("What kind of chat account do you have?"));
329       gtk_label_set_label (GTK_LABEL (priv->second_label),
330           _("If you have other accounts to set up, you can do "
331               "that at any time\nfrom the Edit menu."));
332       empathy_protocol_chooser_set_visible (
333           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
334           account_assistant_chooser_enter_details_filter_func, self);
335
336       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
337           priv->enter_or_create_page, _("Enter your account details"));
338     }
339   else
340     {
341       gtk_label_set_label (GTK_LABEL (priv->first_label),
342           _("What kind of chat account do you want to create?"));
343       gtk_label_set_label (GTK_LABEL (priv->second_label),
344           _("You can register other accounts, or setup\n"
345               "an existing one at any time from the Edit menu."));
346       empathy_protocol_chooser_set_visible (
347           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
348           account_assistant_chooser_create_account_filter_func, self);
349
350       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
351           priv->enter_or_create_page,
352           _("Enter the details for the new account"));
353     }
354     
355   g_signal_connect (priv->chooser, "changed",
356       G_CALLBACK (account_assistant_protocol_changed_cb), self);
357  
358   /* trigger show the first account widget */
359   account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self);
360 }
361
362 static void
363 account_assistant_prepare_cb (GtkAssistant *assistant,
364     GtkWidget *current_page,
365     gpointer user_data)
366 {
367   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
368   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
369   gint current_idx;
370
371   current_idx = gtk_assistant_get_current_page (assistant);
372
373   g_print ("prepare, current idx = %d\n", current_idx);
374
375   if (current_idx == PAGE_ENTER_CREATE)
376     {
377       account_assistant_finish_enter_or_create_page (self,
378           priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
379           TRUE : FALSE);
380     }
381 }
382
383 static gint
384 account_assistant_page_forward_func (gint current_page,
385     gpointer user_data)
386 {
387   EmpathyAccountAssistant *self = user_data;
388   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
389   gint retval;
390
391   retval = current_page;
392
393   if (current_page == 0)
394     {
395       if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
396           priv->first_resp == RESPONSE_CREATE_ACCOUNT)
397         retval = PAGE_ENTER_CREATE;
398     }
399
400   if (current_page == PAGE_ENTER_CREATE)
401     {
402       /* don't forward anymore */
403       retval = -1;
404     }
405
406   g_print ("retval = %d\n", retval);
407   return retval;
408 }
409
410 static void
411 account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
412     EmpathyAccountAssistant *self)
413 {
414   FirstPageResponse response;
415   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
416
417   response = GPOINTER_TO_INT (g_object_get_data
418       (G_OBJECT (button), "response"));
419
420   g_print ("choice %d toggled\n", response);
421   priv->first_resp = response;
422 }
423
424 static GtkWidget *
425 account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
426 {
427   GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1;
428   GdkPixbuf *pix;
429
430   main_vbox = gtk_vbox_new (FALSE, 12);
431   gtk_widget_show (main_vbox);
432   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
433
434   hbox_1 = gtk_hbox_new (FALSE, 12);
435   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
436   gtk_widget_show (hbox_1);
437
438   w = gtk_label_new (
439       _("With Empathy you can chat with people\n"
440         "online nearby and with friends and colleagues\n"
441         "who use Google Talk, AIM, Windows Live\n"
442         "and many other chat programs. With a microphone\n"
443         "or a webcam you can also have audio or video calls."));
444   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
445   gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
446   gtk_widget_show (w);
447
448   pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80);
449   w = gtk_image_new_from_pixbuf (pix);
450   gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6);
451   gtk_widget_show (w);
452
453   g_object_unref (pix);
454
455   w = gtk_label_new (_("Do you have an account you've been using "
456           "with another\nchat program?"));
457   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
458   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
459   gtk_widget_show (w);
460
461   w = gtk_alignment_new (0, 0, 0, 0);
462   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
463   gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
464   gtk_widget_show (w);
465
466   vbox_1 = gtk_vbox_new (FALSE, 6);
467   gtk_container_add (GTK_CONTAINER (w), vbox_1);
468   gtk_widget_show (vbox_1);
469
470   /* TODO: this will have to be updated when kutio's branch have landed */
471   radio = gtk_radio_button_new_with_label (NULL,
472       _("Yes, import my account details from "));
473   gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0);
474   g_object_set_data (G_OBJECT (radio), "response",
475       GINT_TO_POINTER (RESPONSE_IMPORT));
476   gtk_widget_show (radio);
477
478   g_signal_connect (radio, "clicked",
479       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
480
481   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
482       _("Yes, I'll enter my account details now"));
483   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
484   g_object_set_data (G_OBJECT (w), "response",
485       GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
486   gtk_widget_show (w);
487
488   g_signal_connect (w, "clicked",
489       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
490
491   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
492       _("No, I want a new account"));
493   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
494   g_object_set_data (G_OBJECT (w), "response",
495       GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
496   gtk_widget_show (w);
497
498   g_signal_connect (w, "clicked",
499       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
500
501   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
502       _("No, I just want to see people online nearby for now"));
503   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
504   g_object_set_data (G_OBJECT (w), "response",
505       GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
506   gtk_widget_show (w);
507
508   g_signal_connect (w, "clicked",
509       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
510
511   return main_vbox;
512 }
513
514 static GtkWidget *
515 account_assistant_build_import_page (EmpathyAccountAssistant *self)
516 {
517   /* TODO: import page */
518   GtkWidget *main_vbox, *w;
519
520   main_vbox = gtk_vbox_new (FALSE, 12);
521   w = gtk_label_new ("Import your accounts!");
522   gtk_widget_show (w);
523   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
524
525   gtk_widget_show (main_vbox);
526
527   return main_vbox;
528 }
529
530 static GtkWidget *
531 account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self,
532     gboolean is_enter)
533 {
534   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
535   GtkWidget *main_vbox, *w, *chooser, *hbox;
536   PangoAttrList *list;
537
538   main_vbox = gtk_vbox_new (FALSE, 12);
539   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
540   gtk_widget_show (main_vbox);
541
542   w = gtk_label_new (NULL);
543   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
544   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
545   gtk_widget_show (w);
546   priv->first_label = w;
547
548   w = gtk_alignment_new (0, 0, 0, 0);
549   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
550   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
551   gtk_widget_show (w);
552
553   chooser = empathy_protocol_chooser_new ();
554   gtk_container_add (GTK_CONTAINER (w), chooser);
555   gtk_widget_show (chooser);
556   priv->chooser = chooser;
557
558   hbox = gtk_hbox_new (FALSE, 6);
559   gtk_box_pack_end (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
560   gtk_widget_show (hbox);
561
562   w = gtk_image_new_from_icon_name ("gtk-dialog-info", GTK_ICON_SIZE_BUTTON);
563   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
564   gtk_widget_show (w);
565
566   w = gtk_label_new (NULL);
567   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
568   list = pango_attr_list_new ();
569   pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_SMALL));
570   gtk_label_set_attributes (GTK_LABEL (w), list);
571   gtk_widget_show (w);
572   priv->second_label = w;
573   pango_attr_list_unref (list);
574
575   return main_vbox;
576 }
577
578 static void
579 do_get_property (GObject *object,
580     guint property_id,
581     GValue *value,
582     GParamSpec *pspec)
583 {
584   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
585
586   switch (property_id)
587     {
588     case PROP_PARENT:
589       g_value_set_object (value, priv->parent_window);
590       break;
591     default:
592       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
593     }
594 }
595
596 static void
597 do_set_property (GObject *object,
598     guint property_id,
599     const GValue *value,
600     GParamSpec *pspec)
601 {
602   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
603
604   switch (property_id)
605     {
606     case PROP_PARENT:
607       priv->parent_window = g_value_get_object (value);
608       break;
609     default:
610       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
611     }
612 }
613
614 static void
615 do_constructed (GObject *object)
616 {
617   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
618
619   /* set us as transient for the parent window if any */
620   if (priv->parent_window)
621     gtk_window_set_transient_for (GTK_WINDOW (object),
622         priv->parent_window);
623
624   gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
625 }
626
627 static void
628 empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
629 {
630   GObjectClass *oclass = G_OBJECT_CLASS (klass);
631   GParamSpec *param_spec;
632
633   oclass->get_property = do_get_property;
634   oclass->set_property = do_set_property;
635   oclass->constructed = do_constructed;
636
637   param_spec = g_param_spec_object ("parent-window",
638       "parent-window", "The parent window",
639       GTK_TYPE_WINDOW,
640       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
641   g_object_class_install_property (oclass, PROP_PARENT, param_spec);
642
643   g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
644 }
645
646 static void
647 empathy_account_assistant_init (EmpathyAccountAssistant *self)
648 {
649   EmpathyAccountAssistantPriv *priv;
650   GtkAssistant *assistant = GTK_ASSISTANT (self);
651   GtkWidget *page;
652
653   priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
654       EmpathyAccountAssistantPriv);
655   self->priv = priv;
656
657   gtk_assistant_set_forward_page_func (assistant,
658       account_assistant_page_forward_func, self, NULL);
659
660   g_signal_connect (self, "apply",
661       G_CALLBACK (account_assistant_apply_cb), NULL);
662   g_signal_connect (self, "prepare",
663       G_CALLBACK (account_assistant_prepare_cb), NULL);
664
665   /* first page (introduction) */
666   page = account_assistant_build_introduction_page (self);
667   gtk_assistant_append_page (assistant, page);
668   gtk_assistant_set_page_title (assistant, page,
669       _("Welcome to Empathy"));
670   gtk_assistant_set_page_type (assistant, page,
671       GTK_ASSISTANT_PAGE_INTRO);
672   gtk_assistant_set_page_complete (assistant, page, TRUE);
673
674   /* set a default answer */
675   priv->first_resp = RESPONSE_IMPORT;
676
677   /* second page (import accounts) */
678   page = account_assistant_build_import_page (self);
679   gtk_assistant_append_page (assistant, page);
680   gtk_assistant_set_page_title (assistant, page,
681       _("Import your existing accounts"));
682   gtk_assistant_set_page_complete (assistant, page, TRUE);
683
684   /* third page (enter account details) */
685   page = account_assistant_build_enter_or_create_page (self, TRUE);
686   gtk_assistant_append_page (assistant, page);
687   gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
688   priv->enter_or_create_page = page;
689 }
690
691 GtkWidget *
692 empathy_account_assistant_new (GtkWindow *window)
693 {
694   return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, "parent-window",
695       window, NULL);
696 }