[nautilus-actions] Bump NAIExporter interface to version 2
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Bump NAIExporter interface to version 2
- Date: Thu, 22 Dec 2011 00:07:14 +0000 (UTC)
commit 1681925a30d35b2584047fc136ce254007030803
Author: Pierre Wieser <pwieser trychlos org>
Date: Wed Dec 21 07:18:01 2011 +0100
Bump NAIExporter interface to version 2
- Define a new NAIExporterFormatExt structure which embeds a version number and a pixbuf
- Upgrade NAXMLProvider and NadpProvider to this new interface
- Update NAExportFormat object to deal with new NAIExporterFormatExt structure.
ChangeLog | 27 ++++++
src/api/na-iexporter.h | 151 ++++++++++++++++++++++++++++----
src/core/na-export-format.c | 41 ++++++---
src/core/na-export-format.h | 5 +-
src/core/na-exporter.c | 86 +++++++++++++++---
src/io-desktop/nadp-desktop-provider.c | 51 ++++++-----
src/io-desktop/nadp-formats.c | 84 +++++++++++++++++-
src/io-desktop/nadp-formats.h | 7 ++-
src/io-xml/naxml-formats.c | 92 ++++++++++++++++++--
src/io-xml/naxml-formats.h | 5 +
src/io-xml/naxml-provider.c | 41 +++++----
11 files changed, 492 insertions(+), 98 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b6a61ce..64e5ef0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2011-12-21 Pierre Wieser <pwieser trychlos org>
+
+ NAIExporter interface upgrade.
+
+ * src/api/na-iexporter.h:
+ Define a new NAIExporterFormatExt structure, which embeds a GdkPixbuf.
+
+ * src/core/na-export-format.c:
+ * src/core/na-export-format.h (na_export_format_new):
+ Updated to new NAIExporterFormatExt structure.
+
+ * src/core/na-exporter.c (na_exporter_get_formats):
+ Take into account the new NAIExporter interface version.
+
+ * src/io-desktop/nadp-desktop-provider.c: Updated to new NAIExporter
+ interface version.
+
+ * src/io-desktop/nadp-formats.c
+ (nadp_formats_get_formats, nadp_formats_free_formats): New functions.
+
+ * src/io-xml/naxml-formats.c: Updated to the new NAIExporter interface
+ version.
+
+ * src/io-xml/naxml-formats.c:
+ * src/io-xml/naxml-formats.h
+ (naxml_formats_get_formats, naxml_formats_free_formats): New functions.
+
2011-12-20 Pierre Wieser <pwieser trychlos org>
* src/nact/nact-menubar.c: Do not talk about XML files on import/export.
diff --git a/src/api/na-iexporter.h b/src/api/na-iexporter.h
index 8d7ff35..9a63551 100644
--- a/src/api/na-iexporter.h
+++ b/src/api/na-iexporter.h
@@ -34,7 +34,7 @@
/**
* SECTION: iexporter
* @title: NAIExporter
- * @short_description: The Export Interface v 1
+ * @short_description: The Export Interface v 2
* @include: nautilus-actions/na-iexporter.h
*
* The #NAIExporter interface exports items to the outside world.
@@ -58,6 +58,11 @@
* <row>
* <entry>since 2.30</entry>
* <entry>1</entry>
+ * <entry></entry>
+ * </row>
+ * <row>
+ * <entry>since 3.2</entry>
+ * <entry>2</entry>
* <entry>current version</entry>
* </row>
* </tbody>
@@ -66,6 +71,7 @@
* </refsect2>
*/
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include "na-object-item.h"
G_BEGIN_DECLS
@@ -80,6 +86,7 @@ typedef struct _NAIExporterInterfacePrivate NAIExporterInterfacePrivate;
typedef struct _NAIExporterFileParms NAIExporterFileParms;
typedef struct _NAIExporterBufferParms NAIExporterBufferParms;
+#ifndef NA_DISABLE_DEPRECATED
/**
* NAIExporterFormat:
* @format: format identifier (ascii).
@@ -93,21 +100,86 @@ typedef struct _NAIExporterBufferParms NAIExporterBufferParms;
*
* When listing available export formats, the instance returns a #GList
* of these structures.
+ *
+ * Deprecated: 3.2
*/
typedef struct {
- gchar *format;
- gchar *label;
- gchar *description;
+ gchar *format;
+ gchar *label;
+ gchar *description;
}
NAIExporterFormat;
+#endif
+
+/**
+ * NAIExporterFormatExt:
+ * @version: the version of this #NAIExporterFormatExt structure (2).
+ * @provider: the #NAIExporter provider for this format.
+ * @format: format identifier (ascii, allocated by the Nautilus-Actions team).
+ * @label: short label to be displayed in dialog (UTF-8 localized)
+ * @description: full description of the format (UTF-8 localized);
+ * mainly used as a tooltip.
+ * @pixbuf: an image to be associated with this export format;
+ * this pixbuf is supposed to be rendered with GTK_ICON_SIZE_DIALOG size.
+ *
+ * This structure describes a supported output format.
+ * It must be provided by each #NAIExporter implementation
+ * (see e.g. <filename>src/io-xml/naxml-formats.c</filename>).
+ *
+ * When listing available export formats, the instance returns a #GList
+ * of these structures.
+ *
+ * <refsect2>
+ * <title>Versions historic</title>
+ * <table>
+ * <title>Historic of the versions of the #NAIExporteeFormat structure</title>
+ * <tgroup rowsep="1" colsep="1" align="center" cols="3">
+ * <colspec colname="na-version" />
+ * <colspec colname="api-version" />
+ * <colspec colname="current" />
+ * <thead>
+ * <row>
+ * <entry>&prodname; version</entry>
+ * <entry>#NAIExporterFormat structure version</entry>
+ * <entry></entry>
+ * </row>
+ * </thead>
+ * <tbody>
+ * <row>
+ * <entry>since 2.30</entry>
+ * <entry>1</entry>
+ * <entry></entry>
+ * </row>
+ * <row>
+ * <entry>since 3.2</entry>
+ * <entry>2</entry>
+ * <entry>current version</entry>
+ * </row>
+ * </tbody>
+ * </tgroup>
+ * </table>
+ * </refsect2>
+ *
+ * Since: 3.2
+ */
+typedef struct {
+ guint version;
+ NAIExporter *provider;
+ gchar *format;
+ gchar *label;
+ gchar *description;
+ GdkPixbuf *pixbuf;
+}
+ NAIExporterFormatExt;
/**
* NAIExporterInterface:
- * @get_version: returns the version of this interface the plugin implements.
- * @get_name: returns the public plugin name.
- * @get_formats: returns the list of supported formats.
- * @to_file: exports an item to a file.
- * @to_buffer: exports an item to a buffer.
+ * @get_version: returns the version of this interface the plugin implements.
+ * @get_name: returns the public plugin name.
+ * @get_formats: returns the list of supported formats.
+ * @free_formats: free a list of formats
+ * @to_file: exports an item to a file.
+ * @to_buffer: exports an item to a buffer.
*
* This defines the interface that a #NAIExporter should implement.
*/
@@ -127,7 +199,7 @@ typedef struct {
*
* Since: 2.30
*/
- guint ( *get_version )( const NAIExporter *instance );
+ guint ( *get_version )( const NAIExporter *instance );
/**
* get_name:
@@ -138,28 +210,69 @@ typedef struct {
*
* Since: 2.30
*/
- gchar * ( *get_name ) ( const NAIExporter *instance );
+ gchar * ( *get_name ) ( const NAIExporter *instance );
/**
* get_formats:
* @instance: this #NAIExporter instance.
*
- * The returned list is owned by the @instance. It must not be
- * released by the caller.
- *
* To avoid any collision, the format id is allocated by the
* Nautilus-Actions maintainer team. If you wish develop a new
* export format, and so need a new format id, please contact the
* maintainers (see #nautilus-actions.doap).
*
- * Returns: a list of #NAIExporterFormat structures which describe the
- * formats supported by @instance.
+ * Returns:
+ * <itemizedlist>
+ * <listitem>
+ * <formalpara>
+ * <title>
+ * Interface v1:
+ * </title>
+ * <para>
+ * a null-terminated list of #NAIExporterFormat structures
+ * which describes the formats supported by this #NAIExporter
+ * provider.
+ * </para>
+ * <para>
+ * The returned list is owned by the #NAIExporter provider,
+ * and should not be freed nor released by the caller.
+ * </para>
+ * </listitem>
+ * <listitem>
+ * <formalpara>
+ * <title>
+ * Interface v2:
+ * </title>
+ * <para>
+ * a #GList of #NAIExporterFormatExt structures
+ * which describes the formats supported by this #NAIExporter
+ * provider.
+ * </para>
+ * <para>
+ * The caller should then invoke the free_formats() method
+ * in order the provider be able to release the resources
+ * allocated to the list.
+ * </para>
+ * </listitem>
+ * </itemizedlist>
*
* Defaults to %NULL (no format at all).
*
* Since: 2.30
*/
- const NAIExporterFormat * ( *get_formats )( const NAIExporter *instance );
+ void * ( *get_formats )( const NAIExporter *instance );
+
+ /**
+ * free_formats:
+ * @instance: this #NAIExporter instance.
+ * @formats: a null-terminated list of #NAIExporterFormatExt structures,
+ * as returned by get_formats() method.
+ *
+ * Free the resources allocated to the @formats list.
+ *
+ * Since: 3.2
+ */
+ void ( *free_formats )( const NAIExporter *instance, GList *formats );
/**
* to_file:
@@ -173,7 +286,7 @@ typedef struct {
*
* Since: 2.30
*/
- guint ( *to_file ) ( const NAIExporter *instance, NAIExporterFileParms *parms );
+ guint ( *to_file ) ( const NAIExporter *instance, NAIExporterFileParms *parms );
/**
* to_buffer:
@@ -188,7 +301,7 @@ typedef struct {
*
* Since: 2.30
*/
- guint ( *to_buffer ) ( const NAIExporter *instance, NAIExporterBufferParms *parms );
+ guint ( *to_buffer ) ( const NAIExporter *instance, NAIExporterBufferParms *parms );
}
NAIExporterInterface;
diff --git a/src/core/na-export-format.c b/src/core/na-export-format.c
index bec2ffe..2b78be5 100644
--- a/src/core/na-export-format.c
+++ b/src/core/na-export-format.c
@@ -32,7 +32,7 @@
#include <config.h>
#endif
-#include <libintl.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include "na-export-format.h"
@@ -45,10 +45,13 @@ struct _NAExportFormatClassPrivate {
/* private instance data
*/
struct _NAExportFormatPrivate {
- gboolean dispose_has_run;
- GQuark id;
- NAIExporterFormat *str;
- NAIExporter *exporter;
+ gboolean dispose_has_run;
+ GQuark id;
+ gchar *format;
+ gchar *label;
+ gchar *description;
+ GdkPixbuf *pixbuf;
+ NAIExporter *provider;
};
static GObjectClass *st_parent_class = NULL;
@@ -146,6 +149,11 @@ instance_dispose( GObject *object )
self->private->dispose_has_run = TRUE;
+ if( self->private->pixbuf ){
+ g_object_unref( self->private->pixbuf );
+ self->private->pixbuf = NULL;
+ }
+
/* chain up to the parent class */
if( G_OBJECT_CLASS( st_parent_class )->dispose ){
G_OBJECT_CLASS( st_parent_class )->dispose( object );
@@ -164,6 +172,9 @@ instance_finalize( GObject *object )
g_debug( "%s: object=%p", thisfn, ( void * ) object );
self = NA_EXPORT_FORMAT( object );
+ g_free( self->private->format );
+ g_free( self->private->label );
+ g_free( self->private->description );
g_free( self->private );
/* chain call to parent class */
@@ -174,21 +185,23 @@ instance_finalize( GObject *object )
/*
* na_export_format_new:
- * @exporter_format: a #NAIExporterFormat which describes an export format.
- * @exporter: the #NAIExporter which provides this export format.
+ * @exporter_format: a #NAIExporterFormatExt which describes an export format.
*
* Returns: a newly allocated #NAExportFormat object.
*/
NAExportFormat *
-na_export_format_new( const NAIExporterFormat *exporter_format, const NAIExporter *exporter )
+na_export_format_new( const NAIExporterFormatExt *exporter_format )
{
NAExportFormat *format;
format = g_object_new( NA_EXPORT_FORMAT_TYPE, NULL );
format->private->id = g_quark_from_string( exporter_format->format );
- format->private->str = ( NAIExporterFormat * ) exporter_format;
- format->private->exporter = ( NAIExporter * ) exporter;
+ format->private->format = g_strdup( exporter_format->format );
+ format->private->label = g_strdup( exporter_format->label );
+ format->private->description = g_strdup( exporter_format->description );
+ format->private->pixbuf = exporter_format->pixbuf ? g_object_ref( exporter_format->pixbuf ) : NULL;
+ format->private->provider = exporter_format->provider;
return( format );
}
@@ -234,7 +247,7 @@ na_export_format_get_id( const NAExportFormat *format )
if( !format->private->dispose_has_run ){
- id = g_strdup( format->private->str->format );
+ id = g_strdup( format->private->format );
}
return( id );
@@ -258,7 +271,7 @@ na_export_format_get_label( const NAExportFormat *format )
if( !format->private->dispose_has_run ){
- label = g_strdup( gettext( format->private->str->label ));
+ label = g_strdup( format->private->label );
}
return( label );
@@ -282,7 +295,7 @@ na_export_format_get_description( const NAExportFormat *format )
if( !format->private->dispose_has_run ){
- description = g_strdup( gettext( format->private->str->description ));
+ description = g_strdup( format->private->description );
}
return( description );
@@ -308,7 +321,7 @@ na_export_format_get_exporter( const NAExportFormat *format )
if( !format->private->dispose_has_run ){
- exporter = format->private->exporter;
+ exporter = format->private->provider;
}
return( exporter );
diff --git a/src/core/na-export-format.h b/src/core/na-export-format.h
index 257435c..3cf6cac 100644
--- a/src/core/na-export-format.h
+++ b/src/core/na-export-format.h
@@ -63,12 +63,13 @@ typedef struct {
}
NAExportFormatClass;
-#define IPREFS_EXPORT_FORMAT_ASK g_quark_from_static_string( "Ask" )
+#define IPREFS_EXPORT_FORMAT_ASK_ID "Ask"
+#define IPREFS_EXPORT_FORMAT_ASK g_quark_from_static_string( IPREFS_EXPORT_FORMAT_ASK_ID )
#define IPREFS_EXPORT_NO_EXPORT 1
GType na_export_format_get_type( void );
-NAExportFormat *na_export_format_new( const NAIExporterFormat *exporter_format, const NAIExporter *exporter );
+NAExportFormat *na_export_format_new( const NAIExporterFormatExt *exporter_format );
GQuark na_export_format_get_quark ( const NAExportFormat *format );
gchar *na_export_format_get_id ( const NAExportFormat *format );
diff --git a/src/core/na-exporter.c b/src/core/na-exporter.c
index 5c3b22c..7767de7 100644
--- a/src/core/na-exporter.c
+++ b/src/core/na-exporter.c
@@ -40,9 +40,10 @@
extern gboolean iexporter_initialized;
extern gboolean iexporter_finalized;
-static const NAIExporterFormat *exporter_get_formats( const NAIExporter *exporter );
-static gchar *exporter_get_name( const NAIExporter *exporter );
-static NAIExporter *find_exporter_for_format( const NAPivot *pivot, GQuark 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 NAIExporter *find_exporter_for_format( const NAPivot *pivot, GQuark format );
/*
* na_exporter_get_formats:
@@ -59,7 +60,7 @@ na_exporter_get_formats( const NAPivot *pivot )
{
GList *iexporters, *imod;
GList *formats;
- const NAIExporterFormat *str;
+ GList *str_list, *is;
NAExportFormat *format;
g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
@@ -69,15 +70,16 @@ na_exporter_get_formats( const NAPivot *pivot )
if( iexporter_initialized && !iexporter_finalized ){
iexporters = na_pivot_get_providers( pivot, NA_IEXPORTER_TYPE );
- for( imod = iexporters ; imod ; imod = imod->next ){
- str = exporter_get_formats( NA_IEXPORTER( imod->data ));
- while( str->format ){
+ for( imod = iexporters ; imod ; imod = imod->next ){
+ str_list = exporter_get_formats( NA_IEXPORTER( imod->data ));
- format = na_export_format_new( str, NA_IEXPORTER( imod->data ));
+ for( is = str_list ; is ; is = is->next ){
+ format = na_export_format_new(( NAIExporterFormatExt * ) is->data );
formats = g_list_prepend( formats, format );
- str++;
}
+
+ exporter_free_formats( NA_IEXPORTER( imod->data ), str_list );
}
na_pivot_free_providers( iexporters );
@@ -89,7 +91,7 @@ na_exporter_get_formats( const NAPivot *pivot )
/*
* na_exporter_free_formats:
* @formats: a list of available export formats, as returned by
- * #na_exporter_get_formats().
+ * na_exporter_get_formats().
*
* Release the @formats #GList.
*/
@@ -244,18 +246,72 @@ na_exporter_to_file( const NAPivot *pivot, const NAObjectItem *item, const gchar
return( export_uri );
}
-static const NAIExporterFormat *
+/*
+ * Returns a GList of NAIExporterFormatExt structures which describes
+ * the export formats provided by the exporter
+ * If the provider only implements the v1 interface, we dynamically
+ * allocate a new structure and convert the v1 to the v2.
+ */
+static GList *
exporter_get_formats( const NAIExporter *exporter )
{
- const NAIExporterFormat *str;
+ GList *str_list;
+ guint version;
- str = NULL;
+ str_list = NULL;
+
+ version = 1;
+ if( NA_IEXPORTER_GET_INTERFACE( exporter )->get_version ){
+ version = NA_IEXPORTER_GET_INTERFACE( exporter )->get_version( exporter );
+ }
if( NA_IEXPORTER_GET_INTERFACE( exporter )->get_formats ){
- str = NA_IEXPORTER_GET_INTERFACE( exporter )->get_formats( exporter );
+ if( version == 1 ){
+#ifndef NA_DISABLE_DEPRECATED
+ ( const NAIExporterFormat * ) strv1 = NA_IEXPORTER_GET_INTERFACE( exporter )->get_formats( exporter );
+ while( strv1->format ){
+ NAIExporterFormatExt *strv2 = g_new0( NAIExporterFormatExt, 1 );
+ strv2->version = 1;
+ strv2->provider = exporter;
+ strv2->format = strv1->format;
+ strv2->label = strv1->label;
+ strv2->description = strv1->description;
+ strv2->pixbuf = NULL;
+ str_list = g_list_prepend( str_list, strv2 );
+ strv1++;
+ }
+#else
+ ;
+#endif
+ } else {
+ str_list = NA_IEXPORTER_GET_INTERFACE( exporter )->get_formats( exporter );
+ }
}
- return( str );
+ return( str_list );
+}
+
+/*
+ * Free the list returned by exporter_get_formats() for this provider
+ */
+static void
+exporter_free_formats( const NAIExporter *exporter, GList *str_list )
+{
+ guint version;
+
+ version = 1;
+ if( NA_IEXPORTER_GET_INTERFACE( exporter )->get_version ){
+ version = NA_IEXPORTER_GET_INTERFACE( exporter )->get_version( exporter );
+ }
+
+ if( version == 1 ){
+ g_list_foreach( str_list, ( GFunc ) g_free, NULL );
+ g_list_free( str_list );
+
+ } else {
+ g_return_if_fail( !NA_IEXPORTER_GET_INTERFACE( exporter )->free_formats );
+ NA_IEXPORTER_GET_INTERFACE( exporter )->free_formats( exporter, str_list );
+ }
}
static gchar *
diff --git a/src/io-desktop/nadp-desktop-provider.c b/src/io-desktop/nadp-desktop-provider.c
index 9fbb38a..2301533 100644
--- a/src/io-desktop/nadp-desktop-provider.c
+++ b/src/io-desktop/nadp-desktop-provider.c
@@ -39,6 +39,7 @@
#include <api/na-ifactory-provider.h>
#include "nadp-desktop-provider.h"
+#include "nadp-formats.h"
#include "nadp-keys.h"
#include "nadp-monitor.h"
#include "nadp-reader.h"
@@ -50,34 +51,33 @@ struct _NadpDesktopProviderClassPrivate {
void *empty; /* so that gcc -pedantic is happy */
};
-extern NAIExporterFormat nadp_formats[];
-
static GType st_module_type = 0;
static GObjectClass *st_parent_class = NULL;
static guint st_burst_timeout = 100; /* burst timeout in msec */
-static void class_init( NadpDesktopProviderClass *klass );
-static void instance_init( GTypeInstance *instance, gpointer klass );
-static void instance_dispose( GObject *object );
-static void instance_finalize( GObject *object );
+static void class_init( NadpDesktopProviderClass *klass );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_dispose( GObject *object );
+static void instance_finalize( GObject *object );
-static void iio_provider_iface_init( NAIIOProviderInterface *iface );
-static gchar *iio_provider_get_id( const NAIIOProvider *provider );
-static gchar *iio_provider_get_name( const NAIIOProvider *provider );
-static guint iio_provider_get_version( const NAIIOProvider *provider );
+static void iio_provider_iface_init( NAIIOProviderInterface *iface );
+static gchar *iio_provider_get_id( const NAIIOProvider *provider );
+static gchar *iio_provider_get_name( const NAIIOProvider *provider );
+static guint iio_provider_get_version( const NAIIOProvider *provider );
-static void ifactory_provider_iface_init( NAIFactoryProviderInterface *iface );
-static guint ifactory_provider_get_version( const NAIFactoryProvider *reader );
+static void ifactory_provider_iface_init( NAIFactoryProviderInterface *iface );
+static guint ifactory_provider_get_version( const NAIFactoryProvider *reader );
-static void iimporter_iface_init( NAIImporterInterface *iface );
-static guint iimporter_get_version( const NAIImporter *importer );
+static void iimporter_iface_init( NAIImporterInterface *iface );
+static guint iimporter_get_version( const NAIImporter *importer );
-static void iexporter_iface_init( NAIExporterInterface *iface );
-static guint iexporter_get_version( const NAIExporter *exporter );
-static gchar *iexporter_get_name( const NAIExporter *exporter );
-static const NAIExporterFormat *iexporter_get_formats( const NAIExporter *exporter );
+static void iexporter_iface_init( NAIExporterInterface *iface );
+static guint iexporter_get_version( const NAIExporter *exporter );
+static gchar *iexporter_get_name( const NAIExporter *exporter );
+static void *iexporter_get_formats( const NAIExporter *exporter );
+static void iexporter_free_formats( const NAIExporter *exporter, GList *format_list );
-static void on_monitor_timeout( NadpDesktopProvider *provider );
+static void on_monitor_timeout( NadpDesktopProvider *provider );
GType
nadp_desktop_provider_get_type( void )
@@ -309,6 +309,7 @@ iexporter_iface_init( NAIExporterInterface *iface )
iface->get_version = iexporter_get_version;
iface->get_name = iexporter_get_name;
iface->get_formats = iexporter_get_formats;
+ iface->free_formats = iexporter_free_formats;
iface->to_file = nadp_writer_iexporter_export_to_file;
iface->to_buffer = nadp_writer_iexporter_export_to_buffer;
}
@@ -316,7 +317,7 @@ iexporter_iface_init( NAIExporterInterface *iface )
static guint
iexporter_get_version( const NAIExporter *exporter )
{
- return( 1 );
+ return( 2 );
}
static gchar *
@@ -325,10 +326,16 @@ iexporter_get_name( const NAIExporter *exporter )
return( g_strdup( "NA Desktop Exporter" ));
}
-static const NAIExporterFormat *
+static void *
iexporter_get_formats( const NAIExporter *exporter )
{
- return( nadp_formats );
+ return(( void * ) nadp_formats_get_formats( exporter ));
+}
+
+static void
+iexporter_free_formats( const NAIExporter *exporter, GList *format_list )
+{
+ nadp_formats_free_formats( format_list );
}
/**
diff --git a/src/io-desktop/nadp-formats.c b/src/io-desktop/nadp-formats.c
index cc0cb60..fdd9ee2 100644
--- a/src/io-desktop/nadp-formats.c
+++ b/src/io-desktop/nadp-formats.c
@@ -33,12 +33,22 @@
#endif
#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <libintl.h>
#include <api/na-iexporter.h>
#include "nadp-formats.h"
-NAIExporterFormat nadp_formats[] = {
+typedef struct {
+ gchar *format;
+ gchar *label;
+ gchar *description;
+ gchar *image;
+}
+ NadpExportFormat;
+
+static NadpExportFormat nadp_formats[] = {
/* DESKTOP_V1: the initial desktop format as described in
* http://www.nautilus-actions.org/?q=node/377
@@ -54,7 +64,77 @@ NAIExporterFormat nadp_formats[] = {
"The exported .desktop file may later be imported via :\n" \
"- Import assistant of the Nautilus-Actions Configuration Tool,\n" \
"- drag-n-drop into the Nautilus-Actions Configuration Tool,\n" \
- "- or by copying it into a XDG_DATA_DIRS/file-manager/actions directory." ) },
+ "- or by copying it into a XDG_DATA_DIRS/file-manager/actions directory." ),
+ NULL },
{ NULL }
};
+
+/**
+ * nadp_formats_get_formats:
+ * @exporter: this #NAIExporter provider.
+ *
+ * Returns: a #GList of the #NAIExporterFormatExt supported export formats.
+ *
+ * This list should be nadp_formats_free_formats() by the caller.
+ *
+ * Since: 3.2
+ */
+GList *
+nadp_formats_get_formats( const NAIExporter* exporter )
+{
+ GList *str_list;
+ NAIExporterFormatExt *str;
+ guint i;
+ gint width, height;
+
+ str_list = NULL;
+
+ if( !gtk_icon_size_lookup( GTK_ICON_SIZE_DIALOG, &width, &height )){
+ width = height = 48;
+ }
+
+ for( i = 0 ; nadp_formats[i].format ; ++i ){
+ str = g_new0( NAIExporterFormatExt, 1 );
+ str->version = 2;
+ str->provider = NA_IEXPORTER( exporter );
+ str->format = g_strdup( nadp_formats[i].format );
+ str->label = g_strdup( gettext( nadp_formats[i].label ));
+ str->description = g_strdup( gettext( nadp_formats[i].description ));
+ if( nadp_formats[i].image ){
+ str->pixbuf = gdk_pixbuf_new_from_file_at_size( nadp_formats[i].image, width, height, NULL );
+ }
+ str_list = g_list_prepend( str_list, str );
+ }
+
+ return( str_list );
+}
+
+/**
+ * nadp_formats_free_formats:
+ * @formats: a #GList to be freed.
+ *
+ * Returns: a #GList of the #NAIExporterFormatExt supported export formats.
+ *
+ * This list should be nadp_format_free_formats() by the caller.
+ *
+ * Since: 3.2
+ */
+void
+nadp_formats_free_formats( GList *formats )
+{
+ GList *is;
+ NAIExporterFormatExt *str;
+
+ for( is = formats ; is ; is = is->next ){
+ str = ( NAIExporterFormatExt * ) is->data;
+ g_free( str->format );
+ g_free( str->label );
+ g_free( str->description );
+ if( str->pixbuf ){
+ g_object_unref( str->pixbuf );
+ }
+ }
+
+ g_list_free( formats );
+}
diff --git a/src/io-desktop/nadp-formats.h b/src/io-desktop/nadp-formats.h
index a1458ba..4b4ed38 100644
--- a/src/io-desktop/nadp-formats.h
+++ b/src/io-desktop/nadp-formats.h
@@ -33,10 +33,15 @@
#include <glib.h>
+#include <api/na-iexporter.h>
+
G_BEGIN_DECLS
#define NADP_FORMAT_DESKTOP_V1 "Desktop1"
+GList *nadp_formats_get_formats ( const NAIExporter *exporter );
+void nadp_formats_free_formats( GList *formats );
+
G_END_DECLS
-#endif /* __NAXML_FORMATS_H__ */
+#endif /* __NADP_FORMATS_H__ */
diff --git a/src/io-xml/naxml-formats.c b/src/io-xml/naxml-formats.c
index 0fb7bbe..5dd14c7 100644
--- a/src/io-xml/naxml-formats.c
+++ b/src/io-xml/naxml-formats.c
@@ -33,12 +33,20 @@
#endif
#include <glib/gi18n.h>
-
-#include <api/na-iexporter.h>
+#include <gtk/gtk.h>
+#include <libintl.h>
#include "naxml-formats.h"
-NAIExporterFormat naxml_formats[] = {
+typedef struct {
+ gchar *format;
+ gchar *label;
+ gchar *description;
+ gchar *image;
+}
+ NaxmlExportFormat;
+
+static NaxmlExportFormat naxml_formats[] = {
/* GCONF_SCHEMA_V1: a schema with owner, short and long descriptions;
* each action has its own schema addressed by the id
@@ -50,7 +58,8 @@ NAIExporterFormat naxml_formats[] = {
"The exported schema file may later be imported via :\n" \
"- Import assistant of the Nautilus-Actions Configuration Tool,\n" \
"- drag-n-drop into the Nautilus-Actions Configuration Tool,\n" \
- "- or via the gconftool-2 --import-schema-file command-line tool." ) },
+ "- or via the gconftool-2 --import-schema-file command-line tool." ),
+ NULL },
/* GCONF_SCHEMA_V2: the lightest schema still compatible with gconftool-2 --install-schema-file
* (no owner, no short nor long descriptions) - introduced in v 1.11
@@ -64,7 +73,8 @@ NAIExporterFormat naxml_formats[] = {
"The exported schema file may later be imported via :\n" \
"- Import assistant of the Nautilus-Actions Configuration Tool,\n" \
"- drag-n-drop into the Nautilus-Actions Configuration Tool,\n" \
- "- or via the gconftool-2 --import-schema-file command-line tool." ) },
+ "- or via the gconftool-2 --import-schema-file command-line tool." ),
+ NULL },
/* GCONF_ENTRY: not a schema, but a dump of the GConf entry
* introduced in v 1.11
@@ -78,7 +88,77 @@ NAIExporterFormat naxml_formats[] = {
"The exported dump file may later be imported via :\n" \
"- Import assistant of the Nautilus-Actions Configuration Tool (1.11 and above),\n" \
"- drag-n-drop into the Nautilus-Actions Configuration Tool (1.11 and above),\n" \
- "- or via the gconftool-2 --load command-line tool." ) },
+ "- or via the gconftool-2 --load command-line tool." ),
+ NULL },
{ NULL }
};
+
+/**
+ * naxml_formats_get_formats:
+ * @exporter: this #NAIExporter provider.
+ *
+ * Returns: a #GList of the #NAIExporterFormatExt supported export formats.
+ *
+ * This list should be naxml_formats_free_formats() by the caller.
+ *
+ * Since: 3.2
+ */
+GList *
+naxml_formats_get_formats( const NAIExporter* exporter )
+{
+ GList *str_list;
+ NAIExporterFormatExt *str;
+ guint i;
+ gint width, height;
+
+ str_list = NULL;
+
+ if( !gtk_icon_size_lookup( GTK_ICON_SIZE_DIALOG, &width, &height )){
+ width = height = 48;
+ }
+
+ for( i = 0 ; naxml_formats[i].format ; ++i ){
+ str = g_new0( NAIExporterFormatExt, 1 );
+ str->version = 2;
+ str->provider = NA_IEXPORTER( exporter );
+ str->format = g_strdup( naxml_formats[i].format );
+ str->label = g_strdup( gettext( naxml_formats[i].label ));
+ str->description = g_strdup( gettext( naxml_formats[i].description ));
+ if( naxml_formats[i].image ){
+ str->pixbuf = gdk_pixbuf_new_from_file_at_size( naxml_formats[i].image, width, height, NULL );
+ }
+ str_list = g_list_prepend( str_list, str );
+ }
+
+ return( str_list );
+}
+
+/**
+ * naxml_formats_free_formats:
+ * @formats: a #GList to be freed.
+ *
+ * Returns: a #GList of the #NAIExporterFormatExt supported export formats.
+ *
+ * This list should be naxml_format_free_formats() by the caller.
+ *
+ * Since: 3.2
+ */
+void
+naxml_formats_free_formats( GList *formats )
+{
+ GList *is;
+ NAIExporterFormatExt *str;
+
+ for( is = formats ; is ; is = is->next ){
+ str = ( NAIExporterFormatExt * ) is->data;
+ g_free( str->format );
+ g_free( str->label );
+ g_free( str->description );
+ if( str->pixbuf ){
+ g_object_unref( str->pixbuf );
+ }
+ }
+
+ g_list_free( formats );
+}
diff --git a/src/io-xml/naxml-formats.h b/src/io-xml/naxml-formats.h
index 5c4d0a1..1e8c47e 100644
--- a/src/io-xml/naxml-formats.h
+++ b/src/io-xml/naxml-formats.h
@@ -33,12 +33,17 @@
#include <glib.h>
+#include <api/na-iexporter.h>
+
G_BEGIN_DECLS
#define NAXML_FORMAT_GCONF_SCHEMA_V1 "GConfSchemaV1"
#define NAXML_FORMAT_GCONF_SCHEMA_V2 "GConfSchemaV2"
#define NAXML_FORMAT_GCONF_ENTRY "GConfEntry"
+GList *naxml_formats_get_formats ( const NAIExporter *exporter );
+void naxml_formats_free_formats( GList *format_list );
+
G_END_DECLS
#endif /* __NAXML_FORMATS_H__ */
diff --git a/src/io-xml/naxml-provider.c b/src/io-xml/naxml-provider.c
index 3ced3f7..82f8976 100644
--- a/src/io-xml/naxml-provider.c
+++ b/src/io-xml/naxml-provider.c
@@ -37,6 +37,7 @@
#include <api/na-iimporter.h>
#include "naxml-provider.h"
+#include "naxml-formats.h"
#include "naxml-reader.h"
#include "naxml-writer.h"
@@ -52,26 +53,25 @@ struct _NAXMLProviderPrivate {
gboolean dispose_has_run;
};
-extern NAIExporterFormat naxml_formats[];
-
static GType st_module_type = 0;
static GObjectClass *st_parent_class = NULL;
-static void class_init( NAXMLProviderClass *klass );
-static void instance_init( GTypeInstance *instance, gpointer klass );
-static void instance_dispose( GObject *object );
-static void instance_finalize( GObject *object );
+static void class_init( NAXMLProviderClass *klass );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_dispose( GObject *object );
+static void instance_finalize( GObject *object );
-static void iimporter_iface_init( NAIImporterInterface *iface );
-static guint iimporter_get_version( const NAIImporter *importer );
+static void iimporter_iface_init( NAIImporterInterface *iface );
+static guint iimporter_get_version( const NAIImporter *importer );
-static void iexporter_iface_init( NAIExporterInterface *iface );
-static guint iexporter_get_version( const NAIExporter *exporter );
-static gchar *iexporter_get_name( const NAIExporter *exporter );
-static const NAIExporterFormat *iexporter_get_formats( const NAIExporter *exporter );
+static void iexporter_iface_init( NAIExporterInterface *iface );
+static guint iexporter_get_version( const NAIExporter *exporter );
+static gchar *iexporter_get_name( const NAIExporter *exporter );
+static void *iexporter_get_formats( const NAIExporter *exporter );
+static void iexporter_free_formats( const NAIExporter *exporter, GList *format_list );
-static void ifactory_provider_iface_init( NAIFactoryProviderInterface *iface );
-static guint ifactory_provider_get_version( const NAIFactoryProvider *factory );
+static void ifactory_provider_iface_init( NAIFactoryProviderInterface *iface );
+static guint ifactory_provider_get_version( const NAIFactoryProvider *factory );
GType
naxml_provider_get_type( void )
@@ -230,6 +230,7 @@ iexporter_iface_init( NAIExporterInterface *iface )
iface->get_version = iexporter_get_version;
iface->get_name = iexporter_get_name;
iface->get_formats = iexporter_get_formats;
+ iface->free_formats = iexporter_free_formats;
iface->to_file = naxml_writer_export_to_file;
iface->to_buffer = naxml_writer_export_to_buffer;
}
@@ -237,7 +238,7 @@ iexporter_iface_init( NAIExporterInterface *iface )
static guint
iexporter_get_version( const NAIExporter *exporter )
{
- return( 1 );
+ return( 2 );
}
static gchar *
@@ -246,10 +247,16 @@ iexporter_get_name( const NAIExporter *exporter )
return( g_strdup( "NAXML Exporter" ));
}
-static const NAIExporterFormat *
+static void *
iexporter_get_formats( const NAIExporter *exporter )
{
- return( naxml_formats );
+ return(( void * ) naxml_formats_get_formats( exporter ));
+}
+
+static void
+iexporter_free_formats( const NAIExporter *exporter, GList *format_list )
+{
+ naxml_formats_free_formats( format_list );
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]