Dispose list store in folder view on disposing it.
[modest] / src / hildon2 / modest-maemo-security-options-view.c
index 62867f6..4b6ffa6 100644 (file)
 #define PORT_MIN 1
 #define PORT_MAX 65535
 
+typedef struct _ModestMaemoSecurityOptionsViewPrivate ModestMaemoSecurityOptionsViewPrivate;
+struct _ModestMaemoSecurityOptionsViewPrivate {
+       gboolean missing_data;
+};
+
+#define MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE(o) \
+       (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                    MODEST_TYPE_MAEMO_SECURITY_OPTIONS_VIEW, \
+                                    ModestMaemoSecurityOptionsViewPrivate))
+
 static void modest_maemo_security_options_view_init (ModestMaemoSecurityOptionsView *obj);
 static void modest_maemo_security_options_view_finalize (GObject *obj);
 static void modest_maemo_security_options_view_class_init (ModestMaemoSecurityOptionsViewClass *klass);
@@ -141,44 +151,39 @@ create_incoming_security (ModestSecurityOptionsView* self,
                                                                             HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
        modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (ppriv->security_view), 
                                           modest_protocol_registry_get_pop_type_id ());
-       modest_maemo_utils_set_hbutton_layout (title_size_group, 
+       modest_maemo_utils_set_hbutton_layout (title_size_group,
                                               value_size_group,
                                               _("mcen_li_emailsetup_secure_connection"), 
                                               ppriv->security_view);
 
-       if (ppriv->full) {              
-               ppriv->port_view = GTK_WIDGET (modest_number_editor_new (PORT_MIN, PORT_MAX));
-               entry_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                    value_size_group,
-                                                                    _("mcen_fi_emailsetup_port"), 
-                                                                    FALSE,
-                                                                    ppriv->port_view);
-       }
-
        ppriv->auth_view = hildon_check_button_new (MODEST_EDITABLE_SIZE);
        gtk_button_set_label (GTK_BUTTON (ppriv->auth_view), _("mcen_li_emailsetup_secure_authentication"));
        gtk_button_set_alignment (GTK_BUTTON (ppriv->auth_view), 0.0, 0.5);
 
-       /* Track changes in UI */       
+       /* Track changes in UI */
        g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
                          G_CALLBACK (on_security_changed), self);
 
-       /* Pack into container */
-       gtk_box_pack_start (GTK_BOX (self), ppriv->security_view,
-                           FALSE, FALSE, MODEST_MARGIN_HALF);
-       if (ppriv->full)
-               gtk_box_pack_start (GTK_BOX (self), entry_caption, 
-                                   FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view,
-                           FALSE, FALSE, MODEST_MARGIN_HALF);
+       /* Pack into container & show */
+       gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
+       gtk_widget_show (ppriv->security_view);
+       gtk_widget_show (ppriv->auth_view);
 
-       /* Show widgets */
        if (ppriv->full) {
+               ppriv->port_view = GTK_WIDGET (modest_number_editor_new (PORT_MIN, PORT_MAX));
+               entry_caption =
+                       modest_maemo_utils_create_captioned_with_size_type (title_size_group,
+                                                                           value_size_group,
+                                                                           _("mcen_fi_emailsetup_port"),
+                                                                           FALSE,
+                                                                           ppriv->port_view,
+                                                                           MODEST_EDITABLE_SIZE);
+               /* Pack & show widgets */
+               gtk_box_pack_start (GTK_BOX (self), entry_caption, FALSE, FALSE, 0);
                gtk_widget_show (ppriv->port_view);
                gtk_widget_show (entry_caption);
        }
-       gtk_widget_show (ppriv->security_view);
-       gtk_widget_show (ppriv->auth_view);
 }
 
 static void
