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