[nautilus-actions] Get ride of GQuark as internal identifier of export format



commit 66b5d8888a675ca78b0ff6b640bc7434ef81333a
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jan 13 10:44:04 2012 +0100

    Get ride of GQuark as internal identifier of export format

 ChangeLog                          |   27 +++++++
 src/api/na-iexporter.h             |   64 +++++++++++++++++-
 src/core/na-export-format.c        |   27 +-------
 src/core/na-export-format.h        |   17 ++---
 src/core/na-exporter.c             |  132 +++++++++++++----------------------
 src/core/na-exporter.h             |   38 +++-------
 src/io-desktop/nadp-writer.c       |   47 ++++++++++++-
 src/io-xml/naxml-writer.c          |   64 +++++++++++++++---
 src/nact/nact-assistant-export.c   |   16 +++--
 src/nact/nact-clipboard.c          |   13 +++-
 src/nact/nact-export-ask.c         |   36 ++++++----
 src/nact/nact-export-ask.h         |    2 +-
 src/utils/nautilus-actions-new.c   |    6 +-
 src/utils/nautilus-actions-print.c |   21 +-----
 14 files changed, 307 insertions(+), 203 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b959315..34e1221 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,32 @@
 2012-01-13 Pierre Wieser <pwieser trychlos org>
 
+	Get ride of GQuark as internal identifier of export format.
+
+	* src/api/na-iexporter.h:
+	Deprecate _NAIExporterFileParmsv1 and _NAIExporterBufferParmsv1 struct.
+
+	* src/core/na-export-format.c:
+	* src/core/na-export-format.h:
+	(na_export_format_get_quark): Removed function.
+	NA_EXPORT_FORMAT_TYPE GType macro renamed as NA_TYPE_EXPORT_FORMAT.
+
+	* src/core/na-exporter.c:
+	* src/core/na-exporter.h
+	(na_exporter_find_for_format): New function.
+	(na_exporter_get_export_format): Removed function.
+
+	* src/io-desktop/nadp-writer.c
+	(nadp_writer_iexporter_export_to_buffer,
+	nadp_writer_iexporter_export_to_file):
+	* src/io-xml/naxml-writer.c
+	(naxml_writer_export_to_buffer, naxml_writer_export_to_file):
+	* src/nact/nact-assistant-export.c (assistant_apply):
+	* src/nact/nact-clipboard.c (export_row_object):
+	* src/nact/nact-export-ask.c:
+	* src/nact/nact-export-ask.h(nact_export_ask_user):
+	* src/utils/nautilus-actions-new.c (output_to_desktop):
+	* src/utils/nautilus-actions-print.c (main): Updated accordingly.
+
 	* src/core/na-ioptions-list.c: Fix comments.
 
 	* src/core/na-ioption.c (get_ioption_data):
diff --git a/src/api/na-iexporter.h b/src/api/na-iexporter.h
index 5bf2436..9e16ab0 100644
--- a/src/api/na-iexporter.h
+++ b/src/api/na-iexporter.h
@@ -330,6 +330,7 @@ typedef enum {
 }
 	NAIExporterExportStatus;
 
+#ifdef NA_ENABLE_DEPRECATED
 /**
  * NAIExporterFileParms:
  * @version:  version of this structure (input, since v 1)
@@ -344,8 +345,10 @@ typedef enum {
  *
  * The structure that the plugin receives as a parameter of
  * #NAIExporterInterface.to_file () interface method.
+ *
+ * Deprecated: 3.2
  */
