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