#include <modest-tny-platform-factory.h>
#include <modest-tny-account.h>
#include <modest-tny-account-store.h>
+#include <modest-default-connection-policy.h>
#include <modest-tny-local-folders-account.h>
#include <modest-runtime.h>
#include <tny-simple-list.h>
#include <tny-camel-imap-store-account.h>
#include <tny-camel-pop-store-account.h>
#include <tny-folder-stats.h>
+#include <tny-merge-folder.h>
#include <modest-debug.h>
#include <string.h>
#ifdef MODEST_PLATFORM_MAEMO
*/
/* Per-account outbox folders are each in their own on-disk directory: */
- if (special_type == TNY_FOLDER_TYPE_OUTBOX) {
+ if ((special_type == TNY_FOLDER_TYPE_OUTBOX) &&
+ (!modest_tny_account_is_virtual_local_folders (account))) {
gchar *account_id;
const gchar *modest_account_name;
g_return_val_if_fail (account_name, FALSE);
g_return_val_if_fail (tny_account, FALSE);
- tny_account_set_id (tny_account, account_name);
+ /* Do not change the id if it's not needed */
+ if (tny_account_get_id (tny_account) &&
+ strcmp (tny_account_get_id (tny_account), account_name))
+ tny_account_set_id (tny_account, account_name);
/* mbox and maildir accounts use a URI instead of the rest:
* Note that this is not where we create the special local folders account.
else {
/* Set camel-specific options: */
/* Enable secure connection settings: */
- const gchar* option_security = NULL;
+ TnyPair *option_security = NULL;
const gchar* auth_mech_name = NULL;
ModestTransportStoreProtocol protocol;
ModestConnectionProtocol security;
const gchar *hostname;
guint port;
+ /* First of all delete old options */
+ tny_camel_account_clear_options (TNY_CAMEL_ACCOUNT (tny_account));
+
protocol = modest_server_account_settings_get_protocol (server_settings);
security = modest_server_account_settings_get_security (server_settings);
auth_protocol = modest_server_account_settings_get_auth_protocol (server_settings);
switch (security) {
case MODEST_PROTOCOL_CONNECTION_NORMAL:
- option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_NEVER;
+ option_security = tny_pair_new (MODEST_ACCOUNT_OPTION_SSL,MODEST_ACCOUNT_OPTION_SSL_NEVER);
break;
case MODEST_PROTOCOL_CONNECTION_SSL:
/* Apparently, use of "IMAPS" (specified in our UI spec), implies
* use of the "wrapped" option: */
- option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_WRAPPED;
+ option_security = tny_pair_new (MODEST_ACCOUNT_OPTION_SSL,MODEST_ACCOUNT_OPTION_SSL_WRAPPED);
break;
case MODEST_PROTOCOL_CONNECTION_TLS:
- option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_TLS;
+ option_security = tny_pair_new (MODEST_ACCOUNT_OPTION_SSL,MODEST_ACCOUNT_OPTION_SSL_TLS);
break;
case MODEST_PROTOCOL_CONNECTION_TLS_OP:
/* This is not actually in our UI: */
- option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE;
+ option_security = tny_pair_new (MODEST_ACCOUNT_OPTION_SSL,MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE);
break;
default:
break;
}
if(option_security)
- tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
- option_security);
+ tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account), option_security);
/* Secure authentication: */
switch (auth_protocol) {
if (protocol == MODEST_PROTOCOL_STORE_IMAP ||
protocol == MODEST_PROTOCOL_STORE_POP)
auth_mech_name = NULL;
- else if (protocol == MODEST_PROTOCOL_TRANSPORT_SMTP)
- auth_mech_name = MODEST_ACCOUNT_AUTH_ANONYMOUS;
else
auth_mech_name = MODEST_ACCOUNT_AUTH_PLAIN;
break;
break;
}
- if(auth_mech_name)
- tny_account_set_secure_auth_mech (tny_account, auth_mech_name);
+ tny_account_set_secure_auth_mech (tny_account, auth_mech_name);
if (modest_protocol_info_protocol_is_store(protocol) &&
(protocol == MODEST_PROTOCOL_STORE_IMAP) ) {
/* Other connection options, needed for IMAP. */
tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
- MODEST_ACCOUNT_OPTION_USE_LSUB);
+ tny_pair_new (MODEST_ACCOUNT_OPTION_USE_LSUB, ""));
tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
- MODEST_ACCOUNT_OPTION_CHECK_ALL);
+ tny_pair_new (MODEST_ACCOUNT_OPTION_CHECK_ALL, ""));
}
username = modest_server_account_settings_get_username (server_settings);
tny_account_set_pass_func (tny_account,
get_pass_func ? get_pass_func: get_pass_dummy);
}
-
+
+ tny_account_set_connection_policy (tny_account, modest_default_connection_policy_new ());
+
g_object_unref (server_settings);
return tny_account;
static void
set_online_callback (TnyCamelAccount *account, gboolean canceled, GError *err, gpointer user_data)
{
- /* MODEST TODO: Show a real error message here, this is a significant error!
- * Perhaps show the account's settings dialog again?! Reconnecting after
- * changing the settings of an account failed in this situation. */
+ TnyAccountStore *account_store;
- if (err && !canceled)
- g_warning ("err: %s", err->message);
+ account_store = TNY_ACCOUNT_STORE(g_object_get_data (G_OBJECT(account),
+ "account_store"));
+ if (err && !canceled) {
+ /* It seems err is forgotten here ... if the disk is full ! */
+ if (account_store) {
+ tny_account_store_alert (
+ account_store,
+ TNY_ACCOUNT (account), TNY_ALERT_TYPE_ERROR, FALSE,
+ err);
+ }
+ g_warning ("err: %s", err->message);
+ }
}
gboolean
-modest_tny_account_update_from_account (TnyAccount *tny_account)
+modest_tny_account_update_from_account (TnyAccount *tny_account,
+ TnyGetPassFunc get_pass_func,
+ TnyForgetPassFunc forget_pass_func)
{
ModestAccountSettings *settings = NULL;
ModestServerAccountSettings *server_settings = NULL;
- TnyConnectionStatus conn_status;
ModestAccountMgr *account_mgr;
const gchar *account_name;
TnyAccountType type;
const gchar *display_name;
+ TnyConnectionStatus conn_status;
g_return_val_if_fail (tny_account, FALSE);
g_object_unref (server_settings);
g_object_unref (settings);
- /* If the account was online, reconnect to apply the changes */
+ tny_account_set_connection_policy (tny_account, modest_default_connection_policy_new ());
+
+ /* The callback will have an error for you if the reconnect
+ * failed. Please handle it (this is TODO). */
+
conn_status = tny_account_get_connection_status (tny_account);
if (conn_status != TNY_CONNECTION_STATUS_DISCONNECTED) {
TnyAccountStore *account_store = NULL;
-
- /* The callback will have an error for you if the reconnect
- * failed. Please handle it (this is TODO). */
-
+
account_store = TNY_ACCOUNT_STORE(g_object_get_data (G_OBJECT(tny_account),
- "account_store"));
-
+ "account_store"));
+
if (account_store) {
modest_tny_account_store_forget_already_asked (MODEST_TNY_ACCOUNT_STORE (account_store),
- tny_account);
+ tny_account);
}
-
+
tny_camel_account_set_online (TNY_CAMEL_ACCOUNT(tny_account), TRUE,
- set_online_callback, "online");
+ set_online_callback, "online");
}
-
+
return TRUE;
}
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);
-
+
+ tny_account_set_connection_policy (tny_account, modest_default_connection_policy_new ());
+
modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account,
account_name);
g_object_unref (server_settings);
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);
-
+
+ tny_account_set_connection_policy (TNY_ACCOUNT (tny_account), modest_default_connection_policy_new ());
+
modest_tny_account_set_parent_modest_account_name_for_server_account (
TNY_ACCOUNT (tny_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);
-
+
+ tny_account_set_connection_policy (TNY_ACCOUNT (tny_account), modest_default_connection_policy_new ());
+
/* Make this think that it belongs to the modest local-folders parent account: */
modest_tny_account_set_parent_modest_account_name_for_server_account (
TNY_ACCOUNT (tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
-typedef gint (*TnyStatsFunc) (TnyFolderStats *stats);
-#define TASK_GET_ALL_COUNT 0
-#define TASK_GET_LOCAL_SIZE 1
-#define TASK_GET_FOLDER_COUNT 2
-
-typedef struct _RecurseFoldersHelper {
- gint task;
- guint sum;
- guint folders;
-} RecurseFoldersHelper;
+typedef struct _RecurseFoldersAsyncHelper {
+ ModestFolderStats stats;
+ guint pending_calls;
+ GetFolderStatsCallback callback;
+ GetFolderStatsCallback status_callback;
+ gpointer user_data;
+} RecurseFoldersAsyncHelper;
-static void
-recurse_folders (TnyFolderStore *store,
- TnyFolderStoreQuery *query,
- RecurseFoldersHelper *helper)
+static void
+recurse_folders_async_cb (TnyFolderStore *folder_store,
+ gboolean canceled,
+ TnyList *list,
+ GError *err,
+ gpointer user_data)
{
- TnyIterator *iter;
- TnyList *folders = tny_simple_list_new ();
+ RecurseFoldersAsyncHelper *helper;
+ TnyIterator *iter;
- tny_folder_store_get_folders (store, folders, query, NULL);
- iter = tny_list_create_iterator (folders);
+ helper = (RecurseFoldersAsyncHelper *) user_data;
- helper->folders += tny_list_get_length (folders);
+ /* A goto just to avoid an indentation level */
+ if (err || canceled)
+ goto next_folder;
+ /* Retrieve children */
+ iter = tny_list_create_iterator (list);
while (!tny_iterator_is_done (iter)) {
- TnyFolder *folder;
+ TnyList *folders = NULL;
+ TnyFolderStore *folder = NULL;
- folder = TNY_FOLDER (tny_iterator_get_current (iter));
- if (folder) {
- if (helper->task == TASK_GET_ALL_COUNT)
- helper->sum += tny_folder_get_all_count (folder);
-
- if (helper->task == TASK_GET_LOCAL_SIZE)
- helper->sum += tny_folder_get_local_size (folder);
-
- if (TNY_IS_FOLDER_STORE (folder))
- recurse_folders (TNY_FOLDER_STORE (folder), query, helper);
-
- g_object_unref (folder);
+ folders = tny_simple_list_new ();
+ folder = (TnyFolderStore*) tny_iterator_get_current (iter);
+
+ /* Add pending call */
+ helper->pending_calls++;
+ helper->stats.folders++;
+ if (TNY_IS_FOLDER (folder)) {
+ helper->stats.msg_count += tny_folder_get_all_count (TNY_FOLDER (folder));
+ helper->stats.local_size += tny_folder_get_local_size (TNY_FOLDER (folder));
}
+ /* notify */
+ if (helper->status_callback)
+ helper->status_callback (helper->stats, helper->user_data);
+
+ /* Avoid the outbox */
+ if (!TNY_IS_MERGE_FOLDER (folder) &&
+ (TNY_IS_FOLDER (folder) &&
+ tny_folder_get_folder_type (TNY_FOLDER (folder)) != TNY_FOLDER_TYPE_OUTBOX))
+ tny_folder_store_get_folders_async (folder, folders, NULL,
+ recurse_folders_async_cb,
+ NULL, helper);
+ g_object_unref (folders);
+ g_object_unref (G_OBJECT (folder));
+
tny_iterator_next (iter);
}
- g_object_unref (G_OBJECT (iter));
- g_object_unref (G_OBJECT (folders));
-}
-
-gint
-modest_tny_folder_store_get_folder_count (TnyFolderStore *self)
-{
- RecurseFoldersHelper *helper;
- gint retval;
-
- g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1);
-
- /* Create helper */
- helper = g_malloc0 (sizeof (RecurseFoldersHelper));
- helper->task = TASK_GET_FOLDER_COUNT;
- helper->folders = 0;
+ g_object_unref (G_OBJECT (iter));
- recurse_folders (self, NULL, helper);
+next_folder:
+ /* Remove my own pending call */
+ helper->pending_calls--;
- retval = helper->folders;
+ /* This means that we have all the folders */
+ if (helper->pending_calls == 0) {
+ /* notify */
+ if (helper->callback)
+ helper->callback (helper->stats, helper->user_data);
- g_free (helper);
-
- return retval;
-}
-
-gint
-modest_tny_folder_store_get_message_count (TnyFolderStore *self)
-{
- RecurseFoldersHelper *helper;
- gint retval;
-
- g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1);
-
- /* Create helper */
- helper = g_malloc0 (sizeof (RecurseFoldersHelper));
- helper->task = TASK_GET_ALL_COUNT;
- if (TNY_IS_FOLDER (self))
- helper->sum = tny_folder_get_all_count (TNY_FOLDER (self));
-
- recurse_folders (self, NULL, helper);
-
- retval = helper->sum;
-
- g_free (helper);
-
- return retval;
+ /* Free resources */
+ g_slice_free (RecurseFoldersAsyncHelper, helper);
+ }
}
-gint
-modest_tny_folder_store_get_local_size (TnyFolderStore *self)
+void
+modest_tny_folder_store_get_folder_stats (TnyFolderStore *self,
+ GetFolderStatsCallback callback,
+ GetFolderStatsCallback status_callback,
+ gpointer user_data)
{
- RecurseFoldersHelper *helper;
- gint retval;
+ RecurseFoldersAsyncHelper *helper;
+ TnyList *folders;
- g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1);
+ g_return_if_fail (TNY_IS_FOLDER_STORE (self));
/* Create helper */
- helper = g_malloc0 (sizeof (RecurseFoldersHelper));
- helper->task = TASK_GET_LOCAL_SIZE;
- if (TNY_IS_FOLDER (self))
- helper->sum = tny_folder_get_local_size (TNY_FOLDER (self));
-
- recurse_folders (self, NULL, helper);
-
- retval = helper->sum;
-
- g_free (helper);
+ helper = g_slice_new0 (RecurseFoldersAsyncHelper);
+ helper->pending_calls = 1;
+ helper->callback = callback;
+ helper->status_callback = status_callback;
+ helper->user_data = user_data;
+
+ if (TNY_IS_FOLDER (self)) {
+ helper->stats.msg_count = tny_folder_get_all_count (TNY_FOLDER (self));
+ helper->stats.local_size = tny_folder_get_local_size (TNY_FOLDER (self));
+ }
- return retval;
+ folders = tny_simple_list_new ();
+ tny_folder_store_get_folders_async (TNY_FOLDER_STORE (self),
+ folders, NULL,
+ recurse_folders_async_cb,
+ NULL, helper);
+ g_object_unref (folders);
}
const gchar*