-struct _NAIExporterFileParms {
+struct _NAIExporterFileParmsv1 {
 	guint         version;
 	NAObjectItem *exported;
 	gchar        *folder;
@@ -354,6 +357,8 @@ struct _NAIExporterFileParms {
 	GSList       *messages;
 };
 
+typedef struct _NAIExporterFileParmsv1         NAIExporterFileParmsv1;
+
 /**
  * NAIExporterBufferParms:
  * @version:  version of this structure (input, since v 1)
@@ -367,8 +372,10 @@ struct _NAIExporterFileParms {
  *
  * The structure that the plugin receives as a parameter of
  * #NAIExporterInterface.to_buffer () interface method.
+ *
+ * Deprecated: 3.2
  */
-struct _NAIExporterBufferParms {
+struct _NAIExporterBufferParmsv1 {
 	guint         version;
 	NAObjectItem *exported;
 	GQuark        format;
@@ -376,6 +383,59 @@ struct _NAIExporterBufferParms {
 	GSList       *messages;
 };
 
+typedef struct _NAIExporterBufferParmsv1       NAIExporterBufferParmsv1;
+#endif
+
+/**
+ * NAIExporterFileParms:
+ * @version:  version of this structure (input, since v 1, currently equal to 2)
+ * @exported: exported NAObjectItem-derived object (input, since v 1)
+ * @folder:   URI of the target folder (input, since v 1)
+ * @format:   export format string identifier (input, since v 2)
+ * @basename: basename of the exported file (output, since v 1)
+ * @messages: a #GSList list of localized strings;
+ *            the provider may append messages to this list,
+ *            but shouldn't reinitialize it
+ *            (input/output, since v 1).
+ *
+ * The structure that the plugin receives as a parameter of
+ * #NAIExporterInterface.to_file () interface method.
+ *
+ * Since: 3.2
+ */
+struct _NAIExporterFileParms {
+	guint         version;
+	NAObjectItem *exported;
+	gchar        *folder;
+	gchar        *format;
+	gchar        *basename;
+	GSList       *messages;
+};
+
+/**
+ * NAIExporterBufferParms:
+ * @version:  version of this structure (input, since v 1, currently equal to 2)
+ * @exported: exported NAObjectItem-derived object (input, since v 1)
+ * @format:   export format string identifier (input, since v 2)
+ * @buffer:   buffer which contains the exported object (output, since v 1)
+ * @messages: a #GSList list of localized strings;
+ *            the provider may append messages to this list,
+ *            but shouldn't reinitialize it
+ *            (input/output, since v 1).
+ *
+ * The structure that the plugin receives as a parameter of
+ * #NAIExporterInterface.to_buffer () interface method.
+ *
+ * Since: 3.2
+ */
+struct _NAIExporterBufferParms {
+	guint         version;
+	NAObjectItem *exported;
+	gchar        *format;
+	gchar        *buffer;
+	GSList       *messages;
+};
+
 GType na_iexporter_get_type( void );
 
 G_END_DECLS
diff --git a/src/core/na-export-format.c b/src/core/na-export-format.c
index d1f22fc..95ab692 100644
--- a/src/core/na-export-format.c
+++ b/src/core/na-export-format.c
@@ -45,7 +45,6 @@ struct _NAExportFormatClassPrivate {
  */
 struct _NAExportFormatPrivate {
 	gboolean     dispose_has_run;
-	GQuark       id;
 	gchar       *format;
 	gchar       *label;
 	gchar       *description;
@@ -324,9 +323,8 @@ na_export_format_new( const NAIExporterFormatExt *exporter_format )
 {
 	NAExportFormat *format;
 
-	format = g_object_new( NA_EXPORT_FORMAT_TYPE, NULL );
+	format = g_object_new( NA_TYPE_EXPORT_FORMAT, NULL );
 
-	format->private->id = g_quark_from_string( exporter_format->format );
 	format->private->format = g_strdup( exporter_format->format );
 	format->private->label = g_strdup( exporter_format->label );
 	format->private->description = g_strdup( exporter_format->description );
@@ -337,29 +335,6 @@ na_export_format_new( const NAIExporterFormatExt *exporter_format )
 }
 
 /*
- * na_export_format_get_quark:
- * @format: this #NAExportFormat object.
- *
- * Returns: the #GQuark associated with this format.
- */
-GQuark
-na_export_format_get_quark( const NAExportFormat *format )
-{
-	GQuark id;
-
-	g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), 0 );
-
-	id = 0;
-
-	if( !format->private->dispose_has_run ){
-
-		id = format->private->id;
-	}
-
-	return( id );
-}
-
-/*
  * na_export_format_get_provider:
  * @format: this #NAExportFormat object.
  *
diff --git a/src/core/na-export-format.h b/src/core/na-export-format.h
index 8a22b87..d94b376 100644
--- a/src/core/na-export-format.h
+++ b/src/core/na-export-format.h
@@ -40,12 +40,12 @@
 
 G_BEGIN_DECLS
 
-#define NA_EXPORT_FORMAT_TYPE                ( na_export_format_get_type())
-#define NA_EXPORT_FORMAT( object )           ( G_TYPE_CHECK_INSTANCE_CAST( object, NA_EXPORT_FORMAT_TYPE, NAExportFormat ))
-#define NA_EXPORT_FORMAT_CLASS( klass )      ( G_TYPE_CHECK_CLASS_CAST( klass, NA_EXPORT_FORMAT_TYPE, NAExportFormatClass ))
-#define NA_IS_EXPORT_FORMAT( object )        ( G_TYPE_CHECK_INSTANCE_TYPE( object, NA_EXPORT_FORMAT_TYPE ))
-#define NA_IS_EXPORT_FORMAT_CLASS( klass )   ( G_TYPE_CHECK_CLASS_TYPE(( klass ), NA_EXPORT_FORMAT_TYPE ))
-#define NA_EXPORT_FORMAT_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), NA_EXPORT_FORMAT_TYPE, NAExportFormatClass ))
+#define NA_TYPE_EXPORT_FORMAT                ( na_export_format_get_type())
+#define NA_EXPORT_FORMAT( object )           ( G_TYPE_CHECK_INSTANCE_CAST( object, NA_TYPE_EXPORT_FORMAT, NAExportFormat ))
+#define NA_EXPORT_FORMAT_CLASS( klass )      ( G_TYPE_CHECK_CLASS_CAST( klass, NA_TYPE_EXPORT_FORMAT, NAExportFormatClass ))
+#define NA_IS_EXPORT_FORMAT( object )        ( G_TYPE_CHECK_INSTANCE_TYPE( object, NA_TYPE_EXPORT_FORMAT ))
+#define NA_IS_EXPORT_FORMAT_CLASS( klass )   ( G_TYPE_CHECK_CLASS_TYPE(( klass ), NA_TYPE_EXPORT_FORMAT ))
+#define NA_EXPORT_FORMAT_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), NA_TYPE_EXPORT_FORMAT, NAExportFormatClass ))
 
 typedef struct _NAExportFormatPrivate        NAExportFormatPrivate;
 
@@ -63,11 +63,10 @@ typedef struct {
 }
 	NAExportFormatClass;
 
-GType           na_export_format_get_type( void );
+GType           na_export_format_get_type    ( void );
 
-NAExportFormat *na_export_format_new( const NAIExporterFormatExt *exporter_format );
+NAExportFormat *na_export_format_new         ( const NAIExporterFormatExt *exporter_format );
 
-GQuark          na_export_format_get_quark   ( const NAExportFormat *format );
 NAIExporter    *na_export_format_get_provider( const NAExportFormat *format );
 
 G_END_DECLS
diff --git a/src/core/na-exporter.c b/src/core/na-exporter.c
index d1780f2..7f617b6 100644
--- a/src/core/na-exporter.c
+++ b/src/core/na-exporter.c
@@ -40,8 +40,6 @@
 #include "na-export-format.h"
 #include "na-settings.h"
 
-#define	Ask			"Ask"
-
 typedef struct {
 	const gchar *format;				/* export format saved in user's preferences */
 	const gchar *label;					/* short label */
@@ -52,19 +50,20 @@ typedef struct {
 
 static NAExporterFormatStr st_format_ask = {
 
-		Ask,
+		EXPORTER_FORMAT_ASK,
 		N_( "_Ask me" ),
 		N_( "You will be asked for the format to choose each time an item " \
 			"is about to be exported." ),
 		"export-format-ask.png"
 };
 
-static GList       *exporter_get_formats( const NAIExporter *exporter );
-static void         exporter_free_formats( const NAIExporter *exporter, GList * str_list );
-static gchar       *exporter_get_name( const NAIExporter *exporter );
-static NAIExporter *find_exporter_for_format( const NAPivot *pivot, GQuark format );
-static void         on_pixbuf_finalized( gpointer user_data, GObject *pixbuf );
-static GQuark       id_from_string( const gchar *format_str );
+/* i18n: NAIExporter is an interface name, do not even try to translate */
+#define NO_IMPLEMENTATION_MSG			N_( "No NAIExporter implementation found for '%s' format." )
+
+static GList *exporter_get_formats( const NAIExporter *exporter );
+static void   exporter_free_formats( const NAIExporter *exporter, GList * str_list );
+static gchar *exporter_get_name( const NAIExporter *exporter );
+static void   on_pixbuf_finalized( gpointer user_data, GObject *pixbuf );
 
 /*
  * na_exporter_get_formats:
@@ -262,7 +261,7 @@ on_pixbuf_finalized( gpointer user_data /* ==NULL */, GObject *pixbuf )
  */
 gchar *
 na_exporter_to_buffer( const NAPivot *pivot,
-		const NAObjectItem *item, GQuark format, GSList **messages )
+		const NAObjectItem *item, const gchar *format, GSList **messages )
 {
 	static const gchar *thisfn = "na_exporter_to_buffer";
 	gchar *buffer;
@@ -276,20 +275,20 @@ na_exporter_to_buffer( const NAPivot *pivot,
 
 	buffer = NULL;
 
-	g_debug( "%s: pivot=%p, item=%p (%s), format=%u, messages=%p",
+	g_debug( "%s: pivot=%p, item=%p (%s), format=%s, messages=%p",
 			thisfn,
 			( void * ) pivot,
 			( void * ) item, G_OBJECT_TYPE_NAME( item ),
-			( guint ) format,
+			format,
 			( void * ) messages );
 
-	exporter = find_exporter_for_format( pivot, format );
+	exporter = na_exporter_find_for_format( pivot, format );
 	g_debug( "%s: exporter=%p (%s)", thisfn, ( void * ) exporter, G_OBJECT_TYPE_NAME( exporter ));
 
 	if( exporter ){
-		parms.version = 1;
+		parms.version = 2;
 		parms.exported = ( NAObjectItem * ) item;
-		parms.format = format;
+		parms.format = g_strdup( format );
 		parms.buffer = NULL;
 		parms.messages = messages ? *messages : NULL;
 
@@ -302,14 +301,16 @@ na_exporter_to_buffer( const NAPivot *pivot,
 
 		} else {
 			name = exporter_get_name( exporter );
-			msg = g_strdup_printf( _( "NAIExporter %s doesn't implement 'to_buffer' interface." ), name );
+			/* i18n: NAIExporter is an interface name, do not even try to translate */
+			msg = g_strdup_printf( _( "%s NAIExporter doesn't implement 'to_buffer' interface." ), name );
 			*messages = g_slist_append( *messages, msg );
 			g_free( name );
 		}
 
+		g_free( parms.format );
+
 	} else {
-		msg = g_strdup_printf(
-				_( "No NAIExporter implementation found for %s format." ), g_quark_to_string( format ));
+		msg = g_strdup_printf( NO_IMPLEMENTATION_MSG, format );
 		*messages = g_slist_append( *messages, msg );
 	}
 
@@ -332,7 +333,7 @@ na_exporter_to_buffer( const NAPivot *pivot,
  */
 gchar *
 na_exporter_to_file( const NAPivot *pivot,
-		const NAObjectItem *item, const gchar *folder_uri, GQuark format, GSList **messages )
+		const NAObjectItem *item, const gchar *folder_uri, const gchar *format, GSList **messages )
 {
 	static const gchar *thisfn = "na_exporter_to_file";
 	gchar *export_uri;
@@ -346,21 +347,21 @@ na_exporter_to_file( const NAPivot *pivot,
 
 	export_uri = NULL;
 
-	g_debug( "%s: pivot=%p, item=%p (%s), folder_uri=%s, format=%u (%s), messages=%p",
+	g_debug( "%s: pivot=%p, item=%p (%s), folder_uri=%s, format=%s, messages=%p",
 			thisfn,
 			( void * ) pivot,
 			( void * ) item, G_OBJECT_TYPE_NAME( item ),
 			folder_uri,
-			( guint ) format, g_quark_to_string( format ),
+			format,
 			( void * ) messages );
 
-	exporter = find_exporter_for_format( pivot, format );
+	exporter = na_exporter_find_for_format( pivot, format );
 
 	if( exporter ){
-		parms.version = 1;
+		parms.version = 2;
 		parms.exported = ( NAObjectItem * ) item;
 		parms.folder = ( gchar * ) folder_uri;
-		parms.format = format;
+		parms.format = g_strdup( format );
 		parms.basename = NULL;
 		parms.messages = messages ? *messages : NULL;
 
@@ -373,14 +374,16 @@ na_exporter_to_file( const NAPivot *pivot,
 
 		} else {
 			name = exporter_get_name( exporter );
-			msg = g_strdup_printf( _( "NAIExporter %s doesn't implement 'to_file' interface." ), name );
+			/* i18n: NAIExporter is an interface name, do not even try to translate */
+			msg = g_strdup_printf( _( "%s NAIExporter doesn't implement 'to_file' interface." ), name );
 			*messages = g_slist_append( *messages, msg );
 			g_free( name );
 		}
 
+		g_free( parms.format );
+
 	} else {
-		msg = g_strdup_printf(
-				_( "No NAIExporter implementation found for %s format." ), g_quark_to_string( format ));
+		msg = g_strdup_printf( NO_IMPLEMENTATION_MSG, format );
 		*messages = g_slist_append( *messages, msg );
 	}
 
@@ -401,76 +404,39 @@ exporter_get_name( const NAIExporter *exporter )
 	return( name );
 }
 
-static NAIExporter *
-find_exporter_for_format( const NAPivot *pivot, GQuark format )
+/**
+ * na_exporter_find_for_format:
+ * @pivot: the #NAPivot instance.
+ * @format: the string identifier of the searched format.
+ *
+ * Returns: the #NAIExporter instance which provides the @format export
+ * format. The returned instance is owned by @pivot, and should not be
+ * released by the caller.
+ */
+NAIExporter *
+na_exporter_find_for_format( const NAPivot *pivot, const gchar *format )
 {
 	NAIExporter *exporter;
 	GList *formats, *ifmt;
+	gchar *id;
+	NAExportFormat *export_format;
+
+	g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
 
 	exporter = NULL;
 	formats = na_exporter_get_formats( pivot );
 
 	for( ifmt = formats ; ifmt && !exporter ; ifmt = ifmt->next ){
 
-		if( na_export_format_get_quark( NA_EXPORT_FORMAT( ifmt->data )) == format ){
+		export_format = NA_EXPORT_FORMAT( ifmt->data );
+		id = na_ioption_get_id( NA_IOPTION( export_format ));
+		if( !strcmp( id, format )){
 			exporter = na_export_format_get_provider( NA_EXPORT_FORMAT( ifmt->data ));
 		}
+		g_free( id );
 	}
 
 	na_exporter_free_formats( formats );
 
 	return( exporter );
 }
-
-/*
- * na_exporter_get_export_format:
- * @pref: the name of the preference to be read.
- * @mandatory: if not %NULL, a pointer to a boolean which will receive the
- *  mandatory property.
- *
- * Returns: the export format currently set in user's preference.
- *
- * This may be:
- * - either the preferred export format,
- * - or the last chosen export format in NactExportAsk dialog box.
- *
- * The returned integer is either:
- * - the corresponding enum value in the case of "NoImport" or "Ask";
- * - the #GQuark of the string for other export formats.
- */
-GQuark
-na_exporter_get_export_format( const gchar *pref, gboolean *mandatory )
-{
-	gchar *format_str;
-	GQuark format_id;
-
-	g_return_val_if_fail( pref && strlen( pref ), ( GQuark ) EXPORTER_FORMAT_NO_EXPORT );
-
-	format_str = na_settings_get_string( pref, NULL, mandatory );
-	g_return_val_if_fail( format_str && strlen( format_str ), ( GQuark ) EXPORTER_FORMAT_NO_EXPORT );
-
-	format_id = id_from_string( format_str );
-	g_free( format_str );
-
-	return( format_id );
-}
-
-/*
- * na_exporter_id_from_string:
- * @format_str: the string which defines the export format in user's preferences.
- *
- * Returns: the integer which identifies the export format.
- *
- * The returned integer is either:
- * - the corresponding enum value in the case of "NoImport" or "Ask";
- * - the #GQuark of the string for other export formats.
- */
-static GQuark
-id_from_string( const gchar *format_str )
-{
-	if( !strcmp( format_str, Ask )){
-		return(( GQuark ) EXPORTER_FORMAT_ASK );
-	}
-
-	return( g_quark_from_string( format_str ));
-}
diff --git a/src/core/na-exporter.h b/src/core/na-exporter.h
index 4a5c231..dcc7afe 100644
--- a/src/core/na-exporter.h
+++ b/src/core/na-exporter.h
@@ -36,6 +36,7 @@
  * @include: core/na-exporter.h
  */
 
+#include <api/na-iexporter.h>
 #include <api/na-object-api.h>
 
 #include "na-ioption.h"
@@ -43,41 +44,26 @@
 
 G_BEGIN_DECLS
 
-/*
- * NAExporterExportFormat:
- * @EXPORTER_FORMAT_NO_EXPORT:
- * @EXPORTER_FORMAT_ASK:
- *
- * This enum defines some special export formats, which are typically used
- * in switch statements. Standard export formats, as provided by I/O providers,
- * are just #GQuark of their format identifier string.
- *
- * When the user chooses to not export an item, this value is not written in
- * user's preferences.
- */
-typedef enum {
-	EXPORTER_FORMAT_NO_EXPORT = 1,
-	EXPORTER_FORMAT_ASK,
-}
-	NAExporterExportFormat;
-
-GList     *na_exporter_get_formats      ( const NAPivot *pivot );
-void       na_exporter_free_formats     ( GList *formats );
+#define EXPORTER_FORMAT_ASK				"Ask"
+#define EXPORTER_FORMAT_NOEXPORT		"NoExport"
 
-NAIOption *na_exporter_get_ask_option   ( void );
+GList       *na_exporter_get_formats    ( const NAPivot *pivot );
+void         na_exporter_free_formats   ( GList *formats );
+NAIOption   *na_exporter_get_ask_option ( void );
 
-gchar     *na_exporter_to_buffer        ( const NAPivot *pivot,
+gchar       *na_exporter_to_buffer      ( const NAPivot *pivot,
                                           const NAObjectItem *item,
-                                          GQuark format,
+                                          const gchar *format,
                                           GSList **messages );
 
-gchar     *na_exporter_to_file          ( const NAPivot *pivot,
+gchar       *na_exporter_to_file        ( const NAPivot *pivot,
                                           const NAObjectItem *item,
                                           const gchar *folder_uri,
-                                          GQuark format,
+                                          const gchar *format,
                                           GSList **messages );
 
-GQuark     na_exporter_get_export_format( const gchar *pref, gboolean *mandatory );
+NAIExporter *na_exporter_find_for_format( const NAPivot *pivot,
+		                                  const gchar *format );
 
 G_END_DECLS
 
diff --git a/src/io-desktop/nadp-writer.c b/src/io-desktop/nadp-writer.c
index b4fb400..43376bc 100644
--- a/src/io-desktop/nadp-writer.c
+++ b/src/io-desktop/nadp-writer.c
@@ -71,7 +71,11 @@ static void            desktop_weak_notify( NadpDesktopFile *ndf, GObject *item
 static void            write_start_write_type( NadpDesktopFile *ndp, NAObjectItem *item );
 static void            write_done_write_subitems_list( NadpDesktopFile *ndp, NAObjectItem *item );
 
-static ExportFormatFn *find_export_format_fn( GQuark format );
+static ExportFormatFn *find_export_format_fn( const gchar *format );
+
+#ifdef NA_ENABLE_DEPRECATED
+static ExportFormatFn *find_export_format_fn_from_quark( GQuark format );
+#endif
 
 /*
  * This is implementation of NAIIOProvider::is_willing_to_write method
@@ -367,7 +371,16 @@ nadp_writer_iexporter_export_to_buffer( const NAIExporter *instance, NAIExporter
 	}
 
 	if( code == NA_IEXPORTER_CODE_OK ){
+
+#ifdef NA_ENABLE_DEPRECATED
+		if( parms->version == 1 ){
+			fmt = find_export_format_fn_from_quark(( NAIExporterBufferParmsv1 * ) parms->format );
+		} else {
+			fmt = find_export_format_fn( parms->format );
+		}
+#else
 		fmt = find_export_format_fn( parms->format );
+#endif
 
 		if( !fmt ){
 			code = NA_IEXPORTER_CODE_INVALID_FORMAT;
@@ -418,7 +431,16 @@ nadp_writer_iexporter_export_to_file( const NAIExporter *instance, NAIExporterFi
 	}
 
 	if( code == NA_IEXPORTER_CODE_OK ){
+
+#ifdef NA_ENABLE_DEPRECATED
+		if( parms->version == 1 ){
+			fmt = find_export_format_fn_from_quark(( NAIExporterFileParmsv1 * ) parms->format );
+		} else {
+			fmt = find_export_format_fn( parms->format );
+		}
+#else
 		fmt = find_export_format_fn( parms->format );
+#endif
 
 		if( !fmt ){
 			code = NA_IEXPORTER_CODE_INVALID_FORMAT;
@@ -614,7 +636,27 @@ write_done_write_subitems_list( NadpDesktopFile *ndp, NAObjectItem *item )
 }
 
 static ExportFormatFn *
-find_export_format_fn( GQuark format )
+find_export_format_fn( const gchar *format )
+{
+	ExportFormatFn *found;
+	ExportFormatFn *i;
+
+	found = NULL;
+	i = st_export_format_fn;
+
+	while( i->format && !found ){
+		if( !strcmp( i->format, format )){
+			found = i;
+		}
+		i++;
+	}
+
+	return( found );
+}
+
+#ifdef NA_ENABLE_DEPRECATED
+static ExportFormatFn *
+find_export_format_fn_from_quark( GQuark format )
 {
 	ExportFormatFn *found;
 	ExportFormatFn *i;
@@ -631,3 +673,4 @@ find_export_format_fn( GQuark format )
 
 	return( found );
 }
+#endif
diff --git a/src/io-xml/naxml-writer.c b/src/io-xml/naxml-writer.c
index 28d957a..33315cd 100644
--- a/src/io-xml/naxml-writer.c
+++ b/src/io-xml/naxml-writer.c
@@ -116,8 +116,13 @@ static void            write_type_dump( NAXMLWriter *writer, const NAObjectItem
 
 static xmlDocPtr       build_xml_doc( NAXMLWriter *writer );
 static gchar          *convert_to_gconf_slist( const gchar *str );
-static ExportFormatFn *find_export_format_fn( GQuark format );
-static gchar          *get_output_fname( const NAObjectItem *item, const gchar *folder, GQuark format );
+static ExportFormatFn *find_export_format_fn( const gchar *format );
+
+#ifdef NA_ENABLE_DEPRECATED
+static ExportFormatFn *find_export_format_fn_from_quark( GQuark format );
+#endif
+
+static gchar          *get_output_fname( const NAObjectItem *item, const gchar *folder, const gchar *format );
 static void            output_xml_to_file( const gchar *xml, const gchar *filename, GSList **msg );
 static guint           writer_to_buffer( NAXMLWriter *writer );
 
@@ -288,7 +293,15 @@ naxml_writer_export_to_buffer( const NAIExporter *instance, NAIExporterBufferPar
 		writer->private->provider = ( NAIExporter * ) instance;
 		writer->private->exported = parms->exported;
 		writer->private->messages = parms->messages;
+#ifdef NA_ENABLE_DEPRECATED
+		if( parms->version == 1 ){
+			writer->private->fn_str = find_export_format_fn_from_quark(( NAIExporterBufferParmsv1 * ) parms->format );
+		} else {
+			writer->private->fn_str = find_export_format_fn( parms->format );
+		}
+#else
 		writer->private->fn_str = find_export_format_fn( parms->format );
+#endif
 		writer->private->buffer = NULL;
 
 		if( !writer->private->fn_str ){
@@ -322,6 +335,7 @@ naxml_writer_export_to_file( const NAIExporter *instance, NAIExporterFileParms *
 	NAXMLWriter *writer;
 	gchar *filename;
 	guint code;
+	const gchar *format2;
 
 	g_debug( "%s: instance=%p, parms=%p", thisfn, ( void * ) instance, ( void * ) parms );
 
@@ -337,7 +351,18 @@ naxml_writer_export_to_file( const NAIExporter *instance, NAIExporterFileParms *
 		writer->private->provider = ( NAIExporter * ) instance;
 		writer->private->exported = parms->exported;
 		writer->private->messages = parms->messages;
+#ifdef NA_ENABLE_DEPRECATED
+		if( parms->version == 1 ){
+			writer->private->fn_str = find_export_format_fn_from_quark(( NAIExporterFileParmsv1 * ) parms->format );
+			format2 = g_quark_to_string(( NAIExporterFileParmsv1 * ) parms->format );
+		} else {
+			writer->private->fn_str = find_export_format_fn( parms->format );
+			format2 = parms->format;
+		}
+#else
 		writer->private->fn_str = find_export_format_fn( parms->format );
+		format2 = parms->format;
+#endif
 		writer->private->buffer = NULL;
 
 		if( !writer->private->fn_str ){
@@ -347,7 +372,7 @@ naxml_writer_export_to_file( const NAIExporter *instance, NAIExporterFileParms *
 			code = writer_to_buffer( writer );
 
 			if( code == NA_IEXPORTER_CODE_OK ){
-				filename = get_output_fname( parms->exported, parms->folder, parms->format );
+				filename = get_output_fname( parms->exported, parms->folder, format2 );
 
 				if( filename ){
 					parms->basename = g_path_get_basename( filename );
@@ -739,7 +764,27 @@ convert_to_gconf_slist( const gchar *slist_str )
 }
 
 static ExportFormatFn *
-find_export_format_fn( GQuark format )
+find_export_format_fn( const gchar *format )
+{
+	ExportFormatFn *found;
+	ExportFormatFn *i;
+
+	found = NULL;
+	i = st_export_format_fn;
+
+	while( i->format && !found ){
+		if( !strcmp( i->format, format )){
+			found = i;
+		}
+		i++;
+	}
+
+	return( found );
+}
+
+#ifdef NA_ENABLE_DEPRECATED
+static ExportFormatFn *
+find_export_format_fn_from_quark( GQuark format )
 {
 	ExportFormatFn *found;
 	ExportFormatFn *i;
@@ -756,6 +801,7 @@ find_export_format_fn( GQuark format )
 
 	return( found );
 }
+#endif
 
 /*
  * get_output_fname:
@@ -775,7 +821,7 @@ find_export_format_fn( GQuark format )
  * between our test of inexistance and the actual write.
  */
 static gchar *
-get_output_fname( const NAObjectItem *item, const gchar *folder, GQuark format )
+get_output_fname( const NAObjectItem *item, const gchar *folder, const gchar *format )
 {
 	static const gchar *thisfn = "naxml_writer_get_output_fname";
 	gchar *item_id;
@@ -790,20 +836,20 @@ get_output_fname( const NAObjectItem *item, const gchar *folder, GQuark format )
 
 	item_id = na_object_get_id( item );
 
-	if( format == g_quark_from_string( NAXML_FORMAT_GCONF_SCHEMA_V1 )){
+	if( !strcmp( format, NAXML_FORMAT_GCONF_SCHEMA_V1 )){
 		canonical_fname = g_strdup_printf( "config_%s", item_id );
 		canonical_ext = g_strdup( "schemas" );
 
-	} else if( format == g_quark_from_string( NAXML_FORMAT_GCONF_SCHEMA_V2 )){
+	} else if( !strcmp( format, NAXML_FORMAT_GCONF_SCHEMA_V2 )){
 		canonical_fname = g_strdup_printf( "config-%s", item_id );
 		canonical_ext = g_strdup( "schema" );
 
-	} else if( format == g_quark_from_string( NAXML_FORMAT_GCONF_ENTRY )){
+	} else if( !strcmp( format, NAXML_FORMAT_GCONF_ENTRY )){
 		canonical_fname = g_strdup_printf( "%s-%s", NA_IS_OBJECT_ACTION( item ) ? "action" : "menu", item_id );
 		canonical_ext = g_strdup( "xml" );
 
 	} else {
-		g_warning( "%s: unknown format: %s", thisfn, g_quark_to_string( format ));
+		g_warning( "%s: unknown format: %s", thisfn, format );
 	}
 
 	g_free( item_id );
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 7dacff2..bc03cee 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -91,7 +91,7 @@ typedef struct {
 	NAObjectItem *item;
 	GSList       *msg;
 	gchar        *fname;
-	GQuark        format;
+	gchar        *format;
 }
 	ExportStruct;
 
@@ -807,20 +807,24 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 		window->private->results = g_list_append( window->private->results, str );
 
 		str->item = NA_OBJECT_ITEM( na_object_get_origin( NA_IDUPLICABLE( ia->data )));
-		str->format = na_exporter_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, NULL );
+		str->format = na_settings_get_string( NA_IPREFS_EXPORT_PREFERRED_FORMAT, NULL, NULL );
+		g_return_if_fail( str->format && strlen( str->format ));
 
-		if( str->format == EXPORTER_FORMAT_ASK ){
+		if( !strcmp( str->format, EXPORTER_FORMAT_ASK )){
+			g_free( str->format );
 			str->format = nact_export_ask_user( BASE_WINDOW( wnd ), str->item, first );
+			g_return_if_fail( str->format && strlen( str->format ));
 
-			if( str->format == EXPORTER_FORMAT_NO_EXPORT ){
+			if( !str->format || !strcmp( str->format, EXPORTER_FORMAT_NOEXPORT )){
 				str->msg = g_slist_append( NULL, g_strdup( _( "Export canceled due to user action." )));
 			}
 		}
 
-		if( str->format != EXPORTER_FORMAT_NO_EXPORT ){
+		if( strcmp( str->format, EXPORTER_FORMAT_NOEXPORT ) != 0 ){
 			str->fname = na_exporter_to_file( NA_PIVOT( updater ), str->item, window->private->uri, str->format, &str->msg );
 		}
 
+		g_free( str->format );
 		first = FALSE;
 	}
 }
@@ -892,7 +896,7 @@ assist_prepare_exportdone( NactAssistantExport *window, GtkAssistant *assistant,
 			/* i18n: action as been successfully exported to <filename> */
 			text = g_strdup_printf( "%s %s", _( "Successfully exported as" ), str->fname );
 
-		} else if( str->format != EXPORTER_FORMAT_NO_EXPORT ){
+		} else if( strcmp( str->format, EXPORTER_FORMAT_NOEXPORT ) != 0 ){
 			errors += 1;
 		}
 
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index e5e481a..1c3af38 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -561,7 +561,7 @@ export_row_object( NactClipboard *clipboard, NAObject *object, const gchar *dest
 	gint index;
 	GString *data;
 	gchar *buffer;
-	GQuark format;
+	gchar *format;
 	gchar *fname;
 	GSList *msgs;
 
@@ -593,13 +593,16 @@ export_row_object( NactClipboard *clipboard, NAObject *object, const gchar *dest
 	if( index == -1 ){
 
 		*exported = g_list_prepend( *exported, ( gpointer ) action );
-		format = na_exporter_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, NULL );
+		format = na_settings_get_string( NA_IPREFS_EXPORT_PREFERRED_FORMAT, NULL, NULL );
+		g_return_val_if_fail( format && strlen( format ), NULL );
 
-		if( format == EXPORTER_FORMAT_ASK ){
+		if( !strcmp( format, EXPORTER_FORMAT_ASK )){
+			g_free( format );
 			format = nact_export_ask_user( clipboard->private->window, NA_OBJECT_ITEM( action ), first );
+			g_return_val_if_fail( format && strlen( format ), NULL );
 		}
 
-		if( format != EXPORTER_FORMAT_NO_EXPORT ){
+		if( strcmp( format, EXPORTER_FORMAT_NOEXPORT ) != 0 ){
 			if( dest_folder ){
 				fname = na_exporter_to_file( NA_PIVOT( updater ), NA_OBJECT_ITEM( action), dest_folder, format, &msgs );
 				g_free( fname );
@@ -612,6 +615,8 @@ export_row_object( NactClipboard *clipboard, NAObject *object, const gchar *dest
 				}
 			}
 		}
+
+		g_free( format );
 	}
 
 	return( g_string_free( data, FALSE ));
diff --git a/src/nact/nact-export-ask.c b/src/nact/nact-export-ask.c
index 3ff00ee..a97295e 100644
--- a/src/nact/nact-export-ask.c
+++ b/src/nact/nact-export-ask.c
@@ -59,7 +59,7 @@ struct _NactExportAskPrivate {
 	BaseWindow   *parent;
 	gboolean      preferences_locked;
 	NAObjectItem *item;
-	GQuark        format;
+	gchar        *format;
 	gboolean      format_mandatory;
 	gboolean      keep_last_choice;
 	gboolean      keep_last_choice_mandatory;
@@ -84,7 +84,7 @@ static void     on_base_initialize_window( NactExportAsk *editor );
 static void     keep_choice_on_toggled( GtkToggleButton *button, NactExportAsk *editor );
 static void     on_cancel_clicked( GtkButton *button, NactExportAsk *editor );
 static void     on_ok_clicked( GtkButton *button, NactExportAsk *editor );
-static GQuark   get_export_format( NactExportAsk *editor );
+static gchar   *get_export_format( NactExportAsk *editor );
 
 GType
 nact_export_ask_get_type( void )
@@ -247,6 +247,8 @@ instance_finalize( GObject *dialog )
 
 	self = NACT_EXPORT_ASK( dialog );
 
+	g_free( self->private->format );
+
 	g_free( self->private );
 
 	/* chain call to parent class */
@@ -269,14 +271,14 @@ instance_finalize( GObject *dialog )
  * when the set export format is 'Ask me'. Each exported file runs this
  * dialog, unless the user selects the 'keep same choice' box.
  *
- * Returns: the mode chosen by the user as a #GQuark which identifies
- * the export mode.
+ * Returns: the export format chosen by the user as a newly allocated
+ * string which should be g_free() by the caller.
  * The function defaults to returning NA_IPREFS_DEFAULT_EXPORT_FORMAT.
  *
  * When the user selects 'Keep same choice without asking me', this choice
  * becomes his new preferred export format.
  */
-GQuark
+gchar *
 nact_export_ask_user( BaseWindow *parent, NAObjectItem *item, gboolean first )
 {
 	static const gchar *thisfn = "nact_export_ask_user";
@@ -284,14 +286,17 @@ nact_export_ask_user( BaseWindow *parent, NAObjectItem *item, gboolean first )
 	gboolean are_locked, mandatory;
 	gboolean keep, keep_mandatory;
 	int code;
-	GQuark format;
+	gchar *format;
 
-	g_return_val_if_fail( BASE_IS_WINDOW( parent ), EXPORTER_FORMAT_NO_EXPORT );
+	g_return_val_if_fail( BASE_IS_WINDOW( parent ), NULL );
 
 	g_debug( "%s: parent=%p, item=%p (%s), first=%s",
-			thisfn, ( void * ) parent, ( void * ) item, G_OBJECT_TYPE_NAME( item ), first ? "True":"False" );
+			thisfn,
+			( void * ) parent,
+			( void * ) item, G_OBJECT_TYPE_NAME( item ),
+			first ? "True":"False" );
 
-	format = na_exporter_get_export_format( NA_IPREFS_EXPORT_ASK_USER_LAST_FORMAT, &mandatory );
+	format = na_settings_get_string( NA_IPREFS_EXPORT_ASK_USER_LAST_FORMAT, NULL, &mandatory );
 	keep = na_settings_get_boolean( NA_IPREFS_EXPORT_ASK_USER_KEEP_LAST_CHOICE, NULL, &keep_mandatory );
 
 	if( first || !keep ){
@@ -302,7 +307,7 @@ nact_export_ask_user( BaseWindow *parent, NAObjectItem *item, gboolean first )
 				BASE_PROP_WSP_NAME,       st_wsp_name,
 				NULL );
 
-		editor->private->format = format;
+		editor->private->format = g_strdup( format );
 		editor->private->format_mandatory = mandatory;
 		editor->private->keep_last_choice = keep;
 		editor->private->keep_last_choice_mandatory = keep_mandatory;
@@ -315,13 +320,15 @@ nact_export_ask_user( BaseWindow *parent, NAObjectItem *item, gboolean first )
 		code = base_window_run( BASE_WINDOW( editor ));
 		switch( code ){
 			case GTK_RESPONSE_OK:
+				g_free( format );
 				format = get_export_format( editor );
 				break;
 
 			case GTK_RESPONSE_CANCEL:
 			/* base_dialog::do_run only returns OK or CANCEL */
 			default:
-				format = EXPORTER_FORMAT_NO_EXPORT;
+				g_free( format );
+				format = g_strdup( EXPORTER_FORMAT_NOEXPORT );
 				break;
 		}
 
@@ -387,7 +394,7 @@ on_base_initialize_window( NactExportAsk *editor )
 				!priv->format_mandatory && !priv->preferences_locked );
 		na_ioptions_list_set_default(
 				NA_IOPTIONS_LIST( editor ), widget,
-				g_quark_to_string( priv->format ));
+				priv->format );
 
 		base_gtk_utils_toggle_set_initial_state( BASE_WINDOW( editor ),
 				"AskKeepChoiceButton", G_CALLBACK( keep_choice_on_toggled ),
@@ -449,7 +456,7 @@ on_ok_clicked( GtkButton *button, NactExportAsk *editor )
  * let the user go back in ask dialog box the next time he will have some
  * files to export
  */
-static GQuark
+static gchar *
 get_export_format( NactExportAsk *editor )
 {
 	GtkWidget *widget;
@@ -466,7 +473,6 @@ get_export_format( NactExportAsk *editor )
 
 	format_id = na_ioption_get_id( format );
 	na_settings_set_string( NA_IPREFS_EXPORT_ASK_USER_LAST_FORMAT, format_id );
-	g_free( format_id );
 
-	return( na_export_format_get_quark( NA_EXPORT_FORMAT( format )));
+	return( format_id );
 }
diff --git a/src/nact/nact-export-ask.h b/src/nact/nact-export-ask.h
index ae14770..42cd031 100644
--- a/src/nact/nact-export-ask.h
+++ b/src/nact/nact-export-ask.h
@@ -79,7 +79,7 @@ typedef struct {
 
 GType  nact_export_ask_get_type( void );
 
-GQuark nact_export_ask_user    ( BaseWindow *window, NAObjectItem *item, gboolean first );
+gchar *nact_export_ask_user    ( BaseWindow *window, NAObjectItem *item, gboolean first );
 
 G_END_DECLS
 
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index 590e6ba..4f285d2 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -586,6 +586,7 @@ output_to_desktop( NAObjectAction *action, GSList **msgs )
 		code = ( ret == NA_IIO_PROVIDER_CODE_OK );
 
 	} else {
+		/* i18n: 'na-desktop' is a plugin identifier - do not translate */
 		*msgs = g_slist_append( *msgs, _( "Error: unable to find 'na-desktop' i/o provider." ));
 		code = FALSE;
 	}
@@ -600,12 +601,10 @@ output_to_stdout( const NAObjectAction *action, GSList **msgs )
 {
 	gboolean ret;
 	NAUpdater *updater;
-	GQuark format;
 	gchar *buffer;
 
 	updater = na_updater_new();
-	format = g_quark_from_string( "Desktop1" );
-	buffer = na_exporter_to_buffer( NA_PIVOT( updater ), NA_OBJECT_ITEM( action ), format, msgs );
+	buffer = na_exporter_to_buffer( NA_PIVOT( updater ), NA_OBJECT_ITEM( action ), "Desktop1", msgs );
 	ret = ( buffer != NULL );
 
 	if( buffer ){
@@ -624,6 +623,7 @@ output_to_stdout( const NAObjectAction *action, GSList **msgs )
 static void
 exit_with_usage( void )
 {
+	/* i18: '--help' is a command-line option - do not translate */
 	g_printerr( _( "Try %s --help for usage.\n" ), g_get_prgname());
 	exit( EXIT_FAILURE );
 }
diff --git a/src/utils/nautilus-actions-print.c b/src/utils/nautilus-actions-print.c
index 4d60bda..2c42d74 100644
--- a/src/utils/nautilus-actions-print.c
+++ b/src/utils/nautilus-actions-print.c
@@ -88,8 +88,7 @@ main( int argc, char** argv )
 	gchar *help;
 	gint errors;
 	NAObjectItem *item;
-	GList *formats_list, *it;
-	gboolean format_found;
+	NAIExporter *exporter;
 
 	g_type_init();
 	setlocale( LC_ALL, "" );
@@ -134,19 +133,8 @@ main( int argc, char** argv )
 		format = "Desktop1";
 	}
 
-	formats_list = na_exporter_get_formats( pivot );
-	format_found = FALSE;
-
-	for( it = formats_list ; it && !format_found ; it = it->next ){
-		NAExportFormat *export = NA_EXPORT_FORMAT( it->data );
-		gchar *export_id = na_ioption_get_id( NA_IOPTION( export ));
-		format_found = !strcmp( export_id, format );
-		g_free( export_id );
-	}
-
-	na_exporter_free_formats( formats_list );
-
-	if( !format_found ){
+	exporter = na_exporter_find_for_format( pivot, format );
+	if( !exporter ){
 		/* i18n: %s stands for the id of the export format, and is not translatable */
 		g_printerr( _( "Error: %s: unknown export format.\n" ), format );
 		errors += 1;
@@ -227,9 +215,8 @@ export_item( const NAObjectItem *item, const gchar *format )
 {
 	GSList *messages = NULL;
 	GSList *it;
-	GQuark q_format = g_quark_from_string( format );
 
-	gchar *buffer = na_exporter_to_buffer( pivot, item, q_format, &messages );
+	gchar *buffer = na_exporter_to_buffer( pivot, item, format, &messages );
 
 	for( it = messages ; it ; it = it->next ){
 		g_printerr( "%s\n", ( const gchar * ) it->data );



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