1a0a15c653209da2496a13b3bfde32af9b536eac
[modest] / src / hildon2 / modest-maemo-security-options-view.c
1 /* Copyright (c) 2008, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "modest-runtime.h"
31 #include "modest-security-options-view-priv.h"
32 #include "modest-maemo-security-options-view.h"
33 #include "modest-text-utils.h"
34 #include "modest-platform.h"
35 #include "modest-account-protocol.h"
36 #include "widgets/modest-ui-constants.h"
37 #include "widgets/modest-validating-entry.h"
38 #include "modest-maemo-utils.h"
39 #include "modest-hildon-includes.h"
40 #include <modest-toolkit-factory.h>
41 #include <modest-toolkit-utils.h>
42
43 #define PORT_MIN 1
44 #define PORT_MAX 65535
45
46 typedef struct _ModestMaemoSecurityOptionsViewPrivate ModestMaemoSecurityOptionsViewPrivate;
47 struct _ModestMaemoSecurityOptionsViewPrivate {
48         gboolean missing_data;
49 };
50
51 #define MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE(o) \
52         (G_TYPE_INSTANCE_GET_PRIVATE((o), \
53                                      MODEST_TYPE_MAEMO_SECURITY_OPTIONS_VIEW, \
54                                      ModestMaemoSecurityOptionsViewPrivate))
55
56 static void modest_maemo_security_options_view_init (ModestMaemoSecurityOptionsView *obj);
57 static void modest_maemo_security_options_view_finalize (GObject *obj);
58 static void modest_maemo_security_options_view_class_init (ModestMaemoSecurityOptionsViewClass *klass);
59
60 G_DEFINE_TYPE (ModestMaemoSecurityOptionsView, 
61                modest_maemo_security_options_view, 
62                MODEST_TYPE_SECURITY_OPTIONS_VIEW);
63
64 static void on_entry_changed (GtkEditable *editable, gpointer user_data);
65
66 #ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
67 static void on_valid_changed (ModestNumberEditor *editor, gboolean valid, ModestSecurityOptionsView *self);
68 #endif
69
70 /* Tracks changes in the incoming security picker */
71 static void
72 on_security_changed (GtkWidget *widget, 
73                      ModestMaemoSecurityOptionsView *self)
74 {
75         ModestSecurityOptionsViewPrivate* ppriv;
76         ModestProtocolType proto_type;
77         ModestProtocolRegistry *proto_registry;
78         gboolean is_secure;
79
80         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
81
82         proto_registry = modest_runtime_get_protocol_registry ();
83         proto_type = modest_serversecurity_selector_get_active_serversecurity (ppriv->security_view);
84
85         is_secure = modest_protocol_registry_protocol_type_has_tag (proto_registry, proto_type, 
86                                                                     MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS);
87
88         if (MODEST_SECURITY_OPTIONS_VIEW (self)->type == MODEST_SECURITY_OPTIONS_INCOMING) {
89                 /* Activate and dim checkbutton if it's secure */
90                 modest_togglable_set_active (ppriv->auth_view,
91                                              is_secure);
92                 gtk_widget_set_sensitive (ppriv->auth_view, !is_secure);
93         } else {
94
95         }
96
97         if (ppriv->full) {
98                 gint port_number = 
99                         modest_serversecurity_selector_get_active_serversecurity_port (ppriv->security_view);
100                 
101                 if(port_number) {
102                         modest_number_entry_set_value (ppriv->port_view,
103                                                        port_number);
104                 }
105         }
106 }
107
108 static void
109 on_auth_changed (GtkWidget *widget, 
110                  ModestMaemoSecurityOptionsView *self)
111 {
112         ModestSecurityOptionsViewPrivate* ppriv;
113         ModestProtocolRegistry *protocol_registry;
114         ModestProtocolType auth_proto;
115         gboolean secureauth_used;
116         GtkWidget *user_caption, *pwd_caption;
117
118         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
119         protocol_registry = modest_runtime_get_protocol_registry ();
120
121         auth_proto = modest_secureauth_selector_get_active_secureauth (ppriv->auth_view);
122         secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, 
123                                                                             auth_proto);
124
125         /* Get captions, well dimm the whole widget */
126         user_caption = gtk_widget_get_parent (ppriv->user_entry);
127         pwd_caption = gtk_widget_get_parent (ppriv->pwd_entry);
128         
129         /* Enable / disable */
130         gtk_widget_set_sensitive (user_caption, secureauth_used);
131         gtk_widget_set_sensitive (pwd_caption, secureauth_used);
132
133         /* Check if mandatory data is missing */
134         on_entry_changed (GTK_EDITABLE (ppriv->user_entry), (gpointer) self);
135 }
136
137 static void
138 create_incoming_security (ModestSecurityOptionsView* self,
139                           GtkSizeGroup *title_size_group,
140                           GtkSizeGroup *value_size_group)
141 {
142         ModestSecurityOptionsViewPrivate *ppriv;
143         GtkWidget *entry_caption = NULL;
144
145         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
146
147         ppriv->auth_view = modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
148                                                                        _("mcen_li_emailsetup_secure_authentication"));
149         gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
150
151         /* Create widgets for incoming security */
152         ppriv->security_view = modest_toolkit_factory_create_serversecurity_selector (modest_runtime_get_toolkit_factory ());
153         modest_serversecurity_selector_fill (ppriv->security_view,
154                                              modest_protocol_registry_get_pop_type_id ());
155         if (GTK_IS_COMBO_BOX (ppriv->security_view)) {
156                 GtkWidget *captioned;
157
158                 captioned = modest_toolkit_utils_create_captioned (title_size_group, value_size_group,
159                                                                    _("mcen_li_emailsetup_secure_connection"), FALSE,
160                                                                    ppriv->security_view);
161                 g_signal_connect (G_OBJECT (ppriv->security_view), "changed",
162                                   G_CALLBACK (on_security_changed), self);
163                 gtk_box_pack_start (GTK_BOX (self), captioned, FALSE, FALSE, 0);
164                 gtk_widget_show (captioned);
165         } else {
166                 modest_toolkit_utils_set_hbutton_layout (title_size_group,
167                                                          value_size_group,
168                                                          _("mcen_li_emailsetup_secure_connection"), 
169                                                          ppriv->security_view);
170                 g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
171                                   G_CALLBACK (on_security_changed), self);
172                 gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
173         }
174
175         /* Pack into container & show */
176         gtk_widget_show (ppriv->security_view);
177         gtk_widget_show (ppriv->auth_view);
178
179         if (ppriv->full) {
180                 ppriv->port_view = modest_toolkit_factory_create_number_entry (modest_runtime_get_toolkit_factory (),
181                                                                                PORT_MIN, PORT_MAX);
182                 entry_caption =
183                         modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
184                                                                               value_size_group,
185                                                                               _("mcen_fi_emailsetup_port"),
186                                                                               FALSE,
187                                                                               ppriv->port_view,
188                                                                               MODEST_EDITABLE_SIZE);
189                 /* Pack & show widgets */
190                 gtk_box_pack_start (GTK_BOX (self), entry_caption, FALSE, FALSE, 0);
191                 gtk_widget_show (ppriv->port_view);
192                 gtk_widget_show (entry_caption);
193
194                 /* Track changes in UI */
195 #ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
196                 g_signal_connect (G_OBJECT (ppriv->port_view), "valid-changed",
197                                             G_CALLBACK (on_valid_changed), self);
198 #endif
199         }
200 }
201
202 static void
203 on_entry_max (ModestValidatingEntry *self, 
204               gpointer user_data)
205 {
206         modest_platform_information_banner (GTK_WIDGET (self), NULL, 
207                                             _CS("ckdg_ib_maximum_characters_reached"));
208 }
209
210 /*
211  * TODO: call this whenever the auth picker changes. If we set it
212  * explicitely at the beggining to a value then there is no need to
213  * call this handler directly at the beginning
214  */
215 static void
216 on_entry_changed (GtkEditable *editable, 
217                   gpointer user_data)
218 {
219         ModestSecurityOptionsView* self;
220         ModestMaemoSecurityOptionsViewPrivate *priv;
221         ModestSecurityOptionsViewPrivate *ppriv;
222         gboolean is_secure = FALSE;
223         ModestProtocolRegistry *protocol_registry;
224
225         self = MODEST_SECURITY_OPTIONS_VIEW (user_data);
226         priv = MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
227         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
228         protocol_registry = modest_runtime_get_protocol_registry ();
229
230         /* Check if it's a secure protocol */
231         if (modest_is_secureauth_selector (ppriv->auth_view)) {
232                 ModestProtocolType auth_proto;
233                 auth_proto = modest_secureauth_selector_get_active_secureauth (ppriv->auth_view);
234                 is_secure = modest_protocol_registry_protocol_type_is_secure (protocol_registry,
235                                                                               auth_proto);
236         } else if (modest_is_togglable (ppriv->auth_view)) {
237                 is_secure = modest_togglable_get_active (ppriv->auth_view);
238         }
239
240         if (is_secure &&
241             !g_strcmp0 (modest_entry_get_text (ppriv->user_entry), "")) {
242                 priv->missing_data = TRUE;
243         } else {
244                 priv->missing_data = FALSE;
245         }
246
247         if (!priv->missing_data &&
248             ppriv->full &&
249             !modest_number_entry_is_valid (ppriv->port_view))
250                 priv->missing_data = TRUE;
251
252         /* Emit a signal to notify if mandatory data is missing */
253         g_signal_emit_by_name (G_OBJECT (self), "missing_mandatory_data",
254                                priv->missing_data, NULL);
255 }
256
257 #ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
258 static void
259 on_valid_changed (ModestNumberEditor *editor,
260                   gboolean valid,
261                   ModestSecurityOptionsView *self)
262 {
263         on_entry_changed (NULL, (gpointer) self);
264 }
265 #endif
266
267 static void
268 create_outgoing_security (ModestSecurityOptionsView* self,
269                           GtkSizeGroup *title_size_group,
270                           GtkSizeGroup *value_size_group)
271 {
272         ModestSecurityOptionsViewPrivate *ppriv;
273         GtkWidget *user_caption = NULL, *security_caption = NULL, *auth_caption = NULL;
274         GtkWidget *pwd_caption = NULL, *port_caption = NULL;
275
276         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
277         
278         /* The secure connection widgets */
279         ppriv->security_view = modest_toolkit_factory_create_serversecurity_selector (modest_runtime_get_toolkit_factory ());
280         modest_serversecurity_selector_fill (ppriv->security_view,
281                                               MODEST_PROTOCOLS_TRANSPORT_SMTP);
282         if (GTK_IS_COMBO_BOX (ppriv->security_view)) {
283                 security_caption = modest_toolkit_utils_create_captioned (title_size_group, value_size_group,
284                                                                           _("mcen_li_emailsetup_secure_connection"), FALSE,
285                                                                           ppriv->security_view);
286                 gtk_widget_show (security_caption);
287         } else {
288                 modest_toolkit_utils_set_hbutton_layout (title_size_group,
289                                                          value_size_group,
290                                                          _("mcen_li_emailsetup_secure_connection"), 
291                                                          ppriv->security_view);
292                 security_caption = ppriv->security_view;
293         }
294         
295         /* The secure authentication widgets */
296         ppriv->auth_view = modest_toolkit_factory_create_secureauth_selector (modest_runtime_get_toolkit_factory ());
297         if (GTK_IS_COMBO_BOX (ppriv->auth_view)) {
298                 auth_caption = modest_toolkit_utils_create_captioned (title_size_group, value_size_group,
299                                                                       _("mcen_li_emailsetup_secure_authentication"), FALSE,
300                                                                       ppriv->auth_view);
301                 gtk_widget_show (auth_caption);
302         } else {
303                 modest_toolkit_utils_set_hbutton_layout (title_size_group,
304                                                          value_size_group,
305                                                          _("mcen_li_emailsetup_secure_authentication"), 
306                                                          ppriv->auth_view);
307                 auth_caption = ppriv->auth_view;
308         }
309
310         if (ppriv->full) {
311                 gchar *user_label;
312
313                 /* Username widgets */
314                 ppriv->user_entry = GTK_WIDGET (modest_validating_entry_new ());
315
316                 /* Auto-capitalization is the default, so let's turn it off: */
317 #ifdef MODEST_TOOLKIT_HILDON2
318                 hildon_gtk_entry_set_input_mode (GTK_ENTRY (ppriv->user_entry), 
319                                                  HILDON_GTK_INPUT_MODE_FULL);
320 #endif
321
322                 user_label = g_strdup_printf("%s*", _("mail_fi_username"));
323                 user_caption = modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
324                                                                                      value_size_group,
325                                                                                      user_label,
326                                                                                      FALSE,
327                                                                                      ppriv->user_entry,
328                                                                                      MODEST_EDITABLE_SIZE);
329                 g_free (user_label);
330         
331                 /* Prevent the use of some characters. Limit the max
332                    length as well */
333                 modest_validating_entry_set_unallowed_characters_whitespace (
334                      MODEST_VALIDATING_ENTRY (ppriv->user_entry));      
335                 gtk_entry_set_max_length (GTK_ENTRY (ppriv->user_entry), 64);
336                 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (ppriv->user_entry),
337                                                       on_entry_max, self);
338                 
339                 /* Password widgets */
340                 ppriv->pwd_entry = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
341
342                 /* Auto-capitalization is the default, so let's turn it off */
343 #ifdef MODEST_TOOLKIT_HILDON2
344                 hildon_gtk_entry_set_input_mode (GTK_ENTRY (ppriv->pwd_entry),
345                                                  HILDON_GTK_INPUT_MODE_FULL | 
346                                                  HILDON_GTK_INPUT_MODE_INVISIBLE);
347 #endif
348                 gtk_entry_set_visibility (GTK_ENTRY (ppriv->pwd_entry), FALSE);
349
350                 pwd_caption =
351                         modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
352                                                                               value_size_group,
353                                                                               _("mail_fi_password"),
354                                                                               FALSE,
355                                                                               ppriv->pwd_entry,
356                                                                               MODEST_EDITABLE_SIZE);
357
358                 ppriv->port_view = modest_toolkit_factory_create_number_entry (modest_runtime_get_toolkit_factory (),
359                                                                                PORT_MIN, PORT_MAX);
360                 port_caption =
361                         modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
362                                                                               value_size_group,
363                                                                               _("mcen_fi_emailsetup_port"),
364                                                                               FALSE,
365                                                                               ppriv->port_view,
366                                                                               MODEST_EDITABLE_SIZE);
367         }
368
369         /* Track changes in UI */
370         if (GTK_IS_COMBO_BOX (ppriv->security_view)) {
371                 g_signal_connect (G_OBJECT (ppriv->security_view), "changed",
372                                   G_CALLBACK (on_security_changed), self);
373         } else {
374                 g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
375                                   G_CALLBACK (on_security_changed), self);
376         }
377         if (ppriv->full) {
378                 if (GTK_IS_COMBO_BOX (ppriv->auth_view)) {
379                         g_signal_connect (G_OBJECT (ppriv->auth_view), "changed",
380                                           G_CALLBACK (on_auth_changed), self);
381                 } else {
382                         g_signal_connect (G_OBJECT (ppriv->auth_view), "value-changed",
383                                           G_CALLBACK (on_auth_changed), self);
384                 }
385                 g_signal_connect (G_OBJECT (ppriv->user_entry), "changed",
386                                   G_CALLBACK (on_entry_changed), self);
387 #ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
388                 g_signal_connect (G_OBJECT (ppriv->port_view), "valid-changed",
389                                             G_CALLBACK (on_valid_changed), self);
390 #endif
391         }
392
393         /* Initialize widgets */
394         modest_serversecurity_selector_set_active_serversecurity (
395                 ppriv->security_view,
396                 MODEST_PROTOCOLS_CONNECTION_NONE);
397         modest_secureauth_selector_set_active_secureauth (
398            ppriv->auth_view,
399            MODEST_PROTOCOLS_AUTH_NONE);
400
401         /* Pack into container */
402         if (ppriv->full) {
403                 gtk_box_pack_start (GTK_BOX (self), auth_caption, FALSE, FALSE, 0);
404                 gtk_box_pack_start (GTK_BOX (self), user_caption, FALSE, FALSE, 0);
405                 gtk_box_pack_start (GTK_BOX (self), pwd_caption, FALSE, FALSE, 0);
406                 gtk_box_pack_start (GTK_BOX (self), security_caption, FALSE, FALSE, 0);
407                 gtk_box_pack_start (GTK_BOX (self), port_caption, FALSE, FALSE, 0);
408         } else {
409                 gtk_box_pack_start (GTK_BOX (self), auth_caption, FALSE, FALSE, 0);
410                 gtk_box_pack_start (GTK_BOX (self), security_caption, FALSE, FALSE, 0);
411         }
412
413         /* Show widgets */
414         if (ppriv->full) {
415                 gtk_widget_show (ppriv->pwd_entry);
416                 gtk_widget_show (ppriv->user_entry);
417                 gtk_widget_show (ppriv->port_view);
418                 gtk_widget_show (pwd_caption);
419                 gtk_widget_show (user_caption);
420                 gtk_widget_show (port_caption);
421         }
422         gtk_widget_show (ppriv->security_view);
423         gtk_widget_show (ppriv->auth_view);
424 }
425
426 GtkWidget *    
427 modest_maemo_security_options_view_new  (ModestSecurityOptionsType type,
428                                          gboolean full,
429                                          GtkSizeGroup *title_size_group,
430                                          GtkSizeGroup *value_size_group)
431 {
432         ModestSecurityOptionsView* self;
433         ModestSecurityOptionsViewPrivate *ppriv;
434
435         self = (ModestSecurityOptionsView *)
436                 g_object_new (MODEST_TYPE_MAEMO_SECURITY_OPTIONS_VIEW, NULL);
437         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
438
439         ppriv->full = full;
440         self->type = type;
441         if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
442                 create_incoming_security (self, title_size_group, value_size_group);
443         else
444                 create_outgoing_security (self, title_size_group, value_size_group);
445
446         return (GtkWidget *) self;
447 }
448
449 gboolean
450 modest_security_options_view_has_missing_mandatory_data (ModestSecurityOptionsView* self)
451 {
452         ModestMaemoSecurityOptionsViewPrivate *priv;
453
454         priv = MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
455
456         return priv->missing_data;
457 }
458
459 static void
460 modest_maemo_security_options_view_load_settings (ModestSecurityOptionsView* self,
461                                                   ModestAccountSettings *settings)
462 {
463         ModestSecurityOptionsViewPrivate *ppriv;
464         ModestServerAccountSettings *server_settings;
465         gint port_number;
466
467         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
468
469         if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
470                 server_settings = modest_account_settings_get_store_settings (settings);
471         else
472                 server_settings = modest_account_settings_get_transport_settings (settings);
473         port_number = modest_server_account_settings_get_port (server_settings);
474
475         if (port_number == 0) {
476                 /* Show the appropriate port number */
477                 on_security_changed (ppriv->security_view, 
478                                      MODEST_MAEMO_SECURITY_OPTIONS_VIEW (self));
479         } else if (ppriv->full) {
480                 /* Keep the user-entered port-number, or the
481                  * already-appropriate automatic port number */
482                 modest_number_entry_set_value (ppriv->port_view,
483                                                port_number);
484         }
485         /* Frees */
486         g_object_unref (server_settings);
487 }
488
489 static void
490 modest_maemo_security_options_view_save_settings (ModestSecurityOptionsView* self, 
491                                                   ModestAccountSettings *settings)
492 {
493         ModestServerAccountSettings *server_settings;
494         ModestSecurityOptionsViewPrivate *ppriv;
495         gint server_port;
496
497         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
498
499         if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
500                 server_settings = modest_account_settings_get_store_settings (settings);
501         else
502                 server_settings = modest_account_settings_get_transport_settings (settings);
503
504         if (ppriv->full) {
505                 server_port = modest_number_entry_get_value (ppriv->port_view);
506         } else {
507                 server_port = modest_serversecurity_selector_get_active_serversecurity_port (ppriv->security_view);
508         }
509
510         modest_server_account_settings_set_port (server_settings, server_port);
511
512         /* Frees */
513         g_object_unref (server_settings);
514 }
515
516 static gboolean 
517 modest_maemo_security_options_view_changed (ModestSecurityOptionsView* self,
518                                             ModestAccountSettings *settings)
519 {
520         ModestServerAccountSettings *server_settings;
521         ModestSecurityOptionsViewPrivate *ppriv;
522         gint server_port;
523
524         ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
525         
526         /* If we're not showing the port number then it never changes */
527         if (!ppriv->full)
528                 return FALSE;
529
530         if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
531                 server_settings = modest_account_settings_get_store_settings (settings);
532         else
533                 server_settings = modest_account_settings_get_transport_settings (settings);
534         
535         server_port = 
536                 modest_number_entry_get_value (ppriv->port_view);
537
538         /* Frees */
539         g_object_unref (server_settings);
540
541         if (server_port != ppriv->initial_state.port)
542                 return TRUE;
543         else
544                 return FALSE;
545 }
546
547 static void
548 modest_maemo_security_options_view_init (ModestMaemoSecurityOptionsView *obj)
549 {
550 }
551
552 static void
553 modest_maemo_security_options_view_finalize (GObject *obj)
554 {
555         G_OBJECT_CLASS (modest_maemo_security_options_view_parent_class)->finalize (obj);
556 }
557
558
559 static void     
560 modest_maemo_security_options_view_class_init (ModestMaemoSecurityOptionsViewClass *klass)
561 {
562         GObjectClass *gobject_class = (GObjectClass*) klass;
563
564         modest_maemo_security_options_view_parent_class = g_type_class_peek_parent (klass);
565
566         g_type_class_add_private (gobject_class, sizeof (ModestMaemoSecurityOptionsViewPrivate));
567         gobject_class->finalize = modest_maemo_security_options_view_finalize;
568
569         MODEST_SECURITY_OPTIONS_VIEW_CLASS (klass)->load_settings = 
570                 modest_maemo_security_options_view_load_settings;
571         MODEST_SECURITY_OPTIONS_VIEW_CLASS (klass)->save_settings = 
572                 modest_maemo_security_options_view_save_settings;
573         MODEST_SECURITY_OPTIONS_VIEW_CLASS (klass)->changed = 
574                 modest_maemo_security_options_view_changed;
575 }