[nautilus-actions] No more g_object_ref subitems list



commit 926681e99593ee1e36a45ebf201faf9e9d7b78bd
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Oct 8 19:06:31 2009 +0200

    No more g_object_ref subitems list

 ChangeLog                        |   27 +++++++++++++
 src/common/na-object-api.h       |    1 -
 src/common/na-object.c           |    6 +-
 src/common/na-xml-writer.c       |    8 +---
 src/nact/nact-iactions-list.c    |    3 +-
 src/nact/nact-main-menubar.c     |   11 +++--
 src/nact/nact-main-window.c      |    6 +--
 src/nact/nact-tree-model.c       |   15 ++++---
 src/plugin/nautilus-actions.c    |    6 +--
 src/runtime/na-gconf-provider.c  |    3 +-
 src/runtime/na-iio-provider.c    |    8 +--
 src/runtime/na-object-action.c   |    6 +--
 src/runtime/na-object-api.h      |    5 +-
 src/runtime/na-object-class.h    |    8 ++++
 src/runtime/na-object-fn.h       |    1 +
 src/runtime/na-object-item-fn.h  |    4 +-
 src/runtime/na-object-item.c     |   76 ++++++++++++++-----------------------
 src/runtime/na-object-menu.c     |    4 +-
 src/runtime/na-object.c          |   42 ++++++++++++++++++++-
 src/runtime/na-pivot.c           |    3 +-
 src/utils/nautilus-actions-new.c |    3 +-
 21 files changed, 144 insertions(+), 102 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4dc35ee..0f79477 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,32 @@
 2009-10-08 Pierre Wieser <pwieser trychlos org>
 
+	na_object_get_items: Renamed to na_object_get_items_list,
+	Now returns the list itself instead of a refed new list.
+
+	na_object_set_items: Renamed to na_object_set_items_list.
+	Now install the provided GList pointer instead of copying the list.
+
+	* src/common/na-object-api.h:
+	* src/common/na-object.c:
+	* src/common/na-xml-writer.c:
+	* src/nact/nact-iactions-list.c:
+	* src/nact/nact-main-menubar.c:
+	* src/nact/nact-main-window.c:
+	* src/nact/nact-tree-model.c:
+	* src/plugin/nautilus-actions.c:
+	* src/runtime/na-gconf-provider.c:
+	* src/runtime/na-iio-provider.c:
+	* src/runtime/na-object-action.c:
+	* src/runtime/na-object-api.h:
+	* src/runtime/na-object-class.h:
+	* src/runtime/na-object-fn.h:
+	* src/runtime/na-object-item-fn.h:
+	* src/runtime/na-object-item.c:
+	* src/runtime/na-object-menu.c:
+	* src/runtime/na-object.c:
+	* src/runtime/na-pivot.c:
+	* src/utils/nautilus-actions-new.c: Updated accordingly.
+
 	Move parent pointer from NAObjectProfile to NAObjectId class.
 
 	* src/common/na-object-action-fn.h:
diff --git a/src/common/na-object-api.h b/src/common/na-object-api.h
index 9fb231d..637f272 100644
--- a/src/common/na-object-api.h
+++ b/src/common/na-object-api.h
@@ -71,7 +71,6 @@ G_BEGIN_DECLS
 
 /* NAObjectItem
  */
-
 #define na_object_insert_item( object, item, before ) \
 													na_object_item_insert_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ), ( NAObject * ) before )
 #define na_object_remove_item( object, item )		na_object_item_remove_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ))
diff --git a/src/common/na-object.c b/src/common/na-object.c
index 520fb53..74c86e6 100644
--- a/src/common/na-object.c
+++ b/src/common/na-object.c
@@ -39,7 +39,7 @@
 
 #include "na-object-api.h"
 
