Merged the new plugin system from branch plugin-system.
authorJose Dapena Paz <jdapena@igalia.com>
Mon, 22 Sep 2008 14:06:27 +0000 (14:06 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Mon, 22 Sep 2008 14:06:27 +0000 (14:06 +0000)
pmo-trunk-r5674

94 files changed:
Makefile.am
configure.ac
debian/control.maemo-bora
debian/control.maemo-chinook
debian/control.maemo-diablo
debian/modest-plugin-dev.install [new file with mode: 0644]
libmodest-dbus-client/Makefile.am
src/Makefile.am
src/export.map
src/gnome/modest-account-view-window.c
src/maemo/Makefile.am
src/maemo/easysetup/modest-easysetup-provider-combo-box.c
src/maemo/easysetup/modest-easysetup-provider-combo-box.h
src/maemo/easysetup/modest-easysetup-servertype-combo-box.c
src/maemo/easysetup/modest-easysetup-servertype-combo-box.h
src/maemo/easysetup/modest-easysetup-wizard-dialog.c
src/maemo/easysetup/modest-presets.c
src/maemo/easysetup/modest-presets.h
src/maemo/modest-account-settings-dialog.c [deleted file]
src/maemo/modest-account-view-window.c
src/maemo/modest-connection-specific-smtp-edit-window.c
src/maemo/modest-connection-specific-smtp-window.c
src/maemo/modest-default-account-settings-dialog.c [new file with mode: 0644]
src/maemo/modest-maemo-security-options-view.c [new file with mode: 0644]
src/maemo/modest-maemo-security-options-view.h [new file with mode: 0644]
src/maemo/modest-maemo-utils.c
src/maemo/modest-maemo-utils.h
src/maemo/modest-main-window.c
src/maemo/modest-msg-view-window.c
src/maemo/modest-platform.c
src/modest-account-mgr-helpers.c
src/modest-account-mgr-helpers.h
src/modest-account-mgr.c
src/modest-account-mgr.h
src/modest-account-protocol.c [new file with mode: 0644]
src/modest-account-protocol.h [new file with mode: 0644]
src/modest-account-settings.h
src/modest-conf.c
src/modest-conf.h
src/modest-email-clipboard.c
src/modest-email-clipboard.h
src/modest-init.c
src/modest-mail-operation.c
src/modest-module.c [new file with mode: 0644]
src/modest-module.h [new file with mode: 0644]
src/modest-platform.h
src/modest-plugin-1.0.pc.in [new file with mode: 0644]
src/modest-plugin-factory.c [new file with mode: 0644]
src/modest-plugin-factory.h [new file with mode: 0644]
src/modest-plugin.c [new file with mode: 0644]
src/modest-plugin.h [new file with mode: 0644]
src/modest-protocol-info.c [deleted file]
src/modest-protocol-info.h [deleted file]
src/modest-protocol-registry.c [new file with mode: 0644]
src/modest-protocol-registry.h [new file with mode: 0644]
src/modest-protocol.c [new file with mode: 0644]
src/modest-protocol.h [new file with mode: 0644]
src/modest-runtime.c
src/modest-runtime.h
src/modest-server-account-settings.c
src/modest-server-account-settings.h
src/modest-singletons.c
src/modest-singletons.h
src/modest-tny-account-store.c
src/modest-tny-account-store.h
src/modest-tny-account.c
src/modest-tny-account.h
src/modest-tny-folder.c
src/modest-ui-actions.c
src/modest-ui-dimming-rules.c
src/modest-utils.c
src/modest-utils.h
src/widgets/Makefile.am
src/widgets/modest-account-settings-dialog.c [new file with mode: 0644]
src/widgets/modest-account-settings-dialog.h
src/widgets/modest-account-view.c
src/widgets/modest-default-account-settings-dialog.h [new file with mode: 0644]
src/widgets/modest-easysetup-wizard-page.c [new file with mode: 0644]
src/widgets/modest-easysetup-wizard-page.h [new file with mode: 0644]
src/widgets/modest-limit-retrieve-combo-box.h
src/widgets/modest-mozembed-msg-view.c
src/widgets/modest-mozembed-msg-view.h
src/widgets/modest-progress-bar.c
src/widgets/modest-retrieve-combo-box.c
src/widgets/modest-retrieve-combo-box.h
src/widgets/modest-secureauth-combo-box.c
src/widgets/modest-secureauth-combo-box.h
src/widgets/modest-security-options-view-priv.h [new file with mode: 0644]
src/widgets/modest-security-options-view.c [new file with mode: 0644]
src/widgets/modest-security-options-view.h [new file with mode: 0644]
src/widgets/modest-serversecurity-combo-box.c
src/widgets/modest-serversecurity-combo-box.h
src/widgets/modest-window.c
src/widgets/modest-wizard-dialog.c

index 598ac9a..e2de617 100644 (file)
@@ -64,4 +64,4 @@ DISTCLEANFILES =            \
 # (using the postinst thingie in debian/
 NEWS_FILE=NEWS
 newsdir=$(datadir)/modest/data
-news_DATA = $(NEWS_FILE)
\ No newline at end of file
+news_DATA = $(NEWS_FILE)
index d6d7f28..a5e2946 100644 (file)
@@ -139,6 +139,11 @@ if test "$MODEST_PLATFORM" = "detect"; then
        with_platform=$detected_platform
 fi
 
+if test "$with_platform" = "maemo"; then
+       MODEST_PLUGIN_DEFINES=" -DMODEST_PLATFORM_MAEMO"
+elif test "$with_platform" = "gnome"; then
+       MODEST_PLUGIN_DEFINES=" -DMODEST_PLATFORM_GNOME"
+fi
 
 dnl Whether to use maemo-launcher or not
 AC_ARG_ENABLE([maemo-launcher],
@@ -345,12 +350,17 @@ fi
 #
 # check the version of the widgets on maemo
 #
+hildonpkgs=
 if test "x$with_platform" == "xmaemo"; then  
 PKG_CHECK_MODULES(MODEST_HILDON_WIDGETS, hildon-1 >= 0.9.9 hildon-fm-2, have_hildon1=true,have_hildon1=false)  
+hildonpkgs=hildon-1
+
 if test "x$have_hildon1" == "xfalse"; then 
    PKG_CHECK_MODULES(MODEST_HILDON_WIDGETS, hildon-libs >= 0.12.0 hildon-fm, have_hildon0=true,have_hildon0=false)     
+   hildonpkgs=hildon-libs
    if test "x$have_hildon0" == "xtrue"; then
       AC_DEFINE_UNQUOTED(MODEST_HAVE_HILDON0_WIDGETS, 1, ["Whether hildon0 widgets are used."])                      
+      MODEST_PLUGIN_DEFINES+=" -DMODEST_HAVE_HILDON0_WIDGETS"
    else
       AC_MSG_ERROR([hildon widgets and/or hildon-fm not found])
    fi
@@ -359,7 +369,8 @@ else
 fi
 fi
 
-
+AC_SUBST(hildonpkgs)
+AC_SUBST(MODEST_PLUGIN_DEFINES)
 
 #
 # check the version of the addressbook on maemo
@@ -385,6 +396,9 @@ fi
 AM_CONDITIONAL(MODEST_USE_DUMMY_ADDRESS_BOOK,test "x$have_abook" != "xtrue")
 
 
+AM_GLIB_GNU_GETTEXT
+IT_PROG_INTLTOOL([0.35.0])
+
 # gettext support
 GETTEXT_PACKAGE=modest 
 AC_SUBST(GETTEXT_PACKAGE)
@@ -480,14 +494,12 @@ AM_CONDITIONAL(BUILD_DOCS, test x$build_docs = xtrue)
 dnl ## gtk-doc
 GTK_DOC_CHECK([1.0])
 
-dnl Intltool utility programs
-#AC_PROG_INTLTOOL([0.33.0],[no-xml])
-
 AC_OUTPUT([
 po/Makefile.in
 Makefile
 man/Makefile
 src/Makefile
+src/modest-plugin-1.0.pc
 src/dbus_api/Makefile
 src/gnome/Makefile
 src/maemo/Makefile
index 86d9958..f691635 100644 (file)
@@ -10,6 +10,12 @@ Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends},${launcher:Depends},maemo-providers-data
 Description: an e-mail client for platforms with modest resources
 
+Package: modest-plugin-dev
+Architecture: any
+Depends: modest
+Description: Plugin development packages for modest mail client.
+ Plugin development packages for modest, the e-mail client for osso.
+
 Package: modest-dbg
 Section: devel
 Architecture: all
index b2f63f8..c8aff18 100644 (file)
@@ -41,6 +41,12 @@ XB-Maemo-Icon-26:
 Description: an e-mail client for platforms with modest resources
  e-mail client for osso
 
+Package: modest-plugin-dev
+Architecture: any
+Depends: modest
+Description: Plugin development packages for modest mail client.
+ Plugin development packages for modest, the e-mail client for osso.
+
 Package: modest-dbg
 Section: devel
 Architecture: any
index a392461..300766e 100644 (file)
@@ -11,6 +11,12 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${launcher:Depends},modest-provider
 Description: an e-mail client for platforms with modest resources
  e-mail client for osso
 
+Package: modest-plugin-dev
+Architecture: any
+Depends: modest
+Description: Plugin development packages for modest mail client.
+ Plugin development packages for modest, the e-mail client for osso.
+
 Package: modest-dbg
 Section: devel
 Architecture: any
diff --git a/debian/modest-plugin-dev.install b/debian/modest-plugin-dev.install
new file mode 100644 (file)
index 0000000..0b05f5c
--- /dev/null
@@ -0,0 +1,2 @@
+usr/lib/pkgconfig/modest-plugin-1.0.pc
+usr/include/modest-plugin-1.0/
index 5e85cd6..2fe3606 100644 (file)
@@ -49,4 +49,4 @@ library_include_HEADERS = libmodest-dbus-client.h
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libmodest-dbus-client-1.0.pc
 
-
+DISTCLEANFILES = $(pkgconfig_DATA)
index ab62fb8..8144eb6 100644 (file)
@@ -2,26 +2,28 @@
 # Makefile.am
 # Time-stamp: <2008-01-06 10:18:49 (djcb)>
 
-SUBDIRS=$(MODEST_PLATFORM) widgets $(dbus_api)
+SUBDIRS= $(MODEST_PLATFORM) widgets $(dbus_api)
 
 DIST_SUBDIRS = widgets gnome maemo dbus_api
 
 INCLUDES=\
-       $(MODEST_GSTUFF_CFLAGS)\
-       $(MODEST_PLATFORM_CFLAGS) \
-       $(MODEST_HILDON_WIDGETS_CFLAGS) \
-       $(MODEST_OGS_CFLAGS) \
-       $(MODEST_HILDON_HELP_CFLAGS) \
-       $(MODEST_LIBCONIC_CFLAGS) \
-       $(MODEST_HILDON_NOTIFY_CFLAGS) \
-       $(MODEST_MOZEMBED_CFLAGS) \
-       -I$(MODEST_PLATFORM) \
-       -DPREFIX=\"@prefix@\" \
-       -DMAEMO_CHANGES \
-       -DMODEST_LOCALEDIR=\"$(MODEST_LOCALEDIR)\" \
-       -DMODEST_PLATFORM=\"$(MODEST_PLATFORM)\" \
-       -DPIXMAP_PREFIX=\"${datadir}/pixmaps/modest/\" \
-       -DMODEST_UIDIR=\"$(datadir)/modest/ui/\"
+       $(MODEST_GSTUFF_CFLAGS)                                 \
+       $(MODEST_PLATFORM_CFLAGS)                               \
+       $(MODEST_HILDON_WIDGETS_CFLAGS)                         \
+       $(MODEST_OGS_CFLAGS)                                    \
+       $(MODEST_HILDON_HELP_CFLAGS)                            \
+       $(MODEST_LIBCONIC_CFLAGS)                               \
+       $(MODEST_HILDON_NOTIFY_CFLAGS)                          \
+       $(MODEST_MOZEMBED_CFLAGS)                               \
+       -fPIC \
+       -I$(MODEST_PLATFORM)                                    \
+       -DPREFIX=\"@prefix@\"                                   \
+       -DMAEMO_CHANGES                                         \
+       -DMODEST_LOCALEDIR=\"$(MODEST_LOCALEDIR)\"              \
+       -DMODEST_PLATFORM=\"$(MODEST_PLATFORM)\"                \
+       -DPIXMAP_PREFIX=\"${datadir}/pixmaps/modest/\"          \
+       -DMODEST_UIDIR=\"$(datadir)/modest/ui/\"                \
+       -DMODEST_MAILPLUGINDIR=\"$(libdir)/modest/mail-plugins\"
 
 BUILT_SOURCES = modest-marshal.c modest-marshal.h
 
@@ -31,36 +33,57 @@ modest-marshal.c: modest-marshal.list
 modest-marshal.h: modest-marshal.list
        glib-genmarshal --header --prefix=modest_marshal < modest-marshal.list > modest-marshal.h
 
+noinst_LTLIBRARIES = libmodest.la
+
 bin_PROGRAMS=\
        modest
 
+to_remove=\
+       modest-testplugin-protocol.c \
+       modest-testplugin-protocol.h
+
 #
 # NOTE: $(addressbook) will be modest-addressbook-dummy.c
 # if no real addressbook has been defined (configure.ac)
 #
-modest_SOURCES=\
-       modest-account-mgr-helpers.c \
+
+modest_public_headers = \
+       modest-account-mgr.h \
        modest-account-mgr-helpers.h \
+       modest-account-protocol.h \
+       modest-account-settings.h \
+       modest-cache-mgr.h \
+       modest-conf.h \
+       modest-pair.h \
+       modest-platform.h \
+       modest-plugin.h \
+       modest-protocol.h \
+       modest-protocol-registry.h \
+       modest-server-account-settings.h \
+       modest-tny-account-store.h \
+       modest-tny-local-folders-account.h \
+       modest-utils.h
+
+libmodest_la_SOURCES=\
+       $(modest_public_headers) \
+       modest-account-mgr-helpers.c \
        modest-account-mgr-priv.h \
        modest-account-mgr.c \
-       modest-account-mgr.h \
+       modest-account-protocol.c \
        modest-account-settings.c \
-       modest-account-settings.h \
        modest-address-book.h \
        modest-cache-mgr.c \
-       modest-cache-mgr.h \
        modest-conf.c \
-       modest-conf.h \
        modest-count-stream.c \
        modest-count-stream.h \
-       modest-defs.h \
        modest-debug.h \
+       modest-defs.h \
        modest-dimming-rule.c \
        modest-dimming-rule.h \
        modest-dimming-rules-group.c \
        modest-dimming-rules-group.h \
-       modest-email-clipboard.c \
        modest-email-clipboard.h \
+       modest-email-clipboard.c \
        modest-error.h \
        modest-formatter.c \
        modest-formatter.h \
@@ -75,14 +98,16 @@ modest_SOURCES=\
        modest-main.c \
        modest-marshal.c \
        modest-marshal.h \
+       modest-module.c \
+       modest-module.h \
        modest-pair.c \
-       modest-pair.h \
-       modest-platform.h \
-       modest-platform.h \
+       modest-plugin.c \
+       modest-plugin-factory.c \
+       modest-plugin-factory.h \
        modest-progress-object.c \
        modest-progress-object.h \
-       modest-protocol-info.c \
-       modest-protocol-info.h \
+       modest-protocol.c \
+       modest-protocol-registry.c \
        modest-runtime-priv.h \
        modest-runtime.c \
        modest-runtime.h \
@@ -93,17 +118,14 @@ modest_SOURCES=\
        modest-singletons.c \
        modest-singletons.h \
        modest-server-account-settings.c \
-       modest-server-account-settings.h \
        modest-text-utils.c \
        modest-text-utils.h \
        modest-tny-account-store.c \
-       modest-tny-account-store.h \
        modest-tny-account.c \
        modest-tny-account.h \
        modest-tny-folder.c \
        modest-tny-folder.h \
        modest-tny-local-folders-account.c \
-       modest-tny-local-folders-account.h \
        modest-tny-mime-part.c \
        modest-tny-mime-part.h \
        modest-tny-msg.c \
@@ -125,7 +147,6 @@ modest_SOURCES=\
        modest-ui-dimming-rules.c \
        modest-ui-dimming-rules.h \
        modest-utils.c \
-       modest-utils.h \
        modest-widget-memory-priv.h \
        modest-widget-memory.c \
        modest-widget-memory.h \
@@ -133,16 +154,40 @@ modest_SOURCES=\
        modest-default-connection-policy.h 
 
 if MODEST_USE_DUMMY_ADDRESS_BOOK
-modest_SOURCES += modest-address-book-dummy.c
+libmodest_la_SOURCES += modest-address-book-dummy.c
 endif 
 
 
-modest_CFLAGS  = $(MAEMO_LAUNCHER_CFLAGS)
-modest_LDFLAGS = -Wl,--version-script=export.map
+libmodest_la_CFLAGS  = $(MAEMO_LAUNCHER_CFLAGS)
+libmodest_la_LIBADD =                                          \
+       $(MAEMO_LAUNCHER_LIBS)                          \
+       $(MODEST_GSTUFF_LIBS)                           \
+       $(MODEST_MOZEMBED_LIBS)                         \
+       $(MODEST_PLATFORM_LIBS)                         \
+       $(MODEST_HILDON_WIDGETS_LIBS)                   \
+       $(MODEST_HILDON_HELP_LIBS)                      \
+       $(MODEST_HILDON_NOTIFY_LIBS)                    \
+       $(MODEST_OGS_LIBS)                              \
+       ${easysetupmaybe} \
+       widgets/libmodest-widgets.la                    \
+       $(MODEST_PLATFORM)/libmodest-ui.la              
+libmodest_la_LDFLAGS = -rdynamic -export-dynamic -no-undefined -Wl,--version-script=export.map
+
+if MODEST_HAVE_DBUS_API
+libmodest_la_LIBADD += dbus_api/libmodest-dbus-api.la
+endif
+
+
+modest_includedir = $(includedir)/modest-plugin-1.0/
+modest_include_HEADERS = $(modest_public_headers)
+
+modest_SOURCES = modest-main.c
 
-modest_UNWANTED = -export-dynamic -Wl,--export-dynamic
-modest_LDADD =                                                 \
-       $(filter-out $(modest_UNWANTED),                \
+modest_DEPENDENCIES = \
+       libmodest.la
+
+modest_CFLAGS = $(MAEMO_LAUNCHER_CFLAGS)
+modest_LDADD = \
        $(MAEMO_LAUNCHER_LIBS)                          \
        $(MODEST_GSTUFF_LIBS)                           \
        $(MODEST_MOZEMBED_LIBS)                         \
@@ -152,12 +197,16 @@ modest_LDADD =                                            \
        $(MODEST_HILDON_NOTIFY_LIBS)                    \
        $(MODEST_OGS_LIBS)                              \
        ${easysetupmaybe}                               \
-       $(MODEST_PLATFORM)/libmodest-ui.la              \
-       widgets/libmodest-widgets.la)
+       libmodest.la
 
+modest_LDFLAGS = -rdynamic -export-dynamic -no-undefined -Wl,--version-script=export.map
+
+# modest_UNWANTED = -export-dynamic -Wl,--export-dynamic
 
-if MODEST_HAVE_DBUS_API
-modest_LDADD +=        dbus_api/libmodest-dbus-api.la
-endif
 
 EXTRA_DIST=modest-marshal.list
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = modest-plugin-1.0.pc
+
+DISTCLEANFILES = $(pkgconfig_DATA)
\ No newline at end of file
index 814b126..f692f90 100644 (file)
        _end;
        _IO_stdin_used;
        __data_start;
+       modest_account_settings_*;
+       modest_account_mgr_*;
+       modest_account_protocol_*;
+       modest_easysetup_wizard_*;
+       modest_pair_*;
+       modest_platform_*;
+       modest_plugin_*;
+       modest_protocol_*;
+       modest_server_account_settings_*;
+       modest_validating_entry_*;
   local: *;
 };
index 7827f80..5465c78 100644 (file)
@@ -268,17 +268,33 @@ check_for_active_account (ModestAccountViewWindow *self, const gchar* account_na
 static void
 on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
 {
-       ModestAccountViewWindowPrivate *priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE (self);
+       ModestAccountViewWindowPrivate *priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE (self);
        
        gchar* account_name = modest_account_view_get_selected_account (priv->account_view);
        if (!account_name)
                return;
                
+       /* Check whether any connections are active, and cancel them if 
+        * the user wishes.
+        */
        if (check_for_active_account (self, account_name)) {
-               modest_tny_account_store_show_account_settings_dialog (modest_runtime_get_account_store (), account_name);
-               
+               ModestAccountProtocol *proto;
+               ModestProtocolType proto_type;
+
+               /* Get proto */
+               proto_type = modest_account_mgr_get_store_protocol (modest_runtime_get_account_mgr (), 
+                                                                   account_name);
+               proto = (ModestAccountProtocol *)
+                       modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), 
+                                                                      proto_type);
+
+               /* Create and show the dialog */
+               if (proto && MODEST_IS_ACCOUNT_PROTOCOL (proto)) {
+                       ModestAccountSettingsDialog *dialog =
+                               modest_account_protocol_get_account_settings_dialog (proto, account_name);
+                       gtk_widget_show (GTK_WIDGET (dialog));
+               }
        }
-       
        g_free (account_name);
 }
 
index 260a0bc..6405431 100644 (file)
@@ -52,10 +52,11 @@ noinst_LTLIBRARIES=\
 
 libmodest_ui_la_SOURCES=              \
        modest-account-view-window.c  \
-       modest-account-settings-dialog.c \
+       modest-default-account-settings-dialog.c \
        modest-icon-names.h           \
        modest-maemo-global-settings-dialog.c \
        modest-maemo-global-settings-dialog.h \
+       modest-maemo-security-options-view.c \
        modest-main-window.c          \
        modest-main-window-ui.h       \
        modest-hildon-includes.h      \
index ce36138..1147a1d 100644 (file)
@@ -33,6 +33,8 @@
 #include <gtk/gtkcellrenderertext.h>
 #include <glib/gi18n.h>
 #include <modest-text-utils.h>
+#include "modest-protocol-registry.h"
+#include "modest-runtime.h"
 
 #include <stdlib.h>
 #include <string.h> /* For memcpy() */
@@ -105,8 +107,9 @@ easysetup_provider_combo_box_class_init (EasysetupProviderComboBoxClass *klass)
 }
 
 enum MODEL_COLS {
-       MODEL_COL_NAME = 0,
-       MODEL_COL_ID   = 1 /* a string, not an int. */
+       MODEL_COL_ID, /* a string, not an int. */
+       MODEL_COL_NAME,
+       MODEL_COL_ID_TYPE
 };
 
 
@@ -147,7 +150,7 @@ easysetup_provider_combo_box_init (EasysetupProviderComboBox *self)
         * with a string for the name, and a string for the ID (e.g. "vodafone.it"), and the mcc
         * This must match our MODEL_COLS enum constants.
         */
-       priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING));
+       priv->model = GTK_TREE_MODEL (gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT));
 
        /* Setup the combo box: */
        GtkComboBox *combobox = GTK_COMBO_BOX (self);
@@ -174,25 +177,30 @@ easysetup_provider_combo_box_new (void)
 }
 
 void
-easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPresets *presets,
+easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, 
+                                  ModestPresets *presets,
                                   gint mcc)
 {      
+       GtkTreeIter other_iter;
+       EasysetupProviderComboBoxPrivate *priv;
+       GtkListStore *liststore;        
+       GSList *provider_ids_used_already = NULL, *provider_protos, *tmp;
+       gchar ** provider_ids = NULL;
+       gchar ** provider_names;        
+       gchar ** iter_provider_names;
+       gchar ** iter_provider_ids;
+       ModestProtocolRegistry *registry;
+
        g_return_if_fail (EASYSETUP_IS_PROVIDER_COMBO_BOX(combobox));
-       
-       EasysetupProviderComboBoxPrivate *priv = PROVIDER_COMBO_BOX_GET_PRIVATE (combobox);
-       
-       /* Remove any existing rows: */
-       GtkListStore *liststore = GTK_LIST_STORE (priv->model);
+
+       priv = PROVIDER_COMBO_BOX_GET_PRIVATE (combobox);
+       liststore = GTK_LIST_STORE (priv->model);
        gtk_list_store_clear (liststore);
-       
-       GSList *provider_ids_used_already = NULL;
-       
-       /* Add the appropriate rows for this country, from the presets file: */
-       gchar ** provider_ids = NULL;
-       gchar ** provider_names = modest_presets_get_providers (presets, mcc, 
-                                                               TRUE /* include_globals */, &provider_ids);     
-       gchar ** iter_provider_names = provider_names;
-       gchar ** iter_provider_ids = provider_ids;
+       provider_names = modest_presets_get_providers (presets, mcc, TRUE, &provider_ids);
+
+       iter_provider_names = provider_names;
+       iter_provider_ids = provider_ids;
+
        while(iter_provider_names && *iter_provider_names && iter_provider_ids && *iter_provider_ids) {
                const gchar* provider_name = *iter_provider_names;
                const gchar* provider_id = *iter_provider_ids;
@@ -208,7 +216,9 @@ easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPr
                        
                        gtk_list_store_set(liststore, &iter, 
                                           MODEL_COL_ID, provider_id, 
-                                          MODEL_COL_NAME, provider_name, -1);
+                                          MODEL_COL_NAME, provider_name, 
+                                          MODEL_COL_ID_TYPE, EASYSETUP_PROVIDER_COMBO_BOX_ID_PROVIDER,
+                                          -1);
                        
                        provider_ids_used_already = g_slist_prepend (
                                provider_ids_used_already, (gpointer)g_strdup (provider_id));
@@ -223,19 +233,42 @@ easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPr
        g_strfreev (provider_names);
        g_strfreev (provider_ids);
 
+       /* Add the provider protocols */
+       registry = modest_runtime_get_protocol_registry ();
+       provider_protos = modest_protocol_registry_get_by_tag (registry, 
+                                                              MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
+       tmp = provider_protos;
+       while (tmp) {
+               GtkTreeIter iter;
+               ModestProtocol *proto = MODEST_PROTOCOL (tmp->data);
+               const gchar *name = modest_protocol_get_display_name (proto);
+
+               /* only add store protocols, no need to duplicate them */
+               if (modest_protocol_registry_protocol_type_has_tag (registry, 
+                                                                   modest_protocol_get_type_id (proto),
+                                                                   MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS)) {
+                       gtk_list_store_append (liststore, &iter);
+                       gtk_list_store_set (liststore, &iter,
+                                           MODEL_COL_ID, modest_protocol_get_name (proto),
+                                           MODEL_COL_NAME, name,
+                                           MODEL_COL_ID_TYPE, EASYSETUP_PROVIDER_COMBO_BOX_ID_PLUGIN_PROTOCOL,
+                                           -1);
+               }
+               tmp = g_slist_next (tmp);
+       }
+       g_slist_free (provider_protos);
        
        /* Add the "Other" item: */
        /* Note that ID 0 means "Other" for us: */
-       /* TODO: We need a Logical ID for this text. */
-       GtkTreeIter iter;
-       gtk_list_store_prepend (liststore, &iter);
-       gtk_list_store_set (liststore, &iter,
+       gtk_list_store_prepend (liststore, &other_iter);
+       gtk_list_store_set (liststore, &other_iter,
                            MODEL_COL_ID, 0,
                            MODEL_COL_NAME, _("mcen_va_serviceprovider_other"),
+                           MODEL_COL_ID_TYPE, EASYSETUP_PROVIDER_COMBO_BOX_ID_OTHER,
                            -1);
-       
+
        /* Select the "Other" item: */
-       gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+       gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &other_iter);
        
        g_slist_foreach (provider_ids_used_already, (GFunc)g_free, NULL);
        g_slist_free (provider_ids_used_already);
@@ -277,3 +310,23 @@ easysetup_provider_combo_box_set_others_provider (EasysetupProviderComboBox *com
        if (gtk_tree_model_get_iter_first (model, &others_iter))
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &others_iter);
 }
+
+EasysetupProviderComboBoxIdType 
+easysetup_provider_combo_box_get_active_id_type (EasysetupProviderComboBox *combobox)
+{
+       GtkTreeIter active;
+
+       g_return_val_if_fail (EASYSETUP_IS_PROVIDER_COMBO_BOX (combobox), 
+                             EASYSETUP_PROVIDER_COMBO_BOX_ID_OTHER);
+
+       if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active)) {
+               EasysetupProviderComboBoxPrivate *priv = PROVIDER_COMBO_BOX_GET_PRIVATE (combobox);
+               EasysetupProviderComboBoxIdType id_type;
+
+               gtk_tree_model_get (priv->model, &active, MODEL_COL_ID_TYPE, &id_type, -1);
+               return id_type; 
+       } else {
+               /* Fallback to other */
+               return EASYSETUP_PROVIDER_COMBO_BOX_ID_OTHER;
+       }
+}
index 41da709..d4bc283 100644 (file)
@@ -57,6 +57,21 @@ G_BEGIN_DECLS
        (G_TYPE_INSTANCE_GET_CLASS ((obj), \
        EASYSETUP_TYPE_PROVIDER_COMBO_BOX, EasysetupProviderComboBoxClass))
 
+/** The thype of the ID
+ *
+ * this means the value of returned by get_active_provider_id will be
+ * different depending on the value returned by get_active_id_type
+ *
+ * If the selected option is a provider then the ID will be the provider ID
+ * If the selected option is "Other..." the the ID will be 0
+ * If the selected option is a provider protocol () the the ID will be protocol name
+ **/
+typedef enum {
+       EASYSETUP_PROVIDER_COMBO_BOX_ID_PROVIDER,
+       EASYSETUP_PROVIDER_COMBO_BOX_ID_OTHER,
+       EASYSETUP_PROVIDER_COMBO_BOX_ID_PLUGIN_PROTOCOL
+} EasysetupProviderComboBoxIdType;
+
 typedef struct {
        GtkComboBox parent;
 } EasysetupProviderComboBox;
@@ -74,6 +89,8 @@ void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, Mod
 
 gchar* easysetup_provider_combo_box_get_active_provider_id (EasysetupProviderComboBox *combobox);
 
+EasysetupProviderComboBoxIdType easysetup_provider_combo_box_get_active_id_type (EasysetupProviderComboBox *combobox);
+
 G_END_DECLS
 
 #endif /* _EASYSETUP_PROVIDER_COMBO_BOX */
index 90dd408..ab54656 100644 (file)
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <modest-runtime.h>
 #include "modest-easysetup-servertype-combo-box.h"
 #include <gtk/gtkliststore.h>
 #include <gtk/gtkcelllayout.h>
@@ -109,9 +110,6 @@ enum MODEL_COLS {
 };
 
 static void
-easysetup_servertype_combo_box_fill (EasysetupServertypeComboBox *combobox);
-
-static void
 easysetup_servertype_combo_box_init (EasysetupServertypeComboBox *self)
 {
        EasysetupServertypeComboBoxPrivate *priv = SERVERTYPE_COMBO_BOX_GET_PRIVATE (self);
@@ -132,53 +130,90 @@ easysetup_servertype_combo_box_init (EasysetupServertypeComboBox *self)
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combobox), renderer, TRUE);
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, 
        "text", MODEL_COL_NAME, NULL);
-       
-       easysetup_servertype_combo_box_fill (self);
-}
-
-EasysetupServertypeComboBox*
-easysetup_servertype_combo_box_new (void)
-{
-       return g_object_new (EASYSETUP_TYPE_SERVERTYPE_COMBO_BOX, NULL);
 }
 
-void easysetup_servertype_combo_box_fill (EasysetupServertypeComboBox *combobox)
+static void 
+easysetup_servertype_combo_box_fill (EasysetupServertypeComboBox *combobox,
+                                    gboolean filter_providers)
 {      
-       EasysetupServertypeComboBoxPrivate *priv = SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+       EasysetupServertypeComboBoxPrivate *priv;
+       GtkListStore *liststore;
+       ModestProtocolRegistry *protocol_registry;
+       GSList *remote_protocols, *node;
+       GtkTreeIter iter;
        
        /* Remove any existing rows: */
-       GtkListStore *liststore = GTK_LIST_STORE (priv->model);
+       priv = SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+       protocol_registry = modest_runtime_get_protocol_registry ();
+       remote_protocols = modest_protocol_registry_get_by_tag (protocol_registry, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS);
+
+       liststore = GTK_LIST_STORE (priv->model);
        gtk_list_store_clear (liststore);
+
+       for (node = remote_protocols; node != NULL; node = g_slist_next (node)) {
+               ModestProtocol* protocol;
+               gboolean add = TRUE;
+
+               protocol = (ModestProtocol *) node->data;
+
+               /* Do not include the protocols that would be listed
+                  in the providers combo */
+               if (filter_providers)
+                       if (modest_protocol_registry_protocol_type_is_provider (protocol_registry,
+                                                                               modest_protocol_get_type_id (protocol))) {
+                               add = FALSE;
+                       }
+               
+               if (add) {
+                       gtk_list_store_append (liststore, &iter);
+                       gtk_list_store_set (liststore, &iter, 
+                                           MODEL_COL_ID, 
+                                           modest_protocol_get_type_id (protocol),
+                                           MODEL_COL_NAME, 
+                                           modest_protocol_get_display_name (protocol),
+                                           -1);
+               }
+       }
        
-       GtkTreeIter iter;
-       gtk_list_store_append (liststore, &iter);
-       gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_STORE_POP, MODEL_COL_NAME, _("mail_fi_emailtype_pop3"), -1);
-       
-       /* Select the POP item: */
-       gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
-       
-       gtk_list_store_append (liststore, &iter);
-       gtk_list_store_set (liststore, &iter, MODEL_COL_ID, (gint)MODEST_PROTOCOL_STORE_IMAP, MODEL_COL_NAME, _("mail_fi_emailtype_imap"), -1);
+       g_slist_free (remote_protocols);
+}
+
+EasysetupServertypeComboBox*
+easysetup_servertype_combo_box_new (gboolean filter_providers)
+{
+       EasysetupServertypeComboBox *combo;
+
+       combo = g_object_new (EASYSETUP_TYPE_SERVERTYPE_COMBO_BOX, NULL);
+
+       /* Fill the combo */    
+       easysetup_servertype_combo_box_fill (combo, filter_providers);
+
+       return combo;
 }
 
 /**
  * Returns the selected servertype, 
- * or MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN if no servertype was selected.
+ * or MODEST_PROTOCOL_REGISTRY_TYPE_INVALID if no servertype was selected.
  */
-ModestTransportStoreProtocol
+ModestProtocolType
 easysetup_servertype_combo_box_get_active_servertype (EasysetupServertypeComboBox *combobox)
 {
        GtkTreeIter active;
-       const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active);
+       gboolean found;
+
+       found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active);
        if (found) {
-               EasysetupServertypeComboBoxPrivate *priv = SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+               EasysetupServertypeComboBoxPrivate *priv;
+               ModestProtocolType servertype;
+
+               priv = SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
 
-               ModestTransportStoreProtocol servertype = MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN;
+               servertype = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
                gtk_tree_model_get (priv->model, &active, MODEL_COL_ID, &servertype, -1);
                return servertype;      
        }
 
-       return MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN; /* Failed. */
+       return MODEST_PROTOCOL_REGISTRY_TYPE_INVALID; /* Failed. */
 }
 
 /* This allows us to pass more than one piece of data to the signal handler,
@@ -186,7 +221,7 @@ easysetup_servertype_combo_box_get_active_servertype (EasysetupServertypeComboBo
 typedef struct 
 {
                EasysetupServertypeComboBox* self;
-               gint id;
+               ModestProtocolType id;
                gboolean found;
 } ForEachData;
 
@@ -194,10 +229,10 @@ static gboolean
 on_model_foreach_select_id(GtkTreeModel *model, 
        GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
 {
+       ModestProtocolType id = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
        ForEachData *state = (ForEachData*)(user_data);
        
        /* Select the item if it has the matching ID: */
-       guint id = 0;
        gtk_tree_model_get (model, iter, MODEL_COL_ID, &id, -1); 
        if(id == state->id) {
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter);
@@ -214,12 +249,16 @@ on_model_foreach_select_id(GtkTreeModel *model,
  * or MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN if no servertype was selected.
  */
 gboolean
-easysetup_servertype_combo_box_set_active_servertype (EasysetupServertypeComboBox *combobox, ModestTransportStoreProtocol servertype)
+easysetup_servertype_combo_box_set_active_servertype (EasysetupServertypeComboBox *combobox, ModestProtocolType servertype)
 {
-       EasysetupServertypeComboBoxPrivate *priv = SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+       EasysetupServertypeComboBoxPrivate *priv;
+       ForEachData *state;
+       gboolean result;
        
+       priv = SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+
        /* Create a state instance so we can send two items of data to the signal handler: */
-       ForEachData *state = g_new0 (ForEachData, 1);
+       state = g_new0 (ForEachData, 1);
        state->self = combobox;
        state->id = servertype;
        state->found = FALSE;
@@ -227,7 +266,7 @@ easysetup_servertype_combo_box_set_active_servertype (EasysetupServertypeComboBo
        /* Look at each item, and select the one with the correct ID: */
        gtk_tree_model_foreach (priv->model, &on_model_foreach_select_id, state);
 
-       const gboolean result = state->found;
+       result = state->found;
        
        /* Free the state instance: */
        g_free(state);
index 2cbac65..bb7a6b4 100644 (file)
@@ -31,7 +31,7 @@
 #define _EASYSETUP_SERVERTYPE_COMBO_BOX
 
 #include <gtk/gtkcombobox.h>
-#include "modest-protocol-info.h"
+#include "modest-protocol-registry.h"
 
 G_BEGIN_DECLS
 
@@ -67,11 +67,11 @@ typedef struct {
 
 GType easysetup_servertype_combo_box_get_type (void);
 
-EasysetupServertypeComboBox* easysetup_servertype_combo_box_new (void);
+EasysetupServertypeComboBox* easysetup_servertype_combo_box_new (gboolean filter_providers);
 
-ModestTransportStoreProtocol easysetup_servertype_combo_box_get_active_servertype (EasysetupServertypeComboBox *combobox);
+ModestProtocolType easysetup_servertype_combo_box_get_active_servertype (EasysetupServertypeComboBox *combobox);
 
-gboolean easysetup_servertype_combo_box_set_active_servertype (EasysetupServertypeComboBox *combobox, ModestTransportStoreProtocol servertype);
+gboolean easysetup_servertype_combo_box_set_active_servertype (EasysetupServertypeComboBox *combobox, ModestProtocolType servertype);
 
 
 G_END_DECLS
index d550624..24b8ef7 100644 (file)
 #include <gtk/gtkcheckbutton.h>
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkseparator.h>
-#include <string.h> /* For strlen(). */
 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
-#include "widgets/modest-serversecurity-combo-box.h"
-#include "widgets/modest-secureauth-combo-box.h"
 #include "widgets/modest-validating-entry.h"
 #include "modest-text-utils.h"
 #include "modest-conf.h"
+#include "modest-defs.h"
 #include "modest-account-mgr.h"
+#include "modest-signal-mgr.h"
 #include "modest-account-mgr-helpers.h"
 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
 #include "maemo/modest-connection-specific-smtp-window.h"
 #include "widgets/modest-ui-constants.h"
-#include "widgets/modest-account-settings-dialog.h"
+#include "widgets/modest-default-account-settings-dialog.h"
+#include "widgets/modest-easysetup-wizard-page.h"
 #include "maemo/modest-maemo-utils.h"
 #include "modest-utils.h"
 #include "maemo/modest-hildon-includes.h"
+#include "maemo/modest-maemo-security-options-view.h"
+#include <modest-account-protocol.h>
 
 /* Include config.h so that _() works: */
 #ifdef HAVE_CONFIG_H
@@ -117,8 +119,10 @@ struct _ModestEasysetupWizardDialogPrivate
        GtkWidget *combo_incoming_servertype;
        GtkWidget *caption_incoming;
        GtkWidget *entry_incomingserver;
-       GtkWidget *combo_incoming_security;
-       GtkWidget *checkbox_incoming_auth;
+
+       /* Security widgets */
+       GtkWidget *incoming_security;
+       GtkWidget *outgoing_security;
 
        GtkWidget *page_custom_outgoing;
        GtkWidget *entry_outgoingserver;
@@ -128,10 +132,13 @@ struct _ModestEasysetupWizardDialogPrivate
        GtkWidget *button_outgoing_smtp_servers;
        
        GtkWidget *page_complete_customsetup;
+
+       ModestProtocolType last_plugin_protocol_selected;
+       GSList *missing_data_signals;
 };
 
 static void save_to_settings (ModestEasysetupWizardDialog *self);
-
+static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
 
 static gboolean
 on_delete_event (GtkWidget *widget,
@@ -151,42 +158,6 @@ on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
 }
 
 static void
-on_incoming_security_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
-{
-       ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
-       ModestConnectionProtocol protocol_security_incoming;
-
-       g_return_if_fail (priv != NULL);
-       protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
-
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth), modest_protocol_info_is_secure (protocol_security_incoming));
-       gtk_widget_set_sensitive (priv->checkbox_incoming_auth, !modest_protocol_info_is_secure (protocol_security_incoming));
-       
-       on_easysetup_changed (widget, wizard);
-}
-
-static void
-modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
-                                            GValue *value, GParamSpec *pspec)
-{
-       switch (property_id) {
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-       }
-}
-
-static void
-modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
-                                            const GValue *value, GParamSpec *pspec)
-{
-       switch (property_id) {
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-       }
-}
-
-static void
 modest_easysetup_wizard_dialog_dispose (GObject *object)
 {
        if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
@@ -207,14 +178,16 @@ modest_easysetup_wizard_dialog_finalize (GObject *object)
 
        if (priv->settings)
                g_object_unref (priv->settings);
+
+       if (priv->missing_data_signals) {
+               modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
+               priv->missing_data_signals = NULL;
+       }
                
        G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
 }
 
 static void
-show_error (GtkWidget *parent_widget, const gchar* text);
-
-static void
 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
 
 static void
@@ -222,99 +195,109 @@ set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
 
 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
 
-static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
-                                    ModestPresetsSecurity security_incoming)
+static gint 
+get_port_from_protocol (ModestProtocolType server_type,
+                       gboolean alternate_port)
 {
-       int serverport_incoming = 0;
-               /* We don't check for SMTP here as that is impossible for an incoming server. */
-               if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
-                       serverport_incoming =
-                               (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143; 
-               } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
-                       serverport_incoming =
-                               (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110; 
-               }
-       return serverport_incoming;
-}
-
-static GList* 
-check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
-{
-       GError *error = NULL;
-       ModestTransportStoreProtocol protocol;
-       const gchar* hostname;
-       const gchar* username;
-       ModestConnectionProtocol protocol_security_incoming;
-       int port_num; 
-       GList *list_auth_methods;
-       ModestEasysetupWizardDialogPrivate *priv;
-       
-       priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
-       protocol = easysetup_servertype_combo_box_get_active_servertype (
-                EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
-       hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
-       username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
-       protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
-       port_num = get_serverport_incoming(protocol, protocol_security_incoming); 
-       list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, 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)) {
-                       ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
-                       if (modest_protocol_info_auth_is_secure(auth)) {
-                               list = g_list_append(list, GINT_TO_POINTER(auth));
-                       }
-               }
-
-               g_list_free(list_auth_methods);
+       int server_port = 0;
+       ModestProtocol *protocol;
+       ModestProtocolRegistry *protocol_registry;
 
-               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)
-       {
-               show_error (GTK_WIDGET(self), _("mcen_ib_unableto_discover_auth_methods"));
-       }
-
-       if(error != NULL)
-               g_error_free(error);
-
-       return NULL;
-}
+       protocol_registry = modest_runtime_get_protocol_registry ();
+       protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
 
-static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
-{
-       GList* methods = check_for_supported_auth_methods(self);
-       if (!methods)
-       {
-               return FALSE;
+       if (alternate_port) {
+               server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
+       } else {
+               server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
        }
-
-       g_list_free(methods);
-       return TRUE;
+       return server_port;
 }
 
-static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* self)
-{
-       ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
-
-       GList* methods = check_for_supported_auth_methods(self);
-       if (methods)
-       {
-               /* Use the first one: */
-               result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
-               g_list_free(methods);
-       }
-
-       return result;
-}
+/* 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 = easysetup_servertype_combo_box_get_active_servertype ( */
+/*             EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype)); */
+/*     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_serversecurity_combo_box_get_active_serversecurity */
+/*             (MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_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 ModestProtocolType check_first_supported_auth_method(ModestEasysetupWizardDialog* self) */
+/* { */
+/*     ModestProtocolType result; */
+
+/*     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; */
+/* } */
 
 static void
 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
@@ -354,12 +337,13 @@ on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
 /** This is a convenience function to create a caption containing a mandatory widget.
  * When the widget is edited, the enable_buttons() vfunc will be called.
  */
-static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
-                                                 GtkSizeGroup *group,
-                                                 const gchar *value,
-                                                 GtkWidget *control,
-                                                 GtkWidget *icon,
-                                                 HildonCaptionStatus flag)
+static GtkWidget* 
+create_caption_new_with_asterisk (ModestEasysetupWizardDialog *self,
+                                 GtkSizeGroup *group,
+                                 const gchar *value,
+                                 GtkWidget *control,
+                                 GtkWidget *icon,
+                                 HildonCaptionStatus flag)
 {
        GtkWidget *caption = NULL;
   
@@ -455,8 +439,8 @@ on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
 static void
 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
 {
-       /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
-       show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
+       modest_platform_information_banner (GTK_WIDGET (self), NULL,
+                                           _CS("ckdg_ib_maximum_characters_reached"));
 }
 
 static GtkWidget*
@@ -551,7 +535,7 @@ create_page_account_details (ModestEasysetupWizardDialog *self)
        g_list_free (list_prevent);
        list_prevent = NULL;
        modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
-                                                                                                                                        modest_maemo_utils_on_entry_invalid_character, self);
+                                                                                                                                        modest_utils_on_entry_invalid_character, self);
        
        /* Set max length as in the UI spec:
         * The UI spec seems to want us to show a dialog if we hit the maximum. */
@@ -592,7 +576,7 @@ create_page_user_details (ModestEasysetupWizardDialog *self)
        GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
                                                              _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
        g_signal_connect(G_OBJECT(priv->entry_user_name), "changed", 
-                                                                        G_CALLBACK(on_easysetup_changed), self);
+                        G_CALLBACK(on_easysetup_changed), self);
        gtk_widget_show (priv->entry_user_name);
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (caption);
@@ -605,19 +589,21 @@ create_page_user_details (ModestEasysetupWizardDialog *self)
        modest_validating_entry_set_unallowed_characters (
                MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
        modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
-               modest_maemo_utils_on_entry_invalid_character, self);
+               modest_utils_on_entry_invalid_character, self);
        g_list_free (list_prevent);
        
        /* The username widgets: */     
        priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
        /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), 
+                                        HILDON_GTK_INPUT_MODE_FULL);
        caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"), 
-                                                  priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
+                                                  priv->entry_user_username, 
+                                                   NULL, HILDON_CAPTION_MANDATORY);
        gtk_widget_show (priv->entry_user_username);
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        g_signal_connect(G_OBJECT(priv->entry_user_username), "changed", 
-                                                                        G_CALLBACK(on_easysetup_changed), self);
+                        G_CALLBACK(on_easysetup_changed), self);
        gtk_widget_show (caption);
        
        /* Prevent the use of some characters in the username, 
@@ -625,7 +611,7 @@ create_page_user_details (ModestEasysetupWizardDialog *self)
        modest_validating_entry_set_unallowed_characters_whitespace (
                MODEST_VALIDATING_ENTRY (priv->entry_user_username));
        modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
-               modest_maemo_utils_on_entry_invalid_character, self);
+               modest_utils_on_entry_invalid_character, self);
        
        /* Set max length as in the UI spec:
         * The UI spec seems to want us to show a dialog if we hit the maximum. */
@@ -643,7 +629,7 @@ create_page_user_details (ModestEasysetupWizardDialog *self)
        caption = create_caption_new_with_asterisk (self, sizegroup, 
                                                   _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
        g_signal_connect(G_OBJECT(priv->entry_user_password), "changed", 
-                                                                        G_CALLBACK(on_easysetup_changed), self);
+                        G_CALLBACK(on_easysetup_changed), self);
        gtk_widget_show (priv->entry_user_password);
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (caption);
@@ -658,7 +644,7 @@ create_page_user_details (ModestEasysetupWizardDialog *self)
        gtk_widget_show (priv->entry_user_email);
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        g_signal_connect(G_OBJECT(priv->entry_user_email), "changed", 
-                                                                        G_CALLBACK(on_easysetup_changed), self);
+                        G_CALLBACK(on_easysetup_changed), self);
        gtk_widget_show (caption);
        
        /* Set max length as in the UI spec:
@@ -673,7 +659,8 @@ create_page_user_details (ModestEasysetupWizardDialog *self)
        return GTK_WIDGET (box);
 }
 
-static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
+static GtkWidget* 
+create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
 {
        GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        
@@ -705,18 +692,27 @@ static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *s
 static void 
 update_incoming_server_title (ModestEasysetupWizardDialog *self)
 {
-       ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
-       const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
+       ModestEasysetupWizardDialogPrivate* priv; 
+       ModestProtocolType protocol_type; 
+       ModestProtocolRegistry *protocol_registry;
+
+       priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
+       protocol_registry = modest_runtime_get_protocol_registry ();
+       
+       protocol_type = easysetup_servertype_combo_box_get_active_servertype (
                EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
-       const gchar* type = 
-               (protocol == MODEST_PROTOCOL_STORE_POP ? 
-                _("mail_fi_emailtype_pop3") : 
-                _("mail_fi_emailtype_imap") );
-                       
+
+       /* This could happen when the combo box has still no active iter */
+       if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
+               gchar* incomingserver_title;
+               const gchar *protocol_display_name; 
+
+               protocol_display_name = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type));
                
-       gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
-       g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
-       g_free(incomingserver_title);
+               incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), protocol_display_name);
+               g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
+               g_free(incomingserver_title);
+       }
 }
 
 /** Change the caption title for the incoming server, 
@@ -726,13 +722,19 @@ static void
 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
 {
        ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
-       const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
-               EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
-       
-       /* Fill the combo with appropriately titled choices for POP or IMAP. */
-       /* The choices are the same, but the titles are different, as in the UI spec. */
-       modest_serversecurity_combo_box_fill (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol);
+       EasysetupServertypeComboBox *server_type_combo;
+       ModestProtocolType protocol_type;
+       ModestSecurityOptionsView *view;
+
+       server_type_combo = 
+               EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype);
+       protocol_type = 
+               easysetup_servertype_combo_box_get_active_servertype (server_type_combo);
+       
+       /* Fill the combo with appropriately titled choices for all
+          those protocols */
+       view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
+       modest_security_options_view_set_server_type (view, protocol_type);
 }
 
 static void 
