[nautilus-actions] Fix validity checks



commit 3b46c74b9ff69259336d023ff778cbc426945877
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Feb 25 22:37:28 2010 +0100

    Fix validity checks

 ChangeLog                    |   22 ++++++++++++++++++
 src/core/na-data-boxed.c     |   46 +++++++++++++++++++++++++++++++++++----
 src/core/na-factory-object.c |   49 +++++++++++++++++++++++++++++++++--------
 src/core/na-iduplicable.c    |   11 ++++++---
 src/core/na-io-provider.c    |    2 +
 src/core/na-object-item.c    |   24 ++++++++++----------
 src/core/na-object.c         |   10 ++++----
 src/nact/nact-tree-model.c   |    3 --
 8 files changed, 128 insertions(+), 39 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dbe7871..6936431 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
 2009-02-25 Pierre Wieser <pwieser trychlos org>
 
+	Fix validity checks.
+
+	* src/core/na-data-boxed.c
+	(string_is_valid, locale_is_valid, slist_is_valid, pointer_is_valid,
+	uint_is_valid): Fix individual validity checks of elementary data.
+
+	* src/core/na-factory-object.c (na_factory_object_is_valid):
+	First check for presence of mandatory data, then check present data.
+
+	* src/core/na-iduplicable.c (na_iduplicable_duplicate):
+	Also duplicate the status of the source object.
+
+	* src/core/na-io-provider.c (na_io_provider_read_items):
+	Add a comment.
+
+	* src/core/na-object-item.c (na_object_item_copy):
+	* src/core/na-object.c (na_object_object_check_status):
+	Fix minor typo.
+
+	* src/nact/nact-tree-model.c (nact_tree_model_fill):
+	No more check status of newly duplicated objects.
+
 	* src/nact/base-window.c (instance_dispose):
 	Only set dispose after having tested for main window.
 
diff --git a/src/core/na-data-boxed.c b/src/core/na-data-boxed.c
index d7d7208..ccf60f5 100644
--- a/src/core/na-data-boxed.c
+++ b/src/core/na-data-boxed.c
@@ -837,7 +837,16 @@ string_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 static gboolean
 string_is_valid( const NADataBoxed *boxed )
 {
-	return( boxed->private->u.string && strlen( boxed->private->u.string ) > 0 );
+	gboolean is_valid = 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_valid );
 }
 
 static gchar *
@@ -909,7 +918,16 @@ locale_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 static gboolean
 locale_is_valid( const NADataBoxed *boxed )
 {
-	return( boxed->private->u.string && g_utf8_strlen( boxed->private->u.string, -1 ) > 0 );
+	gboolean is_valid = 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_valid );
 }
 
 static GParamSpec *
@@ -955,7 +973,16 @@ slist_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 static gboolean
 slist_is_valid( const NADataBoxed *boxed )
 {
-	return( boxed->private->u.slist && g_slist_length( boxed->private->u.slist ) > 0 );
+	gboolean is_valid = 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_valid );
 }
 
 static gchar *
@@ -1137,7 +1164,16 @@ pointer_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 static gboolean
 pointer_is_valid( const NADataBoxed *boxed )
 {
-	return( boxed->private->u.pointer != NULL );
+	gboolean is_valid = TRUE;
+
+	if( boxed->private->def->mandatory ){
+		if( !boxed->private->u.pointer ){
+			g_debug( "na_data_boxed_string_is_valid: invalid %s: mandatory but null", boxed->private->def->name );
+			is_valid = FALSE;
+		}
+	}
+
+	return( is_valid );
 }
 
 static gchar *
@@ -1216,7 +1252,7 @@ uint_are_equal( const NADataBoxed *a, const NADataBoxed *b )
 static gboolean
 uint_is_valid( const NADataBoxed *boxed )
 {
-	return( boxed->private->u.uint > 0 );
+	return( TRUE );
 }
 
 static gchar *
diff --git a/src/core/na-factory-object.c b/src/core/na-factory-object.c
index 614cdbc..46fa0c4 100644
--- a/src/core/na-factory-object.c
+++ b/src/core/na-factory-object.c
@@ -59,6 +59,14 @@ typedef struct {
 }
 	NafoRWIter;
 
