[nautilus-actions: 1/19] Create pivot data structure NactPivotValue



commit 8838b74f9a1b5f02128269c96a99f58e31261e61
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jun 5 15:36:06 2009 +0200

    Create pivot data structure NactPivotValue
---
 ChangeLog                      |   15 ++++
 src/common/nact-gconf.c        |  161 ++++++++++++++++++++++++++--------------
 src/common/nact-iio-provider.c |    2 +-
 src/common/nact-pivot.c        |   29 +++++++
 src/common/nact-pivot.h        |   24 ++++++-
 5 files changed, 172 insertions(+), 59 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 297e859..a48b756 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2009-06-05 Pierre Wieser <pwieser trychlos org>
 
+	Create pivot data structure NactPivotValue
+
+	* src/common/nact-gconf.c (value_to_pivot):
+	New function.
+
+	* src/common/nact-iio-provider.c
+	(nact_iio_provider_load_profile_properties):
+	Fix thisfn typo.
+
+	* src/common/nact-pivot.c
+	* src/common/nact-pivot.h (nact_pivot_free_pivot_value):
+	New function.
+
+2009-06-04 Pierre Wieser <pwieser trychlos org>
+
 	Create a whole new object model, and defines some communication
 	interfaces.
 
diff --git a/src/common/nact-gconf.c b/src/common/nact-gconf.c
index b66b5f8..db81b2f 100644
--- a/src/common/nact-gconf.c
+++ b/src/common/nact-gconf.c
@@ -68,31 +68,32 @@ enum {
 
 static GObjectClass *st_parent_class = NULL;
 
-static GType        register_type( void );
-static void         class_init( NactGConfClass *klass );
-static void         iio_provider_iface_init( NactIIOProviderInterface *iface );
-static void         instance_init( GTypeInstance *instance, gpointer klass );
-static void         instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
-static void         instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
-static void         instance_dispose( GObject *object );
-static void         instance_finalize( GObject *object );
-static guint        install_gconf_watch( NactGConf *gconf );
-static void         remove_gconf_watch( NactGConf *gconf );
-
-static void         actions_changed_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data );
-
-static void         free_keys_values( GSList *keys );
-static GSList      *load_keys_values( const NactGConf *gconf, const gchar *path );
-static GSList      *load_subdirs( const NactGConf *gconf, const gchar *path );
-static gchar       *path_to_key( const gchar *path );
-static NactGConfIO *path_to_struct( const gchar *path );
-static void         set_item_properties( NactObject *object, GSList *properties );
-
-static GSList      *do_load_actions( NactIIOProvider *provider );
-static void         do_load_action_properties( NactIIOClient *client );
-static GSList      *do_load_profiles( NactIIOClient *client );
-static void         do_load_profile_properties( NactObject *profile );
-static void         do_release_data( NactIIOClient *client );
+static GType          register_type( void );
+static void           class_init( NactGConfClass *klass );
+static void           iio_provider_iface_init( NactIIOProviderInterface *iface );
+static void           instance_init( GTypeInstance *instance, gpointer klass );
+static void           instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
+static void           instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
+static void           instance_dispose( GObject *object );
+static void           instance_finalize( GObject *object );
+static guint          install_gconf_watch( NactGConf *gconf );
+static void           remove_gconf_watch( NactGConf *gconf );
+
+static void           actions_changed_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data );
+
+static void           free_keys_values( GSList *keys );
+static GSList        *load_keys_values( const NactGConf *gconf, const gchar *path );
+static GSList        *load_subdirs( const NactGConf *gconf, const gchar *path );
+static gchar         *path_to_key( const gchar *path );
+static NactGConfIO   *path_to_struct( const gchar *path );
+static void           set_item_properties( NactObject *object, GSList *properties );
+static NactPivotValue *value_to_pivot( const GConfValue *value );
+
+static GSList        *do_load_actions( NactIIOProvider *provider );
+static   void         do_load_action_properties( NactIIOClient *client );
+static GSList        *do_load_profiles( NactIIOClient *client );
+static void           do_load_profile_properties( NactObject *profile );
+static void           do_release_data( NactIIOClient *client );
 
 NactGConf *
 nact_gconf_new( const GObject *pivot )
@@ -279,7 +280,7 @@ install_gconf_watch( NactGConf *gconf )
 			gconf->private->gconf,
 			NACT_GCONF_CONFIG_PATH,
 			( GConfClientNotifyFunc ) actions_changed_cb,
-			gconf,
+			gconf->private->pivot,
 			NULL,
 			&error
 		);
