[nautilus-actions] No more instantiate 'type' data box



commit 3575a5cc8264340e739c3e5ab506953b5eb2ef6a
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Mar 28 21:40:25 2010 +0200

    No more instantiate 'type' data box
    
    Rationale: this data cannot be automatically written as different I/O providers have
    different values. So the data is explicitly written both by I/O providers and by XML
    exporters. Default value is removed so that data is no more instantiated when setting
    default values.

 ChangeLog                         |    9 ++
 src/api/na-ifactory-object.h      |    8 +-
 src/core/na-ifactory-object.c     |   28 +++++++
 src/core/na-object-action.c       |    2 -
 src/core/na-object-item-factory.c |    2 +-
 src/core/na-object-menu.c         |    2 -
 src/io-xml/naxml-writer.c         |  157 ++++++++++++++++++++++++++++---------
 7 files changed, 162 insertions(+), 46 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 01f0395..d923541 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -131,6 +131,15 @@
 	* src/core/na-factory-object.c (set_defaults_iter):
 	Only set a default value when the box has not been yet allocated.
 
+	* src/api/na-ifactory-object.h:
+	* src/core/na-ifactory-object.c (na_ifactory_object_get_data_groups):
+	New function.
+
+	* src/core/na-object-item-factory.c:
+	* src/core/na-object-action.c (instance_init):
+	* src/core/na-object-menu.c (instance_init):
+	No more instantiate 'type' data box.
+
 	* src/core/na-object-item-factory.c:
 	NAFO_DATA_TYPE is no more automatically readen nor written.
 
