[nautilus-actions] Implement NAIfactoryProvider in GConf I/O provider writer
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Implement NAIfactoryProvider in GConf I/O provider writer
- Date: Fri, 26 Feb 2010 00:44:19 +0000 (UTC)
commit ff9c3d10548cc2ef2bac12847a5f123b3ffb0b52
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Feb 26 01:41:26 2010 +0100
Implement NAIfactoryProvider in GConf I/O provider writer
ChangeLog | 19 +++++
src/api/na-ifactory-object.h | 8 ++-
src/api/na-ifactory-provider.h | 14 +++-
src/api/na-object-api.h | 3 +-
src/api/na-object-item.h | 4 +-
src/core/na-factory-object.c | 101 +++++++++++++++++---------
src/core/na-factory-object.h | 2 +-
src/core/na-factory-provider.c | 44 +++++++++++-
src/core/na-factory-provider.h | 8 ++-
src/core/na-ifactory-provider.c | 47 +++++++++---
src/core/na-object-action.c | 18 ++++-
src/core/na-object-item.c | 81 +++++++++++----------
src/core/na-object-menu.c | 18 ++++-
src/core/na-object-profile.c | 7 +-
src/core/na-updater.c | 1 -
src/io-gconf/nagp-gconf-provider.c | 4 +-
src/io-gconf/nagp-writer.c | 144 +++++++++++++++++++++++++++++++++++-
src/io-gconf/nagp-writer.h | 13 +++
18 files changed, 420 insertions(+), 116 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f91a984..925cedc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2009-02-25 Pierre Wieser <pwieser trychlos org>
+ * src/api/na-ifactory-object.h:
+ * src/api/na-ifactory-provider.h:
+ * src/api/na-object-api.h:
+ * src/api/na-object-item.h:
+ * src/core/na-factory-object.c:
+ * src/core/na-factory-object.h:
+ * src/core/na-factory-provider.c:
+ * src/core/na-factory-provider.h:
+ * src/core/na-ifactory-provider.c:
+ * src/core/na-object-action.c:
+ * src/core/na-object-item.c:
+ * src/core/na-object-menu.c:
+ * src/core/na-object-profile.c:
+ * src/core/na-updater.c:
+ * src/io-gconf/nagp-gconf-provider.c:
+ * src/io-gconf/nagp-writer.c:
+ * src/io-gconf/nagp-writer.h:
+ Implement NAIfactoryProvider in GConf I/O provider writer.
+
Fix reference count errors in NACT user interface.
* src/core/na-object-id.c (instance_dispose):
diff --git a/src/api/na-ifactory-object.h b/src/api/na-ifactory-object.h
index b8f14f2..26e8d4e 100644
--- a/src/api/na-ifactory-object.h
+++ b/src/api/na-ifactory-object.h
@@ -167,8 +167,10 @@ typedef struct {
* may append messages to this list, but shouldn't reinitialize it.
*
* Called just before the object is serialized.
+ *
+ * Returns: a NAIIOProvider operation return code.
*/
- void ( *write_start )( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+ guint ( *write_start )( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
/**
* write_done:
@@ -179,8 +181,10 @@ typedef struct {
* may append messages to this list, but shouldn't reinitialize it.
*
* Called when the object has been serialized.
+ *
+ * Returns: a NAIIOProvider operation return code.
*/
- void ( *write_done ) ( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+ guint ( *write_done ) ( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
}
NAIFactoryObjectInterface;
diff --git a/src/api/na-ifactory-provider.h b/src/api/na-ifactory-provider.h
index f6c9186..1fab2a5 100644
--- a/src/api/na-ifactory-provider.h
+++ b/src/api/na-ifactory-provider.h
@@ -120,9 +120,11 @@ typedef struct {
* @messages: a pointer to a #GSList list of strings; the provider
* may append messages to this list, but shouldn't reinitialize it.
*
+ * Returns: a NAIIOProvider operation return code.
+ *
* API called by #NAIFactoryObject just before starting with writing data.
*/
- void ( *write_start )( const NAIFactoryProvider *writer, void *writer_data, const NAIFactoryObject *object, GSList **messages );
+ guint ( *write_start )( const NAIFactoryProvider *writer, void *writer_data, const NAIFactoryObject *object, GSList **messages );
/**
* write_data:
@@ -136,9 +138,11 @@ typedef struct {
*
* Write the data embedded in @value down to @instance.
*
+ * Returns: a NAIIOProvider operation return code.
+ *
* This method must be implemented in order any data be written.
*/
- void ( *write_data ) ( const NAIFactoryProvider *writer, void *writer_data, const NAIFactoryObject *object, const NADataDef *iddef, NADataBoxed *value, GSList **messages );
+ guint ( *write_data ) ( const NAIFactoryProvider *writer, void *writer_data, const NAIFactoryObject *object, const NADataBoxed *boxed, GSList **messages );
/**
* write_done:
@@ -148,17 +152,19 @@ typedef struct {
* @messages: a pointer to a #GSList list of strings; the provider
* may append messages to this list, but shouldn't reinitialize it.
*
+ * Returns: a NAIIOProvider operation return code.
+ *
* API called by #NAIFactoryObject when all data have been written.
* Implementor may take advantage of this to do some cleanup.
*/
- void ( *write_done ) ( const NAIFactoryProvider *writer, void *writer_data, const NAIFactoryObject *object, GSList **messages );
+ guint ( *write_done ) ( const NAIFactoryProvider *writer, void *writer_data, const NAIFactoryObject *object, GSList **messages );
}
NAIFactoryProviderInterface;
GType na_ifactory_provider_get_type( void );
void na_ifactory_provider_read_item ( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *object, GSList **messages );
-void na_ifactory_provider_write_item( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *object, GSList **messages );
+guint na_ifactory_provider_write_item( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *object, GSList **messages );
G_END_DECLS
diff --git a/src/api/na-object-api.h b/src/api/na-object-api.h
index fd94cc6..b3b3043 100644
--- a/src/api/na-object-api.h
+++ b/src/api/na-object-api.h
@@ -82,7 +82,7 @@ G_BEGIN_DECLS
#define na_object_get_parent( obj ) (( NAObjectItem * ) na_ifactory_object_get_as_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_PARENT ))
#define na_object_set_id( obj, id ) na_ifactory_object_set_from_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_ID, ( const void * )( id ))
-#define na_object_set_label( obj, label ) na_ifactory_object_set_from_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_LABEL, ( const void * )( label ))
+#define na_object_set_label( obj, label ) na_ifactory_object_set_from_void( NA_IFACTORY_OBJECT( obj ), ( NA_IS_OBJECT_PROFILE( obj ) ? NAFO_DATA_DESCNAME : NAFO_DATA_LABEL ), ( const void * )( label ))
#define na_object_set_parent( obj, parent ) na_ifactory_object_set_from_void( NA_IFACTORY_OBJECT( obj ), NAFO_DATA_PARENT, ( const void * )( parent ))
#define na_object_sort_alpha_asc( a, b ) na_object_id_sort_alpha_asc( NA_OBJECT_ID( a ), NA_OBJECT_ID( b ))
@@ -120,7 +120,6 @@ G_BEGIN_DECLS
#define na_object_insert_item( obj, child, sibling ) na_object_item_insert_item( NA_OBJECT_ITEM( obj ), NA_OBJECT( child ), ( NAObject * )( sibling ))
#define na_object_remove_item( obj, child ) na_object_item_remove_item( NA_OBJECT_ITEM( obj ), NA_OBJECT_ID( child ))
-#define na_object_build_items_slist( obj ) na_object_item_build_items_slist( NA_OBJECT_ITEM( obj ))
#define na_object_get_items_count( obj ) na_object_item_get_items_count( NA_OBJECT_ITEM( obj ))
#define na_object_count_items( list, cm, ca, cp, brec ) na_object_item_count_items( list, ( cm ), ( ca ), ( cp ), ( brec ))
#define na_object_unref_items( tree ) na_object_item_unref_items( tree )
diff --git a/src/api/na-object-item.h b/src/api/na-object-item.h
index 38d5b8c..3ce395e 100644
--- a/src/api/na-object-item.h
+++ b/src/api/na-object-item.h
@@ -87,13 +87,13 @@ void na_object_item_insert_at ( NAObjectItem *object, const NAObjectId
void na_object_item_insert_item ( NAObjectItem *object, const NAObject *item, const NAObject *before );
void na_object_item_remove_item ( NAObjectItem *object, const NAObjectId *item );
-GSList *na_object_item_build_items_slist( const NAObjectItem *item );
-
guint na_object_item_get_items_count( const NAObjectItem *item );
void na_object_item_count_items( GList *items, gint *menus, gint *actions, gint *profiles, gboolean recurse );
void na_object_item_unref_items( GList *items );
+void na_object_item_factory_write_start( NAObjectItem *item );
+
G_END_DECLS
#endif /* __NAUTILUS_ACTIONS_API_NA_OBJECT_ITEM_H__ */
diff --git a/src/core/na-factory-object.c b/src/core/na-factory-object.c
index 46fa0c4..86848bd 100644
--- a/src/core/na-factory-object.c
+++ b/src/core/na-factory-object.c
@@ -38,6 +38,7 @@
#include <api/na-core-utils.h>
#include <api/na-data-types.h>
+#include <api/na-iio-provider.h>
#include <api/na-ifactory-provider.h>
#include <api/na-data-boxed.h>
@@ -49,7 +50,7 @@
typedef gboolean ( *NADataDefIterFunc )( NADataDef *def, void *user_data );
-/* while iterating on read/write item
+/* while iterating on read item
*/
typedef struct {
NAIFactoryObject *object;
@@ -57,7 +58,17 @@ typedef struct {
void *reader_data;
GSList **messages;
}
- NafoRWIter;
+ NafoReadIter;
+
+/* while iterating on write item
+ */
+typedef struct {
+ NAIFactoryProvider *writer;
+ void *writer_data;
+ GSList **messages;
+ guint code;
+}
+ NafoWriteIter;
/* while iterating on is_valid
*/
@@ -87,8 +98,8 @@ extern NAIFactoryObjectInterface *ifactory_object_klass;
static gboolean define_class_properties_iter( const NADataDef *def, GObjectClass *class );
static gboolean factory_object_is_valid_mandatory_iter( const NADataDef *def, NafoValidIter *data );
-static gboolean factory_object_read_data_iter( NADataDef *def, NafoRWIter *iter );
-static gboolean factory_object_write_data_iter( NADataDef *def, NafoRWIter *iter );
+static gboolean factory_object_read_data_iter( NADataDef *def, NafoReadIter *iter );
+static gboolean factory_object_write_data_iter( const NAIFactoryObject *object, NADataBoxed *boxed, NafoWriteIter *iter );
static NADataGroup *v_get_groups( const NAIFactoryObject *object );
static void v_copy( NAIFactoryObject *target, const NAIFactoryObject *source );
@@ -96,8 +107,8 @@ static gboolean v_are_equal( const NAIFactoryObject *a, const NAIFactoryObje
static gboolean v_is_valid( const NAIFactoryObject *object );
static void v_read_start( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
static void v_read_done( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
-static void v_write_start( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
-static void v_write_done( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
+static guint v_write_start( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
+static guint v_write_done( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
static void attach_boxed_to_object( NAIFactoryObject *object, NADataBoxed *boxed );
static NADataBoxed *data_boxed_from_name( const NAIFactoryObject *object, const gchar *name );
@@ -626,7 +637,7 @@ na_factory_object_read_item( NAIFactoryObject *serializable, const NAIFactoryPro
if( groups ){
v_read_start( serializable, reader, reader_data, messages );
- NafoRWIter *iter = g_new0( NafoRWIter, 1 );
+ NafoReadIter *iter = g_new0( NafoReadIter, 1 );
iter->object = serializable;
iter->reader = ( NAIFactoryProvider * ) reader;
iter->reader_data = reader_data;
@@ -646,7 +657,7 @@ na_factory_object_read_item( NAIFactoryObject *serializable, const NAIFactoryPro
}
static gboolean
-factory_object_read_data_iter( NADataDef *def, NafoRWIter *iter )
+factory_object_read_data_iter( NADataDef *def, NafoReadIter *iter )
{
gboolean stop;
@@ -678,52 +689,66 @@ factory_object_read_data_iter( NADataDef *def, NafoRWIter *iter )
* may append messages to this list, but shouldn't reinitialize it.
*
* Serializes the object down to the @writer.
+ *
+ * Returns: a NAIIOProvider operation return code.
*/
-void
+guint
na_factory_object_write_item( NAIFactoryObject *serializable, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
{
static const gchar *thisfn = "na_factory_object_write_item";
+ guint code;
NADataGroup *groups;
gchar *msg;
- g_return_if_fail( NA_IS_IFACTORY_OBJECT( serializable ));
- g_return_if_fail( NA_IS_IFACTORY_PROVIDER( writer ));
+ g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( serializable ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+ g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( writer ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+
+ code = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR;
groups = v_get_groups( serializable );
+
if( groups ){
+ code = v_write_start( serializable, writer, writer_data, messages );
- v_write_start( serializable, writer, writer_data, messages );
+ } else {
+ msg = g_strdup_printf( "%s: class %s doesn't return any NADataGroup structure",
+ thisfn, G_OBJECT_TYPE_NAME( serializable ));
+ g_warning( "%s", msg );
+ *messages = g_slist_append( *messages, msg );
+ }
+
+ if( code == NA_IIO_PROVIDER_CODE_OK ){
- NafoRWIter *iter = g_new0( NafoRWIter, 1 );
- iter->object = serializable;
- iter->reader = ( NAIFactoryProvider * ) writer;
- iter->reader_data = writer_data;
+ NafoWriteIter *iter = g_new0( NafoWriteIter, 1 );
+ iter->writer = ( NAIFactoryProvider * ) writer;
+ iter->writer_data = writer_data;
iter->messages = messages;
+ iter->code = code;
- iter_on_data_defs( groups, TRUE, ( NADataDefIterFunc ) &factory_object_write_data_iter, iter );
+ na_factory_object_iter_on_boxed( serializable, ( NAFactoryObjectIterBoxedFn ) &factory_object_write_data_iter, iter );
+ code = iter->code;
g_free( iter );
+ }
- v_write_done( serializable, writer, writer_data, messages );
-
- } else {
- msg = g_strdup_printf( "%s: class %s doesn't return any NADataGroup structure",
- thisfn, G_OBJECT_TYPE_NAME( serializable ));
- g_warning( "%s", msg );
- *messages = g_slist_append( *messages, msg );
+ if( code == NA_IIO_PROVIDER_CODE_OK ){
+ code = v_write_done( serializable, writer, writer_data, messages );
}
+
+ return( code );
}
static gboolean
-factory_object_write_data_iter( NADataDef *def, NafoRWIter *iter )
+factory_object_write_data_iter( const NAIFactoryObject *object, NADataBoxed *boxed, NafoWriteIter *iter )
{
- gboolean stop;
-
- stop = FALSE;
+ NADataDef *def = na_data_boxed_get_data_def( boxed );
- /*na_factory_provider_set_value( iter->reader, iter->reader_data, def, iter->messages );*/
+ if( def->serializable && !def->obsoleted ){
+ iter->code = na_factory_provider_write_data( iter->writer, iter->writer_data, object, boxed, iter->messages );
+ }
- return( stop );
+ /* iter while code is ok */
+ return( iter->code == NA_IIO_PROVIDER_CODE_OK );
}
#if 0
@@ -985,20 +1010,28 @@ v_read_done( NAIFactoryObject *serializable, const NAIFactoryProvider *reader, v
}
}
-static void
+static guint
v_write_start( NAIFactoryObject *serializable, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
{
+ guint code = NA_IIO_PROVIDER_CODE_OK;
+
if( NA_IFACTORY_OBJECT_GET_INTERFACE( serializable )->write_start ){
- NA_IFACTORY_OBJECT_GET_INTERFACE( serializable )->write_start( serializable, writer, writer_data, messages );
+ code = NA_IFACTORY_OBJECT_GET_INTERFACE( serializable )->write_start( serializable, writer, writer_data, messages );
}
+
+ return( code );
}
-static void
+static guint
v_write_done( NAIFactoryObject *serializable, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
{
+ guint code = NA_IIO_PROVIDER_CODE_OK;
+
if( NA_IFACTORY_OBJECT_GET_INTERFACE( serializable )->write_done ){
- NA_IFACTORY_OBJECT_GET_INTERFACE( serializable )->write_done( serializable, writer, writer_data, messages );
+ code = NA_IFACTORY_OBJECT_GET_INTERFACE( serializable )->write_done( serializable, writer, writer_data, messages );
}
+
+ return( code );
}
#if 0
diff --git a/src/core/na-factory-object.h b/src/core/na-factory-object.h
index a645106..30101cf 100644
--- a/src/core/na-factory-object.h
+++ b/src/core/na-factory-object.h
@@ -65,7 +65,7 @@ void na_factory_object_dump ( const NAIFactoryObject *obje
void na_factory_object_finalize_instance ( NAIFactoryObject *object );
void na_factory_object_read_item ( NAIFactoryObject *object, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
-void na_factory_object_write_item ( NAIFactoryObject *object, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+guint na_factory_object_write_item ( NAIFactoryObject *object, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
void *na_factory_object_get_as_void ( const NAIFactoryObject *object, const gchar *name );
void na_factory_object_get_as_value ( const NAIFactoryObject *object, const gchar *name, GValue *value );
diff --git a/src/core/na-factory-provider.c b/src/core/na-factory-provider.c
index c4d069e..cf543f4 100644
--- a/src/core/na-factory-provider.c
+++ b/src/core/na-factory-provider.c
@@ -32,13 +32,15 @@
#include <config.h>
#endif
+#include <api/na-iio-provider.h>
+
#include "na-factory-provider.h"
extern gboolean ifactory_provider_initialized; /* defined in na-ifactory-provider.c */
extern gboolean ifactory_provider_finalized;
/**
- * na_factory_provider_read_value:
+ * na_factory_provider_read_data:
* @reader: the instance which implements this #NAIFactoryProvider interface.
* @reader_data: instance data.
* @object: the #NAIFactoryobject being unserialized.
@@ -47,9 +49,13 @@ extern gboolean ifactory_provider_finalized;
* may append messages to this list, but shouldn't reinitialize it.
*
* Reads the specified data and set it up into the @boxed.
+ *
+ * Returns: a new #NADataBoxed object which contains the data.
*/
NADataBoxed *
-na_factory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *object, const NADataDef *def, GSList **messages )
+na_factory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data,
+ const NAIFactoryObject *object, const NADataDef *def,
+ GSList **messages )
{
NADataBoxed *boxed;
@@ -68,3 +74,37 @@ na_factory_provider_read_data( const NAIFactoryProvider *reader, void *reader_da
return( boxed );
}
+
+/**
+ * na_factory_provider_write_data:
+ * @writer: the instance which implements this #NAIFactoryProvider interface.
+ * @writer_data: instance data.
+ * @object: the #NAIFactoryobject being serialized.
+ * @boxed: the #NADataBoxed object which is to be serialized.
+ * @messages: a pointer to a #GSList list of strings; the implementation
+ * may append messages to this list, but shouldn't reinitialize it.
+ *
+ * Returns: a NAIIOProvider operation return code.
+ */
+guint
+na_factory_provider_write_data( const NAIFactoryProvider *writer, void *writer_data,
+ const NAIFactoryObject *object, const NADataBoxed *boxed,
+ GSList **messages )
+{
+ guint code;
+
+ g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( writer ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+ g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+
+ code = NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN;
+
+ if( ifactory_provider_initialized && !ifactory_provider_finalized ){
+
+ if( NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_data ){
+
+ code = NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_data( writer, writer_data, object, boxed, messages );
+ }
+ }
+
+ return( code );
+}
diff --git a/src/core/na-factory-provider.h b/src/core/na-factory-provider.h
index 5cabfb1..7ebbe72 100644
--- a/src/core/na-factory-provider.h
+++ b/src/core/na-factory-provider.h
@@ -44,8 +44,12 @@
G_BEGIN_DECLS
-NADataBoxed *na_factory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data,
- NAIFactoryObject *object, const NADataDef *def,
+NADataBoxed *na_factory_provider_read_data ( const NAIFactoryProvider *reader, void *reader_data,
+ const NAIFactoryObject *object, const NADataDef *def,
+ GSList **messages );
+
+guint na_factory_provider_write_data( const NAIFactoryProvider *writer, void *writer_data,
+ const NAIFactoryObject *object, const NADataBoxed *boxed,
GSList **messages );
G_END_DECLS
diff --git a/src/core/na-ifactory-provider.c b/src/core/na-ifactory-provider.c
index c9b896f..d9ce801 100644
--- a/src/core/na-ifactory-provider.c
+++ b/src/core/na-ifactory-provider.c
@@ -32,6 +32,7 @@
#include <config.h>
#endif
+#include <api/na-iio-provider.h>
#include <api/na-ifactory-provider.h>
#include "na-factory-object.h"
@@ -54,8 +55,8 @@ static guint ifactory_provider_get_version( const NAIFactoryProvider *instance )
static void v_factory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *serializable, GSList **messages );
static void v_factory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, NAIFactoryObject *serializable, GSList **messages );
-static void v_factory_provider_write_start( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages );
-static void v_factory_provider_write_done( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages );
+static guint v_factory_provider_write_start( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages );
+static guint v_factory_provider_write_done( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages );
/**
* Registers the GType of this interface.
@@ -179,19 +180,33 @@ na_ifactory_provider_read_item( const NAIFactoryProvider *reader, void *reader_d
* may append messages to this list, but shouldn't reinitialize it.
*
* Writes the data down to the FactoryProvider.
+ *
+ * Returns: a NAIIOProvider operation return code.
*/
-void
+guint
na_ifactory_provider_write_item( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *object, GSList **messages )
{
- g_return_if_fail( NA_IS_IFACTORY_PROVIDER( writer ));
- g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
+ guint code;
+
+ g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( writer ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+ g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+
+ code = NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN;
if( ifactory_provider_initialized && !ifactory_provider_finalized ){
- v_factory_provider_write_start( writer, writer_data, object, messages );
- na_factory_object_write_item( object, writer, writer_data, messages );
- v_factory_provider_write_done( writer, writer_data, object, messages );
+ code = v_factory_provider_write_start( writer, writer_data, object, messages );
+
+ if( code == NA_IIO_PROVIDER_CODE_OK ){
+ code = na_factory_object_write_item( object, writer, writer_data, messages );
+ }
+
+ if( code == NA_IIO_PROVIDER_CODE_OK ){
+ code = v_factory_provider_write_done( writer, writer_data, object, messages );
+ }
}
+
+ return( code );
}
static void
@@ -210,18 +225,26 @@ v_factory_provider_read_done( const NAIFactoryProvider *reader, void *reader_dat
}
}
-static void
+static guint
v_factory_provider_write_start( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages )
{
+ guint code = NA_IIO_PROVIDER_CODE_OK;
+
if( NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_start ){
- NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_start( writer, writer_data, serializable, messages );
+ code = NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_start( writer, writer_data, serializable, messages );
}
+
+ return( code );
}
-static void
+static guint
v_factory_provider_write_done( const NAIFactoryProvider *writer, void *writer_data, NAIFactoryObject *serializable, GSList **messages )
{
+ guint code = NA_IIO_PROVIDER_CODE_OK;
+
if( NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_done ){
- NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_done( writer, writer_data, serializable, messages );
+ code = NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_done( writer, writer_data, serializable, messages );
}
+
+ return( code );
}
diff --git a/src/core/na-object-action.c b/src/core/na-object-action.c
index c8ebbf2..ab32e1c 100644
--- a/src/core/na-object-action.c
+++ b/src/core/na-object-action.c
@@ -35,6 +35,7 @@
#include <glib/gi18n.h>
#include <string.h>
+#include <api/na-iio-provider.h>
#include <api/na-object-api.h>
#include "na-factory-provider.h"
@@ -85,7 +86,8 @@ static void ifactory_object_copy( NAIFactoryObject *target, const NAIFac
static gboolean ifactory_object_are_equal( const NAIFactoryObject *a, const NAIFactoryObject *b );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
static void ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
-static void ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+static guint ifactory_object_write_start( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+static guint ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
static gboolean check_for_obsoleted_iter( const NAIFactoryObject *object, NADataBoxed *boxed, IterForObsoletedParms *parms );
@@ -279,7 +281,7 @@ ifactory_object_iface_init( NAIFactoryObjectInterface *iface )
iface->is_valid = ifactory_object_is_valid;
iface->read_start = NULL;
iface->read_done = ifactory_object_read_done;
- iface->write_start = NULL;
+ iface->write_start = ifactory_object_write_start;
iface->write_done = ifactory_object_write_done;
}
@@ -362,10 +364,18 @@ ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider
}
}
-static void
-ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
+static guint
+ifactory_object_write_start( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
{
+ na_object_item_factory_write_start( NA_OBJECT_ITEM( instance ));
+
+ return( NA_IIO_PROVIDER_CODE_OK );
+}
+static guint
+ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
+{
+ return( NA_IIO_PROVIDER_CODE_OK );
}
static gboolean
diff --git a/src/core/na-object-item.c b/src/core/na-object-item.c
index e1552c5..33f32c5 100644
--- a/src/core/na-object-item.c
+++ b/src/core/na-object-item.c
@@ -35,6 +35,7 @@
#include <string.h>
#include <uuid/uuid.h>
+#include <api/na-core-utils.h>
#include <api/na-object-api.h>
/* private class data
@@ -68,6 +69,8 @@ static void instance_finalize( GObject *object );
static gchar *object_id_new_id( const NAObjectId *item, const NAObjectId *new_parent );
+static void rebuild_children_slist( NAObjectItem *item );
+
GType
na_object_item_get_type( void )
{
@@ -568,45 +571,6 @@ na_object_item_remove_item( NAObjectItem *item, const NAObjectId *object )
}
/**
- * na_object_item_build_items_slist:
- * @item: this #NAObjectItem object.
- *
- * Returns: a string list which contains the ordered list of ids of
- * subitems.
- *
- * Note that the returned list is built on each call to this function,
- * and is so an exact image of the current situation.
- *
- * The returned list should be na_core_utils_slist_free() by the caller.
- */
-GSList *
-na_object_item_build_items_slist( const NAObjectItem *item )
-{
- GSList *slist;
- GList *subitems, *it;
- gchar *id;
-
- g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
-
- slist = NULL;
-
- if( !item->private->dispose_has_run ){
-
- subitems = na_object_get_items( item );
-
- for( it = subitems ; it ; it = it->next ){
- NAObjectId *item = NA_OBJECT_ID( it->data );
- id = na_object_get_id( item );
- slist = g_slist_prepend( slist, id );
- }
-
- slist = g_slist_reverse( slist );
- }
-
- return( slist );
-}
-
-/**
* na_object_item_get_items_count:
* @item: the #NAObjectItem from which we want a count of subitems.
*
@@ -663,8 +627,10 @@ na_object_item_count_items( GList *items, gint *menus, gint *actions, gint *prof
if( NA_IS_OBJECT_MENU( it->data )){
*menus += 1;
+
} else if( NA_IS_OBJECT_ACTION( it->data )){
*actions += 1;
+
} else if( NA_IS_OBJECT_PROFILE( it->data )){
*profiles += 1;
}
@@ -689,3 +655,40 @@ na_object_item_unref_items( GList *items )
g_list_free( items );
}
+
+/**
+ * na_object_item_factory_write_start:
+ * @item: this #NAObjectItem-derived object.
+ *
+ * Rebuild the string list of children.
+ */
+void
+na_object_item_factory_write_start( NAObjectItem *item )
+{
+ rebuild_children_slist( item );
+}
+
+static void
+rebuild_children_slist( NAObjectItem *item )
+{
+ GSList *slist;
+ GList *subitems, *it;
+ gchar *id;
+
+ slist = NULL;
+
+ if( !item->private->dispose_has_run ){
+
+ subitems = na_object_get_items( item );
+
+ for( it = subitems ; it ; it = it->next ){
+ id = na_object_get_id( it->data );
+ slist = g_slist_prepend( slist, id );
+ }
+ slist = g_slist_reverse( slist );
+
+ na_object_set_items_slist( item, slist );
+
+ na_core_utils_slist_free( slist );
+ }
+}
diff --git a/src/core/na-object-menu.c b/src/core/na-object-menu.c
index c72b118..1e091cb 100644
--- a/src/core/na-object-menu.c
+++ b/src/core/na-object-menu.c
@@ -35,6 +35,7 @@
#include <glib/gi18n.h>
#include <string.h>
+#include <api/na-iio-provider.h>
#include <api/na-ifactory-object.h>
#include <api/na-object-api.h>
@@ -78,7 +79,8 @@ static void ifactory_object_copy( NAIFactoryObject *target, const NAIFac
static gboolean ifactory_object_are_equal( const NAIFactoryObject *a, const NAIFactoryObject *b );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
static void ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
-static void ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+static guint ifactory_object_write_start( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+static guint ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
static gboolean menu_is_valid( const NAObjectMenu *menu );
static gboolean is_valid_label( const NAObjectMenu *menu );
@@ -269,7 +271,7 @@ ifactory_object_iface_init( NAIFactoryObjectInterface *iface )
iface->is_valid = ifactory_object_is_valid;
iface->read_start = NULL;
iface->read_done = ifactory_object_read_done;
- iface->write_start = NULL;
+ iface->write_start = ifactory_object_write_start;
iface->write_done = ifactory_object_write_done;
}
@@ -326,10 +328,18 @@ ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider
}
-static void
-ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
+static guint
+ifactory_object_write_start( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
{
+ na_object_item_factory_write_start( NA_OBJECT_ITEM( instance ));
+
+ return( NA_IIO_PROVIDER_CODE_OK );
+}
+static guint
+ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
+{
+ return( NA_IIO_PROVIDER_CODE_OK );
}
static gboolean
diff --git a/src/core/na-object-profile.c b/src/core/na-object-profile.c
index e5f947a..6c203b2 100644
--- a/src/core/na-object-profile.c
+++ b/src/core/na-object-profile.c
@@ -38,6 +38,7 @@
#include <libnautilus-extension/nautilus-file-info.h>
#include <api/na-core-utils.h>
+#include <api/na-iio-provider.h>
#include <api/na-ifactory-object.h>
#include <api/na-object-api.h>
@@ -83,7 +84,7 @@ static NADataGroup *ifactory_object_get_groups( const NAIFactoryObject *instance
static gchar *ifactory_object_get_default( const NAIFactoryObject *instance, const NADataDef *iddef );
static gboolean ifactory_object_is_valid( const NAIFactoryObject *object );
static void ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider *reader, void *reader_data, GSList **messages );
-static void ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
+static guint ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages );
static gboolean profile_is_valid( const NAObjectProfile *profile );
static gboolean is_valid_path_parameters( const NAObjectProfile *profile );
@@ -352,10 +353,10 @@ ifactory_object_read_done( NAIFactoryObject *instance, const NAIFactoryProvider
}
-static void
+static guint
ifactory_object_write_done( NAIFactoryObject *instance, const NAIFactoryProvider *writer, void *writer_data, GSList **messages )
{
-
+ return( NA_IIO_PROVIDER_CODE_OK );
}
static gboolean
diff --git a/src/core/na-updater.c b/src/core/na-updater.c
index 17ee530..2663985 100644
--- a/src/core/na-updater.c
+++ b/src/core/na-updater.c
@@ -378,7 +378,6 @@ na_updater_write_item( const NAUpdater *updater, NAObjectItem *item, GSList **me
}
if( provider ){
-
if( !na_updater_is_item_writable( updater, item, &reason )){
ret = ( guint ) reason;
diff --git a/src/io-gconf/nagp-gconf-provider.c b/src/io-gconf/nagp-gconf-provider.c
index 253e0d5..2cf6832 100644
--- a/src/io-gconf/nagp-gconf-provider.c
+++ b/src/io-gconf/nagp-gconf-provider.c
@@ -246,8 +246,8 @@ ifactory_provider_iface_init( NAIFactoryProviderInterface *iface )
iface->read_data = nagp_reader_read_data;
iface->read_done = nagp_reader_read_done;
iface->write_start = NULL;
- iface->write_data = NULL;
- iface->write_done = NULL;
+ iface->write_data = nagp_writer_write_data;
+ iface->write_done = nagp_writer_write_done;
}
static guint
diff --git a/src/io-gconf/nagp-writer.c b/src/io-gconf/nagp-writer.c
index 1e448af..665af09 100644
--- a/src/io-gconf/nagp-writer.c
+++ b/src/io-gconf/nagp-writer.c
@@ -34,7 +34,10 @@
#include <string.h>
+#include <api/na-data-def.h>
+#include <api/na-data-types.h>
#include <api/na-iio-provider.h>
+#include <api/na-ifactory-provider.h>
#include <api/na-object-api.h>
#include <api/na-core-utils.h>
#include <api/na-gconf-utils.h>
@@ -43,15 +46,21 @@
#include "nagp-writer.h"
#include "nagp-keys.h"
+typedef struct {
+ gchar *parent_id;
+}
+ WriterData;
+
+#if 0
static gboolean write_item_action( NagpGConfProvider *gconf, const NAObjectAction *action, GSList **message );
static gboolean write_item_menu( NagpGConfProvider *gconf, const NAObjectMenu *menu, GSList **message );
static gboolean write_object_item( NagpGConfProvider *gconf, const NAObjectItem *item, GSList **message );
-
static gboolean write_str( NagpGConfProvider *gconf, const gchar *uuid, const gchar *name, const gchar *key, gchar *value, GSList **message );
static gboolean write_bool( NagpGConfProvider *gconf, const gchar *uuid, const gchar *name, const gchar *key, gboolean value, GSList **message );
static gboolean write_list( NagpGConfProvider *gconf, const gchar *uuid, const gchar *name, const gchar *key, GSList *value, GSList **message );
static gboolean remove_key( NagpGConfProvider *provider, const gchar *uuid, const gchar *key, GSList **messages );
+#endif
/*
* API function: should only be called through NAIIOProvider interface
@@ -105,7 +114,9 @@ nagp_iio_provider_is_able_to_write( const NAIIOProvider *provider )
}
/*
- *
+ * update an existing item or write a new one
+ * in all cases, it is much more easy to delete the existing entries
+ * before trying to write the new ones
*/
guint
nagp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages )
@@ -113,6 +124,7 @@ nagp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem
static const gchar *thisfn = "nagp_gconf_provider_iio_provider_write_item";
NagpGConfProvider *self;
guint ret;
+ WriterData *data;
g_debug( "%s: provider=%p (%s), item=%p (%s), messages=%p",
thisfn,
@@ -136,6 +148,12 @@ nagp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem
if( ret == NA_IIO_PROVIDER_CODE_OK ){
+ data = g_new0( WriterData, 1 );
+
+ na_ifactory_provider_write_item( NA_IFACTORY_PROVIDER( provider ), data, NA_IFACTORY_OBJECT( item ), messages );
+
+ g_free( data );
+#if 0
if( NA_IS_OBJECT_ACTION( item )){
if( !write_item_action( self, NA_OBJECT_ACTION( item ), messages )){
return( NA_IIO_PROVIDER_CODE_WRITE_ERROR );
@@ -147,6 +165,7 @@ nagp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem
return( NA_IIO_PROVIDER_CODE_WRITE_ERROR );
}
}
+#endif
}
gconf_client_suggest_sync( self->private->gconf, NULL );
@@ -154,6 +173,7 @@ nagp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem
return( ret );
}
+#if 0
static gboolean
write_item_action( NagpGConfProvider *provider, const NAObjectAction *action, GSList **messages )
{
@@ -239,6 +259,7 @@ write_object_item( NagpGConfProvider *provider, const NAObjectItem *item, GSList
g_free( uuid );
return( ret );
}
+#endif
/*
* also delete the schema which may be directly attached to this action
@@ -305,6 +326,124 @@ nagp_iio_provider_delete_item( const NAIIOProvider *provider, const NAObjectItem
return( ret );
}
+guint
+nagp_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
+ const NAIFactoryObject *object, const NADataBoxed *boxed,
+ GSList **messages )
+{
+ static const gchar *thisfn = "nagp_writer_write_data";
+ guint code;
+ NADataDef *def;
+ gchar *id;
+ gchar *parent_path, *path;
+ gchar *msg;
+ gchar *str_value;
+ gboolean bool_value;
+ GSList *slist_value;
+ guint uint_value;
+ GConfClient *gconf;
+
+ msg = NULL;
+ code = NA_IIO_PROVIDER_CODE_OK;
+ def = na_data_boxed_get_data_def( boxed );
+
+ id = na_object_get_id( object );
+
+ parent_path = gconf_concat_dir_and_key( NAGP_CONFIGURATIONS_PATH,
+ (( WriterData * ) writer_data )->parent_id ?
+ (( WriterData * ) writer_data )->parent_id : id );
+
+ path = (( WriterData * ) writer_data )->parent_id ?
+ gconf_concat_dir_and_key( parent_path, id ) : g_strdup( parent_path );
+
+ gconf = NAGP_GCONF_PROVIDER( provider )->private->gconf;
+
+ switch( def->type ){
+
+ case NAFD_TYPE_STRING:
+ case NAFD_TYPE_LOCALE_STRING:
+ str_value = na_data_boxed_get_as_string( boxed );
+ na_gconf_utils_write_string( gconf, path, str_value, &msg );
+ if( msg ){
+ *messages = g_slist_append( *messages, msg );
+ code = NA_IIO_PROVIDER_CODE_WRITE_ERROR;
+ }
+ g_free( str_value );
+ break;
+
+ case NAFD_TYPE_BOOLEAN:
+ bool_value = GPOINTER_TO_UINT( na_data_boxed_get_as_void( boxed ));
+ na_gconf_utils_write_bool( gconf, path, bool_value, &msg );
+ if( msg ){
+ *messages = g_slist_append( *messages, msg );
+ code = NA_IIO_PROVIDER_CODE_WRITE_ERROR;
+ }
+ break;
+
+ case NAFD_TYPE_STRING_LIST:
+ slist_value = ( GSList * ) na_data_boxed_get_as_void( boxed );
+ na_gconf_utils_write_string_list( gconf, path, slist_value, &msg );
+ if( msg ){
+ *messages = g_slist_append( *messages, msg );
+ code = NA_IIO_PROVIDER_CODE_WRITE_ERROR;
+ }
+ na_core_utils_slist_free( slist_value );
+ break;
+
+ case NAFD_TYPE_UINT:
+ uint_value = GPOINTER_TO_UINT( na_data_boxed_get_as_void( boxed ));
+ na_gconf_utils_write_int( gconf, path, uint_value, &msg );
+ if( msg ){
+ *messages = g_slist_append( *messages, msg );
+ code = NA_IIO_PROVIDER_CODE_WRITE_ERROR;
+ }
+ break;
+
+ default:
+ g_warning( "%s: unknown type=%u for %s", thisfn, def->type, def->name );
+ code = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR;
+ }
+
+ g_free( msg );
+ g_free( path );
+ g_free( parent_path );
+ g_free( id );
+
+ return( code );
+}
+
+guint
+nagp_writer_write_done( const NAIFactoryProvider *writer, void *writer_data,
+ const NAIFactoryObject *object,
+ GSList **messages )
+{
+ guint code;
+ GSList *children_slist, *ic;
+ WriterData *data;
+ NAObjectProfile *profile;
+
+ code = NA_IIO_PROVIDER_CODE_OK;
+
+ if( NA_IS_OBJECT_ACTION( object )){
+ children_slist = na_object_get_items_slist( object );
+
+ for( ic = children_slist ; ic && code == NA_IIO_PROVIDER_CODE_OK ; ic = ic->next ){
+ data = g_new0( WriterData, 1 );
+ data->parent_id = na_object_get_id( object );
+
+ profile = NA_OBJECT_PROFILE( na_object_get_item( object, ic->data ));
+
+ code = na_ifactory_provider_write_item( writer, data, NA_IFACTORY_OBJECT( profile ), messages );
+
+ g_free( data->parent_id );
+ g_free( data );
+ }
+ }
+
+ return( code );
+}
+
+#if 0
static gboolean
write_str( NagpGConfProvider *provider, const gchar *uuid, const gchar *name, const gchar *key, gchar *value, GSList **messages )
{
@@ -403,3 +542,4 @@ remove_key( NagpGConfProvider *provider, const gchar *uuid, const gchar *key, GS
return( ret );
}
+#endif
diff --git a/src/io-gconf/nagp-writer.h b/src/io-gconf/nagp-writer.h
index 0690296..b62030d 100644
--- a/src/io-gconf/nagp-writer.h
+++ b/src/io-gconf/nagp-writer.h
@@ -31,10 +31,13 @@
#ifndef __NAGP_WRITE_H__
#define __NAGP_WRITE_H__
+#include <api/na-data-boxed.h>
#include <api/na-iio-provider.h>
G_BEGIN_DECLS
+/* NAIIOProvider interface
+ */
gboolean nagp_iio_provider_is_willing_to_write( const NAIIOProvider *provider );
gboolean nagp_iio_provider_is_able_to_write( const NAIIOProvider *provider );
@@ -43,6 +46,16 @@ guint nagp_iio_provider_write_item( const NAIIOProvider *provider, const NAOb
guint nagp_iio_provider_delete_item( const NAIIOProvider *provider, const NAObjectItem *item, GSList **message );
+/* NAIFactoryProvider interface
+ */
+guint nagp_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
+ const NAIFactoryObject *object, const NADataBoxed *boxed,
+ GSList **messages );
+
+guint nagp_writer_write_done( const NAIFactoryProvider *writer, void *writer_data,
+ const NAIFactoryObject *object,
+ GSList **messages );
+
G_END_DECLS
#endif /* __NAGP_WRITE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]