* Fixed several reference count leaks in the dimming rules
authorSergio Villar Senin <svillar@igalia.com>
Tue, 19 Jun 2007 06:47:22 +0000 (06:47 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 19 Jun 2007 06:47:22 +0000 (06:47 +0000)
* Fixed several reference count leaks in the folder view
* Added a dispose method to the header view to prevent cycles when unrefs
* Commented some debug code
* Removed an initialization that could cause the blank right paned issue

pmo-trunk-r2297

src/maemo/modest-main-window.c
src/modest-ui-actions.c
src/modest-ui-dimming-rules.c
src/modest-widget-memory.c
src/widgets/modest-folder-view.c
src/widgets/modest-header-view.c

index b1d0ab6..280b946 100644 (file)
@@ -299,7 +299,7 @@ modest_main_window_init (ModestMainWindow *obj)
        priv->progress_bar = NULL;
        priv->current_toolbar_mode = TOOLBAR_MODE_NORMAL;
        priv->style  = MODEST_MAIN_WINDOW_STYLE_SPLIT;
-       priv->contents_style  = MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS;
+       priv->contents_style  = -1; /* invalid contents style. We need this to select it for the first time */
        priv->merge_ids = NULL;
        priv->optimized_view  = FALSE;
        priv->send_receive_in_progress  = FALSE;
@@ -631,6 +631,8 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        
        priv->folder_view = MODEST_FOLDER_VIEW (modest_platform_create_folder_view (NULL));
+       wrap_in_scrolled_window (folder_win, GTK_WIDGET(priv->folder_view));
+/*     wrap_in_scrolled_window (priv->contents_widget, GTK_WIDGET(priv->header_view)); */
 
        gtk_widget_show (GTK_WIDGET (priv->folder_view));
 
@@ -641,11 +643,6 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
                                                  TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
 
-
-       
-       wrap_in_scrolled_window (folder_win, GTK_WIDGET(priv->folder_view));
-       wrap_in_scrolled_window (priv->contents_widget, GTK_WIDGET(priv->header_view));
-       
        /* Load previous osso state, for instance if we are being restored from 
         * hibernation:  */
        modest_osso_load_state ();
@@ -666,7 +663,23 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        }
 }
 
-ModestWindow*
+/* Debugging */
+/* static void  */
+/* on_window_destroy (ModestWindow *window,  */
+/*                ModestWindowMgr *self) */
+/* { */
+/*     ModestMainWindow *mw = NULL;     */
+/*     ModestMainWindowPrivate *priv = NULL; */
+
+/*     mw  = MODEST_MAIN_WINDOW (window); */
+/*     priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); */
+
+/*     g_print ("\tMW: %d\n", ((GObject*)mw)->ref_count); */
+/*     g_print ("\tHV: %d\n", ((GObject*)priv->header_view)->ref_count); */
+/*     g_print ("\tFV: %d\n", ((GObject*)priv->folder_view)->ref_count); */
+/* } */
+
+ModestWindow *
 modest_main_window_new (void)
 {
        ModestMainWindow *self = NULL;  
@@ -807,30 +820,9 @@ modest_main_window_new (void)
        window_icon = modest_platform_get_icon (MODEST_APP_ICON);
        gtk_window_set_icon (GTK_WINDOW (self), window_icon);
        
-
-       
-       /* Do send & receive when we are idle */
-       /* TODO: Enable this again. I have commented it out because, 
-        * at least in scratchbox, this can cause us to start a second 
-        * update (in response to a connection change) when we are already 
-        * doing an update (started here, at startup). Tinymail doesn't like that.
-        * murrayc.
-        */
-       /* g_idle_add ((GSourceFunc)sync_accounts_cb, self); */
-       
        HildonProgram *app = hildon_program_get_instance ();
        hildon_program_add_window (app, HILDON_WINDOW (self));
        
-       /* Register HildonProgram  signal handlers: */
-       /* These are apparently deprecated, according to the 
-        * "HildonApp/HildonAppView to HildonProgram/HildonWindow migration guide",
-        * though the API reference does not mention that:
-        *
-       g_signal_connect (G_OBJECT(app), "topmost_status_lose",
-               G_CALLBACK (on_hildon_program_save_state), self);
-       g_signal_connect (G_OBJECT(app), "topmost_status_acquire",
-               G_CALLBACK (on_hildon_program_status_acquire), self);
-    */
        g_signal_connect (G_OBJECT(app), "notify::is-topmost",
                G_CALLBACK (on_hildon_program_is_topmost_notify), self);
 
@@ -840,6 +832,11 @@ modest_main_window_new (void)
 
        restore_settings (MODEST_MAIN_WINDOW(self), FALSE);
 
+/*     { */
+/*             g_signal_connect (self, "destroy",  */
+/*                               G_CALLBACK (on_window_destroy), self); */
+/*     } */
+
        return MODEST_WINDOW(self);
 }
 
