2007-06-05 Murray Cumming <murrayc@murrayc.com>modest/trunk] > more ChangeLog2
[modest] / src / maemo / easysetup / modest-easysetup-wizard.c
index 80e5cbd..f4ae2ca 100644 (file)
@@ -26,7 +26,7 @@
  * 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-easysetup-wizard.h"
 #include <glib/gi18n.h>
@@ -52,6 +52,7 @@
 #include "maemo/modest-connection-specific-smtp-window.h"
 #include "widgets/modest-ui-constants.h"
 #include "maemo/modest-account-settings-dialog.h"
+#include "maemo/modest-maemo-utils.h"
 #include <gconf/gconf-client.h>
 #include <string.h> /* For strlen(). */
 
@@ -69,9 +70,18 @@ G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODE
 
 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
 
+typedef enum {
+       MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
+       MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
+} ModestEasysetupWizardDialogServerChanges;
+
 struct _ModestEasysetupWizardDialogPrivate
 {
        ModestPresets *presets;
+
+       /* Remember what fields the user edited manually to not prefill them
+        * again. */
+       ModestEasysetupWizardDialogServerChanges server_changes;
 };
 
 static void
@@ -560,11 +570,27 @@ static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_dat
        ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
        update_incoming_server_title (self);
        update_incoming_server_security_choices (self);
+
+       set_default_custom_servernames (self);
 }
-           
+
+static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
+{
+       ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
+       ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
+       priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
+}
+
 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
 {
        GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+
+       /* Show note that account type cannot be changed in future: */
+       GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
+       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+       gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
+       gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
+       gtk_widget_show (label);
        
        /* 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.
@@ -605,7 +631,11 @@ static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self
         * as in the UI spec: */
        g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
                          G_CALLBACK (on_combo_servertype_changed), self);
-       
+
+       /* Remember when the servername was changed manually: */
+       g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
+                         G_CALLBACK (on_entry_incoming_servername_changed), self);
+
        /* The secure connection widgets: */    
        if (!self->combo_incoming_security)
                self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
@@ -671,6 +701,13 @@ on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
        gtk_widget_show (self->specific_window);
 }
 
+static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
+{
+       ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
+       ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
+       priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
+}
+
 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
 {
        GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
@@ -746,6 +783,9 @@ static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self
                
        g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
                          G_CALLBACK (on_button_outgoing_smtp_servers), self);
+
+       g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
+                         G_CALLBACK (on_entry_outgoing_servername_changed), self);
        
        
        gtk_widget_show (GTK_WIDGET (box));
@@ -896,8 +936,10 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
        }
        
        g_assert(priv->presets);
-       
-       
+
+       /* The server fields did not have been manually changed yet */
+       priv->server_changes = 0;
+
        /* Get the account manager object, 
         * so we can check for existing accounts,
         * and create new accounts: */
@@ -940,7 +982,7 @@ modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
         */
        g_signal_connect_after (G_OBJECT (self), "response",
                                G_CALLBACK (on_response), self);
-            
+
        /* 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 (
@@ -1080,21 +1122,27 @@ util_get_default_servername_from_email_address (const gchar* email_address, Mode
 
 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
 {
+       ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
+
        if (!account_wizard->entry_incomingserver)
                return;
                
        /* Set a default domain for the server, based on the email address,
         * if no server name was already specified.
         */
-       const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
-       if ((!incoming_existing || (strlen(incoming_existing) == 0)) 
-           && account_wizard->entry_user_email) {
+       if (account_wizard->entry_user_email
+           && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
                const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
                        EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
                const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->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 (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
                gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
+               g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
+
                g_free (servername);
        }
        
@@ -1104,13 +1152,17 @@ static void set_default_custom_servernames (ModestEasysetupWizardDialog *account
        if (!account_wizard->entry_outgoingserver)
                return;
                
-       const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
-       if ((!outgoing_existing || (strlen(outgoing_existing) == 0)) 
-           && account_wizard->entry_user_email) {
+       if (account_wizard->entry_user_email
+           && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
                const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
                
                gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
+
+               /* Do not set the OUTGOING_CHANGED flag because of this edit */
+               g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
                gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
+               g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
+
                g_free (servername);
        }
 }
@@ -1170,6 +1222,36 @@ on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *
        }
        else if (next_page == account_wizard->page_custom_outgoing) {
                set_default_custom_servernames (account_wizard);
+    /* Check if the server support secure authentication */
+    if (gtk_toggle_button_get_active (
+                       GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))) {
+#if 0
+                               const ModestTransportStoreProtocol protocol = 
+          easysetup_servertype_combo_box_get_active_servertype (
+                                                                EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
+        const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
+        /* FIXME: Get correct port */
+
+        int port_num = 22; 
+        GList *list_auth_methods = 
+          modest_maemo_utils_get_supported_secure_authentication_methods (
+                                                                      protocol, 
+                                                                      hostname, port_num, GTK_WINDOW (dialog));        
+        if (list_auth_methods) {
+          /* TODO: Select the correct method */
+          g_list_free (list_auth_methods);
+        }
+        else
+        {
+          GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(dialog),
+                                                       GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
+                                                       GTK_BUTTONS_OK, _("Server does not support secure authentication!"));
+          gtk_dialog_run(GTK_DIALOG(error_dialog));
+          gtk_widget_destroy(error_dialog);
+          return FALSE;
+        }
+#endif
+                }
        }
        
        /* If this is the last page, and this is a click on Finish,