[nautilus-actions] Always keep the order of the profiles



commit 8b5f98ef49209b73037ad4bf394b5e128ad1d448
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Oct 13 21:06:25 2009 +0200

    Always keep the order of the profiles

 ChangeLog                            |    5 ++++
 src/runtime/na-gconf-provider-keys.h |    4 +-
 src/runtime/na-gconf-provider.c      |   43 ++++++++++++++++++++++++++--------
 src/runtime/na-object-item.c         |    8 +++---
 src/runtime/na-utils.c               |   27 +++++++++++++++++++++
 src/runtime/na-utils.h               |    1 +
 6 files changed, 72 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3738720..c9351cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@
 	(read_object_item_properties, write_object_item): actions and
 	menus may have ordered subitems
 	(write_item_action, write_item_menu): Write the item's type.
+	(read_item_action): Keep the order of profiles.
 
 	* src/runtime/na-iio-provider.c (build_hierarchy):
 	Use na_object_item_get_items_string_list.
@@ -33,6 +34,10 @@
 	* src/runtime/na-object-menu.c:
 	List of string id of subitems is moved to NAObjectItem.
 
+	* src/runtime/na-utils.c:
+	* src/runtime/na-utils.h (na_utils_remove_from_string_list):
+	New function.
+
 2009-10-12 Pierre Wieser <pwieser trychlos org>
 
 	* src/common/na-object-api.h
diff --git a/src/runtime/na-gconf-provider-keys.h b/src/runtime/na-gconf-provider-keys.h
index c96a807..0561a6f 100644
--- a/src/runtime/na-gconf-provider-keys.h
+++ b/src/runtime/na-gconf-provider-keys.h
@@ -46,8 +46,8 @@
 #define OBJECT_ITEM_LIST_ENTRY			"items"
 #define OBJECT_ITEM_TYPE_ENTRY			"type"
 
-#define OBJECT_ITEM_TYPE_MENU			"menu"
-#define OBJECT_ITEM_TYPE_ACTION			"action"
+#define OBJECT_ITEM_TYPE_MENU			"Menu"
+#define OBJECT_ITEM_TYPE_ACTION			"Action"
 
 /* GConf key names (specific to menu)
  */
diff --git a/src/runtime/na-gconf-provider.c b/src/runtime/na-gconf-provider.c
index ff15dca..869f2e8 100644
--- a/src/runtime/na-gconf-provider.c
+++ b/src/runtime/na-gconf-provider.c
@@ -75,7 +75,7 @@ static NAObjectItem  *read_item( NAGConfProvider *provider, const gchar *path );
 static void           read_item_action( NAGConfProvider *provider, const gchar *path, NAObjectAction *action );
 static void           read_item_action_properties( NAGConfProvider *provider, GSList *entries, NAObjectAction *action );
 static void           read_item_action_properties_v1( NAGConfProvider *gconf, GSList *entries, NAObjectAction *action );
-static void           read_item_action_profile( NAGConfProvider *provider, const gchar *path, NAObjectProfile *profile );
+static void           read_item_action_profile( NAGConfProvider *provider, NAObjectAction *action, const gchar *path );
 static void           read_item_action_profile_properties( NAGConfProvider *provider, GSList *entries, NAObjectProfile *profile );
 static void           read_item_menu( NAGConfProvider *provider, const gchar *path, NAObjectMenu *menu );
 static void           read_item_menu_properties( NAGConfProvider *provider, GSList *entries, NAObjectMenu *menu );
@@ -489,6 +489,7 @@ read_item( NAGConfProvider *provider, const gchar *path )
 	} else if( !have_type || !strcmp( type, OBJECT_ITEM_TYPE_ACTION )){
 		item = NA_OBJECT_ITEM( na_object_action_new());
 		read_item_action( provider, path, NA_OBJECT_ACTION( item ));
+
 	} else {
 		g_warning( "%s: unknown type '%s' at %s", thisfn, type, path );
 	}
@@ -514,6 +515,8 @@ read_item( NAGConfProvider *provider, const gchar *path )
  *
  * - version = '2.0' which introduces the 'profile' notion
  *   profile += name+label
+ *
+ * Profiles are kept in the order specified in 'items' entry if it exists.
  */
 static void
 read_item_action( NAGConfProvider *provider, const gchar *path, NAObjectAction *action )
