* Added global settings dialog specific implementations
[modest] / src / gnome / modest-gnome-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 <glib/gi18n.h>
35 #include <gtk/gtkbox.h>
36 #include <gtk/gtkvbox.h>
37 #include <gtk/gtknotebook.h>
38 #include <gtk/gtklabel.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkhseparator.h>
41 #include "widgets/modest-global-settings-dialog-priv.h"
42 #include "widgets/modest-combo-box.h"
43 #include "gnome/modest-gnome-global-settings-dialog.h"
44 #include "modest-ui-constants.h"
45
46
47 /* include other impl specific header files */
48
49 /* 'private'/'protected' functions */
50 static void modest_gnome_global_settings_dialog_class_init (ModestGnomeGlobalSettingsDialogClass *klass);
51 static void modest_gnome_global_settings_dialog_init       (ModestGnomeGlobalSettingsDialog *obj);
52 static void modest_gnome_global_settings_dialog_finalize   (GObject *obj);
53
54 /* list my signals  */
55 enum {
56         /* MY_SIGNAL_1, */
57         /* MY_SIGNAL_2, */
58         LAST_SIGNAL
59 };
60
61 static GtkWidget* create_updating_page  (ModestGnomeGlobalSettingsDialog *self);
62 static GtkWidget* create_composing_page (ModestGnomeGlobalSettingsDialog *self);
63
64 typedef struct _ModestGnomeGlobalSettingsDialogPrivate ModestGnomeGlobalSettingsDialogPrivate;
65 struct _ModestGnomeGlobalSettingsDialogPrivate {
66 };
67 #define MODEST_GNOME_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
68                                                            MODEST_TYPE_GNOME_GLOBAL_SETTINGS_DIALOG, \
69                                                            ModestGnomeGlobalSettingsDialogPrivate))
70 /* globals */
71 static GtkDialogClass *parent_class = NULL;
72
73 /* uncomment the following if you have defined any signals */
74 /* static guint signals[LAST_SIGNAL] = {0}; */
75
76 GType
77 modest_gnome_global_settings_dialog_get_type (void)
78 {
79         static GType my_type = 0;
80         if (!my_type) {
81                 static const GTypeInfo my_info = {
82                         sizeof(ModestGnomeGlobalSettingsDialogClass),
83                         NULL,           /* base init */
84                         NULL,           /* base finalize */
85                         (GClassInitFunc) modest_gnome_global_settings_dialog_class_init,
86                         NULL,           /* class finalize */
87                         NULL,           /* class data */
88                         sizeof(ModestGnomeGlobalSettingsDialog),
89                         1,              /* n_preallocs */
90                         (GInstanceInitFunc) modest_gnome_global_settings_dialog_init,
91                         NULL
92                 };
93                 my_type = g_type_register_static (MODEST_TYPE_GLOBAL_SETTINGS_DIALOG,
94                                                   "ModestGnomeGlobalSettingsDialog",
95                                                   &my_info, 0);
96         }
97         return my_type;
98 }
99
100 static void
101 modest_gnome_global_settings_dialog_class_init (ModestGnomeGlobalSettingsDialogClass *klass)
102 {
103         GObjectClass *gobject_class;
104         gobject_class = (GObjectClass*) klass;
105
106         parent_class            = g_type_class_peek_parent (klass);
107         gobject_class->finalize = modest_gnome_global_settings_dialog_finalize;
108
109         g_type_class_add_private (gobject_class, sizeof(ModestGnomeGlobalSettingsDialogPrivate));
110 }
111
112 static void
113 modest_gnome_global_settings_dialog_init (ModestGnomeGlobalSettingsDialog *self)
114 {
115         ModestGlobalSettingsDialogPrivate *ppriv;
116 /*      GdkGeometry *geometry; */
117
118         ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
119
120         ppriv->updating_page = create_updating_page (self);
121         ppriv->composing_page = create_composing_page (self);
122     
123         /* Add the notebook pages: */
124         gtk_notebook_append_page (GTK_NOTEBOOK (ppriv->notebook), ppriv->updating_page, 
125                 gtk_label_new (_("mcen_ti_options_updating")));
126         gtk_notebook_append_page (GTK_NOTEBOOK (ppriv->notebook), ppriv->composing_page, 
127                 gtk_label_new (_("mcen_ti_options_composing")));
128                 
129         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), ppriv->notebook);
130         gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->vbox), MODEST_MARGIN_HALF);
131         gtk_widget_show_all (ppriv->notebook);
132 }
133
134 static void
135 modest_gnome_global_settings_dialog_finalize (GObject *obj)
136 {
137 /*      free/unref instance resources here */
138         G_OBJECT_CLASS(parent_class)->finalize (obj);
139 }
140
141 GtkWidget*
142 modest_gnome_global_settings_dialog_new (void)
143 {
144         return GTK_WIDGET(g_object_new(MODEST_TYPE_GNOME_GLOBAL_SETTINGS_DIALOG, NULL));
145 }
146
147
148 /* 
149  * Adds the two widgets to a new row in the table
150  */
151 static void
152 add_to_table (GtkTable *table,
153               GtkWidget *left,
154               GtkWidget *right)
155 {
156         guint n_rows = 0;
157
158         g_object_get (G_OBJECT (table), "n-rows", &n_rows,NULL);
159
160         /* Attach label and value */
161         gtk_table_attach (table, 
162                           left, 0, 1, 
163                           n_rows, n_rows + 1, 
164                           GTK_SHRINK|GTK_FILL, 
165                           GTK_SHRINK|GTK_FILL, 
166                           0, 0);
167         gtk_table_attach (table, 
168                           right, 1, 2, 
169                           n_rows, n_rows + 1, 
170                           GTK_EXPAND|GTK_FILL, 
171                           GTK_SHRINK|GTK_FILL, 
172                           0, 0);
173 }
174
175 /* 
176  * We need this because the translations are comming without ":" 
177  */
178 static GtkWidget *
179 create_label (const gchar *text)
180 {
181         gchar *label_name;
182         GtkWidget *label;
183
184         label_name = g_strdup_printf ("%s:", text);
185         label = gtk_label_new (label_name);
186         g_free (label_name);
187
188         return label;
189 }
190
191 /*
192  * Creates the updating page
193  */
194 static GtkWidget*
195 create_updating_page (ModestGnomeGlobalSettingsDialog *self)
196 {
197         GtkWidget *vbox, *table_update, *table_limit;
198         GtkWidget *label, *check, *combo, *spin;
199         ModestPairList *list;
200
201         vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
202         table_update = gtk_table_new (3, 2, FALSE);
203         table_limit = gtk_table_new (2, 2, FALSE);
204         /* FIXME: set proper values (HIG) */
205         gtk_table_set_row_spacings (GTK_TABLE (table_update), 6);
206         gtk_table_set_col_spacings (GTK_TABLE (table_update), 12);
207         gtk_table_set_row_spacings (GTK_TABLE (table_limit), 6);
208         gtk_table_set_col_spacings (GTK_TABLE (table_limit), 12);
209
210         /* Autoupdate */
211         label = create_label (_("mcen_fi_options_autoupdate"));
212         check = gtk_check_button_new ();
213         add_to_table (GTK_TABLE (table_update), label, check);
214
215         /* Connected via */
216         label = create_label (_("mcen_fi_options_connectiontype"));
217         list = get_connected_via ();
218         combo = modest_combo_box_new (list, g_int_equal);
219         modest_pair_list_free (list);
220         add_to_table (GTK_TABLE (table_update), label, combo);
221
222         /* Update interval */
223         label = create_label (_("mcen_fi_options_updateinterval"));
224         list = get_update_interval ();
225         combo = modest_combo_box_new (list, g_int_equal);
226         modest_pair_list_free (list);
227         add_to_table (GTK_TABLE (table_update), label, combo);
228
229         /* Add to vbox */
230         gtk_box_pack_start (GTK_BOX (vbox), table_update, FALSE, FALSE, MODEST_MARGIN_HALF);
231
232         /* Separator */
233         gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, MODEST_MARGIN_HALF);
234
235         /* Limits */
236         label = create_label (_("mcen_fi_advsetup_sizelimit"));
237         spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1000, 1, 5000, 1, 1, 16)), 
238                                     1, 0);
239         add_to_table (GTK_TABLE (table_limit), label, spin);
240
241         label = create_label (_("mcen_fi_options_playsound"));
242         check = gtk_check_button_new ();
243         add_to_table (GTK_TABLE (table_limit), label, check);
244
245         /* Add to vbox */
246         gtk_box_pack_start (GTK_BOX (vbox), table_limit, FALSE, FALSE, MODEST_MARGIN_HALF);
247
248         return vbox;
249 }
250
251 /*
252  * Creates the composing page
253  */
254 static GtkWidget* 
255 create_composing_page (ModestGnomeGlobalSettingsDialog *self)
256 {
257         GtkWidget *vbox, *table;
258         GtkWidget *label, *check, *combo;
259         ModestPairList *list;
260
261         vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
262         table = gtk_table_new (2, 2, FALSE);
263         /* FIXME: set proper values */
264         gtk_table_set_row_spacings (GTK_TABLE (table), 6);
265         gtk_table_set_col_spacings (GTK_TABLE (table), 12);
266
267         /* Update interval */
268         label = create_label (_("mcen_fi_options_messageformat"));
269         list = get_msg_formats ();
270         combo = modest_combo_box_new (list, g_int_equal);
271         modest_pair_list_free (list);
272         add_to_table (GTK_TABLE (table), label, combo);
273
274         label = create_label (_("mcen_va_options_include_original_inreply"));
275         check = gtk_check_button_new ();
276         add_to_table (GTK_TABLE (table), label, check);
277
278         /* Add to vbox */
279         gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, MODEST_MARGIN_HALF);
280
281         return vbox;
282 }