-static GList         *v_get_childs( const NAObject *object );
+static GList *v_get_childs( const NAObject *object );
 
 /**
  * na_object_iduplicable_check_edition_status:
@@ -198,7 +198,7 @@ na_object_object_reset_origin( NAObject *object, const NAObject *origin )
 }
 
 static GList *
-v_get_childs( const NAObject *object ){
-
+v_get_childs( const NAObject *object )
+{
 	return( na_object_most_derived_get_childs( object ));
 }
diff --git a/src/common/na-xml-writer.c b/src/common/na-xml-writer.c
index b55bf4d..8b174e4 100644
--- a/src/common/na-xml-writer.c
+++ b/src/common/na-xml-writer.c
@@ -565,7 +565,7 @@ create_xml_schema( NAXMLWriter *writer, gint format, const NAObjectAction *actio
 	create_schema_entry( writer, format, NULL, OBJECT_ITEM_ENABLED_ENTRY, text, doc, list_node, "bool", FALSE, ACTION_ENABLED_DESC_SHORT, ACTION_ENABLED_DESC_LONG );
 	g_free( text );
 
-	profiles = na_object_get_items( action );
+	profiles = na_object_get_items_list( action );
 
 	for( ip = profiles ; ip ; ip = ip->next ){
 
@@ -635,8 +635,6 @@ create_xml_schema( NAXMLWriter *writer, gint format, const NAObjectAction *actio
 		g_free( profile_dir );
 	}
 
-	na_object_free_items( profiles );
-
 	return( doc );
 }
 
@@ -751,7 +749,7 @@ create_xml_dump( NAXMLWriter *writer, gint format, const NAObjectAction *action
 	create_dump_entry( writer, format, NULL, OBJECT_ITEM_ENABLED_ENTRY, text, doc, list_node, "bool" );
 	g_free( text );
 
-	profiles = na_object_get_items( action );
+	profiles = na_object_get_items_list( action );
 
 	for( ip = profiles ; ip ; ip = ip->next ){
 
@@ -821,8 +819,6 @@ create_xml_dump( NAXMLWriter *writer, gint format, const NAObjectAction *action
 		g_free( profile_dir );
 	}
 
-	na_object_free_items( profiles );
-
 	return( doc );
 }
 
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 58cbce7..101a613 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -1085,9 +1085,8 @@ do_insert_items( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTr
 		 */
 		if( NA_IS_OBJECT_ITEM( it->data ) && na_object_get_items_count( it->data )){
 
-			subitems = na_object_get_items( it->data );
+			subitems = na_object_get_items_list( it->data );
 			do_insert_into_first( treeview, model, subitems, insert_path, NULL );
-			na_object_free_items( subitems );
 		}
 	}
 
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 962751d..e88bbdb 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -528,10 +528,12 @@ on_new_profile_activated( GtkAction *gtk_action, NactMainWindow *window )
 static void
 on_save_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
+	static const gchar *thisfn = "nact_main_menubar_on_save_activated";
 	GList *items;
 	NactApplication *application;
 	NAPivot *pivot;
 
+	g_debug( "%s: gtk_action=%p, window=%p", thisfn, ( void * ) gtk_action, ( void * ) window );
 	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 
@@ -591,9 +593,8 @@ save_item( NactMainWindow *window, NAPivot *pivot, NAObjectItem *item )
 	g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
 
 	if( NA_IS_OBJECT_MENU( item )){
-		subitems = na_object_get_items( item );
+		subitems = na_object_get_items_list( item );
 		save_items( window, pivot, subitems );
-		na_object_free_items( subitems );
 	}
 
 	if( na_object_is_modified( item ) &&
@@ -616,11 +617,11 @@ save_item( NactMainWindow *window, NAPivot *pivot, NAObjectItem *item )
 
 			dup_pivot = NA_OBJECT_ITEM( na_object_duplicate( item ));
 			na_object_reset_origin( item, dup_pivot );
-			g_debug( "un" );
+			g_debug( "save_item: un" );
 			na_object_dump( item );
-			g_debug( "deux" );
+			g_debug( "save_item: deux" );
 			na_object_dump( dup_pivot );
-			g_debug( "trois" );
+			g_debug( "save_item: trois" );
 			na_pivot_add_item( pivot, NA_OBJECT( dup_pivot ));
 
 			na_object_check_edition_status( item );
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index de4dc9e..580f829 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -817,11 +817,10 @@ actually_delete_item( NactMainWindow *window, NAObject *item, NAPivot *pivot )
 		}
 
 		if( NA_IS_OBJECT_MENU( item )){
-			items = na_object_get_items( item );
+			items = na_object_get_items_list( item );
 			for( it = items ; it ; it = it->next ){
 				actually_delete_item( window, NA_OBJECT( it->data ), pivot );
 			}
-			na_object_free_items( items );
 		}
 	}
 }
