[nautilus-actions] Allow writing empty data



commit 08b1e242a9a4bc571f83e89b23522f71ecfed97c
Author: pierre <pierre vfedora10 virtuals pwi>
Date:   Tue Aug 10 18:56:43 2010 +0200

    Allow writing empty data

 ChangeLog                            |   21 +++
 TODO                                 |    5 -
 src/api/na-data-boxed.h              |    2 +-
 src/core/na-data-boxed.c             |  266 ++++++++++++++++++----------------
 src/core/na-object-action.c          |   72 ++++++----
 src/core/na-object-item-factory.c    |    2 +-
 src/core/na-object-profile-factory.c |    2 +-
 src/io-desktop/nadp-reader.c         |    6 +-
 src/io-desktop/nadp-writer.c         |    2 +-
 src/io-gconf/nagp-writer.c           |    2 +-
 src/io-xml/naxml-reader.c            |    9 +-
 src/io-xml/naxml-writer.c            |    2 +-
 12 files changed, 222 insertions(+), 169 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7b13ad7..47b2fb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2010-08-09 Pierre Wieser <pwieser trychlos org>
 
+	Allow writing of empty data.
+
+	* src/api/na-data-boxed.h:
+	* src/core/na-data-boxed.c
+	(na_data_boxed_is_set): Removed function.
+	(na_data_boxed_is_default): New function.
+
+	* src/io-desktop/nadp-writer.c (nadp_writer_ifactory_provider_write_data):
+	* src/io-gconf/nagp-writer.c (nagp_writer_write_data):
+	* src/io-xml/naxml-writer.c (naxml_writer_write_data):
+	Updated accordingly.
+
+	* src/core/na-object-item-factory.c:
+	* src/core/na-object-profile-factory.c:
+	Remove useless log description for a fake data.
+
+	* src/io-desktop/nadp-reader.c
+	(nadp_reader_ifactory_provider_read_data):
+	* src/io-xml/naxml-reader.c (read_data_boxed_from_node):
+	Set NADataBoxed as soon as a value is found.
+
 	Review pre- and post- write operations in I/O providers.
 
 	* src/core/na-object-action.c: Cleanup the code.
diff --git a/TODO b/TODO
index adfa6a5..32668c9 100644
--- a/TODO
+++ b/TODO
@@ -16,11 +16,6 @@ TODO
 
 - 2010-08-09: in v1.x until ??, %f used to be the basename!!
 
-- an empty list is not a default value
-  e.g. basenames default value = [*]
-  after deleting this default value in the UI, we should write basenames=[] in the I/O provider
-  so that we really have an empty list
-
 N-A ENHANCEMENTS
 ================
 - allow users to upload/download actions directly from a web repository
diff --git a/src/api/na-data-boxed.h b/src/api/na-data-boxed.h
index 2400772..b7bad89 100644
--- a/src/api/na-data-boxed.h
+++ b/src/api/na-data-boxed.h
@@ -77,8 +77,8 @@ NADataBoxed *na_data_boxed_new            ( const NADataDef *def );
 
 NADataDef   *na_data_boxed_get_data_def   ( const NADataBoxed *boxed );
 gboolean     na_data_boxed_are_equal      ( const NADataBoxed *a, const NADataBoxed *b );
+gboolean     na_data_boxed_is_default     ( const NADataBoxed *boxed );
 gboolean     na_data_boxed_is_valid       ( const NADataBoxed *boxed );
-gboolean     na_data_boxed_is_set         ( const NADataBoxed *boxed );
 void         na_data_boxed_dump           ( const NADataBoxed *boxed );
 
 void         na_data_boxed_set_data_def   ( NADataBoxed *boxed, const NADataDef *def );
