Move header window to src/widgets
[modest] / src / hildon2 / modest-default-account-settings-dialog.c
index b688662..618173d 100644 (file)
 #include <gtk/gtklabel.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 "modest-secureauth-picker.h"
 #include "widgets/modest-validating-entry.h"
 #include "modest-text-utils.h"
 #include "modest-account-mgr.h"
@@ -56,6 +54,8 @@
 #include "widgets/modest-ui-constants.h"
 #include <tny-account.h>
 #include <tny-status.h>
+#include <modest-scrollable.h>
+#include <modest-toolkit-factory.h>
 
 #include <gconf/gconf-client.h>
 #include <string.h> /* For strlen(). */
@@ -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 *
@@ -201,22 +205,22 @@ on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
 }
 
 static void
-on_modified_checkbutton_toggled (GtkButton *button, gpointer user_data)
+on_modified_checkbutton_toggled (GtkWidget *button, gpointer user_data)
 {
        set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
 }
 
 static void
-on_modified_number_editor_changed (ModestNumberEditor *number_editor, gint new_value, gpointer user_data)
+on_modified_number_entry_changed (GtkWidget *number_entry, gint new_value, gpointer user_data)
 {
        set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
 }
 
 static void       
-on_number_editor_notify (ModestNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
+on_number_entry_notify (GtkWidget *entry, GParamSpec *arg1, gpointer user_data)
 {
        ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
-       gint value = modest_number_editor_get_value (editor);
+       gint value = modest_number_entry_get_value (entry);
 
        gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
 }
@@ -227,10 +231,10 @@ on_number_editor_notify (ModestNumberEditor *editor, GParamSpec *arg1, gpointer
 static void
 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
 {
-       if (MODEST_IS_NUMBER_EDITOR (widget)) {
+       if (modest_is_number_entry (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);
+                       G_CALLBACK (on_modified_number_entry_changed), self);
+               g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_entry_notify), self);
        }
        else if (GTK_IS_ENTRY (widget)) {
                g_signal_connect (G_OBJECT (widget), "changed",
@@ -238,7 +242,7 @@ connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widge
        } else if (HILDON_IS_PICKER_BUTTON (widget)) {
                g_signal_connect (G_OBJECT (widget), "value-changed",
                                  G_CALLBACK (on_modified_picker_changed), self);
-       } else if (HILDON_IS_CHECK_BUTTON (widget)) {
+       } else if (modest_is_togglable (widget)) {
                g_signal_connect (G_OBJECT (widget), "toggled",
                        G_CALLBACK (on_modified_checkbutton_toggled), self);
        }
@@ -263,9 +267,9 @@ create_captioned (ModestDefaultAccountSettingsDialog *self,
 
        GtkWidget *result;
 
-       result = modest_maemo_utils_create_captioned_with_size_type (title_sizegroup, value_sizegroup,
-                                                                    label_text, use_markup, control,
-                                                                    MODEST_EDITABLE_SIZE);
+       result = modest_toolkit_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:
@@ -370,10 +374,8 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self,
        /* The leave-messages widgets: */
        if(!priv->checkbox_leave_messages) {
                priv->checkbox_leave_messages = 
-                       hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
-               gtk_button_set_label (GTK_BUTTON (priv->checkbox_leave_messages),
-                                     _("mcen_fi_advsetup_leave_on_server"));
-               gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_leave_messages), 0.0, 0.5);
+                       modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
+                                                                   _("mcen_fi_advsetup_leave_on_server"));
        }
        connect_for_modified (self, priv->checkbox_leave_messages);
        gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, 0);
@@ -546,7 +548,7 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self,
                on_entry_max, self);
        
        /* The password widgets: */     
-       priv->entry_user_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+       priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
        /* 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);
@@ -614,7 +616,7 @@ update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
        incomingserver_title = g_strconcat(_("mcen_li_emailsetup_servertype"), "*", 
                                           "\n<small>(", protocol_display_name, ")</small>", NULL);
        
-       modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
+       modest_toolkit_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
        g_free (incomingserver_title);
 }
 
@@ -633,7 +635,7 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self,
 
        /* The incoming server widgets: */
        if(!priv->entry_incomingserver)
-               priv->entry_incomingserver = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+               priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
        /* 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);
 
@@ -652,32 +654,35 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self,
 
        /* Incoming security widgets */
        priv->incoming_security =
-               modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
-                                                       TRUE, security_title_sizegroup,
-                                                       security_value_sizegroup);
+               modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
+                                                                    MODEST_SECURITY_OPTIONS_INCOMING,
+                                                                    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);
        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);
 }
 
 static void
