2007-07-09 Murray Cumming <murrayc@murrayc.com>
[modest] / src / maemo / modest-account-settings-dialog.c
1 /* Copyright (c) 2006, 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
31 #include "modest-account-settings-dialog.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkstock.h>
42 #include "modest-hildon-includes.h"
43
44 #include "widgets/modest-serversecurity-combo-box.h"
45 #include "widgets/modest-secureauth-combo-box.h"
46 #include "widgets/modest-validating-entry.h"
47 #include "widgets/modest-retrieve-combo-box.h"
48 #include "widgets/modest-limit-retrieve-combo-box.h"
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "modest-protocol-info.h"
54 #include "maemo/modest-connection-specific-smtp-window.h"
55 #include "maemo/modest-signature-editor-dialog.h"
56 #include "maemo/modest-maemo-utils.h"
57 #include "widgets/modest-ui-constants.h"
58
59 #include <tny-camel-transport-account.h>
60 #include <tny-camel-imap-store-account.h>
61 #include <tny-camel-pop-store-account.h>
62 #include <tny-status.h>
63
64 #include <gconf/gconf-client.h>
65 #include <string.h> /* For strlen(). */
66
67 /* Include config.h so that _() works: */
68 #ifdef HAVE_CONFIG_H
69 #include <config.h>
70 #endif
71
72 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
73
74 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
75
76 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
77         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
78
79 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
80
81 struct _ModestAccountSettingsDialogPrivate
82 {
83 };
84
85 static void
86 enable_buttons (ModestAccountSettingsDialog *self);
87
88 static gboolean
89 save_configuration (ModestAccountSettingsDialog *dialog);
90
91 static void
92 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
93                                                                                                                         GValue *value, GParamSpec *pspec)
94 {
95         switch (property_id) {
96         default:
97                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
98         }
99 }
100
101 static void
102 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
103                                                                                                                         const GValue *value, GParamSpec *pspec)
104 {
105         switch (property_id) {
106         default:
107                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108         }
109 }
110
111 static void
112 modest_account_settings_dialog_dispose (GObject *object)
113 {
114         if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
115                 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
116 }
117
118 static void
119 modest_account_settings_dialog_finalize (GObject *object)
120 {
121         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
122         
123         if (self->account_name)
124                 g_free (self->account_name);
125                 
126         if (self->original_account_title)
127                 g_free (self->original_account_title);
128                 
129         if (self->account_manager)
130                 g_object_unref (G_OBJECT (self->account_manager));
131                 
132         if (self->specific_window)
133                 gtk_widget_destroy (self->specific_window);
134                 
135         if (self->signature_dialog)
136                 gtk_widget_destroy (self->signature_dialog);
137         
138         G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
139 }
140
141 static void
142 show_error (GtkWindow *parent_window, const gchar* text);
143
144 static void
145 show_ok (GtkWindow *parent_window, const gchar* text);
146
147 static void
148 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
149
150 static void
151 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
152
153 static void
154 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
155 {
156         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
157         self->modified = TRUE;
158 }
159
160 static void
161 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
162 {
163         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
164         self->modified = TRUE;
165 }
166
167 static void
168 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
169 {
170         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
171         self->modified = TRUE;
172 }
173
174 static void
175 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
176 {
177         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
178         self->modified = TRUE;
179 }
180
181 /* Set a modified boolean whenever the widget is changed, 
182  * so we can check for it later.
183  */
184 static void
185 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
186 {
187         if (HILDON_IS_NUMBER_EDITOR (widget)) {
188                 g_signal_connect (G_OBJECT (widget), "notify::value",
189                         G_CALLBACK (on_modified_number_editor_changed), self);
190         }
191         else if (GTK_IS_ENTRY (widget)) {
192                 g_signal_connect (G_OBJECT (widget), "changed",
193                         G_CALLBACK (on_modified_entry_changed), self);
194         } else if (GTK_IS_COMBO_BOX (widget)) {
195                 g_signal_connect (G_OBJECT (widget), "changed",
196                         G_CALLBACK (on_modified_combobox_changed), self);       
197         } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
198                 g_signal_connect (G_OBJECT (widget), "toggled",
199                         G_CALLBACK (on_modified_checkbox_toggled), self);
200         }
201 }
202
203 static void
204 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
205 {
206         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
207         g_assert(self);
208         enable_buttons(self);
209 }
210
211 static void
212 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
213 {
214         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
215         g_assert(self);
216         enable_buttons(self);
217 }
218
219 /** This is a convenience function to create a caption containing a mandatory widget.
220  * When the widget is edited, the enable_buttons() vfunc will be called.
221  */
222 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
223         GtkSizeGroup *group,
224         const gchar *value,
225         GtkWidget *control,
226         GtkWidget *icon,
227         HildonCaptionStatus flag)
228 {
229         GtkWidget *caption = NULL;
230   
231         /* Note: Previously, the translated strings already contained the "*",
232          * Comment out this code if they do again.
233          */
234         /* Add a * character to indicate mandatory fields,
235          * as specified in our "Email UI Specification": */
236         if (flag == HILDON_CAPTION_MANDATORY) {
237                 gchar* title = g_strdup_printf("%s*", value);
238                 caption = hildon_caption_new (group, title, control, icon, flag);       
239                 g_free(title);
240         }       
241         else
242                 caption = hildon_caption_new (group, value, control, icon, flag);
243
244         /* Connect to the appropriate changed signal for the widget, 
245          * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
246          */
247         if (GTK_IS_ENTRY (control)) {
248                 g_signal_connect (G_OBJECT (control), "changed",
249                 G_CALLBACK (on_caption_entry_changed), self);
250                 
251         }
252         else if (GTK_IS_COMBO_BOX (control)) {
253                 g_signal_connect (G_OBJECT (control), "changed",
254                 G_CALLBACK (on_caption_combobox_changed), self);
255         }
256          
257         return caption;
258 }
259
260
261 static void
262 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
263 {
264         ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
265         show_error (GTK_WINDOW (dialog), _CS("ckdg_ib_maximum_characters_reached"));
266 }
267
268 static GtkWidget*
269 create_page_account_details (ModestAccountSettingsDialog *self)
270 {
271         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
272         GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
273         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
274         gtk_widget_show (label);
275         
276         /* Create a size group to be used by all captions.
277          * Note that HildonCaption does not create a default size group if we do not specify one.
278          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
279         GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
280            
281         /* The description widgets: */  
282         self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
283         /* Do use auto-capitalization: */
284         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title), 
285                 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
286         GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"), 
287                 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
288         gtk_widget_show (self->entry_account_title);
289         connect_for_modified (self, self->entry_account_title);
290         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
291         gtk_widget_show (caption);
292         
293         /* Prevent the use of some characters in the account title, 
294          * as required by our UI specification: */
295         GList *list_prevent = NULL;
296         list_prevent = g_list_append (list_prevent, "\\");
297         list_prevent = g_list_append (list_prevent, "/");
298         list_prevent = g_list_append (list_prevent, ":");
299         list_prevent = g_list_append (list_prevent, "*");
300         list_prevent = g_list_append (list_prevent, "?");
301         list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions â€œ, but maybe means ", maybe both. */
302         list_prevent = g_list_append (list_prevent, "“");
303         list_prevent = g_list_append (list_prevent, "<"); 
304         list_prevent = g_list_append (list_prevent, ">"); 
305         list_prevent = g_list_append (list_prevent, "|");
306         list_prevent = g_list_append (list_prevent, "^");       
307         modest_validating_entry_set_unallowed_characters (
308                 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
309         g_list_free (list_prevent);
310         
311         /* Set max length as in the UI spec:
312          * The UI spec seems to want us to show a dialog if we hit the maximum. */
313         gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
314         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title), 
315                 on_entry_max, self);
316         
317         /* The retrieve combobox: */
318         self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
319         caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"), 
320                 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
321         gtk_widget_show (self->combo_retrieve);
322         connect_for_modified (self, self->combo_retrieve);
323         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
324         gtk_widget_show (caption);
325         
326         /* The limit-retrieve combobox: */
327         self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
328         caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"), 
329                 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
330         gtk_widget_show (self->combo_limit_retrieve);
331         connect_for_modified (self, self->combo_limit_retrieve);
332         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
333         gtk_widget_show (caption);
334
335         /* The leave-messages widgets: */
336         if(!self->checkbox_leave_messages)
337                 self->checkbox_leave_messages = gtk_check_button_new ();
338         if (!self->caption_leave_messages) {
339                 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"), 
340                         self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
341         }
342                         
343         gtk_widget_show (self->checkbox_leave_messages);
344         connect_for_modified (self, self->checkbox_leave_messages);
345         gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
346         gtk_widget_show (self->caption_leave_messages);
347         
348         gtk_widget_show (GTK_WIDGET (box));
349         
350         return GTK_WIDGET (box);
351 }
352
353 static void
354 on_button_signature (GtkButton *button, gpointer user_data)
355 {
356         ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
357         
358         /* Create the window, if necessary: */
359         if (!(self->signature_dialog)) {
360                 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
361         
362                 gboolean use_signature = FALSE;
363                 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name, 
364                         &use_signature);
365                 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
366                 modest_signature_editor_dialog_set_settings (
367                         MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog), 
368                         use_signature, signature, account_title);
369                 g_free (signature);
370                 signature = NULL;
371         }
372
373         /* Show the window: */  
374         gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
375         gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
376     const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
377     gtk_widget_hide (self->signature_dialog);
378     if (response != GTK_RESPONSE_OK) {
379         /* Destroy the widget now, and its data: */
380         gtk_widget_destroy (self->signature_dialog);
381         self->signature_dialog = NULL;
382     }
383     else {
384         /* Mark modified, so we use the dialog's data later: */
385         self->modified = TRUE;  
386     }
387 }
388
389 static GtkWidget*
390 create_page_user_details (ModestAccountSettingsDialog *self)
391 {
392         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
393         
394         /* Create a size group to be used by all captions.
395          * Note that HildonCaption does not create a default size group if we do not specify one.
396          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
397         GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
398          
399         /* The name widgets: */
400         self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
401         /* Auto-capitalization is the default, so let's turn it off: */
402         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
403         /* Set max length as in the UI spec:
404          * The UI spec seems to want us to show a dialog if we hit the maximum. */
405         gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
406         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name), 
407                 on_entry_max, self);
408         GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
409                 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
410         gtk_widget_show (self->entry_user_name);
411         connect_for_modified (self, self->entry_user_name);
412         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
413         gtk_widget_show (caption);
414         
415         /* Prevent the use of some characters in the name, 
416          * as required by our UI specification: */
417         GList *list_prevent = NULL;
418         list_prevent = g_list_append (list_prevent, "<");
419         list_prevent = g_list_append (list_prevent, ">");
420         modest_validating_entry_set_unallowed_characters (
421                 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
422         g_list_free (list_prevent);
423         
424         /* The username widgets: */     
425         self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
426         /* Auto-capitalization is the default, so let's turn it off: */
427         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
428         caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"), 
429                 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
430         gtk_widget_show (self->entry_user_username);
431         connect_for_modified (self, self->entry_user_username);
432         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
433         gtk_widget_show (caption);
434         
435         /* Prevent the use of some characters in the username, 
436          * as required by our UI specification: */
437         modest_validating_entry_set_unallowed_characters_whitespace (
438                 MODEST_VALIDATING_ENTRY (self->entry_user_username));
439         
440         /* Set max length as in the UI spec:
441          * The UI spec seems to want us to show a dialog if we hit the maximum. */
442         gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
443         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username), 
444                 on_entry_max, self);
445         
446         /* The password widgets: */     
447         self->entry_user_password = gtk_entry_new ();
448         /* Auto-capitalization is the default, so let's turn it off: */
449         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), 
450                 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
451         gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
452         /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
453         caption = create_caption_new_with_asterisk (self, sizegroup, 
454                 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
455         gtk_widget_show (self->entry_user_password);
456         connect_for_modified (self, self->entry_user_password);
457         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
458         gtk_widget_show (caption);
459         
460         /* The email address widgets: */        
461         self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
462         /* Auto-capitalization is the default, so let's turn it off: */
463         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
464         caption = create_caption_new_with_asterisk (self, sizegroup, 
465                 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
466         gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
467         gtk_widget_show (self->entry_user_email);
468         connect_for_modified (self, self->entry_user_email);
469         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
470         gtk_widget_show (caption);
471         
472         /* Set max length as in the UI spec:
473          * The UI spec seems to want us to show a dialog if we hit the maximum. */
474         gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
475         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email), 
476                 on_entry_max, self);
477         
478         /* Signature button: */
479         if (!self->button_signature)
480                 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
481         caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"), 
482                 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
483         hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
484         gtk_widget_show (self->button_signature);
485         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
486         gtk_widget_show (caption);
487                 
488         g_signal_connect (G_OBJECT (self->button_signature), "clicked",
489                 G_CALLBACK (on_button_signature), self);
490                 
491         gtk_widget_show (GTK_WIDGET (box));
492         
493         return GTK_WIDGET (box);
494 }
495
496 /** Change the caption title for the incoming server, 
497  * as specified in the UI spec:
498  */
499 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
500 {
501         const gchar* type = 
502                 (protocol == MODEST_PROTOCOL_STORE_POP ? 
503                         _("mail_fi_emailtype_pop3") : 
504                         _("mail_fi_emailtype_imap") );
505                         
506                 
507         /* Note that this produces a compiler warning, 
508          * because the compiler does not know that the translated string will have a %s in it.
509          * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
510         gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
511         
512         /* This is a mandatory field, so add a *. This is usually done by 
513          * create_caption_new_with_asterisk() but we can't use that here. */
514         gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
515         g_free (incomingserver_title);
516         
517         g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
518         g_free(with_asterisk);
519 }
520
521 /** Change the caption title for the incoming server, 
522  * as specified in the UI spec:
523  */
524 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
525 {
526         /* Fill the combo with appropriately titled choices for POP or IMAP. */
527         /* The choices are the same, but the titles are different, as in the UI spec. */
528         modest_serversecurity_combo_box_fill (
529                 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
530 }
531            
532 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
533 {
534         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
535         
536         /* Create a size group to be used by all captions.
537          * Note that HildonCaption does not create a default size group if we do not specify one.
538          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
539         GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
540          
541         /* The incoming server widgets: */
542         if(!self->entry_incomingserver)
543                 self->entry_incomingserver = gtk_entry_new ();
544         /* Auto-capitalization is the default, so let's turn it off: */
545         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
546
547         if (self->caption_incoming)
548           gtk_widget_destroy (self->caption_incoming);
549            
550         /* The caption title will be updated in update_incoming_server_title().
551          * so this default text will never be seen: */
552         /* (Note: Changing the title seems pointless. murrayc) */
553         self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup, 
554                 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
555         gtk_widget_show (self->entry_incomingserver);
556         connect_for_modified (self, self->entry_incomingserver);
557         gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
558         gtk_widget_show (self->caption_incoming);
559         
560         /* The secure connection widgets: */
561         /* This will be filled by update_incoming_server_security_choices(). */
562         if (!self->combo_incoming_security)
563                 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
564         GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
565                 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
566         gtk_widget_show (self->combo_incoming_security);
567         connect_for_modified (self, self->combo_incoming_security);
568         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
569         gtk_widget_show (caption);
570         
571         /* Show a default port number when the security method changes, as per the UI spec: */
572         g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
573         
574         
575         /* The port widgets: */
576         /* TODO: There are various rules about this in the UI spec. */
577         if (!self->entry_incoming_port)
578                 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
579         caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"), 
580                 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
581         gtk_widget_show (self->entry_incoming_port);
582         connect_for_modified (self, self->entry_incoming_port);
583         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
584         gtk_widget_show (caption);
585         
586         /* The secure authentication widgets: */
587         if(!self->checkbox_incoming_auth)
588                 self->checkbox_incoming_auth = gtk_check_button_new ();
589         caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
590                 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
591         gtk_widget_show (self->checkbox_incoming_auth);
592         connect_for_modified (self, self->checkbox_incoming_auth);
593         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
594         gtk_widget_show (caption);
595         
596         gtk_widget_show (GTK_WIDGET (box));
597         
598         return GTK_WIDGET (box);
599 }
600
601 static void
602 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
603 {
604         GtkWidget *widget = GTK_WIDGET (user_data);
605         
606         /* Enable the widget only if the toggle button is active: */
607         const gboolean enable = gtk_toggle_button_get_active (togglebutton);
608         gtk_widget_set_sensitive (widget, enable);
609 }
610
611 /* Make the sensitivity of a widget depend on a toggle button.
612  */
613 static void
614 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
615 {
616         g_signal_connect (G_OBJECT (button), "toggled",
617                 G_CALLBACK (on_toggle_button_changed), widget);
618         
619         /* Set the starting sensitivity: */
620         on_toggle_button_changed (button, widget);
621 }
622
623 static void
624 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
625 {
626         ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
627         
628         /* Create the window if necessary: */
629         if (!(self->specific_window)) {
630                 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
631                 modest_connection_specific_smtp_window_fill_with_connections (
632                         MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager, 
633                         self->account_name);
634         }
635
636         /* Show the window: */  
637         gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
638         gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
639     gtk_widget_show (self->specific_window);
640 }
641
642 static void
643 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
644 {
645         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
646         
647         ModestAuthProtocol protocol_security = 
648                 modest_secureauth_combo_box_get_active_secureauth (
649                         MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
650         const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
651         
652         gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
653         gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
654 }
655
656 static void
657 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
658 {
659         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
660         
661         const gint port_number = 
662                 modest_serversecurity_combo_box_get_active_serversecurity_port (
663                         MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
664
665         if(port_number != 0) {
666                 hildon_number_editor_set_value (
667                         HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
668         }               
669 }
670
671 static void
672 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
673 {
674         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
675         
676         const gint port_number = 
677                 modest_serversecurity_combo_box_get_active_serversecurity_port (
678                         MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
679
680         if(port_number != 0) {
681                 hildon_number_editor_set_value (
682                         HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
683         }               
684 }
685
686
687 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
688 {
689         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
690         
691         /* Create a size group to be used by all captions.
692          * Note that HildonCaption does not create a default size group if we do not specify one.
693          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
694         GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
695          
696         /* The outgoing server widgets: */
697         if (!self->entry_outgoingserver)
698                 self->entry_outgoingserver = gtk_entry_new ();
699         /* Auto-capitalization is the default, so let's turn it off: */
700         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
701         GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
702                 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
703         gtk_widget_show (self->entry_outgoingserver);
704         connect_for_modified (self, self->entry_outgoingserver);
705         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
706         gtk_widget_show (caption);
707         
708         /* The secure authentication widgets: */
709         if (!self->combo_outgoing_auth)
710                 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
711         caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
712                 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
713         gtk_widget_show (self->combo_outgoing_auth);
714         connect_for_modified (self, self->combo_outgoing_auth);
715         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
716         gtk_widget_show (caption);
717         
718         /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
719         g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
720         
721         /* The username widgets: */     
722         self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
723         /* Auto-capitalization is the default, so let's turn it off: */
724         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
725         self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"), 
726                 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
727         gtk_widget_show (self->entry_outgoing_username);
728         connect_for_modified (self, self->entry_outgoing_username);
729         gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
730         gtk_widget_show (self->caption_outgoing_username);
731         
732         /* Prevent the use of some characters in the username, 
733          * as required by our UI specification: */
734         modest_validating_entry_set_unallowed_characters_whitespace (
735                 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
736         
737         /* Set max length as in the UI spec:
738          * The UI spec seems to want us to show a dialog if we hit the maximum. */
739         gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
740         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username), 
741                 on_entry_max, self);
742                 
743         /* The password widgets: */     
744         self->entry_outgoing_password = gtk_entry_new ();
745         /* Auto-capitalization is the default, so let's turn it off: */
746         hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password), 
747                 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
748         gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
749         /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
750         self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup, 
751                 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
752         gtk_widget_show (self->entry_outgoing_password);
753         connect_for_modified (self, self->entry_outgoing_password);
754         gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
755         gtk_widget_show (self->caption_outgoing_password);
756         
757         /* The secure connection widgets: */
758         /* This will be filled and set with modest_serversecurity_combo_box_fill() 
759          * and modest_serversecurity_combo_box_set_active_serversecurity().
760          */
761         if (!self->combo_outgoing_security)
762                 
763                 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
764         caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
765                 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
766         gtk_widget_show (self->combo_outgoing_security);
767         connect_for_modified (self, self->combo_outgoing_security);
768         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
769         gtk_widget_show (caption);
770         
771         /* Show a default port number when the security method changes, as per the UI spec: */
772         g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
773         
774         /* The port widgets: */
775         if (!self->entry_outgoing_port)
776                 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
777         caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"), 
778                 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
779         gtk_widget_show (self->entry_outgoing_port);
780         connect_for_modified (self, self->entry_outgoing_port);
781         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
782         gtk_widget_show (caption);
783         
784         GtkWidget *separator = gtk_hseparator_new ();
785         gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
786         gtk_widget_show (separator);
787         
788         /* connection-specific checkbox: */
789         if (!self->checkbox_outgoing_smtp_specific) {
790                 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
791                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific), 
792                         FALSE);
793         }
794         caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"), 
795                 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
796         gtk_widget_show (self->checkbox_outgoing_smtp_specific);
797         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
798         gtk_widget_show (caption);
799         connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
800         
801         /* Connection-specific SMTP-Severs Edit button: */
802         if (!self->button_outgoing_smtp_servers)
803                 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
804         caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"), 
805                 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
806         hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
807         gtk_widget_show (self->button_outgoing_smtp_servers);
808         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
809         gtk_widget_show (caption);
810         
811         /* Only enable the button when the checkbox is checked: */
812         enable_widget_for_togglebutton (self->button_outgoing_smtp_servers, 
813                 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
814                 
815         g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
816                 G_CALLBACK (on_button_outgoing_smtp_servers), self);
817                 
818         gtk_widget_show (GTK_WIDGET (box));
819         
820         return GTK_WIDGET (box);
821 }
822
823 static gboolean
824 check_data (ModestAccountSettingsDialog *self)
825 {
826         /* Check that the title is not already in use: */
827         const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
828         if ((!account_title) || (strlen(account_title) == 0))
829                 return FALSE; /* Should be prevented already anyway. */
830                 
831         if (strcmp(account_title, self->original_account_title) != 0) {
832                 /* Check the changed title: */
833                 const gboolean name_in_use  = modest_account_mgr_account_with_display_name_exists (self->account_manager,
834                         account_title);
835         
836                 if (name_in_use) {
837                         /* Warn the user via a dialog: */
838                         hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
839                 
840                         return FALSE;
841                 }
842         }
843
844         /* Check that the email address is valud: */
845         const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
846         if ((!email_address) || (strlen(email_address) == 0))
847                 return FALSE;
848                         
849         if (!modest_text_utils_validate_email_address (email_address, NULL)) {
850                 /* Warn the user via a dialog: */
851                 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
852                 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
853                                          
854                 /* Return focus to the email address entry: */
855                 gtk_widget_grab_focus (self->entry_user_email);
856                 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
857                 return FALSE;
858         }
859
860         /* Find a suitable authentication method when secure authentication is desired */
861         const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
862         gint port_num = hildon_number_editor_get_value (
863                         HILDON_NUMBER_EDITOR (self->entry_incoming_port));
864         const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
865
866         const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
867                 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
868
869         /* If we use an encrypted protocol then there is no need to encrypt the password */
870         if (!modest_protocol_info_is_secure(protocol_security_incoming))
871         {
872                 if (gtk_toggle_button_get_active (
873                                 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
874                         GError *error = NULL;
875                         GList *list_auth_methods = 
876                                 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol, 
877                                         hostname, port_num, username, GTK_WINDOW (self), &error);
878                         if (list_auth_methods) {
879                                 /* Use the first supported method.
880                                  * TODO: Should we prioritize them, to prefer a particular one? */
881                                 GList* method;
882                                 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
883                                 {
884                                         ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
885                                         // Allow secure methods, e.g MD5 only
886                                         if (modest_protocol_info_auth_is_secure(proto))
887                                         {
888                                                 self->protocol_authentication_incoming = proto;
889                                                 break;
890                                         }
891                                 }
892                                 g_list_free (list_auth_methods);
893                         }
894
895                         if (list_auth_methods == NULL || 
896                                         !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
897                         {
898                                 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
899                                                 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
900                                 {
901                                         show_error (GTK_WINDOW (self), _("Could not discover supported secure authentication methods."));
902                                 }
903
904                                 if(error != NULL)
905                                         g_error_free(error);
906                                         
907                                 /* This is a nasty hack. jschmid. */
908                                 /* Don't let the dialog close */
909                                 /*g_signal_stop_emission_by_name (dialog, "response");*/
910                                 return FALSE;
911                         }
912                 }
913         }
914
915         /* TODO: The UI Spec wants us to check that the servernames are valid, 
916          * but does not specify how.
917          */
918          
919         return TRUE;
920 }
921 /*
922  */
923 static void 
924 on_response (GtkDialog *wizard_dialog,
925         gint response_id,
926         gpointer user_data)
927 {
928         ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
929         enable_buttons (self);
930         
931         gboolean prevent_response = FALSE;
932
933         /* Warn about unsaved changes: */
934         if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
935                 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self), 
936                         _("imum_nc_wizard_confirm_lose_changes")));
937                 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
938                  
939                  const gint dialog_response = gtk_dialog_run (dialog);
940                  gtk_widget_destroy (GTK_WIDGET (dialog));
941                  
942                 if (dialog_response != GTK_RESPONSE_OK)
943                         prevent_response = TRUE;
944         }
945         /* Check for invalid input: */
946         else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
947                 prevent_response = TRUE;
948         }
949                 
950         if (prevent_response) {
951                 /* This is a nasty hack. murrayc. */
952                 /* Don't let the dialog close */
953                 g_signal_stop_emission_by_name (wizard_dialog, "response");
954                 return; 
955         }
956                 
957         if (response_id == GTK_RESPONSE_OK) {
958                 /* Try to save the changes if modified (NB #59251): */
959                 if (self->modified)
960                 {
961                         const gboolean saved = save_configuration (self);
962                         if (saved) {
963                                 /* Do not show the account-saved dialog if we are just saving this 
964                                  * temporarily, because from the user's point of view it will not 
965                                  * really be saved (saved + enabled) until later.
966                                  */
967                                 const gboolean enabled = 
968                                         modest_account_mgr_get_enabled (self->account_manager, self->account_name);
969                                 if (enabled)
970                                         show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
971                         }
972                         else
973                                 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
974                 }
975         }
976 }
977
978 static void
979 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
980 {
981         /* Create the notebook to be used by the GtkDialog base class:
982          * Each page of the notebook will be a page of the wizard: */
983         self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
984
985         /* Get the account manager object, 
986          * so we can check for existing accounts,
987          * and create new accounts: */
988         self->account_manager = modest_runtime_get_account_mgr ();
989         g_assert (self->account_manager);
990         g_object_ref (self->account_manager);
991         
992         self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
993
994     /* Create the common pages, 
995      */
996         self->page_account_details = create_page_account_details (self);
997         self->page_user_details = create_page_user_details (self);
998         self->page_incoming = create_page_incoming (self);
999         self->page_outgoing = create_page_outgoing (self);
1000         
1001         /* Add the notebook pages: */
1002         gtk_notebook_append_page (self->notebook, self->page_account_details, 
1003                 gtk_label_new (_("mcen_ti_account_settings_account")));
1004         gtk_notebook_append_page (self->notebook, self->page_user_details, 
1005                 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1006         gtk_notebook_append_page (self->notebook, self->page_incoming,
1007                 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1008         gtk_notebook_append_page (self->notebook, self->page_outgoing,
1009                 gtk_label_new (_("mcen_ti_advsetup_sending")));
1010                 
1011         GtkDialog *dialog = GTK_DIALOG (self);
1012         gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1013         gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1014         gtk_widget_show (GTK_WIDGET (self->notebook));
1015         
1016     /* Add the buttons: */
1017     gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1018     gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1019     
1020     /* Connect to the dialog's response signal: */
1021     /* We use connect-before 
1022      * so we can stop the signal emission, 
1023      * to stop the default signal handler from closing the dialog.
1024      */
1025     g_signal_connect (G_OBJECT (self), "response",
1026             G_CALLBACK (on_response), self); 
1027             
1028     self->modified = FALSE;
1029     
1030     /* When this window is shown, hibernation should not be possible, 
1031          * because there is no sensible way to save the state: */
1032     modest_window_mgr_prevent_hibernation_while_window_is_shown (
1033         modest_runtime_get_window_mgr (), GTK_WINDOW (self)); 
1034 }
1035
1036 ModestAccountSettingsDialog*
1037 modest_account_settings_dialog_new (void)
1038 {
1039         return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1040 }
1041
1042 /** Update the UI with the stored account details, so they can be edited.
1043  * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1044  */
1045 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1046 {
1047         if (!account_name)
1048                 return;
1049                 
1050         /* Save the account name so we can refer to it later: */
1051         if (dialog->account_name)
1052                 g_free (dialog->account_name);
1053         dialog->account_name = g_strdup (account_name);
1054         
1055                 
1056         /* Get the account data for this account name: */
1057         ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager, 
1058                 account_name);
1059         if (!account_data) {
1060                 g_printerr ("modest: failed to get account data for %s\n", account_name);
1061                 return;
1062         }
1063         
1064         /* Save the account title so we can refer to it if the user changes it: */
1065         if (dialog->original_account_title)
1066                 g_free (dialog->original_account_title);
1067         dialog->original_account_title = g_strdup (account_data->display_name);
1068         
1069
1070         if (!(account_data->store_account)) {
1071                 g_printerr ("modest: account has no stores: %s\n", account_name);
1072                 return;
1073         }
1074                 
1075         /* Show the account data in the widgets: */
1076         
1077         /* Note that we never show the non-display name in the UI.
1078          * (Though the display name defaults to the non-display name at the start.) */
1079         gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1080                 account_data->display_name ? account_data->display_name : "");
1081                 
1082         gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name), 
1083                 account_data->fullname ? account_data->fullname : "");
1084         gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email), 
1085                 account_data->email ? account_data->email : "");
1086                 
1087         ModestServerAccountData *incoming_account = account_data->store_account;
1088                 
1089         if (incoming_account)
1090                 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1091         gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1092                 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1093         if (!retrieve) {
1094                 /* Default to something, though no default is specified in the UI spec: */
1095                 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1096         }
1097         modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1098         g_free (retrieve);
1099         
1100         const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1101                 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1102         modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1103         
1104         
1105         const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1106                 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1107         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);    
1108         
1109         /* Only show the leave-on-server checkbox for POP, 
1110          * as per the UI spec: */
1111         if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1112                 gtk_widget_hide (dialog->caption_leave_messages);
1113         } else {
1114                 gtk_widget_show (dialog->caption_leave_messages);
1115         }
1116         
1117         update_incoming_server_security_choices (dialog, incoming_account->proto);
1118         if (incoming_account) {
1119                 /* Remember this for later: */
1120                 dialog->incoming_protocol = incoming_account->proto;
1121                 
1122                 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1123                         incoming_account->username ? incoming_account->username : "");
1124                 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password), 
1125                         incoming_account->password ? incoming_account->password : "");
1126                         
1127                 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver), 
1128                         incoming_account->hostname ? incoming_account->hostname : "");
1129                         
1130                 /* The UI spec says:
1131                  * If secure authentication is unchecked, allow sending username and password also as plain text.
1132          * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc. 
1133                  * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1134          */                                                                                                              
1135                 const ModestConnectionProtocol security = modest_server_account_get_security (
1136                         dialog->account_manager, incoming_account->account_name);
1137                 modest_serversecurity_combo_box_set_active_serversecurity (
1138                         MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1139                 
1140                 /* Check if we have
1141                  - a secure protocol
1142                  OR
1143                  - use encrypted passwords
1144                 */
1145                 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1146                         dialog->account_manager, incoming_account->account_name);
1147                 dialog->protocol_authentication_incoming = secure_auth;
1148                 if (modest_protocol_info_is_secure(security) || 
1149                                 modest_protocol_info_auth_is_secure(secure_auth))
1150                 {
1151                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth), 
1152                                                                                                                                          TRUE);
1153                 }
1154                 else
1155                 {
1156                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth), 
1157                                                                                                                                          FALSE);
1158                 };
1159                                         
1160                 update_incoming_server_title (dialog, incoming_account->proto);
1161                 
1162                 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1163                         MODEST_ACCOUNT_PORT, TRUE /* server account */);
1164                         
1165                 if (port_num == 0) {
1166                         /* Show the appropriate port number: */
1167                         on_combo_incoming_security_changed (
1168                                 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1169                 } else {
1170                         /* Keep the user-entered port-number,
1171                          * or the already-appropriate automatic port number: */
1172                         hildon_number_editor_set_value (
1173                                 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1174                 }
1175         }
1176         
1177         ModestServerAccountData *outgoing_account = account_data->transport_account;
1178         if (outgoing_account) {
1179                 /* Remember this for later: */
1180                 dialog->outgoing_protocol = outgoing_account->proto;
1181                 
1182                 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver), 
1183                         outgoing_account->hostname ? outgoing_account->hostname : "");
1184                 
1185                 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username), 
1186                         outgoing_account->username ? outgoing_account->username : "");
1187                 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password), 
1188                         outgoing_account->password ? outgoing_account->password : "");
1189                 
1190                 /* Get the secure-auth setting: */
1191                 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1192                         dialog->account_manager, outgoing_account->account_name);
1193                 modest_secureauth_combo_box_set_active_secureauth (
1194                         MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1195                 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1196                 
1197                 modest_serversecurity_combo_box_fill (
1198                         MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1199                 
1200                 /* Get the security setting: */
1201                 const ModestConnectionProtocol security = modest_server_account_get_security (
1202                         dialog->account_manager, outgoing_account->account_name);
1203                 modest_serversecurity_combo_box_set_active_serversecurity (
1204                         MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1205                 
1206                 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1207                         MODEST_ACCOUNT_PORT, TRUE /* server account */);
1208                 if (port_num == 0) {
1209                         /* Show the appropriate port number: */
1210                         on_combo_outgoing_security_changed (
1211                                 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1212                 }
1213                 else {
1214                         /* Keep the user-entered port-number,
1215                          * or the already-appropriate automatic port number: */
1216                         hildon_number_editor_set_value (
1217                                 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1218                 }
1219                 
1220                 const gboolean has_specific = 
1221                         modest_account_mgr_get_has_connection_specific_smtp (
1222                                 dialog->account_manager, 
1223                                 account_name);
1224                 gtk_toggle_button_set_active (
1225                         GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific), 
1226                         has_specific);
1227         }
1228
1229         /* Set window title according to account: */
1230         /* TODO: Is this the correct way to find a human-readable name for
1231          * the protocol used? */
1232         const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1233         gchar *proto_name = g_utf8_strup(proto_str, -1);
1234         gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1235
1236         gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1237         g_free (proto_name);
1238         g_free (account_title);
1239
1240         gtk_window_set_title (GTK_WINDOW (dialog), title);
1241         g_free (title);
1242
1243         /* account_data->is_enabled,  */
1244         /*account_data->is_default,  */
1245
1246         /* account_data->store_account->proto */
1247
1248         modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1249         
1250         /* Unset the modified flag so we can detect changes later: */
1251         dialog->modified = FALSE;
1252 }
1253
1254 /** Show the User Info tab.
1255  */
1256 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1257 {
1258         const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1259         if (page_num == -1) {
1260                 g_warning ("%s: notebook page not found.\n", __FUNCTION__);     
1261         }
1262                 
1263         /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1264         /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1265         
1266         gtk_widget_show (dialog->page_user_details);
1267         gtk_widget_show (GTK_WIDGET (dialog->notebook));
1268         gtk_widget_show (GTK_WIDGET (dialog));
1269         gtk_notebook_set_current_page (dialog->notebook, page_num);
1270 }
1271
1272 static gboolean
1273 save_configuration (ModestAccountSettingsDialog *dialog)
1274 {
1275         g_assert (dialog->account_name);
1276         
1277         const gchar* account_name = dialog->account_name;
1278                 
1279         /* Set the account data from the widgets: */
1280         const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1281         gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1282                 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1283         if (!test)
1284                 return FALSE;
1285                 
1286         const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1287         test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1288                 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1289         if (!test)
1290                 return FALSE;
1291                 
1292         /* Signature: */
1293         if (dialog->signature_dialog) {
1294                 gboolean use_signature = FALSE;
1295         gchar *signature = modest_signature_editor_dialog_get_settings (
1296                 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1297                 &use_signature);
1298         
1299         modest_account_mgr_set_signature(dialog->account_manager, account_name, 
1300                 signature, use_signature);
1301         g_free (signature);
1302     }
1303         
1304         gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1305                 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1306         modest_account_mgr_set_string (dialog->account_manager, account_name,
1307                 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1308         g_free (retrieve);
1309         
1310         const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1311                 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1312         modest_account_mgr_set_int (dialog->account_manager, account_name,
1313                 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1314         
1315         const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1316         test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1317                 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1318         if (!test)
1319                 return FALSE;
1320                         
1321         /* Incoming: */
1322         gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1323                 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1324         g_assert (incoming_account_name);
1325         
1326         const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1327         test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1328                 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1329         if (!test)
1330                 return FALSE;
1331                                 
1332         const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1333         modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1334         
1335         const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1336         modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1337                         
1338         /* port: */
1339         gint port_num = hildon_number_editor_get_value (
1340                         HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1341         modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1342                         MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1343                         
1344         /* The UI spec says:
1345          * If secure authentication is unchecked, allow sending username and password also as plain text.
1346          * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc. 
1347          */
1348         
1349         const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1350                 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1351         modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1352         
1353         modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1354         
1355                 
1356         g_free (incoming_account_name);
1357         
1358         /* Outgoing: */
1359         gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1360                 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1361         g_assert (outgoing_account_name);
1362         
1363         hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1364         test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1365                 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1366         if (!test)
1367                 return FALSE;
1368                 
1369         username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1370         modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1371                 username);
1372                 
1373         password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1374         modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1375                 password);
1376         
1377         const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1378                 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1379         modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1380         
1381         const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1382                 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1383         modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);       
1384         
1385         /* port: */
1386         port_num = hildon_number_editor_get_value (
1387                         HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1388         modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1389                         MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1390                         
1391         g_free (outgoing_account_name);
1392         
1393         
1394         /* Set the changed account title last, to simplify the previous code: */
1395         const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1396         if ((!account_title) || (strlen(account_title) == 0))
1397                 return FALSE; /* Should be prevented already anyway. */
1398                 
1399         if (strcmp(account_title, account_name) != 0) {
1400                 /* Change the title: */
1401                 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1402                 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1403                 if (!test)
1404                         return FALSE;
1405         }
1406         
1407         /* Save connection-specific SMTP server accounts: */
1408         if (dialog->specific_window) {
1409                 return modest_connection_specific_smtp_window_save_server_accounts (
1410                         MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1411         }
1412         else
1413                 return TRUE;
1414 }
1415
1416 static gboolean entry_is_empty (GtkWidget *entry)
1417 {
1418         if (!entry)
1419                 return FALSE;
1420                 
1421         const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1422         if ((!text) || (strlen(text) == 0))
1423                 return TRUE;
1424         else
1425                 return FALSE;
1426 }
1427
1428 static void
1429 enable_buttons (ModestAccountSettingsDialog *self)
1430 {
1431         gboolean enable_ok = TRUE;
1432         
1433         /* The account details title is mandatory: */
1434         if (entry_is_empty(self->entry_account_title))
1435                         enable_ok = FALSE;
1436
1437         /* The user details username is mandatory: */
1438         if (entry_is_empty(self->entry_user_username))
1439                 enable_ok = FALSE;
1440                 
1441         /* The user details email address is mandatory: */
1442         if (enable_ok && entry_is_empty (self->entry_user_email))
1443                 enable_ok = FALSE;
1444
1445         /* The custom incoming server is mandatory: */
1446         if (entry_is_empty(self->entry_incomingserver))
1447                 enable_ok = FALSE;
1448                         
1449         /* Enable the buttons, 
1450          * identifying them via their associated response codes:
1451          */
1452         GtkDialog *dialog_base = GTK_DIALOG (self);
1453     gtk_dialog_set_response_sensitive (dialog_base,
1454                                        GTK_RESPONSE_OK,
1455                                        enable_ok);
1456 }
1457
1458 static void
1459 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1460 {
1461         GObjectClass *object_class = G_OBJECT_CLASS (klass);
1462         g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1463
1464
1465         object_class->get_property = modest_account_settings_dialog_get_property;
1466         object_class->set_property = modest_account_settings_dialog_set_property;
1467         object_class->dispose = modest_account_settings_dialog_dispose;
1468         object_class->finalize = modest_account_settings_dialog_finalize;
1469 }
1470  
1471 static void
1472 show_error (GtkWindow *parent_window, const gchar* text)
1473 {
1474         GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1475         /*
1476         GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1477                 (GtkDialogFlags)0,
1478                  GTK_MESSAGE_ERROR,
1479                  GTK_BUTTONS_OK,
1480                  text ));
1481         */       
1482         
1483         gtk_dialog_run (dialog);
1484         gtk_widget_destroy (GTK_WIDGET (dialog));
1485 }
1486
1487 static void
1488 show_ok (GtkWindow *parent_window, const gchar* text)
1489 {
1490         /* Don't show a dialog but Banner (NB #59248) */
1491         hildon_banner_show_information(GTK_WIDGET(
1492                                                                                                                                                                                 gtk_widget_get_parent_window(GTK_WIDGET(parent_window))), NULL, text);
1493 }