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