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 */
24 #include <glib/gi18n-lib.h>
25 #include <telepathy-glib/util.h>
26 #include <gdk/gdkkeysyms.h>
28 #include "empathy-account-assistant.h"
29 #include "empathy-import-widget.h"
30 #include "empathy-import-utils.h"
31 #include "empathy-auto-salut-account-helper.h"
33 #include <libempathy/empathy-account-settings.h>
34 #include <libempathy/empathy-utils.h>
36 #include <libempathy-gtk/empathy-account-widget.h>
37 #include <libempathy-gtk/empathy-protocol-chooser.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
40 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
41 #include <libempathy/empathy-debug.h>
43 G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant,
46 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountAssistant)
50 RESPONSE_ENTER_ACCOUNT = 2,
51 RESPONSE_CREATE_ACCOUNT = 3,
52 RESPONSE_SALUT_ONLY = 4
56 RESPONSE_CREATE_AGAIN = 1,
57 RESPONSE_CREATE_STOP = 2
58 } CreateEnterPageResponse;
63 PAGE_ENTER_CREATE = 2,
73 FirstPageResponse first_resp;
74 CreateEnterPageResponse create_enter_resp;
75 gboolean enter_create_forward;
76 TpAccountManager *account_mgr;
77 EmpathyConnectionManagers *connection_mgrs;
78 PageID current_page_id;
80 /* enter or create page */
81 GtkWidget *enter_or_create_page;
82 GtkWidget *current_account_widget;
83 EmpathyAccountWidget *current_widget_object;
84 GtkWidget *first_label;
85 GtkWidget *second_label;
87 GtkWidget *create_again_radio;
88 EmpathyAccountSettings *settings;
92 EmpathyImportWidget *iw;
93 GtkWidget *import_page;
96 GtkWidget *salut_page;
97 EmpathyAccountSettings *salut_settings;
98 GtkWidget *salut_account_widget;
99 gboolean create_salut_account;
100 gboolean display_salut_page;
102 GtkWindow *parent_window;
104 gboolean dispose_run;
105 } EmpathyAccountAssistantPriv;
107 static GtkWidget * account_assistant_build_enter_or_create_page (
108 EmpathyAccountAssistant *self);
109 static void account_assistant_finish_enter_or_create_page (
110 EmpathyAccountAssistant *self,
113 static void do_constructed (GObject *object);
116 build_error_vbox (const gchar *primary_message,
117 const gchar *secondary_message)
119 GtkWidget *main_vbox, *w, *hbox;
122 main_vbox = gtk_vbox_new (FALSE, 12);
123 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
124 gtk_widget_show (main_vbox);
126 hbox = gtk_hbox_new (FALSE, 12);
127 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
128 gtk_widget_show (hbox);
130 w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
131 GTK_ICON_SIZE_DIALOG);
132 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
135 w = gtk_label_new (primary_message);
136 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
137 list = pango_attr_list_new ();
138 pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_LARGE));
139 pango_attr_list_insert (list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
140 gtk_label_set_attributes (GTK_LABEL (w), list);
141 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
142 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
145 pango_attr_list_unref (list);
147 w = gtk_label_new (secondary_message);
148 gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
149 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
150 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
151 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
158 account_assistant_build_error_page (EmpathyAccountAssistant *self,
159 GError *error, gint page_num)
161 GtkWidget *main_vbox, *w;
162 const char *primary_message;
163 gchar *secondary_message, *markup;
164 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
166 if (page_num == PAGE_IMPORT)
167 primary_message = _("There was an error while importing the accounts.");
168 else if (page_num >= PAGE_ENTER_CREATE &&
169 priv->first_resp == RESPONSE_ENTER_ACCOUNT)
170 primary_message = _("There was an error while parsing the account details.");
171 else if (page_num >= PAGE_ENTER_CREATE &&
172 priv->first_resp == RESPONSE_CREATE_ACCOUNT)
173 primary_message = _("There was an error while creating the account.");
175 primary_message = _("There was an error.");
177 markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>",
179 secondary_message = g_strdup_printf (_("The error message was: %s"), markup);
181 main_vbox = build_error_vbox (primary_message, secondary_message);
183 w = gtk_label_new (_("You can either go back and try to enter your "
184 "accounts' details again or quit this assistant and add accounts "
185 "later from the Edit menu."));
186 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
187 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
188 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
192 g_free (secondary_message);
197 account_assistant_back_button_clicked_cb (GtkButton *button,
198 EmpathyAccountAssistant *self)
202 page_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
204 gtk_assistant_remove_action_widget (GTK_ASSISTANT (self),
205 GTK_WIDGET (button));
206 gtk_assistant_set_current_page (GTK_ASSISTANT (self), page_num);
210 account_assistant_present_error_page (EmpathyAccountAssistant *self,
211 GError *error, gint page_num)
213 GtkWidget *error_page, *back_button;
216 error_page = account_assistant_build_error_page (self, error,
218 num = gtk_assistant_append_page (GTK_ASSISTANT (self), error_page);
219 gtk_assistant_set_page_title (GTK_ASSISTANT (self), error_page,
220 _("An error occurred"));
221 gtk_assistant_set_page_type (GTK_ASSISTANT (self), error_page,
222 GTK_ASSISTANT_PAGE_SUMMARY);
224 back_button = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
225 gtk_assistant_add_action_widget (GTK_ASSISTANT (self), back_button);
226 g_object_set_data (G_OBJECT (back_button),
227 "page-num", GINT_TO_POINTER (page_num));
228 g_signal_connect (back_button, "clicked",
229 G_CALLBACK (account_assistant_back_button_clicked_cb), self);
230 gtk_widget_show (back_button);
232 gtk_assistant_set_current_page (GTK_ASSISTANT (self), num);
236 update_create_page_buttons (EmpathyAccountAssistant *self)
238 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
239 GtkAssistantPageType type;
241 if (priv->display_salut_page ||
242 priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
243 type = GTK_ASSISTANT_PAGE_CONTENT;
245 type = GTK_ASSISTANT_PAGE_CONFIRM;
247 gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->enter_or_create_page,
252 account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
254 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
258 page = account_assistant_build_enter_or_create_page (self);
259 idx = gtk_assistant_append_page (GTK_ASSISTANT (self), page);
260 priv->enter_or_create_page = page;
261 update_create_page_buttons (self);
263 gtk_assistant_set_current_page (GTK_ASSISTANT (self), idx);
265 account_assistant_finish_enter_or_create_page (self,
266 priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
271 account_assistant_account_enabled_cb (GObject *source,
272 GAsyncResult *result,
275 GError *error = NULL;
276 EmpathyAccountAssistant *self = user_data;
277 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
278 const gchar *protocol;
279 TpAccount *account = TP_ACCOUNT (source);
281 gboolean salut_created = FALSE;
283 tp_account_set_enabled_finish (account, result, &error);
287 g_warning ("Error enabling an account: %s", error->message);
288 g_error_free (error);
291 protocol = tp_account_get_protocol (account);
292 if (!tp_strdiff (protocol, "local-xmpp"))
294 salut_created = TRUE;
297 empathy_connect_new_account (account, priv->account_mgr);
299 current_idx = gtk_assistant_get_current_page (GTK_ASSISTANT (self));
300 if (current_idx == PAGE_SALUT && !salut_created)
301 /* We are on the Salut page and aren't creating the salut account so don't
302 * terminate the assistant. */
305 if (priv->create_enter_resp == RESPONSE_CREATE_STOP)
306 g_signal_emit_by_name (self, "close");
308 account_assistant_reset_enter_create_page (self);
312 account_assistant_apply_account_cb (GObject *source,
313 GAsyncResult *result,
316 GError *error = NULL;
317 EmpathyAccountAssistant *self = user_data;
318 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
319 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
322 empathy_account_settings_apply_finish (settings, result, NULL, &error);
324 priv->is_creating = FALSE;
328 account_assistant_present_error_page (self, error,
329 gtk_assistant_get_current_page (GTK_ASSISTANT (self)));
330 g_error_free (error);
334 /* enable the newly created account */
335 account = empathy_account_settings_get_account (settings);
336 tp_account_set_enabled_async (account, TRUE,
337 account_assistant_account_enabled_cb, self);
341 account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self,
342 EmpathyAccountSettings *settings,
343 gboolean set_display_name)
345 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
347 if (settings == NULL)
350 priv->is_creating = TRUE;
352 if (set_display_name)
356 display_name = empathy_account_widget_get_default_display_name (
357 priv->current_widget_object);
359 empathy_account_settings_set_display_name_async (settings,
360 display_name, NULL, NULL);
362 g_free (display_name);
365 empathy_account_settings_apply_async (settings,
366 account_assistant_apply_account_cb, self);
370 account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object,
372 EmpathyAccountAssistant *self)
374 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
376 gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
377 priv->enter_or_create_page, is_valid);
381 account_assistant_protocol_changed_cb (GtkComboBox *chooser,
382 EmpathyAccountAssistant *self)
384 EmpathyAccountSettings *settings;
385 EmpathyAccountAssistantPriv *priv;
386 GtkWidget *account_widget;
387 EmpathyAccountWidget *widget_object = NULL;
389 priv = GET_PRIV (self);
391 settings = empathy_protocol_chooser_create_account_settings (
392 EMPATHY_PROTOCOL_CHOOSER (chooser));
394 if (settings == NULL)
397 if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
398 empathy_account_settings_set_boolean (settings, "register", TRUE);
400 widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
401 account_widget = empathy_account_widget_get_widget (widget_object);
403 if (priv->current_account_widget != NULL)
405 g_signal_handlers_disconnect_by_func (priv->current_widget_object,
406 account_assistant_handle_apply_cb, self);
407 gtk_widget_destroy (priv->current_account_widget);
410 priv->current_account_widget = account_widget;
411 priv->current_widget_object = widget_object;
413 if (priv->settings != NULL)
414 g_object_unref (priv->settings);
416 priv->settings = settings;
418 g_signal_connect (priv->current_widget_object, "handle-apply",
419 G_CALLBACK (account_assistant_handle_apply_cb), self);
421 if (empathy_account_settings_is_valid (settings))
423 gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
424 priv->enter_or_create_page, TRUE);
427 gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
429 gtk_widget_show (account_widget);
433 account_assistant_chooser_enter_details_filter_func (
434 TpConnectionManager *cm,
435 TpConnectionManagerProtocol *protocol,
436 const gchar *service,
439 if (!tp_strdiff (protocol->name, "local-xmpp"))
446 account_assistant_chooser_create_account_filter_func (
447 TpConnectionManager *cm,
448 TpConnectionManagerProtocol *protocol,
449 const gchar *service,
455 return tp_connection_manager_protocol_can_register (protocol);
459 account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self,
462 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
466 gtk_label_set_label (GTK_LABEL (priv->first_label),
467 _("What kind of chat account do you have?"));
468 /* gtk_label_set_label (GTK_LABEL (priv->second_label),
469 _("If you have other accounts to set up, you can do "
470 "that at any time from the Edit menu."));
472 gtk_label_set_label (GTK_LABEL (priv->second_label),
473 _("Do you have any other chat accounts you want to set up?"));
474 empathy_protocol_chooser_set_visible (
475 EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
476 account_assistant_chooser_enter_details_filter_func, self);
478 gtk_assistant_set_page_title (GTK_ASSISTANT (self),
479 priv->enter_or_create_page, _("Enter your account details"));
483 gtk_label_set_label (GTK_LABEL (priv->first_label),
484 _("What kind of chat account do you want to create?"));
485 /* gtk_label_set_label (GTK_LABEL (priv->second_label),
486 _("You can register other accounts, or setup "
487 "an existing one at any time from the Edit menu."));
489 gtk_label_set_label (GTK_LABEL (priv->second_label),
490 _("Do you want to create other chat accounts?"));
491 empathy_protocol_chooser_set_visible (
492 EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
493 account_assistant_chooser_create_account_filter_func, self);
495 gtk_assistant_set_page_title (GTK_ASSISTANT (self),
496 priv->enter_or_create_page,
497 _("Enter the details for the new account"));
500 g_signal_connect (priv->chooser, "changed",
501 G_CALLBACK (account_assistant_protocol_changed_cb), self);
503 /* trigger show the first account widget */
504 account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self);
508 account_assistant_page_forward_func (gint current_page,
511 EmpathyAccountAssistant *self = user_data;
512 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
515 retval = current_page;
517 if (current_page == PAGE_INTRO)
519 if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
520 priv->first_resp == RESPONSE_CREATE_ACCOUNT)
521 retval = PAGE_ENTER_CREATE;
522 else if (priv->first_resp == RESPONSE_IMPORT)
523 retval = PAGE_IMPORT;
524 else if (priv->first_resp == RESPONSE_SALUT_ONLY)
527 else if (current_page == PAGE_IMPORT)
529 if (priv->display_salut_page)
532 /* Don't go forward */
535 else if (current_page == PAGE_SALUT)
537 /* Don't go forward */
540 else if (current_page >= PAGE_ENTER_CREATE)
542 if (priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
544 priv->enter_create_forward = TRUE;
545 retval = current_page;
547 else if (priv->display_salut_page)
553 /* Don't go forward */
562 update_intro_page_buttons (EmpathyAccountAssistant *self)
564 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
565 GtkWidget *intro_page;
567 intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self),
570 if (priv->first_resp == RESPONSE_SALUT_ONLY &&
571 !priv->display_salut_page)
572 gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
573 GTK_ASSISTANT_PAGE_SUMMARY);
575 gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
576 GTK_ASSISTANT_PAGE_INTRO);
580 account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
581 EmpathyAccountAssistant *self)
583 FirstPageResponse response;
584 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
586 response = GPOINTER_TO_INT (g_object_get_data
587 (G_OBJECT (button), "response"));
589 priv->first_resp = response;
591 update_intro_page_buttons (self);
595 account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
597 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
598 GtkWidget *main_vbox, *hbox_1, *w, *vbox_1;
599 GtkWidget *radio = NULL;
603 main_vbox = gtk_vbox_new (FALSE, 12);
604 gtk_widget_show (main_vbox);
605 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
607 hbox_1 = gtk_hbox_new (FALSE, 12);
608 gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
609 gtk_widget_show (hbox_1);
612 _("With Empathy you can chat with people "
613 "online nearby and with friends and colleagues "
614 "who use Google Talk, AIM, Windows Live "
615 "and many other chat programs. With a microphone "
616 "or a webcam you can also have audio or video calls."));
617 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
618 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
619 gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
622 pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80);
623 w = gtk_image_new_from_pixbuf (pix);
624 gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
627 g_object_unref (pix);
629 w = gtk_label_new (_("Do you have an account you've been using "
630 "with another chat program?"));
631 gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
632 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
633 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
636 w = gtk_alignment_new (0, 0, 0, 0);
637 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
638 gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
641 vbox_1 = gtk_vbox_new (TRUE, 0);
642 gtk_container_add (GTK_CONTAINER (w), vbox_1);
643 gtk_widget_show (vbox_1);
645 if (empathy_import_accounts_to_import ())
647 hbox_1 = gtk_hbox_new (FALSE, 0);
648 gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0);
649 gtk_widget_show (hbox_1);
651 radio = gtk_radio_button_new_with_label (NULL,
652 _("Yes, import my account details from "));
653 gtk_box_pack_start (GTK_BOX (hbox_1), radio, TRUE, TRUE, 0);
654 g_object_set_data (G_OBJECT (radio), "response",
655 GINT_TO_POINTER (RESPONSE_IMPORT));
656 gtk_widget_show (radio);
658 w = gtk_combo_box_text_new ();
659 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), "Pidgin");
660 gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
661 gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0);
664 g_signal_connect (radio, "clicked",
665 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
666 priv->first_resp = RESPONSE_IMPORT;
670 priv->first_resp = RESPONSE_ENTER_ACCOUNT;
673 str = _("Yes, I'll enter my account details now");
677 radio = gtk_radio_button_new_with_label (NULL, str);
682 w = gtk_radio_button_new_with_label_from_widget (
683 GTK_RADIO_BUTTON (radio), str);
686 gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
687 g_object_set_data (G_OBJECT (w), "response",
688 GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
691 g_signal_connect (w, "clicked",
692 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
694 w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
695 _("No, I want a new account"));
696 gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
697 g_object_set_data (G_OBJECT (w), "response",
698 GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
701 g_signal_connect (w, "clicked",
702 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
704 w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
705 _("No, I just want to see people online nearby for now"));
706 gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
707 g_object_set_data (G_OBJECT (w), "response",
708 GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
711 g_signal_connect (w, "clicked",
712 G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
718 account_assistant_build_import_page (EmpathyAccountAssistant *self)
720 GtkWidget *main_vbox, *w, *import;
721 EmpathyImportWidget *iw;
722 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
724 main_vbox = gtk_vbox_new (FALSE, 12);
725 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
726 w = gtk_label_new (_("Select the accounts you want to import:"));
727 gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
729 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
731 w = gtk_alignment_new (0, 0, 1, 1);
732 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
733 gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
736 /* NOTE: this is hardcoded as we support pidgin only */
737 iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN);
738 import = empathy_import_widget_get_widget (iw);
739 gtk_container_add (GTK_CONTAINER (w), import);
740 gtk_widget_show (import);
744 gtk_widget_show (main_vbox);
750 account_assistant_radio_create_again_clicked_cb (GtkButton *button,
751 EmpathyAccountAssistant *self)
753 CreateEnterPageResponse response;
754 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
756 response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
759 priv->create_enter_resp = response;
761 update_create_page_buttons (self);
765 account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self)
767 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
768 GtkWidget *main_vbox, *w, *chooser, *vbox, *hbox, *radio;
770 main_vbox = gtk_vbox_new (FALSE, 12);
771 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
772 gtk_widget_show (main_vbox);
774 hbox = gtk_hbox_new (FALSE, 6);
775 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
776 gtk_widget_show (hbox);
778 w = gtk_label_new (NULL);
779 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
781 priv->first_label = w;
783 w = gtk_alignment_new (0, 0, 0, 0);
784 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
785 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
788 chooser = empathy_protocol_chooser_new ();
789 gtk_box_pack_start (GTK_BOX (hbox), chooser, FALSE, FALSE, 0);
790 gtk_widget_show (chooser);
791 priv->chooser = chooser;
793 vbox = gtk_vbox_new (FALSE, 6);
794 gtk_box_pack_end (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
795 gtk_widget_show (vbox);
797 w = gtk_label_new (NULL);
798 gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
799 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
800 gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
802 priv->second_label = w;
804 w = gtk_alignment_new (0, 0, 0, 0);
805 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
806 gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
809 hbox = gtk_hbox_new (FALSE, 6);
810 gtk_container_add (GTK_CONTAINER (w), hbox);
811 gtk_widget_show (hbox);
813 radio = gtk_radio_button_new_with_label (NULL, _("Yes"));
814 gtk_box_pack_start (GTK_BOX (hbox), radio, FALSE, FALSE, 0);
815 g_object_set_data (G_OBJECT (radio), "response",
816 GINT_TO_POINTER (RESPONSE_CREATE_AGAIN));
817 gtk_widget_show (radio);
819 w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
820 _("No, that's all for now"));
821 gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
822 g_object_set_data (G_OBJECT (w), "response",
823 GINT_TO_POINTER (RESPONSE_CREATE_STOP));
824 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
825 priv->create_enter_resp = RESPONSE_CREATE_STOP;
826 priv->create_again_radio = w;
829 g_signal_connect (w, "clicked",
830 G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
831 g_signal_connect (radio, "clicked",
832 G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
838 account_assistant_close_cb (GtkAssistant *assistant,
841 EmpathyAccountAssistantPriv *priv = GET_PRIV (assistant);
843 if (priv->is_creating)
846 gtk_widget_destroy (GTK_WIDGET (assistant));
850 impl_signal_apply (GtkAssistant *assistant)
852 EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
853 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
856 current_page = gtk_assistant_get_current_page (assistant);
858 if (current_page == PAGE_SALUT)
860 if (priv->create_salut_account)
861 /* create_salut_account_settings() already set the display name of the
862 * account so there is no need to set it again. */
863 account_assistant_apply_account_and_finish (self, priv->salut_settings,
867 else if (current_page >= PAGE_ENTER_CREATE &&
868 priv->settings != NULL &&
869 empathy_account_settings_is_valid (priv->settings))
871 account_assistant_apply_account_and_finish (self, priv->settings, TRUE);
872 g_object_unref (priv->settings);
873 priv->settings = NULL;
875 else if (current_page == PAGE_IMPORT)
877 empathy_import_widget_add_selected_accounts (priv->iw);
882 impl_signal_cancel (GtkAssistant *assistant)
884 gtk_widget_destroy (GTK_WIDGET (assistant));
888 impl_signal_prepare (GtkAssistant *assistant,
889 GtkWidget *current_page)
891 EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
892 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
895 /* check from which page we are coming from */
896 if (priv->current_page_id == PAGE_IMPORT)
897 empathy_import_widget_add_selected_accounts (priv->iw);
899 current_idx = gtk_assistant_get_current_page (assistant);
900 priv->current_page_id = current_idx;
902 if (current_idx >= PAGE_ENTER_CREATE)
904 if (!priv->enter_create_forward && current_idx != PAGE_SALUT)
906 account_assistant_finish_enter_or_create_page (self,
907 priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
912 priv->enter_create_forward = FALSE;
915 if (priv->settings != NULL &&
916 empathy_account_settings_is_valid (priv->settings))
918 account_assistant_apply_account_and_finish (self, priv->settings,
920 g_object_unref (priv->settings);
921 priv->settings = NULL;
927 do_get_property (GObject *object,
932 EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
937 g_value_set_object (value, priv->parent_window);
939 case PROP_CONNECTION_MGRS:
940 g_value_set_object (value, priv->connection_mgrs);
943 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
948 do_set_property (GObject *object,
953 EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
958 priv->parent_window = g_value_get_object (value);
960 case PROP_CONNECTION_MGRS:
961 priv->connection_mgrs = g_value_dup_object (value);
964 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
969 do_dispose (GObject *obj)
971 EmpathyAccountAssistantPriv *priv = GET_PRIV (obj);
973 if (priv->dispose_run)
976 priv->dispose_run = TRUE;
978 if (priv->settings != NULL)
980 g_object_unref (priv->settings);
981 priv->settings = NULL;
984 g_object_unref (priv->account_mgr);
985 priv->account_mgr = NULL;
987 g_object_unref (priv->connection_mgrs);
988 priv->connection_mgrs = NULL;
990 if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL)
991 G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj);
995 empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
997 GObjectClass *oclass = G_OBJECT_CLASS (klass);
998 GtkAssistantClass *gtkclass = GTK_ASSISTANT_CLASS (klass);
999 GParamSpec *param_spec;
1001 oclass->get_property = do_get_property;
1002 oclass->set_property = do_set_property;
1003 oclass->constructed = do_constructed;
1004 oclass->dispose = do_dispose;
1006 gtkclass->apply = impl_signal_apply;
1007 gtkclass->prepare = impl_signal_prepare;
1008 gtkclass->cancel = impl_signal_cancel;
1010 param_spec = g_param_spec_object ("parent-window",
1011 "parent-window", "The parent window",
1013 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1014 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1016 param_spec = g_param_spec_object ("connection-managers",
1017 "connection-managers", "A EmpathyConnectionManagers",
1018 EMPATHY_TYPE_CONNECTION_MANAGERS,
1019 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1020 g_object_class_install_property (oclass, PROP_CONNECTION_MGRS, param_spec);
1022 g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
1026 create_salut_check_box_toggled_cb (GtkWidget *widget,
1027 EmpathyAccountAssistant *self)
1029 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1031 gboolean page_valid;
1033 sensitive = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
1035 gtk_widget_set_sensitive (priv->salut_account_widget, sensitive);
1040 priv->create_salut_account = FALSE;
1044 /* page is complete if the account is valid */
1045 page_valid = empathy_account_settings_is_valid (priv->salut_settings);
1046 priv->create_salut_account = TRUE;
1049 gtk_assistant_set_page_complete (GTK_ASSISTANT (self), priv->salut_page,
1054 account_assistant_salut_handle_apply_cb (EmpathyAccountWidget *widget_object,
1056 EmpathyAccountAssistant *self)
1058 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1060 gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
1061 priv->salut_page, is_valid);
1065 account_assistant_build_salut_page (EmpathyAccountAssistant *self)
1067 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1068 GtkWidget *main_vbox, *hbox_1, *w;
1070 EmpathyAccountSettings *settings;
1071 GtkWidget *account_widget;
1072 EmpathyAccountWidget *widget_object;
1075 main_vbox = gtk_vbox_new (FALSE, 12);
1076 gtk_widget_show (main_vbox);
1077 gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
1079 hbox_1 = gtk_hbox_new (FALSE, 12);
1080 gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
1081 gtk_widget_show (hbox_1);
1083 w = gtk_label_new (NULL);
1084 markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1085 _("Empathy can automatically discover and chat with the people "
1086 "connected on the same network as you. "
1087 "If you want to use this feature, please check that the "
1088 "details below are correct. "
1089 "You can easily change these details later or disable this feature "
1090 "by using the 'Accounts' dialog"),
1091 _("Edit->Accounts"));
1092 gtk_label_set_markup (GTK_LABEL (w), markup);
1094 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
1095 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
1096 gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
1097 gtk_widget_show (w);
1099 pix = empathy_pixbuf_from_icon_name_sized ("im-local-xmpp", 80);
1100 w = gtk_image_new_from_pixbuf (pix);
1101 gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
1102 gtk_widget_show (w);
1104 g_object_unref (pix);
1106 w = gtk_check_button_new_with_mnemonic (
1107 _("I do _not want to enable this feature for now"));
1108 gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
1109 g_signal_connect (w, "toggled",
1110 G_CALLBACK (create_salut_check_box_toggled_cb), self);
1111 gtk_widget_show (w);
1113 w = gtk_alignment_new (0, 0, 0, 0);
1114 gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
1115 gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
1116 gtk_widget_show (w);
1118 settings = create_salut_account_settings ();
1120 widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
1121 account_widget = empathy_account_widget_get_widget (widget_object);
1123 priv->salut_settings = settings;
1124 priv->salut_account_widget = account_widget;
1126 g_signal_connect (widget_object, "handle-apply",
1127 G_CALLBACK (account_assistant_salut_handle_apply_cb), self);
1129 gtk_box_pack_start (GTK_BOX (main_vbox), account_widget,
1131 gtk_widget_show (account_widget);
1137 account_assistant_build_salut_error_page (EmpathyAccountAssistant *self)
1142 markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1143 _("You won't be able to chat with people connected to your local "
1144 "network, as telepathy-salut is not installed. If you want to enable "
1145 "this feature, please install the telepathy-salut package and create "
1146 "a People Nearby account from the Accounts dialog"),
1147 _("Edit->Accounts"));
1149 vbox = build_error_vbox (_("telepathy-salut not installed"), markup);
1155 account_mgr_prepare_cb (GObject *source_object,
1156 GAsyncResult *result,
1159 EmpathyAccountAssistant *self = user_data;
1160 EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
1161 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1162 GError *error = NULL;
1164 if (!tp_account_manager_prepare_finish (manager, result, &error))
1166 DEBUG ("Failed to prepare account manager: %s", error->message);
1167 g_error_free (error);
1171 if (!should_create_salut_account (manager))
1173 DEBUG ("No need to create a Salut account");
1174 priv->display_salut_page = FALSE;
1176 update_intro_page_buttons (self);
1178 gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->import_page,
1179 GTK_ASSISTANT_PAGE_CONFIRM);
1181 update_create_page_buttons (self);
1186 empathy_account_assistant_init (EmpathyAccountAssistant *self)
1188 EmpathyAccountAssistantPriv *priv;
1190 priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
1191 EmpathyAccountAssistantPriv);
1194 gtk_window_set_title (GTK_WINDOW (self),
1195 _("Messaging and VoIP Accounts Assistant"));
1197 priv->account_mgr = tp_account_manager_dup ();
1201 do_constructed (GObject *object)
1203 GtkAssistant *assistant = GTK_ASSISTANT (object);
1204 EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (object);
1205 EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
1208 /* set us as transient for the parent window if any */
1209 if (priv->parent_window)
1210 gtk_window_set_transient_for (GTK_WINDOW (object),
1211 priv->parent_window);
1213 /* set the dialog hint, so this will be centered over the parent window */
1214 gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);
1216 g_assert (priv->connection_mgrs != NULL);
1217 g_assert (empathy_connection_managers_is_ready (priv->connection_mgrs));
1219 g_signal_connect (self, "close",
1220 G_CALLBACK (account_assistant_close_cb), NULL);
1222 gtk_assistant_set_forward_page_func (assistant,
1223 account_assistant_page_forward_func, self, NULL);
1225 /* first page (introduction) */
1226 page = account_assistant_build_introduction_page (self);
1227 gtk_assistant_append_page (assistant, page);
1228 gtk_assistant_set_page_title (assistant, page,
1229 _("Welcome to Empathy"));
1230 gtk_assistant_set_page_type (assistant, page,
1231 GTK_ASSISTANT_PAGE_INTRO);
1232 gtk_assistant_set_page_complete (assistant, page, TRUE);
1234 /* second page (import accounts) */
1235 page = account_assistant_build_import_page (self);
1236 gtk_assistant_append_page (assistant, page);
1237 gtk_assistant_set_page_title (assistant, page,
1238 _("Import your existing accounts"));
1239 gtk_assistant_set_page_complete (assistant, page, TRUE);
1240 gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1241 priv->import_page = page;
1243 /* third page (enter account details) */
1244 page = account_assistant_build_enter_or_create_page (self);
1245 gtk_assistant_append_page (assistant, page);
1246 gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1247 priv->enter_or_create_page = page;
1249 /* fourth page (salut details) */
1250 if (empathy_connection_managers_get_cm (priv->connection_mgrs, "salut")
1253 page = account_assistant_build_salut_page (self);
1254 gtk_assistant_append_page (assistant, page);
1255 gtk_assistant_set_page_title (assistant, page,
1256 _("Please enter personal details"));
1257 gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
1259 priv->create_salut_account = TRUE;
1261 if (empathy_account_settings_is_valid (priv->salut_settings))
1263 gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
1269 page = account_assistant_build_salut_error_page (self);
1270 gtk_assistant_append_page (assistant, page);
1271 gtk_assistant_set_page_title (assistant, page, _("An error occurred"));
1272 gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_SUMMARY);
1274 priv->create_salut_account = FALSE;
1277 priv->salut_page = page;
1278 priv->display_salut_page = TRUE;
1280 tp_account_manager_prepare_async (priv->account_mgr, NULL,
1281 account_mgr_prepare_cb, self);
1283 gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
1287 empathy_account_assistant_show (GtkWindow *window,
1288 EmpathyConnectionManagers *connection_mgrs)
1290 static GtkWidget *dialog = NULL;
1294 dialog = g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT,
1295 "parent-window", window,
1296 "connection-managers", connection_mgrs,
1298 g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &dialog);
1301 gtk_window_present (GTK_WINDOW (dialog));