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
47 #define USE_SERVERSECURITY_PICKER
50 #ifdef USE_SCROLLED_WINDOW
51 #include <modest-scrolled-window-scrollable.h>
53 #include <modest-hildon-pannable-area-scrollable.h>
56 #ifdef USE_GTK_TOOLBAR
57 #include <modest-find-toolbar.h>
59 #include <modest-hildon-find-toolbar.h>
62 #ifdef USE_COUNTRY_COMBOBOX
63 #include <modest-country-combo-box.h>
65 #include <modest-country-picker.h>
68 #ifdef USE_PROVIDER_COMBOBOX
69 #include <modest-provider-combo-box.h>
71 #include <modest-provider-picker.h>
74 #ifdef USE_SERVERTYPE_COMBOBOX
75 #include <modest-servertype-combo-box.h>
77 #include <modest-servertype-picker.h>
80 #ifdef USE_SERVERSECURITY_COMBOBOX
81 #include <modest-serversecurity-combo-box.h>
83 #include <modest-serversecurity-picker.h>
86 static void modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass);
87 static void modest_toolkit_factory_init (ModestToolkitFactory *self);
89 /* GObject interface */
90 static GtkWidget * modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self);
91 static GtkWidget * modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self,
93 static GtkWidget * modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self,
95 static GtkWidget * modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self,
97 static GtkWidget * modest_toolkit_factory_create_entry_default (ModestToolkitFactory *self);
98 static GtkWidget * modest_toolkit_factory_create_number_entry_default (ModestToolkitFactory *self,
101 static GtkWidget * modest_toolkit_factory_create_file_chooser_dialog_default (ModestToolkitFactory *self,
104 GtkFileChooserAction action);
105 static GtkWidget * modest_toolkit_factory_create_country_selector_default (ModestToolkitFactory *self);
106 static GtkWidget * modest_toolkit_factory_create_provider_selector_default (ModestToolkitFactory *self);
107 static GtkWidget * modest_toolkit_factory_create_servertype_selector_default (ModestToolkitFactory *self,
108 gboolean filter_providers);
109 static GtkWidget * modest_toolkit_factory_create_serversecurity_selector_default (ModestToolkitFactory *self);
111 static GObjectClass *parent_class = NULL;
113 G_DEFINE_TYPE (ModestToolkitFactory,
114 modest_toolkit_factory,
117 ModestToolkitFactory *
118 modest_toolkit_factory_get_instance (void)
120 GObject* self = g_object_new (MODEST_TYPE_TOOLKIT_FACTORY, NULL);
122 return (ModestToolkitFactory *) self;
126 modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass)
128 parent_class = g_type_class_peek_parent (klass);
130 klass->create_scrollable = modest_toolkit_factory_create_scrollable_default;
131 klass->create_check_button = modest_toolkit_factory_create_check_button_default;
132 klass->create_check_menu = modest_toolkit_factory_create_check_menu_default;
133 klass->create_isearch_toolbar = modest_toolkit_factory_create_isearch_toolbar_default;
134 klass->create_entry = modest_toolkit_factory_create_entry_default;
135 klass->create_number_entry = modest_toolkit_factory_create_number_entry_default;
136 klass->create_file_chooser_dialog = modest_toolkit_factory_create_file_chooser_dialog_default;
137 klass->create_country_selector = modest_toolkit_factory_create_country_selector_default;
138 klass->create_provider_selector = modest_toolkit_factory_create_provider_selector_default;
139 klass->create_servertype_selector = modest_toolkit_factory_create_servertype_selector_default;
140 klass->create_serversecurity_selector = modest_toolkit_factory_create_serversecurity_selector_default;
144 modest_toolkit_factory_init (ModestToolkitFactory *self)
149 modest_toolkit_factory_create_scrollable (ModestToolkitFactory *self)
151 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_scrollable (self);
155 modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self)
157 #ifdef USE_SCROLLED_WINDOW
158 return modest_scrolled_window_scrollable_new ();
160 return modest_hildon_pannable_area_scrollable_new ();
165 modest_toolkit_factory_create_check_button (ModestToolkitFactory *self, const gchar *label)
167 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_button (self, label);
171 modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self, const gchar *label)
174 #ifdef USE_GTK_CHECK_BUTTON
175 result = gtk_check_button_new_with_label (label);
177 result = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
178 gtk_button_set_label (GTK_BUTTON (result), label);
179 gtk_button_set_alignment (GTK_BUTTON (result), 0.0, 0.5);
185 modest_toolkit_factory_create_check_menu (ModestToolkitFactory *self, const gchar *label)
187 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_menu (self, label);
191 modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self, const gchar *label)
194 #ifdef USE_GTK_CHECK_MENU
195 result = gtk_check_menu_item_new_with_label (label);
197 result = hildon_check_button_new (0);
198 gtk_button_set_label (GTK_BUTTON (result), label);
199 gtk_button_set_alignment (GTK_BUTTON (result), 0.5, 0.5);
205 modest_togglable_get_active (GtkWidget *widget)
207 if (GTK_IS_CHECK_MENU_ITEM (widget)) {
208 return gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
209 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
210 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
211 #ifdef MODEST_TOOLKIT_HILDON2
212 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
213 return hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget));
216 g_return_val_if_reached (FALSE);
221 modest_togglable_set_active (GtkWidget *widget, gboolean active)
223 if (GTK_IS_CHECK_MENU_ITEM (widget)) {
224 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), active);
225 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
226 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), active);
227 #ifdef MODEST_TOOLKIT_HILDON2
228 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
229 hildon_check_button_set_active (HILDON_CHECK_BUTTON (widget), active);
235 modest_is_togglable (GtkWidget *widget)
237 return GTK_IS_CHECK_MENU_ITEM (widget)
238 || GTK_IS_TOGGLE_BUTTON (widget)
239 #ifdef MODEST_TOOLKIT_HILDON2
240 || HILDON_IS_CHECK_BUTTON (widget)
246 modest_toolkit_factory_create_isearch_toolbar (ModestToolkitFactory *self, const gchar *label)
248 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_isearch_toolbar (self, label);
252 modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self, const gchar *label)
255 #ifdef USE_GTK_FIND_TOOLBAR
256 result = modest_find_toolbar_new (label);
258 result = modest_hildon_find_toolbar_new (label);
264 modest_toolkit_factory_create_entry (ModestToolkitFactory *self)
266 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_entry (self);
270 modest_toolkit_factory_create_entry_default (ModestToolkitFactory *self)
273 return gtk_entry_new ();
275 return hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
280 modest_entry_set_text (GtkWidget *widget, const gchar *text)
282 #ifdef MODEST_TOOLKIT_HILDON2
283 hildon_entry_set_text (HILDON_ENTRY (widget), text);
285 gtk_entry_set_text (GTK_ENTRY (widget), text);
290 modest_entry_get_text (GtkWidget *widget)
292 #ifdef MODEST_TOOLKIT_HILDON2
293 return hildon_entry_get_text (HILDON_ENTRY (widget));
295 return gtk_entry_set_text (GTK_ENTRY (widget));
300 modest_entry_set_hint (GtkWidget *widget, const gchar *hint)
302 #ifdef MODEST_TOOLKIT_HILDON2
303 hildon_entry_set_placeholder (HILDON_ENTRY (widget), hint);
305 gtk_widget_set_tooltip_text (widget, hint);
310 modest_is_entry (GtkWidget *widget)
312 #ifdef MODEST_TOOLKIT_HILDON2
313 return HILDON_IS_ENTRY (widget);
315 return GTK_IS_ENTRY (widget);
320 modest_toolkit_factory_create_number_entry (ModestToolkitFactory *self, gint min, gint max)
322 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_number_entry (self, min, max);
326 modest_toolkit_factory_create_number_entry_default (ModestToolkitFactory *self, gint min, gint max)
329 #ifdef USE_GTK_SPIN_BUTTON
330 result = gtk_spin_button_new_with_range (min, max, 1.0);
331 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (result), 0);
333 result = modest_number_editor_new (min, max);
339 modest_number_entry_set_value (GtkWidget *widget, gint value)
341 #ifdef USE_GTK_SPIN_BUTTON
342 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
344 modest_number_editor_set_value (MODEST_NUMBER_EDITOR (widget), value);
349 modest_number_entry_get_value (GtkWidget *widget)
351 #ifdef USE_GTK_SPIN_BUTTON
352 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
354 return modest_number_editor_get_value (MODEST_NUMBER_EDITOR (widget));
359 modest_number_entry_is_valid (GtkWidget *widget)
361 #ifdef USE_GTK_SPIN_BUTTON
364 return modest_number_editor_is_valid (MODEST_NUMBER_EDITOR (widget));
369 modest_is_number_entry (GtkWidget *widget)
371 #ifdef USE_GTK_SPIN_BUTTON
372 return GTK_IS_SPIN_BUTTON (widget);
374 return MODEST_IS_NUMBER_EDITOR (widget);
379 modest_toolkit_factory_create_file_chooser_dialog (ModestToolkitFactory *self,
382 GtkFileChooserAction action)
384 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_file_chooser_dialog (self, title, parent, action);
388 modest_toolkit_factory_create_file_chooser_dialog_default (ModestToolkitFactory *self,
391 GtkFileChooserAction action)
394 #ifdef USE_GTK_FILE_CHOOSER
395 result = gtk_file_chooser_dialog_new (title, parent, action,
396 (action == GTK_FILE_CHOOSER_ACTION_OPEN) ? GTK_STOCK_OPEN : GTK_STOCK_SAVE,
398 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
401 result = hildon_file_chooser_dialog_new (parent, action);
402 gtk_window_set_title ((GtkWindow *) result, title);
408 modest_toolkit_factory_create_country_selector (ModestToolkitFactory *self)
410 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_country_selector (self);
414 modest_toolkit_factory_create_country_selector_default (ModestToolkitFactory *self)
417 #ifdef USE_COUNTRY_COMBOBOX
418 result = modest_country_combo_box_new ();
420 result = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
421 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
427 modest_country_selector_get_active_country_mcc (GtkWidget *widget)
429 #ifdef USE_COUNTRY_COMBOBOX
430 return modest_country_combo_box_get_active_country_mcc (MODEST_COUNTRY_COMBO_BOX (widget));
432 return modest_country_picker_get_active_country_mcc (MODEST_COUNTRY_PICKER (widget));
437 modest_country_selector_load_data (GtkWidget *widget)
439 #ifdef USE_COUNTRY_COMBOBOX
440 modest_country_combo_box_load_data (MODEST_COUNTRY_COMBO_BOX (widget));
442 modest_country_picker_load_data (MODEST_COUNTRY_PICKER (widget));
447 modest_country_selector_set_active_country_locale (GtkWidget *widget)
449 #ifdef USE_COUNTRY_COMBOBOX
450 return modest_country_combo_box_set_active_country_locale (MODEST_COUNTRY_COMBO_BOX (widget));
452 return modest_country_picker_set_active_country_locale (MODEST_COUNTRY_PICKER (widget));
457 modest_toolkit_factory_create_provider_selector (ModestToolkitFactory *self)
459 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_provider_selector (self);
463 modest_toolkit_factory_create_provider_selector_default (ModestToolkitFactory *self)
466 #ifdef USE_PROVIDER_COMBOBOX
467 result = modest_provider_combo_box_new ();
469 result = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
470 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
476 modest_provider_selector_fill (GtkWidget *widget,
477 ModestPresets *presets,
480 #ifdef USE_PROVIDER_COMBOBOX
481 modest_provider_combo_box_fill (MODEST_PROVIDER_COMBO_BOX (widget),
485 modest_provider_picker_fill (MODEST_PROVIDER_PICKER (widget),
492 modest_provider_selector_get_active_provider_id (GtkWidget *widget)
494 #ifdef USE_PROVIDER_COMBOBOX
495 return modest_provider_combo_box_get_active_provider_id (MODEST_PROVIDER_COMBO_BOX (widget));
497 return modest_provider_picker_get_active_provider_id (MODEST_PROVIDER_PICKER (widget));
502 modest_provider_selector_get_active_provider_label (GtkWidget *widget)
504 #ifdef USE_PROVIDER_COMBOBOX
506 return modest_provider_combo_box_get_active_provider_label (MODEST_PROVIDER_COMBO_BOX (widget));
510 selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
511 return g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
515 ModestProviderSelectorIdType
516 modest_provider_selector_get_active_id_type (GtkWidget *widget)
518 ModestProviderSelectorIdType result;
519 #ifdef USE_PROVIDER_COMBOBOX
520 ModestProviderComboBoxIdType id_type;
522 id_type = modest_provider_combo_box_get_active_id_type (MODEST_PROVIDER_COMBO_BOX (widget));
524 case MODEST_PROVIDER_COMBO_BOX_ID_PROVIDER:
525 result = MODEST_PROVIDER_SELECTOR_ID_PROVIDER;
527 case MODEST_PROVIDER_COMBO_BOX_ID_OTHER:
528 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
530 case MODEST_PROVIDER_COMBO_BOX_ID_PLUGIN_PROTOCOL:
531 result = MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL;
534 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
538 ModestProviderPickerIdType id_type;
540 id_type = modest_provider_picker_get_active_id_type (MODEST_PROVIDER_PICKER (widget));
542 case MODEST_PROVIDER_PICKER_ID_PROVIDER:
543 result = MODEST_PROVIDER_SELECTOR_ID_PROVIDER;
545 case MODEST_PROVIDER_PICKER_ID_OTHER:
546 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
548 case MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL:
549 result = MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL;
552 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
559 modest_provider_selector_set_others_provider (GtkWidget *self)
561 #ifdef USE_PROVIDER_COMBOBOX
562 modest_provider_combo_box_set_others_provider (MODEST_PROVIDER_COMBO_BOX (self));
564 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (self));
569 modest_toolkit_factory_create_servertype_selector (ModestToolkitFactory *self, gboolean filter_providers)
571 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_servertype_selector (self, filter_providers);
575 modest_toolkit_factory_create_servertype_selector_default (ModestToolkitFactory *self, gboolean filter_providers)
578 #ifdef USE_PROVIDER_COMBOBOX
579 result = GTK_WIDGET (modest_servertype_combo_box_new (filter_providers));
581 result = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
582 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
589 modest_servertype_selector_get_active_servertype (GtkWidget *self)
591 #ifdef USE_SERVERTYPE_COMBOBOX
592 return modest_servertype_combo_box_get_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self));
594 return modest_servertype_picker_get_active_servertype (MODEST_SERVERTYPE_PICKER (self));
599 modest_servertype_selector_set_active_servertype (GtkWidget *self,
600 ModestProtocolType protocol_type_id)
602 #ifdef USE_SERVERTYPE_COMBOBOX
603 modest_servertype_combo_box_set_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self), protocol_type_id);
605 modest_servertype_picker_set_active_servertype (MODEST_SERVERTYPE_PICKER (self), protocol_type_id);
610 modest_toolkit_factory_create_serversecurity_selector (ModestToolkitFactory *self)
612 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_serversecurity_selector (self);
616 modest_toolkit_factory_create_serversecurity_selector_default (ModestToolkitFactory *self)
619 #ifdef USE_PROVIDER_COMBOBOX
620 result = GTK_WIDGET (modest_serversecurity_combo_box_new ());
622 result = GTK_WIDGET (modest_serversecurity_picker_new (MODEST_EDITABLE_SIZE,
623 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
629 modest_serversecurity_selector_fill (GtkWidget *combobox,
630 ModestProtocolType protocol)
632 #ifdef USE_SERVERSECURITY_COMBOBOX
633 modest_serversecurity_combo_box_fill (MODEST_SERVERSECURITY_COMBO_BOX (combobox),
636 modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (combobox),
642 modest_serversecurity_selector_get_active_serversecurity (GtkWidget *combobox)
644 #ifdef USE_SERVERSECURITY_COMBOBOX
645 return modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (combobox));
647 return modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (combobox));
652 modest_serversecurity_selector_set_active_serversecurity (GtkWidget *combobox,
653 ModestProtocolType serversecurity)
655 #ifdef USE_SERVERSECURITY_COMBOBOX
656 return modest_serversecurity_combo_box_set_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (combobox),
659 return modest_serversecurity_picker_set_active_serversecurity (MODEST_SERVERSECURITY_PICKER (combobox),
665 modest_serversecurity_selector_get_active_serversecurity_port (GtkWidget *combobox)
667 #ifdef USE_SERVERSECURITY_COMBOBOX
668 return modest_serversecurity_combo_box_get_active_serversecurity_port (MODEST_SERVERSECURITY_COMBO_BOX (combobox));
670 return modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (combobox));