+static gboolean
+on_save (ModestWizardDialog *dialog)
+{
+ ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
+ ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+
+ save_to_settings (self);
+
+ if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
+ modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
+ return FALSE;
+ }
+
+ return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
+
+}
+
+
+static GList*
+check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
+{
+ GError *error = NULL;
+ ModestProtocolType protocol_type;
+ const gchar* hostname;
+ const gchar* username;
+ ModestProtocolType security_protocol_incoming_type;
+ ModestProtocolRegistry *registry;
+ int port_num;
+ GList *list_auth_methods;
+ ModestEasysetupWizardDialogPrivate *priv;
+
+ priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+ registry = modest_runtime_get_protocol_registry ();
+ protocol_type = modest_servertype_picker_get_active_servertype (
+ MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
+ hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
+ username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
+ security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
+ (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
+ port_num = get_port_from_protocol(protocol_type, FALSE);
+ list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
+ username, GTK_WINDOW (self), &error);
+
+ if (list_auth_methods) {
+ /* TODO: Select the correct method */
+ GList* list = NULL;
+ GList* method;
+ for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
+ ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
+ if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
+ MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
+ list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
+ }
+ }
+
+ g_list_free(list_auth_methods);
+
+ if (list)
+ return list;
+ }
+
+ if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
+ error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
+ {
+ modest_platform_information_banner (GTK_WIDGET(self), NULL,
+ _("mcen_ib_unableto_discover_auth_methods"));
+ }
+
+ if(error != NULL)
+ g_error_free(error);
+
+ return NULL;
+}
+
+static gboolean
+check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
+{
+ GList* methods = check_for_supported_auth_methods(self);
+ if (!methods)
+ {
+ return FALSE;
+ }
+
+ g_list_free(methods);
+ return TRUE;
+}
+
+static gboolean
+check_support_show_progress (gpointer userdata)
+{
+ ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
+ ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+
+ priv->check_support_show_progress_id = 0;
+
+ if (priv->destroyed)
+ return FALSE;
+
+ hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
+
+ return FALSE;
+}
+
+static void
+check_support_callback (ModestAccountProtocol *protocol,
+ gboolean supported,
+ gpointer userdata)
+{
+ ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
+ ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+
+ priv->pending_check_support --;
+
+ if (priv->check_support_show_progress_id > 0) {
+ g_source_remove (priv->check_support_show_progress_id);
+ priv->check_support_show_progress_id = 0;
+ }
+
+ if (priv->pending_check_support == 0) {
+ priv->check_support_done = TRUE;
+
+ if (!priv->destroyed) {
+ if (priv->presets)
+ fill_providers (self);
+ hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
+ invoke_enable_buttons_vfunc (self);
+ }
+ }
+ g_object_unref (self);
+}
+
+
+static void
+check_support_of_protocols (ModestEasysetupWizardDialog *self)
+{
+ ModestProtocolRegistry *registry;
+ GSList *provider_protos, *node;
+ ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+
+ registry = modest_runtime_get_protocol_registry ();
+ provider_protos = modest_protocol_registry_get_by_tag (registry,
+ MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
+
+ for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
+ ModestProtocol *proto = MODEST_PROTOCOL (node->data);
+
+ if (!modest_protocol_registry_protocol_type_has_tag (registry,
+ modest_protocol_get_type_id (proto),
+ MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
+ continue;
+
+ if (modest_protocol_registry_protocol_type_has_tag
+ (registry,
+ modest_protocol_get_type_id (proto),
+ MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
+ /* Check if there's already an account configured with this account type */
+ if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
+ modest_protocol_get_type_id (proto)))
+ continue;
+ }
+
+ if (MODEST_ACCOUNT_PROTOCOL (proto)) {
+ priv->pending_check_support ++;
+ modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
+ check_support_callback,
+ g_object_ref (self));
+ }
+ }
+ g_slist_free (provider_protos);
+
+ if (priv->pending_check_support > 0) {
+ priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
+ check_support_show_progress,
+ g_object_ref (self), g_object_unref);
+ } else {
+ priv->check_support_done = TRUE;
+ }
+ invoke_enable_buttons_vfunc (self);
+}