[nautilus-actions] na_object_free_items renamed to na_object_free_items_list



commit 26d2fb3b3271f91648e3f3cedda4f0df56065adb
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Oct 8 19:33:43 2009 +0200

    na_object_free_items renamed to na_object_free_items_list

 ChangeLog                        |   16 ++++++++++++++++
 src/nact/nact-assistant-export.c |    4 ++--
 src/nact/nact-assistant-import.c |    2 +-
 src/nact/nact-iactions-list.c    |   12 ++++++------
 src/nact/nact-main-menubar.c     |   16 ++++++++--------
 src/nact/nact-main-window.c      |    8 ++++----
 src/runtime/na-iio-provider.c    |    2 +-
 src/runtime/na-object-api.h      |    4 +++-
 src/runtime/na-object-class.h    |   10 +++++++++-
 src/runtime/na-object-fn.h       |    1 +
 src/runtime/na-object-item-fn.h  |    3 ++-
 src/runtime/na-object-item.c     |   37 ++++++++++++++++++++++++++++---------
 src/runtime/na-object.c          |   36 ++++++++++++++++++++++++++++++++++++
 src/runtime/na-pivot.c           |    4 ++--
 14 files changed, 119 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0f79477..2c9dcbb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2009-10-08 Pierre Wieser <pwieser trychlos org>
 
+	na_object_free_items: Renamed to na_object_free_items_list.
+
+	* src/nact/nact-assistant-export.c:
+	* src/nact/nact-assistant-import.c:
+	* src/nact/nact-iactions-list.c:
+	* src/nact/nact-main-menubar.c:
+	* src/nact/nact-main-window.c:
+	* src/runtime/na-iio-provider.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.c:
+	* src/runtime/na-pivot.c: Updated accordingly.
+
 	na_object_get_items: Renamed to na_object_get_items_list,
 	Now returns the list itself instead of a refed new list.
 
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 763f53c..6a6bfb1 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -435,7 +435,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 		}
 	}
 
-	na_object_free_items( actions );
+	na_object_free_items_list( actions );
 
 	if( window->private->errors ){
 		if( !reason ){
@@ -750,7 +750,7 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
 		text = tmp;
 	}
 
-	na_object_free_items( actions );
+	na_object_free_items_list( actions );
 
 	g_assert( window->private->uri && strlen( window->private->uri ));
 
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index 9c7d884..ce056b5 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -661,7 +661,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 
 		items = g_list_prepend( NULL, action );
 		nact_iactions_list_insert_items( NACT_IACTIONS_LIST( mainwnd ), items, NULL );
-		na_object_free_items( items );
+		na_object_free_items_list( items );
 	}
 
 	na_utils_free_string_list( uris );
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 101a613..8160c23 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -284,7 +284,7 @@ static void
 free_items_callback( NactIActionsList *instance, GList *items )
 {
 	g_debug( "free_items_callback: selection=%p (%d items)", ( void * ) items, g_list_length( items ));
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 }
 
 static void
@@ -792,11 +792,10 @@ nact_iactions_list_get_management_mode( NactIActionsList *instance )
  * Returns: the currently selected rows as a list of #NAObjects.
  *
  * We acquire here a new reference on objects corresponding to actually
- * selected rows. It is supposed that their subitems are also concerned,
- * but this may be caller-dependant.
+ * selected rows, and their childs.
  *
- * The caller may safely call na_object_free_items() on the returned
- * list, or g_list_free() if it wants keep the references somewhere.
+ * The caller may safely call na_object_free_items_list() on the
+ * returned list.
  */
 GList *
 nact_iactions_list_get_selected_items( NactIActionsList *instance )
@@ -822,7 +821,8 @@ 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 );
-			items = g_list_prepend( items, object );
+			items = g_list_prepend( items, na_object_ref( object ));
+			g_object_unref( object );
 		}
 
 		g_list_foreach( listrows, ( GFunc ) gtk_tree_path_free, NULL );
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index e88bbdb..7d1bc8b 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -470,7 +470,7 @@ on_new_menu_activated( GtkAction *gtk_action, NactMainWindow *window )
 	menu = na_object_menu_new();
 	items = g_list_prepend( NULL, menu );
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 }
 
 static void
