[nautilus-actions] Implement NAIIOProvider::duplicate_data interface for desktop files



commit 4a836dec6db77a2fcc6abcb9b3a53d259e825476
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jun 18 11:39:24 2010 +0200

    Implement NAIIOProvider::duplicate_data interface for desktop files

 ChangeLog                              |   11 ++++++++
 src/core/na-object-item-factory.c      |    4 ++-
 src/core/na-object-item.c              |   19 ++++++++++++++
 src/io-desktop/nadp-desktop-provider.c |    1 +
 src/io-desktop/nadp-writer.c           |   41 ++++++++++++++++++++++++++++++++
 src/io-desktop/nadp-writer.h           |    5 ++-
 6 files changed, 78 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 00a4b5e..3639b71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2010-06-18 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-object-item-factory.c:
+	Provider data is no more duplicable by NAObjectFactory.
+
+	* src/core/na-object-item.c (object_copy):
+	Explicitely triggers NAIOProvider::duplicate_data method.
+
+	* src/io-desktop/nadp-desktop-provider.c (iio_provider_iface_init):
+	* src/io-desktop/nadp-writer.c:
+	* src/io-desktop/nadp-writer.h (nadp_iio_provider_duplicate_data):
+	Implement NAIIOProvider::duplicate_data interface.
+
 	* src/io-gconf/nagp-gconf-provider.c (iio_provider_iface_init):
 	Initialize NAIIOProvider duplicate_data() virtual pointer.
 
