[nautilus-actions] Read profiles from .desktop files



commit 74436b277c41635ab2232d9127b5c41de7cbae2b
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Mar 26 18:46:10 2010 +0100

    Read profiles from .desktop files

 ChangeLog                              |   18 +++
 src/io-desktop/nadp-desktop-file.c     |   80 ++++++++++-
 src/io-desktop/nadp-desktop-file.h     |    3 +-
 src/io-desktop/nadp-desktop-provider.c |  185 ++----------------------
 src/io-desktop/nadp-desktop-provider.h |    8 -
 src/io-desktop/nadp-keys.h             |    4 +-
 src/io-desktop/nadp-reader.c           |  243 ++++++++++++++++++++++++++++++++
 src/io-desktop/nadp-reader.h           |    6 +-
 src/io-desktop/nadp-writer.c           |   84 ++++++------
 9 files changed, 403 insertions(+), 228 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 620ba31..0de3cac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -133,6 +133,24 @@
 
 2009-03-26 Pierre Wieser <pwieser trychlos org>
 
+	* src/io-desktop/nadp-desktop-file.c:
+	* src/io-desktop/nadp-desktop-file.h
+	(check_key_file): Check that we don't have a 'Hidden=true' key.
+	(nadp_desktop_file_get_profiles): New function.
+
+	* src/io-desktop/nadp-desktop-provider.c:
+	* src/io-desktop/nadp-desktop-provider.h:
+	Move reader functions and structure to nadp-reader.c.
+
+	* src/io-desktop/nadp-keys.h:
+	Relabel type of items in .desktop file (cf. draft 0.9).
+
+	* src/io-desktop/nadp-reader.c:
+	* src/io-desktop/nadp-reader.h:
+	Read profiles present in the .desktop file.
+
+2009-03-26 Pierre Wieser <pwieser trychlos org>
+
 	Releasing 2.30.0.
 
 2009-03-25 Pierre Wieser <pwieser trychlos org>
diff --git a/src/io-desktop/nadp-desktop-file.c b/src/io-desktop/nadp-desktop-file.c
index 4823b3f..38dfff9 100644
--- a/src/io-desktop/nadp-desktop-file.c
+++ b/src/io-desktop/nadp-desktop-file.c
@@ -313,16 +313,44 @@ check_key_file( NadpDesktopFile *ndf )
 	static const gchar *thisfn = "nadp_desktop_file_check_key_file";
 	gboolean ret;
 	gchar *start_group;
+	gboolean has_key;
+	gboolean hidden;
+	GError *error;
 
-	ret = TRUE;
+	ret = FALSE;
+	error = NULL;
 
 	/* start group must be 'Desktop Entry' */
 	start_group = g_key_file_get_start_group( ndf->private->key_file );
 	if( strcmp( start_group, NADP_GROUP_DESKTOP )){
-
 		g_warning( "%s: %s: invalid start group, found %s, waited for %s",
 				thisfn, ndf->private->path, start_group, NADP_GROUP_DESKTOP );
 		ret = FALSE;
+
+	/* must not have Hidden=true value */
+	} else {
+		has_key = g_key_file_has_key( ndf->private->key_file, start_group, NADP_KEY_HIDDEN, &error );
+		if( error ){
+			g_warning( "%s: %s: %s", thisfn, ndf->private->path, error->message );
+			ret = FALSE;
+
+		} else if( has_key ){
+			hidden = g_key_file_get_boolean( ndf->private->key_file, start_group, NADP_KEY_HIDDEN, &error );
+			if( error ){
+				g_warning( "%s: %s: %s", thisfn, ndf->private->path, error->message );
+				ret = FALSE;
+
+			} else if( hidden ){
+				g_warning( "%s: %s: Hidden=true", thisfn, ndf->private->path );
+				ret = FALSE;
+
+			} else {
+				ret = TRUE;
+			}
+
+		} else {
+			ret = TRUE;
+		}
 	}
 
 	g_free( start_group );
