[nautilus-actions] Fix ref count in tree store



commit 8b937be711a9c8d2d227dbd3c87eccfe6f0fe5f8
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Oct 16 15:23:21 2009 +0200

    Fix ref count in tree store
    
    When the action is embedded in a menu, unreffing the menu also unref the action.
    So add a ref when displaying only actions in the tree view.

 ChangeLog                     |   11 +++++++++++
 src/nact/nact-iactions-list.c |    9 +++++++--
 src/nact/nact-tree-model.c    |   15 +++++++++++----
 src/runtime/na-object-item.c  |    4 ++--
 4 files changed, 31 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d959266..aaa0b98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-10-16 Pierre Wieser <pwieser trychlos org>
+
+	* src/nact/nact-iactions-list.c (nact_iactions_list_fill):
+	Only count items in edition mode.
+
+	* src/nact/nact-tree-model.c
+	(nact_tree_model_fill): Only check status in edition mode.
+	(fill_tree_store): Add a ref when the action is embedded in a menu.
+
+	* src/runtime/na-object-item.c (object_ref): Fix comment.
+
 2009-10-15 Pierre Wieser <pwieser trychlos org>
 
 	* src/runtime/na-object-item.c (object_are_equal):
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 6019bac..ab2323d 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -836,8 +836,11 @@ nact_iactions_list_fill( NactIActionsList *instance, GList *items )
 		ialid->menus = 0;
 		ialid->actions = 0;
 		ialid->profiles = 0;
-		na_object_item_count_items( items, &ialid->menus, &ialid->actions, &ialid->profiles, TRUE );
-		send_list_count_updated_signal( instance, ialid );
+
+		if( !only_actions ){
+			na_object_item_count_items( items, &ialid->menus, &ialid->actions, &ialid->profiles, TRUE );
+			send_list_count_updated_signal( instance, ialid );
+		}
 
 		select_first_row( instance );
 	}
@@ -971,6 +974,7 @@ nact_iactions_list_get_selected_items( NactIActionsList *instance )
 			path = ( GtkTreePath * ) it->data;
 			gtk_tree_model_get_iter( model, &iter, path );
 			gtk_tree_model_get( model, &iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
+			/*g_debug( "nact_iactions_list_get_selected_items: object=%p", ( void * ) object );*/
 			items = g_list_prepend( items, na_object_ref( object ));
 			g_object_unref( object );
 		}
@@ -1764,6 +1768,7 @@ is_iduplicable_proxy( NactIActionsList *instance, IActionsListInstanceData *iali
 	gboolean is_proxy;
 
 	is_proxy = ( ialid->management_mode == IACTIONS_LIST_MANAGEMENT_MODE_EDITION );
+	g_debug( "nact_iactions_list_is_iduplicable_proxy: is_proxy=%s", is_proxy ? "True":"False" );
 
 	return( is_proxy );
 }
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 17f51af..646f9b2 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -677,7 +677,9 @@ nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions)
 
 		for( it = items ; it ; it = it->next ){
 			duplicate = na_object_duplicate( it->data );
-			na_object_check_status( duplicate );
+			if( !only_actions ){
+				na_object_check_status( duplicate );
+			}
 			fill_tree_store( ts_model, model->private->treeview, duplicate, only_actions, NULL );
 			na_object_unref( duplicate );
 		}
@@ -717,6 +719,11 @@ fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
 				na_object_append_item( object, it->data );
 				na_object_set_parent( it->data, object );
 			}
+		/* need to add a reference count if action has a parent, because
+		 * the action will be unreffed when unreffing the menu
+		 */
+		} else if( na_object_get_parent( object )){
+			g_object_ref( object );
 		}
 	}
 
@@ -964,7 +971,6 @@ nact_tree_model_remove( NactTreeModel *model, NAObject *object )
 		store = GTK_TREE_STORE( gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model )));
 
 		if( search_for_object( model, GTK_TREE_MODEL( store ), object, &iter )){
-			/*parents = add_parent( parents, GTK_TREE_MODEL( store ), &iter );*/
 			parent = na_object_get_parent( object );
 			g_debug( "%s: object=%p, parent=%p", thisfn, ( void * ) object, ( void * ) parent );
 			if( parent ){
@@ -982,10 +988,11 @@ nact_tree_model_remove( NactTreeModel *model, NAObject *object )
 static void
 append_item( GtkTreeStore *model, GtkTreeView *treeview, GtkTreeIter *parent, GtkTreeIter *iter, const NAObject *object )
 {
-	gtk_tree_store_append( model, iter, parent );
+	/*g_debug( "nact_tree_model_append_item: object=%p (ref_count=%d), parent=%p",
+					( void * ) object, G_OBJECT( object )->ref_count, ( void * ) parent );*/
 
+	gtk_tree_store_append( model, iter, parent );
 	gtk_tree_store_set( model, iter, IACTIONS_LIST_NAOBJECT_COLUMN, object, -1 );
-
 	display_item( model, treeview, iter, object );
 }
 
diff --git a/src/runtime/na-object-item.c b/src/runtime/na-object-item.c
index 61f853e..a59dc1c 100644
--- a/src/runtime/na-object-item.c
+++ b/src/runtime/na-object-item.c
@@ -968,8 +968,8 @@ object_ref( NAObject *object )
 }
 
 /*
- * if we 'dispose' ic->data during the loop, the the 'ic->next' pointer
- * is no more valid for the next iteration, so we have to keep its value
+ * if we 'dispose' ic->data during the loop, the 'ic->next' pointer will
+ * no more be valid for the next iteration, so we have to keep its value
  * before actually unref the data
  */
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]