[nautilus-actions] Various code improvements



commit 97138a7329a813a00b6b99b4d12e4398dc86bddd
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Mar 4 07:18:41 2012 +0100

    Various code improvements

 ChangeLog                          |   10 ++++++++++
 src/core/na-icontext.c             |   28 ++++++++--------------------
 src/core/na-selected-info.c        |   33 +++++++++++++++++++++++++++------
 src/plugin-menu/nautilus-actions.c |   36 +++++++++++++++++++++++++++---------
 4 files changed, 72 insertions(+), 35 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2724649..728e744 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-03-04 Pierre Wieser <pwieser trychlos org>
+
+	* src/core/na-icontext.c (is_candidate_for_folders): Improve code
+	readability.
+
+	* src/core/na-selected-info.c (dump): Dump file type.
+
+	* src/plugin-menu/nautilus-actions.c (build_nautilus_menu_rec): Improve
+	debug messages.
+
 2012-03-01 Pierre Wieser <pwieser trychlos org>
 
 	* tools/release-tarball.sh:
diff --git a/src/core/na-icontext.c b/src/core/na-icontext.c
index 8df9748..56a02f5 100644
--- a/src/core/na-icontext.c
+++ b/src/core/na-icontext.c
@@ -1038,8 +1038,8 @@ is_compatible_scheme( const gchar *pattern, const gchar *scheme )
 }
 
 /*
- * assumuing here the same sort of optimization than for schemes
- * i.e. we assume that all selected items are must probably located
+ * assuming here the same sort of optimization than for schemes
+ * i.e. we assume that all selected items are most probably located
  * in the same dirname
  * so we take care of only checking _distinct_ dirnames against folder
  * conditions
@@ -1060,7 +1060,7 @@ is_candidate_for_folders( const NAIContext *object, guint target, GList *files )
 				gchar *dirname = na_selected_info_get_dirname( NA_SELECTED_INFO( it->data ));
 
 				if( na_core_utils_slist_count( distincts, dirname ) == 0 ){
-					g_debug( "%s: distinct dirname=%s", thisfn, dirname );
+					g_debug( "%s: examining new distinct selected dirname=%s", thisfn, dirname );
 
 					GSList *id;
 					gchar *dirname_utf8, *pattern_utf8;
@@ -1070,34 +1070,22 @@ is_candidate_for_folders( const NAIContext *object, guint target, GList *files )
 
 					distincts = g_slist_prepend( distincts, g_strdup( dirname ));
 					dirname_utf8 = g_filename_to_utf8( dirname, -1, NULL, NULL, NULL );
-					match = FALSE;
 
 					for( id = folders ; id && ok ; id = id->next ){
 						pattern = ( const gchar * ) id->data;
+						g_debug( "%s: examining new condition pattern=%s", thisfn, pattern );
 						positive = is_positive_assertion( pattern );
 						pattern_utf8 = g_filename_to_utf8( positive ? pattern : pattern+1, -1, NULL, NULL, NULL );
 						has_pattern = ( g_strstr_len( pattern_utf8, -1, "*" ) != NULL );
 
-						if( !positive || !match ){
-							if(( has_pattern && g_pattern_match_simple( pattern_utf8, dirname_utf8 )) || g_str_has_prefix( dirname_utf8, pattern_utf8 )){
-								g_debug( "%s: condition=%s, positive=%s: matched",
-										thisfn, pattern, positive ? "True":"False" );
-								if( positive ){
-									match = TRUE;
-								} else {
-									ok = FALSE;
-								}
-							/*} else {
-								g_debug( "%s: condition=%s, positive=%s: not matched",
-										thisfn, pattern_utf8, positive ? "True":"False" );*/
-							}
-						}
+						match = ( has_pattern && g_pattern_match_simple( pattern_utf8, dirname_utf8 )) ||
+								g_str_has_prefix( dirname_utf8, pattern_utf8 );
+
+						ok &= ( match && positive ) || ( !match && !positive );
 
 						g_free( pattern_utf8 );
 					}
 
