[nautilus-actions] Enhance import assistant



commit fbeccee7660c664753430cddea6eaf4edee22509
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sat Oct 17 22:57:52 2009 +0200

    Enhance import assistant

 ChangeLog                        |   10 +++++++++
 src/common/na-utils.c            |   27 +++++++++++++++++++++++++
 src/common/na-utils.h            |    7 +++++-
 src/nact/nact-assistant-import.c |   41 ++++++++++++++++++++++++-------------
 src/nact/nact-xml-reader.c       |   26 ++++++++++++------------
 5 files changed, 82 insertions(+), 29 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7e3fa8e..c7bb12a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-10-17 Pierre Wieser <pwieser trychlos org>
 
+	* src/common/na-utils.c:
+	* src/common/na-utils.h (na_utils_prefix_strings): New function.
+
+	* src/nact/nact-assistant-import.c (prepare_importdone):
+	Enhance the summary page.
+
+	* src/nact/nact-xml-reader.c:
+	Actually relabel action if required.
+	Return all messages.
+
 	* src/nact/nact-assistant-export.c (assist_prepare_exportdone):
 	* src/nact/nact-assistant-import.c (prepare_importdone):
 	At end, quit the assistant on Cancel without warning.
diff --git a/src/common/na-utils.c b/src/common/na-utils.c
index cee94de..d0852de 100644
--- a/src/common/na-utils.c
+++ b/src/common/na-utils.c
@@ -308,6 +308,33 @@ na_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list
 }
 
 /**
+ * na_utils_prefix_strings:
+ * @prefix: the prefix to be prepended.
+ * @str: a multiline string.
+ *
+ * Appends a prefix to each line of the string.
+ *
+ * Returns: a new string which should be g_free() by the caller.
+ */
+gchar *
+na_utils_prefix_strings( const gchar *prefix, const gchar *str )
+{
+	GSList *list, *il;
+	GString *result;
+
+	list = text_to_string_list( str, "\n", NULL );
+	result = g_string_new( "" );
+
+	for( il = list ; il ; il = il->next ){
+		g_string_append_printf( result, "%s%s", prefix, ( gchar * ) il->data );
+	}
+
+	na_utils_free_string_list( list );
+
+	return( g_string_free( result, FALSE ));
+}
+
+/**
  * na_utils_remove_last_level_from_path:
  * @path: a full path.
  *
diff --git a/src/common/na-utils.h b/src/common/na-utils.h
index 2975915..6e3402a 100644
--- a/src/common/na-utils.h
+++ b/src/common/na-utils.h
@@ -53,7 +53,12 @@ gboolean na_utils_schema_to_boolean( const gchar *value, gboolean default_value
 /*
  * Some functions for GString manipulations.
  */
-gchar *  na_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list );
+gchar   *na_utils_gstring_joinv( const gchar *start, const gchar *separator, gchar **list );
+
+/*
+ * String manipulations
+ */
+gchar   *na_utils_prefix_strings( const gchar *prefix, const gchar *str );
 
 /*
  * path manipulations
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index 70ee11c..8b73f82 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -586,7 +586,7 @@ static gchar *
 add_import_mode( NactAssistantImport *window, const gchar *text )
 {
 	gint mode;
-	gchar *label1, *label2;
+	gchar *label1, *label2, *label3;
 	gchar *result;
 
 	mode = get_import_mode( window );
@@ -620,8 +620,11 @@ add_import_mode( NactAssistantImport *window, const gchar *text )
 	}
 
 	if( label1 ){
-		result = g_strdup_printf( "%s\n\n<b>%s</b>\n\n%s", text, label1, label2 );
+		label3 = na_utils_prefix_strings( "\t", label2 );
 		g_free( label2 );
+
+		result = g_strdup_printf( "%s\n\n<b>%s</b>\n\n%s", text, label1, label3 );
+		g_free( label3 );
 		g_free( label1 );
 	}
 
@@ -654,6 +657,9 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 
 	g_object_get( G_OBJECT( wnd ), BASE_WINDOW_PROP_PARENT, &mainwnd, NULL );
 
+	/* first import actions
+	 * getting results in the same order than uris
+	 */
 	for( is = uris ; is ; is = is->next ){
 
 		msg = NULL;
@@ -666,16 +672,24 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 		na_utils_free_string_list( msg );
 
 		window->private->results = g_slist_prepend( window->private->results, str );
+	}
+	na_utils_free_string_list( uris );
+	window->private->results = g_slist_reverse( window->private->results );
 
-		if( action ){
-			na_object_check_status( action );
-			items = g_list_prepend( NULL, action );
-			nact_iactions_list_insert_items( NACT_IACTIONS_LIST( mainwnd ), items, NULL );
-			na_object_free_items_list( items );
+	/* then insert them in the list
+	 * assuring that actions will be inserted in the same order as uris
+	 */
+	items = NULL;
+	for( is = window->private->results ; is ; is = is->next ){
+		str = ( ImportUriStruct * ) is->data;
+		if( str->action ){
+			na_object_check_status( str->action );
+			items = g_list_prepend( items, str->action );
 		}
 	}
-
-	na_utils_free_string_list( uris );
+	items = g_list_reverse( items );
+	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( mainwnd ), items, NULL );
+	na_object_free_items_list( items );
 }
 
 static void
