#include <tny-gtk-folder-store-tree-model.h>
#include <tny-gtk-header-list-model.h>
#include <tny-folder.h>
+#include <tny-folder-store-observer.h>
#include <tny-account-store.h>
#include <tny-account.h>
#include <tny-folder.h>
update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
{
ModestFolderViewPrivate *priv;
- GtkTreeModel *model;
+ GtkTreeModel *model, *old_model;
+ TnyAccount *local_account;
+ TnyList *model_as_list;
g_return_val_if_fail (account_store, FALSE);
g_signal_emit (G_OBJECT(self),
signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
NULL, TRUE);
-
+
+ /* Remove the old model as observer of the local folder account */
+ local_account =
+ modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store (),
+ MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID,
+ TNY_ACCOUNT_TYPE_STORE);
+ old_model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ if (old_model) {
+ GtkTreeModel *sorted, *model;
+
+ if (GTK_IS_TREE_MODEL_FILTER (old_model))
+ sorted = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (old_model));
+ else
+ sorted = old_model;
+
+ model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sorted));
+
+ tny_folder_store_remove_observer (TNY_FOLDER_STORE (local_account),
+ TNY_FOLDER_STORE_OBSERVER (model));
+ }
+
/* FIXME: the local accounts are not shown when the query
selects only the subscribed folders. */
/* model = tny_gtk_folder_store_tree_model_new (TRUE, priv->query); */
/* Deal with the model via its TnyList Interface,
* filling the TnyList via a get_accounts() call: */
- TnyList *model_as_list = TNY_LIST(model);
+ model_as_list = TNY_LIST(model);
/* Get the accounts: */
tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
model_as_list,
TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+
+ /* Set the folder view as an account observer in order to let
+ us see the UI changes automatically when creating and
+ deleting folders just under the local account */
+ tny_folder_store_add_observer (TNY_FOLDER_STORE (local_account),
+ TNY_FOLDER_STORE_OBSERVER (model));
+
+ g_object_unref (model_as_list);
model_as_list = NULL;
+ g_object_unref (local_account);
/*
if (account_list)