Fixes NB#134253, save button active in account settings if incoming port is empty
[modest] / src / hildon2 / modest-default-account-settings-dialog.c
index 1d2da2d..81175d7 100644 (file)
@@ -138,6 +138,10 @@ enable_buttons (ModestDefaultAccountSettingsDialog *self);
 static gboolean
 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
 
+static void on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
+                                      gboolean missing,
+                                      gpointer user_data);
+
 static const gchar * null_means_empty (const gchar * str);
 
 static const gchar *
@@ -263,8 +267,9 @@ create_captioned (ModestDefaultAccountSettingsDialog *self,
 
        GtkWidget *result;
 
-       result = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
-                                                     label_text, use_markup, control);
+       result = modest_maemo_utils_create_captioned_with_size_type (title_sizegroup, value_sizegroup,
+                                                                    label_text, use_markup, control,
+                                                                    MODEST_EDITABLE_SIZE);
 
        /* Connect to the appropriate changed signal for the widget, 
         * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
@@ -315,18 +320,16 @@ on_entry_max (ModestValidatingEntry *self, gpointer user_data)
 }
 
 static GtkWidget*
-create_page_account_details (ModestDefaultAccountSettingsDialog *self)
+create_page_account_details (ModestDefaultAccountSettingsDialog *self, 
+                            GtkSizeGroup *title_sizegroup,
+                            GtkSizeGroup *value_sizegroup)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *box;
-       GtkSizeGroup* title_sizegroup;
-       GtkSizeGroup* value_sizegroup;
        GtkWidget *hbox;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
        box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-       value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
            
        /* The description widgets: */  
        priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
@@ -380,9 +383,6 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
        gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, 0);
        gtk_widget_show (priv->checkbox_leave_messages);
 
-       g_object_unref (title_sizegroup);
-       g_object_unref (value_sizegroup);
-       
        gtk_widget_show (GTK_WIDGET (box));
        
        return GTK_WIDGET (box);
@@ -480,18 +480,16 @@ delete_button_clicked (ModestDefaultAccountSettingsDialog *self)
 }
 
 static GtkWidget*
-create_page_user_details (ModestDefaultAccountSettingsDialog *self)
+create_page_user_details (ModestDefaultAccountSettingsDialog *self,
+                         GtkSizeGroup *title_sizegroup,
+                         GtkSizeGroup *value_sizegroup)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *box;
-       GtkSizeGroup* title_sizegroup;
-       GtkSizeGroup* value_sizegroup;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
 
        box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-       value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
  
        /* The name widgets: */
        priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
@@ -596,9 +594,6 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
                                                                RESPONSE_SIGNATURE_DUMMY);
        gtk_widget_show (priv->button_signature);
 
-       g_object_unref (title_sizegroup);
-       g_object_unref (value_sizegroup);
-
        gtk_widget_show (GTK_WIDGET (box));
 
        return GTK_WIDGET (box);
@@ -627,23 +622,19 @@ update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
        g_free (incomingserver_title);
 }
 
-static GtkWidget* 
-create_page_incoming (ModestDefaultAccountSettingsDialog *self)
+/* The size groups passed as arguments are only used by the security settings */
+static GtkWidget*
+create_page_incoming (ModestDefaultAccountSettingsDialog *self,
+                     GtkSizeGroup *security_title_sizegroup,
+                     GtkSizeGroup *security_value_sizegroup)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *box;
-       GtkSizeGroup *title_sizegroup;
-       GtkSizeGroup *value_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. */
-       title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-       value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-        
+       box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+
        /* The incoming server widgets: */
        if(!priv->entry_incomingserver)
                priv->entry_incomingserver = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
@@ -652,11 +643,11 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self)
 
        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_captioned (self, title_sizegroup, value_sizegroup,
+       priv->caption_incoming = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
                                                   "Incoming Server", FALSE, priv->entry_incomingserver);
        gtk_widget_show (priv->entry_incomingserver);
        connect_for_modified (self, priv->entry_incomingserver);
@@ -664,18 +655,18 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self)
        gtk_widget_show (priv->caption_incoming);
 
        /* Incoming security widgets */
-       priv->incoming_security = 
+       priv->incoming_security =
                modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
-                                                       TRUE, title_sizegroup, value_sizegroup);
-       gtk_box_pack_start (GTK_BOX (box), priv->incoming_security, 
+                                                       TRUE, security_title_sizegroup,
+                                                       security_value_sizegroup);
+       gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
                            FALSE, FALSE, 0);
 
        gtk_widget_show (priv->incoming_security);