diff --git a/src/api/na-ifactory-object.h b/src/api/na-ifactory-object.h
index 8afadbf..360fb9d 100644
--- a/src/api/na-ifactory-object.h
+++ b/src/api/na-ifactory-object.h
@@ -175,11 +175,13 @@ typedef struct {
 
 GType        na_ifactory_object_get_type( void );
 
-NADataBoxed *na_ifactory_object_get_data_boxed( const NAIFactoryObject *object, const gchar *name );
+NADataGroup *na_ifactory_object_get_data_groups( const NAIFactoryObject *object );
 
-void        *na_ifactory_object_get_as_void   ( const NAIFactoryObject *object, const gchar *name );
+NADataBoxed *na_ifactory_object_get_data_boxed ( const NAIFactoryObject *object, const gchar *name );
 
-void         na_ifactory_object_set_from_void ( NAIFactoryObject *object, const gchar *name, const void *data );
+void        *na_ifactory_object_get_as_void    ( const NAIFactoryObject *object, const gchar *name );
+
+void         na_ifactory_object_set_from_void  ( NAIFactoryObject *object, const gchar *name, const void *data );
 
 G_END_DECLS
 
diff --git a/src/core/na-ifactory-object.c b/src/core/na-ifactory-object.c
index 8cbf1b4..45104a6 100644
--- a/src/core/na-ifactory-object.c
+++ b/src/core/na-ifactory-object.c
@@ -142,6 +142,34 @@ ifactory_object_get_version( const NAIFactoryObject *instance )
 }
 
 /**
+ * na_ifactory_object_get_data_groups:
+ * @object: a #NAIFactoryObject object.
+ *
+ * Returns: The #NADataGroup groups definition, or %NULL.
+ *
+ * The returned #NADataGroup is owned by the #NAIFactoryObject @object,
+ * and should not be released by the caller.
+ */
+NADataGroup *
+na_ifactory_object_get_data_groups( const NAIFactoryObject *object )
+{
+	NADataGroup *groups;
+
+	g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
+
+	groups = NULL;
+
+	if( ifactory_object_initialized && !ifactory_object_finalized ){
+
+		if( NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_groups ){
+			groups = NA_IFACTORY_OBJECT_GET_INTERFACE( object )->get_groups( object );
+		}
+	}
+
+	return( groups );
+}
+
+/**
  * na_ifactory_object_get_data_boxed:
  * @object: a #NAIFactoryObject object.
  * @name: the name of the elementary data we are searching for.
diff --git a/src/core/na-object-action.c b/src/core/na-object-action.c
index 6edfe77..f30c946 100644
--- a/src/core/na-object-action.c
+++ b/src/core/na-object-action.c
@@ -179,8 +179,6 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self = NA_OBJECT_ACTION( instance );
 
 	self->private = g_new0( NAObjectActionPrivate, 1 );
-
-	na_ifactory_object_set_from_void( NA_IFACTORY_OBJECT( instance ), NAFO_DATA_TYPE, ( void * ) "Action" );
 }
 
 static void
diff --git a/src/core/na-object-item-factory.c b/src/core/na-object-item-factory.c
index 3f1581d..e569b3e 100644
--- a/src/core/na-object-item-factory.c
+++ b/src/core/na-object-item-factory.c
@@ -57,7 +57,7 @@ NADataDef data_def_item [] = {
 					"- 'Menu'.\n" \
 					"The value is case sensitive and must not be localized." ),
 				NAFD_TYPE_STRING,
-				"Action",
+				NULL,
 				FALSE,
 				FALSE,
 				FALSE,
diff --git a/src/core/na-object-menu.c b/src/core/na-object-menu.c
index 2416c44..047d339 100644
--- a/src/core/na-object-menu.c
+++ b/src/core/na-object-menu.c
@@ -173,8 +173,6 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self = NA_OBJECT_MENU( instance );
 
 	self->private = g_new0( NAObjectMenuPrivate, 1 );
-
-	na_ifactory_object_set_from_void( NA_IFACTORY_OBJECT( instance ), NAFO_DATA_TYPE, ( void * ) "Menu" );
 }
 
 static void
diff --git a/src/io-xml/naxml-writer.c b/src/io-xml/naxml-writer.c
index 0ae0b4c..db6f010 100644
--- a/src/io-xml/naxml-writer.c
+++ b/src/io-xml/naxml-writer.c
@@ -88,6 +88,7 @@ struct ExportFormatFn {
 	void ( *write_list_attribs_fn )( NAXMLWriter *, const NAObjectItem * );
 	gchar  *element_node;
 	void ( *write_data_fn )( NAXMLWriter *, const NAObjectId *, const NADataBoxed * );
+	void ( *write_type_fn )( NAXMLWriter *, const NAObjectItem *, const NADataDef *, const gchar * );
 };
 
 static GObjectClass *st_parent_class = NULL;
@@ -99,14 +100,21 @@ static void            instance_dispose( GObject *object );
 static void            instance_finalize( GObject *object );
 
 static void            write_data_schema_v1( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxed *boxed );
+static void            write_data_schema_v1_element( NAXMLWriter *writer, const NADataDef *def );
+static void            write_type_schema_v1( NAXMLWriter *writer, const NAObjectItem *object, const NADataDef *def, const gchar *value );
 static void            write_data_schema_v2( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxed *boxed );
+static void            write_data_schema_v2_element( NAXMLWriter *writer, const NADataDef *def, const gchar *object_id, const gchar *value_str );
+static void            write_type_schema_v2( NAXMLWriter *writer, const NAObjectItem *object, const NADataDef *def, const gchar *value );
 static void            write_list_attribs_dump( NAXMLWriter *writer, const NAObjectItem *object );
 static void            write_data_dump( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxed *boxed );
+static void            write_data_dump_element( NAXMLWriter *writer, const NADataDef *def, const NADataBoxed *boxed, const gchar *entry, const gchar *value_str );
+static void            write_type_dump( NAXMLWriter *writer, const NAObjectItem *object, const NADataDef *def, const gchar *value );
 
 static xmlDocPtr       build_xml_doc( NAXMLWriter *writer );
 static ExportFormatFn *find_export_format_fn( GQuark format );
 static gchar          *get_output_fname( const NAObjectItem *item, const gchar *folder, GQuark format );
 static void            output_xml_to_file( const gchar *xml, const gchar *filename, GSList **msg );
+static void            write_type( NAXMLWriter *writer, NAObjectItem *object, const NADataGroup *groups );
 static guint           writer_to_buffer( NAXMLWriter *writer );
 
 static ExportFormatFn st_export_format_fn[] = {
@@ -116,21 +124,24 @@ static ExportFormatFn st_export_format_fn[] = {
 					NAXML_KEY_SCHEMA_LIST,
 					NULL,
 					NAXML_KEY_SCHEMA_NODE,
-					write_data_schema_v1 },
+					write_data_schema_v1,
+					write_type_schema_v1 },
 
 	{ NAXML_FORMAT_GCONF_SCHEMA_V2,
 					NAXML_KEY_SCHEMA_ROOT,
 					NAXML_KEY_SCHEMA_LIST,
 					NULL,
 					NAXML_KEY_SCHEMA_NODE,
-					write_data_schema_v2 },
+					write_data_schema_v2,
+					write_type_schema_v2 },
 
 	{ NAXML_FORMAT_GCONF_ENTRY,
 					NAXML_KEY_DUMP_ROOT,
 					NAXML_KEY_DUMP_LIST,
 					write_list_attribs_dump,
 					NAXML_KEY_DUMP_NODE,
-					write_data_dump },
+					write_data_dump,
+					write_type_dump },
 
 	{ NULL }
 };
@@ -373,6 +384,7 @@ guint
 naxml_writer_write_start( const NAIFactoryProvider *provider, void *writer_data, const NAIFactoryObject *object, GSList **messages  )
 {
 	NAXMLWriter *writer;
+	NADataGroup *groups;
 
 	g_debug( "naxml_writer_write_start: object=%p (%s)", ( void * ) object, G_OBJECT_TYPE_NAME( object ));
 
@@ -386,6 +398,9 @@ naxml_writer_write_start( const NAIFactoryProvider *provider, void *writer_data,
 		if( writer->private->fn_str->write_list_attribs_fn ){
 			( *writer->private->fn_str->write_list_attribs_fn )( writer, NA_OBJECT_ITEM( object ));
 		}
+
+		groups = na_ifactory_object_get_data_groups( object );
+		write_type( writer, NA_OBJECT_ITEM( object ), groups );
 	}
 
 	return( NA_IIO_PROVIDER_CODE_OK );
@@ -399,12 +414,17 @@ naxml_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
 	/*NADataDef *def = na_data_boxed_get_data_def( boxed );
 	g_debug( "naxml_writer_write_data: def=%s", def->name );*/
 
