* Fixed a compilation warning in Maemo
[modest] / src / widgets / modest-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 #include <glib/gi18n.h>
31 #include "modest-global-settings-dialog.h"
32 #include "modest-defs.h"
33 #include "modest-ui-constants.h"
34 #include "widgets/modest-combo-box.h"
35 /* include other impl specific header files */
36
37 /* 'private'/'protected' functions */
38 static void modest_global_settings_dialog_class_init (ModestGlobalSettingsDialogClass *klass);
39 static void modest_global_settings_dialog_init       (ModestGlobalSettingsDialog *obj);
40 static void modest_global_settings_dialog_finalize   (GObject *obj);
41
42 enum {
43         MODEST_CONNECTED_VIA_WLAN,
44         MODEST_CONNECTED_VIA_ANY
45 };
46
47 enum {
48         MODEST_UPDATE_INTERVAL_5_MIN,
49         MODEST_UPDATE_INTERVAL_10_MIN,
50         MODEST_UPDATE_INTERVAL_15_MIN,
51         MODEST_UPDATE_INTERVAL_30_MIN,
52         MODEST_UPDATE_INTERVAL_1_HOUR,
53         MODEST_UPDATE_INTERVAL_2_HOUR
54 };
55
56 /* list my signals  */
57 enum {
58         /* MY_SIGNAL_1, */
59         /* MY_SIGNAL_2, */
60         LAST_SIGNAL
61 };
62
63 static GtkWidget* create_updating_page  (void);
64 static GtkWidget* create_composing_page (void);
65
66 typedef struct _ModestGlobalSettingsDialogPrivate ModestGlobalSettingsDialogPrivate;
67 struct _ModestGlobalSettingsDialogPrivate {
68         GtkWidget *notebook;
69         GtkWidget *updating_page;
70         GtkWidget *composing_page;
71         gboolean   modified;
72 };
73 #define MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
74                                                            MODEST_TYPE_GLOBAL_SETTINGS_DIALOG, \
75                                                            ModestGlobalSettingsDialogPrivate))
76 /* globals */
77 static GtkDialogClass *parent_class = NULL;
78
79 /* uncomment the following if you have defined any signals */
80 /* static guint signals[LAST_SIGNAL] = {0}; */
81
82 GType
83 modest_global_settings_dialog_get_type (void)
84 {
85         static GType my_type = 0;
86         if (!my_type) {
87                 static const GTypeInfo my_info = {
88                         sizeof(ModestGlobalSettingsDialogClass),
89                         NULL,           /* base init */
90                         NULL,           /* base finalize */
91                         (GClassInitFunc) modest_global_settings_dialog_class_init,
92                         NULL,           /* class finalize */
93                         NULL,           /* class data */
94                         sizeof(ModestGlobalSettingsDialog),
95                         1,              /* n_preallocs */
96                         (GInstanceInitFunc) modest_global_settings_dialog_init,
97                         NULL
98                 };
99                 my_type = g_type_register_static (GTK_TYPE_DIALOG,
100                                                   "ModestGlobalSettingsDialog",
101                                                   &my_info, 0);
102         }
103         return my_type;
104 }
105
106 static void
107 modest_global_settings_dialog_class_init (ModestGlobalSettingsDialogClass *klass)
108 {
109         GObjectClass *gobject_class;
110         gobject_class = (GObjectClass*) klass;
111
112         parent_class            = g_type_class_peek_parent (klass);
113         gobject_class->finalize = modest_global_settings_dialog_finalize;
114
115         g_type_class_add_private (gobject_class, sizeof(ModestGlobalSettingsDialogPrivate));
116 }
117
118 static void
119 modest_global_settings_dialog_init (ModestGlobalSettingsDialog *self)
120 {
121         ModestGlobalSettingsDialogPrivate *priv;
122 /*      GdkGeometry *geometry; */
123
124         priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
125
126         priv->modified = FALSE;
127         priv->notebook = gtk_notebook_new ();
128         priv->updating_page = create_updating_page ();
129         priv->composing_page = create_composing_page ();
130     
131         /* Add the notebook pages: */
132         gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), priv->updating_page, 
133                 gtk_label_new (_("mcen_ti_options_updating")));
134         gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), priv->composing_page, 
135                 gtk_label_new (_("mcen_ti_options_composing")));
136                 
137         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), priv->notebook);
138         gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->vbox), MODEST_MARGIN_HALF);
139         gtk_widget_show_all (priv->notebook);
140         
141         /* Add the buttons: */
142         gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
143         gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
144     
145 /*      /\* Connect to the dialog's response signal: *\/ */
146 /*      /\* We use connect-before  */
147 /*       * so we can stop the signal emission,  */
148 /*       * to stop the default signal handler from closing the dialog. */
149 /*       *\/ */
150 /*      g_signal_connect (G_OBJECT (self), "response", */
151 /*                        G_CALLBACK (on_response), self);  */
152
153         /* Set title */
154         gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_options"));
155
156         /* Set geometry */
157 /*      geometry = g_malloc0(sizeof (GdkGeometry)); */
158 /*      geometry->max_width = MODEST_DIALOG_WINDOW_MAX_WIDTH; */
159 /*      geometry->min_width = MODEST_DIALOG_WINDOW_MIN_WIDTH; */
160 /*      geometry->max_height = MODEST_DIALOG_WINDOW_MAX_HEIGHT; */
161 /*      geometry->min_height = MODEST_DIALOG_WINDOW_MIN_HEIGHT; */
162 /*      gtk_window_set_geometry_hints (GTK_WINDOW (self), */
163 /*                                     GTK_WIDGET (self), */
164 /*                                     geometry, */
165 /*                                     GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); */
166         gtk_widget_set_size_request (GTK_WIDGET (self), 
167                                      MODEST_DIALOG_WINDOW_MAX_WIDTH, 
168                                      MODEST_DIALOG_WINDOW_MAX_HEIGHT);
169 }
170
171 static void
172 modest_global_settings_dialog_finalize (GObject *obj)
173 {
174 /*      free/unref instance resources here */
175         G_OBJECT_CLASS(parent_class)->finalize (obj);
176 }
177
178 GtkWidget*
179 modest_global_settings_dialog_new (void)
180 {
181         return GTK_WIDGET(g_object_new(MODEST_TYPE_GLOBAL_SETTINGS_DIALOG, NULL));
182 }
183
184 /* 
185  * Adds the two widgets to a new row in the table
186  */
187 static void
188 add_to_table (GtkTable *table,
189               GtkWidget *left,
190               GtkWidget *right)
191 {
192         guint n_rows = 0;
193
194         g_object_get (G_OBJECT (table), "n-rows", &n_rows,NULL);
195
196         /* Create label */
197         gtk_misc_set_alignment (GTK_MISC (left), 1.0, 0.0);
198
199         /* Create value */
200 /*      gtk_misc_set_alignment (GTK_MISC (right), 0.0, 0.0); */
201
202         /* Attach label and value */
203         gtk_table_attach (table, 
204                           left, 0, 1, 
205                           n_rows, n_rows + 1, 
206                           GTK_SHRINK|GTK_FILL, 
207                           GTK_SHRINK|GTK_FILL, 
208                           0, 0);
209         gtk_table_attach (table, 
210                           right, 1, 2, 
211                           n_rows, n_rows + 1, 
212                           GTK_EXPAND|GTK_FILL, 
213                           GTK_SHRINK|GTK_FILL, 
214                           0, 0);
215 }
216
217 /*
218  * Creates a pair list (number,string) and adds it to the given list
219  */
220 static void
221 add_to_modest_pair_list (const gint num, const gchar *str, GSList **list)
222 {
223         guint *number;
224         ModestPair *pair;
225
226         number = g_malloc0 (sizeof (guint));
227         *number = num;
228         pair = modest_pair_new (number, g_strdup (str), TRUE);
229         *list = g_slist_prepend (*list, pair);
230 }
231
232 /*
233  * Gets a list of pairs 
234  */
235 static ModestPairList *
236 get_connected_via (void)
237 {
238         GSList *list = NULL;
239
240         add_to_modest_pair_list (MODEST_CONNECTED_VIA_WLAN, 
241                                  _("mcen_va_options_connectiontype_wlan"), 
242                                  &list);
243         add_to_modest_pair_list (MODEST_CONNECTED_VIA_ANY, 
244                                  _("mcen_va_options_connectiontype_all"), 
245                                  &list);
246
247         return (ModestPairList *) g_slist_reverse (list);
248 }
249
250 /*
251  * Gets a list of pairs of update intervals
252  */
253 static ModestPairList *
254 get_update_interval (void)
255 {
256         GSList *list = NULL;
257
258         add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_5_MIN, 
259                                  _("mcen_va_options_updateinterval_5min"), 
260                                  &list);
261         add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_10_MIN, 
262                                  _("mcen_va_options_updateinterval_10min"), 
263                                  &list);
264         add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_15_MIN, 
265                                  _("mcen_va_options_updateinterval_15min"), 
266                                  &list);
267         add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_30_MIN, 
268                                  _("mcen_va_options_updateinterval_30min"), 
269                                  &list);
270         add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_1_HOUR, 
271                                  _("mcen_va_options_updateinterval_1h"), 
272                                  &list);
273         add_to_modest_pair_list (MODEST_UPDATE_INTERVAL_2_HOUR, 
274                                  _("mcen_va_options_updateinterval_2h"), 
275                                  &list);
276
277         return (ModestPairList *) g_slist_reverse (list);
278 }
279
280 /* 
281  * We need this because the translations are comming without ":" 
282  */
283 static GtkWidget *
284 create_label (const gchar *text)
285 {
286         gchar *label_name;
287         GtkWidget *label;
288
289         label_name = g_strdup_printf ("%s:", text);
290         label = gtk_label_new (label_name);
291         g_free (label_name);
292
293         return label;
294 }
295
296 /*
297  * Creates the updating page
298  */
299 static GtkWidget*
300 create_updating_page (void)
301 {
302         GtkWidget *vbox, *table_update, *table_limit;
303         GtkWidget *label, *check, *combo, *spin;
304         ModestPairList *list;
305
306         vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
307         table_update = gtk_table_new (3, 2, FALSE);
308         table_limit = gtk_table_new (2, 2, FALSE);
309         /* FIXME: set proper values */
310         gtk_table_set_row_spacings (GTK_TABLE (table_update), 6);
311         gtk_table_set_col_spacings (GTK_TABLE (table_update), 12);
312         gtk_table_set_row_spacings (GTK_TABLE (table_limit), 6);
313         gtk_table_set_col_spacings (GTK_TABLE (table_limit), 12);
314
315         /* Autoupdate */
316         label = create_label (_("mcen_fi_options_autoupdate"));
317         check = gtk_check_button_new ();
318         add_to_table (GTK_TABLE (table_update), label, check);
319
320         /* Connected via */
321         label = create_label (_("mcen_fi_options_connectiontype"));
322         list = get_connected_via ();
323         combo = modest_combo_box_new (list, g_int_equal);
324         modest_pair_list_free (list);
325         add_to_table (GTK_TABLE (table_update), label, combo);
326
327         /* Update interval */
328         label = create_label (_("mcen_fi_options_updateinterval"));
329         list = get_update_interval ();
330         combo = modest_combo_box_new (list, g_int_equal);
331         modest_pair_list_free (list);
332         add_to_table (GTK_TABLE (table_update), label, combo);
333
334         /* Add to vbox */
335         gtk_box_pack_start (GTK_BOX (vbox), table_update, FALSE, FALSE, MODEST_MARGIN_HALF);
336
337         /* Separator */
338         gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, MODEST_MARGIN_HALF);
339
340         /* Limits */
341         label = create_label (_("mcen_fi_advsetup_sizelimit"));
342         spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1000, 1, 5000, 1, 1, 16)), 
343                                     1, 0);
344         add_to_table (GTK_TABLE (table_limit), label, spin);
345
346         label = create_label (_("mcen_fi_options_playsound"));
347         check = gtk_check_button_new ();
348         add_to_table (GTK_TABLE (table_limit), label, check);
349
350         /* Add to vbox */
351         gtk_box_pack_start (GTK_BOX (vbox), table_limit, FALSE, FALSE, MODEST_MARGIN_HALF);
352
353         return vbox;
354 }
355
356 /*
357  * Gets a list of pairs 
358  */
359 static ModestPairList *
360 get_msg_formats (void)
361 {
362         GSList *list = NULL;
363
364         add_to_modest_pair_list (MODEST_FILE_FORMAT_FORMATTED_TEXT, 
365                                  _("mcen_va_options_messageformat_html"), 
366                                  &list);
367         add_to_modest_pair_list (MODEST_FILE_FORMAT_PLAIN_TEXT, 
368                                  _("mcen_va_options_messageformat_plain"), 
369                                  &list);
370
371         return (ModestPairList *) g_slist_reverse (list);
372 }
373
374
375 /*
376  * Creates the composing page
377  */
378 static GtkWidget* 
379 create_composing_page (void)
380 {
381         GtkWidget *vbox, *table;
382         GtkWidget *label, *check, *combo;
383         ModestPairList *list;
384
385         vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
386         table = gtk_table_new (2, 2, FALSE);
387         /* FIXME: set proper values */
388         gtk_table_set_row_spacings (GTK_TABLE (table), 6);
389         gtk_table_set_col_spacings (GTK_TABLE (table), 12);
390
391         /* Update interval */
392         label = create_label (_("mcen_fi_options_messageformat"));
393         list = get_msg_formats ();
394         combo = modest_combo_box_new (list, g_int_equal);
395         modest_pair_list_free (list);
396         add_to_table (GTK_TABLE (table), label, combo);
397
398         label = create_label (_("mcen_va_options_include_original_inreply"));
399         check = gtk_check_button_new ();
400         add_to_table (GTK_TABLE (table), label, check);
401
402         /* Add to vbox */
403         gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, MODEST_MARGIN_HALF);
404
405         return vbox;
406 }