-					ok &= match;
-
 					g_free( dirname_utf8 );
 				}
 
diff --git a/src/core/na-selected-info.c b/src/core/na-selected-info.c
index 3faf0be..f8e1401 100644
--- a/src/core/na-selected-info.c
+++ b/src/core/na-selected-info.c
@@ -74,6 +74,7 @@ static void            instance_dispose( GObject *object );
 static void            instance_finalize( GObject *object );
 
 static void            dump( const NASelectedInfo *nsi );
+static const char     *dump_file_type( GFileType type );
 static NASelectedInfo *new_from_nautilus_file_info( NautilusFileInfo *item );
 static NASelectedInfo *new_from_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg );
 static void            query_file_attributes( NASelectedInfo *info, GFile *location, gchar **errmsg );
@@ -703,11 +704,34 @@ dump( const NASelectedInfo *nsi )
 	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: attributes_are_set=%s", thisfn, nsi->private->attributes_are_set ? "True":"False" );
+	g_debug( "%s:          file_type=%s", thisfn, dump_file_type( nsi->private->file_type ));
 	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 );
-	g_debug( "%s: attributes_are_set=%s", thisfn, nsi->private->attributes_are_set ? "True":"False" );
+}
+
+static const char *
+dump_file_type( GFileType type )
+{
+	switch( type ){
+		case G_FILE_TYPE_REGULAR:
+			return( "regular" );
+		case G_FILE_TYPE_DIRECTORY:
+			return( "directory" );
+		case G_FILE_TYPE_SYMBOLIC_LINK:
+			return( "symbolic link" );
+		case G_FILE_TYPE_SPECIAL:
+			return( "special (socket, fifo, blockdev, chardev)" );
+		case G_FILE_TYPE_SHORTCUT:
+			return( "shortcut" );
+		case G_FILE_TYPE_MOUNTABLE:
+			return( "mountable" );
+		default:
+			break;
+	}
+	return( "unknown" );
 }
 
 static NASelectedInfo *
@@ -715,7 +739,6 @@ new_from_nautilus_file_info( NautilusFileInfo *item )
 {
 	gchar *uri = nautilus_file_info_get_uri( item );
 	gchar *mimetype = nautilus_file_info_get_mime_type( item );
-	g_debug( "new_from_nautilus_file_info: uri=%s, mimetype=%s", uri, mimetype );
 	NASelectedInfo *info = new_from_uri( uri, mimetype, NULL );
 	g_free( mimetype );
 	g_free( uri );
@@ -772,7 +795,6 @@ new_from_nautilus_file_info( NautilusFileInfo *item )
  * be properly represented within a URI.
  *
  * pwi 2011-01-04:
- *
  * It results from the above excerpt that:
  * - as double quotes are not valid character in URI, they have to be
  *   escaped as %22, and so Nautilus does
@@ -806,7 +828,7 @@ new_from_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg )
 	vfs = g_new0( NAGnomeVFSURI, 1 );
 	na_gnome_vfs_uri_parse( vfs, uri );
 	if( !info->private->filename ){
-		g_debug( "new_from_uri: uri='%s', filename=NULL, setting it to '%s'", uri, vfs->path );
+		g_debug( "na_selected_info_new_from_uri: uri='%s', filename=NULL, setting it to '%s'", uri, vfs->path );
 		info->private->filename = g_strdup( vfs->path );
 	}
 
@@ -846,8 +868,7 @@ query_file_attributes( NASelectedInfo *nsi, GFile *location, gchar **errmsg )
 		if( errmsg ){
 			*errmsg = g_strdup_printf( _( "Error when querying informations for %s URI: %s" ), nsi->private->uri, error->message );
 		} else {
-			g_warning( "%s: URI='%s'", thisfn, nsi->private->uri );
-			g_warning( "%s: g_file_query_info: %s", thisfn, error->message );
+			g_warning( "%s: uri=%s, g_file_query_info: %s", thisfn, nsi->private->uri, error->message );
 		}
 		g_error_free( error );
 		return;