@@ -1016,9 +1015,8 @@ set_current_object_item( NactMainWindow *window, GSList *selected_items )
 			/*g_return_if_fail( count_profiles >= 1 );*/
 
 			if( count_profiles == 1 ){
-				profiles = na_object_get_items( window->private->edited_item );
+				profiles = na_object_get_items_list( window->private->edited_item );
 				window->private->edited_profile = NA_OBJECT_PROFILE( profiles->data );
-				na_object_free_items( profiles );
 			}
 	}
 
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index cc135c2..3fbbea1 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -695,9 +695,8 @@ fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
 				append_item( model, treeview, parent, &iter, duplicate );
 				g_object_unref( duplicate );
 			}
-			subitems = na_object_get_items( duplicate );
+			subitems = na_object_get_items_list( duplicate );
 			fill_tree_store( model, treeview, subitems, only_actions, only_actions ? NULL : &iter );
-			na_object_free_items( subitems );
 		}
 
 		if( NA_IS_OBJECT_ACTION( object )){
@@ -706,9 +705,8 @@ fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
 			append_item( model, treeview, parent, &iter, duplicate );
 			g_object_unref( duplicate );
 			if( !only_actions ){
-				subitems = na_object_get_items( duplicate );
+				subitems = na_object_get_items_list( duplicate );
 				fill_tree_store( model, treeview, subitems, only_actions, &iter );
-				na_object_free_items( subitems );
 			}
 			g_return_if_fail( NA_IS_OBJECT_ACTION( duplicate ));
 			g_return_if_fail( na_object_get_items_count( duplicate ) >= 1 );
@@ -1052,12 +1050,16 @@ iter_on_store_item( NactTreeModel *model, GtkTreeModel *store, GtkTreeIter *iter
 	gboolean stop;
 
 	gtk_tree_model_get( store, iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
+	/* unreffing as soon as we got the pointer so that the ref count is
+	 * unchanged in dump_store
+	 */
+	g_object_unref( object );
+
 	path = gtk_tree_model_get_path( store, iter );
 
 	stop = ( *fn )( model, path, object, user_data );
 
 	gtk_tree_path_free( path );
-	g_object_unref( object );
 
 	if( !stop ){
 		iter_on_store( model, store, iter, fn, user_data );
@@ -1514,9 +1516,10 @@ idrag_dest_drag_data_received( GtkTreeDragDest *drag_dest, GtkTreePath *dest, Gt
 
 					if( action ){
 						g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), FALSE );
-						g_object_unref( action );
+						na_object_unref( action );
 					}
 				}
+				nact_tree_model_dump( NACT_TREE_MODEL( drag_dest ));
 				na_utils_free_string_list( uri_list );
 				result = TRUE;
 			}
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index 4a7ecab..4a3a896 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -362,10 +362,9 @@ build_nautilus_menus( NautilusActions *plugin, GList *tree, GList *files )
 		g_free( label );
 
 		if( NA_IS_OBJECT_MENU( it->data )){
-			subitems = na_object_get_items( it->data );
+			subitems = na_object_get_items_list( it->data );
 			submenu = build_nautilus_menus( plugin, subitems, files );
 			/*g_debug( "%s: submenu has %d items", thisfn, g_list_length( submenu ));*/
-			na_object_free_items( subitems );
 			if( submenu ){
 				item = create_item_from_menu( NA_OBJECT_MENU( it->data ), submenu );
 				menus_list = g_list_append( menus_list, item );
@@ -406,7 +405,7 @@ is_action_candidate( NautilusActions *plugin, NAObjectAction *action, GList *fil
 		return( NULL );
 	}
 
-	profiles = na_object_get_items( action );
+	profiles = na_object_get_items_list( action );
 	for( ip = profiles ; ip && !candidate ; ip = ip->next ){
 
 		NAObjectProfile *profile = NA_OBJECT_PROFILE( ip->data );
@@ -420,7 +419,6 @@ is_action_candidate( NautilusActions *plugin, NAObjectAction *action, GList *fil
  		}
  	}
 
-	na_object_free_items( profiles );
 	g_free( action_label );
 
 	return( candidate );
diff --git a/src/runtime/na-gconf-provider.c b/src/runtime/na-gconf-provider.c
index 5e12308..fddbc6e 100644
--- a/src/runtime/na-gconf-provider.c
+++ b/src/runtime/na-gconf-provider.c
@@ -833,7 +833,7 @@ write_item_action( NAGConfProvider *provider, const NAObjectAction *action, gcha
 
 	ret = write_str( provider, uuid, NULL, ACTION_VERSION_ENTRY, na_object_action_get_version( action ), message );
 
-	profiles = na_object_get_items( action );
+	profiles = na_object_get_items_list( action );
 
 	for( ip = profiles ; ip && ret ; ip = ip->next ){
 
@@ -855,7 +855,6 @@ write_item_action( NAGConfProvider *provider, const NAObjectAction *action, gcha
 		g_free( name );
 	}
 
-	na_object_free_items( profiles );
 	g_free( uuid );
 
 	return( ret );
diff --git a/src/runtime/na-iio-provider.c b/src/runtime/na-iio-provider.c
index 5e2aed6..16588b9 100644
--- a/src/runtime/na-iio-provider.c
+++ b/src/runtime/na-iio-provider.c
@@ -229,8 +229,7 @@ build_hierarchy( GList *tree, GSList *level_zero, gboolean list_if_empty )
 				if( NA_IS_OBJECT_MENU( it->data )){
 					subitems_ids = na_object_menu_get_items_list( NA_OBJECT_MENU( it->data ));
 					subitems = build_hierarchy( tree, subitems_ids, FALSE );
-					na_object_set_items( it->data, subitems );
-					na_object_free_items( subitems );
+					na_object_set_items_list( it->data, subitems );
 					na_utils_free_string_list( subitems_ids );
 				}
 			}
@@ -469,10 +468,9 @@ sort_tree( const NAPivot *pivot, GList *tree, GCompareFunc fn )
 	 */
 	for( it = sorted ; it ; it = it->next ){
 		if( NA_IS_OBJECT_ITEM( it->data )){
-			items = na_object_get_items( it->data );
+			items = na_object_get_items_list( it->data );
 			items = sort_tree( pivot, items, fn );
-			na_object_set_items( it->data, items );
-			na_object_free_items( items );
+			na_object_set_items_list( it->data, items );
 		}
 	}
 
diff --git a/src/runtime/na-object-action.c b/src/runtime/na-object-action.c
index 9666ab5..a6820d7 100644
--- a/src/runtime/na-object-action.c
+++ b/src/runtime/na-object-action.c
@@ -497,11 +497,10 @@ object_copy( NAObject *target, const NAObject *source )
 		/* profiles have been copied (duplicated) as subitems by parent class
 		 * we have to attach new profiles to target action
 		 */
-		profiles = na_object_get_items( target );
+		profiles = na_object_get_items_list( target );
 		for( ip = profiles ; ip ; ip = ip->next ){
 			na_object_set_parent( ip->data, target );
 		}
-		na_object_free_items( profiles );
 	}
 }
 
@@ -537,7 +536,7 @@ object_are_equal( const NAObject *a, const NAObject *b )
 		}
 
 		if( equal ){
-			profiles = na_object_get_items( a );
+			profiles = na_object_get_items_list( a );
 			for( ip = profiles ; ip && equal ; ip = ip->next ){
 				id = na_object_get_id( ip->data );
 				profile = NA_OBJECT_PROFILE( na_object_get_item( b, id ));
@@ -551,7 +550,6 @@ object_are_equal( const NAObject *a, const NAObject *b )
 
 				g_free( id );
 			}
-			na_object_free_items( profiles );
 		}
 
 #if NA_IDUPLICABLE_EDITION_STATUS_DEBUG
diff --git a/src/runtime/na-object-api.h b/src/runtime/na-object-api.h
index acfcf39..31cdbd0 100644
--- a/src/runtime/na-object-api.h
+++ b/src/runtime/na-object-api.h
@@ -59,6 +59,7 @@ G_BEGIN_DECLS
 #define na_object_dump( object )					na_object_object_dump( NA_OBJECT( object ))
 #define na_object_dump_norec( object )				na_object_object_dump_norec( NA_OBJECT( object ))
 #define na_object_dump_tree( tree )					na_object_object_dump_tree( tree )
+#define na_object_unref( object )					na_object_object_unref( NA_OBJECT( object ))
 
 /* NAIDuplicable
  */
@@ -84,7 +85,7 @@ G_BEGIN_DECLS
 #define na_object_get_provider( object )			na_object_item_get_provider( NA_OBJECT_ITEM( object ))
 #define na_object_is_enabled( object )				na_object_item_is_enabled( NA_OBJECT_ITEM( object ))
 #define na_object_get_item( object, id )			na_object_item_get_item( NA_OBJECT_ITEM( object ), id )
-#define na_object_get_items( object )				na_object_item_get_items( NA_OBJECT_ITEM( object ))
+#define na_object_get_items_list( object )			na_object_item_get_items_list( NA_OBJECT_ITEM( object ))
 #define na_object_get_items_count( object )			na_object_item_get_items_count( NA_OBJECT_ITEM( object ))
 #define na_object_free_items( list )				na_object_item_free_items( list )
 
@@ -92,7 +93,7 @@ G_BEGIN_DECLS
 #define na_object_set_icon( object, icon )			na_object_item_set_icon( NA_OBJECT_ITEM( object ), icon )
 #define na_object_set_provider( object, provider )	na_object_item_set_provider( NA_OBJECT_ITEM( object ), provider )
 #define na_object_set_enabled( object, enabled )	na_object_item_set_enabled( NA_OBJECT_ITEM( object ), enabled )
-#define na_object_set_items( object, list )			na_object_item_set_items( NA_OBJECT_ITEM( object ), list )
+#define na_object_set_items_list( object, list )	na_object_item_set_items_list( NA_OBJECT_ITEM( object ), list )
 
 #define na_object_append_item( object, item )		na_object_item_append_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ))
 
diff --git a/src/runtime/na-object-class.h b/src/runtime/na-object-class.h
index d1b1f44..68acea1 100644
--- a/src/runtime/na-object-class.h
+++ b/src/runtime/na-object-class.h
@@ -163,6 +163,14 @@ typedef struct {
 	 * if any.
 	 */
 	GList *    ( *get_childs )      ( const NAObject *object );
+
+	/**
+	 * unref:
+	 * @object: the #NAObject object.
+	 *
+	 * Recursively unref all childs.
+	 */
+	void       ( *unref )           ( NAObject *object );
 }
 	NAObjectClass;
 
diff --git a/src/runtime/na-object-fn.h b/src/runtime/na-object-fn.h
index 4ea6264..dad61e8 100644
--- a/src/runtime/na-object-fn.h
+++ b/src/runtime/na-object-fn.h
@@ -57,6 +57,7 @@ gboolean  na_object_iduplicable_is_modified( const NAObject *object );
 void      na_object_object_dump( const NAObject *object );
 void      na_object_object_dump_norec( const NAObject *object );
 void      na_object_object_dump_tree( GList *tree );
+void      na_object_object_unref( NAObject *object );
 
 GList    *na_object_most_derived_get_childs( const NAObject *object );
 GList    *na_object_get_hierarchy( const NAObject *object );
diff --git a/src/runtime/na-object-item-fn.h b/src/runtime/na-object-item-fn.h
index ee8a1e8..b6a49f3 100644
--- a/src/runtime/na-object-item-fn.h
+++ b/src/runtime/na-object-item-fn.h
@@ -52,7 +52,7 @@ gchar         *na_object_item_get_icon( const NAObjectItem *item );
 NAIIOProvider *na_object_item_get_provider( const NAObjectItem *item );
 gboolean       na_object_item_is_enabled( const NAObjectItem *item );
 NAObject      *na_object_item_get_item( const NAObjectItem *item, const gchar *id );
-GList         *na_object_item_get_items( const NAObjectItem *item );
+GList         *na_object_item_get_items_list( const NAObjectItem *item );
 guint          na_object_item_get_items_count( const NAObjectItem *item );
 void           na_object_item_free_items( GList *items );
 
@@ -60,7 +60,7 @@ void           na_object_item_set_tooltip( NAObjectItem *item, const gchar *tool
 void           na_object_item_set_icon( NAObjectItem *item, const gchar *icon_name );
 void           na_object_item_set_enabled( NAObjectItem *item, gboolean enabled );
 void           na_object_item_set_provider( NAObjectItem *item, const NAIIOProvider *provider );
-void           na_object_item_set_items( NAObjectItem *item, GList *items );
+void           na_object_item_set_items_list( NAObjectItem *item, GList *items );
 
 void           na_object_item_append_item( NAObjectItem *item, const NAObject *object );
 
diff --git a/src/runtime/na-object-item.c b/src/runtime/na-object-item.c
index b74d25d..41c47f8 100644
--- a/src/runtime/na-object-item.c
+++ b/src/runtime/na-object-item.c
@@ -77,6 +77,7 @@ static void     object_copy( NAObject *target, const NAObject *source );
 static gboolean object_are_equal( const NAObject *a, const NAObject *b );
 static gboolean object_is_valid( const NAObject *object );
 static GList   *object_get_childs( const NAObject *object );
+static void     object_unref( NAObject *object );
 
 static gchar   *object_id_new_id( const NAObjectId *object, const NAObjectId *new_parent );
 
@@ -170,6 +171,7 @@ class_init( NAObjectItemClass *klass )
 	naobject_class->are_equal = object_are_equal;
 	naobject_class->is_valid = object_is_valid;
 	naobject_class->get_childs = object_get_childs;
+	naobject_class->unref = object_unref;
 
 	objectid_class = NA_OBJECT_ID_CLASS( klass );
 	objectid_class->new_id = object_id_new_id;
@@ -422,31 +424,23 @@ na_object_item_get_item( const NAObjectItem *item, const gchar *id )
 }
 
 /**
- * na_object_item_get_items:
+ * na_object_item_get_items_list:
  * @item: the #NAObjectItem from which we want a list of subitems.
  *
- * Returns: a newly allocated #GList of #NAObject objects which are
- * embedded in the @item. Depending of the exact nature of @item, these
- * may be #NAObjectMenu, #NAObjectAction or #NAObjectProfile subitems.
+ * Returns: the list of child objects.
  *
- * The returned pointer should be na_object_item_free_items() or
- * na_object_free_items() by the caller.
+ * The returned pointer is owned by @item, and must not be released
+ * by the caller.
  */
 GList *
-na_object_item_get_items( const NAObjectItem *item )
+na_object_item_get_items_list( const NAObjectItem *item )
 {
 	GList *items = NULL;
-	GList *it;
 
 	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
 
 	if( !item->private->dispose_has_run ){
-
-		for( it = item->private->items ; it ; it = it->next ){
-			items = g_list_prepend( items, g_object_ref( it->data ));
-		}
-
-		items = g_list_reverse( items );
+		items = item->private->items;
 	}
 
 	return( items );
@@ -478,25 +472,13 @@ na_object_item_get_items_count( const NAObjectItem *item )
  * @list: a list of #NAObject subitems as returned by
  * na_object_item_get_items().
  *
- * Frees the list.
+ * This function does nothing. It is just defined ad a placeholder and
+ * to keep in the code a balance between get_items() and free_items()
+ * calls.
  */
 void
 na_object_item_free_items( GList *items )
 {
-	GList *it;
-
-	for( it = items ; it ; it = it->next ){
-		if( G_IS_OBJECT( it->data )){
-			g_debug( "na_object_item_free_items: items=%p, it_data=%p (%s, ref_count=%d)",
-				( void * ) items,
-				( void * ) it->data, G_OBJECT_TYPE_NAME( it->data ), G_OBJECT( it->data )->ref_count);
-			g_object_unref( it->data );
-		} else {
-			g_debug( "na_object_item_free_items: %p not an object", ( void * ) it->data );
-		}
-	}
-
-	g_list_free( items );
 }
 
 /**
@@ -600,34 +582,22 @@ na_object_item_set_provider( NAObjectItem *item, const NAIIOProvider *provider )
 }
 
 /**
- * na_object_item_set_items:
+ * na_object_item_set_items_list:
  * @item: the #NAObjectItem whose subitems have to be set.
  * @list: a #GList list of #NAObject subitems to be installed.
  *
  * Sets the list of the subitems for the @item.
  *
- * The previously existing list is removed and replaced by the provided
- * one. As we create here a new list with a new reference on provided
- * subitems, the provided list can be safely na_object_items_free_items()
- * by the caller.
+ * The provided list pointer simply overrides the existing one.
  */
 void
-na_object_item_set_items( NAObjectItem *item, GList *items )
+na_object_item_set_items_list( NAObjectItem *item, GList *items )
 {
-	GList *it;
-
 	g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
 
 	if( !item->private->dispose_has_run ){
 
-		na_object_item_free_items( item->private->items );
-		item->private->items = NULL;
-
-		for( it = items ; it ; it = it->next ){
-			item->private->items = g_list_prepend( item->private->items, g_object_ref( it->data ));
-		}
-
-		item->private->items = g_list_reverse( item->private->items );
+		item->private->items = items;
 	}
 }
 
@@ -717,8 +687,7 @@ object_copy( NAObject *target, const NAObject *source )
 			subitems = g_list_prepend( subitems, na_object_duplicate( it->data ));
 		}
 		subitems = g_list_reverse( subitems );
-		na_object_set_items( target, subitems );
-		na_object_free_items( subitems );
+		na_object_set_items_list( target, subitems );
 	}
 }
 
