* ModestAccountMgr: the account manager is just a facade to the configuration...
authorSergio Villar Senin <svillar@igalia.com>
Mon, 23 Jul 2007 16:38:03 +0000 (16:38 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Mon, 23 Jul 2007 16:38:03 +0000 (16:38 +0000)
not know TnyAccounts only ModestAccounts. TnyAccounts are managed by the TnyAccountStore
        - removed the server_account parametter from the account_removed signal
        - removed the server_account parametter from the remove_account method
        - Changed the signature of the methods that handled the signal
        - completetly rewritten the account removal code
        * ModestTnyAccountStore
        - now it issues a account_removed for both the store and the transport account
        - completety rewritten the get_server_account method, it makes no sense to use the account mgr, because we h
ave the accounts
        * ModestFolderView
        - added a missing check
        - added a missing select inbox
- added a condition to the filter_row method, do not take into account the visible_account_id if we aren't in SHOW_ONE style

pmo-trunk-r2774

src/maemo/easysetup/modest-easysetup-wizard.c
src/maemo/modest-account-view-window.c
src/maemo/modest-msg-view-window.c
src/modest-account-mgr.c
src/modest-account-mgr.h
src/modest-mail-operation.c
src/modest-tny-account-store.c
src/widgets/modest-account-view.c
src/widgets/modest-folder-view.c

index 70c6336..56377c8 100644 (file)
@@ -1029,7 +1029,7 @@ on_response (ModestWizardDialog *wizard_dialog,
                /* Remove any temporarily-saved account that will not actually be needed: */
                if (self->saved_account_name) {
                        modest_account_mgr_remove_account (self->account_manager,
-                                                          self->saved_account_name, FALSE);
+                                                          self->saved_account_name);
                }
        }
 
index 7e57a0d..a22c47b 100644 (file)
@@ -191,9 +191,7 @@ on_delete_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
                                is_default = TRUE;
                        g_free (default_account_name);
                                
-                       gboolean removed = modest_account_mgr_remove_account (account_mgr,
-                                                                            account_name,
-                                                                            FALSE);
+                       gboolean removed = modest_account_mgr_remove_account (account_mgr, account_name);
                        if (!removed) {
                                g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);
                        }
index b136be5..a431f2a 100644 (file)
@@ -89,27 +89,30 @@ static void modest_msg_view_window_clipboard_owner_change (GtkClipboard *clipboa
                                                           GdkEvent *event,
                                                           ModestMsgViewWindow *window);
 
-static void cancel_progressbar (GtkToolButton *toolbutton,
-                               ModestMsgViewWindow *self);
+static void cancel_progressbar  (GtkToolButton *toolbutton,
+                                ModestMsgViewWindow *self);
 
-static void         on_queue_changed                     (ModestMailOperationQueue *queue,
-                                                         ModestMailOperation *mail_op,
-                                                         ModestMailOperationQueueNotification type,
-                                                         ModestMsgViewWindow *self);
-static void on_account_removed (ModestAccountMgr *obj,
-                                const gchar *account,
-                                gboolean server_account,
-                                gpointer user_data);
+static void on_queue_changed    (ModestMailOperationQueue *queue,
+                                ModestMailOperation *mail_op,
+                                ModestMailOperationQueueNotification type,
+                                ModestMsgViewWindow *self);
 
-static void view_msg_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg, gpointer user_data);
+static void on_account_removed  (TnyAccountStore *account_store, 
+                                TnyAccount *account,
+                                gpointer user_data);
 
-static void set_toolbar_mode (ModestMsgViewWindow *self, 
-                             ModestToolBarModes mode);
+static void view_msg_cb         (ModestMailOperation *mail_op, 
+                                TnyHeader *header, 
+                                TnyMsg *msg, 
+                                gpointer user_data);
 
-static gboolean set_toolbar_transfer_mode     (ModestMsgViewWindow *self); 
+static void set_toolbar_mode    (ModestMsgViewWindow *self, 
+                                ModestToolBarModes mode);
 
 static void update_window_title (ModestMsgViewWindow *window);
 