@@ -485,7 +485,7 @@ on_new_action_activated( GtkAction *gtk_action, NactMainWindow *window )
 	action = na_object_action_new_with_profile();
 	items = g_list_prepend( NULL, action );
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 }
 
 static void
@@ -514,7 +514,7 @@ on_new_profile_activated( GtkAction *gtk_action, NactMainWindow *window )
 	items = g_list_prepend( NULL, profile );
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 	g_free( name );
 }
 
@@ -700,7 +700,7 @@ on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
 	clipboard = nact_main_window_get_clipboard( window );
 	nact_clipboard_primary_set( clipboard, items, CLIPBOARD_MODE_COPY );
 	update_clipboard_counters( window );
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 
 	g_signal_emit_by_name( window, MAIN_WINDOW_SIGNAL_UPDATE_ACTION_SENSITIVITIES, NULL );
 }
@@ -727,7 +727,7 @@ on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
 
 	items = prepare_for_paste( window );
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 }
 
 /*
@@ -752,7 +752,7 @@ on_paste_into_activated( GtkAction *gtk_action, NactMainWindow *window )
 
 	items = prepare_for_paste( window );
 	nact_iactions_list_insert_into( NACT_IACTIONS_LIST( window ), items );
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 }
 
 static GList *
@@ -835,10 +835,10 @@ on_duplicate_activated( GtkAction *gtk_action, NactMainWindow *window )
 		na_object_set_origin( obj, NULL );
 		dup = g_list_prepend( NULL, obj );
 		nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), dup, it->data );
-		na_object_free_items( dup );
+		na_object_free_items_list( dup );
 	}
 
-	na_object_free_items( items );
+	na_object_free_items_list( items );
 }
 
 /*
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 580f829..4a48b64 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -552,7 +552,7 @@ instance_dispose( GObject *window )
 		for( it = self->private->deleted ; it ; it = it->next ){
 			g_debug( "nact_main_window_instance_dispose: %p (%s)", ( void * ) it->data, G_OBJECT_TYPE_NAME( it->data ));
 		}
-		na_object_free_items( self->private->deleted );
+		na_object_free_items_list( self->private->deleted );
 
 		nact_iactions_list_dispose( NACT_IACTIONS_LIST( window ));
 		nact_iaction_tab_dispose( NACT_IACTION_TAB( window ));
@@ -712,7 +712,7 @@ nact_main_window_has_modified_items( const NactMainWindow *window )
  * Adds the given list to the deleted one.
  *
  * Note that we move the ref from @items list to our own deleted list.
- * So that the caller should not try to na_object_free_items() the
+ * So that the caller should not try to na_object_free_items_list() the
  * provided list.
  */
 void
@@ -789,7 +789,7 @@ nact_main_window_remove_deleted( NactMainWindow *window )
 		}
 
 		g_debug( "nact_main_window_remove_deleted: before free deleted" );
-		na_object_free_items( window->private->deleted );
+		na_object_free_items_list( window->private->deleted );
 		window->private->deleted = NULL;
 	}
 }
@@ -1168,7 +1168,7 @@ reload( NactMainWindow *window )
 		na_pivot_reload_items( pivot );
 		nact_iactions_list_fill( NACT_IACTIONS_LIST( window ), na_pivot_get_items( pivot ));
 
-		na_object_free_items( window->private->deleted );
+		na_object_free_items_list( window->private->deleted );
 		window->private->deleted = NULL;
 	}
 }
diff --git a/src/runtime/na-iio-provider.c b/src/runtime/na-iio-provider.c
index 16588b9..ccd53a6 100644
--- a/src/runtime/na-iio-provider.c
+++ b/src/runtime/na-iio-provider.c
@@ -175,7 +175,7 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
 		level_zero = na_iprefs_get_level_zero_items( NA_IPREFS( pivot ));
 		hierarchy = build_hierarchy( merged, level_zero, TRUE );
 		na_utils_free_string_list( level_zero );
