[nautilus-actions] Properly quote 'exotic' filenames
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Properly quote 'exotic' filenames
- Date: Wed, 29 Dec 2010 19:51:16 +0000 (UTC)
commit a39674aa605c8e84badcdb36dc0d51691ab2f712
Author: Pierre Wieser <pwieser trychlos org>
Date: Wed Dec 29 20:49:23 2010 +0100
Properly quote 'exotic' filenames
Exotic filenames include quotes, double quotes and spaces.
Fix #638278.
ChangeLog | 12 ++
src/core/na-selected-info.c | 172 +++++++++++++++++++++---------
src/core/na-selected-info.h | 4 +-
src/core/na-tokens.c | 65 +++++-------
src/nact/nautilus-actions-config-tool.ui | 36 +++---
5 files changed, 181 insertions(+), 108 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7d47e1e..6109818 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2010-12-29 Pierre Wieser <pwieser trychlos org>
+ * src/core/na-selected-info.c:
+ * src/core/na-selected-info.h:
+ No more keep GFile location nor NAGnomeVFSURI parsed URI.
+ (na_selected_info_get_location): Removed function.
+ (na_selected_info_get_uri_host, na_selected_info_get_uri_user,
+ na_selected_info_get_uri_port): New functions.
+
+ * src/core/na-tokens.c (na_tokens_new_from_selection):
+ Make use of new na_selected_info functions.
+ Quote the filename elements.
+ Fix #638278.
+
* src/core/na-tokens.c (build_string_lists):
Keep the same order than Nautilus. Fix #638272.
diff --git a/src/core/na-selected-info.c b/src/core/na-selected-info.c
index 6be4604..3333771 100644
--- a/src/core/na-selected-info.c
+++ b/src/core/na-selected-info.c
@@ -49,8 +49,13 @@ struct _NASelectedInfoClassPrivate {
struct _NASelectedInfoPrivate {
gboolean dispose_has_run;
gchar *uri;
- NAGnomeVFSURI *vfs;
- GFile *location;
+ gchar *filename;
+ gchar *dirname;
+ gchar *basename;
+ gchar *hostname;
+ gchar *username;
+ gchar *scheme;
+ guint port;
gchar *mimetype;
GFileType file_type;
gboolean can_read;
@@ -71,7 +76,7 @@ static void instance_finalize( GObject *object );
static void dump( const NASelectedInfo *nsi );
static NASelectedInfo *new_from_nautilus_file_info( NautilusFileInfo *item );
static NASelectedInfo *new_from_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg );
-static gboolean query_file_attributes( NASelectedInfo *info, gchar **errmsg );
+static gboolean query_file_attributes( NASelectedInfo *info, GFile *location, gchar **errmsg );
GType
na_selected_info_get_type( void )
@@ -160,9 +165,6 @@ instance_dispose( GObject *object )
self->private->dispose_has_run = TRUE;
- g_object_unref( self->private->location );
- na_gnome_vfs_uri_free( self->private->vfs );
-
/* chain up to the parent class */
if( G_OBJECT_CLASS( st_parent_class )->dispose ){
G_OBJECT_CLASS( st_parent_class )->dispose( object );
@@ -182,6 +184,12 @@ instance_finalize( GObject *object )
g_debug( "%s: object=%p", thisfn, ( void * ) object );
g_free( self->private->uri );
+ g_free( self->private->filename );
+ g_free( self->private->dirname );
+ g_free( self->private->basename );
+ g_free( self->private->hostname );
+ g_free( self->private->username );
+ g_free( self->private->scheme );
g_free( self->private->mimetype );
g_free( self->private->owner );
@@ -276,31 +284,6 @@ na_selected_info_free_list( GList *files )
}
/*
- * na_selected_info_get_location:
- * @nsi: this #NASelectedInfo object.
- *
- * Returns: a new reference to the #GFile location.
- *
- * The returned location should be g_object_unref() by the caller.
- */
-GFile *
-na_selected_info_get_location( const NASelectedInfo *nsi )
-{
- GFile *location;
-
- g_return_val_if_fail( NA_IS_SELECTED_INFO( nsi ), NULL );
-
- location = NULL;
-
- if( !nsi->private->dispose_has_run ){
-
- location = g_object_ref( nsi->private->location );
- }
-
- return( location );
-}
-
-/*
* na_selected_info_get_basename:
* @nsi: this #NASelectedInfo object.
*
@@ -319,7 +302,7 @@ na_selected_info_get_basename( const NASelectedInfo *nsi )
if( !nsi->private->dispose_has_run ){
- basename = g_strdup( g_path_get_basename( nsi->private->vfs->path ));
+ basename = g_strdup( nsi->private->basename );
}
return( basename );
@@ -344,7 +327,7 @@ na_selected_info_get_dirname( const NASelectedInfo *nsi )
if( !nsi->private->dispose_has_run ){
- dirname = g_strdup( g_path_get_dirname( nsi->private->vfs->path ));
+ dirname = g_strdup( nsi->private->dirname );
}
return( dirname );
@@ -380,7 +363,8 @@ na_selected_info_get_mime_type( const NASelectedInfo *nsi )
* na_selected_info_get_path:
* @nsi: this #NASelectedInfo object.
*
- * Returns: the filename of the item.
+ * Returns: the filename of the item as a newly allocated string which
+ * should be g_free() by the caller.
*/
gchar *
na_selected_info_get_path( const NASelectedInfo *nsi )
@@ -393,7 +377,7 @@ na_selected_info_get_path( const NASelectedInfo *nsi )
if( !nsi->private->dispose_has_run ){
- path = g_strdup( nsi->private->vfs->path );
+ path = g_strdup( nsi->private->filename );
}
return( path );
@@ -424,6 +408,77 @@ na_selected_info_get_uri( const NASelectedInfo *nsi )
}
/*
+ * na_selected_info_get_uri_host:
+ * @nsi: this #NASelectedInfo object.
+ *
+ * Returns: the host associated to this @nsi object, as a
+ * newly allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_selected_info_get_uri_host( const NASelectedInfo *nsi )
+{
+ gchar *host;
+
+ g_return_val_if_fail( NA_IS_SELECTED_INFO( nsi ), NULL );
+
+ host = NULL;
+
+ if( !nsi->private->dispose_has_run ){
+
+ host = g_strdup( nsi->private->hostname );
+ }
+
+ return( host );
+}
+
+/*
+ * na_selected_info_get_uri_user:
+ * @nsi: this #NASelectedInfo object.
+ *
+ * Returns: the user associated to this @nsi object, as a
+ * newly allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_selected_info_get_uri_user( const NASelectedInfo *nsi )
+{
+ gchar *user;
+
+ g_return_val_if_fail( NA_IS_SELECTED_INFO( nsi ), NULL );
+
+ user = NULL;
+
+ if( !nsi->private->dispose_has_run ){
+
+ user = g_strdup( nsi->private->username );
+ }
+
+ return( user );
+}
+
+/*
+ * na_selected_info_get_uri_port:
+ * @nsi: this #NASelectedInfo object.
+ *
+ * Returns: the port associated to this @nsi object.
+ */
+guint
+na_selected_info_get_uri_port( const NASelectedInfo *nsi )
+{
+ guint port;
+
+ g_return_val_if_fail( NA_IS_SELECTED_INFO( nsi ), 0 );
+
+ port = 0;
+
+ if( !nsi->private->dispose_has_run ){
+
+ port = nsi->private->port;
+ }
+
+ return( port );
+}
+
+/*
* na_selected_info_get_uri_scheme:
* @nsi: this #NASelectedInfo object.
*
@@ -441,7 +496,7 @@ na_selected_info_get_uri_scheme( const NASelectedInfo *nsi )
if( !nsi->private->dispose_has_run ){
- scheme = g_strdup( nsi->private->vfs->scheme );
+ scheme = g_strdup( nsi->private->scheme );
}
return( scheme );
@@ -615,13 +670,19 @@ dump( const NASelectedInfo *nsi )
{
static const gchar *thisfn = "na_selected_info_dump";
- g_debug( "%s: uri=%s", thisfn, nsi->private->uri );
- g_debug( "%s: mimetype=%s", thisfn, nsi->private->mimetype );
- g_debug( "%s: vfs->path=%s", thisfn, nsi->private->vfs->path );
- g_debug( "%s: vfs->host_name=%s", thisfn, nsi->private->vfs->host_name );
- g_debug( "%s: vfs->host_port=%d", thisfn, nsi->private->vfs->host_port );
- g_debug( "%s: vfs->user_name=%s", thisfn, nsi->private->vfs->user_name );
- g_debug( "%s: vfs->password=%s", thisfn, nsi->private->vfs->password );
+ g_debug( "%s: uri=%s", thisfn, nsi->private->uri );
+ g_debug( "%s: mimetype=%s", thisfn, nsi->private->mimetype );
+ g_debug( "%s: filename=%s", thisfn, nsi->private->filename );
+ g_debug( "%s: dirname=%s", thisfn, nsi->private->dirname );
+ g_debug( "%s: basename=%s", thisfn, nsi->private->basename );
+ g_debug( "%s: hostname=%s", thisfn, nsi->private->hostname );
+ g_debug( "%s: username=%s", thisfn, nsi->private->username );
+ g_debug( "%s: scheme=%s", thisfn, nsi->private->scheme );
+ g_debug( "%s: port=%d", thisfn, nsi->private->port );
+ g_debug( "%s: can_read=%s", thisfn, nsi->private->can_read ? "True":"False" );
+ g_debug( "%s: can_write=%s", thisfn, nsi->private->can_write ? "True":"False" );
+ g_debug( "%s: can_execute=%s", thisfn, nsi->private->can_execute ? "True":"False" );
+ g_debug( "%s: owner=%s", thisfn, nsi->private->owner );
}
static NASelectedInfo *
@@ -640,6 +701,9 @@ new_from_nautilus_file_info( NautilusFileInfo *item )
static NASelectedInfo *
new_from_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg )
{
+ GFile *location;
+ NAGnomeVFSURI *vfs;
+
NASelectedInfo *info = g_object_new( NA_SELECTED_INFO_TYPE, NULL );
info->private->uri = g_strdup( uri );
@@ -647,29 +711,39 @@ new_from_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg )
info->private->mimetype = g_strdup( mimetype );
}
- info->private->location = g_file_new_for_uri( uri );
- info->private->vfs = g_new0( NAGnomeVFSURI, 1 );
- na_gnome_vfs_uri_parse( info->private->vfs, info->private->uri );
+ info->private->filename = g_filename_from_uri( uri, NULL, NULL );
+ info->private->dirname = g_path_get_dirname( info->private->filename );
+ info->private->basename = g_path_get_basename( info->private->filename );
+
+ vfs = g_new0( NAGnomeVFSURI, 1 );
+ na_gnome_vfs_uri_parse( vfs, uri );
+ info->private->hostname = g_strdup( vfs->host_name );
+ info->private->username = g_strdup( vfs->user_name );
+ info->private->scheme = g_strdup( vfs->scheme );
+ info->private->port = vfs->host_port;
+ na_gnome_vfs_uri_free( vfs );
- if( query_file_attributes( info, errmsg )){
+ location = g_file_new_for_uri( uri );
+ if( query_file_attributes( info, location, errmsg )){
dump( info );
} else {
g_object_unref( info );
info = NULL;
}
+ g_object_unref( location );
return( info );
}
static gboolean
-query_file_attributes( NASelectedInfo *nsi, gchar **errmsg )
+query_file_attributes( NASelectedInfo *nsi, GFile *location, gchar **errmsg )
{
static const gchar *thisfn = "na_selected_info_query_file_attributes";
GError *error;
error = NULL;
- GFileInfo *info = g_file_query_info( nsi->private->location,
+ GFileInfo *info = g_file_query_info( location,
G_FILE_ATTRIBUTE_STANDARD_TYPE
"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
"," G_FILE_ATTRIBUTE_ACCESS_CAN_READ
diff --git a/src/core/na-selected-info.h b/src/core/na-selected-info.h
index c8d9cba..3aea653 100644
--- a/src/core/na-selected-info.h
+++ b/src/core/na-selected-info.h
@@ -80,12 +80,14 @@ GList *na_selected_info_get_list_from_list( GList *nautilus_selection )
GList *na_selected_info_copy_list ( GList *files );
void na_selected_info_free_list ( GList *files );
-GFile *na_selected_info_get_location ( const NASelectedInfo *nsi );
gchar *na_selected_info_get_basename ( const NASelectedInfo *nsi );
gchar *na_selected_info_get_dirname ( const NASelectedInfo *nsi );
gchar *na_selected_info_get_mime_type ( const NASelectedInfo *nsi );
gchar *na_selected_info_get_path ( const NASelectedInfo *nsi );
gchar *na_selected_info_get_uri ( const NASelectedInfo *nsi );
+gchar *na_selected_info_get_uri_host ( const NASelectedInfo *nsi );
+gchar *na_selected_info_get_uri_user ( const NASelectedInfo *nsi );
+guint na_selected_info_get_uri_port ( const NASelectedInfo *nsi );
gchar *na_selected_info_get_uri_scheme( const NASelectedInfo *nsi );
gboolean na_selected_info_is_directory ( const NASelectedInfo *nsi );
gboolean na_selected_info_is_executable ( const NASelectedInfo *nsi );
diff --git a/src/core/na-tokens.c b/src/core/na-tokens.c
index a58c7c0..dc24cb7 100644
--- a/src/core/na-tokens.c
+++ b/src/core/na-tokens.c
@@ -314,9 +314,7 @@ na_tokens_new_from_selection( GList *selection )
NATokens *tokens;
GList *it;
gchar *uri, *filename, *basedir, *basename, *bname_woext, *ext, *mimetype;
- GFile *location;
gboolean first;
- NAGnomeVFSURI *vfs;
g_debug( "%s: selection=%p (count=%d)", thisfn, ( void * ) selection, g_list_length( selection ));
@@ -326,40 +324,37 @@ na_tokens_new_from_selection( GList *selection )
tokens->private->count = g_list_length( selection );
for( it = selection ; it ; it = it->next ){
- location = na_selected_info_get_location( NA_SELECTED_INFO( it->data ));
mimetype = na_selected_info_get_mime_type( NA_SELECTED_INFO( it->data ));
uri = na_selected_info_get_uri( NA_SELECTED_INFO( it->data ));
- filename = g_file_get_path( location );
- basedir = filename ? g_path_get_dirname( filename ) : NULL;
- basename = g_file_get_basename( location );
+ filename = na_selected_info_get_path( NA_SELECTED_INFO( it->data ));
+ basedir = na_selected_info_get_dirname( NA_SELECTED_INFO( it->data ));
+ basename = na_selected_info_get_basename( NA_SELECTED_INFO( it->data ));
na_core_utils_dir_split_ext( basename, &bname_woext, &ext );
- g_debug( "%s: uri=%s, filename=%s, basedir=%s, basename=%s, bname_woext=%s, ext=%s",
- thisfn, uri, filename, basedir, basename, bname_woext, ext );
-
if( first ){
- vfs = g_new0( NAGnomeVFSURI, 1 );
- na_gnome_vfs_uri_parse( vfs, uri );
-
- tokens->private->hostname = g_strdup( vfs->host_name );
- tokens->private->username = g_strdup( vfs->user_name );
- tokens->private->port = vfs->host_port;
- tokens->private->scheme = g_strdup( vfs->scheme );
-
- na_gnome_vfs_uri_free( vfs );
+ tokens->private->hostname = na_selected_info_get_uri_host( NA_SELECTED_INFO( it->data ));
+ tokens->private->username = na_selected_info_get_uri_user( NA_SELECTED_INFO( it->data ));
+ tokens->private->port = na_selected_info_get_uri_port( NA_SELECTED_INFO( it->data ));
+ tokens->private->scheme = na_selected_info_get_uri_scheme( NA_SELECTED_INFO( it->data ));
first = FALSE;
}
tokens->private->uris = g_slist_prepend( tokens->private->uris, uri );
- tokens->private->filenames = g_slist_prepend( tokens->private->filenames, filename );
- tokens->private->basedirs = g_slist_prepend( tokens->private->basedirs, basedir );
- tokens->private->basenames = g_slist_prepend( tokens->private->basenames, basename );
- tokens->private->basenames_woext = g_slist_prepend( tokens->private->basenames_woext, bname_woext );
- tokens->private->exts = g_slist_prepend( tokens->private->exts, ext );
- tokens->private->mimetypes = g_slist_prepend( tokens->private->mimetypes, mimetype );
- g_object_unref( location );
+ tokens->private->filenames = g_slist_prepend( tokens->private->filenames, g_shell_quote( filename ));
+ tokens->private->basedirs = g_slist_prepend( tokens->private->basedirs, g_shell_quote( basedir ));
+ tokens->private->basenames = g_slist_prepend( tokens->private->basenames, g_shell_quote( basename ));
+ tokens->private->basenames_woext = g_slist_prepend( tokens->private->basenames_woext, g_shell_quote( bname_woext ));
+ tokens->private->exts = g_slist_prepend( tokens->private->exts, g_shell_quote( ext ));
+
+ g_free( filename );
+ g_free( basedir );
+ g_free( basename );
+ g_free( bname_woext );
+ g_free( ext );
+
+ tokens->private->mimetypes = g_slist_prepend( tokens->private->mimetypes, mimetype );
}
return( build_string_lists( tokens ));
@@ -567,9 +562,7 @@ parse_singular( const NATokens *tokens, const gchar *input, guint i, gboolean ut
if( tokens->private->basenames ){
nth = ( const gchar * ) g_slist_nth_data( tokens->private->basenames, i );
if( nth ){
- tmp = g_shell_quote( nth );
- output = g_string_append( output, tmp );
- g_free( tmp );
+ output = g_string_append( output, nth );
}
}
break;
@@ -588,9 +581,7 @@ parse_singular( const NATokens *tokens, const gchar *input, guint i, gboolean ut
if( tokens->private->basedirs ){
nth = ( const gchar * ) g_slist_nth_data( tokens->private->basedirs, i );
if( nth ){
- tmp = g_shell_quote( nth );
- output = g_string_append( output, tmp );
- g_free( tmp );
+ output = g_string_append( output, nth );
}
}
break;
@@ -605,9 +596,7 @@ parse_singular( const NATokens *tokens, const gchar *input, guint i, gboolean ut
if( tokens->private->filenames ){
nth = ( const gchar * ) g_slist_nth_data( tokens->private->filenames, i );
if( nth ){
- tmp = g_shell_quote( nth );
- output = g_string_append( output, tmp );
- g_free( tmp );
+ output = g_string_append( output, nth );
}
}
break;
@@ -689,9 +678,7 @@ parse_singular( const NATokens *tokens, const gchar *input, guint i, gboolean ut
if( tokens->private->basenames_woext ){
nth = ( const gchar * ) g_slist_nth_data( tokens->private->basenames_woext, i );
if( nth ){
- tmp = g_shell_quote( nth );
- output = g_string_append( output, tmp );
- g_free( tmp );
+ output = g_string_append( output, nth );
}
}
break;
@@ -706,9 +693,7 @@ parse_singular( const NATokens *tokens, const gchar *input, guint i, gboolean ut
if( tokens->private->exts ){
nth = ( const gchar * ) g_slist_nth_data( tokens->private->exts, i );
if( nth ){
- tmp = g_shell_quote( nth );
- output = g_string_append( output, tmp );
- g_free( tmp );
+ output = g_string_append( output, nth );
}
}
break;
diff --git a/src/nact/nautilus-actions-config-tool.ui b/src/nact/nautilus-actions-config-tool.ui
index f489551..77b5173 100644
--- a/src/nact/nautilus-actions-config-tool.ui
+++ b/src/nact/nautilus-actions-config-tool.ui
@@ -1075,11 +1075,10 @@ Defining several profiles lets you have several commands, each applying with a d
</packing>
</child>
<child type="tab">
- <object class="GtkLabel" id="label65">
+ <object class="GtkLabel" id="label15">
<property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">This tab lets you determines for which basenames the currently selected item will be displayed in the Nautilus context menu.
-Basenames may be negated to specify for which basenames your item must not appear.</property>
- <property name="label" translatable="yes">_Basenames</property>
+ <property name="tooltip_text" translatable="yes">This advanced tab lets you precisely define how your command will be executed.</property>
+ <property name="label" translatable="yes">E_xecution</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -1246,11 +1245,11 @@ Basenames may be negated to specify for which basenames your item must not appea
</packing>
</child>
<child type="tab">
- <object class="GtkLabel" id="label75">
+ <object class="GtkLabel" id="label65">
<property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">This tab lets you determines for which type of objects the currently selected item will be displayed in the Nautilus context menu.
-Mimetypes may be negated to specify for which type of objects your item must not appear.</property>
- <property name="label" translatable="yes">_Mimetypes</property>
+ <property name="tooltip_text" translatable="yes">This tab lets you determines for which basenames the currently selected item will be displayed in the Nautilus context menu.
+Basenames may be negated to specify for which basenames your item must not appear.</property>
+ <property name="label" translatable="yes">_Basenames</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -1397,11 +1396,11 @@ Mimetypes may be negated to specify for which basenames your item must not appea
</packing>
</child>
<child type="tab">
- <object class="GtkLabel" id="label16">
+ <object class="GtkLabel" id="label75">
<property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">This tab lets you determines where (in which folders) the currently selected files must be found in order the item be displayed in the Nautilus context menu.
-Folder filters may be negated to specify for which folders your item must not appear.</property>
- <property name="label" translatable="yes">_Folders</property>
+ <property name="tooltip_text" translatable="yes">This tab lets you determines for which type of objects the currently selected item will be displayed in the Nautilus context menu.
+Mimetypes may be negated to specify for which type of objects your item must not appear.</property>
+ <property name="label" translatable="yes">_Mimetypes</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -1575,10 +1574,11 @@ Folder filters may be negated to specify for which folders your item must not ap
</packing>
</child>
<child type="tab">
- <object class="GtkLabel" id="label15">
+ <object class="GtkLabel" id="label16">
<property name="visible">True</property>
- <property name="tooltip_text" translatable="yes">This advanced tab lets you precisely define how your command will be executed.</property>
- <property name="label" translatable="yes">E_xecution</property>
+ <property name="tooltip_text" translatable="yes">This tab lets you determines where (in which folders) the currently selected files must be found in order the item be displayed in the Nautilus context menu.
+Folder filters may be negated to specify for which folders your item must not appear.</property>
+ <property name="label" translatable="yes">_Folders</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -1762,7 +1762,7 @@ Filters may be negated to specify for which capabilities your item must not appe
<property name="use_underline">True</property>
</object>
<packing>
- <property name="position">5</property>
+ <property name="position">6</property>
<property name="tab_fill">False</property>
</packing>
</child>
@@ -2332,7 +2332,7 @@ Filters may be negated to specify for which schemes your item must not appear.</
<property name="use_underline">True</property>
</object>
<packing>
- <property name="position">5</property>
+ <property name="position">8</property>
<property name="tab_fill">False</property>
</packing>
</child>
@@ -2601,7 +2601,7 @@ Filters may be negated to specify for which schemes your item must not appear.</
<property name="use_underline">True</property>
</object>
<packing>
- <property name="position">7</property>
+ <property name="position">9</property>
<property name="tab_fill">False</property>
</packing>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]