[nautilus-actions] na_object_duplicate(): takes a DuplicateMode argument



commit 2e39e346019ac96f2d04551813967d2ef7be52d4
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Feb 1 20:05:27 2012 +0100

    na_object_duplicate(): takes a DuplicateMode argument

 ChangeLog                      |   16 +++++++++++++++
 src/api/na-iduplicable.h       |   41 +++++++++++++++++++++++++++------------
 src/api/na-object-api.h        |    2 +-
 src/api/na-object.h            |    6 ++--
 src/core/na-iduplicable.c      |   22 +++++---------------
 src/core/na-object-item.c      |   25 +++++++++++++++--------
 src/core/na-object.c           |   19 ++++++++++-------
 src/nact/nact-clipboard.c      |    4 +-
 src/nact/nact-menubar-edit.c   |    2 +-
 src/nact/nact-menubar-file.c   |    2 +-
 src/nact/nact-tree-model-dnd.c |    2 +-
 src/nact/nact-tree-model.c     |    2 +-
 12 files changed, 87 insertions(+), 56 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e86ae16..b4c2452 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2012-02-01 Pierre Wieser <pwieser trychlos org>
+
+	* src/api/na-iduplicable.h:
+	* src/core/na-iduplicable.c (copy, na_iduplicable_duplicate):
+	* src/api/na-object-api.h (na_object_duplicate):
+	* src/api/na-object.h (copy):
+	* src/core/na-object.c (iduplicable_copy):
+	* src/core/na-object-item.c (object_copy, copy_children): Add a 'mode' argument.
+
+	* src/nact/nact-clipboard.c
+	(nact_clipboard_primary_set, nact_clipboard_primary_get):
+	* src/nact/nact-menubar-edit.c (nact_menubar_edit_on_duplicate):
+	* src/nact/nact-menubar-file.c (nact_menubar_file_save_items):
+	* src/nact/nact-tree-model-dnd.c (drop_inside):
+	* src/nact/nact-tree-model.c (nact_tree_model_fill): Updated accordingly.
+
 2012-01-30 Pierre Wieser <pwieser trychlos org>
 
 	* src/plugin-tracker/na-tracker.c:
diff --git a/src/api/na-iduplicable.h b/src/api/na-iduplicable.h
index 0a3c757..1f1be30 100644
--- a/src/api/na-iduplicable.h
+++ b/src/api/na-iduplicable.h
@@ -132,7 +132,8 @@ typedef struct {
 	/**
 	 * copy:
 	 * @target: the #NAIDuplicable target of the copy.
-	 * @source: the #NAIDuplicable source of the copy
+	 * @source: the #NAIDuplicable source of the copy.
+	 * @mode: the duplication mode.
 	 *
 	 * Copies data from @source to @Åarget, so that @target becomes an
 	 * exact copy of @source.
@@ -144,7 +145,7 @@ typedef struct {
 	 *
 	 * Since: 2.30
 	 */
-	void     ( *copy )     ( NAIDuplicable *target, const NAIDuplicable *source );
+	void     ( *copy )      ( NAIDuplicable *target, const NAIDuplicable *source, guint mode );
 
 	/**
 	 * are_equal:
@@ -166,7 +167,7 @@ typedef struct {
 	 *
 	 * Since: 2.30
 	 */
-	gboolean ( *are_equal )( const NAIDuplicable *a, const NAIDuplicable *b );
+	gboolean ( *are_equal ) ( const NAIDuplicable *a, const NAIDuplicable *b );
 
 	/**
 	 * is_valid:
@@ -183,25 +184,39 @@ typedef struct {
 	 *
 	 * Since: 2.30
 	 */
-	gboolean ( *is_valid )   ( const NAIDuplicable *object );
+	gboolean ( *is_valid )  ( const NAIDuplicable *object );
 }
 	NAIDuplicableInterface;
 
 #define IDUPLICABLE_SIGNAL_MODIFIED_CHANGED		"iduplicable-modified-changed"
 #define IDUPLICABLE_SIGNAL_VALID_CHANGED		"iduplicable-valid-changed"
 
