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