[nautilus-actions: 22/45] Import the two new export formats
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions: 22/45] Import the two new export formats
- Date: Wed, 29 Jul 2009 21:19:37 +0000 (UTC)
commit 3f77875052ef462614d31b177b1ffc1169bfa626
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Jul 27 05:36:35 2009 +0200
Import the two new export formats
ChangeLog | 9 +
...action-8c4fa203-b5d0-449a-bdc8-61d398febef6.xml | 19 +-
...fig-8c4fa203-b5d0-449a-bdc8-61d398febef6.schema | 16 +-
...ig_8c4fa203-b5d0-449a-bdc8-61d398febef6.schemas | 20 +-
src/common/na-gconf.c | 19 +-
src/common/na-utils.c | 21 +-
src/common/na-utils.h | 2 +
src/nact/nact-assist-export.c | 4 +-
src/nact/nact-gconf-reader.c | 507 ++++++++++++++++----
src/nact/nact-main-window.c | 7 +
10 files changed, 479 insertions(+), 145 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1e44834..71f063e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-07-27 Pierre Wieser <pwieser trychlos org>
+
+ * src/common/na-utils.c:
+ * src/common/na-utils.h (na_utils_path_to_key):
+ New function moved from na-gconf.c.
+
+ * src/nact/nact-gconf-reader.c:
+ Import the two new export formats.
+
2009-07-26 Pierre Wieser <pwieser trychlos org>
* src/common/na-action.h:
diff --git a/exports/action-8c4fa203-b5d0-449a-bdc8-61d398febef6.xml b/exports/action-8c4fa203-b5d0-449a-bdc8-61d398febef6.xml
index 5939974..5a506aa 100644
--- a/exports/action-8c4fa203-b5d0-449a-bdc8-61d398febef6.xml
+++ b/exports/action-8c4fa203-b5d0-449a-bdc8-61d398febef6.xml
@@ -10,19 +10,19 @@
<entry>
<key>label</key>
<value>
- <string>New Nautilus action</string>
+ <string>Import/Export test</string>
</value>
</entry>
<entry>
<key>tooltip</key>
<value>
- <string></string>
+ <string>The tooltip for "import/export test" action</string>
</value>
</entry>
<entry>
<key>icon</key>
<value>
- <string></string>
+ <string>gtk-justify-center</string>
</value>
</entry>
<entry>
@@ -34,13 +34,13 @@
<entry>
<key>profile-zero/path</key>
<value>
- <string></string>
+ <string>/bin/ls</string>
</value>
</entry>
<entry>
<key>profile-zero/parameters</key>
<value>
- <string></string>
+ <string>%h %M</string>
</value>
</entry>
<entry>
@@ -49,6 +49,7 @@
<list type="string">
<value>
<string>*</string>
+ <string>*.c</string>
</value>
</list>
</value>
@@ -72,19 +73,19 @@
<entry>
<key>profile-zero/isfile</key>
<value>
- <string>true</string>
+ <string>false</string>
</value>
</entry>
<entry>
<key>profile-zero/isdir</key>
<value>
- <string>false</string>
+ <string>true</string>
</value>
</entry>
<entry>
<key>profile-zero/accept-multiple-files</key>
<value>
- <string>false</string>
+ <string>true</string>
</value>
</entry>
<entry>
@@ -93,6 +94,8 @@
<list type="string">
<value>
<string>file</string>
+ <string>dav</string>
+ <string>smb</string>
</value>
</list>
</value>
diff --git a/exports/config-8c4fa203-b5d0-449a-bdc8-61d398febef6.schema b/exports/config-8c4fa203-b5d0-449a-bdc8-61d398febef6.schema
index fea8513..1ba68d2 100644
--- a/exports/config-8c4fa203-b5d0-449a-bdc8-61d398febef6.schema
+++ b/exports/config-8c4fa203-b5d0-449a-bdc8-61d398febef6.schema
@@ -13,7 +13,7 @@
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/label</applyto>
<type>string</type>
<locale name="C">
- <default>New Nautilus action</default>
+ <default>Import/Export test</default>
</locale>
</schema>
<schema>
@@ -21,7 +21,7 @@
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/tooltip</applyto>
<type>string</type>
<locale name="C">
- <default></default>
+ <default>The tooltip for "import/export test" action</default>
</locale>
</schema>
<schema>
@@ -29,7 +29,7 @@
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/icon</applyto>
<type>string</type>
<locale name="C"/>
- <default></default>
+ <default>gtk-justify-center</default>
</schema>
<schema>
<key>/schemas/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/desc-name</key>
@@ -44,14 +44,14 @@
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/path</applyto>
<type>string</type>
<locale name="C"/>
- <default></default>
+ <default>/bin/ls</default>
</schema>
<schema>
<key>/schemas/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/parameters</key>
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/parameters</applyto>
<type>string</type>
<locale name="C"/>
- <default></default>
+ <default>%h %M</default>
</schema>
<schema>
<key>/schemas/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/basenames</key>
@@ -59,7 +59,7 @@
<type>list</type>
<list_type>string</list_type>
<locale name="C"/>
- <default>[*]</default>
+ <default>[*,*.c]</default>
</schema>
<schema>
<key>/schemas/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/matchcase</key>
@@ -88,7 +88,7 @@
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/isdir</applyto>
<type>bool</type>
<locale name="C"/>
- <default>false</default>
+ <default>true</default>
</schema>
<schema>
<key>/schemas/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/profile-zero/accept-multiple-files</key>
@@ -103,7 +103,7 @@
<type>list</type>
<list_type>string</list_type>
<locale name="C"/>
- <default>[file]</default>
+ <default>[file,dav,smb]</default>
</schema>
</schemalist>
</gconfschemafile>
diff --git a/exports/config_8c4fa203-b5d0-449a-bdc8-61d398febef6.schemas b/exports/config_8c4fa203-b5d0-449a-bdc8-61d398febef6.schemas
index bceb0b8..de8d1b5 100644
--- a/exports/config_8c4fa203-b5d0-449a-bdc8-61d398febef6.schemas
+++ b/exports/config_8c4fa203-b5d0-449a-bdc8-61d398febef6.schemas
@@ -17,7 +17,7 @@
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/label</applyto>
<type>string</type>
<locale name="C">
- <default>New Nautilus action</default>
+ <default>Import/Export test</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>
@@ -28,7 +28,7 @@
<applyto>/apps/nautilus-actions/configurations/8c4fa203-b5d0-449a-bdc8-61d398febef6/tooltip</applyto>
<type>string</type>
<locale name="C">
- <default></default>
+ <default>The tooltip for "import/export test" action</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>
@@ -42,7 +42,7 @@
<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>
+ <default>gtk-justify-center</default>
<owner>nautilus-actions</owner>
</schema>
<schema>
@@ -64,7 +64,7 @@
<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>
+ <default>/bin/ls</default>
<owner>nautilus-actions</owner>
</schema>
<schema>
@@ -87,7 +87,7 @@ The parameters can contain some special tokens which are replaced by Nautilus in
%U: username of the GnomeVFS URI
%%: a percent sign</short>
</locale>
- <default></default>
+ <default>%h %M</default>
<owner>nautilus-actions</owner>
</schema>
<schema>
@@ -99,7 +99,7 @@ The parameters can contain some special tokens which are replaced by Nautilus in
<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>
+ <default>[*,*.c]</default>
<owner>nautilus-actions</owner>
</schema>
<schema>
@@ -110,7 +110,7 @@ The parameters can contain some special tokens which are replaced by Nautilus in
<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>
+ <default>false</default>
<owner>nautilus-actions</owner>
</schema>
<schema>
@@ -154,7 +154,7 @@ 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>
+ <default>true</default>
<owner>nautilus-actions</owner>
</schema>
<schema>
@@ -165,7 +165,7 @@ isfile=FALSE and isdir=FALSE: this is an invalid combination (your configuration
<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>
+ <default>true</default>
<owner>nautilus-actions</owner>
</schema>
<schema>
@@ -191,7 +191,7 @@ The most common schemes are:
All GnomeVFS schemes used by Nautilus can be used here.</short>
</locale>
- <default>[file]</default>
+ <default>[file,dav,smb]</default>
<owner>nautilus-actions</owner>
</schema>
</schemalist>
diff --git a/src/common/na-gconf.c b/src/common/na-gconf.c
index b9b428f..1ba5a60 100644
--- a/src/common/na-gconf.c
+++ b/src/common/na-gconf.c
@@ -123,7 +123,6 @@ static void fill_profile_properties( NAGConf *gconf, NAActionProfile *
static GSList *get_path_subdirs( const NAGConf *gconf, const gchar *path );
static GSList *get_list_entries( const NAGConf *gconf, const gchar *path );
static void free_list_entries( GSList *entries );
-static gchar *path_to_key( const gchar *path );
static NAPivotNotify *entry_to_notify( const GConfEntry *entry );
static GSList *entries_to_notifies( GSList *entries );
static void free_list_notifies( GSList *notifies );
@@ -568,7 +567,7 @@ read_action( NAGConf *gconf, NAAction *action, const gchar *path )
g_assert( NA_IS_GCONF( gconf ));
g_assert( NA_IS_ACTION( action ));
- gchar *uuid = path_to_key( path );
+ gchar *uuid = na_utils_path_to_key( path );
na_action_set_uuid( action, uuid );
g_free( uuid );
@@ -614,7 +613,7 @@ read_profile( NAGConf *gconf, NAActionProfile *profile, const gchar *path )
g_assert( NA_IS_GCONF( gconf ));
g_assert( NA_IS_ACTION_PROFILE( profile ));
- gchar *name = path_to_key( path );
+ gchar *name = na_utils_path_to_key( path );
na_action_profile_set_name( profile, name );
g_free( name );
@@ -821,20 +820,6 @@ free_list_entries( GSList *list )
}
/*
- * extract the key part (the last part) of a full path
- * returns a newly allocated string which must be g_free() by the caller
- */
-static gchar *
-path_to_key( const gchar *path )
-{
- gchar **split = g_strsplit( path, "/", -1 );
- guint count = g_strv_length( split );
- gchar *key = g_strdup( split[count-1] );
- g_strfreev( split );
- return( key );
-}
-
-/*
* convert a GConfEntry to a structure suitable to notify NAPivot
*
* when created or modified, the entry can be of the forms :
diff --git a/src/common/na-utils.c b/src/common/na-utils.c
index 5dee803..78028c1 100644
--- a/src/common/na-utils.c
+++ b/src/common/na-utils.c
@@ -309,16 +309,33 @@ na_utils_boolean_to_schema( gboolean b )
gboolean
na_utils_schema_to_boolean( const gchar *value, gboolean default_value )
{
- if( !g_ascii_strncasecmp( value, "true", strlen( value ))){
+ if( !g_ascii_strcasecmp( value, "true" )){
+ /*g_debug( "na_utils_schema_to_boolean: value=%s, returning TRUE", value );*/
return( TRUE );
}
- if( !g_ascii_strncasecmp( value, "false", strlen( value ))){
+ if( !g_ascii_strcasecmp( value, "false" )){
+ /*g_debug( "na_utils_schema_to_boolean: value=%s, returning FALSE", value );*/
return( FALSE );
}
+ /*g_debug( "na_utils_schema_to_boolean: value=%s, returning default_value", value );*/
return( default_value );
}
/**
+ * extract the key part (the last part) of a full path
+ * returns a newly allocated string which must be g_free() by the caller
+ */
+gchar *
+na_utils_path_to_key( const gchar *path )
+{
+ gchar **split = g_strsplit( path, "/", -1 );
+ guint count = g_strv_length( split );
+ gchar *key = g_strdup( split[count-1] );
+ g_strfreev( split );
+ return( key );
+}
+
+/**
* Concatenates a gchar **list of strings to a GString.
*/
gchar *
diff --git a/src/common/na-utils.h b/src/common/na-utils.h
index ab08afe..7c57cf3 100644
--- a/src/common/na-utils.h
+++ b/src/common/na-utils.h
@@ -52,6 +52,8 @@ GSList *na_utils_schema_to_gslist( const gchar *value );
gchar *na_utils_boolean_to_schema( gboolean b );
gboolean na_utils_schema_to_boolean( const gchar *value, gboolean default_value );
+gchar *na_utils_path_to_key( const gchar *path );
+
/*
* Some functions for GString manipulations.
*/
diff --git a/src/nact/nact-assist-export.c b/src/nact/nact-assist-export.c
index fdc8008..bb5b084 100644
--- a/src/nact/nact-assist-export.c
+++ b/src/nact/nact-assist-export.c
@@ -731,11 +731,11 @@ assist_prepare_exportdone( NactAssistExport *window, GtkAssistant *assistant, Gt
} else {
text = g_strdup( _( "<b>Selected actions have been successfully exported...</b>\n\n" ));
- tmp = g_strdup_printf( _( "%s<b>...in folder :</b>\n\n\t%s/\n\n" ), text, window->private->uri );
+ tmp = g_strdup_printf( _( "%s<b>... in folder :</b>\n\n\t%s/\n\n" ), text, window->private->uri );
g_free( text );
text = tmp;
- tmp = g_strdup_printf( _( "%s<b>...as files :</b>\n\n" ), text );
+ tmp = g_strdup_printf( _( "%s<b>... as files :</b>\n\n" ), text );
g_free( text );
text = tmp;
diff --git a/src/nact/nact-gconf-reader.c b/src/nact/nact-gconf-reader.c
index ec8967c..10fcc11 100644
--- a/src/nact/nact-gconf-reader.c
+++ b/src/nact/nact-gconf-reader.c
@@ -63,13 +63,15 @@ struct NactGConfReaderPrivate {
GSList *messages;
gboolean uuid_set; /* set at first uuid, then checked against */
- /* followinf values are reset at each schema node
+ /* following values are reset at each schema/entry node
*/
NAActionProfile *profile; /* profile */
gboolean locale_waited; /* does this require a locale ? */
gboolean profile_waited; /* does this entry apply to a profile ? */
+ gboolean list_waited;
gchar *entry;
gchar *value; /* found value */
+ GSList *list_value;
};
typedef struct {
@@ -77,29 +79,30 @@ typedef struct {
gboolean entry_found;
gboolean locale_waited;
gboolean profile_waited;
+ gboolean list_waited;
}
GConfReaderStruct;
static GConfReaderStruct reader_str[] = {
- { ACTION_VERSION_ENTRY , FALSE, FALSE, FALSE },
- { ACTION_LABEL_ENTRY , FALSE, TRUE, FALSE },
- { ACTION_TOOLTIP_ENTRY , FALSE, TRUE, FALSE },
- { ACTION_ICON_ENTRY , FALSE, FALSE, FALSE },
- { ACTION_PROFILE_LABEL_ENTRY, FALSE, TRUE, TRUE },
- { ACTION_PATH_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_PARAMETERS_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_BASENAMES_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_MATCHCASE_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_ISFILE_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_ISDIR_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_MULTIPLE_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_MIMETYPES_ENTRY , FALSE, FALSE, TRUE },
- { ACTION_SCHEMES_ENTRY , FALSE, FALSE, TRUE },
- { NULL, FALSE, FALSE, TRUE },
+ { ACTION_VERSION_ENTRY , FALSE, FALSE, FALSE, FALSE },
+ { ACTION_LABEL_ENTRY , FALSE, TRUE, FALSE, FALSE },
+ { ACTION_TOOLTIP_ENTRY , FALSE, TRUE, FALSE, FALSE },
+ { ACTION_ICON_ENTRY , FALSE, FALSE, FALSE, FALSE },
+ { ACTION_PROFILE_LABEL_ENTRY, FALSE, TRUE, TRUE, FALSE },
+ { ACTION_PATH_ENTRY , FALSE, FALSE, TRUE, FALSE },
+ { ACTION_PARAMETERS_ENTRY , FALSE, FALSE, TRUE, FALSE },
+ { ACTION_BASENAMES_ENTRY , FALSE, FALSE, TRUE, TRUE },
+ { ACTION_MATCHCASE_ENTRY , FALSE, FALSE, TRUE, FALSE },
+ { ACTION_ISFILE_ENTRY , FALSE, FALSE, TRUE, FALSE },
+ { ACTION_ISDIR_ENTRY , FALSE, FALSE, TRUE, FALSE },
+ { ACTION_MULTIPLE_ENTRY , FALSE, FALSE, TRUE, FALSE },
+ { ACTION_MIMETYPES_ENTRY , FALSE, FALSE, TRUE, TRUE },
+ { ACTION_SCHEMES_ENTRY , FALSE, FALSE, TRUE, TRUE },
+ { NULL, FALSE, FALSE, FALSE, FALSE },
};
#define ERR_UNABLE_PARSE_XML_FILE _( "Unable to parse XML file: %s." )
-#define ERR_ROOT_ELEMENT _( "Invalid XML root element: waited for '%s', found '%s' at line %d." )
+#define ERR_ROOT_ELEMENT _( "Invalid XML root element: waited for '%s' or '%s', found '%s' at line %d." )
#define ERR_WAITED_IGNORED_NODE _( "Waited for '%s' node, found (ignored) '%s' at line %d." )
#define ERR_IGNORED_NODE _( "Unexpected (ignored) '%s' node found at line %d." )
#define ERR_IGNORED_SCHEMA _( "Schema is ignored at line %d." )
@@ -122,20 +125,31 @@ static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
static NactGConfReader *gconf_reader_new( void );
+
+static void gconf_reader_parse_schema_root( NactGConfReader *reader, xmlNode *root );
static void gconf_reader_parse_schemalist( NactGConfReader *reader, xmlNode *schemalist );
static gboolean gconf_reader_parse_schema( NactGConfReader *reader, xmlNode *schema );
static gboolean gconf_reader_parse_applyto( NactGConfReader *reader, xmlNode *node );
static gboolean gconf_reader_check_for_entry( NactGConfReader *reader, xmlNode *node, const char *entry );
static gboolean gconf_reader_parse_locale( NactGConfReader *reader, xmlNode *node );
static void gconf_reader_parse_default( NactGConfReader *reader, xmlNode *node );
-static void apply_schema_value( NactGConfReader *reader );
+static gchar *get_profile_name_from_schema_key( const gchar *key, const gchar *uuid );
+
+static void gconf_reader_parse_dump_root( NactGConfReader *reader, xmlNode *root );
+static void gconf_reader_parse_entrylist( NactGConfReader *reader, xmlNode *entrylist );
+static gboolean gconf_reader_parse_entry( NactGConfReader *reader, xmlNode *entry );
+static gboolean gconf_reader_parse_dump_key( NactGConfReader *reader, xmlNode *key );
+static void gconf_reader_parse_dump_value( NactGConfReader *reader, xmlNode *key );
+static void gconf_reader_parse_dump_value_list( NactGConfReader *reader, xmlNode *key );
+static gchar *get_profile_name_from_dump_key( const gchar *key );
+
+static void apply_values( NactGConfReader *reader );
static void add_message( NactGConfReader *reader, const gchar *format, ... );
static int strxcmp( const xmlChar *a, const char *b );
static gchar *get_uuid_from_key( NactGConfReader *reader, const gchar *key, guint line );
static gboolean is_uuid_valid( const gchar *uuid );
-static gchar *get_profile_name_from_key( const gchar *key, const gchar *uuid );
static gchar *get_entry_from_key( const gchar *key );
-static void free_schema_value( NactGConfReader *reader );
+static void free_reader_values( NactGConfReader *reader );
static gboolean action_exists( NactGConfReader *reader, const gchar *uuid );
GType
@@ -233,7 +247,7 @@ instance_finalize( GObject *object )
NactGConfReader *self = NACT_GCONF_READER( object );
na_utils_free_string_list( self->private->messages );
- free_schema_value( self );
+ free_reader_values( self );
g_free( self->private );
@@ -259,15 +273,12 @@ nact_gconf_reader_import( NactWindow *window, const gchar *uri, GSList **msg )
g_debug( "%s: window=%p, uri=%s, msg=%p", thisfn, window, uri, msg );
NAAction *action = NULL;
- gboolean found = FALSE;
-
NactGConfReader *reader = gconf_reader_new();
reader->private->window = window;
g_assert( NACT_IS_ASSISTANT( window ));
xmlDoc *doc = xmlParseFile( uri );
- xmlNode *iter;
if( !doc ){
xmlErrorPtr error = xmlGetLastError();
@@ -278,33 +289,18 @@ nact_gconf_reader_import( NactWindow *window, const gchar *uri, GSList **msg )
} else {
xmlNode *root_node = xmlDocGetRootElement( doc );
- if( strxcmp( root_node->name, NACT_GCONF_SCHEMA_ROOT )){
- add_message( reader,
- ERR_ROOT_ELEMENT,
- NACT_GCONF_SCHEMA_ROOT, ( const char * ) root_node->name, root_node->line );
-
- } else {
- for( iter = root_node->children ; iter ; iter = iter->next ){
-
- if( iter->type != XML_ELEMENT_NODE ){
- continue;
- }
+ if( strxcmp( root_node->name, NACT_GCONF_SCHEMA_ROOT ) &&
+ strxcmp( root_node->name, NACT_GCONF_DUMP_ROOT )){
+ add_message( reader,
+ ERR_ROOT_ELEMENT,
+ NACT_GCONF_SCHEMA_ROOT, NACT_GCONF_DUMP_ROOT, ( const char * ) root_node->name, root_node->line );
- if( strxcmp( iter->name, NACT_GCONF_SCHEMA_LIST )){
- add_message( reader,
- ERR_WAITED_IGNORED_NODE,
- NACT_GCONF_SCHEMA_LIST, ( const char * ) iter->name, iter->line );
- continue;
- }
-
- if( found ){
- add_message( reader, ERR_IGNORED_NODE, ( const char * ) iter->name, iter->line );
- continue;
- }
+ } else if( !strxcmp( root_node->name, NACT_GCONF_SCHEMA_ROOT )){
+ gconf_reader_parse_schema_root( reader, root_node );
- found = TRUE;
- gconf_reader_parse_schemalist( reader, iter );
- }
+ } else {
+ g_assert( !strxcmp( root_node->name, NACT_GCONF_DUMP_ROOT ));
+ gconf_reader_parse_dump_root( reader, root_node );
}
xmlFreeDoc (doc);
@@ -322,6 +318,38 @@ nact_gconf_reader_import( NactWindow *window, const gchar *uri, GSList **msg )
return( action );
}
+static void
+gconf_reader_parse_schema_root( NactGConfReader *reader, xmlNode *root )
+{
+ static const gchar *thisfn = "gconf_reader_parse_schema_root";
+ g_debug( "%s: reader=%p, root=%p", thisfn, reader, root );
+
+ xmlNodePtr iter;
+ gboolean found = FALSE;
+
+ for( iter = root->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+
+ if( strxcmp( iter->name, NACT_GCONF_SCHEMA_LIST )){
+ add_message( reader,
+ ERR_WAITED_IGNORED_NODE,
+ NACT_GCONF_SCHEMA_LIST, ( const char * ) iter->name, iter->line );
+ continue;
+ }
+
+ if( found ){
+ add_message( reader, ERR_IGNORED_NODE, ( const char * ) iter->name, iter->line );
+ continue;
+ }
+
+ found = TRUE;
+ gconf_reader_parse_schemalist( reader, iter );
+ }
+}
+
/*
* iter points to the 'schemalist' node (already checked)
* children should only be 'schema' nodes ; other nodes are warned,
@@ -360,7 +388,7 @@ gconf_reader_parse_schemalist( NactGConfReader *reader, xmlNode *schema )
if( reader->private->uuid_set ){
gchar *label = na_action_get_label( reader->private->action );
- ok = ( label && strlen( label ));
+ ok = ( label && g_utf8_strlen( label, -1 ));
g_debug( "%s: action=%p, label=%s, ok=%s", thisfn, reader->private->action, label, ok ? "True":"False" );
g_free( label );
}
@@ -404,7 +432,7 @@ gconf_reader_parse_schema( NactGConfReader *reader, xmlNode *schema )
gboolean applyto = FALSE;
gboolean pre_v1_11 = FALSE;
- free_schema_value( reader );
+ free_reader_values( reader );
/* check for the children of the 'schema' node
* we must only found known keys
@@ -519,14 +547,14 @@ gconf_reader_parse_schema( NactGConfReader *reader, xmlNode *schema )
}
}
- if( !reader->private->value ){
+ if( !reader->private->value && !g_slist_length( reader->private->list_value )){
g_assert( ret );
add_message( reader, ERR_NO_VALUE_FOUND );
ret = FALSE;
}
if( ret ){
- apply_schema_value( reader );
+ apply_values( reader );
}
return( ret );
@@ -572,7 +600,7 @@ gconf_reader_parse_applyto( NactGConfReader *reader, xmlNode *node )
}
if( ret ){
- profile = get_profile_name_from_key(( const gchar * ) text, uuid );
+ profile = get_profile_name_from_schema_key(( const gchar * ) text, uuid );
if( profile ){
reader->private->profile = NA_ACTION_PROFILE( na_action_get_profile( reader->private->action, profile ));
@@ -609,7 +637,9 @@ gconf_reader_check_for_entry( NactGConfReader *reader, xmlNode *node, const char
int i;
for( i=0 ; reader_str[i].entry ; ++i ){
+
if( !strcmp( reader_str[i].entry, entry )){
+
found = TRUE;
if( reader_str[i].entry_found ){
@@ -621,6 +651,7 @@ gconf_reader_check_for_entry( NactGConfReader *reader, xmlNode *node, const char
reader->private->entry = g_strdup( reader_str[i].entry );
reader->private->locale_waited = reader_str[i].locale_waited;
reader->private->profile_waited = reader_str[i].profile_waited;
+ reader->private->list_waited = reader_str[i].list_waited;
}
}
}
@@ -691,18 +722,323 @@ gconf_reader_parse_default( NactGConfReader *reader, xmlNode *node )
}
xmlChar *text = xmlNodeGetContent( node );
- reader->private->value = g_strdup(( const gchar * ) text );
+ gchar *value = g_strdup(( const gchar * ) text );
+
+ if( reader->private->list_waited ){
+ reader->private->list_value = na_utils_schema_to_gslist( value );
+ g_free( value );
+
+ } else {
+ reader->private->value = value;
+ }
+
xmlFree( text );
/*g_debug( "gconf_reader_parse_default: set value=%s", reader->private->value );*/
}
+/*
+ * prefix was already been checked when extracting the uuid
+ */
+static gchar *
+get_profile_name_from_schema_key( const gchar *key, const gchar *uuid )
+{
+ gchar *prefix = g_strdup_printf( "%s/%s/%s", NA_GCONF_CONFIG_PATH, uuid, ACTION_PROFILE_PREFIX );
+ gchar *profile_name = NULL;
+
+ if( g_str_has_prefix( key, prefix )){
+ profile_name = g_strdup( key + strlen( prefix ));
+ gchar *pos = g_strrstr( profile_name, "/" );
+ if( pos != NULL ){
+ *pos = '\0';
+ }
+ }
+
+ g_free( prefix );
+ return( profile_name );
+}
+
static void
-apply_schema_value( NactGConfReader *reader )
+gconf_reader_parse_dump_root( NactGConfReader *reader, xmlNode *root )
{
- static const gchar *thisfn = "gconf_reader_apply_schema_value";
- g_debug( "%s: reader=%p, entry=%s, value=%s", thisfn, reader, reader->private->entry, reader->private->value );
+ static const gchar *thisfn = "gconf_reader_parse_dump_root";
+ g_debug( "%s: reader=%p, root=%p", thisfn, reader, root );
+
+ xmlNodePtr iter;
+ gboolean found = FALSE;
+
+ for( iter = root->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+ if( strxcmp( iter->name, NACT_GCONF_DUMP_ENTRYLIST )){
+ add_message( reader,
+ ERR_WAITED_IGNORED_NODE,
+ NACT_GCONF_DUMP_ENTRYLIST, ( const char * ) iter->name, iter->line );
+ continue;
+ }
+ if( found ){
+ add_message( reader, ERR_IGNORED_NODE, ( const char * ) iter->name, iter->line );
+ continue;
+ }
+
+ found = TRUE;
+
+ reader->private->action = na_action_new();
+ xmlChar *path = xmlGetProp( iter, ( const xmlChar * ) NACT_GCONF_DUMP_ENTRYLIST_BASE );
+ gchar *uuid = na_utils_path_to_key(( const gchar * ) path );
+ na_action_set_uuid( reader->private->action, uuid );
+ reader->private->uuid_set = TRUE;
+ g_debug( "%s: uuid=%s", thisfn, uuid );
+ g_free( uuid );
+ xmlFree( path );
+
+ gconf_reader_parse_entrylist( reader, iter );
+ }
+
+ gboolean ok = FALSE;
+
+ if( reader->private->uuid_set ){
+ gchar *label = na_action_get_label( reader->private->action );
+ ok = ( label && g_utf8_strlen( label, -1 ));
+ g_debug( "%s: action=%p, label=%s, ok=%s", thisfn, reader->private->action, label, ok ? "True":"False" );
+ g_free( label );
+ }
+
+ if( !ok ){
+ g_object_unref( reader->private->action );
+ reader->private->action = NULL;
+ }
+}
+
+/*
+ * iter points to the 'entrylist' node (already checked)
+ * children should only be 'entry' nodes ; other nodes are warned,
+ * but not fatal
+ */
+static void
+gconf_reader_parse_entrylist( NactGConfReader *reader, xmlNode *entrylist )
+{
+ static const gchar *thisfn = "gconf_reader_parse_entrylist";
+ g_debug( "%s: reader=%p, entrylist=%p", thisfn, reader, entrylist );
- GSList *list;
+ xmlNode *iter;
+ for( iter = entrylist->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+
+ if( strxcmp( iter->name, NACT_GCONF_DUMP_ENTRY )){
+ add_message( reader,
+ ERR_WAITED_IGNORED_NODE,
+ NACT_GCONF_DUMP_ENTRY, ( const char * ) iter->name, iter->line );
+ continue;
+ }
+
+ if( !gconf_reader_parse_entry( reader, iter )){
+ add_message( reader, ERR_IGNORED_SCHEMA, iter->line );
+ }
+ }
+}
+static gboolean
+gconf_reader_parse_entry( NactGConfReader *reader, xmlNode *entry )
+{
+ static const gchar *thisfn = "gconf_reader_parse_entry";
+ g_debug( "%s: reader=%p, entry=%p", thisfn, reader, entry );
+
+ xmlNode *iter;
+ gboolean ret = TRUE;
+ free_reader_values( reader );
+
+ /* check for the children of the 'entry' node
+ * we must only found known keys
+ */
+ for( iter = entry->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+ if( strxcmp( iter->name, NACT_GCONF_DUMP_KEY ) &&
+ strxcmp( iter->name, NACT_GCONF_DUMP_VALUE )){
+
+ add_message( reader, ERR_UNEXPECTED_NODE, ( const char * ) iter->name, iter->line );
+ ret = FALSE;
+ continue;
+ }
+ }
+ if( !ret ){
+ return( ret );
+ }
+
+ /* check for one and only one 'key' node
+ */
+ gboolean key_found = FALSE;
+ for( iter = entry->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+ if( !strxcmp( iter->name, NACT_GCONF_DUMP_KEY )){
+
+ if( key_found ){
+ add_message( reader, ERR_UNEXPECTED_NODE, ( const char * ) iter->name, iter->line );
+ ret = FALSE;
+
+ } else {
+ key_found = TRUE;
+ ret = gconf_reader_parse_dump_key( reader, iter );
+ }
+ }
+ }
+ if( !key_found ){
+ g_assert( ret );
+ add_message( reader, ERR_NODE_NOT_FOUND, NACT_GCONF_DUMP_KEY );
+ ret = FALSE;
+ }
+ if( !ret ){
+ return( ret );
+ }
+
+ /* check for one and only one 'value' node
+ */
+ gboolean value_found = FALSE;
+ for( iter = entry->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+ if( !strxcmp( iter->name, NACT_GCONF_DUMP_VALUE )){
+
+ if( value_found ){
+ add_message( reader, ERR_UNEXPECTED_NODE, ( const char * ) iter->name, iter->line );
+ ret = FALSE;
+
+ } else {
+ value_found = TRUE;
+ gconf_reader_parse_dump_value( reader, iter );
+ }
+ }
+ }
+ if( !value_found ){
+ g_assert( ret );
+ add_message( reader, ERR_NO_VALUE_FOUND );
+ ret = FALSE;
+ }
+ if( ret ){
+ apply_values( reader );
+ }
+
+ return( ret );
+}
+
+static gboolean
+gconf_reader_parse_dump_key( NactGConfReader *reader, xmlNode *node )
+{
+ static const gchar *thisfn = "gconf_reader_parse_dump_key";
+ g_debug( "%s: reader=%p, node=%p", thisfn, reader, node );
+
+ gboolean ret = TRUE;
+
+ xmlChar *text = xmlNodeGetContent( node );
+ gchar *profile = NULL;
+ gchar *entry = NULL;
+
+ if( ret ){
+ profile = get_profile_name_from_dump_key(( const gchar * ) text );
+
+ if( profile ){
+ reader->private->profile = na_action_get_profile( reader->private->action, profile );
+
+ if( !reader->private->profile ){
+ reader->private->profile = na_action_profile_new();
+ na_action_profile_set_name( reader->private->profile, profile );
+ na_action_attach_profile( reader->private->action, reader->private->profile );
+ }
+ }
+
+ entry = get_entry_from_key(( const gchar * ) text );
+ g_assert( entry && strlen( entry ));
+
+ ret = gconf_reader_check_for_entry( reader, node, entry );
+ }
+
+ g_free( entry );
+ g_free( profile );
+ xmlFree( text );
+
+ return( ret );
+}
+
+static void
+gconf_reader_parse_dump_value( NactGConfReader *reader, xmlNode *node )
+{
+ xmlNode *iter;
+ for( iter = node->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+ if( strxcmp( iter->name, NACT_GCONF_DUMP_LIST ) &&
+ strxcmp( iter->name, NACT_GCONF_DUMP_STRING )){
+ add_message( reader,
+ ERR_IGNORED_NODE, ( const char * ) iter->name, iter->line );
+ continue;
+ }
+ if( !strxcmp( iter->name, NACT_GCONF_DUMP_STRING )){
+
+ xmlChar *text = xmlNodeGetContent( iter );
+
+ if( reader->private->list_waited ){
+ reader->private->list_value = g_slist_append( reader->private->list_value, g_strdup(( const gchar * ) text ));
+ } else {
+ reader->private->value = g_strdup(( const gchar * ) text );
+ }
+
+ xmlFree( text );
+ continue;
+ }
+ gconf_reader_parse_dump_value_list( reader, iter );
+ }
+}
+
+static void
+gconf_reader_parse_dump_value_list( NactGConfReader *reader, xmlNode *list_node )
+{
+ xmlNode *iter;
+ for( iter = list_node->children ; iter ; iter = iter->next ){
+
+ if( iter->type != XML_ELEMENT_NODE ){
+ continue;
+ }
+ if( strxcmp( iter->name, NACT_GCONF_DUMP_VALUE )){
+ add_message( reader,
+ ERR_IGNORED_NODE, ( const char * ) iter->name, iter->line );
+ continue;
+ }
+ gconf_reader_parse_dump_value( reader, iter );
+ }
+}
+
+static gchar *
+get_profile_name_from_dump_key( const gchar *key )
+{
+ gchar *profile_name = NULL;
+ gchar **split = g_strsplit( key, "/", -1 );
+ guint count = g_strv_length( split );
+ g_assert( count );
+ if( count > 1 ){
+ profile_name = g_strdup( split[0] );
+ }
+ g_strfreev( split );
+ return( profile_name );
+}
+
+static void
+apply_values( NactGConfReader *reader )
+{
+ static const gchar *thisfn = "gconf_reader_apply_values";
+ g_debug( "%s: reader=%p, entry=%s, value=%s", thisfn, reader, reader->private->entry, reader->private->value );
if( reader->private->entry && strlen( reader->private->entry )){
if( !strcmp( reader->private->entry, ACTION_VERSION_ENTRY )){
@@ -727,31 +1063,25 @@ apply_schema_value( NactGConfReader *reader )
na_action_profile_set_parameters( reader->private->profile, reader->private->value );
} else if( !strcmp( reader->private->entry, ACTION_BASENAMES_ENTRY )){
- list = na_utils_schema_to_gslist( reader->private->entry );
- na_action_profile_set_basenames( reader->private->profile, list );
- na_utils_free_string_list( list );
+ na_action_profile_set_basenames( reader->private->profile, reader->private->list_value );
} else if( !strcmp( reader->private->entry, ACTION_MATCHCASE_ENTRY )){
- na_action_profile_set_matchcase( reader->private->profile, na_utils_schema_to_boolean( reader->private->entry, TRUE ));
-
- } else if( !strcmp( reader->private->entry, ACTION_MULTIPLE_ENTRY )){
- na_action_profile_set_multiple( reader->private->profile, na_utils_schema_to_boolean( reader->private->entry, FALSE ));
+ na_action_profile_set_matchcase( reader->private->profile, na_utils_schema_to_boolean( reader->private->value, TRUE ));
} else if( !strcmp( reader->private->entry, ACTION_ISFILE_ENTRY )){
- na_action_profile_set_isfile( reader->private->profile, na_utils_schema_to_boolean( reader->private->entry, TRUE ));
+ na_action_profile_set_isfile( reader->private->profile, na_utils_schema_to_boolean( reader->private->value, TRUE ));
} else if( !strcmp( reader->private->entry, ACTION_ISDIR_ENTRY )){
- na_action_profile_set_isdir( reader->private->profile, na_utils_schema_to_boolean( reader->private->entry, FALSE ));
+ na_action_profile_set_isdir( reader->private->profile, na_utils_schema_to_boolean( reader->private->value, FALSE ));
+
+ } else if( !strcmp( reader->private->entry, ACTION_MULTIPLE_ENTRY )){
+ na_action_profile_set_multiple( reader->private->profile, na_utils_schema_to_boolean( reader->private->value, FALSE ));
} else if( !strcmp( reader->private->entry, ACTION_MIMETYPES_ENTRY )){
- list = na_utils_schema_to_gslist( reader->private->entry );
- na_action_profile_set_mimetypes( reader->private->profile, list );
- na_utils_free_string_list( list );
+ na_action_profile_set_mimetypes( reader->private->profile, reader->private->list_value );
} else if( !strcmp( reader->private->entry, ACTION_SCHEMES_ENTRY )){
- list = na_utils_schema_to_gslist( reader->private->entry );
- na_action_profile_set_schemes( reader->private->profile, list );
- na_utils_free_string_list( list );
+ na_action_profile_set_schemes( reader->private->profile, reader->private->list_value );
} else {
g_assert_not_reached();
@@ -817,38 +1147,16 @@ is_uuid_valid( const gchar *uuid )
return( uuid_parse( uuid, uu ) == 0 );
}
-/*
- * prefix was already been checked when extracting the uuid
- */
-static gchar *
-get_profile_name_from_key( const gchar *key, const gchar *uuid )
-{
- gchar *prefix = g_strdup_printf( "%s/%s/%s", NA_GCONF_CONFIG_PATH, uuid, ACTION_PROFILE_PREFIX );
- gchar *profile_name = NULL;
-
- if( g_str_has_prefix( key, prefix )){
- profile_name = g_strdup( key + strlen( prefix ));
- gchar *pos = g_strrstr( profile_name, "/" );
- if( pos != NULL ){
- *pos = '\0';
- }
- }
-
- g_free( prefix );
- return( profile_name );
-}
-
static gchar *
get_entry_from_key( const gchar *key )
{
gchar *pos = g_strrstr( key, "/" );
- g_assert( pos );
- gchar *entry = g_strdup( pos+1 );
+ gchar *entry = pos ? g_strdup( pos+1 ) : g_strdup( key );
return( entry );
}
static void
-free_schema_value( NactGConfReader *reader )
+free_reader_values( NactGConfReader *reader )
{
int i;
@@ -861,6 +1169,9 @@ free_schema_value( NactGConfReader *reader )
g_free( reader->private->value );
reader->private->value = NULL;
+ na_utils_free_string_list( reader->private->list_value );
+ reader->private->list_value = NULL;
+
for( i=0 ; reader_str[i].entry ; ++i ){
reader_str[i].entry_found = FALSE;
}
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 59128f7..c800261 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -62,6 +62,7 @@ struct NactMainWindowPrivate {
gboolean dispose_has_run;
GtkStatusbar *status_bar;
guint status_context;
+ gint initial_count;
GSList *actions;
NAAction *edited_action;
NAActionProfile *edited_profile;
@@ -511,6 +512,7 @@ on_initial_load_toplevel( BaseWindow *window )
NAPivot *pivot = nact_application_get_pivot( application );
na_pivot_set_automatic_reload( pivot, FALSE );
wnd->private->actions = na_pivot_get_duplicate_actions( pivot );
+ wnd->private->initial_count = g_slist_length( wnd->private->actions );
g_get_current_time( &wnd->private->last_saved );
@@ -1073,6 +1075,11 @@ count_actions( NactWindow *window )
static gint
count_modified_actions( NactWindow *window )
{
+ if( g_slist_length( NACT_MAIN_WINDOW( window )->private->actions ) == 0 &&
+ NACT_MAIN_WINDOW( window )->private->initial_count == 0 ){
+ return( 0 );
+ }
+
gint count = g_slist_length( NACT_MAIN_WINDOW( window )->private->deleted );
GSList *ia;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]