@@ -698,14 +712,13 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 	pivot = nact_application_get_pivot( application );
 
 	/* i18n: result of the import assistant */
-	text = g_strdup( _( "Selected files have been imported:" ));
+	text = g_strdup( _( "Selected files have been proceeded :" ));
 
 	tmp = g_strdup_printf( "<b>%s</b>\n\n", text );
 	g_free( text );
 	text = tmp;
 
 	for( is = window->private->results ; is ; is = is->next ){
-
 		str = ( ImportUriStruct * ) is->data;
 
 		file = g_file_new_for_uri( str->uri );
@@ -728,10 +741,8 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 			window->private->actions = g_slist_prepend( window->private->actions, str->action );
 
 		} else {
-			/* i18n: just indicate that the import of this file was unsuccessfull */
-			text2 = g_strdup( _( "NOT OK" ));
-			tmp = g_strdup_printf( "%s\t\t %s\n", text, text2 );
-			g_free( text2 );
+			/* i18n: indicate that the file was not iported */
+			tmp = g_strdup_printf( "%s\t\t%s\n", text, _( "Not imported" ));
 		}
 
 		g_free( text );
diff --git a/src/nact/nact-xml-reader.c b/src/nact/nact-xml-reader.c
index 13e6985..1938e80 100644
--- a/src/nact/nact-xml-reader.c
+++ b/src/nact/nact-xml-reader.c
@@ -70,7 +70,6 @@ struct NactXMLReaderPrivate {
 	NAObjectAction  *action;			/* the action that we will return, or NULL */
 	GSList          *messages;
 	gboolean         uuid_set;			/* set at first uuid, then checked against */
-	gboolean         relabel;			/* renumbered action: set a 'renumbered' label */
 
 	/* following values are reset at each schema/entry node
 	 */
@@ -235,7 +234,6 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self->private->action = NULL;
 	self->private->messages = NULL;
 	self->private->uuid_set = FALSE;
-	self->private->relabel = FALSE;
 	self->private->profile = NULL;
 	self->private->locale_waited = FALSE;
 	self->private->entry = NULL;
@@ -353,7 +351,6 @@ nact_xml_reader_import( BaseWindow *window, const gchar *uri, gint import_mode,
 	}
 
 	xmlCleanupParser();
-	*msg = na_utils_duplicate_string_list( reader->private->messages );
 
 	if( reader->private->action ){
 		g_assert( NA_IS_OBJECT_ACTION( reader->private->action ));
@@ -362,6 +359,7 @@ nact_xml_reader_import( BaseWindow *window, const gchar *uri, gint import_mode,
 		}
 	}
 
+	*msg = na_utils_duplicate_string_list( reader->private->messages );
 	g_object_unref( reader );
 
 	return( action );
@@ -447,10 +445,6 @@ gconf_reader_parse_schemalist( NactXMLReader *reader, xmlNode *schema )
 		g_free( label );
 	}
 
-	if( ok && reader->private->relabel ){
-		relabel( reader );
-	}
-
 	if( !ok ){
 		g_object_unref( reader->private->action );
 		reader->private->action = NULL;
@@ -902,10 +896,6 @@ gconf_reader_parse_entrylist( NactXMLReader *reader, xmlNode *entrylist )
 		}
 		g_free( label );
 
-		if( ok && reader->private->relabel ){
-			relabel( reader );
-		}
-
 	} else {
 		g_object_unref( reader->private->action );
 		reader->private->action = NULL;
@@ -1288,9 +1278,9 @@ manage_import_mode( NactXMLReader *reader )
 
 	uuid = na_object_get_id( reader->private->action );
 	exists = nact_main_window_get_item( main_window, uuid );
-	g_free( uuid );
 
 	if( !exists ){
+		g_free( uuid );
 		return( TRUE );
 	}
 
@@ -1303,20 +1293,30 @@ manage_import_mode( NactXMLReader *reader )
 	switch( mode ){
 		case IPREFS_IMPORT_RENUMBER:
 			na_object_set_new_id( reader->private->action, NULL );
-			reader->private->relabel = TRUE;
+			relabel( reader );
+			if( reader->private->import_mode == IPREFS_IMPORT_ASK ){
+				add_message( reader, "%s", _( "Action was renumbered due to user request." ));
+			}
 			ret = TRUE;
 			break;
 
 		case IPREFS_IMPORT_OVERRIDE:
+			if( reader->private->import_mode == IPREFS_IMPORT_ASK ){
+				add_message( reader, "%s", _( "Existing action was overriden due to user request." ));
+			}
 			ret = TRUE;
 			break;
 
 		case IPREFS_IMPORT_NO_IMPORT:
 		default:
 			add_message( reader, ERR_UUID_ALREADY_EXISTS, uuid );
+			if( reader->private->import_mode == IPREFS_IMPORT_ASK ){
+				add_message( reader, "%s", _( "Import was canceled due to user request." ));
+			}
 			ret = FALSE;
 	}
 
+	g_free( uuid );
 	return( ret );
 }
 



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