-		na_object_free_items( merged );
+		na_object_free_items_list( merged );
 
 		g_debug( "%s: tree before alphabetical reordering (if any)", thisfn );
 		na_object_dump_tree( hierarchy );
diff --git a/src/runtime/na-object-api.h b/src/runtime/na-object-api.h
index 31cdbd0..8c8963b 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_ref( object )						na_object_object_ref( NA_OBJECT( object ))
 #define na_object_unref( object )					na_object_object_unref( NA_OBJECT( object ))
 
 /* NAIDuplicable
@@ -80,6 +81,8 @@ G_BEGIN_DECLS
 
 /* NAObjectItem
  */
+#define na_object_free_items_list( list )			na_object_item_free_items_list( list )
+
 #define na_object_get_tooltip( object )				na_object_item_get_tooltip( NA_OBJECT_ITEM( object ))
 #define na_object_get_icon( object )				na_object_item_get_icon( NA_OBJECT_ITEM( object ))
 #define na_object_get_provider( object )			na_object_item_get_provider( NA_OBJECT_ITEM( object ))
@@ -87,7 +90,6 @@ G_BEGIN_DECLS
 #define na_object_get_item( object, id )			na_object_item_get_item( NA_OBJECT_ITEM( object ), id )
 #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 )
 
 #define na_object_set_tooltip( object, tooltip )	na_object_item_set_tooltip( NA_OBJECT_ITEM( object ), tooltip )
 #define na_object_set_icon( object, icon )			na_object_item_set_icon( NA_OBJECT_ITEM( object ), icon )
diff --git a/src/runtime/na-object-class.h b/src/runtime/na-object-class.h
index 68acea1..a7fb83d 100644
--- a/src/runtime/na-object-class.h
+++ b/src/runtime/na-object-class.h
@@ -165,10 +165,18 @@ typedef struct {
 	GList *    ( *get_childs )      ( const NAObject *object );
 
 	/**
+	 * ref:
+	 * @object: the #NAObject object.
+	 *
+	 * Recursively ref the @object and all its childs.
+	 */
+	void       ( *ref )             ( NAObject *object );
+
+	/**
 	 * unref:
 	 * @object: the #NAObject object.
 	 *
-	 * Recursively unref all childs.
+	 * Recursively unref the @object and all its childs.
 	 */
 	void       ( *unref )           ( NAObject *object );
 }
diff --git a/src/runtime/na-object-fn.h b/src/runtime/na-object-fn.h
index dad61e8..51341fc 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 );
+NAObject *na_object_object_ref( NAObject *object );
 void      na_object_object_unref( NAObject *object );
 
 GList    *na_object_most_derived_get_childs( const NAObject *object );
diff --git a/src/runtime/na-object-item-fn.h b/src/runtime/na-object-item-fn.h
index b6a49f3..9481503 100644
--- a/src/runtime/na-object-item-fn.h
+++ b/src/runtime/na-object-item-fn.h
@@ -47,6 +47,8 @@
 
 G_BEGIN_DECLS
 
+void           na_object_item_free_items_list( GList *items );
+
 gchar         *na_object_item_get_tooltip( const NAObjectItem *item );
 gchar         *na_object_item_get_icon( const NAObjectItem *item );
 NAIIOProvider *na_object_item_get_provider( const NAObjectItem *item );
@@ -54,7 +56,6 @@ 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_list( const NAObjectItem *item );
 guint          na_object_item_get_items_count( const NAObjectItem *item );
-void           na_object_item_free_items( GList *items );
 
 void           na_object_item_set_tooltip( NAObjectItem *item, const gchar *tooltip );
 void           na_object_item_set_icon( NAObjectItem *item, const gchar *icon_name );