@@ -740,11 +742,19 @@ on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
 {
        ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
        ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
-       
+       EasysetupServertypeComboBox *combo;
+       ModestProtocolType protocol_type;
+
        priv->dirty = TRUE;
        
+       /* Update title */
        update_incoming_server_title (self);
+
+       /* Update security options if needed */
+       combo = EASYSETUP_SERVERTYPE_COMBO_BOX (combobox);
+       protocol_type = easysetup_servertype_combo_box_get_active_servertype (combo);
        update_incoming_server_security_choices (self);
+       gtk_widget_show (priv->incoming_security);
 
        set_default_custom_servernames (self);
 }
@@ -761,16 +771,26 @@ on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
 static GtkWidget* 
 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
 {
-       ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+       ModestProtocolRegistry *protocol_registry;
+       ModestEasysetupWizardDialogPrivate* priv; 
+       GtkWidget *box; 
+       GtkWidget *scrolled_window;
+       GtkWidget *label;
+       GtkSizeGroup *sizegroup;
+       GtkWidget *caption;
+
+       priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
+       protocol_registry = modest_runtime_get_protocol_registry ();
+
+       box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
 
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                        GTK_POLICY_NEVER,
                                        GTK_POLICY_AUTOMATIC);
 
        /* Show note that account type cannot be changed in future: */
-       GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
+       label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
        gtk_widget_set_size_request (label, 600, -1);
        gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
@@ -779,14 +799,12 @@ create_page_custom_incoming (ModestEasysetupWizardDialog *self)
        /* Create a size group to be used by all captions.
         * Note that HildonCaption does not create a default size group if we do not specify one.
         * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
-       GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
         
        /* The incoming server widgets: */
-       priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
-       easysetup_servertype_combo_box_set_active_servertype (
-               EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
-       GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
-                                                             _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
+       priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new (TRUE));
+       caption = create_caption_new_with_asterisk (self, sizegroup, 
+                                                   _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
        gtk_widget_show (priv->combo_incoming_servertype);
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (caption);
@@ -801,7 +819,9 @@ create_page_custom_incoming (ModestEasysetupWizardDialog *self)
         * so this default text will never be seen: */
        /* (Note: Changing the title seems pointless. murrayc) */
        priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup, 
-                                                                 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
+                                                                 "Incoming Server", 
+                                                                  priv->entry_incomingserver, 
+                                                                  NULL, HILDON_CAPTION_MANDATORY);
        update_incoming_server_title (self);
        gtk_widget_show (priv->entry_incomingserver);
        gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
@@ -816,36 +836,25 @@ create_page_custom_incoming (ModestEasysetupWizardDialog *self)
        g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
                          G_CALLBACK (on_entry_incoming_servername_changed), self);
 
-       /* The secure connection widgets: */    
-       priv->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
-       update_incoming_server_security_choices (self);
-       modest_serversecurity_combo_box_set_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
-       caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
-                                     priv->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
-       g_signal_connect (G_OBJECT (priv->combo_incoming_security), "changed",
-                         G_CALLBACK (on_incoming_security_changed), self);
-       gtk_widget_show (priv->combo_incoming_security);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       priv->checkbox_incoming_auth = gtk_check_button_new ();
-       g_signal_connect (G_OBJECT (priv->checkbox_incoming_auth), "toggled",
-                         G_CALLBACK (on_easysetup_changed), self);
-       caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
-                                     priv->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
-       
-       gtk_widget_show (priv->checkbox_incoming_auth);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       gtk_widget_show (GTK_WIDGET (box));
+       /* The secure connection widgets. These are only valid for
+          protocols with security */   
+       priv->incoming_security = 
+               modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
+                                                       FALSE, sizegroup);
+       gtk_box_pack_start (GTK_BOX (box), priv->incoming_security, 
+                           FALSE, FALSE, MODEST_MARGIN_HALF);
+
+       /* Set default selection */
+       easysetup_servertype_combo_box_set_active_servertype (
+               EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), 
+               MODEST_PROTOCOLS_STORE_POP);
 
        gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
        gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
                                             gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
+       gtk_widget_show (GTK_WIDGET (box));
        gtk_widget_show (scrolled_window);
-       
+
        return GTK_WIDGET (scrolled_window);
 }
 
@@ -923,30 +932,15 @@ create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
        gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (caption);
        set_default_custom_servernames (self);
-       
-       /* The secure connection widgets: */    
-       priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
-       g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed",
-                         G_CALLBACK (on_easysetup_changed), self);
-       modest_serversecurity_combo_box_fill (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
-       modest_serversecurity_combo_box_set_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
-       caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
-                                     priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (priv->combo_outgoing_security);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* The secure authentication widgets: */
-       priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
-                       g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed",
-                         G_CALLBACK (on_easysetup_changed), self);
-       caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
-                                     priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (priv->combo_outgoing_auth);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
+
+       /* The secure connection widgets. These are only valid for
+          protocols with security */   
+       priv->outgoing_security = 
+               modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
+                                                       FALSE, sizegroup);
+       gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security, 
+                           FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (priv->outgoing_security);
        
        GtkWidget *separator = gtk_hseparator_new ();
        gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
@@ -998,12 +992,12 @@ show_advanced_edit(gpointer user_data)
        gint response;
        
        /* Show the Account Settings window: */
-       ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
+       ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
        if (priv->pending_load_settings) {
                save_to_settings (self);
                priv->pending_load_settings = FALSE;
        }
-       modest_account_settings_dialog_set_account (dialog, priv->settings);
+       modest_account_settings_dialog_load_settings (dialog, priv->settings);
        
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
        
@@ -1022,7 +1016,8 @@ on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
        /* Show the Account Settings window: */
        show_advanced_edit(self);
 }
-static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
+static GtkWidget* 
+create_page_complete_custom (ModestEasysetupWizardDialog *self)
 {
        GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
@@ -1176,6 +1171,53 @@ presets_loader (gpointer userdata)
 }
 
 static void
+modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
+                                           GtkWidget *page,
+                                           const gchar *label)
+{
+       gint index;
+       /* Append page and set attributes */
+       index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
+       gtk_container_child_set (GTK_CONTAINER (notebook), page,
+                                "tab-expand", TRUE, "tab-fill", TRUE,
+                                NULL);
+       gtk_widget_show (page);
+}
+
+static void
+init_user_page (ModestEasysetupWizardDialogPrivate *priv)
+{
+       priv->page_user_details = NULL;
+       priv->entry_user_name = NULL;
+       priv->entry_user_username = NULL;
+       priv->entry_user_password = NULL;
+       priv->entry_user_email = NULL;
+}
+
+static void
+init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
+{
+       priv->page_custom_incoming = NULL;
+       priv->combo_incoming_servertype = NULL;
+       priv->caption_incoming = NULL;
+       priv->entry_incomingserver = NULL;
+       priv->entry_user_email = NULL;
+       priv->incoming_security = NULL;
+}
+
+static void
+init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
+{
+       priv->page_custom_outgoing = NULL;
+       priv->entry_outgoingserver = NULL;
+       priv->combo_outgoing_security = NULL;
+       priv->combo_outgoing_auth = NULL;
+       priv->checkbox_outgoing_smtp_specific = NULL;
+       priv->button_outgoing_smtp_servers = NULL;
+       priv->outgoing_security = NULL;
+}
+
+static void
 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
 {
        gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
@@ -1207,51 +1249,22 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
        /* Initialize fields */
        priv->page_welcome = create_page_welcome (self);
        priv->page_account_details = create_page_account_details (self);
-       priv->page_user_details = create_page_user_details (self);
-       priv->page_complete_easysetup = NULL;       
-       priv->page_custom_incoming = NULL;
-       priv->combo_incoming_servertype = NULL;
-       priv->caption_incoming = NULL;
-       priv->entry_incomingserver = NULL;
-       priv->combo_incoming_security = NULL;
-       priv->checkbox_incoming_auth = NULL;
-       priv->page_custom_outgoing = NULL;
-       priv->entry_outgoingserver = NULL;
-       priv->combo_outgoing_security = NULL;
-       priv->combo_outgoing_auth = NULL;
-       priv->checkbox_outgoing_smtp_specific = NULL;
-       priv->button_outgoing_smtp_servers = NULL;
-       priv->page_complete_customsetup = NULL;
-
-       /* Add the common pages: */
-       gtk_notebook_append_page (notebook, priv->page_welcome, 
-                                 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
-       gtk_container_child_set (GTK_CONTAINER (notebook), 
-                                priv->page_welcome,
-                                "tab-expand", TRUE,
-                                "tab-fill", TRUE,
-                                NULL);
 
-       gtk_notebook_append_page (notebook, priv->page_account_details, 
-                                 gtk_label_new (_("mcen_ti_accountdetails")));
-       gtk_container_child_set (GTK_CONTAINER (notebook), 
-                                priv->page_account_details,
-                                "tab-expand", TRUE,
-                                "tab-fill", TRUE,
-                                NULL);
+       init_user_page (priv);
+       init_incoming_page (priv);
+       init_outgoing_page (priv);
 
-       gtk_notebook_append_page (notebook, priv->page_user_details, 
-                                 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
-       gtk_container_child_set (GTK_CONTAINER (notebook), 
-                                priv->page_user_details,
-                                "tab-expand", TRUE,
-                                "tab-fill", TRUE,
-                                NULL);
+       priv->page_complete_easysetup = NULL;       
+       priv->page_complete_customsetup = NULL;
+       priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+       priv->missing_data_signals = NULL;
+
+       /* Add the common pages */
+       modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome, 
+                                                   _("mcen_ti_emailsetup_welcome"));
+       modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details, 
+                                                   _("mcen_ti_accountdetails"));
                
-       /* Create and add the easysetup-specific pages,
-        * because we need _some_ final page to enable the Next and Finish buttons: */
-       create_subsequent_easysetup_pages (self);
-
        /* Connect to the dialog's response signal so we can enable/disable buttons 
         * for the newly-selected page, because the prev/next buttons cause response to be emitted.
         * Note that we use g_signal_connect_after() instead of g_signal_connect()
@@ -1302,7 +1315,8 @@ modest_easysetup_wizard_dialog_new (void)
        return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
 }
 
-static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
+static void 
+create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
 {
        ModestEasysetupWizardDialogPrivate *priv;
        GtkNotebook *notebook = NULL;
@@ -1311,12 +1325,17 @@ static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *se
        g_assert(notebook);
 
        priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
-       
+
+       if (!priv->page_user_details) {
+               priv->page_user_details = create_page_user_details (self);
+       }                       
+
        /* Create the custom pages: */
        if(!(priv->page_custom_incoming)) {
                priv->page_custom_incoming = create_page_custom_incoming (self);
        }
                
+       /* TODO: only if needed */
        if(!(priv->page_custom_outgoing)) {
                priv->page_custom_outgoing = create_page_custom_outgoing (self);
        }
@@ -1324,24 +1343,22 @@ static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *se
        if(!(priv->page_complete_customsetup)) {
                priv->page_complete_customsetup = create_page_complete_custom (self);
        }
-       
+
+       if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
+               modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
+                                                           _("mcen_ti_emailsetup_userdetails"));
+
        if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
-               gtk_notebook_append_page (notebook, priv->page_custom_incoming,
-                                         gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
+               modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming, 
+                                                           _("mcen_ti_emailsetup_incomingdetails"));
        
        if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))           
-               gtk_notebook_append_page (notebook, priv->page_custom_outgoing,
-                                         gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
+               modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing, 
+                                                           _("mcen_ti_emailsetup_outgoingdetails"));
                
-       if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup))) {
-               gtk_notebook_append_page (notebook, priv->page_complete_customsetup,
-                                         gtk_label_new (_("mcen_ti_emailsetup_complete")));
-               gtk_container_child_set (GTK_CONTAINER (notebook), 
-                                        priv->page_complete_customsetup,
-                                        "tab-expand", TRUE,
-                                        "tab-fill", TRUE,
-                                        NULL);
-       }
+       if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
+               modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup, 
+                                                           _("mcen_ti_emailsetup_complete"));
                        
        /* This is unnecessary with GTK+ 2.10: */
        modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
@@ -1361,69 +1378,153 @@ create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
        if(!priv->page_complete_easysetup)
                priv->page_complete_easysetup = create_page_complete_easysetup (self);
 
-       if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup))) {
-               gtk_notebook_append_page (notebook, priv->page_complete_easysetup, 
-                                         gtk_label_new (_("mcen_ti_emailsetup_complete")));
-               gtk_container_child_set (GTK_CONTAINER (notebook),
-                                        priv->page_complete_easysetup,
-                                        "tab-expand", TRUE,
-                                        "tab-fill", TRUE,
-                                        NULL);
-       }
+       if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
+               modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup, 
+                                                           _("mcen_ti_emailsetup_complete"));
                        
        /* This is unnecessary with GTK+ 2.10: */
        modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
 }
+
+/* */
+static void
+remove_non_common_tabs (GtkNotebook *notebook, 
+                       gboolean remove_user_details) 
+{
+       gint starting_tab;
+       /* The first 2 tabs are the common ones (welcome tab and the
+          providers tab), so we always remove starting from the
+          end */
+
+       starting_tab = (remove_user_details) ? 2 : 3;
+       while (gtk_notebook_get_n_pages (notebook) > starting_tab) 
+               gtk_notebook_remove_page (notebook, -1); 
+}
+
+static void
+on_missing_mandatory_data (ModestAccountProtocol *protocol,
+                          gboolean missing,
+                          gpointer user_data)
+{
+       real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
+}
+
 /* After the user details page,
  * the following pages depend on whether "Other" was chosen 
  * in the provider combobox on the account page
  */
-static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
+static void 
+create_subsequent_pages (ModestEasysetupWizardDialog *self)
 {
        ModestEasysetupWizardDialogPrivate *priv;
+       EasysetupProviderComboBox *combo;
+       EasysetupProviderComboBoxIdType id_type;
+       GtkNotebook *notebook;
 
        priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+       combo = EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider);
+       id_type = easysetup_provider_combo_box_get_active_id_type (combo);
+       g_object_get (self, "wizard-notebook", &notebook, NULL);
 
-       if (easysetup_provider_combo_box_get_active_provider_id (
-                   EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider)) == 0) {
+       if (id_type == EASYSETUP_PROVIDER_COMBO_BOX_ID_OTHER) {
                /* "Other..." was selected: */
-               
-               /* Make sure that the easysetup pages do not exist: */
-               if(priv->page_complete_easysetup) {
-                       gtk_widget_destroy (priv->page_complete_easysetup);
+
+               /* If we come from a rollbacked easysetup */
+               if (priv->page_complete_easysetup) {
+                       remove_non_common_tabs (notebook, FALSE);
                        priv->page_complete_easysetup = NULL;
-               }
+               } 
                
+               /* If we come from a rollbacked plugin protocol setup */
+               if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
+                       remove_non_common_tabs (notebook, TRUE);
+                       priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+                       modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
+                       priv->missing_data_signals = NULL;
+               }
+
                create_subsequent_customsetup_pages (self);
-       }       
-       else {
-               /* A specific provider was selected: */
-               {
-                       /* Make sure that the custom pages do not exist:
-                        * Because they will be used if they exist, when creating the account. */
-                       if(priv->page_custom_incoming) {
-                               gtk_widget_destroy (priv->page_custom_incoming);
-                               priv->page_custom_incoming = NULL;
-                               priv->combo_incoming_servertype = NULL;
-                               priv->caption_incoming = NULL;
-                               priv->entry_incomingserver = NULL;
-                               priv->combo_incoming_security = NULL;
-                               priv->checkbox_incoming_auth = NULL;
-                       }
+       } else {
+               /* If we come from a rollbacked custom setup */
+               if (priv->page_custom_incoming) {
+                       remove_non_common_tabs (notebook, TRUE);
+                       init_user_page (priv);
+                       init_incoming_page (priv);
+                       init_outgoing_page (priv);
+                       init_user_page (priv);
+                       priv->page_complete_customsetup = NULL;
+               }
+
+               /* It's a pluggable protocol and not a provider with presets */
+               if (id_type == EASYSETUP_PROVIDER_COMBO_BOX_ID_PLUGIN_PROTOCOL) {
+                       ModestProtocol *protocol;
+                       gchar *proto_name;
+                       ModestProtocolType proto_type;
+
                        
-                       if(priv->page_custom_outgoing) {
-                               gtk_widget_destroy (priv->page_custom_outgoing);
-                               priv->page_custom_outgoing = NULL;
-                               priv->entry_outgoingserver = NULL;
-                               priv->combo_outgoing_security = NULL;
-                               priv->combo_outgoing_auth = NULL;
-                               priv->checkbox_outgoing_smtp_specific = NULL;
-                               priv->button_outgoing_smtp_servers = NULL;
+                       /* If we come from a rollbacked easy setup */
+                       if (priv->last_plugin_protocol_selected == 
+                           MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
+                           priv->page_complete_easysetup) {
+                               remove_non_common_tabs (notebook, TRUE);
+                               init_user_page (priv);
+                               priv->page_complete_easysetup = NULL;
                        }
                        
-                       if(priv->page_complete_customsetup) {
-                               gtk_widget_destroy (priv->page_complete_customsetup);
-                               priv->page_complete_customsetup = NULL;
+                       proto_name = easysetup_provider_combo_box_get_active_provider_id (combo);
+                       protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
+                                                                                 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
+                                                                                 proto_name);
+                       proto_type = modest_protocol_get_type_id (protocol);
+
+                       if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
+                           proto_type != priv->last_plugin_protocol_selected) {
+                               ModestPairList *tabs;
+                               GSList *tmp;
+
+                               /* Remember the last selected plugin protocol */
+                               priv->last_plugin_protocol_selected = proto_type;
+
+                               /* Get tabs */
+                               tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
+                               tmp = (GSList *) tabs;
+                               while (tmp) {
+                                       ModestPair *pair = (ModestPair *) tmp->data;
+                                       modest_easysetup_wizard_dialog_append_page (notebook,
+                                                                                   GTK_WIDGET (pair->second),
+                                                                                   (const gchar *) pair->first);
+
+                                       /* Connect signals */
+                                       priv->missing_data_signals = 
+                                               modest_signal_mgr_connect (priv->missing_data_signals, 
+                                                                          G_OBJECT (pair->second), 
+                                                                          "missing-mandatory-data",
+                                                                          G_CALLBACK (on_missing_mandatory_data), 
+                                                                          self);
+
+                                       g_free (pair->first);
+                                       tmp = g_slist_next (tmp);
+                                       /* Critical: if you don't show the page then the dialog will ignore it */
+/*                                     gtk_widget_show (GTK_WIDGET (pair->second)); */
+                               }
+                               modest_pair_list_free (tabs);
+                       }
+                       g_free (proto_name);
+               } else {
+                       if (priv->last_plugin_protocol_selected != 
+                           MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
+                               remove_non_common_tabs (notebook, TRUE);
+                               init_user_page (priv);
+                               priv->page_complete_easysetup = NULL;
+                               priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+                               modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
+                               priv->missing_data_signals = NULL;
+                       }
+                       if (!priv->page_user_details) {
+                               priv->page_user_details = create_page_user_details (self);
+                               modest_easysetup_wizard_dialog_append_page (notebook, 
+                                                                           priv->page_user_details,
+                                                                           _("mcen_ti_emailsetup_userdetails"));
                        }
                }
                
@@ -1434,26 +1535,32 @@ static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
 
 
 static gchar*
-util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
+util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
 {
+       const gchar* hostname = NULL;
+       gchar* at;
+       gchar* domain;
+       ModestProtocolRegistry *protocol_registry;
+       ModestProtocol *protocol;
+
        if (!email_address)
                return NULL;
        
-       gchar* at = g_utf8_strchr (email_address, -1, '@');
+       at = g_utf8_strchr (email_address, -1, '@');
        if (!at || (g_utf8_strlen (at, -1) < 2))
                return NULL;
                
-       gchar* domain = g_utf8_next_char (at);
+       domain = g_utf8_next_char (at);
        if(!domain)
                return NULL;
+
+       protocol_registry = modest_runtime_get_protocol_registry ();
+       protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
                
-       const gchar* hostname = NULL;
-       if (servertype == MODEST_PROTOCOL_STORE_POP)
-               hostname = "pop";
-       else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
-               hostname = "imap";
-       else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
-               hostname = "smtp";
+       if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
+           modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
+               hostname = modest_protocol_get_name (protocol);
+       }
        
        if (!hostname)
                return NULL;
@@ -1474,18 +1581,22 @@ set_default_custom_servernames (ModestEasysetupWizardDialog *self)
         */
        if (priv->entry_user_email
            && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
-               const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
+               const ModestProtocolType protocol_type = easysetup_servertype_combo_box_get_active_servertype (
                        EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
-               const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
-               
-               gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
 
-               /* Do not set the INCOMING_CHANGED flag because of this edit */
-               g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
-               gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
-               g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
+               /* This could happen when the combo box has still no active iter */
+               if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
+                       const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));    
+                       gchar* servername = util_get_default_servername_from_email_address (email_address, 
+                                                                                           protocol_type);
 
-               g_free (servername);
+                       /* Do not set the INCOMING_CHANGED flag because of this edit */
+                       g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
+                       gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
+                       g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
+                       
+                       g_free (servername);
+               }
        }
        
        /* Set a default domain for the server, based on the email address,
@@ -1498,7 +1609,7 @@ set_default_custom_servernames (ModestEasysetupWizardDialog *self)
            && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
                const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
                
-               gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
+               gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
 
                /* Do not set the OUTGOING_CHANGED flag because of this edit */
                g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
@@ -1518,7 +1629,7 @@ get_entered_account_title (ModestEasysetupWizardDialog *self)
        priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
        account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
 
