2 * Copyright (C) 2009 Collabora Ltd.
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.
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.
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
18 * Authors: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
21 /* empathy-account-assistant.c */
23 #include <glib/gi18n.h>
24 #include <telepathy-glib/util.h>
25 #include <gdk/gdkkeysyms.h>
27 #include "empathy-account-assistant.h"
28 #include "empathy-import-widget.h"
29 #include "empathy-import-utils.h"
31 #include <libempathy/empathy-account-settings.h>
32 #include <libempathy/empathy-utils.h>
34 #include <libempathy-gtk/empathy-account-widget.h>
35 #include <libempathy-gtk/empathy-protocol-chooser.h>
36 #include <libempathy-gtk/empathy-ui-utils.h>
38 G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant,
41 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountAssistant)
45 RESPONSE_ENTER_ACCOUNT = 2,
46 RESPONSE_CREATE_ACCOUNT = 3,
47 RESPONSE_SALUT_ONLY = 4
51 RESPONSE_CREATE_AGAIN = 1,
52 RESPONSE_CREATE_STOP = 2
53 } CreateEnterPageResponse;
58 PAGE_ENTER_CREATE = 2,
66 FirstPageResponse first_resp;
67 CreateEnterPageResponse create_enter_resp;
68 gboolean enter_create_forward;
70 /* enter or create page */
71 GtkWidget *enter_or_create_page;
72 GtkWidget *current_account_widget;
73 EmpathyAccountWidget *current_widget_object;
74 GtkWidget *first_label;
75 GtkWidget *second_label;
77 GtkWidget *create_again_radio;
78 EmpathyAccountSettings *settings;
82 EmpathyImportWidget *iw;
84 GtkWindow *parent_window;
87 } EmpathyAccountAssistantPriv;
89 static GtkWidget * account_assistant_build_enter_or_create_page (
90 EmpathyAccountAssistant *self);
91 static void account_assistant_finish_enter_or_create_page (
92 EmpathyAccountAssistant *self,
96 account_assistant_build_error_page (EmpathyAccountAssistant *self,
97 GError *error, gint page_num)
99 GtkWidget *main_vbox, *w, *hbox;
102 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
104 main_vbox = gtk_vbox_new (FALSE, 12);
105 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
106 gtk_widget_show (main_vbox);
108 hbox = gtk_hbox_new (FALSE, 12);
109 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
110 gtk_widget_show (hbox);
112 w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
113 GTK_ICON_SIZE_DIALOG);
114 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
117 if (page_num == PAGE_IMPORT)
118 message = _("There has been an error while importing the accounts.");
119 else if (page_num >= PAGE_ENTER_CREATE &&
120 priv->first_resp == RESPONSE_ENTER_ACCOUNT)
121 message = _("There has been an error while parsing the account details.");
122 else if (page_num >= PAGE_ENTER_CREATE &&
123 priv->first_resp == RESPONSE_CREATE_ACCOUNT)
124 message = _("There has been an error while creating the account.");
126 message = _("There has been an error.");
128 w = gtk_label_new (message);
129 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
130 list = pango_attr_list_new ();
131 pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_LARGE));
132 pango_attr_list_insert (list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
133 gtk_label_set_attributes (GTK_LABEL (w), list);
134 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
135 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
138 pango_attr_list_unref (list);
140 message = g_markup_printf_escaped
141 (_("The error message was: <span style=\"italic\">%s</span>"),
143 w = gtk_label_new (message);
144 gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
145 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
146 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
149 w = gtk_label_new (_("You can either go back and try to enter your "
150 "accounts' details again or quit this assistant and add accounts "
151 "later from the Edit menu."));
152 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
153 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
154 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
161 account_assistant_back_button_clicked_cb (GtkButton *button,
162 EmpathyAccountAssistant *self)
166 page_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
168 gtk_assistant_remove_action_widget (GTK_ASSISTANT (self),
169 GTK_WIDGET (button));
170 gtk_assistant_set_current_page (GTK_ASSISTANT (self), page_num);
174 account_assistant_present_error_page (EmpathyAccountAssistant *self,
175 GError *error, gint page_num)
177 GtkWidget *error_page, *back_button;
180 error_page = account_assistant_build_error_page (self, error,
182 num = gtk_assistant_append_page (GTK_ASSISTANT (self), error_page);
183 gtk_assistant_set_page_title (GTK_ASSISTANT (self), error_page,
184 _("An error occurred"));
185 gtk_assistant_set_page_type (GTK_ASSISTANT (self), error_page,
186 GTK_ASSISTANT_PAGE_SUMMARY);
188 back_button = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
189 gtk_assistant_add_action_widget (GTK_ASSISTANT (self), back_button);
190 g_object_set_data (G_OBJECT (back_button),
191 "page-num", GINT_TO_POINTER (page_num));
192 g_signal_connect (back_button, "clicked",
193 G_CALLBACK (account_assistant_back_button_clicked_cb), self);
194 gtk_widget_show (back_button);
196 gtk_assistant_set_current_page (GTK_ASSISTANT (self), num);
200 account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
202 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
206 page = account_assistant_build_enter_or_create_page (self);
207 idx = gtk_assistant_append_page (GTK_ASSISTANT (self), page);
208 gtk_assistant_set_page_type (GTK_ASSISTANT (self), page,
209 GTK_ASSISTANT_PAGE_CONFIRM);
210 priv->enter_or_create_page = page;
212 gtk_assistant_set_current_page (GTK_ASSISTANT (self), idx);
214 account_assistant_finish_enter_or_create_page (self,
215 priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
220 account_assistant_account_enabled_cb (GObject *source,
221 GAsyncResult *result,
224 GError *error = NULL;
225 EmpathyAccountAssistant *self = user_data;
226 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
228 empathy_account_set_enabled_finish (EMPATHY_ACCOUNT (source),
233 g_warning ("Error enabling an account: %s", error->message);
234 g_error_free (error);
237 if (priv->create_enter_resp == RESPONSE_CREATE_STOP)
238 g_signal_emit_by_name (self, "close");
240 account_assistant_reset_enter_create_page (self);
244 account_assistant_apply_account_cb (GObject *source,
245 GAsyncResult *result,
248 GError *error = NULL;
249 EmpathyAccountAssistant *self = user_data;
250 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
251 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
252 EmpathyAccount *account;
254 empathy_account_settings_apply_finish (settings, result, &error);
256 priv->is_creating = FALSE;
260 account_assistant_present_error_page (self, error,
261 gtk_assistant_get_current_page (GTK_ASSISTANT (self)));
262 g_error_free (error);
266 /* enable the newly created account */
267 account = empathy_account_settings_get_account (settings);
268 empathy_account_set_enabled_async (account, TRUE,
269 account_assistant_account_enabled_cb, self);
273 account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self)
275 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
277 if (priv->settings == NULL)
280 priv->is_creating = TRUE;
282 empathy_account_settings_apply_async (priv->settings,
283 account_assistant_apply_account_cb, self);
287 account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object,
289 EmpathyAccountAssistant *self)
291 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
293 gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
294 priv->enter_or_create_page, is_valid);
298 account_assistant_protocol_changed_cb (GtkComboBox *chooser,
299 EmpathyAccountAssistant *self)
301 TpConnectionManager *cm;
302 TpConnectionManagerProtocol *proto;
303 EmpathyAccountSettings *settings;
304 EmpathyAccountAssistantPriv *priv;
306 GtkWidget *account_widget;
307 EmpathyAccountWidget *widget_object = NULL;
310 priv = GET_PRIV (self);
312 cm = empathy_protocol_chooser_dup_selected (
313 EMPATHY_PROTOCOL_CHOOSER (chooser), &proto, &is_gtalk);
315 if (cm == NULL || proto == NULL)
316 /* we are not ready yet */
320 /* To translator: %s is the protocol name */
321 str = g_strdup_printf (_("New %s account"),
322 empathy_protocol_name_to_display_name (
323 is_gtalk ? "gtalk" : proto->name));
325 settings = empathy_account_settings_new (cm->name, proto->name, str);
328 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
331 if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
332 empathy_account_settings_set_boolean (settings, "register", TRUE);
334 widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
335 account_widget = empathy_account_widget_get_widget (widget_object);
337 if (priv->current_account_widget != NULL)
339 g_signal_handlers_disconnect_by_func (priv->current_widget_object,
340 account_assistant_handle_apply_cb, self);
341 gtk_widget_destroy (priv->current_account_widget);
344 priv->current_account_widget = account_widget;
345 priv->current_widget_object = widget_object;
347 if (priv->settings != NULL)
348 g_object_unref (priv->settings);
350 priv->settings = settings;
352 g_signal_connect (priv->current_widget_object, "handle-apply",
353 G_CALLBACK (account_assistant_handle_apply_cb), self);
355 gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
357 gtk_widget_show (account_widget);
363 account_assistant_chooser_enter_details_filter_func (
364 TpConnectionManager *cm,
365 TpConnectionManagerProtocol *protocol,
368 if (!tp_strdiff (protocol->name, "local-xmpp") ||
369 !tp_strdiff (protocol->name, "irc"))
376 account_assistant_chooser_create_account_filter_func (
377 TpConnectionManager *cm,
378 TpConnectionManagerProtocol *protocol,
381 return tp_connection_manager_protocol_can_register (protocol);
385 account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self,
388 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
392 gtk_label_set_label (GTK_LABEL (priv->first_label),
393 _("What kind of chat account do you have?"));
394 /* gtk_label_set_label (GTK_LABEL (priv->second_label),
395 _("If you have other accounts to set up, you can do "
396 "that at any time from the Edit menu."));
398 gtk_label_set_label (GTK_LABEL (priv->second_label),
399 _("Do you have any other chat accounts you want to set up?"));
400 empathy_protocol_chooser_set_visible (
401 EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
402 account_assistant_chooser_enter_details_filter_func, self);
404 gtk_assistant_set_page_title (GTK_ASSISTANT (self),
405 priv->enter_or_create_page, _("Enter your account details"));
409 gtk_label_set_label (GTK_LABEL (priv->first_label),
410 _("What kind of chat account do you want to create?"));
411 /* gtk_label_set_label (GTK_LABEL (priv->second_label),
412 _("You can register other accounts, or setup "
413 "an existing one at any time from the Edit menu."));
415 gtk_label_set_label (GTK_LABEL (priv->second_label),
416 _("Do you want to create other chat accounts?"));
417 empathy_protocol_chooser_set_visible (
418 EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
419 account_assistant_chooser_create_account_filter_func, self);
421 gtk_assistant_set_page_title (GTK_ASSISTANT (self),
422 priv->enter_or_create_page,
423 _("Enter the details for the new account"));
426 g_signal_connect (priv->chooser, "changed",
427 G_CALLBACK (account_assistant_protocol_changed_cb), self);
429 /* trigger show the first account widget */
430 account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self);
434 account_assistant_page_forward_func (gint current_page,
437 EmpathyAccountAssistant *self = user_data;
438 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
441 retval = current_page;
443 if (current_page == PAGE_INTRO)
445 if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
446 priv->first_resp == RESPONSE_CREATE_ACCOUNT)
447 retval = PAGE_ENTER_CREATE;
448 if (priv->first_resp == RESPONSE_IMPORT)
449 retval = PAGE_IMPORT;
452 if (current_page == PAGE_IMPORT ||
453 current_page >= PAGE_ENTER_CREATE)
454 /* don't forward anymore */
457 if (current_page >= PAGE_ENTER_CREATE &&
458 priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
460 priv->enter_create_forward = TRUE;
461 retval = current_page;
468 account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
469 EmpathyAccountAssistant *self)
471 FirstPageResponse response;
472 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
473 GtkWidget *intro_page;
475 response = GPOINTER_TO_INT (g_object_get_data
476 (G_OBJECT (button), "response"));
478 priv->first_resp = response;
480 intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self),
483 if (response == RESPONSE_SALUT_ONLY)
484 gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
485 GTK_ASSISTANT_PAGE_SUMMARY);
487 gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
488 GTK_ASSISTANT_PAGE_INTRO);
492 account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
494 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
495 GtkWidget *main_vbox, *hbox_1, *w, *vbox_1;
496 GtkWidget *radio = NULL;
500 main_vbox = gtk_vbox_new (FALSE, 12);
501 gtk_widget_show (main_vbox);
502 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
504 hbox_1 = gtk_hbox_new (FALSE, 12);
505 gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
506 gtk_widget_show (hbox_1);
509 _("With Empathy you can chat with people "
510 "online nearby and with friends and colleagues "
511 "who use Google Talk, AIM, Windows Live "
512 "and many other chat programs. With a microphone "
513 "or a webcam you can also have audio or video calls."));
514 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
515 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
516 gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
519 pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80);
520 w = gtk_image_new_from_pixbuf (pix);
521 gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
524 g_object_unref (pix);
526 w = gtk_label_new (_("Do you have an account you've been using "
527 "with another chat program?"));
528 gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
529 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
530 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
533 w = gtk_alignment_new (0, 0, 0, 0);
534 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
535 gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
538 vbox_1 = gtk_vbox_new (TRUE, 0);
539 gtk_container_add (GTK_CONTAINER (w), vbox_1);
540 gtk_widget_show (vbox_1);
542 if (empathy_import_accounts_to_import ())
544 hbox_1 = gtk_hbox_new (FALSE, 0);
545 gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0);
546 gtk_widget_show (hbox_1);
548 radio = gtk_radio_button_new_with_label (NULL,
549 _("Yes, import my account details from "));
550 gtk_box_pack_start (GTK_BOX (hbox_1), radio, TRUE, TRUE, 0);
551 g_object_set_data (G_OBJECT (radio), "response",
552 GINT_TO_POINTER (RESPONSE_IMPORT));
553 gtk_widget_show (radio);
555 w = gtk_combo_box_new_text ();
556 gtk_combo_box_append_text (GTK_COMBO_BOX (w), "Pidgin");
557 gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
558 gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0);
561 g_signal_connect (radio, "clicked",
562 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
563 priv->first_resp = RESPONSE_IMPORT;
567 priv->first_resp = RESPONSE_ENTER_ACCOUNT;
570 str = _("Yes, I'll enter my account details now");
574 radio = gtk_radio_button_new_with_label (NULL, str);
579 w = gtk_radio_button_new_with_label_from_widget (
580 GTK_RADIO_BUTTON (radio), str);
583 gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
584 g_object_set_data (G_OBJECT (w), "response",
585 GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
588 g_signal_connect (w, "clicked",
589 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
591 w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
592 _("No, I want a new account"));
593 gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
594 g_object_set_data (G_OBJECT (w), "response",
595 GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
598 g_signal_connect (w, "clicked",
599 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
601 w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
602 _("No, I just want to see people online nearby for now"));
603 gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
604 g_object_set_data (G_OBJECT (w), "response",
605 GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
608 g_signal_connect (w, "clicked",
609 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
615 account_assistant_build_import_page (EmpathyAccountAssistant *self)
617 GtkWidget *main_vbox, *w, *import;
618 EmpathyImportWidget *iw;
619 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
621 main_vbox = gtk_vbox_new (FALSE, 12);
622 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
623 w = gtk_label_new (_("Select the accounts you want to import:"));
624 gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
626 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
628 w = gtk_alignment_new (0, 0, 0, 0);
629 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
630 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
633 /* NOTE: this is hardcoded as we support pidgin only */
634 iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN);
635 import = empathy_import_widget_get_widget (iw);
636 gtk_container_add (GTK_CONTAINER (w), import);
637 gtk_widget_show (import);
641 gtk_widget_show (main_vbox);
647 account_assistant_radio_create_again_clicked_cb (GtkButton *button,
648 EmpathyAccountAssistant *self)
650 CreateEnterPageResponse response;
651 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
653 response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
656 priv->create_enter_resp = response;
658 gtk_assistant_set_page_type (GTK_ASSISTANT (self),
659 priv->enter_or_create_page,
660 (response == RESPONSE_CREATE_AGAIN) ?
661 GTK_ASSISTANT_PAGE_CONTENT : GTK_ASSISTANT_PAGE_CONFIRM);
665 account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self)
667 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
668 GtkWidget *main_vbox, *w, *chooser, *vbox, *hbox, *radio;
670 main_vbox = gtk_vbox_new (FALSE, 12);
671 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
672 gtk_widget_show (main_vbox);
674 w = gtk_label_new (NULL);
675 gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
676 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
678 priv->first_label = w;
680 w = gtk_alignment_new (0, 0, 0, 0);
681 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
682 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
685 chooser = empathy_protocol_chooser_new ();
686 gtk_container_add (GTK_CONTAINER (w), chooser);
687 gtk_widget_show (chooser);
688 priv->chooser = chooser;
690 vbox = gtk_vbox_new (FALSE, 6);
691 gtk_box_pack_end (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
692 gtk_widget_show (vbox);
694 w = gtk_label_new (NULL);
695 gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
696 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
697 gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
699 priv->second_label = w;
701 w = gtk_alignment_new (0, 0, 0, 0);
702 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
703 gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
706 hbox = gtk_hbox_new (FALSE, 6);
707 gtk_container_add (GTK_CONTAINER (w), hbox);
708 gtk_widget_show (hbox);
710 radio = gtk_radio_button_new_with_label (NULL, _("Yes"));
711 gtk_box_pack_start (GTK_BOX (hbox), radio, FALSE, FALSE, 0);
712 g_object_set_data (G_OBJECT (radio), "response",
713 GINT_TO_POINTER (RESPONSE_CREATE_AGAIN));
714 gtk_widget_show (radio);
716 w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
717 _("No, that's all for now"));
718 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
719 g_object_set_data (G_OBJECT (w), "response",
720 GINT_TO_POINTER (RESPONSE_CREATE_STOP));
721 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
722 priv->create_enter_resp = RESPONSE_CREATE_STOP;
723 priv->create_again_radio = w;
726 g_signal_connect (w, "clicked",
727 G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
728 g_signal_connect (radio, "clicked",
729 G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
735 account_assistant_close_cb (GtkAssistant *assistant,
738 EmpathyAccountAssistantPriv *priv = GET_PRIV (assistant);
740 if (priv->is_creating)
743 gtk_widget_destroy (GTK_WIDGET (assistant));
747 impl_signal_apply (GtkAssistant *assistant)
749 EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
750 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
753 current_page = gtk_assistant_get_current_page (assistant);
755 if (current_page >= PAGE_ENTER_CREATE)
756 account_assistant_apply_account_and_finish (self);
758 if (current_page == PAGE_IMPORT)
759 empathy_import_widget_add_selected_accounts (priv->iw);
763 impl_signal_cancel (GtkAssistant *assistant)
765 gtk_widget_destroy (GTK_WIDGET (assistant));
769 impl_signal_prepare (GtkAssistant *assistant,
770 GtkWidget *current_page)
772 EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
773 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
776 current_idx = gtk_assistant_get_current_page (assistant);
778 if (current_idx >= PAGE_ENTER_CREATE)
780 if (!priv->enter_create_forward)
782 account_assistant_finish_enter_or_create_page (self,
783 priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
788 priv->enter_create_forward = FALSE;
789 account_assistant_apply_account_and_finish (self);
795 do_get_property (GObject *object,
800 EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
805 g_value_set_object (value, priv->parent_window);
808 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
813 do_set_property (GObject *object,
818 EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
823 priv->parent_window = g_value_get_object (value);
826 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
831 do_constructed (GObject *object)
833 EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
835 /* set us as transient for the parent window if any */
836 if (priv->parent_window)
837 gtk_window_set_transient_for (GTK_WINDOW (object),
838 priv->parent_window);
840 /* set the dialog hint, so this will be centered over the parent window */
841 gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
845 do_dispose (GObject *obj)
847 EmpathyAccountAssistantPriv *priv = GET_PRIV (obj);
849 if (priv->dispose_run)
852 priv->dispose_run = TRUE;
854 if (priv->settings != NULL)
856 g_object_unref (priv->settings);
857 priv->settings = NULL;
860 if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL)
861 G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj);
865 empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
867 GObjectClass *oclass = G_OBJECT_CLASS (klass);
868 GtkAssistantClass *gtkclass = GTK_ASSISTANT_CLASS (klass);
869 GParamSpec *param_spec;
871 oclass->get_property = do_get_property;
872 oclass->set_property = do_set_property;
873 oclass->constructed = do_constructed;
874 oclass->dispose = do_dispose;
876 gtkclass->apply = impl_signal_apply;
877 gtkclass->prepare = impl_signal_prepare;
878 gtkclass->cancel = impl_signal_cancel;
880 param_spec = g_param_spec_object ("parent-window",
881 "parent-window", "The parent window",
883 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
884 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
886 g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
890 empathy_account_assistant_init (EmpathyAccountAssistant *self)
892 EmpathyAccountAssistantPriv *priv;
893 GtkAssistant *assistant = GTK_ASSISTANT (self);
896 priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
897 EmpathyAccountAssistantPriv);
900 g_signal_connect (self, "close",
901 G_CALLBACK (account_assistant_close_cb), NULL);
903 gtk_assistant_set_forward_page_func (assistant,
904 account_assistant_page_forward_func, self, NULL);
906 /* first page (introduction) */
907 page = account_assistant_build_introduction_page (self);
908 gtk_assistant_append_page (assistant, page);
909 gtk_assistant_set_page_title (assistant, page,
910 _("Welcome to Empathy"));
911 gtk_assistant_set_page_type (assistant, page,
912 GTK_ASSISTANT_PAGE_INTRO);
913 gtk_assistant_set_page_complete (assistant, page, TRUE);
915 /* second page (import accounts) */
916 page = account_assistant_build_import_page (self);
917 gtk_assistant_append_page (assistant, page);
918 gtk_assistant_set_page_title (assistant, page,
919 _("Import your existing accounts"));
920 gtk_assistant_set_page_complete (assistant, page, TRUE);
921 gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
923 /* third page (enter account details) */
924 page = account_assistant_build_enter_or_create_page (self);
925 gtk_assistant_append_page (assistant, page);
926 gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
927 priv->enter_or_create_page = page;
929 gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
933 empathy_account_assistant_show (GtkWindow *window)
935 static GtkWidget *dialog = NULL;
939 dialog = g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, "parent-window",
941 g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &dialog);
944 gtk_window_present (GTK_WINDOW (dialog));