diff --git a/src/runtime/na-object-item.c b/src/runtime/na-object-item.c
index 41c47f8..14058ef 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_ref( NAObject *object );
 static void     object_unref( NAObject *object );
 
 static gchar   *object_id_new_id( const NAObjectId *object, const NAObjectId *new_parent );
@@ -171,6 +172,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->ref = object_ref;
 	naobject_class->unref = object_unref;
 
 	objectid_class = NA_OBJECT_ID_CLASS( klass );
@@ -468,17 +470,21 @@ na_object_item_get_items_count( const NAObjectItem *item )
 }
 
 /**
- * na_object_item_free_items:
- * @list: a list of #NAObject subitems as returned by
- * na_object_item_get_items().
+ * na_object_item_free_items_list:
+ * @list: a list of #NAObject items.
  *
- * 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.
+ * Recursively unref the #NAObject of the list, freeing the list at last.
  */
 void
-na_object_item_free_items( GList *items )
+na_object_item_free_items_list( GList *items )
 {
+	GList *it;
+
+	for( it = items ; it ; it = it->next ){
+		na_object_unref( it->data );
+	}
+
+	g_list_free( items );
 }
 
 /**
@@ -826,14 +832,27 @@ object_get_childs( const NAObject *object )
 }
 
 static void
+object_ref( 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_ref( ic->data );
+	}
+}
+
+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 );
+		/*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 );
 	}
 }
diff --git a/src/runtime/na-object.c b/src/runtime/na-object.c
index 2409e6a..8740e70 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_ref( NAObject *object );
 static void           v_unref( NAObject *object );
 
 static gboolean       are_equal_hierarchy( const NAObject *a, const NAObject *b );
@@ -141,6 +142,7 @@ class_init( NAObjectClass *klass )
 	klass->are_equal = do_are_equal;
 	klass->is_valid = do_is_valid;
 	klass->get_childs = NULL;
+	klass->ref = NULL;
 	klass->unref = NULL;
 }
 
@@ -397,6 +399,32 @@ na_object_object_dump_tree( GList *tree )
 }
 
 /**
+ * na_object_object_ref:
+ * @object: a #NAObject-derived object.
+ *
+ * Recursively ref the @object and all its childs, incrementing their
+ * reference_count by 1.
+ *
+ * Returns: a reference on the @pbject.
+ */
+NAObject *
+na_object_object_ref( NAObject *object )
+{
+	NAObject *ref = NULL;
+
+	g_return_if_fail( NA_IS_OBJECT( object ));
+
+	if( !object->private->dispose_has_run ){
+
+		v_ref( object );
+
+		ref = g_object_ref( object );
+	}
+
+	return( ref );
+}
+
+/**
  * na_object_object_unref:
  * @object: a #NAObject-derived object.
  *
@@ -554,6 +582,14 @@ v_get_childs( const NAObject *object ){
 }
 
 static void
+v_ref( NAObject *object )
+{
+	if( NA_OBJECT_GET_CLASS( object )->ref ){
+		NA_OBJECT_GET_CLASS( object )->ref( object );
+	}
+}
+
+static void
 v_unref( NAObject *object )
 {
 	if( NA_OBJECT_GET_CLASS( object )->unref ){
diff --git a/src/runtime/na-pivot.c b/src/runtime/na-pivot.c
index fdae6ac..3a8f58d 100644
--- a/src/runtime/na-pivot.c
+++ b/src/runtime/na-pivot.c
@@ -247,7 +247,7 @@ instance_dispose( GObject *object )
 		self->private->providers = NULL;
 
 		/* release item tree */
-		na_object_free_items( self->private->tree );
+		na_object_free_items_list( self->private->tree );
 		self->private->tree = NULL;
 
 		/* release the GConf monitoring */
@@ -426,7 +426,7 @@ na_pivot_reload_items( NAPivot *pivot )
 
 	if( !pivot->private->dispose_has_run ){
 
-		na_object_free_items( pivot->private->tree );
+		na_object_free_items_list( pivot->private->tree );
 
 		pivot->private->tree = na_iio_provider_get_items_tree( pivot );
 	}



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