@@ -397,6 +425,54 @@ nadp_desktop_file_get_id( const NadpDesktopFile *ndf )
 }
 
 /**
+ * nadp_desktop_file_get_profiles:
+ * @ndf: the #NadpDesktopFile instance.
+ *
+ * Returns: the list of profiles in the file, as a newly allocated GSList
+ * which must be na_core_utils_slist_free() by the caller.
+ *
+ * Silently ignore unknown groups.
+ */
+GSList *
+nadp_desktop_file_get_profiles( const NadpDesktopFile *ndf )
+{
+	GSList *list;
+	gchar **groups, **ig;
+	gchar *profile_pfx;
+	gchar *profile_id;
+	guint pfx_len;
+
+	g_return_val_if_fail( NADP_IS_DESKTOP_FILE( ndf ), NULL );
+
+	list = NULL;
+
+	if( !ndf->private->dispose_has_run ){
+
+		groups = g_key_file_get_groups( ndf->private->key_file, NULL );
+		if( groups ){
+			ig = groups;
+			profile_pfx = g_strdup_printf( "%s ", NADP_GROUP_PROFILE );
+			pfx_len = strlen( profile_pfx );
+
+			while( *ig ){
+
+				if( !strncmp( *ig, profile_pfx, pfx_len )){
+					profile_id = g_strdup( *ig );
+					list = g_slist_prepend( list, profile_id+pfx_len );
+				}
+
+				ig++;
+			}
+
+			g_strfreev( groups );
+			g_free( profile_pfx );
+		}
+	}
+
+	return( list );
+}
+
+/**
  * nadp_desktop_file_get_boolean:
  * @ndf: this #NadpDesktopFile instance.
  * @group: the searched group.
diff --git a/src/io-desktop/nadp-desktop-file.h b/src/io-desktop/nadp-desktop-file.h
index 04b08e5..611514e 100644
--- a/src/io-desktop/nadp-desktop-file.h
+++ b/src/io-desktop/nadp-desktop-file.h
@@ -81,8 +81,9 @@ gchar           *nadp_desktop_file_get_key_file_path( const NadpDesktopFile *ndf
 gboolean         nadp_desktop_file_write            ( NadpDesktopFile *ndf );
 
 gchar           *nadp_desktop_file_get_file_type    ( const NadpDesktopFile *ndf );
-
 gchar           *nadp_desktop_file_get_id           ( const NadpDesktopFile *ndf );
+GSList          *nadp_desktop_file_get_profiles     ( const NadpDesktopFile *ndf );
+
 gboolean         nadp_desktop_file_get_boolean      ( const NadpDesktopFile *ndf, const gchar *group, const gchar *key, gboolean *key_found, gboolean default_value );
 gchar           *nadp_desktop_file_get_locale_string( const NadpDesktopFile *ndf, const gchar *group, const gchar *key, gboolean *key_found, const gchar *default_value );
 gchar           *nadp_desktop_file_get_string       ( const NadpDesktopFile *ndf, const gchar *group, const gchar *key, gboolean *key_found, const gchar *default_value );
diff --git a/src/io-desktop/nadp-desktop-provider.c b/src/io-desktop/nadp-desktop-provider.c
index bc5ba44..68c30bc 100644
--- a/src/io-desktop/nadp-desktop-provider.c
+++ b/src/io-desktop/nadp-desktop-provider.c
@@ -33,13 +33,11 @@
 #endif
 
 #include <glib/gi18n.h>
-#include <stdlib.h>
 #include <string.h>
 
 #include <api/na-core-utils.h>
 #include <api/na-iio-provider.h>
 #include <api/na-ifactory-provider.h>
-#include <api/na-data-types.h>
 
 #include "nadp-desktop-provider.h"
 #include "nadp-keys.h"
@@ -55,21 +53,18 @@ struct NadpDesktopProviderClassPrivate {
 static GType         st_module_type = 0;
 static GObjectClass *st_parent_class = NULL;
 
-static void         class_init( NadpDesktopProviderClass *klass );
-static void         instance_init( GTypeInstance *instance, gpointer klass );
-static void         instance_dispose( GObject *object );
-static void         instance_finalize( GObject *object );
+static void   class_init( NadpDesktopProviderClass *klass );
+static void   instance_init( GTypeInstance *instance, gpointer klass );
+static void   instance_dispose( GObject *object );
+static void   instance_finalize( GObject *object );
 
-static void         iio_provider_iface_init( NAIIOProviderInterface *iface );
-static gchar       *iio_provider_get_id( const NAIIOProvider *provider );
-static gchar       *iio_provider_get_name( const NAIIOProvider *provider );
-static guint        iio_provider_get_version( const NAIIOProvider *provider );
+static void   iio_provider_iface_init( NAIIOProviderInterface *iface );
+static gchar *iio_provider_get_id( const NAIIOProvider *provider );
+static gchar *iio_provider_get_name( const NAIIOProvider *provider );
+static guint  iio_provider_get_version( const NAIIOProvider *provider );
 
-static void         ifactory_provider_iface_init( NAIFactoryProviderInterface *iface );
-static guint        ifactory_provider_get_version( const NAIFactoryProvider *reader );
-static void         ifactory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages );
-static NADataBoxed *ifactory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, const NADataDef *iddef, GSList **messages );
-static void         ifactory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages );
+static void   ifactory_provider_iface_init( NAIFactoryProviderInterface *iface );
+static guint  ifactory_provider_get_version( const NAIFactoryProvider *reader );
 
 GType
 nadp_desktop_provider_get_type( void )
@@ -228,9 +223,9 @@ ifactory_provider_iface_init( NAIFactoryProviderInterface *iface )
 	g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
 
 	iface->get_version = ifactory_provider_get_version;
-	iface->read_start = ifactory_provider_read_start;
-	iface->read_data = ifactory_provider_read_data;
-	iface->read_done = ifactory_provider_read_done;
+	iface->read_start = nadp_reader_ifactory_provider_read_start;
+	iface->read_data = nadp_reader_ifactory_provider_read_data;
+	iface->read_done = nadp_reader_ifactory_provider_read_done;
 	iface->write_start = NULL;
 	iface->write_data = NULL;
 	iface->write_done = NULL;
@@ -241,157 +236,3 @@ ifactory_provider_get_version( const NAIFactoryProvider *reader )
 {
 	return( 1 );
 }
-
-/*
- * called before starting with reading an object
- */
-static void
-ifactory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages )
-{
-	static const gchar *thisfn = "nadp_desktop_provider_ifactory_provider_read_start";
-
-	g_debug( "%s: reader=%p (%s), reader_data=%p, serializable=%p (%s), messages=%p",
-			thisfn,
-			( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
-			( void * ) reader_data,
-			( void * ) serializable, G_OBJECT_TYPE_NAME( serializable ),
-			( void * ) messages );
-
-	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
-	g_return_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ));
-	g_return_if_fail( NA_IS_IFACTORY_OBJECT( serializable ));
-
-	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){
-
-	}
-}
-
-/*
- * reading any data from a desktop file requires:
- * - a NadpDesktopFile object which has been initialized with the .desktop file
- *   -> has been attached to the NAObjectItem in get_item() above
- * - the data type (+ reading default value)
- * - group and key names
- *
- * Returns: NULL if the key has not been found
- * letting the caller deal with default values
- */
-static NADataBoxed *
-ifactory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *object, const NADataDef *def, GSList **messages )
-{
-	static const gchar *thisfn = "nadp_desktop_provider_ifactory_provider_read_value";
-	NADataBoxed *boxed;
-	gboolean found;
-	NadpReaderData *nrd;
-	gchar *group, *key;
-	gchar *msg;
-	gchar *str_value;
-	gboolean bool_value;
-	GSList *slist_value;
-	guint uint_value;
-
-	/*g_debug( "%s: reader=%p (%s), reader_data=%p, def=%p, messages=%p",
-			thisfn,
-			( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
-			( void * ) reader_data,
-			( void * ) def,
-			( void * ) messages );*/
-
-	g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( reader ), NULL );
-	g_return_val_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ), NULL );
-	g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
-
-	boxed = NULL;
-
-	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){
-
-		nrd = ( NadpReaderData * ) reader_data;
-		g_return_val_if_fail( NADP_IS_DESKTOP_FILE( nrd->ndf ), NULL );
-
-		if( nadp_keys_get_group_and_key( def, &group, &key )){
-
-			switch( def->type ){
-
-				case NAFD_TYPE_LOCALE_STRING:
-					str_value = nadp_desktop_file_get_locale_string( nrd->ndf, group, key, &found, def->default_value );
-					if( str_value && found ){
-						boxed = na_data_boxed_new( def );
-						na_data_boxed_set_from_void( boxed, str_value );
-					}
-					g_free( str_value );
-					break;
-
-				case NAFD_TYPE_STRING:
-					str_value = nadp_desktop_file_get_string( nrd->ndf, group, key, &found, def->default_value );
-					if( str_value && found ){
-						boxed = na_data_boxed_new( def );
-						na_data_boxed_set_from_void( boxed, str_value );
-					}
-					g_free( str_value );
-					break;
-
-				case NAFD_TYPE_BOOLEAN:
-					bool_value = nadp_desktop_file_get_boolean( nrd->ndf, group, key, &found, na_core_utils_boolean_from_string( def->default_value ));
-					if( found ){
-						boxed = na_data_boxed_new( def );
-						na_data_boxed_set_from_void( boxed, GUINT_TO_POINTER( bool_value ));
-					}
-					break;
-
-				case NAFD_TYPE_STRING_LIST:
-					slist_value = nadp_desktop_file_get_string_list( nrd->ndf, group, key, &found, def->default_value );
-					if( slist_value && found ){
-						boxed = na_data_boxed_new( def );
-						na_data_boxed_set_from_void( boxed, slist_value );
-					}
-					na_core_utils_slist_free( slist_value );
-					break;
-
-				case NAFD_TYPE_UINT:
-					uint_value = nadp_desktop_file_get_uint( nrd->ndf, group, key, &found, atoi( def->default_value ));
-					if( found ){
-						boxed = na_data_boxed_new( def );
-						na_data_boxed_set_from_void( boxed, GUINT_TO_POINTER( uint_value ));
-					}
-					break;
-
-				default:
-					msg = g_strdup_printf( "%s: %d: invalid data type.", thisfn, def->type );
-					g_warning( "%s", msg );
-					*messages = g_slist_append( *messages, msg );
-			}
-
-			/*g_debug( "%s: group=%s, key=%s", thisfn, group, key );*/
-			g_free( key );
-			g_free( group );
-		}
-	}
-
-	return( boxed );
-}
-
-/*
- * called when each NAIFactoryObject object has been readen
- * nothing to do here
- */
-static void
-ifactory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages )
-{
-	static const gchar *thisfn = "nadp_desktop_provider_ifactory_provider_read_done";
-	/*NAObjectProfile *profile;*/
-
-	g_debug( "%s: reader=%p (%s), reader_data=%p, serializable=%p (%s), messages=%p",
-			thisfn,
-			( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
-			( void * ) reader_data,
-			( void * ) serializable, G_OBJECT_TYPE_NAME( serializable ),
-			( void * ) messages );
-
-	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
-	g_return_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ));
-	g_return_if_fail( NA_IS_IFACTORY_OBJECT( serializable ));
-
-	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){
-
-	}
-}
diff --git a/src/io-desktop/nadp-desktop-provider.h b/src/io-desktop/nadp-desktop-provider.h
index b5a2b55..6ba7703 100644
--- a/src/io-desktop/nadp-desktop-provider.h
+++ b/src/io-desktop/nadp-desktop-provider.h
@@ -76,14 +76,6 @@ typedef struct {
 }
 	NadpDesktopProviderClass;
 
