[nautilus-actions: 28/45] Fix and update nautilus-actions-new utility



commit 3cf81160dec672d465b87e3dce9cbc36cf7a7294
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Jul 28 20:07:32 2009 +0200

    Fix and update nautilus-actions-new utility

 ChangeLog                                          |   37 +++-
 m4/na-log-domains.m4                               |    3 +
 src/common/Makefile.am                             |    3 +
 src/common/na-iio-provider.c                       |    7 +-
 .../nact-gconf-keys.h => common/na-xml-names.h}    |   34 ++-
 .../nact-gconf-writer.c => common/na-xml-writer.c} |  155 ++++++-----
 src/common/na-xml-writer.h                         |   78 ++++++
 src/nact/.gitignore                                |    1 +
 src/nact/Makefile.am                               |   12 +-
 src/nact/nact-application.c                        |    2 +-
 src/nact/nact-assist-export.c                      |    6 +-
 src/nact/nact-gconf-reader.c                       |    2 +-
 src/nact/nact-gconf-writer.h                       |   77 ------
 src/nact/nact-import-export-format.h               |   57 ----
 src/nact/nact.desktop.in                           |    2 +-
 ...s-config.ui => nautilus-actions-config-tool.ui} |    0
 src/utils/.gitignore                               |    1 +
 src/utils/Makefile.am                              |   21 +-
 src/utils/nautilus-actions-new-config.c            |  201 --------------
 src/utils/nautilus-actions-new.c                   |  276 ++++++++++++++++++++
 src/utils/nautilus-actions-tools-utils.c           |   68 -----
 src/utils/nautilus-actions-tools-utils.h           |   45 ----
 22 files changed, 531 insertions(+), 557 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 646f10c..a7fcd61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2009-07-28 Pierre Wieser <pwieser trychlos org>
+
+	* src/common/na-iio-provider.c:
+	Write action now accepts a NULL NAPivot to deal with command-line
+	utility.
+
+	* src/nact/nact-gconf-keys.h:
+	Renamed as src/common/na-xml-names.h.
+
+	* src/nact/nact-gconf-writer.{c,h}:
+	Renamed as src/common/na-xml-writer.{c,h}.
+
+	* src/nact/nact-import-export-format.h: Removed file.
+
+	* src/nact/nautilus-actions-config.ui:
+	Renamed as src/nact/nautilus-actions-config-tool.ui.
+
+	* src/utils/nautilus-actions-new-config.c:
+	Renamed as src/utils/nautilus-actions-new.c.
+
+	* src/utils/nautilus-actions-tools-utils.c:
+	* src/utils/nautilus-actions-tools-utils.h: Removed files.
+
+	* configure.ac:
+	* src/common/Makefile.am:
+	* src/nact/Makefile.am:
+	* src/nact/nact-application.c:
+	* src/nact/nact-assist-export.c:
+	* src/nact/nact.desktop.in
+	* src/utils/Makefile.am: Updated accordingly.
+
+	* m4/na-log-domains.m4:
+	Define a new log domain for utilities.
+
 2009-07-27 Pierre Wieser <pwieser trychlos org>
 
 	* m4/na-log-domains.m4: New file.
@@ -7,8 +41,7 @@
 	* m4/nact-maintainer-mode.m4: Renamed to m4/na-maintainer-mode.m4.
 	* m4/nact-nautilus-extdir.m4: Renamed to m4/na-nautilus-extdir.m4.
 
-	* configure.ac:
-	Updated accordingly.
+	* configure.ac: Updated accordingly.
 
 	* src/common/na-object.c:
 	* src/common/na-object.h (na_object_check_edited_status):
diff --git a/m4/na-log-domains.m4 b/m4/na-log-domains.m4
index 0c5d067..c03ec05 100644
--- a/m4/na-log-domains.m4
+++ b/m4/na-log-domains.m4
@@ -13,4 +13,7 @@ AC_DEFUN([NA_LOG_DOMAINS],[
 
 	AC_SUBST([NA_LOGDOMAIN_NACT],[NA-nact])
 	AC_DEFINE_UNQUOTED([NA_LOGDOMAIN_NACT],["NA-nact"],[Log domain of NACT user interface])
+
+	AC_SUBST([NA_LOGDOMAIN_UTILS],[NA-utils])
+	AC_DEFINE_UNQUOTED([NA_LOGDOMAIN_UTILS],["NA-utils"],[Log domain of utilities])
 ])
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index cac8002..83867d9 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -56,6 +56,9 @@ libnact_la_SOURCES = \
 	na-pivot.h									\
 	na-utils.c									\
 	na-utils.h									\
+	na-xml-names.h								\
+	na-xml-writer.c								\
+	na-xml-writer.h								\
 	$(NULL)
 
 libnact_la_LIBADD = -lxml2 -luuid