-	writer = NAXML_WRITER( writer_data );
+	/* do no export empty values
+	 */
+	if( na_data_boxed_is_set( boxed )){
 
-	writer->private->schema_node = NULL;
-	writer->private->locale_node = NULL;
+		writer = NAXML_WRITER( writer_data );
+
+		writer->private->schema_node = NULL;
+		writer->private->locale_node = NULL;
 
-	( *writer->private->fn_str->write_data_fn )( writer, NA_OBJECT_ID( object ), boxed );
+		( *writer->private->fn_str->write_data_fn )( writer, NA_OBJECT_ID( object ), boxed );
+	}
 
 	return( NA_IIO_PROVIDER_CODE_OK );
 }
@@ -424,18 +444,34 @@ write_data_schema_v1( NAXMLWriter *writer, const NAObjectId *object, const NADat
 
 	def = na_data_boxed_get_data_def( boxed );
 
+	write_data_schema_v1_element( writer, def );
+}
+
+static void
+write_data_schema_v1_element( NAXMLWriter *writer, const NADataDef *def )
+{
 	if( !writer->private->locale_node ){
 		writer->private->locale_node = xmlNewChild( writer->private->schema_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE_LOCALE ), NULL );
 		xmlNewProp( writer->private->locale_node, BAD_CAST( "name" ), BAD_CAST( "C" ));
 	}
 
 	xmlNewChild( writer->private->schema_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE_OWNER ), BAD_CAST( PACKAGE_TARNAME ));
-
 	xmlNewChild( writer->private->locale_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE_LOCALE_SHORT ), BAD_CAST( def->short_label ));
-
 	xmlNewChild( writer->private->locale_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE_LOCALE_LONG ), BAD_CAST( def->long_label ));
 }
 