-
-       g_object_unref (title_sizegroup);       
-       g_object_unref (value_sizegroup);       
        gtk_widget_show (GTK_WIDGET (box));
-       
+       g_signal_connect (priv->incoming_security, "missing-mandatory-data",
+                         G_CALLBACK (on_missing_mandatory_data), self);
+
        return GTK_WIDGET (box);
 }
 
@@ -730,20 +721,16 @@ on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
                                           !missing);
 }
 
-static GtkWidget* 
-create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
+static GtkWidget*
+create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
+                     GtkSizeGroup *security_title_sizegroup,
+                     GtkSizeGroup *security_value_sizegroup)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        gchar *smtp_caption_label;
        GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (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 *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-       GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
  
        /* The outgoing server widgets: */
        if (!priv->entry_outgoingserver)
@@ -752,7 +739,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        /* 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);
        smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
-       GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
+       GtkWidget *caption = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
                                               smtp_caption_label, TRUE, priv->entry_outgoingserver);
        g_free (smtp_caption_label);
        gtk_widget_show (priv->entry_outgoingserver);
@@ -763,7 +750,8 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        /* Outgoing security widgets */
        priv->outgoing_security = 
                modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
-                                                       TRUE, title_sizegroup, value_sizegroup);
+                                                       TRUE, security_title_sizegroup,
+                                                       security_value_sizegroup);
        gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security, 
                            FALSE, FALSE, 0);
        gtk_widget_show (priv->outgoing_security);
@@ -772,6 +760,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
 
        GtkWidget *separator = gtk_hseparator_new ();
        gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
+       hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
        gtk_widget_show (separator);
 
        /* connection-specific checkbox: */
@@ -800,9 +789,6 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers, 
                GTK_BUTTON (priv->checkbox_outgoing_smtp_specific));
 
-       g_object_unref (title_sizegroup);
-       g_object_unref (value_sizegroup);
-
        g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
                G_CALLBACK (on_button_outgoing_smtp_servers), self);
 
@@ -810,7 +796,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
 
        return GTK_WIDGET (box);
 }
-       
+
 static gboolean
 check_data (ModestDefaultAccountSettingsDialog *self)
 {
@@ -826,23 +812,23 @@ check_data (ModestDefaultAccountSettingsDialog *self)
        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) {
+
+       if (g_strcmp0 (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;
 
@@ -851,7 +837,7 @@ check_data (ModestDefaultAccountSettingsDialog *self)
        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"));
@@ -1025,6 +1011,9 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
        GtkWidget *pannable;
        GtkWidget *separator;
        GtkWidget *align;
+       GtkSizeGroup* account_title_sizegroup;
+       GtkSizeGroup* account_value_sizegroup;
+       GtkSizeGroup *sec_title_sizegroup, *sec_value_sizegroup;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
 
@@ -1040,16 +1029,28 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
        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);
+       /* Create the common pages */
+       account_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       account_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       priv->page_account_details = create_page_account_details (self, account_title_sizegroup, account_value_sizegroup);
+       priv->page_user_details = create_page_user_details (self, account_title_sizegroup, account_value_sizegroup);
+       g_object_unref (account_title_sizegroup);
+       g_object_unref (account_value_sizegroup);
        
+
+       /* Create size groups for security settings */
+       sec_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       sec_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+       /* Create incoming and outgoing "pages" */
+       priv->page_incoming = create_page_incoming (self, sec_title_sizegroup, sec_value_sizegroup);
+       priv->page_outgoing = create_page_outgoing (self, sec_title_sizegroup, sec_value_sizegroup);
+       g_object_unref (sec_title_sizegroup);
+       g_object_unref (sec_value_sizegroup);
+
        /* Add the notebook pages: */
        gtk_box_pack_start (GTK_BOX (priv->main_container),
                            priv->page_account_details,
@@ -1059,6 +1060,7 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
                            FALSE, FALSE, 0);
 
        separator = gtk_hseparator_new ();
+       hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
        gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
                            FALSE, FALSE, MODEST_MARGIN_DEFAULT);
        gtk_widget_show (separator);
@@ -1066,6 +1068,7 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
                            priv->page_incoming,
                            FALSE, FALSE, 0);
        separator = gtk_hseparator_new ();
+       hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
        gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
                            FALSE, FALSE, MODEST_MARGIN_DEFAULT);
        gtk_widget_show (separator);