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