-/* the structure passed as reader data to NAIFactoryObject
- */
-typedef struct {
-	NadpDesktopFile *ndf;
-	NAObjectItem    *action;
-}
-	NadpReaderData;
-
 /* this is a ':'-separated list of XDG_DATA_DIRS/subdirs searched for
  * menus or actions .desktop files.
  */
diff --git a/src/io-desktop/nadp-keys.h b/src/io-desktop/nadp-keys.h
index 266a03a..8d4acfe 100644
--- a/src/io-desktop/nadp-keys.h
+++ b/src/io-desktop/nadp-keys.h
@@ -39,8 +39,8 @@ G_BEGIN_DECLS
 #define NADP_GROUP_PROFILE							"X-Action-Profile"
 
 #define NADP_KEY_TYPE								G_KEY_FILE_DESKTOP_KEY_TYPE
-#define NADP_VALUE_TYPE_ACTION						"Action"
-#define NADP_VALUE_TYPE_MENU						"Menu"
+#define NADP_VALUE_TYPE_ACTION						"ExtensionAction"
+#define NADP_VALUE_TYPE_MENU						"ExtensionMenu"
 #define NADP_KEY_NAME								G_KEY_FILE_DESKTOP_KEY_NAME
 #define NADP_KEY_TOOLTIP							"Tooltip"
 #define NADP_KEY_ICON								G_KEY_FILE_DESKTOP_KEY_ICON