+static gboolean set_toolbar_transfer_mode     (ModestMsgViewWindow *self); 
+
 
 /* list my signals */
 enum {
@@ -446,15 +449,18 @@ modest_msg_view_window_finalize (GObject *obj)
 
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (obj);
        if (priv->clipboard_change_handler > 0) {
-               g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_PRIMARY), priv->clipboard_change_handler);
+               g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_PRIMARY), 
+                                            priv->clipboard_change_handler);
                priv->clipboard_change_handler = 0;
        }
        if (priv->queue_change_handler > 0) {
-               g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()), priv->queue_change_handler);
+               g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()), 
+                                            priv->queue_change_handler);
                priv->queue_change_handler = 0;
        }
        if (priv->account_removed_handler > 0) {
-               g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_account_mgr ()), priv->account_removed_handler);
+               g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_account_store ()), 
+                                            priv->account_removed_handler);
                priv->account_removed_handler = 0;
        }
        if (priv->header_model != NULL) {
@@ -676,8 +682,8 @@ modest_msg_view_window_new (TnyMsg *msg,
                                                       obj);
 
        /* Account manager */
-       priv->account_removed_handler = g_signal_connect (G_OBJECT(modest_runtime_get_account_mgr()),
-                                                         "account-removed",
+       priv->account_removed_handler = g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),
+                                                         "account_removed",
                                                          G_CALLBACK(on_account_removed),
                                                          obj);
 
@@ -1584,25 +1590,20 @@ observers_empty (ModestMsgViewWindow *self)
 }
 
 static void
-on_account_removed (ModestAccountMgr *mgr,
-                    const gchar *account,
-                   gboolean server_account,
+on_account_removed (TnyAccountStore *account_store, 
+                   TnyAccount *account,
                    gpointer user_data)
 {
-       ModestTnyAccountStore *store;
-       const gchar *our_acc;
-       TnyAccount *tny_acc;
-
-       store = modest_runtime_get_account_store ();
-       our_acc = modest_window_get_active_account (MODEST_WINDOW (user_data));
-       tny_acc = modest_tny_account_store_get_tny_account_by (store, 
-                                                              MODEST_TNY_ACCOUNT_STORE_QUERY_ID, 
-                                                              account);
+       /* Do nothing if it's a transport account, because we only
+          show the messages of a store account */
+       if (tny_account_get_account_type(account) == TNY_ACCOUNT_TYPE_STORE) {
+               const gchar *parent_acc = NULL;
+               const gchar *our_acc = NULL;
 
+               our_acc = modest_window_get_active_account (MODEST_WINDOW (user_data));
+               parent_acc = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
 
-       if(tny_acc != NULL) {
-               const gchar* parent_acc = 
-                       modest_tny_account_get_parent_modest_account_name_for_server_account (tny_acc);
+               /* Close this window if I'm showing a message of the removed account */
                if (strcmp (parent_acc, our_acc) == 0)
                        modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (user_data));
        }
index 6a59bec..46ed9d4 100644 (file)
@@ -186,8 +186,8 @@ modest_account_mgr_class_init (ModestAccountMgrClass * klass)
                              G_SIGNAL_RUN_FIRST,
                              G_STRUCT_OFFSET(ModestAccountMgrClass,account_removed),
                              NULL, NULL,
-                             modest_marshal_VOID__STRING_BOOLEAN,
-                             G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN);
+                             g_cclosure_marshal_VOID__STRING,
+                             G_TYPE_NONE, 1, G_TYPE_STRING);
        signals[ACCOUNT_CHANGED_SIGNAL] =
                g_signal_new ("account_changed",
                               G_TYPE_FROM_CLASS (klass),
@@ -531,68 +531,67 @@ modest_account_mgr_add_server_account_uri (ModestAccountMgr * self,
        return TRUE;
 }
 
+/* 
+ * Utility function used by modest_account_mgr_remove_account
+ */
+static void
+real_remove_account (ModestConf *conf,
+                    const gchar *acc_name,
+                    gboolean server_account)
+{
+       GError *err = NULL;
+       gchar *key = NULL;
+
+       key = _modest_account_mgr_get_account_keyname (acc_name, NULL, server_account);
+       modest_conf_remove_key (conf, key, &err);
+       g_free (key);       
+
+       if (err) {
+               g_printerr ("modest: error removing key: %s\n", err->message);
+               g_error_free (err);
+       }
+}
+
 gboolean
 modest_account_mgr_remove_account (ModestAccountMgr * self,
-                                  const gchar* name,  gboolean server_account)
+                                  const gchar* name)
 {
        ModestAccountMgrPrivate *priv;
-       gchar *key;
-       gboolean retval, default_account_deleted;
-       GError *err = NULL;
+       gchar *default_account_name, *store_acc_name, *transport_acc_name;
+       gboolean default_account_deleted;
 
        g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE);
        g_return_val_if_fail (name, FALSE);
 
