}
-
-TnyAccount*
-modest_account_mgr_get_tny_account (ModestAccountMgr *self, const gchar* account_name,
- TnyAccountType type)
-{
- TnyAccount *account = NULL;
- TnyList *accounts;
- TnyIterator *iter;
- gchar *server_account;
- const gchar *conf_key;
- TnyGetAccountsRequestType request_type; /* really confusing.... */
-
- g_return_val_if_fail (self, NULL);
- g_return_val_if_fail (account_name, NULL);
-
- switch (type) {
- case TNY_ACCOUNT_TYPE_STORE:
- conf_key = MODEST_ACCOUNT_STORE_ACCOUNT;
- request_type = TNY_ACCOUNT_STORE_STORE_ACCOUNTS;
- break;
- case TNY_ACCOUNT_TYPE_TRANSPORT:
- conf_key = MODEST_ACCOUNT_TRANSPORT_ACCOUNT;
- request_type = TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS;
- break;
- default:
- g_return_val_if_reached (NULL);
- }
-
- server_account = modest_account_mgr_get_string (self, account_name, conf_key, FALSE, NULL);
- if (!server_account) {
- g_printerr ("modest: no %s account specified for %s\n",
- type == TNY_ACCOUNT_TYPE_TRANSPORT ? "transport" : "store", account_name);
- return NULL;
- }
-
- accounts = tny_simple_list_new ();
- tny_account_store_get_accounts (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()),
- accounts, request_type);
- iter = tny_list_create_iterator (accounts);
- while (tny_iterator_is_done (iter)) {
- account = TNY_ACCOUNT(tny_iterator_get_current(iter));
- if (strcmp (tny_account_get_id (account), server_account) == 0)
- break;
- g_object_unref (G_OBJECT(account));
- }
-
- g_object_unref (G_OBJECT(iter));
- g_object_unref (G_OBJECT(accounts));
-
- if (!account)
- g_printerr ("modest: no tny %s account found for %s\n",
- type == TNY_ACCOUNT_TYPE_TRANSPORT ? "transport" : "store", account_name);
- else {
- /* sanity check */
- if ((type == TNY_ACCOUNT_TYPE_TRANSPORT && !TNY_IS_TRANSPORT_ACCOUNT(account)) ||
- (type == TNY_ACCOUNT_TYPE_STORE && !TNY_IS_STORE_ACCOUNT(account))) {
- g_printerr ("modest: tny %s acccount found for %s, but was expecting %s account\n",
- type == TNY_ACCOUNT_TYPE_TRANSPORT ? "transport" : "store", account_name,
- type == TNY_ACCOUNT_TYPE_TRANSPORT ? "store" : "transport");
- g_object_unref (G_OBJECT(account));
- account = NULL;
- }
- }
- return account;
-}
-
-
gchar*
modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name)
{
G_BEGIN_DECLS
typedef struct {
- TnyAccount *tny_account;
gchar *account_name;
gchar *hostname;
gchar *username;
void modest_account_mgr_free_account_data (ModestAccountMgr *self,
ModestAccountData *data);
-
-
/**
* modest_account_mgr_set_enabled
* @self: a ModestAccountMgr instance
gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
-
-/**
- * modest_account_mgr_get_tny_account:
- * @self: a #ModestAccountMgr instance
- * @name: the account name
- * @type: the #TnyAccountType to check; either TNY_ACCOUNT_TYPE_TRANSPORT or TNY_ACCOUNT_TYPE_STORE
- *
- * get the TnyAccount corresponding to the store/transport (server) accounts for some account.
- * ie., every account has two server accounts, and for every server account there is a corresponding
- * TnyAccount
- *
- * Returns: the requested TnyAccount, or NULL in case of error
- */
-TnyAccount* modest_account_mgr_get_tny_account (ModestAccountMgr *self, const gchar* name,
- TnyAccountType type);
-
/**
* modest_account_mgr_get_from_string
* @self: a #ModestAccountMgr instance
*/
#define MODEST_DIR ".modest"
#define MODEST_CACHE_DIR "cache"
-#define MODEST_LOCAL_FOLDERS_MAILDIR "local_folders"
#define MODEST_LOCAL_FOLDERS_ACCOUNT_NAME "local_folders"
-#define MODEST_LOCAL_FOLDERS_DISPLAY_NAME N_("Local folders")
+#define MODEST_LOCAL_FOLDERS_ACCOUNT_ID MODEST_LOCAL_FOLDERS_ACCOUNT_NAME
+#define MODEST_LOCAL_FOLDERS_MAILDIR MODEST_LOCAL_FOLDERS_ACCOUNT_NAME
+
+#define MODEST_LOCAL_FOLDERS_DISPLAY_NAME N_(MODEST_LOCAL_FOLDERS_ACCOUNT_NAME)
/* configuration key definitions for modest */
#define MODEST_CONF_NAMESPACE "/apps/modest"
g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
-
- tny_send_queue_add (send_queue, msg);
+ if (!TNY_IS_SEND_QUEUE(send_queue))
+ g_printerr ("modest: could not find send queue for account\n");
+ else
+ tny_send_queue_add (send_queue, msg);
}
void
#include <modest-tny-account-store.h>
#include <modest-tny-platform-factory.h>
#include <modest-mail-operation.h>
-
+#include <modest-tny-account.h>
#include <modest-account-mgr.h>
#include <modest-account-mgr-helpers.h>
int retval;
TnyTransportAccount *account;
ModestMailOperation *mail_operation = NULL;
- ModestAccountMgr *account_mgr;
gchar *from_string;
g_return_val_if_fail (account_name, MODEST_ERR_SEND);
- account_mgr = modest_runtime_get_account_mgr ();
- account = TNY_TRANSPORT_ACCOUNT(modest_account_mgr_get_tny_account (account_mgr, account_name,
- TNY_ACCOUNT_TYPE_TRANSPORT));
+ account = TNY_TRANSPORT_ACCOUNT (modest_tny_account_store_get_tny_account_by_account
+ (modest_runtime_get_account_store(), account_name,
+ TNY_ACCOUNT_TYPE_TRANSPORT));
if (!account) {
g_printerr ("modest: no transport defined account for %s\n",
account_name);
return MODEST_ERR_SEND;
}
- from_string = modest_account_mgr_get_from_string (account_mgr, account_name);
+ from_string = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
+ account_name);
mail_operation = modest_mail_operation_new ();
modest_mail_operation_send_new_mail (mail_operation, account,
} else
retval = MODEST_ERR_NONE; /* hurray! */
+ g_object_unref (G_OBJECT(account));
g_object_unref (G_OBJECT(mail_operation));
g_free (from_string);
gpointer orig_key, send_queue;
g_return_val_if_fail (_singletons, NULL);
- g_return_val_if_fail (!TNY_IS_TRANSPORT_ACCOUNT(account), NULL);
+ g_return_val_if_fail (TNY_IS_TRANSPORT_ACCOUNT(account), NULL);
cache_mgr = modest_singletons_get_cache_mgr (_singletons);
send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
- MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF);
+ MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
+
if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) {
send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
g_hash_table_insert (send_queue_cache, account, send_queue);
ModestTnySendQueue* modest_runtime_get_send_queue (TnyTransportAccount *account);
-
G_END_DECLS
#endif /*__MODEST_RUNTIME_H__*/
g_printerr ("modest: cannot create modest account mgr instance\n");
return;
}
-
+
priv->account_store = modest_tny_account_store_new (priv->account_mgr);
if (!priv->account_store) {
g_printerr ("modest: cannot create modest tny account store instance\n");
return;
}
-
+
priv->cache_mgr = modest_cache_mgr_new ();
if (!priv->cache_mgr) {
g_printerr ("modest: cannot create modest cache mgr instance\n");
priv->account_store = NULL;
}
+
if (priv->account_mgr) {
g_object_unref (G_OBJECT(priv->account_mgr));
check_object_is_dead ((GObject*)priv->account_mgr,
return MODEST_SINGLETONS_GET_PRIVATE(self)->cache_mgr;
}
-
ModestMailOperationQueue*
modest_singletons_get_mail_operation_queue (ModestSingletons *self)
{
#include <modest-cache-mgr.h>
#include <modest-widget-factory.h>
-
G_BEGIN_DECLS
/* convenience macros */
/* 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_init (gpointer g, gpointer iface_data);
/* list my signals */
typedef struct _ModestTnyAccountStorePrivate ModestTnyAccountStorePrivate;
struct _ModestTnyAccountStorePrivate {
-
- gchar *cache_dir;
-
+ gchar *cache_dir;
GHashTable *password_hash;
TnyDevice *device;
- TnySessionCamel *tny_session_camel;
-
ModestAccountMgr *account_mgr;
- TnyAccount *local_folders;
+ TnySessionCamel *session;
+
+ /* we cache them here */
+ GSList *store_accounts;
+ GSList *transport_accounts;
};
#define MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
G_STRUCT_OFFSET(ModestTnyAccountStoreClass, account_update),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
+ G_TYPE_NONE, 1, G_TYPE_STRING);
}
priv->cache_dir = NULL;
priv->account_mgr = NULL;
- priv->tny_session_camel = NULL;
priv->device = NULL;
+ priv->session = NULL;
priv->password_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
-
- priv->local_folders = NULL;
}
-
-/* we need these dummy functions, or tinymail will complain */
-static gchar*
-get_password_dummy (TnyAccount *account, const gchar *prompt, gboolean *cancel)
-{
- return NULL;
-}
static void
-forget_password_dummy (TnyAccount *account)
+account_list_free (GSList *accounts)
{
- return;
-}
-
-/* create a pseudo-account for our local folders */
-static TnyAccount*
-get_local_folders_account (ModestTnyAccountStore *self)
-{
- TnyStoreAccount *tny_account;
- CamelURL *url;
- gchar *maildir, *url_string;
- ModestTnyAccountStorePrivate *priv;
-
- priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-
- tny_account = tny_camel_store_account_new ();
- if (!tny_account) {
- g_printerr ("modest: cannot create account for local folders");
- return NULL;
+ GSList *cursor = accounts;
+ while (cursor) {
+ g_object_unref (G_OBJECT(cursor->data));
+ cursor = cursor->next;
}
-
- tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),priv->tny_session_camel);
-
- 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_account_set_name (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME);
- tny_account_set_id (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME);
- tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_password_dummy);
- tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_password_dummy);
-
- camel_url_free (url);
- g_free (maildir);
- g_free (url_string);
-
- return TNY_ACCOUNT(tny_account);
+ g_slist_free (accounts);
}
-
static void
on_account_removed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean server_account,
gpointer user_data)
{
- ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
+ ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
+ ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+ /* FIXME: make this more finegrained; changes do not really affect _all_
+ * accounts, and some do not affect tny accounts at all (such as 'last_update')
+ */
+ account_list_free (priv->store_accounts);
+ priv->store_accounts = NULL;
+
+ account_list_free (priv->transport_accounts);
+ priv->transport_accounts = NULL;
+
g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
account);
-
}
const gchar *key, gpointer user_data)
{
ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
+ ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ /* FIXME: make this more finegrained; changes do not really affect _all_
+ * accounts, and some do not affect tny accounts at all (such as 'last_update')
+ */
+ account_list_free (priv->store_accounts);
+ priv->store_accounts = NULL;
+
+ account_list_free (priv->transport_accounts);
+ priv->transport_accounts = NULL;
+
g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
account);
gchar *pwd = NULL;
gpointer pwd_ptr;
gboolean already_asked;
-
key = tny_account_get_id (account);
account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(obj);
ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
- if (priv->tny_session_camel) {
- camel_object_unref (CAMEL_OBJECT(priv->tny_session_camel));
- priv->tny_session_camel = NULL;
- }
-
g_free (priv->cache_dir);
priv->cache_dir = NULL;
priv->account_mgr = NULL;
}
+ if (priv->session) {
+ camel_object_unref (CAMEL_OBJECT(priv->session));
+ priv->session = NULL;
+ }
+
+ /* this includes the local folder */
+ account_list_free (priv->store_accounts);
+ priv->store_accounts = NULL;
+
+ account_list_free (priv->transport_accounts);
+ priv->transport_accounts = NULL;
+
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
GObject *obj;
ModestTnyAccountStorePrivate *priv;
+ TnyList *list;
g_return_val_if_fail (account_mgr, NULL);
priv->account_mgr = account_mgr;
g_object_ref (G_OBJECT(priv->account_mgr));
+
+ priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
- /* The session needs the platform factory */
- priv->tny_session_camel = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
- if (!priv->tny_session_camel) {
- g_printerr ("modest: cannot create TnySessionCamel instance\n");
- g_object_unref (obj);
- return NULL;
- }
-
- tny_session_camel_set_ui_locker (priv->tny_session_camel, tny_gtk_lockable_new ());
+ tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ());
/* FIXME: unref this in the end? */
+
+ /* force a cache fill... ugly */
+ list = TNY_LIST(tny_simple_list_new());
+ tny_account_store_get_accounts (TNY_ACCOUNT_STORE(obj), list,
+ TNY_ACCOUNT_STORE_BOTH);
+ g_object_unref(list);
/* Connect signals */
g_signal_connect (G_OBJECT(account_mgr), "account_changed",
static void
-modest_tny_account_store_get_accounts (TnyAccountStore *account_store, TnyList *list,
- TnyGetAccountsRequestType request_type)
+get_cached_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type)
{
- TnyAccountType type;
- ModestTnyAccountStore *self;
ModestTnyAccountStorePrivate *priv;
GSList *accounts, *cursor;
- g_return_if_fail (account_store);
- g_return_if_fail (TNY_IS_LIST(list));
- g_return_if_fail (request_type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS ||
- request_type == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS ||
- request_type == TNY_ACCOUNT_STORE_BOTH);
-
- self = MODEST_TNY_ACCOUNT_STORE(account_store);
- priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-
- if (request_type == TNY_ACCOUNT_STORE_BOTH) {
- modest_tny_account_store_get_accounts (account_store, list,
- TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
- modest_tny_account_store_get_accounts (account_store, list,
- TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
- return;
- }
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+ accounts = (type == TNY_ACCOUNT_TYPE_STORE ? priv->store_accounts : priv->transport_accounts);
- /*
- * confusingly, tinymail uses both TnyAccountRequestType and TnyAccountType
- */
- switch (request_type) {
- case TNY_ACCOUNT_STORE_STORE_ACCOUNTS : type = TNY_ACCOUNT_TYPE_STORE; break;
- case TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS: type = TNY_ACCOUNT_TYPE_TRANSPORT; break;
- default: g_return_if_reached (); /* 'BOTH' is not possible here */
+ cursor = accounts;
+ while (cursor) {
+ tny_list_prepend (list, G_OBJECT(cursor->data));
+ cursor = cursor->next;
}
+}
+
+/* this function fills the TnyList, and also returns a GSList of the accounts,
+ * for caching purposes
+ */
+static GSList*
+get_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type)
+{
+ ModestTnyAccountStorePrivate *priv;
+ GSList *account_names, *cursor;
+ GSList *accounts = NULL;
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ account_names = modest_account_mgr_account_names (priv->account_mgr, NULL);
- accounts = modest_account_mgr_account_names (priv->account_mgr, NULL);
- for (cursor = accounts; cursor; cursor = cursor->next) {
+ for (cursor = account_names; cursor; cursor = cursor->next) {
+
gchar *account_name = (gchar*)cursor->data;
- if (modest_account_mgr_get_enabled(priv->account_mgr, account_name) == TRUE) {
- TnyAccount *tny_account = modest_tny_account_new_from_account (priv->account_mgr, account_name,
- type);
- if (tny_account) {
- tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), priv->tny_session_camel);
-
- tny_account_set_forget_pass_func (tny_account, forget_password);
- tny_account_set_pass_func (tny_account, get_password);
+
+ /* only return enabled accounts */
+ if (modest_account_mgr_get_enabled(priv->account_mgr, account_name)) {
+ TnyAccount *tny_account =
+ modest_tny_account_new_from_account (priv->account_mgr, account_name,
+ type, priv->session, get_password,
+ forget_password);
+ if (tny_account) { /* something went wrong */
g_object_set_data (G_OBJECT(tny_account), "account_store", (gpointer)self);
-
tny_list_prepend (list, G_OBJECT(tny_account));
- g_object_unref (G_OBJECT(tny_account));
- }
+ accounts = g_slist_append (accounts, tny_account); /* cache it */
+ } else
+ g_printerr ("modest: failed to create account for %s\n", account_name);
}
g_free (account_name);
}
- g_slist_free (accounts);
-
+ g_slist_free (account_names);
+
/* also, add the local folder pseudo-account */
- if (request_type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) {
- if (!priv->local_folders)
- priv->local_folders = get_local_folders_account (self);
- if (!priv->local_folders)
- g_printerr ("modest: no local folders account\n");
- else
- tny_list_prepend (list, G_OBJECT(priv->local_folders));
+ if (type == TNY_ACCOUNT_TYPE_STORE) {
+ TnyAccount *tny_account =
+ modest_tny_account_new_for_local_folders (priv->account_mgr, priv->session);
+ tny_list_prepend (list, G_OBJECT(tny_account));
+ accounts = g_slist_append (accounts, tny_account); /* cache it */
}
+
+ return accounts;
}
+
+
+static void
+modest_tny_account_store_get_accounts (TnyAccountStore *self, TnyList *list,
+ TnyGetAccountsRequestType request_type)
+{
+ ModestTnyAccountStorePrivate *priv;
+
+ g_return_if_fail (self);
+ g_return_if_fail (TNY_IS_LIST(list));
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ if (request_type == TNY_ACCOUNT_STORE_BOTH) {
+ modest_tny_account_store_get_accounts (self, list, TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+ modest_tny_account_store_get_accounts (self, list, TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
+ return;
+ }
+
+ if (request_type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) {
+
+ if (!priv->store_accounts)
+ priv->store_accounts = get_accounts (self, list, TNY_ACCOUNT_TYPE_STORE);
+ else
+ get_cached_accounts (self, list, TNY_ACCOUNT_TYPE_STORE);
+
+ } else if (request_type == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) {
+
+ if (!priv->transport_accounts)
+ priv->transport_accounts = get_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
+ else
+ get_cached_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
+ } else
+ g_return_if_reached (); /* incorrect req type */
+}
+
static const gchar*
modest_tny_account_store_get_cache_dir (TnyAccountStore *self)
tny_account_store_get_session (TnyAccountStore *self)
{
g_return_val_if_fail (self, NULL);
- return MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self)->tny_session_camel;
+ return MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self)->session;
}
TnyAccount*
-modest_tny_account_store_get_local_folders_account (ModestTnyAccountStore *self)
+modest_tny_account_store_get_tny_account_by_id (ModestTnyAccountStore *self, const gchar *id)
{
+ TnyAccount *account = NULL;
+ ModestTnyAccountStorePrivate *priv;
+ GSList *cursor;
+
g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (id, NULL);
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ for (cursor = priv->store_accounts; cursor ; cursor = cursor->next) {
+ const gchar *acc_id = tny_account_get_id (TNY_ACCOUNT(cursor->data));
+ if (acc_id && strcmp (acc_id, id) == 0) {
+ account = TNY_ACCOUNT(cursor->data);
+ break;
+ }
+ }
+
+ /* if we already found something, no need to search the transport accounts */
+ for (cursor = priv->transport_accounts; !account && cursor ; cursor = cursor->next) {
+ const gchar *acc_id = tny_account_get_id (TNY_ACCOUNT(cursor->data));
+ if (acc_id && strcmp (acc_id, id) == 0) {
+ account = TNY_ACCOUNT(cursor->data);
+ break;
+ }
+ }
+
+ if (account)
+ g_object_ref (G_OBJECT(account));
- return MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self)->local_folders;
+ return account;
+}
+
+
+TnyAccount*
+modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self,
+ const gchar *account_name,
+ TnyAccountType type)
+{
+ TnyAccount *account = NULL;
+ ModestAccountData *account_data;
+ const gchar *id = NULL;
+ ModestTnyAccountStorePrivate *priv;
+
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (account_name, NULL);
+ g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT,
+ NULL);
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ account_data = modest_account_mgr_get_account_data (priv->account_mgr, account_name);
+ if (!account_data) {
+ g_printerr ("modest: cannot get account data for account '%s'\n", account_name);
+ return NULL;
+ }
+
+ if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
+ id = account_data->store_account->account_name;
+ else if (account_data->transport_account)
+ id = account_data->transport_account->account_name;
+
+ if (id)
+ account = modest_tny_account_store_get_tny_account_by_id (self, id);
+ if (!account)
+ g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
+ type == TNY_ACCOUNT_TYPE_STORE? "store" : "transport",
+ account_name, id ? id : "<none>");
+
+ modest_account_mgr_free_account_data (priv->account_mgr, account_data);
+ return account;
}
*/
ModestTnyAccountStore* modest_tny_account_store_new (ModestAccountMgr *account_mgr);
+
+/**
+ * modest_tny_account_store_get_account_by_id
+ * @self: a ModestTnyAccountStore instance
+ * @id: some ID
+ *
+ * get the account with the given ID or NULL if it's not found
+ *
+ * Returns: the tnyaccount or NULL,
+ * g_object_unref when it's no longer needed
+ */
+TnyAccount* modest_tny_account_store_get_tny_account_by_id (ModestTnyAccountStore *self,
+ const gchar *id);
+
+
+/**
+ * modest_tny_account_store_get_tny_account_by_account
+ * @self: a ModestTnyAccountStore instance
+ * @account_name: an account name
+ * @type: the tny account type
+ *
+ * get the tny account corresponding to one of the server_accounts for account with @account_name
+ *
+ * Returns: the tnyaccount or NULL in case it's not found or error,
+ * g_object_unref when it's no longer needed
+ */
+TnyAccount* modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self,
+ const gchar *account_name,
+ TnyAccountType type);
+
/**
* tny_account_store_get_session
* @self: a TnyAccountStore instance
*/
TnySessionCamel* tny_account_store_get_session (TnyAccountStore *self);
-/**
- * tny_account_store_get_local_folders_account
- * @self: a ModestTnyAccountStore instance
- *
- * return the account corresponding to the local folders
- *
- * Returns: the tnyaccount for the local folders
- */
-TnyAccount* modest_tny_account_store_get_local_folders_account (ModestTnyAccountStore *self);
G_END_DECLS
g_return_val_if_fail (account, NULL);
g_return_val_if_fail (0 <= special_type && special_type < TNY_FOLDER_TYPE_NUM,
NULL);
-
- local_account = modest_tny_account_store_get_local_folders_account
- (modest_runtime_get_account_store());
+
+ local_account = modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store(),
+ MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
if (!local_account) {
g_printerr ("modest: cannot get local account\n");
return NULL;
g_return_val_if_fail (account_mgr, NULL);
g_return_val_if_fail (account_data, NULL);
-
+
/* sanity checks */
if (account_data->proto == MODEST_PROTOCOL_UNKNOWN) {
g_printerr ("modest: '%s' does not provide a protocol\n",
account_data->account_name);
return NULL;
}
-
+
switch (account_data->proto) {
case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
case MODEST_PROTOCOL_TRANSPORT_SMTP:
}
tny_account_set_id (tny_account, account_data->account_name);
- /*
- * FIXME --> bug in tinymail
- */
- if (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SENDMAIL ||
- account_data->proto == MODEST_PROTOCOL_TRANSPORT_SMTP) {
- g_printerr ("modest: BUG: cannot create transports accounts... stay tuned\n");
- g_object_unref (G_OBJECT(tny_account));
- return NULL;
- }
-
/* Proto */
tny_account_set_proto (tny_account,
modest_protocol_info_get_protocol_name(account_data->proto));
-
if (account_data->uri)
tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
else {
}
+/* we need these dummy functions, or tinymail will complain */
+static gchar*
+get_pass_dummy (TnyAccount *account, const gchar *prompt, gboolean *cancel)
+{
+ return NULL;
+}
+static void
+forget_pass_dummy (TnyAccount *account)
+{
+ /* intentionally left blank */
+}
+
TnyAccount*
modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar *account_name,
- TnyAccountType type)
+ TnyAccountType type,
+ TnySessionCamel *session,
+ TnyGetPassFunc get_pass_func,
+ TnyForgetPassFunc forget_pass_func)
{
TnyAccount *tny_account = NULL;
ModestAccountData *account_data = NULL;
ModestServerAccountData *server_data = NULL;
-
+
+ g_return_val_if_fail (account_mgr, NULL);
+ g_return_val_if_fail (account_name, NULL);
+
account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
if (!account_data) {
g_printerr ("modest: cannot get account data for account %s\n", account_name);
return NULL;
}
+ tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
+ tny_account_set_forget_pass_func (tny_account,
+ forget_pass_func ? forget_pass_func : forget_pass_dummy);
+ tny_account_set_pass_func (tny_account,
+ get_pass_func ? get_pass_func: get_pass_dummy);
+
/* this name is what shows up in the folder view -- so for some POP/IMAP/... server
* account, we set its name to the acount of which it is part */
if (account_data->display_name)
return tny_account;
}
+
+TnyAccount*
+modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySessionCamel *session)
+{
+ TnyStoreAccount *tny_account;
+ CamelURL *url;
+ gchar *maildir, *url_string;
+
+ g_return_val_if_fail (account_mgr, NULL);
+
+ tny_account = tny_camel_store_account_new ();
+ if (!tny_account) {
+ g_printerr ("modest: cannot create account for local folders");
+ return NULL;
+ }
+ tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
+
+ 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_account_set_name (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME);
+ tny_account_set_id (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
+ tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
+ tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
+
+ camel_url_free (url);
+ g_free (maildir);
+ g_free (url_string);
+
+ return TNY_ACCOUNT(tny_account);
+}
+
+
#include <tny-folder.h>
#include <modest-account-mgr.h>
#include <modest-local-folder-info.h>
+#include <tny-session-camel.h>
G_BEGIN_DECLS
* @account_mgr: a valid account mgr instance
* @account_name: the account name for which to create a corresponding tny account
* @type: the type of account to create (TNY_ACCOUNT_TYPE_STORE or TNY_ACCOUNT_TYPE_TRANSPORT)
+ * @session: a tny camel session
+ * @get_pass_func: the get-password function
+ * @forget_pass_func: the forget-password function
*
* get a tnyaccount corresponding to the server_accounts (store or transport) for this account.
* NOTE: this function does not set the camel session or the get/forget password functions
*
* Returns: a new TnyAccount or NULL in case of error.
*/
-TnyAccount* modest_tny_account_new_from_account (ModestAccountMgr *account_mgr,
- const gchar *account_name, TnyAccountType type);
-
+TnyAccount*
+modest_tny_account_new_from_account (ModestAccountMgr *account_mgr, const gchar *account_name,
+ TnyAccountType type,
+ TnySessionCamel *session,
+ TnyGetPassFunc get_pass_func,
+ TnyForgetPassFunc forget_pass_func);
+/**
+ * modest_tny_account_new_for_local_folders:
+ * @account_mgr: a valid account mgr instance
+ * @session: a tny camel session
+ *
+ * get the local folders (pseudo) account; you should only need one such account.
+ *
+ * Returns: a new local folders TnyAccount or NULL in case of error.
+ */
+TnyAccount* modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr,
+ TnySessionCamel *session);
/**
* modest_tny_account_get_special_folder:
/* uncomment the following if you have defined any signals */
/* static guint signals[LAST_SIGNAL] = {0}; */
-
/*
* this thread actually tries to send all the mails in the outbox
*/
static void
modest_tny_send_queue_cancel (TnySendQueue *self, gboolean remove)
{
- TNY_CAMEL_SEND_QUEUE_GET_CLASS(parent_class)->cancel_func (self, remove);
+ g_warning (__FUNCTION__);
+
+ TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->cancel_func (self, remove);
}
static void
{
ModestTnySendQueuePrivate *priv;
- g_return_if_fail (self);
+ g_return_if_fail (TNY_IS_SEND_QUEUE(self));
g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
+
+ g_warning (__FUNCTION__);
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
/* FIXME: do something smart here... */
-
- TNY_CAMEL_SEND_QUEUE_GET_CLASS(parent_class)->add_func (self, msg);
+
+ TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_func (self, msg);
}
static TnyFolder*
{
ModestTnySendQueuePrivate *priv;
+ g_warning (__FUNCTION__);
+
g_return_val_if_fail (self, NULL);
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
ModestTnySendQueuePrivate *priv;
g_return_val_if_fail (self, NULL);
+
+ g_warning (__FUNCTION__);
priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
(GInstanceInitFunc) modest_tny_send_queue_instance_init,
NULL
};
- my_type = g_type_register_static (G_TYPE_OBJECT,
+ my_type = g_type_register_static (TNY_TYPE_CAMEL_SEND_QUEUE,
"ModestTnySendQueue",
&my_info, 0);
}
parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = modest_tny_send_queue_finalize;
- parent_class->add_func = modest_tny_send_queue_add;
- parent_class->get_outbox_func = modest_tny_send_queue_get_outbox;
- parent_class->get_sentbox_func = modest_tny_send_queue_get_sentbox;
- parent_class->cancel_func = modest_tny_send_queue_cancel;
+ TNY_CAMEL_SEND_QUEUE_CLASS(klass)->add_func = modest_tny_send_queue_add;
+ TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_outbox_func = modest_tny_send_queue_get_outbox;
+ TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_sentbox_func = modest_tny_send_queue_get_sentbox;
+ TNY_CAMEL_SEND_QUEUE_CLASS(klass)->cancel_func = modest_tny_send_queue_cancel;
g_type_class_add_private (gobject_class, sizeof(ModestTnySendQueuePrivate));
}
return;
}
transport_account =
- TNY_TRANSPORT_ACCOUNT(modest_account_mgr_get_tny_account (account_mgr,
- account_name,
- TNY_ACCOUNT_TYPE_TRANSPORT));
+ TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
+ (modest_runtime_get_account_store(),
+ account_name,
+ TNY_ACCOUNT_TYPE_TRANSPORT));
if (!transport_account) {
- g_printerr ("modest: no transport account found\n");
+ g_printerr ("modest: no transport account found for '%s'\n", account_name);
g_free (account_name);
modest_edit_msg_window_free_msg_data (edit_window, data);
return;
g_free (account_name);
g_object_unref (G_OBJECT (mail_operation));
g_object_unref (G_OBJECT (transport_account));
+
modest_edit_msg_window_free_msg_data (edit_window, data);
/* Save settings and close the window */