diff --git a/src/io-desktop/nadp-reader.c b/src/io-desktop/nadp-reader.c
index 9bba667..cfbe565 100644
--- a/src/io-desktop/nadp-reader.c
+++ b/src/io-desktop/nadp-reader.c
@@ -32,9 +32,11 @@
 #include <config.h>
 #endif
 
+#include <stdlib.h>
 #include <string.h>
 
 #include <api/na-core-utils.h>
+#include <api/na-data-types.h>
 #include <api/na-ifactory-object-data.h>
 #include <api/na-ifactory-provider.h>
 #include <api/na-object-api.h>
@@ -42,6 +44,7 @@
 #include "nadp-desktop-provider.h"
 #include "nadp-keys.h"
 #include "nadp-reader.h"
+#include "nadp-utils.h"
 #include "nadp-xdg-dirs.h"
 
 typedef struct {
@@ -50,6 +53,14 @@ typedef struct {
 }
 	DesktopPath;
 
+/* the structure passed as reader data to NAIFactoryObject
+ */
+typedef struct {
+	NadpDesktopFile *ndf;
+	NAObjectAction  *action;
+}
+	NadpReaderData;
+
 static GList            *get_list_of_desktop_paths( const NadpDesktopProvider *provider, GSList **mesages );
 static void              get_list_of_desktop_files( const NadpDesktopProvider *provider, GList **files, const gchar *dir, GSList **messages );
 static gboolean          is_already_loaded( const NadpDesktopProvider *provider, GList *files, const gchar *desktop_id );
@@ -58,6 +69,11 @@ static NAIFactoryObject *item_from_desktop_path( const NadpDesktopProvider *prov
 static void              desktop_weak_notify( NadpDesktopFile *ndf, GObject *item );
 static void              free_desktop_paths( GList *paths );
 
+static gboolean          read_done_desktop_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages );
+static void              read_done_load_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, NadpReaderData *data, GSList **messages );
+static void              read_done_action_load_profile( const NAIFactoryProvider *provider, NadpReaderData *reader_data, const gchar *profile_id, GSList **messages );
+static void              read_done_attach_profile( const NAIFactoryProvider *provider, NAObjectProfile *profile, NadpReaderData *reader_data, GSList **messages );
+
 /*
  * Returns an unordered list of NAIFactoryObject-derived objects
  *
@@ -302,3 +318,230 @@ free_desktop_paths( GList *paths )
 
 	g_list_free( paths );
 }
+
+/*
+ * called before starting with reading an object
+ */
+void
+nadp_reader_ifactory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages )
+{
+	static const gchar *thisfn = "nadp_reader_ifactory_provider_read_start";
+
+	g_debug( "%s: reader=%p (%s), reader_data=%p, serializable=%p (%s), messages=%p",
+			thisfn,
+			( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
+			( void * ) reader_data,
+			( void * ) serializable, G_OBJECT_TYPE_NAME( serializable ),
+			( void * ) messages );
+
+	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
+	g_return_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ));
+	g_return_if_fail( NA_IS_IFACTORY_OBJECT( serializable ));
+
+	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){
+	}
+}
+
+/*
+ * reading any data from a desktop file requires:
+ * - a NadpDesktopFile object which has been initialized with the .desktop file
+ *   -> has been attached to the NAObjectItem in get_item() above
+ * - the data type (+ reading default value)
+ * - group and key names
+ *
+ * Returns: NULL if the key has not been found
+ * letting the caller deal with default values
+ */
+NADataBoxed *
+nadp_reader_ifactory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *object, const NADataDef *def, GSList **messages )
+{
+	static const gchar *thisfn = "nadp_reader_ifactory_provider_read_value";
+	NADataBoxed *boxed;
+	gboolean found;
+	NadpReaderData *nrd;
+	gchar *group, *key;
+	gchar *msg;
+	gchar *str_value;
+	gboolean bool_value;
+	GSList *slist_value;
+	guint uint_value;
+
+	/*g_debug( "%s: reader=%p (%s), reader_data=%p, def=%p, messages=%p",
+			thisfn,
+			( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
+			( void * ) reader_data,
+			( void * ) def,
+			( void * ) messages );*/
+
+	g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( reader ), NULL );
+	g_return_val_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ), NULL );
+	g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NULL );
+
+	boxed = NULL;
+
+	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){
+
+		nrd = ( NadpReaderData * ) reader_data;
+		g_return_val_if_fail( NADP_IS_DESKTOP_FILE( nrd->ndf ), NULL );
+
+		if( nadp_keys_get_group_and_key( def, &group, &key )){
+
+			switch( def->type ){
+
+				case NAFD_TYPE_LOCALE_STRING:
+					str_value = nadp_desktop_file_get_locale_string( nrd->ndf, group, key, &found, def->default_value );
+					if( str_value && found ){
+						boxed = na_data_boxed_new( def );
+						na_data_boxed_set_from_void( boxed, str_value );
+					}
+					g_free( str_value );
+					break;
+
+				case NAFD_TYPE_STRING:
+					str_value = nadp_desktop_file_get_string( nrd->ndf, group, key, &found, def->default_value );
+					if( str_value && found ){
+						boxed = na_data_boxed_new( def );
+						na_data_boxed_set_from_void( boxed, str_value );
+					}
+					g_free( str_value );
+					break;
+
+				case NAFD_TYPE_BOOLEAN:
+					bool_value = nadp_desktop_file_get_boolean( nrd->ndf, group, key, &found, na_core_utils_boolean_from_string( def->default_value ));
+					if( found ){
+						boxed = na_data_boxed_new( def );
+						na_data_boxed_set_from_void( boxed, GUINT_TO_POINTER( bool_value ));
+					}
+					break;
+
+				case NAFD_TYPE_STRING_LIST:
+					slist_value = nadp_desktop_file_get_string_list( nrd->ndf, group, key, &found, def->default_value );
+					if( slist_value && found ){
+						boxed = na_data_boxed_new( def );
+						na_data_boxed_set_from_void( boxed, slist_value );
+					}
+					na_core_utils_slist_free( slist_value );
+					break;
+
+				case NAFD_TYPE_UINT:
+					uint_value = nadp_desktop_file_get_uint( nrd->ndf, group, key, &found, atoi( def->default_value ));
+					if( found ){
+						boxed = na_data_boxed_new( def );
+						na_data_boxed_set_from_void( boxed, GUINT_TO_POINTER( uint_value ));
+					}
+					break;
+
+				default:
+					msg = g_strdup_printf( "%s: %d: invalid data type.", thisfn, def->type );
+					g_warning( "%s", msg );
+					*messages = g_slist_append( *messages, msg );
+			}
+
+			/*g_debug( "%s: group=%s, key=%s", thisfn, group, key );*/
+			g_free( key );
+			g_free( group );
+		}
+	}
+
+	return( boxed );
+}
+
+/*
+ * called when each NAIFactoryObject object has been readen
+ */
+void
+nadp_reader_ifactory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages )
+{
+	static const gchar *thisfn = "nadp_reader_ifactory_provider_read_done";
+	gboolean writable;
+
+	g_debug( "%s: reader=%p (%s), reader_data=%p, serializable=%p (%s), messages=%p",
+			thisfn,
+			( void * ) reader, G_OBJECT_TYPE_NAME( reader ),
+			( void * ) reader_data,
+			( void * ) serializable, G_OBJECT_TYPE_NAME( serializable ),
+			( void * ) messages );
+
+	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
+	g_return_if_fail( NADP_IS_DESKTOP_PROVIDER( reader ));
+	g_return_if_fail( NA_IS_IFACTORY_OBJECT( serializable ));
+
+	if( !NADP_DESKTOP_PROVIDER( reader )->private->dispose_has_run ){
+
+		if( NA_IS_OBJECT_ITEM( serializable )){
+			writable = read_done_desktop_is_writable( reader, NA_OBJECT_ITEM( serializable ), ( NadpReaderData * ) reader_data, messages );
+			na_object_set_readonly( serializable, !writable );
+		}
+
+		if( NA_IS_OBJECT_ACTION( serializable )){
+			read_done_load_profiles( reader, NA_OBJECT_ACTION( serializable ), ( NadpReaderData * ) reader_data, messages );
+		}
+
+		if( NA_IS_OBJECT_PROFILE( serializable )){
+			read_done_attach_profile( reader, NA_OBJECT_PROFILE( serializable ), ( NadpReaderData * ) reader_data, messages );
+		}
+
+	}
+}
+
+static gboolean
+read_done_desktop_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages )
+{
+	NadpDesktopFile *ndf;
+	gchar *path;
+	gboolean writable;
+
+	ndf = reader_data->ndf;
+	path = nadp_desktop_file_get_key_file_path( ndf );
+	writable = nadp_utils_is_writable_file( path );
+	g_free( path );
+
+	return( writable );
+}
+
+static void
+read_done_load_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, NadpReaderData *reader_data, GSList **messages )
+{
+	GSList *order;
+	GSList *list_profiles;
+	GSList *ip;
+
+	reader_data->action = action;
+	order = na_object_get_items_slist( action );
+	list_profiles = nadp_desktop_file_get_profiles( reader_data->ndf );
+
+	/* read profiles in the specified order
+	 */
+	for( ip = order ; ip ; ip = ip->next ){
+		read_done_action_load_profile( provider, reader_data, ( const gchar * ) ip->data, messages );
+		list_profiles = na_core_utils_slist_remove_ascii( list_profiles, ( const gchar * ) ip->data );
+	}
+
+	/* append other profiles
+	 * this is mandatory for pre-2.29 actions which introduced order of profiles
+	 */
+	for( ip = list_profiles ; ip ; ip = ip->next ){
+		g_debug( "nadp_reader_read_done_load_profiles: loading profile=%s", ( gchar * ) ip->data );
+		read_done_action_load_profile( provider, reader_data, ( const gchar * ) ip->data, messages );
+	}
+}
+
+static void
+read_done_action_load_profile( const NAIFactoryProvider *provider, NadpReaderData *reader_data, const gchar *profile_id, GSList **messages )
+{
+	NAObjectProfile *profile = na_object_profile_new();
+
+	na_object_set_id( profile, profile_id );
+
+	na_ifactory_provider_read_item(
+			NA_IFACTORY_PROVIDER( provider ),
+			reader_data,
+			NA_IFACTORY_OBJECT( profile ),
+			messages );
+}
+
+static void
+read_done_attach_profile( const NAIFactoryProvider *provider, NAObjectProfile *profile, NadpReaderData *reader_data, GSList **messages )
+{
+	na_object_attach_profile( reader_data->action, profile );
+}
diff --git a/src/io-desktop/nadp-reader.h b/src/io-desktop/nadp-reader.h
index 5bdd0ae..acffee1 100644
--- a/src/io-desktop/nadp-reader.h
+++ b/src/io-desktop/nadp-reader.h
@@ -35,7 +35,11 @@
 
 G_BEGIN_DECLS
 
-GList *nadp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages );
+GList       *nadp_iio_provider_read_items( const NAIIOProvider *provider, GSList **messages );
+
+void         nadp_reader_ifactory_provider_read_start( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages );
+NADataBoxed *nadp_reader_ifactory_provider_read_data( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, const NADataDef *iddef, GSList **messages );
+void         nadp_reader_ifactory_provider_read_done( const NAIFactoryProvider *reader, void *reader_data, const NAIFactoryObject *serializable, GSList **messages );
 
 G_END_DECLS
 
diff --git a/src/io-desktop/nadp-writer.c b/src/io-desktop/nadp-writer.c
index 6c90009..af68faf 100644
--- a/src/io-desktop/nadp-writer.c
+++ b/src/io-desktop/nadp-writer.c
@@ -93,48 +93,6 @@ nadp_iio_provider_is_able_to_write( const NAIIOProvider *provider )
 }
 
 /*
- * the item comes from being readen from a desktop file
- * -> see if this desktop file is writable ?
- *
- * This is only used to setup the 'read-only' initial status of the
- * NAObjectItem - We don't care of all events which can suddenly make
- * this item becomes readonly (eventually we will deal for errors,
- * and reset the flag at this time)
- *
- * Internal function: do not call from outside the instance.
- */
-/*
-gboolean
-nadp_iio_provider_is_writable( const NAIIOProvider *provider, const NAObjectItem *item )
-{
-	static const gchar *thisfn = "nadp_iio_provider_is_writable";
-	gboolean writable;
-	NadpDesktopFile *ndf;
-	gchar *path;
-
-	writable = FALSE;
-	g_return_val_if_fail( NADP_IS_DESKTOP_PROVIDER( provider ), writable );
-	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), writable );
-
-	if( NA_IS_OBJECT_MENU( item )){
-		g_warning( "%s: menu are not yet handled by Desktop provider", thisfn );
-		return( FALSE );
-	}
-
-	ndf = ( NadpDesktopFile * ) na_object_get_provider_data( item );
-
-	if( ndf ){
-		g_return_val_if_fail( NADP_IS_DESKTOP_FILE( ndf ), writable );
-		path = nadp_desktop_file_get_key_file_path( ndf );
-		writable = nadp_utils_is_writable_file( path );
-		g_free( path );
-	}
-
-	return( writable );
-}
-*/
-
-/*
  * This is implementation of NAIIOProvider::write_item method
  */
 guint
