[nautilus-actions] Fix incorrect and optimize handling of scheme conditions
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Fix incorrect and optimize handling of scheme conditions
- Date: Mon, 9 Aug 2010 21:16:11 +0000 (UTC)
commit b9b5f48b4ef4d49709b1e4ede5b7494d201ae7f2
Author: pierre <pierre vfedora10 virtuals pwi>
Date: Mon Aug 9 15:57:00 2010 +0200
Fix incorrect and optimize handling of scheme conditions
ChangeLog | 3 ++
src/core/na-icontext.c | 83 ++++++++++++++++++++++++++++++------------------
2 files changed, 55 insertions(+), 31 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5064e9b..570af08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2010-08-09 Pierre Wieser <pwieser trychlos org>
+ * src/core/na-icontext.c (is_candidate_for_schemes):
+ Fix incorrect and optimize handling of scheme conditions.
+
* src/core/na-icontext.c (is_candidate_for_basenames):
Fix incorrect handling of basename conditions.
diff --git a/src/core/na-icontext.c b/src/core/na-icontext.c
index f30c12b..e97f9e8 100644
--- a/src/core/na-icontext.c
+++ b/src/core/na-icontext.c
@@ -75,9 +75,7 @@ static void split_mimetype( const gchar *mimetype, gchar **group, gchar **su
static gboolean is_candidate_for_basenames( const NAIContext *object, guint target, GList *files );
static gboolean is_candidate_for_selection_count( const NAIContext *object, guint target, GList *files );
static gboolean is_candidate_for_schemes( const NAIContext *object, guint target, GList *files );
-#if 0
-static gboolean validate_schemes( GSList *object_schemes, NASelectedInfo *iter );
-#endif
+static gboolean is_compatible_scheme( const gchar *pattern, const gchar *scheme );
static gboolean is_candidate_for_folders( const NAIContext *object, guint target, GList *files );
static gboolean is_candidate_for_capabilities( const NAIContext *object, guint target, GList *files );
@@ -670,7 +668,9 @@ is_candidate_for_mimetypes( const NAIContext *object, guint target, GList *files
}
}
- ok = match;
+ if( ok ){
+ ok = match;
+ }
g_free( fsubgroup );
g_free( fgroup );
@@ -770,7 +770,9 @@ is_candidate_for_basenames( const NAIContext *object, guint target, GList *files
g_free( pattern );
}
- ok = match;
+ if( ok ){
+ ok = match;
+ }
g_free( bname_utf8 );
g_free( bname );
@@ -827,45 +829,48 @@ is_candidate_for_selection_count( const NAIContext *object, guint target, GList
return( ok );
}
+/*
+ * it is likely that all selected items have the same scheme, because they
+ * are all in the same location and the scheme mainly depends on location
+ * so we have here a great possible optimization by only testing the
+ * first selected item.
+ */
static gboolean
is_candidate_for_schemes( const NAIContext *object, guint target, GList *files )
{
static const gchar *thisfn = "na_icontext_is_candidate_for_schemes";
gboolean ok = TRUE;
GSList *schemes = na_object_get_schemes( object );
- GSList *is;
- gboolean positive;
- guint count_positive = 0;
- guint count_compatible = 0;
- gchar *pattern, *scheme;
- GList *it;
- gboolean match;
if( schemes ){
- for( is = schemes ; is && ok ; is = is->next ){
- pattern = ( gchar * ) is->data;
- positive = is_positive_assertion( pattern );
- if( positive ){
- count_positive += 1;
- } else {
- pattern += 1;
- }
+ if( strcmp( schemes->data, "*" ) != 0 || g_slist_length( schemes ) > 1 ){
+ GSList *is;
+ gchar *scheme, *pattern;
+ gboolean match, positive;
+
+ scheme = na_selected_info_get_uri_scheme( NA_SELECTED_INFO( files->data ));
+ match = FALSE;
- if( strcmp( pattern, "*" ) == 0 ){
- count_compatible_patterns( positive, TRUE, &count_compatible, &ok );
+ for( is = schemes ; is && ok ; is = is->next ){
+ pattern = ( gchar * ) is->data;
+ positive = is_positive_assertion( pattern );
- } else {
- for( it = files ; it && ok ; it = it->next ){
- scheme = na_selected_info_get_uri_scheme( NA_SELECTED_INFO( it->data ));
- match = ( strcmp( pattern, scheme ) == 0 );
- g_free( scheme );
- count_compatible_patterns( positive, match, &count_compatible, &ok );
+ if( !positive || !match ){
+ if( is_compatible_scheme( positive ? pattern : pattern+1, scheme )){
+ if( positive ){
+ match = TRUE;
+ } else {
+ ok = FALSE;
+ }
+ }
}
}
- }
- if( count_positive > 0 && count_compatible == 0 ){
- ok = FALSE;
+ if( ok ){
+ ok = match;
+ }
+
+ g_free( scheme );
}
if( !ok ){
@@ -881,6 +886,22 @@ is_candidate_for_schemes( const NAIContext *object, guint target, GList *files )
}
static gboolean
+is_compatible_scheme( const gchar *pattern, const gchar *scheme )
+{
+ gboolean compatible;
+
+ compatible = FALSE;
+
+ if( strcmp( pattern, "*" )){
+ compatible = TRUE;
+ } else {
+ compatible = ( strcmp( pattern, scheme ) == 0 );
+ }
+
+ return( compatible );
+}
+
+static gboolean
is_candidate_for_folders( const NAIContext *object, guint target, GList *files )
{
static const gchar *thisfn = "na_icontext_is_candidate_for_folders";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]