return account;
}
+typedef struct _AddOutboxInfo {
+ ModestTnyAccountStore *account_store;
+ TnyAccount *transport_account;
+} AddOutboxInfo;
static void
-add_outbox_from_transport_account_to_global_outbox (ModestTnyAccountStore *self,
- const gchar *account_name,
- TnyAccount *transport_account)
+add_outbox_from_transport_account_to_global_outbox_get_folders_cb (TnyFolderStore *folder_store,
+ gboolean cancelled,
+ TnyList *list,
+ GError *err,
+ gpointer userdata)
{
- TnyList *folders = NULL;
- TnyIterator *iter_folders = NULL;
- TnyAccount *local_account = NULL, *account_outbox = NULL;
- TnyFolder *per_account_outbox = NULL;
+ TnyIterator *iter_folders;
+ TnyFolder *per_account_outbox;
+ TnyAccount *local_account = NULL;
+ AddOutboxInfo *info = (AddOutboxInfo *) userdata;
ModestTnyAccountStorePrivate *priv = NULL;
+ ModestTnyAccountStore *self;
+ self = MODEST_TNY_ACCOUNT_STORE (info->account_store);
priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-
- /* Create per account local outbox */
- account_outbox =
- modest_tny_account_new_for_per_account_local_outbox_folder (priv->account_mgr,
- account_name,
- priv->session);
- tny_list_append (priv->store_accounts_outboxes, G_OBJECT (account_outbox));
-
- /* Get the outbox folder */
- folders = tny_simple_list_new ();
- tny_folder_store_get_folders (TNY_FOLDER_STORE (account_outbox), folders, NULL, NULL);
- if (tny_list_get_length (folders) != 1) {
+
+ if (tny_list_get_length (list) != 1) {
g_warning ("%s: > 1 outbox found (%d)?!", __FUNCTION__,
- tny_list_get_length (folders));
+ tny_list_get_length (list));
}
- iter_folders = tny_list_create_iterator (folders);
+ iter_folders = tny_list_create_iterator (list);
per_account_outbox = TNY_FOLDER (tny_iterator_get_current (iter_folders));
g_object_unref (iter_folders);
- g_object_unref (folders);
- g_object_unref (account_outbox);
+ g_object_unref (list);
/* Add the outbox of the new per-account-local-outbox account
to the global local merged OUTBOX of the local folders
account */
- local_account = modest_tny_account_store_get_local_folders_account (self);
+ local_account = modest_tny_account_store_get_local_folders_account (info->account_store);
modest_tny_local_folders_account_add_folder_to_outbox (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (local_account),
per_account_outbox);
/* Add the pair to the hash table */
g_hash_table_insert (priv->outbox_of_transport,
- transport_account,
+ info->transport_account,
per_account_outbox);
+ /* Notify that the local account changed */
+ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_CHANGED_SIGNAL], 0, local_account);
+
+ g_object_unref (info->transport_account);
g_object_unref (local_account);
g_object_unref (per_account_outbox);
+ g_slice_free (AddOutboxInfo, info);
+}
+
+
+static void
+add_outbox_from_transport_account_to_global_outbox (ModestTnyAccountStore *self,
+ const gchar *account_name,
+ TnyAccount *transport_account)
+{
+ TnyList *folders = NULL;
+ TnyAccount *account_outbox = NULL;
+ ModestTnyAccountStorePrivate *priv = NULL;
+ AddOutboxInfo *info;
+
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ /* Create per account local outbox */
+ account_outbox =
+ modest_tny_account_new_for_per_account_local_outbox_folder (priv->account_mgr,
+ account_name,
+ priv->session);
+
+ if (!G_IS_OBJECT (account_outbox)) {
+ g_warning ("%s: could not create per account local outbox folder", __FUNCTION__);
+ return;
+ }
+
+ tny_list_append (priv->store_accounts_outboxes, G_OBJECT (account_outbox));
+
+ /* Get the outbox folder */
+ folders = tny_simple_list_new ();
+ info = g_slice_new0 (AddOutboxInfo);
+ info->account_store = self;
+ info->transport_account = g_object_ref (transport_account);
+ tny_folder_store_get_folders_async (TNY_FOLDER_STORE (account_outbox), folders, NULL,
+ add_outbox_from_transport_account_to_global_outbox_get_folders_cb, NULL, (gpointer) info);
+ g_object_unref (account_outbox);
}
/*
/* Create a new pseudo-account with an outbox for this
transport account and add it to the global outbox
in the local account */
- add_outbox_from_transport_account_to_global_outbox (self, account, transport_account);
-
+ add_outbox_from_transport_account_to_global_outbox (self, account, transport_account);
+
/* Notify the observers. We do it after everything is
created */
if (notify) {
- TnyAccount *local_account = NULL;
-
- /* Notify the observers about the new server & transport accounts */
g_signal_emit (G_OBJECT (self), signals [ACCOUNT_INSERTED_SIGNAL], 0, store_account);
g_signal_emit (G_OBJECT (self), signals [ACCOUNT_INSERTED_SIGNAL], 0, transport_account);
-
- /* Notify that the local account changed */
- local_account = modest_tny_account_store_get_local_folders_account (self);
- g_signal_emit (G_OBJECT (self), signals [ACCOUNT_CHANGED_SIGNAL], 0, local_account);
- g_object_unref (local_account);
}
/* Frees */
g_object_unref (account);
/* Clear the cache if it's an store account */
- if (TNY_IS_STORE_ACCOUNT (account))
+ if (TNY_IS_STORE_ACCOUNT (account)) {
tny_store_account_delete_cache (TNY_STORE_ACCOUNT (account));
+ } else if (TNY_IS_TRANSPORT_ACCOUNT (account)) {
+ ModestTnySendQueue* send_queue;
+ send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT (account), FALSE);
+ if (send_queue) {
+ if (modest_tny_send_queue_sending_in_progress (send_queue))
+ tny_send_queue_cancel (TNY_SEND_QUEUE (send_queue),
+ TNY_SEND_QUEUE_CANCEL_ACTION_REMOVE,
+ NULL);
+ modest_runtime_remove_send_queue (TNY_TRANSPORT_ACCOUNT (account));
+ }
+ }
}
static void
if (outbox_account) {
tny_list_remove (priv->store_accounts_outboxes, G_OBJECT (outbox_account));
+ /* Remove existing emails to send */
+ tny_store_account_delete_cache (TNY_STORE_ACCOUNT (outbox_account));
g_object_unref (outbox_account);
}
local_account = modest_tny_account_store_get_local_folders_account (self);
modest_tny_local_folders_account_remove_folder_from_outbox (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (local_account),
outbox);
+
g_hash_table_remove (priv->outbox_of_transport, transport_account);
/* Notify the change in the local account */
TnyTransportAccount *account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current (acc_iter));
ModestTnySendQueue *send_queue;
ModestTnySendQueueStatus status;
- send_queue = modest_runtime_get_send_queue(TNY_TRANSPORT_ACCOUNT(account));
+ send_queue = modest_runtime_get_send_queue(TNY_TRANSPORT_ACCOUNT(account), TRUE);
status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
if (status != MODEST_TNY_SEND_QUEUE_UNKNOWN) {
header_acc = g_object_ref(account);
found = g_hash_table_lookup_extended (priv->account_settings_dialog_hash,
account_name, NULL, (gpointer*)&dialog_as_gpointer);
- if (found)
+ if (found) {
+ modest_account_settings_dialog_check_allow_changes ((ModestAccountSettingsDialog *) dialog_as_gpointer);
return (GtkWidget *) dialog_as_gpointer;
- else {
+ } else {
ModestAccountSettings *settings;
GtkWidget *dialog;
dialog = (GtkWidget *) modest_account_settings_dialog_new ();
modest_account_settings_dialog_set_account (MODEST_ACCOUNT_SETTINGS_DIALOG (dialog), settings);
g_object_unref (settings);
modest_account_settings_dialog_switch_to_user_info (MODEST_ACCOUNT_SETTINGS_DIALOG (dialog));
+ modest_account_settings_dialog_check_allow_changes (MODEST_ACCOUNT_SETTINGS_DIALOG (dialog));
modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
g_hash_table_insert (priv->account_settings_dialog_hash, g_strdup (account_name), dialog);