@@ -308,3 +266,45 @@ desktop_weak_notify( NadpDesktopFile *ndf, GObject *item )
 
 	g_object_unref( ndf );
 }
+
+#if 0
+/*
+ * the item comes from being readen from a desktop file
+ * -> see if this desktop file is writable ?
+ *
+ * This is only used to setup the 'read-only' initial status of the
+ * NAObjectItem - We don't care of all events which can suddenly make
+ * this item becomes readonly (eventually we will deal for errors,
+ * and reset the flag at this time)
+ *
+ * Internal function: do not call from outside the instance.
+ */
+gboolean
+nadp_writer_desktop_is_writable( const NAIIOProvider *provider, const NAObjectItem *item )
+{
+	static const gchar *thisfn = "nadp_writer_desktop_is_writable";
+	gboolean writable;
+	NadpDesktopFile *ndf;
+	gchar *path;
+
+	writable = FALSE;
+	g_return_val_if_fail( NADP_IS_DESKTOP_PROVIDER( provider ), writable );
+	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), writable );
+
+	if( NA_IS_OBJECT_MENU( item )){
+		g_warning( "%s: menu are not yet handled by Desktop provider", thisfn );
+		return( FALSE );
+	}
+
+	ndf = ( NadpDesktopFile * ) na_object_get_provider_data( item );
+
+	if( ndf ){
+		g_return_val_if_fail( NADP_IS_DESKTOP_FILE( ndf ), writable );
+		path = nadp_desktop_file_get_key_file_path( ndf );
+		writable = nadp_utils_is_writable_file( path );
+		g_free( path );
+	}
+
+	return( writable );
+}
+#endif



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