Commit 7d167987 authored by Pierre Wieser's avatar Pierre Wieser

Store order mode preference as a string

parent 89a7f09b
2009-09-30 Pierre Wieser <pwieser@trychlos.org>
* data/nautilus-actions.schemas.in:
Order mode preference is now a string to let the GConf edition
be more user friendly.
* src/common/na-gconf-utils.c:
* src/common/na-gconf-utils.h (na_gconf_utils_read_string):
New function.
* src/common/na-iprefs.c:
Define order_mode_table to convert internal mode to GConf string.
* src/common/na-about.c: Renamed as na-iabout.c.
* src/common/na-about.h: Renamed as na-iabout.h.
Defines the NAIAbout interface to let the implementor provides
......
......@@ -325,12 +325,13 @@ 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>int</type>
<type>string</type>
<locale name="C">
<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>
<short>Sort mode</short>
<long>This preference indicates the preferred sort mode. Possible values are :
- "AscendingAlphaOrder": the actions are maintained in ascending alphabetical order (historical behavior).
- "DescendingAlphaOrder": the actions are maintained in descending alphabetical order.
- "ManualOrder": user is free to reorder them via Nautilus-Actions configuration tool.</long>
</locale>
<default>0</default>
</schema>
......
......@@ -405,6 +405,38 @@ na_gconf_utils_read_int( GConfClient *gconf, const gchar *path, gboolean use_sch
return( ret );
}
/**
* na_gconf_utils_read_string:
* @gconf: a #GConfClient instance.
* @path: the full path to the key.
* @use_schema: whether to use the default value from schema, or not.
* @default_value: default value to be used if schema is not used or
* doesn't exist.
*
* Returns: the required string value in a newly allocated string which
* should be g_free() by the caller.
*/
gchar *
na_gconf_utils_read_string( GConfClient *gconf, const gchar *path, gboolean use_schema, const gchar *default_value )
{
GConfValue *value = NULL;
gchar *result;
g_return_val_if_fail( GCONF_IS_CLIENT( gconf ), NULL );
result = g_strdup( default_value );
value = read_value( gconf, path, use_schema, GCONF_VALUE_STRING );
if( value ){
g_free( result );
result = g_strdup( gconf_value_get_string( value ));
gconf_value_free( value );
}
return( result );
}
/**
* na_gconf_utils_read_string_list:
* @gconf: a #GConfClient instance.
......
......@@ -55,6 +55,7 @@ gchar *na_gconf_utils_path_to_key( const gchar *path );
gboolean na_gconf_utils_read_bool( GConfClient *gconf, const gchar *path, gboolean use_schema, gboolean default_value );
gint na_gconf_utils_read_int( GConfClient *gconf, const gchar *path, gboolean use_schema, gint default_value );
gchar *na_gconf_utils_read_string( GConfClient *gconf, const gchar *path, gboolean use_schema, const gchar *default_value );
GSList *na_gconf_utils_read_string_list( GConfClient *gconf, const gchar *path );
gboolean na_gconf_utils_write_bool( GConfClient *gconf, const gchar *path, gboolean value, gchar **message );
......
......@@ -50,6 +50,16 @@ typedef struct {
}
NAIPrefsPrivate;
#define DEFAULT_ORDER_MODE_INT PREFS_ORDER_ALPHA_ASCENDING
#define DEFAULT_ORDER_MODE_STR "AscendingOrder"
static GConfEnumStringPair order_mode_table[] = {
{ PREFS_ORDER_ALPHA_ASCENDING , "AscendingOrder" },
{ PREFS_ORDER_ALPHA_DESCENDING, "DescendingOrder" },
{ PREFS_ORDER_MANUAL , "ManualOrder" },
{ 0, NULL }
};
#define NA_IPREFS_PRIVATE_DATA "na-iprefs-private-data"
static gboolean st_initialized = FALSE;
......@@ -60,10 +70,12 @@ 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 gint read_int( NAIPrefs *instance, const gchar *name, gint default_value );*/
static gchar *read_string( NAIPrefs *instance, const gchar *name, const gchar *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_int( NAIPrefs *instance, const gchar *name, gint value );*/
static void write_string( NAIPrefs *instance, const gchar *name, const gchar *value );
static void write_string_list( NAIPrefs *instance, const gchar *name, GSList *list );
static void setup_private_data( NAIPrefs *instance );
......@@ -195,13 +207,20 @@ na_iprefs_set_level_zero_items( NAIPrefs *instance, GSList *order )
gint
na_iprefs_get_order_mode( NAIPrefs *instance )
{
gint alpha_order = PREFS_ORDER_ALPHA_ASCENDING;
gint alpha_order = DEFAULT_ORDER_MODE_INT;
gint order_int;
gchar *order_str;
g_return_val_if_fail( NA_IS_IPREFS( instance ), PREFS_ORDER_ALPHA_ASCENDING );
g_return_val_if_fail( NA_IS_IPREFS( instance ), DEFAULT_ORDER_MODE_INT );
if( st_initialized && !st_finalized ){
setup_private_data( instance );
alpha_order = read_int( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, PREFS_ORDER_ALPHA_ASCENDING );
order_str = read_string( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, DEFAULT_ORDER_MODE_STR );
if( gconf_string_to_enum( order_mode_table, order_str, &order_int )){
alpha_order = order_int;
}
g_free( order_str );
}
return( alpha_order );
......@@ -218,11 +237,14 @@ na_iprefs_get_order_mode( NAIPrefs *instance )
void
na_iprefs_set_order_mode( NAIPrefs *instance, gint mode )
{
const gchar *order_str;
g_return_if_fail( NA_IS_IPREFS( instance ));
if( st_initialized && !st_finalized ){
setup_private_data( instance );
write_int( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, mode );
order_str = gconf_enum_to_string( order_mode_table, mode );
write_string( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, order_str ? order_str : DEFAULT_ORDER_MODE_STR );
}
}
......@@ -278,24 +300,37 @@ read_bool( NAIPrefs *instance, const gchar *name, gboolean default_value )
gchar *path;
gboolean ret;
path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
ret = na_gconf_utils_read_bool( get_gconf_client( instance ), path, TRUE, default_value );
g_free( path );
return( ret );
}
static gint
/*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 );
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
ret = na_gconf_utils_read_int( get_gconf_client( instance ), path, TRUE, default_value );
g_free( path );
return( ret );
}*/
static gchar *
read_string( NAIPrefs *instance, const gchar *name, const gchar *default_value )
{
gchar *path;
gchar *value;
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
value = na_gconf_utils_read_string( get_gconf_client( instance ), path, TRUE, default_value );
g_free( path );
return( value );
}
static GSList *
......@@ -304,7 +339,7 @@ read_string_list( NAIPrefs *instance, const gchar *name )
gchar *path;
GSList *list;
path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
list = na_gconf_utils_read_string_list( get_gconf_client( instance ), path );
g_free( path );
......@@ -316,19 +351,29 @@ write_bool( NAIPrefs *instance, const gchar *name, gboolean value )
{
gchar *path;
path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
na_gconf_utils_write_bool( get_gconf_client( instance ), path, value, NULL );
g_free( path );
}
static void
/*static void
write_int( NAIPrefs *instance, const gchar *name, gint value )
{
gchar *path;
path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
na_gconf_utils_write_int( get_gconf_client( instance ), path, value, NULL );
g_free( path );
}*/
static void
write_string( NAIPrefs *instance, const gchar *name, const gchar *value )
{
gchar *path;
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
na_gconf_utils_write_string( get_gconf_client( instance ), path, value, NULL );
g_free( path );
}
static void
......@@ -336,7 +381,7 @@ write_string_list( NAIPrefs *instance, const gchar *name, GSList *list )
{
gchar *path;
path = g_strdup_printf( "%s/%s", NA_GCONF_PREFS_PATH, name );
path = gconf_concat_dir_and_key( NA_GCONF_PREFS_PATH, name );
na_gconf_utils_write_string_list( get_gconf_client( instance ), path, list, NULL );
g_free( path );
}
......
......@@ -122,7 +122,7 @@ void na_iprefs_set_add_about_item( NAIPrefs *instance, gboolean enabled );
/* alphabetical order values
*/
enum {
PREFS_ORDER_ALPHA_ASCENDING = 0,
PREFS_ORDER_ALPHA_ASCENDING = 1,
PREFS_ORDER_ALPHA_DESCENDING,
PREFS_ORDER_MANUAL
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment