* all:
[modest] / src / modest-tny-account-store.c
index 7455bc5..a3d588f 100644 (file)
@@ -41,6 +41,7 @@
 #include <tny-camel-pop-store-account.h>
 #include <modest-marshal.h>
 #include <modest-protocol-info.h>
+#include <modest-local-folder-info.h>
 #include "modest-account-mgr.h"
 #include "modest-tny-account-store.h"
 #include "modest-tny-platform-factory.h"
@@ -54,14 +55,9 @@ static void modest_tny_account_store_finalize     (GObject *obj);
 
 /* implementations for tny-account-store-iface */
 static void    modest_tny_account_store_instance_init (ModestTnyAccountStore *obj);
-
 static void    modest_tny_account_store_init                     (gpointer g, gpointer iface_data);
-static void    modest_tny_account_store_add_store_account       (TnyAccountStore *self,
-                                                                TnyStoreAccount *account);
-static void    modest_tny_account_store_add_transport_account   (TnyAccountStore *self,
-                                                                TnyTransportAccount *account);
-static void    modest_tny_account_store_get_accounts            (TnyAccountStore *iface, TnyList *list,
-                                                                TnyGetAccountsRequestType type);
+
+
 /* list my signals */
 enum {
        PASSWORD_REQUESTED_SIGNAL,
@@ -71,7 +67,9 @@ enum {
 
 typedef struct _ModestTnyAccountStorePrivate ModestTnyAccountStorePrivate;
 struct _ModestTnyAccountStorePrivate {
+
        gchar              *cache_dir;
+       
        GHashTable         *password_hash;
        TnyDevice          *device;
        TnyPlatformFactory *platform_fact;
@@ -159,6 +157,7 @@ modest_tny_account_store_instance_init (ModestTnyAccountStore *obj)
                MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
 
        priv->cache_dir              = NULL;
+       
        priv->platform_fact          = NULL;
        priv->tny_session_camel      = NULL;
        priv->device                 = NULL;
@@ -440,68 +439,59 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
        return MODEST_TNY_ACCOUNT_STORE(obj);
 }
 
-
-static gboolean
-add_account  (TnyAccountStore *self, TnyAccount *account) {
-
-       ModestTnyAccountStore *account_store;
-       ModestTnyAccountStorePrivate *priv;
-       ModestAccountMgr *account_mgr;  
-       const gchar *account_name;
-       const gchar *hostname, *username, *proto;
-
-       g_return_val_if_fail (self, FALSE);
-       g_return_val_if_fail (account, FALSE);
-
-       account_store  = MODEST_TNY_ACCOUNT_STORE(self);
-       priv           = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-       account_mgr    = modest_tny_platform_factory_get_account_mgr_instance
-                           (MODEST_TNY_PLATFORM_FACTORY(priv->platform_fact));
-       
-       
-       account_name   = tny_account_get_id(account);
-       if (!account_name) {
-               g_printerr ("modest: failed to retrieve account name\n");
-               return FALSE;
-       }
-
-       hostname =  tny_account_get_hostname(account);
-       username =  tny_account_get_user(account);
-       proto    =  tny_account_get_proto(account);
-
-       return modest_account_mgr_add_server_account (account_mgr,
-                                                     account_name,
-                                                     hostname, username, NULL,
-                                                     modest_protocol_info_get_protocol(proto));
-}
-
-
 static void
 modest_tny_account_store_add_store_account  (TnyAccountStore *self,
                                             TnyStoreAccount *account)
 {
-       ModestTnyAccountStorePrivate *priv;
-
-       priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-       tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(account),
-                                      priv->tny_session_camel);
-       
-       if (!add_account (self, TNY_ACCOUNT(account)))
-               g_printerr ("modest: failed to add store account\n");
+       /* we should not need this...*/
+       g_printerr ("modest: add_store_account_func not implemented\n");
 }
 
 
 static void
 modest_tny_account_store_add_transport_account  (TnyAccountStore *self,
                                                 TnyTransportAccount *account)
+{      
+       /* we should not need this...*/
+       g_printerr ("modest: add_transport_account_func not implemented\n");
+}
+
+
+/* create a pseudo-account for our local folders */
+static TnyAccount*
+get_local_folder_account (ModestTnyAccountStore *self)
 {
+       TnyStoreAccount *tny_account;
+       CamelURL *url;
+       gchar *maildir, *url_string;
        ModestTnyAccountStorePrivate *priv;
-       
+
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-       tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(account),
-                                      priv->tny_session_camel);        
-       if (!add_account (self, TNY_ACCOUNT(account)))
-               g_printerr ("modest: failed to add transport account\n");
+       
+       tny_account = tny_camel_store_account_new ();
+       if (!tny_account) {
+               g_printerr ("modest: cannot create account for local folders");
+               return NULL;
+       }
+
+       maildir = modest_local_folder_info_get_maildir_path ();
+       
+       url = camel_url_new ("maildir:", NULL);
+       camel_url_set_path (url, maildir);
+
+       url_string = camel_url_to_string (url, 0);
+       tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
+
+       tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),
+                                      priv->tny_session_camel);
+
+       tny_account_set_name (TNY_ACCOUNT(tny_account), _("Local folders")); 
+                             
+       camel_url_free (url);
+       g_free (maildir);
+       g_free (url_string);
+
+       return TNY_ACCOUNT(tny_account);
 }
 
 
@@ -548,6 +538,7 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface, TnyList *list,
        ModestTnyAccountStorePrivate *priv;
        GSList                       *accounts, *cursor;
        ModestAccountMgr             *account_mgr; 
+       TnyAccount                   *local_folder_account;
        
        g_return_if_fail (iface);
        g_return_if_fail (TNY_IS_LIST(list));
@@ -577,14 +568,17 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface, TnyList *list,
                modest_account_mgr_free_account_data (account_mgr, account_data);
        }
        g_slist_free (accounts);
+
+       /* also, add the local folder pseudo-account */
+       local_folder_account = get_local_folder_account (MODEST_TNY_ACCOUNT_STORE(self));
+       if (!local_folder_account) 
+               g_printerr ("modest: failed to add local folders account\n");
+       else
+               tny_list_prepend (list, G_OBJECT(local_folder_account));
+       
        tny_session_camel_set_account_store (priv->tny_session_camel, iface);
 }
 
-
-/*
- * the cache dir will be ~/.modest/cache
- * might want to change this in a simple #define...
- */
 static const gchar*
 modest_tny_account_store_get_cache_dir (TnyAccountStore *self)
 {
@@ -592,7 +586,9 @@ modest_tny_account_store_get_cache_dir (TnyAccountStore *self)
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
        
        if (!priv->cache_dir)
-               priv->cache_dir = g_build_filename (g_get_home_dir(), ".modest",
+               priv->cache_dir = g_build_filename (g_get_home_dir(), 
+                                                   MODEST_DIR,
+                                                   MODEST_CACHE_DIR,
                                                    "cache", NULL);
        return priv->cache_dir;
 }
@@ -620,7 +616,8 @@ static gboolean
 modest_tny_account_store_alert (TnyAccountStore *self, TnyAlertType type,
                                const gchar *prompt)
 {
-       g_printerr ("modest: alert [%d]: %s", type, prompt);
+       g_printerr ("modest: alert_func not implemented (%d, %s)\n",
+                   type, prompt);
        return TRUE;
 }
 
@@ -652,11 +649,12 @@ void
 modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *self,
                                            ModestTnyGetPassFunc func)
 {
-       g_warning (__FUNCTION__);
+       g_message (__FUNCTION__);
        return; /* not implemented, we use signals */
 }
 
 
+
 TnySessionCamel*
 tny_account_store_get_session    (TnyAccountStore *self)
 {