-       if (!account_title || (strlen (account_title) == 0)) {
+       if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
                return NULL;
        } else {
                /* Strip it of whitespace at the start and end: */
@@ -1528,7 +1639,7 @@ get_entered_account_title (ModestEasysetupWizardDialog *self)
                if (!result)
                        return NULL;
                        
-               if (strlen (result) == 0) {
+               if (g_utf8_strlen (result, -1) == 0) {
                        g_free (result);
                        return NULL;    
                }
@@ -1542,6 +1653,9 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *
 {
        ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
        ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+       ModestProtocolRegistry *protocol_registry;
+
+       protocol_registry = modest_runtime_get_protocol_registry ();
 
        /* if are browsing pages previous to the last one, then we have pending settings in
         * this wizard */
@@ -1568,11 +1682,14 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *
             
                        return FALSE;
                }
-       }
-       else if (current_page == priv->page_user_details) {
+
+               /* Make sure that the subsequent pages are appropriate for the provider choice. */
+               create_subsequent_pages (self);
+
+       } else if (current_page == priv->page_user_details) {
                /* Check that the email address is valud: */
                const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
-               if ((!email_address) || (strlen(email_address) == 0))
+               if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
                        return FALSE;
                        
                if (!modest_text_utils_validate_email_address (email_address, NULL)) {
@@ -1585,38 +1702,25 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *
 
                        return FALSE;
                }
-               
-               /* Make sure that the subsequent pages are appropriate for the provider choice. */
-               create_subsequent_pages (self);
        }
-       
-       /* TODO: The UI Spec wants us to check that the servernames are valid, 
-        * but does not specify how.
-        */
          
-       if(next_page == priv->page_custom_incoming) {
+       if (next_page == priv->page_custom_incoming) {
                set_default_custom_servernames (self);
-       }
-       else if (next_page == priv->page_custom_outgoing) {
+       } else if (next_page == priv->page_custom_outgoing) {
                set_default_custom_servernames (self);
 
                /* Check if the server supports secure authentication */
-               const ModestConnectionProtocol security_incoming = 
-                       modest_serversecurity_combo_box_get_active_serversecurity (
-                               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
-               if (gtk_toggle_button_get_active (
-                       GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))
-                               && !modest_protocol_info_is_secure(security_incoming))
-               {
-                               if (!check_has_supported_auth_methods (self))
-                                       return FALSE;
-               }
+/*             if (modest_security_options_view_auth_check (security_options)) */
+/*                     if (!check_has_supported_auth_methods (self)) */
+/*                             return FALSE; */
+               gtk_widget_show (priv->outgoing_security);
        }
        
        /* If this is the last page, and this is a click on Finish, 
         * then attempt to create the dialog.
         */
-       if(!next_page) /* This is NULL when this is a click on Finish. */
+       if(!next_page && 
+          current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
        {
                if (priv->pending_load_settings) {
                        save_to_settings (self);
@@ -1641,7 +1745,7 @@ static gboolean entry_is_empty (GtkWidget *entry)
                return FALSE;
                
        const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
-       if ((!text) || (strlen(text) == 0))
+       if ((!text) || (g_utf8_strlen (text, -1) == 0))
                return TRUE;
        else {
                /* Strip it of whitespace at the start and end: */
@@ -1651,7 +1755,7 @@ static gboolean entry_is_empty (GtkWidget *entry)
                if (!stripped)
                        return TRUE;
                        
-               const gboolean result = (strlen (stripped) == 0);
+               const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
                
                g_free (stripped);
                return result;
@@ -1659,6 +1763,41 @@ static gboolean entry_is_empty (GtkWidget *entry)
 }
 
 static void
+real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
+{              
+       GtkNotebook *notebook = NULL;
+       gboolean is_finish_tab;
+       GtkWidget *current;
+       ModestEasysetupWizardDialogPrivate *priv;
+
+       /* Get data */
+       priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
+       g_object_get (dialog, "wizard-notebook", &notebook, NULL);
+       
+       /* Disable the Finish button until we are on the last page,
+        * because HildonWizardDialog enables this for all but the
+        * first page */
+       current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
+       is_finish_tab = ((current == priv->page_complete_easysetup) ||
+                        (current == priv->page_complete_customsetup));
+
+       if (is_finish_tab) {
+               /* Disable Next on the last page no matter what the
+                  argument say */
+               enable_next = FALSE;
+       } else {
+               /* Not the last one */
+               gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
+                                                  MODEST_WIZARD_DIALOG_FINISH,
+                                                  FALSE);
+       }
+       
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
+                                          MODEST_WIZARD_DIALOG_NEXT,
+                                          enable_next);
+}
+
+static void
 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
 {
        ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
@@ -1667,13 +1806,11 @@ on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
        gboolean enable_next = TRUE;
        if (current_page == priv->page_welcome) {
                enable_next = TRUE;
-       }
-       else if (current_page == priv->page_account_details) {
+       } else if (current_page == priv->page_account_details) {
                /* The account details title is mandatory: */
                if (entry_is_empty(priv->entry_account_title))
                        enable_next = FALSE;
-       }
-       else if (current_page == priv->page_user_details) {     
+       } else if (current_page == priv->page_user_details) {   
                /* The user details username is mandatory: */
                if (entry_is_empty(priv->entry_user_username))
                        enable_next = FALSE;
@@ -1681,39 +1818,17 @@ on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
                /* The user details email address is mandatory: */
                if (enable_next && entry_is_empty (priv->entry_user_email))
                        enable_next = FALSE;
-       }
-       else if (current_page == priv->page_custom_incoming) {
+       } else if (current_page == priv->page_custom_incoming) {
                /* The custom incoming server is mandatory: */
                if (entry_is_empty(priv->entry_incomingserver))
                        enable_next = FALSE;
+       } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
+               enable_next = !modest_easysetup_wizard_page_validate (
+                      MODEST_EASYSETUP_WIZARD_PAGE (current_page));
        }
                        
-       /* Enable the buttons, 
-        * identifying them via their associated response codes: */
-                                  
-       /* Disable the Finish button until we are on the last page,
-        * because HildonWizardDialog enables this for all but the first page: */
-       GtkNotebook *notebook = NULL;
-       GtkDialog *dialog_base = GTK_DIALOG (dialog);
-       g_object_get (dialog_base, "wizard-notebook", &notebook, NULL);
-       
-       gint current = gtk_notebook_get_current_page (notebook);
-       gint last = gtk_notebook_get_n_pages (notebook) - 1;
-       const gboolean is_last = (current == last);
-    
-       if(!is_last) {
-               gtk_dialog_set_response_sensitive (dialog_base,
-                                                  MODEST_WIZARD_DIALOG_FINISH,
-                                                  FALSE);
-       } else
-       {
-               /* Disable Next on the last page: */
-               enable_next = FALSE;
-       }
-       
-       gtk_dialog_set_response_sensitive (dialog_base,
-                                          MODEST_WIZARD_DIALOG_NEXT,
-                                          enable_next);
+       /* Enable/disable buttons */ 
+       real_enable_buttons (dialog, enable_next);
 }
 
 static void
@@ -1723,8 +1838,6 @@ modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *kla
        g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
 
 
-       object_class->get_property = modest_easysetup_wizard_dialog_get_property;
-       object_class->set_property = modest_easysetup_wizard_dialog_set_property;
        object_class->dispose = modest_easysetup_wizard_dialog_dispose;
        object_class->finalize = modest_easysetup_wizard_dialog_finalize;
        
@@ -1735,14 +1848,6 @@ modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *kla
        base_klass->before_next = on_before_next;
        base_klass->enable_buttons = on_enable_buttons;
 }
-static void
-show_error (GtkWidget *parent_widget, const gchar* text)
-{
-       //TODO: Apparently this doesn't show anything in Maemo Bora:
-       hildon_banner_show_information(parent_widget, NULL, text);      
-}
-
 
 /**
  * save_to_settings:
@@ -1760,31 +1865,75 @@ save_to_settings (ModestEasysetupWizardDialog *self)
        const gchar *username, *password;
        gchar *store_hostname, *transport_hostname;
        guint store_port, transport_port;
-       ModestTransportStoreProtocol store_protocol, transport_protocol;
-       ModestConnectionProtocol store_security, transport_security;
-       ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
+       ModestProtocolRegistry *protocol_registry;
+       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;
+       EasysetupProviderComboBox *combo;
+       EasysetupProviderComboBoxIdType id_type;
+
+       priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
+       combo = EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider);
+       protocol_registry = modest_runtime_get_protocol_registry ();
 
        /* Get details from the specified presets: */
-       provider_id = easysetup_provider_combo_box_get_active_provider_id (
-               EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
+       id_type = easysetup_provider_combo_box_get_active_id_type (combo);
+       provider_id = easysetup_provider_combo_box_get_active_provider_id (combo);
                
+       /* Let the plugin save the settings. We do a return in order
+          to save an indentation level */
+       if (id_type == EASYSETUP_PROVIDER_COMBO_BOX_ID_PLUGIN_PROTOCOL) {
+               ModestProtocol *protocol;
+
+               protocol = modest_protocol_registry_get_protocol_by_name (
+                      modest_runtime_get_protocol_registry (),
+                      MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
+                      provider_id);
+
+               if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
+                       gint n_pages, i = 0;
+                       GtkNotebook *notebook;
+                       GList *wizard_pages = NULL;
+
+                       g_object_get (self, "wizard-notebook", &notebook, NULL);
+                       n_pages = gtk_notebook_get_n_pages (notebook);
+                       for (i = 0; i < n_pages; i++) {
+                               GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
+                               if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
+                                       wizard_pages  = g_list_append (wizard_pages, page);
+                       }
+                       modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
+                                                                     wizard_pages,
+                                                                     priv->settings);
+                       g_list_free (wizard_pages);
+               } else {
+                       g_warning ("The selected protocol is a plugin protocol "//
+                                  "but it's not a ModestAccountProtocol");
+               }
+
+               return;
+       }
+
        /* username and password (for both incoming and outgoing): */
        username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
        password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
 
+       store_settings = modest_account_settings_get_store_settings (priv->settings);
+       transport_settings = modest_account_settings_get_transport_settings (priv->settings);
+
        /* Incoming server: */
-       /* Note: We need something as default for the ModestTransportStoreProtocol* values, 
+       /* Note: We need something as default for the transport store protocol values, 
         * or modest_account_mgr_add_server_account will fail. */
        store_port = 0;
-       store_protocol = MODEST_PROTOCOL_STORE_POP;
-       store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
-       store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
+       store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+       store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
+       store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
 
        if (provider_id) {
-               ModestPresetsServerType store_provider_server_type;
-               ModestPresetsSecurity store_provider_security;
+               ModestProtocolType store_provider_server_type;
+               gboolean store_provider_use_alternate_port;
                /* Use presets: */
                store_hostname = modest_presets_get_server (priv->presets, provider_id, 
                                                            TRUE /* store */);
@@ -1792,76 +1941,67 @@ save_to_settings (ModestEasysetupWizardDialog *self)
                store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
                                                                         provider_id, 
                                                                         TRUE /* store */);
-               store_provider_security  = modest_presets_get_info_server_security (priv->presets,
+               store_security  = modest_presets_get_info_server_security (priv->presets,
                                                                                    provider_id, 
                                                                                    TRUE /* store */);
+               store_auth_protocol  = modest_presets_get_info_server_auth (priv->presets,
+                                                                                    provider_id, 
+                                                                                    TRUE /* store */);
+               store_provider_use_alternate_port  = modest_presets_get_info_server_use_alternate_port (priv->presets,
+                                                                                                       provider_id, 
+                                                                                                       TRUE /* store */);
 
                /* We don't check for SMTP here as that is impossible for an incoming server. */
-               if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
-                       store_protocol = MODEST_PROTOCOL_STORE_IMAP;
-               else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
-                       store_protocol = MODEST_PROTOCOL_STORE_POP;
-               else /* fallback */
-                       store_protocol = MODEST_PROTOCOL_STORE_POP;
+               if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
+                       store_protocol = MODEST_PROTOCOLS_STORE_POP;
+               else
+                       store_protocol = store_provider_server_type;
 
                /* we check if there is a *special* port */
                special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
                if (special_port != 0)
                        store_port = special_port;
                else 
-                       store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
-               
-               if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
-                       store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
-               
-               if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
-                       store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
+                       store_port = get_port_from_protocol(store_provider_server_type, store_security);
+
+               modest_server_account_settings_set_security_protocol (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);
        } else {
                /* Use custom pages because no preset was specified: */
                store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));               
                store_protocol = easysetup_servertype_combo_box_get_active_servertype (
                        EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));              
-               store_security = modest_serversecurity_combo_box_get_active_serversecurity (
-                       MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
-               
-               /* 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->checkbox_incoming_auth)) &&
-                   !modest_protocol_info_is_secure(store_security)) {
-                       store_auth_protocol = check_first_supported_auth_method (self);
-               } else {
-                       store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
-               }
+
+               modest_security_options_view_save_settings (
+                                   MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
+                                   priv->settings);
        }
 
-       /* now we store the store account settings */
-       store_settings = modest_account_settings_get_store_settings (priv->settings);
+       /* now we store the common store account 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_PROTOCOL_STORE_POP;
-       transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
-       transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
+       transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+       transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
+       transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
        transport_port = 0;
        
        if (provider_id) {
-               ModestPresetsServerType transport_provider_server_type;
-               ModestPresetsSecurity transport_provider_security;
+               ModestProtocolType transport_provider_server_type;
+               ModestProtocolType transport_provider_security;
 
-               /* Use presets: */
+               /* Use presets */
                transport_hostname = modest_presets_get_server (priv->presets, provider_id, 
                                                                FALSE /* transport */);
                        
@@ -1873,14 +2013,10 @@ save_to_settings (ModestEasysetupWizardDialog *self)
                                                                                       FALSE /* transport */);
 
                /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
-               transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL; 
-               if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
-                       transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
-
-               transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
-               if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
+               transport_protocol = transport_provider_server_type;
+               transport_security = transport_provider_security;
+               if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
                        /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
-                       transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
                        /* we check if there is a *special* port */
                        special_port = modest_presets_get_port (priv->presets, provider_id,
                                                                FALSE /* transport */);
@@ -1888,31 +2024,48 @@ save_to_settings (ModestEasysetupWizardDialog *self)
                                transport_port = special_port;
                        else 
                                transport_port = 465;
-                       transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
+                       transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
                } else {
                        /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
-                       transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
+                       transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
                }
+
+               modest_server_account_settings_set_security_protocol (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);
        } else {
+               ModestProtocolRegistry *registry;
+               ModestProtocol *store_proto;
+
+               registry = modest_runtime_get_protocol_registry ();
                /* Use custom pages because no preset was specified: */
                transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
-               transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
-               transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
-                       MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));               
-               transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
-                       MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
+
+               store_proto = modest_protocol_registry_get_protocol_by_type (registry, 
+                                                                            store_protocol);
+
+               if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
+                       /* fallback to SMTP if none was specified */
+                       g_warning ("No transport protocol was specified for store %d (%s)",
+                                  modest_protocol_get_type_id (store_proto),
+                                  modest_protocol_get_display_name (store_proto));
+                       transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
+               }
+
+               modest_security_options_view_save_settings (
+                                   MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
+                                   priv->settings);
        }
-           
-       /* now we transport the transport account settings */
-       transport_settings = modest_account_settings_get_transport_settings (priv->settings);
+
+       /* now we store the common transport account 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);
@@ -1921,8 +2074,8 @@ save_to_settings (ModestEasysetupWizardDialog *self)
        email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_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 */
+       /* we don't set retrieve type to preserve advanced settings if
+          any. By default account settings are set to headers only */
        
        /* Save the connection-specific SMTP server accounts. */
         modest_account_settings_set_use_connection_specific_smtp 
index 7dc7c64..ef23742 100644 (file)
@@ -28,6 +28,8 @@
  */
 
 #include <string.h> /* for strcmp */
+#include <modest-protocol-registry.h>
+#include <modest-runtime.h>
 #include "modest-presets.h"
 #include <stdio.h>
 
