]> git.0d.be Git - empathy.git/blob - src/empathy-account-assistant.c
Implement close and cancel;
[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_handle_apply_cb (EmpathyAccountWidget *widget_object,
225     gboolean is_valid,
226     EmpathyAccountAssistant *self)
227 {
228   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
229
230   gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
231       priv->enter_or_create_page, is_valid);
232 }
233
234 static void
235 account_assistant_protocol_changed_cb (GtkComboBox *chooser,
236     EmpathyAccountAssistant *self)
237 {
238   TpConnectionManager *cm;
239   TpConnectionManagerProtocol *proto;
240   EmpathyAccountSettings *settings;
241   EmpathyAccountAssistantPriv *priv;
242   char *str;
243   GtkWidget *account_widget;
244   EmpathyAccountWidget *widget_object = NULL;
245
246   priv = GET_PRIV (self);
247
248   cm = empathy_protocol_chooser_dup_selected (
249       EMPATHY_PROTOCOL_CHOOSER (chooser), &proto);
250
251   if (cm == NULL || proto == NULL)
252     /* we are not ready yet */
253     return;
254
255   /* Create account */
256   /* To translator: %s is the protocol name */
257   str = g_strdup_printf (_("New %s account"), proto->name);
258
259   settings = empathy_account_settings_new (cm->name, proto->name, str);
260
261   if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
262     empathy_account_settings_set_boolean (settings, "register", TRUE);
263
264   account_widget = empathy_account_widget_simple_new_for_protocol
265     (proto->name, settings, &widget_object);
266
267   if (priv->current_account_widget != NULL)
268     {
269       g_signal_handlers_disconnect_by_func (priv->current_widget_object,
270           account_assistant_handle_apply_cb, self);
271       gtk_widget_destroy (priv->current_account_widget);
272     }
273
274   priv->current_account_widget = account_widget;
275   priv->current_widget_object = widget_object;
276
277   if (priv->settings != NULL)
278     g_object_unref (priv->settings);
279
280   priv->settings = settings;
281
282   g_signal_connect (priv->current_widget_object, "handle-apply",
283       G_CALLBACK (account_assistant_handle_apply_cb), self);
284
285   gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
286       FALSE, FALSE, 0);
287   gtk_widget_show (account_widget);
288
289   g_free (str);
290 }
291
292 static gboolean
293 account_assistant_chooser_enter_details_filter_func (
294     TpConnectionManager *cm,
295     TpConnectionManagerProtocol *protocol,
296     gpointer user_data)
297 {
298   if (!tp_strdiff (protocol->name, "local-xmpp") ||
299       !tp_strdiff (protocol->name, "irc"))
300     return FALSE;
301
302   return TRUE;
303 }
304
305 static gboolean
306 account_assistant_chooser_create_account_filter_func (
307     TpConnectionManager *cm,
308     TpConnectionManagerProtocol *protocol,
309     gpointer user_data)
310 {
311   return tp_connection_manager_protocol_can_register (protocol);
312 }
313
314 static void
315 account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self,
316     gboolean is_enter)
317 {
318   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
319   
320   if (is_enter)
321     {
322       gtk_label_set_label (GTK_LABEL (priv->first_label),
323           _("What kind of chat account do you have?"));
324       gtk_label_set_label (GTK_LABEL (priv->second_label),
325           _("If you have other accounts to set up, you can do "
326               "that at any time\nfrom the Edit menu."));
327       empathy_protocol_chooser_set_visible (
328           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
329           account_assistant_chooser_enter_details_filter_func, self);
330
331       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
332           priv->enter_or_create_page, _("Enter your account details"));
333     }
334   else
335     {
336       gtk_label_set_label (GTK_LABEL (priv->first_label),
337           _("What kind of chat account do you want to create?"));
338       gtk_label_set_label (GTK_LABEL (priv->second_label),
339           _("You can register other accounts, or setup\n"
340               "an existing one at any time from the Edit menu."));
341       empathy_protocol_chooser_set_visible (
342           EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
343           account_assistant_chooser_create_account_filter_func, self);
344
345       gtk_assistant_set_page_title (GTK_ASSISTANT (self),
346           priv->enter_or_create_page,
347           _("Enter the details for the new account"));
348     }
349     
350   g_signal_connect (priv->chooser, "changed",
351       G_CALLBACK (account_assistant_protocol_changed_cb), self);
352  
353   /* trigger show the first account widget */
354   account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self);
355 }
356
357 static gint
358 account_assistant_page_forward_func (gint current_page,
359     gpointer user_data)
360 {
361   EmpathyAccountAssistant *self = user_data;
362   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
363   gint retval;
364
365   retval = current_page;
366
367   if (current_page == 0)
368     {
369       if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
370           priv->first_resp == RESPONSE_CREATE_ACCOUNT)
371         retval = PAGE_ENTER_CREATE;
372     }
373
374   if (current_page == PAGE_ENTER_CREATE)
375     {
376       /* don't forward anymore */
377       retval = -1;
378     }
379
380   g_print ("retval = %d\n", retval);
381   return retval;
382 }
383
384 static void
385 account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
386     EmpathyAccountAssistant *self)
387 {
388   FirstPageResponse response;
389   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
390   GtkWidget *intro_page;
391
392   response = GPOINTER_TO_INT (g_object_get_data
393       (G_OBJECT (button), "response"));
394
395   priv->first_resp = response;
396
397   intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self),
398       PAGE_INTRO);
399
400   if (response == RESPONSE_SALUT_ONLY)
401     gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
402         GTK_ASSISTANT_PAGE_SUMMARY);
403   else
404     gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
405         GTK_ASSISTANT_PAGE_INTRO);
406 }
407
408 static GtkWidget *
409 account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
410 {
411   GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1;
412   GdkPixbuf *pix;
413
414   main_vbox = gtk_vbox_new (FALSE, 12);
415   gtk_widget_show (main_vbox);
416   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
417
418   hbox_1 = gtk_hbox_new (FALSE, 12);
419   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
420   gtk_widget_show (hbox_1);
421
422   w = gtk_label_new (
423       _("With Empathy you can chat with people\n"
424         "online nearby and with friends and colleagues\n"
425         "who use Google Talk, AIM, Windows Live\n"
426         "and many other chat programs. With a microphone\n"
427         "or a webcam you can also have audio or video calls."));
428   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
429   gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
430   gtk_widget_show (w);
431
432   pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80);
433   w = gtk_image_new_from_pixbuf (pix);
434   gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6);
435   gtk_widget_show (w);
436
437   g_object_unref (pix);
438
439   w = gtk_label_new (_("Do you have an account you've been using "
440           "with another\nchat program?"));
441   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
442   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
443   gtk_widget_show (w);
444
445   w = gtk_alignment_new (0, 0, 0, 0);
446   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
447   gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
448   gtk_widget_show (w);
449
450   vbox_1 = gtk_vbox_new (FALSE, 6);
451   gtk_container_add (GTK_CONTAINER (w), vbox_1);
452   gtk_widget_show (vbox_1);
453
454   /* TODO: this will have to be updated when kutio's branch have landed */
455   radio = gtk_radio_button_new_with_label (NULL,
456       _("Yes, import my account details from "));
457   gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0);
458   g_object_set_data (G_OBJECT (radio), "response",
459       GINT_TO_POINTER (RESPONSE_IMPORT));
460   gtk_widget_show (radio);
461
462   g_signal_connect (radio, "clicked",
463       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
464
465   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
466       _("Yes, I'll enter my account details now"));
467   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
468   g_object_set_data (G_OBJECT (w), "response",
469       GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
470   gtk_widget_show (w);
471
472   g_signal_connect (w, "clicked",
473       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
474
475   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
476       _("No, I want a new account"));
477   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
478   g_object_set_data (G_OBJECT (w), "response",
479       GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
480   gtk_widget_show (w);
481
482   g_signal_connect (w, "clicked",
483       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
484
485   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
486       _("No, I just want to see people online nearby for now"));
487   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
488   g_object_set_data (G_OBJECT (w), "response",
489       GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
490   gtk_widget_show (w);
491
492   g_signal_connect (w, "clicked",
493       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
494
495   return main_vbox;
496 }
497
498 static GtkWidget *
499 account_assistant_build_import_page (EmpathyAccountAssistant *self)
500 {
501   /* TODO: import page */
502   GtkWidget *main_vbox, *w;
503
504   main_vbox = gtk_vbox_new (FALSE, 12);
505   w = gtk_label_new ("Import your accounts!");
506   gtk_widget_show (w);
507   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
508
509   gtk_widget_show (main_vbox);
510
511   return main_vbox;
512 }
513
514 static GtkWidget *
515 account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self,
516     gboolean is_enter)
517 {
518   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
519   GtkWidget *main_vbox, *w, *chooser, *hbox;
520   PangoAttrList *list;
521
522   main_vbox = gtk_vbox_new (FALSE, 12);
523   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
524   gtk_widget_show (main_vbox);
525
526   w = gtk_label_new (NULL);
527   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
528   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
529   gtk_widget_show (w);
530   priv->first_label = w;
531
532   w = gtk_alignment_new (0, 0, 0, 0);
533   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
534   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
535   gtk_widget_show (w);
536
537   chooser = empathy_protocol_chooser_new ();
538   gtk_container_add (GTK_CONTAINER (w), chooser);
539   gtk_widget_show (chooser);
540   priv->chooser = chooser;
541
542   hbox = gtk_hbox_new (FALSE, 6);
543   gtk_box_pack_end (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
544   gtk_widget_show (hbox);
545
546   w = gtk_image_new_from_icon_name ("gtk-dialog-info", GTK_ICON_SIZE_BUTTON);
547   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
548   gtk_widget_show (w);
549
550   w = gtk_label_new (NULL);
551   gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
552   list = pango_attr_list_new ();
553   pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_SMALL));
554   gtk_label_set_attributes (GTK_LABEL (w), list);
555   gtk_widget_show (w);
556   priv->second_label = w;
557   pango_attr_list_unref (list);
558
559   return main_vbox;
560 }
561
562 static void
563 impl_signal_apply (GtkAssistant *assistant)
564 {
565   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
566   gint current_page;
567
568   current_page = gtk_assistant_get_current_page (assistant);
569
570   if (current_page == RESPONSE_ENTER_ACCOUNT)
571     account_assistant_apply_account_and_finish (self);
572 }
573
574 static void
575 impl_signal_close (GtkAssistant *assistant)
576 {
577   gtk_widget_destroy (GTK_WIDGET (assistant));
578 }
579
580 static void
581 impl_signal_cancel (GtkAssistant *assistant)
582 {
583   gtk_widget_destroy (GTK_WIDGET (assistant));
584 }
585
586 static void
587 impl_signal_prepare (GtkAssistant *assistant,
588     GtkWidget *current_page)
589 {
590   EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
591   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
592   gint current_idx;
593
594   current_idx = gtk_assistant_get_current_page (assistant);
595
596   g_print ("prepare, current idx = %d\n", current_idx);
597
598   if (current_idx == PAGE_ENTER_CREATE)
599     {
600       account_assistant_finish_enter_or_create_page (self,
601           priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
602           TRUE : FALSE);
603     }
604 }
605
606 static void
607 do_get_property (GObject *object,
608     guint property_id,
609     GValue *value,
610     GParamSpec *pspec)
611 {
612   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
613
614   switch (property_id)
615     {
616     case PROP_PARENT:
617       g_value_set_object (value, priv->parent_window);
618       break;
619     default:
620       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
621     }
622 }
623
624 static void
625 do_set_property (GObject *object,
626     guint property_id,
627     const GValue *value,
628     GParamSpec *pspec)
629 {
630   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
631
632   switch (property_id)
633     {
634     case PROP_PARENT:
635       priv->parent_window = g_value_get_object (value);
636       break;
637     default:
638       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
639     }
640 }
641
642 static void
643 do_constructed (GObject *object)
644 {
645   EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
646
647   /* set us as transient for the parent window if any */
648   if (priv->parent_window)
649     gtk_window_set_transient_for (GTK_WINDOW (object),
650         priv->parent_window);
651
652   /* set the dialog hint, so this will be centered over the parent window */
653   gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
654 }
655
656 static void
657 do_dispose (GObject *obj)
658 {
659   EmpathyAccountAssistantPriv *priv = GET_PRIV (obj);
660
661   if (priv->dispose_run)
662     return;
663
664   priv->dispose_run = TRUE;
665
666   if (priv->settings != NULL)
667     {
668       g_object_unref (priv->settings);
669       priv->settings = NULL;
670     }
671
672   if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL)
673     G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj);
674 }
675
676 static void
677 empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
678 {
679   GObjectClass *oclass = G_OBJECT_CLASS (klass);
680   GtkAssistantClass *gtkclass = GTK_ASSISTANT_CLASS (klass);
681   GParamSpec *param_spec;
682
683   oclass->get_property = do_get_property;
684   oclass->set_property = do_set_property;
685   oclass->constructed = do_constructed;
686   oclass->dispose = do_dispose;
687
688   gtkclass->apply = impl_signal_apply;
689   gtkclass->prepare = impl_signal_prepare;
690   gtkclass->close = impl_signal_close;
691   gtkclass->cancel = impl_signal_cancel;
692
693   param_spec = g_param_spec_object ("parent-window",
694       "parent-window", "The parent window",
695       GTK_TYPE_WINDOW,
696       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
697   g_object_class_install_property (oclass, PROP_PARENT, param_spec);
698
699   g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
700 }
701
702 static void
703 empathy_account_assistant_init (EmpathyAccountAssistant *self)
704 {
705   EmpathyAccountAssistantPriv *priv;
706   GtkAssistant *assistant = GTK_ASSISTANT (self);
707   GtkWidget *page;
708
709   priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
710       EmpathyAccountAssistantPriv);
711   self->priv = priv;
712
713   gtk_assistant_set_forward_page_func (assistant,
714       account_assistant_page_forward_func, self, NULL);
715
716   /* first page (introduction) */
717   page = account_assistant_build_introduction_page (self);
718   gtk_assistant_append_page (assistant, page);
719   gtk_assistant_set_page_title (assistant, page,
720       _("Welcome to Empathy"));
721   gtk_assistant_set_page_type (assistant, page,
722       GTK_ASSISTANT_PAGE_INTRO);
723   gtk_assistant_set_page_complete (assistant, page, TRUE);
724
725   /* set a default answer */
726   priv->first_resp = RESPONSE_IMPORT;
727
728   /* second page (import accounts) */
729   page = account_assistant_build_import_page (self);
730   gtk_assistant_append_page (assistant, page);
731   gtk_assistant_set_page_title (assistant, page,
732       _("Import your existing accounts"));
733   gtk_assistant_set_page_complete (assistant, page, TRUE);
734
735   /* third page (enter account details) */
736   page = account_assistant_build_enter_or_create_page (self, TRUE);
737   gtk_assistant_append_page (assistant, page);
738   gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
739   priv->enter_or_create_page = page;
740 }
741
742 GtkWidget *
743 empathy_account_assistant_new (GtkWindow *window)
744 {
745   return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, "parent-window",
746       window, NULL);
747 }