Insert the trailing space of signature separator as " "
[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                 /* Check existence of dialog */
560                 if (dialog == NULL)
561                         return NULL;
562
563                 /* Load settings */
564                 settings = modest_account_mgr_load_account_settings (modest_runtime_get_account_mgr (),
565                                                                      account_name);
566                 modest_account_settings_dialog_load_settings (dialog, settings);
567
568                 /* Close dialog on response */
569                 g_signal_connect_swapped (dialog,
570                                           "response",
571                                           G_CALLBACK (gtk_widget_destroy),
572                                           dialog);
573
574                 g_hash_table_insert (priv->account_dialogs, g_strdup (account_name), dialog);
575                 g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) account_dialog_weak_handler, self);
576         }
577
578         return dialog;
579 }
580
581 ModestPairList*
582 modest_account_protocol_get_easysetupwizard_tabs (ModestAccountProtocol *self)
583 {
584         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_easysetupwizard_tabs (self);
585 }
586
587
588 void 
589 modest_account_protocol_save_settings (ModestAccountProtocol *self, 
590                                        ModestAccountSettingsDialog *dialog,
591                                        ModestAccountSettings *settings)
592 {
593         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_settings (self, dialog, settings);
594 }
595
596 void 
597 modest_account_protocol_save_wizard_settings (ModestAccountProtocol *self, 
598                                               GList *wizard_pages,
599                                               ModestAccountSettings *settings)
600 {
601         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_wizard_settings (self, wizard_pages, settings);
602 }
603
604 /* Default implementations */
605 static ModestAccountSettingsDialog *
606 modest_account_protocol_create_account_settings_dialog_default (ModestAccountProtocol *self)
607 {
608         return modest_default_account_settings_dialog_new ();
609 }
610
611 static ModestPairList*
612 modest_account_protocol_get_easysetupwizard_tabs_default (ModestAccountProtocol *self)
613 {
614         g_warning ("You must implement get_easysetupwizard_tabs");
615         return NULL;
616 }
617
618 static void 
619 modest_account_protocol_save_settings_default (ModestAccountProtocol *self, 
620                                                ModestAccountSettingsDialog *dialog,
621                                                ModestAccountSettings *settings)
622 {
623         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
624         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
625         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
626
627         g_warning ("You must implement save_settings");
628 }
629
630 static void 
631 modest_account_protocol_save_wizard_settings_default (ModestAccountProtocol *self, 
632                                                       GList *wizard_pages,
633                                                       ModestAccountSettings *settings)
634 {
635         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
636         g_return_if_fail (wizard_pages);
637         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
638
639         g_warning ("You must implement save_wizard_settings");
640 }
641
642 static ModestWizardDialogResponseOverrideFunc
643 modest_account_protocol_get_wizard_response_override_default (ModestAccountProtocol *self)
644 {
645         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
646
647         return NULL;
648 }
649
650 ModestWizardDialogResponseOverrideFunc
651 modest_account_protocol_get_wizard_response_override (ModestAccountProtocol *self)
652 {
653         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
654
655         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_wizard_response_override (self);   
656 }
657
658 static gboolean
659 modest_account_protocol_is_supported_default (ModestAccountProtocol *self)
660 {
661         return TRUE;
662 }
663
664 gboolean
665 modest_account_protocol_is_supported (ModestAccountProtocol *self)
666 {
667         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->is_supported (self);
668 }
669
670 static void
671 modest_account_protocol_check_support_default (ModestAccountProtocol *self,
672                                                ModestAccountProtocolCheckSupportFunc func,
673                                                gpointer userdata)
674 {
675         if (func)
676                 func (self, TRUE, userdata);
677 }
678
679 void
680 modest_account_protocol_check_support (ModestAccountProtocol *self,
681                                        ModestAccountProtocolCheckSupportFunc func,
682                                        gpointer userdata)
683 {
684         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->check_support (self, func, userdata);
685 }
686
687 static void
688 modest_account_protocol_cancel_check_support_default (ModestAccountProtocol *self)
689 {
690         return;
691 }
692
693 void
694 modest_account_protocol_cancel_check_support (ModestAccountProtocol *self)
695 {
696         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->cancel_check_support (self);
697 }
698
699 static void
700 modest_account_protocol_wizard_finished_default (ModestAccountProtocol *self)
701 {
702         return;
703 }
704
705 void
706 modest_account_protocol_wizard_finished (ModestAccountProtocol *self)
707 {
708         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->wizard_finished (self);
709 }
710
711 static gboolean
712 modest_account_protocol_decode_part_to_stream_default (ModestAccountProtocol *self,
713                                                        TnyMimePart *part,
714                                                        const gchar *stream_uri,
715                                                        TnyStream *stream,
716                                                        gssize *written,
717                                                        GError **error)
718 {
719         /* By default account protocols do not handle themselves the transfer */
720         return FALSE;
721 }
722
723 gboolean
724 modest_account_protocol_decode_part_to_stream (ModestAccountProtocol *self,
725                                                TnyMimePart *part,
726                                                const gchar *stream_uri,
727                                                TnyStream *stream,
728                                                gssize *written,
729                                                GError **error)
730 {
731         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->decode_part_to_stream (self,
732                                                                                 part,
733                                                                                 stream_uri,
734                                                                                 stream,
735                                                                                 written,
736                                                                                 error);
737 }
738
739 static gboolean
740 modest_account_protocol_decode_part_to_stream_async_default (ModestAccountProtocol *self,
741                                                              TnyMimePart *part,
742                                                              const gchar *stream_uri,
743                                                              TnyStream *stream, 
744                                                              TnyMimePartCallback callback, 
745                                                              TnyStatusCallback status_callback, 
746                                                              gpointer user_data)
747 {
748         /* By default account protocols do not handle themselves the transfer */
749         return FALSE;
750 }
751
752 gboolean
753 modest_account_protocol_decode_part_to_stream_async (ModestAccountProtocol *self,
754                                                      TnyMimePart *part, 
755                                                      const gchar *stream_uri,
756                                                      TnyStream *stream, 
757                                                      TnyMimePartCallback callback, 
758                                                      TnyStatusCallback status_callback, 
759                                                      gpointer user_data)
760 {
761         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->decode_part_to_stream_async (self,
762                                                                                       part,
763                                                                                       stream_uri,
764                                                                                       stream,
765                                                                                       callback,
766                                                                                       status_callback,
767                                                                                       user_data);
768 }
769
770 gchar *
771 modest_account_protocol_get_from (ModestAccountProtocol *self,
772                                   const gchar *account_id,
773                                   const gchar *mailbox)
774 {
775         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from (self, account_id, mailbox);
776 }
777 static gchar *
778 modest_account_protocol_get_from_default (ModestAccountProtocol *self,
779                                           const gchar *account_id,
780                                           const gchar *mailbox)
781 {
782         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
783
784         return NULL;
785 }
786
787 ModestPairList *
788 modest_account_protocol_get_from_list (ModestAccountProtocol *self,
789                                        const gchar *account_id)
790 {
791         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from_list (self, account_id);
792 }
793 static ModestPairList *
794 modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
795                                                const gchar *account_id)
796 {
797         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
798
799         return NULL;
800 }
801
802 gchar *
803 modest_account_protocol_get_signature (ModestAccountProtocol *self,
804                                        const gchar *account_id,
805                                        const gchar *mailbox,
806                                        gboolean *has_signature)
807 {
808         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_signature (self, account_id, mailbox, has_signature);
809 }
810
811 static gchar *
812 modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
813                                                const gchar *account_id,
814                                                const gchar *mailbox,
815                                                gboolean *has_signature)
816 {
817         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
818         if (has_signature)
819                 *has_signature = FALSE;
820
821         return NULL;
822 }
823
824 const GdkPixbuf*
825 modest_account_protocol_get_icon (ModestAccountProtocol *self,
826                                   ModestAccountProtocolIconType icon_type,
827                                   GObject *object,
828                                   guint icon_size)
829 {
830         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_icon (self, icon_type, object, icon_size);
831 }
832
833 static const GdkPixbuf * 
834 modest_account_protocol_get_icon_default (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
835                                           GObject *object, guint icon_size)
836 {
837         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
838
839         return NULL;
840 }
841
842 gchar *
843 modest_account_protocol_get_service_name (ModestAccountProtocol *self,
844                                           const gchar *account_id,
845                                           const gchar *mailbox)
846 {
847         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_name (self, account_id, mailbox);
848 }
849
850 static gchar *
851 modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
852                                                   const gchar *account_id,
853                                                   const gchar *mailbox)
854 {
855         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
856
857         return NULL;
858 }
859
860 const GdkPixbuf *
861 modest_account_protocol_get_service_icon (ModestAccountProtocol *self,
862                                           const gchar *account_id,
863                                           const gchar *mailbox,
864                                           guint icon_size)
865 {
866         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_icon (self, account_id, mailbox, icon_size);
867 }
868
869 static const GdkPixbuf *
870 modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
871                                                   const gchar *account_id,
872                                                   const gchar *mailbox,
873                                                   guint icon_size)
874 {
875         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
876
877         return NULL;
878 }
879
880 void
881 modest_account_protocol_save_remote_draft (ModestAccountProtocol *self,
882                                            const gchar *account_id,
883                                            TnyMsg *new_msg,
884                                            TnyMsg *old_msg,
885                                            ModestAccountProtocolSaveRemoteDraftCallback callback,
886                                            gpointer userdata)
887 {
888         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_remote_draft (self, account_id, 
889                                                                      new_msg, old_msg,
890                                                                      callback, userdata);
891 }
892
893 static void
894 modest_account_protocol_save_remote_draft_default (ModestAccountProtocol *self,
895                                                    const gchar *account_id,
896                                                    TnyMsg *new_msg,
897                                                    TnyMsg *old_msg,
898                                                    ModestAccountProtocolSaveRemoteDraftCallback callback,
899                                                    gpointer userdata)
900 {
901         if (callback) {
902                 callback (self, NULL, account_id, NULL, new_msg, old_msg, userdata);
903         }
904 }
905