diff --git a/src/core/na-data-boxed.c b/src/core/na-data-boxed.c
index be5eb73..4d273e5 100644
--- a/src/core/na-data-boxed.c
+++ b/src/core/na-data-boxed.c
@@ -67,8 +67,8 @@ typedef struct {
 	void         ( *free )           ( const NADataBoxed * );
 	void         ( *dump )           ( const NADataBoxed * );
 	gboolean     ( *are_equal )      ( const NADataBoxed *, const NADataBoxed * );
+	gboolean     ( *is_default )     ( const NADataBoxed * );
 	gboolean     ( *is_valid )       ( const NADataBoxed * );
-	gboolean     ( *is_set )         ( const NADataBoxed * );
 	gchar *      ( *get_as_string )  ( const NADataBoxed * );
 	void *       ( *get_as_void )    ( const NADataBoxed * );
 	void         ( *get_as_value )   ( const NADataBoxed *, GValue *value );
@@ -93,8 +93,8 @@ static GParamSpec *string_spec( const NADataDef *idtype );
 static void        string_free( const NADataBoxed *boxed );
 static void        string_dump( const NADataBoxed *boxed );
 static gboolean    string_are_equal( const NADataBoxed *a, const NADataBoxed *b );
+static gboolean    string_is_default( const NADataBoxed *boxed );
 static gboolean    string_is_valid( const NADataBoxed *boxed );
-static gboolean    string_is_set( const NADataBoxed *boxed );
 static gchar      *string_get_as_string( const NADataBoxed *boxed );
 static void       *string_get_as_void( const NADataBoxed *boxed );
 static void        string_get_as_value( const NADataBoxed *boxed, GValue *value );
@@ -104,15 +104,15 @@ static void        string_set_from_value( NADataBoxed *boxed, const GValue *valu
 static void        string_set_from_void( NADataBoxed *boxed, const void *value );
 
 static gboolean    locale_are_equal( const NADataBoxed *a, const NADataBoxed *b );
+static gboolean    locale_is_default( const NADataBoxed *boxed );
 static gboolean    locale_is_valid( const NADataBoxed *boxed );
-static gboolean    locale_is_set( const NADataBoxed *boxed );
 
 static GParamSpec *slist_spec( const NADataDef *idtype );
 static void        slist_free( const NADataBoxed *boxed );
 static void        slist_dump( const NADataBoxed *boxed );
 static gboolean    slist_are_equal( const NADataBoxed *a, const NADataBoxed *b );
+static gboolean    slist_is_default( const NADataBoxed *boxed );
 static gboolean    slist_is_valid( const NADataBoxed *boxed );
-static gboolean    slist_is_set( const NADataBoxed *boxed );
 static gchar      *slist_get_as_string( const NADataBoxed *boxed );
 static void       *slist_get_as_void( const NADataBoxed *boxed );
 static void        slist_get_as_value( const NADataBoxed *boxed, GValue *value );
@@ -125,8 +125,8 @@ static GParamSpec *bool_spec( const NADataDef *idtype );
 static void        bool_free( const NADataBoxed *boxed );
 static void        bool_dump( const NADataBoxed *boxed );
 static gboolean    bool_are_equal( const NADataBoxed *a, const NADataBoxed *b );
+static gboolean    bool_is_default( const NADataBoxed *boxed );
 static gboolean    bool_is_valid( const NADataBoxed *boxed );
-static gboolean    bool_is_set( const NADataBoxed *boxed );
 static gchar      *bool_get_as_string( const NADataBoxed *boxed );
 static void       *bool_get_as_void( const NADataBoxed *boxed );
 static void        bool_get_as_value( const NADataBoxed *boxed, GValue *value );
@@ -139,8 +139,8 @@ static GParamSpec *pointer_spec( const NADataDef *idtype );
 static void        pointer_free( const NADataBoxed *boxed );
 static void        pointer_dump( const NADataBoxed *boxed );
 static gboolean    pointer_are_equal( const NADataBoxed *a, const NADataBoxed *b );
+static gboolean    pointer_is_default( const NADataBoxed *boxed );
 static gboolean    pointer_is_valid( const NADataBoxed *boxed );
-static gboolean    pointer_is_set( const NADataBoxed *boxed );
 static gchar      *pointer_get_as_string( const NADataBoxed *boxed );
 static void       *pointer_get_as_void( const NADataBoxed *boxed );
 static void        pointer_get_as_value( const NADataBoxed *boxed, GValue *value );
@@ -153,8 +153,8 @@ static GParamSpec *uint_spec( const NADataDef *idtype );
 static void        uint_free( const NADataBoxed *boxed );
 static void        uint_dump( const NADataBoxed *boxed );
 static gboolean    uint_are_equal( const NADataBoxed *a, const NADataBoxed *b );
+static gboolean    uint_is_default( const NADataBoxed *boxed );
 static gboolean    uint_is_valid( const NADataBoxed *boxed );
-static gboolean    uint_is_set( const NADataBoxed *boxed );
 static gchar      *uint_get_as_string( const NADataBoxed *boxed );
 static void       *uint_get_as_void( const NADataBoxed *boxed );
 static void        uint_get_as_value( const NADataBoxed *boxed, GValue *value );
@@ -169,8 +169,8 @@ static DataBoxedFn st_data_boxed_fn[] = {
 				string_free,
 				string_dump,
 				string_are_equal,
+				string_is_default,
 				string_is_valid,
-				string_is_set,
 				string_get_as_string,
 				string_get_as_void,
 				string_get_as_value,
@@ -184,8 +184,8 @@ static DataBoxedFn st_data_boxed_fn[] = {
 				string_free,
 				string_dump,
 				locale_are_equal,
+				locale_is_default,
 				locale_is_valid,
-				locale_is_set,
 				string_get_as_string,
 				string_get_as_void,
 				string_get_as_value,
@@ -199,8 +199,8 @@ static DataBoxedFn st_data_boxed_fn[] = {
 				slist_free,
 				slist_dump,
 				slist_are_equal,
+				slist_is_default,
 				slist_is_valid,
-				slist_is_set,
 				slist_get_as_string,
 				slist_get_as_void,
 				slist_get_as_value,
@@ -214,8 +214,8 @@ static DataBoxedFn st_data_boxed_fn[] = {
 				bool_free,
 				bool_dump,
 				bool_are_equal,
+				bool_is_default,
 				bool_is_valid,
-				bool_is_set,
 				bool_get_as_string,
 				bool_get_as_void,
 				bool_get_as_value,
@@ -229,8 +229,8 @@ static DataBoxedFn st_data_boxed_fn[] = {
 				pointer_free,
 				pointer_dump,
 				pointer_are_equal,
+				pointer_is_default,
 				pointer_is_valid,
-				pointer_is_set,
 				pointer_get_as_string,
 				pointer_get_as_void,
 				pointer_get_as_value,
@@ -244,8 +244,8 @@ static DataBoxedFn st_data_boxed_fn[] = {
 				uint_free,
 				uint_dump,
 				uint_are_equal,
+				uint_is_default,
 				uint_is_valid,
-				uint_is_set,
 				uint_get_as_string,
 				uint_get_as_void,
 				uint_get_as_value,
@@ -506,64 +506,64 @@ na_data_boxed_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 }
 
 /**
- * na_data_boxed_is_valid:
- * @object: the #NADataBoxed object whose validity is to be checked.
+ * na_data_boxed_is_default:
+ * @boxed: this #NADataBoxed object.
  *
- * Returns: %TRUE if the boxed is valid, %FALSE else.
+ * Returns: %TRUE if the #NADataBoxed holds its default value,
+ * %FALSE else.
  */
 gboolean
-na_data_boxed_is_valid( const NADataBoxed *boxed )
+na_data_boxed_is_default( const NADataBoxed *boxed )
 {
+	gboolean is_default;
 	DataBoxedFn *fn;
-	gboolean is_valid;
 
 	g_return_val_if_fail( NA_IS_DATA_BOXED( boxed ), FALSE );
 
-	is_valid = FALSE;
+	is_default = FALSE;
 
 	if( !boxed->private->dispose_has_run ){
 
 		fn = get_data_boxed_fn( boxed->private->def->type );
 
 		if( fn ){
-			if( fn->is_valid ){
-				is_valid = ( *fn->is_valid )( boxed );
+			if( fn->is_default ){
+				is_default = ( *fn->is_default )( boxed );
 			}
 		}
 	}
 
-	return( is_valid );
+	return( is_default );
 }
 
 /**
- * na_data_boxed_is_set:
- * @boxed: this #NADataBoxed object.
+ * na_data_boxed_is_valid:
+ * @object: the #NADataBoxed object whose validity is to be checked.
  *
- * Returns: %TRUE if the #NADataBoxed is set,
- * %FALSE else, e.g. empty or equal to the default value.
+ * Returns: %TRUE if the boxed is valid, %FALSE else.
  */
 gboolean
-na_data_boxed_is_set( const NADataBoxed *boxed )
+na_data_boxed_is_valid( const NADataBoxed *boxed )
 {
-	gboolean is_set;
 	DataBoxedFn *fn;
+	gboolean is_valid;
 
 	g_return_val_if_fail( NA_IS_DATA_BOXED( boxed ), FALSE );
 
-	is_set = FALSE;
+	is_valid = FALSE;
 
 	if( !boxed->private->dispose_has_run ){
 
 		fn = get_data_boxed_fn( boxed->private->def->type );
 
 		if( fn ){
-			if( fn->is_set ){
-				is_set = ( *fn->is_set )( boxed );
+			if( fn->is_valid ){
+				is_valid = ( *fn->is_valid )( boxed );
 			}
 		}
 	}
 
-	return( is_set );
+	return( is_valid );
 }
 
 /**
@@ -857,50 +857,58 @@ string_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 }
 
 static gboolean
-string_is_valid( const NADataBoxed *boxed )
+string_is_default( const NADataBoxed *boxed )
 {
-	gboolean is_valid = TRUE;
+	gboolean is_default = FALSE;
 
-	if( boxed->private->def->mandatory ){
-		if( !boxed->private->u.string || !strlen( boxed->private->u.string )){
-			g_debug( "na_data_boxed_string_is_valid: invalid %s: mandatory but empty or null", boxed->private->def->name );
-			is_valid = FALSE;
+	if( boxed->private->def->default_value ){
+		if( boxed->private->u.string ){
+			/* default value is not null and string has something */
+			is_default = ( strcmp( boxed->private->u.string, boxed->private->def->default_value ) == 0 );
+
+		} else {
+			/* default value is not null, but string is null */
+			is_default = FALSE;
 		}
+	} else if( boxed->private->u.string ){
+		/* default value is null, but string has something */
+		is_default = FALSE;
+
+	} else {
+		/* default value and string are both null */
+		is_default = TRUE;
 	}
 
-	return( is_valid );
+	return( is_default );
 }
 
 static gboolean
-string_is_set( const NADataBoxed *boxed )
+string_is_valid( const NADataBoxed *boxed )
 {
-	gboolean is_set = FALSE;
+	gboolean is_valid = TRUE;
 
-	if( boxed->private->u.string && strlen( boxed->private->u.string )){
-		if( boxed->private->def->default_value && strlen( boxed->private->def->default_value )){
-			is_set = ( strcmp( boxed->private->u.string, boxed->private->def->default_value ) != 0 );
-		} else {
-			is_set = TRUE;
+	if( boxed->private->def->mandatory ){
+		if( !boxed->private->u.string || !strlen( boxed->private->u.string )){
+			g_debug( "na_data_boxed_string_is_valid: invalid %s: mandatory but empty or null", boxed->private->def->name );
+			is_valid = FALSE;
 		}
 	}
 
-	return( is_set );
+	return( is_valid );
 }
 
 static gchar *
 string_get_as_string( const NADataBoxed *boxed )
 {
-	return( g_strdup( boxed->private->u.string ));
+	return( boxed->private->u.string ? g_strdup( boxed->private->u.string ) : g_strdup( "" ));
 }
 
 static void *
 string_get_as_void( const NADataBoxed *boxed )
 {
-	void *value = NULL;
+	void *value;
 
-	if( boxed->private->u.string ){
-		value = g_strdup( boxed->private->u.string );
-	}
+	value = ( void * ) string_get_as_string( boxed );
 
 	return( value );
 }
@@ -908,7 +916,11 @@ string_get_as_void( const NADataBoxed *boxed )
 static void
 string_get_as_value( const NADataBoxed *boxed, GValue *value )
 {
-	g_value_set_string( value, boxed->private->u.string );
+	gchar *str;
+
+	str = string_get_as_string( boxed );
+	g_value_set_string( value, str );
+	g_free( str );
 }
 
 static void
@@ -954,34 +966,44 @@ locale_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 }
 
 static gboolean
-locale_is_valid( const NADataBoxed *boxed )
+locale_is_default( const NADataBoxed *boxed )
 {
-	gboolean is_valid = TRUE;
+	gboolean is_default = FALSE;
 
-	if( boxed->private->def->mandatory ){
-		if( !boxed->private->u.string || !g_utf8_strlen( boxed->private->u.string, -1 )){
-			g_debug( "na_data_boxed_string_is_valid: invalid %s: mandatory but empty or null", boxed->private->def->name );
-			is_valid = FALSE;
+	if( boxed->private->def->default_value ){
+		if( boxed->private->u.string ){
+			/* default value is not null and string has something */
+			is_default = ( na_core_utils_str_collate( boxed->private->u.string, boxed->private->def->default_value ) == 0 );
+
+		} else {
+			/* default value is not null, but string is null */
+			is_default = FALSE;
 		}
+	} else if( boxed->private->u.string ){
+		/* default value is null, but string has something */
+		is_default = FALSE;
+
+	} else {
+		/* default value and string are both null */
+		is_default = TRUE;
 	}
 
-	return( is_valid );
+	return( is_default );
 }
 
 static gboolean
-locale_is_set( const NADataBoxed *boxed )
+locale_is_valid( const NADataBoxed *boxed )
 {
-	gboolean is_set = FALSE;
+	gboolean is_valid = TRUE;
 
-	if( boxed->private->u.string && g_utf8_strlen( boxed->private->u.string, -1 )){
-		if( boxed->private->def->default_value && g_utf8_strlen( boxed->private->def->default_value, -1 )){
-			is_set = ( na_core_utils_str_collate( boxed->private->u.string, boxed->private->def->default_value ) != 0 );
-		} else {
-			is_set = TRUE;
+	if( boxed->private->def->mandatory ){
+		if( !boxed->private->u.string || !g_utf8_strlen( boxed->private->u.string, -1 )){
+			g_debug( "na_data_boxed_string_is_valid: invalid %s: mandatory but empty or null", boxed->private->def->name );
+			is_valid = FALSE;
 		}
 	}
 
-	return( is_set );
+	return( is_valid );
 }
 
 static GParamSpec *
@@ -1023,38 +1045,43 @@ slist_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 }
 
 static gboolean
-slist_is_valid( const NADataBoxed *boxed )
+slist_is_default( const NADataBoxed *boxed )
 {
-	gboolean is_valid = TRUE;
+	gboolean is_default = FALSE;
+	GSList *default_value;
 
-	if( boxed->private->def->mandatory ){
-		if( !boxed->private->u.slist || !g_slist_length( boxed->private->u.slist )){
-			g_debug( "na_data_boxed_string_is_valid: invalid %s: mandatory but empty or null", boxed->private->def->name );
-			is_valid = FALSE;
+	if( boxed->private->def->default_value ){
+		if( boxed->private->u.slist ){
+			default_value = na_gconf_utils_slist_from_string( boxed->private->def->default_value );
+			is_default = na_core_utils_slist_are_equal( default_value, boxed->private->u.slist );
+			na_core_utils_slist_free( default_value );
+
+		} else {
+			is_default = FALSE;
 		}
+	} else if( boxed->private->u.slist ){
+		is_default = FALSE;
+
+	} else {
+		is_default = TRUE;
 	}
 
-	return( is_valid );
+	return( is_default );
 }
 
 static gboolean
-slist_is_set( const NADataBoxed *boxed )
+slist_is_valid( const NADataBoxed *boxed )
 {
-	gboolean is_set = FALSE;
-	GSList *default_value;
-
-	if( boxed->private->u.slist && g_slist_length( boxed->private->u.slist )){
-		if( boxed->private->def->default_value ){
-			default_value = na_gconf_utils_slist_from_string( boxed->private->def->default_value );
-			is_set = !na_core_utils_slist_are_equal( default_value, boxed->private->u.slist );
-			na_core_utils_slist_free( default_value );
+	gboolean is_valid = TRUE;
 
-		} else {
-			is_set = TRUE;
+	if( boxed->private->def->mandatory ){
+		if( !boxed->private->u.slist || !g_slist_length( boxed->private->u.slist )){
+			g_debug( "na_data_boxed_string_is_valid: invalid %s: mandatory but empty or null", boxed->private->def->name );
+			is_valid = FALSE;
 		}
 	}
 
-	return( is_set );
+	return( is_valid );
 }
 
 static gchar *
@@ -1154,23 +1181,23 @@ bool_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 }
 
 static gboolean
-bool_is_valid( const NADataBoxed *boxed )
-{
-	return( TRUE );
-}
-
-static gboolean
-bool_is_set( const NADataBoxed *boxed )
+bool_is_default( const NADataBoxed *boxed )
 {
-	gboolean is_set = TRUE;
+	gboolean is_default = FALSE;
 	gboolean default_value;
 
 	if( boxed->private->def->default_value && strlen( boxed->private->def->default_value )){
 		default_value = na_core_utils_boolean_from_string( boxed->private->def->default_value );
-		is_set = ( default_value != boxed->private->u.boolean );
+		is_default = ( default_value == boxed->private->u.boolean );
 	}
 
-	return( is_set );
+	return( is_default );
+}
+
+static gboolean
+bool_is_valid( const NADataBoxed *boxed )
+{
+	return( TRUE );
 }
 
 static gchar *
@@ -1244,6 +1271,16 @@ pointer_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 	return( a->private->u.pointer == b->private->u.pointer );
 }
 
+/*
+ * say that a pointer never has its default value
+ * (essentially because there cannot be any relevant default value for a pointer)
+ */
+static gboolean
+pointer_is_default( const NADataBoxed *boxed )
+{
+	return( FALSE );
+}
+
 static gboolean
 pointer_is_valid( const NADataBoxed *boxed )
 {
@@ -1259,18 +1296,6 @@ pointer_is_valid( const NADataBoxed *boxed )
 	return( is_valid );
 }
 
-static gboolean
-pointer_is_set( const NADataBoxed *boxed )
-{
-	gboolean is_set = FALSE;
-
-	if( boxed->private->u.pointer ){
-		is_set = TRUE;
-	}
-
-	return( is_set );
-}
-
 static gchar *
 pointer_get_as_string( const NADataBoxed *boxed )
 {
@@ -1346,26 +1371,23 @@ uint_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 }
 
 static gboolean
-uint_is_valid( const NADataBoxed *boxed )
-{
-	return( TRUE );
-}
-
-static gboolean
-uint_is_set( const NADataBoxed *boxed )
+uint_is_default( const NADataBoxed *boxed )
 {
-	gboolean is_set = FALSE;
+	gboolean is_default = FALSE;
 	guint default_value;
 
 	if( boxed->private->def->default_value ){
 		default_value = atoi( boxed->private->def->default_value );
-		is_set = ( boxed->private->u.uint != default_value );
-
-	} else {
-		is_set = TRUE;
+		is_default = ( boxed->private->u.uint == default_value );
 	}
 
-	return( is_set );
+	return( is_default );
+}
+
+static gboolean
+uint_is_valid( const NADataBoxed *boxed )
+{
+	return( TRUE );
 }
 
 static gchar *
diff --git a/src/core/na-object-action.c b/src/core/na-object-action.c
index fda2eb9..2cb6ba6 100644
--- a/src/core/na-object-action.c
+++ b/src/core/na-object-action.c
@@ -404,23 +404,48 @@ icontext_is_candidate( NAIContext *object, guint target, GList *selection )
  *  it is be identified by an version = "1.x"
  *  or by any data found in data_def_action_v1 (defined in na-object-action-factory.c)
  *  -> move obsoleted data to a new profile, updating the version string
+ *
+ *  actions readen from .desktop already have iversion=3 (cf. desktop_read_start)
+ *  and v1 actions may only come from xml or gconf
  */
 static void
 read_done_convert_v1_to_v2( NAIFactoryObject *instance )
 {
 	static const gchar *thisfn = "na_object_action_read_done_convert_v1_to_v2";
-	gboolean is_pre_v2;
+	guint iversion;
+	gchar *version;
 	GList *to_move;
 	NADataDef *def;
 	NADataBoxed *boxed;
-	gchar *version;
 	GList *ibox;
 	NAObjectProfile *profile;
 
-	is_pre_v2 = FALSE;
-	to_move = NULL;
+	/* check for new numeric version
+	 */
+	iversion = na_object_get_iversion( instance );
+	if( iversion >= 2 ){
+		return;
+	}
 
+	/* check for older alpha version
+	 * was not set in 2.30 serie
+	 */
+	version = na_object_get_version( instance );
+	if( version ){
+		iversion = atoi( version );
+		g_free( version );
+	}
+	if( iversion >= 2 ){
+		return;
+	}
+
+	/* we so have here a not-versioned action, in very old 1.x or in 2.30
+	 * search for old data in the body: this is only possible before profiles
+	 * because starting with contexts, iversion was written
+	 */
+	to_move = NULL;
 	def = data_def_action_v1;
+
 	while( def->name ){
 		boxed = na_ifactory_object_get_data_boxed( instance , def->name );
 		if( boxed ){
@@ -431,33 +456,26 @@ read_done_convert_v1_to_v2( NAIFactoryObject *instance )
 		def++;
 	}
 
-	if( to_move ){
-		is_pre_v2 = TRUE;
-
-	} else {
-		version = na_object_get_version( instance );
-		if( version && strlen( version ) && atoi( version ) < 2 ){
-			is_pre_v2 = TRUE;
-		}
-		g_free( version );
+	if( !to_move ){
+		return;
 	}
 
-	if( is_pre_v2 ){
-		profile = na_object_profile_new();
-		na_object_set_id( profile, "profile-pre-v2" );
-		na_object_set_label( profile, _( "Profile automatically created from pre-v2 action" ));
-		na_object_attach_profile( instance, profile );
+	/* now create a new profile
+	 */
+	profile = na_object_profile_new();
+	na_object_set_id( profile, "profile-pre-v2" );
+	na_object_set_label( profile, _( "Profile automatically created from pre-v2 action" ));
+	na_object_attach_profile( instance, profile );
 
-		if( to_move ){
-			for( ibox = to_move ; ibox ; ibox = ibox->next ){
-				na_factory_object_move_boxed(
-						NA_IFACTORY_OBJECT( profile ), instance, NA_DATA_BOXED( ibox->data ));
-			}
+	if( to_move ){
+		for( ibox = to_move ; ibox ; ibox = ibox->next ){
+			na_factory_object_move_boxed(
+					NA_IFACTORY_OBJECT( profile ), instance, NA_DATA_BOXED( ibox->data ));
 		}
-
-		na_factory_object_set_defaults( NA_IFACTORY_OBJECT( profile ));
-		na_object_set_version( instance, "2.0" );
 	}
+
+	na_factory_object_set_defaults( NA_IFACTORY_OBJECT( profile ));
+	na_object_set_version( instance, "2.0" );
 }
 
 /*
diff --git a/src/core/na-object-item-factory.c b/src/core/na-object-item-factory.c
index 7062b1e..c152eaa 100644
--- a/src/core/na-object-item-factory.c
+++ b/src/core/na-object-item-factory.c
@@ -160,7 +160,7 @@ NADataDef data_def_item [] = {
 				FALSE,
 				FALSE,
 				"Unlocalized icon name or path",
-				"Unlocalized icon name or path",
+				NULL,
 				NAFD_TYPE_STRING,
 				"",
 				FALSE,
diff --git a/src/core/na-object-profile-factory.c b/src/core/na-object-profile-factory.c
index c228eb1..cc590df 100644
--- a/src/core/na-object-profile-factory.c
+++ b/src/core/na-object-profile-factory.c
@@ -73,7 +73,7 @@ static NADataDef data_def_profile [] = {
 				FALSE,
 				FALSE,
 				"Unlocalized name of the profile",
-				"Unlocalized name of the profile",
+				NULL,
 				NAFD_TYPE_STRING,
 				"",
 				FALSE,
diff --git a/src/io-desktop/nadp-reader.c b/src/io-desktop/nadp-reader.c
index d9ee5ca..ddfa075 100644
--- a/src/io-desktop/nadp-reader.c
+++ b/src/io-desktop/nadp-reader.c
@@ -522,7 +522,7 @@ nadp_reader_ifactory_provider_read_data( const NAIFactoryProvider *reader, void
 
 				case NAFD_TYPE_LOCALE_STRING:
 					str_value = nadp_desktop_file_get_locale_string( nrd->ndf, group, def->desktop_entry, &found, def->default_value );
-					if( str_value && found ){
+					if( found ){
 						boxed = na_data_boxed_new( def );
 						na_data_boxed_set_from_void( boxed, str_value );
 					}
@@ -531,7 +531,7 @@ nadp_reader_ifactory_provider_read_data( const NAIFactoryProvider *reader, void
 
 				case NAFD_TYPE_STRING:
 					str_value = nadp_desktop_file_get_string( nrd->ndf, group, def->desktop_entry, &found, def->default_value );
-					if( str_value && found ){
+					if( found ){
 						boxed = na_data_boxed_new( def );
 						na_data_boxed_set_from_void( boxed, str_value );
 					}
@@ -549,7 +549,7 @@ nadp_reader_ifactory_provider_read_data( const NAIFactoryProvider *reader, void
 
 				case NAFD_TYPE_STRING_LIST:
 					slist_value = nadp_desktop_file_get_string_list( nrd->ndf, group, def->desktop_entry, &found, def->default_value );
-					if( slist_value && found ){
+					if( found ){
 						boxed = na_data_boxed_new( def );
 						na_data_boxed_set_from_void( boxed, slist_value );
 					}
diff --git a/src/io-desktop/nadp-writer.c b/src/io-desktop/nadp-writer.c
index a432319..025642a 100644
--- a/src/io-desktop/nadp-writer.c
+++ b/src/io-desktop/nadp-writer.c
@@ -510,7 +510,7 @@ nadp_writer_ifactory_provider_write_data(
 			group_name = g_strdup( NADP_GROUP_DESKTOP );
 		}
 
-		if( na_data_boxed_is_set( boxed ) || def->write_if_default ){
+		if( !na_data_boxed_is_default( boxed ) || def->write_if_default ){
 
 			switch( def->type ){
 
diff --git a/src/io-gconf/nagp-writer.c b/src/io-gconf/nagp-writer.c
index eb1c61b..e662f55 100644
--- a/src/io-gconf/nagp-writer.c
+++ b/src/io-gconf/nagp-writer.c
@@ -291,7 +291,7 @@ nagp_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
 	code = NA_IIO_PROVIDER_CODE_OK;
 	def = na_data_boxed_get_data_def( boxed );
 
-	if( na_data_boxed_is_set( boxed ) || def->write_if_default ){
+	if( !na_data_boxed_is_default( boxed ) || def->write_if_default ){
 
 		if( NA_IS_OBJECT_PROFILE( object )){
 			NAObjectItem *parent = NA_OBJECT_ITEM( na_object_get_parent( object ));
diff --git a/src/io-xml/naxml-reader.c b/src/io-xml/naxml-reader.c
index de4dba0..23bdc36 100644
--- a/src/io-xml/naxml-reader.c
+++ b/src/io-xml/naxml-reader.c
@@ -720,12 +720,9 @@ read_data_boxed_from_node( NAXMLReader *reader, xmlChar *path, xmlNode *parent,
 
 		if( reader->private->root_node_str->fn_get_value ){
 			value = ( *reader->private->root_node_str->fn_get_value )( reader, parent, def );
-
-			if( value ){
-				boxed = na_data_boxed_new( def );
-				na_data_boxed_set_from_string( boxed, value );
-				g_free( value );
-			}
+			boxed = na_data_boxed_new( def );
+			na_data_boxed_set_from_string( boxed, value );
+			g_free( value );
 		}
 	}
 
diff --git a/src/io-xml/naxml-writer.c b/src/io-xml/naxml-writer.c
index 7b8469f..a6b99ab 100644
--- a/src/io-xml/naxml-writer.c
+++ b/src/io-xml/naxml-writer.c
@@ -457,7 +457,7 @@ naxml_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
 
 	/* do no export empty values
 	 */
-	if( na_data_boxed_is_set( boxed ) || def->write_if_default ){
+	if( !na_data_boxed_is_default( boxed ) || def->write_if_default ){
 
 		writer = NAXML_WRITER( writer_data );
 



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