* Fixes NB#86700 select the default region in the accounts wizard dialog by default
[modest] / src / maemo / easysetup / modest-easysetup-wizard-dialog.c
index 51fb83d..eee0903 100644 (file)
@@ -40,6 +40,7 @@
 #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-secureauth-combo-box.h"
 #include "widgets/modest-validating-entry.h"
 #include "modest-text-utils.h"
+#include "modest-conf.h"
 #include "modest-account-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 "maemo/modest-account-settings-dialog.h"
+#include "widgets/modest-account-settings-dialog.h"
 #include "maemo/modest-maemo-utils.h"
 #include "modest-utils.h"
-#include <gconf/gconf-client.h>
-#include <string.h> /* For strlen(). */
 #include "maemo/modest-hildon-includes.h"
 
 /* Include config.h so that _() works: */
@@ -128,8 +128,6 @@ struct _ModestEasysetupWizardDialogPrivate
        GtkWidget *button_outgoing_smtp_servers;
        
        GtkWidget *page_complete_customsetup;
-       
-       GtkWidget *specific_window;
 };
 
 static void save_to_settings (ModestEasysetupWizardDialog *self);
@@ -153,6 +151,22 @@ 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)
 {
@@ -190,9 +204,6 @@ modest_easysetup_wizard_dialog_finalize (GObject *object)
                
        if (priv->presets)
                modest_presets_destroy (priv->presets);
-               
-       if (priv->specific_window)
-               gtk_widget_destroy (priv->specific_window);
 
        if (priv->settings)
                g_object_unref (priv->settings);
@@ -269,7 +280,7 @@ check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
        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), _("Could not discover supported secure authentication methods."));
+               show_error (GTK_WIDGET(self), _("mcen_ib_unableto_discover_auth_methods"));
        }
 
        if(error != NULL)
@@ -448,62 +459,6 @@ on_entry_max (ModestValidatingEntry *self, gpointer user_data)
        show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
 }
 
-static void
-on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
-{
-       /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
-       
-       const gchar *show_char = NULL;
-       if (character)
-         show_char = character;
-       else {
-         /* TODO: We need a logical ID for this: */
-         show_char = _("whitespace");
-       }
-       
-       /* TODO: Should this show just this one bad character or all the not-allowed characters? */
-       gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
-       show_error (GTK_WIDGET (self), message);
-}
-
-static gint
-get_default_country_code(void)
-{
-       /* TODO: Default to the current country somehow.
-        * But I don't know how to get the information that is specified in the
-        * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
-        *
-        * This is probably not the best choice of gconf key:
-        * This is the  "mcc used in the last pairing", ie. the last connection you made.
-        * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
-        *
-        */
-       GError *error = NULL;
-       const gchar* key = "/apps/osso/operator-wizard/last_mcc";
-       gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
-
-       if(mcc_id < 0)
-               mcc_id = 0;
-
-       if (error) {
-               g_warning ("Error getting gconf key %s:\n%s", key, error->message);
-               g_error_free (error);
-               error = NULL;
-
-               mcc_id = 0;
-       }
-
-       /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
-        * This might just be a Maemo bug.
-        */
-       if (mcc_id == 0)
-       {
-               /* For now, we default to Finland when there is nothing better: */
-               mcc_id = 244;
-       }
-       return mcc_id;
-}
-
 static GtkWidget*
 create_page_account_details (ModestEasysetupWizardDialog *self)
 {
@@ -596,7 +551,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),
-                                                                                                                                        on_entry_invalid_character, self);
+                                                                                                                                        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. */
@@ -650,7 +605,7 @@ 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),
-               on_entry_invalid_character, self);
+               modest_maemo_utils_on_entry_invalid_character, self);
        g_list_free (list_prevent);
        
        /* The username widgets: */     
@@ -670,7 +625,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),
-               on_entry_invalid_character, self);
+               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. */
@@ -759,9 +714,6 @@ update_incoming_server_title (ModestEasysetupWizardDialog *self)
                 _("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);
        g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
        g_free(incomingserver_title);
@@ -872,7 +824,7 @@ create_page_custom_incoming (ModestEasysetupWizardDialog *self)
        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_easysetup_changed), self);
+                         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);
@@ -924,22 +876,19 @@ on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
 {
        ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
        ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
+       GtkWidget *specific_window;
        
        /* We set dirty here because setting it depending on the connection specific dialog
        seems overkill */
        priv->dirty = TRUE;
        
        /* Create the window, if necessary: */
-       if (!(priv->specific_window)) {
-               priv->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
-               modest_connection_specific_smtp_window_fill_with_connections (
-                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window), priv->account_manager);
-       }
+       specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
+       modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
 
-       /* Show the window: */
-       gtk_window_set_transient_for (GTK_WINDOW (priv->specific_window), GTK_WINDOW (self));
-       gtk_window_set_modal (GTK_WINDOW (priv->specific_window), TRUE);
-       gtk_widget_show (priv->specific_window);
+       /* Show the window */
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window));
+       gtk_widget_show (specific_window);
 }
 
 static void 
@@ -1164,12 +1113,17 @@ presets_idle (gpointer userdata)
        priv->presets = idle_data->presets;
 
        if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
-               gint mcc = get_default_country_code();
+/*             gint mcc = get_default_country_code(); */
+               gint mcc;
                /* Fill the combo in an idle call, as it takes a lot of time */
                easysetup_country_combo_box_load_data(
                        MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
-               easysetup_country_combo_box_set_active_country_mcc (
-                       MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc);
+/*             easysetup_country_combo_box_set_active_country_mcc ( */
+/*                     MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc); */
+               easysetup_country_combo_box_set_active_country_locale (
+                       MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
+               mcc = easysetup_country_combo_box_get_active_country_mcc (
+                       MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
                easysetup_provider_combo_box_fill (
                        EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
                        priv->presets, mcc);
@@ -1268,7 +1222,6 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
        priv->checkbox_outgoing_smtp_specific = NULL;
        priv->button_outgoing_smtp_servers = NULL;
        priv->page_complete_customsetup = NULL;
-       priv->specific_window = NULL;
 
        /* Add the common pages: */
        gtk_notebook_append_page (notebook, priv->page_welcome, 
@@ -1972,9 +1925,5 @@ save_to_settings (ModestEasysetupWizardDialog *self)
        display_name = get_entered_account_title (self);
        modest_account_settings_set_display_name (priv->settings, display_name);
        g_free (display_name);
-
-       if (priv->specific_window)
-               modest_connection_specific_smtp_window_save_server_accounts (
-                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window));
 }