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_COMBOBOX
48 #define USE_GTK_SECURITY_OPTIONS_VIEW
51 #ifdef USE_SCROLLED_WINDOW
52 #include <modest-scrolled-window-scrollable.h>
54 #include <modest-hildon-pannable-area-scrollable.h>
57 #ifdef USE_GTK_TOOLBAR
58 #include <modest-find-toolbar.h>
60 #include <modest-hildon-find-toolbar.h>
63 #ifdef USE_COUNTRY_COMBOBOX
64 #include <modest-country-combo-box.h>
66 #include <modest-country-picker.h>
69 #ifdef USE_PROVIDER_COMBOBOX
70 #include <modest-provider-combo-box.h>
72 #include <modest-provider-picker.h>
75 #ifdef USE_SERVERTYPE_COMBOBOX
76 #include <modest-servertype-combo-box.h>
78 #include <modest-servertype-picker.h>
81 #ifdef USE_SERVERSECURITY_COMBOBOX
82 #include <modest-serversecurity-combo-box.h>
84 #include <modest-serversecurity-picker.h>
87 #ifdef USE_GTK_SECURITY_OPTIONS_VIEW
88 #include <modest-gtk-security-options-view.h>
90 #include <modest-maemo-security-options-view.h>
93 static void modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass);
94 static void modest_toolkit_factory_init (ModestToolkitFactory *self);
96 /* GObject interface */
97 static GtkWidget * modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self);
98 static GtkWidget * modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self,
100 static GtkWidget * modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self,
102 static GtkWidget * modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self,
104 static GtkWidget * modest_toolkit_factory_create_entry_default (ModestToolkitFactory *self);
105 static GtkWidget * modest_toolkit_factory_create_number_entry_default (ModestToolkitFactory *self,
108 static GtkWidget * modest_toolkit_factory_create_file_chooser_dialog_default (ModestToolkitFactory *self,
111 GtkFileChooserAction action);
112 static GtkWidget * modest_toolkit_factory_create_country_selector_default (ModestToolkitFactory *self);
113 static GtkWidget * modest_toolkit_factory_create_provider_selector_default (ModestToolkitFactory *self);
114 static GtkWidget * modest_toolkit_factory_create_servertype_selector_default (ModestToolkitFactory *self,
115 gboolean filter_providers);
116 static GtkWidget * modest_toolkit_factory_create_serversecurity_selector_default (ModestToolkitFactory *self);
118 static GObjectClass *parent_class = NULL;
120 G_DEFINE_TYPE (ModestToolkitFactory,
121 modest_toolkit_factory,
124 ModestToolkitFactory *
125 modest_toolkit_factory_get_instance (void)
127 GObject* self = g_object_new (MODEST_TYPE_TOOLKIT_FACTORY, NULL);
129 return (ModestToolkitFactory *) self;
133 modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass)
135 parent_class = g_type_class_peek_parent (klass);
137 klass->create_scrollable = modest_toolkit_factory_create_scrollable_default;
138 klass->create_check_button = modest_toolkit_factory_create_check_button_default;
139 klass->create_check_menu = modest_toolkit_factory_create_check_menu_default;
140 klass->create_isearch_toolbar = modest_toolkit_factory_create_isearch_toolbar_default;
141 klass->create_entry = modest_toolkit_factory_create_entry_default;
142 klass->create_number_entry = modest_toolkit_factory_create_number_entry_default;
143 klass->create_file_chooser_dialog = modest_toolkit_factory_create_file_chooser_dialog_default;
144 klass->create_country_selector = modest_toolkit_factory_create_country_selector_default;
145 klass->create_provider_selector = modest_toolkit_factory_create_provider_selector_default;
146 klass->create_servertype_selector = modest_toolkit_factory_create_servertype_selector_default;
147 klass->create_serversecurity_selector = modest_toolkit_factory_create_serversecurity_selector_default;
151 modest_toolkit_factory_init (ModestToolkitFactory *self)
156 modest_toolkit_factory_create_scrollable (ModestToolkitFactory *self)
158 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_scrollable (self);
162 modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self)
164 #ifdef USE_SCROLLED_WINDOW
165 return modest_scrolled_window_scrollable_new ();
167 return modest_hildon_pannable_area_scrollable_new ();
172 modest_toolkit_factory_create_check_button (ModestToolkitFactory *self, const gchar *label)
174 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_button (self, label);
178 modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self, const gchar *label)
181 #ifdef USE_GTK_CHECK_BUTTON
182 result = gtk_check_button_new_with_label (label);
184 result = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
185 gtk_button_set_label (GTK_BUTTON (result), label);
186 gtk_button_set_alignment (GTK_BUTTON (result), 0.0, 0.5);
192 modest_toolkit_factory_create_check_menu (ModestToolkitFactory *self, const gchar *label)
194 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_menu (self, label);
198 modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self, const gchar *label)
201 #ifdef USE_GTK_CHECK_MENU
202 result = gtk_check_menu_item_new_with_label (label);
204 result = hildon_check_button_new (0);
205 gtk_button_set_label (GTK_BUTTON (result), label);
206 gtk_button_set_alignment (GTK_BUTTON (result), 0.5, 0.5);
212 modest_togglable_get_active (GtkWidget *widget)
214 if (GTK_IS_CHECK_MENU_ITEM (widget)) {
215 return gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
216 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
217 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
218 #ifdef MODEST_TOOLKIT_HILDON2
219 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
220 return hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget));
223 g_return_val_if_reached (FALSE);
228 modest_togglable_set_active (GtkWidget *widget, gboolean active)
230 if (GTK_IS_CHECK_MENU_ITEM (widget)) {
231 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), active);
232 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
233 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), active);
234 #ifdef MODEST_TOOLKIT_HILDON2
235 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
236 hildon_check_button_set_active (HILDON_CHECK_BUTTON (widget), active);
242 modest_is_togglable (GtkWidget *widget)
244 return GTK_IS_CHECK_MENU_ITEM (widget)
245 || GTK_IS_TOGGLE_BUTTON (widget)
246 #ifdef MODEST_TOOLKIT_HILDON2
247 || HILDON_IS_CHECK_BUTTON (widget)
253 modest_toolkit_factory_create_isearch_toolbar (ModestToolkitFactory *self, const gchar *label)
255 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_isearch_toolbar (self, label);
259 modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self, const gchar *label)
262 #ifdef USE_GTK_FIND_TOOLBAR
263 result = modest_find_toolbar_new (label);
265 result = modest_hildon_find_toolbar_new (label);
271 modest_toolkit_factory_create_entry (ModestToolkitFactory *self)
273 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_entry (self);
277 modest_toolkit_factory_create_entry_default (ModestToolkitFactory *self)
280 return gtk_entry_new ();
282 return hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
287 modest_entry_set_text (GtkWidget *widget, const gchar *text)
289 #ifdef MODEST_TOOLKIT_HILDON2
290 hildon_entry_set_text (HILDON_ENTRY (widget), text);
292 gtk_entry_set_text (GTK_ENTRY (widget), text);
297 modest_entry_get_text (GtkWidget *widget)
299 #ifdef MODEST_TOOLKIT_HILDON2
300 return hildon_entry_get_text (HILDON_ENTRY (widget));
302 return gtk_entry_set_text (GTK_ENTRY (widget));
307 modest_entry_set_hint (GtkWidget *widget, const gchar *hint)
309 #ifdef MODEST_TOOLKIT_HILDON2
310 hildon_entry_set_placeholder (HILDON_ENTRY (widget), hint);
312 gtk_widget_set_tooltip_text (widget, hint);
317 modest_is_entry (GtkWidget *widget)
319 #ifdef MODEST_TOOLKIT_HILDON2
320 return HILDON_IS_ENTRY (widget);
322 return GTK_IS_ENTRY (widget);
327 modest_toolkit_factory_create_number_entry (ModestToolkitFactory *self, gint min, gint max)
329 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_number_entry (self, min, max);
333 modest_toolkit_factory_create_number_entry_default (ModestToolkitFactory *self, gint min, gint max)
336 #ifdef USE_GTK_SPIN_BUTTON
337 result = gtk_spin_button_new_with_range (min, max, 1.0);
338 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (result), 0);
340 result = modest_number_editor_new (min, max);
346 modest_number_entry_set_value (GtkWidget *widget, gint value)
348 #ifdef USE_GTK_SPIN_BUTTON
349 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
351 modest_number_editor_set_value (MODEST_NUMBER_EDITOR (widget), value);
356 modest_number_entry_get_value (GtkWidget *widget)
358 #ifdef USE_GTK_SPIN_BUTTON
359 return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
361 return modest_number_editor_get_value (MODEST_NUMBER_EDITOR (widget));
366 modest_number_entry_is_valid (GtkWidget *widget)
368 #ifdef USE_GTK_SPIN_BUTTON
371 return modest_number_editor_is_valid (MODEST_NUMBER_EDITOR (widget));
376 modest_is_number_entry (GtkWidget *widget)
378 #ifdef USE_GTK_SPIN_BUTTON
379 return GTK_IS_SPIN_BUTTON (widget);
381 return MODEST_IS_NUMBER_EDITOR (widget);
386 modest_toolkit_factory_create_file_chooser_dialog (ModestToolkitFactory *self,
389 GtkFileChooserAction action)
391 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_file_chooser_dialog (self, title, parent, action);
395 modest_toolkit_factory_create_file_chooser_dialog_default (ModestToolkitFactory *self,
398 GtkFileChooserAction action)
401 #ifdef USE_GTK_FILE_CHOOSER
402 result = gtk_file_chooser_dialog_new (title, parent, action,
403 (action == GTK_FILE_CHOOSER_ACTION_OPEN) ? GTK_STOCK_OPEN : GTK_STOCK_SAVE,
405 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
408 result = hildon_file_chooser_dialog_new (parent, action);
409 gtk_window_set_title ((GtkWindow *) result, title);
415 modest_toolkit_factory_create_country_selector (ModestToolkitFactory *self)
417 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_country_selector (self);
421 modest_toolkit_factory_create_country_selector_default (ModestToolkitFactory *self)
424 #ifdef USE_COUNTRY_COMBOBOX
425 result = modest_country_combo_box_new ();
427 result = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
428 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
434 modest_country_selector_get_active_country_mcc (GtkWidget *widget)
436 #ifdef USE_COUNTRY_COMBOBOX
437 return modest_country_combo_box_get_active_country_mcc (MODEST_COUNTRY_COMBO_BOX (widget));
439 return modest_country_picker_get_active_country_mcc (MODEST_COUNTRY_PICKER (widget));
444 modest_country_selector_load_data (GtkWidget *widget)
446 #ifdef USE_COUNTRY_COMBOBOX
447 modest_country_combo_box_load_data (MODEST_COUNTRY_COMBO_BOX (widget));
449 modest_country_picker_load_data (MODEST_COUNTRY_PICKER (widget));
454 modest_country_selector_set_active_country_locale (GtkWidget *widget)
456 #ifdef USE_COUNTRY_COMBOBOX
457 return modest_country_combo_box_set_active_country_locale (MODEST_COUNTRY_COMBO_BOX (widget));
459 return modest_country_picker_set_active_country_locale (MODEST_COUNTRY_PICKER (widget));
464 modest_toolkit_factory_create_provider_selector (ModestToolkitFactory *self)
466 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_provider_selector (self);
470 modest_toolkit_factory_create_provider_selector_default (ModestToolkitFactory *self)
473 #ifdef USE_PROVIDER_COMBOBOX
474 result = modest_provider_combo_box_new ();
476 result = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
477 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
483 modest_provider_selector_fill (GtkWidget *widget,
484 ModestPresets *presets,
487 #ifdef USE_PROVIDER_COMBOBOX
488 modest_provider_combo_box_fill (MODEST_PROVIDER_COMBO_BOX (widget),
492 modest_provider_picker_fill (MODEST_PROVIDER_PICKER (widget),
499 modest_provider_selector_get_active_provider_id (GtkWidget *widget)
501 #ifdef USE_PROVIDER_COMBOBOX
502 return modest_provider_combo_box_get_active_provider_id (MODEST_PROVIDER_COMBO_BOX (widget));
504 return modest_provider_picker_get_active_provider_id (MODEST_PROVIDER_PICKER (widget));
509 modest_provider_selector_get_active_provider_label (GtkWidget *widget)
511 #ifdef USE_PROVIDER_COMBOBOX
513 return modest_provider_combo_box_get_active_provider_label (MODEST_PROVIDER_COMBO_BOX (widget));
517 selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
518 return g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
522 ModestProviderSelectorIdType
523 modest_provider_selector_get_active_id_type (GtkWidget *widget)
525 ModestProviderSelectorIdType result;
526 #ifdef USE_PROVIDER_COMBOBOX
527 ModestProviderComboBoxIdType id_type;
529 id_type = modest_provider_combo_box_get_active_id_type (MODEST_PROVIDER_COMBO_BOX (widget));
531 case MODEST_PROVIDER_COMBO_BOX_ID_PROVIDER:
532 result = MODEST_PROVIDER_SELECTOR_ID_PROVIDER;
534 case MODEST_PROVIDER_COMBO_BOX_ID_OTHER:
535 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
537 case MODEST_PROVIDER_COMBO_BOX_ID_PLUGIN_PROTOCOL:
538 result = MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL;
541 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
545 ModestProviderPickerIdType id_type;
547 id_type = modest_provider_picker_get_active_id_type (MODEST_PROVIDER_PICKER (widget));
549 case MODEST_PROVIDER_PICKER_ID_PROVIDER:
550 result = MODEST_PROVIDER_SELECTOR_ID_PROVIDER;
552 case MODEST_PROVIDER_PICKER_ID_OTHER:
553 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
555 case MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL:
556 result = MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL;
559 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
566 modest_provider_selector_set_others_provider (GtkWidget *self)
568 #ifdef USE_PROVIDER_COMBOBOX
569 modest_provider_combo_box_set_others_provider (MODEST_PROVIDER_COMBO_BOX (self));
571 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (self));
576 modest_toolkit_factory_create_servertype_selector (ModestToolkitFactory *self, gboolean filter_providers)
578 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_servertype_selector (self, filter_providers);
582 modest_toolkit_factory_create_servertype_selector_default (ModestToolkitFactory *self, gboolean filter_providers)
585 #ifdef USE_PROVIDER_COMBOBOX
586 result = GTK_WIDGET (modest_servertype_combo_box_new (filter_providers));
588 result = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
589 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
596 modest_servertype_selector_get_active_servertype (GtkWidget *self)
598 #ifdef USE_SERVERTYPE_COMBOBOX
599 return modest_servertype_combo_box_get_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self));
601 return modest_servertype_picker_get_active_servertype (MODEST_SERVERTYPE_PICKER (self));
606 modest_servertype_selector_set_active_servertype (GtkWidget *self,
607 ModestProtocolType protocol_type_id)
609 #ifdef USE_SERVERTYPE_COMBOBOX
610 modest_servertype_combo_box_set_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self), protocol_type_id);
612 modest_servertype_picker_set_active_servertype (MODEST_SERVERTYPE_PICKER (self), protocol_type_id);
617 modest_toolkit_factory_create_serversecurity_selector (ModestToolkitFactory *self)
619 return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_serversecurity_selector (self);
623 modest_toolkit_factory_create_serversecurity_selector_default (ModestToolkitFactory *self)
626 #ifdef USE_PROVIDER_COMBOBOX
627 result = GTK_WIDGET (modest_serversecurity_combo_box_new ());
629 result = GTK_WIDGET (modest_serversecurity_picker_new (MODEST_EDITABLE_SIZE,
630 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
636 modest_serversecurity_selector_fill (GtkWidget *combobox,
637 ModestProtocolType protocol)
639 #ifdef USE_SERVERSECURITY_COMBOBOX
640 modest_serversecurity_combo_box_fill (MODEST_SERVERSECURITY_COMBO_BOX (combobox),
643 modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (combobox),
649 modest_serversecurity_selector_get_active_serversecurity (GtkWidget *combobox)
651 #ifdef USE_SERVERSECURITY_COMBOBOX
652 return modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (combobox));
654 return modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (combobox));
659 modest_serversecurity_selector_set_active_serversecurity (GtkWidget *combobox,
660 ModestProtocolType serversecurity)
662 #ifdef USE_SERVERSECURITY_COMBOBOX
663 return modest_serversecurity_combo_box_set_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (combobox),
666 return modest_serversecurity_picker_set_active_serversecurity (MODEST_SERVERSECURITY_PICKER (combobox),
672 modest_serversecurity_selector_get_active_serversecurity_port (GtkWidget *combobox)
674 #ifdef USE_SERVERSECURITY_COMBOBOX
675 return modest_serversecurity_combo_box_get_active_serversecurity_port (MODEST_SERVERSECURITY_COMBO_BOX (combobox));
677 return modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (combobox));
682 modest_toolkit_factory_create_security_options_view (ModestToolkitFactory *self,
683 ModestSecurityOptionsType type,
685 GtkSizeGroup *title_size_group,
686 GtkSizeGroup *value_size_group)
689 #ifdef USE_GTK_SECURITY_OPTIONS_VIEW
690 result = GTK_WIDGET (modest_gtk_security_options_view_new (type, full, title_size_group, value_size_group));
692 result = GTK_WIDGET (modest_maemo_security_options_view_new (type, full, title_size_group, value_size_group));