NULL);
TnyAccount *local_account = NULL;
-
+
/* The accounts have already been instantiated by
* modest_tny_account_store_get_accounts(), which is the
* TnyAccountStore::get_accounts_func() implementation,
}
-
+#if 0
gboolean
modest_tny_account_update_from_server_account_name (TnyAccount *tny_account,
ModestAccountMgr *account_mgr,
modest_account_mgr_free_server_account_data (account_mgr, account_data);
return TRUE;
}
-
+#endif
/* intentionally left blank */
}
+
+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. */
+
+ if (err && !canceled)
+ g_warning ("err: %s", err->message);
+}
+
+gboolean
+modest_tny_account_update_from_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
+ const gchar *account_name, TnyAccountType type)
+{
+ ModestAccountData *account_data = NULL;
+ ModestServerAccountData *server_data = NULL;
+ TnyConnectionStatus conn_status;
+
+ g_return_val_if_fail (tny_account, FALSE);
+ g_return_val_if_fail (account_mgr, FALSE);
+ g_return_val_if_fail (account_name, FALSE);
+ g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT,
+ FALSE);
+
+ account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
+ if (!account_data) {
+ g_printerr ("modest: %s: cannot get account data for account %s\n",
+ __FUNCTION__, account_name);
+ return FALSE;
+ }
+
+ if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
+ server_data = account_data->store_account;
+ else if (type == TNY_ACCOUNT_TYPE_TRANSPORT && account_data->transport_account)
+ server_data = account_data->transport_account;
+ if (!server_data) {
+ g_printerr ("modest: no %s account defined for '%s'\n",
+ type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
+ account_data->display_name);
+ modest_account_mgr_free_account_data (account_mgr, account_data);
+ return FALSE;
+ }
+
+ update_tny_account (tny_account, account_mgr, server_data);
+
+ /* This name is what shows up in the folder view -- so for some POP/IMAP/... server
+ * account, we set its name to the account of which it is part. */
+
+ if (account_data->display_name)
+ tny_account_set_name (tny_account, account_data->display_name);
+
+ modest_account_mgr_free_account_data (account_mgr, account_data);
+
+ /* If the account was online, reconnect to apply the changes */
+ conn_status = tny_account_get_connection_status (tny_account);
+ if (conn_status != TNY_CONNECTION_STATUS_DISCONNECTED) {
+
+ /* The callback will have an error for you if the reconnect
+ * failed. Please handle it (this is TODO). */
+
+ tny_camel_account_set_online (TNY_CAMEL_ACCOUNT(tny_account), TRUE,
+ set_online_callback, "online");
+ }
+
+ return TRUE;
+}
+
+
+
TnyAccount*
modest_tny_account_new_from_account (ModestAccountMgr *account_mgr,
const gchar *account_name,
g_return_val_if_fail (account_mgr, NULL);
g_return_val_if_fail (account_name, NULL);
g_return_val_if_fail (session, NULL);
+ g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT,
+ NULL);
account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
if (!account_data) {
tny_account_set_pass_func (tny_account,
get_pass_func ? get_pass_func: get_pass_dummy);
-
- modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account, account_name);
-
+ modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account,
+ account_name);
modest_account_mgr_free_account_data (account_mgr, account_data);
return tny_account;
}
/* printf ("DEBUG: %s: display name=%s\n", __FUNCTION__, display_name); */
- tny_account_set_name (account, display_name);
+ if (display_name && previous_display_name &&
+ (strcmp (display_name, previous_display_name) != 0)) {
+ tny_account_set_name (account, display_name);
+ }
/* Inform the application that the name is now ready: */
if (callback_data->callback)
/* Create helper */
helper = g_malloc0 (sizeof (RecurseFoldersHelper));
helper->task = TASK_GET_FOLDER_COUNT;
- helper->sum = 0;
helper->folders = 0;
recurse_folders (self, NULL, helper);
/* Create helper */
helper = g_malloc0 (sizeof (RecurseFoldersHelper));
helper->task = TASK_GET_ALL_COUNT;
- helper->sum = 0;
+ if (TNY_IS_FOLDER (self))
+ helper->sum = tny_folder_get_all_count (TNY_FOLDER (self));
recurse_folders (self, NULL, helper);
/* Create helper */
helper = g_malloc0 (sizeof (RecurseFoldersHelper));
helper->task = TASK_GET_LOCAL_SIZE;
- helper->sum = 0;
+ if (TNY_IS_FOLDER (self))
+ helper->sum = tny_folder_get_local_size (TNY_FOLDER (self));
recurse_folders (self, NULL, helper);
void
modest_tny_account_set_parent_modest_account_name_for_server_account (TnyAccount *self,
- const gchar* parent_modest_acount_name)
+ const gchar* parent_modest_account_name)
{
g_object_set_data_full (G_OBJECT(self), "modest_account",
- (gpointer) g_strdup (parent_modest_acount_name), g_free);
+ (gpointer) g_strdup (parent_modest_account_name), g_free);
}
gboolean