diff --git a/src/common/na-iio-provider.c b/src/common/na-iio-provider.c
index 05d617d..0c15fe7 100644
--- a/src/common/na-iio-provider.c
+++ b/src/common/na-iio-provider.c
@@ -180,7 +180,8 @@ na_iio_provider_read_actions( const NAPivot *pivot )
 /**
  * na_iio_provider_write_action:
  * @pivot: the #NAPivot object which owns the list of registered I/O
- * storage providers.
+ * storage providers. if NULL, @action must already have registered
+ * its own provider.
  * @action: the #NAAction action to be written.
  * @message: the I/O provider can allocate and store here an error
  * message.
@@ -195,7 +196,7 @@ na_iio_provider_write_action( const NAPivot *pivot, NAAction *action, gchar **me
 	static const gchar *thisfn = "na_iio_provider_write_action";
 	g_debug( "%s: pivot=%p, action=%p, message=%p", thisfn, pivot, action, message );
 
-	g_assert( NA_IS_PIVOT( pivot ));
+	g_assert( NA_IS_PIVOT( pivot ) || !pivot );
 	g_assert( NA_IS_ACTION( action ));
 
 	guint ret = NA_IIO_PROVIDER_NOT_WRITABLE;
@@ -214,7 +215,7 @@ na_iio_provider_write_action( const NAPivot *pivot, NAAction *action, gchar **me
 
 	/* else, search for a provider which is willing to write the action
 	 */