@@ -1521,7 +1518,6 @@ modest_main_window_set_contents_style (ModestMainWindow *self,
                break;
        case MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS:
        {
-               /* TODO: show here account details */
                TnyFolderStore *selected_folderstore = 
                        modest_folder_view_get_selected (priv->folder_view);
                if (TNY_IS_ACCOUNT (selected_folderstore)) {    
@@ -1531,6 +1527,7 @@ modest_main_window_set_contents_style (ModestMainWindow *self,
                        wrap_in_scrolled_window (priv->contents_widget, 
                                         priv->details_widget);
                }
+               g_object_unref (selected_folderstore);
                break;
        }
        case MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY:
@@ -1598,6 +1595,7 @@ on_configuration_key_changed (ModestConf* conf,
                g_free (new_text);
                g_list_free (children);
        }
+       g_object_unref (account);
 }
 
 static gboolean
index 9b8dfff..3009450 100644 (file)
@@ -1256,7 +1256,7 @@ folder_refreshed_cb (const GObject *obj,
                     TnyFolder *folder, 
                     gpointer user_data)
 {
-       printf ("DEBUG: %s\n", __FUNCTION__);
+/*     printf ("DEBUG: %s\n", __FUNCTION__); */
        ModestMainWindow *win = NULL;
        GtkWidget *header_view;
 
@@ -1268,11 +1268,11 @@ folder_refreshed_cb (const GObject *obj,
 
        /* Check if folder is empty and set headers view contents style */
        if (tny_folder_get_all_count (folder) == 0) {
-       printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
+/*     printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__); */
                modest_main_window_set_contents_style (win,
                                                       MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
        } else {
-               printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
+/*             printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__); */
 
                /* Set the header view, we could change it to
                   the empty view after the refresh. We do not
@@ -1282,9 +1282,7 @@ folder_refreshed_cb (const GObject *obj,
                modest_main_window_set_contents_style (win, 
                                                       MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
 
-               /* Restore configuration. There is no need to set the
-                  contents style to headers because it was already
-                  being done in folder_selection_changed */
+               /* Restore configuration */
                modest_widget_memory_restore (modest_runtime_get_conf (), 
                                              G_OBJECT(header_view),
                                              MODEST_CONF_HEADER_VIEW_KEY);
@@ -1310,10 +1308,12 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
        conf = modest_runtime_get_conf ();
 
        if (TNY_IS_ACCOUNT (folder_store)) {
-               /* Update active account */
-               set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
-               /* Show account details */
-               modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
+               if (selected) {
+                       /* Update active account */
+                       set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
+                       /* Show account details */
+                       modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
+               }
        } else {
                if (TNY_IS_FOLDER (folder_store) && selected) {
                        
@@ -1339,7 +1339,7 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
                        /* Do not show folder */
                        modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
                        modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
-               }                       
+               }
        }
 
        /* Update toolbar dimming state */
@@ -2506,6 +2506,7 @@ modest_ui_actions_on_details (GtkAction *action,
                                return;
 
                        show_folder_details (folder, GTK_WINDOW (win));
+                       g_object_unref (folder);
 
                } else {
                        header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
@@ -3085,6 +3086,7 @@ modest_ui_actions_on_help (GtkAction *action,
                                        help_id = NULL;
                                }
                        }
+                       g_object_unref (folder_store);
                } else {
                        help_id = "applications_email_mainview";        
                }
index 39a1b9a..4d2f6c5 100644 (file)
@@ -92,10 +92,9 @@ modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data)
        
        if (TNY_IS_ACCOUNT (parent_folder)) {
                /* If it's the local account then do not dim */
-               if (modest_tny_account_is_virtual_local_folders (
-                       TNY_ACCOUNT (parent_folder)))
-                       return FALSE;
-               else {
+               if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
+                       dimmed = FALSE;
+               } else {
                        const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder));
                        /* If it's POP then dim */
                        dimmed = (modest_protocol_info_get_transport_store_protocol (proto_str) == 
@@ -116,6 +115,7 @@ modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data)
                if (!dimmed)
                        dimmed = _selected_folder_is_any_of_type (win, types, 3);
        }
+       g_object_unref (parent_folder);
 
        return dimmed;
 }
