* Fixes NB#55338
authorSergio Villar Senin <svillar@igalia.com>
Thu, 7 Jun 2007 09:46:15 +0000 (09:46 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Thu, 7 Jun 2007 09:46:15 +0000 (09:46 +0000)
pmo-trunk-r2093

src/widgets/modest-folder-view.c
src/widgets/modest-msg-view.c

index 0e35b8d..52ff5de 100644 (file)
@@ -35,6 +35,7 @@
 #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>
@@ -718,7 +719,9 @@ static gboolean
 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);
 
@@ -728,7 +731,27 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
        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); */
@@ -736,13 +759,22 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
        
        /* 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)
index 43185d7..6c7f40a 100644 (file)
@@ -1415,7 +1415,7 @@ modest_msg_view_get_message (ModestMsgView *self)
 {
        TnyMsg *msg;
 
-       g_return_val_if_fail (self, NULL);
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW (self), NULL);
 
        msg = MODEST_MSG_VIEW_GET_PRIVATE(self)->msg;