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