-       if (!modest_account_mgr_account_exists (self, name, server_account)) {
+       if (!modest_account_mgr_account_exists (self, name, FALSE)) {
                g_printerr ("modest: %s: account '%s' does not exist\n", __FUNCTION__, name);
                return FALSE;
        }
 
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        default_account_deleted = FALSE;
 
-       if (!server_account) {
-               gchar *server_account_name, *default_account_name;
-
-               /* If this was the default, then remove that setting: */
-               default_account_name = modest_account_mgr_get_default_account (self);
-               if (default_account_name && (strcmp (default_account_name, name) == 0)) {
-                       modest_account_mgr_unset_default_account (self);
-                       default_account_deleted = TRUE;
-               }
-               g_free (default_account_name);
-
-               /* in case we're deleting an account, also delete the dependent store and transport account */
-               server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_STORE_ACCOUNT,
-                                                                   FALSE);
-               if (server_account_name) {
-                       if (!modest_account_mgr_remove_account (self, server_account_name, TRUE))
-                               g_printerr ("modest: failed to remove store account '%s' (%s)\n",
-                                           server_account_name, name);
-                       g_free (server_account_name);
-               } else
-                       g_printerr ("modest: could not find the store account for %s\n", name);
-               
-               server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_TRANSPORT_ACCOUNT,
-                                                                   FALSE);
-               if (server_account_name) {
-                       if (!modest_account_mgr_remove_account (self, server_account_name, TRUE))
-                               g_printerr ("modest: failed to remove transport account '%s' (%s)\n",
-                                           server_account_name, name);
-                       g_free (server_account_name);
-               } else
-                       g_printerr ("modest: could not find the transport account for %s\n", name);
+       /* If this was the default, then remove that setting: */
+       default_account_name = modest_account_mgr_get_default_account (self);
+       if (default_account_name && (strcmp (default_account_name, name) == 0)) {
+               modest_account_mgr_unset_default_account (self);
+               default_account_deleted = TRUE;
        }
+       g_free (default_account_name);
+
+       /* Delete transport and store accounts */
+       store_acc_name = modest_account_mgr_get_string (self, name, 
+                                                       MODEST_ACCOUNT_STORE_ACCOUNT, FALSE);
+       if (store_acc_name)
+               real_remove_account (priv->modest_conf, store_acc_name, TRUE);
+
+       transport_acc_name = modest_account_mgr_get_string (self, name, 
+                                                           MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE);
+       if (transport_acc_name)
+               real_remove_account (priv->modest_conf, transport_acc_name, TRUE);
                        
-       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-       key = _modest_account_mgr_get_account_keyname (name, NULL, server_account);
-       
-       retval = modest_conf_remove_key (priv->modest_conf, key, &err);
-       g_free (key);
-
-       if (err) {
-               g_printerr ("modest: error removing key: %s\n", err->message);
-               g_error_free (err);
-       }
+       /* Remove the modest account */
+       real_remove_account (priv->modest_conf, name, FALSE);
 
        if (default_account_deleted) {  
                /* pick another one as the new default account. We do
@@ -601,16 +600,13 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                   deleted account */
                modest_account_mgr_set_first_account_as_default (self);
        }
+       
+       /* Notify the observers. We do this *after* deleting
+          the keys, because otherwise a call to account_names
+          will retrieve also the deleted account */
+       g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, name);
 
-       if (server_account) {
-               /* Notify the observers. We do this *after* deleting
-                  the keys, because otherwise a call to account_names
-                  will retrieve also the deleted account */
-               g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0,
-                              name, server_account);
-       }
-
-       return retval;
+       return TRUE;
 }
 
 