-GType          na_iduplicable_get_type( void );
+/**
+ * DuplicateMode:
+ * @DUPLICATE_ONLY:   only duplicates the provided object.
+ * @DUPLICATE_OBJECT: only duplicate a menu
+ *                    (a menu with some subitems is duplicated to an empty menu)
+ * @DUPLICATE_REC:    recursively duplicates all the provided hierarchy.
+ */
+typedef enum {
+	DUPLICATE_ONLY = 1,
+	DUPLICATE_OBJECT,
+	DUPLICATE_REC
+}
+	DuplicableMode;
+
+GType          na_iduplicable_get_type         ( void );
 
-void           na_iduplicable_dispose     ( const NAIDuplicable *object );
-void           na_iduplicable_dump        ( const NAIDuplicable *object );
-NAIDuplicable *na_iduplicable_duplicate   ( const NAIDuplicable *object );
-void           na_iduplicable_check_status( const NAIDuplicable *object );
+void           na_iduplicable_dispose          ( const NAIDuplicable *object );
+void           na_iduplicable_dump             ( const NAIDuplicable *object );
+NAIDuplicable *na_iduplicable_duplicate        ( const NAIDuplicable *object, guint mode );
+void           na_iduplicable_check_status     ( const NAIDuplicable *object );
 
-NAIDuplicable *na_iduplicable_get_origin  ( const NAIDuplicable *object );
-gboolean       na_iduplicable_is_valid    ( const NAIDuplicable *object );
-gboolean       na_iduplicable_is_modified ( const NAIDuplicable *object );
+NAIDuplicable *na_iduplicable_get_origin       ( const NAIDuplicable *object );
+gboolean       na_iduplicable_is_valid         ( const NAIDuplicable *object );
+gboolean       na_iduplicable_is_modified      ( const NAIDuplicable *object );
 
-void           na_iduplicable_set_origin  ( NAIDuplicable *object, const NAIDuplicable *origin );
+void           na_iduplicable_set_origin       ( NAIDuplicable *object, const NAIDuplicable *origin );
 
 void           na_iduplicable_register_consumer( GObject *consumer );
 
diff --git a/src/api/na-object-api.h b/src/api/na-object-api.h
index 56f5147..7d42d8c 100644
--- a/src/api/na-object-api.h
+++ b/src/api/na-object-api.h
@@ -54,7 +54,7 @@ G_BEGIN_DECLS
 
 /* NAIDuplicable
  */
-#define na_object_duplicate( obj )                      na_iduplicable_duplicate( NA_IDUPLICABLE( obj ))
+#define na_object_duplicate( obj, mode )                na_iduplicable_duplicate( NA_IDUPLICABLE( obj ), mode )
 #define na_object_check_status( obj )                   na_object_object_check_status_rec( NA_OBJECT( obj ))
 
 #define na_object_get_origin( obj )                     na_iduplicable_get_origin( NA_IDUPLICABLE( obj ))
