964269d4ea47573e3a3ccdd8d81d67eab10c6e49
[modest] / src / modest-tny-account-store.c
1 /* Copyright (c) 2006, 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 <string.h>
31 #include <glib/gi18n.h>
32
33 #include <tny-account.h>
34 #include <tny-account-store.h>
35 #include <tny-store-account.h>
36 #include <tny-transport-account.h>
37 #include <tny-device.h>
38 #include <tny-account-store.h>
39 #include <tny-camel-transport-account.h>
40 #include <tny-camel-imap-store-account.h>
41 #include <tny-camel-pop-store-account.h>
42 #include <modest-marshal.h>
43 #include <modest-protocol-info.h>
44 #include <modest-local-folder-info.h>
45
46 #include <modest-account-mgr.h>
47 #include <modest-account-mgr-helpers.h>
48
49 #include "modest-tny-account-store.h"
50 #include "modest-tny-platform-factory.h"
51 #include <tny-gtk-lockable.h>
52 #include <camel/camel.h>
53
54 /* 'private'/'protected' functions */
55 static void modest_tny_account_store_class_init   (ModestTnyAccountStoreClass *klass);
56 //static void modest_tny_account_store_init         (ModestTnyAccountStore *obj);
57 static void modest_tny_account_store_finalize     (GObject *obj);
58
59 /* implementations for tny-account-store-iface */
60 static void    modest_tny_account_store_instance_init (ModestTnyAccountStore *obj);
61 static void    modest_tny_account_store_init                     (gpointer g, gpointer iface_data);
62
63
64 /* list my signals */
65 enum {
66         PASSWORD_REQUESTED_SIGNAL,
67         ACCOUNT_UPDATE_SIGNAL,
68         LAST_SIGNAL
69 };
70
71 typedef struct _ModestTnyAccountStorePrivate ModestTnyAccountStorePrivate;
72 struct _ModestTnyAccountStorePrivate {
73
74         gchar              *cache_dir;
75         
76         GHashTable         *password_hash;
77         TnyDevice          *device;
78         TnyPlatformFactory *platform_fact;
79         TnySessionCamel    *tny_session_camel;
80 };
81
82 #define MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
83                                                       MODEST_TYPE_TNY_ACCOUNT_STORE, \
84                                                       ModestTnyAccountStorePrivate))
85 /* globals */
86 static GObjectClass *parent_class = NULL;
87
88 static guint signals[LAST_SIGNAL] = {0};
89
90 GType
91 modest_tny_account_store_get_type (void)
92 {
93         static GType my_type = 0;
94
95         if (!my_type) {
96                 static const GTypeInfo my_info = {
97                         sizeof(ModestTnyAccountStoreClass),
98                         NULL,           /* base init */
99                         NULL,           /* base finalize */
100                         (GClassInitFunc) modest_tny_account_store_class_init,
101                         NULL,           /* class finalize */
102                         NULL,           /* class data */
103                         sizeof(ModestTnyAccountStore),
104                         0,              /* n_preallocs */
105                         (GInstanceInitFunc) modest_tny_account_store_instance_init,
106                         NULL
107                 };
108
109                 static const GInterfaceInfo iface_info = {
110                         (GInterfaceInitFunc) modest_tny_account_store_init,
111                         NULL,         /* interface_finalize */
112                         NULL          /* interface_data */
113                 };
114                 /* hack hack */
115                 my_type = g_type_register_static (G_TYPE_OBJECT,
116                                                   "ModestTnyAccountStore",
117                                                   &my_info, 0);
118                 g_type_add_interface_static (my_type, TNY_TYPE_ACCOUNT_STORE,
119                                              &iface_info);
120         }
121         return my_type;
122 }
123
124 static void
125 modest_tny_account_store_class_init (ModestTnyAccountStoreClass *klass)
126 {
127         GObjectClass *gobject_class;
128         gobject_class = (GObjectClass*) klass;
129
130         parent_class            = g_type_class_peek_parent (klass);
131         gobject_class->finalize = modest_tny_account_store_finalize;
132
133         g_type_class_add_private (gobject_class,
134                                   sizeof(ModestTnyAccountStorePrivate));
135
136         signals[PASSWORD_REQUESTED_SIGNAL] =
137                 g_signal_new ("password_requested",
138                               G_TYPE_FROM_CLASS (gobject_class),
139                               G_SIGNAL_RUN_FIRST,
140                               G_STRUCT_OFFSET(ModestTnyAccountStoreClass, password_requested),
141                               NULL, NULL,
142                               modest_marshal_VOID__STRING_POINTER_POINTER_POINTER,
143                               G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
144         
145         signals[ACCOUNT_UPDATE_SIGNAL] =
146                 g_signal_new ("account_update",
147                               G_TYPE_FROM_CLASS (gobject_class),
148                               G_SIGNAL_RUN_FIRST,
149                               G_STRUCT_OFFSET(ModestTnyAccountStoreClass, account_update),
150                               NULL, NULL,
151                               g_cclosure_marshal_VOID__STRING,
152                               G_TYPE_NONE, 1, G_TYPE_STRING);
153         
154 }
155
156 static void
157 modest_tny_account_store_instance_init (ModestTnyAccountStore *obj)
158 {
159         ModestTnyAccountStorePrivate *priv =
160                 MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
161
162         priv->cache_dir              = NULL;
163         
164         priv->platform_fact          = NULL;
165         priv->tny_session_camel      = NULL;
166         priv->device                 = NULL;
167         
168         priv->password_hash          = g_hash_table_new_full (g_str_hash, g_str_equal,
169                                                               g_free, g_free);
170 }
171
172
173 static void
174 on_account_removed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean server_account,
175                     gpointer user_data)
176 {
177         ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
178
179         g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
180                        account);
181         
182 }
183
184
185 static void
186 on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean server_account,
187                     const gchar *key, gpointer user_data)
188 {
189         ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
190         
191         g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
192                        account);
193 }
194
195
196 static ModestTnyAccountStore*
197 get_account_store_for_account (TnyAccount *account)
198 {
199         return MODEST_TNY_ACCOUNT_STORE(g_object_get_data (G_OBJECT(account), "account_store"));
200 }
201
202
203
204 static void
205 set_account_store_for_account (TnyAccount *account, ModestTnyAccountStore *store)
206 {
207         g_object_set_data (G_OBJECT(account), "account_store", (gpointer)store);
208 }
209
210 static gchar*
211 get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
212 {
213         const gchar *key;
214         ModestAccountMgr *account_mgr;
215         const TnyAccountStore *account_store;
216         ModestTnyAccountStore *self;
217         ModestTnyAccountStorePrivate *priv;
218         gchar *pwd = NULL;
219         gpointer pwd_ptr;
220         gboolean already_asked;
221
222         
223         key           = tny_account_get_id (account);
224         account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
225
226         self = MODEST_TNY_ACCOUNT_STORE (account_store);
227         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
228         
229         account_mgr = modest_tny_platform_factory_get_account_mgr_instance
230                 (MODEST_TNY_PLATFORM_FACTORY(priv->platform_fact));
231         
232         /* is it in the hash? if it's already there, it must be wrong... */
233         pwd_ptr = (gpointer)&pwd; /* pwd_ptr so the compiler does not complained about
234                                    * type-punned ptrs...*/
235         already_asked = g_hash_table_lookup_extended (priv->password_hash,
236                                                       key,
237                                                       NULL,
238                                                       (gpointer*)&pwd_ptr);
239
240         /* if the password is not already there, try ModestConf */
241         if (!already_asked) {
242                 pwd  = modest_account_mgr_get_string (account_mgr,
243                                                       key, MODEST_ACCOUNT_PASSWORD,
244                                                       TRUE, NULL);
245                 g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup (pwd));
246         }
247
248         /* if it was already asked, it must have been wrong, so ask again */
249         if (already_asked || !pwd || strlen(pwd) == 0) {
250
251                 /* we don't have it yet. we emit a signal to get the password somewhere */
252                 const gchar* name = tny_account_get_name (account);
253                 gboolean remember;
254                 pwd = NULL;
255
256                 g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0,
257                                name, &pwd, cancel, &remember);
258
259                 if (!*cancel) {
260                         if (remember)
261                                 modest_account_mgr_set_string (account_mgr,
262                                                                key, MODEST_ACCOUNT_PASSWORD,
263                                                                pwd,
264                                                                TRUE, NULL);
265                         /* We need to dup the string even knowing that
266                            it's already a dup of the contents of an
267                            entry, because it if it's wrong, then camel
268                            will free it */
269                         g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup(pwd));
270                 } else {
271                         g_hash_table_remove (priv->password_hash, key);
272                         g_free (pwd);
273                         pwd = NULL;
274                 }
275         } else
276                 *cancel = FALSE;
277
278         return pwd;
279 }
280
281
282 static void
283 forget_password (TnyAccount *account) {
284
285         ModestTnyAccountStore *self;
286         ModestTnyAccountStorePrivate *priv;
287         const TnyAccountStore *account_store;
288         gchar *pwd;
289         const gchar *key;
290         ModestAccountMgr *account_mgr;
291         
292         account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
293         self = MODEST_TNY_ACCOUNT_STORE (account_store);
294         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
295         key  = tny_account_get_id (account);
296
297         /* Do not remove the key, this will allow us to detect that we
298            have already asked for it at least once */
299         pwd = g_hash_table_lookup (priv->password_hash, key);
300         if (pwd) {
301                 memset (pwd, 0, strlen (pwd));
302                 g_hash_table_insert (priv->password_hash, g_strdup (key), NULL);
303         }
304
305         account_mgr = modest_tny_platform_factory_get_account_mgr_instance
306                 (MODEST_TNY_PLATFORM_FACTORY(priv->platform_fact));
307
308         /* Remove from configuration system */
309         modest_account_mgr_unset (account_mgr,
310                                   key, MODEST_ACCOUNT_PASSWORD,
311                                   TRUE, NULL);
312 }
313
314
315
316 /* instantiate the correct tny account subclass */
317 static TnyAccount*
318 tny_account_for_proto (ModestProtocol proto) 
319 {
320         ModestProtocolType type;        
321         TnyAccount *tny_account = NULL;
322         
323         type  = modest_protocol_info_get_protocol_type (proto);
324         
325         if (type == MODEST_PROTOCOL_TYPE_TRANSPORT) 
326                 tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ());
327         else if (proto == MODEST_PROTOCOL_STORE_POP)
328                 tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ());
329         else if (proto == MODEST_PROTOCOL_STORE_IMAP)
330                 tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ());
331         else 
332                 g_return_val_if_reached (NULL);
333         
334         if (tny_account)
335                 tny_account_set_proto (tny_account,
336                                        modest_protocol_info_get_protocol_name(proto));
337         else
338                 g_printerr ("modest: could not get tny account for %d\n",
339                             proto);    
340         return tny_account;
341 }
342
343
344 /* create a tnyaccount for the server account connected to the account with name 'key'
345  */
346 static TnyAccount*
347 get_tny_account_from_server_account (ModestTnyAccountStore *self,
348                                      ModestServerAccountData *account_data,
349                                      ModestProtocolType modest_type)
350 {
351         TnyAccount *tny_account;
352         ModestTnyAccountStorePrivate *priv;
353                 
354         g_return_val_if_fail (self, NULL);
355         g_return_val_if_fail (account_data, NULL);
356
357         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
358         
359         /* proto */
360         if (account_data->proto == MODEST_PROTOCOL_UNKNOWN) {
361                 g_printerr ("modest: '%s' does not provide a protocol\n",
362                             account_data->account_name);
363                 return NULL;
364         }
365                 
366         tny_account = tny_account_for_proto (account_data->proto);
367         if (!tny_account) {
368                 g_printerr ("modest: could not create tny account for '%s'\n",
369                             account_data->account_name);
370                 return NULL;
371         }
372         
373         set_account_store_for_account (TNY_ACCOUNT(tny_account), self);
374         tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),  /* session */
375                                        priv->tny_session_camel);        
376         tny_account_set_id            (tny_account, account_data->account_name); /* id */
377
378         if (account_data->hostname)
379                 tny_account_set_hostname (tny_account, account_data->hostname);
380
381         if (account_data->username) 
382                 tny_account_set_user (tny_account, account_data->username);
383
384         tny_account_set_pass_func (tny_account, get_password);
385         tny_account_set_forget_pass_func (tny_account, forget_password);
386
387         return tny_account;
388 }
389
390
391
392 static void
393 modest_tny_account_store_finalize (GObject *obj)
394 {
395         ModestTnyAccountStore *self        = MODEST_TNY_ACCOUNT_STORE(obj);
396         ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
397
398         if (priv->tny_session_camel) {
399                 camel_object_unref (CAMEL_OBJECT(priv->tny_session_camel));
400                 priv->tny_session_camel = NULL;
401         }
402
403         g_free (priv->cache_dir);
404         priv->cache_dir = NULL;
405
406         if (priv->device) {
407                 g_object_unref (priv->device);
408                 priv->device = NULL;
409         }
410         
411         if (priv->password_hash) {
412                 g_hash_table_destroy (priv->password_hash);
413                 priv->password_hash = NULL;
414         }
415         
416         G_OBJECT_CLASS(parent_class)->finalize (obj);
417 }
418
419
420 ModestTnyAccountStore*
421 modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
422
423         GObject *obj;
424         ModestTnyAccountStorePrivate *priv;
425         TnyPlatformFactory *pfact;
426         
427         g_return_val_if_fail (account_mgr, NULL);
428
429         obj  = G_OBJECT(g_object_new(MODEST_TYPE_TNY_ACCOUNT_STORE, NULL));
430         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
431
432         g_signal_connect (G_OBJECT(account_mgr), "account_changed",
433                                        G_CALLBACK (on_account_changed), obj);
434         g_signal_connect (G_OBJECT(account_mgr), "account_removed",
435                                        G_CALLBACK (on_account_removed), obj);
436
437         pfact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance());
438         if (!pfact) {
439                 g_printerr ("modest: cannot get platform factory instance\n");
440                 g_object_unref (obj);
441                 return NULL;
442         } else
443                 priv->platform_fact = pfact;
444         
445         priv->tny_session_camel = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
446         if (!priv->tny_session_camel) {
447                 g_printerr ("modest: cannot create TnySessionCamel instance\n");
448                 g_object_unref (obj);
449                 return NULL;
450         }
451
452         tny_session_camel_set_ui_locker (priv->tny_session_camel, tny_gtk_lockable_new ());
453
454         return MODEST_TNY_ACCOUNT_STORE(obj);
455 }
456
457 static void
458 modest_tny_account_store_add_store_account  (TnyAccountStore *self,
459                                              TnyStoreAccount *account)
460 {
461         /* we should not need this...*/
462         g_printerr ("modest: add_store_account_func not implemented\n");
463 }
464
465
466 static void
467 modest_tny_account_store_add_transport_account  (TnyAccountStore *self,
468                                                  TnyTransportAccount *account)
469 {       
470         /* we should not need this...*/
471         g_printerr ("modest: add_transport_account_func not implemented\n");
472 }
473
474
475 /* create a pseudo-account for our local folders */
476 static TnyAccount*
477 get_local_folder_account (ModestTnyAccountStore *self)
478 {
479         TnyStoreAccount *tny_account;
480         CamelURL *url;
481         gchar *maildir, *url_string;
482         ModestTnyAccountStorePrivate *priv;
483
484         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
485         
486         tny_account = tny_camel_store_account_new ();
487         if (!tny_account) {
488                 g_printerr ("modest: cannot create account for local folders");
489                 return NULL;
490         }
491
492         maildir = modest_local_folder_info_get_maildir_path ();
493         
494         url = camel_url_new ("maildir:", NULL);
495         camel_url_set_path (url, maildir);
496
497         url_string = camel_url_to_string (url, 0);
498         tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
499         
500         tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),
501                                        priv->tny_session_camel);
502         tny_account_set_name (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME); 
503         tny_account_set_id (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME); 
504         
505         camel_url_free (url);
506         g_free (maildir);
507         g_free (url_string);
508
509         return TNY_ACCOUNT(tny_account);
510 }
511
512
513 static TnyAccount*
514 get_tny_account_from_account (ModestTnyAccountStore *self, ModestAccountData *account_data,
515                               TnyGetAccountsRequestType type) 
516 {
517         TnyAccount *tny_account = NULL;
518         ModestServerAccountData *server_account = NULL;
519
520         if (type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS && account_data->store_account)
521                 server_account = account_data->store_account;
522         else if (type == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS && account_data->transport_account)
523                 server_account = account_data->transport_account;
524         
525         if (!server_account) {
526                 g_printerr ("modest: no %s account defined for '%s'\n",
527                             type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS ? "store" : "transport",
528                             account_data->display_name);
529                 return NULL;
530         }
531         
532         tny_account = get_tny_account_from_server_account (self, server_account, type);
533         if (!tny_account) { 
534                 g_printerr ("modest: failed to create tny account for %s\n",
535                             account_data->account_name);
536                 return NULL;
537         }
538         
539         if (account_data->display_name)
540                 tny_account_set_name (tny_account, account_data->display_name); 
541
542         return tny_account;
543 }
544
545
546 static void
547 modest_tny_account_store_get_accounts  (TnyAccountStore *iface, TnyList *list,
548                                         TnyGetAccountsRequestType type)
549 {
550         ModestTnyAccountStore        *self;
551         ModestTnyAccountStorePrivate *priv;
552         GSList                       *accounts, *cursor;
553         ModestAccountMgr             *account_mgr; 
554         TnyAccount                   *local_folder_account;
555         
556         g_return_if_fail (iface);
557         g_return_if_fail (TNY_IS_LIST(list));
558
559         self        = MODEST_TNY_ACCOUNT_STORE(iface);
560         priv        = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
561         account_mgr = modest_tny_platform_factory_get_account_mgr_instance
562                 (MODEST_TNY_PLATFORM_FACTORY(priv->platform_fact));
563         
564         if (type == TNY_ACCOUNT_STORE_BOTH) {
565                 modest_tny_account_store_get_accounts (iface, list, TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
566                 modest_tny_account_store_get_accounts (iface, list, TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
567         }
568         
569         accounts = modest_account_mgr_account_names (account_mgr, NULL); 
570         for (cursor = accounts; cursor; cursor = cursor->next) {
571                 TnyAccount *tny_account;
572                 ModestAccountData *account_data =
573                         modest_account_mgr_get_account_data (account_mgr, 
574                                                              (gchar*)cursor->data);
575                 if (account_data && account_data->enabled) {
576                         tny_account = get_tny_account_from_account (self, account_data, type);
577                         if (tny_account)
578                                 tny_list_prepend (list, G_OBJECT(tny_account));
579                 }
580                 g_free (cursor->data);
581                 modest_account_mgr_free_account_data (account_mgr, account_data);
582         }
583         g_slist_free (accounts);
584
585         /* also, add the local folder pseudo-account */
586         local_folder_account = get_local_folder_account (MODEST_TNY_ACCOUNT_STORE(self));
587         if (!local_folder_account) 
588                 g_printerr ("modest: failed to add local folders account\n");
589         else
590                 tny_list_prepend (list, G_OBJECT(local_folder_account));
591         
592         tny_session_camel_set_account_store (priv->tny_session_camel, iface);
593 }
594
595 static const gchar*
596 modest_tny_account_store_get_cache_dir (TnyAccountStore *self)
597 {
598         ModestTnyAccountStorePrivate *priv;
599         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
600         
601         if (!priv->cache_dir)
602                 priv->cache_dir = g_build_filename (g_get_home_dir(), 
603                                                     MODEST_DIR,
604                                                     MODEST_CACHE_DIR,
605                                                     "cache", NULL);
606         return priv->cache_dir;
607 }
608
609
610 /*
611  * callers need to unref
612  */
613 static TnyDevice*
614 modest_tny_account_store_get_device (TnyAccountStore *self)
615 {
616         ModestTnyAccountStorePrivate *priv;
617
618         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
619
620         if (!priv->device) 
621                 priv->device = tny_platform_factory_new_device (priv->platform_fact);
622         
623         return g_object_ref (G_OBJECT(priv->device));
624 }
625
626
627
628 static gboolean
629 modest_tny_account_store_alert (TnyAccountStore *self, TnyAlertType type,
630                                 const gchar *prompt)
631 {
632         g_printerr ("modest: alert_func not implemented (%d, %s)\n",
633                     type, prompt);
634         return TRUE;
635 }
636
637
638 static void
639 modest_tny_account_store_init (gpointer g, gpointer iface_data)
640 {
641         TnyAccountStoreIface *klass;
642
643         g_return_if_fail (g);
644
645         klass = (TnyAccountStoreIface *)g;
646
647         klass->get_accounts_func =
648                 modest_tny_account_store_get_accounts;
649         klass->add_transport_account_func =
650                 modest_tny_account_store_add_transport_account;
651         klass->add_store_account_func =
652                 modest_tny_account_store_add_store_account;
653         klass->get_cache_dir_func =
654                 modest_tny_account_store_get_cache_dir;
655         klass->get_device_func =
656                 modest_tny_account_store_get_device;
657         klass->alert_func =
658                 modest_tny_account_store_alert;
659 }
660
661 void
662 modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *self,
663                                             ModestTnyGetPassFunc func)
664 {
665         g_message (__FUNCTION__);
666         return; /* not implemented, we use signals */
667 }
668
669
670
671 TnySessionCamel*
672 tny_account_store_get_session    (TnyAccountStore *self)
673 {
674         g_return_val_if_fail (self, NULL);      
675         return MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self)->tny_session_camel;
676 }