+/* while iterating on is_valid
+ */
+typedef struct {
+	NAIFactoryObject  *object;
+	gboolean           is_valid;
+}
+	NafoValidIter;
+
 #if 0
 /* while iterating on set defaults
  */
@@ -78,6 +86,7 @@ extern NAIFactoryObjectInterface *ifactory_object_klass;
 #endif
 
 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 );
 
@@ -430,8 +439,8 @@ na_factory_object_are_equal( const NAIFactoryObject *a, const NAIFactoryObject *
 gboolean
 na_factory_object_is_valid( const NAIFactoryObject *object )
 {
-	static const gchar *thisfn = "na_factory_object_is_valid";
 	gboolean is_valid;
+	NADataGroup *groups;
 	GList *list, *iv;
 
 	g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), FALSE );
@@ -439,17 +448,20 @@ na_factory_object_is_valid( const NAIFactoryObject *object )
 	list = g_object_get_data( G_OBJECT( object ), NA_IFACTORY_OBJECT_PROP_DATA );
 	is_valid = TRUE;
 
-	for( iv = list ; iv && is_valid ; iv = iv->next ){
+	/* mndatory data must be set
+	 */
+	NafoValidIter iter_data;
+	iter_data.object = ( NAIFactoryObject * ) object;
+	iter_data.is_valid = TRUE;
 
-		NADataBoxed *boxed = NA_DATA_BOXED( iv->data );
-		NADataDef *def = na_data_boxed_get_data_def( boxed );
-		if( def->mandatory ){
+	groups = v_get_groups( object );
+	if( groups ){
+		iter_on_data_defs( groups, FALSE, ( NADataDefIterFunc ) factory_object_is_valid_mandatory_iter, &iter_data );
+	}
+	is_valid = iter_data.is_valid;
 
-			is_valid = na_data_boxed_is_valid( boxed );
-			if( !is_valid ){
-				g_debug( "%s: %s: invalid", thisfn, def->name );
-			}
-		}
+	for( iv = list ; iv && is_valid ; iv = iv->next ){
+		is_valid = na_data_boxed_is_valid( NA_DATA_BOXED( iv->data ));
 	}
 
 	if( is_valid ){
@@ -459,6 +471,23 @@ na_factory_object_is_valid( const NAIFactoryObject *object )
 	return( is_valid );
 }
 
+static gboolean
+factory_object_is_valid_mandatory_iter( const NADataDef *def, NafoValidIter *data )
+{
+	NADataBoxed *boxed;
+
+	if( def->mandatory && !def->obsoleted ){
+		boxed = data_boxed_from_name( data->object, def->name );
+		if( !boxed ){
+			g_debug( "na_factory_object_is_valid_mandatory_iter: invalid %s: mandatory but not set", def->name );
+			data->is_valid = FALSE;
+		}
+	}
+
+	/* do not stop iteration while valid */
+	return( !data->is_valid );
+}
+
 /**
  * na_factory_object_dump:
  * @object: this #NAIFactoryObject instance.
diff --git a/src/core/na-iduplicable.c b/src/core/na-iduplicable.c
index c791394..d71d783 100644
--- a/src/core/na-iduplicable.c
+++ b/src/core/na-iduplicable.c
@@ -249,7 +249,7 @@ na_iduplicable_duplicate( const NAIDuplicable *object )
 {
 	static const gchar *thisfn = "na_iduplicable_duplicate";
 	NAIDuplicable *dup;
-	DuplicableStr *str;
+	DuplicableStr *dup_str, *obj_str;
 
 	g_debug( "%s: object=%p (%s)",
 			thisfn,
@@ -265,9 +265,12 @@ na_iduplicable_duplicate( const NAIDuplicable *object )
 
 		v_copy( dup, object );
 
-		str = get_duplicable_str( dup );
-		str->origin = ( NAIDuplicable * ) object;
-		g_object_set_data( G_OBJECT( object ), NA_IDUPLICABLE_DATA_DUPLICABLE, str );
+		dup_str = get_duplicable_str( dup );
+		obj_str = get_duplicable_str( object );
+
+		dup_str->origin = ( NAIDuplicable * ) object;
+		dup_str->modified = obj_str->modified;
+		dup_str->valid = obj_str->valid;
 	}
 
 	return( dup );
diff --git a/src/core/na-io-provider.c b/src/core/na-io-provider.c
index 8f17e1a..d12a2ea 100644
--- a/src/core/na-io-provider.c
+++ b/src/core/na-io-provider.c
@@ -673,6 +673,8 @@ na_io_provider_read_items( const NAPivot *pivot, GSList **messages )
 			break;
 	}
 
+	/* check status here...
+	 */
 	filtered = filter_unwanted_items( pivot, hierarchy );
 	g_list_free( hierarchy );
 
diff --git a/src/core/na-object-item.c b/src/core/na-object-item.c
index 465e488..eab06fc 100644
--- a/src/core/na-object-item.c
+++ b/src/core/na-object-item.c
@@ -248,28 +248,28 @@ void
 na_object_item_copy( NAObjectItem *item, const NAObjectItem *source )
 {
 	static const gchar *thisfn = "na_object_item_copy";
-	GList *tgt_childs, *src_childs, *ic;
+	GList *tgt_children, *src_children, *ic;
 	NAObject *dup;
 
-	tgt_childs = na_object_get_items( item );
-	if( tgt_childs ){
+	tgt_children = na_object_get_items( item );
+	if( tgt_children ){
 
-		g_warning( "%s: target %s has already %d childs",
-				thisfn, G_OBJECT_TYPE_NAME( item ), g_list_length( tgt_childs ));
-		na_object_unref_items( tgt_childs );
-		tgt_childs = NULL;
+		g_warning( "%s: target %s has already %d children",
+				thisfn, G_OBJECT_TYPE_NAME( item ), g_list_length( tgt_children ));
+		na_object_unref_items( tgt_children );
+		tgt_children = NULL;
 	}
 
-	src_childs = na_object_get_items( source );
-	for( ic = src_childs ; ic ; ic = ic->next ){
+	src_children = na_object_get_items( source );
+	for( ic = src_children ; ic ; ic = ic->next ){
 
 		dup = ( NAObject * ) na_object_duplicate( ic->data );
 		na_object_set_parent( dup, item );
-		tgt_childs = g_list_prepend( tgt_childs, dup );
+		tgt_children = g_list_prepend( tgt_children, dup );
 	}
 
-	tgt_childs = g_list_reverse( tgt_childs );
-	na_object_set_items( item, tgt_childs );
+	tgt_children = g_list_reverse( tgt_children );
+	na_object_set_items( item, tgt_children );
 }
 
 /**
diff --git a/src/core/na-object.c b/src/core/na-object.c
index 75cb5e8..0b1d082 100644
--- a/src/core/na-object.c
+++ b/src/core/na-object.c
@@ -379,7 +379,7 @@ void
 na_object_object_check_status( const NAObject *object )
 {
 	static const gchar *thisfn = "na_object_object_check_status";
-	GList *childs, *ic;
+	GList *children, *ic;
 
 	g_debug( "%s: object=%p (%s)",
 			thisfn,
@@ -390,9 +390,9 @@ na_object_object_check_status( const NAObject *object )
 	if( !object->private->dispose_has_run ){
 
 		if( NA_IS_OBJECT_ITEM( object )){
+			children = na_object_get_items( object );
 
-			childs = na_object_get_items( object );
-			for( ic = childs ; ic ; ic = ic->next ){
+			for( ic = children ; ic ; ic = ic->next ){
 				na_object_check_status( ic->data );
 			}
 		}
@@ -762,6 +762,6 @@ na_object_free_hierarchy( GList *hierarchy )
 void
 na_object_object_debug_invalid( const NAObject *object, const gchar *reason )
 {
-	g_debug( "na_object_object_debug_invalid: object is marked invalid for reason \"%s\"", reason );
-	na_object_dump_norec( object );
+	g_debug( "na_object_object_debug_invalid: object %p (%s) is marked invalid for reason \"%s\"",
+			( void * ) object, G_OBJECT_TYPE_NAME( object ), reason );
 }
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 20a3b14..cb7549d 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -599,9 +599,6 @@ nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions)
 
 		for( it = items ; it ; it = it->next ){
 			duplicate = ( NAObject * ) na_object_duplicate( it->data );
-			if( !only_actions ){
-				na_object_check_status( duplicate );
-			}
 			fill_tree_store( ts_model, model->private->treeview, duplicate, only_actions, NULL );
 			g_object_unref( duplicate );
 		}



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