index 6510cf3..9fc6e16 100644 (file)
@@ -58,18 +58,18 @@ struct _ModestAccountMgrClass {
 
        void (* account_removed)   (ModestAccountMgr *obj, 
                                    const gchar* account,
-                                   gboolean server_account,
                                    gpointer user_data);
+
        void (* account_changed)   (ModestAccountMgr *obj, 
                                    const gchar* account,
                                    const GSList* key, 
                                    gboolean server_account,
                                    gpointer user_data);
+
        void (* account_busy_changed)   (ModestAccountMgr *obj, 
                                    const gchar* account,
                                    gboolean busy,
-                                   gpointer user_data);
-       
+                                   gpointer user_data);        
 };
 
 /**
@@ -159,7 +159,6 @@ gboolean modest_account_mgr_add_server_account_uri    (ModestAccountMgr *self,
  * modest_account_mgr_remove_account:
  * @self: a ModestAccountMgr instance
  * @name: the name of the account to remove
- * @server_account: TRUE if the account to remove is a server account
  * @err: a #GError ptr, or NULL to ignore.
  * 
  * remove an existing account. the account with @name should already exist; note
@@ -170,9 +169,7 @@ gboolean modest_account_mgr_add_server_account_uri    (ModestAccountMgr *self,
  * @err gives details in case of error
  */
 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
-                                                          const gchar* name,
-                                                          gboolean server_account);
-
+                                                          const gchar* name);
 
 /**
  * modest_account_mgr_account_names:
index 39dbea7..0d8447e 100644 (file)
@@ -1160,7 +1160,7 @@ update_account_thread (gpointer thr_user_data)
         * for POP3, we do a logout-login upon send/receive -- many POP-servers (like Gmail) do not
         * show any updates unless we do that
         */
