Added cancel_check_support method to account protocols.
[modest] / src / modest-account-protocol.c
1 /* Copyright (c) 2008, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <tny-simple-list.h>
31 #include "modest-account-protocol.h"
32 #include "modest-account-mgr-helpers.h"
33 #include "widgets/modest-default-account-settings-dialog.h"
34 #include "modest-runtime.h"
35 #include "modest-marshal.h"
36
37 enum {
38         PROP_0,
39         PROP_PORT,
40         PROP_ALTERNATE_PORT,
41         PROP_ACCOUNT_G_TYPE,
42 };
43
44 typedef struct _ModestAccountProtocolPrivate ModestAccountProtocolPrivate;
45 struct _ModestAccountProtocolPrivate {
46         guint port;
47         guint alternate_port;
48         TnyList *account_options;
49         GHashTable *custom_auth_mechs;
50         GType account_g_type;
51
52         GHashTable *account_dialogs;
53 };
54
55 /* 'private'/'protected' functions */
56 static void   modest_account_protocol_class_init (ModestAccountProtocolClass *klass);
57 static void   modest_account_protocol_finalize   (GObject *obj);
58 static void   modest_account_protocol_get_property (GObject *obj,
59                                             guint property_id,
60                                             GValue *value,
61                                             GParamSpec *pspec);
62 static void   modest_account_protocol_set_property (GObject *obj,
63                                             guint property_id,
64                                             const GValue *value,
65                                             GParamSpec *pspec);
66 static void   modest_account_protocol_instance_init (ModestAccountProtocol *obj);
67
68 #define MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE(o)     (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
69                                                                                  MODEST_TYPE_ACCOUNT_PROTOCOL, \
70                                                                                  ModestAccountProtocolPrivate))
71
72 static TnyAccount *modest_account_protocol_create_account_default (ModestAccountProtocol *self);
73
74 static ModestAccountSettingsDialog *modest_account_protocol_create_account_settings_dialog_default (ModestAccountProtocol *self);
75
76 static ModestPairList* modest_account_protocol_get_easysetupwizard_tabs_default (ModestAccountProtocol *self);
77
78 static void modest_account_protocol_save_settings_default (ModestAccountProtocol *self, 
79                                                            ModestAccountSettingsDialog *dialog,
80                                                            ModestAccountSettings *settings);
81
82 static void modest_account_protocol_save_wizard_settings_default (ModestAccountProtocol *self, 
83                                                                   GList *wizard_pages,
84                                                                   ModestAccountSettings *settings);
85
86 static ModestWizardDialogResponseOverrideFunc 
87 modest_account_protocol_get_wizard_response_override_default (ModestAccountProtocol *self);
88
89 static void modest_account_protocol_check_support_default (ModestAccountProtocol *self,
90                                                            ModestAccountProtocolCheckSupportFunc func,
91                                                            gpointer userdata);
92 static void modest_account_protocol_cancel_check_support_default (ModestAccountProtocol *self);
93 static gboolean modest_account_protocol_is_supported_default (ModestAccountProtocol *self);
94 static gchar *modest_account_protocol_get_from_default (ModestAccountProtocol *self,
95                                                         const gchar *account_id,
96                                                         const gchar *mailbox);
97 static ModestPairList *modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
98                                                                       const gchar *account_id);
99 static gchar *modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
100                                                              const gchar *account_id,
101                                                              const gchar *mailbox,
102                                                              gboolean *has_signature);
103 static const GdkPixbuf *modest_account_protocol_get_icon_default (ModestAccountProtocol *self,
104                                                                   ModestAccountProtocolIconType icon_type, 
105                                                                   GObject *object, 
106                                                                   guint icon_size);
107
108 static gchar *modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
109                                                                 const gchar *account_id,
110                                                                 const gchar *mailbox);
111
112 static const GdkPixbuf *modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
113                                                                           const gchar *account_id,
114                                                                           const gchar *mailbox,
115                                                                           guint icon_size);
116 static void modest_account_protocol_save_remote_draft_default (ModestAccountProtocol *self,
117                                                                const gchar *account_id,
118                                                                TnyMsg *new_msg,
119                                                                TnyMsg *old_msg,
120                                                                ModestAccountProtocolSaveRemoteDraftCallback callback,
121                                                                gpointer userdata);
122
123 /* globals */
124 static GObjectClass *parent_class = NULL;
125
126 GType
127 modest_account_protocol_get_type (void)
128 {
129         static GType my_type = 0;
130
131         if (!my_type) {
132                 static const GTypeInfo my_info = {
133                         sizeof(ModestAccountProtocolClass),
134                         NULL,   /* base init */
135                         NULL,   /* base finalize */
136                         (GClassInitFunc) modest_account_protocol_class_init,
137                         NULL,   /* class finalize */
138                         NULL,   /* class data */
139                         sizeof(ModestAccountProtocol),
140                         0,      /* n_preallocs */
141                         (GInstanceInitFunc) modest_account_protocol_instance_init,
142                         NULL
143                 };
144
145                 my_type = g_type_register_static (MODEST_TYPE_PROTOCOL,
146                                                   "ModestAccountProtocol",
147                                                   &my_info, 0);
148         }
149         return my_type;
150 }
151
152 static void
153 modest_account_protocol_class_init (ModestAccountProtocolClass *klass)
154 {
155         GObjectClass *object_class;
156         ModestAccountProtocolClass *account_class;
157
158         object_class = (GObjectClass *) klass;
159         account_class = MODEST_ACCOUNT_PROTOCOL_CLASS (klass);
160         parent_class = g_type_class_peek_parent (klass);
161         object_class->finalize = modest_account_protocol_finalize;
162         object_class->set_property = modest_account_protocol_set_property;
163         object_class->get_property = modest_account_protocol_get_property;
164
165         g_object_class_install_property (object_class,
166                                          PROP_PORT,
167                                          g_param_spec_uint ("port",
168                                                            _("Standard port"),
169                                                            _("The standard port for the protocol"),
170                                                            0, G_MAXINT, 0,
171                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
172
173         g_object_class_install_property (object_class,
174                                          PROP_ALTERNATE_PORT,
175                                          g_param_spec_uint ("alternate-port",
176                                                            _("Alternate port"),
177                                                            _("The alternate port for the protocol (usually used in SSL)"),
178                                                            0, G_MAXINT, 0,
179                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
180
181         g_object_class_install_property (object_class,
182                                          PROP_ACCOUNT_G_TYPE,
183                                          g_param_spec_gtype ("account-g-type",
184                                                              _("Account factory GType"),
185                                                              _("Account factory GType used for creating new instances."),
186                                                              TNY_TYPE_ACCOUNT,
187                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
188
189         g_type_class_add_private (object_class,
190                                   sizeof(ModestAccountProtocolPrivate));
191
192         /* Virtual methods */
193         account_class->create_account_settings_dialog = 
194                 modest_account_protocol_create_account_settings_dialog_default;
195         account_class->get_easysetupwizard_tabs = 
196                 modest_account_protocol_get_easysetupwizard_tabs_default;
197         account_class->save_settings = 
198                 modest_account_protocol_save_settings_default;
199         account_class->save_wizard_settings = 
200                 modest_account_protocol_save_wizard_settings_default;
201         account_class->create_account =
202                 modest_account_protocol_create_account_default;
203         account_class->get_wizard_response_override =
204                 modest_account_protocol_get_wizard_response_override_default;
205         account_class->is_supported =
206                 modest_account_protocol_is_supported_default;
207         account_class->check_support =
208                 modest_account_protocol_check_support_default;
209         account_class->cancel_check_support =
210                 modest_account_protocol_cancel_check_support_default;
211         account_class->get_from =
212                 modest_account_protocol_get_from_default;
213         account_class->get_from_list =
214                 modest_account_protocol_get_from_list_default;
215         account_class->get_signature =
216                 modest_account_protocol_get_signature_default;
217         account_class->get_icon =
218                 modest_account_protocol_get_icon_default;
219         account_class->get_service_name =
220                 modest_account_protocol_get_service_name_default;
221         account_class->get_service_icon =
222                 modest_account_protocol_get_service_icon_default;
223         account_class->save_remote_draft =
224                 modest_account_protocol_save_remote_draft_default;
225
226 }
227
228 static void
229 modest_account_protocol_instance_init (ModestAccountProtocol *obj)
230 {
231         ModestAccountProtocolPrivate *priv;
232
233         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (obj);
234
235         priv->port = 0;
236         priv->alternate_port = 0;
237         priv->account_g_type = 0;
238         priv->account_options = tny_simple_list_new ();
239         priv->custom_auth_mechs = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
240
241         priv->account_dialogs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
242 }
243
244 static gboolean
245 remove_account (const gchar *account_name, GObject *account, GObject *account_to_remove)
246 {
247         return (account == account_to_remove);
248 }
249
250 static void
251 account_dialog_weak_handler (ModestAccountProtocol *self, GObject *where_the_object_was)
252 {
253         ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
254
255         g_hash_table_foreach_remove (priv->account_dialogs, (GHRFunc) remove_account, where_the_object_was);
256 }
257
258 static gboolean
259 dialogs_remove (const gchar *account_name, GObject *account_dialog, ModestAccountProtocol *self)
260 {
261         g_object_weak_unref (account_dialog, (GWeakNotify) account_dialog_weak_handler, self);
262
263         return TRUE;
264 }
265
266 static void   
267 modest_account_protocol_finalize   (GObject *obj)
268 {
269         ModestAccountProtocol *protocol = MODEST_ACCOUNT_PROTOCOL (obj);
270         ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (protocol);
271
272         if (priv->account_dialogs) {
273                 g_hash_table_foreach_remove (priv->account_dialogs, (GHRFunc) dialogs_remove, obj);
274                 g_hash_table_destroy (priv->account_dialogs);
275         }
276
277         if (priv->account_options)
278                 g_object_unref (priv->account_options);
279         priv->account_options = NULL;
280
281         if (priv->custom_auth_mechs)
282                 g_hash_table_destroy (priv->custom_auth_mechs);
283         priv->custom_auth_mechs = NULL;
284
285         G_OBJECT_CLASS (parent_class)->finalize (obj);
286 }
287
288 static void   
289 modest_account_protocol_get_property (GObject *obj,
290                                       guint property_id,
291                                       GValue *value,
292                                       GParamSpec *pspec)
293 {
294         ModestAccountProtocol *protocol = MODEST_ACCOUNT_PROTOCOL (obj);
295         ModestAccountProtocolPrivate *priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (protocol);
296
297         switch (property_id) {
298         case PROP_PORT:
299                 g_value_set_uint (value, priv->port);
300                 break;
301         case PROP_ALTERNATE_PORT:
302                 g_value_set_uint (value, priv->alternate_port);
303                 break;
304         case PROP_ACCOUNT_G_TYPE:
305                 g_value_set_gtype (value, priv->account_g_type);
306                 break;
307         default:
308                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
309         }
310
311 }
312
313 static void   
314 modest_account_protocol_set_property (GObject *obj,
315                                       guint property_id,
316                                       const GValue *value,
317                                       GParamSpec *pspec)
318 {
319         ModestAccountProtocol *protocol = MODEST_ACCOUNT_PROTOCOL (obj);
320
321         switch (property_id) {
322         case PROP_PORT:
323                 modest_account_protocol_set_port (protocol, g_value_get_uint (value));
324                 break;
325         case PROP_ALTERNATE_PORT:
326                 modest_account_protocol_set_alternate_port (protocol, g_value_get_uint (value));
327                 break;
328         case PROP_ACCOUNT_G_TYPE:
329                 modest_account_protocol_set_account_g_type (protocol, g_value_get_gtype (value));
330                 break;
331         default:
332                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
333         }
334
335 }
336
337
338 ModestProtocol*
339 modest_account_protocol_new (const gchar *name, const gchar *display_name,
340                              guint port, guint alternate_port,
341                              GType account_g_type)
342 {
343         return g_object_new (MODEST_TYPE_ACCOUNT_PROTOCOL, 
344                              "display-name", display_name, "name", name, 
345                              "port", port, "alternate-port", alternate_port,
346                              "account-g-type", account_g_type,
347                              NULL);
348 }
349
350 guint
351 modest_account_protocol_get_port (ModestAccountProtocol *self)
352 {
353         ModestAccountProtocolPrivate *priv;
354
355         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), 0);
356
357         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
358         return priv->port;
359 }
360
361 void         
362 modest_account_protocol_set_port (ModestAccountProtocol *self,
363                                   guint port)
364 {
365         ModestAccountProtocolPrivate *priv;
366
367         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
368
369         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
370         priv->port = port;
371 }
372
373
374 guint
375 modest_account_protocol_get_alternate_port (ModestAccountProtocol *self)
376 {
377         ModestAccountProtocolPrivate *priv;
378
379         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), 0);
380
381         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
382         return priv->alternate_port;
383 }
384
385 void         
386 modest_account_protocol_set_alternate_port (ModestAccountProtocol *self,
387                                             guint alternate_port)
388 {
389         ModestAccountProtocolPrivate *priv;
390
391         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
392
393         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
394         priv->alternate_port = alternate_port;
395 }
396
397 GType
398 modest_account_protocol_get_account_g_type (ModestAccountProtocol *self)
399 {
400         ModestAccountProtocolPrivate *priv;
401
402         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), 0);
403
404         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
405         return priv->account_g_type;
406 }
407
408 TnyList *
409 modest_account_protocol_get_account_options (ModestAccountProtocol *self)
410 {
411         TnyList *result;
412         ModestAccountProtocolPrivate *priv;
413
414         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
415         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
416
417         result = tny_list_copy (priv->account_options);
418
419         return result;
420 }
421
422 void
423 modest_account_protocol_set_account_options (ModestAccountProtocol *self,
424                                              TnyList *list)
425 {
426         ModestAccountProtocolPrivate *priv;
427
428         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
429         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
430
431         if (priv->account_options) {
432                 g_object_unref (priv->account_options);
433                 priv->account_options = NULL;
434         }
435         priv->account_options = tny_list_copy (list);
436 }
437
438 gboolean
439 modest_account_protocol_has_custom_secure_auth_mech (ModestAccountProtocol *self, 
440                                                      ModestProtocolType auth_protocol_type)
441 {
442         ModestAccountProtocolPrivate *priv;
443
444         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), FALSE);
445         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
446
447         return g_hash_table_lookup_extended (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type), NULL, NULL);
448 }
449
450 const gchar *
451 modest_account_protocol_get_custom_secure_auth_mech (ModestAccountProtocol *self, 
452                                                      ModestProtocolType auth_protocol_type)
453 {
454         ModestAccountProtocolPrivate *priv;
455
456         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
457         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
458
459         return (const gchar *) g_hash_table_lookup (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type));
460 }
461
462 void
463 modest_account_protocol_set_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type, const gchar *secure_auth_mech)
464 {
465         ModestAccountProtocolPrivate *priv;
466
467         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
468         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
469
470         g_hash_table_replace (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type), g_strdup (secure_auth_mech));
471 }
472
473 void
474 modest_account_protocol_unset_custom_secure_auth_mech (ModestAccountProtocol *self, ModestProtocolType auth_protocol_type)
475 {
476         ModestAccountProtocolPrivate *priv;
477
478         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
479         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);      
480
481         g_hash_table_remove (priv->custom_auth_mechs, GINT_TO_POINTER (auth_protocol_type));
482 }
483
484
485 void         
486 modest_account_protocol_set_account_g_type (ModestAccountProtocol *self,
487                                             GType account_g_type)
488 {
489         ModestAccountProtocolPrivate *priv;
490
491         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
492
493         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
494         priv->account_g_type = account_g_type;
495 }
496
497 static TnyAccount *
498 modest_account_protocol_create_account_default (ModestAccountProtocol *self)
499 {
500         ModestAccountProtocolPrivate *priv;
501
502         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
503
504         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
505         if (priv->account_g_type > 0) {
506                 return g_object_new (priv->account_g_type, NULL);
507         } else {
508                 return NULL;
509         }
510 }
511
512 TnyAccount *
513 modest_account_protocol_create_account (ModestAccountProtocol *self)
514 {
515         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
516
517         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->create_account (self); 
518 }
519
520 /* This is a template method for getting the account settings
521    dialog. It calls create_account_settings that must be implemented
522    by subclasses and then perform several common operations with the
523    dialog */
524 ModestAccountSettingsDialog *
525 modest_account_protocol_get_account_settings_dialog (ModestAccountProtocol *self,
526                                                      const gchar *account_name)
527 {
528         ModestAccountSettingsDialog *dialog;
529         ModestAccountSettings *settings;
530         ModestAccountProtocolPrivate *priv;
531
532         priv = MODEST_ACCOUNT_PROTOCOL_GET_PRIVATE (self);
533         dialog = g_hash_table_lookup (priv->account_dialogs, account_name);
534
535         if (dialog == NULL) {
536
537                 dialog = MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->create_account_settings_dialog (self);
538         
539                 /* Load settings */
540                 settings = modest_account_mgr_load_account_settings (modest_runtime_get_account_mgr (), 
541                                                                      account_name);
542                 modest_account_settings_dialog_load_settings (dialog, settings);
543         
544                 /* Close dialog on response */
545                 g_signal_connect_swapped (dialog,
546                                           "response",
547                                           G_CALLBACK (gtk_widget_destroy),
548                                           dialog);
549
550                 g_hash_table_insert (priv->account_dialogs, g_strdup (account_name), dialog);
551                 g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) account_dialog_weak_handler, self);
552         }
553
554         return dialog;
555 }
556
557 ModestPairList*
558 modest_account_protocol_get_easysetupwizard_tabs (ModestAccountProtocol *self)
559 {
560         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_easysetupwizard_tabs (self);
561 }
562
563
564 void 
565 modest_account_protocol_save_settings (ModestAccountProtocol *self, 
566                                        ModestAccountSettingsDialog *dialog,
567                                        ModestAccountSettings *settings)
568 {
569         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_settings (self, dialog, settings);
570 }
571
572 void 
573 modest_account_protocol_save_wizard_settings (ModestAccountProtocol *self, 
574                                               GList *wizard_pages,
575                                               ModestAccountSettings *settings)
576 {
577         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_wizard_settings (self, wizard_pages, settings);
578 }
579
580 /* Default implementations */
581 static ModestAccountSettingsDialog *
582 modest_account_protocol_create_account_settings_dialog_default (ModestAccountProtocol *self)
583 {
584         return modest_default_account_settings_dialog_new ();
585 }
586
587 static ModestPairList*
588 modest_account_protocol_get_easysetupwizard_tabs_default (ModestAccountProtocol *self)
589 {
590         g_warning ("You must implement get_easysetupwizard_tabs");
591         return NULL;
592 }
593
594 static void 
595 modest_account_protocol_save_settings_default (ModestAccountProtocol *self, 
596                                                ModestAccountSettingsDialog *dialog,
597                                                ModestAccountSettings *settings)
598 {
599         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
600         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
601         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
602
603         g_warning ("You must implement save_settings");
604 }
605
606 static void 
607 modest_account_protocol_save_wizard_settings_default (ModestAccountProtocol *self, 
608                                                       GList *wizard_pages,
609                                                       ModestAccountSettings *settings)
610 {
611         g_return_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self));
612         g_return_if_fail (wizard_pages);
613         g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
614
615         g_warning ("You must implement save_wizard_settings");
616 }
617
618 static ModestWizardDialogResponseOverrideFunc
619 modest_account_protocol_get_wizard_response_override_default (ModestAccountProtocol *self)
620 {
621         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
622
623         return NULL;
624 }
625
626 ModestWizardDialogResponseOverrideFunc
627 modest_account_protocol_get_wizard_response_override (ModestAccountProtocol *self)
628 {
629         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
630
631         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_wizard_response_override (self);   
632 }
633
634 static gboolean
635 modest_account_protocol_is_supported_default (ModestAccountProtocol *self)
636 {
637         return TRUE;
638 }
639
640 gboolean
641 modest_account_protocol_is_supported (ModestAccountProtocol *self)
642 {
643         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->is_supported (self);
644 }
645
646 static void
647 modest_account_protocol_check_support_default (ModestAccountProtocol *self,
648                                                ModestAccountProtocolCheckSupportFunc func,
649                                                gpointer userdata)
650 {
651         if (func)
652                 func (self, TRUE, userdata);
653 }
654
655 void
656 modest_account_protocol_check_support (ModestAccountProtocol *self,
657                                        ModestAccountProtocolCheckSupportFunc func,
658                                        gpointer userdata)
659 {
660         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->check_support (self, func, userdata);
661 }
662
663 static void
664 modest_account_protocol_cancel_check_support_default (ModestAccountProtocol *self)
665 {
666         return;
667 }
668
669 void
670 modest_account_protocol_cancel_check_support (ModestAccountProtocol *self)
671 {
672         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->cancel_check_support (self);
673 }
674
675 gchar *
676 modest_account_protocol_get_from (ModestAccountProtocol *self,
677                                   const gchar *account_id,
678                                   const gchar *mailbox)
679 {
680         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from (self, account_id, mailbox);
681 }
682 static gchar *
683 modest_account_protocol_get_from_default (ModestAccountProtocol *self,
684                                           const gchar *account_id,
685                                           const gchar *mailbox)
686 {
687         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
688
689         return NULL;
690 }
691
692 ModestPairList *
693 modest_account_protocol_get_from_list (ModestAccountProtocol *self,
694                                        const gchar *account_id)
695 {
696         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_from_list (self, account_id);
697 }
698 static ModestPairList *
699 modest_account_protocol_get_from_list_default (ModestAccountProtocol *self,
700                                                const gchar *account_id)
701 {
702         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
703
704         return NULL;
705 }
706
707 gchar *
708 modest_account_protocol_get_signature (ModestAccountProtocol *self,
709                                        const gchar *account_id,
710                                        const gchar *mailbox,
711                                        gboolean *has_signature)
712 {
713         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_signature (self, account_id, mailbox, has_signature);
714 }
715
716 static gchar *
717 modest_account_protocol_get_signature_default (ModestAccountProtocol *self,
718                                                const gchar *account_id,
719                                                const gchar *mailbox,
720                                                gboolean *has_signature)
721 {
722         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
723         if (has_signature)
724                 *has_signature = FALSE;
725
726         return NULL;
727 }
728
729 const GdkPixbuf*
730 modest_account_protocol_get_icon (ModestAccountProtocol *self,
731                                   ModestAccountProtocolIconType icon_type,
732                                   GObject *object,
733                                   guint icon_size)
734 {
735         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_icon (self, icon_type, object, icon_size);
736 }
737
738 static const GdkPixbuf * 
739 modest_account_protocol_get_icon_default (ModestAccountProtocol *self, ModestAccountProtocolIconType icon_type, 
740                                           GObject *object, guint icon_size)
741 {
742         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
743
744         return NULL;
745 }
746
747 gchar *
748 modest_account_protocol_get_service_name (ModestAccountProtocol *self,
749                                           const gchar *account_id,
750                                           const gchar *mailbox)
751 {
752         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_name (self, account_id, mailbox);
753 }
754
755 static gchar *
756 modest_account_protocol_get_service_name_default (ModestAccountProtocol *self,
757                                                   const gchar *account_id,
758                                                   const gchar *mailbox)
759 {
760         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
761
762         return NULL;
763 }
764
765 const GdkPixbuf *
766 modest_account_protocol_get_service_icon (ModestAccountProtocol *self,
767                                           const gchar *account_id,
768                                           const gchar *mailbox,
769                                           guint icon_size)
770 {
771         return MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->get_service_icon (self, account_id, mailbox, icon_size);
772 }
773
774 static const GdkPixbuf *
775 modest_account_protocol_get_service_icon_default (ModestAccountProtocol *self,
776                                                   const gchar *account_id,
777                                                   const gchar *mailbox,
778                                                   guint icon_size)
779 {
780         g_return_val_if_fail (MODEST_IS_ACCOUNT_PROTOCOL (self), NULL);
781
782         return NULL;
783 }
784
785 void
786 modest_account_protocol_save_remote_draft (ModestAccountProtocol *self,
787                                            const gchar *account_id,
788                                            TnyMsg *new_msg,
789                                            TnyMsg *old_msg,
790                                            ModestAccountProtocolSaveRemoteDraftCallback callback,
791                                            gpointer userdata)
792 {
793         MODEST_ACCOUNT_PROTOCOL_GET_CLASS (self)->save_remote_draft (self, account_id, 
794                                                                      new_msg, old_msg,
795                                                                      callback, userdata);
796 }
797
798 static void
799 modest_account_protocol_save_remote_draft_default (ModestAccountProtocol *self,
800                                                    const gchar *account_id,
801                                                    TnyMsg *new_msg,
802                                                    TnyMsg *old_msg,
803                                                    ModestAccountProtocolSaveRemoteDraftCallback callback,
804                                                    gpointer userdata)
805 {
806         if (callback) {
807                 callback (self, NULL, account_id, NULL, new_msg, old_msg, userdata);
808         }
809 }
810