+
+static ModestProtocolType check_first_supported_auth_method(ModestAccountAssistant* self)
+{
+ ModestProtocolType result = MODEST_PROTOCOLS_AUTH_PASSWORD;
+
+ GList* methods = check_for_supported_auth_methods(self);
+ if (methods)
+ {
+ /* Use the first one: */
+ result = (ModestProtocolType) (GPOINTER_TO_INT(methods->data));
+ g_list_free(methods);
+ }
+
+ return result;
+}
+
+/**
+ * save_to_settings:
+ * @self: a #ModestEasysetupWizardDialog
+ *
+ * takes information from all the wizard and stores it in settings
+ */
+static void
+save_to_settings (ModestAccountAssistant *self)
+{
+ ModestAccountAssistantPrivate *priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (self);
+ gchar* display_name;
+ const gchar *username, *password;
+ gchar *store_hostname, *transport_hostname;
+ guint store_port, transport_port;
+ ModestProtocolType store_protocol, transport_protocol;
+ ModestProtocolType store_security, transport_security;
+ ModestProtocolType store_auth_protocol, transport_auth_protocol;
+ ModestServerAccountSettings *store_settings, *transport_settings;
+ const gchar *fullname, *email_address;
+
+ /* username and password (for both incoming and outgoing): */
+ username = gtk_entry_get_text (GTK_ENTRY (priv->username));
+ password = gtk_entry_get_text (GTK_ENTRY (priv->password));
+
+ /* Incoming server: */
+ /* Note: We need something as default for the ModestTransportStoreProtocol* values,
+ * or modest_account_mgr_add_server_account will fail. */
+ store_port = 0;
+ store_protocol = MODEST_PROTOCOLS_STORE_POP;
+ store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
+ store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
+
+ /* Use custom pages because no preset was specified: */
+ store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->store_server_widget) ));
+ store_protocol = modest_protocol_info_get_transport_store_protocol (modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->store_protocol_combo)));
+ store_security = modest_protocol_info_get_connection_protocol (modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->store_security_combo)));
+
+ /* The UI spec says:
+ * If secure authentication is unchecked, allow sending username and password also as plain text.
+ * If secure authentication is checked, require one of the secure methods during
+ * connection: SSL, TLS, CRAM-MD5 etc. */
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->store_secure_auth)) &&
+ !modest_protocol_registry_protocol_type_is_secure(modest_runtime_get_protocol_registry (),
+ store_security)) {
+ store_auth_protocol = check_first_supported_auth_method (self);
+ } else {
+ store_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
+ }
+
+ /* now we store the store account settings */
+ store_settings = modest_account_settings_get_store_settings (priv->settings);
+ modest_server_account_settings_set_hostname (store_settings, store_hostname);
+ modest_server_account_settings_set_username (store_settings, username);
+ modest_server_account_settings_set_password (store_settings, password);
+ modest_server_account_settings_set_protocol (store_settings, store_protocol);
+ modest_server_account_settings_set_security (store_settings, store_security);
+ modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
+ if (store_port != 0)
+ modest_server_account_settings_set_port (store_settings, store_port);
+
+ g_object_unref (store_settings);
+ g_free (store_hostname);
+
+ /* Outgoing server: */
+ transport_hostname = NULL;
+ transport_protocol = MODEST_PROTOCOLS_STORE_POP;
+ transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
+ transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
+ transport_port = 0;
+
+ transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->transport_server_widget) ));
+ transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
+ transport_security = modest_protocol_info_get_connection_protocol (modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->transport_security_combo)));
+ transport_auth_protocol = modest_protocol_info_get_auth_protocol (modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->transport_secure_auth_combo)));
+
+ /* now we transport the transport account settings */
+ transport_settings = modest_account_settings_get_transport_settings (priv->settings);
+ modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
+ modest_server_account_settings_set_username (transport_settings, username);
+ modest_server_account_settings_set_password (transport_settings, password);
+ modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
+ modest_server_account_settings_set_security (transport_settings, transport_security);
+ modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
+ if (transport_port != 0)
+ modest_server_account_settings_set_port (transport_settings, transport_port);
+
+ g_object_unref (transport_settings);
+ g_free (transport_hostname);
+
+ fullname = gtk_entry_get_text (GTK_ENTRY (priv->fullname));
+ email_address = gtk_entry_get_text (GTK_ENTRY (priv->email));
+ modest_account_settings_set_fullname (priv->settings, fullname);
+ modest_account_settings_set_email_address (priv->settings, email_address);
+ /* we don't set retrieve type to preserve advanced settings if any. By default account settings
+ are set to headers only */
+
+ display_name = get_entered_account_title (self);
+ modest_account_settings_set_display_name (priv->settings, display_name);
+ g_free (display_name);
+
+}
+
+static void
+on_response (ModestWizardDialog *wizard_dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ ModestAccountAssistant *self = MODEST_ACCOUNT_ASSISTANT (wizard_dialog);
+
+ invoke_enable_buttons_vfunc (self);
+}
+
+static void
+on_response_before (ModestWizardDialog *wizard_dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ ModestAccountAssistant *self = MODEST_ACCOUNT_ASSISTANT (wizard_dialog);
+ ModestAccountAssistantPrivate *priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE(wizard_dialog);
+
+ if (response_id == GTK_RESPONSE_CANCEL) {
+ /* This is mostly copied from
+ * src/maemo/modest-account-settings-dialog.c */
+ if (priv->dirty) {
+ gint dialog_response = modest_platform_run_confirmation_dialog (GTK_WINDOW (self),
+ _("imum_nc_wizard_confirm_lose_changes"));
+
+ if (dialog_response != GTK_RESPONSE_OK) {
+ /* Don't let the dialog close */
+ g_signal_stop_emission_by_name (wizard_dialog, "response");
+ }
+ }
+ }
+}
+