[nautilus-actions] Update the sort semantic in IIOProvider interface



commit 266a94196f1fb75e53aa68d74c36c05a96a9d839
Author: pierre <pierre vfedora10 virtuals pwi>
Date:   Mon Sep 28 18:30:59 2009 +0200

    Update the sort semantic in IIOProvider interface

 ChangeLog                        |    6 +++-
 data/nautilus-actions.schemas.in |   10 ++++---
 src/common/na-iio-provider.c     |   26 +++++++++++++++---
 src/common/na-iprefs.c           |   52 +++++++++++++++++++++++++++-----------
 src/common/na-iprefs.h           |   51 +++++++++++++------------------------
 src/common/na-pivot.c            |    2 +-
 6 files changed, 88 insertions(+), 59 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d6dcfa4..66eea08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
 2009-09-28 Pierre Wieser <pwieser trychlos org>
 
 	* data/nautilus-actions.schemas.in:
-	Define a schema fot the three new preferences.
+	Define a schema for the three new preferences.
+	Update the schema with the new semantic of actions sorting.
 
 	* src/common/na-gconf-utils.c:
 	* src/common/na-gconf-utils.h
@@ -15,12 +16,15 @@
 
 	* src/common/na-iio-provider.c (na_iio_provider_get_items_tree):
 	Dump the hierarchy tree before the alphabetical sort.
+	Implement the new actions sorting semantic when loading the tree.
 
 	* src/nact/base-iprefs.c:
 	* src/nact/base-iprefs.c (base_iprefs_get_bool,
 	base_iprefs_set_bool):
 	Replace the BaseWindow argument by a BaseIPrefs	one.
 	Define three new UI preferences.
+	(na_iprefs_is_alphabetical_order):
+	Renamed as na_iprefs_get_alphabetical_order().
 
 	* src/nact/nact-assistant-export.c:
 	Implements IActionsList::get_treeview_name virtual function.
diff --git a/data/nautilus-actions.schemas.in b/data/nautilus-actions.schemas.in
index 6977db6..bf26c9d 100644
--- a/data/nautilus-actions.schemas.in
+++ b/data/nautilus-actions.schemas.in
@@ -325,12 +325,14 @@ All schemes used by Nautilus can be used here.</long>
     <schema>
       <key>/schemas/apps/nautilus-actions/preferences/iprefs-alphabetical-order</key>
       <owner>nautilus-actions</owner>
-      <type>bool</type>
+      <type>int</type>
       <locale name="C">
-        <short>Sort actions in alphabetical order</short>
-        <long>When TRUE, the actions are maintained in alphabetical order (historical behavior). When FALSE, user is free to reorder them via Nautilus-Actions configuration tool.</long>
+        <short>Sort indicator</short>
+        <long>If set to zero, the actions are maintained in ascending alphabetical order (historical behavior).
+If set to 1, actions are maintained in descending alphabetical order.
+When set to 2, user is free to reorder them via Nautilus-Actions configuration tool.</long>
       </locale>
-      <default>true</default>
+      <default>0</default>
     </schema>
 
     <schema>
