[nautilus-actions] NAIPrefs is no more an interface
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] NAIPrefs is no more an interface
- Date: Wed, 19 Jan 2011 21:52:45 +0000 (UTC)
commit 5d66fb95db946ee962fc7802440f4662df166c53
Author: Pierre <pierre vfedora13 virtuals pwi>
Date: Thu Jan 13 12:49:48 2011 +0100
NAIPrefs is no more an interface
Becomes a map/enum convertor for preferences which are store as strings
(e.g. list-order-mode, import-mode, and so on).
ChangeLog | 5 +
src/core/na-iprefs.c | 481 +++++++++++---------------------------------------
src/core/na-iprefs.h | 68 ++------
3 files changed, 115 insertions(+), 439 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3fa905c..399fa7e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -29,6 +29,11 @@
* src/utils/nautilus-actions-run.c:
* src/utils/nautilus-actions-schemas.c: Add locale.h include.
+2011-01-13 Pierre Wieser <pwieser trychlos org>
+
+ * src/core/na-iprefs.c:
+ * src/core/na-iprefs.h: NAIPrefs is no more an interface.
+
2011-01-12 Pierre Wieser <pwieser trychlos org>
* src/nact/nact-iprefs.c:
diff --git a/src/core/na-iprefs.c b/src/core/na-iprefs.c
index 2e650d3..00df17a 100644
--- a/src/core/na-iprefs.c
+++ b/src/core/na-iprefs.c
@@ -32,444 +32,161 @@
#include <config.h>
#endif
-#include <api/na-gconf-utils.h>
+#include <string.h>
+
#include <api/na-iimporter.h>
#include "na-iprefs.h"
+#include "na-settings.h"
-/* private interface data
- */
-struct _NAIPrefsInterfacePrivate {
- GConfClient *gconf;
-};
-
-#define DEFAULT_ORDER_MODE_INT IPREFS_ORDER_ALPHA_ASCENDING
-#define DEFAULT_ORDER_MODE_STR "AscendingOrder"
-
-static GConfEnumStringPair order_mode_table[] = {
- { IPREFS_ORDER_ALPHA_ASCENDING , "AscendingOrder" },
- { IPREFS_ORDER_ALPHA_DESCENDING, "DescendingOrder" },
- { IPREFS_ORDER_MANUAL , "ManualOrder" },
- { 0, NULL }
-};
-
-#define DEFAULT_IMPORT_MODE_INT IMPORTER_MODE_NO_IMPORT
-#define DEFAULT_IMPORT_MODE_STR "NoImport"
-
-static GConfEnumStringPair import_mode_table[] = {
- { IMPORTER_MODE_NO_IMPORT, DEFAULT_IMPORT_MODE_STR },
- { IMPORTER_MODE_RENUMBER, "Renumber" },
- { IMPORTER_MODE_OVERRIDE, "Override" },
- { IMPORTER_MODE_ASK, "Ask" },
- { 0, NULL }
-};
-
-static gboolean st_initialized = FALSE;
-static gboolean st_finalized = FALSE;
-
-static GType register_type( void );
-static void interface_base_init( NAIPrefsInterface *klass );
-static void interface_base_finalize( NAIPrefsInterface *klass );
-
-static void write_string( NAIPrefs *instance, const gchar *name, const gchar *value );
-
-GType
-na_iprefs_get_type( void )
-{
- static GType iface_type = 0;
-
- if( !iface_type ){
- iface_type = register_type();
- }
-
- return( iface_type );
-}
-
-static GType
-register_type( void )
-{
- static const gchar *thisfn = "na_iprefs_register_type";
- GType type;
-
- static const GTypeInfo info = {
- sizeof( NAIPrefsInterface ),
- ( GBaseInitFunc ) interface_base_init,
- ( GBaseFinalizeFunc ) interface_base_finalize,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- NULL
- };
-
- g_debug( "%s", thisfn );
-
- type = g_type_register_static( G_TYPE_INTERFACE, "NAIPrefs", &info, 0 );
-
- g_type_interface_add_prerequisite( type, G_TYPE_OBJECT );
-
- return( type );
-}
-
-static void
-interface_base_init( NAIPrefsInterface *klass )
-{
- static const gchar *thisfn = "na_iprefs_interface_base_init";
-
- if( !st_initialized ){
-
- g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
-
- klass->private = g_new0( NAIPrefsInterfacePrivate, 1 );
-
- klass->private->gconf = gconf_client_get_default();
-
- st_initialized = TRUE;
- }
-}
-
-static void
-interface_base_finalize( NAIPrefsInterface *klass )
-{
- static const gchar *thisfn = "na_iprefs_interface_base_finalize";
-
- if( !st_finalized ){
-
- g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
-
- st_finalized = TRUE;
-
- g_object_unref( klass->private->gconf );
-
- g_free( klass->private );
- }
+typedef struct {
+ guint id;
+ const gchar *str;
}
+ EnumMap;
-/*
- * na_iprefs_get_order_mode:
- * @instance: this #NAIPrefs interface instance.
- *
- * Returns: the order mode currently set.
- *
- * 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.
+/* import mode: what to do when the imported id already exists ?
+ * enum is defined in api/na-iimporter.h
*/
-gint
-na_iprefs_get_order_mode( NAIPrefs *instance )
-{
- gint alpha_order = DEFAULT_ORDER_MODE_INT;
- gint order_int;
- gchar *order_str;
-
- g_return_val_if_fail( NA_IS_IPREFS( instance ), DEFAULT_ORDER_MODE_INT );
-
- if( st_initialized && !st_finalized ){
-
- order_str = na_iprefs_read_string(
- instance,
- IPREFS_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 );
-}
+#define IMPORT_MODE_NOIMPORT_STR "NoImport"
+#define IMPORT_MODE_RENUMBER_STR "Renumber"
+#define IMPORT_MODE_OVERRIDE_STR "Override"
+#define IMPORT_MODE_ASK_STR "Ask"
+
+static EnumMap st_import_mode[] = {
+ { IMPORTER_MODE_NO_IMPORT, IMPORT_MODE_NOIMPORT_STR },
+ { IMPORTER_MODE_RENUMBER, IMPORT_MODE_RENUMBER_STR },
+ { IMPORTER_MODE_OVERRIDE, IMPORT_MODE_OVERRIDE_STR },
+ { IMPORTER_MODE_ASK, IMPORT_MODE_ASK_STR },
+ { 0 }
+};
-/*
- * na_iprefs_set_order_mode:
- * @instance: this #NAIPrefs interface instance.
- * @mode: the new value to be written.
- *
- * Writes the current status of 'alphabetical order' to the GConf
- * preference system.
+/* sort mode of the items in the file manager context menu
+ * enum is defined in core/na-iprefs.h
*/
-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 ){
+#define ORDER_ALPHA_ASC_STR "AscendingOrder"
+#define ORDER_ALPHA_DESC_STR "DescendingOrder"
+#define ORDER_MANUAL_STR "ManualOrder"
+
+static EnumMap st_order_mode[] = {
+ { IPREFS_ORDER_ALPHA_ASCENDING, ORDER_ALPHA_ASC_STR },
+ { IPREFS_ORDER_ALPHA_DESCENDING, ORDER_ALPHA_DESC_STR },
+ { IPREFS_ORDER_MANUAL, ORDER_MANUAL_STR },
+ { 0 }
+};
- order_str = gconf_enum_to_string( order_mode_table, mode );
-
- write_string(
- instance,
- IPREFS_DISPLAY_ALPHABETICAL_ORDER,
- order_str ? order_str : DEFAULT_ORDER_MODE_STR );
- }
-}
+static const gchar *enum_map_string_from_id( const EnumMap *map, guint id );
+static guint enum_map_id_from_string( const EnumMap *map, const gchar *str );
/*
* na_iprefs_get_import_mode:
- * @gconf: a #GCongClient client.
- * @pref: name of the import key to be readen
- *
- * Returns: the import mode currently set.
+ * @pivot: the #NAPivot application object.
+ * @pref: name of the import key to be readen.
*
- * Note: this function returns a suitable default value even if the key
- * is not found in GConf preferences or no schema has been installed.
+ * This preference defines what to do when an imported item has the same
+ * identifier that an already existing one. Default value is defined in
+ * core/na-settings.h.
*
- * Note: please take care of keeping the default value synchronized with
- * those defined in schemas.
+ * Returns: the import mode currently set.
*/
guint
-na_iprefs_get_import_mode( GConfClient *gconf, const gchar *pref )
+na_iprefs_get_import_mode( const NAPivot *pivot, const gchar *pref )
{
- gint import_mode = DEFAULT_IMPORT_MODE_INT;
- gint import_int;
- gchar *import_str;
- gchar *path;
-
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, pref );
-
- import_str = na_gconf_utils_read_string(
- gconf,
- path,
- TRUE,
- DEFAULT_IMPORT_MODE_STR );
-
- if( gconf_string_to_enum( import_mode_table, import_str, &import_int )){
- import_mode = import_int;
- }
+ gchar *import_mode_str;
+ guint import_mode;
+ NASettings *settings;
- g_free( import_str );
- g_free( path );
+ settings = na_pivot_get_settings( pivot );
+ import_mode_str = na_settings_get_string( settings, pref, NULL, NULL );
+ import_mode = enum_map_id_from_string( st_import_mode, import_mode_str );
+ g_free( import_mode_str );
return( import_mode );
}
/*
* na_iprefs_set_import_mode:
- * @gconf: a #GCongClient client.
- * @pref: name of the import key to be written
+ * @pivot: the #NAPivot application object.
+ * @pref: name of the import key to be written.
* @mode: the new value to be written.
*
- * Writes the current status of 'import mode' to the GConf
- * preference system.
+ * Writes the current status of 'import mode' to the preferences system.
*/
void
-na_iprefs_set_import_mode( GConfClient *gconf, const gchar *pref, guint mode )
+na_iprefs_set_import_mode( const NAPivot *pivot, const gchar *pref, guint mode )
{
const gchar *import_str;
- gchar *path;
-
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, pref );
-
- import_str = gconf_enum_to_string( import_mode_table, mode );
+ NASettings *settings;
- na_gconf_utils_write_string(
- gconf,
- path,
- import_str ? import_str : DEFAULT_IMPORT_MODE_STR,
- NULL );
-
- g_free( path );
+ settings = na_pivot_get_settings( pivot );
+ import_str = enum_map_string_from_id( st_import_mode, mode );
+ na_settings_set_string( settings, pref, import_str );
}
/*
- * na_iprefs_get_gconf_client:
- * @instance: this #NAIPrefs interface instance.
- *
- * Returns: a GConfClient object.
- */
-GConfClient *
-na_iprefs_get_gconf_client( const NAIPrefs *instance )
-{
- GConfClient *client;
-
- g_return_val_if_fail( NA_IS_IPREFS( instance ), NULL );
-
- client = NULL;
-
- if( st_initialized && !st_finalized ){
-
- client = NA_IPREFS_GET_INTERFACE( instance )->private->gconf;
- }
-
- return( client );
-}
-
-/*
- * na_iprefs_read_bool:
- * @instance: this #NAIPrefs interface instance.
- * @key: the name of the preference entry.
- * @default_value: default value to be returned if the entry is not found,
- * no default value is available in the schema, of there is no schema at all.
+ * na_iprefs_get_order_mode:
+ * @pivot: the #NAPivot application object.
*
- * Returns: the boolean value.
+ * Returns: the order mode currently set.
*/
-gboolean
-na_iprefs_read_bool( const NAIPrefs *instance, const gchar *key, gboolean default_value )
+gint
+na_iprefs_get_order_mode( const NAPivot *pivot )
{
- gchar *path;
- gboolean ret;
-
- g_return_val_if_fail( NA_IS_IPREFS( instance ), FALSE );
+ gchar *order_mode_str;
+ guint order_mode;
+ NASettings *settings;
- ret = FALSE;
+ settings = na_pivot_get_settings( pivot );
+ order_mode_str = na_settings_get_string( settings, NA_IPREFS_ITEMS_LIST_ORDER_MODE, NULL, NULL );
+ order_mode = enum_map_id_from_string( st_order_mode, order_mode_str );
+ g_free( order_mode_str );
- if( st_initialized && !st_finalized ){
-
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, key );
- ret = na_gconf_utils_read_bool( na_iprefs_get_gconf_client( instance ), path, TRUE, default_value );
- g_free( path );
- }
-
- return( ret );
+ return( order_mode );
}
/*
- * na_iprefs_read_string:
- * @instance: this #NAIPrefs interface instance.
- * @key: the preference key.
- * @default_value: the default value, used if entry is not found and
- * there is no schema.
+ * na_iprefs_set_order_mode:
+ * @pivot: the #NAPivot application object.
+ * @mode: the new value to be written.
*
- * Returns: the value, as a newly allocated string which should be
- * g_free() by the caller.
+ * Writes the current status of 'alphabetical order' to the GConf
+ * preference system.
*/
-gchar *
-na_iprefs_read_string( const NAIPrefs *instance, const gchar *key, const gchar *default_value )
+void
+na_iprefs_set_order_mode( const NAPivot *pivot, gint mode )
{
- gchar *path;
- gchar *value;
-
- g_return_val_if_fail( NA_IS_IPREFS( instance ), NULL );
-
- value = NULL;
-
- if( st_initialized && !st_finalized ){
-
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, key );
- value = na_gconf_utils_read_string( na_iprefs_get_gconf_client( instance ), path, TRUE, default_value );
- g_free( path );
- }
+ const gchar *order_str;
+ NASettings *settings;
- return( value );
+ settings = na_pivot_get_settings( pivot );
+ order_str = enum_map_string_from_id( st_order_mode, mode );
+ na_settings_set_string( settings, NA_IPREFS_ITEMS_LIST_ORDER_MODE, order_str );
}
-/*
- * na_iprefs_read_string_list:
- * @instance: this #NAIPrefs interface instance.
- * @key: the preference key.
- * @default_value: a default value, used if entry is not found, or there
- * is no default value in the schema, of there is no schema at all.
- *
- * Returns: the list value, which should be na_utils_free_string_list()
- * by the caller.
- */
-GSList *
-na_iprefs_read_string_list( const NAIPrefs *instance, const gchar *key, const gchar *default_value )
+static const gchar *
+enum_map_string_from_id( const EnumMap *map, guint id )
{
- gchar *path;
- GSList *list;
-
- g_return_val_if_fail( NA_IS_IPREFS( instance ), NULL );
-
- list = NULL;
+ const EnumMap *i = map;
- if( st_initialized && !st_finalized ){
-
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, key );
- list = na_gconf_utils_read_string_list( na_iprefs_get_gconf_client( instance ), path );
- g_free( path );
-
- if(( !list || !g_slist_length( list )) && default_value ){
- g_slist_free( list );
- list = g_slist_append( NULL, g_strdup( default_value ));
+ while( i->id ){
+ if( i->id == id ){
+ return( i->str );
}
+ i++;
}
-
- return( list );
+ return( map->str );
}
-/*
- * na_iprefs_read_uint:
- * @instance: this #NAIPrefs interface instance.
- * @key: the preference entry.
- * @default_value: the value to be returned if the key is not found.
- *
- * Returns: the uint value associated with the given key.
- */
-guint
-na_iprefs_read_uint( const NAIPrefs *instance, const gchar *key, guint default_value )
+static guint
+enum_map_id_from_string( const EnumMap *map, const gchar *str )
{
- guint value;
- gchar *path;
-
- g_return_val_if_fail( NA_IS_IPREFS( instance ), 0 );
-
- value = 0;
-
- if( st_initialized && !st_finalized ){
+ const EnumMap *i = map;
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, key );
- value = na_gconf_utils_read_int( na_iprefs_get_gconf_client( instance ), path, TRUE, default_value );
- g_free( path );
- }
-
- return( value );
-}
-
-/*
- * na_iprefs_write_string:
- * @instance: this #NAIPrefs interface instance.
- * @name: the preference key.
- * @value: the value to be written.
- *
- * Writes the value as the given GConf preference.
- */
-static void
-write_string( NAIPrefs *instance, const gchar *name, const gchar *value )
-{
- gchar *path;
-
- g_return_if_fail( NA_IS_IPREFS( instance ));
-
- if( st_initialized && !st_finalized ){
-
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, name );
- na_gconf_utils_write_string( na_iprefs_get_gconf_client( instance ), path, value, NULL );
- g_free( path );
- }
-}
-
-/*
- * na_iprefs_write_string_list
- * @instance: this #NAIPrefs interface instance.
- * @key: the preference key.
- * @value: the value to be written.
- *
- * Writes the value as the given GConf preference.
- *
- * Returns: %TRUE if the string list has been successfully written,
- * %FALSE else.
- */
-gboolean
-na_iprefs_write_string_list( const NAIPrefs *instance, const gchar *key, GSList *value )
-{
- gboolean ret = FALSE;
- gchar *path;
-
- g_return_val_if_fail( NA_IS_IPREFS( instance ), FALSE );
-
- if( st_initialized && !st_finalized ){
-
- path = gconf_concat_dir_and_key( IPREFS_GCONF_PREFS_PATH, key );
- ret = na_gconf_utils_write_string_list( na_iprefs_get_gconf_client( instance ), path, value, NULL );
- g_free( path );
+ while( i->id ){
+ if( !strcmp( i->str == str )){
+ return( i->id );
+ }
+ i++;
}
-
- return( ret );
+ return( map->id );
}
diff --git a/src/core/na-iprefs.h b/src/core/na-iprefs.h
index ca72949..93400fd 100644
--- a/src/core/na-iprefs.h
+++ b/src/core/na-iprefs.h
@@ -64,75 +64,29 @@
* It the user didn't have defined a root submenu, whether in the NACT
* user interface or by choosing the ad-hoc preference, the plugin
* doesn't provides one, and the 'About' item will not be displayed.
+ *
+ * Starting with 3.1.0, NAIPrefs interface is deprecated.
+ * Instead, this file implements all maps needed to transform an enum
+ * used in the code to and from a string stored in preferences.
*/
-#include <glib-object.h>
-#include <gconf/gconf-client.h>
+#include "na-pivot.h"
G_BEGIN_DECLS
-#define NA_IPREFS_TYPE ( na_iprefs_get_type())
-#define NA_IPREFS( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, NA_IPREFS_TYPE, NAIPrefs ))
-#define NA_IS_IPREFS( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, NA_IPREFS_TYPE ))
-#define NA_IPREFS_GET_INTERFACE( instance ) ( G_TYPE_INSTANCE_GET_INTERFACE(( instance ), NA_IPREFS_TYPE, NAIPrefsInterface ))
-
-typedef struct _NAIPrefs NAIPrefs;
-
-typedef struct _NAIPrefsInterfacePrivate NAIPrefsInterfacePrivate;
-
-typedef struct {
- /*< private >*/
- GTypeInterface parent;
- NAIPrefsInterfacePrivate *private;
-}
- NAIPrefsInterface;
-
-/* GConf Preference keys managed by IPrefs interface
- */
-#define IPREFS_GCONF_BASEDIR "/apps/nautilus-actions"
-#define IPREFS_GCONF_PREFERENCES "preferences"
-#define IPREFS_GCONF_PREFS_PATH IPREFS_GCONF_BASEDIR "/" IPREFS_GCONF_PREFERENCES
-
-#define IPREFS_LEVEL_ZERO_ITEMS "iprefs-level-zero"
-#define IPREFS_DISPLAY_ALPHABETICAL_ORDER "iprefs-alphabetical-order"
-#define IPREFS_CREATE_ROOT_MENU "iprefs-create-root-menu"
-#define IPREFS_ADD_ABOUT_ITEM "iprefs-add-about-item"
-
-#define IPREFS_RELABEL_MENUS "iprefs-relabel-menus"
-#define IPREFS_RELABEL_ACTIONS "iprefs-relabel-actions"
-#define IPREFS_RELABEL_PROFILES "iprefs-relabel-profiles"
-
-#define IPREFS_IMPORT_ITEMS_IMPORT_MODE "import-mode"
-#define IPREFS_IMPORT_KEEP_CHOICE "import-keep-choice"
-#define IPREFS_IMPORT_ASK_LAST_MODE "import-ask-user-last-mode"
-
-#define IPREFS_AUTOSAVE_ON "auto-save-on"
-#define IPREFS_AUTOSAVE_PERIOD "auto-save-period"
-
-/* alphabetical order values
+/* sort mode of the items in the file manager context menu
*/
enum {
- IPREFS_ORDER_ALPHA_ASCENDING = 1,
+ IPREFS_ORDER_ALPHA_ASCENDING = 1, /* default */
IPREFS_ORDER_ALPHA_DESCENDING,
IPREFS_ORDER_MANUAL
};
-GType na_iprefs_get_type( void );
-
-gint na_iprefs_get_order_mode ( NAIPrefs *instance );
-void na_iprefs_set_order_mode ( NAIPrefs *instance, gint mode );
-
-guint na_iprefs_get_import_mode ( GConfClient *gconf, const gchar *pref );
-void na_iprefs_set_import_mode ( GConfClient *gconf, const gchar *pref, guint mode );
-
-GConfClient *na_iprefs_get_gconf_client ( const NAIPrefs *instance );
-
-gboolean na_iprefs_read_bool ( const NAIPrefs *instance, const gchar *key, gboolean default_value );
-gchar *na_iprefs_read_string ( const NAIPrefs *instance, const gchar *key, const gchar *default_value );
-GSList *na_iprefs_read_string_list ( const NAIPrefs *instance, const gchar *key, const gchar *default_value );
-guint na_iprefs_read_uint ( const NAIPrefs *instance, const gchar *key, guint defaut_value );
+guint na_iprefs_get_import_mode( const NAPivot *pivot, const gchar *pref );
+void na_iprefs_set_import_mode( const NAPivot *pivot, const gchar *pref, guint mode );
-gboolean na_iprefs_write_string_list( const NAIPrefs *instance, const gchar *key, GSList *value );
+guint na_iprefs_get_order_mode ( const NAPivot *pivot );
+void na_iprefs_set_order_mode ( const NAPivot *pivot, gint mode );
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]