diff --git a/src/api/na-object.h b/src/api/na-object.h
index 0abaadd..3e539be 100644
--- a/src/api/na-object.h
+++ b/src/api/na-object.h
@@ -98,8 +98,8 @@ typedef struct {
 	/**
 	 * copy:
 	 * @target: the NAObject-derived object which will receive data.
-	 * @source: the NAObject-derived object which will provide data.
-	 * @recursive: whether children should be recursively copied.
+	 * @source: the NAObject-derived object which provides data.
+	 * @mode: the copy mode.
 	 *
 	 * Copies data and properties from @source to @target.
 	 *
@@ -108,7 +108,7 @@ typedef struct {
 	 *
 	 * Since: 2.30
 	 */
-	void     ( *copy )     ( NAObject *target, const NAObject *source, gboolean recursive );
+	void     ( *copy )     ( NAObject *target, const NAObject *source, guint mode );
 
 	/**
 	 * are_equal:
diff --git a/src/core/na-iduplicable.c b/src/core/na-iduplicable.c
index ed7c72c..098eb9a 100644
--- a/src/core/na-iduplicable.c
+++ b/src/core/na-iduplicable.c
@@ -69,7 +69,7 @@ static GType          register_type( void );
 static void           interface_base_init( NAIDuplicableInterface *klass );
 static void           interface_base_finalize( NAIDuplicableInterface *klass );
 
-static void           v_copy( NAIDuplicable *target, const NAIDuplicable *source );
+static void           v_copy( NAIDuplicable *target, const NAIDuplicable *source, guint mode );
 static gboolean       v_are_equal( const NAIDuplicable *a, const NAIDuplicable *b );
 static gboolean       v_is_valid( const NAIDuplicable *object );
 
@@ -275,28 +275,18 @@ na_iduplicable_dump( const NAIDuplicable *object )
 /**
  * na_iduplicable_duplicate:
  * @object: the #NAIDuplicable object to be duplicated.
+ * @mode: the %DuplicableMode duplication mode.
  *
  * Exactly duplicates a #NAIDuplicable -implemented object, including
  * modification and validity status which are copied from @object to
  * the duplicated one.
  *
- * Though this function is not recursive by itself, it is widely supposed
- * everywhere in the program that recursivity is provided but #NAObject
- * implementation.
- *
- * <important>
- *   <para>
- *     na_object_duplicate() (aka na_iduplicable_duplicate())
- *     is definitively recursive
- *   </para>
- * </important>
- *
  * Returns: a new #NAIDuplicable.
  *
  * Since: 2.30
  */
 NAIDuplicable *
-na_iduplicable_duplicate( const NAIDuplicable *object )
+na_iduplicable_duplicate( const NAIDuplicable *object, guint mode )
 {
 	static const gchar *thisfn = "na_iduplicable_duplicate";
 	NAIDuplicable *dup;
@@ -310,7 +300,7 @@ na_iduplicable_duplicate( const NAIDuplicable *object )
 
 	dup = g_object_new( G_OBJECT_TYPE( object ), NULL );
 
-	v_copy( dup, object );
+	v_copy( dup, object, mode );
 
 	dup_str = get_duplicable_str( dup );
 	obj_str = get_duplicable_str( object );
@@ -503,10 +493,10 @@ na_iduplicable_set_modified( NAIDuplicable *object, gboolean modified )
 #endif /* NA_ENABLE_DEPRECATED */
 
 static void
-v_copy( NAIDuplicable *target, const NAIDuplicable *source )
+v_copy( NAIDuplicable *target, const NAIDuplicable *source, guint mode )
 {
 	if( NA_IDUPLICABLE_GET_INTERFACE( target )->copy ){
-		NA_IDUPLICABLE_GET_INTERFACE( target )->copy( target, source );
+		NA_IDUPLICABLE_GET_INTERFACE( target )->copy( target, source, mode );
 	}
 }
 
diff --git a/src/core/na-object-item.c b/src/core/na-object-item.c
index b62cef8..ced7cc7 100644
--- a/src/core/na-object-item.c
+++ b/src/core/na-object-item.c
@@ -69,7 +69,7 @@ static void     instance_dispose( GObject *object );
 static void     instance_finalize( GObject *object );
 
 static void     object_dump( const NAObject *object );
-static void     object_copy( NAObject*target, const NAObject *source, gboolean recursive );
+static void     object_copy( NAObject*target, const NAObject *source, guint mode );
 static gboolean object_are_equal( const NAObject *a, const NAObject *b );
 static gboolean object_is_valid( const NAObject *object );
 
@@ -77,7 +77,7 @@ static gchar   *object_id_new_id( const NAObjectId *item, const NAObjectId *new_
 
 static void     count_items_rec( GList *items, gint *menus, gint *actions, gint *profiles, gboolean recurse );
 static GSList  *get_children_slist( const NAObjectItem *item );
-static void     copy_children( NAObjectItem *target, const NAObjectItem *source );
+static void     copy_children( NAObjectItem *target, const NAObjectItem *source, guint mode );
 
 GType
 na_object_item_get_type( void )
@@ -225,7 +225,7 @@ object_dump( const NAObject *object )
 }
 
 static void
-object_copy( NAObject *target, const NAObject *source, gboolean recursive )
+object_copy( NAObject *target, const NAObject *source, guint mode )
 {
 	static const gchar *thisfn = "na_object_item_object_copy";
 	void *provider;
@@ -239,8 +239,10 @@ object_copy( NAObject *target, const NAObject *source, gboolean recursive )
 
 	if( !dest->private->dispose_has_run && !src->private->dispose_has_run ){
 
-		if( recursive ){
-			copy_children( dest, src );
+		if( mode == DUPLICATE_REC ||
+			( mode == DUPLICATE_OBJECT && G_OBJECT_TYPE( source ) == NA_TYPE_OBJECT_ACTION )){
+
+				copy_children( dest, src, mode );
 		}
 
 		provider = na_object_get_provider( source );
@@ -262,7 +264,7 @@ object_copy( NAObject *target, const NAObject *source, gboolean recursive )
 
 		/* chain up to the parent class */
 		if( NA_OBJECT_CLASS( st_parent_class )->copy ){
-			NA_OBJECT_CLASS( st_parent_class )->copy( target, source, recursive );
+			NA_OBJECT_CLASS( st_parent_class )->copy( target, source, mode );
 		}
 	}
 }
@@ -825,8 +827,12 @@ get_children_slist( const NAObjectItem *item )
 	return( g_slist_reverse( slist ));
 }
 
+/*
+ * only copy children if mode is 'full recursive'
+ * or mode is 'duplicate object' and this is an action with profiles
+ */
 static void
-copy_children( NAObjectItem *target, const NAObjectItem *source )
+copy_children( NAObjectItem *target, const NAObjectItem *source, guint mode )
 {
 	static const gchar *thisfn = "na_object_item_copy_children";
 	GList *tgt_children, *src_children, *ic;
@@ -835,14 +841,15 @@ copy_children( NAObjectItem *target, const NAObjectItem *source )
 	tgt_children = na_object_get_items( target );
 	if( tgt_children ){
 		g_warning( "%s: target_children=%p (count=%d)",
-				thisfn, ( void * ) tgt_children, g_list_length( tgt_children ));
+				thisfn,
+				( void * ) tgt_children, g_list_length( tgt_children ));
 		g_return_if_fail( tgt_children == NULL );
 	}
 
 	src_children = na_object_get_items( source );
 	for( ic = src_children ; ic ; ic = ic->next ){
 
-		dup = ( NAObject * ) na_object_duplicate( ic->data );
+		dup = ( NAObject * ) na_object_duplicate( ic->data, mode );
 		na_object_set_parent( dup, target );
 		tgt_children = g_list_prepend( tgt_children, dup );
 	}
diff --git a/src/core/na-object.c b/src/core/na-object.c
index e6f6ec5..bb70bbf 100644
--- a/src/core/na-object.c
+++ b/src/core/na-object.c
@@ -59,13 +59,13 @@ static void     instance_finalize( GObject *object );
 static void     object_dump( const NAObject *object );
 
 static void     iduplicable_iface_init( NAIDuplicableInterface *iface, void *user_data );
-static void     iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source );
+static void     iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source, guint mode );
 static gboolean iduplicable_are_equal( const NAIDuplicable *a, const NAIDuplicable *b );
 static gboolean iduplicable_is_valid( const NAIDuplicable *object );
 
 static void     check_status_down_rec( const NAObject *object );
 static void     check_status_up_rec( const NAObject *object, gboolean was_modified, gboolean was_valid );
-static void     v_copy( NAObject *target, const NAObject *source, gboolean recursive );
+static void     v_copy( NAObject *target, const NAObject *source, guint mode );
 static gboolean v_are_equal( const NAObject *a, const NAObject *b );
 static gboolean v_is_valid( const NAObject *a );
 static void     dump_tree( GList *tree, gint level );
@@ -224,7 +224,7 @@ iduplicable_iface_init( NAIDuplicableInterface *iface, void *user_data )
  * it recursively copies @source to @target
  */
 static void
-iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source )
+iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source, guint mode )
 {
 	static const gchar *thisfn = "na_object_iduplicable_copy";
 	NAObject *dest, *src;
@@ -238,8 +238,11 @@ iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source )
 	if( !dest->private->dispose_has_run &&
 		!src->private->dispose_has_run ){
 
-		g_debug( "%s: target=%p (%s), source=%p (%s)",
-				thisfn, ( void * ) dest, G_OBJECT_TYPE_NAME( dest ), ( void * ) src, G_OBJECT_TYPE_NAME( src ));
+		g_debug( "%s: target=%p (%s), source=%p (%s), mode=%d",
+				thisfn,
+				( void * ) dest, G_OBJECT_TYPE_NAME( dest ),
+				( void * ) src, G_OBJECT_TYPE_NAME( src ),
+				mode );
 
 		if( NA_IS_IFACTORY_OBJECT( target )){
 			na_factory_object_copy( NA_IFACTORY_OBJECT( target ), NA_IFACTORY_OBJECT( source ));
@@ -249,7 +252,7 @@ iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source )
 			na_icontext_copy( NA_ICONTEXT( target ), NA_ICONTEXT( source ));
 		}
 
-		v_copy( dest, src, TRUE );
+		v_copy( dest, src, mode );
 	}
 }
 
