[nautilus-actions] na_iprefs_get_import_mode(): removed function



commit e4d290a8bf8788ae0dde99b0613711f6feb52276
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Jan 4 23:06:19 2012 +0100

    na_iprefs_get_import_mode(): removed function
    
    + NAIImporterImportMode enum is now deprecated, and moved as NAImporterImportMode to (internal) na-importer.h
    + NAImporterParms now accepts a nul preferred import mode, defaulting to NA_IPREFS_IMPORT_PREFERRED_MODE.

 ChangeLog                      |   10 ++++++
 src/api/na-iimporter.h         |    4 ++
 src/core/na-importer.c         |   61 +++++++++++++++++++++++++++++----------
 src/core/na-importer.h         |   48 +++++++++++++++++++++++++------
 src/core/na-iprefs.c           |   27 +-----------------
 src/core/na-iprefs.h           |    1 -
 src/nact/nact-tree-model-dnd.c |    3 +-
 7 files changed, 100 insertions(+), 54 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5c21aeb..2ce3e08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2012-01-04 Pierre Wieser <pwieser trychlos org>
 
+	* src/api/na-iimporter.h: Deprecate NAIImporterImportMode enum.
+
+	* src/core/na-importer.h: Define new NAImporterImportMode enum here.
+
+	* src/core/na-importer.c (ask_user_for_mode):
+	* src/core/na-iprefs.c:
+	* src/core/na-iprefs.h:
+	* src/nact/nact-tree-model-dnd.c:
+	Get ride of na_iprefs_get_import_mode() function.
+
 	Review interface initialization in implementations.
 
 	* src/core/na-export-format.c (ioption_iface_init):
diff --git a/src/api/na-iimporter.h b/src/api/na-iimporter.h
index fac7f28..f12f468 100644
--- a/src/api/na-iimporter.h
+++ b/src/api/na-iimporter.h
@@ -153,6 +153,7 @@ typedef struct {
 }
 	NAIImporterInterface;
 
+#ifdef NA_ENABLE_DEPRECATED
 /**
  * NAIImporterImportMode:
  * @IMPORTER_MODE_NO_IMPORT: a "do not import" mode.
@@ -161,6 +162,8 @@ typedef struct {
  * @IMPORTER_MODE_ASK:       ask the user for what to do with this particular item.
  *
  * Define the mode of an import operation.
+ *
+ * Deprecated: 3.2
  */
 typedef enum {
 	IMPORTER_MODE_NO_IMPORT = 1,
@@ -169,6 +172,7 @@ typedef enum {
 	IMPORTER_MODE_ASK
 }
 	NAIImporterImportMode;
+#endif
 
 /**
  * NAIImporterImportStatus:
diff --git a/src/core/na-importer.c b/src/core/na-importer.c
index 5595ca4..65f40d3 100644
--- a/src/core/na-importer.c
+++ b/src/core/na-importer.c
@@ -39,29 +39,23 @@
 #include <api/na-iimporter.h>
 #include <api/na-object-api.h>
 
-#include "na-iprefs.h"
 #include "na-import-mode.h"
 #include "na-importer.h"
 #include "na-importer-ask.h"
 
 typedef struct {
-	guint  id;
-	gchar *mode;
-	gchar *label;
-	gchar *description;
-	gchar *image;
+	guint        id;				/* the import mode used in switch statement in the code */
+	const gchar *mode;				/* the import mode saved in user's preferences */
+	const gchar *label;				/* short label */
+	const gchar *description;		/* full description */
+	gchar       *image;				/* associated image */
 }
 	NAImportModeStr;
 