@@ -193,75 +195,138 @@ modest_presets_get_domain      (ModestPresets *self,
 
 
 
-ModestPresetsServerType
+ModestProtocolType
 modest_presets_get_info_server_type (ModestPresets *self,
                                     const gchar *provider_id,
                                     gboolean incoming_server)
 {
-       ModestPresetsServerType info = MODEST_PRESETS_SERVER_TYPE_NONE;
+       ModestProtocolType protocol_type = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+       ModestProtocolRegistry *protocol_registry;
+       ModestProtocol *protocol;
        gchar *val = NULL;
        
        g_return_val_if_fail (self && self->keyfile, 0);
+       protocol_registry = modest_runtime_get_protocol_registry ();
 
        if (incoming_server) {
                val = g_key_file_get_string (self->keyfile, provider_id,
                                             MODEST_PRESETS_KEY_INCOMING, NULL);
                if (!val)
-                       return info;
+                       return protocol_type;
                
                g_free (val);
                val = g_key_file_get_string (self->keyfile, provider_id,
                                             MODEST_PRESETS_KEY_MAILBOX_TYPE,NULL);
-               if (val && strcmp (val, "pop") == 0)
-                       info = MODEST_PRESETS_SERVER_TYPE_POP;
-               if (val && strcmp (val, "imap") == 0)
-                       info = MODEST_PRESETS_SERVER_TYPE_IMAP;
+               
+               protocol = modest_protocol_registry_get_protocol_by_name (protocol_registry, MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS, val);
+               if (protocol == NULL)
+                       return protocol_type;
+               protocol_type = modest_protocol_get_type_id (protocol);
        } else {
                val = g_key_file_get_string (self->keyfile, provider_id,
                                             MODEST_PRESETS_KEY_OUTGOING, NULL);
                if (!val)
-                       return info;
-               info = MODEST_PRESETS_SERVER_TYPE_SMTP;
+                       return protocol_type;
+
+               protocol_type = MODEST_PROTOCOLS_TRANSPORT_SMTP;
        }
        g_free (val);
 
        /* debug: */
 /*     g_message ("provider id: %s, server type: %d", provider_id, info); */
-       return info;
+       return protocol_type;
 }
 
 
 
-ModestPresetsSecurity
+ModestProtocolType
 modest_presets_get_info_server_security (ModestPresets *self, const gchar *provider_id,
                                         gboolean incoming_server)
 {
-       ModestPresetsSecurity info = MODEST_PRESETS_SECURITY_NONE;
+       ModestProtocolType protocol_type = MODEST_PROTOCOLS_CONNECTION_NONE;
        gchar *val = NULL;
        
-       g_return_val_if_fail (self && self->keyfile, MODEST_PRESETS_SECURITY_NONE);
+       g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
 
        if (incoming_server) {
                val = g_key_file_get_string (self->keyfile, provider_id,
                                             MODEST_PRESETS_KEY_INCOMING, NULL);
                if (val) {
                        g_free (val);   
+
                        val = g_key_file_get_string (self->keyfile, provider_id,
-                                                    MODEST_PRESETS_KEY_APOP, NULL);
-                       if (val && strcmp(val, "true") == 0)
-                               info |= MODEST_PRESETS_SECURITY_APOP;
-                       g_free(val);
+                                                    MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
+                       if (val && ((strcmp (val, "1") == 0) || (strcmp (val, "2") == 0))) {
+                               protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
+                       }
+                       g_free (val);
+               }
+       } else /* outgoing: */ {
+               val = g_key_file_get_string (self->keyfile, provider_id,
+                                            MODEST_PRESETS_KEY_OUTGOING, NULL);
+               if (val) {
+                       g_free (val);
                        
                        val = g_key_file_get_string (self->keyfile, provider_id,
+                                                    MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
+                       /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
+                       if (val && strcmp(val,"true") == 0)
+                               protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
+                       g_free(val);
+               }
+       }
+
+       return protocol_type;
+}
+
+gboolean 
+modest_presets_get_info_server_use_alternate_port (ModestPresets *self, const gchar *provider_id,
+                                                  gboolean incoming_server)
+{
+       gboolean result = FALSE;
+       gchar *val = NULL;
+       
+       g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
+
+       if (incoming_server) {
+               val = g_key_file_get_string (self->keyfile, provider_id,
+                                            MODEST_PRESETS_KEY_INCOMING, NULL);
+               if (val) {
+                       g_free (val);   
+
+                       val = g_key_file_get_string (self->keyfile, provider_id,
                                                     MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
-                       if (val && strcmp (val, "1") == 0) 
-                               info |= MODEST_PRESETS_SECURITY_SECURE_INCOMING;
-                       if (val && strcmp (val, "2") == 0) {
-                               info |= MODEST_PRESETS_SECURITY_SECURE_INCOMING;
-                               info |= MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT;
+                       if (val && (strcmp (val, "2") == 0)) {
+                               result = TRUE;
                        }
                        g_free (val);
                }
+       } 
+
+       return result;
+}
+
+ModestProtocolType
+modest_presets_get_info_server_auth (ModestPresets *self, const gchar *provider_id,
+                                        gboolean incoming_server)
+{
+       ModestProtocolType protocol_type = MODEST_PROTOCOLS_AUTH_NONE;
+       gchar *val = NULL;
+       
+       g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_AUTH_NONE);
+
+       if (incoming_server) {
+               val = g_key_file_get_string (self->keyfile, provider_id,
+                                            MODEST_PRESETS_KEY_INCOMING, NULL);
+               if (val) {
+                        g_free (val);   
+                        val = g_key_file_get_string (self->keyfile, provider_id,
+                                                     MODEST_PRESETS_KEY_APOP, NULL);
+                        if (val && strcmp(val, "true") == 0)
+                               protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
+                        g_free(val);
+
+               }
        } else /* outgoing: */ {
                val = g_key_file_get_string (self->keyfile, provider_id,
                                             MODEST_PRESETS_KEY_OUTGOING, NULL);
@@ -272,15 +337,14 @@ modest_presets_get_info_server_security (ModestPresets *self, const gchar *provi
                                                     MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
                        /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
                        if (val && strcmp(val,"true") == 0)
-                               info |= MODEST_PRESETS_SECURITY_SECURE_SMTP;
+                               protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
                        g_free(val);
                }
        }
 
-       return info;
+       return protocol_type;
 }
 
-
 /*
  * at the moment, this only for mac.com, which have a special SMTP port
  */
index d71b67d..96e90d1 100644 (file)
@@ -31,6 +31,7 @@
 #define __MODEST_PRESETS_H__
 
 #include <glib.h>
+#include <modest-protocol.h>
 
 struct _ModestPresets {
 /* private data: don't touch */
@@ -38,26 +39,6 @@ struct _ModestPresets {
 };
 typedef struct _ModestPresets ModestPresets;
 
-typedef enum _ModestPresetsServerType {
-       MODEST_PRESETS_SERVER_TYPE_NONE,                      
-       MODEST_PRESETS_SERVER_TYPE_IMAP,
-       MODEST_PRESETS_SERVER_TYPE_POP,
-       MODEST_PRESETS_SERVER_TYPE_SMTP
-} ModestPresetsServerType;
-
-/** These are flags, which should be ORed.
- */
-typedef enum _ModestPresetsSecurity {
-       MODEST_PRESETS_SECURITY_NONE                           = 0,                           
-       MODEST_PRESETS_SECURITY_APOP                           = 1 << 0,
-       MODEST_PRESETS_SECURITY_SECURE_SMTP                    = 1 << 1, /* if set, port will be 465
-                                                                         * instead of 25 */
-       MODEST_PRESETS_SECURITY_SECURE_INCOMING                = 1 << 2,
-       MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT = 1 << 3, /* POP3S=>995, IMAPS=>993 */
-} ModestPresetsSecurity;
-
-/* typedef enum _ModestPresetsInfo ModestPresetsInfo; */
-
 
 /**
  * modest_presets_new:
@@ -126,11 +107,41 @@ gchar *                   modest_presets_get_domain      (ModestPresets *self,
  *
  * get information about some incoming or outgoing mailserver
  *
- * Returns: a ModestPresetsServerType with the required information
+ * Returns: a #ModestProtocolType with the required information
  */
-ModestPresetsServerType          modest_presets_get_info_server_type (ModestPresets *self,
-                                                                     const gchar *provider_id,
-                                                                     gboolean incoming_server);
+ModestProtocolType          modest_presets_get_info_server_type (ModestPresets *self,
+                                                                const gchar *provider_id,
+                                                                gboolean incoming_server);
+
+/**
+ * modest_presets_get_info_server_security:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider 
+ * @incoming_server: get the incoming mailserver if TRUE, get the
+ * outgoing server otherwise
+ *
+ * get information about some incoming or outgoing mailserver
+ *
+ * Returns: #ModestProtocolType with server auth
+ */                                        
+ModestProtocolType          modest_presets_get_info_server_auth (ModestPresets *self,
+                                                                const gchar *provider_id,
+                                                                gboolean incoming_server);
+
+/**
+ * modest_presets_get_info_server_security:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider 
+ * @incoming_server: get the incoming mailserver if TRUE, get the
+ * outgoing server otherwise
+ *
+ * get information about some incoming or outgoing mailserver
+ *
+ * Returns: #ModestProtocolType with server security
+ */                                        
+ModestProtocolType          modest_presets_get_info_server_security (ModestPresets *self,
+                                                                    const gchar *provider_id,
+                                                                    gboolean incoming_server);
 
 /**
  * modest_presets_get_info_server_security:
@@ -141,11 +152,11 @@ ModestPresetsServerType          modest_presets_get_info_server_type (ModestPres
  *
  * get information about some incoming or outgoing mailserver
  *
- * Returns: ModestPresetsSecurity ORable flags with the required information
+ * Returns: %TRUE if we should use the alternate port.
  */                                        
-ModestPresetsSecurity          modest_presets_get_info_server_security (ModestPresets *self,
-                                                                       const gchar *provider_id,
-                                                                       gboolean incoming_server);
+gboolean          modest_presets_get_info_server_use_alternate_port (ModestPresets *self,
+                                                                    const gchar *provider_id,
+                                                                    gboolean incoming_server);
 
 
 /**
diff --git a/src/maemo/modest-account-settings-dialog.c b/src/maemo/modest-account-settings-dialog.c
deleted file mode 100644 (file)
index 0fdc76b..0000000
+++ /dev/null
@@ -1,1669 +0,0 @@
-/* Copyright (c) 2006, Nokia Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * * Neither the name of the Nokia Corporation nor the names of its
- *   contributors may be used to endorse or promote products derived from
- *   this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "modest-account-settings-dialog.h"
-#include <glib/gi18n.h>
-#include <gtk/gtknotebook.h>
-#include <gtk/gtkvbox.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkcombobox.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkbutton.h>
-#include <gtk/gtkcheckbutton.h>
-#include <gtk/gtkmessagedialog.h>
-#include <gtk/gtkstock.h>
-#include "modest-hildon-includes.h"
-
-#include "widgets/modest-serversecurity-combo-box.h"
-#include "widgets/modest-secureauth-combo-box.h"
-#include "widgets/modest-validating-entry.h"
-#include "widgets/modest-retrieve-combo-box.h"
-#include "widgets/modest-limit-retrieve-combo-box.h"
-#include "modest-text-utils.h"
-#include "modest-account-mgr.h"
-#include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
-#include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
-#include "modest-protocol-info.h"
-#include "maemo/modest-connection-specific-smtp-window.h"
-#include "maemo/modest-signature-editor-dialog.h"
-#include <modest-utils.h>
-#include "maemo/modest-maemo-utils.h"
-#include "widgets/modest-ui-constants.h"
-#include <tny-account.h>
-#include <tny-status.h>
-
-#include <gconf/gconf-client.h>
-#include <string.h> /* For strlen(). */
-
-/* Include config.h so that _() works: */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#define PORT_MIN 1
-#define PORT_MAX 65535
-
-G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
-
-#define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
-       (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
-
-typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
-
-struct _ModestAccountSettingsDialogPrivate
-{
-};
-
-static void
-enable_buttons (ModestAccountSettingsDialog *self);
-
-static gboolean
-save_configuration (ModestAccountSettingsDialog *dialog);
-
-static const gchar * null_means_empty (const gchar * str);
-
-static const gchar *
-null_means_empty (const gchar * str)
-{
-       return str ? str : "";
-}
-
-
-static void
-modest_account_settings_dialog_get_property (GObject *object, guint property_id,
-                                                                                                                       GValue *value, GParamSpec *pspec)
-{
-       switch (property_id) {
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-       }
-}
-
-static void
-modest_account_settings_dialog_set_property (GObject *object, guint property_id,
-                                                                                                                       const GValue *value, GParamSpec *pspec)
-{
-       switch (property_id) {
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-       }
-}
-
-static void
-modest_account_settings_dialog_dispose (GObject *object)
-{
-       if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
-               G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
-}
-
-static void
-modest_account_settings_dialog_finalize (GObject *object)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
-       
-       if (self->account_name)
-               g_free (self->account_name);
-               
-       if (self->original_account_title)
-               g_free (self->original_account_title);
-               
-       if (self->account_manager)
-               g_object_unref (G_OBJECT (self->account_manager));
-               
-       if (self->signature_dialog)
-               gtk_widget_destroy (self->signature_dialog);
-
-       if (self->settings) {
-               g_object_unref (self->settings);
-               self->settings = NULL;
-       }
-       
-       G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
-}
-
-static void
-on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
-
-static void
-on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
-
-static void
-on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       self->modified = TRUE;
-}
-
-static void
-on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       self->modified = TRUE;
-}
-
-static void
-on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       self->modified = TRUE;
-}
-
-static void
-on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       self->modified = TRUE;
-}
-
-static void       
-on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
-{
-       ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       gint value = hildon_number_editor_get_value (editor);
-
-       gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
-}
-
-/* Set a modified boolean whenever the widget is changed, 
- * so we can check for it later.
- */
-static void
-connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
-{
-       if (HILDON_IS_NUMBER_EDITOR (widget)) {
-               g_signal_connect (G_OBJECT (widget), "notify::value",
-                       G_CALLBACK (on_modified_number_editor_changed), self);
-               g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
-       }
-       else if (GTK_IS_ENTRY (widget)) {
-               g_signal_connect (G_OBJECT (widget), "changed",
-                       G_CALLBACK (on_modified_entry_changed), self);
-       } else if (GTK_IS_COMBO_BOX (widget)) {
-               g_signal_connect (G_OBJECT (widget), "changed",
-                       G_CALLBACK (on_modified_combobox_changed), self);       
-       } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
-               g_signal_connect (G_OBJECT (widget), "toggled",
-                       G_CALLBACK (on_modified_checkbox_toggled), self);
-       }
-}
-
-static void
-on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       g_assert(self);
-       enable_buttons(self);
-}
-
-static void
-on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       g_assert(self);
-       enable_buttons(self);
-}
-
-/** This is a convenience function to create a caption containing a mandatory widget.
- * When the widget is edited, the enable_buttons() vfunc will be called.
- */
-static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
-       GtkSizeGroup *group,
-       const gchar *value,
-       GtkWidget *control,
-       GtkWidget *icon,
-       HildonCaptionStatus flag)
-{
-       GtkWidget *caption = NULL;
-  
-       /* Note: Previously, the translated strings already contained the "*",
-        * Comment out this code if they do again.
-        */
-       /* Add a * character to indicate mandatory fields,
-        * as specified in our "Email UI Specification": */
-       if (flag == HILDON_CAPTION_MANDATORY) {
-               gchar* title = g_strdup_printf("%s*", value);
-               caption = hildon_caption_new (group, title, control, icon, flag);       
-               g_free(title);
-       }       
-       else
-               caption = hildon_caption_new (group, value, control, icon, flag);
-
-       /* Connect to the appropriate changed signal for the widget, 
-        * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
-        */
-       if (GTK_IS_ENTRY (control)) {
-               g_signal_connect (G_OBJECT (control), "changed",
-               G_CALLBACK (on_caption_entry_changed), self);
-               
-       }
-       else if (GTK_IS_COMBO_BOX (control)) {
-               g_signal_connect (G_OBJECT (control), "changed",
-               G_CALLBACK (on_caption_combobox_changed), self);
-       }
-        
-       return caption;
-}
-
-static void
-on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
-{
-       gchar *tmp, *msg;
-                       
-       tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
-       msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
-
-       hildon_banner_show_information(GTK_WIDGET (self), NULL, msg);
-
-       g_free (msg);
-       g_free (tmp);
-}
-
-static void
-on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
-{
-       gchar *tmp, *msg;
-                       
-       tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
-       msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
-
-       hildon_banner_show_information(GTK_WIDGET (self), NULL, msg);
-
-       g_free (msg);
-       g_free (tmp);
-}
-
-
-static void
-on_entry_max (ModestValidatingEntry *self, gpointer user_data)
-{
-       hildon_banner_show_information(GTK_WIDGET (self), NULL, 
-                                      _CS("ckdg_ib_maximum_characters_reached"));
-}
-
-static GtkWidget*
-create_page_account_details (ModestAccountSettingsDialog *self)
-{
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       GtkAdjustment *focus_adjustment = NULL;
-       
-       /* Create a size group to be used by all captions.
-        * Note that HildonCaption does not create a default size group if we do not specify one.
-        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
-       GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-       GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
-                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-           
-       /* The description widgets: */  
-       self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
-       /* Do use auto-capitalization: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title), 
-               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
-       GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"), 
-               self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
-       gtk_widget_show (self->entry_account_title);
-       connect_for_modified (self, self->entry_account_title);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* Prevent the use of some characters in the account title, 
-        * as required by our UI specification: */
-       GList *list_prevent = NULL;
-       list_prevent = g_list_append (list_prevent, "\\");
-       list_prevent = g_list_append (list_prevent, "/");
-       list_prevent = g_list_append (list_prevent, ":");
-       list_prevent = g_list_append (list_prevent, "*");
-       list_prevent = g_list_append (list_prevent, "?");
-       list_prevent = g_list_append (list_prevent, "\"");
-       list_prevent = g_list_append (list_prevent, "<"); 
-       list_prevent = g_list_append (list_prevent, ">"); 
-       list_prevent = g_list_append (list_prevent, "|");
-       list_prevent = g_list_append (list_prevent, "^");       
-       modest_validating_entry_set_unallowed_characters (
-               MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
-       g_list_free (list_prevent);
-       modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
-                                        on_entry_invalid_account_title_character, self);
-       
-       /* Set max length as in the UI spec:
-        * The UI spec seems to want us to show a dialog if we hit the maximum. */
-       gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
-       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title), 
-               on_entry_max, self);
-       
-       /* The retrieve combobox: */
-       self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
-       caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"), 
-               self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
-       gtk_widget_show (self->combo_retrieve);
-       connect_for_modified (self, self->combo_retrieve);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* The limit-retrieve combobox: */
-       self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
-       caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"), 
-               self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
-       gtk_widget_show (self->combo_limit_retrieve);
-       connect_for_modified (self, self->combo_limit_retrieve);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-
-       /* The leave-messages widgets: */
-       if(!self->checkbox_leave_messages)
-               self->checkbox_leave_messages = gtk_check_button_new ();
-       if (!self->caption_leave_messages) {
-               self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"), 
-                       self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
-       }
-                       
-       gtk_widget_show (self->checkbox_leave_messages);
-       connect_for_modified (self, self->checkbox_leave_messages);
-       gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (self->caption_leave_messages);
-
-       g_object_unref (sizegroup);
-       
-       gtk_widget_show (GTK_WIDGET (box));
-       
-       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
-       gtk_widget_show (scrollwin);
-
-       focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
-       gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment); 
-       
-       return GTK_WIDGET (scrollwin);
-}
-
-static gchar*
-get_entered_account_title (ModestAccountSettingsDialog *dialog)
-{
-       const gchar* account_title = 
-               gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
-       if (!account_title || (strlen (account_title) == 0))
-               return NULL;
-       else {
-               /* Strip it of whitespace at the start and end: */
-               gchar *result = g_strdup (account_title);
-               result = g_strstrip (result);
-               
-               if (!result)
-                       return NULL;
-                       
-               if (strlen (result) == 0) {
-                       g_free (result);
-                       return NULL;    
-               }
-               
-               return result;
-       }
-}
-
-
-static void
-on_button_signature (GtkButton *button, gpointer user_data)
-{
-       ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       gint response;
-
-       /* Create the window, if necessary: */
-       if (!(self->signature_dialog)) {
-               self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
-       
-               gboolean use_signature = modest_account_settings_get_use_signature (self->settings);
-               const gchar *signature = modest_account_settings_get_signature(self->settings);
-               gchar* account_title = get_entered_account_title (self);
-               modest_signature_editor_dialog_set_settings (
-                       MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog), 
-                       use_signature, signature, account_title);
-
-               g_free (account_title);
-               account_title = NULL;
-               signature = NULL;
-       }
-
-       /* Show the window: */  
-       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
-                                    GTK_WINDOW (self->signature_dialog));
-
-       response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
-       gtk_widget_hide (self->signature_dialog);
-       if (response != GTK_RESPONSE_OK) {
-               /* Destroy the widget now, and its data: */
-               gtk_widget_destroy (self->signature_dialog);
-               self->signature_dialog = NULL;
-       } else {
-               /* Mark modified, so we use the dialog's data later: */
-               self->modified = TRUE;  
-       }
-}
-
-static GtkWidget*
-create_page_user_details (ModestAccountSettingsDialog *self)
-{
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       GtkAdjustment *focus_adjustment = NULL;
-       
-       /* Create a size group to be used by all captions.
-        * Note that HildonCaption does not create a default size group if we do not specify one.
-        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
-       GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-       GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
-                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-        
-       /* The name widgets: */
-       self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
-
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
-       /* Set max length as in the UI spec:
-        * The UI spec seems to want us to show a dialog if we hit the maximum. */
-       gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
-       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name), 
-               on_entry_max, self);
-       GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
-               _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->entry_user_name);
-       connect_for_modified (self, self->entry_user_name);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-
-
-       /* Prevent the use of some characters in the name, 
-        * as required by our UI specification: */
-       GList *list_prevent = NULL;
-       list_prevent = g_list_append (list_prevent, "<");
-       list_prevent = g_list_append (list_prevent, ">");
-       modest_validating_entry_set_unallowed_characters (
-               MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
-       g_list_free (list_prevent);
-       modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
-                                        on_entry_invalid_fullname_character, self);
-       
-       /* The username widgets: */     
-       self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
-       caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"), 
-               self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
-       gtk_widget_show (self->entry_user_username);
-       connect_for_modified (self, self->entry_user_username);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* Prevent the use of some characters in the username, 
-        * as required by our UI specification: */
-       modest_validating_entry_set_unallowed_characters_whitespace (
-               MODEST_VALIDATING_ENTRY (self->entry_user_username));
-       modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (self->entry_user_username), 
-                                         modest_maemo_utils_on_entry_invalid_character, 
-                                         self);
-       
-       /* Set max length as in the UI spec:
-        * The UI spec seems to want us to show a dialog if we hit the maximum. */
-       gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
-       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username), 
-               on_entry_max, self);
-       
-       /* The password widgets: */     
-       self->entry_user_password = gtk_entry_new ();
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), 
-               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
-       gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
-       /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
-       caption = create_caption_new_with_asterisk (self, sizegroup, 
-               _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->entry_user_password);
-       connect_for_modified (self, self->entry_user_password);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* The email address widgets: */        
-       self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
-       caption = create_caption_new_with_asterisk (self, sizegroup, 
-               _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
-       gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
-       gtk_widget_show (self->entry_user_email);
-       connect_for_modified (self, self->entry_user_email);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* Set max length as in the UI spec:
-        * The UI spec seems to want us to show a dialog if we hit the maximum. */
-       gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
-       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email), 
-               on_entry_max, self);
-       
-       /* Signature button: */
-       if (!self->button_signature)
-               self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
-       caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"), 
-               self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
-       hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
-       gtk_widget_show (self->button_signature);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-
-       g_object_unref (sizegroup);
-               
-       g_signal_connect (G_OBJECT (self->button_signature), "clicked",
-               G_CALLBACK (on_button_signature), self);
-               
-       gtk_widget_show (GTK_WIDGET (box));
-       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
-       gtk_widget_show (scrollwin);
-
-       focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
-       gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment); 
-       
-       return GTK_WIDGET (scrollwin);
-}
-
-/** Change the caption title for the incoming server, 
- * as specified in the UI spec:
- */
-static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
-{
-       const gchar* type = 
-               (protocol == MODEST_PROTOCOL_STORE_POP ? 
-                       _("mail_fi_emailtype_pop3") : 
-                       _("mail_fi_emailtype_imap") );
-                       
-               
-       /* Note that this produces a compiler warning, 
-        * because the compiler does not know that the translated string will have a %s in it.
-        * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
-       gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
-       
-       /* This is a mandatory field, so add a *. This is usually done by 
-        * create_caption_new_with_asterisk() but we can't use that here. */
-       gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
-       g_free (incomingserver_title);
-       
-       g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
-       g_free(with_asterisk);
-}
-
-/** Change the caption title for the incoming server, 
- * as specified in the UI spec:
- */
-static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
-{
-       /* Fill the combo with appropriately titled choices for POP or IMAP. */
-       /* The choices are the same, but the titles are different, as in the UI spec. */
-       modest_serversecurity_combo_box_fill (
-               MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
-}
-           
-static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
-{
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       
-       /* Create a size group to be used by all captions.
-        * Note that HildonCaption does not create a default size group if we do not specify one.
-        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
-       GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-        
-       /* The incoming server widgets: */
-       if(!self->entry_incomingserver)
-               self->entry_incomingserver = gtk_entry_new ();
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
-
-       if (self->caption_incoming)
-         gtk_widget_destroy (self->caption_incoming);
-          
-       /* The caption title will be updated in update_incoming_server_title().
-        * so this default text will never be seen: */
-       /* (Note: Changing the title seems pointless. murrayc) */
-       self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup, 
-               "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
-       gtk_widget_show (self->entry_incomingserver);
-       connect_for_modified (self, self->entry_incomingserver);
-       gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (self->caption_incoming);
-       
-       /* The secure connection widgets: */
-       /* This will be filled by update_incoming_server_security_choices(). */
-       if (!self->combo_incoming_security)
-               self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
-       GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
-               self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->combo_incoming_security);
-       connect_for_modified (self, self->combo_incoming_security);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* Show a default port number when the security method changes, as per the UI spec: */
-       g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
-       
-       
-       /* The port widgets: */
-       if (!self->entry_incoming_port)
-               self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
-       caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"), 
-               self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->entry_incoming_port);
-       connect_for_modified (self, self->entry_incoming_port);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* The secure authentication widgets: */
-       if(!self->checkbox_incoming_auth)
-               self->checkbox_incoming_auth = gtk_check_button_new ();
-       caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
-               self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->checkbox_incoming_auth);
-       connect_for_modified (self, self->checkbox_incoming_auth);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-
-       g_object_unref (sizegroup);
-       gtk_widget_show (caption);
-       
-       gtk_widget_show (GTK_WIDGET (box));
-       
-       return GTK_WIDGET (box);
-}
-
-static void
-on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
-{
-       GtkWidget *widget = GTK_WIDGET (user_data);
-       
-       /* Enable the widget only if the toggle button is active: */
-       const gboolean enable = gtk_toggle_button_get_active (togglebutton);
-       gtk_widget_set_sensitive (widget, enable);
-}
-
-/* Make the sensitivity of a widget depend on a toggle button.
- */
-static void
-enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
-{
-       g_signal_connect (G_OBJECT (button), "toggled",
-               G_CALLBACK (on_toggle_button_changed), widget);
-       
-       /* Set the starting sensitivity: */
-       on_toggle_button_changed (button, widget);
-}
-
-static void
-on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
-{
-       ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       ModestConnectionSpecificSmtpWindow *smtp_win;
-
-       /* Create the window if necessary: */
-       smtp_win = modest_connection_specific_smtp_window_new ();
-       modest_connection_specific_smtp_window_fill_with_connections (smtp_win, self->account_manager);
-
-       /* Show the window: */  
-       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win));
-       gtk_widget_show (GTK_WIDGET (smtp_win));
-       self->modified = TRUE;
-}
-
-static void
-on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       
-       ModestAuthProtocol protocol_security = 
-               modest_secureauth_combo_box_get_active_secureauth (
-                       MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
-       const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
-       
-       gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
-       gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
-}
-
-static void
-on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       
-       const gint port_number = 
-               modest_serversecurity_combo_box_get_active_serversecurity_port (
-                       MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
-
-       if(port_number != 0) {
-               hildon_number_editor_set_value (
-                       HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
-       }               
-}
-
-static void
-on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
-       ModestConnectionProtocol protocol_security_incoming;
-       gint port_number;
-       
-       port_number = 
-               modest_serversecurity_combo_box_get_active_serversecurity_port (
-                       MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
-
-       if(port_number != 0) {
-               hildon_number_editor_set_value (
-                       HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
-       }               
-
-       protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
-       gtk_widget_set_sensitive (self->checkbox_incoming_auth, !modest_protocol_info_is_secure (protocol_security_incoming));
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth), modest_protocol_info_is_secure (protocol_security_incoming));
-
-}
-
-
-static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
-{
-       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       GtkAdjustment *focus_adjustment = NULL;
-       
-       /* Put it all in a scrolled window, so that all widgets can be 
-        * accessed even when the on-screen keyboard is visible: */
-       GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), 
-               GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-       
-       /* Create a size group to be used by all captions.
-        * Note that HildonCaption does not create a default size group if we do not specify one.
-        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
-       GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-        
-       /* The outgoing server widgets: */
-       if (!self->entry_outgoingserver)
-               self->entry_outgoingserver = gtk_entry_new ();
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
-       GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
-               _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->entry_outgoingserver);
-       connect_for_modified (self, self->entry_outgoingserver);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* The secure authentication widgets: */
-       if (!self->combo_outgoing_auth)
-               self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
-       caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
-               self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->combo_outgoing_auth);
-       connect_for_modified (self, self->combo_outgoing_auth);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
-       g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
-       
-       /* The username widgets: */     
-       self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
-       self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"), 
-               self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
-       gtk_widget_show (self->entry_outgoing_username);
-       connect_for_modified (self, self->entry_outgoing_username);
-       gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (self->caption_outgoing_username);
-       
-       /* Prevent the use of some characters in the username, 
-        * as required by our UI specification: */
-       modest_validating_entry_set_unallowed_characters_whitespace (
-               MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
-       
-       /* Set max length as in the UI spec:
-        * The UI spec seems to want us to show a dialog if we hit the maximum. */
-       gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
-       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username), 
-               on_entry_max, self);
-               
-       /* The password widgets: */     
-       self->entry_outgoing_password = gtk_entry_new ();
-       /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password), 
-               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
-       gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
-       /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
-       self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup, 
-               _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->entry_outgoing_password);
-       connect_for_modified (self, self->entry_outgoing_password);
-       gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (self->caption_outgoing_password);
-       
-       /* The secure connection widgets: */
-       /* This will be filled and set with modest_serversecurity_combo_box_fill() 
-        * and modest_serversecurity_combo_box_set_active_serversecurity().
-        */
-       if (!self->combo_outgoing_security)
-               
-               self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
-       caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
-               self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->combo_outgoing_security);
-       connect_for_modified (self, self->combo_outgoing_security);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* Show a default port number when the security method changes, as per the UI spec: */
-       g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
-       
-       /* The port widgets: */
-       if (!self->entry_outgoing_port)
-               self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
-       caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"), 
-               self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->entry_outgoing_port);
-       connect_for_modified (self, self->entry_outgoing_port);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       GtkWidget *separator = gtk_hseparator_new ();
-       gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (separator);
-       
-       /* connection-specific checkbox: */
-       if (!self->checkbox_outgoing_smtp_specific) {
-               self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
-               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific), 
-                       FALSE);
-       }
-       caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"), 
-               self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
-       gtk_widget_show (self->checkbox_outgoing_smtp_specific);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
-       
-       /* Connection-specific SMTP-Severs Edit button: */
-       if (!self->button_outgoing_smtp_servers)
-               self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
-       caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"), 
-               self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
-       hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
-       gtk_widget_show (self->button_outgoing_smtp_servers);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
-       /* Only enable the button when the checkbox is checked: */
-       enable_widget_for_togglebutton (self->button_outgoing_smtp_servers, 
-               GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
-
-       g_object_unref (sizegroup);
-               
-       g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
-               G_CALLBACK (on_button_outgoing_smtp_servers), self);
-               
-       gtk_widget_show (GTK_WIDGET (box));
-       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
-       gtk_widget_show(scrollwin);
-
-       focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
-       gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
-       
-       return GTK_WIDGET (scrollwin);
-}
-       
-static gboolean
-check_data (ModestAccountSettingsDialog *self)
-{
-       /* Check that the title is not already in use: */
-       gchar* account_title = get_entered_account_title (self);
-       if (!account_title)
-               return FALSE; /* Should be prevented already anyway. */
-               
-       if (strcmp(account_title, self->original_account_title) != 0) {
-               /* Check the changed title: */
-               const gboolean name_in_use  = modest_account_mgr_account_with_display_name_exists (self->account_manager,
-                       account_title);
-       
-               if (name_in_use) {
-                       /* Warn the user via a dialog: */
-                       hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
-               
-               g_free (account_title);
-                       return FALSE;
-               }
-       }
-       
-       g_free (account_title);
-       account_title  = NULL;
-
-       /* Check that the email address is valid: */
-       const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
-       if ((!email_address) || (strlen(email_address) == 0)) {
-               return FALSE;
-       }
-                       
-       if (!modest_text_utils_validate_email_address (email_address, NULL)) {
-               /* Warn the user via a dialog: */
-               hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
-                                         
-               /* Return focus to the email address entry: */
-               gtk_widget_grab_focus (self->entry_user_email);
-               gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
-               return FALSE;
-       }
-
-       /* make sure the domain name for the incoming server is valid */
-       const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
-       if ((!hostname) || (strlen(hostname) == 0)) {
-               return FALSE;
-       }
-       
-       if (!modest_text_utils_validate_domain_name (hostname)) {
-               /* Warn the user via a dialog: */
-               hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
-                                         
-               /* Return focus to the email address entry: */
-        gtk_widget_grab_focus (self->entry_incomingserver);
-               gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
-               return FALSE;
-       }
-
-       /* make sure the domain name for the outgoing server is valid */
-       const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
-       if ((!hostname2) || (strlen(hostname2) == 0)) {
-               return FALSE;
-       }
-       
-       if (!modest_text_utils_validate_domain_name (hostname2)) {
-               /* Warn the user via a dialog: */
-               hildon_banner_show_information (self->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
-
-               /* Return focus to the email address entry: */
-               gtk_widget_grab_focus (self->entry_outgoingserver);
-               gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
-               return FALSE;
-       }
-       
-       /* Find a suitable authentication method when secure authentication is desired */
-
-       const gint port_num = hildon_number_editor_get_value (
-                       HILDON_NUMBER_EDITOR (self->entry_incoming_port));
-       const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
-
-       const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
-       if (!modest_protocol_info_is_secure(protocol_security_incoming))
-       {
-               if (gtk_toggle_button_get_active (
-                               GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
-                       GError *error = NULL;
-
-                       GList *list_auth_methods = 
-                               modest_utils_get_supported_secure_authentication_methods (self->incoming_protocol, 
-                                       hostname, port_num, username, GTK_WINDOW (self), &error);
-                       if (list_auth_methods) {
-                               /* Use the first supported method.
-                                * TODO: Should we prioritize them, to prefer a particular one? */
-                               GList* method;
-                               for (method = list_auth_methods; method != NULL; method = g_list_next(method))
-                               {
-                                       ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(method->data));
-                                       // Allow secure methods, e.g MD5 only
-                                       if (modest_protocol_info_auth_is_secure(proto))
-                                       {
-                                               self->protocol_authentication_incoming = proto;
-                                               break;
-                                       }
-                               }
-                               g_list_free (list_auth_methods);
-                       }
-
-                       if (list_auth_methods == NULL || 
-                                       !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
-                       {
-                               if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
-                                               error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
-                                       hildon_banner_show_information(GTK_WIDGET (self), NULL, 
-                                                                      _("mcen_ib_unableto_discover_auth_methods"));
-
-                               if(error != NULL)
-                                       g_error_free(error);
-                                       
-                               /* This is a nasty hack. jschmid. */
-                               /* Don't let the dialog close */
-                               /*g_signal_stop_emission_by_name (dialog, "response");*/
-                               return FALSE;
-                       }
-               }
-       }
-       
-       return TRUE;
-}
-/*
- */
-static void 
-on_response (GtkDialog *wizard_dialog,
-       gint response_id,
-       gpointer user_data)
-{
-       ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
-       enable_buttons (self);
-       
-       gboolean prevent_response = FALSE;
-
-       /* Warn about unsaved changes: */
-       if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
-               GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self), 
-                       _("imum_nc_wizard_confirm_lose_changes")));
-               /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
-                
-                const gint dialog_response = gtk_dialog_run (dialog);
-                gtk_widget_destroy (GTK_WIDGET (dialog));
-                
-               if (dialog_response != GTK_RESPONSE_OK)
-                       prevent_response = TRUE;
-       }
-       /* Check for invalid input: */
-       else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
-               prevent_response = TRUE;
-       }
-               
-       if (prevent_response) {
-               /* This is a nasty hack. murrayc. */
-               /* Don't let the dialog close */
-               g_signal_stop_emission_by_name (wizard_dialog, "response");
-               return; 
-       }
-               
-       if (response_id == GTK_RESPONSE_OK) {
-               /* Try to save the changes if modified (NB #59251): */
-               if (self->modified)
-               {
-                       const gboolean saved = save_configuration (self);
-                       if (saved) {
-                               /* Do not show the account-saved dialog if we are just saving this 
-                                * temporarily, because from the user's point of view it will not 
-                                * really be saved (saved + enabled) until later
-                                */
-                               if (modest_account_settings_get_account_name (self->settings) != NULL) {
-                                       ModestServerAccountSettings *store_settings;
-                                       ModestServerAccountSettings *transport_settings;
-                                       const gchar *store_account_name;
-                                       const gchar *transport_account_name;
-
-
-                                       store_settings = modest_account_settings_get_store_settings (self->settings);
-                                       transport_settings = modest_account_settings_get_transport_settings (self->settings);
-                                       store_account_name = modest_server_account_settings_get_account_name (store_settings);
-                                       transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
-                                       
-                                       if (store_account_name) {
-                                               modest_account_mgr_notify_account_update (self->account_manager, 
-                                                                                         store_account_name);
-                                       }
-                                       if (transport_account_name) {
-                                               modest_account_mgr_notify_account_update (self->account_manager, 
-                                                                                         transport_account_name);
-                                       }
-                                       g_object_unref (store_settings);
-                                       g_object_unref (transport_settings);
-                                       
-                                       hildon_banner_show_information(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
-                               }
-                       } else {
-                               hildon_banner_show_information (NULL, NULL, _("mail_ib_setting_failed"));
-                       }
-               }
-       }
-}
-
-static void
-modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
-{
-       /* Create the notebook to be used by the GtkDialog base class:
-        * Each page of the notebook will be a page of the wizard: */
-       self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
-       self->settings = modest_account_settings_new ();
-
-       /* Get the account manager object, 
-        * so we can check for existing accounts,
-        * and create new accounts: */
-       self->account_manager = modest_runtime_get_account_mgr ();
-       g_assert (self->account_manager);
-       g_object_ref (self->account_manager);
-       
-       self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
-
-    /* Create the common pages, 
-     */
-       self->page_account_details = create_page_account_details (self);
-       self->page_user_details = create_page_user_details (self);
-       self->page_incoming = create_page_incoming (self);
-       self->page_outgoing = create_page_outgoing (self);
-       
-       /* Add the notebook pages: */
-       gtk_notebook_append_page (self->notebook, self->page_account_details, 
-               gtk_label_new (_("mcen_ti_account_settings_account")));
-       gtk_notebook_append_page (self->notebook, self->page_user_details, 
-               gtk_label_new (_("mcen_ti_account_settings_userinfo")));
-       gtk_notebook_append_page (self->notebook, self->page_incoming,
-               gtk_label_new (_("mcen_ti_advsetup_retrieval")));
-       gtk_notebook_append_page (self->notebook, self->page_outgoing,
-               gtk_label_new (_("mcen_ti_advsetup_sending")));
-               
-       GtkDialog *dialog = GTK_DIALOG (self);
-       gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
-       gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
-       gtk_widget_show (GTK_WIDGET (self->notebook));
-        
-    /* Add the buttons: */
-    gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
-    gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
-    
-    /* Connect to the dialog's response signal: */
-    /* We use connect-before 
-     * so we can stop the signal emission, 
-     * to stop the default signal handler from closing the dialog.
-     */
-    g_signal_connect (G_OBJECT (self), "response",
-            G_CALLBACK (on_response), self); 
-            
-    self->modified = FALSE;
-
-    /* When this window is shown, hibernation should not be possible, 
-        * because there is no sensible way to save the state: */
-    modest_window_mgr_prevent_hibernation_while_window_is_shown (
-       modest_runtime_get_window_mgr (), GTK_WINDOW (self)); 
-
-    hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
-                                   modest_maemo_utils_get_osso_context());
-}
-
-ModestAccountSettingsDialog*
-modest_account_settings_dialog_new (void)
-{
-       return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
-}
-
-/** Update the UI with the stored account details, so they can be edited.
- * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
- */
-void modest_account_settings_dialog_set_account (ModestAccountSettingsDialog *dialog, ModestAccountSettings *settings)
-{
-       ModestServerAccountSettings *incoming_account;
-       ModestServerAccountSettings *outgoing_account;
-       const gchar *account_name;
-
-       g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
-
-       incoming_account = modest_account_settings_get_store_settings (settings);
-       outgoing_account = modest_account_settings_get_transport_settings (settings);
-
-       account_name = modest_account_settings_get_account_name (settings);
-               
-       /* Save the account name so we can refer to it later: */
-       if (dialog->account_name)
-               g_free (dialog->account_name);
-       dialog->account_name = g_strdup (account_name);
-
-       if (dialog->settings)
-               g_object_unref (dialog->settings);
-       dialog->settings = g_object_ref (settings);
-       
-       /* Save the account title so we can refer to it if the user changes it: */
-       if (dialog->original_account_title)
-               g_free (dialog->original_account_title);
-       dialog->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
-       
-       /* Show the account data in the widgets: */
-       
-       /* Note that we never show the non-display name in the UI.
-        * (Though the display name defaults to the non-display name at the start.) */
-       gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
-                           null_means_empty (modest_account_settings_get_display_name (settings)));
-       gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name), 
-                           null_means_empty (modest_account_settings_get_fullname (settings)));
-       gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email), 
-                           null_means_empty (modest_account_settings_get_email_address (settings)));
-       modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), modest_server_account_settings_get_protocol (incoming_account));
-       modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), 
-                                                           modest_account_settings_get_retrieve_type (settings));
-       modest_limit_retrieve_combo_box_set_active_limit_retrieve (
-               MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), 
-               modest_account_settings_get_retrieve_limit (settings));
-       
-       
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), 
-                                     modest_account_settings_get_leave_messages_on_server (settings));
-       
-       /* Only show the leave-on-server checkbox for POP, 
-        * as per the UI spec: */
-       if (modest_server_account_settings_get_protocol (incoming_account) != MODEST_PROTOCOL_STORE_POP) {
-               gtk_widget_hide (dialog->caption_leave_messages);
-       } else {
-               gtk_widget_show (dialog->caption_leave_messages);
-       }
-       
-       update_incoming_server_security_choices (dialog, modest_server_account_settings_get_protocol (incoming_account));
-       if (incoming_account) {
-               const gchar *username;
-               const gchar *password;
-               const gchar *hostname;
-               /* Remember this for later: */
-               dialog->incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
-               
-               hostname = modest_server_account_settings_get_hostname (incoming_account);
-               username = modest_server_account_settings_get_username (incoming_account);
-               password = modest_server_account_settings_get_password (incoming_account);
-               gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
-                                   null_means_empty (username));
-               gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password), 
-                                   null_means_empty (password));
-                       
-               gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver), 
-                                   null_means_empty (hostname));
-                       
-               /* 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. 
-                * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
-         */                                                                                                             
-               modest_serversecurity_combo_box_set_active_serversecurity (
-                       MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), 
-                       modest_server_account_settings_get_security (incoming_account));
-               
-               /* Check if we have
-                - a secure protocol
-                OR
-                - use encrypted passwords
-               */
-               const ModestAuthProtocol secure_auth = modest_server_account_settings_get_auth_protocol (incoming_account);
-               dialog->protocol_authentication_incoming = (secure_auth != MODEST_PROTOCOL_AUTH_NONE)?
-                       secure_auth:MODEST_PROTOCOL_AUTH_PASSWORD;
-               ModestConnectionProtocol secure_protocol = modest_server_account_settings_get_security (incoming_account);
-               if (modest_protocol_info_is_secure (secure_protocol) || modest_protocol_info_auth_is_secure(secure_auth))
-               {
-                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth), 
-                                                    TRUE);
-               }
-               else
-               {
-                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth), 
-                                                    FALSE);
-               };
-
-               gtk_widget_set_sensitive (dialog->checkbox_incoming_auth, !modest_protocol_info_is_secure (secure_protocol));
-                                       
-               update_incoming_server_title (dialog, dialog->incoming_protocol);
-               
-               const gint port_num = modest_server_account_settings_get_port (incoming_account);
-               if (port_num == 0) {
-                       /* Show the appropriate port number: */
-                       on_combo_incoming_security_changed (
-                               GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
-               } else {
-                       /* Keep the user-entered port-number,
-                        * or the already-appropriate automatic port number: */
-                       hildon_number_editor_set_value (
-                               HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
-               }
-               g_object_unref (incoming_account);
-       }
-       
-       outgoing_account = modest_account_settings_get_transport_settings (settings);
-       if (outgoing_account) {
-               const gchar *hostname;
-               const gchar *username;
-               const gchar *password;
-
-               /* Remember this for later: */
-               dialog->outgoing_protocol = 
-                       modest_server_account_settings_get_protocol (outgoing_account);
-
-               hostname = modest_server_account_settings_get_hostname (outgoing_account);
-               username = modest_server_account_settings_get_username (outgoing_account);
-               password = modest_server_account_settings_get_password (outgoing_account);
-               gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver), 
-                                   null_means_empty (hostname));
-               
-               gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username), 
-                                   null_means_empty (username));
-               gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password), 
-                                   null_means_empty (password));
-               
-               /* Get the secure-auth setting: */
-               const ModestAuthProtocol secure_auth = modest_server_account_settings_get_auth_protocol (outgoing_account);
-               modest_secureauth_combo_box_set_active_secureauth (
-                       MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
-               on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
-               
-               modest_serversecurity_combo_box_fill (
-                       MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), 
-                       dialog->outgoing_protocol);
-               
-               /* Get the security setting: */
-               const ModestConnectionProtocol security = modest_server_account_settings_get_security (outgoing_account);
-               modest_serversecurity_combo_box_set_active_serversecurity (
-                       MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
-               
-               const gint port_num = modest_server_account_settings_get_port (outgoing_account);
-               if (port_num == 0) {
-                       /* Show the appropriate port number: */
-                       on_combo_outgoing_security_changed (
-                               GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
-               }
-               else {
-                       /* Keep the user-entered port-number,
-                        * or the already-appropriate automatic port number: */
-                       hildon_number_editor_set_value (
-                               HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
-               }
-               
-               const gboolean has_specific = 
-                       modest_account_settings_get_use_connection_specific_smtp (settings);
-               gtk_toggle_button_set_active (
-                       GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific), 
-                       has_specific);
-               g_object_unref (outgoing_account);
-       }
-
-       /* Set window title according to account: */
-       /* TODO: Is this the correct way to find a human-readable name for
-        * the protocol used? */
-       const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
-       gchar *proto_name = g_utf8_strup(proto_str, -1);
-       const gchar *account_title = modest_account_settings_get_display_name(settings);
-
-       gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
-       g_free (proto_name);
-
-       gtk_window_set_title (GTK_WINDOW (dialog), title);
-       g_free (title);
-
-       /* account_data->is_enabled,  */
-       /*account_data->is_default,  */
-
-       /* Unset the modified flag so we can detect changes later: */
-       dialog->modified = FALSE;
-}
-
-/** Show the User Info tab.
- */
-void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
-{
-       const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
-       if (page_num == -1) {
-               g_warning ("%s: notebook page not found.\n", __FUNCTION__);     
-       }
-               
-       /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
-       /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
-       
-       gtk_widget_show (dialog->page_user_details);
-       gtk_widget_show (GTK_WIDGET (dialog->notebook));
-       gtk_widget_show (GTK_WIDGET (dialog));
-       gtk_notebook_set_current_page (dialog->notebook, page_num);
-}
-
-static gboolean
-save_configuration (ModestAccountSettingsDialog *dialog)
-{
-       const gchar* account_name = dialog->account_name;
-       ModestServerAccountSettings *store_settings;
-       ModestServerAccountSettings *transport_settings;
-               
-       /* Set the account data from the widgets: */
-       const gchar* user_fullname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
-       modest_account_settings_set_fullname (dialog->settings, user_fullname);
-       
-       const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
-       modest_account_settings_set_email_address (dialog->settings, emailaddress);
-               
-       /* Signature: */
-       if (dialog->signature_dialog) {
-               gboolean use_signature = FALSE;
-               gchar *signature = 
-                       modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
-                                                                    &use_signature);
-       
-               modest_account_settings_set_use_signature (dialog->settings, use_signature);
-               modest_account_settings_set_signature (dialog->settings, signature);
-       }
-       
-       ModestAccountRetrieveType retrieve_type = modest_retrieve_combo_box_get_active_retrieve_conf (
-               MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
-       modest_account_settings_set_retrieve_type (dialog->settings, retrieve_type);
-       
-       gint retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
-               MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
-       modest_account_settings_set_retrieve_limit (dialog->settings, retrieve_limit);
-       
-       const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
-       modest_account_settings_set_leave_messages_on_server (dialog->settings, leave_on_server); 
-
-       store_settings = modest_account_settings_get_store_settings (dialog->settings);
-                       
-       const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
-       modest_server_account_settings_set_hostname (store_settings, hostname);
-                               
-       const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
-       modest_server_account_settings_set_username (store_settings, username);
-       
-       const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
-       modest_server_account_settings_set_password (store_settings, password);
-                       
-       /* port: */
-       gint port_num = hildon_number_editor_get_value (
-                       HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
-       modest_server_account_settings_set_port (store_settings, port_num);
-                       
-       /* 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. 
-        */
-       
-       const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
-       modest_server_account_settings_set_security (store_settings, protocol_security_incoming);
-       if (modest_protocol_info_is_secure (protocol_security_incoming)) {
-               modest_server_account_settings_set_auth_protocol (store_settings, FALSE);
-       } else {
-               modest_server_account_settings_set_auth_protocol (store_settings, 
-                                                                 dialog->protocol_authentication_incoming);
-       }
-
-       g_object_unref (store_settings);
-       
-       /* Outgoing: */
-       transport_settings = modest_account_settings_get_transport_settings (dialog->settings);
-       
-       hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
-       modest_server_account_settings_set_hostname (transport_settings, hostname);
-               
-       username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
-       modest_server_account_settings_set_username (transport_settings, username);
-               
-       password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
-       modest_server_account_settings_set_password (transport_settings, password);
-       
-       const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
-       modest_server_account_settings_set_security (transport_settings, protocol_security_outgoing);
-       
-       const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
-               MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
-       modest_server_account_settings_set_auth_protocol (transport_settings, protocol_authentication_outgoing);        
-       
-       /* port: */
-       port_num = hildon_number_editor_get_value (
-                       HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
-       modest_server_account_settings_set_port (transport_settings, port_num);
-       g_object_unref (transport_settings);
-       
-       
-       /* Set the changed account title last, to simplify the previous code: */
-       gchar* account_title = get_entered_account_title (dialog);
-       if (!account_title)
-               return FALSE; /* Should be prevented already anyway. */
-               
-/*     if (strcmp (account_title, account_name) != 0) { */
-       modest_account_settings_set_display_name (dialog->settings, account_title);
-/*     } */
-       g_free (account_title);
-       account_title = NULL;
-       
-       /* Save connection-specific SMTP server accounts: */
-       modest_account_settings_set_use_connection_specific_smtp 
-               (dialog->settings, 
-                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbox_outgoing_smtp_specific)));
-
-       /* this configuration is not persistent, we should not save */
-       if (account_name != NULL)
-               modest_account_mgr_save_account_settings (dialog->account_manager, dialog->settings);
-
-       return TRUE;
-}
-
-static gboolean entry_is_empty (GtkWidget *entry)
-{
-       if (!entry)
-               return FALSE;
-               
-       const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
-       if ((!text) || (strlen(text) == 0))
-               return TRUE;
-       else {
-               /* Strip it of whitespace at the start and end: */
-               gchar *stripped = g_strdup (text);
-               stripped = g_strstrip (stripped);
-               
-               if (!stripped)
-                       return TRUE;
-                       
-               const gboolean result = (strlen (stripped) == 0);
-               
-               g_free (stripped);
-               return result;
-       }
-}
-
-static void
-enable_buttons (ModestAccountSettingsDialog *self)
-{
-       gboolean enable_ok = TRUE;
-       ModestAuthProtocol outgoing_auth_protocol;
-       
-       /* The account details title is mandatory: */
-       if (entry_is_empty(self->entry_account_title))
-               enable_ok = FALSE;
-
-       /* The user details username is mandatory: */
-       if (enable_ok && entry_is_empty(self->entry_user_username))
-               enable_ok = FALSE;
-               
-       /* The user details email address is mandatory: */
-       if (enable_ok && entry_is_empty (self->entry_user_email))
-               enable_ok = FALSE;
-
-       /* The custom incoming server is mandatory: */
-       if (enable_ok && entry_is_empty(self->entry_incomingserver))
-               enable_ok = FALSE;
-
-       /* The custom incoming server is mandatory: */
-       if (enable_ok && entry_is_empty(self->entry_outgoingserver))
-               enable_ok = FALSE;
-
-       /* Outgoing username is mandatory if outgoing auth is secure */
-       if (self->combo_outgoing_auth) {
-               outgoing_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
-                       MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
-               if (enable_ok && 
-                   outgoing_auth_protocol != MODEST_PROTOCOL_AUTH_NONE &&
-                   entry_is_empty (self->entry_outgoing_username))
-                       enable_ok = FALSE;
-       }
-                       
-       /* Enable the buttons, 
-        * identifying them via their associated response codes:
-        */
-       GtkDialog *dialog_base = GTK_DIALOG (self);
-       gtk_dialog_set_response_sensitive (dialog_base,
-                                          GTK_RESPONSE_OK,
-                                          enable_ok);
-}
-
-void
-modest_account_settings_dialog_check_allow_changes (ModestAccountSettingsDialog *self)
-{
-       ModestServerAccountSettings *incoming_settings;
-       const gchar *server_account_name;
-       gboolean username_known;
-
-       if (!G_IS_OBJECT (self->settings))
-               return;
-
-       incoming_settings = modest_account_settings_get_store_settings (self->settings);
-       server_account_name = modest_server_account_settings_get_account_name (incoming_settings);
-
-       username_known = modest_account_mgr_get_server_account_username_has_succeeded (self->account_manager, 
-                                                                                      server_account_name);
-
-       /* Enable or disable widgets */
-       gtk_widget_set_sensitive (self->entry_user_username, !username_known);
-       gtk_widget_set_sensitive (self->entry_incomingserver, !username_known);
-       /* gtk_widget_set_sensitive (self->entry_outgoingserver, !username_known); */
-       /* gtk_widget_set_sensitive (self->entry_outgoing_username, !username_known); */
-       gtk_widget_set_sensitive (self->entry_incoming_port, !username_known);
-/*     gtk_widget_set_sensitive (self->entry_outgoing_port, !username_known); */
-       gtk_widget_set_sensitive (self->combo_incoming_security, !username_known);
-/*     gtk_widget_set_sensitive (self->combo_outgoing_security, !username_known); */
-}
-
-void 
-modest_account_settings_dialog_set_modified (ModestAccountSettingsDialog *dialog, gboolean modified)
-{
-       g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
-
-       dialog->modified = modified;
-
-}
-
-static void
-modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
-{
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
-       g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
-
-
-       object_class->get_property = modest_account_settings_dialog_get_property;
-       object_class->set_property = modest_account_settings_dialog_set_property;
-       object_class->dispose = modest_account_settings_dialog_dispose;
-       object_class->finalize = modest_account_settings_dialog_finalize;
-}
index b8c38b4..c72225e 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <modest-runtime.h>
 #include "modest-platform.h"