@@ -856,6 +825,19 @@ object_get_childs( const NAObject *object )
 	return( childs );
 }
 
+static void
+object_unref( NAObject *object )
+{
+	GList *childs, *ic;
+
+	childs = object_get_childs( object );
+	for( ic = childs ; ic ; ic = ic->next ){
+		g_debug( "na_object_item_object_unref: object=%p (%s, ref_count=%d)",
+				( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
+		na_object_unref( ic->data );
+	}
+}
+
 /*
  * new_parent is not relevant when allocating a new UUID for an action
  * or a menu ; it may safely be left as NULL though there is no gain to
diff --git a/src/runtime/na-object-menu.c b/src/runtime/na-object-menu.c
index 8106c1a..0149417 100644
--- a/src/runtime/na-object-menu.c
+++ b/src/runtime/na-object-menu.c
@@ -239,7 +239,7 @@ na_object_menu_rebuild_items_list( const NAObjectMenu *menu )
 
 	if( !menu->private->dispose_has_run ){
 
-		items = na_object_get_items( menu );
+		items = na_object_get_items_list( menu );
 
 		for( it = items ; it ; it = it->next ){
 			NAObjectItem *item = NA_OBJECT_ITEM( it->data );
@@ -247,8 +247,6 @@ na_object_menu_rebuild_items_list( const NAObjectMenu *menu )
 			list = g_slist_prepend( list, uuid );
 		}
 
-		na_object_free_items( items );
-
 		list = g_slist_reverse( list );
 	}
 
diff --git a/src/runtime/na-object.c b/src/runtime/na-object.c
index 7e2dd92..2409e6a 100644
--- a/src/runtime/na-object.c
+++ b/src/runtime/na-object.c
@@ -60,6 +60,7 @@ static gboolean       iduplicable_are_equal( const NAIDuplicable *a, const NAIDu
 static gboolean       iduplicable_is_valid( const NAIDuplicable *object );
 
 static GList         *v_get_childs( const NAObject *object );
+static void           v_unref( NAObject *object );
 
 static gboolean       are_equal_hierarchy( const NAObject *a, const NAObject *b );
 static void           copy_hierarchy( NAObject *target, const NAObject *source );
@@ -140,6 +141,7 @@ class_init( NAObjectClass *klass )
 	klass->are_equal = do_are_equal;
 	klass->is_valid = do_is_valid;
 	klass->get_childs = NULL;
+	klass->unref = NULL;
 }
 
 static void
@@ -342,6 +344,9 @@ na_object_iduplicable_is_modified( const NAObject *object )
  * The recursivity is dealt with here. If we let #NAObjectItem do this,
  * the dump of #NAObjectItem-derived object will be splitted, childs
  * being inserted inside.
+ *
+ * na_object_dump() doesn't modify the reference count of the dumped
+ * object.
  */
 void
 na_object_object_dump( const NAObject *object )
@@ -392,6 +397,32 @@ na_object_object_dump_tree( GList *tree )
 }
 
 /**
+ * na_object_object_unref:
+ * @object: a #NAObject-derived object.
+ *
+ * Recursively unref the @object and all its childs, decrementing their
+ * reference_count by 1.
+ */
+void
+na_object_object_unref( NAObject *object )
+{
+	g_return_if_fail( NA_IS_OBJECT( object ));
+
+	if( !object->private->dispose_has_run ){
+
+		g_debug( "na_object_object_unref: object=%p (%s, ref_count=%d)",
+				( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
+
+		v_unref( object );
+
+		g_debug( "na_object_object_unref: unreffing %p (%s, ref_count=%d)",
+				( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
+
+		g_object_unref( object );
+	}
+}
+
+/**
  * na_object_most_derived_get_childs:
  * @object: this #NAObject instance.
  *
@@ -522,6 +553,14 @@ v_get_childs( const NAObject *object ){
 	return( na_object_most_derived_get_childs( object ));
 }
 
+static void
+v_unref( NAObject *object )
+{
+	if( NA_OBJECT_GET_CLASS( object )->unref ){
+		NA_OBJECT_GET_CLASS( object )->unref( object );
+	}
+}
+
 static gboolean
 are_equal_hierarchy( const NAObject *a, const NAObject *b )
 {
@@ -641,9 +680,8 @@ dump_tree( GList *tree, gint level )
 		g_free( label );
 
 		if( NA_IS_OBJECT_ITEM( it->data )){
-			subitems = na_object_get_items( it->data );
+			subitems = na_object_get_items_list( it->data );
 			dump_tree( subitems, level+1 );
-			na_object_free_items( subitems );
 		}
 	}
 
diff --git a/src/runtime/na-pivot.c b/src/runtime/na-pivot.c
index b6d2d4c..fdae6ac 100644
--- a/src/runtime/na-pivot.c
+++ b/src/runtime/na-pivot.c
@@ -703,9 +703,8 @@ get_item_from_tree( const NAPivot *pivot, GList *tree, uuid_t uuid )
 		}
 
 		if( !found && NA_IS_OBJECT_ITEM( ia->data )){
-			subitems = na_object_get_items( ia->data );
+			subitems = na_object_get_items_list( ia->data );
 			found = get_item_from_tree( pivot, subitems, uuid );
-			na_object_free_items( subitems );
 		}
 	}
 
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index 2ffe667..ccb47a5 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -214,9 +214,8 @@ get_action_from_cmdline( void )
 	GSList *mimetypes = NULL;
 	GSList *schemes = NULL;
 
-	profiles = na_object_get_items( action );
+	profiles = na_object_get_items_list( action );
 	profile = NA_OBJECT_PROFILE( profiles->data );
-	na_object_free_items( profiles );
 
 	na_object_set_label( action, label );
 	na_object_set_tooltip( action, tooltip );



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