-	if( !instance ){
+	if( !instance && pivot ){
 		GSList *providers = na_pivot_get_providers( pivot, NA_IIO_PROVIDER_TYPE );
 		GSList *ip;
 		for( ip = providers ; ip ; ip = ip->next ){
diff --git a/src/nact/nact-gconf-keys.h b/src/common/na-xml-names.h
similarity index 90%
rename from src/nact/nact-gconf-keys.h
rename to src/common/na-xml-names.h
index c39f89d..dbd1221 100644
--- a/src/nact/nact-gconf-keys.h
+++ b/src/common/na-xml-names.h
@@ -28,13 +28,32 @@
  *   ... and many others (see AUTHORS)
  */
 
-#ifndef __NACT_GCONF_KEYS_H__
-#define __NACT_GCONF_KEYS_H__
+#ifndef __NA_XML_NAMES_H__
+#define __NA_XML_NAMES_H__
 
-#include <glib-object.h>
+#include <glib/gi18n.h>
 
 G_BEGIN_DECLS
 
+/* import/export formats
+ *
+ * FORMAT_GCONFSCHEMAFILE_V1: a schema with owner, short and long
+ * descriptions ; each action has its own schema addressed by the uuid
+ * (historical format up to v1.10.x serie)
+ *
+ * FORMAT_GCONFSCHEMAFILE_V2: the lightest schema still compatible
+ * with gconftool-2 --install-schema-file (no owner, no short nor long
+ * descriptions) - introduced in v 1.11
+ *
+ * FORMAT_GCONFENTRY: not a schema, but a dump of the GConf entry
+ * introduced in v 1.11
+ */
+enum {
+	FORMAT_GCONFSCHEMAFILE_V1 = 1,
+	FORMAT_GCONFSCHEMAFILE_V2,
+	FORMAT_GCONFENTRY
+};
+
 /* XML element names (GConf schema)
  * used in FORMAT_GCONFSCHEMAFILE_V1 and FORMAT_GCONFSCHEMAFILE_V2
  */
@@ -48,15 +67,14 @@ G_BEGIN_DECLS
 #define NACT_GCONF_SCHEMA_LOCALE			"locale"
 #define NACT_GCONF_SCHEMA_DEFAULT			"default"
 
-/* Previous used keys
+/* Previouly used keys
  *
  * Up to v 1.10, export used to contain a full schema description,
  * while import only checked for applyto keys (along with locale
  * and default)
  *
- * Starting with 1.11, export only contains required keys (applyto,
- * default and locale) ; import of course accept all previous keys
- * without warning
+ * Starting with 1.11, we have introduced a lighter export schema
+ * (mainly without owner and short and long descriptions)
  *
  * only used in FORMAT_GCONFSCHEMAFILE_V1
  */
@@ -110,4 +128,4 @@ G_BEGIN_DECLS
 
 G_END_DECLS
 
-#endif /* __NACT_GCONF_KEYS_H__ */
+#endif /* __NA_XML_NAMES_H__ */
diff --git a/src/nact/nact-gconf-writer.c b/src/common/na-xml-writer.c
similarity index 83%
rename from src/nact/nact-gconf-writer.c
rename to src/common/na-xml-writer.c
index 258f173..7074f71 100644
--- a/src/nact/nact-gconf-writer.c
+++ b/src/common/na-xml-writer.c
@@ -35,21 +35,20 @@
 #include <glib/gi18n.h>
 #include <libxml/tree.h>
 
-#include <common/na-gconf-keys.h>
-#include <common/na-utils.h>
-
-#include "nact-gconf-keys.h"
-#include "nact-gconf-writer.h"
-#include "nact-import-export-format.h"
+#include "na-action-profile.h"
+#include "na-gconf-keys.h"
+#include "na-utils.h"
+#include "na-xml-names.h"
+#include "na-xml-writer.h"
 
 /* private class data
  */
-struct NactGConfWriterClassPrivate {
+struct NAXMLWriterClassPrivate {
 };
 
 /* private instance data
  */
-struct NactGConfWriterPrivate {
+struct NAXMLWriterPrivate {
 	gboolean  dispose_has_run;
 	gchar    *uuid;
 };
@@ -64,41 +63,41 @@ enum {
 
 static GObjectClass *st_parent_class = NULL;
 
-static GType            register_type( void );
-static void             class_init( NactGConfWriterClass *klass );
-static void             instance_init( GTypeInstance *instance, gpointer klass );
-static void             instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
-static void             instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
-static void             instance_dispose( GObject *object );
-static void             instance_finalize( GObject *object );
-
-static NactGConfWriter *gconf_writer_new( const gchar *uuid );
-static xmlDocPtr        create_xml_schema( NactGConfWriter *writer, gint format, NAAction *action );
-static void             create_schema_entry(
-										NactGConfWriter *writer,
-										gint format,
-										const gchar *profile_name,
-										const gchar *key,
-										const gchar *value,
-										xmlDocPtr doc,
-										xmlNodePtr list_node,
-										const gchar *type,
-										gboolean is_l10n_value,
-										const gchar *short_desc,
-										const gchar *long_desc );
-static xmlDocPtr        create_xml_dump( NactGConfWriter *writer, gint format, NAAction *action );
-static void             create_dump_entry(
-										NactGConfWriter *writer,
-										gint format,
-										const gchar *profile_name,
-										const gchar *key,
-										const gchar *value,
-										xmlDocPtr doc,
-										xmlNodePtr list_node,
-										const gchar *type );
+static GType        register_type( void );
+static void         class_init( NAXMLWriterClass *klass );
+static void         instance_init( GTypeInstance *instance, gpointer klass );
+static void         instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
+static void         instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
+static void         instance_dispose( GObject *object );
+static void         instance_finalize( GObject *object );
+
+static NAXMLWriter *xml_writer_new( const gchar *uuid );
+static xmlDocPtr    create_xml_schema( NAXMLWriter *writer, gint format, NAAction *action );
+static void         create_schema_entry(
+								NAXMLWriter *writer,
+								gint format,
+								const gchar *profile_name,
+								const gchar *key,
+								const gchar *value,
+								xmlDocPtr doc,
+								xmlNodePtr list_node,
+								const gchar *type,
+								gboolean is_l10n_value,
+								const gchar *short_desc,
+								const gchar *long_desc );
+static xmlDocPtr    create_xml_dump( NAXMLWriter *writer, gint format, NAAction *action );
+static void         create_dump_entry(
+								NAXMLWriter *writer,
+								gint format,
+								const gchar *profile_name,
+								const gchar *key,
+								const gchar *value,
+								xmlDocPtr doc,
+								xmlNodePtr list_node,
+								const gchar *type );
 
 GType
-nact_gconf_writer_get_type( void )
+na_xml_writer_get_type( void )
 {
 	static GType object_type = 0;
 
@@ -113,26 +112,26 @@ static GType
 register_type( void )
 {
 	static GTypeInfo info = {
-		sizeof( NactGConfWriterClass ),
+		sizeof( NAXMLWriterClass ),
 		NULL,
 		NULL,
 		( GClassInitFunc ) class_init,
 		NULL,
 		NULL,
-		sizeof( NactGConfWriter ),
+		sizeof( NAXMLWriter ),
 		0,
 		( GInstanceInitFunc ) instance_init
 	};
 
-	GType type = g_type_register_static( G_TYPE_OBJECT, "NactGConfWriter", &info, 0 );
+	GType type = g_type_register_static( G_TYPE_OBJECT, "NAXMLWriter", &info, 0 );
 
 	return( type );
 }
 
 static void
-class_init( NactGConfWriterClass *klass )
+class_init( NAXMLWriterClass *klass )
 {
-	static const gchar *thisfn = "nact_gconf_writer_class_init";
+	static const gchar *thisfn = "na_xml_writer_class_init";
 	g_debug( "%s: klass=%p", thisfn, klass );
 
 	st_parent_class = g_type_class_peek_parent( klass );
@@ -151,19 +150,19 @@ class_init( NactGConfWriterClass *klass )
 			G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
 	g_object_class_install_property( object_class, PROP_GCONF_WRITER_UUID, spec );
 
-	klass->private = g_new0( NactGConfWriterClassPrivate, 1 );
+	klass->private = g_new0( NAXMLWriterClassPrivate, 1 );
 }
 
 static void
 instance_init( GTypeInstance *instance, gpointer klass )
 {
-	static const gchar *thisfn = "nact_gconf_writer_instance_init";
+	static const gchar *thisfn = "na_xml_writer_instance_init";
 	g_debug( "%s: instance=%p, klass=%p", thisfn, instance, klass );
 
-	g_assert( NACT_IS_GCONF_WRITER( instance ));
-	NactGConfWriter *self = NACT_GCONF_WRITER( instance );
+	g_assert( NA_IS_XML_WRITER( instance ));
+	NAXMLWriter *self = NA_XML_WRITER( instance );
 
-	self->private = g_new0( NactGConfWriterPrivate, 1 );
+	self->private = g_new0( NAXMLWriterPrivate, 1 );
 
 	self->private->dispose_has_run = FALSE;
 }
@@ -171,8 +170,8 @@ instance_init( GTypeInstance *instance, gpointer klass )
 static void
 instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec )
 {
-	g_assert( NACT_IS_GCONF_WRITER( object ));
-	NactGConfWriter *self = NACT_GCONF_WRITER( object );
+	g_assert( NA_IS_XML_WRITER( object ));
+	NAXMLWriter *self = NA_XML_WRITER( object );
 
 	switch( property_id ){
 		case PROP_GCONF_WRITER_UUID:
@@ -188,8 +187,8 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
 static void
 instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec )
 {
-	g_assert( NACT_IS_GCONF_WRITER( object ));
-	NactGConfWriter *self = NACT_GCONF_WRITER( object );
+	g_assert( NA_IS_XML_WRITER( object ));
+	NAXMLWriter *self = NA_XML_WRITER( object );
 
 	switch( property_id ){
 		case PROP_GCONF_WRITER_UUID:
@@ -206,8 +205,8 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
 static void
 instance_dispose( GObject *object )
 {
-	g_assert( NACT_IS_GCONF_WRITER( object ));
-	NactGConfWriter *self = NACT_GCONF_WRITER( object );
+	g_assert( NA_IS_XML_WRITER( object ));
+	NAXMLWriter *self = NA_XML_WRITER( object );
 
 	if( !self->private->dispose_has_run ){
 
@@ -221,8 +220,8 @@ instance_dispose( GObject *object )
 static void
 instance_finalize( GObject *object )
 {
-	g_assert( NACT_IS_GCONF_WRITER( object ));
-	NactGConfWriter *self = NACT_GCONF_WRITER( object );
+	g_assert( NA_IS_XML_WRITER( object ));
+	NAXMLWriter *self = NA_XML_WRITER( object );
 
 	g_free( self->private->uuid );
 
@@ -234,22 +233,27 @@ instance_finalize( GObject *object )
 	}
 }
 
-static NactGConfWriter *
-gconf_writer_new( const gchar *uuid )
+static NAXMLWriter *
+xml_writer_new( const gchar *uuid )
 {
-	return( g_object_new( NACT_GCONF_WRITER_TYPE, PROP_GCONF_WRITER_UUID_STR, uuid, NULL ));
+	return( g_object_new( NA_XML_WRITER_TYPE, PROP_GCONF_WRITER_UUID_STR, uuid, NULL ));
 }
 
 /**
- * Export the specified action as a GConf schema.
+ * na_xml_writer_export:
+ * @action:
+ * @folder: the directoy where to write the output XML file.
+ * If NULL, the output will be directed to stdout.
+ *
+ * Export the specified action as an XML file.
  *
- * Returns the written filename.
+ * Returns: the written filename, or NULL if written to stdout.
  */
 gchar *
-nact_gconf_writer_export( NAAction *action, const gchar *folder, gint format, gchar **msg )
+na_xml_writer_export( NAAction *action, const gchar *folder, gint format, gchar **msg )
 {
 	gchar *uuid = na_action_get_uuid( action );
-	NactGConfWriter *writer = gconf_writer_new( uuid );
+	NAXMLWriter *writer = xml_writer_new( uuid );
 	g_free( uuid );
 
 	xmlDocPtr doc = NULL;
@@ -268,7 +272,11 @@ nact_gconf_writer_export( NAAction *action, const gchar *folder, gint format, gc
 
 		case FORMAT_GCONFENTRY:
 			doc = create_xml_dump( writer, format, action );
-			filename = g_strdup_printf( "%s/action-%s.xml", folder, writer->private->uuid );
+			if( folder ){
+				filename = g_strdup_printf( "%s/action-%s.xml", folder, writer->private->uuid );
+			} else {
+				filename = g_strdup( "-" );
+			}
 			break;
 	}
 
@@ -280,6 +288,11 @@ nact_gconf_writer_export( NAAction *action, const gchar *folder, gint format, gc
 		filename = NULL;
 	}
 
+	if( !folder ){
+		g_free( filename );
+		filename = NULL;
+	}
+
 	xmlFreeDoc (doc);
 	xmlCleanupParser();
 	g_object_unref( writer );
@@ -288,7 +301,7 @@ nact_gconf_writer_export( NAAction *action, const gchar *folder, gint format, gc
 }
 
 static xmlDocPtr
-create_xml_schema( NactGConfWriter *writer, gint format, NAAction *action )
+create_xml_schema( NAXMLWriter *writer, gint format, NAAction *action )
 {
 	xmlDocPtr doc = xmlNewDoc( BAD_CAST( "1.0" ));
 	xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST( NACT_GCONF_SCHEMA_ROOT ));
@@ -390,7 +403,7 @@ create_xml_schema( NactGConfWriter *writer, gint format, NAAction *action )
 }
 
 static void
-create_schema_entry( NactGConfWriter *writer,
+create_schema_entry( NAXMLWriter *writer,
 		gint format,
 		const gchar *profile_name, const gchar *key, const gchar *value,
 		xmlDocPtr doc, xmlNodePtr list_node, const gchar *type, gboolean is_l10n_value,
@@ -447,7 +460,7 @@ create_schema_entry( NactGConfWriter *writer,
 }
 
 static xmlDocPtr
-create_xml_dump( NactGConfWriter *writer, gint format, NAAction *action )
+create_xml_dump( NAXMLWriter *writer, gint format, NAAction *action )
 {
 	xmlDocPtr doc = xmlNewDoc( BAD_CAST( "1.0" ));
 	xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST( NACT_GCONF_DUMP_ROOT ));
@@ -553,7 +566,7 @@ create_xml_dump( NactGConfWriter *writer, gint format, NAAction *action )
 }
 
 static void
-create_dump_entry( NactGConfWriter *writer,
+create_dump_entry( NAXMLWriter *writer,
 		gint format,
 		const gchar *profile_name, const gchar *key, const gchar *value,
 		xmlDocPtr doc, xmlNodePtr list_node, const gchar *type )
diff --git a/src/common/na-xml-writer.h b/src/common/na-xml-writer.h
new file mode 100644
index 0000000..efbd22a
--- /dev/null
+++ b/src/common/na-xml-writer.h
@@ -0,0 +1,78 @@
+/*
+ * 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 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 __NA_XML_WRITER_H__
+#define __NA_XML_WRITER_H__
+
+/**
+ * SECTION: na_xml_writer
+ * @short_description: #NAXMLWriter class definition.
+ * @include: common/na-xml-writer.h
+ *
+ * This class exports Nautilus Actions as XML files.
+ *
+ * This class is embedded in libnact library as it is used by
+ * nautilus-actions-new utility.
+ */
+
+#include "na-action.h"
+
+G_BEGIN_DECLS
+
+#define NA_XML_WRITER_TYPE					( na_xml_writer_get_type())
+#define NA_XML_WRITER( object )				( G_TYPE_CHECK_INSTANCE_CAST( object, NA_XML_WRITER_TYPE, NAXMLWriter ))
+#define NA_XML_WRITER_CLASS( klass )		( G_TYPE_CHECK_CLASS_CAST( klass, NA_XML_WRITER_TYPE, NAXMLWriterClass ))
+#define NA_IS_XML_WRITER( object )			( G_TYPE_CHECK_INSTANCE_TYPE( object, NA_XML_WRITER_TYPE ))
+#define NA_IS_XML_WRITER_CLASS( klass )		( G_TYPE_CHECK_CLASS_TYPE(( klass ), NA_XML_WRITER_TYPE ))
+#define NA_XML_WRITER_GET_CLASS( object )	( G_TYPE_INSTANCE_GET_CLASS(( object ), NA_XML_WRITER_TYPE, NAXMLWriterClass ))
+
+typedef struct NAXMLWriterPrivate NAXMLWriterPrivate;
+
+typedef struct {
+	GObject             parent;
+	NAXMLWriterPrivate *private;
+}
+	NAXMLWriter;
+
+typedef struct NAXMLWriterClassPrivate NAXMLWriterClassPrivate;
+
+typedef struct {
+	GObjectClass             parent;
+	NAXMLWriterClassPrivate *private;
+}
+	NAXMLWriterClass;
+
+GType  na_xml_writer_get_type( void );
+
+gchar *na_xml_writer_export( NAAction *action, const gchar *folder, gint format, gchar **msg );
+
+G_END_DECLS
+
+#endif /* __NA_XML_WRITER_H__ */
diff --git a/src/nact/.gitignore b/src/nact/.gitignore
index f23dbfc..582b638 100644
--- a/src/nact/.gitignore
+++ b/src/nact/.gitignore
@@ -1,2 +1,3 @@
 nact.desktop
 nautilus-actions-config
+nautilus-actions-config-tool
diff --git a/src/nact/Makefile.am b/src/nact/Makefile.am
index ce6d29a..dc3c66d 100644
--- a/src/nact/Makefile.am
+++ b/src/nact/Makefile.am
@@ -27,7 +27,7 @@
 #   ... and many others (see AUTHORS)
 
 bin_PROGRAMS = \
-	nautilus-actions-config								\
+	nautilus-actions-config-tool						\
 	$(NULL)
 
 gladedir = $(datadir)/nautilus-actions
@@ -40,7 +40,7 @@ AM_CPPFLAGS += \
 	$(NAUTILUS_ACTIONS_CFLAGS)							\
 	$(NULL)
 
-nautilus_actions_config_SOURCES = \
+nautilus_actions_config_tool_SOURCES = \
 	base-application.c									\
 	base-application.h									\
 	base-application-class.h							\
@@ -55,11 +55,8 @@ nautilus_actions_config_SOURCES = \
 	nact-assist-export.h								\
 	nact-assist-import.c								\
 	nact-assist-import.h								\
-	nact-gconf-keys.h									\
 	nact-gconf-reader.c									\
 	nact-gconf-reader.h									\
-	nact-gconf-writer.c									\
-	nact-gconf-writer.h									\
 	nact-iaction-tab.c									\
 	nact-iaction-tab.h									\
 	nact-iactions-list.c								\
@@ -72,7 +69,6 @@ nautilus_actions_config_SOURCES = \
 	nact-iconditions-tab.h								\
 	nact-imenubar.c										\
 	nact-imenubar.h										\
-	nact-import-export-format.h							\
 	nact-iprefs.c										\
 	nact-iprefs.h										\
 	nact-main.c											\
@@ -82,12 +78,12 @@ nautilus_actions_config_SOURCES = \
 	nact-window.h										\
 	$(NULL)
 
-nautilus_actions_config_LDADD = \
+nautilus_actions_config_tool_LDADD = \
 	$(top_builddir)/src/common/libnact.la				\
 	$(NAUTILUS_ACTIONS_LIBS)							\
 	$(NULL)
 
-glade_DATA = nautilus-actions-config.ui
+glade_DATA = nautilus-actions-config-tool.ui
 
 @INTLTOOL_DESKTOP_RULE@
 
diff --git a/src/nact/nact-application.c b/src/nact/nact-application.c
index 195e6e7..9136ccc 100644
--- a/src/nact/nact-application.c
+++ b/src/nact/nact-application.c
@@ -37,7 +37,7 @@
 
 #include "nact-application.h"
 
-#define GLADE_FILENAME				GLADEDIR "/nautilus-actions-config.ui"
+#define GLADE_FILENAME				GLADEDIR "/nautilus-actions-config-tool.ui"
 
 /* private class data
  */
diff --git a/src/nact/nact-assist-export.c b/src/nact/nact-assist-export.c
index bfd4ed3..b236b0c 100644
--- a/src/nact/nact-assist-export.c
+++ b/src/nact/nact-assist-export.c
@@ -38,14 +38,14 @@
 
 #include <common/na-action.h>
 #include <common/na-utils.h>
+#include <common/na-xml-names.h>
+#include <common/na-xml-writer.h>
 
 #include "base-application.h"
 #include "nact-main-window.h"
 #include "nact-assist-export.h"
-#include "nact-gconf-writer.h"
 #include "nact-iactions-list.h"
 #include "nact-iprefs.h"
-#include "nact-import-export-format.h"
 
 /* Export Assistant
  *
@@ -775,7 +775,7 @@ do_export( NactAssistExport *window )
 
 	for( ia = actions ; ia ; ia = ia->next ){
 		NAAction *action = NA_ACTION( ia->data );
-		gchar *fname = nact_gconf_writer_export( action, window->private->uri, window->private->format, &msg );
+		gchar *fname = na_xml_writer_export( action, window->private->uri, window->private->format, &msg );
 
 		if( fname && strlen( fname )){
 			window->private->fnames = g_slist_prepend( window->private->fnames, fname );
diff --git a/src/nact/nact-gconf-reader.c b/src/nact/nact-gconf-reader.c
index 1804044..b926a7f 100644
--- a/src/nact/nact-gconf-reader.c
+++ b/src/nact/nact-gconf-reader.c
@@ -40,9 +40,9 @@
 
 #include <common/na-gconf-keys.h>
 #include <common/na-utils.h>
+#include <common/na-xml-names.h>
 
 #include "nact-application.h"
-#include "nact-gconf-keys.h"
 #include "nact-gconf-reader.h"
 #include "nact-assistant.h"
 
diff --git a/src/nact/nact.desktop.in b/src/nact/nact.desktop.in
index 9521356..eb93638 100644
--- a/src/nact/nact.desktop.in
+++ b/src/nact/nact.desktop.in
@@ -4,6 +4,6 @@ Type=Application
 Encoding=UTF-8
 _Name=Nautilus Actions Configuration
 _Comment=Add items to the Nautilus popup menu
-Exec=nautilus-actions-config
+Exec=nautilus-actions-config-tool
 Icon=nautilus-actions
 Categories=Application;FileManager;DesktopSettings;Settings;AdvancedSettings;
diff --git a/src/nact/nautilus-actions-config.ui b/src/nact/nautilus-actions-config-tool.ui
similarity index 100%
rename from src/nact/nautilus-actions-config.ui
rename to src/nact/nautilus-actions-config-tool.ui
diff --git a/src/utils/.gitignore b/src/utils/.gitignore
index f675c9b..fa9cc5f 100644
--- a/src/utils/.gitignore
+++ b/src/utils/.gitignore
@@ -1,2 +1,3 @@
 nautilus-actions-check-actions-change
 nautilus-actions-new-config
+nautilus-actions-new
diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
index 8150ad6..1b85305 100644
--- a/src/utils/Makefile.am
+++ b/src/utils/Makefile.am
@@ -27,22 +27,21 @@
 #   ... and many others (see AUTHORS)
 
 bin_PROGRAMS = \
-	nautilus-actions-new-config					\
+	nautilus-actions-new							\
 	$(NULL)
 
 AM_CPPFLAGS += \
-	-I $(top_srcdir)/src						\
-	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"	\
-	$(NAUTILUS_ACTIONS_UTILS_CFLAGS)			\
+	-I $(top_srcdir)/src							\
+	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"		\
+	$(NAUTILUS_ACTIONS_UTILS_CFLAGS)				\
+	-DG_LOG_DOMAIN=\"${NA_LOGDOMAIN_UTILS}\"		\
 	$(NULL)
 
-nautilus_actions_new_config_SOURCES = \
-	nautilus-actions-tools-utils.c				\
-	nautilus-actions-tools-utils.h				\
-	nautilus-actions-new-config.c				\
+nautilus_actions_new_SOURCES = \
+	nautilus-actions-new.c							\
 	$(NULL)
 
-nautilus_actions_new_config_LDADD = \
-	$(top_builddir)/src/common/libnact.la		\
-	$(NAUTILUS_ACTIONS_UTILS_LIBS)				\
+nautilus_actions_new_LDADD = \
+	$(top_builddir)/src/common/libnact.la			\
+	$(NAUTILUS_ACTIONS_UTILS_LIBS)					\
 	$(NULL)
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
new file mode 100644
index 0000000..e43ac21
--- /dev/null
+++ b/src/utils/nautilus-actions-new.c
@@ -0,0 +1,276 @@
+/*
+ * 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 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 <glib.h>
+#include <glib/gi18n.h>
+#include <stdlib.h>
+
+#include <common/na-action.h>
+#include <common/na-action-profile.h>
+#include <common/na-gconf.h>
+#include <common/na-iio-provider.h>
+#include <common/na-xml-names.h>
+#include <common/na-xml-writer.h>
+
+static gchar     *label           = "";
+static gchar     *tooltip         = "";
+static gchar     *icon            = "";
+static gchar     *command         = "";
+static gchar     *parameters      = "";
+static gchar    **basenames_array = NULL;
+static gboolean   matchcase       = FALSE;
+static gchar    **mimetypes_array = NULL;
+static gboolean   isfile          = FALSE;
+static gboolean   isdir           = FALSE;
+static gboolean   accept_multiple = FALSE;
+static gchar    **schemes_array   = NULL;
+static gchar     *output_dir      = NULL;
+static gboolean   output_gconf    = FALSE;
+
+static GOptionEntry entries[] = {
+
+	{ "label"                , 'l', 0, G_OPTION_ARG_STRING      , &label          ,	N_("The label of the menu item (mandatory)"), N_("LABEL") },
+	{ "tooltip"              , 't', 0, G_OPTION_ARG_STRING      , &tooltip        , N_("The tooltip of the menu item"), N_("TOOLTIP") },
+	{ "icon"                 , 'i', 0, G_OPTION_ARG_STRING      , &icon           , N_("The icon of the menu item (filename or GTK stock ID)"), N_("ICON") },
+	{ "command"              , 'c', 0, G_OPTION_ARG_FILENAME    , &command        , N_("The path of the command"), N_("PATH") },
+	{ "parameters"           , 'p', 0, G_OPTION_ARG_STRING      , &parameters     , N_("The parameters of the command"), N_("PARAMS") },
+	{ "match"                , 'm', 0, G_OPTION_ARG_STRING_ARRAY, &basenames_array, N_("A pattern to match selected files against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
+	{ "match-case"           , 'C', 0, G_OPTION_ARG_NONE        , &matchcase      , N_("The path of the command"), N_("PATH") },
+	{ "mimetypes"            , 'T', 0, G_OPTION_ARG_STRING_ARRAY, &mimetypes_array, N_("A pattern to match selected files' mimetype against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
+	{ "accept-files"         , 'f', 0, G_OPTION_ARG_NONE        , &isfile         , N_("Set it if the selection must only contain files"), NULL },
+	{ "accept-dirs"          , 'd', 0, G_OPTION_ARG_NONE        , &isdir          , N_("Set it if the selection must only contain folders. Specify both '--isfile' and '--isdir' options is selection can contain both types of items"), NULL },
+	{ "accept-multiple-files", 'M', 0, G_OPTION_ARG_NONE        , &accept_multiple, N_("Set it if the selection can have several items"), NULL },
+	{ "scheme"               , 's', 0, G_OPTION_ARG_STRING_ARRAY, &schemes_array  , N_("A valid GVFS scheme where the selected files should be located (you must set one option for each scheme you need)"), N_("SCHEME") },
+	{ NULL }
+};
+
+static GOptionEntry output_entries[] = {
+
+	{ "output-gconf"         , 'g', 0, G_OPTION_ARG_NONE        , &output_gconf   , N_("Directly import the newly created action in GConf configuration"), NULL },
+	{ "output-dir"           , 'o', 0, G_OPTION_ARG_FILENAME    , &output_dir     , N_("The folder where to write the new action as a GConf dump output [default: stdout]"), N_("DIR") },
+	{ NULL }
+};
+
+static GOptionContext *init_options( void );
+static NAAction       *get_action_from_cmdline( void );
+static gboolean        write_to_gconf( NAAction *action, gchar **msg );
+static void            exit_with_usage( void );
+
+int
+main( int argc, char** argv )
+{
+	g_type_init ();
+
+	int status = EXIT_SUCCESS;
+
+	GOptionContext *context = init_options();
+
+	if( argc == 1 ){
+		g_set_prgname( argv[0] );
+		gchar *help = g_option_context_get_help( context, FALSE, NULL );
+		g_print( "\n%s", help );
+		g_free( help );
+		exit( status );
+	}
+
+	GError *error = NULL;
+	if( !g_option_context_parse( context, &argc, &argv, &error )){
+		g_printerr( _("Syntax error: %s\n" ), error->message );
+		g_error_free (error);
+		exit_with_usage();
+	}
+
+	if( !label || !g_utf8_strlen( label, -1 )){
+		g_printerr( _( "Error: an action label is mandatory." ));
+		exit_with_usage();
+	}
+
+	if( output_gconf && output_dir ){
+		g_printerr( _( "Error: only one output option may be specified." ));
+		exit_with_usage();
+	}
+
+	NAAction *action = get_action_from_cmdline();
+	gchar *msg = NULL;
+
+	if( output_gconf ){
+		if( write_to_gconf( action, &msg )){
+			/* i18n: Action <action_label> written to...*/
+			g_print( _( "Action '%s' succesfully written to GConf configuration.\n" ), label );
+		}
+
+	} else {
+		gchar * output_fname = na_xml_writer_export( action, output_dir, FORMAT_GCONFENTRY, &msg );
+		if( output_fname ){
+			/* i18n: Action <action_label> written to <output_filename>...*/
+			g_print( _( "Action '%s' succesfully written to %s, and ready to be imported in NACT.\n" ), label, output_fname );
+			g_free( output_fname );
+		}
+	}
+
+	if( msg ){
+		g_printerr( "%s\n", msg );
+		g_free( msg );
+		status = EXIT_FAILURE;
+	}
+
+	g_object_unref( action );
+	g_option_context_free( context );
+
+	exit( status );
+}
+
+/*
+ * init options context
+ */
+static GOptionContext *
+init_options( void )
+{
+	GOptionContext *context = g_option_context_new( _( "Define a new action.\n\n"
+			"  The created action defaults to be written to stdout.\n"
+			"  It can also be written to an output folder, in a file later suitable for an import in NACT.\n"
+			"  Or you may choose to directly write the action into your GConf configuration." ));
+
+#ifdef ENABLE_NLS
+	bindtextdomain( GETTEXT_PACKAGE, GNOMELOCALEDIR );
+# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
+	bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
+# endif
+	textdomain( GETTEXT_PACKAGE );
+	g_option_context_add_main_entries( context, entries, GETTEXT_PACKAGE );
+#else
+	g_option_context_add_main_entries( context, entries, NULL );
+#endif
+
+	gchar* description = g_strdup_printf( "%s.\n%s", PACKAGE_STRING,
+			_( "Bug reports are welcomed at http://bugzilla.gnome.org,";
+				" or you may prefer to mail to <maintainer nautilus-actions org>.\n" ));
+
+	g_option_context_set_description( context, description );
+
+	g_free( description );
+
+	GOptionGroup *output_group = g_option_group_new(
+			"output", _( "Output of the program" ), _( "Choose where the program creates the action" ), NULL, NULL );
+
+	g_option_group_add_entries( output_group, output_entries );
+
+	g_option_context_add_group( context, output_group );
+
+	return( context );
+}
+
+/*
+ * allocate a new action, and fill it with values readen from command-line
+ */
+static NAAction *
+get_action_from_cmdline( void )
+{
+	NAAction *action = na_action_new_with_profile();
+	NAActionProfile *profile = NA_ACTION_PROFILE( na_action_get_profiles( action )->data );
+
+	na_action_set_label( action, label );
+	na_action_set_tooltip( action, tooltip );
+	na_action_set_icon( action, icon );
+
+	na_action_profile_set_path( profile, command );
+	na_action_profile_set_parameters( profile, parameters );
+
+	int i = 0;
+	GSList *basenames = NULL;
+	while( basenames_array != NULL && basenames_array[i] != NULL ){
+		basenames = g_slist_append( basenames, g_strdup( basenames_array[i] ));
+		i++;
+	}
+	na_action_profile_set_basenames( profile, basenames );
+	g_slist_foreach( basenames, ( GFunc ) g_free, NULL );
+	g_slist_free( basenames );
+
+	na_action_profile_set_matchcase( profile, matchcase );
+
+	i = 0;
+	GSList *mimetypes = NULL;
+	while( mimetypes_array != NULL && mimetypes_array[i] != NULL ){
+		mimetypes = g_slist_append( mimetypes, g_strdup( mimetypes_array[i] ));
+		i++;
+	}
+	na_action_profile_set_mimetypes( profile, mimetypes );
+	g_slist_foreach( mimetypes, ( GFunc ) g_free, NULL );
+	g_slist_free( mimetypes );
+
+	if( !isfile && !isdir ){
+		isfile = TRUE;
+	}
+	na_action_profile_set_isfile( profile, isfile );
+	na_action_profile_set_isdir( profile, isdir );
+	na_action_profile_set_multiple( profile, accept_multiple );
+
+	i = 0;
+	GSList *schemes = NULL;
+	while( schemes_array != NULL && schemes_array[i] != NULL ){
+		schemes = g_slist_append( schemes, g_strdup( schemes_array[i] ));
+		i++;
+	}
+	na_action_profile_set_schemes( profile, schemes );
+	g_slist_foreach( schemes, ( GFunc ) g_free, NULL );
+	g_slist_free( schemes );
+
+	return( action );
+}
+
+/*
+ * initialize GConf as an I/O provider
+ * then writes the action
+ */
+static gboolean
+write_to_gconf( NAAction *action, gchar **msg )
+{
+	NAGConf *gconf = na_gconf_new( NULL );
+
+	na_action_set_provider( action, NA_IIO_PROVIDER( gconf ));
+
+	guint ret = na_iio_provider_write_action( NULL, action, msg );
+
+	return( ret == NA_IIO_PROVIDER_WRITE_OK );
+}
+
+/*
+ * print a help message and exit with failure
+ */
+static void
+exit_with_usage( void )
+{
+	g_printerr( _("Try %s --help for usage.\n"), g_get_prgname());
+	exit( EXIT_FAILURE );
+}



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