@@ -328,6 +329,8 @@ remove_gconf_watch( NactGConf *gconf )
  * if the modification is made elsewhere (an action is imported as a
  * xml file in gconf, of gconf is directly edited), we'd have to rely
  * on the key of the value
+ *
+ * user_data is a ptr to NactPivot object.
  */
 static void
 actions_changed_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data )
@@ -335,13 +338,24 @@ actions_changed_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, gpoin
 	static const gchar *thisfn = "actions_changed_cb";
 	g_debug( "%s: client=%p, cnxnid=%u, entry=%p, user_data=%p", thisfn, client, cnxn_id, entry, user_data );
 
+	g_assert( NACT_IS_PIVOT( user_data ));
+
+	const GConfValue* value = gconf_entry_get_value( entry );
+	const gchar *path = gconf_entry_get_key( entry );
+	const gchar *subpath = path + strlen( NACT_GCONF_CONFIG_PATH ) + 1;
+
+	gchar **split = g_strsplit( subpath, "/", 2 );
+	gchar *key = g_strdup( split[0] );
+	g_strfreev( split );
+
+	/*nact_pivot_on_action_changed( NACT_PIVOT( user_data ), key, parm, value );*/
+	g_free( key );
+
 	/*NactGConf *gconf = NACT_GCONF( user_data );*/
 
 	/* The Key value format is XXX:YYYY-YYYY-... where XXX is an number incremented to make key
 	 * effectively changed each time and YYYY-YYYY-... is the modified uuid */
-	const GConfValue* value = gconf_entry_get_value (entry);
 	const gchar* notify_value = gconf_value_get_string (value);
-	const gchar *key = gconf_entry_get_key( entry );
 	g_debug( "%s: notify_value='%s', key='%s'", thisfn, notify_value, key );
 	/*const gchar* uuid = notify_value + 4;*/
 