+static void
+write_type_schema_v1( NAXMLWriter *writer, const NAObjectItem *object, const NADataDef *def, const gchar *value )
+{
+	gchar *object_id;
+
+	object_id = na_object_get_id( object );
+	write_data_schema_v2_element( writer, def, object_id, value );
+	write_data_schema_v1_element( writer, def );
+
+	g_free( object_id );
+}
+
 /*
  * <schema>
  *  <key>/schemas/apps/nautilus-actions/configurations/entry</key>
@@ -446,19 +482,11 @@ write_data_schema_v2( NAXMLWriter *writer, const NAObjectId *object, const NADat
 {
 	gchar *object_id;
 	NADataDef *def;
-	xmlChar *content;
-	xmlNodePtr parent_value_node;
 	gchar *value_str;
 
 	def = na_data_boxed_get_data_def( boxed );
 	value_str = na_data_boxed_get_as_string( boxed );
 
-	/* do no export empty values
-	 */
-	if( !na_data_boxed_is_set( boxed )){
-		return;
-	}
-
 	/* boolean value must be lowercase
 	 */
 	if( def->type == NAFD_TYPE_BOOLEAN ){
@@ -467,8 +495,6 @@ write_data_schema_v2( NAXMLWriter *writer, const NAObjectId *object, const NADat
 		value_str = tmp;
 	}
 
-	writer->private->schema_node = xmlNewChild( writer->private->list_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE ), NULL );
-
 	object_id = na_object_get_id( object );
 
 	if( NA_IS_OBJECT_PROFILE( object )){
@@ -480,6 +506,25 @@ write_data_schema_v2( NAXMLWriter *writer, const NAObjectId *object, const NADat
 		object_id = tmp;
 	}
 
+	write_data_schema_v2_element( writer, def, object_id, value_str );
+
+	g_free( value_str );
+	g_free( object_id );
+}
+
+/*
+ * <schema>
+ *  <key>/schemas/apps/nautilus-actions/configurations/entry</key>
+ *  <applyto>/apps/nautilus-actions/configurations/item_id/profile_id/entry</applyto>
+ */
+static void
+write_data_schema_v2_element( NAXMLWriter *writer, const NADataDef *def, const gchar *object_id, const gchar *value_str )
+{
+	xmlChar *content;
+	xmlNodePtr parent_value_node;
+
+	writer->private->schema_node = xmlNewChild( writer->private->list_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE ), NULL );
+
 	content = BAD_CAST( g_build_path( "/", NAGP_SCHEMAS_PATH, def->gconf_entry, NULL ));
 	xmlNewChild( writer->private->schema_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE_KEY ), content );
 	xmlFree( content );
@@ -504,8 +549,21 @@ write_data_schema_v2( NAXMLWriter *writer, const NAObjectId *object, const NADat
 	content = xmlEncodeSpecialChars( writer->private->doc, BAD_CAST( value_str ));
 	xmlNewChild( parent_value_node, NULL, BAD_CAST( NAXML_KEY_SCHEMA_NODE_DEFAULT ), content );
 	xmlFree( content );
+}
+
+/*
+ * <schema>
+ *  <key>/schemas/apps/nautilus-actions/configurations/entry</key>
+ *  <applyto>/apps/nautilus-actions/configurations/item_id/profile_id/entry</applyto>
+ */
+static void
+write_type_schema_v2( NAXMLWriter *writer, const NAObjectItem *object, const NADataDef *def, const gchar *value )
+{
+	gchar *object_id;
+
+	object_id = na_object_get_id( object );
+	write_data_schema_v2_element( writer, def, object_id, value );
 
-	g_free( value_str );
 	g_free( object_id );
 }
 
