[nautilus-actions] Implement is_candidate_for_basenames() function
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Implement is_candidate_for_basenames() function
- Date: Fri, 30 Jul 2010 02:09:24 +0000 (UTC)
commit ec1c3afa348ac483f0813e4b12e3d81a4dcc6c1b
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Jul 30 04:08:52 2010 +0200
Implement is_candidate_for_basenames() function
ChangeLog | 7 +++++
TODO | 2 -
src/core/na-icontext.c | 54 ++++++++++++++++++++++++++++++++++++++++--
src/core/na-selected-info.c | 25 ++++++++++++++++++++
src/core/na-selected-info.h | 1 +
5 files changed, 84 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fc619ee..f2a8a72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2010-07-30 Pierre Wieser <pwieser trychlos org>
+ * src/core/na-icontext.c (is_candidate_for_basenames):
+ Implement the function.
+
+ * src/core/na-selected-info.c:
+ * src/core/na-selected-info.h (na_selected_info_get_basename):
+ New function.
+
* configure.ac: Add a dependancy on libgtop.
* src/core/na-icontext.c (is_candidate_for_show_if_running):
diff --git a/TODO b/TODO
index 6190d12..15e3e3b 100644
--- a/TODO
+++ b/TODO
@@ -496,8 +496,6 @@ Parameter Description
- 2010-07-27: enhancement: while editing a new filter, making it duplicate, try to keep editing
instead of terminating the edition and letting the old value
-- 2010-07-30: TODO: is_candidate_for_basenames
-
- 2010-07-30: TODO: is_candidate_for_selection_count
- 2010-07-30: TODO: is_candidate_for_schemes
diff --git a/src/core/na-icontext.c b/src/core/na-icontext.c
index 64d5a7f..2e32515 100644
--- a/src/core/na-icontext.c
+++ b/src/core/na-icontext.c
@@ -650,7 +650,7 @@ is_candidate_for_mimetypes( const NAIContext *object, guint target, GList *files
count_positive += 1;
}
gchar *imgroup, *imsubgroup;
- split_mimetype( imtype, &imgroup, &imsubgroup );
+ split_mimetype( positive ? imtype : imtype+1, &imgroup, &imsubgroup );
for( it = files ; it && ok ; it = it->next ){
gchar *ftype = na_selected_info_get_mime_type( NA_SELECTED_INFO( it->data ));
@@ -733,10 +733,58 @@ is_candidate_for_basenames( const NAIContext *object, guint target, GList *files
static const gchar *thisfn = "na_icontext_is_candidate_for_basenames";
gboolean ok = TRUE;
GSList *basenames = na_object_get_basenames( object );
+ GSList *ib;
+ gboolean positive;
+ guint count_positive = 0;
+ guint count_compatible = 0;
+ gchar *pattern, *bname, *bname_utf8;
+ GList *it;
+ GPatternSpec *pattern_spec;
+ gboolean match;
if( basenames ){
- gboolean matchcase = na_object_get_matchcase( object );
- matchcase = FALSE;
+ if( strcmp( basenames->data, "*" ) != 0 || g_slist_length( basenames ) > 1 ){
+ gboolean matchcase = na_object_get_matchcase( object );
+
+ for( ib = basenames ; ib && ok ; ib = ib->next ){
+ pattern = matchcase ?
+ g_strdup(( gchar * ) ib->data ) :
+ g_ascii_strdown(( gchar * ) ib->data, strlen(( gchar * ) ib->data ));
+
+ positive = is_positive_assertion( pattern );
+ if( positive ){
+ count_positive += 1;
+ }
+
+ pattern_spec = g_pattern_spec_new( positive ? pattern : pattern+1 );
+
+ for( it = files ; it && ok ; it = it->next ){
+ bname = na_selected_info_get_basename( NA_SELECTED_INFO( it->data ));
+ bname_utf8 = g_filename_to_utf8( bname, -1, NULL, NULL, NULL );
+ match = g_pattern_match_string( pattern_spec, bname_utf8 );
+ g_free( bname_utf8 );
+ g_free( bname );
+
+ g_debug( "%s: pattern=%s, positive=%s, match=%s", thisfn, pattern, positive ? "True":"False", match ? "True":"False" );
+ if( positive ){
+ if( match ){
+ count_compatible += 1;
+ }
+ } else {
+ if( match ){
+ ok = FALSE;
+ break;
+ }
+ }
+ }
+
+ g_free( pattern );
+ }
+ }
+
+ if( count_positive > 0 && count_compatible == 0 ){
+ ok = FALSE;
+ }
if( !ok ){
gchar *basenames_str = na_core_utils_slist_to_text( basenames );
diff --git a/src/core/na-selected-info.c b/src/core/na-selected-info.c
index 5e6dec3..447c297 100644
--- a/src/core/na-selected-info.c
+++ b/src/core/na-selected-info.c
@@ -286,6 +286,31 @@ na_selected_info_get_location( const NASelectedInfo *nsi )
}
/**
+ * na_selected_info_get_basename:
+ * @nsi: this #NASelectedInfo object.
+ *
+ * Returns: the basename of the file associated with this
+ * #NASelectedInfo object, as a newly allocated string which
+ * must be g_free() by the caller.
+ */
+gchar *
+na_selected_info_get_basename( const NASelectedInfo *nsi )
+{
+ gchar *basename;
+
+ g_return_val_if_fail( NA_IS_SELECTED_INFO( nsi ), NULL );
+
+ basename = NULL;
+
+ if( !nsi->private->dispose_has_run ){
+
+ basename = g_strdup( g_path_get_basename( nsi->private->vfs->path ));
+ }
+
+ return( basename );
+}
+
+/**
* na_selected_info_get_mime_type:
* @nsi: this #NASelectedInfo object.
*
diff --git a/src/core/na-selected-info.h b/src/core/na-selected-info.h
index cd647d3..f8db094 100644
--- a/src/core/na-selected-info.h
+++ b/src/core/na-selected-info.h
@@ -80,6 +80,7 @@ GList *na_selected_info_copy_list ( GList *list );
void na_selected_info_free_list ( GList *list );
GFile *na_selected_info_get_location ( const NASelectedInfo *nsi );
+gchar *na_selected_info_get_basename ( 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 );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]