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.
32 #endif /*HAVE_CONFIG_H*/
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"
49 /* include other impl specific header files */
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);
63 static GtkWidget* create_updating_page (ModestGnomeGlobalSettingsDialog *self);
64 static GtkWidget* create_composing_page (ModestGnomeGlobalSettingsDialog *self);
65 static ModestConnectedVia current_connection (void);
67 typedef struct _ModestGnomeGlobalSettingsDialogPrivate ModestGnomeGlobalSettingsDialogPrivate;
68 struct _ModestGnomeGlobalSettingsDialogPrivate {
70 #define MODEST_GNOME_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
71 MODEST_TYPE_GNOME_GLOBAL_SETTINGS_DIALOG, \
72 ModestGnomeGlobalSettingsDialogPrivate))
74 static GtkDialogClass *parent_class = NULL;
76 /* uncomment the following if you have defined any signals */
77 /* static guint signals[LAST_SIGNAL] = {0}; */
80 modest_gnome_global_settings_dialog_get_type (void)
82 static GType my_type = 0;
84 static const GTypeInfo my_info = {
85 sizeof(ModestGnomeGlobalSettingsDialogClass),
87 NULL, /* base finalize */
88 (GClassInitFunc) modest_gnome_global_settings_dialog_class_init,
89 NULL, /* class finalize */
90 NULL, /* class data */
91 sizeof(ModestGnomeGlobalSettingsDialog),
93 (GInstanceInitFunc) modest_gnome_global_settings_dialog_init,
96 my_type = g_type_register_static (MODEST_TYPE_GLOBAL_SETTINGS_DIALOG,
97 "ModestGnomeGlobalSettingsDialog",
104 modest_gnome_global_settings_dialog_class_init (ModestGnomeGlobalSettingsDialogClass *klass)
106 GObjectClass *gobject_class;
107 gobject_class = (GObjectClass*) klass;
109 parent_class = g_type_class_peek_parent (klass);
110 gobject_class->finalize = modest_gnome_global_settings_dialog_finalize;
112 g_type_class_add_private (gobject_class, sizeof(ModestGnomeGlobalSettingsDialogPrivate));
114 MODEST_GLOBAL_SETTINGS_DIALOG_CLASS (klass)->current_connection_func = current_connection;
118 modest_gnome_global_settings_dialog_init (ModestGnomeGlobalSettingsDialog *self)
120 ModestGlobalSettingsDialogPrivate *ppriv;
121 /* GdkGeometry *geometry; */
123 ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
125 gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
127 ppriv->updating_page = create_updating_page (self);
128 ppriv->composing_page = create_composing_page (self);
130 /* Add the notebook pages: */
131 gtk_notebook_append_page (GTK_NOTEBOOK (ppriv->notebook), ppriv->updating_page,
132 gtk_label_new (_("mcen_ti_options_updating")));
133 gtk_notebook_append_page (GTK_NOTEBOOK (ppriv->notebook), ppriv->composing_page,
134 gtk_label_new (_("mcen_ti_options_composing")));
136 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), ppriv->notebook);
137 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (self)->vbox), 12);
138 gtk_container_set_border_width (GTK_CONTAINER (self), 12);
139 gtk_window_set_default_size (GTK_WINDOW (self), 480, -1);
141 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->action_area), 0);
143 /* Load current config */
144 _modest_global_settings_dialog_load_conf (MODEST_GLOBAL_SETTINGS_DIALOG (self));
146 /* Add the buttons: */
147 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
148 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_SAVE, GTK_RESPONSE_OK);
150 gtk_widget_show_all (ppriv->notebook);
154 modest_gnome_global_settings_dialog_finalize (GObject *obj)
156 /* free/unref instance resources here */
157 G_OBJECT_CLASS(parent_class)->finalize (obj);
161 modest_gnome_global_settings_dialog_new (void)
163 return GTK_WIDGET(g_object_new(MODEST_TYPE_GNOME_GLOBAL_SETTINGS_DIALOG, NULL));
168 * Adds the two widgets to a new row in the table
171 add_to_table (GtkTable *table,
177 g_object_get (G_OBJECT (table), "n-rows", &n_rows,NULL);
179 /* Attach label and value */
180 gtk_table_attach (table,
186 gtk_table_attach (table,
189 GTK_EXPAND | GTK_FILL,
195 * We need this because the translations are comming without ":"
198 create_label (const gchar *text)
203 label_name = g_strdup_printf ("%s:", text);
204 label = gtk_label_new (label_name);
205 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
212 * Creates the updating page
215 create_updating_page (ModestGnomeGlobalSettingsDialog *self)
217 GtkWidget *vbox, *table_update, *table_limit;
219 ModestGlobalSettingsDialogPrivate *ppriv;
221 ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
223 vbox = gtk_vbox_new (FALSE, 0);
224 table_update = gtk_table_new (3, 2, FALSE);
225 table_limit = gtk_table_new (2, 2, FALSE);
226 /* FIXME: set proper values (HIG) */
227 gtk_table_set_row_spacings (GTK_TABLE (table_update), 3);
228 gtk_table_set_col_spacings (GTK_TABLE (table_update), 12);
229 gtk_table_set_row_spacings (GTK_TABLE (table_limit), 3);
230 gtk_table_set_col_spacings (GTK_TABLE (table_limit), 12);
233 label = create_label (_("mcen_fi_options_autoupdate"));
234 ppriv->auto_update = gtk_check_button_new ();
235 add_to_table (GTK_TABLE (table_update), label, ppriv->auto_update);
238 label = create_label (_("mcen_fi_options_connectiontype"));
240 /* Note: This ModestPairList* must exist for as long as the combo
241 * that uses it, because the ModestComboBox uses the ID opaquely,
242 * so it can't know how to manage its memory. */
243 ppriv->connect_via_list = _modest_global_settings_dialog_get_connected_via ();
244 ppriv->connect_via = modest_combo_box_new (ppriv->connect_via_list, g_int_equal);
246 add_to_table (GTK_TABLE (table_update), label, ppriv->connect_via);
248 /* Update interval */
249 label = create_label (_("mcen_fi_options_updateinterval"));
251 /* Note: This ModestPairList* must exist for as long as the combo
252 * that uses it, because the ModestComboBox uses the ID opaquely,
253 * so it can't know how to manage its memory. */
254 ppriv->update_interval_list = _modest_global_settings_dialog_get_update_interval ();
255 ppriv->update_interval = modest_combo_box_new (ppriv->update_interval_list, g_int_equal);
257 add_to_table (GTK_TABLE (table_update), label, ppriv->update_interval);
260 gtk_box_pack_start (GTK_BOX (vbox), table_update, FALSE, FALSE, MODEST_MARGIN_HALF);
263 gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, MODEST_MARGIN_HALF);
266 label = create_label (_("mcen_fi_advsetup_sizelimit"));
267 ppriv->size_limit = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1000, 1, 5000, 1, 1, 16)),
269 add_to_table (GTK_TABLE (table_limit), label, ppriv->size_limit);
271 label = create_label (_("mcen_fi_options_playsound"));
272 ppriv->play_sound = gtk_check_button_new ();
273 add_to_table (GTK_TABLE (table_limit), label, ppriv->play_sound);
276 gtk_box_pack_start (GTK_BOX (vbox), table_limit, FALSE, FALSE, MODEST_MARGIN_HALF);
277 gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
283 * Creates the composing page
286 create_composing_page (ModestGnomeGlobalSettingsDialog *self)
288 GtkWidget *vbox, *table;
291 vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
292 table = gtk_table_new (2, 2, FALSE);
293 /* FIXME: set proper values */
294 gtk_table_set_row_spacings (GTK_TABLE (table), 3);
295 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
297 /* Update interval */
298 label = create_label (_("mcen_fi_options_messageformat"));
300 ModestGlobalSettingsDialogPrivate *ppriv =
301 MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
303 /* Note: This ModestPairList* must exist for as long as the combo
304 * that uses it, because the ModestComboBox uses the ID opaquely,
305 * so it can't know how to manage its memory. */
306 ppriv->msg_format_list = _modest_global_settings_dialog_get_msg_formats ();
307 ppriv->msg_format = modest_combo_box_new (ppriv->msg_format_list, g_int_equal);
309 add_to_table (GTK_TABLE (table), label, ppriv->msg_format);
312 gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
313 gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
318 static ModestConnectedVia
319 current_connection (void)
321 return MODEST_CONNECTED_VIA_ANY;