[nautilus-actions: 29/45] Export a Nautilus Actions schema



commit 6b347c20a30286ac835371684cd3f7cfa7f9edf6
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Jul 28 23:31:18 2009 +0200

    Export a Nautilus Actions schema

 ChangeLog                           |    6 +
 exports/.gitignore                  |    1 +
 exports/nautilus-actions.schema.in  |  189 ++++++++++++++++++++++++++
 src/common/na-gconf-keys.h          |    4 +-
 src/common/na-xml-names.h           |    9 +-
 src/common/na-xml-writer.c          |   95 +++++++++++++-
 src/nact/nact-iprefs.c              |    4 +-
 src/utils/.gitignore                |    1 +
 src/utils/Makefile.am               |   10 ++
 src/utils/nautilus-actions-schema.c |  252 +++++++++++++++++++++++++++++++++++
 10 files changed, 563 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a7fcd61..edd5f03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,11 +4,15 @@
 	Write action now accepts a NULL NAPivot to deal with command-line
 	utility.
 
+	* src/common/na-xml-names.h:
+	Define new FORMAT_GCONFSCHEMA format to create a schema.
+
 	* 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}.
+	Create a schema on FORMAT_GCONFSCHEMA format.
 
 	* src/nact/nact-import-export-format.h: Removed file.
 
@@ -21,6 +25,8 @@
 	* src/utils/nautilus-actions-tools-utils.c:
 	* src/utils/nautilus-actions-tools-utils.h: Removed files.
 
+	* src/utils/nautilus-actions-schema.c: New file.
+
 	* configure.ac:
 	* src/common/Makefile.am:
 	* src/nact/Makefile.am:
diff --git a/exports/.gitignore b/exports/.gitignore
new file mode 100644
index 0000000..6bec850
--- /dev/null
+++ b/exports/.gitignore
@@ -0,0 +1 @@
+nautilus-actions.schema
diff --git a/exports/nautilus-actions.schema.in b/exports/nautilus-actions.schema.in
new file mode 100644
index 0000000..fca19a7
--- /dev/null
+++ b/exports/nautilus-actions.schema.in
@@ -0,0 +1,189 @@
+(nautilus-actions-install-schema:27405): NA-common-DEBUG: na_xml_writer_class_init: klass=0x86e36e0
+(nautilus-actions-install-schema:27405): NA-common-DEBUG: na_xml_writer_instance_init: instance=0x86e2f50, klass=0x86e36e0
+<?xml version="1.0" encoding="UTF-8"?>
+<gconfschemafile>
+  <schemalist>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/version</key>
+      <owner>nautilus-actions</owner>
+      <type>string</type>
+      <locale name="C">
+        <short>The version of the configuration format</short>
+        <short>The version of the configuration format that will be used to manage backward compatibility</short>
+      </locale>
+      <default>2.0</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/label</key>
+      <owner>nautilus-actions</owner>
+      <type>string</type>
+      <locale name="C">
+        <default></default>
+        <short>The label of the menu item</short>
+        <short>The label of the menu item that will appear in the Nautilus popup menu when the selection matches the appearance condition settings</short>
+      </locale>
+      <default></default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/tooltip</key>
+      <owner>nautilus-actions</owner>
+      <type>string</type>
+      <locale name="C">
+        <default></default>
+        <short>The tooltip of the menu item</short>
+        <short>The tooltip of the menu item that will appear in the Nautilus statusbar when the user points to the Nautilus popup menu item with his/her mouse</short>
+      </locale>
+      <default></default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/icon</key>
+      <owner>nautilus-actions</owner>
+      <type>string</type>
+      <locale name="C">
+        <short>The icon of the menu item</short>
+        <short>The icon of the menu item that will appear next to the label in the Nautilus popup menu when the selection matches the appearance conditions settings</short>
+      </locale>
+      <default></default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/desc-name</key>
+      <owner>nautilus-actions</owner>
+      <type>string</type>
+      <locale name="C">
+        <default>Default profile</default>
+        <short>A description name of the profile</short>
+        <short>The field is here to give the user a human readable name for a profile in the Nact interface. If not set there will be a default auto generated string set by default</short>
+      </locale>
+      <default>Default profile</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/path</key>
+      <owner>nautilus-actions</owner>
+      <type>string</type>
+      <locale name="C">
+        <short>The path of the command</short>
+        <short>The path of the command to start when the user select the menu item in the Nautilus popup menu</short>
+      </locale>
+      <default></default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/parameters</key>
+      <owner>nautilus-actions</owner>
+      <type>string</type>
+      <locale name="C">
+        <short>The parameters of the command</short>
+        <short>The parameters of the command to start when the user selects the menu item in the Nautilus popup menu.
+
+The parameters can contain some special tokens which are replaced by Nautilus information before starting the command:
+
+%d: base folder of the selected file(s)
+%f: the name of the selected file or the first one if many are selected
+%m: space-separated list of the basenames of the selected file(s)/folder(s)
+%M: space-separated list of the selected file(s)/folder(s), with their full paths
+%u: GVFS URI
+%s: scheme of the GVFS URI
+%h: hostname of the GVFS URI
+%U: username of the GVFS URI
+%%: a percent sign</short>
+      </locale>
+      <default></default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/basenames</key>
+      <owner>nautilus-actions</owner>
+      <type>list</type>
+      <list_type>string</list_type>
+      <locale name="C">
+        <short>The list of pattern to match the selected file(s)/folder(s)</short>
+        <short>A list of strings with joker '*' or '?' to match the name of the selected file(s)/folder(s). Each selected items must match at least one of the filename patterns for the action to appear</short>
+      </locale>
+      <default>[*]</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/matchcase</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>'true' if the filename patterns have to be case sensitive, 'false' otherwise</short>
+        <short>If you need to match a filename in a case-sensitive manner, set this key to 'true'. If you also want, for example '*.jpg' to match 'photo.JPG', set 'false'</short>
+      </locale>
+      <default>true</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/mimetypes</key>
+      <owner>nautilus-actions</owner>
+      <type>list</type>
+      <list_type>string</list_type>
+      <locale name="C">
+        <short>The list of patterns to match the mimetypes of the selected file(s)</short>
+        <short>A list of strings with joker '*' or '?' to match the mimetypes of the selected file(s). Each selected items must match at least one of the mimetype patterns for the action to appear</short>
+      </locale>
+      <default>[*/*]</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/isfile</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>'true' if the selection can have files, 'false' otherwise</short>
+        <short>This setting is tied in with the 'isdir' setting. The valid combinations are:
+
+isfile=TRUE and isdir=FALSE: the selection may hold only files
+isfile=FALSE and isdir=TRUE: the selection may hold only folders
+isfile=TRUE and isdir=TRUE: the selection may hold both files and folders
+isfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration will never appear)</short>
+      </locale>
+      <default>true</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/isdir</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>'true' if the selection can have folders, 'false' otherwise</short>
+        <short>This setting is tied in with the 'isfile' setting. The valid combinations are:
+
+isfile=TRUE and isdir=FALSE: the selection may hold only files
+isfile=FALSE and isdir=TRUE: the selection may hold only folders
+isfile=TRUE and isdir=TRUE: the selection may hold both files and folders
+isfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration will never appear)</short>
+      </locale>
+      <default>false</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/accept-multiple-files</key>
+      <owner>nautilus-actions</owner>
+      <type>bool</type>
+      <locale name="C">
+        <short>'true' if the selection can have several items, 'false' otherwise</short>
+        <short>If you need one or more files or folders to be selected, set this key to 'true'. If you want just one file or folder, set 'false'</short>
+      </locale>
+      <default>false</default>
+    </schema>
+    <schema>
+      <key>/schemas/apps/nautilus-actions/configurations/schemes</key>
+      <owner>nautilus-actions</owner>
+      <type>list</type>
+      <list_type>string</list_type>
+      <locale name="C">
+        <short>The list of GVFS schemes where the selected files should be located</short>
+        <short>Defines the list of valid GVFS schemes to be matched against the selected items. The GVFS scheme is the protocol used to access the files. The keyword to use is the one used in the GVFS URI.
+
+Examples of GVFS URI include: 
+file:///tmp/foo.txt
+sftp:///root test example net/tmp/foo.txt
+
+The most common schemes are:
+
+'file': local files
+'sftp': files accessed via SSH
+'ftp': files accessed via FTP
+'smb': files accessed via Samba (Windows share)
+'dav': files accessed via WebDav
+
+All GVFS schemes used by Nautilus can be used here.</short>
+      </locale>
+      <default>[file]</default>
+    </schema>
+  </schemalist>
+</gconfschemafile>
diff --git a/src/common/na-gconf-keys.h b/src/common/na-gconf-keys.h
index fdb26e9..d3b2bbf 100644
--- a/src/common/na-gconf-keys.h
+++ b/src/common/na-gconf-keys.h
@@ -33,8 +33,10 @@
 
 /* GConf general information
  */
-#define NA_GCONF_CONFIG_PATH			NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR "/configurations"
+#define NA_GCONF_CONFIG_CONFIGURATION	"configurations"
+#define NA_GCONF_CONFIG_PATH			NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR "/" NA_GCONF_CONFIG_CONFIGURATION
 #define NA_GCONF_SCHEMA_PREFIX			"/schemas"
+#define NA_GCONF_SCHEMA_PREFERENCES		"preferences"
 
 /* GConf key names
  */
diff --git a/src/common/na-xml-names.h b/src/common/na-xml-names.h
index dbd1221..659e400 100644
--- a/src/common/na-xml-names.h
+++ b/src/common/na-xml-names.h
@@ -51,7 +51,8 @@ G_BEGIN_DECLS
 enum {
 	FORMAT_GCONFSCHEMAFILE_V1 = 1,
 	FORMAT_GCONFSCHEMAFILE_V2,
-	FORMAT_GCONFENTRY
+	FORMAT_GCONFENTRY,
+	FORMAT_GCONFSCHEMA
 };
 
 /* XML element names (GConf schema)
@@ -108,7 +109,7 @@ enum {
 #define ACTION_PATH_DESC_SHORT		_("The path of the command")
 #define ACTION_PATH_DESC_LONG		_("The path of the command to start when the user select the menu item in the Nautilus popup menu")
 #define ACTION_PARAMETERS_DESC_SHORT _("The parameters of the command")
-#define ACTION_PARAMETERS_DESC_LONG	_("The parameters of the command to start when the user selects the menu item in the Nautilus popup menu.\n\nThe parameters can contain some special tokens which are replaced by Nautilus information before starting the command:\n\n%d: base folder of the selected file(s)\n%f: the name of the selected file or the first one if many are selected\n%m: space-separated list of the basenames of the selected file(s)/folder(s)\n%M: space-separated list of the selected file(s)/folder(s), with their full paths\n%u: GnomeVFS URI\n%s: scheme of the GnomeVFS URI\n%h: hostname of the GnomeVFS URI\n%U: username of the GnomeVFS URI\n%%: a percent sign")
+#define ACTION_PARAMETERS_DESC_LONG	_("The parameters of the command to start when the user selects the menu item in the Nautilus popup menu.\n\nThe parameters can contain some special tokens which are replaced by Nautilus information before starting the command:\n\n%d: base folder of the selected file(s)\n%f: the name of the selected file or the first one if many are selected\n%m: space-separated list of the basenames of the selected file(s)/folder(s)\n%M: space-separated list of the selected file(s)/folder(s), with their full paths\n%u: GVFS URI\n%s: scheme of the GVFS URI\n%h: hostname of the GVFS URI\n%U: username of the GVFS URI\n%%: a percent sign")
 #define ACTION_BASENAMES_DESC_SHORT	_("The list of pattern to match the selected file(s)/folder(s)")
 #define ACTION_BASENAMES_DESC_LONG	_("A list of strings with joker '*' or '?' to match the name of the selected file(s)/folder(s). Each selected items must match at least one of the filename patterns for the action to appear")
 #define ACTION_MATCHCASE_DESC_SHORT _("'true' if the filename patterns have to be case sensitive, 'false' otherwise")
@@ -121,8 +122,8 @@ enum {
 #define ACTION_ISDIR_DESC_LONG		_("This setting is tied in with the 'isfile' setting. The valid combinations are:\n\nisfile=TRUE and isdir=FALSE: the selection may hold only files\nisfile=FALSE and isdir=TRUE: the selection may hold only folders\nisfile=TRUE and isdir=TRUE: the selection may hold both files and folders\nisfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration will never appear)")
 #define ACTION_MULTIPLE_DESC_SHORT	_("'true' if the selection can have several items, 'false' otherwise")
 #define ACTION_MULTIPLE_DESC_LONG	_("If you need one or more files or folders to be selected, set this key to 'true'. If you want just one file or folder, set 'false'")
-#define ACTION_SCHEMES_DESC_SHORT	_("The list of GnomeVFS schemes where the selected files should be located")
-#define ACTION_SCHEMES_DESC_LONG	_("Defines the list of valid GnomeVFS schemes to be matched against the selected items. The GnomeVFS scheme is the protocol used to access the files. The keyword to use is the one used in the GnomeVFS URI.\n\nExamples of GnomeVFS URI include: \nfile:///tmp/foo.txt\nsftp:///root test example net/tmp/foo.txt\n\nThe most common schemes are:\n\n'file': local files\n'sftp': files accessed via SSH\n'ftp': files accessed via FTP\n'smb': files accessed via Samba (Windows share)\n'dav': files accessed via WebDav\n\nAll GnomeVFS schemes used by Nautilus can be used here.")
+#define ACTION_SCHEMES_DESC_SHORT	_("The list of GVFS schemes where the selected files should be located")
+#define ACTION_SCHEMES_DESC_LONG	_("Defines the list of valid GVFS schemes to be matched against the selected items. The GVFS scheme is the protocol used to access the files. The keyword to use is the one used in the GVFS URI.\n\nExamples of GVFS URI include: \nfile:///tmp/foo.txt\nsftp:///root test example net/tmp/foo.txt\n\nThe most common schemes are:\n\n'file': local files\n'sftp': files accessed via SSH\n'ftp': files accessed via FTP\n'smb': files accessed via Samba (Windows share)\n'dav': files accessed via WebDav\n\nAll GVFS schemes used by Nautilus can be used here.")
 #define ACTION_VERSION_DESC_SHORT	_("The version of the configuration format")
 #define ACTION_VERSION_DESC_LONG	_("The version of the configuration format that will be used to manage backward compatibility")
 
diff --git a/src/common/na-xml-writer.c b/src/common/na-xml-writer.c
index 7074f71..12523a6 100644
--- a/src/common/na-xml-writer.c
+++ b/src/common/na-xml-writer.c
@@ -95,6 +95,17 @@ static void         create_dump_entry(
 								xmlDocPtr doc,
 								xmlNodePtr list_node,
 								const gchar *type );
+static xmlDocPtr    create_gconf_schema( NAXMLWriter *writer );
+static void         create_gconf_schema_entry(
+								NAXMLWriter *writer,
+								const gchar *entry,
+								xmlDocPtr doc,
+								xmlNodePtr list_node,
+								const gchar *type,
+								const gchar *short_desc,
+								const gchar *long_desc,
+								const gchar *default_value,
+								gboolean is_i18n );
 
 GType
 na_xml_writer_get_type( void )
@@ -252,12 +263,13 @@ xml_writer_new( const gchar *uuid )
 gchar *
 na_xml_writer_export( NAAction *action, const gchar *folder, gint format, gchar **msg )
 {
-	gchar *uuid = na_action_get_uuid( action );
+	gchar *uuid = action ? na_action_get_uuid( action ) : NULL;
 	NAXMLWriter *writer = xml_writer_new( uuid );
 	g_free( uuid );
 
 	xmlDocPtr doc = NULL;
 	gchar *filename = NULL;
+	gboolean free_filename = FALSE;
 
 	switch( format ){
 		case FORMAT_GCONFSCHEMAFILE_V1:
@@ -270,12 +282,30 @@ na_xml_writer_export( NAAction *action, const gchar *folder, gint format, gchar
 			filename = g_strdup_printf( "%s/config-%s.schema", folder, writer->private->uuid );
 			break;
 
+		/* this is the format used by nautilus-actions-new utility,
+		 * and that's why this option takes care of a NULL folder
+		 */
 		case FORMAT_GCONFENTRY:
 			doc = create_xml_dump( writer, format, action );
 			if( folder ){
 				filename = g_strdup_printf( "%s/action-%s.xml", folder, writer->private->uuid );
 			} else {
 				filename = g_strdup( "-" );
+				free_filename = TRUE;
+			}
+			break;
+
+		/* this is the format used by nautilus-actions-install-schema
+		 * utility, and that's why this option takes care of a NULL
+		 * folder, or an output filename
+		 */
+		case FORMAT_GCONFSCHEMA:
+			doc = create_gconf_schema( writer );
+			if( folder ){
+				filename = g_strdup( folder );
+			} else {
+				filename = g_strdup( "-" );
+				free_filename = TRUE;
 			}
 			break;
 	}
