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;
65 GtkWidget *store_server_widget;
66 GtkWidget *store_protocol_combo;
67 GtkWidget *store_security_combo;
68 GtkWidget *store_secure_auth;
70 GtkWidget *transport_widget;
72 GtkWidget *transport_holder;
74 ModestPairList *receiving_transport_store_protos;
75 ModestPairList *sending_transport_store_protos;
76 ModestPairList *security_protos;
79 #define MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
80 MODEST_TYPE_ACCOUNT_ASSISTANT, \
81 ModestAccountAssistantPrivate))
83 static GtkAssistantClass *parent_class = NULL;
85 /* uncomment the following if you have defined any signals */
86 /* static guint signals[LAST_SIGNAL] = {0}; */
89 modest_account_assistant_get_type (void)
91 static GType my_type = 0;
93 static const GTypeInfo my_info = {
94 sizeof(ModestAccountAssistantClass),
96 NULL, /* base finalize */
97 (GClassInitFunc) modest_account_assistant_class_init,
98 NULL, /* class finalize */
99 NULL, /* class data */
100 sizeof(ModestAccountAssistant),
102 (GInstanceInitFunc) modest_account_assistant_init,
105 my_type = g_type_register_static (GTK_TYPE_ASSISTANT,
106 "ModestAccountAssistant",
113 modest_account_assistant_class_init (ModestAccountAssistantClass *klass)
115 GObjectClass *gobject_class;
116 gobject_class = (GObjectClass*) klass;
118 parent_class = g_type_class_peek_parent (klass);
119 gobject_class->finalize = modest_account_assistant_finalize;
121 g_type_class_add_private (gobject_class, sizeof(ModestAccountAssistantPrivate));
123 /* signal definitions go here, e.g.: */
124 /* signals[MY_SIGNAL_1] = */
125 /* g_signal_new ("my_signal_1",....); */
126 /* signals[MY_SIGNAL_2] = */
127 /* g_signal_new ("my_signal_2",....); */
134 add_intro_page (ModestAccountAssistant *assistant)
136 GtkWidget *page, *label;
138 page = gtk_vbox_new (FALSE, 12);
140 label = gtk_label_new (_("mcen_ia_emailsetup_intro"));
141 gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
142 gtk_misc_set_padding (GTK_MISC (label), 12, 12);
143 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
144 gtk_box_pack_start (GTK_BOX(page), label, FALSE, FALSE, 0);
145 gtk_widget_set_size_request (label, 400, -1);
146 gtk_widget_show_all (page);
148 gtk_assistant_append_page (GTK_ASSISTANT(assistant), page);
150 gtk_assistant_set_page_title (GTK_ASSISTANT(assistant), page,
151 _("mcen_ti_emailsetup_welcome"));
152 gtk_assistant_set_page_type (GTK_ASSISTANT(assistant), page,
153 GTK_ASSISTANT_PAGE_INTRO);
154 gtk_assistant_set_page_complete (GTK_ASSISTANT(assistant),
160 set_current_page_complete (ModestAccountAssistant *self, gboolean complete)
165 pageno = gtk_assistant_get_current_page (GTK_ASSISTANT(self));
168 page = gtk_assistant_get_nth_page (GTK_ASSISTANT(self), pageno);
169 gtk_assistant_set_page_complete (GTK_ASSISTANT(self), page, complete);
175 identity_page_update_completeness (GtkEditable *editable,
176 ModestAccountAssistant *self)
178 ModestAccountAssistantPrivate *priv;
181 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
183 txt = gtk_entry_get_text (GTK_ENTRY(priv->fullname));
184 if (!txt || strlen(txt) == 0) {
185 set_current_page_complete (self, FALSE);
189 /* FIXME: regexp check for email address */
190 txt = gtk_entry_get_text (GTK_ENTRY(priv->email));
191 if (!modest_text_utils_validate_email_address (txt, NULL)) {
192 set_current_page_complete (self, FALSE);
196 txt = gtk_entry_get_text (GTK_ENTRY(priv->username));
197 if (!txt || txt[0] == '\0') {
198 set_current_page_complete (self, FALSE);
201 set_current_page_complete (self, TRUE);
205 field_name_label (const gchar *text)
210 fixed_text = g_strconcat (text, ":", NULL);
211 label = gtk_label_new (fixed_text);
213 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
219 add_identity_page (ModestAccountAssistant *self)
221 GtkWidget *page, *label, *table, *frame;
222 GtkWidget *alignment;
223 ModestAccountAssistantPrivate *priv;
225 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
227 priv->account_name = gtk_entry_new ();
228 gtk_entry_set_max_length (GTK_ENTRY (priv->fullname), 40);
229 priv->fullname = gtk_entry_new ();
230 gtk_entry_set_max_length (GTK_ENTRY (priv->fullname), 40);
231 priv->email = gtk_entry_new ();
232 gtk_entry_set_width_chars (GTK_ENTRY (priv->email), 40);
233 priv->username = gtk_entry_new ();
234 gtk_entry_set_width_chars (GTK_ENTRY (priv->username), 40);
235 priv->password = gtk_entry_new ();
236 gtk_entry_set_width_chars (GTK_ENTRY (priv->password), 40);
237 gtk_entry_set_visibility (GTK_ENTRY (priv->password), FALSE);
239 page = gtk_vbox_new (FALSE, 24);
241 label = gtk_label_new (
242 _("Please enter below the name for the account you're creating."));
243 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
244 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
245 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
246 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 12, 12);
247 gtk_container_add (GTK_CONTAINER (alignment), label);
248 gtk_box_pack_start (GTK_BOX(page), alignment, FALSE, FALSE, 0);
250 table = gtk_table_new (1,2, FALSE);
251 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
252 gtk_table_set_row_spacings (GTK_TABLE (table), 1);
253 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Account name")),
255 gtk_table_attach_defaults (GTK_TABLE(table),priv->account_name,
257 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
258 gtk_container_add (GTK_CONTAINER (alignment), table);
259 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 12, 0);
260 gtk_box_pack_start (GTK_BOX(page), alignment, FALSE, FALSE, 0);
262 frame = gtk_frame_new (NULL);
263 label = gtk_label_new (NULL);
264 gtk_label_set_markup (GTK_LABEL (label), _("<b>Public information </b>"));
265 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
266 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
267 table = gtk_table_new (2,2, FALSE);
268 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
269 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
270 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Full name")),
272 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Email address")),
274 gtk_table_attach_defaults (GTK_TABLE(table),priv->fullname,
276 gtk_table_attach_defaults (GTK_TABLE(table),priv->email,
278 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
279 gtk_container_add (GTK_CONTAINER (alignment), table);
280 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
281 gtk_container_add (GTK_CONTAINER (frame), alignment);
282 gtk_box_pack_start (GTK_BOX(page), frame, FALSE, FALSE, 0);
285 frame = gtk_frame_new (NULL);
286 label = gtk_label_new (NULL);
287 gtk_label_set_markup (GTK_LABEL (label), _("<b>Server account </b>"));
288 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
289 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
290 table = gtk_table_new (2,2, FALSE);
291 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
292 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
293 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("User name")),
295 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Password")),
297 gtk_table_attach_defaults (GTK_TABLE(table),priv->username,
299 gtk_table_attach_defaults (GTK_TABLE(table),priv->password,
301 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
302 gtk_container_add (GTK_CONTAINER (alignment), table);
303 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
304 gtk_container_add (GTK_CONTAINER (frame), alignment);
305 gtk_box_pack_start (GTK_BOX(page), frame, FALSE, FALSE, 0);
307 g_signal_connect (G_OBJECT(priv->fullname), "changed",
308 G_CALLBACK(identity_page_update_completeness),
310 g_signal_connect (G_OBJECT(priv->username), "changed",
311 G_CALLBACK(identity_page_update_completeness),
313 g_signal_connect (G_OBJECT(priv->password), "changed",
314 G_CALLBACK(identity_page_update_completeness),
316 g_signal_connect (G_OBJECT(priv->email), "changed",
317 G_CALLBACK(identity_page_update_completeness),
319 g_signal_connect (G_OBJECT(priv->account_name), "changed",
320 G_CALLBACK(identity_page_update_completeness),
324 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
325 gtk_container_add (GTK_CONTAINER (alignment), page);
326 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 12, 12, 12);
327 gtk_widget_show_all (alignment);
328 gtk_assistant_append_page (GTK_ASSISTANT(self), alignment);
330 gtk_assistant_set_page_title (GTK_ASSISTANT(self), alignment,
332 gtk_assistant_set_page_type (GTK_ASSISTANT(self), alignment,
333 GTK_ASSISTANT_PAGE_CONTENT);
334 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
340 receiving_page_update_completeness (GtkEditable *editable,
341 ModestAccountAssistant *self)
343 ModestAccountAssistantPrivate *priv;
346 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
348 txt = gtk_entry_get_text (GTK_ENTRY (priv->store_server_widget));
349 if (!txt || strlen(txt) == 0) {
350 set_current_page_complete (self, FALSE);
353 set_current_page_complete (self, TRUE);
357 add_receiving_page (ModestAccountAssistant *self)
359 GtkWidget *page, *vbox;
360 GtkWidget *table, *frame;
361 GtkWidget *alignment;
362 ModestAccountAssistantPrivate *priv;
365 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
366 page = gtk_alignment_new (0.5, 0.0, 1.0, 0.0);
367 gtk_alignment_set_padding (GTK_ALIGNMENT (page), 12, 12, 12, 12);
368 vbox = gtk_vbox_new (FALSE, 24);
369 gtk_container_add (GTK_CONTAINER (page), vbox);
371 /* Warning label on top */
372 label = gtk_label_new (_("TODO: Note unable to..."));
373 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
374 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
375 gtk_box_pack_start (GTK_BOX(vbox),
379 /* Note: This ModestPairList* must exist for as long as the combo
380 * that uses it, because the ModestComboBox uses the ID opaquely,
381 * so it can't know how to manage its memory. */
382 priv->receiving_transport_store_protos =
383 modest_protocol_info_get_supported_store_protocol_pair_list ();
384 priv->store_protocol_combo = modest_combo_box_new (priv->receiving_transport_store_protos, g_str_equal);
385 priv->store_server_widget = gtk_entry_new ();
387 /* Setup incoming server frame */
388 frame = gtk_frame_new (NULL);
389 label = gtk_label_new (NULL);
390 gtk_label_set_markup (GTK_LABEL (label), _("<b>Incoming server</b>"));
391 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
392 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
393 table = gtk_table_new (2, 2, FALSE);
394 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
395 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
396 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Account type")),
399 alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
400 gtk_container_add (GTK_CONTAINER (alignment), priv->store_protocol_combo);
401 gtk_table_attach (GTK_TABLE (table), alignment,
403 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
404 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Incoming server")),
406 GTK_FILL, GTK_FILL, 0, 0);
407 gtk_table_attach (GTK_TABLE (table), priv->store_server_widget,
409 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
410 alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
411 gtk_container_add (GTK_CONTAINER (alignment), table);
412 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
413 gtk_container_add (GTK_CONTAINER (frame), alignment);
414 gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0);
416 /* Setup security information widgets */
417 priv->security_protos =
418 modest_protocol_info_get_connection_protocol_pair_list ();
419 priv->store_security_combo = modest_combo_box_new (priv->security_protos, g_str_equal);
420 priv->store_secure_auth = gtk_check_button_new ();
422 /* Setup security frame */
423 frame = gtk_frame_new (NULL);
424 label = gtk_label_new (NULL);
425 gtk_label_set_markup (GTK_LABEL (label), _("<b>Security options</b>"));
426 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
427 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
428 table = gtk_table_new (2, 2, FALSE);
429 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
430 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
431 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Secure connection")),
434 gtk_table_attach (GTK_TABLE (table), priv->store_security_combo,
436 GTK_FILL | GTK_EXPAND, 0, 0, 0);
437 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Use secure authentication")),
439 GTK_FILL, GTK_FILL, 0, 0);
440 gtk_table_attach_defaults (GTK_TABLE (table), priv->store_secure_auth,
442 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
443 gtk_container_add (GTK_CONTAINER (alignment), table);
444 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
445 gtk_container_add (GTK_CONTAINER (frame), alignment);
446 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, FALSE, 0);
448 /* Setup assistant page */
449 gtk_assistant_append_page (GTK_ASSISTANT(self), page);
451 gtk_assistant_set_page_title (GTK_ASSISTANT(self), page,
452 _("Receiving mail"));
453 gtk_assistant_set_page_type (GTK_ASSISTANT(self), page,
454 GTK_ASSISTANT_PAGE_CONTENT);
455 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
457 gtk_widget_show_all (page);
464 on_sending_combo_box_changed (GtkComboBox *combo, ModestAccountAssistant *self)
466 ModestAccountAssistantPrivate *priv;
469 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
471 chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combo));
473 if (priv->transport_widget)
474 gtk_container_remove (GTK_CONTAINER(priv->transport_holder),
475 priv->transport_widget);
476 priv->transport_widget =
477 modest_transport_widget_new (modest_protocol_info_get_transport_store_protocol(chosen));
479 gtk_container_add (GTK_CONTAINER(priv->transport_holder),
480 priv->transport_widget);
482 gtk_widget_show_all (priv->transport_holder);
488 add_sending_page (ModestAccountAssistant *self)
490 GtkWidget *page, *box, *combo;
491 ModestAccountAssistantPrivate *priv;
493 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
494 page = gtk_vbox_new (FALSE, 6);
496 gtk_box_pack_start (GTK_BOX(page),
498 _("Please select among the following options")),
500 box = gtk_hbox_new (FALSE, 0);
501 gtk_box_pack_start (GTK_BOX(box),
502 gtk_label_new(_("Server type")),
505 /* Note: This ModestPairList* must exist for as long as the combo
506 * that uses it, because the ModestComboBox uses the ID opaquely,
507 * so it can't know how to manage its memory. */
508 priv->sending_transport_store_protos = modest_protocol_info_get_transport_store_protocol_pair_list ();
509 combo = modest_combo_box_new (priv->sending_transport_store_protos, g_str_equal);
511 g_signal_connect (G_OBJECT(combo), "changed",
512 G_CALLBACK(on_sending_combo_box_changed), self);
514 gtk_box_pack_start (GTK_BOX(box), combo, FALSE,FALSE,0);
515 gtk_box_pack_start (GTK_BOX(page), box, FALSE,FALSE, 0);
517 gtk_box_pack_start (GTK_BOX(page), gtk_hseparator_new(), FALSE, FALSE, 0);
519 priv->transport_holder = gtk_hbox_new (FALSE, 0);
520 gtk_box_pack_start (GTK_BOX(page), priv->transport_holder,
523 /* Force the selection */
524 on_sending_combo_box_changed (GTK_COMBO_BOX (combo), self);
526 gtk_assistant_append_page (GTK_ASSISTANT(self), page);
528 gtk_assistant_set_page_title (GTK_ASSISTANT(self), page,
530 gtk_assistant_set_page_type (GTK_ASSISTANT(self), page,
531 GTK_ASSISTANT_PAGE_INTRO);
532 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
534 gtk_widget_show_all (page);
540 add_final_page (ModestAccountAssistant *self)
542 GtkWidget *page, *box;
543 ModestAccountAssistantPrivate *priv;
545 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
546 page = gtk_vbox_new (FALSE, 6);
548 gtk_box_pack_start (GTK_BOX(page),
550 _("We're almost done. Press 'Apply' to store this new account")),
552 box = gtk_hbox_new (FALSE, 6);
554 gtk_entry_new_with_max_length (40);
555 gtk_entry_set_text (GTK_ENTRY(priv->account_name),
556 gtk_entry_get_text(GTK_ENTRY(priv->email)));
557 gtk_box_pack_start (GTK_BOX(box),gtk_label_new(_("Account name:")),
559 gtk_box_pack_start (GTK_BOX(box),priv->account_name , FALSE,FALSE,6);
561 gtk_box_pack_start (GTK_BOX(page), box, FALSE, FALSE, 6);
563 gtk_assistant_append_page (GTK_ASSISTANT(self), page);
565 gtk_assistant_set_page_title (GTK_ASSISTANT(self), page,
566 _("Account Management"));
567 gtk_assistant_set_page_type (GTK_ASSISTANT(self), page,
568 GTK_ASSISTANT_PAGE_CONFIRM);
570 gtk_assistant_set_page_complete (GTK_ASSISTANT(self),
572 gtk_widget_show_all (page);
577 modest_account_assistant_init (ModestAccountAssistant *obj)
579 ModestAccountAssistantPrivate *priv;
580 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(obj);
582 priv->account_mgr = NULL;
584 priv->store_server_widget = NULL;
585 priv->transport_widget = NULL;
589 modest_account_assistant_finalize (GObject *obj)
591 ModestAccountAssistantPrivate *priv;
593 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(obj);
595 if (priv->account_mgr) {
596 g_object_unref (G_OBJECT(priv->account_mgr));
597 priv->account_mgr = NULL;
600 /* These had to stay alive for as long as the comboboxes that used them: */
601 modest_pair_list_free (priv->receiving_transport_store_protos);
602 modest_pair_list_free (priv->sending_transport_store_protos);
604 G_OBJECT_CLASS(parent_class)->finalize (obj);
608 on_cancel (ModestAccountAssistant *self, gpointer user_data)
614 label = gtk_label_new (_("Are you sure you want to cancel\n"
615 "setting up a new account?"));
617 dialog = gtk_dialog_new_with_buttons (_("Cancel"),
619 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
620 GTK_STOCK_YES, GTK_RESPONSE_ACCEPT,
621 GTK_STOCK_NO, GTK_RESPONSE_CANCEL,
624 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
625 label, FALSE, FALSE, 6);
627 gtk_widget_show_all ((GTK_DIALOG(dialog)->vbox));
629 gtk_window_set_resizable (GTK_WINDOW(dialog), FALSE);
631 response = gtk_dialog_run (GTK_DIALOG(dialog));
632 gtk_widget_destroy (dialog);
635 case GTK_RESPONSE_ACCEPT:
636 /* close the assistant */
637 gtk_widget_hide (GTK_WIDGET(self));
639 case GTK_RESPONSE_CANCEL:
640 /* don't do anything */
642 default: g_assert_not_reached ();
648 get_account_name (ModestAccountAssistant *self)
650 ModestAccountAssistantPrivate *priv;
651 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
653 return gtk_entry_get_text (GTK_ENTRY(priv->account_name));
657 get_fullname (ModestAccountAssistant *self)
659 ModestAccountAssistantPrivate *priv;
660 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
662 return gtk_entry_get_text (GTK_ENTRY(priv->fullname));
668 get_email (ModestAccountAssistant *self)
670 ModestAccountAssistantPrivate *priv;
671 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
673 return gtk_entry_get_text (GTK_ENTRY(priv->email));
678 on_close (ModestAccountAssistant *self, gpointer user_data)
680 gtk_widget_hide (GTK_WIDGET (self));
685 * FIXME: hmmmm this a Camel internal thing, should move this
689 get_account_uri (ModestTransportStoreProtocol proto, const gchar* path)
695 case MODEST_PROTOCOL_STORE_MBOX:
696 url = camel_url_new ("mbox:", NULL); break;
697 case MODEST_PROTOCOL_STORE_MAILDIR:
698 url = camel_url_new ("maildir:", NULL); break;
700 g_return_val_if_reached (NULL);
702 camel_url_set_path (url, path);
703 uri = camel_url_to_string (url, 0);
704 camel_url_free (url);
710 get_new_server_account_name (ModestAccountMgr* acc_mgr, ModestTransportStoreProtocol proto,
711 const gchar* username, const gchar *servername)
717 name = g_strdup_printf ("%s:%d",
718 modest_protocol_info_get_transport_store_protocol_name(proto), i++);
719 if (modest_account_mgr_account_exists (acc_mgr, name, TRUE))
729 on_apply (ModestAccountAssistant *self, gpointer user_data)
731 /* ModestAccountAssistantPrivate *priv; */
732 /* ModestTransportStoreProtocol proto = MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN; */
733 /* ModestAuthProtocol security = MODEST_PROTOCOL_CONNECTION_NORMAL; */
734 /* ModestConnectionProtocol auth = MODEST_PROTOCOL_AUTH_NONE; */
735 /* gchar *store_name, *transport_name; */
736 /* const gchar *account_name, *username, *servername, *path; */
737 /* ModestTransportWidget *transport; */
739 /* priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self); */
741 /* /\* create server account -> store *\/ */
742 /* store = MODEST_STORE_WIDGET(priv->store_widget); */
743 /* proto = modest_store_widget_get_proto (store); */
744 /* username = modest_store_widget_get_username (store); */
745 /* servername = modest_store_widget_get_servername (store); */
746 /* path = modest_store_widget_get_path (store); */
747 /* security = modest_store_widget_get_security (store); */
748 /* auth = modest_store_widget_get_auth (store); */
749 /* store_name = get_new_server_account_name (priv->account_mgr, proto,username, servername); */
751 /* if (proto == MODEST_PROTOCOL_STORE_MAILDIR || */
752 /* proto == MODEST_PROTOCOL_STORE_MBOX) { */
753 /* gchar *uri = get_account_uri (proto, path); */
754 /* modest_account_mgr_add_server_account_uri (priv->account_mgr, store_name, proto, uri); */
757 /* modest_account_mgr_add_server_account (priv->account_mgr, */
760 /* 0, /\* FIXME: does this mean default?*\/ */
767 /* /\* create server account -> transport *\/ */
768 /* transport = MODEST_TRANSPORT_WIDGET(priv->transport_widget); */
769 /* proto = modest_transport_widget_get_proto (transport); */
770 /* username = NULL; */
771 /* servername = NULL; */
772 /* if (proto == MODEST_PROTOCOL_TRANSPORT_SMTP) { */
773 /* servername = modest_transport_widget_get_servername (transport); */
774 /* if (modest_transport_widget_get_requires_auth (transport)) */
775 /* username = modest_transport_widget_get_username (transport); */
778 /* transport_name = get_new_server_account_name (priv->account_mgr, proto,username, servername); */
779 /* modest_account_mgr_add_server_account (priv->account_mgr, */
780 /* transport_name, servername, */
781 /* 0, /\* FIXME: does this mean default?*\/ */
782 /* username, NULL, */
783 /* proto, security, auth); */
785 /* /\* create account *\/ */
786 /* account_name = get_account_name (self); */
787 /* modest_account_mgr_add_account (priv->account_mgr, */
790 /* get_fullname (self), */
791 /* get_email (self), */
792 /* MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY, */
794 /* transport_name, TRUE); */
797 /* g_free (store_name); */
798 /* g_free (transport_name); */
804 modest_account_assistant_new (ModestAccountMgr *account_mgr)
807 ModestAccountAssistant *self;
808 ModestAccountAssistantPrivate *priv;
810 g_return_val_if_fail (account_mgr, NULL);
812 obj = g_object_new(MODEST_TYPE_ACCOUNT_ASSISTANT, NULL);
813 self = MODEST_ACCOUNT_ASSISTANT(obj);
815 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
817 g_object_ref (account_mgr);
818 priv->account_mgr = account_mgr;
820 add_intro_page (self);
821 add_identity_page (self);
822 add_receiving_page (self);
823 add_sending_page (self);
824 add_final_page (self);
826 gtk_assistant_set_current_page (GTK_ASSISTANT(self), 0);
827 gtk_window_set_title (GTK_WINDOW(self),
828 _("Modest Account Wizard"));
829 gtk_window_set_resizable (GTK_WINDOW(self), TRUE);
830 gtk_window_set_default_size (GTK_WINDOW(self), 400, 400);
832 gtk_window_set_modal (GTK_WINDOW(self), TRUE);
834 g_signal_connect (G_OBJECT(self), "apply",
835 G_CALLBACK(on_apply), NULL);
836 g_signal_connect (G_OBJECT(self), "cancel",
837 G_CALLBACK(on_cancel), NULL);
838 g_signal_connect (G_OBJECT(self), "close",
839 G_CALLBACK(on_close), NULL);
841 return GTK_WIDGET(self);