[nautilus-actions] Implement the is_candidate_for_folders() function



commit 3a279d8df64ca2708a121e1adffa0bb57c16aac8
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sat Jul 31 19:53:11 2010 +0200

    Implement the is_candidate_for_folders() function

 ChangeLog                   |    7 ++++
 TODO                        |    2 -
 src/core/na-icontext.c      |   84 +++++++++++++++++++++++++-----------------
 src/core/na-selected-info.c |   25 +++++++++++++
 src/core/na-selected-info.h |    1 +
 5 files changed, 83 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 21e18ed..83a6d5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-07-31 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-icontext.c (is_candidate_for_folders):
+	Implement the function.
+
+	* src/core/na-selected-info.c:
+	* src/core/na-selected-info.h (na_selected_info_get_dirname):
+	New function.
+
 	* src/core/na-icontext.c (is_candidate_for_schemes):
 	Implement the function.
 
diff --git a/TODO b/TODO
index 9e05e1e..bcbcc22 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_folders
-
 - 2010-07-30: TODO: is_candidate_for_capabilities
 
 - 2010-06-20: TODO: is_candidate_for_show_in: get current environment
diff --git a/src/core/na-icontext.c b/src/core/na-icontext.c
index 24db284..1f18b12 100644
--- a/src/core/na-icontext.c
+++ b/src/core/na-icontext.c
@@ -79,9 +79,6 @@ static gboolean is_candidate_for_schemes( const NAIContext *object, guint target
 static gboolean validate_schemes( GSList *object_schemes, NASelectedInfo *iter );
 #endif
 static gboolean is_candidate_for_folders( const NAIContext *object, guint target, GList *files );
-#if 0
-static gboolean is_current_folder_inside( const NAIContext *object, NASelectedInfo *current_folder );
-#endif
 static gboolean is_candidate_for_capabilities( const NAIContext *object, guint target, GList *files );
 
 static void     count_compatible_patterns( gboolean positive, gboolean match, guint *count_compatible, gboolean *ok );
@@ -741,7 +738,6 @@ is_candidate_for_basenames( const NAIContext *object, guint target, GList *files
 				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;
@@ -759,7 +755,7 @@ is_candidate_for_basenames( const NAIContext *object, guint target, GList *files
 					count_compatible_patterns( positive, match, &count_compatible, &ok );
 				}
 
-				g_object_unref( pattern_spec );
+				g_pattern_spec_free( pattern_spec );
 				g_free( pattern );
 			}
 		}
@@ -835,7 +831,6 @@ is_candidate_for_schemes( const NAIContext *object, guint target, GList *files )
 	if( schemes ){
 		for( is = schemes ; is && ok ; is = is->next ){
 			pattern = ( gchar * ) is->data;
-
 			positive = is_positive_assertion( pattern );
 			if( positive ){
 				count_positive += 1;
@@ -878,8 +873,57 @@ is_candidate_for_folders( const NAIContext *object, guint target, GList *files )
 	static const gchar *thisfn = "na_icontext_is_candidate_for_folders";
 	gboolean ok = TRUE;
 	GSList *folders = na_object_get_folders( object );
+	GSList *id;
+	const gchar *pattern;
+	GList *it;
+	gchar *dirname, *dirname_utf8;
+	gboolean positive, match;
+	guint count_positive = 0;
+	guint count_compatible = 0;
+	GPatternSpec *pattern_spec;
 
 	if( folders ){
+		if( strcmp( folders->data, "/" ) != 0 || g_slist_length( folders ) > 1 ){
+			for( id = folders ; id && ok ; id = id->next ){
+				pattern = ( const gchar * ) id->data;
+				positive = is_positive_assertion( pattern );
+				if( positive ){
+					count_positive += 1;
+				} else {
+					pattern += 1;
+				}
+
+				pattern_spec = NULL;
+				if( g_strstr_len( pattern, -1, "*" ) != NULL ){
+					pattern_spec = g_pattern_spec_new( pattern );
+				}
+
+				for( it = files ; it && ok ; it = it->next ){
+					dirname = na_selected_info_get_dirname( NA_SELECTED_INFO( it->data ));
+
+					if( pattern_spec ){
+						dirname_utf8 = g_filename_to_utf8( dirname, -1, NULL, NULL, NULL );
+						match = g_pattern_match_string( pattern_spec, dirname_utf8 );
+						g_free( dirname_utf8 );
+
+					} else {
+						match = g_str_has_prefix( dirname, pattern );
+					}
+
+					g_free( dirname );
+					g_debug( "%s: pattern=%s, positive=%s, match=%s", thisfn, pattern, positive ? "True":"False", match ? "True":"False" );
+					count_compatible_patterns( positive, match, &count_compatible, &ok );
+				}
+
+				if( pattern_spec ){
+					g_pattern_spec_free( pattern_spec );
+				}
+			}
+		}
+
+		if( count_positive > 0 && count_compatible == 0 ){
+			ok = FALSE;
+		}
 
 		if( !ok ){
 			gchar *folders_str = na_core_utils_slist_to_text( folders );
@@ -893,34 +937,6 @@ is_candidate_for_folders( const NAIContext *object, guint target, GList *files )
 	return( ok );
 }
 
-#if 0
-static gboolean
-is_current_folder_inside( const NAIContext *object, NASelectedInfo *current_folder )
-{
-	gboolean is_inside;
-	GSList *folders, *ifold;
-	const gchar *path;
-	gchar *current_folder_path;
-
-	is_inside = FALSE;
-	current_folder_path = na_selected_info_get_path( current_folder );
-	folders = na_object_get_folders( object );
-
-	for( ifold = folders ; ifold && !is_inside ; ifold = ifold->next ){
-		path = ( const gchar * ) ifold->data;
-		if( path && g_utf8_strlen( path, -1 )){
-			is_inside = g_str_has_prefix( current_folder_path, path );
-			g_debug( "na_object_object_is_current_folder_inside: current_folder_path=%s, path=%s, is_inside=%s", current_folder_path, path, is_inside ? "True":"False" );
-		}
-	}
-
-	na_core_utils_slist_free( folders );
-	g_free( current_folder_path );
-
-	return( is_inside );
-}
-#endif
-
 static gboolean
 is_candidate_for_capabilities( const NAIContext *object, guint target, GList *files )
 {
diff --git a/src/core/na-selected-info.c b/src/core/na-selected-info.c
index 447c297..b439390 100644
--- a/src/core/na-selected-info.c
+++ b/src/core/na-selected-info.c
@@ -311,6 +311,31 @@ na_selected_info_get_basename( const NASelectedInfo *nsi )
 }
 
 /**
+ * na_selected_info_get_dirname:
+ * @nsi: this #NASelectedInfo object.
+ *
+ * Returns: the dirname 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_dirname( const NASelectedInfo *nsi )
+{
+	gchar *dirname;
+
+	g_return_val_if_fail( NA_IS_SELECTED_INFO( nsi ), NULL );
+
+	dirname = NULL;
+
+	if( !nsi->private->dispose_has_run ){
+
+		dirname = g_strdup( g_path_get_dirname( nsi->private->vfs->path ));
+	}
+
+	return( dirname );
+}
+
+/**
  * 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 f8db094..8b65736 100644
--- a/src/core/na-selected-info.h
+++ b/src/core/na-selected-info.h
@@ -81,6 +81,7 @@ 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_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 );



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