@@ -288,7 +318,7 @@ na_xml_writer_export( NAAction *action, const gchar *folder, gint format, gchar
 		filename = NULL;
 	}
 
-	if( !folder ){
+	if( free_filename ){
 		g_free( filename );
 		filename = NULL;
 	}
@@ -601,3 +631,64 @@ create_dump_entry( NAXMLWriter *writer,
 		xmlFree( encoded_content );
 	}
 }
+
+static xmlDocPtr
+create_gconf_schema( NAXMLWriter *writer )
+{
+	xmlDocPtr doc = xmlNewDoc( BAD_CAST( "1.0" ));
+	xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST( NACT_GCONF_SCHEMA_ROOT ));
+	xmlDocSetRootElement( doc, root_node );
+	xmlNodePtr list_node = xmlNewChild( root_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_LIST ), NULL );
+
+	create_gconf_schema_entry( writer, ACTION_VERSION_ENTRY       , doc, list_node, "string", ACTION_VERSION_DESC_SHORT     , ACTION_VERSION_DESC_LONG, NAUTILUS_ACTIONS_CONFIG_VERSION, FALSE );
+	create_gconf_schema_entry( writer, ACTION_LABEL_ENTRY         , doc, list_node, "string", ACTION_LABEL_DESC_SHORT       , ACTION_LABEL_DESC_LONG, "", TRUE );
+	create_gconf_schema_entry( writer, ACTION_TOOLTIP_ENTRY       , doc, list_node, "string", ACTION_TOOLTIP_DESC_SHORT     , ACTION_TOOLTIP_DESC_LONG, "", TRUE );
+	create_gconf_schema_entry( writer, ACTION_ICON_ENTRY          , doc, list_node, "string", ACTION_ICON_DESC_SHORT        , ACTION_ICON_DESC_LONG, "", FALSE );
+	create_gconf_schema_entry( writer, ACTION_PROFILE_LABEL_ENTRY , doc, list_node, "string", ACTION_PROFILE_NAME_DESC_SHORT, ACTION_PROFILE_NAME_DESC_LONG, _( "Default profile" ), TRUE );
+	create_gconf_schema_entry( writer, ACTION_PATH_ENTRY          , doc, list_node, "string", ACTION_PATH_DESC_SHORT        , ACTION_PATH_DESC_LONG, "", FALSE );
+	create_gconf_schema_entry( writer, ACTION_PARAMETERS_ENTRY    , doc, list_node, "string", ACTION_PARAMETERS_DESC_SHORT  , ACTION_PARAMETERS_DESC_LONG, "", FALSE );
+	create_gconf_schema_entry( writer, ACTION_BASENAMES_ENTRY     , doc, list_node, "list"  , ACTION_BASENAMES_DESC_SHORT   , ACTION_BASENAMES_DESC_LONG, "[*]", FALSE );
+	create_gconf_schema_entry( writer, ACTION_MATCHCASE_ENTRY     , doc, list_node, "bool"  , ACTION_MATCHCASE_DESC_SHORT   , ACTION_MATCHCASE_DESC_LONG, "true", FALSE );
+	create_gconf_schema_entry( writer, ACTION_MIMETYPES_ENTRY     , doc, list_node, "list"  , ACTION_MIMETYPES_DESC_SHORT   , ACTION_MIMETYPES_DESC_LONG, "[*/*]", FALSE );
+	create_gconf_schema_entry( writer, ACTION_ISFILE_ENTRY        , doc, list_node, "bool"  , ACTION_ISFILE_DESC_SHORT      , ACTION_ISFILE_DESC_LONG, "true", FALSE );
+	create_gconf_schema_entry( writer, ACTION_ISDIR_ENTRY         , doc, list_node, "bool"  , ACTION_ISDIR_DESC_SHORT       , ACTION_ISDIR_DESC_LONG, "false", FALSE );
+	create_gconf_schema_entry( writer, ACTION_MULTIPLE_ENTRY      , doc, list_node, "bool"  , ACTION_MULTIPLE_DESC_SHORT    , ACTION_MULTIPLE_DESC_LONG, "false", FALSE );
+	create_gconf_schema_entry( writer, ACTION_SCHEMES_ENTRY       , doc, list_node, "list"  , ACTION_SCHEMES_DESC_SHORT     , ACTION_SCHEMES_DESC_LONG, "[file]", FALSE );
+
+	return( doc );
+}
+
+static void
+create_gconf_schema_entry( NAXMLWriter *writer,
+		const gchar *entry,
+		xmlDocPtr doc, xmlNodePtr list_node, const gchar *type,
+		const gchar *short_desc, const gchar *long_desc,
+		const gchar *default_value, gboolean is_i18n )
+{
+	xmlNodePtr schema_node = xmlNewChild( list_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_ENTRY ), NULL );
+
+	xmlChar *content = BAD_CAST( g_build_path( "/", NA_GCONF_SCHEMA_PREFIX, NA_GCONF_CONFIG_PATH, entry, NULL ));
+	xmlNewChild( schema_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_KEY ), content );
+	xmlFree( content );
+
+	xmlNewChild( schema_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_OWNER ), BAD_CAST( PACKAGE_TARNAME ));
+
+	xmlNewChild( schema_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_TYPE ), BAD_CAST( type ));
+	if( !g_ascii_strcasecmp( type, "list" )){
+		xmlNewChild( schema_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_LIST_TYPE ), BAD_CAST( "string" ));
+	}
+
+	xmlNodePtr locale_node = xmlNewChild( schema_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_LOCALE ), NULL );
+	xmlNewProp( locale_node, BAD_CAST( "name" ), BAD_CAST( "C" ));
+
+	content = xmlEncodeSpecialChars( doc, BAD_CAST( default_value ));
+	xmlNewChild( schema_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_DEFAULT ), content );
+	if( is_i18n ){
+		xmlNewChild( locale_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_DEFAULT ), content );
+	}
+	xmlFree( content );
+
+	xmlNewChild( locale_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_SHORT ), BAD_CAST( short_desc ));
+
+	xmlNewChild( locale_node, NULL, BAD_CAST( NACT_GCONF_SCHEMA_SHORT ), BAD_CAST( long_desc ));
+}
diff --git a/src/nact/nact-iprefs.c b/src/nact/nact-iprefs.c
index ff62bbb..4da3dc9 100644
--- a/src/nact/nact-iprefs.c
+++ b/src/nact/nact-iprefs.c
@@ -36,6 +36,8 @@
 #include <gconf/gconf.h>
 #include <gconf/gconf-client.h>
 