@@ -691,8 +691,11 @@ _selected_folder_not_writeable (ModestMainWindow *win)
        
        /* Get selected folder as parent of new folder to create */
        parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
-       if (!(parent_folder && TNY_IS_FOLDER(parent_folder)))
+       if (!(parent_folder && TNY_IS_FOLDER(parent_folder))) {
+               if (parent_folder)
+                       g_object_unref (parent_folder);
                return TRUE;
+       }
        
        /* Check dimmed rule */ 
        rules = modest_tny_folder_get_rules (TNY_FOLDER (parent_folder));
@@ -764,10 +767,9 @@ _selected_folder_is_MMC_or_POP_root (ModestMainWindow *win)
        
        if (TNY_IS_ACCOUNT (parent_folder)) {
                /* If it's the local account then do not dim */
-               if (modest_tny_account_is_virtual_local_folders (
-                                                                TNY_ACCOUNT (parent_folder)))
-                       return FALSE;
-               else {
+               if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
+                       result = FALSE;
+               } else {
                                /* If it's the MMC root folder then dim it */
                        if (!strcmp (tny_account_get_id (TNY_ACCOUNT (parent_folder)), MODEST_MMC_ACCOUNT_ID)) {
                                        result = TRUE;
@@ -779,6 +781,7 @@ _selected_folder_is_MMC_or_POP_root (ModestMainWindow *win)
                        }
                }
        }
+       g_object_unref (parent_folder);
 
        return result;
 }
@@ -804,8 +807,11 @@ _selected_folder_is_empty (ModestMainWindow *win)
        
        /* Get selected folder as parent of new folder to create */
        folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
-       if (!(folder && TNY_IS_FOLDER(folder)))
+       if (!(folder && TNY_IS_FOLDER(folder))) {
+               if (folder)
+                       g_object_unref (folder);
                return TRUE;
+       }
        
        /* Check folder type */
        result = tny_folder_get_all_count (TNY_FOLDER (folder)) == 0;
