[nautilus-actions] Homogeneïze the read_done functions of I/O providers



commit 58932cd9a3902f1bb1becbcca93e995e84cf903f
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Jul 26 05:57:24 2010 +0200

    Homogeneïze the read_done functions of I/O providers

 ChangeLog                    |    5 ++
 src/io-desktop/nadp-reader.c |   91 +++++++++++++++++++++---------------------
 src/io-gconf/nagp-reader.c   |   48 ++++++++++++----------
 3 files changed, 78 insertions(+), 66 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ff01384..7e5890d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2010-07-26 Pierre Wieser <pwieser trychlos org>
 
+	* src/io-desktop/nadp-reader.c
+	(nadp_reader_ifactory_provider_read_done):
+	* src/io-gconf/nagp-reader.c (nagp_reader_read_done):
+	Homogeneïze the read_done functions.
+
 	Move the reading of the subitems key for the desktop I/O provider
 	from 'read_done' to 'read_start'.
 
diff --git a/src/io-desktop/nadp-reader.c b/src/io-desktop/nadp-reader.c
index 383184d..6531c2f 100644
--- a/src/io-desktop/nadp-reader.c
+++ b/src/io-desktop/nadp-reader.c
@@ -69,11 +69,12 @@ 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_subitems_key( 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_start_read_subitems_key( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages );
+
+static gboolean          read_done_item_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages );
+static void              read_done_action_read_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 );
+static void              read_done_profile_attach_profile( const NAIFactoryProvider *provider, NAObjectProfile *profile, NadpReaderData *reader_data, GSList **messages );
 
 /*
  * Returns an unordered list of NAIFactoryObject-derived objects
@@ -331,26 +332,45 @@ 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";
-	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 ){
+
+		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 );
+
 		if( NA_IS_OBJECT_ITEM( serializable )){
-			read_subitems_key( reader, NA_OBJECT_ITEM( serializable ), ( NadpReaderData * ) reader_data, messages );
+			read_start_read_subitems_key( reader, NA_OBJECT_ITEM( serializable ), ( NadpReaderData * ) reader_data, messages );
 		}
 	}
 }
 
+static void
+read_start_read_subitems_key( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages )
+{
+	GSList *subitems;
+	gboolean key_found;
+
+	subitems = nadp_desktop_file_get_string_list( reader_data->ndf,
+			NADP_GROUP_DESKTOP,
+			NA_IS_OBJECT_ACTION( item ) ? NADP_KEY_PROFILES : NADP_KEY_ITEMS_LIST,
+			&key_found,
+			NULL );
+
+	if( key_found ){
+		na_object_set_items_slist( item, subitems );
+	}
+
+	na_core_utils_slist_free( subitems );
+}
+
 /*
  * reading any data from a desktop file requires:
  * - a NadpDesktopFile object which has been initialized with the .desktop file
@@ -473,37 +493,37 @@ nadp_reader_ifactory_provider_read_done( const NAIFactoryProvider *reader, void
 	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 ){
 
+		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 );
+
 		if( NA_IS_OBJECT_ITEM( serializable )){
-			writable = read_done_desktop_is_writable( reader, NA_OBJECT_ITEM( serializable ), ( NadpReaderData * ) reader_data, messages );
+			writable = read_done_item_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 );
+			read_done_action_read_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 );
+			read_done_profile_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 )
+read_done_item_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages )
 {
 	NadpDesktopFile *ndf;
 	gchar *path;
@@ -517,32 +537,13 @@ read_done_desktop_is_writable( const NAIFactoryProvider *provider, NAObjectItem
 	return( writable );
 }
 
-static void
-read_subitems_key( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages )
-{
-	GSList *subitems;
-	gboolean key_found;
-
-	subitems = nadp_desktop_file_get_string_list( reader_data->ndf,
-			NADP_GROUP_DESKTOP,
-			NA_IS_OBJECT_ACTION( item ) ? NADP_KEY_PROFILES : NADP_KEY_ITEMS_LIST,
-			&key_found,
-			NULL );
-
-	if( key_found ){
-		na_object_set_items_slist( item, subitems );
-	}
-
-	na_core_utils_slist_free( subitems );
-}
-
 /*
  * read and attach profiles in the specified order
  * profiles which may exist in .desktop files, but are not referenced
  * in the 'Profiles' string list are just ignored
  */
 static void