@@ -485,44 +499,77 @@ set_item_properties( NactObject *object, GSList *properties )
 {
 	g_assert( NACT_IS_OBJECT( object ));
 
-	GSList *item, *listvalues, *iv, *strings;
-
+	GSList *item;
 	for( item = properties ; item != NULL ; item = item->next ){
 
 		GConfEntry *entry = ( GConfEntry * ) item->data;
-
 		const char *key = gconf_entry_get_key( entry );
-		GConfValue *value = gconf_entry_get_value( entry );
-
-		switch( value->type ){
-
-			case GCONF_VALUE_STRING:
-				g_object_set( G_OBJECT( object ), key, gconf_value_get_string( value ), NULL );
-				break;
-
-			case GCONF_VALUE_BOOL:
-				g_object_set( G_OBJECT( object ), key, gconf_value_get_bool( value ), NULL );
-				break;
-
-			case GCONF_VALUE_LIST:
-				listvalues = gconf_value_get_list( value );
-				strings = NULL;
-				for( iv = listvalues ; iv != NULL ; iv = iv->next ){
-					strings = g_slist_prepend( strings,
-							( gpointer ) gconf_value_get_string(( GConfValue * ) iv->data ));
-				}
-				g_object_set( G_OBJECT( object ), key, strings, NULL );
-				/*g_slist_free( strings );*/
-				break;
-
-			default:
-				g_assert_not_reached();
-				break;
+		NactPivotValue *value = value_to_pivot( gconf_entry_get_value( entry ));
+
+		if( value ){
+			switch( value->type ){
+
+				case NACT_PIVOT_STR:
+				case NACT_PIVOT_BOOL:
+				case NACT_PIVOT_STRLIST:
+					g_object_set( G_OBJECT( object ), key, value->data, NULL );
+					break;
+
+				default:
+					g_assert_not_reached();
+					break;
+			}
+			nact_pivot_free_pivot_value( value );
 		}
 	}
 }
 
 /*
+ * convert a GConfValue to our internal data type
+ */
+static NactPivotValue *
+value_to_pivot( const GConfValue *value )
+{
+	NactPivotValue *pivot_value = NULL;
+	GSList *listvalues, *iv, *strings;
+
+	switch( value->type ){
+
+		case GCONF_VALUE_STRING:
+			pivot_value = g_new0( NactPivotValue, 1 );
+			pivot_value->type = NACT_PIVOT_STR;
+			pivot_value->data = ( gpointer ) g_strdup( gconf_value_get_string( value ));
+			break;
+
+		case GCONF_VALUE_BOOL:
+			pivot_value = g_new0( NactPivotValue, 1 );
+			pivot_value->type = NACT_PIVOT_BOOL;
+			pivot_value->data = ( gpointer ) gconf_value_get_bool( value );
+			break;
+
+		case GCONF_VALUE_LIST:
+			listvalues = gconf_value_get_list( value );
+			strings = NULL;
+			for( iv = listvalues ; iv != NULL ; iv = iv->next ){
+				strings = g_slist_prepend( strings,
+						( gpointer ) gconf_value_get_string(( GConfValue * ) iv->data ));
+			}
+
+			pivot_value = g_new0( NactPivotValue, 1 );
+			pivot_value->type = NACT_PIVOT_STRLIST;
+			pivot_value->data = ( gpointer ) nactuti_duplicate_string_list( strings );
+			/*nactuti_free_string_list( strings );*/
+			break;
+
+		default:
+			g_assert_not_reached();
+			break;
+	}
+
+	return( pivot_value );
+}
+
+/*
  * NactIIOProviderInterface implementation
  * load the list of actions and returns them as a GSList
  */
diff --git a/src/common/nact-iio-provider.c b/src/common/nact-iio-provider.c
index 1407b9a..1fd565f 100644
--- a/src/common/nact-iio-provider.c
+++ b/src/common/nact-iio-provider.c
@@ -205,7 +205,7 @@ nact_iio_provider_load_profiles( NactIIOClient *client )
 void
 nact_iio_provider_load_profile_properties( NactObject *profile )
 {
-	static const gchar *thisfn = "nact_iio_provider_load_action_properties";
+	static const gchar *thisfn = "nact_iio_provider_load_profile_properties";
 	g_debug( "%s", thisfn );
 
 	g_assert( NACT_IS_ACTION_PROFILE( profile ));
diff --git a/src/common/nact-pivot.c b/src/common/nact-pivot.c
index 14ffe43..46fe846 100644
--- a/src/common/nact-pivot.c
+++ b/src/common/nact-pivot.c
@@ -35,6 +35,7 @@
 #include "nact-gconf.h"
 #include "nact-pivot.h"
 #include "nact-iio-provider.h"
+#include "uti-lists.h"
 
 struct NactPivotPrivate {
 	gboolean  dispose_has_run;
@@ -212,3 +213,31 @@ nact_pivot_get_providers( const NactPivot *pivot, GType type )
 
 	return( list );
 }
+
+/**
+ * Free a NactPivotValue structure and its content.
+ */
+void
+nact_pivot_free_pivot_value( NactPivotValue *value )
+{
+	if( value ){
+		switch( value->type ){
+
+			case NACT_PIVOT_STR:
+				g_free(( gchar * ) value->data );
+				break;
+
+			case NACT_PIVOT_BOOL:
+				break;
+
+			case NACT_PIVOT_STRLIST:
+				nactuti_free_string_list(( GSList * ) value->data );
+				break;
+
+			default:
+				g_assert_not_reached();
+				break;
+		}
+		g_free( value );
+	}
+}
diff --git a/src/common/nact-pivot.h b/src/common/nact-pivot.h
index 1fa0346..c0871af 100644
--- a/src/common/nact-pivot.h
+++ b/src/common/nact-pivot.h
@@ -44,6 +44,24 @@
 
 G_BEGIN_DECLS
 
+/*
+ * We would want have a sort of GConfValue, but which is not named with
+ * GConf, in order to propose this same structure to other storage
+ * subsystems.
+ * We so define this, with only the data types we need.
+ */
+enum {
+	NACT_PIVOT_STR = 1,
+	NACT_PIVOT_BOOL,
+	NACT_PIVOT_STRLIST
+};
+
+typedef struct {
+	guint    type;
+	gpointer data;
+}
+	NactPivotValue;
+
 #define NACT_PIVOT_TYPE					( nact_pivot_get_type())
 #define NACT_PIVOT( object )			( G_TYPE_CHECK_INSTANCE_CAST( object, NACT_PIVOT_TYPE, NactPivot ))
 #define NACT_PIVOT_CLASS( klass )		( G_TYPE_CHECK_CLASS_CAST( klass, NACT_PIVOT_TYPE, NactPivotClass ))
@@ -71,7 +89,11 @@ GType      nact_pivot_get_type( void );
 
 NactPivot *nact_pivot_new( void );
 
-GSList    *nact_pivot_get_providers( GType type );
+GSList    *nact_pivot_get_providers( const NactPivot *pivot, GType type );
+
+void       nact_pivot_on_action_changed( NactPivot *pivot, const gchar *uuid, const gchar *parm, NactPivotValue *value );
+
+void       nact_pivot_free_pivot_value( NactPivotValue *value );
 
 G_END_DECLS
 



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