diff --git a/src/plugin-menu/nautilus-actions.c b/src/plugin-menu/nautilus-actions.c
index 953e521..809d7d5 100644
--- a/src/plugin-menu/nautilus-actions.c
+++ b/src/plugin-menu/nautilus-actions.c
@@ -395,15 +395,6 @@ menu_provider_get_file_items( NautilusMenuProvider *provider, GtkWidget *window,
 			return(( GList * ) NULL );
 		}
 
-#ifdef NA_MAINTAINER_MODE
-		GList *im;
-		for( im = files ; im ; im = im->next ){
-			gchar *uri = nautilus_file_info_get_uri( NAUTILUS_FILE_INFO( im->data ));
-			g_debug( "%s: uri=%s", thisfn, uri );
-			g_free( uri );
-		}
-#endif
-
 		selected = na_selected_info_get_list_from_list(( GList * ) files );
 
 		if( selected ){
@@ -413,6 +404,17 @@ menu_provider_get_file_items( NautilusMenuProvider *provider, GtkWidget *window,
 					( void * ) window,
 					( void * ) files, g_list_length( files ));
 
+#ifdef NA_MAINTAINER_MODE
+			GList *im;
+			for( im = files ; im ; im = im->next ){
+				gchar *uri = nautilus_file_info_get_uri( NAUTILUS_FILE_INFO( im->data ));
+				gchar *mimetype = nautilus_file_info_get_mime_type( NAUTILUS_FILE_INFO( im->data ));
+				g_debug( "%s: uri='%s', mimetype='%s'", thisfn, uri, mimetype );
+				g_free( mimetype );
+				g_free( uri );
+			}
+#endif
+
 			nautilus_menus_list = build_nautilus_menu(
 					NAUTILUS_ACTIONS( provider ),
 					ITEM_TARGET_SELECTION,
@@ -533,14 +535,19 @@ build_nautilus_menu_rec( GList *tree, guint target, GList *selection, NATokens *
 	GList *submenu;
 	NAObjectProfile *profile;
 	NautilusMenuItem *menu_item;
+	gchar *label;
 
 	nautilus_menu = NULL;
 
 	for( it = tree ; it ; it = it->next ){
 
 		g_return_val_if_fail( NA_IS_OBJECT_ITEM( it->data ), NULL );
+		label = na_object_get_label( it->data );
+		g_debug( "%s: examining %s", thisfn, label );
 
 		if( !na_icontext_is_candidate( NA_ICONTEXT( it->data ), target, selection )){
+			g_debug( "%s: is not candidate (NAIContext): %s", thisfn, label );
+			g_free( label );
 			continue;
 		}
 
@@ -550,6 +557,9 @@ build_nautilus_menu_rec( GList *tree, guint target, GList *selection, NATokens *
 		 * dynamically empty - thus the NAObjectItem invalid :(
 		 */
 		if( !na_object_is_valid( item )){
+			g_debug( "%s: item %s becomes invalid after expand_tokens_item", thisfn, label );
+			g_object_unref( item );
+			g_free( label );
 			continue;
 		}
 
@@ -574,6 +584,8 @@ build_nautilus_menu_rec( GList *tree, guint target, GList *selection, NATokens *
 					nautilus_menu = g_list_append( nautilus_menu, menu_item );
 				}
 			}
+			g_object_unref( item );
+			g_free( label );
 			continue;
 		}
 
@@ -585,7 +597,13 @@ build_nautilus_menu_rec( GList *tree, guint target, GList *selection, NATokens *
 		if( profile ){
 			menu_item = create_item_from_profile( profile, target, selection, tokens );
 			nautilus_menu = g_list_append( nautilus_menu, menu_item );
+
+		} else {
+			g_debug( "%s: %s does not have any valid candidate profile", thisfn, label );
 		}
+
+		g_object_unref( item );
+		g_free( label );
 	}
 
 	return( nautilus_menu );



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