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