[nautilus-actions] Import mode preference is now stored as a GConf string



commit 5b105457805a36e8d03c9d76559fc63a106bee24
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Sep 30 21:50:39 2009 +0200

    Import mode preference is now stored as a GConf string

 ChangeLog                        |    8 ++++
 data/nautilus-actions.schemas.in |   12 +++---
 src/common/na-iprefs.c           |   77 ++++++++++++++++++++++++-------------
 src/common/na-iprefs.h           |    3 +
 src/nact/nact-assistant-import.c |   65 ++++++++++++++++++++++++++++++-
 5 files changed, 129 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 21bc5a0..c95a848 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
 	* data/nautilus-actions.schemas.in:
 	Order mode preference is now a string to let the GConf edition
 	be more user friendly.
+	Import mode: idem.
 
 	* src/common/na-gconf-utils.c:
 	* src/common/na-gconf-utils.h (na_gconf_utils_read_string):
@@ -11,6 +12,10 @@
 	* src/common/na-iprefs.c:
 	Define order_mode_table to convert internal mode to GConf string.
 
+	* src/common/na-iprefs.c:
+	* src/common/na-iprefs.c
+	(na_iprefs_read_string, na_iprefs_write_string): New functions.
+
 	* 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
@@ -21,6 +26,9 @@
 	* src/nact/nact-main-menubar.c:
 	* src/nact/nact-main-window.c: Updated accordingly.
 
+	* src/nact/nact-assistant-import.c:
+	Import mode preference is now stored as a string.
+
 	* src/plugin/nautilus-actions.c:
 	Builds a hierachical menu for Nautilus context menu.
 
diff --git a/data/nautilus-actions.schemas.in b/data/nautilus-actions.schemas.in
index 9790021..5eb5ba4 100644
--- a/data/nautilus-actions.schemas.in
+++ b/data/nautilus-actions.schemas.in
@@ -303,10 +303,10 @@ All schemes used by Nautilus can be used here.</long>
       <type>int</type>
       <locale name="C">
         <short>Import mode</short>
-        <long>Last import mode choosen in the Import assistant. Possible values are:
-1: do not import an action whose UUID already exists
-2: allocate a new UUID if the imported UUID already exists
-3: override the existing action with the imported one.</long>
+        <long>Last import mode choosen in the Import assistant. Possible values are :
+- "NoImport": do not import an action whose UUID already exists,
+- "Renumber": allocate a new UUID if the imported UUID already exists,
+- "Override": override the existing action with the imported one.</long>
       </locale>
       <default>/tmp</default>
     </schema>
@@ -329,8 +329,8 @@ All schemes used by Nautilus can be used here.</long>
       <locale name="C">
         <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.
+- "AscendingOrder": the actions are maintained in ascending alphabetical order (historical behavior).
+- "DescendingOrder": 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>
diff --git a/src/common/na-iprefs.c b/src/common/na-iprefs.c
index 9fd9216..8fa9224 100644
--- a/src/common/na-iprefs.c
+++ b/src/common/na-iprefs.c
@@ -71,11 +71,9 @@ 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 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_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 );
@@ -216,7 +214,10 @@ na_iprefs_get_order_mode( NAIPrefs *instance )
 	if( st_initialized && !st_finalized ){
 
 		setup_private_data( instance );
-		order_str = read_string( instance, PREFS_DISPLAY_ALPHABETICAL_ORDER, DEFAULT_ORDER_MODE_STR );
+		order_str = na_iprefs_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;
 		}
@@ -242,9 +243,13 @@ na_iprefs_set_order_mode( NAIPrefs *instance, gint mode )
 	g_return_if_fail( NA_IS_IPREFS( instance ));
 
 	if( st_initialized && !st_finalized ){
+
 		setup_private_data( instance );
 		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 );
+		na_iprefs_write_string(
+				instance,
+				PREFS_DISPLAY_ALPHABETICAL_ORDER,
+				order_str ? order_str : DEFAULT_ORDER_MODE_STR );
 	}
 }
 
@@ -294,6 +299,47 @@ na_iprefs_set_add_about_item( NAIPrefs *instance, gboolean enabled )
 	}
 }
 
