1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
30 #include <glib/gi18n.h>
31 #include <gtk/gtknotebook.h>
32 #include <gtk/gtkstock.h>
33 #include <gtk/gtklabel.h>
34 #include <gtk/gtktogglebutton.h>
35 #include "widgets/modest-global-settings-dialog.h"
36 #include "widgets/modest-global-settings-dialog-priv.h"
37 #include "modest-defs.h"
38 #include "modest-conf.h"
39 #include "modest-runtime.h"
40 #include "modest-ui-constants.h"
41 #include "modest-tny-msg.h"
42 #include "widgets/modest-combo-box.h"
43 #ifdef MODEST_PLATFORM_MAEMO
44 #ifdef MODEST_HILDON_VERSION_0
45 #include <hildon-widgets/hildon-number-editor.h>
47 #include <hildon/hildon-number-editor.h>
48 #endif /*MODEST_HILDON_VERSION_0*/
50 /* include other impl specific header files */
52 /* 'private'/'protected' functions */
53 static void modest_global_settings_dialog_class_init (ModestGlobalSettingsDialogClass *klass);
54 static void modest_global_settings_dialog_init (ModestGlobalSettingsDialog *obj);
55 static void modest_global_settings_dialog_finalize (GObject *obj);
57 static void on_response (GtkDialog *dialog,
69 static GtkDialogClass *parent_class = NULL;
71 /* uncomment the following if you have defined any signals */
72 /* static guint signals[LAST_SIGNAL] = {0}; */
75 modest_global_settings_dialog_get_type (void)
77 static GType my_type = 0;
79 static const GTypeInfo my_info = {
80 sizeof(ModestGlobalSettingsDialogClass),
82 NULL, /* base finalize */
83 (GClassInitFunc) modest_global_settings_dialog_class_init,
84 NULL, /* class finalize */
85 NULL, /* class data */
86 sizeof(ModestGlobalSettingsDialog),
88 (GInstanceInitFunc) modest_global_settings_dialog_init,
91 my_type = g_type_register_static (GTK_TYPE_DIALOG,
92 "ModestGlobalSettingsDialog",
99 modest_global_settings_dialog_class_init (ModestGlobalSettingsDialogClass *klass)
101 GObjectClass *gobject_class;
102 gobject_class = (GObjectClass*) klass;
104 parent_class = g_type_class_peek_parent (klass);
105 gobject_class->finalize = modest_global_settings_dialog_finalize;
107 g_type_class_add_private (gobject_class, sizeof(ModestGlobalSettingsDialogPrivate));
111 modest_global_settings_dialog_init (ModestGlobalSettingsDialog *self)
113 ModestGlobalSettingsDialogPrivate *priv;
114 /* GdkGeometry *geometry; */
116 priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
118 priv->notebook = gtk_notebook_new ();
120 /* Add the buttons: */
121 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
122 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
124 /* Connect to the dialog's response signal: */
125 g_signal_connect (G_OBJECT (self), "response",
126 G_CALLBACK (on_response), self);
129 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_options"));
132 /* geometry = g_malloc0(sizeof (GdkGeometry)); */
133 /* geometry->max_width = MODEST_DIALOG_WINDOW_MAX_WIDTH; */
134 /* geometry->min_width = MODEST_DIALOG_WINDOW_MIN_WIDTH; */
135 /* geometry->max_height = MODEST_DIALOG_WINDOW_MAX_HEIGHT; */
136 /* geometry->min_height = MODEST_DIALOG_WINDOW_MIN_HEIGHT; */
137 /* gtk_window_set_geometry_hints (GTK_WINDOW (self), */
138 /* GTK_WIDGET (self), */
140 /* GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); */
141 gtk_widget_set_size_request (GTK_WIDGET (self),
142 MODEST_DIALOG_WINDOW_MAX_WIDTH,
143 MODEST_DIALOG_WINDOW_MAX_HEIGHT);
147 modest_global_settings_dialog_finalize (GObject *obj)
149 /* free/unref instance resources here */
150 G_OBJECT_CLASS(parent_class)->finalize (obj);
154 * Creates a pair list (number,string) and adds it to the given list
157 add_to_modest_pair_list (const gint num, const gchar *str, GSList **list)
162 number = g_malloc0 (sizeof (gint));
164 pair = modest_pair_new (number, g_strdup (str), FALSE);
165 *list = g_slist_prepend (*list, pair);
169 * Gets a list of pairs
172 _modest_global_settings_dialog_get_connected_via (void)
176 add_to_modest_pair_list (MODEST_CONNECTED_VIA_WLAN,
177 _("mcen_va_options_connectiontype_wlan"),
179 add_to_modest_pair_list (MODEST_CONNECTED_VIA_ANY,
180 _("mcen_va_options_connectiontype_all"),
183 return (ModestPairList *) g_slist_reverse (list);
187 * Gets a list of pairs of update intervals
190 _modest_global_settings_dialog_get_update_interval (void)
194 add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_5_MIN,
195 _("mcen_va_options_updateinterval_5min"),
197 add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_10_MIN,
198 _("mcen_va_options_updateinterval_10min"),
200 add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_15_MIN,
201 _("mcen_va_options_updateinterval_15min"),
203 add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_30_MIN,
204 _("mcen_va_options_updateinterval_30min"),
206 add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_1_HOUR,
207 _("mcen_va_options_updateinterval_1h"),
209 add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_2_HOUR,
210 _("mcen_va_options_updateinterval_2h"),
213 return (ModestPairList *) g_slist_reverse (list);
217 * Gets a list of pairs
220 _modest_global_settings_dialog_get_msg_formats (void)
224 add_to_modest_pair_list (MODEST_FILE_FORMAT_FORMATTED_TEXT,
225 _("mcen_va_options_messageformat_html"),
227 add_to_modest_pair_list (MODEST_FILE_FORMAT_PLAIN_TEXT,
228 _("mcen_va_options_messageformat_plain"),
231 return (ModestPairList *) g_slist_reverse (list);
235 _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *priv)
239 gint combo_id, value;
240 GError *error = NULL;
242 conf = modest_runtime_get_conf ();
245 checked = modest_conf_get_bool (conf, MODEST_CONF_AUTO_UPDATE, &error);
247 g_clear_error (&error);
251 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->auto_update), checked);
254 combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, &error);
256 g_error_free (error);
258 combo_id = MODEST_CONNECTED_VIA_WLAN;
260 modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->connect_via),
261 (gpointer) &combo_id);
263 /* Update interval */
264 combo_id = modest_conf_get_int (conf, MODEST_CONF_UPDATE_INTERVAL, &error);
266 g_error_free (error);
268 combo_id = MODEST_UPDATE_INTERVAL_15_MIN;
270 modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->update_interval),
271 (gpointer) &combo_id);
274 value = modest_conf_get_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, &error);
276 g_error_free (error);
280 /* It's better to do this in the subclasses, but it's just one
281 line, so we'll leave it here for the moment */
282 #ifdef MODEST_PLATFORM_MAEMO
283 hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (priv->size_limit), value);
285 gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_limit, value);
288 /* TODO Fix with the value */
291 checked = modest_conf_get_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, &error);
293 g_error_free (error);
297 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->play_sound), checked);
300 combo_id = modest_conf_get_int (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, &error);
302 g_error_free (error);
304 combo_id = MODEST_FILE_FORMAT_FORMATTED_TEXT;
306 modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->msg_format),
307 (gpointer) &combo_id);
310 value = modest_conf_get_int (conf, MODEST_CONF_REPLY_TYPE, &error);
312 g_error_free (error);
314 value = MODEST_TNY_MSG_REPLY_TYPE_QUOTE;
316 if (value == MODEST_TNY_MSG_REPLY_TYPE_QUOTE)
320 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->include_reply), checked);
324 _modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv)
328 gint *combo_id, value;
330 conf = modest_runtime_get_conf ();
333 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auto_update));
334 modest_conf_set_bool (conf, MODEST_CONF_AUTO_UPDATE, checked, NULL);
337 combo_id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->connect_via));
338 modest_conf_set_int (conf, MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, *combo_id, NULL);
340 /* Update interval */
341 combo_id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->update_interval));
342 modest_conf_set_int (conf, MODEST_CONF_UPDATE_INTERVAL, *combo_id, NULL);
345 /* It's better to do this in the subclasses, but it's just one
346 line, so we'll leave it here for the moment */
347 #ifdef MODEST_PLATFORM_MAEMO
348 value = hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (priv->size_limit));
350 value = gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_limit);
352 modest_conf_set_int (conf, MODEST_CONF_MSG_SIZE_LIMIT, value, NULL);
355 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->play_sound));
356 modest_conf_set_bool (conf, MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, checked, NULL);
359 combo_id = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->msg_format));
360 modest_conf_set_int (conf, MODEST_CONF_PREFER_FORMATTED_TEXT, *combo_id, NULL);
363 checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->include_reply));
364 modest_conf_set_int (conf, MODEST_CONF_REPLY_TYPE,
365 (checked) ? MODEST_TNY_MSG_REPLY_TYPE_QUOTE :
366 MODEST_TNY_MSG_REPLY_TYPE_CITE, NULL);
370 on_response (GtkDialog *dialog,
374 ModestGlobalSettingsDialogPrivate *priv;
376 priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data);
378 if (arg1 == GTK_RESPONSE_OK)
379 _modest_global_settings_dialog_save_conf (priv);