diff --git a/src/common/na-iio-provider.c b/src/common/na-iio-provider.c
index 6fa69cf..24bb549 100644
--- a/src/common/na-iio-provider.c
+++ b/src/common/na-iio-provider.c
@@ -61,8 +61,9 @@ static guint    try_write_item( const NAIIOProvider *instance, NAObject *item, g
 static gboolean do_is_willing_to_write( const NAIIOProvider *instance );
 static gboolean do_is_writable( const NAIIOProvider *instance, const NAObject *item );
 
-static GList   *sort_tree( const NAPivot *pivot, GList *tree );
-static gint     compare_label_alpha_fn( const NAObjectId *a, const NAObjectId *b );
+static GList   *sort_tree( const NAPivot *pivot, GList *tree, GCompareFunc fn );
+static gint     compare_label_alpha_asc_fn( const NAObjectId *a, const NAObjectId *b );
+static gint     compare_label_alpha_desc_fn( const NAObjectId *a, const NAObjectId *b );
 
 /**
  * Registers the GType of this interface.
@@ -159,6 +160,7 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
 	GList *providers;
 	GList *merged, *hierarchy;
 	GSList *level_zero;
+	gint order_mode;
 
 	g_debug( "%s: pivot=%p", thisfn, ( void * ) pivot );
 	g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
@@ -181,8 +183,16 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
 		na_object_dump_tree( hierarchy );
 		g_debug( "%s: end of tree", thisfn );
 
-		if( na_iprefs_is_alphabetical_order( NA_IPREFS( pivot ))){
-			hierarchy = sort_tree( pivot, hierarchy );
+		order_mode = na_iprefs_get_alphabetical_order( NA_IPREFS( pivot ));
+		switch( order_mode ){
+			case PREFS_ORDER_ALPHA_DESCENDING:
+				hierarchy = sort_tree( pivot, hierarchy, compare_label_alpha_desc_fn );
+				break;
+
+			case PREFS_ORDER_ALPHA_ASCENDING:
+			default:
+				hierarchy = sort_tree( pivot, hierarchy, compare_label_alpha_asc_fn );
+				break;
 		}
 	}
 
@@ -469,7 +479,7 @@ sort_tree( const NAPivot *pivot, GList *tree )
 }
 
 static gint
-compare_label_alpha_fn( const NAObjectId *a, const NAObjectId *b )
+compare_label_alpha_asc_fn( const NAObjectId *a, const NAObjectId *b )
 {
 	gchar *label_a, *label_b;
 	gint compare;
@@ -484,3 +494,9 @@ compare_label_alpha_fn( const NAObjectId *a, const NAObjectId *b )
 
 	return( compare );
 }
+
+static gint
+compare_label_alpha_desc_fn( const NAObjectId *a, const NAObjectId *b )
+{
+	return( -1 * compare_label_alpha_asc_fn( a, b ));
+}
diff --git a/src/common/na-iprefs.c b/src/common/na-iprefs.c
index 80f11d1..4adadf9 100644
--- a/src/common/na-iprefs.c
+++ b/src/common/na-iprefs.c
@@ -50,8 +50,10 @@ static void     interface_base_init( NAIPrefsInterface *klass );
 static void     interface_base_finalize( NAIPrefsInterface *klass );
 
 static gboolean read_bool( NAIPrefs *instance, const gchar *name, gboolean default_value );
+static gint     read_int( NAIPrefs *instance, const gchar *name, gint default_value );
 static GSList  *read_string_list( NAIPrefs *instance, const gchar *name );
 static void     write_bool( NAIPrefs *instance, const gchar *name, gboolean value );
+static void     write_int( NAIPrefs *instance, const gchar *name, gint value );
 static void     write_string_list( NAIPrefs *instance, const gchar *name, GSList *list );
 
 GType
@@ -166,27 +168,26 @@ na_iprefs_set_level_zero_items( NAIPrefs *instance, GSList *order )
 }
 
 /**
- * na_iprefs_is_alphabetical_order:
+ * na_iprefs_get_alphabetical_order:
  * @instance: this #NAIPrefs interface instance.
  *
- * Returns: #TRUE if the actions are to be maintained in alphabetical
- * order of their label, #FALSE else.
+ * Returns: the order mode currently set.
  *
- * Note: this function returns a suitable default value if the key is
- * not found in GConf preferences.
+ * Note: this function returns a suitable default value even if the key
+ * is not found in GConf preferences or no schema has been installed.
  *
  * Note: please take care of keeping the default value synchronized with
  * those defined in schemas.
  */
-gboolean
-na_iprefs_is_alphabetical_order( NAIPrefs *instance )
+gint
+na_iprefs_get_alphabetical_order( NAIPrefs *instance )
 {
-	gboolean alpha_order = FALSE;
+	gint alpha_order = PREFS_ORDER_ALPHA_ASCENDING;
 
-	g_return_val_if_fail( NA_IS_IPREFS( instance ), FALSE );
+	g_return_val_if_fail( NA_IS_IPREFS( instance ), PREFS_ORDER_ALPHA_ASCENDING );
 
 	if( st_initialized && !st_finalized ){
-		alpha_order = read_bool( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, TRUE );
+		alpha_order = read_int( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, PREFS_ORDER_ALPHA_ASCENDING );
 	}
 
 	return( alpha_order );
@@ -195,18 +196,18 @@ na_iprefs_is_alphabetical_order( NAIPrefs *instance )
 /**
  * na_iprefs_set_alphabetical_order:
  * @instance: this #NAIPrefs interface instance.
- * @enabled: the new value to be written.
+ * @mode: the new value to be written.
  *
  * Writes the current status of 'alphabetical order' to the GConf
  * preference system.
  */
 void
-na_iprefs_set_alphabetical_order( NAIPrefs *instance, gboolean enabled )
+na_iprefs_set_alphabetical_order( NAIPrefs *instance, gint mode )
 {
 	g_return_if_fail( NA_IS_IPREFS( instance ));
 
 	if( st_initialized && !st_finalized ){
-		write_bool( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, enabled );
+		write_int( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, mode );
 	}
 }
 
@@ -261,7 +262,20 @@ read_bool( NAIPrefs *instance, const gchar *name, gboolean default_value )
 	gboolean ret;
 
 	path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
-	ret = na_gconf_utils_read_bool( NA_IPREFS_GET_INTERFACE( instance )->private->client, path, FALSE, default_value );
+	ret = na_gconf_utils_read_bool( NA_IPREFS_GET_INTERFACE( instance )->private->client, path, TRUE, default_value );
+	g_free( path );
+
+	return( ret );
+}
+
+static gint
+read_int( NAIPrefs *instance, const gchar *name, gint default_value )
+{
+	gchar *path;
+	gint ret;
+
+	path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
+	ret = na_gconf_utils_read_int( NA_IPREFS_GET_INTERFACE( instance )->private->client, path, TRUE, default_value );
 	g_free( path );
 
 	return( ret );
@@ -286,9 +300,17 @@ write_bool( NAIPrefs *instance, const gchar *name, gboolean value )
 	gchar *path;
 
 	path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
-
 	na_gconf_utils_write_bool( NA_IPREFS_GET_INTERFACE( instance )->private->client, path, value, NULL );
+	g_free( path );
+}
 
+static void
+write_int( NAIPrefs *instance, const gchar *name, gint value )
+{
+	gchar *path;
+
+	path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
+	na_gconf_utils_write_int( NA_IPREFS_GET_INTERFACE( instance )->private->client, path, value, NULL );
 	g_free( path );
 }
 
diff --git a/src/common/na-iprefs.h b/src/common/na-iprefs.h
index 7e3a34e..092fb66 100644
--- a/src/common/na-iprefs.h
+++ b/src/common/na-iprefs.h
@@ -46,42 +46,19 @@
  *
  * Displaying the actions.
  *
- * - actions in alphabetical order: yes/no
+ * - actions in alphabetical order:
+ *
  *   Nautilus-Actions used to display the actions in alphabetical order.
  *   Starting with 1.12.x, Nautilus-Actions lets the user rearrange
  *   himself the order of its actions.
- *   Defaults to yes to stay compatible with previous versions.
- *
- *   Actions can be organized in a set of submenus. In this case, the
- *   'alphabetical order' preferences is also satisfied, on a level
- *   basis.
- *   This is not a preference: as submenus are available, user is free
- *   to define some in NACT ; plugin will take care of them.
- *
- *   Defined order is saved in the same time than actions. So
- *   considering the following operations:
- *
- *   a) set preference to 'no'
- *   b) rearrange the items in any order
- *   c) save
- *   d) set preference to 'yes'
- *      -> the items are reordered in alphabetical order
- *   e) set preference to 'no'
- *      -> the previous order is restaured (as it has been previously
- *         saved)
- *
- *   but
- *
- *   a) set preference to 'no'
- *   b) rearrange the items in any order
- *   c) set preference to 'yes'
- *      -> the items are reordered in alphabetical order
- *   d) save
- *   e) set preference to 'no'
- *      -> the items stay in alphabetical order, as the previous save
- *         has removed the previous order.
+ *
+ *   This option may have three values :
+ *   - ascending alphabetical order (historical behavior, and default),
+ *   - descending alphabetical order,
+ *   - manual ordering.
  *
  * - adding a 'About Nautilus Actions' item at end of actions: yes/no
