X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-account.c;h=04bc796aa538b36a577d12680a8a77fc554c707e;hp=2496a16c298577d965e6e16ceb8cfa1cec42833d;hb=092fe34f03c3165f87be7e09877bb614c468590f;hpb=a87b228eaa0848907bd3e7f722d644dc1cb2dbd4 diff --git a/src/modest-tny-account.c b/src/modest-tny-account.c index 2496a16..04bc796 100644 --- a/src/modest-tny-account.c +++ b/src/modest-tny-account.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #ifdef MODEST_PLATFORM_MAEMO @@ -274,7 +275,10 @@ update_tny_account (TnyAccount *tny_account, 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. @@ -285,7 +289,7 @@ update_tny_account (TnyAccount *tny_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; @@ -294,33 +298,35 @@ update_tny_account (TnyAccount *tny_account, 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) { @@ -331,8 +337,6 @@ update_tny_account (TnyAccount *tny_account, 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 = NULL; else auth_mech_name = MODEST_ACCOUNT_AUTH_PLAIN; break; @@ -360,16 +364,16 @@ update_tny_account (TnyAccount *tny_account, break; } - if(auth_mech_name) + if (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); @@ -529,13 +533,6 @@ modest_tny_account_update_from_account (TnyAccount *tny_account, g_object_unref (server_settings); g_object_unref (settings); - tny_account_set_forget_pass_func (tny_account, NULL); - tny_account_set_pass_func (tny_account, NULL); - 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); - tny_account_set_connection_policy (tny_account, modest_default_connection_policy_new ()); /* The callback will have an error for you if the reconnect @@ -902,119 +899,109 @@ modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *ac -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; - - 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); + TnyList *folders = NULL; + TnyFolderStore *folder = NULL; - 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)); -} + g_object_unref (G_OBJECT (iter)); -gint -modest_tny_folder_store_get_folder_count (TnyFolderStore *self) -{ - RecurseFoldersHelper *helper; - gint retval; +next_folder: + /* Remove my own pending call */ + helper->pending_calls--; - g_return_val_if_fail (TNY_IS_FOLDER_STORE (self), -1); + /* This means that we have all the folders */ + if (helper->pending_calls == 0) { + /* notify */ + if (helper->callback) + helper->callback (helper->stats, helper->user_data); - /* Create helper */ - helper = g_malloc0 (sizeof (RecurseFoldersHelper)); - helper->task = TASK_GET_FOLDER_COUNT; - helper->folders = 0; - - recurse_folders (self, NULL, helper); - - retval = helper->folders; - - 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*