-       if (!first_time && TNY_IS_CAMEL_POP_STORE_ACCOUNT(priv->account)) 
+       if (!first_time && TNY_IS_CAMEL_POP_STORE_ACCOUNT (priv->account)) 
                tny_camel_pop_store_account_reconnect (TNY_CAMEL_POP_STORE_ACCOUNT(priv->account));
 
        /* Get all the folders. We can do it synchronously because
index fc6c5b1..8211b78 100644 (file)
@@ -343,37 +343,31 @@ on_vfs_volume_unmounted(GnomeVFSVolumeMonitor *volume_monitor,
 static void
 on_account_removed (ModestAccountMgr *acc_mgr, 
                    const gchar *account,
-                   gboolean is_server_account,
                    gpointer user_data)
 {
+       TnyAccount *store_account = NULL, *transport_account = NULL;
        ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
-       TnyAccount *server_account;
        
-       /* Clear the account cache */
-       server_account = modest_tny_account_store_get_tny_account_by  (self, 
-                                                                     MODEST_TNY_ACCOUNT_STORE_QUERY_ID, 
-                                                                     account);
-       if (server_account) {
-               if (TNY_IS_STORE_ACCOUNT (server_account)) {
-
-                       tny_store_account_delete_cache (TNY_STORE_ACCOUNT (server_account));
-               
-                       g_signal_emit (G_OBJECT (self), 
-                                      tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNT_REMOVED], 
-                                      0, server_account);
-
-/*                     /\* FIXME: make this more finegrained; changes do not */
-/*                      * really affect _all_ accounts, and some do not */
-/*                      * affect tny accounts at all (such as 'last_update') */
-/*                      *\/ */
-/*                     recreate_all_accounts (self); */
-                       
-/*                     g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0, */
-/*                                    account); */
-               }
-               g_object_unref (server_account);
-       } else
-               g_printerr ("modest: cannot find server account for %s", account);
+       /* Get the server and the transport account */
+       store_account = 
+               modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_STORE);
+       transport_account = 
+               modest_tny_account_store_get_server_account (self, account, TNY_ACCOUNT_TYPE_TRANSPORT);
+
+       /* Clear the cache */
+       tny_store_account_delete_cache (TNY_STORE_ACCOUNT (store_account));
+
+       /* Notify the observers */
+       g_signal_emit (G_OBJECT (self),
+                      tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNT_REMOVED],
+                      0, store_account);
+       g_signal_emit (G_OBJECT (self),
+                      tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNT_REMOVED],
+                      0, transport_account);
+
+       /* Frees */
+       g_object_unref (store_account);
+       g_object_unref (transport_account);
 }
 
 /**
@@ -1517,59 +1511,50 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self,
 
 TnyAccount*
 modest_tny_account_store_get_server_account (ModestTnyAccountStore *self,
-                                                    const gchar *account_name,
-                                                    TnyAccountType type)
+                                            const gchar *account_name,
+                                            TnyAccountType type)
 {
+       ModestTnyAccountStorePrivate *priv = NULL;
        TnyAccount *account = NULL;
-       gchar *id = NULL;
-       ModestTnyAccountStorePrivate *priv;     
+       GSList *account_list = NULL;
+       gboolean found = FALSE;
 
        g_return_val_if_fail (self, NULL);
        g_return_val_if_fail (account_name, NULL);
-       g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || type == TNY_ACCOUNT_TYPE_TRANSPORT,
+       g_return_val_if_fail (type == TNY_ACCOUNT_TYPE_STORE || 
+                             type == TNY_ACCOUNT_TYPE_TRANSPORT,
                              NULL);
        
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
-       /* Special case for the local account */
-       if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
-               if(type == TNY_ACCOUNT_TYPE_STORE)
-                       id = g_strdup (MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
-               else {
-                       /* The local folders modest account has no transport server account. */
-                       return NULL;
-               }
-       } else {
-               ModestAccountData *account_data;
-               account_data = modest_account_mgr_get_account_data (priv->account_mgr, account_name);
-               if (!account_data) {
-                       g_printerr ("modest: %s: cannot get account data for account '%s'\n", __FUNCTION__,
-                                   account_name);
-                       return NULL;
-               }
-
-               if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
-                       id = g_strdup (account_data->store_account->account_name);
-               else if (type == TNY_ACCOUNT_TYPE_TRANSPORT && account_data->transport_account)
-                       id = g_strdup (account_data->transport_account->account_name);
+       account_list = (type == TNY_ACCOUNT_TYPE_STORE) ? 
+               priv->store_accounts : 
+               priv->transport_accounts;
+       
+       /* Look for the server account */
+       while (account_list && !found) {
+               const gchar *modest_acc_name;
 
-               modest_account_mgr_free_account_data (priv->account_mgr, account_data);
+               account = TNY_ACCOUNT (account_list->data);;
+               modest_acc_name = 
+                       modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+               
+               if (!strcmp (account_name, modest_acc_name))
+                       found = TRUE;
+               else
+                       account_list = g_slist_next (account_list);     
        }
 
-       if (!id)
-               g_printerr ("modest: could not get an id for account %s\n",
+       if (!found) {
+               g_printerr ("modest: could not get tny %s account for %s\n",
+                           (type == TNY_ACCOUNT_TYPE_STORE) ? "store" : "transport",
                            account_name);
-       else    
-               account = modest_tny_account_store_get_tny_account_by (self, 
-                                                                      MODEST_TNY_ACCOUNT_STORE_QUERY_ID, id);
-
-       if (!account)
-               g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
-                           type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
-                           account_name, id ? id : "<none>");
-       g_free (id);
+       } else {
+               /* Pick a reference */
+               g_object_ref (account);
+       }
 
-       return account; 
+       return account;
 }
 
 static TnyAccount*