@@ -526,24 +584,11 @@ write_list_attribs_dump( NAXMLWriter *writer, const NAObjectItem *object )
 static void
 write_data_dump( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxed *boxed )
 {
-	xmlNodePtr entry_node;
 	gchar *entry;
 	NADataDef *def;
-	xmlNodePtr value_node;
-	xmlNodePtr value_list_node, value_list_value_node;
-	GSList *list, *is;
-	xmlChar *encoded_content;
 	gchar *value_str;
 
-	value_str = NULL;
 	def = na_data_boxed_get_data_def( boxed );
-
-	/* do no export empty values
-	 */
-	if( !na_data_boxed_is_set( boxed )){
-		return;
-	}
-
 	value_str = na_data_boxed_get_as_string( boxed );
 
 	/* boolean value must be lowercase
@@ -554,8 +599,6 @@ write_data_dump( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxe
 		value_str = tmp;
 	}
 
-	entry_node = xmlNewChild( writer->private->list_node, NULL, BAD_CAST( writer->private->fn_str->element_node ), NULL );
-
 	if( NA_IS_OBJECT_PROFILE( object )){
 		gchar *id = na_object_get_id( object );
 		entry = g_strdup_printf( "%s/%s", id, def->gconf_entry );
@@ -563,6 +606,24 @@ write_data_dump( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxe
 	} else {
 		entry = g_strdup( def->gconf_entry );
 	}
+
+	write_data_dump_element( writer, def, boxed, entry, value_str );
+
+	g_free( entry );
+	g_free( value_str );
+}
+
+static void
+write_data_dump_element( NAXMLWriter *writer, const NADataDef *def, const NADataBoxed *boxed, const gchar *entry, const gchar *value_str )
+{
+	xmlNodePtr entry_node;
+	xmlNodePtr value_node;
+	xmlNodePtr value_list_node, value_list_value_node;
+	GSList *list, *is;
+	xmlChar *encoded_content;
+
+	entry_node = xmlNewChild( writer->private->list_node, NULL, BAD_CAST( writer->private->fn_str->element_node ), NULL );
+
 	xmlNewChild( entry_node, NULL, BAD_CAST( NAXML_KEY_DUMP_NODE_KEY ), BAD_CAST( entry ));
 
 	value_node = xmlNewChild( entry_node, NULL, BAD_CAST( NAXML_KEY_DUMP_NODE_VALUE ), NULL );
@@ -583,10 +644,13 @@ write_data_dump( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxe
 		encoded_content = xmlEncodeSpecialChars( writer->private->doc, BAD_CAST( value_str ));
 		xmlNewChild( value_node, NULL, BAD_CAST( na_data_types_get_gconf_dump_key( def->type )), encoded_content );
 		xmlFree( encoded_content );
-		g_free( value_str );
 	}
+}
 
-	g_free( entry );
+static void
+write_type_dump( NAXMLWriter *writer, const NAObjectItem *object, const NADataDef *def, const gchar *value )
+{
+	write_data_dump_element( writer, def, NULL, def->gconf_entry, value );
 }
 
 static ExportFormatFn *
@@ -682,7 +746,7 @@ get_output_fname( const NAObjectItem *item, const gchar *folder, GQuark format )
 	return( candidate_fname );
 }
 
-/**
+/*
  * output_xml_to_file:
  * @xml: the xml buffer.
  * @filename: the full path of the output filename as an URI.
@@ -749,6 +813,23 @@ output_xml_to_file( const gchar *xml, const gchar *filename, GSList **msg )
 	g_object_unref( file );
 }
 
+/* at end of write_start (list_node already created)
+ * explicitly write the 'Type' node
+ */
+static void
+write_type( NAXMLWriter *writer, NAObjectItem *object, const NADataGroup *groups )
+{
+	const NADataDef *def;
+	const gchar *svalue;
+
+	writer->private->schema_node = NULL;
+	writer->private->locale_node = NULL;
+	def = na_data_def_get_data_def( groups, NA_FACTORY_OBJECT_ITEM_GROUP, NAFO_DATA_TYPE );
+	svalue = NA_IS_OBJECT_ACTION( object ) ? NAGP_VALUE_TYPE_ACTION : NAGP_VALUE_TYPE_MENU;
+
+	( *writer->private->fn_str->write_type_fn )( writer, object, def, svalue );
+}
+
 static guint
 writer_to_buffer( NAXMLWriter *writer )
 {



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