[nautilus-actions] Define NAIExporter interface



commit e7a242f561373ae7778dbccf8f218ab0cd6a530a
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Feb 15 19:57:25 2010 +0100

    Define NAIExporter interface

 ChangeLog               |    5 ++
 src/api/Makefile.am     |    1 +
 src/api/na-iexporter.h  |  129 +++++++++++++++++++++++++++++++++++++++++
 src/core/Makefile.am    |    1 +
 src/core/na-iexporter.c |  146 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 282 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8743da6..3eb1b3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-02-15 Pierre Wieser <pwieser trychlos org>
 
+	Define NAIExporter interface.
+
+	* src/api/na-iexporter.h:
+	* src/core/na-iexporter.c: New files.
+
 	* src/core/na-dbus-tracker.h: New file.
 
 	Remove useless src/api/na-gconf-keys.h
diff --git a/src/api/Makefile.am b/src/api/Makefile.am
index 22579e5..c5423c7 100644
--- a/src/api/Makefile.am
+++ b/src/api/Makefile.am
@@ -35,6 +35,7 @@ api_include_HEADERS = \
 	na-idata-factory.h									\
 	na-idata-factory-enum.h								\
 	na-idata-factory-str.h								\
+	na-iexporter.h										\
 	na-iio-factory.h									\
 	na-iio-factory-factory.h							\
 	na-iio-provider.h									\
diff --git a/src/api/na-iexporter.h b/src/api/na-iexporter.h
new file mode 100644
index 0000000..470c894
--- /dev/null
+++ b/src/api/na-iexporter.h
@@ -0,0 +1,129 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Frederic Ruaudel <grumz grumz net>
+ *   Rodrigo Moya <rodrigo gnome-db org>
+ *   Pierre Wieser <pwieser trychlos org>
+ *   ... and many others (see AUTHORS)
+ */
+
+#ifndef __NAUTILUS_ACTIONS_API_NA_IEXPORTER_H__
+#define __NAUTILUS_ACTIONS_API_NA_IEXPORTER_H__
+
+/**
+ * SECTION: na_iexporter
+ * @short_description: #NAIExporter interface definition.
+ * @include: nautilus-actions/na-iexporter.h
+ *
+ * The #NAIExporter interface exports items to the outside world.
+ *
+ * Nautilus-Actions v 2.30 - API version:  1
+ */
+
+#include "na-object-item.h"
+
+G_BEGIN_DECLS
+
+#define NA_IEXPORTER_TYPE						( na_iexporter_get_type())
+#define NA_IEXPORTER( instance )				( G_TYPE_CHECK_INSTANCE_CAST( instance, NA_IEXPORTER_TYPE, NAIExporter ))
+#define NA_IS_IEXPORTER( instance )				( G_TYPE_CHECK_INSTANCE_TYPE( instance, NA_IEXPORTER_TYPE ))
+#define NA_IEXPORTER_GET_INTERFACE( instance )	( G_TYPE_INSTANCE_GET_INTERFACE(( instance ), NA_IEXPORTER_TYPE, NAIExporterInterface ))
+
+typedef struct NAIExporter                 NAIExporter;
+
+typedef struct NAIExporterInterfacePrivate NAIExporterInterfacePrivate;
+
+typedef struct {
+	GTypeInterface             parent;
+	NAIExporterInterfacePrivate *private;
+
+	/**
+	 * get_version:
+	 * @instance: this #NAIExporter instance.
+	 *
+	 * Returns: the version of this interface supported by the I/O provider.
+	 *
+	 * Defaults to 1.
+	 */
+	guint    ( *get_version )( const NAIExporter *instance );
+
+	/**
+	 * get_formats:
+	 * @instance: this #NAIExporter instance.
+	 *
+	 * Returns: a list of #NAExporterStr structures which describe the
+	 * formats supported by @instance.
+	 *
+	 * Defaults to %NULL (no format at all).
+	 *
+	 * #NAExporterStr structures addressed in the returned list are
+	 * owned by the @instance. They must not be released by the caller.
+	 * Only the list itself should be g_list_free().
+	 */
+	GList *  ( *get_formats )( const NAIExporter *instance );
+
+	/**
+	 * export:
+	 * @instance: this #NAIExporter instance.
+	 * @item: a #NAObjectItem-derived object.
+	 * @uri: the target directory URI.
+	 * @format: the target format.
+	 * @fname: the place where allocate a new string to store the output
+	 * filename URI.
+	 *
+	 * Exports the specified @item to the target @uri in the required
+	 * @format.
+	 *
+	 * Returns: the status of the operation.
+	 */
+	guint    ( *export )     ( const NAIExporter *instance, const NAObjectItem *item, const gchar *uri, const gchar *format, gchar **fname );
+}
+	NAIExporterInterface;
+
+GType na_iexporter_get_type( void );
+
+/* When listing available export formats, the instance returns a GList
+ * of these structures
+ */
+typedef struct {
+	gchar *format;						/* format identifier (ascii) */
+	gchar *ui_label;					/* short label to be displayed in the UI (UTF-8 locale) */
+	gchar *ui_description;				/* full description of the format (UTF-8 locale) */
+}
+	NAExporterStr;
+
+/* The reasons for which an item may not have been exported
+ */
+enum {
+	NA_IEXPORTER_CODE_OK = 0,
+	NA_IEXPORTER_CODE_INVALID_ITEM,
+	NA_IEXPORTER_CODE_INVALID_TARGET,
+	NA_IEXPORTER_CODE_INVALID_FORMAT,
+	NA_IEXPORTER_CODE_UNABLE_TO_WRITE,
+	NA_IEXPORTER_CODE_ERROR,
+};
+
+G_END_DECLS
+
+#endif /* __NAUTILUS_ACTIONS_API_NA_IEXPORTER_H__ */
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index a71ec22..e1c77dc 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -47,6 +47,7 @@ libna_core_la_SOURCES = \
 	na-gconf-utils.c									\
 	na-iduplicable.c									\
 	na-idata-factory.c									\
