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