@@ -840,8 +846,11 @@ _selected_folder_is_any_of_type (ModestWindow *win,
                /* Get selected folder as parent of new folder to create */
                folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
 
-               if (!(folder && TNY_IS_FOLDER(folder)))
+               if (!(folder && TNY_IS_FOLDER(folder))) {
+                       if (folder)
+                               g_object_unref (folder);
                        return TRUE;
+               }
                
                /* Check folder type */
                result = _folder_is_any_of_type (TNY_FOLDER(folder), types, ntypes);
index 22c8da2..c9e5b3e 100644 (file)
@@ -269,8 +269,11 @@ save_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        gint sort_flag_id = 0;
        
        folder = modest_header_view_get_folder (header_view);
-       if (!folder || modest_header_view_is_empty (header_view))
+       if (!folder || modest_header_view_is_empty (header_view)) {
+               if (folder)
+                       g_object_unref (folder);
                return TRUE; /* no non-empty folder: no settings */
+       }
        
        type  = modest_tny_folder_guess_folder_type (folder);
        style = modest_header_view_get_style   (header_view);
@@ -356,10 +359,14 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view,
        gint sort_colid = -1, sort_type;
        
        folder = modest_header_view_get_folder (header_view);
-       if (!folder || modest_header_view_is_empty (header_view))
+       if (!folder || modest_header_view_is_empty (header_view)) {
+               if (folder)
+                       g_object_unref (folder);
                return TRUE; /* no non-empty folder: no settings */
+       }
        
-       type = modest_tny_folder_guess_folder_type (folder);    style = modest_header_view_get_style   (header_view);
+       type = modest_tny_folder_guess_folder_type (folder);    
+       style = modest_header_view_get_style (header_view);
 
        key = _modest_widget_memory_get_keyname_with_double_type (name, type, style,
                                                                  MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
@@ -564,7 +571,7 @@ modest_widget_memory_restore (ModestConf *conf, GObject *widget, const gchar *na
        g_return_val_if_fail (conf, FALSE);
        g_return_val_if_fail (widget, FALSE);
        g_return_val_if_fail (name, FALSE);
-       
+
        if (GTK_IS_WINDOW(widget))
                return restore_settings_window (conf, GTK_WINDOW(widget), name);
        else if (GTK_IS_PANED(widget))
index 887d99f..eec1b19 100644 (file)
@@ -569,6 +569,11 @@ modest_folder_view_finalize (GObject *obj)
                priv->conf_key_signal = 0;
        }
 
+       if (priv->cur_folder_store) {
+               g_object_unref (priv->cur_folder_store);
+               priv->cur_folder_store = NULL;
+       }
+
        /* Clear hidding array created by cut operation */
        _clear_hidding_filter (MODEST_FOLDER_VIEW (obj));
 
@@ -888,27 +893,21 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
        
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE(user_data);
 
-       /* folder was _un_selected if true */
-       if (!gtk_tree_selection_get_selected (sel, &model, &iter)) {
-               if (priv->cur_folder_store)
-                       g_object_unref (priv->cur_folder_store);
-               priv->cur_folder_store = NULL;
-
-               /* Notify the display name observers */
-               g_signal_emit (G_OBJECT(user_data),
-                              signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
-                              NULL);
+       if(!gtk_tree_selection_get_selected (sel, &model, &iter))
                return;
-       }
 
-       tree_view = MODEST_FOLDER_VIEW (user_data);
+       /* Notify the display name observers */
+       g_signal_emit (G_OBJECT(user_data),
+                      signals[FOLDER_DISPLAY_NAME_CHANGED_SIGNAL], 0,
+                      NULL);
 
+       tree_view = MODEST_FOLDER_VIEW (user_data);
        gtk_tree_model_get (model, &iter,
                            TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
                            -1);
 
        /* If the folder is the same do not notify */
-       if (priv->cur_folder_store == folder) {
+       if (priv->cur_folder_store == folder && folder) {
                g_object_unref (folder);
                return;
        }
@@ -918,6 +917,7 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
                g_signal_emit (G_OBJECT(tree_view), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
                               priv->cur_folder_store, FALSE);
                g_object_unref (priv->cur_folder_store);
+               priv->cur_folder_store = NULL;
        }
 
        /* New current references */
@@ -926,7 +926,7 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
        /* New folder has been selected */
        g_signal_emit (G_OBJECT(tree_view),
                       signals[FOLDER_SELECTION_CHANGED_SIGNAL],
-                      0, folder, TRUE);
+                      0, priv->cur_folder_store, TRUE);
 }
 
 TnyFolderStore *
@@ -1681,7 +1681,7 @@ find_inbox_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *inbox_iter
                gchar *name = NULL;
 
                gtk_tree_model_get (model, iter, 
-                                       TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name,
+                                   TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name,
                                    TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, 
                                    &type, -1);
 
@@ -1727,9 +1727,9 @@ modest_folder_view_select_first_inbox_or_local (ModestFolderView *self)
        GtkTreeIter iter, inbox_iter;
        GtkTreeSelection *sel;
 
-       /* Do not set it if the folder view was not painted */
-       if (!GTK_WIDGET_MAPPED (self))
-               return; 
+/*     /\* Do not set it if the folder view was not painted *\/ */
+/*     if (!GTK_WIDGET_MAPPED (self)) */
+/*             return; */
 
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
        if (!model)
index 297e1cb..8fea86a 100644 (file)
@@ -51,6 +51,7 @@
 static void modest_header_view_class_init  (ModestHeaderViewClass *klass);
 static void modest_header_view_init        (ModestHeaderView *obj);
 static void modest_header_view_finalize    (GObject *obj);
+static void modest_header_view_dispose     (GObject *obj);
 
 static void          on_header_row_activated (GtkTreeView *treeview, GtkTreePath *path,
                                              GtkTreeViewColumn *column, gpointer userdata);
@@ -184,6 +185,7 @@ modest_header_view_class_init (ModestHeaderViewClass *klass)
 
        parent_class            = g_type_class_peek_parent (klass);
        gobject_class->finalize = modest_header_view_finalize;
+       gobject_class->dispose = modest_header_view_dispose;
        
        g_type_class_add_private (gobject_class, sizeof(ModestHeaderViewPrivate));
        
@@ -506,6 +508,26 @@ modest_header_view_init (ModestHeaderView *obj)
 }
 
 static void
