[nautilus-actions] Convert 'all/allfiles' mimetype to 'all/all' + 'file' scheme



commit 90e067e4841c4303c16594c9c489b7d7064c2737
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Dec 30 15:27:41 2010 +0100

    Convert 'all/allfiles' mimetype to 'all/all' + 'file' scheme

 ChangeLog              |    4 +++
 src/core/na-icontext.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6fb7380..d95fc2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,11 @@
 2010-12-30 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-icontext.c (na_icontext_read_done):
+	Convert 'all/allfiles' mimetype to 'all/all' + 'file' scheme.
+
 	* src/core/na-object-id.c (na_object_id_prepare_for_paste):
 	Set data provider to NULL when duplicating a desktop file item.
+	This fixed the 'unable to save a copied item' bug.
 
 2010-12-29 Pierre Wieser <pwieser trychlos org>
 
diff --git a/src/core/na-icontext.c b/src/core/na-icontext.c
index 31f1ec3..e09b0ce 100644
--- a/src/core/na-icontext.c
+++ b/src/core/na-icontext.c
@@ -61,6 +61,8 @@ static GType    register_type( void );
 static void     interface_base_init( NAIContextInterface *klass );
 static void     interface_base_finalize( NAIContextInterface *klass );
 
+static void     convert_allfiles_mimetype( NAIContext *context );
+
 static gboolean v_is_candidate( NAIContext *object, guint target, GList *selection );
 
 static gboolean is_candidate_for_target( const NAIContext *object, guint target, GList *files );
@@ -284,6 +286,8 @@ na_icontext_is_all_mimetypes( const NAIContext *context )
 		break;
 	}
 
+	na_core_utils_slist_free( mimetypes );
+
 	return( is_all );
 }
 
@@ -293,11 +297,27 @@ na_icontext_is_all_mimetypes( const NAIContext *context )
  *
  * Prepares the specified #NAIContext just after it has been readen.
  *
+ * <unorderedlist>
+ *   <listitem>
+ *     <para>
+ *       This converts a 'all/allfiles' mimetype to 'all/all' + 'file' scheme.
+ *     </para>
+ *   </listitem>
+ *   <listitem>
+ *     <para>
+ *       This setup an internal flag when mimetypes is like 'all/all'
+ *       in order to optimize computation time;
+ *     </para>
+ *   </listitem>
+ * </unorderedlist>
+ *
  * Since: 2.30
  */
 void
 na_icontext_read_done( NAIContext *context )
 {
+	convert_allfiles_mimetype( context );
+
 	na_object_set_all_mimetypes( context, na_icontext_is_all_mimetypes( context ));
 }
 
@@ -394,6 +414,55 @@ na_icontext_replace_folder( NAIContext *context, const gchar *old, const gchar *
 	na_core_utils_slist_free( folders );
 }
 
+/*
+ * Convert 'all/allfiles' mimetype to 'all/all' + 'file' scheme.
+ * This takes into account
+ * - all/allfiles, allfiles, allfiles/ * and allfiles/all
+ * - negated assertions.
+ */
+static void
+convert_allfiles_mimetype( NAIContext *context )
+{
+	GSList *mimetypes, *im;
+	GSList *schemes;
+	gchar *tmp;
+	gboolean modified;
+
+	modified = FALSE;
+	mimetypes = na_object_get_mimetypes( context );
+	schemes = na_object_get_schemes( context );
+
+	for( im = mimetypes ; im ; im = im->next ){
+		if( !im->data || !strlen( im->data )){
+			continue;
+		}
+
+		gchar *imtype = ( gchar * ) im->data;
+		gboolean positive = is_positive_assertion( imtype );
+		guint i = ( positive ? 0 : 1 );
+
+		if( !strcmp( imtype+i, "allfiles" ) ||
+			!strcmp( imtype+i, "allfiles/*" ) ||
+			!strcmp( imtype+i, "allfiles/all" ) ||
+			!strcmp( imtype+i, "all/allfiles" )){
+
+				g_free( im->data );
+				im->data = g_strdup( "all/all" );
+				tmp = g_strdup_printf( "%sfile", positive ? "" : "!" );
+				schemes = g_slist_prepend( schemes, tmp );
+				modified = TRUE;
+		}
+	}
+
+	if( modified ){
+		na_object_set_mimetypes( context, mimetypes );
+		na_object_set_schemes( context, schemes );
+	}
+
+	na_core_utils_slist_free( mimetypes );
+	na_core_utils_slist_free( schemes );
+}
+
 static gboolean
 v_is_candidate( NAIContext *context, guint target, GList *selection )
 {



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