Provide selector picker or combobox from factory
[modest] / src / widgets / modest-toolkit-factory.c
1 /* Copyright (c) 2009, Igalia
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 #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>
36 #endif
37 #include "modest-toolkit-factory.h"
38
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
44 #define USE_GTK_ENTRY
45 #define USE_GTK_FILE_CHOOSER
46 #define USE_COUNTRY_COMBOBOX
47 #define USE_SERVERSECURITY_COMBOBOX
48 #define USE_SECUREAUTH_COMBOBOX
49 #define USE_GTK_SECURITY_OPTIONS_VIEW
50 #define USE_GTK_TEXT_VIEW
51 #define USE_SELECTOR_COMBOBOX
52 #endif
53
54 #ifdef USE_SCROLLED_WINDOW
55 #include <modest-scrolled-window-scrollable.h>
56 #else
57 #include <modest-hildon-pannable-area-scrollable.h>
58 #endif
59
60 #ifdef USE_GTK_TOOLBAR
61 #include <modest-find-toolbar.h>
62 #else
63 #include <modest-hildon-find-toolbar.h>
64 #endif
65
66 #ifdef USE_COUNTRY_COMBOBOX
67 #include <modest-country-combo-box.h>
68 #else
69 #include <modest-country-picker.h>
70 #endif
71
72 #ifdef USE_PROVIDER_COMBOBOX
73 #include <modest-provider-combo-box.h>
74 #else
75 #include <modest-provider-picker.h>
76 #endif
77
78 #ifdef USE_SERVERTYPE_COMBOBOX
79 #include <modest-servertype-combo-box.h>
80 #else
81 #include <modest-servertype-picker.h>
82 #endif
83
84 #ifdef USE_SERVERSECURITY_COMBOBOX
85 #include <modest-serversecurity-combo-box.h>
86 #else
87 #include <modest-serversecurity-picker.h>
88 #endif
89
90 #ifdef USE_SECUREAUTH_COMBOBOX
91 #include <modest-secureauth-combo-box.h>
92 #else
93 #include <modest-secureauth-picker.h>
94 #endif
95
96 #ifdef USE_GTK_SECURITY_OPTIONS_VIEW
97 #include <modest-gtk-security-options-view.h>
98 #else
99 #include <modest-maemo-security-options-view.h>
100 #endif
101
102 #ifdef USE_SELECTOR_COMBOBOX
103 #include <modest-combo-box.h>
104 #else
105 #include <modest-selector-picker.h>
106 #endif
107
108 static void modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass);
109 static void modest_toolkit_factory_init (ModestToolkitFactory *self);
110
111 /* GObject interface */
112 static GtkWidget * modest_toolkit_factory_create_scrollable_default           (ModestToolkitFactory *self);
113 static GtkWidget * modest_toolkit_factory_create_check_button_default         (ModestToolkitFactory *self,
114                                                                                const gchar *label);
115 static GtkWidget * modest_toolkit_factory_create_check_menu_default           (ModestToolkitFactory *self,
116                                                                                const gchar *label);
117 static GtkWidget * modest_toolkit_factory_create_isearch_toolbar_default      (ModestToolkitFactory *self,
118                                                                                const gchar *label);
119 static GtkWidget * modest_toolkit_factory_create_entry_default                (ModestToolkitFactory *self);
120 static GtkWidget * modest_toolkit_factory_create_number_entry_default         (ModestToolkitFactory *self,
121                                                                                gint min,
122                                                                                gint max);
123 static GtkWidget * modest_toolkit_factory_create_file_chooser_dialog_default  (ModestToolkitFactory *self,
124                                                                                const gchar *title,
125                                                                                GtkWindow *parent,
126                                                                                GtkFileChooserAction action);
127 static GtkWidget * modest_toolkit_factory_create_country_selector_default     (ModestToolkitFactory *self);
128 static GtkWidget * modest_toolkit_factory_create_provider_selector_default    (ModestToolkitFactory *self);
129 static GtkWidget * modest_toolkit_factory_create_servertype_selector_default  (ModestToolkitFactory *self,
130                                                                                gboolean filter_providers);
131 static GtkWidget * modest_toolkit_factory_create_serversecurity_selector_default (ModestToolkitFactory *self);
132 static GtkWidget * modest_toolkit_factory_create_secureauth_selector_default (ModestToolkitFactory *self);
133 static GtkWidget * modest_toolkit_factory_create_security_options_view_default (ModestToolkitFactory *self, 
134                                                                                 ModestSecurityOptionsType type,
135                                                                                 gboolean full, 
136                                                                                 GtkSizeGroup *title_size_group,
137                                                                                 GtkSizeGroup *value_size_group);
138 static GtkWidget * modest_toolkit_factory_create_text_view_default            (ModestToolkitFactory *self);
139 static GtkWidget * modest_toolkit_factory_create_selector_default             (ModestToolkitFactory *self,
140                                                                                ModestPairList *pairs, GEqualFunc id_equal_func);
141
142 /* globals */
143 static GObjectClass *parent_class = NULL;
144
145 G_DEFINE_TYPE    (ModestToolkitFactory,
146                   modest_toolkit_factory,
147                   G_TYPE_OBJECT);
148
149 ModestToolkitFactory *
150 modest_toolkit_factory_get_instance                            (void)
151 {
152     GObject* self = g_object_new (MODEST_TYPE_TOOLKIT_FACTORY, NULL);
153
154     return (ModestToolkitFactory *) self;
155 }
156
157 static void
158 modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass)
159 {
160         parent_class = g_type_class_peek_parent (klass);
161
162         klass->create_scrollable = modest_toolkit_factory_create_scrollable_default;
163         klass->create_check_button = modest_toolkit_factory_create_check_button_default;
164         klass->create_check_menu = modest_toolkit_factory_create_check_menu_default;
165         klass->create_isearch_toolbar = modest_toolkit_factory_create_isearch_toolbar_default;
166         klass->create_entry = modest_toolkit_factory_create_entry_default;
167         klass->create_number_entry = modest_toolkit_factory_create_number_entry_default;
168         klass->create_file_chooser_dialog = modest_toolkit_factory_create_file_chooser_dialog_default;
169         klass->create_country_selector = modest_toolkit_factory_create_country_selector_default;
170         klass->create_provider_selector = modest_toolkit_factory_create_provider_selector_default;
171         klass->create_servertype_selector = modest_toolkit_factory_create_servertype_selector_default;
172         klass->create_serversecurity_selector = modest_toolkit_factory_create_serversecurity_selector_default;
173         klass->create_secureauth_selector = modest_toolkit_factory_create_secureauth_selector_default;
174         klass->create_security_options_view = modest_toolkit_factory_create_security_options_view_default;
175         klass->create_text_view = modest_toolkit_factory_create_text_view_default;
176         klass->create_selector = modest_toolkit_factory_create_selector_default;
177 }
178
179 static void
180 modest_toolkit_factory_init (ModestToolkitFactory *self)
181 {
182 }
183
184 GtkWidget *
185 modest_toolkit_factory_create_scrollable (ModestToolkitFactory *self)
186 {
187         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_scrollable (self);
188 }
189
190 static GtkWidget *
191 modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self)
192 {
193 #ifdef USE_SCROLLED_WINDOW
194         return modest_scrolled_window_scrollable_new ();
195 #else
196         return modest_hildon_pannable_area_scrollable_new ();
197 #endif
198 }
199
200 GtkWidget *
201 modest_toolkit_factory_create_check_button (ModestToolkitFactory *self, const gchar *label)
202 {
203         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_button (self, label);
204 }
205
206 static GtkWidget *
207 modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self, const gchar *label)
208 {
209         GtkWidget *result;
210 #ifdef USE_GTK_CHECK_BUTTON
211         result = gtk_check_button_new_with_label (label);
212 #else
213         result = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
214         gtk_button_set_label (GTK_BUTTON (result), label);
215         gtk_button_set_alignment (GTK_BUTTON (result), 0.0, 0.5);
216 #endif
217         return result;
218 }
219
220 GtkWidget *
221 modest_toolkit_factory_create_check_menu (ModestToolkitFactory *self, const gchar *label)
222 {
223         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_menu (self, label);
224 }
225
226 static GtkWidget *
227 modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self, const gchar *label)
228 {
229         GtkWidget *result;
230 #ifdef USE_GTK_CHECK_MENU
231         result = gtk_check_menu_item_new_with_label (label);
232 #else
233         result = hildon_check_button_new (0);
234         gtk_button_set_label (GTK_BUTTON (result), label);
235         gtk_button_set_alignment (GTK_BUTTON (result), 0.5, 0.5);
236 #endif
237         return result;
238 }
239
240 gboolean
241 modest_togglable_get_active (GtkWidget *widget)
242 {
243         if (GTK_IS_CHECK_MENU_ITEM (widget)) {
244                 return gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
245         } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
246                 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
247 #ifdef MODEST_TOOLKIT_HILDON2
248         } else if (HILDON_IS_CHECK_BUTTON (widget)) {
249                 return hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget));
250 #endif
251         } else {
252                 g_return_val_if_reached (FALSE);
253         }
254 }
255
256 void
257 modest_togglable_set_active (GtkWidget *widget, gboolean active)
258 {
259         if (GTK_IS_CHECK_MENU_ITEM (widget)) {
260                 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), active);
261         } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
262                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), active);
263 #ifdef MODEST_TOOLKIT_HILDON2
264         } else if (HILDON_IS_CHECK_BUTTON (widget)) {
265                 hildon_check_button_set_active (HILDON_CHECK_BUTTON (widget), active);
266 #endif
267         }
268 }
269
270 gboolean
271 modest_is_togglable (GtkWidget *widget)
272 {
273         return GTK_IS_CHECK_MENU_ITEM (widget) 
274                 || GTK_IS_TOGGLE_BUTTON (widget)
275 #ifdef MODEST_TOOLKIT_HILDON2
276                 || HILDON_IS_CHECK_BUTTON (widget)
277 #endif
278                 ;
279 }
280
281 GtkWidget *
282 modest_toolkit_factory_create_isearch_toolbar (ModestToolkitFactory *self, const gchar *label)
283 {
284         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_isearch_toolbar (self, label);
285 }
286
287 static GtkWidget *
288 modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self, const gchar *label)
289 {
290         GtkWidget *result;
291 #ifdef USE_GTK_FIND_TOOLBAR
292         result = modest_find_toolbar_new (label);
293 #else
294         result = modest_hildon_find_toolbar_new (label);
295 #endif
296         return result;
297 }
298
299 GtkWidget *
300 modest_toolkit_factory_create_entry (ModestToolkitFactory *self)
301 {
302         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_entry (self);
303 }
304
305 static GtkWidget *
306 modest_toolkit_factory_create_entry_default (ModestToolkitFactory *self)
307 {
308 #ifdef USE_GTK_ENTRY
309         return gtk_entry_new ();
310 #else
311         return hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
312 #endif
313 }
314
315 void
316 modest_entry_set_text (GtkWidget *widget, const gchar *text)
317 {
318 #ifdef MODEST_TOOLKIT_HILDON2
319         hildon_entry_set_text (HILDON_ENTRY (widget), text);
320 #else
321         gtk_entry_set_text (GTK_ENTRY (widget), text);
322 #endif
323 }
324
325 const gchar *
326 modest_entry_get_text (GtkWidget *widget)
327 {
328 #ifdef MODEST_TOOLKIT_HILDON2
329         return hildon_entry_get_text (HILDON_ENTRY (widget));
330 #else
331         return gtk_entry_set_text (GTK_ENTRY (widget));
332 #endif
333 }
334
335 void 
336 modest_entry_set_hint (GtkWidget *widget, const gchar *hint)
337 {
338 #ifdef MODEST_TOOLKIT_HILDON2
339         hildon_entry_set_placeholder (HILDON_ENTRY (widget), hint);
340 #else
341         gtk_widget_set_tooltip_text (widget, hint);
342 #endif
343 }
344
345 gboolean
346 modest_is_entry (GtkWidget *widget)
347 {
348 #ifdef MODEST_TOOLKIT_HILDON2
349         return HILDON_IS_ENTRY (widget);
350 #else
351         return GTK_IS_ENTRY (widget);
352 #endif
353 }
354
355 GtkWidget *
356 modest_toolkit_factory_create_number_entry (ModestToolkitFactory *self, gint min, gint max)
357 {
358         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_number_entry (self, min, max);
359 }
360
361 static GtkWidget *
362 modest_toolkit_factory_create_number_entry_default (ModestToolkitFactory *self, gint min, gint max)
363 {
364         GtkWidget *result;
365 #ifdef USE_GTK_SPIN_BUTTON
366         result = gtk_spin_button_new_with_range (min, max, 1.0);
367         gtk_spin_button_set_digits (GTK_SPIN_BUTTON (result), 0);
368 #else
369         result = modest_number_editor_new (min, max);
370 #endif
371         return result;
372 }
373
374 void
375 modest_number_entry_set_value (GtkWidget *widget, gint value)
376 {
377 #ifdef USE_GTK_SPIN_BUTTON
378         gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
379 #else
380         modest_number_editor_set_value (MODEST_NUMBER_EDITOR (widget), value);
381 #endif
382 }
383
384 gint
385 modest_number_entry_get_value (GtkWidget *widget)
386 {
387 #ifdef USE_GTK_SPIN_BUTTON
388         return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
389 #else
390         return modest_number_editor_get_value (MODEST_NUMBER_EDITOR (widget));
391 #endif
392 }
393
394 gboolean 
395 modest_number_entry_is_valid (GtkWidget *widget)
396 {
397 #ifdef USE_GTK_SPIN_BUTTON
398         return TRUE;
399 #else
400         return modest_number_editor_is_valid (MODEST_NUMBER_EDITOR (widget));
401 #endif
402 }
403
404 gboolean
405 modest_is_number_entry (GtkWidget *widget)
406 {
407 #ifdef USE_GTK_SPIN_BUTTON
408         return GTK_IS_SPIN_BUTTON (widget);
409 #else
410         return MODEST_IS_NUMBER_EDITOR (widget);
411 #endif
412 }
413
414 GtkWidget *
415 modest_toolkit_factory_create_file_chooser_dialog (ModestToolkitFactory *self,
416                                                    const gchar *title,
417                                                    GtkWindow *parent,
418                                                    GtkFileChooserAction action)
419 {
420         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_file_chooser_dialog (self, title, parent, action);
421 }
422
423 static GtkWidget *
424 modest_toolkit_factory_create_file_chooser_dialog_default (ModestToolkitFactory *self,
425                                                            const gchar *title,
426                                                            GtkWindow *parent,
427                                                            GtkFileChooserAction action)
428 {
429         GtkWidget *result;
430 #ifdef USE_GTK_FILE_CHOOSER
431         result = gtk_file_chooser_dialog_new (title, parent, action,
432                                               (action == GTK_FILE_CHOOSER_ACTION_OPEN) ? GTK_STOCK_OPEN : GTK_STOCK_SAVE,
433                                               GTK_RESPONSE_OK,
434                                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
435                                               NULL);
436 #else
437         result = hildon_file_chooser_dialog_new (parent, action);
438         gtk_window_set_title ((GtkWindow *) result, title);
439 #endif
440         return result;
441 }
442
443 GtkWidget *
444 modest_toolkit_factory_create_country_selector (ModestToolkitFactory *self)
445 {
446         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_country_selector (self);
447 }
448
449 static GtkWidget *
450 modest_toolkit_factory_create_country_selector_default (ModestToolkitFactory *self)
451 {
452         GtkWidget *result;
453 #ifdef USE_COUNTRY_COMBOBOX
454         result = modest_country_combo_box_new ();
455 #else
456         result = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE, 
457                                                         HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
458 #endif
459         return result;
460 }
461
462 gint
463 modest_country_selector_get_active_country_mcc (GtkWidget *widget)
464 {
465 #ifdef USE_COUNTRY_COMBOBOX
466         return modest_country_combo_box_get_active_country_mcc (MODEST_COUNTRY_COMBO_BOX (widget));
467 #else
468         return modest_country_picker_get_active_country_mcc (MODEST_COUNTRY_PICKER (widget));
469 #endif
470 }
471
472 void
473 modest_country_selector_load_data (GtkWidget *widget)
474 {
475 #ifdef USE_COUNTRY_COMBOBOX
476         modest_country_combo_box_load_data (MODEST_COUNTRY_COMBO_BOX (widget));
477 #else
478         modest_country_picker_load_data (MODEST_COUNTRY_PICKER (widget));
479 #endif
480 }
481
482 gboolean
483 modest_country_selector_set_active_country_locale (GtkWidget *widget)
484 {
485 #ifdef USE_COUNTRY_COMBOBOX
486         return modest_country_combo_box_set_active_country_locale (MODEST_COUNTRY_COMBO_BOX (widget));
487 #else
488         return modest_country_picker_set_active_country_locale (MODEST_COUNTRY_PICKER (widget));
489 #endif
490 }
491
492 GtkWidget *
493 modest_toolkit_factory_create_provider_selector (ModestToolkitFactory *self)
494 {
495         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_provider_selector (self);
496 }
497
498 static GtkWidget *
499 modest_toolkit_factory_create_provider_selector_default (ModestToolkitFactory *self)
500 {
501         GtkWidget *result;
502 #ifdef USE_PROVIDER_COMBOBOX
503         result = GTK_WIDGET (modest_provider_combo_box_new ());
504 #else
505         result = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE, 
506                                                          HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
507 #endif
508         return result;
509 }
510
511 void
512 modest_provider_selector_fill (GtkWidget *widget,
513                                ModestPresets *presets,
514                                gint mcc)
515 {
516 #ifdef USE_PROVIDER_COMBOBOX
517         modest_provider_combo_box_fill (MODEST_PROVIDER_COMBO_BOX (widget),
518                                         presets,
519                                         mcc);
520 #else
521         modest_provider_picker_fill (MODEST_PROVIDER_PICKER (widget),
522                                      presets,
523                                      mcc);
524 #endif
525 }
526
527 gchar *
528 modest_provider_selector_get_active_provider_id (GtkWidget *widget)
529 {
530 #ifdef USE_PROVIDER_COMBOBOX
531         return modest_provider_combo_box_get_active_provider_id (MODEST_PROVIDER_COMBO_BOX (widget));
532 #else
533         return modest_provider_picker_get_active_provider_id (MODEST_PROVIDER_PICKER (widget));
534 #endif
535 }
536
537 gchar *
538 modest_provider_selector_get_active_provider_label (GtkWidget *widget)
539 {
540 #ifdef USE_PROVIDER_COMBOBOX
541         
542         return modest_provider_combo_box_get_active_provider_label (MODEST_PROVIDER_COMBO_BOX (widget));
543 #else
544         GtkWidget *selector;
545         
546         selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
547         return g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
548 #endif
549 }
550
551 ModestProviderSelectorIdType
552 modest_provider_selector_get_active_id_type (GtkWidget *widget)
553 {
554         ModestProviderSelectorIdType result;
555 #ifdef USE_PROVIDER_COMBOBOX
556         ModestProviderComboBoxIdType id_type;
557
558         id_type = modest_provider_combo_box_get_active_id_type (MODEST_PROVIDER_COMBO_BOX (widget));
559         switch (id_type) {
560         case MODEST_PROVIDER_COMBO_BOX_ID_PROVIDER:
561                 result = MODEST_PROVIDER_SELECTOR_ID_PROVIDER;
562                 break;
563         case MODEST_PROVIDER_COMBO_BOX_ID_OTHER:
564                 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
565                 break;
566         case MODEST_PROVIDER_COMBO_BOX_ID_PLUGIN_PROTOCOL:
567                 result = MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL;
568                 break;
569         default:
570                 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
571         }
572         return result;
573 #else
574         ModestProviderPickerIdType id_type;
575
576         id_type = modest_provider_picker_get_active_id_type (MODEST_PROVIDER_PICKER (widget));
577         switch (id_type) {
578         case MODEST_PROVIDER_PICKER_ID_PROVIDER:
579                 result = MODEST_PROVIDER_SELECTOR_ID_PROVIDER;
580                 break;
581         case MODEST_PROVIDER_PICKER_ID_OTHER:
582                 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
583                 break;
584         case MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL:
585                 result = MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL;
586                 break;
587         default:
588                 result = MODEST_PROVIDER_SELECTOR_ID_OTHER;
589         }
590 #endif
591         return result;
592 }
593
594 void
595 modest_provider_selector_set_others_provider (GtkWidget *self)
596 {
597 #ifdef USE_PROVIDER_COMBOBOX
598         modest_provider_combo_box_set_others_provider (MODEST_PROVIDER_COMBO_BOX (self));
599 #else
600         modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (self));
601 #endif
602 }
603
604 GtkWidget *
605 modest_toolkit_factory_create_servertype_selector (ModestToolkitFactory *self, gboolean filter_providers)
606 {
607         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_servertype_selector (self, filter_providers);
608 }
609
610 static GtkWidget *
611 modest_toolkit_factory_create_servertype_selector_default (ModestToolkitFactory *self, gboolean filter_providers)
612 {
613         GtkWidget *result;
614 #ifdef USE_PROVIDER_COMBOBOX
615         result = GTK_WIDGET (modest_servertype_combo_box_new (filter_providers));
616 #else
617         result = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE, 
618                                                          HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
619                                                          filter_providers));
620 #endif
621         return result;
622 }
623
624 ModestProtocolType
625 modest_servertype_selector_get_active_servertype (GtkWidget *self)
626 {
627 #ifdef USE_SERVERTYPE_COMBOBOX
628         return modest_servertype_combo_box_get_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self));
629 #else
630         return modest_servertype_picker_get_active_servertype (MODEST_SERVERTYPE_PICKER (self));
631 #endif
632 }
633
634 void
635 modest_servertype_selector_set_active_servertype (GtkWidget *self,
636                                                   ModestProtocolType protocol_type_id)
637 {
638 #ifdef USE_SERVERTYPE_COMBOBOX
639         modest_servertype_combo_box_set_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self), protocol_type_id);
640 #else
641         modest_servertype_picker_set_active_servertype (MODEST_SERVERTYPE_PICKER (self), protocol_type_id);
642 #endif
643 }
644
645 GtkWidget *
646 modest_toolkit_factory_create_serversecurity_selector (ModestToolkitFactory *self)
647 {
648         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_serversecurity_selector (self);
649 }
650
651 static GtkWidget *
652 modest_toolkit_factory_create_serversecurity_selector_default (ModestToolkitFactory *self)
653 {
654         GtkWidget *result;
655 #ifdef USE_SERVERSECURITY_COMBOBOX
656         result = GTK_WIDGET (modest_serversecurity_combo_box_new ());
657 #else
658         result = GTK_WIDGET (modest_serversecurity_picker_new (MODEST_EDITABLE_SIZE, 
659                                                                HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
660 #endif
661         return result;
662 }
663
664 void
665 modest_serversecurity_selector_fill (GtkWidget *combobox, 
666                                      ModestProtocolType protocol)
667 {
668 #ifdef USE_SERVERSECURITY_COMBOBOX
669         modest_serversecurity_combo_box_fill (MODEST_SERVERSECURITY_COMBO_BOX (combobox),
670                                               protocol);
671 #else
672         modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (combobox),
673                                            protocol);
674 #endif
675 }
676
677 ModestProtocolType
678 modest_serversecurity_selector_get_active_serversecurity (GtkWidget *combobox)
679 {
680 #ifdef USE_SERVERSECURITY_COMBOBOX
681         return modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (combobox));
682 #else
683         return modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (combobox));
684 #endif
685 }
686
687 gboolean
688 modest_serversecurity_selector_set_active_serversecurity (GtkWidget *combobox,
689                                                           ModestProtocolType serversecurity)
690 {
691 #ifdef USE_SERVERSECURITY_COMBOBOX
692         return modest_serversecurity_combo_box_set_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (combobox),
693                                                                           serversecurity);
694 #else
695         return modest_serversecurity_picker_set_active_serversecurity (MODEST_SERVERSECURITY_PICKER (combobox),
696                                                                        serversecurity);
697 #endif
698 }
699
700 gint
701 modest_serversecurity_selector_get_active_serversecurity_port (GtkWidget *combobox)
702 {
703 #ifdef USE_SERVERSECURITY_COMBOBOX
704         return modest_serversecurity_combo_box_get_active_serversecurity_port (MODEST_SERVERSECURITY_COMBO_BOX (combobox));
705 #else
706         return modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (combobox));
707 #endif
708 }
709
710 GtkWidget *
711 modest_toolkit_factory_create_secureauth_selector (ModestToolkitFactory *self)
712 {
713         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_secureauth_selector (self);
714 }
715
716 static GtkWidget *
717 modest_toolkit_factory_create_secureauth_selector_default (ModestToolkitFactory *self)
718 {
719         GtkWidget *result;
720 #ifdef USE_SECUREAUTH_COMBOBOX
721         result = GTK_WIDGET (modest_secureauth_combo_box_new ());
722 #else
723         result = GTK_WIDGET (modest_secureauth_picker_new (MODEST_EDITABLE_SIZE, 
724                                                            HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
725 #endif
726         return result;
727 }
728
729 ModestProtocolType
730 modest_secureauth_selector_get_active_secureauth (GtkWidget *widget)
731 {
732 #ifdef USE_SECUREAUTH_COMBOBOX
733         return modest_secureauth_combo_box_get_active_secureauth (MODEST_SECUREAUTH_COMBO_BOX (widget));
734 #else
735         return modest_secureauth_picker_get_active_secureauth (MODEST_SECUREAUTH_PICKER (widget));
736 #endif
737 }
738
739 gboolean
740 modest_secureauth_selector_set_active_secureauth (GtkWidget *widget,
741                                                   ModestProtocolType secureauth)
742 {
743 #ifdef USE_SECUREAUTH_COMBOBOX
744         return modest_secureauth_combo_box_set_active_secureauth (MODEST_SECUREAUTH_COMBO_BOX (widget),
745                                                                   secureauth);
746 #else
747         return modest_secureauth_picker_set_active_secureauth (MODEST_SECUREAUTH_PICKER (widget),
748                                                                secureauth);
749 #endif
750 }
751
752 gboolean
753 modest_is_secureauth_selector (GtkWidget *widget)
754 {
755 #ifdef USE_SECUREAUTH_COMBOBOX
756         return MODEST_IS_SECUREAUTH_COMBO_BOX (widget);
757 #else
758         return MODEST_IS_SECUREAUTH_PICKER (widget);
759 #endif
760 }
761
762 GtkWidget *
763 modest_toolkit_factory_create_security_options_view (ModestToolkitFactory *self, 
764                                                      ModestSecurityOptionsType type,
765                                                      gboolean full, 
766                                                      GtkSizeGroup *title_size_group, 
767                                                      GtkSizeGroup *value_size_group)
768 {
769         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_security_options_view (self, type, full, 
770                                                                                       title_size_group, value_size_group);
771 }
772
773 static GtkWidget *
774 modest_toolkit_factory_create_security_options_view_default (ModestToolkitFactory *self, 
775                                                              ModestSecurityOptionsType type,
776                                                              gboolean full, 
777                                                              GtkSizeGroup *title_size_group, 
778                                                              GtkSizeGroup *value_size_group)
779 {
780         GtkWidget *result;
781 #ifdef USE_GTK_SECURITY_OPTIONS_VIEW
782         result = GTK_WIDGET (modest_gtk_security_options_view_new (type, full, title_size_group, value_size_group));
783 #else
784         result = GTK_WIDGET (modest_maemo_security_options_view_new (type, full, title_size_group, value_size_group));
785 #endif
786         return result;
787 }
788
789 GtkWidget *
790 modest_toolkit_factory_create_text_view (ModestToolkitFactory *self)
791 {
792         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_text_view (self);
793 }
794
795 static GtkWidget *
796 modest_toolkit_factory_create_text_view_default (ModestToolkitFactory *self)
797 {
798 #ifdef USE_GTK_TEXT_VIEW
799         return gtk_text_view_new ();
800 #else
801         return hildon_text_view_new ();
802 #endif
803 }
804
805 GtkTextBuffer *
806 modest_text_view_get_buffer (GtkWidget *widget)
807 {
808 #ifdef USE_GTK_TEXT_VIEW
809         return gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
810 #else
811         return hildon_text_view_get_buffer (HILDON_TEXT_VIEW (widget));
812 #endif
813 }
814
815 gboolean
816 modest_is_text_view (GtkWidget *widget)
817 {
818 #ifdef USE_GTK_TEXT_VIEW
819         return GTK_IS_TEXT_VIEW (widget);
820 #else
821         return HILDON_IS_TEXT_VIEW (widget);
822 #endif
823 }
824
825 GtkWidget *
826 modest_toolkit_factory_create_selector (ModestToolkitFactory *self,
827                                         ModestPairList *pairs, GEqualFunc id_equal_func)
828 {
829         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_selector (self, pairs, id_equal_func);
830 }
831
832 static GtkWidget *
833 modest_toolkit_factory_create_selector_default (ModestToolkitFactory *self,
834                                                 ModestPairList *pairs, GEqualFunc id_equal_func)
835 {
836 #ifdef USE_SELECTOR_COMBOBOX
837         return modest_combo_box_new (pairs, id_equal_func);
838 #else
839         return modest_selector_picker_new (MODEST_EDITABLE_SIZE, 
840                                            HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
841                                            pairs, id_equal_func);
842 #endif
843 }
844
845 void
846 modest_selector_set_pair_list (GtkWidget *widget, 
847                                ModestPairList *pairs)
848 {
849 #ifdef USE_SELECTOR_COMBOBOX
850         modest_combo_box_set_pair_list (MODEST_COMBO_BOX (widget),
851                                         pairs);
852 #else
853         modest_selector_picker_set_pair_list (MODEST_SELECTOR_PICKER (widget),
854                                               pairs);
855 #endif
856 }
857
858 gpointer
859 modest_selector_get_active_id  (GtkWidget *self)
860 {
861 #ifdef USE_SELECTOR_COMBOBOX
862         return modest_combo_box_get_active_id (MODEST_COMBO_BOX (self));
863 #else
864         return modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (self));
865 #endif
866 }
867
868 void
869 modest_selector_set_active_id (GtkWidget *self, gpointer id)
870 {
871 #ifdef USE_SELECTOR_COMBOBOX
872         modest_combo_box_set_active_id (MODEST_COMBO_BOX (self), id);
873 #else
874         modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (self), id);
875 #endif
876 }
877
878 const gchar*
879 modest_selector_get_active_display_name  (GtkWidget *self)
880 {
881 #ifdef USE_SELECTOR_COMBOBOX
882         return modest_combo_box_get_active_display_name (MODEST_COMBO_BOX (self));
883 #else
884         return modest_selector_picker_get_active_display_name (MODEST_SELECTOR_PICKER (self));
885 #endif
886 }
887
888 void
889 modest_selector_set_value_max_chars (GtkWidget *self, gint value_max_width_chars)
890 {
891 #ifndef USE_SELECTOR_COMBOBOX
892         modest_selector_picker_set_value_max_chars (MODEST_SELECTOR_PICKER (self), value_max_width_chars);
893 #endif
894 }
895
896 gint
897 modest_selector_get_value_max_chars (GtkWidget *self)
898 {
899 #ifdef USE_SELECTOR_COMBOBOX
900         return G_MAXINT;
901 #else
902         return modest_selector_picker_get_value_max_chars (MODEST_SELECTOR_PICKER (self));
903 #endif
904 }