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-runtime.h"
39 #include "modest-utils.h"
40 #include "modest-protocol-registry.h"
41 #include "modest-platform.h"
42 #include "gnome/modest-gnome-utils.h"
46 /* 'private'/'protected' functions */
47 static void modest_account_assistant_class_init (ModestAccountAssistantClass *klass);
48 static void modest_account_assistant_init (ModestAccountAssistant *obj);
49 static void modest_account_assistant_finalize (GObject *obj);
50 static gboolean on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page);
51 static void on_response (ModestWizardDialog *wizard_dialog,
54 static void on_response_before (ModestWizardDialog *wizard_dialog,
65 typedef struct _ModestAccountAssistantPrivate ModestAccountAssistantPrivate;
66 struct _ModestAccountAssistantPrivate {
68 ModestAccountMgr *account_mgr;
69 ModestAccountSettings *settings;
74 GtkWidget *account_name;
80 GtkWidget *store_server_widget;
81 GtkWidget *store_protocol_combo;
82 GtkWidget *store_security_combo;
83 GtkWidget *store_secure_auth;
84 GtkWidget *transport_server_widget;
85 GtkWidget *transport_security_combo;
86 GtkWidget *transport_secure_auth_combo;
88 GtkWidget *transport_widget;
90 GtkWidget *transport_holder;
92 ModestPairList *receiving_transport_store_protos;
93 ModestPairList *sending_transport_store_protos;
94 ModestPairList *security_protos;
95 ModestPairList *transport_security_protos;
96 ModestPairList *transport_auth_protos;
99 #define MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
100 MODEST_TYPE_ACCOUNT_ASSISTANT, \
101 ModestAccountAssistantPrivate))
103 static GtkAssistantClass *parent_class = NULL;
105 /* uncomment the following if you have defined any signals */
106 /* static guint signals[LAST_SIGNAL] = {0}; */
108 static void save_to_settings (ModestAccountAssistant *self);
111 modest_account_assistant_get_type (void)
113 static GType my_type = 0;
115 static const GTypeInfo my_info = {
116 sizeof(ModestAccountAssistantClass),
117 NULL, /* base init */
118 NULL, /* base finalize */
119 (GClassInitFunc) modest_account_assistant_class_init,
120 NULL, /* class finalize */
121 NULL, /* class data */
122 sizeof(ModestAccountAssistant),
124 (GInstanceInitFunc) modest_account_assistant_init,
127 my_type = g_type_register_static (MODEST_TYPE_WIZARD_DIALOG,
128 "ModestAccountAssistant",
135 modest_account_assistant_class_init (ModestAccountAssistantClass *klass)
137 GObjectClass *gobject_class;
138 gobject_class = (GObjectClass*) klass;
140 parent_class = g_type_class_peek_parent (klass);
141 gobject_class->finalize = modest_account_assistant_finalize;
143 g_type_class_add_private (gobject_class, sizeof(ModestAccountAssistantPrivate));
145 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
146 base_klass->before_next = on_before_next;
150 on_delete_event (GtkWidget *widget,
152 ModestAccountAssistant *assistant)
154 gtk_dialog_response (GTK_DIALOG (assistant), GTK_RESPONSE_CANCEL);
159 on_assistant_changed(GtkWidget* widget, ModestAccountAssistant* assistant)
161 ModestAccountAssistantPrivate* priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(assistant);
162 g_return_if_fail (priv != NULL);
167 on_incoming_security_changed(GtkWidget* widget, ModestAccountAssistant* assistant)
169 ModestAccountAssistantPrivate* priv;
170 ModestProtocolType protocol_id;
171 ModestProtocol *protocol_security_incoming;
173 ModestProtocolRegistry *registry;
176 g_return_if_fail (MODEST_IS_ACCOUNT_ASSISTANT (assistant));
178 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(assistant);
179 registry = modest_runtime_get_protocol_registry ();
180 name = (const gchar *) modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->store_security_combo));
181 protocol_security_incoming = modest_protocol_registry_get_protocol_by_name (registry,
182 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS,
184 protocol_id = modest_protocol_get_type_id (protocol_security_incoming);
185 is_secure = modest_protocol_registry_protocol_type_is_secure (registry, protocol_id);
187 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->store_secure_auth), is_secure);
188 gtk_widget_set_sensitive (priv->store_secure_auth, !is_secure);
190 on_assistant_changed (widget, assistant);
194 invoke_enable_buttons_vfunc (ModestAccountAssistant *assistant)
196 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (assistant);
198 /* Call the vfunc, which may be overridden by derived classes: */
199 if (klass->enable_buttons) {
200 GtkNotebook *notebook = NULL;
201 g_object_get (assistant, "wizard-notebook", ¬ebook, NULL);
203 const gint current_page_num = gtk_notebook_get_current_page (notebook);
204 if (current_page_num == -1)
207 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
208 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (assistant), current_page_widget);
213 on_entry_changed (GtkEditable *editable, gpointer userdata)
215 on_assistant_changed (NULL, MODEST_ACCOUNT_ASSISTANT (userdata));
216 invoke_enable_buttons_vfunc(MODEST_ACCOUNT_ASSISTANT (userdata));
220 on_combo_changed (GtkComboBox *combo, gpointer userdata)
222 on_assistant_changed (NULL, MODEST_ACCOUNT_ASSISTANT (userdata));
223 invoke_enable_buttons_vfunc(MODEST_ACCOUNT_ASSISTANT (userdata));
227 add_intro_page (ModestAccountAssistant *assistant)
229 GtkWidget *page, *label;
230 ModestAccountAssistantPrivate *priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (assistant);
232 page = gtk_vbox_new (FALSE, 12);
234 label = gtk_label_new (_("mcen_ia_emailsetup_intro"));
235 gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
236 gtk_misc_set_padding (GTK_MISC (label), 12, 12);
237 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
238 gtk_box_pack_start (GTK_BOX(page), label, FALSE, FALSE, 0);
239 gtk_widget_set_size_request (label, 400, -1);
240 gtk_widget_show_all (page);
242 gtk_notebook_append_page (GTK_NOTEBOOK(priv->notebook), page, NULL);
244 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK(priv->notebook), page,
245 _("mcen_ti_emailsetup_welcome"));
246 /* gtk_notebook_set_page_type (GTK_NOTEBOOK(assistant), page, */
247 /* GTK_ASSISTANT_PAGE_INTRO); */
248 /* gtk_notebook_set_page_complete (GTK_ASSISTANT(assistant), */
254 set_current_page_complete (ModestAccountAssistant *self, gboolean complete)
258 ModestAccountAssistantPrivate *priv;
260 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (self);
262 pageno = gtk_notebook_get_current_page (GTK_NOTEBOOK(priv->notebook));
265 page = gtk_notebook_get_nth_page (GTK_NOTEBOOK(priv->notebook), pageno);
266 /* gtk_assistant_set_page_complete (GTK_NOTEBOOK(priv->notebook), page, complete); */
272 field_name_label (const gchar *text)
277 fixed_text = g_strconcat (text, ":", NULL);
278 label = gtk_label_new (fixed_text);
280 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
286 add_identity_page (ModestAccountAssistant *self)
288 GtkWidget *page, *label, *table, *frame;
289 GtkWidget *alignment;
290 ModestAccountAssistantPrivate *priv;
292 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
294 priv->account_name = gtk_entry_new ();
295 gtk_entry_set_max_length (GTK_ENTRY (priv->account_name), 40);
296 g_signal_connect (G_OBJECT (priv->account_name), "changed", G_CALLBACK (on_entry_changed), self);
297 priv->fullname = gtk_entry_new ();
298 gtk_entry_set_max_length (GTK_ENTRY (priv->fullname), 40);
299 g_signal_connect (G_OBJECT (priv->fullname), "changed", G_CALLBACK (on_entry_changed), self);
300 priv->email = gtk_entry_new ();
301 gtk_entry_set_width_chars (GTK_ENTRY (priv->email), 40);
302 g_signal_connect (G_OBJECT (priv->email), "changed", G_CALLBACK (on_entry_changed), self);
303 priv->username = gtk_entry_new ();
304 gtk_entry_set_width_chars (GTK_ENTRY (priv->username), 40);
305 g_signal_connect (G_OBJECT (priv->username), "changed", G_CALLBACK (on_entry_changed), self);
306 priv->password = gtk_entry_new ();
307 gtk_entry_set_width_chars (GTK_ENTRY (priv->password), 40);
308 gtk_entry_set_visibility (GTK_ENTRY (priv->password), FALSE);
310 page = gtk_vbox_new (FALSE, 24);
312 label = gtk_label_new (
313 _("Please enter below the name for the account you're creating."));
314 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
315 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
316 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
317 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 12, 12);
318 gtk_container_add (GTK_CONTAINER (alignment), label);
319 gtk_box_pack_start (GTK_BOX(page), alignment, FALSE, FALSE, 0);
321 table = gtk_table_new (1,2, FALSE);
322 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
323 gtk_table_set_row_spacings (GTK_TABLE (table), 1);
324 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Account name")),
326 gtk_table_attach_defaults (GTK_TABLE(table),priv->account_name,
328 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
329 gtk_container_add (GTK_CONTAINER (alignment), table);
330 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 12, 0);
331 gtk_box_pack_start (GTK_BOX(page), alignment, FALSE, FALSE, 0);
333 frame = gtk_frame_new (NULL);
334 label = gtk_label_new (NULL);
335 gtk_label_set_markup (GTK_LABEL (label), _("<b>Public information </b>"));
336 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
337 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
338 table = gtk_table_new (2,2, FALSE);
339 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
340 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
341 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Full name")),
343 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Email address")),
345 gtk_table_attach_defaults (GTK_TABLE(table),priv->fullname,
347 gtk_table_attach_defaults (GTK_TABLE(table),priv->email,
349 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
350 gtk_container_add (GTK_CONTAINER (alignment), table);
351 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
352 gtk_container_add (GTK_CONTAINER (frame), alignment);
353 gtk_box_pack_start (GTK_BOX(page), frame, FALSE, FALSE, 0);
356 frame = gtk_frame_new (NULL);
357 label = gtk_label_new (NULL);
358 gtk_label_set_markup (GTK_LABEL (label), _("<b>Server account </b>"));
359 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
360 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
361 table = gtk_table_new (2,2, FALSE);
362 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
363 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
364 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("User name")),
366 gtk_table_attach_defaults (GTK_TABLE(table),field_name_label (_("Password")),
368 gtk_table_attach_defaults (GTK_TABLE(table),priv->username,
370 gtk_table_attach_defaults (GTK_TABLE(table),priv->password,
372 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
373 gtk_container_add (GTK_CONTAINER (alignment), table);
374 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
375 gtk_container_add (GTK_CONTAINER (frame), alignment);
376 gtk_box_pack_start (GTK_BOX(page), frame, FALSE, FALSE, 0);
378 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
379 gtk_container_add (GTK_CONTAINER (alignment), page);
380 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 12, 12, 12);
381 gtk_widget_show_all (alignment);
382 gtk_notebook_append_page (GTK_NOTEBOOK(priv->notebook), alignment, NULL);
384 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK(priv->notebook), alignment,
386 /* gtk_assistant_set_page_type (GTK_ASSISTANT(self), alignment, */
387 /* GTK_ASSISTANT_PAGE_CONTENT); */
388 /* gtk_assistant_set_page_complete (GTK_ASSISTANT(self), */
389 /* alignment, FALSE); */
394 receiving_page_update_completeness (GtkEditable *editable,
395 ModestAccountAssistant *self)
397 ModestAccountAssistantPrivate *priv;
400 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
402 txt = gtk_entry_get_text (GTK_ENTRY (priv->store_server_widget));
403 if (!txt || strlen(txt) == 0) {
404 set_current_page_complete (self, FALSE);
407 set_current_page_complete (self, TRUE);
411 add_receiving_page (ModestAccountAssistant *self)
413 GtkWidget *page, *vbox;
414 GtkWidget *table, *frame;
415 GtkWidget *alignment;
416 ModestAccountAssistantPrivate *priv;
418 const gchar *tag = MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS;
420 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
421 page = gtk_alignment_new (0.5, 0.0, 1.0, 0.0);
422 gtk_alignment_set_padding (GTK_ALIGNMENT (page), 12, 12, 12, 12);
423 vbox = gtk_vbox_new (FALSE, 24);
424 gtk_container_add (GTK_CONTAINER (page), vbox);
426 /* Warning label on top */
427 label = gtk_label_new (_("Setting details for the incoming mail server."));
428 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
429 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
430 gtk_box_pack_start (GTK_BOX(vbox),
434 /* Note: This ModestPairList* must exist for as long as the combo
435 * that uses it, because the ModestComboBox uses the ID opaquely,
436 * so it can't know how to manage its memory. */
437 priv->receiving_transport_store_protos = modest_gnome_utils_get_protocols_pair_list (tag);
438 priv->store_protocol_combo = modest_combo_box_new (priv->receiving_transport_store_protos, g_str_equal);
439 priv->store_server_widget = gtk_entry_new ();
441 /* Setup incoming server frame */
442 frame = gtk_frame_new (NULL);
443 label = gtk_label_new (NULL);
444 gtk_label_set_markup (GTK_LABEL (label), _("<b>Incoming server</b>"));
445 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
446 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
447 table = gtk_table_new (2, 2, FALSE);
448 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
449 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
450 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Account type")),
453 alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
454 gtk_container_add (GTK_CONTAINER (alignment), priv->store_protocol_combo);
455 gtk_table_attach (GTK_TABLE (table), alignment,
457 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
458 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Incoming server")),
460 GTK_FILL, GTK_FILL, 0, 0);
461 gtk_table_attach (GTK_TABLE (table), priv->store_server_widget,
463 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
464 alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
465 gtk_container_add (GTK_CONTAINER (alignment), table);
466 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
467 gtk_container_add (GTK_CONTAINER (frame), alignment);
468 gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0);
470 /* Setup security information widgets */
471 tag = MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS;
472 priv->security_protos = modest_gnome_utils_get_protocols_pair_list (tag);
473 priv->store_security_combo = modest_combo_box_new (priv->security_protos, g_str_equal);
474 priv->store_secure_auth = gtk_check_button_new ();
476 /* Setup security frame */
477 frame = gtk_frame_new (NULL);
478 label = gtk_label_new (NULL);
479 gtk_label_set_markup (GTK_LABEL (label), _("<b>Security options</b>"));
480 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
481 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
482 table = gtk_table_new (2, 2, FALSE);
483 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
484 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
485 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Secure connection")),
488 gtk_table_attach (GTK_TABLE (table), priv->store_security_combo,
490 GTK_FILL | GTK_EXPAND, 0, 0, 0);
491 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Use secure authentication")),
493 GTK_FILL, GTK_FILL, 0, 0);
494 gtk_table_attach_defaults (GTK_TABLE (table), priv->store_secure_auth,
496 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
497 gtk_container_add (GTK_CONTAINER (alignment), table);
498 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
499 gtk_container_add (GTK_CONTAINER (frame), alignment);
500 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, FALSE, 0);
502 /* Setup assistant page */
503 gtk_notebook_append_page (GTK_NOTEBOOK(priv->notebook), page, NULL);
505 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK(priv->notebook), page,
506 _("Incoming details"));
507 gtk_widget_show_all (page);
514 on_sending_combo_box_changed (GtkComboBox *combo, ModestAccountAssistant *self)
516 ModestAccountAssistantPrivate *priv;
518 ModestProtocol *proto;
520 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
522 chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combo));
524 if (priv->transport_widget)
525 gtk_container_remove (GTK_CONTAINER(priv->transport_holder),
526 priv->transport_widget);
528 proto = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
529 MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS,
531 priv->transport_widget = modest_transport_widget_new (modest_protocol_get_type_id (proto));
533 gtk_container_add (GTK_CONTAINER(priv->transport_holder),
534 priv->transport_widget);
536 gtk_widget_show_all (priv->transport_holder);
537 on_assistant_changed (NULL, MODEST_ACCOUNT_ASSISTANT (self));
543 add_sending_page (ModestAccountAssistant *self)
545 GtkWidget *page, *vbox;
546 GtkWidget *table, *frame;
547 GtkWidget *alignment;
548 ModestAccountAssistantPrivate *priv;
550 const gchar *tag = MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS;
552 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
553 page = gtk_alignment_new (0.5, 0.0, 1.0, 0.0);
554 gtk_alignment_set_padding (GTK_ALIGNMENT (page), 12, 12, 12, 12);
555 vbox = gtk_vbox_new (FALSE, 24);
556 gtk_container_add (GTK_CONTAINER (page), vbox);
558 /* Warning label on top */
559 label = gtk_label_new (_("Settings for the outgoing mail server"));
560 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
561 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
562 gtk_box_pack_start (GTK_BOX(vbox),
566 priv->transport_server_widget = gtk_entry_new ();
567 /* Setup incoming server frame */
568 frame = gtk_frame_new (NULL);
569 label = gtk_label_new (NULL);
570 gtk_label_set_markup (GTK_LABEL (label), _("<b>Outgoing server</b>"));
571 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
572 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
573 table = gtk_table_new (2, 2, FALSE);
574 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
575 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
576 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Outgoing server (SMTP)")),
578 GTK_FILL, GTK_FILL, 0, 0);
579 gtk_table_attach (GTK_TABLE (table), priv->transport_server_widget,
581 GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
582 alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
583 gtk_container_add (GTK_CONTAINER (alignment), table);
584 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
585 gtk_container_add (GTK_CONTAINER (frame), alignment);
586 gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0);
588 /* Setup security information widgets */
589 priv->transport_security_protos = modest_gnome_utils_get_protocols_pair_list (tag);
590 priv->transport_security_combo = modest_combo_box_new (priv->security_protos, g_str_equal);
591 tag = MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS;
592 priv->transport_auth_protos = modest_gnome_utils_get_protocols_pair_list (tag);
593 priv->transport_secure_auth_combo = GTK_WIDGET (modest_combo_box_new (priv->transport_auth_protos, g_str_equal));
595 /* Setup security frame */
596 frame = gtk_frame_new (NULL);
597 label = gtk_label_new (NULL);
598 gtk_label_set_markup (GTK_LABEL (label), _("<b>Security options</b>"));
599 gtk_frame_set_label_widget (GTK_FRAME (frame), label);
600 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
601 table = gtk_table_new (2, 2, FALSE);
602 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
603 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
604 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Secure connection")),
607 gtk_table_attach (GTK_TABLE (table), priv->transport_security_combo,
609 GTK_FILL | GTK_EXPAND, 0, 0, 0);
610 gtk_table_attach (GTK_TABLE (table), field_name_label (_("Secure authentication")),
612 GTK_FILL, GTK_FILL, 0, 0);
613 gtk_table_attach_defaults (GTK_TABLE (table), priv->transport_secure_auth_combo,
615 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
616 gtk_container_add (GTK_CONTAINER (alignment), table);
617 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
618 gtk_container_add (GTK_CONTAINER (frame), alignment);
619 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, FALSE, 0);
621 /* Setup assistant page */
622 gtk_notebook_append_page (GTK_NOTEBOOK(priv->notebook), page, NULL);
624 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK(priv->notebook), page,
625 _("Outgoing details"));
626 gtk_widget_show_all (page);
631 modest_account_assistant_init (ModestAccountAssistant *obj)
633 ModestAccountAssistantPrivate *priv;
634 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(obj);
636 priv->account_mgr = NULL;
638 priv->store_server_widget = NULL;
639 priv->transport_widget = NULL;
640 priv->settings = modest_account_settings_new ();
643 priv->notebook = gtk_notebook_new ();
644 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
646 g_object_set (obj, "wizard-notebook", priv->notebook, NULL);
647 g_object_set (obj, "wizard-name", _("Account wizard"), NULL);
649 add_intro_page (obj);
650 add_identity_page (obj);
651 add_receiving_page (obj);
652 add_sending_page (obj);
654 gtk_notebook_set_current_page (GTK_NOTEBOOK(priv->notebook), 0);
655 gtk_window_set_resizable (GTK_WINDOW(obj), TRUE);
656 gtk_window_set_default_size (GTK_WINDOW(obj), 400, 400);
658 gtk_window_set_modal (GTK_WINDOW(obj), TRUE);
660 g_signal_connect_after (G_OBJECT (obj), "response",
661 G_CALLBACK (on_response), obj);
663 /* This is to show a confirmation dialog when the user hits cancel */
664 g_signal_connect (G_OBJECT (obj), "response",
665 G_CALLBACK (on_response_before), obj);
667 g_signal_connect (G_OBJECT (obj), "delete-event",
668 G_CALLBACK (on_delete_event), obj);
672 modest_account_assistant_finalize (GObject *obj)
674 ModestAccountAssistantPrivate *priv;
676 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(obj);
678 if (priv->account_mgr) {
679 g_object_unref (G_OBJECT(priv->account_mgr));
680 priv->account_mgr = NULL;
683 if (priv->settings) {
684 g_object_unref (G_OBJECT (priv->settings));
685 priv->settings = NULL;
688 /* These had to stay alive for as long as the comboboxes that used them: */
689 modest_pair_list_free (priv->receiving_transport_store_protos);
690 modest_pair_list_free (priv->sending_transport_store_protos);
692 G_OBJECT_CLASS(parent_class)->finalize (obj);
696 get_account_name (ModestAccountAssistant *self)
698 ModestAccountAssistantPrivate *priv;
699 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
701 return gtk_entry_get_text (GTK_ENTRY(priv->account_name));
705 get_fullname (ModestAccountAssistant *self)
707 ModestAccountAssistantPrivate *priv;
708 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
710 return gtk_entry_get_text (GTK_ENTRY(priv->fullname));
716 get_email (ModestAccountAssistant *self)
718 ModestAccountAssistantPrivate *priv;
719 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
721 return gtk_entry_get_text (GTK_ENTRY(priv->email));
727 * FIXME: hmmmm this a Camel internal thing, should move this
731 get_account_uri (ModestProtocolType proto, const gchar* path)
736 if (proto == modest_protocol_registry_get_mbox_type_id ()) {
737 url = camel_url_new ("mbox:", NULL);
739 if (proto == modest_protocol_registry_get_maildir_type_id ())
740 url = camel_url_new ("maildir:", NULL);
742 g_return_val_if_reached (NULL);
745 camel_url_set_path (url, path);
746 uri = camel_url_to_string (url, 0);
747 camel_url_free (url);
753 get_new_server_account_name (ModestAccountMgr* acc_mgr,
754 ModestProtocolType proto_id,
755 const gchar *username,
756 const gchar *servername)
759 const gchar *proto_name;
761 ModestProtocolRegistry *registry;
762 ModestProtocol *proto;
764 registry = modest_runtime_get_protocol_registry ();
765 proto = modest_protocol_registry_get_protocol_by_type (registry, proto_id);
766 proto_name = modest_protocol_get_name (proto);
769 name = g_strdup_printf ("%s:%d", proto_name, i++);
771 if (modest_account_mgr_account_exists (acc_mgr, name, TRUE))
782 modest_account_assistant_new (ModestAccountMgr *account_mgr)
785 ModestAccountAssistant *self;
786 ModestAccountAssistantPrivate *priv;
788 g_return_val_if_fail (account_mgr, NULL);
790 obj = g_object_new(MODEST_TYPE_ACCOUNT_ASSISTANT, NULL);
791 self = MODEST_ACCOUNT_ASSISTANT(obj);
793 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
795 g_object_ref (account_mgr);
796 priv->account_mgr = account_mgr;
798 return GTK_WIDGET(self);
802 get_entered_account_title (ModestAccountAssistant *self)
804 ModestAccountAssistantPrivate *priv;
805 const gchar* account_title;
807 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(self);
808 account_title = gtk_entry_get_text (GTK_ENTRY (priv->account_name));
810 if (!account_title || (strlen (account_title) == 0)) {
813 /* Strip it of whitespace at the start and end: */
814 gchar *result = g_strdup (account_title);
815 result = g_strstrip (result);
820 if (strlen (result) == 0) {
830 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
832 ModestAccountAssistant *self = MODEST_ACCOUNT_ASSISTANT (dialog);
833 ModestAccountAssistantPrivate *priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (self);
835 /* Do extra validation that couldn't be done for every key press,
836 * either because it was too slow,
837 * or because it requires interaction:
839 if(!next_page) /* This is NULL when this is a click on Finish. */
841 save_to_settings (self);
842 modest_account_mgr_add_account_from_settings (modest_runtime_get_account_mgr (), priv->settings);
850 get_serverport_incoming(ModestProtocolType protocol,
851 ModestProtocolType security)
853 int serverport_incoming = 0;
855 /* We don't check for SMTP here as that is impossible for an incoming server. */
856 if ((security == modest_protocol_registry_get_none_connection_type_id ()) ||
857 (security == modest_protocol_registry_get_tls_connection_type_id ()) ||
858 (security == modest_protocol_registry_get_tlsop_connection_type_id ())) {
860 if (protocol == MODEST_PROTOCOLS_STORE_IMAP) {
861 serverport_incoming = 143;
862 } else if (protocol == MODEST_PROTOCOLS_STORE_POP) {
863 serverport_incoming = 110;
865 } else if (security == modest_protocol_registry_get_ssl_connection_type_id ()) {
866 if (protocol == MODEST_PROTOCOLS_STORE_IMAP) {
867 serverport_incoming = 993;
868 } else if (protocol == MODEST_PROTOCOLS_STORE_POP) {
869 serverport_incoming = 995;
873 return serverport_incoming;
877 check_for_supported_auth_methods (ModestAccountAssistant* self)
879 GError *error = NULL;
880 ModestProtocolType protocol;
881 const gchar* hostname;
882 const gchar* username;
883 gchar *store_protocol_name, *store_security_name;
884 ModestProtocolType security_protocol;
886 GList *list_auth_methods;
887 ModestAccountAssistantPrivate *priv;
888 ModestProtocolRegistry *registry;
889 ModestProtocol *proto;
891 priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (self);
892 hostname = gtk_entry_get_text(GTK_ENTRY(priv->store_server_widget));
893 username = gtk_entry_get_text(GTK_ENTRY(priv->username));
894 store_protocol_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (priv->store_protocol_combo));
895 registry = modest_runtime_get_protocol_registry ();
896 proto = modest_protocol_registry_get_protocol_by_name (registry,
897 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS,
898 store_protocol_name);
899 protocol = modest_protocol_get_type_id (proto);
901 g_free (store_protocol_name);
902 store_security_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (priv->store_security_combo));
904 proto = modest_protocol_registry_get_protocol_by_name (registry,
905 MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS,
906 store_security_name);
907 security_protocol = modest_protocol_get_type_id (proto);
908 g_free (store_security_name);
909 port_num = get_serverport_incoming(protocol, security_protocol);
910 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num,
911 username, GTK_WINDOW (self), &error);
913 if (list_auth_methods) {
914 /* TODO: Select the correct method */
917 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
918 ModestProtocolType auth = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
919 if (modest_protocol_registry_protocol_type_is_secure (registry, auth)) {
920 list = g_list_append(list, GINT_TO_POINTER(auth));
924 g_list_free(list_auth_methods);
936 static ModestProtocolType check_first_supported_auth_method(ModestAccountAssistant* self)
938 ModestProtocolType result = MODEST_PROTOCOLS_AUTH_PASSWORD;
940 GList* methods = check_for_supported_auth_methods(self);
943 /* Use the first one: */
944 result = (ModestProtocolType) (GPOINTER_TO_INT(methods->data));
945 g_list_free(methods);
953 * @self: a #ModestEasysetupWizardDialog
955 * takes information from all the wizard and stores it in settings
958 save_to_settings (ModestAccountAssistant *self)
960 ModestAccountAssistantPrivate *priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (self);
962 const gchar *username, *password;
963 gchar *store_hostname, *transport_hostname;
964 guint store_port, transport_port;
965 ModestProtocolType store_protocol, transport_protocol;
966 ModestProtocolType store_security, transport_security;
967 ModestProtocolType store_auth_protocol, transport_auth_protocol;
968 ModestServerAccountSettings *store_settings, *transport_settings;
969 const gchar *fullname, *email_address;
971 /* username and password (for both incoming and outgoing): */
972 username = gtk_entry_get_text (GTK_ENTRY (priv->username));
973 password = gtk_entry_get_text (GTK_ENTRY (priv->password));
975 /* Incoming server: */
976 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
977 * or modest_account_mgr_add_server_account will fail. */
979 store_protocol = MODEST_PROTOCOLS_STORE_POP;
980 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
981 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
983 /* Use custom pages because no preset was specified: */
984 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->store_server_widget) ));
985 store_protocol = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->store_protocol_combo));
986 store_security = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->store_security_combo));
989 * If secure authentication is unchecked, allow sending username and password also as plain text.
990 * If secure authentication is checked, require one of the secure methods during
991 * connection: SSL, TLS, CRAM-MD5 etc. */
992 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->store_secure_auth)) &&
993 !modest_protocol_registry_protocol_type_is_secure(modest_runtime_get_protocol_registry (),
995 store_auth_protocol = check_first_supported_auth_method (self);
997 store_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
1000 /* now we store the store account settings */
1001 store_settings = modest_account_settings_get_store_settings (priv->settings);
1002 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1003 modest_server_account_settings_set_username (store_settings, username);
1004 modest_server_account_settings_set_password (store_settings, password);
1005 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1006 modest_server_account_settings_set_security_protocol (store_settings, store_security);
1007 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1008 if (store_port != 0)
1009 modest_server_account_settings_set_port (store_settings, store_port);
1011 g_object_unref (store_settings);
1012 g_free (store_hostname);
1014 /* Outgoing server: */
1015 transport_hostname = NULL;
1016 transport_protocol = MODEST_PROTOCOLS_STORE_POP;
1017 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1018 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1021 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->transport_server_widget) ));
1022 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1023 transport_security = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->transport_security_combo));
1024 transport_auth_protocol = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->transport_secure_auth_combo));
1026 /* now we transport the transport account settings */
1027 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1028 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1029 modest_server_account_settings_set_username (transport_settings, username);
1030 modest_server_account_settings_set_password (transport_settings, password);
1031 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1032 modest_server_account_settings_set_security_protocol (transport_settings, transport_security);
1033 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1034 if (transport_port != 0)
1035 modest_server_account_settings_set_port (transport_settings, transport_port);
1037 g_object_unref (transport_settings);
1038 g_free (transport_hostname);
1040 fullname = gtk_entry_get_text (GTK_ENTRY (priv->fullname));
1041 email_address = gtk_entry_get_text (GTK_ENTRY (priv->email));
1042 modest_account_settings_set_fullname (priv->settings, fullname);
1043 modest_account_settings_set_email_address (priv->settings, email_address);
1044 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1045 are set to headers only */
1047 display_name = get_entered_account_title (self);
1048 modest_account_settings_set_display_name (priv->settings, display_name);
1049 g_free (display_name);
1054 on_response (ModestWizardDialog *wizard_dialog,
1058 ModestAccountAssistant *self = MODEST_ACCOUNT_ASSISTANT (wizard_dialog);
1060 invoke_enable_buttons_vfunc (self);
1064 on_response_before (ModestWizardDialog *wizard_dialog,
1068 ModestAccountAssistant *self = MODEST_ACCOUNT_ASSISTANT (wizard_dialog);
1069 ModestAccountAssistantPrivate *priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(wizard_dialog);
1071 if (response_id == GTK_RESPONSE_CANCEL) {
1072 /* This is mostly copied from
1073 * src/maemo/modest-account-settings-dialog.c */
1075 gint dialog_response = modest_platform_run_confirmation_dialog (GTK_WINDOW (self),
1076 _("imum_nc_wizard_confirm_lose_changes"));
1078 if (dialog_response != GTK_RESPONSE_OK) {
1079 /* Don't let the dialog close */
1080 g_signal_stop_emission_by_name (wizard_dialog, "response");