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