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