+#include <common/na-gconf-keys.h>
+
 #include "nact-iprefs.h"
 
 /* private interface data
@@ -46,7 +48,7 @@ struct NactIPrefsInterfacePrivate {
 
 /* GConf general information
  */
-#define NA_GCONF_PREFS_PATH		NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR "/preferences"
+#define NA_GCONF_PREFS_PATH		NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR "/" NA_GCONF_SCHEMA_PREFERENCES
 
 /* key to read/write the last visited folder when browsing for a file
  */
diff --git a/src/utils/.gitignore b/src/utils/.gitignore
index fa9cc5f..02b3e53 100644
--- a/src/utils/.gitignore
+++ b/src/utils/.gitignore
@@ -1,3 +1,4 @@
 nautilus-actions-check-actions-change
 nautilus-actions-new-config
 nautilus-actions-new
+nautilus-actions-schema
diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
index 1b85305..2a40a07 100644
--- a/src/utils/Makefile.am
+++ b/src/utils/Makefile.am
@@ -28,6 +28,7 @@
 
 bin_PROGRAMS = \
 	nautilus-actions-new							\
+	nautilus-actions-schema							\
 	$(NULL)
 
 AM_CPPFLAGS += \
@@ -45,3 +46,12 @@ nautilus_actions_new_LDADD = \
 	$(top_builddir)/src/common/libnact.la			\
 	$(NAUTILUS_ACTIONS_UTILS_LIBS)					\
 	$(NULL)
