Fixed leak in modest-folder-view
[modest] / src / widgets / modest-folder-view.c
index b400c29..22b99cd 100644 (file)
@@ -76,7 +76,8 @@ static void         tny_account_store_view_init (gpointer g,
 static void         modest_folder_view_set_account_store (TnyAccountStoreView *self, 
                                                          TnyAccountStore     *account_store);
 
-static void         on_selection_changed   (GtkTreeSelection *sel, gpointer data);
+static void         on_selection_changed   (GtkTreeSelection *sel, 
+                                           gpointer data);
 
 static void         on_account_removed     (TnyAccountStore *self, 
                                            TnyAccount *account,
@@ -1222,7 +1223,6 @@ on_account_changed (TnyAccountStore *account_store,
                    TnyAccount *tny_account,
                    gpointer user_data)
 {
-       /* do nothing */
        ModestFolderViewPrivate *priv;
        GtkTreeModel *sort_model, *filter_model;
 
@@ -1236,7 +1236,7 @@ on_account_changed (TnyAccountStore *account_store,
        /* Get the inner model */
        filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
        sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
-       
+
        /* Remove the account from the model */
        tny_list_remove (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))),
                         G_OBJECT (tny_account));
@@ -1249,6 +1249,19 @@ on_account_changed (TnyAccountStore *account_store,
        gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));
 }
 
+/**
+ *
+ * Selects the first inbox or the local account in an idle
+ */
+static gboolean
+on_idle_select_first_inbox_or_local (gpointer user_data)
+{
+       ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
+
+       modest_folder_view_select_first_inbox_or_local (self);
+
+       return FALSE;
+}
 
 
 static void
@@ -1260,6 +1273,7 @@ on_account_removed (TnyAccountStore *account_store,
        ModestFolderViewPrivate *priv;
        GtkTreeModel *sort_model, *filter_model;
        GtkTreeSelection *sel = NULL;
+       gboolean same_account_selected = FALSE;
 
        /* Ignore transport account removals, we're not showing them
           in the folder view */
@@ -1285,6 +1299,7 @@ on_account_removed (TnyAccountStore *account_store,
                if (selected_folder_account == account) {
                        sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
                        gtk_tree_selection_unselect_all (sel);
+                       same_account_selected = TRUE;
                }
                g_object_unref (selected_folder_account);
        }
@@ -1296,7 +1311,7 @@ on_account_removed (TnyAccountStore *account_store,
 
                folder_to_select_account = tny_folder_get_account (priv->folder_to_select);
                if (folder_to_select_account == account) {
-/*                     modest_folder_view_disable_next_folder_selection (self); */
+                       modest_folder_view_disable_next_folder_selection (self);
                        g_object_unref (priv->folder_to_select);
                        priv->folder_to_select = NULL;
                }
@@ -1327,16 +1342,8 @@ on_account_removed (TnyAccountStore *account_store,
 
        /* Select the first INBOX if the currently selected folder
           belongs to the account that is being deleted */
-       if (priv->cur_folder_store) {
-               TnyAccount *folder_selected_account;
-
-               folder_selected_account = (TNY_IS_FOLDER (priv->cur_folder_store)) ?
-                       modest_tny_folder_get_account (TNY_FOLDER (priv->cur_folder_store)) :
-                       TNY_ACCOUNT (g_object_ref (priv->cur_folder_store));
-               if (account == folder_selected_account)
-                       modest_folder_view_select_first_inbox_or_local (self);
-               g_object_unref (folder_selected_account);
-       }
+       if (same_account_selected)
+               g_idle_add (on_idle_select_first_inbox_or_local, self);
 }
 
 void
@@ -1659,10 +1666,13 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
        /* New current references */
        priv->cur_folder_store = folder;
 
-       /* New folder has been selected */
-       g_signal_emit (G_OBJECT(tree_view),
-                      signals[FOLDER_SELECTION_CHANGED_SIGNAL],
-                      0, priv->cur_folder_store, TRUE);
+       /* New folder has been selected. Do not notify if there is
+          nothing new selected */
+       if (selected) {
+               g_signal_emit (G_OBJECT(tree_view),
+                              signals[FOLDER_SELECTION_CHANGED_SIGNAL],
+                              0, priv->cur_folder_store, TRUE);
+       }
 }
 
 TnyFolderStore *
@@ -2460,7 +2470,6 @@ on_drag_motion (GtkWidget      *widget,
                        goto out;
                }
        }
-       g_object_unref (folder);
 
        /* Expand the selected row after 1/2 second */
        if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), dest_row)) {
@@ -2481,6 +2490,8 @@ on_drag_motion (GtkWidget      *widget,
             gdk_drag_status(context, GDK_ACTION_DEFAULT, time);
 
  out:
+       if (folder)
+               g_object_unref (folder);
        if (dest_row)
                gtk_tree_path_free (dest_row);
        g_signal_stop_emission_by_name (widget, "drag-motion");