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