1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <glib/gi18n.h>
32 #include <camel/camel-url.h>
33 #include <widgets/modest-combo-box.h>
34 #include "modest-account-assistant.h"
35 #include "modest-store-widget.h"
36 #include "modest-transport-widget.h"
37 #include "modest-text-utils.h"
38 #include <modest-protocol-info.h>
42 /* 'private'/'protected' functions */
43 static void modest_account_assistant_class_init (ModestAccountAssistantClass *klass);
44 static void modest_account_assistant_init (ModestAccountAssistant *obj);
45 static void modest_account_assistant_finalize (GObject *obj);
54 typedef struct _ModestAccountAssistantPrivate ModestAccountAssistantPrivate;
55 struct _ModestAccountAssistantPrivate {
57 ModestAccountMgr *account_mgr;
59 GtkWidget *account_name;
66 GtkWidget *store_widget;
67 GtkWidget *transport_widget;
69 GtkWidget *transport_holder;
70 GtkWidget *store_holder;
72 ModestPairList *receiving_transport_store_protos;
73 ModestPairList *sending_transport_store_protos;
76 #define MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
77 MODEST_TYPE_ACCOUNT_ASSISTANT, \
78 ModestAccountAssistantPrivate))
80 static GtkAssistantClass *parent_class = NULL;
82 /* uncomment the following if you have defined any signals */
83 /* static guint signals[LAST_SIGNAL] = {0}; */
86 modest_account_assistant_get_type (void)
88 static GType my_type = 0;
90 static const GTypeInfo my_info = {
91 sizeof(ModestAccountAssistantClass),
93 NULL, /* base finalize */
94 (GClassInitFunc) modest_account_assistant_class_init,
95 NULL, /* class finalize */
96 NULL, /* class data */
97 sizeof(ModestAccountAssistant),
99 (GInstanceInitFunc) modest_account_assistant_init,
102 my_type = g_type_register_static (GTK_TYPE_ASSISTANT,
103 "ModestAccountAssistant",
110 modest_account_assistant_class_init (ModestAccountAssistantClass *klass)
112 GObjectClass *gobject_class;
113 gobject_class = (GObjectClass*) klass;
115 parent_class = g_type_class_peek_parent (klass);
116 gobject_class->finalize = modest_account_assistant_finalize;
118 g_type_class_add_private (gobject_class, sizeof(ModestAccountAssistantPrivate));
120 /* signal definitions go here, e.g.: */
121 /* signals[MY_SIGNAL_1] = */
122 /* g_signal_new ("my_signal_1",....); */
123 /* signals[MY_SIGNAL_2] = */
124 /* g_signal_new ("my_signal_2",....); */
131 add_intro_page (ModestAccountAssistant *assistant)
133 GtkWidget *page, *label;
135 page = gtk_vbox_new (FALSE, 12);
137 label = gtk_label_new (_("mcen_ia_emailsetup_intro"));
138 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
139 gtk_box_pack_start (GTK_BOX(page), label, FALSE, FALSE, 0);
140 gtk_widget_set_size_request (label, 400, -1);
141 gtk_widget_show_all (page);
143 gtk_assistant_append_page (GTK_ASSISTANT(assistant), page);
145 gtk_assistant_set_page_title (GTK_ASSISTANT(assistant), page,
146 _("mcen_ti_emailsetup_welcome"));
147 gtk_assistant_set_page_type (GTK_ASSISTANT(assistant), page,
148 GTK_ASSISTANT_PAGE_INTRO);
149 gtk_assistant_set_page_complete (GTK_ASSISTANT(assistant),
157 set_current_page_complete (ModestAccountAssistant *self, gboolean complete)
162 pageno = gtk_assistant_get_current_page (GTK_ASSISTANT(self));
165 page = gtk_assistant_get_nth_page (GTK_ASSISTANT(self), pageno);
166 gtk_assistant_set_page_complete (GTK_ASSISTANT(self), page, complete);
172 identity_page_update_completeness (GtkEditable *editable,
173 ModestAccountAssistant *self)
175 ModestAccountAssistantPrivate *priv;
178 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
180 txt = gtk_entry_get_text (GTK_ENTRY(priv->fullname));
181 if (!txt || strlen(txt) == 0) {
182 set_current_page_complete (self, FALSE);
186 /* FIXME: regexp check for email address */
187 txt = gtk_entry_get_text (GTK_ENTRY(priv->email));
188 if (!modest_text_utils_validate_email_address (txt, NULL)) {
189 set_current_page_complete (self, FALSE);
193 txt = gtk_entry_get_text (GTK_ENTRY(priv->username));
194 if (!txt || txt[0] == '\0') {
195 set_current_page_complete (self, FALSE);
198 set_current_page_complete (self, TRUE);
202 field_name_label (const gchar *text)
207 fixed_text = g_strconcat (text, ":", NULL);
208 label = gtk_label_new (fixed_text);
210 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
216 add_identity_page (ModestAccountAssistant *self)
218 GtkWidget *page, *label, *table, *frame;
219 GtkWidget *alignment;
220 ModestAccountAssistantPrivate *priv;
222 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
224 priv->account_name = gtk_entry_new ();
225 gtk_entry_set_max_length (GTK_ENTRY (priv->fullname), 40);
226 priv->fullname = gtk_entry_new ();
227 gtk_entry_set_max_length (GTK_ENTRY (priv->fullname), 40);
228 priv->email = gtk_entry_new ();
229 gtk_entry_set_width_chars (GTK_ENTRY (priv->email), 40);
230 priv->username = gtk_entry_new ();
231 gtk_entry_set_width_chars (GTK_ENTRY (priv->username), 40);
232 priv->password = gtk_entry_new ();
233 gtk_entry_set_width_chars (GTK_ENTRY (priv->password), 40);
234 gtk_entry_set_visibility (GTK_ENTRY (priv->password), FALSE);
236 page = gtk_vbox_new (FALSE, 24);
238 label = gtk_label_new (
239 _("Please enter below the name for the account you're creating."));
240 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
241 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
242 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
243 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 12, 12);
244 gtk_container_add (GTK_CONTAINER (alignment), label);
245 gtk_box_pack_start (GTK_BOX(page), alignment, FALSE, FALSE, 0);
247 table = gtk_table_new (1,2, FALSE);
248 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
249 gtk_table_set_row_spacings (GTK_TABLE (table), 1);
250 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Account name")),
252 gtk_table_attach_defaults (GTK_TABLE(table),priv->account_name,
254 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
255 gtk_container_add (GTK_CONTAINER (alignment), table);
256 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 12, 0);
257 gtk_box_pack_start (GTK_BOX(page), alignment, FALSE, FALSE, 0);
259 frame = gtk_frame_new (NULL);
260 label = gtk_label_new (NULL);
261 gtk_label_set_markup (GTK_LABEL (label), _("<b>Public information </b>"));
262 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
263 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
264 table = gtk_table_new (2,2, FALSE);
265 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
266 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
267 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Full name")),
269 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Email address")),
271 gtk_table_attach_defaults (GTK_TABLE(table),priv->fullname,
273 gtk_table_attach_defaults (GTK_TABLE(table),priv->email,
275 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
276 gtk_container_add (GTK_CONTAINER (alignment), table);
277 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
278 gtk_container_add (GTK_CONTAINER (frame), alignment);
279 gtk_box_pack_start (GTK_BOX(page), frame, FALSE, FALSE, 0);
282 frame = gtk_frame_new (NULL);
283 label = gtk_label_new (NULL);
284 gtk_label_set_markup (GTK_LABEL (label), _("<b>Server account </b>"));
285 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
286 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
287 table = gtk_table_new (2,2, FALSE);
288 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
289 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
290 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("User name")),
292 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Password")),
294 gtk_table_attach_defaults (GTK_TABLE(table),priv->username,
296 gtk_table_attach_defaults (GTK_TABLE(table),priv->password,
298 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
299 gtk_container_add (GTK_CONTAINER (alignment), table);
300 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
301 gtk_container_add (GTK_CONTAINER (frame), alignment);
302 gtk_box_pack_start (GTK_BOX(page), frame, FALSE, FALSE, 0);
304 g_signal_connect (G_OBJECT(priv->fullname), "changed",
305 G_CALLBACK(identity_page_update_completeness),
307 g_signal_connect (G_OBJECT(priv->username), "changed",
308 G_CALLBACK(identity_page_update_completeness),
310 g_signal_connect (G_OBJECT(priv->password), "changed",
311 G_CALLBACK(identity_page_update_completeness),
313 g_signal_connect (G_OBJECT(priv->email), "changed",
314 G_CALLBACK(identity_page_update_completeness),
316 g_signal_connect (G_OBJECT(priv->account_name), "changed",
317 G_CALLBACK(identity_page_update_completeness),
321 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
322 gtk_container_add (GTK_CONTAINER (alignment), page);
323 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 12, 12, 12);
324 gtk_widget_show_all (alignment);
325 gtk_assistant_append_page (GTK_ASSISTANT(self), alignment);
327 gtk_assistant_set_page_title (GTK_ASSISTANT(self), alignment,
329 gtk_assistant_set_page_type (GTK_ASSISTANT(self), alignment,
330 GTK_ASSISTANT_PAGE_CONTENT);
331 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
337 receiving_page_update_completeness (GtkEditable *editable,
338 ModestAccountAssistant *self)
340 ModestAccountAssistantPrivate *priv;
343 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
345 txt = modest_store_widget_get_username (MODEST_STORE_WIDGET (priv->store_widget));
346 if (!txt || strlen(txt) == 0) {
347 set_current_page_complete (self, FALSE);
351 txt = modest_store_widget_get_servername (MODEST_STORE_WIDGET (priv->store_widget));
352 if (!txt || strlen(txt) == 0) {
353 set_current_page_complete (self, FALSE);
356 set_current_page_complete (self, TRUE);
360 on_receiving_combo_box_changed (GtkComboBox *combo, ModestAccountAssistant *self)
362 ModestAccountAssistantPrivate *priv;
364 ModestTransportStoreProtocol proto;
366 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
367 chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combo));
368 if (priv->store_widget)
369 gtk_container_remove (GTK_CONTAINER(priv->store_holder),
372 proto = modest_protocol_info_get_transport_store_protocol (chosen);
374 /* FIXME: we could have these widgets cached instead of
375 creating them every time */
376 priv->store_widget = modest_store_widget_new (proto);
377 if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP) {
378 g_signal_connect (priv->store_widget,
380 G_CALLBACK (receiving_page_update_completeness),
382 set_current_page_complete (self, FALSE);
384 set_current_page_complete (self, TRUE);
386 gtk_container_add (GTK_CONTAINER(priv->store_holder),
389 gtk_widget_show_all (priv->store_holder);
394 add_receiving_page (ModestAccountAssistant *self)
396 GtkWidget *page, *box, *combo;
397 ModestAccountAssistantPrivate *priv;
399 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
400 page = gtk_vbox_new (FALSE, 6);
402 gtk_box_pack_start (GTK_BOX(page),
404 _("Please select among the following options")),
406 box = gtk_hbox_new (FALSE, 6);
407 gtk_box_pack_start (GTK_BOX(box),
408 gtk_label_new(_("Server type")),
411 /* Note: This ModestPairList* must exist for as long as the combo
412 * that uses it, because the ModestComboBox uses the ID opaquely,
413 * so it can't know how to manage its memory. */
414 priv->receiving_transport_store_protos =
415 modest_protocol_info_get_transport_store_protocol_pair_list ();
416 combo = modest_combo_box_new (priv->receiving_transport_store_protos, g_str_equal);
418 g_signal_connect (G_OBJECT(combo), "changed",
419 G_CALLBACK(on_receiving_combo_box_changed), self);
421 gtk_box_pack_start (GTK_BOX(box), combo, FALSE,FALSE,6);
422 gtk_box_pack_start (GTK_BOX(page), box, FALSE,FALSE, 6);
424 gtk_box_pack_start (GTK_BOX(page), gtk_hseparator_new(), FALSE, FALSE, 0);
426 priv->store_holder = gtk_hbox_new (FALSE, 0);
427 gtk_box_pack_start (GTK_BOX(page), priv->store_holder,
430 /* Force the selection */
431 on_receiving_combo_box_changed (GTK_COMBO_BOX (combo), self);
433 gtk_assistant_append_page (GTK_ASSISTANT(self), page);
435 gtk_assistant_set_page_title (GTK_ASSISTANT(self), page,
436 _("Receiving mail"));
437 gtk_assistant_set_page_type (GTK_ASSISTANT(self), page,
438 GTK_ASSISTANT_PAGE_CONTENT);
439 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
441 gtk_widget_show_all (page);
448 on_sending_combo_box_changed (GtkComboBox *combo, ModestAccountAssistant *self)
450 ModestAccountAssistantPrivate *priv;
453 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
455 chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combo));
457 if (priv->transport_widget)
458 gtk_container_remove (GTK_CONTAINER(priv->transport_holder),
459 priv->transport_widget);
460 priv->transport_widget =
461 modest_transport_widget_new (modest_protocol_info_get_transport_store_protocol(chosen));
463 gtk_container_add (GTK_CONTAINER(priv->transport_holder),
464 priv->transport_widget);
466 gtk_widget_show_all (priv->transport_holder);
472 add_sending_page (ModestAccountAssistant *self)
474 GtkWidget *page, *box, *combo;
475 ModestAccountAssistantPrivate *priv;
477 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
478 page = gtk_vbox_new (FALSE, 6);
480 gtk_box_pack_start (GTK_BOX(page),
482 _("Please select among the following options")),
484 box = gtk_hbox_new (FALSE, 0);
485 gtk_box_pack_start (GTK_BOX(box),
486 gtk_label_new(_("Server type")),
489 /* Note: This ModestPairList* must exist for as long as the combo
490 * that uses it, because the ModestComboBox uses the ID opaquely,
491 * so it can't know how to manage its memory. */
492 priv->sending_transport_store_protos = modest_protocol_info_get_transport_store_protocol_pair_list ();
493 combo = modest_combo_box_new (priv->sending_transport_store_protos, g_str_equal);
495 g_signal_connect (G_OBJECT(combo), "changed",
496 G_CALLBACK(on_sending_combo_box_changed), self);
498 gtk_box_pack_start (GTK_BOX(box), combo, FALSE,FALSE,0);
499 gtk_box_pack_start (GTK_BOX(page), box, FALSE,FALSE, 0);
501 gtk_box_pack_start (GTK_BOX(page), gtk_hseparator_new(), FALSE, FALSE, 0);
503 priv->transport_holder = gtk_hbox_new (FALSE, 0);
504 gtk_box_pack_start (GTK_BOX(page), priv->transport_holder,
507 /* Force the selection */
508 on_sending_combo_box_changed (GTK_COMBO_BOX (combo), self);
510 gtk_assistant_append_page (GTK_ASSISTANT(self), page);
512 gtk_assistant_set_page_title (GTK_ASSISTANT(self), page,
514 gtk_assistant_set_page_type (GTK_ASSISTANT(self), page,
515 GTK_ASSISTANT_PAGE_INTRO);
516 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
518 gtk_widget_show_all (page);
524 add_final_page (ModestAccountAssistant *self)
526 GtkWidget *page, *box;
527 ModestAccountAssistantPrivate *priv;
529 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
530 page = gtk_vbox_new (FALSE, 6);
532 gtk_box_pack_start (GTK_BOX(page),
534 _("We're almost done. Press 'Apply' to store this new account")),
536 box = gtk_hbox_new (FALSE, 6);
538 gtk_entry_new_with_max_length (40);
539 gtk_entry_set_text (GTK_ENTRY(priv->account_name),
540 gtk_entry_get_text(GTK_ENTRY(priv->email)));
541 gtk_box_pack_start (GTK_BOX(box),gtk_label_new(_("Account name:")),
543 gtk_box_pack_start (GTK_BOX(box),priv->account_name , FALSE,FALSE,6);
545 gtk_box_pack_start (GTK_BOX(page), box, FALSE, FALSE, 6);
547 gtk_assistant_append_page (GTK_ASSISTANT(self), page);
549 gtk_assistant_set_page_title (GTK_ASSISTANT(self), page,
550 _("Account Management"));
551 gtk_assistant_set_page_type (GTK_ASSISTANT(self), page,
552 GTK_ASSISTANT_PAGE_CONFIRM);
554 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
556 gtk_widget_show_all (page);
561 modest_account_assistant_init (ModestAccountAssistant *obj)
563 ModestAccountAssistantPrivate *priv;
564 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(obj);
566 priv->account_mgr = NULL;
568 priv->store_widget = NULL;
569 priv->transport_widget = NULL;
573 modest_account_assistant_finalize (GObject *obj)
575 ModestAccountAssistantPrivate *priv;
577 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(obj);
579 if (priv->account_mgr) {
580 g_object_unref (G_OBJECT(priv->account_mgr));
581 priv->account_mgr = NULL;
584 /* These had to stay alive for as long as the comboboxes that used them: */
585 modest_pair_list_free (priv->receiving_transport_store_protos);
586 modest_pair_list_free (priv->sending_transport_store_protos);
588 G_OBJECT_CLASS(parent_class)->finalize (obj);
592 on_cancel (ModestAccountAssistant *self, gpointer user_data)
598 label = gtk_label_new (_("Are you sure you want to cancel\n"
599 "setting up a new account?"));
601 dialog = gtk_dialog_new_with_buttons (_("Cancel"),
603 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
604 GTK_STOCK_YES, GTK_RESPONSE_ACCEPT,
605 GTK_STOCK_NO, GTK_RESPONSE_CANCEL,
608 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
609 label, FALSE, FALSE, 6);
611 gtk_widget_show_all ((GTK_DIALOG(dialog)->vbox));
613 gtk_window_set_resizable (GTK_WINDOW(dialog), FALSE);
615 response = gtk_dialog_run (GTK_DIALOG(dialog));
616 gtk_widget_destroy (dialog);
619 case GTK_RESPONSE_ACCEPT:
620 /* close the assistant */
621 gtk_widget_hide (GTK_WIDGET(self));
623 case GTK_RESPONSE_CANCEL:
624 /* don't do anything */
626 default: g_assert_not_reached ();
632 get_account_name (ModestAccountAssistant *self)
634 ModestAccountAssistantPrivate *priv;
635 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
637 return gtk_entry_get_text (GTK_ENTRY(priv->account_name));
641 get_fullname (ModestAccountAssistant *self)
643 ModestAccountAssistantPrivate *priv;
644 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
646 return gtk_entry_get_text (GTK_ENTRY(priv->fullname));
652 get_email (ModestAccountAssistant *self)
654 ModestAccountAssistantPrivate *priv;
655 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
657 return gtk_entry_get_text (GTK_ENTRY(priv->email));
662 on_close (ModestAccountAssistant *self, gpointer user_data)
664 gtk_widget_hide (GTK_WIDGET (self));
669 * FIXME: hmmmm this a Camel internal thing, should move this
673 get_account_uri (ModestTransportStoreProtocol proto, const gchar* path)
679 case MODEST_PROTOCOL_STORE_MBOX:
680 url = camel_url_new ("mbox:", NULL); break;
681 case MODEST_PROTOCOL_STORE_MAILDIR:
682 url = camel_url_new ("maildir:", NULL); break;
684 g_return_val_if_reached (NULL);
686 camel_url_set_path (url, path);
687 uri = camel_url_to_string (url, 0);
688 camel_url_free (url);
694 get_new_server_account_name (ModestAccountMgr* acc_mgr, ModestTransportStoreProtocol proto,
695 const gchar* username, const gchar *servername)
701 name = g_strdup_printf ("%s:%d",
702 modest_protocol_info_get_transport_store_protocol_name(proto), i++);
703 if (modest_account_mgr_account_exists (acc_mgr, name, TRUE))
713 on_apply (ModestAccountAssistant *self, gpointer user_data)
715 ModestAccountAssistantPrivate *priv;
716 ModestTransportStoreProtocol proto = MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN;
717 ModestAuthProtocol security = MODEST_PROTOCOL_CONNECTION_NORMAL;
718 ModestConnectionProtocol auth = MODEST_PROTOCOL_AUTH_NONE;
719 gchar *store_name, *transport_name;
720 const gchar *account_name, *username, *servername, *path;
721 ModestStoreWidget *store;
722 ModestTransportWidget *transport;
724 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
726 /* create server account -> store */
727 store = MODEST_STORE_WIDGET(priv->store_widget);
728 proto = modest_store_widget_get_proto (store);
729 username = modest_store_widget_get_username (store);
730 servername = modest_store_widget_get_servername (store);
731 path = modest_store_widget_get_path (store);
732 security = modest_store_widget_get_security (store);
733 auth = modest_store_widget_get_auth (store);
734 store_name = get_new_server_account_name (priv->account_mgr, proto,username, servername);
736 if (proto == MODEST_PROTOCOL_STORE_MAILDIR ||
737 proto == MODEST_PROTOCOL_STORE_MBOX) {
738 gchar *uri = get_account_uri (proto, path);
739 modest_account_mgr_add_server_account_uri (priv->account_mgr, store_name, proto, uri);
742 modest_account_mgr_add_server_account (priv->account_mgr,
745 0, /* FIXME: does this mean default?*/
752 /* create server account -> transport */
753 transport = MODEST_TRANSPORT_WIDGET(priv->transport_widget);
754 proto = modest_transport_widget_get_proto (transport);
757 if (proto == MODEST_PROTOCOL_TRANSPORT_SMTP) {
758 servername = modest_transport_widget_get_servername (transport);
759 if (modest_transport_widget_get_requires_auth (transport))
760 username = modest_transport_widget_get_username (transport);
763 transport_name = get_new_server_account_name (priv->account_mgr, proto,username, servername);
764 modest_account_mgr_add_server_account (priv->account_mgr,
765 transport_name, servername,
766 0, /* FIXME: does this mean default?*/
768 proto, security, auth);
771 account_name = get_account_name (self);
772 modest_account_mgr_add_account (priv->account_mgr,
777 MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY,
779 transport_name, TRUE);
783 g_free (transport_name);
789 modest_account_assistant_new (ModestAccountMgr *account_mgr)
792 ModestAccountAssistant *self;
793 ModestAccountAssistantPrivate *priv;
795 g_return_val_if_fail (account_mgr, NULL);
797 obj = g_object_new(MODEST_TYPE_ACCOUNT_ASSISTANT, NULL);
798 self = MODEST_ACCOUNT_ASSISTANT(obj);
800 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
802 g_object_ref (account_mgr);
803 priv->account_mgr = account_mgr;
805 add_intro_page (self);
806 add_identity_page (self);
807 add_receiving_page (self);
808 add_sending_page (self);
809 add_final_page (self);
811 gtk_assistant_set_current_page (GTK_ASSISTANT(self), 0);
812 gtk_window_set_title (GTK_WINDOW(self),
813 _("Modest Account Wizard"));
814 gtk_window_set_resizable (GTK_WINDOW(self), TRUE);
815 gtk_window_set_default_size (GTK_WINDOW(self), 400, 400);
817 gtk_window_set_modal (GTK_WINDOW(self), TRUE);
819 g_signal_connect (G_OBJECT(self), "apply",
820 G_CALLBACK(on_apply), NULL);
821 g_signal_connect (G_OBJECT(self), "cancel",
822 G_CALLBACK(on_cancel), NULL);
823 g_signal_connect (G_OBJECT(self), "close",
824 G_CALLBACK(on_close), NULL);
826 return GTK_WIDGET(self);