+	na-iexporter.c										\
 	na-iio-factory.c									\
 	na-iio-provider.c									\
 	na-io-factory.c										\
diff --git a/src/core/na-iexporter.c b/src/core/na-iexporter.c
new file mode 100644
index 0000000..090a738
--- /dev/null
+++ b/src/core/na-iexporter.c
@@ -0,0 +1,146 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Frederic Ruaudel <grumz grumz net>
+ *   Rodrigo Moya <rodrigo gnome-db org>
+ *   Pierre Wieser <pwieser trychlos org>
+ *   ... and many others (see AUTHORS)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <api/na-iexporter.h>
+
+/* private interface data
+ */
+struct NAIExporterInterfacePrivate {
+	void *empty;						/* so that gcc -pedantic is happy */
+};
+
+static gboolean st_initialized = FALSE;
+static gboolean st_finalized   = FALSE;
+
+static GType  register_type( void );
+static void   interface_base_init( NAIExporterInterface *klass );
+static void   interface_base_finalize( NAIExporterInterface *klass );
+
+static guint  iexporter_get_version( const NAIExporter *instance );
+static GList *iexporter_get_formats( const NAIExporter *instance );
+
+/**
+ * na_iexporter_get_type:
+ *
+ * Returns: the #GType type of this interface.
+ */
+GType
+na_iexporter_get_type( void )
+{
+	static GType type = 0;
+
+	if( !type ){
+		type = register_type();
+	}
+
+	return( type );
+}
+
+/*
+ * na_iexporter_register_type:
+ *
+ * Registers this interface.
+ */
+static GType
+register_type( void )
+{
+	static const gchar *thisfn = "na_iexporter_register_type";
+	GType type;
+
+	static const GTypeInfo info = {
+		sizeof( NAIExporterInterface ),
+		( GBaseInitFunc ) interface_base_init,
+		( GBaseFinalizeFunc ) interface_base_finalize,
+		NULL,
+		NULL,
+		NULL,
+		0,
+		0,
+		NULL
+	};
+
+	g_debug( "%s", thisfn );
+
+	type = g_type_register_static( G_TYPE_INTERFACE, "NAIExporter", &info, 0 );
+
+	g_type_interface_add_prerequisite( type, G_TYPE_OBJECT );
+
+	return( type );
+}
+
+static void
+interface_base_init( NAIExporterInterface *klass )
+{
+	static const gchar *thisfn = "na_iexporter_interface_base_init";
+
+	if( !st_initialized ){
+
+		g_debug( "%s: klass%p (%s)", thisfn, ( void * ) klass, G_OBJECT_CLASS_NAME( klass ));
+
+		klass->private = g_new0( NAIExporterInterfacePrivate, 1 );
+
+		klass->get_version = iexporter_get_version;
+		klass->get_formats = iexporter_get_formats;
+		klass->export = NULL;
+
+		st_initialized = TRUE;
+	}
+}
+
+static void
+interface_base_finalize( NAIExporterInterface *klass )
+{
+	static const gchar *thisfn = "na_iexporter_interface_base_finalize";
+
+	if( st_initialized && !st_finalized ){
+
+		g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
+
+		st_finalized = TRUE;
+
+		g_free( klass->private );
+	}
+}
+
+static guint
+iexporter_get_version( const NAIExporter *instance )
+{
+	return( 1 );
+}
+
+static GList *
+iexporter_get_formats( const NAIExporter *instance )
+{
+	return( NULL );
+}



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