+#include "modest-account-protocol.h"
 #include <modest-account-mgr-helpers.h>
 #include <string.h>
 #include "modest-tny-platform-factory.h"
@@ -251,13 +252,13 @@ on_delete_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
                /* The warning text depends on the account type: */
                gchar *txt = NULL;      
                gint response;
-               
-               if (modest_account_mgr_get_store_protocol (account_mgr, account_name) 
-                   == MODEST_PROTOCOL_STORE_POP) {
-                               txt = g_strdup_printf (_("emev_nc_delete_mailbox"), 
-                                                      account_title);
-               } else {
-                       txt = g_strdup_printf (_("emev_nc_delete_mailboximap"), 
+               ModestProtocol *protocol;
+
+               protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
+                                                                         modest_account_mgr_get_store_protocol (account_mgr, account_name));
+               txt = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX, account_title);
+               if (txt == NULL) {
+                       txt = g_strdup_printf (_("emev_nc_delete_mailbox"), 
                                               account_title);
                }
                
@@ -328,14 +329,23 @@ on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
         * the user wishes.
         */
        if (check_for_active_account (self, account_name)) {
-               GtkWidget *dialog = modest_tny_account_store_show_account_settings_dialog (modest_runtime_get_account_store (), account_name);
-               
-               /* When the dialog is closed, reconnect */
-               g_signal_connect (dialog, "response", 
-                                 G_CALLBACK (on_account_settings_dialog_response), 
-                                 self);
+               ModestAccountProtocol *proto;
+               ModestProtocolType proto_type;
+
+               /* Get proto */
+               proto_type = modest_account_mgr_get_store_protocol (modest_runtime_get_account_mgr (), 
+                                                                   account_name);
+               proto = (ModestAccountProtocol *)
+                       modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), 
+                                                                      proto_type);
+
+               /* Create and show the dialog */
+               if (proto && MODEST_IS_ACCOUNT_PROTOCOL (proto)) {
+                       ModestAccountSettingsDialog *dialog =
+                               modest_account_protocol_get_account_settings_dialog (proto, account_name);
+                       gtk_widget_show (GTK_WIDGET (dialog));
+               }
        }
-       
        g_free (account_name);
 }
 
@@ -390,7 +400,6 @@ on_new_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
        gtk_widget_show (GTK_WIDGET (wizard));
 }
 
-
 static void
 on_close_button_clicked (GtkWidget *button, gpointer user_data)
 {              
index a3aa05b..37886bc 100644 (file)
@@ -358,9 +358,9 @@ modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEd
        if (!priv->combo_outgoing_security)
                priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
        modest_serversecurity_combo_box_fill (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
+               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOLS_TRANSPORT_SMTP);
        modest_serversecurity_combo_box_set_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
+               MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOLS_CONNECTION_NONE);
        caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
                priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
        gtk_widget_show (priv->combo_outgoing_security);
@@ -450,7 +450,7 @@ modest_connection_specific_smtp_edit_window_set_connection (
        
                modest_serversecurity_combo_box_set_active_serversecurity (
                MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), 
-               modest_server_account_settings_get_security (server_settings));
+               modest_server_account_settings_get_security_protocol (server_settings));
        
                modest_secureauth_combo_box_set_active_secureauth (
                MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth), 
