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