+
+nautilus_actions_schema_SOURCES = \
+	nautilus-actions-schema.c						\
+	$(NULL)
+
+nautilus_actions_schema_LDADD = \
+	$(top_builddir)/src/common/libnact.la			\
+	$(NAUTILUS_ACTIONS_UTILS_LIBS)					\
+	$(NULL)
diff --git a/src/utils/nautilus-actions-schema.c b/src/utils/nautilus-actions-schema.c
new file mode 100644
index 0000000..9dca5b1
--- /dev/null
+++ b/src/utils/nautilus-actions-schema.c
@@ -0,0 +1,252 @@
+/*
+ * 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 <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <stdlib.h>
+
+#include <common/na-gconf-keys.h>
+#include <common/na-xml-names.h>
+#include <common/na-xml-writer.h>
+
+/*static gchar     *output_fname = NULL;
+static gboolean   output_gconf = FALSE;*/
+static gboolean   output_stdout = FALSE;
+
+static GOptionEntry entries[] = {
+
+	/*{ "output-gconf"         , 'g', 0, G_OPTION_ARG_NONE    , &output_gconf   , N_("Writes the Nautilus Actions schema in GConf"), NULL },
+	{ "output-filename"      , 'o', 0, G_OPTION_ARG_FILENAME, &output_fname   , N_("The file where to write the GConf schema ('-' for stdout)"), N_("FILENAME") },*/
+	{ "stdout", 's', 0, G_OPTION_ARG_NONE, &output_stdout, N_("Output the schema on stdout"), NULL },
+	{ NULL }
+};
+
+static GOptionContext *init_options( void );
+/*static gboolean        write_to_gconf( gchar **msg );
+static gboolean        write_schema( GConfClient *gconf, const gchar *prefix, GConfValueType type, const gchar *entry, const gchar *dshort, const gchar *dlong, const gchar *default_value, 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( output_gconf && output_fname ){
+		g_printerr( _( "Error: only one output option may be specified." ));
+		exit_with_usage();
+	}*/
+
+	gchar *msg = NULL;
+
+	/*if( output_gconf ){
+		if( write_to_gconf( &msg )){
+			g_print( _( "Nautilus Actions schema succesfully written to GConf.\n" ));
+		}
+
+	} else {*/
+		na_xml_writer_export( NULL, NULL, FORMAT_GCONFSCHEMA, &msg );
+		/*if( !msg ){
+			g_print( _( "Nautilus Actions schema succesfully written to %s.\n" ), output_fname );
+			g_free( output_fname );
+		}*/
+	/*}*/
+
+	if( msg ){
+		g_printerr( "%s\n", msg );
+		g_free( msg );
+		status = EXIT_FAILURE;
+	}
+
+	g_option_context_free( context );
+
+	exit( status );
+}
+
+/*
+ * init options context
+ */
+static GOptionContext *
+init_options( void )
+{
+	GOptionContext *context = g_option_context_new( _( "Output the Nautilus Actions GConf schema on stdout." ));
+			/*"  The schema can be written to stdout.\n"
+			"  It can also be written to an output file, in a file later suitable for an installation via gconftool-2.\n"
+			"  Or you may choose to directly write the schema into the 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 );
+
+	return( context );
+}
+
+/*
+ * writes the schema via GConfClient
+ */
+/*static gboolean
+write_to_gconf( gchar **msg )
+{
+	GConfClient *gconf = gconf_client_get_default();
+
+	gchar *prefix_config = g_strdup_printf( "%s%s", NA_GCONF_SCHEMA_PREFIX, NA_GCONF_CONFIG_PATH );
+	gchar *prefix_prefs = g_strdup_printf( "%s%s/%s", NA_GCONF_SCHEMA_PREFIX, NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR, NA_GCONF_SCHEMA_PREFERENCES );
+
+	gboolean ret =
+		write_schema( gconf, prefix_config, GCONF_VALUE_STRING, ACTION_VERSION_ENTRY, ACTION_VERSION_DESC_SHORT, ACTION_VERSION_DESC_LONG, NAUTILUS_ACTIONS_CONFIG_VERSION, msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_STRING, ACTION_LABEL_ENTRY, ACTION_LABEL_DESC_SHORT, ACTION_LABEL_DESC_LONG, "", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_STRING, ACTION_TOOLTIP_ENTRY, ACTION_TOOLTIP_DESC_SHORT, ACTION_TOOLTIP_DESC_LONG, "", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_STRING, ACTION_ICON_ENTRY, ACTION_ICON_DESC_SHORT, ACTION_ICON_DESC_LONG, "", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_STRING, ACTION_PROFILE_LABEL_ENTRY, ACTION_PROFILE_NAME_DESC_SHORT, ACTION_PROFILE_NAME_DESC_LONG, _( "Default profile" ), msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_STRING, ACTION_PATH_ENTRY, ACTION_PATH_DESC_SHORT, ACTION_PATH_DESC_LONG, "", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_STRING, ACTION_PARAMETERS_ENTRY, ACTION_PARAMETERS_DESC_SHORT, ACTION_PARAMETERS_DESC_LONG, "", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_LIST, ACTION_BASENAMES_ENTRY, ACTION_BASENAMES_DESC_SHORT, ACTION_BASENAMES_DESC_LONG, "*", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_BOOL, ACTION_MATCHCASE_ENTRY, ACTION_MATCHCASE_DESC_SHORT, ACTION_MATCHCASE_DESC_LONG, "true", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_LIST, ACTION_MIMETYPES_ENTRY, ACTION_MIMETYPES_DESC_SHORT, ACTION_MIMETYPES_DESC_LONG, "*
+		/
+		 *", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_BOOL, ACTION_ISFILE_ENTRY, ACTION_ISFILE_DESC_SHORT, ACTION_ISFILE_DESC_LONG, "true", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_BOOL, ACTION_ISDIR_ENTRY, ACTION_ISDIR_DESC_SHORT, ACTION_ISDIR_DESC_LONG, "false", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_BOOL, ACTION_MULTIPLE_ENTRY, ACTION_MULTIPLE_DESC_SHORT, ACTION_MULTIPLE_DESC_LONG, "false", msg ) &&
+		write_schema( gconf, prefix_config, GCONF_VALUE_LIST, ACTION_SCHEMES_ENTRY, ACTION_SCHEMES_DESC_SHORT, ACTION_SCHEMES_DESC_LONG, "file", msg );
+
+	g_free( prefix_prefs );
+	g_free( prefix_config );
+
+	gconf_client_suggest_sync( gconf, NULL );
+	return( ret );
+}
+
+static gboolean
+write_schema( GConfClient *gconf, const gchar *prefix, GConfValueType type, const gchar *entry, const gchar *dshort, const gchar *dlong, const gchar *default_value, gchar **message )
+{
+	gchar *path = g_strdup_printf( "%s/%s", prefix, entry );
+	g_debug( "write_schema: path=%s", path );
+	gboolean ret = TRUE;
+	GError *error = NULL;
+
+	GConfSchema *schema = gconf_schema_new();
+	gconf_schema_set_owner( schema, PACKAGE );
+	gconf_schema_set_type( schema, type );
+*/
+	/* FIXME: if we write the schema with a 'C' locale, how will it be
+	 * localized ?? but get_language_names return a list. Do we have to
+	 * write a locale for each element of the list ? for the first one ?
+	 */
+	/*gconf_schema_set_locale( schema, "C" );
+
+	gconf_schema_set_short_desc( schema, dshort );
+	gconf_schema_set_long_desc( schema, dlong );
+
+
+	GConfValue *value = NULL;
+	if( type == GCONF_VALUE_LIST ){
+		gconf_schema_set_list_type( schema, GCONF_VALUE_STRING );
+
+		GConfValue *first = gconf_value_new_from_string( GCONF_VALUE_STRING, default_value, &error );
+		GSList *list = NULL;
+		list = g_slist_append( list, first );
+		value = gconf_value_new( GCONF_VALUE_LIST );
+		gconf_value_set_list_type( value, GCONF_VALUE_STRING );
+		gconf_value_set_list( value, list );
+		g_slist_free( list );
+
+	} else {
+		value = gconf_value_new_from_string( type, default_value, &error );
+		if( error ){
+			*message = g_strdup( error->message );
+			g_error_free( error );
+			ret = FALSE;
+		}
+	}
+
+	if( ret ){
+		gconf_schema_set_default_value( schema, value );
+
+		if( !gconf_client_set_schema( gconf, path, schema, &error )){
+			*message = g_strdup( error->message );
+			g_error_free( error );
+			ret = FALSE;
+		}
+	}
+
+	gconf_schema_free( schema );
+	g_free( path );
+	return( ret );
+}*/
+
+/*
+ * 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]