Fix modest_tny_msg_header_get_all_recipients_list (in case from is empty)
[modest] / src / modest-account-protocol.c
1 /* Copyright (c) 2008, Nokia Corporation
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 <tny-simple-list.h>
31 #include "modest-account-protocol.h"
32 #include "modest-account-mgr-helpers.h"
33 #include "widgets/modest-default-account-settings-dialog.h"
34 #include "modest-runtime.h"
35
36 enum {
37         PROP_0,
38         PROP_PORT,
39         PROP_ALTERNATE_PORT,
40         PROP_ACCOUNT_G_TYPE,
41 };
42
43 typedef struct _ModestAccountProtocolPrivate ModestAccountProtocolPrivate;
44 struct _ModestAccountProtocolPrivate {
45         guint port;
46         guint alternate_port;
47         TnyList *account_options;
48         GHashTable *custom_auth_mechs;
49         GType account_g_type;
50
51         GHashTable *account_dialogs;
52 };
53
54 /* 'private'/'protected' functions */
55 static void   modest_account_protocol_class_init (ModestAccountProtocolClass *klass);
56 static void   modest_account_protocol_finalize   (GObject *obj);
57 static void   modest_account_protocol_get_property (GObject *obj,
58                                             guint property_id,
59                                             GValue *value,
60                                             GParamSpec *pspec);
61 static void   modest_account_protocol_set_property (GObject *obj,
62                                             guint property_id,
63                                             const GValue *value,
64                                             GParamSpec *pspec);
65 static void   modest_account_protocol_instance_init (ModestAccountProtocol *obj);
66
67 #define MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE(o)     (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
68                                                                                  MODEST_TYPE_ACCOUNT_PROTOCOL, \
69                                                                                  ModestAccountProtocolPrivate))
70
71 static TnyAccount *modest_account_protocol_create_account_default (ModestAccountProtocol *self);
72
73 static ModestAccountSettingsDialog *modest_account_protocol_create_account_settings_dialog_default (ModestAccountProtocol *self);
74
75 static ModestPairList* modest_account_protocol_get_easysetupwizard_tabs_default (ModestAccountProtocol *self);
76
77 static void modest_account_protocol_save_settings_default (ModestAccountProtocol *self, 
78                                                            ModestAccountSettingsDialog *dialog,
79                                                            ModestAccountSettings *settings);
80
81 static void modest_account_protocol_save_wizard_settings_default (ModestAccountProtocol *self, 
82                                                                   GList *wizard_pages,
83                                                                   ModestAccountSettings *settings);
84
85 static ModestWizardDialogResponseOverrideFunc 
86 modest_account_protocol_get_wizard_response_override_default (ModestAccountProtocol *self);
87
88 static void modest_account_protocol_check_support_default (ModestAccountProtocol *self,
89                                                            ModestAccountProtocolCheckSupportFunc func,
90                                                            gpointer userdata);
91 static gboolean modest_account_protocol_is_supported_default (ModestAccountProtocol *self);
92 static gchar *modest_account_protocol_get_from_default (ModestAccountProtocol *self,
93                                                         const gchar *account_id,
94                                                         const gchar *mailbox);
95 static ModestPairList *modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
96                                                                       const gchar *account_id);
97 static gchar *modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
98                                                              const gchar *account_id,
99                                                              const gchar *mailbox,
100                                                              gboolean *has_signature);
101 static const GdkPixbuf *modest_account_protocol_get_icon_default (ModestAccountProtocol *self,
102                                                                   ModestAccountProtocolIconType icon_type, 
103                                                                   GObject *object, 
104                                                                   guint icon_size);
105
106 static gchar *modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
107                                                                 const gchar *account_id,
108                                                                 const gchar *mailbox);
109
110 static const GdkPixbuf *modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
111                                                                           const gchar *account_id,
112                                                                           const gchar *mailbox,
113                                                                           guint icon_size);
114
115 /* globals */
116 static GObjectClass *parent_class = NULL;
117
118 GType
119 modest_account_protocol_get_type (void)
120 {
121         static GType my_type = 0;
122
123         if (!my_type) {
124                 static const GTypeInfo my_info = {
125                         sizeof(ModestAccountProtocolClass),
126                         NULL,   /* base init */
127                         NULL,   /* base finalize */
128                         (GClassInitFunc) modest_account_protocol_class_init,
129                         NULL,   /* class finalize */
130                         NULL,   /* class data */
131                         sizeof(ModestAccountProtocol),
132                         0,      /* n_preallocs */
133                         (GInstanceInitFunc) modest_account_protocol_instance_init,
134                         NULL
135                 };
136
137                 my_type = g_type_register_static (MODEST_TYPE_PROTOCOL,
138                                                   "ModestAccountProtocol",
139                                                   &my_info, 0);
140         }
141         return my_type;
142 }
143
144 static void
145 modest_account_protocol_class_init (ModestAccountProtocolClass *klass)
146 {
147         GObjectClass *object_class;
148         ModestAccountProtocolClass *account_class;
149
150         object_class = (GObjectClass *) klass;
151         account_class = MODEST_ACCOUNT_PROTOCOL_CLASS (klass);
152         parent_class = g_type_class_peek_parent (klass);
153         object_class->finalize = modest_account_protocol_finalize;
154         object_class->set_property = modest_account_protocol_set_property;
155         object_class->get_property = modest_account_protocol_get_property;
156
157         g_object_class_install_property (object_class,
158                                          PROP_PORT,
159                                          g_param_spec_uint ("port",
160                                                            _("Standard port"),
161                                                            _("The standard port for the protocol"),
162                                                            0, G_MAXINT, 0,
163                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
164
165         g_object_class_install_property (object_class,
166                                          PROP_ALTERNATE_PORT,
167                                          g_param_spec_uint ("alternate-port",
168                                                            _("Alternate port"),
169                                                            _("The alternate port for the protocol (usually used in SSL)"),
170                                                            0, G_MAXINT, 0,
171                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
172
173         g_object_class_install_property (object_class,
174                                          PROP_ACCOUNT_G_TYPE,
175                                          g_param_spec_gtype ("account-g-type",
176                                                              _("Account factory GType"),
177                                                              _("Account factory GType used for creating new instances."),
178                                                              TNY_TYPE_ACCOUNT,
179                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
180
181         g_type_class_add_private (object_class,
182                                   sizeof(ModestAccountProtocolPrivate));
183
184         /* Virtual methods */
185         account_class->create_account_settings_dialog = 
186                 modest_account_protocol_create_account_settings_dialog_default;
187         account_class->get_easysetupwizard_tabs = 
188                 modest_account_protocol_get_easysetupwizard_tabs_default;
189         account_class->save_settings = 
190                 modest_account_protocol_save_settings_default;
191         account_class->save_wizard_settings = 
192                 modest_account_protocol_save_wizard_settings_default;
193         account_class->create_account =
194                 modest_account_protocol_create_account_default;
195         account_class->get_wizard_response_override =
196                 modest_account_protocol_get_wizard_response_override_default;
197         account_class->is_supported =
198                 modest_account_protocol_is_supported_default;
199         account_class->check_support =
200                 modest_account_protocol_check_support_default;
201         account_class->get_from =
202                 modest_account_protocol_get_from_default;
203         account_class->get_from_list =
204                 modest_account_protocol_get_from_list_default;
205         account_class->get_signature =
206                 modest_account_protocol_get_signature_default;
207         account_class->get_icon =
208                 modest_account_protocol_get_icon_default;
209         account_class->get_service_name =
210                 modest_account_protocol_get_service_name_default;
211         account_class->get_service_icon =
212                 modest_account_protocol_get_service_icon_default;
213 }
214
215 static void
216 modest_account_protocol_instance_init (ModestAccountProtocol *obj)
217 {
218         ModestAccountProtocolPrivate *priv;
219
220         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (obj);
221
222         priv->port = 0;
223         priv->alternate_port = 0;
224         priv->account_g_type = 0;
225         priv->account_options = tny_simple_list_new ();
226         priv->custom_auth_mechs = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
227
228         priv->account_dialogs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
229 }
230
231 static gboolean
232 remove_account (const gchar *account_name, GObject *account, GObject *account_to_remove)
233 {
234         return (account == account_to_remove);
235 }
236
237 static void
238 account_dialog_weak_handler (ModestAccountProtocol *self, GObject *where_the_object_was)
239 {
240         ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
241
242         g_hash_table_foreach_remove (priv->account_dialogs, (GHRFunc) remove_account, where_the_object_was);
243 }
244
245 static gboolean
246 dialogs_remove (const gchar *account_name, GObject *account_dialog, ModestAccountProtocol *self)
247 {
248         g_object_weak_unref (account_dialog, (GWeakNotify) account_dialog_weak_handler, self);
249
250         return TRUE;
251 }
252
253 static void   
254 modest_account_protocol_finalize   (GObject *obj)
255 {
256         ModestAccountProtocol *protocol = MODEST_ACCOUNT_PROTOCOL (obj);
257         ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (protocol);
258
259         if (priv->account_dialogs) {
260                 g_hash_table_foreach_remove (priv->account_dialogs, (GHRFunc) dialogs_remove, obj);
261                 g_hash_table_destroy (priv->account_dialogs);
262         }
263
264         if (priv->account_options)
265                 g_object_unref (priv->account_options);
266         priv->account_options = NULL;
267
268         if (priv->custom_auth_mechs)
269                 g_hash_table_destroy (priv->custom_auth_mechs);
270         priv->custom_auth_mechs = NULL;
271
272         G_OBJECT_CLASS (parent_class)->finalize (obj);
273 }
274
275 static void   
276 modest_account_protocol_get_property (GObject *obj,
277                                       guint property_id,
278                                       GValue *value,
279                                       GParamSpec *pspec)
280 {
281         ModestAccountProtocol *protocol = MODEST_ACCOUNT_PROTOCOL (obj);
282         ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (protocol);
283
284         switch (property_id) {
285         case PROP_PORT:
286                 g_value_set_uint (value, priv->port);
287                 break;
288         case PROP_ALTERNATE_PORT:
289                 g_value_set_uint (value, priv->alternate_port);
290                 break;
291         case PROP_ACCOUNT_G_TYPE:
292                 g_value_set_gtype (value, priv->account_g_type);
293                 break;
294         default:
295                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
296         }
297
298 }
299
300 static void   
301 modest_account_protocol_set_property (GObject *obj,
302                                       guint property_id,
303                                       const GValue *value,
304                                       GParamSpec *pspec)
305 {
306         ModestAccountProtocol *protocol = MODEST_ACCOUNT_PROTOCOL (obj);
307
308         switch (property_id) {
309         case PROP_PORT:
310                 modest_account_protocol_set_port (protocol, g_value_get_uint (value));
311                 break;
312         case PROP_ALTERNATE_PORT:
313                 modest_account_protocol_set_alternate_port (protocol, g_value_get_uint (value));
314                 break;
315         case PROP_ACCOUNT_G_TYPE:
316                 modest_account_protocol_set_account_g_type (protocol, g_value_get_gtype (value));
317                 break;
318         default:
319                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
320         }
321
322 }
323
324
325 ModestProtocol*
326 modest_account_protocol_new (const gchar *name, const gchar *display_name,
327                              guint port, guint alternate_port,
328                              GType account_g_type)
329 {
330         return g_object_new (MODEST_TYPE_ACCOUNT_PROTOCOL, 
331                              "display-name", display_name, "name", name, 
332                              "port", port, "alternate-port", alternate_port,
333                              "account-g-type", account_g_type,
334                              NULL);
335 }
336
337 guint
338 modest_account_protocol_get_port (ModestAccountProtocol *self)
339 {
340         ModestAccountProtocolPrivate *priv;
341
342         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), 0);
343
344         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
345         return priv->port;
346 }
347
348 void         
349 modest_account_protocol_set_port (ModestAccountProtocol *self,
350                                   guint port)
351 {
352         ModestAccountProtocolPrivate *priv;
353
354         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
355
356         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
357         priv->port = port;
358 }
359
360
361 guint
362 modest_account_protocol_get_alternate_port (ModestAccountProtocol *self)
363 {
364         ModestAccountProtocolPrivate *priv;
365
366         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), 0);
367
368         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
369         return priv->alternate_port;
370 }
371
372 void         
373 modest_account_protocol_set_alternate_port (ModestAccountProtocol *self,
374                                             guint alternate_port)
375 {
376         ModestAccountProtocolPrivate *priv;
377
378         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
379
380         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
381         priv->alternate_port = alternate_port;
382 }
383
384 GType
385 modest_account_protocol_get_account_g_type (ModestAccountProtocol *self)
386 {
387         ModestAccountProtocolPrivate *priv;
388
389         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), 0);
390
391         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
392         return priv->account_g_type;
393 }
394
395 TnyList *
396 modest_account_protocol_get_account_options (ModestAccountProtocol *self)
397 {
398         TnyList *result;
399         ModestAccountProtocolPrivate *priv;
400
401         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
402         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
403
404         result = tny_list_copy (priv->account_options);
405
406         return result;
407 }
408
409 void
410 modest_account_protocol_set_account_options (ModestAccountProtocol *self,
411                                              TnyList *list)
412 {
413         ModestAccountProtocolPrivate *priv;
414
415         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
416         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
417
418         if (priv->account_options) {
419                 g_object_unref (priv->account_options);
420                 priv->account_options = NULL;
421         }
422         priv->account_options = tny_list_copy (list);
423 }
424
425 gboolean
426 modest_account_protocol_has_custom_secure_auth_mech (ModestAccountProtocol *self, 
427                                                      ModestProtocolType auth_protocol_type)
428 {
429         ModestAccountProtocolPrivate *priv;
430
431         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), FALSE);
432         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
433
434         return g_hash_table_lookup_extended (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type), NULL, NULL);
435 }
436
437 const gchar *
438 modest_account_protocol_get_custom_secure_auth_mech (ModestAccountProtocol *self, 
439                                                      ModestProtocolType auth_protocol_type)
440 {
441         ModestAccountProtocolPrivate *priv;
442
443         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
444         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
445
446         return (const gchar *) g_hash_table_lookup (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type));
447 }
448
449 void
450 modest_account_protocol_set_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type, const gchar *secure_auth_mech)
451 {
452         ModestAccountProtocolPrivate *priv;
453
454         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
455         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
456
457         g_hash_table_replace (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type), g_strdup (secure_auth_mech));
458 }
459
460 void
461 modest_account_protocol_unset_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type)
462 {
463         ModestAccountProtocolPrivate *priv;
464
465         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
466         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
467
468         g_hash_table_remove (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type));
469 }
470
471
472 void         
473 modest_account_protocol_set_account_g_type (ModestAccountProtocol *self,
474                                             GType account_g_type)
475 {
476         ModestAccountProtocolPrivate *priv;
477
478         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
479
480         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
481         priv->account_g_type = account_g_type;
482 }
483
484 static TnyAccount *
485 modest_account_protocol_create_account_default (ModestAccountProtocol *self)
486 {
487         ModestAccountProtocolPrivate *priv;
488
489         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
490
491         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
492         if (priv->account_g_type > 0) {
493                 return g_object_new (priv->account_g_type, NULL);
494         } else {
495                 return NULL;
496         }
497 }
498
499 TnyAccount *
500 modest_account_protocol_create_account (ModestAccountProtocol *self)
501 {
502         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
503
504         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->create_account (self); 
505 }
506
507 /* This is a template method for getting the account settings
508    dialog. It calls create_account_settings that must be implemented
509    by subclasses and then perform several common operations with the
510    dialog */
511 ModestAccountSettingsDialog *
512 modest_account_protocol_get_account_settings_dialog (ModestAccountProtocol *self,
513                                                      const gchar *account_name)
514 {
515         ModestAccountSettingsDialog *dialog;
516         ModestAccountSettings *settings;
517         ModestAccountProtocolPrivate *priv;
518
519         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
520         dialog = g_hash_table_lookup (priv->account_dialogs, account_name);
521
522         if (dialog == NULL) {
523
524                 dialog = MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->create_account_settings_dialog (self);
525         
526                 /* Load settings */
527                 settings = modest_account_mgr_load_account_settings (modest_runtime_get_account_mgr (), 
528                                                                      account_name);
529                 modest_account_settings_dialog_load_settings (dialog, settings);
530         
531                 /* Close dialog on response */
532                 g_signal_connect_swapped (dialog,
533                                           "response",
534                                           G_CALLBACK (gtk_widget_destroy),
535                                           dialog);
536
537                 g_hash_table_insert (priv->account_dialogs, g_strdup (account_name), dialog);
538                 g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) account_dialog_weak_handler, self);
539         }
540
541         return dialog;
542 }
543
544 ModestPairList*
545 modest_account_protocol_get_easysetupwizard_tabs (ModestAccountProtocol *self)
546 {
547         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_easysetupwizard_tabs (self);
548 }
549
550
551 void 
552 modest_account_protocol_save_settings (ModestAccountProtocol *self, 
553                                        ModestAccountSettingsDialog *dialog,
554                                        ModestAccountSettings *settings)
555 {
556         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_settings (self, dialog, settings);
557 }
558
559 void 
560 modest_account_protocol_save_wizard_settings (ModestAccountProtocol *self, 
561                                               GList *wizard_pages,
562                                               ModestAccountSettings *settings)
563 {
564         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_wizard_settings (self, wizard_pages, settings);
565 }
566
567 /* Default implementations */
568 static ModestAccountSettingsDialog *
569 modest_account_protocol_create_account_settings_dialog_default (ModestAccountProtocol *self)
570 {
571         return modest_default_account_settings_dialog_new ();
572 }
573
574 static ModestPairList*
575 modest_account_protocol_get_easysetupwizard_tabs_default (ModestAccountProtocol *self)
576 {
577         g_warning ("You must implement get_easysetupwizard_tabs");
578         return NULL;
579 }
580
581 static void 
582 modest_account_protocol_save_settings_default (ModestAccountProtocol *self, 
583                                                ModestAccountSettingsDialog *dialog,
584                                                ModestAccountSettings *settings)
585 {
586         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
587         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
588         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
589
590         g_warning ("You must implement save_settings");
591 }
592
593 static void 
594 modest_account_protocol_save_wizard_settings_default (ModestAccountProtocol *self, 
595                                                       GList *wizard_pages,
596                                                       ModestAccountSettings *settings)
597 {
598         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
599         g_return_if_fail (wizard_pages);
600         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
601
602         g_warning ("You must implement save_wizard_settings");
603 }
604
605 static ModestWizardDialogResponseOverrideFunc
606 modest_account_protocol_get_wizard_response_override_default (ModestAccountProtocol *self)
607 {
608         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
609
610         return NULL;
611 }
612
613 ModestWizardDialogResponseOverrideFunc
614 modest_account_protocol_get_wizard_response_override (ModestAccountProtocol *self)
615 {
616         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
617
618         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_wizard_response_override (self);   
619 }
620
621 static gboolean
622 modest_account_protocol_is_supported_default (ModestAccountProtocol *self)
623 {
624         return TRUE;
625 }
626
627 gboolean
628 modest_account_protocol_is_supported (ModestAccountProtocol *self)
629 {
630         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->is_supported (self);
631 }
632
633 static void
634 modest_account_protocol_check_support_default (ModestAccountProtocol *self,
635                                                ModestAccountProtocolCheckSupportFunc func,
636                                                gpointer userdata)
637 {
638         if (func)
639                 func (self, TRUE, userdata);
640 }
641
642 void
643 modest_account_protocol_check_support (ModestAccountProtocol *self,
644                                        ModestAccountProtocolCheckSupportFunc func,
645                                        gpointer userdata)
646 {
647         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->check_support (self, func, userdata);
648 }
649
650 gchar *
651 modest_account_protocol_get_from (ModestAccountProtocol *self,
652                                   const gchar *account_id,
653                                   const gchar *mailbox)
654 {
655         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from (self, account_id, mailbox);
656 }
657 static gchar *
658 modest_account_protocol_get_from_default (ModestAccountProtocol *self,
659                                           const gchar *account_id,
660                                           const gchar *mailbox)
661 {
662         g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
663
664         return NULL;
665 }
666
667 ModestPairList *
668 modest_account_protocol_get_from_list (ModestAccountProtocol *self,
669                                        const gchar *account_id)
670 {
671         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from_list (self, account_id);
672 }
673 static ModestPairList *
674 modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
675                                                const gchar *account_id)
676 {
677         g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
678
679         return NULL;
680 }
681
682 gchar *
683 modest_account_protocol_get_signature (ModestAccountProtocol *self,
684                                        const gchar *account_id,
685                                        const gchar *mailbox,
686                                        gboolean *has_signature)
687 {
688         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_signature (self, account_id, mailbox, has_signature);
689 }
690
691 static gchar *
692 modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
693                                                const gchar *account_id,
694                                                const gchar *mailbox,
695                                                gboolean *has_signature)
696 {
697         g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
698         if (has_signature)
699                 *has_signature = FALSE;
700
701         return NULL;
702 }
703
704 const GdkPixbuf*
705 modest_account_protocol_get_icon (ModestAccountProtocol *self,
706                                   ModestAccountProtocolIconType icon_type,
707                                   GObject *object,
708                                   guint icon_size)
709 {
710         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_icon (self, icon_type, object, icon_size);
711 }
712
713 static const GdkPixbuf * 
714 modest_account_protocol_get_icon_default (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
715                                           GObject *object, guint icon_size)
716 {
717         g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
718
719         return NULL;
720 }
721
722 gchar *
723 modest_account_protocol_get_service_name (ModestAccountProtocol *self,
724                                           const gchar *account_id,
725                                           const gchar *mailbox)
726 {
727         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_name (self, account_id, mailbox);
728 }
729
730 static gchar *
731 modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
732                                                   const gchar *account_id,
733                                                   const gchar *mailbox)
734 {
735         g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
736
737         return NULL;
738 }
739
740 const GdkPixbuf *
741 modest_account_protocol_get_service_icon (ModestAccountProtocol *self,
742                                           const gchar *account_id,
743                                           const gchar *mailbox,
744                                           guint icon_size)
745 {
746         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_icon (self, account_id, mailbox, icon_size);
747 }
748
749 static const GdkPixbuf *
750 modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
751                                                   const gchar *account_id,
752                                                   const gchar *mailbox,
753                                                   guint icon_size)
754 {
755         g_return_val_if_fail (MODEST_ACCOUNT_PROTOCOL (self), NULL);
756
757         return NULL;
758 }
759