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