@@ -493,13 +493,13 @@ modest_connection_specific_smtp_edit_window_get_settings (ModestConnectionSpecif
        modest_server_account_settings_set_hostname (server_settings, 
                                                     gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
        modest_server_account_settings_set_protocol (server_settings,
-                                                    MODEST_PROTOCOL_TRANSPORT_SMTP);
+                                                    MODEST_PROTOCOLS_TRANSPORT_SMTP);
        modest_server_account_settings_set_username (server_settings,
                                                     gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));
        modest_server_account_settings_set_password (server_settings,
                                                     gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
        
-       modest_server_account_settings_set_security (server_settings, 
+       modest_server_account_settings_set_security_protocol (server_settings, 
                                                     modest_serversecurity_combo_box_get_active_serversecurity (
                                                     MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security)));
        modest_server_account_settings_set_auth_protocol (server_settings,
index 8c31398..3f98ded 100644 (file)
@@ -252,7 +252,7 @@ on_button_edit (ModestConnectionSpecificSmtpWindow *self)
                /* Get existing server account data if a server account is already specified: */
                gboolean settings_were_retrieved = FALSE;
                if (server_account_name && !server_settings) {
-                       server_settings = modest_account_mgr_load_server_settings(mgr, server_account_name);
+                       server_settings = modest_account_mgr_load_server_settings(mgr, server_account_name, TRUE);
                        if (server_settings)
                                settings_were_retrieved = TRUE;
                }
diff --git a/src/maemo/modest-default-account-settings-dialog.c b/src/maemo/modest-default-account-settings-dialog.c
new file mode 100644 (file)
index 0000000..e4d8b51
--- /dev/null
@@ -0,0 +1,1560 @@
+/* Copyright (c) 2008, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include <glib/gi18n.h>
+#include <gtk/gtknotebook.h>
+#include <gtk/gtkvbox.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkcombobox.h>
+#include <gtk/gtkentry.h>
+#include <gtk/gtkbutton.h>
+#include <gtk/gtkcheckbutton.h>
+#include <gtk/gtkmessagedialog.h>
+#include <gtk/gtkstock.h>
+#include "modest-hildon-includes.h"
+#include "modest-default-account-settings-dialog.h"
+#include "modest-account-mgr.h"
+#include "widgets/modest-serversecurity-combo-box.h"
+#include "widgets/modest-secureauth-combo-box.h"
+#include "widgets/modest-validating-entry.h"
+#include "widgets/modest-retrieve-combo-box.h"
+#include "widgets/modest-limit-retrieve-combo-box.h"
+#include "modest-text-utils.h"
+#include "modest-account-mgr.h"
+#include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
+#include <modest-server-account-settings.h>
+#include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
+#include "maemo/modest-connection-specific-smtp-window.h"
+#include "maemo/modest-signature-editor-dialog.h"
+#include <modest-utils.h>
+#include <modest-defs.h>
+#include "maemo/modest-maemo-utils.h"
+#include "maemo/modest-maemo-security-options-view.h"
+#include "widgets/modest-ui-constants.h"
+#include <tny-account.h>
+#include <tny-status.h>
+
+#include <gconf/gconf-client.h>
+#include <string.h> /* For strlen(). */
+
+/* Include config.h so that _() works: */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define PORT_MIN 1
+#define PORT_MAX 65535
+
+static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
+
+G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog, 
+                        modest_default_account_settings_dialog, 
+                        GTK_TYPE_DIALOG,
+                        0, 
+                        G_IMPLEMENT_INTERFACE (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, 
+                                               modest_account_settings_dialog_init));
+
+#define MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
+       (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, ModestDefaultAccountSettingsDialogPrivate))
+
+typedef struct _ModestDefaultAccountSettingsDialogPrivate ModestDefaultAccountSettingsDialogPrivate;
+
+struct _ModestDefaultAccountSettingsDialogPrivate
+{
+       /* Used by derived widgets to query existing accounts,
+        * and to create new accounts: */
+       ModestAccountMgr *account_manager;
+       ModestAccountSettings *settings;
+       
+       gboolean modified;
+       gchar * account_name; /* This may not change. It is not user visible. */
+       ModestProtocolType incoming_protocol; /* This may not change. */
+       ModestProtocolType outgoing_protocol; /* This may not change. */
+       gchar * original_account_title;
+
+       ModestProtocolType protocol_authentication_incoming;
+       
+       GtkNotebook *notebook;
+       
+       GtkWidget *page_account_details;
+       GtkWidget *entry_account_title;
+       GtkWidget *combo_retrieve;
+       GtkWidget *combo_limit_retrieve;
+       GtkWidget *caption_leave_messages;
+       GtkWidget *checkbox_leave_messages;
+       
+       GtkWidget *page_user_details;
+       GtkWidget *entry_user_name;
+       GtkWidget *entry_user_username;
+       GtkWidget *entry_user_password;
+       GtkWidget *entry_user_email;
+/*     GtkWidget *entry_incoming_port; */
+       GtkWidget *button_signature;
+       
+       GtkWidget *page_complete_easysetup;
+       
+       GtkWidget *page_incoming;
+       GtkWidget *caption_incoming;
+       GtkWidget *entry_incomingserver;
+/*     GtkWidget *combo_incoming_security; */
+/*     GtkWidget *checkbox_incoming_auth; */
+
+       GtkWidget *page_outgoing;
+       GtkWidget *entry_outgoingserver;
+/*     GtkWidget *caption_outgoing_username; */
+/*     GtkWidget *entry_outgoing_username; */
+/*     GtkWidget *caption_outgoing_password; */
+/*     GtkWidget *entry_outgoing_password; */
+/*     GtkWidget *combo_outgoing_security; */
+/*     GtkWidget *combo_outgoing_auth; */
+/*     GtkWidget *entry_outgoing_port; */
+       GtkWidget *checkbox_outgoing_smtp_specific;
+       GtkWidget *button_outgoing_smtp_servers;
+       
+       GtkWidget *signature_dialog;
+
+       GtkWidget *incoming_security;
+       GtkWidget *outgoing_security;
+};
+
+static void
+enable_buttons (ModestDefaultAccountSettingsDialog *self);
+
+static gboolean
+save_configuration (ModestDefaultAccountSettingsDialog *dialog);
+
+static const gchar * null_means_empty (const gchar * str);
+
+static const gchar *
+null_means_empty (const gchar * str)
+{
+       return str ? str : "";
+}
+
+static void
+modest_default_account_settings_dialog_dispose (GObject *object)
+{
+       if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
+               G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
+}
+
+static void
+modest_default_account_settings_dialog_finalize (GObject *object)
+{
+       ModestDefaultAccountSettingsDialog *self;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+       
+       if (priv->account_name)
+               g_free (priv->account_name);
+               
+       if (priv->original_account_title)
+               g_free (priv->original_account_title);
+               
+       if (priv->account_manager)
+               g_object_unref (G_OBJECT (priv->account_manager));
+               
+       if (priv->signature_dialog)
+               gtk_widget_destroy (priv->signature_dialog);
+
+       if (priv->settings) {
+               g_object_unref (priv->settings);
+               priv->settings = NULL;
+       }
+       
+       G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
+}
+
+static void 
+set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+       priv->modified = modified;
+}
+
+static void
+on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
+{
+       set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
+}
+
+static void
+on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
+{
+       set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
+}
+
+static void
+on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
+{
+       set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
+}
+
+static void
+on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
+{
+       set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
+}
+
+static void       
+on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
+{
+       ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
+       gint value = hildon_number_editor_get_value (editor);
+
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
+}
+
+/* Set a modified boolean whenever the widget is changed, 
+ * so we can check for it later.
+ */
+static void
+connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
+{
+       if (HILDON_IS_NUMBER_EDITOR (widget)) {
+               g_signal_connect (G_OBJECT (widget), "notify::value",
+                       G_CALLBACK (on_modified_number_editor_changed), self);
+               g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
+       }
+       else if (GTK_IS_ENTRY (widget)) {
+               g_signal_connect (G_OBJECT (widget), "changed",
+                       G_CALLBACK (on_modified_entry_changed), self);
+       } else if (GTK_IS_COMBO_BOX (widget)) {
+               g_signal_connect (G_OBJECT (widget), "changed",
+                       G_CALLBACK (on_modified_combobox_changed), self);       
+       } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
+               g_signal_connect (G_OBJECT (widget), "toggled",
+                       G_CALLBACK (on_modified_checkbox_toggled), self);
+       }
+}
+
+static void
+on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
+{
+       ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
+       g_assert(self);
+       enable_buttons(self);
+}
+
+static void
+on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
+{
+       ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
+       g_assert(self);
+       enable_buttons(self);
+}
+
+/** This is a convenience function to create a caption containing a mandatory widget.
+ * When the widget is edited, the enable_buttons() vfunc will be called.
+ */
+static GtkWidget* 
+create_caption_new_with_asterisk(ModestDefaultAccountSettingsDialog *self,
+       GtkSizeGroup *group,
+       const gchar *value,
+       GtkWidget *control,
+       GtkWidget *icon,
+       HildonCaptionStatus flag)
+{
+       GtkWidget *caption = NULL;
+  
+       /* Note: Previously, the translated strings already contained the "*",
+        * Comment out this code if they do again.
+        */
+       /* Add a * character to indicate mandatory fields,
+        * as specified in our "Email UI Specification": */
+       if (flag == HILDON_CAPTION_MANDATORY) {
+               gchar* title = g_strdup_printf("%s*", value);
+               caption = hildon_caption_new (group, title, control, icon, flag);       
+               g_free(title);
+       }       
+       else
+               caption = hildon_caption_new (group, value, control, icon, flag);
+
+       /* Connect to the appropriate changed signal for the widget, 
+        * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
+        */
+       if (GTK_IS_ENTRY (control)) {
+               g_signal_connect (G_OBJECT (control), "changed",
+               G_CALLBACK (on_caption_entry_changed), self);
+               
+       }
+       else if (GTK_IS_COMBO_BOX (control)) {
+               g_signal_connect (G_OBJECT (control), "changed",
+               G_CALLBACK (on_caption_combobox_changed), self);
+       }
+        
+       return caption;
+}
+
+static void
+on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
+{
+       gchar *tmp, *msg;
+                       
+       tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
+       msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
+
+       modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
+
+       g_free (msg);
+       g_free (tmp);
+}
+
+static void
+on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
+{
+       gchar *tmp, *msg;
+                       
+       tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
+       msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
+
+       modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
+
+       g_free (msg);
+       g_free (tmp);
+}
+
+
+static void
+on_entry_max (ModestValidatingEntry *self, gpointer user_data)
+{
+       modest_platform_information_banner (GTK_WIDGET (self), NULL, 
+                                           _CS("ckdg_ib_maximum_characters_reached"));
+}
+
+static GtkWidget*
+create_page_account_details (ModestDefaultAccountSettingsDialog *self)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       GtkWidget *box;
+       GtkAdjustment *focus_adjustment = NULL;
+       GtkSizeGroup* sizegroup;
+       GtkWidget *scrollwin;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+       box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+       sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       scrollwin = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
+                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+           
+       /* The description widgets: */  
+       priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
+       /* Do use auto-capitalization: */
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title), 
+               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
+       GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"), 
+               priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
+       gtk_widget_show (priv->entry_account_title);
+       connect_for_modified (self, priv->entry_account_title);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+       
+       /* Prevent the use of some characters in the account title, 
+        * as required by our UI specification: */
+       GList *list_prevent = NULL;
+       list_prevent = g_list_append (list_prevent, "\\");
+       list_prevent = g_list_append (list_prevent, "/");
+       list_prevent = g_list_append (list_prevent, ":");
+       list_prevent = g_list_append (list_prevent, "*");
+       list_prevent = g_list_append (list_prevent, "?");
+       list_prevent = g_list_append (list_prevent, "\"");
+       list_prevent = g_list_append (list_prevent, "<"); 
+       list_prevent = g_list_append (list_prevent, ">"); 
+       list_prevent = g_list_append (list_prevent, "|");
+       list_prevent = g_list_append (list_prevent, "^");       
+       modest_validating_entry_set_unallowed_characters (
+               MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
+       g_list_free (list_prevent);
+       modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
+                                        on_entry_invalid_account_title_character, self);
+       
+       /* Set max length as in the UI spec:
+        * The UI spec seems to want us to show a dialog if we hit the maximum. */
+       gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
+       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title), 
+               on_entry_max, self);
+       
+       /* The retrieve combobox: */
+       priv->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
+       caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"), 
+               priv->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
+       gtk_widget_show (priv->combo_retrieve);
+       connect_for_modified (self, priv->combo_retrieve);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+       
+       /* The limit-retrieve combobox: */
+       priv->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
+       caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"), 
+               priv->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
+       gtk_widget_show (priv->combo_limit_retrieve);
+       connect_for_modified (self, priv->combo_limit_retrieve);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+
+       /* The leave-messages widgets: */
+       if(!priv->checkbox_leave_messages)
+               priv->checkbox_leave_messages = gtk_check_button_new ();
+       if (!priv->caption_leave_messages) {
+               priv->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"), 
+                       priv->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
+       }
+                       
+       gtk_widget_show (priv->checkbox_leave_messages);
+       connect_for_modified (self, priv->checkbox_leave_messages);
+       gtk_box_pack_start (GTK_BOX (box), priv->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (priv->caption_leave_messages);
+
+       g_object_unref (sizegroup);
+       
+       gtk_widget_show (GTK_WIDGET (box));
+       
+       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
+       gtk_widget_show (scrollwin);
+
+       focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
+       gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment); 
+       
+       return GTK_WIDGET (scrollwin);
+}
+
+static gchar*
+get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       const gchar* account_title;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
+       account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
+
+       if (!account_title || (strlen (account_title) == 0))
+               return NULL;
+       else {
+               /* Strip it of whitespace at the start and end: */
+               gchar *result = g_strdup (account_title);
+               result = g_strstrip (result);
+               
+               if (!result)
+                       return NULL;
+                       
+               if (strlen (result) == 0) {
+                       g_free (result);
+                       return NULL;    
+               }
+               
+               return result;
+       }
+}
+
+
+static void
+on_button_signature (GtkButton *button, gpointer user_data)
+{
+       ModestDefaultAccountSettingsDialog *self;
+       gint response;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       /* Create the window, if necessary: */
+       if (!(priv->signature_dialog)) {
+               priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
+       
+               gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
+               const gchar *signature = modest_account_settings_get_signature(priv->settings);
+               gchar* account_title = get_entered_account_title (self);
+               modest_signature_editor_dialog_set_settings (
+                       MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog), 
+                       use_signature, signature, account_title);
+
+               g_free (account_title);
+               account_title = NULL;
+               signature = NULL;
+       }
+
+       /* Show the window: */  
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
+                                    GTK_WINDOW (priv->signature_dialog));
+
+       response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
+       gtk_widget_hide (priv->signature_dialog);
+       if (response != GTK_RESPONSE_OK) {
+               /* Destroy the widget now, and its data: */
+               gtk_widget_destroy (priv->signature_dialog);
+               priv->signature_dialog = NULL;
+       } else {
+               /* Mark modified, so we use the dialog's data later: */
+               priv->modified = TRUE;  
+       }
+}
+
+static GtkWidget*
+create_page_user_details (ModestDefaultAccountSettingsDialog *self)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       GtkWidget *box;
+       GtkAdjustment *focus_adjustment = NULL;
+       GtkSizeGroup* sizegroup;
+       GtkWidget *scrollwin;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+       sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       scrollwin = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
+                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+        
+       /* The name widgets: */
+       priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
+
+       /* Auto-capitalization is the default, so let's turn it off: */
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
+       /* Set max length as in the UI spec:
+        * The UI spec seems to want us to show a dialog if we hit the maximum. */
+       gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
+       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name), 
+               on_entry_max, self);
+       GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
+               _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
+       gtk_widget_show (priv->entry_user_name);
+       connect_for_modified (self, priv->entry_user_name);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+
+
+       /* Prevent the use of some characters in the name, 
+        * as required by our UI specification: */
+       GList *list_prevent = NULL;
+       list_prevent = g_list_append (list_prevent, "<");
+       list_prevent = g_list_append (list_prevent, ">");
+       modest_validating_entry_set_unallowed_characters (
+               MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
+       g_list_free (list_prevent);
+       modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
+                                        on_entry_invalid_fullname_character, self);
+       
+       /* The username widgets: */     
+       priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
+       /* Auto-capitalization is the default, so let's turn it off: */
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
+       caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"), 
+               priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
+       gtk_widget_show (priv->entry_user_username);
+       connect_for_modified (self, priv->entry_user_username);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+       
+       /* Prevent the use of some characters in the username, 
+        * as required by our UI specification: */
+       modest_validating_entry_set_unallowed_characters_whitespace (
+               MODEST_VALIDATING_ENTRY (priv->entry_user_username));
+       modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username), 
+                                         modest_utils_on_entry_invalid_character, 
+                                         self);
+       
+       /* Set max length as in the UI spec:
+        * The UI spec seems to want us to show a dialog if we hit the maximum. */
+       gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
+       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username), 
+               on_entry_max, self);
+       
+       /* The password widgets: */     
+       priv->entry_user_password = gtk_entry_new ();
+       /* Auto-capitalization is the default, so let's turn it off: */
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password), 
+               HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
+       gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
+       /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
+       caption = create_caption_new_with_asterisk (self, sizegroup, 
+               _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
+       gtk_widget_show (priv->entry_user_password);
+       connect_for_modified (self, priv->entry_user_password);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+       
+       /* The email address widgets: */        
+       priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
+       /* Auto-capitalization is the default, so let's turn it off: */
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
+       caption = create_caption_new_with_asterisk (self, sizegroup, 
+               _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
+       gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
+       gtk_widget_show (priv->entry_user_email);
+       connect_for_modified (self, priv->entry_user_email);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+       
+       /* Set max length as in the UI spec:
+        * The UI spec seems to want us to show a dialog if we hit the maximum. */
+       gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
+       modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email), 
+               on_entry_max, self);
+       
+       /* Signature button: */
+       if (!priv->button_signature)
+               priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
+       caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"), 
+               priv->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
+       hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
+       gtk_widget_show (priv->button_signature);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+
+       g_object_unref (sizegroup);
+               
+       g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
+               G_CALLBACK (on_button_signature), self);
+               
+       gtk_widget_show (GTK_WIDGET (box));
+       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
+       gtk_widget_show (scrollwin);
+
+       focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
+       gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment); 
+       
+       return GTK_WIDGET (scrollwin);
+}
+
+/* Change the caption title for the incoming server */
+static void
+update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
+                             ModestProtocolType protocol_type)
+{
+       ModestProtocolRegistry *protocol_registry;
+       ModestProtocol *protocol;
+       const gchar *protocol_display_name;
+       gchar* incomingserver_title;
+       gchar *with_asterisk;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       protocol_registry = modest_runtime_get_protocol_registry ();
+       protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
+       protocol_display_name = modest_protocol_get_display_name (protocol);
+       incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), 
+                                              protocol_display_name);
+       
+       /* This is a mandatory field, so add a *. This is usually done by
+        * create_caption_new_with_asterisk() but we can't use that here. */
+       with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
+       g_free (incomingserver_title);
+       
+       g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
+       g_free (with_asterisk);
+}
+
+/** Change the caption title for the incoming server, 
+ * as specified in the UI spec:
+ */
+/* static void  */
+/* update_incoming_server_security_choices (ModestDefaultAccountSettingsDialog *self,  */
+/*                                      ModestProtocolType protocol) */
+/* { */
+/*     /\* Fill the combo with appropriately titled choices for POP or IMAP. *\/ */
+/*     /\* The choices are the same, but the titles are different, as in the UI spec. *\/ */
+/*     modest_serversecurity_combo_box_fill ( */
+/*             MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol); */
+/* } */
+           
+static GtkWidget* 
+create_page_incoming (ModestDefaultAccountSettingsDialog *self)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       GtkWidget *box;
+       GtkSizeGroup *sizegroup;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE); 
+       /* Create a size group to be used by all captions.
+        * Note that HildonCaption does not create a default size group if we do not specify one.
+        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
+       sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+        
+       /* The incoming server widgets: */
+       if(!priv->entry_incomingserver)
+               priv->entry_incomingserver = gtk_entry_new ();
+       /* Auto-capitalization is the default, so let's turn it off: */
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
+
+       if (priv->caption_incoming)
+               gtk_widget_destroy (priv->caption_incoming);
+          
+       /* The caption title will be updated in update_incoming_server_title().
+        * so this default text will never be seen: */
+       /* (Note: Changing the title seems pointless. murrayc) */
+       priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup, 
+               "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
+       gtk_widget_show (priv->entry_incomingserver);
+       connect_for_modified (self, priv->entry_incomingserver);
+       gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (priv->caption_incoming);
+
+       /* Incoming security widgets */
+       priv->incoming_security = 
+               modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
+                                                       TRUE, sizegroup);
+       gtk_box_pack_start (GTK_BOX (box), priv->incoming_security, 
+                           FALSE, FALSE, MODEST_MARGIN_HALF);
+
+       gtk_widget_show (priv->incoming_security);
+
+       g_object_unref (sizegroup);     
+       gtk_widget_show (GTK_WIDGET (box));
+       
+       return GTK_WIDGET (box);
+}
+
+static void
+on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
+{
+       GtkWidget *widget = GTK_WIDGET (user_data);
+       
+       /* Enable the widget only if the toggle button is active: */
+       const gboolean enable = gtk_toggle_button_get_active (togglebutton);
+       gtk_widget_set_sensitive (widget, enable);
+}
+
+/* Make the sensitivity of a widget depend on a toggle button.
+ */
+static void
+enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
+{
+       g_signal_connect (G_OBJECT (button), "toggled",
+               G_CALLBACK (on_toggle_button_changed), widget);
+       
+       /* Set the starting sensitivity: */
+       on_toggle_button_changed (button, widget);
+}
+
+static void
+on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
+{
+       ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
+       ModestConnectionSpecificSmtpWindow *smtp_win;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       /* Create the window if necessary: */
+       smtp_win = modest_connection_specific_smtp_window_new ();
+       modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
+
+       /* Show the window: */  
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win));
+       gtk_widget_show (GTK_WIDGET (smtp_win));
+       priv->modified = TRUE;
+}
+
+/* static void */
+/* on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data) */
+/* { */
+/*     ModestDefaultAccountSettingsDialog *self; */
+/*     ModestProtocolRegistry *protocol_registry; */
+/*     ModestProtocolType protocol_security;    */
+/*     gboolean secureauth_used; */
+
+/*     self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
+/*     protocol_registry = modest_runtime_get_protocol_registry (); */
+       
+/*     protocol_security =  */
+/*             modest_secureauth_combo_box_get_active_secureauth ( */
+/*                     MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth)); */
+/*     secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, protocol_security); */
+       
+/*     gtk_widget_set_sensitive (priv->caption_outgoing_username, secureauth_used); */
+/*     gtk_widget_set_sensitive (priv->caption_outgoing_password, secureauth_used); */
+/* } */
+
+/* static void */
+/* on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data) */
+/* { */
+/*     ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
+       
+/*     const gint port_number =  */
+/*             modest_serversecurity_combo_box_get_active_serversecurity_port ( */
+/*                     MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security)); */
+
+/*     if(port_number != 0) { */
+/*             hildon_number_editor_set_value ( */
+/*                     HILDON_NUMBER_EDITOR (priv->entry_outgoing_port), port_number); */
+/*     }                */
+/* } */
+
+static void
+on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
+                          gboolean missing,
+                          gpointer user_data)
+{
+       /* Disable the OK button */
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
+                                          GTK_RESPONSE_OK,
+                                          !missing);
+}
+
+static GtkWidget* 
+create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+       GtkAdjustment *focus_adjustment = NULL;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+       
+       /* Put it all in a scrolled window, so that all widgets can be 
+        * accessed even when the on-screen keyboard is visible: */
+       GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), 
+               GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+       
+       /* Create a size group to be used by all captions.
+        * Note that HildonCaption does not create a default size group if we do not specify one.
+        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
+       GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+        
+       /* The outgoing server widgets: */
+       if (!priv->entry_outgoingserver)
+               priv->entry_outgoingserver = gtk_entry_new ();
+       /* Auto-capitalization is the default, so let's turn it off: */
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
+       GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
+               _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
+       gtk_widget_show (priv->entry_outgoingserver);
+       connect_for_modified (self, priv->entry_outgoingserver);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+
+       /* Outgoing security widgets */
+       priv->outgoing_security = 
+               modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
+                                                       TRUE, sizegroup);
+       gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security, 
+                           FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (priv->outgoing_security);
+       g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
+                         G_CALLBACK (on_missing_mandatory_data), self);
+
+       GtkWidget *separator = gtk_hseparator_new ();
+       gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (separator);
+       
+       /* connection-specific checkbox: */
+       if (!priv->checkbox_outgoing_smtp_specific) {
+               priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific), 
+                       FALSE);
+       }
+       caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"), 
+               priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
+       gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+       connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
+       
+       /* Connection-specific SMTP-Severs Edit button: */
+       if (!priv->button_outgoing_smtp_servers)
+               priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
+       caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"), 
+               priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
+       hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
+       gtk_widget_show (priv->button_outgoing_smtp_servers);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_widget_show (caption);
+       
+       /* Only enable the button when the checkbox is checked: */
+       enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers, 
+               GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
+
+       g_object_unref (sizegroup);
+               
+       g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
+               G_CALLBACK (on_button_outgoing_smtp_servers), self);
+               
+       gtk_widget_show (GTK_WIDGET (box));
+       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
+       gtk_widget_show(scrollwin);
+
+       focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
+       gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
+       
+       return GTK_WIDGET (scrollwin);
+}
+       
+static gboolean
+check_data (ModestDefaultAccountSettingsDialog *self)
+{
+       gchar* account_title;
+       const gchar* email_address; 
+       const gchar* hostname;
+       const gchar* hostname2;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       /* Check that the title is not already in use: */
+       account_title = get_entered_account_title (self);
+       if (!account_title)
+               return FALSE; /* Should be prevented already anyway. */
+               
+       if (strcmp(account_title, priv->original_account_title) != 0) {
+               gboolean name_in_use; 
+
+               /* Check the changed title: */
+               name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
+                                                                                  account_title);
+               
+               if (name_in_use) {
+                       /* Warn the user via a dialog: */
+                       modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
+                       
+                       g_free (account_title);
+                       return FALSE;
+               }
+       }
+       
+       g_free (account_title);
+       account_title  = NULL;
+
+       /* Check that the email address is valid: */
+       email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
+       if ((!email_address) || (strlen(email_address) == 0)) {
+               return FALSE;
+       }
+                       
+       if (!modest_text_utils_validate_email_address (email_address, NULL)) {
+               /* Warn the user via a dialog: */
+               modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
+                                         
+               /* Return focus to the email address entry: */
+               gtk_widget_grab_focus (priv->entry_user_email);
+               gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
+               return FALSE;
+       }
+
+       /* make sure the domain name for the incoming server is valid */
+       hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
+       if ((!hostname) || (strlen(hostname) == 0)) {
+               return FALSE;
+       }
+       
+       if (!modest_text_utils_validate_domain_name (hostname)) {
+               /* Warn the user via a dialog: */
+               modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
+                                         
+               /* Return focus to the email address entry: */
+               gtk_widget_grab_focus (priv->entry_incomingserver);
+               gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
+               return FALSE;
+       }
+
+       /* make sure the domain name for the outgoing server is valid */
+       hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
+       if ((!hostname2) || (strlen(hostname2) == 0)) {
+               return FALSE;
+       }
+       
+       if (!modest_text_utils_validate_domain_name (hostname2)) {
+               /* Warn the user via a dialog: */
+               modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
+
+               /* Return focus to the email address entry: */
+               gtk_widget_grab_focus (priv->entry_outgoingserver);
+               gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
+               return FALSE;
+       }
+       
+/*     /\* Find a suitable authentication method when secure authentication is desired *\/ */
+/*     port_num = hildon_number_editor_get_value ( */
+/*             HILDON_NUMBER_EDITOR (priv->entry_incoming_port)); */
+/*     username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)); */
+
+/*     protocol_registry = modest_runtime_get_protocol_registry (); */
+
+/*     protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity ( */
+/*             MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security)); */
+/*     if (!modest_protocol_registry_protocol_type_is_secure(protocol_registry, protocol_security_incoming)) */
+/*     { */
+/*             if (gtk_toggle_button_get_active ( */
+/*                             GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))) { */
+/*                     GError *error = NULL; */
+/*                     GList *list_auth_methods; */
+
+/*                     list_auth_methods =  */
+/*                             modest_utils_get_supported_secure_authentication_methods (priv->incoming_protocol,  */
+/*                                                                                       hostname, port_num, username, GTK_WINDOW (self), &error); */
+/*                     if (list_auth_methods) { */
+/*                             GList* method; */
+
+/*                             /\* Use the first supported method. */
+/*                              * TODO: Should we prioritize them, to prefer a particular one? *\/ */
+/*                             for (method = list_auth_methods; method != NULL; method = g_list_next(method)) */
+/*                             { */
+/*                                     ModestProtocolType proto = (ModestProtocolType)(GPOINTER_TO_INT(method->data)); */
+/*                                     // Allow secure methods, e.g MD5 only */
+/*                                     if (modest_protocol_registry_protocol_type_is_secure(protocol_registry, proto)) */
+/*                                     { */
+/*                                             priv->protocol_authentication_incoming = proto; */
+/*                                             break; */
+/*                                     } */
+/*                             } */
+/*                             g_list_free (list_auth_methods); */
+/*                     } */
+
+/*                     if (list_auth_methods == NULL ||  */
+/*                         !modest_protocol_registry_protocol_type_is_secure(protocol_registry, priv->protocol_authentication_incoming)) */
+/*                     { */
+/*                             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); */
+                                       
+/*                             /\* This is a nasty hack. jschmid. *\/ */
+/*                             /\* Don't let the dialog close *\/ */
+/*                             /\*g_signal_stop_emission_by_name (dialog, "response");*\/ */
+/*                             return FALSE; */
+/*                     } */
+/*             } */
+/*     } */
+       
+       return TRUE;
+}
+
+static void 
+on_response (GtkDialog *wizard_dialog,
+            gint response_id,
+            gpointer user_data)
+{
+       ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       gboolean prevent_response = FALSE, sec_changed;
+       ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+       enable_buttons (self);
+
+       /* Check if security widgets changed */
+       incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
+       outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
+       sec_changed =
+               modest_security_options_view_changed (incoming_sec, priv->settings) ||
+               modest_security_options_view_changed (outgoing_sec, priv->settings);
+
+       /* Warn about unsaved changes: */
+       if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
+               GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self), 
+                       _("imum_nc_wizard_confirm_lose_changes")));
+               /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
+                
+                const gint dialog_response = gtk_dialog_run (dialog);
+                gtk_widget_destroy (GTK_WIDGET (dialog));
+                
+               if (dialog_response != GTK_RESPONSE_OK)
+                       prevent_response = TRUE;
+       }
+       /* Check for invalid input: */
+       else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
+               prevent_response = TRUE;
+       }
+               
+       if (prevent_response) {
+               /* This is a nasty hack. murrayc. */
+               /* Don't let the dialog close */
+               g_signal_stop_emission_by_name (wizard_dialog, "response");
+               return; 
+       }
+               
+       if (response_id == GTK_RESPONSE_OK) {
+               /* Try to save the changes if modified (NB #59251): */
+               if (priv->modified || sec_changed) {
+                       if (save_configuration (self)) {
+                               /* Do not show the account-saved dialog if we are just saving this 
+                                * temporarily, because from the user's point of view it will not 
+                                * really be saved (saved + enabled) until later
+                                */
+                               if (modest_account_settings_get_account_name (priv->settings) != NULL) {
+                                       ModestServerAccountSettings *store_settings;
+                                       ModestServerAccountSettings *transport_settings;
+                                       const gchar *store_account_name;
+                                       const gchar *transport_account_name;
+
+
+                                       store_settings = modest_account_settings_get_store_settings (priv->settings);
+                                       transport_settings = modest_account_settings_get_transport_settings (priv->settings);
+                                       store_account_name = modest_server_account_settings_get_account_name (store_settings);
+                                       transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
+                                       
+                                       if (store_account_name) {
+                                               modest_account_mgr_notify_account_update (priv->account_manager, 
+                                                                                         store_account_name);
+                                       }
+                                       if (transport_account_name) {
+                                               modest_account_mgr_notify_account_update (priv->account_manager, 
+                                                                                         transport_account_name);
+                                       }
+                                       g_object_unref (store_settings);
+                                       g_object_unref (transport_settings);
+                                       
+                                       modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
+                               }
+                       } else {
+                               modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
+                       }
+               }
+       }
+}
+
+static void
+modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
+
+       priv->incoming_security = NULL;
+       priv->outgoing_security = NULL;
+
+       /* Create the notebook to be used by the GtkDialog base class:
+        * Each page of the notebook will be a page of the wizard: */
+       priv->notebook = GTK_NOTEBOOK (gtk_notebook_new());
+       priv->settings = modest_account_settings_new ();
+
+       /* Get the account manager object, 
+        * so we can check for existing accounts,
+        * and create new accounts: */
+       priv->account_manager = modest_runtime_get_account_mgr ();
+       g_assert (priv->account_manager);
+       g_object_ref (priv->account_manager);
+       
+       priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
+
+    /* Create the common pages, 
+     */
+       priv->page_account_details = create_page_account_details (self);
+       priv->page_user_details = create_page_user_details (self);
+       priv->page_incoming = create_page_incoming (self);
+       priv->page_outgoing = create_page_outgoing (self);
+       
+       /* Add the notebook pages: */
+       gtk_notebook_append_page (priv->notebook, priv->page_account_details, 
+               gtk_label_new (_("mcen_ti_account_settings_account")));
+       gtk_notebook_append_page (priv->notebook, priv->page_user_details, 
+               gtk_label_new (_("mcen_ti_account_settings_userinfo")));
+       gtk_notebook_append_page (priv->notebook, priv->page_incoming,
+               gtk_label_new (_("mcen_ti_advsetup_retrieval")));
+       gtk_notebook_append_page (priv->notebook, priv->page_outgoing,
+               gtk_label_new (_("mcen_ti_advsetup_sending")));
+               
+       GtkDialog *dialog = GTK_DIALOG (self);
+       gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (priv->notebook));
+       gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
+       gtk_widget_show (GTK_WIDGET (priv->notebook));
+        
+    /* Add the buttons: */
+    gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
+    gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
+    
+    /* Connect to the dialog's response signal: */
+    /* We use connect-before 
+     * so we can stop the signal emission, 
+     * to stop the default signal handler from closing the dialog.
+     */
+    g_signal_connect (G_OBJECT (self), "response",
+            G_CALLBACK (on_response), self); 
+            
+    priv->modified = FALSE;
+
+    /* When this window is shown, hibernation should not be possible, 
+        * because there is no sensible way to save the state: */
+    modest_window_mgr_prevent_hibernation_while_window_is_shown (
+       modest_runtime_get_window_mgr (), GTK_WINDOW (self)); 
+
+    hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
+                                   modest_maemo_utils_get_osso_context());
+}
+
+ModestAccountSettingsDialog*
+modest_default_account_settings_dialog_new (void)
+{
+       return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
+}
+
+/** Update the UI with the stored account details, so they can be edited.
+ * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
+ */
+static void 
+modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog, 
+                                                     ModestAccountSettings *settings)
+{
+       ModestServerAccountSettings *incoming_account;
+       ModestServerAccountSettings *outgoing_account;
+       ModestProtocolRegistry *protocol_registry;
+       const gchar *account_name, *server_account_name;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       gint page_num;
+       gboolean username_known;
+
+       g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
+       g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
+       protocol_registry = modest_runtime_get_protocol_registry ();
+
+       incoming_account = modest_account_settings_get_store_settings (settings);
+       outgoing_account = modest_account_settings_get_transport_settings (settings);
+
+       account_name = modest_account_settings_get_account_name (settings);
+               
+       /* Save the account name so we can refer to it later: */
+       if (priv->account_name)
+               g_free (priv->account_name);
+       priv->account_name = g_strdup (account_name);
+
+       if (priv->settings)
+               g_object_unref (priv->settings);
+       priv->settings = g_object_ref (settings);
+       
+       /* Save the account title so we can refer to it if the user changes it: */
+       if (priv->original_account_title)
+               g_free (priv->original_account_title);
+       priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
+       
+       /* Show the account data in the widgets: */
+       
+       /* Note that we never show the non-display name in the UI.
+        * (Though the display name defaults to the non-display name at the start.) */
+       gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
+                           null_means_empty (modest_account_settings_get_display_name (settings)));
+       gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name), 
+                           null_means_empty (modest_account_settings_get_fullname (settings)));
+       gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email), 
+                           null_means_empty (modest_account_settings_get_email_address (settings)));
+       modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), 
+                                                           modest_account_settings_get_retrieve_type (settings));
+       modest_limit_retrieve_combo_box_set_active_limit_retrieve (
+               MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve), 
+               modest_account_settings_get_retrieve_limit (settings));
+       
+       
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages), 
+                                     modest_account_settings_get_leave_messages_on_server (settings));
+       
+
+       if (incoming_account) {
+               const gchar *username, *password, *hostname, *proto_str, *account_title;
+               gchar *proto_name, *title;
+               ModestProtocolType incoming_protocol;
+
+               modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), modest_server_account_settings_get_protocol (incoming_account));
+               
+               if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
+                                                                                modest_server_account_settings_get_protocol (incoming_account))) {
+                       gtk_widget_hide (priv->caption_leave_messages);
+               } else {
+                       gtk_widget_show (priv->caption_leave_messages);
+               }
+
+               /* Remember this for later: */
+               incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
+               
+               hostname = modest_server_account_settings_get_hostname (incoming_account);
+               username = modest_server_account_settings_get_username (incoming_account);
+               password = modest_server_account_settings_get_password (incoming_account);
+               gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
+                                   null_means_empty (username));
+               gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password), 
+                                   null_means_empty (password));
+                       
+               gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver), 
+                                   null_means_empty (hostname));
+
+               /* Load security settings */
+               modest_security_options_view_load_settings (
+                           MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security), 
+                           settings);
+               gtk_widget_show (priv->incoming_security);
+                                       
+               /* Update the incoming label */
+               update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog), 
+                                             incoming_protocol);
+               
+               /* Set window title according to account */
+               proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
+               proto_name = g_utf8_strup (proto_str, -1);
+               account_title = modest_account_settings_get_display_name(settings);
+               title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
+               
+               gtk_window_set_title (GTK_WINDOW (dialog), title);
+
+               g_free (proto_name);
+               g_free (title);
+               g_object_unref (incoming_account);
+       }
+       
+       outgoing_account = modest_account_settings_get_transport_settings (settings);
+       if (outgoing_account) {
+               const gchar *hostname;
+               const gchar *username;
+               const gchar *password;
+               ModestProtocolType outgoing_protocol;
+
+               /* Remember this for later: */
+               outgoing_protocol = 
+                       modest_server_account_settings_get_protocol (outgoing_account);
+
+               hostname = modest_server_account_settings_get_hostname (outgoing_account);
+               username = modest_server_account_settings_get_username (outgoing_account);
+               password = modest_server_account_settings_get_password (outgoing_account);
+               gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver), 
+                                   null_means_empty (hostname));
+
+               /* Load security settings */
+               modest_security_options_view_load_settings (
+                           MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security), 
+                           settings);
+               gtk_widget_show (priv->outgoing_security);
+
+               const gboolean has_specific = 
+                       modest_account_settings_get_use_connection_specific_smtp (settings);
+               gtk_toggle_button_set_active (
+                       GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific), 
+                       has_specific);
+               g_object_unref (outgoing_account);
+       }
+
+       /* Switch to user page */
+       page_num = gtk_notebook_page_num (priv->notebook,priv->page_user_details);
+       gtk_notebook_set_current_page (priv->notebook, page_num);
+
+       /* Check if we allow changes or not */
+       server_account_name = modest_server_account_settings_get_account_name (incoming_account);
+       username_known = 
+               modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
+                                                                             server_account_name);
+       gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
+       gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
+       modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
+                                                    !username_known);
+
+
+       /* Unset the modified flag so we can detect changes later: */
+       priv->modified = FALSE;
+}
+
+static gboolean
+save_configuration (ModestDefaultAccountSettingsDialog *dialog)
+{
+       const gchar* user_fullname;
+       const gchar* emailaddress;
+       ModestServerAccountSettings *store_settings;
+       ModestServerAccountSettings *transport_settings;
+       ModestAccountRetrieveType retrieve_type;
+       gint retrieve_limit;
+       gboolean leave_on_server;
+       const gchar* hostname;
+       const gchar* username;
+       const gchar* password;
+       gchar* account_title;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       const gchar* account_name;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
+       account_name = priv->account_name;
+
+       /* Set the account data from the widgets: */
+       user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
+       modest_account_settings_set_fullname (priv->settings, user_fullname);
+       
+       emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
+       modest_account_settings_set_email_address (priv->settings, emailaddress);
+               
+       /* Signature: */
+       if (priv->signature_dialog) {
+               gboolean use_signature = FALSE;
+               gchar *signature;
+               signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
+                                                                        &use_signature);
+       
+               modest_account_settings_set_use_signature (priv->settings, use_signature);
+               modest_account_settings_set_signature (priv->settings, signature);
+       }
+       
+       retrieve_type = modest_retrieve_combo_box_get_active_retrieve_conf (
+               MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve));
+       modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
+       
+       retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
+               MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve));
+       modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
+       
+       leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages));
+       modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server); 
+
+       store_settings = modest_account_settings_get_store_settings (priv->settings);
+                       
+       hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
+       modest_server_account_settings_set_hostname (store_settings, hostname);
+                               
+       username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
+       modest_server_account_settings_set_username (store_settings, username);
+       
+       password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
+       modest_server_account_settings_set_password (store_settings, password);
+
+       /* Save security settings */
+       modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security), 
+                                                   priv->settings);
+
+       g_object_unref (store_settings);
+       
+       /* Outgoing: */
+       transport_settings = modest_account_settings_get_transport_settings (priv->settings);
+       
+       hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
+       modest_server_account_settings_set_hostname (transport_settings, hostname);
+                       
+       /* Save security settings */
+       modest_security_options_view_save_settings (
+           MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security), 
+           priv->settings);
+       
+       /* Set the changed account title last, to simplify the previous code: */
+       account_title = get_entered_account_title (dialog);
+       if (!account_title)
+               return FALSE; /* Should be prevented already anyway. */
+               
+/*     if (strcmp (account_title, account_name) != 0) { */
+       modest_account_settings_set_display_name (priv->settings, account_title);
+/*     } */
+       g_free (account_title);
+       account_title = NULL;
+       
+       /* Save connection-specific SMTP server accounts: */
+       modest_account_settings_set_use_connection_specific_smtp 
+               (priv->settings, 
+                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
+
+       /* this configuration is not persistent, we should not save */
+       if (account_name != NULL)
+               modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
+
+       return TRUE;
+}
+
+static gboolean entry_is_empty (GtkWidget *entry)
+{
+       if (!entry)
+               return FALSE;
+               
+       const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
+       if ((!text) || (strlen(text) == 0))
+               return TRUE;
+       else {
+               /* Strip it of whitespace at the start and end: */
+               gchar *stripped = g_strdup (text);
+               stripped = g_strstrip (stripped);
+               
+               if (!stripped)
+                       return TRUE;
+                       
+               const gboolean result = (strlen (stripped) == 0);
+               
+               g_free (stripped);
+               return result;
+       }
+}
+
+static void
+enable_buttons (ModestDefaultAccountSettingsDialog *self)
+{
+       gboolean enable_ok = TRUE;
+       ModestProtocolRegistry *protocol_registry;
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+       
+       /* The account details title is mandatory: */
+       if (entry_is_empty(priv->entry_account_title))
+               enable_ok = FALSE;
+
+       /* The user details username is mandatory: */
+       if (enable_ok && entry_is_empty(priv->entry_user_username))
+               enable_ok = FALSE;
+               
+       /* The user details email address is mandatory: */
+       if (enable_ok && entry_is_empty (priv->entry_user_email))
+               enable_ok = FALSE;
+
+       /* The custom incoming server is mandatory: */
+       if (enable_ok && entry_is_empty(priv->entry_incomingserver))
+               enable_ok = FALSE;
+
+       /* The custom outgoing server is mandatory: */
+       if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
+               enable_ok = FALSE;
+
+       protocol_registry = modest_runtime_get_protocol_registry ();
+                       
+       /* Enable the buttons, 
+        * identifying them via their associated response codes:
+        */
+       GtkDialog *dialog_base = GTK_DIALOG (self);
+       gtk_dialog_set_response_sensitive (dialog_base,
+                                          GTK_RESPONSE_OK,
+                                          enable_ok);
+}
+
+static void
+modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
+
+       object_class->dispose = modest_default_account_settings_dialog_dispose;
+       object_class->finalize = modest_default_account_settings_dialog_finalize;
+}
+
+static void 
+modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
+{
+       ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
+
+       iface->load_settings = modest_default_account_settings_dialog_load_settings;
+}
diff --git a/src/maemo/modest-maemo-security-options-view.c b/src/maemo/modest-maemo-security-options-view.c
new file mode 100644 (file)
index 0000000..9595fca
--- /dev/null
@@ -0,0 +1,488 @@
+/* Copyright (c) 2008, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "modest-runtime.h"
+#include "modest-security-options-view-priv.h"
+#include "modest-maemo-security-options-view.h"
+#include "modest-text-utils.h"
+#include "modest-platform.h"
+#include "modest-account-protocol.h"
+#include "widgets/modest-ui-constants.h"
+#include "widgets/modest-validating-entry.h"
+#include "widgets/modest-serversecurity-combo-box.h"
+#include "widgets/modest-secureauth-combo-box.h"
+#include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
+#include <hildon-widgets/hildon-caption.h>
+#include <hildon-widgets/hildon-number-editor.h>
+#else
+#include <hildon/hildon-caption.h>
+#include <hildon/hildon-number-editor.h>
+#endif /*MODEST_HAVE_HILDON0_WIDGETS*/
+
+#define PORT_MIN 1
+#define PORT_MAX 65535
+
+typedef struct _ModestMaemoSecurityOptionsViewPrivate ModestMaemoSecurityOptionsViewPrivate;
+struct _ModestMaemoSecurityOptionsViewPrivate {
+};
+
+#define MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE(o) \
+       (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                    MODEST_TYPE_MAEMO_SECURITY_OPTIONS_VIEW, \
+                                    ModestMaemoSecurityOptionsViewPrivate))
+
+static void modest_maemo_security_options_view_init (ModestMaemoSecurityOptionsView *obj);
+static void modest_maemo_security_options_view_finalize (GObject *obj);
+static void modest_maemo_security_options_view_class_init (ModestMaemoSecurityOptionsViewClass *klass);
+
+G_DEFINE_TYPE (ModestMaemoSecurityOptionsView, 
+              modest_maemo_security_options_view, 
+              MODEST_TYPE_SECURITY_OPTIONS_VIEW);
+
+static void on_entry_changed (GtkEditable *editable, gpointer user_data);
+
+/* Tracks changes in the incoming security combo box */
+static void
+on_security_changed (GtkWidget *widget, 
+                    ModestMaemoSecurityOptionsView *self)
+{
+       ModestSecurityOptionsViewPrivate* ppriv;
+       ModestServersecurityComboBox *combo;
+       ModestProtocolType proto_type;
+       ModestProtocolRegistry *proto_registry;
+       gboolean is_secure;
+
+       ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
+
+       proto_registry = modest_runtime_get_protocol_registry ();
+       combo = MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view);
+       proto_type = modest_serversecurity_combo_box_get_active_serversecurity (combo);
+
+       is_secure = modest_protocol_registry_protocol_type_has_tag (proto_registry, proto_type, 
+                                                                   MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS);
+
+       if (MODEST_SECURITY_OPTIONS_VIEW (self)->type == MODEST_SECURITY_OPTIONS_INCOMING) {
+               /* Activate and dim checkbutton if it's secure */
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ppriv->auth_view), 
+                                             is_secure);
+               gtk_widget_set_sensitive (ppriv->auth_view, !is_secure);
+       } else {
+
+       }
+
+       if (ppriv->full) {
+               gint port_number = 
+                       modest_serversecurity_combo_box_get_active_serversecurity_port (MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view));
+               
+               if(port_number) {
+                       hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (ppriv->port_view), 
+                                                       port_number);
+               }
+       }
+}
+
+static void
+on_auth_changed (GtkWidget *widget, 
+                ModestMaemoSecurityOptionsView *self)
+{
+       ModestSecurityOptionsViewPrivate* ppriv;
+       ModestSecureauthComboBox *combo;
+       ModestProtocolRegistry *protocol_registry;
+       ModestProtocolType auth_proto;
+       gboolean secureauth_used;
+       GtkWidget *user_caption, *pwd_caption;
+
+       ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
+       protocol_registry = modest_runtime_get_protocol_registry ();
+       combo = MODEST_SECUREAUTH_COMBO_BOX (ppriv->auth_view);
+
+       auth_proto = modest_secureauth_combo_box_get_active_secureauth (combo);
+       secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, 
+                                                                           auth_proto);
+
+       /* Get captions, well dimm the whole widget */
+       user_caption = gtk_widget_get_parent (ppriv->user_entry);
+       pwd_caption = gtk_widget_get_parent (ppriv->pwd_entry);
+       
+       /* Enable / disable */
+       gtk_widget_set_sensitive (user_caption, secureauth_used);
+       gtk_widget_set_sensitive (pwd_caption, secureauth_used);
+
+       /* Check if mandatory data is missing */
+       on_entry_changed (GTK_EDITABLE (ppriv->user_entry), (gpointer) self);
+}
+
+static void
+create_incoming_security (ModestSecurityOptionsView* self,
+                         GtkSizeGroup *size_group)
+{
+       ModestSecurityOptionsViewPrivate *ppriv;
+       GtkWidget *combo_caption, *check_caption, *entry_caption;
+
+       ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
+
+       /* Create widgets for incoming security */
+       ppriv->security_view = GTK_WIDGET (modest_serversecurity_combo_box_new ());
+       combo_caption = hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_connection"),
+                                           ppriv->security_view, NULL, 
+                                           HILDON_CAPTION_OPTIONAL);
+
+       if (ppriv->full) {              
+               ppriv->port_view = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
+               entry_caption = hildon_caption_new (size_group, _("mcen_fi_emailsetup_port"), 
+                                                   ppriv->port_view, NULL, 
+                                                   HILDON_CAPTION_OPTIONAL);
+       }
+
+       ppriv->auth_view = gtk_check_button_new ();
+       check_caption = 
+               hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_authentication"),
+                                   ppriv->auth_view, NULL, HILDON_CAPTION_OPTIONAL);
+
+       /* Track changes in UI */       
+       g_signal_connect (G_OBJECT (ppriv->security_view), "changed",
+                         G_CALLBACK (on_security_changed), self);
+
+       /* Pack into container */
+       gtk_box_pack_start (GTK_BOX (self), combo_caption,
+                           FALSE, FALSE, MODEST_MARGIN_HALF);
+       if (ppriv->full)
+               gtk_box_pack_start (GTK_BOX (self), entry_caption, 
+                                   FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (self), check_caption,
+                           FALSE, FALSE, MODEST_MARGIN_HALF);
+
+       /* Show widgets */
+       if (ppriv->full) {
+               gtk_widget_show (ppriv->port_view);
+               gtk_widget_show (entry_caption);
+       }
+       gtk_widget_show (ppriv->security_view);
+       gtk_widget_show (ppriv->auth_view);
+       gtk_widget_show (combo_caption);
+       gtk_widget_show (check_caption);
+}
+
+static void
+on_entry_max (ModestValidatingEntry *self, 
+             gpointer user_data)
+{
+       modest_platform_information_banner (GTK_WIDGET (self), NULL, 
+                                           _CS("ckdg_ib_maximum_characters_reached"));
+}
+
+/*
+ * TODO: call this whenever the auth combo changes. If we set it
+ * explicitely at the beggining to a value then there is no need to
+ * call this handler directly at the beginning
+ */
+static void
+on_entry_changed (GtkEditable *editable, 
+                 gpointer user_data)
+{
+       ModestSecurityOptionsView* self;
+       ModestSecurityOptionsViewPrivate *ppriv;
+       ModestProtocolType auth_proto;
+       ModestSecureauthComboBox *combo;
+       gboolean is_secure, missing;
+       ModestProtocolRegistry *protocol_registry;
+
+       self = MODEST_SECURITY_OPTIONS_VIEW (user_data);
+       ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
+       protocol_registry = modest_runtime_get_protocol_registry ();
+
+       /* Outgoing username is mandatory if outgoing auth is secure */
+       combo = MODEST_SECUREAUTH_COMBO_BOX (ppriv->auth_view);
+       auth_proto = modest_secureauth_combo_box_get_active_secureauth (combo);
+       is_secure = modest_protocol_registry_protocol_type_is_secure (protocol_registry, 
+                                                                     auth_proto);
+
+       if (is_secure && 
+           !g_ascii_strcasecmp (gtk_entry_get_text (GTK_ENTRY (ppriv->user_entry)), "")) {
+               missing = TRUE;
+       } else {
+               missing = FALSE;
+       }
+       
+       /* Emit a signal to notify if mandatory data is missing */
+       g_signal_emit_by_name (G_OBJECT (self), "missing_mandatory_data", 
+                              missing, NULL);
+}
+
+static void
+create_outgoing_security (ModestSecurityOptionsView* self,
+                         GtkSizeGroup *size_group)
+{
+       ModestSecurityOptionsViewPrivate *ppriv;
+       GtkWidget *sec_caption, *auth_caption, *user_caption;
+       GtkWidget *pwd_caption, *port_caption;
+
+       ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
+       
+       /* The secure connection widgets */
+       ppriv->security_view = GTK_WIDGET (modest_serversecurity_combo_box_new ());
+       modest_serversecurity_combo_box_fill (MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view), 
+                                             MODEST_PROTOCOLS_TRANSPORT_SMTP);
+       sec_caption = hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_connection"),
+                                     ppriv->security_view, NULL, HILDON_CAPTION_OPTIONAL);
+       
+       /* The secure authentication widgets */
+       ppriv->auth_view = GTK_WIDGET (modest_secureauth_combo_box_new ());
+       auth_caption = hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_authentication"),
+                                          ppriv->auth_view, NULL, HILDON_CAPTION_OPTIONAL);
+
+       if (ppriv->full) {
+               gchar *user_label;
+
+               /* Username widgets */
+               ppriv->user_entry = GTK_WIDGET (modest_validating_entry_new ());
+
+               /* Auto-capitalization is the default, so let's turn it off: */
+               hildon_gtk_entry_set_input_mode (GTK_ENTRY (ppriv->user_entry), 
+                                                HILDON_GTK_INPUT_MODE_FULL);
+
+               user_label = g_strdup_printf("%s*", _("mail_fi_username"));
+               user_caption = hildon_caption_new (size_group, user_label, 
+                                                  ppriv->user_entry, NULL, 
+                                                  HILDON_CAPTION_MANDATORY);
+               g_free (user_label);
+       
+               /* Prevent the use of some characters. Limit the max
+                  length as well */
+               modest_validating_entry_set_unallowed_characters_whitespace (
+                    MODEST_VALIDATING_ENTRY (ppriv->user_entry));      
+               gtk_entry_set_max_length (GTK_ENTRY (ppriv->user_entry), 64);
+               modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (ppriv->user_entry),
+                                                     on_entry_max, self);
+               
+               /* Password widgets */
+               ppriv->pwd_entry = gtk_entry_new ();
+
+               /* Auto-capitalization is the default, so let's