+/* This is the callback of the tny_camel_account_set_online called in
+ on_account_removed to disconnect the account */
+static void
+on_account_disconnect_when_removing (TnyCamelAccount *account,
+ gboolean canceled,
+ GError *err,
+ gpointer user_data)
+{
+ ModestTnyAccountStore *self;
+ ModestTnyAccountStorePrivate *priv;
+
+ self = MODEST_TNY_ACCOUNT_STORE (user_data);
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
+
+ if (canceled || err) {
+ /* The account was not cancelled */
+ } else {
+ /* Clear the cache if it's an store account */
+ if (TNY_IS_STORE_ACCOUNT (account))
+ tny_store_account_delete_cache (TNY_STORE_ACCOUNT (account));
+ }
+
+ /* Remove it from the list of accounts */
+ if (TNY_IS_STORE_ACCOUNT (account))
+ tny_list_remove (priv->store_accounts, (GObject *) account);
+ else
+ tny_list_remove (priv->transport_accounts, (GObject *) account);
+
+ /* Notify the observers */
+ g_signal_emit (G_OBJECT (self), signals [ACCOUNT_REMOVED_SIGNAL],
+ 0, account);
+
+ /* Unref the extra reference added by get_server_account */
+ g_object_unref (account);
+}
+