[nautilus-actions] Make the dump more pretty
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Make the dump more pretty
- Date: Fri, 26 Feb 2010 00:43:13 +0000 (UTC)
commit 10d8b9160906b138da0f69821405619057fc747d
Author: Pierre Wieser <pwieser trychlos org>
Date: Wed Feb 24 01:42:54 2010 +0100
Make the dump more pretty
ChangeLog | 7 ++++
src/api/na-data-boxed.h | 1 +
src/api/na-gconf-utils.h | 1 +
src/core/na-data-boxed.c | 75 +++++++++++++++++++++++++++++++++++++++++-
src/core/na-factory-object.c | 21 +++++++++++-
src/core/na-gconf-utils.c | 28 +++++++++++++++
6 files changed, 131 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ce456d0..437e404 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2009-02-24 Pierre Wieser <pwieser trychlos org>
+ * src/api/na-data-boxed.h:
+ * src/api/na-gconf-utils.h:
+ * src/core/na-data-boxed.c:
+ * src/core/na-factory-object.c:
+ * src/core/na-gconf-utils.c:
+ Make the dump more pretty.
+
* exports/action-5c4fa203-b5d0_post_v1.11_type_3.xml:
* exports/config-4c4fa203-b5d0_post_v1.11_type_2.schema:
* exports/config_1af5a47e-96d9_v1.schemas:
diff --git a/src/api/na-data-boxed.h b/src/api/na-data-boxed.h
index 86fe815..0b6b3e5 100644
--- a/src/api/na-data-boxed.h
+++ b/src/api/na-data-boxed.h
@@ -80,6 +80,7 @@ gboolean na_data_boxed_are_equal ( const NADataBoxed *a, const NADataBo
gboolean na_data_boxed_is_valid ( const NADataBoxed *boxed );
void na_data_boxed_dump ( const NADataBoxed *boxed );
+gchar *na_data_boxed_get_as_string ( const NADataBoxed *boxed );
void *na_data_boxed_get_as_void ( const NADataBoxed *boxed );
void na_data_boxed_get_as_value ( const NADataBoxed *boxed, GValue *value );
diff --git a/src/api/na-gconf-utils.h b/src/api/na-gconf-utils.h
index 4d4d816..5d26abf 100644
--- a/src/api/na-gconf-utils.h
+++ b/src/api/na-gconf-utils.h
@@ -64,6 +64,7 @@ gboolean na_gconf_utils_write_string_list( GConfClient *gconf, const gchar *path
gboolean na_gconf_utils_remove_entry ( GConfClient *gconf, const gchar *path, gchar **message );
GSList *na_gconf_utils_slist_from_string( const gchar *string );
+gchar *na_gconf_utils_slist_to_string ( GSList *slist );
G_END_DECLS
diff --git a/src/core/na-data-boxed.c b/src/core/na-data-boxed.c
index 5c666a5..ebbabd8 100644
--- a/src/core/na-data-boxed.c
+++ b/src/core/na-data-boxed.c
@@ -68,6 +68,7 @@ typedef struct {
void ( *dump ) ( const NADataBoxed * );
gboolean ( *are_equal ) ( const NADataBoxed *, const NADataBoxed * );
gboolean ( *is_valid ) ( const NADataBoxed * );
+ gchar * ( *get_as_string ) ( const NADataBoxed * );
void * ( *get_as_void ) ( const NADataBoxed * );
void ( *get_as_value ) ( const NADataBoxed *, GValue *value );
void ( *set_from_boxed )( NADataBoxed *, const NADataBoxed * );
@@ -92,6 +93,7 @@ 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_valid( 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 );
static void string_set_from_boxed( NADataBoxed *boxed, const NADataBoxed *source );
@@ -107,6 +109,7 @@ 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_valid( 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 );
static void slist_set_from_boxed( NADataBoxed *boxed, const NADataBoxed *source );
@@ -119,6 +122,7 @@ 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_valid( 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 );
static void bool_set_from_boxed( NADataBoxed *boxed, const NADataBoxed *source );
@@ -131,6 +135,7 @@ 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_valid( 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 );
static void pointer_set_from_boxed( NADataBoxed *boxed, const NADataBoxed *source );
@@ -143,6 +148,7 @@ 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_valid( 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 );
static void uint_set_from_boxed( NADataBoxed *boxed, const NADataBoxed *source );
@@ -157,6 +163,7 @@ static DataBoxedFn st_data_boxed_fn[] = {
string_dump,
string_are_equal,
string_is_valid,
+ string_get_as_string,
string_get_as_void,
string_get_as_value,
string_set_from_boxed,
@@ -170,6 +177,7 @@ static DataBoxedFn st_data_boxed_fn[] = {
string_dump,
locale_are_equal,
locale_is_valid,
+ string_get_as_string,
string_get_as_void,
string_get_as_value,
string_set_from_boxed,
@@ -183,6 +191,7 @@ static DataBoxedFn st_data_boxed_fn[] = {
slist_dump,
slist_are_equal,
slist_is_valid,
+ slist_get_as_string,
slist_get_as_void,
slist_get_as_value,
slist_set_from_boxed,
@@ -196,6 +205,7 @@ static DataBoxedFn st_data_boxed_fn[] = {
bool_dump,
bool_are_equal,
bool_is_valid,
+ bool_get_as_string,
bool_get_as_void,
bool_get_as_value,
bool_set_from_boxed,
@@ -209,6 +219,7 @@ static DataBoxedFn st_data_boxed_fn[] = {
pointer_dump,
pointer_are_equal,
pointer_is_valid,
+ pointer_get_as_string,
pointer_get_as_void,
pointer_get_as_value,
pointer_set_from_boxed,
@@ -222,6 +233,7 @@ static DataBoxedFn st_data_boxed_fn[] = {
uint_dump,
uint_are_equal,
uint_is_valid,
+ uint_get_as_string,
uint_get_as_void,
uint_get_as_value,
uint_set_from_boxed,
@@ -229,7 +241,7 @@ static DataBoxedFn st_data_boxed_fn[] = {
uint_set_from_value,
uint_set_from_void
},
- { 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+ { 0 }
};
GType
@@ -524,6 +536,37 @@ na_data_boxed_dump( const NADataBoxed *boxed )
}
/**
+ * na_data_boxed_get_as_string:
+ * @boxed: the #NADataBoxed whose value is to be set.
+ *
+ * Returns: the value of the @boxed, as a newly allocated string which
+ * should be g_free() by the caller.
+ */
+gchar *
+na_data_boxed_get_as_string( const NADataBoxed *boxed )
+{
+ DataBoxedFn *fn;
+ gchar *value;
+
+ g_return_val_if_fail( NA_IS_DATA_BOXED( boxed ), NULL );
+
+ value = NULL;
+
+ if( !boxed->private->dispose_has_run ){
+
+ fn = get_data_boxed_fn( boxed->private->def->type );
+
+ if( fn ){
+ if( fn->get_as_string ){
+ value = ( *fn->get_as_string )( boxed );
+ }
+ }
+ }
+
+ return( value );
+}
+
+/**
* na_data_boxed_get_as_void:
* @boxed: the #NADataBoxed whose value is to be set.
*
@@ -773,6 +816,12 @@ string_is_valid( const NADataBoxed *boxed )
return( boxed->private->u.string && strlen( boxed->private->u.string ) > 0 );
}
+static gchar *
+string_get_as_string( const NADataBoxed *boxed )
+{
+ return( g_strdup( boxed->private->u.string ));
+}
+
static void *
string_get_as_void( const NADataBoxed *boxed )
{
@@ -885,6 +934,12 @@ slist_is_valid( const NADataBoxed *boxed )
return( boxed->private->u.slist && g_slist_length( boxed->private->u.slist ) > 0 );
}
+static gchar *
+slist_get_as_string( const NADataBoxed *boxed )
+{
+ return( na_gconf_utils_slist_to_string( boxed->private->u.slist ));
+}
+
static void *
slist_get_as_void( const NADataBoxed *boxed )
{
@@ -981,6 +1036,12 @@ bool_is_valid( const NADataBoxed *boxed )
return( TRUE );
}
+static gchar *
+bool_get_as_string( const NADataBoxed *boxed )
+{
+ return( g_strdup_printf( "%s", boxed->private->u.boolean ? "True":"False" ));
+}
+
static void *
bool_get_as_void( const NADataBoxed *boxed )
{
@@ -1055,6 +1116,12 @@ pointer_is_valid( const NADataBoxed *boxed )
return( boxed->private->u.pointer != NULL );
}
+static gchar *
+pointer_get_as_string( const NADataBoxed *boxed )
+{
+ return( g_strdup_printf( "%p", boxed->private->u.pointer ));
+}
+
static void *
pointer_get_as_void( const NADataBoxed *boxed )
{
@@ -1128,6 +1195,12 @@ uint_is_valid( const NADataBoxed *boxed )
return( boxed->private->u.uint > 0 );
}
+static gchar *
+uint_get_as_string( const NADataBoxed *boxed )
+{
+ return( g_strdup_printf( "%u", boxed->private->u.uint ));
+}
+
static void *
uint_get_as_void( const NADataBoxed *boxed )
{
diff --git a/src/core/na-factory-object.c b/src/core/na-factory-object.c
index 60a45af..0b886a9 100644
--- a/src/core/na-factory-object.c
+++ b/src/core/na-factory-object.c
@@ -464,13 +464,32 @@ na_factory_object_is_valid( const NAIFactoryObject *object )
void
na_factory_object_dump( const NAIFactoryObject *object )
{
+ static const gchar *thisfn = "na_factory_object_dump";
+ static const gchar *prefix = "na-factory-data-";
GList *list, *it;
+ guint length;
+ guint l_prefix;
+ length = 0;
+ l_prefix = strlen( prefix );
list = g_object_get_data( G_OBJECT( object ), NA_IFACTORY_OBJECT_PROP_DATA );
for( it = list ; it ; it = it->next ){
+ NADataBoxed *boxed = NA_DATA_BOXED( it->data );
+ NADataDef *def = na_data_boxed_get_data_def( boxed );
+ length = MAX( length, strlen( def->name ));
+ }
+
+ length -= l_prefix;
+ length += 1;
- na_data_boxed_dump( NA_DATA_BOXED( it->data ));
+ for( it = list ; it ; it = it->next ){
+ /*na_data_boxed_dump( NA_DATA_BOXED( it->data ));*/
+ NADataBoxed *boxed = NA_DATA_BOXED( it->data );
+ NADataDef *def = na_data_boxed_get_data_def( boxed );
+ gchar *value = na_data_boxed_get_as_string( boxed );
+ g_debug( "%s: %*s=%s", thisfn, length, def->name+l_prefix, value );
+ g_free( value );
}
}
diff --git a/src/core/na-gconf-utils.c b/src/core/na-gconf-utils.c
index bb654ae..f42e551 100644
--- a/src/core/na-gconf-utils.c
+++ b/src/core/na-gconf-utils.c
@@ -677,6 +677,34 @@ na_gconf_utils_slist_from_string( const gchar *value )
return( slist );
}
+/**
+ * na_gconf_utils_slist_to_string:
+ * @slist: a #GSList to be displayed.
+ *
+ * Returns: the content of @slist, with the GConf format, as a newly
+ * allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_gconf_utils_slist_to_string( GSList *slist )
+{
+ GSList *is;
+ GString *str = g_string_new( "[" );
+ gboolean first;
+
+ first = TRUE;
+ for( is = slist ; is ; is = is->next ){
+ if( !first ){
+ str = g_string_append( str, "," );
+ }
+ str = g_string_append( str, ( const gchar * ) is->data );
+ first = FALSE;
+ }
+
+ str = g_string_append( str, "]" );
+
+ return( g_string_free( str, FALSE ));
+}
+
static gboolean
sync_gconf( GConfClient *gconf, gchar **message )
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]