[nautilus-actions] NAXMLWriter: output lists in GConf format



commit 7fb7dc32fa8defff1e153f4a27f38ab065ed4653
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Dec 9 13:06:05 2011 +0100

    NAXMLWriter: output lists in GConf format

 ChangeLog                 |    4 +++
 src/io-xml/naxml-writer.c |   53 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c71e201..1d3dfe2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-12-09 Pierre Wieser <pwieser trychlos org>
 
+	* src/io-xml/naxml-writer.c
+	(write_data_schema_v2, write_data_dump):
+	String and uint lists have the GConf format (between square brackets).
+
 	* src/io-xml/naxml-reader.c (read_done_action_read_profiles):
 	Make sure we have at least one profile attached to the action.
 
diff --git a/src/io-xml/naxml-writer.c b/src/io-xml/naxml-writer.c
index a23374c..44bde56 100644
--- a/src/io-xml/naxml-writer.c
+++ b/src/io-xml/naxml-writer.c
@@ -115,6 +115,7 @@ static void            write_data_dump_element( NAXMLWriter *writer, const NADat
 static void            write_type_dump( NAXMLWriter *writer, const NAObjectItem *object, const NADataDef *def, const gchar *value );
 
 static xmlDocPtr       build_xml_doc( NAXMLWriter *writer );
+static gchar          *convert_to_gconf_slist( const gchar *str );
 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 );
@@ -520,13 +521,23 @@ write_data_schema_v2( NAXMLWriter *writer, const NAObjectId *object, const NADat
 {
 	gchar *object_id;
 	gchar *value_str;
+	gchar *tmp;
 
 	value_str = na_boxed_get_string( NA_BOXED( boxed ));
 
 	/* boolean value must be lowercase
 	 */
 	if( def->type == NA_DATA_TYPE_BOOLEAN ){
-		gchar *tmp = g_ascii_strdown( value_str, -1 );
+		tmp = g_ascii_strdown( value_str, -1 );
+		g_free( value_str );
+		value_str = tmp;
+	}
+
+	/* string or uint list value must be converted to gconf format
+	 * comma-separated and enclosed within square brackets
+	 */
+	if( def->type == NA_DATA_TYPE_STRING_LIST || def->type == NA_DATA_TYPE_UINT_LIST ){
+		tmp = convert_to_gconf_slist( value_str );
 		g_free( value_str );
 		value_str = tmp;
 	}
@@ -622,13 +633,23 @@ write_data_dump( NAXMLWriter *writer, const NAObjectId *object, const NADataBoxe
 {
 	gchar *entry;
 	gchar *value_str;
+	gchar *tmp;
 
 	value_str = na_boxed_get_string( NA_BOXED( boxed ));
 
 	/* boolean value must be lowercase
 	 */
 	if( def->type == NA_DATA_TYPE_BOOLEAN ){
-		gchar *tmp = g_ascii_strdown( value_str, -1 );
+		tmp = g_ascii_strdown( value_str, -1 );
+		g_free( value_str );
+		value_str = tmp;
+	}
+
+	/* string or uint list value must be converted to gconf format
+	 * comma-separated and enclosed within square brackets
+	 */
+	if( def->type == NA_DATA_TYPE_STRING_LIST || def->type == NA_DATA_TYPE_UINT_LIST ){
+		tmp = convert_to_gconf_slist( value_str );
 		g_free( value_str );
 		value_str = tmp;
 	}
@@ -689,6 +710,34 @@ write_type_dump( NAXMLWriter *writer, const NAObjectItem *object, const NADataDe
 	write_data_dump_element( writer, def, NULL, def->gconf_entry, value );
 }
 
+/*
+ * we have here a string list as "value; value;"
+ * we want "[value, value]"
+ */
+static gchar *
+convert_to_gconf_slist( const gchar *slist_str )
+{
+	GSList *values;
+	GSList *is;
+	gboolean first;
+	GString *str = g_string_new( "[" );
+
+	values = na_core_utils_slist_from_split( slist_str, ";" );
+	first = TRUE;
+
+	for( is = values ; is ; is = is->next ){
+		if( !first ){
+			str = g_string_append( str, "," );
+		}
+		str = g_string_append( str, ( const gchar * ) is->data );
+		first = FALSE;
+	}
+
+	str = g_string_append( str, "]" );
+
+	return( g_string_free( str, FALSE ));
+}
+
 static ExportFormatFn *
 find_export_format_fn( GQuark format )
 {



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