+/**
+ * na_iprefs_read_string:
+ * @instance: this #NAIPrefs interface instance.
+ * @name: the preference key.
+ * @default_value: the default value, used if entry is not found and
+ * there is no schema.
+ *
+ * Returns: the value, as a newly allocated string which should be
+ * g_free() by the caller.
+ */
+gchar *
+na_iprefs_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 );
+}
+
+/**
+ * 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.
+ */
+void
+na_iprefs_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 gboolean
 read_bool( NAIPrefs *instance, const gchar *name, gboolean default_value )
 {
@@ -320,19 +366,6 @@ read_int( NAIPrefs *instance, const gchar *name, gint default_value )
 	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 *
 read_string_list( NAIPrefs *instance, const gchar *name )
 {
@@ -367,16 +400,6 @@ write_int( NAIPrefs *instance, const gchar *name, gint value )
 }*/
 
 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
 write_string_list( NAIPrefs *instance, const gchar *name, GSList *list )
 {
 	gchar *path;
diff --git a/src/common/na-iprefs.h b/src/common/na-iprefs.h
index 0dfbb0a..3054114 100644
--- a/src/common/na-iprefs.h
+++ b/src/common/na-iprefs.h
@@ -108,6 +108,9 @@ void     na_iprefs_set_order_mode( NAIPrefs *instance, gint mode );
 gboolean na_iprefs_should_add_about_item( NAIPrefs *instance );
 void     na_iprefs_set_add_about_item( NAIPrefs *instance, gboolean enabled );
 
+gchar   *na_iprefs_read_string( NAIPrefs *instance, const gchar *key, const gchar *default_value );
+void     na_iprefs_write_string( NAIPrefs *instance, const gchar *key, const gchar *value );
+
 /* GConf key
  */
 #define NA_GCONF_PREFERENCES				"preferences"
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index 07df74d..537cd0f 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -32,6 +32,7 @@
 #include <config.h>
 #endif
 
+#include <gconf/gconf.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <string.h>
@@ -39,10 +40,12 @@
 #include <common/na-object-api.h>
 #include <common/na-object-action-class.h>
 #include <common/na-iio-provider.h>
+#include <common/na-iprefs.h>
+#include <common/na-pivot.h>
 #include <common/na-utils.h>
 
 #include "base-iprefs.h"
-#include "base-application.h"
+#include "nact-application.h"
 #include "nact-iactions-list.h"
 #include "nact-assistant-import.h"
 #include "nact-xml-reader.h"
@@ -90,6 +93,16 @@ struct NactAssistantImportPrivate {
 #define IPREFS_IMPORT_ACTIONS_FOLDER_URI		"import-folder-uri"
 #define IPREFS_IMPORT_ACTIONS_IMPORT_MODE		"import-mode"
 
+#define DEFAULT_IMPORT_MODE_INT					NO_IMPORT_MODE
+#define DEFAULT_IMPORT_MODE_STR					"NoImport"
+
+static GConfEnumStringPair import_mode_table[] = {
+	{ NO_IMPORT_MODE, "NoImport" },
+	{ RENUMBER_MODE , "Renumber" },
+	{ OVERRIDE_MODE , "Override" },
+	{ 0, NULL }
+};
+
 static BaseAssistantClass *st_parent_class = NULL;
 
 static GType    register_type( void );
@@ -110,6 +123,8 @@ static void     on_file_selection_changed( GtkFileChooser *chooser, gpointer use
 static gboolean has_readable_files( GSList *uris );
 static void     runtime_init_duplicates( NactAssistantImport *window, GtkAssistant *assistant );
 static void     set_import_mode( NactAssistantImport *window, gint mode );
+static gint     get_pref_import_mode( NactAssistantImport *window );
+static void     set_pref_import_mode( NactAssistantImport *window, gint mode );
 
 static void     assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page );
 static void     prepare_confirm( NactAssistantImport *window, GtkAssistant *assistant, GtkWidget *page );
@@ -449,7 +464,7 @@ runtime_init_duplicates( NactAssistantImport *window, GtkAssistant *assistant )
 
 	g_debug( "%s: window=%p", thisfn, ( void * ) window );
 
-	mode = base_iprefs_get_int( BASE_WINDOW( window ), IPREFS_IMPORT_ACTIONS_IMPORT_MODE );
+	mode = get_pref_import_mode( window );
 	set_import_mode( window, mode );
 
 	page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_DUPLICATES );
@@ -480,6 +495,50 @@ set_import_mode( NactAssistantImport *window, gint mode )
 	}
 }
 
+static gint
+get_pref_import_mode( NactAssistantImport *window )
+{
+	gint import_mode = DEFAULT_IMPORT_MODE_INT;
+	NactApplication *application;
+	NAPivot *pivot;
+	gchar *mode_str;
+	gint mode_int;
+
+	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	pivot = nact_application_get_pivot( application );
+
+	mode_str = na_iprefs_read_string(
+			NA_IPREFS( pivot ),
+			IPREFS_IMPORT_ACTIONS_IMPORT_MODE,
+			DEFAULT_IMPORT_MODE_STR );
+
+	if( gconf_string_to_enum( import_mode_table, mode_str, &mode_int )){
+		import_mode = mode_int;
+	}
+
+	g_free( mode_str );
+
+	return( import_mode );
+}
+
+static void
+set_pref_import_mode( NactAssistantImport *window, gint mode )
+{
+	NactApplication *application;
+	NAPivot *pivot;
+	const gchar *mode_str;
+
+	mode_str = gconf_enum_to_string( import_mode_table, mode );
+
+	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	pivot = nact_application_get_pivot( application );
+
+	na_iprefs_write_string(
+			NA_IPREFS( pivot ),
+			IPREFS_IMPORT_ACTIONS_IMPORT_MODE,
+			mode_str ? mode_str : DEFAULT_IMPORT_MODE_STR );
+}
+
 static void
 assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page )
 {
@@ -724,7 +783,7 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 	g_free( text );
 
 	mode = get_import_mode( window );
-	base_iprefs_set_int( BASE_WINDOW( window ), IPREFS_IMPORT_ACTIONS_IMPORT_MODE, mode );
+	set_pref_import_mode( window, mode );
 
 	gtk_assistant_set_page_complete( assistant, page, TRUE );
 	base_assistant_set_warn_on_cancel( BASE_ASSISTANT( window ), FALSE );



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