diff --git a/src/core/na-object-item-factory.c b/src/core/na-object-item-factory.c
index e0175bc..71e43d0 100644
--- a/src/core/na-object-item-factory.c
+++ b/src/core/na-object-item-factory.c
@@ -335,6 +335,8 @@ NADataDef data_def_item [] = {
 
 	/* dynamic data, so non readable / non writable (but has property)
 	 * is left at the NAIIOProvider disposition
+	 * not copyable as directly duplicated by NAIIOProvider interface
+	 * (see NAObjectItem::object_copy)
 	 */
 	{ NAFO_DATA_PROVIDER_DATA,
 				FALSE,
@@ -345,7 +347,7 @@ NADataDef data_def_item [] = {
 				NAFD_TYPE_POINTER,
 				NULL,
 				FALSE,
-				TRUE,
+				FALSE,
 				FALSE,
 				FALSE,
 				FALSE,
diff --git a/src/core/na-object-item.c b/src/core/na-object-item.c
index f304904..c7055f9 100644
--- a/src/core/na-object-item.c
+++ b/src/core/na-object-item.c
@@ -38,6 +38,8 @@
 #include <api/na-core-utils.h>
 #include <api/na-object-api.h>
 
+#include "na-io-provider.h"
+
 /* private class data
  */
 struct NAObjectItemClassPrivate {
@@ -204,6 +206,9 @@ instance_finalize( GObject *object )
 static void
 object_copy( NAObject *target, const NAObject *source, gboolean recursive )
 {
+	static const gchar *thisfn = "na_object_item_object_copy";
+	void *provider;
+
 	g_return_if_fail( NA_IS_OBJECT_ITEM( target ));
 	g_return_if_fail( NA_IS_OBJECT_ITEM( source ));
 
@@ -213,6 +218,20 @@ object_copy( NAObject *target, const NAObject *source, gboolean recursive )
 		if( recursive ){
 			copy_children( NA_OBJECT_ITEM( target ), NA_OBJECT_ITEM( source ));
 		}
+
+		provider = na_object_get_provider( source );
+
+		if( provider ){
+			if( !NA_IS_IO_PROVIDER( provider )){
+				g_warning( "%s: source=%p (%s), provider=%p is not a NAIOProvider",
+						thisfn,
+						( void * ) source, G_OBJECT_TYPE_NAME( source ),
+						( void * ) provider );
+
+			} else {
+				na_io_provider_duplicate_data( NA_IO_PROVIDER( provider ), NA_OBJECT_ITEM( target ), NA_OBJECT_ITEM( source ), NULL );
+			}
+		}
 	}
 }
 
diff --git a/src/io-desktop/nadp-desktop-provider.c b/src/io-desktop/nadp-desktop-provider.c
index 9593c11..d96d29e 100644
--- a/src/io-desktop/nadp-desktop-provider.c
+++ b/src/io-desktop/nadp-desktop-provider.c
@@ -204,6 +204,7 @@ iio_provider_iface_init( NAIIOProviderInterface *iface )
 	iface->is_able_to_write = nadp_iio_provider_is_able_to_write;
 	iface->write_item = nadp_iio_provider_write_item;
 	iface->delete_item = nadp_iio_provider_delete_item;
+	iface->duplicate_data = nadp_iio_provider_duplicate_data;
 }
 
 static guint
diff --git a/src/io-desktop/nadp-writer.c b/src/io-desktop/nadp-writer.c
index 4b1b03e..44992bf 100644
--- a/src/io-desktop/nadp-writer.c
+++ b/src/io-desktop/nadp-writer.c
@@ -276,6 +276,47 @@ desktop_weak_notify( NadpDesktopFile *ndf, GObject *item )
 	g_object_unref( ndf );
 }
 
+/*
+ * Implementation of NAIIOProvider::duplicate_data
+ * Add a ref on NadpDesktopFile data, so that unreffing origin object in NACT
+ * does not invalid duplicated pointer
+ */
+guint
+nadp_iio_provider_duplicate_data( const NAIIOProvider *provider, NAObjectItem *dest, const NAObjectItem *source, GSList **messages )
+{
+	static const gchar *thisfn = "nadp_iio_provider_duplicate_data";
+	guint ret;
+	NadpDesktopProvider *self;
+	NadpDesktopFile *ndf;
+
+	g_debug( "%s: provider=%p (%s), dest=%p (%s), source=%p (%s), messages=%p",
+			thisfn,
+			( void * ) provider, G_OBJECT_TYPE_NAME( provider ),
+			( void * ) dest, G_OBJECT_TYPE_NAME( dest ),
+			( void * ) source, G_OBJECT_TYPE_NAME( source ),
+			( void * ) messages );
+
+	ret = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR;
+
+	g_return_val_if_fail( NA_IS_IIO_PROVIDER( provider ), ret );
+	g_return_val_if_fail( NADP_IS_DESKTOP_PROVIDER( provider ), ret );
+	g_return_val_if_fail( NA_IS_OBJECT_ITEM( dest ), ret );
+	g_return_val_if_fail( NA_IS_OBJECT_ITEM( source ), ret );
+
+	self = NADP_DESKTOP_PROVIDER( provider );
+
+	if( self->private->dispose_has_run ){
+		return( NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN );
+	}
+
+	ndf = ( NadpDesktopFile * ) na_object_get_provider_data( source );
+	g_return_val_if_fail( ndf && NADP_IS_DESKTOP_FILE( ndf ), ret );
+	na_object_set_provider_data( dest, g_object_ref( ndf ));
+	g_object_weak_ref( G_OBJECT( dest ), ( GWeakNotify ) desktop_weak_notify, ndf );
+
+	return( NA_IIO_PROVIDER_CODE_OK );
+}
+
 #if 0
 /*
  * the item comes from being readen from a desktop file
diff --git a/src/io-desktop/nadp-writer.h b/src/io-desktop/nadp-writer.h
index 0f6cf01..6dfe1a9 100644
--- a/src/io-desktop/nadp-writer.h
+++ b/src/io-desktop/nadp-writer.h
@@ -38,8 +38,9 @@ G_BEGIN_DECLS
 gboolean nadp_iio_provider_is_willing_to_write( const NAIIOProvider *provider );
 gboolean nadp_iio_provider_is_able_to_write   ( const NAIIOProvider *provider );
 
-guint    nadp_iio_provider_write_item ( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages );
-guint    nadp_iio_provider_delete_item( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages );
+guint    nadp_iio_provider_write_item    ( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages );
+guint    nadp_iio_provider_delete_item   ( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages );
+guint    nadp_iio_provider_duplicate_data( const NAIIOProvider *provider, NAObjectItem *dest, const NAObjectItem *source, GSList **messages );
 
 guint    nadp_writer_ifactory_provider_write_start(
 				const NAIFactoryProvider *provider, void *writer_data, const NAIFactoryObject *object,



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