@@ -199,32 +204,47 @@ on_entry_changed (GtkEditable *editable,
                  gpointer user_data)
 {
        ModestSecurityOptionsView* self;
+       ModestMaemoSecurityOptionsViewPrivate *priv;
        ModestSecurityOptionsViewPrivate *ppriv;
        ModestProtocolType auth_proto;
        ModestSecureauthPicker *picker;
-       gboolean is_secure, missing;
+       gboolean is_secure;
        ModestProtocolRegistry *protocol_registry;
 
        self = MODEST_SECURITY_OPTIONS_VIEW (user_data);
+       priv = MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
        protocol_registry = modest_runtime_get_protocol_registry ();
 
        /* Outgoing username is mandatory if outgoing auth is secure */
        picker = MODEST_SECUREAUTH_PICKER (ppriv->auth_view);
        auth_proto = modest_secureauth_picker_get_active_secureauth (picker);
-       is_secure = modest_protocol_registry_protocol_type_is_secure (protocol_registry, 
+       is_secure = modest_protocol_registry_protocol_type_is_secure (protocol_registry,
                                                                      auth_proto);
 
-       if (is_secure && 
+       if (is_secure &&
            !g_ascii_strcasecmp (hildon_entry_get_text (HILDON_ENTRY (ppriv->user_entry)), "")) {
-               missing = TRUE;
+               priv->missing_data = TRUE;
        } else {
-               missing = FALSE;
+               priv->missing_data = FALSE;
        }
-       
+
+       if (!priv->missing_data &&
+           ppriv->full &&
+           !modest_number_editor_is_valid (MODEST_NUMBER_EDITOR (ppriv->port_view)))
+               priv->missing_data = TRUE;
+
        /* Emit a signal to notify if mandatory data is missing */
-       g_signal_emit_by_name (G_OBJECT (self), "missing_mandatory_data", 
-                              missing, NULL);
+       g_signal_emit_by_name (G_OBJECT (self), "missing_mandatory_data",
+                              priv->missing_data, NULL);
+}
+
+void
+on_valid_changed (ModestNumberEditor *editor,
+                 gboolean valid,
+                 ModestSecurityOptionsView *self)
+{
+       on_entry_changed (NULL, (gpointer) self);
 }
 
 static void
@@ -267,11 +287,12 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                                 HILDON_GTK_INPUT_MODE_FULL);
 
                user_label = g_strdup_printf("%s*", _("mail_fi_username"));
-               user_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                   value_size_group,
-                                                                   user_label,
-                                                                   FALSE,
-                                                                   ppriv->user_entry);
+               user_caption = modest_maemo_utils_create_captioned_with_size_type (title_size_group,
+                                                                                  value_size_group,
+                                                                                  user_label,
+                                                                                  FALSE,
+                                                                                  ppriv->user_entry,
+                                                                                  MODEST_EDITABLE_SIZE);
                g_free (user_label);
        
                /* Prevent the use of some characters. Limit the max
@@ -291,18 +312,22 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                                 HILDON_GTK_INPUT_MODE_INVISIBLE);
                gtk_entry_set_visibility (GTK_ENTRY (ppriv->pwd_entry), FALSE);
 
-               pwd_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                  value_size_group,
-                                                                  _("mail_fi_password"), 
-                                                                  FALSE,
-                                                                  ppriv->pwd_entry);
+               pwd_caption =
+                       modest_maemo_utils_create_captioned_with_size_type (title_size_group,
+                                                                           value_size_group,
+                                                                           _("mail_fi_password"),
+                                                                           FALSE,
+                                                                           ppriv->pwd_entry,
+                                                                           MODEST_EDITABLE_SIZE);
 
                ppriv->port_view = GTK_WIDGET (modest_number_editor_new (PORT_MIN, PORT_MAX));
-               port_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                   value_size_group,
-                                                                   _("mcen_fi_emailsetup_port"), 
-                                                                   FALSE,
-                                                                   ppriv->port_view);
+               port_caption =
+                       modest_maemo_utils_create_captioned_with_size_type (title_size_group,
+                                                                           value_size_group,
+                                                                           _("mcen_fi_emailsetup_port"),
+                                                                           FALSE,
+                                                                           ppriv->port_view,
+                                                                           MODEST_EDITABLE_SIZE);
        }
 
        /* Track changes in UI */       
@@ -313,6 +338,8 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                  G_CALLBACK (on_auth_changed), self);
                g_signal_connect (G_OBJECT (ppriv->user_entry), "changed",
                                  G_CALLBACK (on_entry_changed), self);
+               g_signal_connect (G_OBJECT (ppriv->port_view), "valid-changed",
+                                           G_CALLBACK (on_valid_changed), self);
        }
 
        /* Initialize widgets */
@@ -325,15 +352,14 @@ create_outgoing_security (ModestSecurityOptionsView* self,
 
        /* Pack into container */
        if (ppriv->full) {
-               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), user_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), pwd_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), port_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), user_caption, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), pwd_caption, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), port_caption, FALSE, FALSE, 0);
        } else {
-               /* The order is different */
-               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
        }
 
        /* Show widgets */
@@ -372,8 +398,18 @@ modest_maemo_security_options_view_new  (ModestSecurityOptionsType type,
        return (GtkWidget *) self;
 }
 
-static void 
-modest_maemo_security_options_view_load_settings (ModestSecurityOptionsView* self, 
+gboolean
+modest_security_options_view_has_missing_mandatory_data (ModestSecurityOptionsView* self)
+{
+       ModestMaemoSecurityOptionsViewPrivate *priv;
+
+       priv = MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
+
+       return priv->missing_data;
+}
+
+static void
+modest_maemo_security_options_view_load_settings (ModestSecurityOptionsView* self,
                                                  ModestAccountSettings *settings)
 {
        ModestSecurityOptionsViewPrivate *ppriv;
@@ -479,6 +515,7 @@ modest_maemo_security_options_view_class_init (ModestMaemoSecurityOptionsViewCla
 
        modest_maemo_security_options_view_parent_class = g_type_class_peek_parent (klass);
 
+       g_type_class_add_private (gobject_class, sizeof (ModestMaemoSecurityOptionsViewPrivate));
        gobject_class->finalize = modest_maemo_security_options_view_finalize;
 
        MODEST_SECURITY_OPTIONS_VIEW_CLASS (klass)->load_settings =