-on_check_button_clicked (GtkButton *button, gpointer user_data)
+on_check_button_clicked (GtkWidget *button, gpointer user_data)
 {
        GtkWidget *widget = GTK_WIDGET (user_data);
        
        /* Enable the widget only if the check button is active: */
-       const gboolean enable = hildon_check_button_get_active (HILDON_CHECK_BUTTON (button));
+       const gboolean enable = modest_togglable_get_active (button);
        gtk_widget_set_sensitive (widget, enable);
 }
 
 /* Make the sensitivity of a widget depend on a check button.
  */
 static void
-enable_widget_for_checkbutton (GtkWidget *widget, GtkButton* button)
+enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
 {
        g_signal_connect (G_OBJECT (button), "clicked",
                G_CALLBACK (on_check_button_clicked), widget);
@@ -728,8 +733,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
  
        /* The outgoing server widgets: */
        if (!priv->entry_outgoingserver)
-               priv->entry_outgoingserver = 
-                       hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+               priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
        /* 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);
@@ -743,9 +747,10 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
 
        /* Outgoing security widgets */
        priv->outgoing_security = 
-               modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
-                                                       TRUE, security_title_sizegroup,
-                                                       security_value_sizegroup);
+               modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
+                                                                    MODEST_SECURITY_OPTIONS_OUTGOING,
+                                                                    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);
@@ -759,12 +764,11 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
 
        /* connection-specific checkbox: */
        if (!priv->checkbox_outgoing_smtp_specific) {
-               priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (MODEST_EDITABLE_SIZE);
-               hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific), 
-                       FALSE);
-               gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
-                                     _("mcen_fi_advsetup_connection_smtp"));
-               gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific), 0.0, 0.5);
+               priv->checkbox_outgoing_smtp_specific = 
+                       modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
+                                                                   _("mcen_fi_advsetup_connection_smtp"));
+               modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
+                                            FALSE);
        }
        gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
        gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific, 
@@ -781,7 +785,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
 
        /* Only enable the button when the checkbox is checked: */
        enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers, 
-               GTK_BUTTON (priv->checkbox_outgoing_smtp_specific));
+               priv->checkbox_outgoing_smtp_specific);
 
        g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
                G_CALLBACK (on_button_outgoing_smtp_servers), self);
@@ -790,7 +794,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
 
        return GTK_WIDGET (box);
 }
-       
+
 static gboolean
 check_data (ModestDefaultAccountSettingsDialog *self)
 {
@@ -806,23 +810,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;
 
@@ -831,7 +835,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"));
@@ -1002,7 +1006,7 @@ static void
 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
-       GtkWidget *pannable;
+       GtkWidget *scrollable;
        GtkWidget *separator;
        GtkWidget *align;
        GtkSizeGroup* account_title_sizegroup;
@@ -1071,18 +1075,17 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
                            FALSE, FALSE, 0);
                
        GtkDialog *dialog = GTK_DIALOG (self);
-       pannable = hildon_pannable_area_new ();
-       g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL);
+       scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
 
        align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
        gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
        gtk_widget_show (align);
        gtk_container_add (GTK_CONTAINER (align), priv->main_container);
        
-       hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
-       gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (pannable));
+       modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
+       gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (scrollable));
        gtk_widget_show (GTK_WIDGET (priv->main_container));
-       gtk_widget_show (GTK_WIDGET (pannable));
+       gtk_widget_show (GTK_WIDGET (scrollable));
         
     /* Add the buttons: */
        gtk_dialog_add_button (GTK_DIALOG(self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
@@ -1163,8 +1166,8 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
        gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email), 
                            null_means_empty (modest_account_settings_get_email_address (settings)));
 
-       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages), 
-                                       modest_account_settings_get_leave_messages_on_server (settings));
+       modest_togglable_set_active (priv->checkbox_leave_messages,
+                                    modest_account_settings_get_leave_messages_on_server (settings));
 
        incoming_account = modest_account_settings_get_store_settings (settings);
        if (incoming_account) {
@@ -1241,9 +1244,8 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
 
                const gboolean has_specific = 
                        modest_account_settings_get_use_connection_specific_smtp (settings);
-               hildon_check_button_set_active (
-                       HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific), 
-                       has_specific);
+               modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
+                                            has_specific);
                g_object_unref (outgoing_account);
        }
 
@@ -1302,7 +1304,7 @@ save_configuration (ModestDefaultAccountSettingsDialog *dialog)
                modest_account_settings_set_signature (priv->settings, signature);
        }
 
-       leave_on_server = hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages));
+       leave_on_server = modest_togglable_get_active (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);
@@ -1347,7 +1349,7 @@ save_configuration (ModestDefaultAccountSettingsDialog *dialog)
        /* Save connection-specific SMTP server accounts: */
        modest_account_settings_set_use_connection_specific_smtp 
                (priv->settings, 
-                hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
+                modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
 
        /* this configuration is not persistent, we should not save */
        if (account_name != NULL)