+ *
  *   This is used only when there is a root submenu, i.e. when the
  *   Nautilus context menu will only display one item (the root
  *   submenu). Only in this case, and if preference is 'yes', the we
@@ -124,8 +101,8 @@ GType    na_iprefs_get_type( void );
 GSList  *na_iprefs_get_level_zero_items( NAIPrefs *instance );
 void     na_iprefs_set_level_zero_items( NAIPrefs *instance, GSList *order );
 
-gboolean na_iprefs_is_alphabetical_order( NAIPrefs *instance );
-void     na_iprefs_set_alphabetical_order( NAIPrefs *instance, gboolean enabled );
+gint     na_iprefs_get_alphabetical_order( NAIPrefs *instance );
+void     na_iprefs_set_alphabetical_order( NAIPrefs *instance, gint mode );
 
 gboolean na_iprefs_should_add_about_item( NAIPrefs *instance );
 void     na_iprefs_set_add_about_item( NAIPrefs *instance, gboolean enabled );
@@ -141,6 +118,14 @@ void     na_iprefs_set_add_about_item( NAIPrefs *instance, gboolean enabled );
 #define PREFS_DISPLAY_ALPHABETICAL_ORDER	"iprefs-alphabetical-order"
 #define PREFS_ADD_ABOUT_ITEM				"iprefs-add-about-item"
 
+/* alphabetical order values
+ */
+enum {
+	PREFS_ORDER_ALPHA_ASCENDING = 0,
+	PREFS_ORDER_ALPHA_DESCENDING,
+	PREFS_ORDER_MANUAL
+};
+
 G_END_DECLS
 
 #endif /* __NA_IPREFS_H__ */
diff --git a/src/common/na-pivot.c b/src/common/na-pivot.c
index e53196b..c9a7bff 100644
--- a/src/common/na-pivot.c
+++ b/src/common/na-pivot.c
@@ -182,7 +182,7 @@ class_init( NAPivotClass *klass )
 	klass->private = g_new0( NAPivotClassPrivate, 1 );
 
 	/* register the signal and its default handler
-	 * this signal should be sent by the IIOProvider when an actions
+	 * this signal should be sent by the IIOProvider when an action
 	 * has changed in the underlying storage subsystem
 	 */
 	st_signals[ ACTION_CHANGED ] = g_signal_new_class_handler(



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