[nautilus-actions] Refactor NADataElement class
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Refactor NADataElement class
- Date: Fri, 19 Feb 2010 02:30:33 +0000 (UTC)
commit 92791dc437c8141ff5223b5cfa5d5fc73584b33b
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Feb 19 02:41:19 2010 +0100
Refactor NADataElement class
ChangeLog | 26 +
src/api/na-core-utils.h | 3 +-
src/api/na-idata-factory-str.h | 10 +
src/core/na-core-utils.c | 62 ++-
src/core/na-data-element.c | 978 ++++++++++++++++++++++++++-----------
src/core/na-data-element.h | 12 +-
src/core/na-data-factory.c | 34 +-
src/core/na-io-provider.c | 4 +-
src/core/na-io-provider.h | 2 +-
src/core/na-object-action-enum.c | 23 +-
src/core/na-object-id-enum.c | 9 +-
src/core/na-object-item-enum.c | 45 ++-
src/core/na-object-item.c | 10 +-
src/core/na-object-menu-enum.c | 2 +-
src/core/na-object-profile-enum.c | 32 +-
src/core/na-object.c | 53 ++-
src/io-desktop/nadp-writer.c | 4 +-
src/io-gconf/nagp-reader.c | 1 +
src/nact/nact-assistant-export.c | 8 +-
src/nact/nact-iactions-list-bis.c | 2 +-
src/nact/nact-main-statusbar.c | 2 +-
src/nact/nact-tree-model-dnd.c | 2 +-
src/nact/nact-tree-model.c | 2 +-
23 files changed, 928 insertions(+), 398 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 13f066d..f538e85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,31 @@
2009-02-18 Pierre Wieser <pwieser trychlos org>
+ * src/api/na-core-utils.h:
+ * src/api/na-idata-factory-str.h:
+ * src/core/na-core-utils.c:
+ * src/core/na-data-element.c:
+ * src/core/na-data-element.h:
+ * src/core/na-data-factory.c:
+ * src/core/na-io-provider.c:
+ * src/core/na-io-provider.h:
+ * src/core/na-object-action-enum.c:
+ * src/core/na-object-id-enum.c:
+ * src/core/na-object-item-enum.c:
+ * src/core/na-object-item.c:
+ * src/core/na-object-menu-enum.c:
+ * src/core/na-object-profile-enum.c:
+ * src/core/na-object.c:
+ * src/io-desktop/nadp-writer.c:
+ * src/io-gconf/nagp-reader.c:
+ * src/nact/nact-assistant-export.c:
+ * src/nact/nact-iactions-list-bis.c:
+ * src/nact/nact-main-statusbar.c:
+ * src/nact/nact-tree-model-dnd.c:
+ * src/nact/nact-tree-model.c:
+ Fix non empty string list.
+ Fix under reference in export assistant.
+ Refactor NADataElement class.
+
* src/core/na-exporter.c (na_exporter_get_formats):
Fix infinite loop.
diff --git a/src/api/na-core-utils.h b/src/api/na-core-utils.h
index 0cf5b31..7c78a38 100644
--- a/src/api/na-core-utils.h
+++ b/src/api/na-core-utils.h
@@ -70,7 +70,8 @@ gchar *na_core_utils_gstring_joinv( const gchar *start, const gchar *separator
/* directory management
*/
-gboolean na_core_utils_dir_is_writable( const gchar *path );
+gboolean na_core_utils_dir_is_writable_path( const gchar *path );
+gboolean na_core_utils_dir_is_writable_uri( const gchar *uri );
/* file management
*/
diff --git a/src/api/na-idata-factory-str.h b/src/api/na-idata-factory-str.h
index aba1c68..c341508 100644
--- a/src/api/na-idata-factory-str.h
+++ b/src/api/na-idata-factory-str.h
@@ -106,6 +106,16 @@ typedef struct {
gboolean mandatory; /* whether this data must be not null and not empty
* when we are testing for validity of an object */
+
+ void ( *free )( void * ); /* a pointer to a function to free the element data
+ * a default function is provided for main elementary
+ * data types:
+ * - STRING and LOCALE_STRING: g_free
+ * - STRING_LIST: na_core_utils_slist_free
+ * - BOOLEAN, UINT, POINTER: none
+ *
+ * This may be used mainly when POINTER type is used
+ * to cast e.g. a GList of items */
}
NadfIdType;
diff --git a/src/core/na-core-utils.c b/src/core/na-core-utils.c
index a651d65..3829f61 100644
--- a/src/core/na-core-utils.c
+++ b/src/core/na-core-utils.c
@@ -42,7 +42,8 @@
#include "na-iabout.h"
-static GSList *text_to_string_list( const gchar *text, const gchar *separator, const gchar *default_value );
+static GSList *text_to_string_list( const gchar *text, const gchar *separator, const gchar *default_value );
+static gboolean info_dir_is_writable( GFile *file, const gchar *path );
/**
* na_core_utils_boolean_from_string
@@ -178,7 +179,7 @@ na_core_utils_slist_dump( GSList *list )
GSList *i;
int c;
- g_debug( "%s: list at %p has %d elements", thisfn, ( void * ) list, g_slist_length( list ));
+ g_debug( "%s: list at %p has %d element(s)", thisfn, ( void * ) list, g_slist_length( list ));
for( i=list, c=0 ; i ; i=i->next ){
g_debug( "%s: [%2d] %s", thisfn, c++, ( gchar * ) i->data );
@@ -459,7 +460,7 @@ text_to_string_list( const gchar *text, const gchar *separator, const gchar *def
}
/**
- * na_core_utils_dir_is_writable:
+ * na_core_utils_dir_is_writable_path:
* @path: the path of the directory to be tested.
*
* Returns: %TRUE if the directory is writable, %FALSE else.
@@ -471,20 +472,64 @@ text_to_string_list( const gchar *text, const gchar *separator, const gchar *def
* There is no "super-test". Just try...
*/
gboolean
-na_core_utils_dir_is_writable( const gchar *path )
+na_core_utils_dir_is_writable_path( const gchar *path )
{
- static const gchar *thisfn = "na_core_utils_dir_is_writable";
+ static const gchar *thisfn = "na_core_utils_path_is_writable";
GFile *file;
- GError *error = NULL;
- GFileInfo *info;
- GFileType type;
gboolean writable;
if( !path || !g_utf8_strlen( path, -1 )){
+ g_warning( "%s: empty path", thisfn );
return( FALSE );
}
file = g_file_new_for_path( path );
+ writable = info_dir_is_writable( file, path );
+ g_object_unref( file );
+
+ return( writable );
+}
+
+/**
+ * na_core_utils_dir_is_writable_uri:
+ * @uri: the URI of the directory to be tested.
+ *
+ * Returns: %TRUE if the directory is writable, %FALSE else.
+ *
+ * Please note that this type of test is subject to race conditions,
+ * as the directory may become unwritable after a successful test,
+ * but before the caller has been able to actually write into it.
+ *
+ * There is no "super-test". Just try...
+ */
+gboolean
+na_core_utils_dir_is_writable_uri( const gchar *uri )
+{
+ static const gchar *thisfn = "na_core_utils_dir_is_writable_uri";
+ GFile *file;
+ gboolean writable;
+
+ if( !uri || !g_utf8_strlen( uri, -1 )){
+ g_warning( "%s: empty uri", thisfn );
+ return( FALSE );
+ }
+
+ file = g_file_new_for_uri( uri );
+ writable = info_dir_is_writable( file, uri );
+ g_object_unref( file );
+
+ return( writable );
+}
+
+static gboolean
+info_dir_is_writable( GFile *file, const gchar *path )
+{
+ static const gchar *thisfn = "na_core_utils_info_dir_is_writable";
+ GError *error = NULL;
+ GFileInfo *info;
+ GFileType type;
+ gboolean writable;
+
info = g_file_query_info( file,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, &error );
@@ -492,7 +537,6 @@ na_core_utils_dir_is_writable( const gchar *path )
if( error ){
g_warning( "%s: g_file_query_info error: %s", thisfn, error->message );
g_error_free( error );
- g_object_unref( file );
return( FALSE );
}
diff --git a/src/core/na-data-element.c b/src/core/na-data-element.c
index 936fa5b..ed5f246 100644
--- a/src/core/na-data-element.c
+++ b/src/core/na-data-element.c
@@ -49,8 +49,8 @@ struct NADataElementClassPrivate {
/* private instance data
*/
struct NADataElementPrivate {
- gboolean dispose_has_run;
- guint type;
+ gboolean dispose_has_run;
+ NadfIdType *iddef ;
union {
gboolean boolean;
gchar *string;
@@ -60,6 +60,22 @@ struct NADataElementPrivate {
} u;
};
+typedef struct {
+ guint type;
+ GParamSpec * ( *spec ) ( const NadfIdType * );
+ void ( *free ) ( const NADataElement * );
+ void ( *dump ) ( const NADataElement * );
+ gboolean ( *are_equal ) ( const NADataElement *, const NADataElement * );
+ gboolean ( *is_valid ) ( const NADataElement * );
+ void * ( *get ) ( const NADataElement * );
+ void ( *get_via_value ) ( const NADataElement *, GValue *value );
+ void ( *set_from_element )( NADataElement *, const NADataElement * );
+ void ( *set_from_string ) ( NADataElement *, const gchar *string );
+ void ( *set_from_value ) ( NADataElement *, const GValue *value );
+ void ( *set_from_void ) ( NADataElement *, const void *value );
+}
+ DataElementFn;
+
static GObjectClass *st_parent_class = NULL;
static GType register_type( void );
@@ -68,6 +84,153 @@ static void instance_init( GTypeInstance *instance, gpointer klass );
static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
+static DataElementFn *get_data_element_fn( guint type );
+
+static GParamSpec *string_spec( const NadfIdType *idtype );
+static void string_free( const NADataElement *element );
+static void string_dump( const NADataElement *element );
+static gboolean string_are_equal( const NADataElement *a, const NADataElement *b );
+static gboolean string_is_valid( const NADataElement *element );
+static void *string_get( const NADataElement *element );
+static void string_get_via_value( const NADataElement *element, GValue *value );
+static void string_set_from_element( NADataElement *element, const NADataElement *source );
+static void string_set_from_string( NADataElement *element, const gchar *string );
+static void string_set_from_value( NADataElement *element, const GValue *value );
+static void string_set_from_void( NADataElement *element, const void *value );
+
+static gboolean locale_are_equal( const NADataElement *a, const NADataElement *b );
+static gboolean locale_is_valid( const NADataElement *element );
+
+static GParamSpec *slist_spec( const NadfIdType *idtype );
+static void slist_free( const NADataElement *element );
+static void slist_dump( const NADataElement *element );
+static gboolean slist_are_equal( const NADataElement *a, const NADataElement *b );
+static gboolean slist_is_valid( const NADataElement *element );
+static void *slist_get( const NADataElement *element );
+static void slist_get_via_value( const NADataElement *element, GValue *value );
+static void slist_set_from_element( NADataElement *element, const NADataElement *source );
+static void slist_set_from_string( NADataElement *element, const gchar *string );
+static void slist_set_from_value( NADataElement *element, const GValue *value );
+static void slist_set_from_void( NADataElement *element, const void *value );
+
+static GParamSpec *bool_spec( const NadfIdType *idtype );
+static void bool_free( const NADataElement *element );
+static void bool_dump( const NADataElement *element );
+static gboolean bool_are_equal( const NADataElement *a, const NADataElement *b );
+static gboolean bool_is_valid( const NADataElement *element );
+static void *bool_get( const NADataElement *element );
+static void bool_get_via_value( const NADataElement *element, GValue *value );
+static void bool_set_from_element( NADataElement *element, const NADataElement *source );
+static void bool_set_from_string( NADataElement *element, const gchar *string );
+static void bool_set_from_value( NADataElement *element, const GValue *value );
+static void bool_set_from_void( NADataElement *element, const void *value );
+
+static GParamSpec *pointer_spec( const NadfIdType *idtype );
+static void pointer_free( const NADataElement *element );
+static void pointer_dump( const NADataElement *element );
+static gboolean pointer_are_equal( const NADataElement *a, const NADataElement *b );
+static gboolean pointer_is_valid( const NADataElement *element );
+static void *pointer_get( const NADataElement *element );
+static void pointer_get_via_value( const NADataElement *element, GValue *value );
+static void pointer_set_from_element( NADataElement *element, const NADataElement *source );
+static void pointer_set_from_string( NADataElement *element, const gchar *string );
+static void pointer_set_from_value( NADataElement *element, const GValue *value );
+static void pointer_set_from_void( NADataElement *element, const void *value );
+
+static GParamSpec *uint_spec( const NadfIdType *idtype );
+static void uint_free( const NADataElement *element );
+static void uint_dump( const NADataElement *element );
+static gboolean uint_are_equal( const NADataElement *a, const NADataElement *b );
+static gboolean uint_is_valid( const NADataElement *element );
+static void *uint_get( const NADataElement *element );
+static void uint_get_via_value( const NADataElement *element, GValue *value );
+static void uint_set_from_element( NADataElement *element, const NADataElement *source );
+static void uint_set_from_string( NADataElement *element, const gchar *string );
+static void uint_set_from_value( NADataElement *element, const GValue *value );
+static void uint_set_from_void( NADataElement *element, const void *value );
+
+static DataElementFn st_data_element_fn[] = {
+ { NADF_TYPE_STRING,
+ string_spec,
+ string_free,
+ string_dump,
+ string_are_equal,
+ string_is_valid,
+ string_get,
+ string_get_via_value,
+ string_set_from_element,
+ string_set_from_string,
+ string_set_from_value,
+ string_set_from_void
+ },
+ { NADF_TYPE_LOCALE_STRING,
+ string_spec,
+ string_free,
+ string_dump,
+ locale_are_equal,
+ locale_is_valid,
+ string_get,
+ string_get_via_value,
+ string_set_from_element,
+ string_set_from_string,
+ string_set_from_value,
+ string_set_from_void
+ },
+ { NADF_TYPE_STRING_LIST,
+ slist_spec,
+ slist_free,
+ slist_dump,
+ slist_are_equal,
+ slist_is_valid,
+ slist_get,
+ slist_get_via_value,
+ slist_set_from_element,
+ slist_set_from_string,
+ slist_set_from_value,
+ slist_set_from_void
+ },
+ { NADF_TYPE_BOOLEAN,
+ bool_spec,
+ bool_free,
+ bool_dump,
+ bool_are_equal,
+ bool_is_valid,
+ bool_get,
+ bool_get_via_value,
+ bool_set_from_element,
+ bool_set_from_string,
+ bool_set_from_value,
+ bool_set_from_void
+ },
+ { NADF_TYPE_POINTER,
+ pointer_spec,
+ pointer_free,
+ pointer_dump,
+ pointer_are_equal,
+ pointer_is_valid,
+ pointer_get,
+ pointer_get_via_value,
+ pointer_set_from_element,
+ pointer_set_from_string,
+ pointer_set_from_value,
+ pointer_set_from_void
+ },
+ { NADF_TYPE_UINT,
+ uint_spec,
+ uint_free,
+ uint_dump,
+ uint_are_equal,
+ uint_is_valid,
+ uint_get,
+ uint_get_via_value,
+ uint_set_from_element,
+ uint_set_from_string,
+ uint_set_from_value,
+ uint_set_from_void
+ },
+ { 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+};
+
GType
na_data_element_get_type( void )
{
@@ -170,20 +333,9 @@ instance_finalize( GObject *object )
self = NA_DATA_ELEMENT( object );
- switch( self->private->type ){
-
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- g_free( self->private->u.string );
- break;
-
- case NADF_TYPE_STRING_LIST:
- na_core_utils_slist_free( self->private->u.slist );
- break;
-
- case NADF_TYPE_BOOLEAN:
- case NADF_TYPE_POINTER:
- break;
+ DataElementFn *fn = get_data_element_fn( self->private->iddef->type );
+ if( fn->free ){
+ ( *fn->free )( self );
}
g_free( self->private );
@@ -194,20 +346,42 @@ instance_finalize( GObject *object )
}
}
+static DataElementFn *
+get_data_element_fn( guint type )
+{
+ static const gchar *thisfn = "na_data_element_get_data_element_fn";
+ int i;
+ DataElementFn *fn;
+
+ fn = NULL;
+
+ for( i = 0 ; st_data_element_fn[i].type && !fn ; ++i ){
+ if( st_data_element_fn[i].type == type ){
+ fn = st_data_element_fn+i;
+ }
+ }
+
+ if( !fn ){
+ g_warning( "%s: unmanaged type=%d", thisfn, type );
+ }
+
+ return( fn );
+}
+
/**
* na_data_element_new:
- * @type: a #NAIDataFactory standard type.
+ * @iddef: the #NadfIdType definition structure for this element.
*
* Returns: a newly allocated #NADataElement.
*/
NADataElement *
-na_data_element_new( guint type )
+na_data_element_new( const NadfIdType *iddef )
{
NADataElement *element;
element = g_object_new( NA_DATA_ELEMENT_TYPE, NULL );
- element->private->type = type;
+ element->private->iddef = ( NadfIdType * ) iddef;
return( element );
}
@@ -215,90 +389,110 @@ na_data_element_new( guint type )
/**
* na_data_element_dump:
* @element: this #NADataElement object.
- * @name: the name attributed to this element.
*
* Dump the content of @element.
*/
void
-na_data_element_dump( const NADataElement *element, const gchar *name )
+na_data_element_dump( const NADataElement *element )
{
- static const gchar *thisfn = "na_data_element_dump";
+ DataElementFn *fn;
- switch( element->private->type ){
+ fn = get_data_element_fn( element->private->iddef->type );
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- g_debug( "%s: %s=%s", thisfn, name, element->private->u.string );
- break;
+ if( fn ){
+ if( fn->dump ){
+ ( *fn->dump )( element );
+ }
+ }
+}
- case NADF_TYPE_STRING_LIST:
- g_debug( "%s: %s:", thisfn, name );
- na_core_utils_slist_dump( element->private->u.slist );
- break;
+/**
+ * na_data_element_get:
+ * @element: the #NADataElement whose value is to be set.
+ *
+ * Returns: the content of the @element.
+ *
+ * If of type NADF_TYPE_STRING, NADF_TYPE_LOCALE_STRING OR
+ * NADF_TYPE_STRING_LIST, then the content is returned in a newly
+ * allocated value, which should be released by the caller.
+ */
+void *
+na_data_element_get( const NADataElement *element )
+{
+ DataElementFn *fn;
+ void *value;
- case NADF_TYPE_BOOLEAN:
- g_debug( "%s: %s=%s", thisfn, name, element->private->u.boolean ? "True":"False" );
- break;
+ g_return_val_if_fail( NA_IS_DATA_ELEMENT( element ), NULL );
- case NADF_TYPE_POINTER:
- g_debug( "%s: %s=%p", thisfn, name, ( void * ) element->private->u.pointer );
- break;
+ value = NULL;
- case NADF_TYPE_UINT:
- g_debug( "%s: %s=%d", thisfn, name, element->private->u.uint );
- break;
+ if( !element->private->dispose_has_run ){
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, element->private->type );
+ fn = get_data_element_fn( element->private->iddef->type );
+ if( fn ){
+ if( fn->get ){
+ value = ( *fn->get )( element );
+ }
+ }
}
+
+ return( value );
}
/**
- * na_data_element_set:
+ * na_data_element_set_from_value:
* @element: the #NADataElement whose value is to be set.
- * @value: the source #NADataElement.
+ * @value: the string to be set.
*
- * Copy value from @value to @element.
+ * Setup @value with the content of the @element.
*/
void
-na_data_element_set( NADataElement *element, const NADataElement *value )
+na_data_element_set_to_value( const NADataElement *element, GValue *value )
{
- static const gchar *thisfn = "na_data_element_set";
+ DataElementFn *fn;
g_return_if_fail( NA_IS_DATA_ELEMENT( element ));
- g_return_if_fail( NA_IS_DATA_ELEMENT( value ));
- g_return_if_fail( element->private->type == value->private->type );
if( !element->private->dispose_has_run ){
- switch( element->private->type ){
+ fn = get_data_element_fn( element->private->iddef->type );
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- g_free( element->private->u.string );
- element->private->u.string = g_strdup( value->private->u.string );
- break;
+ if( fn ){
+ if( fn->get_via_value ){
+ ( *fn->get_via_value )( element, value );
+ }
+ }
+ }
+}
- case NADF_TYPE_STRING_LIST:
- na_core_utils_slist_free( element->private->u.slist );
- element->private->u.slist = na_core_utils_slist_duplicate( value->private->u.slist );
- break;
+/**
+ * na_data_element_set:
+ * @element: the #NADataElement whose value is to be set.
+ * @value: the source #NADataElement.
+ *
+ * Copy value from @value to @element.
+ */
+void
+na_data_element_set( NADataElement *element, const NADataElement *value )
+{
+ DataElementFn *fn;
- case NADF_TYPE_BOOLEAN:
- element->private->u.boolean = value->private->u.boolean;
- break;
+ g_return_if_fail( NA_IS_DATA_ELEMENT( element ));
+ g_return_if_fail( NA_IS_DATA_ELEMENT( value ));
+ g_return_if_fail( element->private->iddef->type == value->private->iddef->type );
- case NADF_TYPE_POINTER:
- element->private->u.pointer = value->private->u.pointer;
- break;
+ if( !element->private->dispose_has_run ){
- case NADF_TYPE_UINT:
- element->private->u.uint = value->private->u.uint;
- break;
+ fn = get_data_element_fn( element->private->iddef->type );
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, element->private->type );
+ if( fn ){
+ if( fn->free ){
+ ( *fn->free )( element );
+ }
+ if( fn->set_from_element ){
+ ( *fn->set_from_element )( element, value );
+ }
}
}
}
@@ -313,41 +507,21 @@ na_data_element_set( NADataElement *element, const NADataElement *value )
void
na_data_element_set_from_string( NADataElement *element, const gchar *value )
{
- static const gchar *thisfn = "na_data_element_set_from_string";
+ DataElementFn *fn;
g_return_if_fail( NA_IS_DATA_ELEMENT( element ));
if( !element->private->dispose_has_run ){
- switch( element->private->type ){
-
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- g_free( element->private->u.string );
- element->private->u.string = g_strdup( value );
- break;
-
- case NADF_TYPE_STRING_LIST:
- na_core_utils_slist_free( element->private->u.slist );
- element->private->u.slist = g_slist_append( NULL, g_strdup( value ));
- break;
-
- case NADF_TYPE_BOOLEAN:
- element->private->u.boolean = na_core_utils_boolean_from_string( value );
- break;
+ fn = get_data_element_fn( element->private->iddef->type );
- /* only a NULL value may be relevant here
- */
- case NADF_TYPE_POINTER:
- element->private->u.pointer = NULL;
- break;
-
- case NADF_TYPE_UINT:
- element->private->u.uint = atoi( value );
- break;
-
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, element->private->type );
+ if( fn ){
+ if( fn->free ){
+ ( *fn->free )( element );
+ }
+ if( fn->set_from_string ){
+ ( *fn->set_from_string )( element, value );
+ }
}
}
}
@@ -362,39 +536,21 @@ na_data_element_set_from_string( NADataElement *element, const gchar *value )
void
na_data_element_set_from_value( NADataElement *element, const GValue *value )
{
- static const gchar *thisfn = "na_data_element_set_from_value";
+ DataElementFn *fn;
g_return_if_fail( NA_IS_DATA_ELEMENT( element ));
if( !element->private->dispose_has_run ){
- switch( element->private->type ){
-
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- g_free( element->private->u.string );
- element->private->u.string = g_value_dup_string( value );
- break;
+ fn = get_data_element_fn( element->private->iddef->type );
- case NADF_TYPE_STRING_LIST:
- na_core_utils_slist_free( element->private->u.slist );
- element->private->u.slist = na_core_utils_slist_duplicate( g_value_get_pointer( value ));
- break;
-
- case NADF_TYPE_BOOLEAN:
- element->private->u.boolean = g_value_get_boolean( value );
- break;
-
- case NADF_TYPE_POINTER:
- element->private->u.pointer = g_value_get_pointer( value );
- break;
-
- case NADF_TYPE_UINT:
- element->private->u.uint = g_value_get_uint( value );
- break;
-
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, element->private->type );
+ if( fn ){
+ if( fn->free ){
+ ( *fn->free )( element );
+ }
+ if( fn->set_from_value ){
+ ( *fn->set_from_value )( element, value );
+ }
}
}
}
@@ -409,249 +565,487 @@ na_data_element_set_from_value( NADataElement *element, const GValue *value )
void
na_data_element_set_from_void( NADataElement *element, const void *value )
{
- static const gchar *thisfn = "na_data_element_set_from_void";
+ DataElementFn *fn;
g_return_if_fail( NA_IS_DATA_ELEMENT( element ));
if( !element->private->dispose_has_run ){
- switch( element->private->type ){
+ fn = get_data_element_fn( element->private->iddef->type );
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- g_free( element->private->u.string );
- element->private->u.string = g_strdup(( const gchar * ) value );
- break;
+ if( fn ){
+ if( fn->free ){
+ ( *fn->free )( element );
+ }
+ if( fn->set_from_void ){
+ ( *fn->set_from_void )( element, value );
+ }
+ }
+ }
+}
- case NADF_TYPE_STRING_LIST:
- na_core_utils_slist_free( element->private->u.slist );
- element->private->u.slist = na_core_utils_slist_duplicate(( GSList * ) value );
- break;
+/**
+ * na_data_element_are_equal:
+ * @a: the first #NADataElement object.
+ * @b: the second #NADataElement object.
+ *
+ * Returns: %TRUE if the two elements are equal, %FALSE else.
+ */
+gboolean
+na_data_element_are_equal( const NADataElement *a, const NADataElement *b )
+{
+ DataElementFn *fn;
+ gboolean are_equal;
- case NADF_TYPE_BOOLEAN:
- element->private->u.boolean = GPOINTER_TO_UINT( value );
- break;
+ g_return_val_if_fail( NA_IS_DATA_ELEMENT( a ), FALSE );
+ g_return_val_if_fail( NA_IS_DATA_ELEMENT( b ), FALSE );
+
+ are_equal = FALSE;
- case NADF_TYPE_POINTER:
- element->private->u.pointer = ( void * ) value;
- break;
+ if( !a->private->dispose_has_run &&
+ !b->private->dispose_has_run ){
- case NADF_TYPE_UINT:
- element->private->u.uint = GPOINTER_TO_UINT( value );
- break;
+ if( a->private->iddef->type == b->private->iddef->type ){
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, element->private->type );
+ fn = get_data_element_fn( a->private->iddef->type );
+
+ if( fn ){
+ if( fn->are_equal ){
+ are_equal = ( *fn->are_equal )( a, b );
+ }
+ }
}
}
+
+ return( are_equal );
}
/**
- * na_data_element_get:
- * @element: the #NADataElement whose value is to be set.
- *
- * Returns: the content of the @element.
+ * na_data_element_is_valid:
+ * @object: the #NADataElement object whose validity is to be checked.
*
- * If of type NADF_TYPE_STRING, NADF_TYPE_LOCALE_STRING OR
- * NADF_TYPE_STRING_LIST, then the content is returned in a newly
- * allocated value, which should be released by the caller.
+ * Returns: %TRUE if the element is valid, %FALSE else.
*/
-void *
-na_data_element_get( const NADataElement *element )
+gboolean
+na_data_element_is_valid( const NADataElement *element )
{
- static const gchar *thisfn = "na_data_element_set_to_value";
- void *value;
+ DataElementFn *fn;
+ gboolean is_valid;
- g_return_val_if_fail( NA_IS_DATA_ELEMENT( element ), NULL );
+ g_return_val_if_fail( NA_IS_DATA_ELEMENT( element ), FALSE );
- value = NULL;
+ is_valid = FALSE;
if( !element->private->dispose_has_run ){
- switch( element->private->type ){
+ fn = get_data_element_fn( element->private->iddef->type );
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- value = g_strdup( element->private->u.string );
- break;
+ if( fn ){
+ if( fn->is_valid ){
+ is_valid = ( *fn->is_valid )( element );
+ }
+ }
+ }
- case NADF_TYPE_STRING_LIST:
- value = na_core_utils_slist_duplicate( element->private->u.slist );
- break;
+ return( is_valid );
+}
- case NADF_TYPE_BOOLEAN:
- value = GUINT_TO_POINTER( element->private->u.boolean );
- break;
+static GParamSpec *
+string_spec( const NadfIdType *idtype )
+{
+ return( NULL );
+}
- case NADF_TYPE_POINTER:
- value = element->private->u.pointer;
- break;
+static void
+string_free( const NADataElement *element )
+{
+ if( element->private->iddef->free ){
+ ( *element->private->iddef->free )( element->private->u.string );
+ } else {
+ g_free( element->private->u.string );
+ }
+ element->private->u.string = NULL;
+}
- case NADF_TYPE_UINT:
- value = GUINT_TO_POINTER( element->private->u.uint );
- break;
+static void
+string_dump( const NADataElement *element )
+{
+ g_debug( "na-data-element: %s=%s", element->private->iddef->name, element->private->u.string );
+}
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, element->private->type );
- }
+static gboolean
+string_are_equal( const NADataElement *a, const NADataElement *b )
+{
+ if( !a->private->u.string && !b->private->u.string ){
+ return( TRUE );
+ }
+ if( !a->private->u.string || !b->private->u.string ){
+ return( FALSE );
+ }
+ return( strcmp( a->private->u.string, b->private->u.string ) == 0 );
+}
+
+static gboolean
+string_is_valid( const NADataElement *element )
+{
+ return( element->private->u.string && strlen( element->private->u.string ) > 0 );
+}
+
+static void *
+string_get( const NADataElement *element )
+{
+ void *value = NULL;
+
+ if( element->private->u.string ){
+ value = g_strdup( element->private->u.string );
}
return( value );
}
-/**
- * na_data_element_set_from_value:
- * @element: the #NADataElement whose value is to be set.
- * @value: the string to be set.
- *
- * Setup @value with the content of the @element.
- */
-void
-na_data_element_set_to_value( const NADataElement *element, GValue *value )
+static void
+string_get_via_value( const NADataElement *element, GValue *value )
{
- static const gchar *thisfn = "na_data_element_set_to_value";
+ g_value_set_string( value, element->private->u.string );
+}
- g_return_if_fail( NA_IS_DATA_ELEMENT( element ));
+static void
+string_set_from_element( NADataElement *element, const NADataElement *source )
+{
+ element->private->u.string = g_strdup( source->private->u.string );
+}
- if( !element->private->dispose_has_run ){
+static void
+string_set_from_string( NADataElement *element, const gchar *string )
+{
+ if( string ){
+ element->private->u.string = g_strdup( string );
+ }
+}
+
+static void
+string_set_from_value( NADataElement *element, const GValue *value )
+{
+ if( g_value_get_string( value )){
+ element->private->u.string = g_value_dup_string( value );
+ }
+}
- switch( element->private->type ){
+static void
+string_set_from_void( NADataElement *element, const void *value )
+{
+ if( value ){
+ element->private->u.string = g_strdup(( const gchar * ) value );
+ }
+}
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- g_value_set_string( value, element->private->u.string );
- break;
+static gboolean
+locale_are_equal( const NADataElement *a, const NADataElement *b )
+{
+ if( !a->private->u.string && !b->private->u.string ){
+ return( TRUE );
+ }
+ if( !a->private->u.string || !b->private->u.string ){
+ return( FALSE );
+ }
+ return( g_utf8_collate( a->private->u.string, b->private->u.string ) == 0 );
+}
- case NADF_TYPE_STRING_LIST:
- g_value_set_pointer( value, na_core_utils_slist_duplicate( element->private->u.slist ));
- break;
+static gboolean
+locale_is_valid( const NADataElement *element )
+{
+ return( element->private->u.string && g_utf8_strlen( element->private->u.string, -1 ) > 0 );
+}
- case NADF_TYPE_BOOLEAN:
- g_value_set_boolean( value, element->private->u.boolean );
- break;
+static GParamSpec *
+slist_spec( const NadfIdType *idtype )
+{
+ return( NULL );
+}
- case NADF_TYPE_POINTER:
- g_value_set_pointer( value, element->private->u.pointer );
- break;
+static void
+slist_free( const NADataElement *element )
+{
+ if( element->private->iddef->free ){
+ ( *element->private->iddef->free )( element->private->u.slist );
+ } else {
+ na_core_utils_slist_free( element->private->u.slist );
+ }
+ element->private->u.slist = NULL;
+}
- case NADF_TYPE_UINT:
- g_value_set_uint( value, element->private->u.uint );
- break;
+static void
+slist_dump( const NADataElement *element )
+{
+ g_debug( "na-data-element: %s=", element->private->iddef->name );
+ na_core_utils_slist_dump( element->private->u.slist );
+}
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, element->private->type );
- }
+static gboolean
+slist_are_equal( const NADataElement *a, const NADataElement *b )
+{
+ if( !a->private->u.slist && !b->private->u.slist ){
+ return( TRUE );
+ }
+ if( !a->private->u.slist || !b->private->u.slist ){
+ return( FALSE );
}
+ return( na_core_utils_slist_are_equal( a->private->u.slist, b->private->u.slist ));
}
-/**
- * na_data_element_are_equal:
- * @a: the first #NADataElement object.
- * @b: the second #NADataElement object.
- *
- * Returns: %TRUE if the two elements are equal, %FALSE else.
- */
-gboolean
-na_data_element_are_equal( const NADataElement *a, const NADataElement *b )
+static gboolean
+slist_is_valid( const NADataElement *element )
{
- static const gchar *thisfn = "na_data_element_are_equal";
- gboolean are_equal;
+ return( element->private->u.slist && g_slist_length( element->private->u.slist ) > 0 );
+}
- g_return_val_if_fail( NA_IS_DATA_ELEMENT( a ), FALSE );
- g_return_val_if_fail( NA_IS_DATA_ELEMENT( b ), FALSE );
+static void *
+slist_get( const NADataElement *element )
+{
+ void *value = NULL;
- are_equal = FALSE;
+ if( element->private->u.slist ){
+ value = na_core_utils_slist_duplicate( element->private->u.slist );
+ }
- if( !a->private->dispose_has_run &&
- !b->private->dispose_has_run ){
+ return( value );
+}
- if( a->private->type == b->private->type ){
+static void
+slist_get_via_value( const NADataElement *element, GValue *value )
+{
+ g_value_set_pointer( value, na_core_utils_slist_duplicate( element->private->u.slist ));
+}
+
+static void
+slist_set_from_element( NADataElement *element, const NADataElement *source )
+{
+ element->private->u.slist = na_core_utils_slist_duplicate( source->private->u.slist );
+}
+
+static void
+slist_set_from_string( NADataElement *element, const gchar *string )
+{
+ if( string ){
+ element->private->u.slist = g_slist_append( NULL, g_strdup( string ));
+ }
+}
+
+static void
+slist_set_from_value( NADataElement *element, const GValue *value )
+{
+ if( g_value_get_pointer( value )){
+ element->private->u.slist = na_core_utils_slist_duplicate( g_value_get_pointer( value ));
+ }
+}
+
+static void
+slist_set_from_void( NADataElement *element, const void *value )
+{
+ if( value ){
+ element->private->u.slist = na_core_utils_slist_duplicate(( GSList * ) value );
+ }
+}
- are_equal = TRUE;
+static GParamSpec *
+bool_spec( const NadfIdType *idtype )
+{
+ return( NULL );
+}
- switch( a->private->type ){
+static void
+bool_free( const NADataElement *element )
+{
+ /* n/a */
+}
- case NADF_TYPE_STRING:
- are_equal = ( strcmp( a->private->u.string, b->private->u.string ) == 0 );
- break;
+static void
+bool_dump( const NADataElement *element )
+{
+ g_debug( "na-data-element: %s=%s",
+ element->private->iddef->name, element->private->u.boolean ? "True":"False" );
+}
- case NADF_TYPE_LOCALE_STRING:
- are_equal = ( g_utf8_collate( a->private->u.string, b->private->u.string ) == 0 );
- break;
+static gboolean
+bool_are_equal( const NADataElement *a, const NADataElement *b )
+{
+ return( a->private->u.boolean == b->private->u.boolean );
+}
- case NADF_TYPE_STRING_LIST:
- are_equal = na_core_utils_slist_are_equal( a->private->u.slist, b->private->u.slist );
- break;
+static gboolean
+bool_is_valid( const NADataElement *element )
+{
+ return( TRUE );
+}
- case NADF_TYPE_BOOLEAN:
- are_equal = ( a->private->u.boolean == b->private->u.boolean );
- break;
+static void *
+bool_get( const NADataElement *element )
+{
+ return( GUINT_TO_POINTER( element->private->u.boolean ));
+}
- case NADF_TYPE_POINTER:
- are_equal = ( a->private->u.pointer == b->private->u.pointer );
- break;
+static void
+bool_get_via_value( const NADataElement *element, GValue *value )
+{
+ g_value_set_boolean( value, element->private->u.boolean );
+}
- case NADF_TYPE_UINT:
- are_equal = ( a->private->u.uint == b->private->u.uint );
- break;
+static void
+bool_set_from_element( NADataElement *element, const NADataElement *source )
+{
+ element->private->u.boolean = source->private->u.boolean;
+}
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, a->private->type );
- are_equal = FALSE;
- }
- }
+static void
+bool_set_from_string( NADataElement *element, const gchar *string )
+{
+ element->private->u.boolean = na_core_utils_boolean_from_string( string );
+}
+
+static void
+bool_set_from_value( NADataElement *element, const GValue *value )
+{
+ element->private->u.boolean = g_value_get_boolean( value );
+}
+
+static void
+bool_set_from_void( NADataElement *element, const void *value )
+{
+ element->private->u.boolean = GPOINTER_TO_UINT( value );
+}
+
+static GParamSpec *
+pointer_spec( const NadfIdType *idtype )
+{
+ return( NULL );
+}
+
+static void
+pointer_free( const NADataElement *element )
+{
+ if( element->private->iddef->free ){
+ ( *element->private->iddef->free )( element->private->u.pointer );
}
+ element->private->u.pointer = NULL;
+}
- return( are_equal );
+static void
+pointer_dump( const NADataElement *element )
+{
+ g_debug( "na-data-element: %s=%p",
+ element->private->iddef->name, ( void * ) element->private->u.pointer );
}
-/**
- * na_data_element_is_valid:
- * @object: the #NADataElement object whose validity is to be checked.
- *
- * Returns: %TRUE if the element is valid, %FALSE else.
- */
-gboolean
-na_data_element_is_valid( const NADataElement *object )
+static gboolean
+pointer_are_equal( const NADataElement *a, const NADataElement *b )
{
- static const gchar *thisfn = "na_data_element_is_valid";
- gboolean is_valid;
+ return( a->private->u.pointer == b->private->u.pointer );
+}
- g_return_val_if_fail( NA_IS_DATA_ELEMENT( object ), FALSE );
+static gboolean
+pointer_is_valid( const NADataElement *element )
+{
+ return( element->private->u.pointer != NULL );
+}
- is_valid = FALSE;
+static void *
+pointer_get( const NADataElement *element )
+{
+ return( element->private->u.pointer );
+}
- if( !object->private->dispose_has_run ){
+static void
+pointer_get_via_value( const NADataElement *element, GValue *value )
+{
+ g_value_set_pointer( value, element->private->u.pointer );
+}
- is_valid = TRUE;
+static void
+pointer_set_from_element( NADataElement *element, const NADataElement *source )
+{
+ element->private->u.pointer = source->private->u.pointer;
+}
- switch( object->private->type ){
+static void
+pointer_set_from_string( NADataElement *element, const gchar *pointer )
+{
+}
- case NADF_TYPE_STRING:
- case NADF_TYPE_LOCALE_STRING:
- is_valid = object->private->u.string && strlen( object->private->u.string ) > 0;
- break;
+static void
+pointer_set_from_value( NADataElement *element, const GValue *value )
+{
+ element->private->u.pointer = g_value_get_pointer( value );
+}
- case NADF_TYPE_STRING_LIST:
- is_valid = object->private->u.slist && g_slist_length( object->private->u.slist ) > 0;
- break;
+static void
+pointer_set_from_void( NADataElement *element, const void *value )
+{
+ element->private->u.pointer = ( void * ) value;
+}
- case NADF_TYPE_BOOLEAN:
- break;
+static GParamSpec *
+uint_spec( const NadfIdType *idtype )
+{
+ return( NULL );
+}
+
+static void
+uint_free( const NADataElement *element )
+{
+ /* n/a */
+}
- case NADF_TYPE_POINTER:
- is_valid = ( object->private->u.pointer != NULL );
- break;
+static void
+uint_dump( const NADataElement *element )
+{
+ g_debug( "na-data-element: %s=%d",
+ element->private->iddef->name, element->private->u.uint );
+}
- case NADF_TYPE_UINT:
- is_valid = ( object->private->u.uint > 0 );
- break;
+static gboolean
+uint_are_equal( const NADataElement *a, const NADataElement *b )
+{
+ return( a->private->u.uint == b->private->u.uint );
+}
- default:
- g_warning( "%s: unmanaged type=%d", thisfn, object->private->type );
- is_valid = FALSE;
- }
- }
+static gboolean
+uint_is_valid( const NADataElement *element )
+{
+ return( element->private->u.uint > 0 );
+}
- return( is_valid );
+static void *
+uint_get( const NADataElement *element )
+{
+ return( GUINT_TO_POINTER( element->private->u.uint ));
+}
+
+static void
+uint_get_via_value( const NADataElement *element, GValue *value )
+{
+ g_value_set_uint( value, element->private->u.uint );
+}
+
+static void
+uint_set_from_element( NADataElement *element, const NADataElement *source )
+{
+ element->private->u.uint = source->private->u.uint;
+}
+
+static void
+uint_set_from_string( NADataElement *element, const gchar *string )
+{
+ element->private->u.uint = atoi( string );
+}
+
+static void
+uint_set_from_value( NADataElement *element, const GValue *value )
+{
+ element->private->u.uint = g_value_get_uint( value );
+}
+
+static void
+uint_set_from_void( NADataElement *element, const void *value )
+{
+ element->private->u.uint = GPOINTER_TO_UINT( value );
}
diff --git a/src/core/na-data-element.h b/src/core/na-data-element.h
index dfe0ed9..c29264b 100644
--- a/src/core/na-data-element.h
+++ b/src/core/na-data-element.h
@@ -42,6 +42,8 @@
#include <glib-object.h>
+#include <api/na-idata-factory-str.h>
+
G_BEGIN_DECLS
#define NA_DATA_ELEMENT_TYPE ( na_data_element_get_type())
@@ -69,18 +71,18 @@ typedef struct {
GType na_data_element_get_type( void );
-NADataElement *na_data_element_new( guint type );
+NADataElement *na_data_element_new( const NadfIdType *iddef );
+
+void na_data_element_dump( const NADataElement *element );
-void na_data_element_dump( const NADataElement *element, const gchar *name );
+void *na_data_element_get ( const NADataElement *element );
+void na_data_element_set_to_value ( const NADataElement *element, GValue *value );
void na_data_element_set ( NADataElement *element, const NADataElement *value );
void na_data_element_set_from_string ( NADataElement *element, const gchar *value );
void na_data_element_set_from_value ( NADataElement *element, const GValue *value );
void na_data_element_set_from_void ( NADataElement *element, const void *value );
-void *na_data_element_get ( const NADataElement *element );
-void na_data_element_set_to_value ( const NADataElement *element, GValue *value );
-
gboolean na_data_element_are_equal ( const NADataElement *a, const NADataElement *b );
gboolean na_data_element_is_valid ( const NADataElement *element );
diff --git a/src/core/na-data-factory.c b/src/core/na-data-factory.c
index 6d0dd6e..a9f4316 100644
--- a/src/core/na-data-factory.c
+++ b/src/core/na-data-factory.c
@@ -235,7 +235,7 @@ data_factory_init_iter( const NadfIdType *iddef, NAIDataFactory *object )
stop = FALSE;
default_value = v_get_default( object, iddef );
- element = na_data_element_new( iddef->type );
+ element = na_data_element_new( iddef );
na_data_element_set_from_string( element, ( const void * )( default_value ? default_value : iddef->default_value ));
g_free( default_value );
@@ -250,20 +250,6 @@ data_factory_init_iter( const NadfIdType *iddef, NAIDataFactory *object )
return( stop );
}
-static gchar *
-v_get_default( const NAIDataFactory *object, const NadfIdType *iddef )
-{
- gchar *default_value;
-
- default_value = NULL;
-
- if( NA_IDATA_FACTORY_GET_INTERFACE( object )->get_default ){
- default_value = NA_IDATA_FACTORY_GET_INTERFACE( object )->get_default( object, iddef );
- }
-
- return( default_value );
-}
-
/**
* na_data_factory_copy:
* @target: the target #NAIDataFactory instance.
@@ -295,6 +281,20 @@ na_data_factory_copy( NAIDataFactory *target, const NAIDataFactory *source )
v_copy( target, source );
}
+static gchar *
+v_get_default( const NAIDataFactory *object, const NadfIdType *iddef )
+{
+ gchar *default_value;
+
+ default_value = NULL;
+
+ if( NA_IDATA_FACTORY_GET_INTERFACE( object )->get_default ){
+ default_value = NA_IDATA_FACTORY_GET_INTERFACE( object )->get_default( object, iddef );
+ }
+
+ return( default_value );
+}
+
static void
v_copy( NAIDataFactory *target, const NAIDataFactory *source )
{
@@ -431,10 +431,11 @@ na_data_factory_dump( const NAIDataFactory *object )
NadfDataValue *str;
list = g_object_get_data( G_OBJECT( object ), NA_IDATA_FACTORY_PROP_DATA );
+
for( it = list ; it ; it = it->next ){
str = ( NadfDataValue * ) it->data;
- na_data_element_dump( str->element, str->iddef->name );
+ na_data_element_dump( str->element );
}
}
@@ -451,6 +452,7 @@ na_data_factory_finalize( NAIDataFactory *object )
NadfDataValue *str;
list = g_object_get_data( G_OBJECT( object ), NA_IDATA_FACTORY_PROP_DATA );
+
for( it = list ; it ; it = it->next ){
str = ( NadfDataValue * ) it->data;
diff --git a/src/core/na-io-provider.c b/src/core/na-io-provider.c
index c25a93e..6b53d31 100644
--- a/src/core/na-io-provider.c
+++ b/src/core/na-io-provider.c
@@ -1234,14 +1234,14 @@ na_io_provider_delete_item( const NAIOProvider *provider, const NAObjectItem *it
}
/**
- * na_io_provider_get_tooltip:
+ * na_io_provider_get_readonly_tooltip:
* @reason: the reason for why an item is not writable.
*
* Returns: the associated tooltip, as a newly allocated string which
* should be g_free() by the caller.
*/
gchar *
-na_io_provider_get_tooltip( guint reason )
+na_io_provider_get_readonly_tooltip( guint reason )
{
gchar *tooltip;
diff --git a/src/core/na-io-provider.h b/src/core/na-io-provider.h
index 6ce3035..636dddd 100644
--- a/src/core/na-io-provider.h
+++ b/src/core/na-io-provider.h
@@ -101,7 +101,7 @@ gboolean na_io_provider_has_write_api ( const NAIOProvider *p
guint na_io_provider_write_item ( const NAIOProvider *provider, const NAObjectItem *item, GSList **messages );
guint na_io_provider_delete_item( const NAIOProvider *provider, const NAObjectItem *item, GSList **messages );
-gchar *na_io_provider_get_tooltip( guint reason );
+gchar *na_io_provider_get_readonly_tooltip( guint reason );
G_END_DECLS
diff --git a/src/core/na-object-action-enum.c b/src/core/na-object-action-enum.c
index fb79ad7..b657961 100644
--- a/src/core/na-object-action-enum.c
+++ b/src/core/na-object-action-enum.c
@@ -49,7 +49,8 @@ static NadfIdType action_iddef [] = {
"2.0",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_TARGET_SELECTION,
"na-object-target-selection",
@@ -60,7 +61,8 @@ static NadfIdType action_iddef [] = {
"TRUE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_TARGET_BACKGROUND,
"na-object-target-background",
@@ -71,7 +73,8 @@ static NadfIdType action_iddef [] = {
"FALSE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_TARGET_TOOLBAR,
"na-object-target-toolbar",
@@ -84,7 +87,8 @@ static NadfIdType action_iddef [] = {
"FALSE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_TOOLBAR_LABEL,
"na-object-toolbar-label",
@@ -96,7 +100,8 @@ static NadfIdType action_iddef [] = {
"",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_TOOLBAR_SAME_LABEL,
"na-object-toolbar-same-label",
@@ -107,7 +112,8 @@ static NadfIdType action_iddef [] = {
"true",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_LAST_ALLOCATED,
"na-object-last-allocated",
@@ -119,9 +125,10 @@ static NadfIdType action_iddef [] = {
"0",
TRUE,
FALSE,
- FALSE },
+ FALSE,
+ NULL },
- { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE },
+ { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE, FALSE, NULL },
};
NadfIdGroup action_id_groups [] = {
diff --git a/src/core/na-object-id-enum.c b/src/core/na-object-id-enum.c
index 187171f..4641581 100644
--- a/src/core/na-object-id-enum.c
+++ b/src/core/na-object-id-enum.c
@@ -48,7 +48,8 @@ NadfIdType id_iddef [] = {
NULL,
TRUE,
TRUE,
- TRUE },
+ TRUE,
+ NULL },
{ NADF_DATA_LABEL,
"na-object-label",
@@ -60,7 +61,8 @@ NadfIdType id_iddef [] = {
"",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_PARENT,
"na-object-parent",
@@ -71,7 +73,8 @@ NadfIdType id_iddef [] = {
NULL,
FALSE,
FALSE,
- FALSE },
+ FALSE,
+ NULL },
{ 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE },
};
diff --git a/src/core/na-object-item-enum.c b/src/core/na-object-item-enum.c
index 29c82dc..6b092c6 100644
--- a/src/core/na-object-item-enum.c
+++ b/src/core/na-object-item-enum.c
@@ -35,6 +35,8 @@
#include <api/na-idata-factory-enum.h>
#include <api/na-idata-factory-str.h>
+static void free_items_list( void * list );
+
NadfIdType item_iddef [] = {
{ NADF_DATA_TOOLTIP,
@@ -46,7 +48,8 @@ NadfIdType item_iddef [] = {
"",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_ICON,
"na-object-icon",
@@ -58,7 +61,8 @@ NadfIdType item_iddef [] = {
"",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_DESCRIPTION,
"na-object-description",
@@ -70,7 +74,8 @@ NadfIdType item_iddef [] = {
"",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_SUBITEMS,
"na-object-subitems",
@@ -81,7 +86,8 @@ NadfIdType item_iddef [] = {
NULL,
FALSE,
FALSE,
- FALSE },
+ FALSE,
+ free_items_list },
{ NADF_DATA_SUBITEMS_SLIST,
"na-object-subitems-slist",
@@ -90,10 +96,11 @@ NadfIdType item_iddef [] = {
"List of subitems ids, " \
"as readen from corresponding entry from the storage subsystem.",
NADF_TYPE_STRING_LIST,
- "",
+ NULL,
+ FALSE,
FALSE,
FALSE,
- FALSE },
+ NULL },
{ NADF_DATA_ENABLED,
"na-object-enabled",
@@ -106,7 +113,8 @@ NadfIdType item_iddef [] = {
"TRUE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_READONLY,
"na-object-readonly",
@@ -122,7 +130,8 @@ NadfIdType item_iddef [] = {
"FALSE",
TRUE,
FALSE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_PROVIDER,
"na-object-provider",
@@ -133,7 +142,8 @@ NadfIdType item_iddef [] = {
NULL,
TRUE,
FALSE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_PROVIDER_DATA,
"na-object-provider-data",
@@ -144,7 +154,20 @@ NadfIdType item_iddef [] = {
NULL,
TRUE,
FALSE,
- FALSE },
+ FALSE,
+ NULL },
- { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE },
+ { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE, FALSE, NULL },
};
+
+static void
+free_items_list( void * list )
+{
+ static const gchar *thisfn = "na_object_item_enum_free_items_list";
+
+ g_debug( "%s: list=%p (count=%d)", thisfn, list, g_list_length(( GList * ) list ));
+
+ if( list ){
+ /*g_list_free(( GList * ) list );*/
+ }
+}
diff --git a/src/core/na-object-item.c b/src/core/na-object-item.c
index a6ef836..183e75c 100644
--- a/src/core/na-object-item.c
+++ b/src/core/na-object-item.c
@@ -436,20 +436,20 @@ na_object_item_get_position( const NAObjectItem *object, const NAObjectId *child
void
na_object_item_append_item( NAObjectItem *item, const NAObjectId *child )
{
- GList *childs_list;
+ GList *children;
g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
g_return_if_fail( NA_IS_OBJECT_ID( child ));
if( !item->private->dispose_has_run ){
- childs_list = na_object_get_items( item );
+ children = na_object_get_items( item );
- if( !g_list_find( childs_list, ( gpointer ) child )){
+ if( !g_list_find( children, ( gpointer ) child )){
- childs_list = g_list_append( childs_list, ( gpointer ) child );
+ children = g_list_append( children, ( gpointer ) child );
na_object_set_parent( child, item );
- na_object_set_items( item, childs_list );
+ na_object_set_items( item, children );
}
}
}
diff --git a/src/core/na-object-menu-enum.c b/src/core/na-object-menu-enum.c
index 5aa2d34..17a4cab 100644
--- a/src/core/na-object-menu-enum.c
+++ b/src/core/na-object-menu-enum.c
@@ -40,7 +40,7 @@ extern NadfIdType item_iddef []; /* defined in na-object-item-enum.c */
static NadfIdType menu_iddef [] = {
- { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE },
+ { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE, FALSE, NULL },
};
NadfIdGroup menu_id_groups [] = {
diff --git a/src/core/na-object-profile-enum.c b/src/core/na-object-profile-enum.c
index 18f1405..8f9628f 100644
--- a/src/core/na-object-profile-enum.c
+++ b/src/core/na-object-profile-enum.c
@@ -48,7 +48,8 @@ static NadfIdType profile_iddef [] = {
"",
TRUE,
TRUE,
- TRUE },
+ TRUE,
+ NULL },
{ NADF_DATA_PARAMETERS,
"na-object-parameters",
@@ -59,7 +60,8 @@ static NadfIdType profile_iddef [] = {
"",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_BASENAMES,
"na-object-basenames",
@@ -71,7 +73,8 @@ static NadfIdType profile_iddef [] = {
"*",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_MATCHCASE,
"na-object-matchcase",
@@ -83,7 +86,8 @@ static NadfIdType profile_iddef [] = {
"TRUE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_MIMETYPES,
"na-object-mimetypes",
@@ -95,7 +99,8 @@ static NadfIdType profile_iddef [] = {
"*",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_ISFILE,
"na-object-isfile",
@@ -107,7 +112,8 @@ static NadfIdType profile_iddef [] = {
"TRUE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_ISDIR,
"na-object-isdir",
@@ -119,7 +125,8 @@ static NadfIdType profile_iddef [] = {
"FALSE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_MULTIPLE,
"na-object-multiple",
@@ -131,7 +138,8 @@ static NadfIdType profile_iddef [] = {
"FALSE",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_SCHEMES,
"na-object-schemes",
@@ -143,7 +151,8 @@ static NadfIdType profile_iddef [] = {
"file",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
{ NADF_DATA_FOLDERS,
"na-object-folders",
@@ -155,9 +164,10 @@ static NadfIdType profile_iddef [] = {
"/",
TRUE,
TRUE,
- FALSE },
+ FALSE,
+ NULL },
- { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE },
+ { 0, NULL, FALSE, NULL, NULL, 0, NULL, FALSE, FALSE, FALSE, NULL },
};
NadfIdGroup profile_id_groups [] = {
diff --git a/src/core/na-object.c b/src/core/na-object.c
index 911921f..659f635 100644
--- a/src/core/na-object.c
+++ b/src/core/na-object.c
@@ -66,6 +66,8 @@ static void instance_init( GTypeInstance *instance, gpointer klass );
static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
+static void object_dump( const NAObject *object );
+
static void iduplicable_iface_init( NAIDuplicableInterface *iface );
static void iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source );
static gboolean iduplicable_copy_iter( GObjectClass *class, const NAObject *target, NAObject *source );
@@ -74,8 +76,6 @@ static gboolean iduplicable_are_equal_iter( GObjectClass *class, const NAO
static gboolean iduplicable_is_valid( const NAIDuplicable *object );
static gboolean iduplicable_is_valid_iter( GObjectClass *class, const NAObject *a, HierarchyIter *str );
-static void object_dump( const NAObject *object );
-
static gboolean dump_class_hierarchy_iter( GObjectClass *class, const NAObject *object, void *user_data );
static void dump_tree( GList *tree, gint level );
static void iter_on_class_hierarchy( const NAObject *object, HierarchyIterFunc pfn, void *user_data );
@@ -204,6 +204,21 @@ instance_finalize( GObject *object )
}
static void
+object_dump( const NAObject *object )
+{
+ static const char *thisfn = "na_object_do_dump";
+
+ g_debug( "%s: object=%p (%s, ref_count=%d)", thisfn,
+ ( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
+
+ na_iduplicable_dump( NA_IDUPLICABLE( object ));
+
+ if( NA_IS_IDATA_FACTORY( object )){
+ na_data_factory_dump( NA_IDATA_FACTORY( object ));
+ }
+}
+
+static void
iduplicable_iface_init( NAIDuplicableInterface *iface )
{
static const gchar *thisfn = "na_object_iduplicable_iface_init";
@@ -340,21 +355,6 @@ iduplicable_is_valid_iter( GObjectClass *class, const NAObject *a, HierarchyIter
return( stop );
}
-static void
-object_dump( const NAObject *object )
-{
- static const char *thisfn = "na_object_do_dump";
-
- g_debug( "%s: object=%p (%s, ref_count=%d)", thisfn,
- ( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
-
- na_iduplicable_dump( NA_IDUPLICABLE( object ));
-
- if( NA_IS_IDATA_FACTORY( object )){
- na_data_factory_dump( NA_IDATA_FACTORY( object ));
- }
-}
-
/**
* na_object_object_check_status:
* @object: the #NAObject-derived object to be checked.
@@ -612,18 +612,23 @@ NAObject *
na_object_object_ref( NAObject *object )
{
NAObject *ref = NULL;
- GList *childs, *ic;
+ GList *children, *ic;
g_debug( "na_object_object_ref: object=%p (%s, ref_count=%d)",
( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
+
g_return_val_if_fail( NA_IS_OBJECT( object ), NULL );
if( !object->private->dispose_has_run ){
if( NA_IS_OBJECT_ITEM( object )){
- childs = na_object_get_items( object );
- for( ic = childs ; ic ; ic = ic->next ){
+ children = na_object_get_items( object );
+
+ for( ic = children ; ic ; ic = ic->next ){
+
+ g_debug( "na_object_object_ref: child=%p (%s, ref_count=%d)",
+ ( void * ) ic->data, G_OBJECT_TYPE_NAME( ic->data ), G_OBJECT( ic->data )->ref_count );
na_object_ref( ic->data );
}
@@ -639,13 +644,13 @@ na_object_object_ref( NAObject *object )
* na_object_object_unref:
* @object: a #NAObject-derived object.
*
- * Recursively unref the @object and all its childs, decrementing their
+ * Recursively unref the @object and all its children, decrementing their
* reference_count by 1.
*/
void
na_object_object_unref( NAObject *object )
{
- GList *childs, *ic;
+ GList *children, *ic;
g_debug( "na_object_object_unref: object=%p (%s, ref_count=%d)",
( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count );
@@ -656,9 +661,9 @@ na_object_object_unref( NAObject *object )
if( NA_IS_OBJECT_ITEM( object )){
- childs = na_object_get_items( object );
- for( ic = childs ; ic ; ic = ic->next ){
+ children = na_object_get_items( object );
+ for( ic = children ; ic ; ic = ic->next ){
na_object_unref( ic->data );
}
}
diff --git a/src/io-desktop/nadp-writer.c b/src/io-desktop/nadp-writer.c
index 2575491..fcb31bc 100644
--- a/src/io-desktop/nadp-writer.c
+++ b/src/io-desktop/nadp-writer.c
@@ -76,13 +76,13 @@ nadp_iio_provider_is_able_to_write( const NAIIOProvider *provider )
userdir = nadp_xdg_dirs_get_user_data_dir();
if( g_file_test( userdir, G_FILE_TEST_IS_DIR )){
- able_to = na_core_utils_dir_is_writable( userdir );
+ able_to = na_core_utils_dir_is_writable_path( userdir );
} else if( g_mkdir_with_parents( userdir, 0700 )){
g_warning( "%s: %s: %s", thisfn, userdir, g_strerror( errno ));
} else {
- able_to = na_core_utils_dir_is_writable( userdir );
+ able_to = na_core_utils_dir_is_writable_path( userdir );
}
g_free( userdir );
diff --git a/src/io-gconf/nagp-reader.c b/src/io-gconf/nagp-reader.c
index 902338c..42cb237 100644
--- a/src/io-gconf/nagp-reader.c
+++ b/src/io-gconf/nagp-reader.c
@@ -282,6 +282,7 @@ read_item_action_properties_v1( NagpGConfProvider *provider, GSList *entries, NA
static void
read_item_action_profile( NagpGConfProvider *provider, NAObjectAction *action, const gchar *path )
{
+ /*static const gchar *thisfn = "nagp_reader_read_item_action_profile";*/
NAObjectProfile *profile;
gchar *name;
GSList *entries;
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index e5811c6..67d0d4d 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -432,8 +432,10 @@ assist_runtime_init_actions_list( NactAssistantExport *window, GtkAssistant *ass
static void
on_iactions_list_selection_changed( NactIActionsList *instance, GSList *selected_items )
{
- /*static const gchar *thisfn = "nact_assistant_export_on_actions_list_selection_changed";
- g_debug( "%s: selection=%p, user_data=%p", thisfn, selection, user_data );*/
+ static const gchar *thisfn = "nact_assistant_export_on_actions_list_selection_changed";
+
+ g_debug( "%s: selection=%p, selected_items=%p (count=%d)",
+ thisfn, ( void * ) instance, ( void * ) selected_items, g_slist_length( selected_items ));
GtkAssistant *assistant;
gint pos;
@@ -536,7 +538,7 @@ on_folder_selection_changed( GtkFileChooser *chooser, gpointer user_data )
uri = gtk_file_chooser_get_uri( chooser );
g_debug( "%s: uri=%s", thisfn, uri );
- enabled = ( uri && strlen( uri ) && na_core_utils_dir_is_writable( uri ));
+ enabled = ( uri && strlen( uri ) && na_core_utils_dir_is_writable_uri( uri ));
if( enabled ){
g_free( assist->private->uri );
diff --git a/src/nact/nact-iactions-list-bis.c b/src/nact/nact-iactions-list-bis.c
index 8ef39ba..c0e7d71 100644
--- a/src/nact/nact-iactions-list-bis.c
+++ b/src/nact/nact-iactions-list-bis.c
@@ -366,7 +366,7 @@ nact_iactions_list_bis_get_selected_items( NactIActionsList *instance )
path = ( GtkTreePath * ) it->data;
gtk_tree_model_get_iter( model, &iter, path );
gtk_tree_model_get( model, &iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
- /*g_debug( "nact_iactions_list_get_selected_items: object=%p", ( void * ) object );*/
+ g_debug( "nact_iactions_list_get_selected_items: object=%p", ( void * ) object );
items = g_list_prepend( items, na_object_ref( object ));
g_object_unref( object );
}
diff --git a/src/nact/nact-main-statusbar.c b/src/nact/nact-main-statusbar.c
index 87e40b2..12f77fa 100644
--- a/src/nact/nact-main-statusbar.c
+++ b/src/nact/nact-main-statusbar.c
@@ -207,7 +207,7 @@ nact_main_statusbar_set_locked( NactMainWindow *window, gboolean readonly, gint
gtk_image_set_from_file( image, LOCKED_IMAGE );
set_pixbuf = FALSE;
g_free( tooltip );
- tooltip = na_io_provider_get_tooltip( reason );
+ tooltip = na_io_provider_get_readonly_tooltip( reason );
}
gtk_widget_set_tooltip_text( GTK_WIDGET( image ), tooltip );
diff --git a/src/nact/nact-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c
index 6b793c7..db2e128 100644
--- a/src/nact/nact-tree-model-dnd.c
+++ b/src/nact/nact-tree-model-dnd.c
@@ -298,7 +298,7 @@ nact_tree_model_dnd_imulti_drag_source_drag_data_get( EggTreeMultiDragSource *dr
folder = get_xds_atom_value( context );
dest_folder = g_path_get_dirname( folder );
g_free( folder );
- is_writable = na_core_utils_dir_is_writable( dest_folder );
+ is_writable = na_core_utils_dir_is_writable_path( dest_folder );
gtk_selection_data_set( selection_data, selection_data->target, 8, ( guchar * )( is_writable ? "S" : "F" ), 1 );
if( is_writable ){
nact_clipboard_dnd_set( model->private->clipboard, info, rows, dest_folder, TRUE );
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 767ac99..20a3b14 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -603,7 +603,7 @@ nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions)
na_object_check_status( duplicate );
}
fill_tree_store( ts_model, model->private->treeview, duplicate, only_actions, NULL );
- na_object_unref( duplicate );
+ g_object_unref( duplicate );
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]