-#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 NAImportModeStr st_import_modes[] = {
 
 	{ IMPORTER_MODE_NO_IMPORT,
-			IMPORT_MODE_NOIMPORT_STR,
+			"NoImport",
 			N_( "Do _not import the item" ),
 			N_( "This used to be the historical behavior.\n" \
 				"The selected file will be marked as \"NOT OK\" in the Summary page.\n" \
@@ -69,7 +63,7 @@ static NAImportModeStr st_import_modes[] = {
 			"import-mode-no-import.png" },
 
 	{ IMPORTER_MODE_RENUMBER,
-			IMPORT_MODE_RENUMBER_STR,
+			"Renumber",
 			N_( "Import the item, _allocating it a new identifier" ),
 			N_( "The selected file will be imported with a slightly modified label " \
 				"indicating the renumbering.\n" \
@@ -77,7 +71,7 @@ static NAImportModeStr st_import_modes[] = {
 			"import-mode-renumber.png" },
 
 	{ IMPORTER_MODE_OVERRIDE,
-			IMPORT_MODE_OVERRIDE_STR,
+			"Override",
 			N_( "_Override the existing item" ),
 			N_( "The item found in the selected file will silently override the " \
 				"current one which has the same identifier.\n" \
@@ -90,7 +84,7 @@ static NAImportModeStr st_import_modes[] = {
 static NAImportModeStr st_import_ask_mode = {
 
 	IMPORTER_MODE_ASK,
-			IMPORT_MODE_ASK_STR,
+			"Ask",
 			N_( "_Ask me" ),
 			N_( "You will be asked each time an imported ID already exists." ),
 			"import-mode-ask.png"
@@ -101,6 +95,7 @@ static void              manage_import_mode( NAImporterParms *parms, GList *resu
 static NAObjectItem     *is_importing_already_exists( NAImporterParms *parms, GList *results, NAImporterResult *result );
 static void              renumber_label_item( NAObjectItem *item );
 static guint             ask_user_for_mode( const NAObjectItem *importing, const NAObjectItem *existing, NAImporterAskUserParms *parms );
+static guint             get_id_from_string( const gchar *str );
 static NAIOption        *get_mode_from_struct( const NAImportModeStr *str );
 
 /* i18n: '%s' stands for the file URI */
@@ -140,6 +135,7 @@ na_importer_import_from_uris( const NAPivot *pivot, NAImporterParms *parms )
 	GSList *uri;
 	NAImporterResult *import_result;
 	NAImporterAskUserParms ask_parms;
+	gchar *mode_str;
 
 	g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
 	g_return_val_if_fail( parms != NULL, NULL );
@@ -167,6 +163,14 @@ na_importer_import_from_uris( const NAPivot *pivot, NAImporterParms *parms )
 	ask_parms.keep_choice = FALSE;
 	ask_parms.pivot = pivot;
 
+	/* set the default import mode
+	 */
+	if( !parms->preferred_mode ){
+		mode_str = na_settings_get_string( NA_IPREFS_IMPORT_PREFERRED_MODE, NULL, NULL );
+		parms->preferred_mode = get_id_from_string( mode_str );
+		g_free( mode_str );
+	}
+
 	/* second phase: check for their pre-existence
 	 */
 	for( ires = results ; ires ; ires = ires->next ){
@@ -420,17 +424,42 @@ static guint
 ask_user_for_mode( const NAObjectItem *importing, const NAObjectItem *existing, NAImporterAskUserParms *parms )
 {
 	guint mode;
+	gchar *mode_str;
 
 	if( parms->count == 0 || !parms->keep_choice ){
 		mode = na_importer_ask_user( importing, existing, parms );
 
 	} else {
-		mode = na_iprefs_get_import_mode( NA_IPREFS_IMPORT_ASK_USER_LAST_MODE, NULL );
+		mode_str = na_settings_get_string( NA_IPREFS_IMPORT_ASK_USER_LAST_MODE, NULL, NULL );
+		mode = get_id_from_string( mode_str );
+		g_free( mode_str );
 	}
 
 	return( mode );
 }
 
+static guint
+get_id_from_string( const gchar *str )
+{
+	int i;
+
+	/* search in standard import modes
+	 */
+	for( i = 0 ; st_import_modes[i].id ; ++i ){
+		if( !strcmp( st_import_modes[i].mode, str )){
+			return( st_import_modes[i].id );
+		}
+	}
+
+	/* else, is it ask option ?
+	 */
+	if( !strcmp( st_import_ask_mode.mode, str )){
+		return( st_import_ask_mode.id );
+	}
+
+	return( 0 );
+}
+
 /*
  * na_importer_get_modes:
  *
diff --git a/src/core/na-importer.h b/src/core/na-importer.h
index 808abff..fc64492 100644
--- a/src/core/na-importer.h
+++ b/src/core/na-importer.h
@@ -66,6 +66,32 @@
 
 G_BEGIN_DECLS
 
+#ifndef NA_ENABLE_DEPRECATED
+/*
+ * NAImporterImportMode:
+ * @IMPORTER_MODE_NO_IMPORT: a "do not import" mode.
+ * @IMPORTER_MODE_RENUMBER:  reallocate a new id when the imported one already exists.
+ * @IMPORTER_MODE_OVERRIDE:  override the existing id with the imported one.
+ * @IMPORTER_MODE_ASK:       ask the user for what to do with this particular item.
+ *
+ * Define the mode of an import operation.
+ *
+ * Since: 3.2
+ *
+ * This same enum used to be defined as NAIImporterImportMode in api/na-iimporter.h
+ * header. The enum has been deprecated there in N-A 3.2 when the NAIImporter v2
+ * interface was defined. It has so been moved here with the NAImporterImportMode
+ * name.
+ */
+typedef enum {
+	IMPORTER_MODE_NO_IMPORT = 1,
+	IMPORTER_MODE_RENUMBER,
+	IMPORTER_MODE_OVERRIDE,
+	IMPORTER_MODE_ASK
+}
+	NAImporterImportMode;
+#endif
+
 /*
  * NAImporterCheckFn:
  * @imported: the currently imported #NAObjectItem -derived object.
@@ -95,20 +121,24 @@ typedef struct {
 	GSList             *uris;				/* the list of uris to import */
 	NAImporterCheckFn   check_fn;			/* the check_for_duplicate function */
 	void               *check_fn_data;		/* data to be passed to the check_fn function */
-	guint               preferred_mode;		/* preferred import mode */
+	guint               preferred_mode;		/* preferred import mode, defaults to NA_IPREFS_IMPORT_PREFERRED_MODE */
 	GtkWindow          *parent_toplevel;	/* parent toplevel */
 }
 	NAImporterParms;
 
 typedef struct {
-		/* phase 1: import into memory */
-	gchar             *uri;					/* the imported uri */
-	NAObjectItem      *imported;			/* the imported NAObjectItem-derived object, or %NULL */
-	NAIImporter       *importer;			/* the importer module, or %NULL */
-		/* phase 2: check for pre-existence */
-	gboolean           exist;				/* whether the imported Id already existed */
-	guint              mode;				/* the actual mode in effect for this import */
-	GSList            *messages;			/* a #GSList list of localized strings */
+
+	/* phase 1: import into memory from i/o provider
+	 */
+	gchar        *uri;					/* the imported uri */
+	NAObjectItem *imported;				/* the imported NAObjectItem-derived object, or %NULL */
+	NAIImporter  *importer;				/* the importer module, or %NULL */
+
+	/* phase 2: check for pre-existence
+	 */
+	gboolean      exist;				/* whether the imported Id already existed */
+	guint         mode;					/* the actual mode in effect for this import */
+	GSList       *messages;				/* a #GSList list of localized strings */
 }
 	NAImporterResult;
 
diff --git a/src/core/na-iprefs.c b/src/core/na-iprefs.c
index 16821de..0c994e4 100644
--- a/src/core/na-iprefs.c
+++ b/src/core/na-iprefs.c
@@ -35,8 +35,8 @@
 #include <string.h>
 
 #include <api/na-core-utils.h>
-#include <api/na-iimporter.h>
 
+#include "na-importer.h"
 #include "na-iprefs.h"
 #include "na-settings.h"
 
@@ -80,31 +80,6 @@ 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:
- * @pref: name of the import key to be read.
- * @mandatory: if not %NULL, a pointer to a boolean which will receive the
- *  mandatory property.
- *
- * 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.
- *
- * Returns: the import mode currently set.
- */
-guint
-na_iprefs_get_import_mode( const gchar *pref, gboolean *mandatory )
-{
-	gchar *import_mode_str;
-	guint import_mode;
-
-	import_mode_str = na_settings_get_string( pref, NULL, mandatory );
-	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:
  * @pref: name of the import key to be written.
  * @mode: the new value to be written.
diff --git a/src/core/na-iprefs.h b/src/core/na-iprefs.h
index dd32070..5a670ac 100644
--- a/src/core/na-iprefs.h
+++ b/src/core/na-iprefs.h
@@ -52,7 +52,6 @@ enum {
 	IPREFS_ORDER_MANUAL
 };
 
-guint    na_iprefs_get_import_mode        ( const gchar *pref, gboolean *mandatory );
 void     na_iprefs_set_import_mode        ( const gchar *pref, guint mode );
 
 guint    na_iprefs_get_order_mode         ( gboolean *mandatory );
diff --git a/src/nact/nact-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c
index 641f854..9e1f907 100644
--- a/src/nact/nact-tree-model-dnd.c
+++ b/src/nact/nact-tree-model-dnd.c
@@ -39,7 +39,6 @@
 #include <api/na-core-utils.h>
 #include <api/na-object-api.h>
 
-#include <core/na-iprefs.h>
 #include <core/na-gnome-vfs-uri.h>
 #include <core/na-importer.h>
 
@@ -861,7 +860,7 @@ drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selec
 	parms.uris = g_slist_reverse( na_core_utils_slist_from_split( selection_data_data, "\r\n" ));
 	parms.check_fn = ( NAImporterCheckFn ) is_dropped_already_exists;
 	parms.check_fn_data = main_window;
-	parms.preferred_mode = na_iprefs_get_import_mode( NA_IPREFS_IMPORT_PREFERRED_MODE, NULL );
+	parms.preferred_mode = 0;
 	parms.parent_toplevel = base_window_get_gtk_toplevel( BASE_WINDOW( main_window ));
 
 	import_results = na_importer_import_from_uris( NA_PIVOT( updater ), &parms );



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