@@ -521,7 +524,8 @@ read_item_action( NAGConfProvider *provider, const gchar *path, NAObjectAction *
 	static const gchar *thisfn = "na_gconf_provider_read_item_action";
 	gchar *uuid;
 	GSList *entries, *list_profiles, *ip;
-	NAObjectProfile *profile;
+	GSList *order;
+	gchar *profile_path;
 
 	g_debug( "%s: provider=%p, path=%s, action=%p",
 			thisfn, ( void * ) provider, path, ( void * ) action );
@@ -532,24 +536,38 @@ read_item_action( NAGConfProvider *provider, const gchar *path, NAObjectAction *
 	g_free( uuid );
 
 	entries = na_gconf_utils_get_entries( provider->private->gconf, path );
-
 	read_item_action_properties( provider, entries, action  );
 
+	order = na_object_item_get_items_string_list( NA_OBJECT_ITEM( action ));
 	list_profiles = na_gconf_utils_get_subdirs( provider->private->gconf, path );
 
 	if( list_profiles ){
-		for( ip = list_profiles ; ip ; ip = ip->next ){
 
-			const gchar *profile_path = ( const gchar * ) ip->data;
-			profile = na_object_profile_new();
-			read_item_action_profile( provider, profile_path, profile );
-			na_object_action_attach_profile( action, profile );
+		/* read profiles in the specified order
+		 */
+		for( ip = order ; ip ; ip = ip->next ){
+			profile_path = gconf_concat_dir_and_key( path, ( gchar * ) ip->data );
+			read_item_action_profile( provider, action, profile_path );
+			list_profiles = na_utils_remove_from_string_list( list_profiles, profile_path );
+			g_free( profile_path );
+		}
+
+		/* read other profiles
+		 */
+		for( ip = list_profiles ; ip ; ip = ip->next ){
+			profile_path = g_strdup(( gchar * ) ip->data );
+			read_item_action_profile( provider, action, profile_path );
+			g_free( profile_path );
 		}
 
+	/* if there is no subdir, this may be a valid v1 or an invalid v2
+	 * at least try to read some properties
+	 */
 	} else {
 		read_item_action_properties_v1( provider, entries, action );
 	}
 
+	na_utils_free_string_list( order );
 	na_gconf_utils_free_subdirs( list_profiles );
 	na_gconf_utils_free_entries( entries );
 
@@ -590,12 +608,15 @@ read_item_action_properties_v1( NAGConfProvider *provider, GSList *entries, NAOb
 }
 
 static void
-read_item_action_profile( NAGConfProvider *provider, const gchar *path, NAObjectProfile *profile )
+read_item_action_profile( NAGConfProvider *provider, NAObjectAction *action, const gchar *path )
 {
+	NAObjectProfile *profile;
 	gchar *name;
 	GSList *entries;
 
-	g_return_if_fail( NA_IS_OBJECT_PROFILE( profile ));
+	g_return_if_fail( NA_IS_OBJECT_ACTION( action ));
+
+	profile = na_object_profile_new();
 
 	name = na_gconf_utils_path_to_key( path );
 	na_object_set_id( profile, name );
@@ -604,6 +625,8 @@ read_item_action_profile( NAGConfProvider *provider, const gchar *path, NAObject
 	entries = na_gconf_utils_get_entries( provider->private->gconf, path );
 	read_item_action_profile_properties( provider, entries, profile );
 	na_gconf_utils_free_entries( entries );
+
+	na_object_action_attach_profile( action, profile );
 }
 
 static void
diff --git a/src/runtime/na-object-item.c b/src/runtime/na-object-item.c
index d707df5..d564b9e 100644
--- a/src/runtime/na-object-item.c
+++ b/src/runtime/na-object-item.c
@@ -699,7 +699,7 @@ na_object_item_rebuild_items_list( const NAObjectItem *item )
 {
 	GSList *list = NULL;
 	GList *items, *it;
-	gchar *uuid;
+	gchar *id;
 
 	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
 
@@ -708,9 +708,9 @@ na_object_item_rebuild_items_list( const NAObjectItem *item )
 		items = na_object_get_items_list( item );
 
 		for( it = items ; it ; it = it->next ){
-			NAObjectItem *item = NA_OBJECT_ITEM( it->data );
-			uuid = na_object_get_id( item );
-			list = g_slist_prepend( list, uuid );
+			NAObjectId *item = NA_OBJECT_ID( it->data );
+			id = na_object_get_id( item );
+			list = g_slist_prepend( list, id );
 		}
 
 		list = g_slist_reverse( list );
diff --git a/src/runtime/na-utils.c b/src/runtime/na-utils.c
index e65bc0a..fd5cde4 100644
--- a/src/runtime/na-utils.c
+++ b/src/runtime/na-utils.c
@@ -99,6 +99,33 @@ na_utils_free_string_list( GSList *list )
 }
 
 /**
+ * na_utils_remove_from_string_list:
+ * @list: the GSList to be updated.
+ * @str: the string to be removed.
+ *
+ * Removes from the @list the item which has a string which is equal to
+ * @str.
+ *
+ * Returns: the new @list start position.
+ */
+GSList *
+na_utils_remove_from_string_list( GSList *list, const gchar *str )
+{
+	GSList *is;
+
+	for( is = list ; is ; is = is->next ){
+		const gchar *istr = ( const gchar * ) is->data;
+		if( !g_utf8_collate( str, istr )){
+			g_free( is->data );
+			list = g_slist_delete_link( list, is );
+			break;
+		}
+	}
+
+	return( list );
+}
+
+/**
  * na_utils_string_lists_are_equal:
  * @first: a GSList of strings.
  * @second: another GSList of strings to be compared with @first.
diff --git a/src/runtime/na-utils.h b/src/runtime/na-utils.h
index 65b323f..b6831a7 100644
--- a/src/runtime/na-utils.h
+++ b/src/runtime/na-utils.h
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
 GSList  *na_utils_duplicate_string_list( GSList *list );
 gboolean na_utils_find_in_list( GSList *list, const gchar *str );
 void     na_utils_free_string_list( GSList *list );
+GSList  *na_utils_remove_from_string_list( GSList *list, const gchar *str );
 gboolean na_utils_string_lists_are_equal( GSList *first, GSList *second );
 
 /* a GSList to a string [aaaa,bbbb,cccc]



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