@@ -431,10 +434,10 @@ check_status_up_rec( const NAObject *object, gboolean was_modified, gboolean was
 }
 
 static void
-v_copy( NAObject *target, const NAObject *source, gboolean recursive )
+v_copy( NAObject *target, const NAObject *source, guint mode )
 {
 	if( NA_OBJECT_GET_CLASS( target )->copy ){
-		NA_OBJECT_GET_CLASS( target )->copy( target, source, recursive );
+		NA_OBJECT_GET_CLASS( target )->copy( target, source, mode );
 	}
 }
 
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index 87eaac4..6a05f7d 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -699,7 +699,7 @@ nact_clipboard_primary_set( NactClipboard *clipboard, GList *items, gint mode )
 
 		for( it = items ; it ; it = it->next ){
 			user_data->items =
-					g_list_prepend( user_data->items, na_object_duplicate( it->data ));
+					g_list_prepend( user_data->items, na_object_duplicate( it->data, DUPLICATE_REC ));
 		}
 		user_data->items = g_list_reverse( user_data->items );
 
@@ -749,7 +749,7 @@ nact_clipboard_primary_get( NactClipboard *clipboard, gboolean *relabel )
 
 			if( user_data ){
 				for( it = user_data->items ; it ; it = it->next ){
-					obj = NA_OBJECT( na_object_duplicate( it->data ));
+					obj = NA_OBJECT( na_object_duplicate( it->data, DUPLICATE_REC ));
 					na_object_set_origin( obj, NULL );
 					items = g_list_prepend( items, obj );
 				}
diff --git a/src/nact/nact-menubar-edit.c b/src/nact/nact-menubar-edit.c
index 9724bd0..496159c 100644
--- a/src/nact/nact-menubar-edit.c
+++ b/src/nact/nact-menubar-edit.c
@@ -406,7 +406,7 @@ nact_menubar_edit_on_duplicate( GtkAction *gtk_action, BaseWindow *window )
 	items = na_object_copyref_items( bar->private->selected_items );
 
 	for( it = items ; it ; it = it->next ){
-		obj = NA_OBJECT( na_object_duplicate( it->data ));
+		obj = NA_OBJECT( na_object_duplicate( it->data, DUPLICATE_REC ));
 		action = NULL;
 
 		/* duplicating a profile
diff --git a/src/nact/nact-menubar-file.c b/src/nact/nact-menubar-file.c
index 9d1f068..ec5216f 100644
--- a/src/nact/nact-menubar-file.c
+++ b/src/nact/nact-menubar-file.c
@@ -332,7 +332,7 @@ nact_menubar_file_save_items( BaseWindow *window )
 
 	for( it = items ; it ; it = it->next ){
 		save_item( window, bar->private->updater, NA_OBJECT_ITEM( it->data ), &messages );
-		duplicate = NA_OBJECT_ITEM( na_object_duplicate( it->data ));
+		duplicate = NA_OBJECT_ITEM( na_object_duplicate( it->data, DUPLICATE_REC ));
 		na_object_reset_origin( it->data, duplicate );
 		na_object_check_status( it->data );
 		new_pivot = g_list_prepend( new_pivot, duplicate );
diff --git a/src/nact/nact-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c
index 2bba001..9d7f270 100644
--- a/src/nact/nact-tree-model-dnd.c
+++ b/src/nact/nact-tree-model-dnd.c
@@ -614,7 +614,7 @@ drop_inside( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selecti
 				g_object_unref( current );
 
 				if( copy_data ){
-					inserted = ( NAObject * ) na_object_duplicate( current );
+					inserted = ( NAObject * ) na_object_duplicate( current, DUPLICATE_REC );
 					na_object_set_origin( inserted, NULL );
 					na_object_check_status( inserted );
 					relabel = na_updater_should_pasted_be_relabeled( updater, inserted );
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index ceb3800..b91665b 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -670,7 +670,7 @@ nact_tree_model_fill( NactTreeModel *model, GList *items )
 		gtk_tree_store_clear( ts_model );
 
 		for( it = items ; it ; it = it->next ){
-			duplicate = ( NAObject * ) na_object_duplicate( it->data );
+			duplicate = ( NAObject * ) na_object_duplicate( it->data, DUPLICATE_REC );
 			na_object_check_status( duplicate );
 			fill_tree_store( ts_model, model->private->treeview, duplicate, NULL );
 			na_object_unref( duplicate );



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