22151331d856053b1da046b6be3fe2406b6bb44c
[modest] / src / hildon2 / modest-hildon2-global-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 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif /*HAVE_CONFIG_H*/
33
34 #include <modest-hildon-includes.h>
35 #include <modest-scrollable.h>
36 #include <modest-maemo-utils.h>
37
38 #include <glib/gi18n.h>
39 #include <string.h>
40 #include <gtk/gtkbox.h>
41 #include <gtk/gtkvbox.h>
42 #include <gtk/gtknotebook.h>
43 #include <gtk/gtklabel.h>
44 #include <gtk/gtkcheckbutton.h>
45 #include "modest-runtime.h"
46 #include "widgets/modest-global-settings-dialog-priv.h"
47 #include "modest-hildon2-global-settings-dialog.h"
48 #include "widgets/modest-ui-constants.h"
49 #include "modest-text-utils.h"
50 #include "modest-defs.h"
51 #include <tny-account-store.h>
52 #include <modest-account-mgr-helpers.h>
53 #include <modest-toolkit-utils.h>
54
55
56 #define MSG_SIZE_MAX_VAL 5000
57 #define MSG_SIZE_DEF_VAL 1000
58 #define MSG_SIZE_MIN_VAL 1
59
60 #define DEFAULT_FOCUS_WIDGET "default-focus-widget"
61
62 /* 'private'/'protected' functions */
63 static void modest_hildon2_global_settings_dialog_class_init (ModestHildon2GlobalSettingsDialogClass *klass);
64 static void modest_hildon2_global_settings_dialog_init       (ModestHildon2GlobalSettingsDialog *obj);
65 static void modest_hildon2_global_settings_dialog_finalize   (GObject *obj);
66
67 static ModestConnectedVia current_connection (void);
68
69 static GtkWidget* create_updating_page   (ModestHildon2GlobalSettingsDialog *self);
70
71 static void       on_auto_update_clicked (GtkButton *button,
72                                           gpointer user_data);
73 static void       update_sensitive       (ModestGlobalSettingsDialog *dialog);
74 static ModestPairList * get_accounts_list (void);
75
76 static void modest_hildon2_global_settings_dialog_load_settings (ModestGlobalSettingsDialog *self);
77
78 typedef struct _ModestHildon2GlobalSettingsDialogPrivate ModestHildon2GlobalSettingsDialogPrivate;
79 struct _ModestHildon2GlobalSettingsDialogPrivate {
80         ModestPairList *connect_via_list;
81 };
82 #define MODEST_HILDON2_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
83                                                            MODEST_TYPE_HILDON2_GLOBAL_SETTINGS_DIALOG, \
84                                                            ModestHildon2GlobalSettingsDialogPrivate))
85 /* globals */
86 static GtkDialogClass *parent_class = NULL;
87
88 GType
89 modest_hildon2_global_settings_dialog_get_type (void)
90 {
91         static GType my_type = 0;
92         if (!my_type) {
93                 static const GTypeInfo my_info = {
94                         sizeof(ModestHildon2GlobalSettingsDialogClass),
95                         NULL,           /* base init */
96                         NULL,           /* base finalize */
97                         (GClassInitFunc) modest_hildon2_global_settings_dialog_class_init,
98                         NULL,           /* class finalize */
99                         NULL,           /* class data */
100                         sizeof(ModestHildon2GlobalSettingsDialog),
101                         1,              /* n_preallocs */
102                         (GInstanceInitFunc) modest_hildon2_global_settings_dialog_init,
103                         NULL
104                 };
105                 my_type = g_type_register_static (MODEST_TYPE_GLOBAL_SETTINGS_DIALOG,
106                                                   "ModestHildon2GlobalSettingsDialog",
107                                                   &my_info, 0);
108         }
109         return my_type;
110 }
111
112 static void
113 modest_hildon2_global_settings_dialog_class_init (ModestHildon2GlobalSettingsDialogClass *klass)
114 {
115         GObjectClass *gobject_class;
116         gobject_class = (GObjectClass*) klass;
117
118         parent_class            = g_type_class_peek_parent (klass);
119         gobject_class->finalize = modest_hildon2_global_settings_dialog_finalize;
120
121         g_type_class_add_private (gobject_class, sizeof(ModestHildon2GlobalSettingsDialogPrivate));
122
123         MODEST_GLOBAL_SETTINGS_DIALOG_CLASS (klass)->current_connection_func = current_connection;
124 }
125
126 typedef struct {
127         ModestHildon2GlobalSettingsDialog *dia;
128         GtkWidget *focus_widget;
129 } SwitchPageHelper;
130
131
132 static void
133 modest_hildon2_global_settings_dialog_init (ModestHildon2GlobalSettingsDialog *self)
134 {
135         ModestHildon2GlobalSettingsDialogPrivate *priv;
136         ModestGlobalSettingsDialogPrivate *ppriv;
137         GtkWidget *align;
138         GtkWidget *top_vbox;
139
140         priv  = MODEST_HILDON2_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
141         ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
142
143         ppriv->updating_page = create_updating_page (self);
144         top_vbox = gtk_vbox_new (FALSE, 0);
145         align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
146         gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
147
148         /* Add the buttons: */
149         gtk_dialog_add_button (GTK_DIALOG (self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
150
151         /* Set the default focusable widgets */
152         g_object_set_data (G_OBJECT(ppriv->updating_page), DEFAULT_FOCUS_WIDGET,
153                            (gpointer)ppriv->auto_update);
154
155         gtk_container_add (GTK_CONTAINER (top_vbox), ppriv->updating_page);
156         gtk_container_add (GTK_CONTAINER (align), top_vbox);
157         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), align);
158         gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->vbox), MODEST_MARGIN_HALF);
159         gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
160
161         gtk_widget_show (align);
162         gtk_widget_show (top_vbox);
163 }
164
165 static void
166 modest_hildon2_global_settings_dialog_finalize (GObject *obj)
167 {
168         ModestGlobalSettingsDialogPrivate *ppriv;
169         ModestHildon2GlobalSettingsDialogPrivate *priv;
170
171         priv = MODEST_HILDON2_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (obj);
172         ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (obj);
173
174 /*      free/unref instance resources here */
175         G_OBJECT_CLASS(parent_class)->finalize (obj);
176 }
177
178 GtkWidget*
179 modest_hildon2_global_settings_dialog_new (void)
180 {
181         GtkWidget *self = GTK_WIDGET(g_object_new(MODEST_TYPE_HILDON2_GLOBAL_SETTINGS_DIALOG, NULL));
182
183         /* Load settings */
184         modest_hildon2_global_settings_dialog_load_settings (MODEST_GLOBAL_SETTINGS_DIALOG (self));
185
186         return self;
187 }
188
189 /*
190  * Creates the updating page
191  */
192 static GtkWidget*
193 create_updating_page (ModestHildon2GlobalSettingsDialog *self)
194 {
195         GtkWidget *vbox;
196         GtkSizeGroup *title_size_group;
197         GtkSizeGroup *value_size_group;
198         ModestGlobalSettingsDialogPrivate *ppriv;
199         GtkWidget *scrollable, *separator;
200         ModestHildon2GlobalSettingsDialogPrivate *priv;
201
202         priv = MODEST_HILDON2_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
203         ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
204         vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
205
206         title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
207         value_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
208
209         /* Default account selector */
210         ppriv->accounts_list = get_accounts_list ();
211         ppriv->default_account_selector = modest_toolkit_factory_create_selector (modest_runtime_get_toolkit_factory (),
212                                                                                   ppriv->accounts_list,
213                                                                                   g_str_equal);
214         if (ppriv->accounts_list == NULL) {
215                 gtk_widget_set_sensitive (GTK_WIDGET (ppriv->default_account_selector), FALSE);
216         } else {
217                 gchar *default_account;
218
219                 default_account = modest_account_mgr_get_default_account (
220                         modest_runtime_get_account_mgr ());
221                 if (default_account) {
222                         modest_selector_set_active_id (ppriv->default_account_selector,
223                                                        default_account);
224                         ppriv->initial_state.default_account = default_account;
225                 }
226         }
227         if (GTK_IS_COMBO_BOX (ppriv->default_account_selector)) {
228                 GtkWidget *caption;
229
230                 caption = modest_toolkit_utils_create_vcaptioned (title_size_group,
231                                                                   _("mcen_ti_default_account"), FALSE,
232                                                                   ppriv->default_account_selector);
233                 gtk_widget_show (caption);
234                 gtk_box_pack_start (GTK_BOX (vbox), caption,
235                                     FALSE, FALSE, 0);
236         } else {
237                 modest_toolkit_utils_set_vbutton_layout (title_size_group,
238                                                          _("mcen_ti_default_account"),
239                                                          ppriv->default_account_selector);
240                 gtk_box_pack_start (GTK_BOX (vbox), ppriv->default_account_selector,
241                                     FALSE, FALSE, 0);
242         }
243
244         /* Message format */
245         /* Note: This ModestPairList* must exist for as long as the picker
246          * that uses it, because the ModestSelectorPicker uses the ID opaquely,
247          * so it can't know how to manage its memory. */
248         ppriv->msg_format_list = _modest_global_settings_dialog_get_msg_formats ();
249         ppriv->msg_format = modest_toolkit_factory_create_selector (modest_runtime_get_toolkit_factory (),
250                                                                     ppriv->msg_format_list, g_int_equal);
251         if (GTK_IS_COMBO_BOX (ppriv->msg_format)) {
252                 GtkWidget *caption;
253                 caption = modest_toolkit_utils_create_vcaptioned (title_size_group,
254                                                                   _("mcen_fi_options_messageformat"), FALSE,
255                                                                   ppriv->msg_format);
256                 gtk_widget_show (caption);
257                 gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, 0);
258         } else {
259                 modest_toolkit_utils_set_vbutton_layout (title_size_group,
260                                                          _("mcen_fi_options_messageformat"),
261                                                          ppriv->msg_format);
262                 gtk_box_pack_start (GTK_BOX (vbox), ppriv->msg_format, FALSE, FALSE, 0);
263         }
264
265
266         /* Incoming notifications */
267         ppriv->notifications = hildon_check_button_new (MODEST_EDITABLE_SIZE);
268         gtk_button_set_label (GTK_BUTTON (ppriv->notifications), _("mcen_fi_options_incoming_notifications"));
269         gtk_button_set_alignment (GTK_BUTTON (ppriv->notifications), 0.0, 0.5);
270         gtk_box_pack_start (GTK_BOX (vbox), ppriv->notifications, FALSE, FALSE, 0);
271
272         /* Automatic add to contacts */
273         ppriv->add_to_contacts = hildon_check_button_new (MODEST_EDITABLE_SIZE);
274         gtk_button_set_label (GTK_BUTTON (ppriv->add_to_contacts), _("mcen_fi_options_automatic_add"));
275         gtk_button_set_alignment (GTK_BUTTON (ppriv->add_to_contacts), 0.0, 0.5);
276         gtk_box_pack_start (GTK_BOX (vbox), ppriv->add_to_contacts, FALSE, FALSE, 0);
277
278         /* Separator label */
279         separator = gtk_label_new (_("mcen_ti_updating"));
280         gtk_label_set_justify ((GtkLabel *) separator, GTK_JUSTIFY_CENTER);
281         gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
282
283         /* Auto update */
284         ppriv->auto_update = modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
285                                                                          _("mcen_fi_options_autoupdate"));
286         gtk_box_pack_start (GTK_BOX (vbox), ppriv->auto_update, FALSE, FALSE, 0);
287         g_signal_connect (ppriv->auto_update, "clicked", G_CALLBACK (on_auto_update_clicked), self);
288
289         /* Connected via */
290
291         /* Note: This ModestPairList* must exist for as long as the picker
292          * that uses it, because the ModestSelectorPicker uses the ID opaquely, 
293          * so it can't know how to manage its memory. */ 
294         ppriv->connect_via_list = _modest_global_settings_dialog_get_connected_via ();
295         ppriv->connect_via = modest_toolkit_factory_create_selector (modest_runtime_get_toolkit_factory (),
296                                                                      ppriv->connect_via_list, g_int_equal);
297         if (GTK_IS_COMBO_BOX (ppriv->connect_via)) {
298                 GtkWidget *caption;
299                 caption = modest_toolkit_utils_create_vcaptioned (title_size_group,
300                                                                   _("mcen_fi_options_connectiontype"), FALSE,
301                                                                   ppriv->connect_via);
302                 gtk_widget_show (caption);
303                 gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, 0);
304         } else {
305                 modest_toolkit_utils_set_vbutton_layout (title_size_group, 
306                                                          _("mcen_fi_options_connectiontype"),
307                                                          ppriv->connect_via);
308                 gtk_box_pack_start (GTK_BOX (vbox), ppriv->connect_via, FALSE, FALSE, 0);
309         }
310
311         /* Update interval */
312
313         /* Note: This ModestPairList* must exist for as long as the picker
314          * that uses it, because the ModestSelectorPicker uses the ID opaquely, 
315          * so it can't know how to manage its memory. */ 
316         ppriv->update_interval_list = _modest_global_settings_dialog_get_update_interval ();
317         ppriv->update_interval = modest_toolkit_factory_create_selector (modest_runtime_get_toolkit_factory (),
318                                                                          ppriv->update_interval_list, g_int_equal);
319         if (GTK_IS_COMBO_BOX (ppriv->update_interval)) {
320                 GtkWidget *caption;
321                 caption = modest_toolkit_utils_create_vcaptioned (title_size_group,
322                                                                   _("mcen_fi_options_updateinterval"), FALSE,
323                                                                   ppriv->update_interval);
324                 gtk_widget_show (caption);
325                 gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, 0);
326         } else {
327                 modest_toolkit_utils_set_vbutton_layout (title_size_group, 
328                                                          _("mcen_fi_options_updateinterval"), 
329                                                          ppriv->update_interval);
330                 gtk_box_pack_start (GTK_BOX (vbox), ppriv->update_interval, FALSE, FALSE, 0);
331         }
332
333         scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
334
335         modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), vbox);
336         gtk_widget_show (vbox);
337         gtk_widget_show (scrollable);
338
339         g_object_unref (title_size_group);
340         g_object_unref (value_size_group);
341
342         return scrollable;
343 }
344
345
346 static void
347 update_sensitive (ModestGlobalSettingsDialog *dialog)
348 {
349         ModestGlobalSettingsDialogPrivate *ppriv;
350
351         g_return_if_fail (MODEST_IS_GLOBAL_SETTINGS_DIALOG (dialog));
352         ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (dialog);
353
354         if (modest_togglable_get_active (ppriv->auto_update)) {
355                 gtk_widget_set_sensitive (ppriv->connect_via, TRUE);
356                 gtk_widget_set_sensitive (ppriv->update_interval, TRUE);
357         } else {
358                 gtk_widget_set_sensitive (ppriv->connect_via, FALSE);
359                 gtk_widget_set_sensitive (ppriv->update_interval, FALSE);
360         }
361 }
362
363 static void
364 on_auto_update_clicked (GtkButton *button,
365                         gpointer user_data)
366 {
367         g_return_if_fail (MODEST_IS_GLOBAL_SETTINGS_DIALOG (user_data));
368         update_sensitive ((ModestGlobalSettingsDialog *) user_data);
369 }
370
371 static ModestConnectedVia
372 current_connection (void)
373 {
374         return modest_platform_get_current_connection ();
375 }
376
377 static gint
378 order_by_acc_name (gconstpointer a,
379                    gconstpointer b)
380 {
381         ModestPair *pair_a, *pair_b;
382
383         pair_a = (ModestPair *) a;
384         pair_b = (ModestPair *) b;
385
386         if (pair_a->second && pair_b->second) {
387                 gint compare = g_utf8_collate ((gchar *) pair_a->second,
388                                                (gchar *) pair_b->second);
389                 if (compare > 0)
390                         compare = -1;
391                 else if (compare < 0)
392                         compare = 1;
393
394                 return compare;
395         } else {
396                 return 0;
397         }
398 }
399
400 static ModestPairList *
401 get_accounts_list (void)
402 {
403         GSList *list = NULL;
404         GSList *cursor, *account_names;
405         ModestAccountMgr *account_mgr;
406
407         account_mgr = modest_runtime_get_account_mgr ();
408
409         cursor = account_names = modest_account_mgr_account_names (account_mgr, TRUE /*only enabled*/);
410         while (cursor) {
411                 gchar *account_name;
412                 ModestAccountSettings *settings;
413                 ModestServerAccountSettings *store_settings;
414
415                 account_name = (gchar*)cursor->data;
416
417                 settings = modest_account_mgr_load_account_settings (account_mgr, account_name);
418                 if (!settings) {
419                         g_printerr ("modest: failed to get account data for %s\n", account_name);
420                         cursor = cursor->next;
421                         continue;
422                 }
423                 store_settings = modest_account_settings_get_store_settings (settings);
424
425                 /* don't display accounts without stores */
426                 if (modest_server_account_settings_get_account_name (store_settings) != NULL) {
427
428                         if (modest_account_settings_get_enabled (settings)) {
429                                 ModestPair *pair;
430
431                                 pair = modest_pair_new (
432                                         g_strdup (account_name),
433                                         g_strdup (modest_account_settings_get_display_name (settings)),
434                                         FALSE);
435                                 list = g_slist_insert_sorted (list, pair, order_by_acc_name);
436                         }
437                 }
438
439                 g_object_unref (store_settings);
440                 g_object_unref (settings);
441                 cursor = cursor->next;
442         }
443
444         return (ModestPairList *) g_slist_reverse (list);
445 }
446
447
448 static void
449 modest_hildon2_global_settings_dialog_load_settings (ModestGlobalSettingsDialog *self)
450 {
451         ModestConf *conf;
452         gboolean checked;
453         gint combo_id;
454         GError *error = NULL;
455         ModestGlobalSettingsDialogPrivate *ppriv;
456
457         ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
458         conf = modest_runtime_get_conf ();
459
460         /* Incoming notifications */
461         checked = modest_conf_get_bool (conf, MODEST_CONF_NOTIFICATIONS, &error);
462         if (error) {
463                 g_clear_error (&error);
464                 error = NULL;
465                 checked = FALSE;
466         }
467         hildon_check_button_set_active (HILDON_CHECK_BUTTON (ppriv->notifications), checked);
468         ppriv->initial_state.notifications = checked;
469
470         /* Add to contacts */
471         checked = modest_conf_get_bool (conf, MODEST_CONF_AUTO_ADD_TO_CONTACTS, &error);
472         if (error) {
473                 g_clear_error (&error);
474                 error = NULL;
475                 checked = FALSE;
476         }
477         hildon_check_button_set_active (HILDON_CHECK_BUTTON (ppriv->add_to_contacts), checked);
478         ppriv->initial_state.add_to_contacts = checked;
479
480         /* Autoupdate */
481         checked = modest_conf_get_bool (conf, MODEST_CONF_AUTO_UPDATE, &error);
482         if (error) {
483                 g_clear_error (&error);
484                 error = NULL;
485                 checked = FALSE;
486         }
487         modest_togglable_set_active (ppriv->auto_update, checked);
488         ppriv->initial_state.auto_update = checked;
489
490         /* Connected by */
491         combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, &error);
492         if (error) {
493                 g_error_free (error);
494                 error = NULL;
495                 combo_id = MODEST_CONNECTED_VIA_WLAN_OR_WIMAX;
496         }
497         modest_selector_set_active_id (ppriv->connect_via,
498                                        (gpointer) &combo_id);
499         ppriv->initial_state.connect_via = combo_id;
500
501         /* Update interval */
502         combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_INTERVAL, &error);
503         if (error) {
504                 g_error_free (error);
505                 error = NULL;
506                 combo_id = MODEST_UPDATE_INTERVAL_15_MIN;
507         }
508         modest_selector_set_active_id (ppriv->update_interval,
509                                        (gpointer) &combo_id);
510         ppriv->initial_state.update_interval = combo_id;
511
512         /* Play sound */
513         checked = modest_conf_get_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, &error);
514         if (error) {
515                 g_error_free (error);
516                 error = NULL;
517                 checked = FALSE;
518         }
519         ppriv->initial_state.play_sound = checked;
520
521         /* Msg format */
522         checked = modest_conf_get_bool (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, &error);
523         if (error) {
524                 g_error_free (error);
525                 error = NULL;
526                 combo_id = MODEST_FILE_FORMAT_FORMATTED_TEXT;
527         }
528         combo_id = (checked) ? MODEST_FILE_FORMAT_FORMATTED_TEXT : MODEST_FILE_FORMAT_PLAIN_TEXT;
529         modest_selector_set_active_id (ppriv->msg_format,
530                                        (gpointer) &combo_id);
531         ppriv->initial_state.prefer_formatted_text = checked;
532
533         /* force update of sensitiveness */
534         update_sensitive (MODEST_GLOBAL_SETTINGS_DIALOG (self));
535 }