-read_done_load_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, NadpReaderData *reader_data, GSList **messages )
+read_done_action_read_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, NadpReaderData *reader_data, GSList **messages )
 {
 	GSList *order;
 	GSList *ip;
@@ -581,7 +582,7 @@ read_done_action_load_profile( const NAIFactoryProvider *provider, NadpReaderDat
 }
 
 static void
-read_done_attach_profile( const NAIFactoryProvider *provider, NAObjectProfile *profile, NadpReaderData *reader_data, GSList **messages )
+read_done_profile_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-gconf/nagp-reader.c b/src/io-gconf/nagp-reader.c
index 076a2eb..24e3cba 100644
--- a/src/io-gconf/nagp-reader.c
+++ b/src/io-gconf/nagp-reader.c
@@ -55,8 +55,8 @@ typedef struct {
 
 static NAObjectItem *read_item( NagpGConfProvider *provider, const gchar *path, GSList **messages );
 
-static void          read_done_item_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, ReaderData *data, GSList **messages );
-static void          read_done_action_load_profiles_from_list( const NAIFactoryProvider *provider, NAObjectAction *action, ReaderData *data, GSList **messages );
+static gboolean      read_done_item_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, ReaderData *data, GSList **messages );
+static void          read_done_action_read_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, ReaderData *data, GSList **messages );
 static void          read_done_action_load_profile( const NAIFactoryProvider *provider, ReaderData *data, const gchar *path, GSList **messages );
 static void          read_done_profile_attach_profile( const NAIFactoryProvider *provider, NAObjectProfile *profile, ReaderData *data, GSList **messages );
 
@@ -198,33 +198,39 @@ void
 nagp_reader_read_done( const NAIFactoryProvider *provider, void *reader_data, const NAIFactoryObject *object, GSList **messages  )
 {
 	static const gchar *thisfn = "nagp_reader_read_done";
+	gboolean writable;
 
 	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( provider ));
+	g_return_if_fail( NAGP_IS_GCONF_PROVIDER( provider ));
 	g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
 
-	g_debug( "%s: provider=%p, reader_data=%p, object=%p (%s), messages=%p",
-			thisfn,
-			( void * ) provider,
-			( void * ) reader_data,
-			( void * ) object, G_OBJECT_TYPE_NAME( object ),
-			( void * ) messages );
+	if( !NAGP_GCONF_PROVIDER( provider )->private->dispose_has_run ){
 
-	if( NA_IS_OBJECT_ITEM( object )){
-		read_done_item_is_writable( provider, NA_OBJECT_ITEM( object ), ( ReaderData * ) reader_data, messages );
-	}
+		g_debug( "%s: provider=%p (%s), reader_data=%p, object=%p (%s), messages=%p",
+				thisfn,
+				( void * ) provider, G_OBJECT_TYPE_NAME( provider ),
+				( void * ) reader_data,
+				( void * ) object, G_OBJECT_TYPE_NAME( object ),
+				( void * ) messages );
 
-	if( NA_IS_OBJECT_ACTION( object )){
-		read_done_action_load_profiles_from_list( provider, NA_OBJECT_ACTION( object ), ( ReaderData * ) reader_data, messages );
-	}
+		if( NA_IS_OBJECT_ITEM( object )){
+			writable = read_done_item_is_writable( provider, NA_OBJECT_ITEM( object ), ( ReaderData * ) reader_data, messages );
+			na_object_set_readonly( object, !writable );
+		}
 
-	if( NA_IS_OBJECT_PROFILE( object )){
-		read_done_profile_attach_profile( provider, NA_OBJECT_PROFILE( object ), ( ReaderData * ) reader_data, messages );
-	}
+		if( NA_IS_OBJECT_ACTION( object )){
+			read_done_action_read_profiles( provider, NA_OBJECT_ACTION( object ), ( ReaderData * ) reader_data, messages );
+		}
+
+		if( NA_IS_OBJECT_PROFILE( object )){
+			read_done_profile_attach_profile( provider, NA_OBJECT_PROFILE( object ), ( ReaderData * ) reader_data, messages );
+		}
 
-	g_debug( "%s: quitting for %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
+		g_debug( "%s: quitting for %s at %p", thisfn, G_OBJECT_TYPE_NAME( object ), ( void * ) object );
+	}
 }
 
-static void
+static gboolean
 read_done_item_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, ReaderData *data, GSList **messages )
 {
 	GSList *ie;
@@ -243,11 +249,11 @@ read_done_item_is_writable( const NAIFactoryProvider *provider, NAObjectItem *it
 	}
 
 	g_debug( "nagp_reader_read_done_item: writable=%s", writable ? "True":"False" );
-	na_object_set_readonly( item, !writable );
+	return( writable );
 }
 
 static void
-read_done_action_load_profiles_from_list( const NAIFactoryProvider *provider, NAObjectAction *action, ReaderData *data, GSList **messages )
+read_done_action_read_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, ReaderData *data, GSList **messages )
 {
 	GSList *order;
 	GSList *list_profiles;



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