index da7af15..fbac3d9 100644 (file)
@@ -144,7 +144,8 @@ modest_account_view_finalize (GObject *obj)
 
        if (priv->account_mgr) {
                if (priv->sig1)
-                       g_signal_handler_disconnect (priv->account_mgr, priv->sig1);
+                       g_signal_handler_disconnect (modest_runtime_get_account_store (), 
+                                                    priv->sig1);
 
                if (priv->sig2)
                        g_signal_handler_disconnect (priv->account_mgr, priv->sig2);
@@ -312,11 +313,17 @@ on_account_busy_changed(ModestAccountMgr *account_mgr, const gchar *account_name
 }
 
 static void
-on_account_removed (ModestAccountMgr *account_mgr,
-                   const gchar* account, gboolean server_account,
-                   ModestAccountView *self)
-{               
-       update_account_view (account_mgr, self);
+on_account_removed (TnyAccountStore *account_store, 
+                   TnyAccount *account,
+                   gpointer user_data)
+{
+       ModestAccountView *self;
+       ModestAccountViewPrivate *priv;
+
+       self = MODEST_ACCOUNT_VIEW (user_data);
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
+
+       update_account_view (priv->account_mgr, MODEST_ACCOUNT_VIEW (user_data));
 }
 
 
@@ -491,7 +498,7 @@ init_view (ModestAccountView *self)
         */                     
        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(self), TRUE);
 
-       priv->sig1 = g_signal_connect (G_OBJECT(priv->account_mgr),"account_removed",
+       priv->sig1 = g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),"account_removed",
                                       G_CALLBACK(on_account_removed), self);
        priv->sig2 = g_signal_connect (G_OBJECT(priv->account_mgr), "account_changed",
                                       G_CALLBACK(on_account_changed), self);
index 834b647..e026ccb 100644 (file)
@@ -126,7 +126,8 @@ static gint         expand_row_timeout     (gpointer data);
 
 static void         setup_drag_and_drop    (GtkTreeView *self);
 
-static gboolean     _clipboard_set_selected_data (ModestFolderView *folder_view, gboolean delete);
+static gboolean     _clipboard_set_selected_data (ModestFolderView *folder_view, 
+                                                 gboolean delete);
 
 static void         _clear_hidding_filter (ModestFolderView *folder_view);
 
@@ -808,8 +809,18 @@ on_account_removed (TnyAccountStore *account_store,
 
        /* If the removed account is the currently viewed one then
           clear the configuration value. The new visible account will be the default account */
-       if (!strcmp (priv->visible_account_id, tny_account_get_id (account))) {
+       if (priv->visible_account_id &&
+           !strcmp (priv->visible_account_id, tny_account_get_id (account))) {
+
+               /* Clear the current visible account_id */
                modest_folder_view_set_account_id_of_visible_server_account (self, NULL);
+
+               /* Call the restore method, this will set the new visible account */
+               modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self),
+                                             MODEST_CONF_FOLDER_VIEW_KEY);
+
+               /* Select the INBOX */
+               modest_folder_view_select_first_inbox_or_local (self);
        }
 }
 
@@ -825,7 +836,10 @@ on_account_update (TnyAccountStore *account_store,
        self = MODEST_FOLDER_VIEW (user_data);
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
 
-       if (!priv->visible_account_id)
+       /* If we're adding a new account, and there is no previous
+          one, we need to select the visible server account */
+       if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
+           !priv->visible_account_id)
                modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self),
                                              MODEST_CONF_FOLDER_VIEW_KEY);
 
@@ -964,11 +978,17 @@ filter_row (GtkTreeModel *model,
        
                        /* If it isn't a special folder, 
                         * don't show it unless it is the visible account: */
-                       if (!modest_tny_account_is_virtual_local_folders (acc) &&
-                               strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) { 
+                       if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
+                           !modest_tny_account_is_virtual_local_folders (acc) &&
+                           strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
+                               
                                /* Show only the visible account id */
-                               if (priv->visible_account_id && strcmp (account_id, priv->visible_account_id))
+                               if (priv->visible_account_id) {
+                                       if (strcmp (account_id, priv->visible_account_id))
+                                               retval = FALSE;
+                               } else {
                                        retval = FALSE;
+                               }                               
                        }
                        
                        /* Never show these to the user. They are merged into one folder 
@@ -1994,11 +2014,6 @@ find_inbox_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *inbox_iter
                                    TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name,
                                    TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, 
                                    &type, -1);
-
-               /*
-               printf ("DEBUG: %s: name=%s, type=%d, TNY_FOLDER_TYPE_INBOX=%d\n", 
-                       __FUNCTION__, name, type, TNY_FOLDER_TYPE_INBOX);
-               */
                        
                gboolean result = FALSE;
                if (type == TNY_FOLDER_TYPE_INBOX) {