+modest_header_view_dispose (GObject *obj)
+{
+       ModestHeaderView        *self;
+       ModestHeaderViewPrivate *priv;
+       
+       self = MODEST_HEADER_VIEW(obj);
+       priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+
+       if (priv->folder) {
+               tny_folder_remove_observer (priv->folder, TNY_FOLDER_OBSERVER (obj));
+               g_object_unref (G_OBJECT (priv->folder));
+               priv->folder   = NULL;
+       }
+
+       G_OBJECT_CLASS(parent_class)->dispose (obj);
+}
+
+
+
+static void
 modest_header_view_finalize (GObject *obj)
 {
        ModestHeaderView        *self;
@@ -522,12 +544,6 @@ modest_header_view_finalize (GObject *obj)
        g_mutex_unlock (priv->observers_lock);
        g_mutex_free (priv->observers_lock);
 
-       if (priv->folder) {
-               tny_folder_remove_observer (priv->folder, TNY_FOLDER_OBSERVER (obj));
-               g_object_unref (G_OBJECT (priv->folder));
-               priv->folder   = NULL;
-       }
-
        /* Clear hidding array created by cut operation */
        _clear_hidding_filter (MODEST_HEADER_VIEW (obj));
 
@@ -551,7 +567,7 @@ modest_header_view_new (TnyFolder *folder, ModestHeaderViewStyle style)
        priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
        
        modest_header_view_set_style   (self, style);
-       modest_header_view_set_folder (self, NULL, NULL, NULL);
+/*     modest_header_view_set_folder (self, NULL, NULL, NULL); */
 
        gtk_tree_view_columns_autosize (GTK_TREE_VIEW(obj));
        gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW(obj),TRUE);
@@ -768,25 +784,17 @@ modest_header_view_get_style (ModestHeaderView *self)
 static void
 modest_header_view_set_model (GtkTreeView *header_view, GtkTreeModel *model)
 {
-       GtkTreeModel *old_model_filter = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
-       GtkTreeModel *old_model_sort = NULL;
-
-       if (old_model_filter) 
-               old_model_sort = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(old_model_filter));
-
-       if (old_model_sort && GTK_IS_TREE_MODEL_SORT (old_model_sort)) { 
-               GtkTreeModel *old_model;
-               ModestHeaderViewPrivate *priv;
-
-               priv = MODEST_HEADER_VIEW_GET_PRIVATE (header_view);
-               old_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (old_model_sort));
-
-               /* Set new model */
-               gtk_tree_view_set_model (header_view, model);
-       } else
-               gtk_tree_view_set_model (header_view, model);
-
-       return;
+/*     GtkTreeModel *old_model_sort = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)); */
+/*     if (old_model_sort && GTK_IS_TREE_MODEL_SORT (old_model_sort)) { */
+/*             GtkTreeModel *old_model; */
+/*             ModestHeaderViewPrivate *priv; */
+/*             priv = MODEST_HEADER_VIEW_GET_PRIVATE (header_view); */
+/*             old_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (old_model_sort)); */
+
+/*             /\* Set new model *\/ */
+/*             gtk_tree_view_set_model (header_view, model); */
+/*     } else */
+       gtk_tree_view_set_model (header_view, model);
 }
 
 TnyFolder*
@@ -952,7 +960,6 @@ modest_header_view_set_folder (ModestHeaderView *self,
                               gpointer user_data)
 {
        ModestHeaderViewPrivate *priv;
-       ModestMailOperation *mail_op = NULL;
        ModestWindowMgr *mgr = NULL;
        GObject *source = NULL;
  
@@ -962,11 +969,13 @@ modest_header_view_set_folder (ModestHeaderView *self,
                g_mutex_lock (priv->observers_lock);
                tny_folder_remove_observer (priv->folder, TNY_FOLDER_OBSERVER (self));
                g_object_unref (priv->folder);
+/*             g_print ("---------- REMAINING %d\n", ((GObject*)priv->folder)->ref_count); */
                priv->folder = NULL;
                g_mutex_unlock (priv->observers_lock);
        }
 
        if (folder) {
+               ModestMailOperation *mail_op = NULL;
 
                /* Get main window to use it as source of mail operation */
                mgr = modest_runtime_get_window_mgr ();
@@ -993,7 +1002,6 @@ modest_header_view_set_folder (ModestHeaderView *self,
 
                /* Free */
                g_object_unref (mail_op);
-
        } else {
                g_mutex_lock (priv->observers_lock);