* Added some coments/mark in all gdk_threads_enter
[modest] / src / maemo / modest-account-settings-dialog.c
index cea9426..5f4fba0 100644 (file)
@@ -255,18 +255,24 @@ static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *
 }
 
 static void
-on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
+on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
 {
-       /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
-       /* We could add a special case for whitespace here 
-       if (character == NULL) ...
-       */
-       /* 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"), character);
+       gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"),
+                                         "\\ / : * ? \" < > | ^");
        show_error (GTK_WIDGET (self), message);
 }
 
 static void
+on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
+{
+       gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"),
+                                         "< >");
+       show_error (GTK_WIDGET (self), message);
+}
+
+
+
+static void
 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
 {
        /* ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data); */
@@ -306,8 +312,7 @@ create_page_account_details (ModestAccountSettingsDialog *self)
        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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
-       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, "|");
@@ -316,7 +321,7 @@ create_page_account_details (ModestAccountSettingsDialog *self)
                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_character, self);
+                                        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. */
@@ -400,14 +405,19 @@ 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:
@@ -421,7 +431,8 @@ create_page_user_details (ModestAccountSettingsDialog *self)
        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;
@@ -430,6 +441,8 @@ create_page_user_details (ModestAccountSettingsDialog *self)
        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 ());
@@ -499,8 +512,13 @@ create_page_user_details (ModestAccountSettingsDialog *self)
                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 (box);
+       return GTK_WIDGET (scrollwin);
 }
 
 /** Change the caption title for the incoming server, 
@@ -585,7 +603,7 @@ static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
        /* The port widgets: */
        /* TODO: There are various rules about this in the UI spec. */
        if (!self->entry_incoming_port)
-               self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
+               self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (1, 65535));
        caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"), 
                self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
        gtk_widget_show (self->entry_incoming_port);
@@ -697,6 +715,7 @@ on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
 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: */
@@ -789,7 +808,7 @@ static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
        
        /* The port widgets: */
        if (!self->entry_outgoing_port)
-               self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
+               self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (1, 65535));
        caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"), 
                self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
        gtk_widget_show (self->entry_outgoing_port);
@@ -834,10 +853,16 @@ static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *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)
 {
@@ -859,7 +884,7 @@ check_data (ModestAccountSettingsDialog *self)
                }
        }
 
-       /* Check that the email address is valud: */
+       /* 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;
@@ -875,8 +900,39 @@ check_data (ModestAccountSettingsDialog *self)
                return FALSE;
        }
 
-       /* Find a suitable authentication method when secure authentication is desired */
+       /* 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: */
+               /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
+               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: */
+               /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
+               hildon_banner_show_information (NULL, 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 */
+
        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));
@@ -929,11 +985,10 @@ check_data (ModestAccountSettingsDialog *self)
                        }
                }
        }
+       
+       
 
-       /* TODO: The UI Spec wants us to check that the servernames are valid, 
-        * but does not specify how.
-        */
-        
+       
        return TRUE;
 }
 /*