1 /* Copyright (c) 2009, Igalia
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 #ifdef MODEST_TOOLKIT_HILDON2
32 #include <hildon/hildon.h>
33 #include <hildon/hildon-file-chooser-dialog.h>
34 #include <modest-number-editor.h>
35 #include <modest-ui-constants.h>
37 #include "modest-toolkit-factory.h"
39 #ifndef MODEST_TOOLKIT_HILDON2
40 #define USE_SCROLLED_WINDOW
41 #define USE_GTK_FIND_TOOLBAR
42 #define USE_GTK_CHECK_BUTTON
43 #define USE_GTK_CHECK_MENU
45 #define USE_GTK_FILE_CHOOSER
46 #define USE_COUNTRY_COMBOBOX
49 #ifdef USE_SCROLLED_WINDOW
50 #include <modest-scrolled-window-scrollable.h>
52 #include <modest-hildon-pannable-area-scrollable.h>
55 #ifdef USE_GTK_TOOLBAR
56 #include <modest-find-toolbar.h>
58 #include <modest-hildon-find-toolbar.h>
61 #ifdef USE_COUNTRY_COMBOBOX
62 #include <modest-country-combo-box.h>
64 #include <modest-country-picker.h>
67 static void modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass);
68 static void modest_toolkit_factory_init (ModestToolkitFactory *self);
70 /* GObject interface */
71 static GtkWidget * modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self);
72 static GtkWidget * modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self,
74 static GtkWidget * modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self,
76 static GtkWidget * modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self,
78 static GtkWidget * modest_toolkit_factory_create_entry_default (ModestToolkitFactory *self);
79 static GtkWidget * modest_toolkit_factory_create_number_entry_default (ModestToolkitFactory *self,
82 static GtkWidget * modest_toolkit_factory_create_file_chooser_dialog_default (ModestToolkitFactory *self,
85 GtkFileChooserAction action);
86 static GtkWidget * modest_toolkit_factory_create_country_selector_default (ModestToolkitFactory *self);
88 static GObjectClass *parent_class = NULL;
90 G_DEFINE_TYPE (ModestToolkitFactory,
91 modest_toolkit_factory,
94 ModestToolkitFactory *
95 modest_toolkit_factory_get_instance (void)
97 GObject* self = g_object_new (MODEST_TYPE_TOOLKIT_FACTORY, NULL);
99 return (ModestToolkitFactory *) self;
103 modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass)
105 parent_class = g_type_class_peek_parent (klass);
107 klass->create_scrollable = modest_toolkit_factory_create_scrollable_default;
108 klass->create_check_button = modest_toolkit_factory_create_check_button_default;
109 klass->create_check_menu = modest_toolkit_factory_create_check_menu_default;
110 klass->create_isearch_toolbar = modest_toolkit_factory_create_isearch_toolbar_default;
111 klass->create_entry = modest_toolkit_factory_create_entry_default;
112 klass->create_number_entry = modest_toolkit_factory_create_number_entry_default;
113 klass->create_file_chooser_dialog = modest_toolkit_factory_create_file_chooser_dialog_default;
114 klass->create_country_selector = modest_toolkit_factory_create_country_selector_default;
118 modest_toolkit_factory_init (ModestToolkitFactory *self)
123 modest_toolkit_factory_create_scrollable (ModestToolkitFactory *self)
125 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_scrollable (self);
129 modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self)
131 #ifdef USE_SCROLLED_WINDOW
132 return modest_scrolled_window_scrollable_new ();
134 return modest_hildon_pannable_area_scrollable_new ();
139 modest_toolkit_factory_create_check_button (ModestToolkitFactory *self, const gchar *label)
141 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_button (self, label);
145 modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self, const gchar *label)
148 #ifdef USE_GTK_CHECK_BUTTON
149 result = gtk_check_button_new_with_label (label);
151 result = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
152 gtk_button_set_label (GTK_BUTTON (result), label);
153 gtk_button_set_alignment (GTK_BUTTON (result), 0.0, 0.5);
159 modest_toolkit_factory_create_check_menu (ModestToolkitFactory *self, const gchar *label)
161 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_menu (self, label);
165 modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self, const gchar *label)
168 #ifdef USE_GTK_CHECK_MENU
169 result = gtk_check_menu_item_new_with_label (label);
171 result = hildon_check_button_new (0);
172 gtk_button_set_label (GTK_BUTTON (result), label);
173 gtk_button_set_alignment (GTK_BUTTON (result), 0.5, 0.5);
179 modest_togglable_get_active (GtkWidget *widget)
181 if (GTK_IS_CHECK_MENU_ITEM (widget)) {
182 return gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
183 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
184 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
185 #ifdef MODEST_TOOLKIT_HILDON2
186 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
187 return hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget));
190 g_return_val_if_reached (FALSE);
195 modest_togglable_set_active (GtkWidget *widget, gboolean active)
197 if (GTK_IS_CHECK_MENU_ITEM (widget)) {
198 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), active);
199 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
200 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), active);
201 #ifdef MODEST_TOOLKIT_HILDON2
202 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
203 hildon_check_button_set_active (HILDON_CHECK_BUTTON (widget), active);
209 modest_is_togglable (GtkWidget *widget)
211 return GTK_IS_CHECK_MENU_ITEM (widget)
212 || GTK_IS_TOGGLE_BUTTON (widget)
213 #ifdef MODEST_TOOLKIT_HILDON2
214 || HILDON_IS_CHECK_BUTTON (widget)
220 modest_toolkit_factory_create_isearch_toolbar (ModestToolkitFactory *self, const gchar *label)
222 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_isearch_toolbar (self, label);
226 modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self, const gchar *label)
229 #ifdef USE_GTK_FIND_TOOLBAR
230 result = modest_find_toolbar_new (label);
232 result = modest_hildon_find_toolbar_new (label);
238 modest_toolkit_factory_create_entry (ModestToolkitFactory *self)
240 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_entry (self);
244 modest_toolkit_factory_create_entry_default (ModestToolkitFactory *self)
247 return gtk_entry_new ();
249 return hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
254 modest_entry_set_text (GtkWidget *widget, const gchar *text)
256 #ifdef MODEST_TOOLKIT_HILDON2
257 hildon_entry_set_text (HILDON_ENTRY (widget), text);
259 gtk_entry_set_text (GTK_ENTRY (widget), text);
264 modest_entry_get_text (GtkWidget *widget)
266 #ifdef MODEST_TOOLKIT_HILDON2
267 return hildon_entry_get_text (HILDON_ENTRY (widget));
269 return gtk_entry_set_text (GTK_ENTRY (widget));
274 modest_entry_set_hint (GtkWidget *widget, const gchar *hint)
276 #ifdef MODEST_TOOLKIT_HILDON2
277 hildon_entry_set_placeholder (HILDON_ENTRY (widget), hint);
279 gtk_widget_set_tooltip_text (widget, hint);
284 modest_is_entry (GtkWidget *widget)
286 #ifdef MODEST_TOOLKIT_HILDON2
287 return HILDON_IS_ENTRY (widget);
289 return GTK_IS_ENTRY (widget);
294 modest_toolkit_factory_create_number_entry (ModestToolkitFactory *self, gint min, gint max)
296 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_number_entry (self, min, max);
300 modest_toolkit_factory_create_number_entry_default (ModestToolkitFactory *self, gint min, gint max)
303 #ifdef USE_GTK_SPIN_BUTTON
304 result = gtk_spin_button_new_with_range (min, max, 1.0);
305 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (result), 0);
307 result = modest_number_editor_new (min, max);
313 modest_number_entry_set_value (GtkWidget *widget, gint value)
315 #ifdef USE_GTK_SPIN_BUTTON
316 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
318 modest_number_editor_set_value (MODEST_NUMBER_EDITOR (widget), value);
323 modest_number_entry_get_value (GtkWidget *widget)
325 #ifdef USE_GTK_SPIN_BUTTON
326 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
328 return modest_number_editor_get_value (MODEST_NUMBER_EDITOR (widget));
333 modest_number_entry_is_valid (GtkWidget *widget)
335 #ifdef USE_GTK_SPIN_BUTTON
338 return modest_number_editor_is_valid (MODEST_NUMBER_EDITOR (widget));
343 modest_is_number_entry (GtkWidget *widget)
345 #ifdef USE_GTK_SPIN_BUTTON
346 return GTK_IS_SPIN_BUTTON (widget);
348 return MODEST_IS_NUMBER_EDITOR (widget);
353 modest_toolkit_factory_create_file_chooser_dialog (ModestToolkitFactory *self,
356 GtkFileChooserAction action)
358 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_file_chooser_dialog (self, title, parent, action);
362 modest_toolkit_factory_create_file_chooser_dialog_default (ModestToolkitFactory *self,
365 GtkFileChooserAction action)
368 #ifdef USE_GTK_FILE_CHOOSER
369 result = gtk_file_chooser_dialog_new (title, parent, action,
370 (action == GTK_FILE_CHOOSER_ACTION_OPEN) ? GTK_STOCK_OPEN : GTK_STOCK_SAVE,
372 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
375 result = hildon_file_chooser_dialog_new (parent, action);
376 gtk_window_set_title ((GtkWindow *) result, title);
382 modest_toolkit_factory_create_country_selector (ModestToolkitFactory *self)
384 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_country_selector (self);
388 modest_toolkit_factory_create_country_selector_default (ModestToolkitFactory *self)
391 #ifdef USE_COUNTRY_COMBOBOX
392 result = modest_country_combo_box_new ();
394 result = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
395 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
401 modest_country_selector_get_active_country_mcc (GtkWidget *widget)
403 #ifdef USE_COUNTRY_COMBOBOX
404 return modest_country_combo_box_get_active_country_mcc (MODEST_COUNTRY_COMBO_BOX (widget));
406 return modest_country_picker_get_active_country_mcc (MODEST_COUNTRY_PICKER (widget));
411 modest_country_selector_load_data (GtkWidget *widget)
413 #ifdef USE_COUNTRY_COMBOBOX
414 modest_country_combo_box_load_data (MODEST_COUNTRY_COMBO_BOX (widget));
416 modest_country_picker_load_data (MODEST_COUNTRY_PICKER (widget));
421 modest_country_selector_set_active_country_locale (GtkWidget *widget)
423 #ifdef USE_COUNTRY_COMBOBOX
424 return modest_country_combo_box_set_active_country_locale (MODEST_COUNTRY_COMBO_BOX (widget));
426 return modest_country_picker_set_active_country_locale (MODEST_COUNTRY_PICKER (widget));