[nautilus-actions] Enhance export assistant



commit 2ee5923cbf83f3228bc379fdd1b6a569ab918813
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sat Oct 17 23:48:18 2009 +0200

    Enhance export assistant

 ChangeLog                            |    7 ++
 src/common/na-xml-writer.c           |    2 +-
 src/common/na-xml-writer.h           |    2 +-
 src/nact/nact-assistant-export.c     |  187 +++++++++++++++-------------------
 src/nact/nact-assistant-import.c     |    1 -
 src/utils/nautilus-actions-new.c     |   22 +++-
 src/utils/nautilus-actions-schemas.c |   10 ++-
 7 files changed, 114 insertions(+), 117 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c7bb12a..8df0673 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-10-17 Pierre Wieser <pwieser trychlos org>
 
+	* src/common/na-xml-writer.c:
+	* src/common/na-xml-writer.h (na_xml_writer_export):
+	Now returns messages as a GSList.
+
+	* src/nact/nact-assistant-export.c (assist_prepare_exportdone):
+	Enhance sumary page.
+
 	* src/common/na-utils.c:
 	* src/common/na-utils.h (na_utils_prefix_strings): New function.
 
diff --git a/src/common/na-xml-writer.c b/src/common/na-xml-writer.c
index 271b790..8b38c14 100644
--- a/src/common/na-xml-writer.c
+++ b/src/common/na-xml-writer.c
@@ -295,7 +295,7 @@ xml_writer_new( const gchar *uuid )
  * Returns: the written filename, or NULL if written to stdout.
  */
 gchar *
-na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint format, gchar **msg )
+na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint format, GSList **msg )
 {
 	static const gchar *thisfn = "na_xml_writer_export";
 	gchar *filename = NULL;
diff --git a/src/common/na-xml-writer.h b/src/common/na-xml-writer.h
index 2a47634..dc4b680 100644
--- a/src/common/na-xml-writer.h
+++ b/src/common/na-xml-writer.h
@@ -71,7 +71,7 @@ typedef struct {
 
 GType  na_xml_writer_get_type( void );
 
-gchar *na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint format, gchar **msg );
+gchar *na_xml_writer_export( const NAObjectAction *action, const gchar *folder, gint format, GSList **msg );
 gchar *na_xml_writer_get_output_fname( const NAObjectAction *action, const gchar *folder, gint format );
 gchar *na_xml_writer_get_xml_buffer( const NAObjectAction *action, gint format );
 void   na_xml_writer_output_xml( const gchar *xml, const gchar *filename );
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 930d6a5..5a00f3e 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -81,13 +81,19 @@ struct NactAssistantExportClassPrivate {
 /* private instance data
  */
 struct NactAssistantExportPrivate {
-	gboolean        dispose_has_run;
-	gchar          *uri;
-	GSList         *fnames;
-	gint            errors;
-	gchar          *reason;
+	gboolean  dispose_has_run;
+	gchar    *uri;
+	GList    *results;
 };
 
+typedef struct {
+	NAObjectAction *action;
+	GSList         *msg;
+	gchar          *fname;
+	gint            format;
+}
+	ExportStruct;
+
 #define IPREFS_EXPORT_ACTIONS_FOLDER_URI		"export-folder-uri"
 
 static BaseAssistantClass *st_parent_class = NULL;
@@ -139,10 +145,7 @@ static void            assistant_prepare( BaseAssistant *window, GtkAssistant *a
 static void            assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page );
 static void            assistant_apply( BaseAssistant *window, GtkAssistant *assistant );
 static void            assist_prepare_exportdone( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page );
-
-#ifdef NA_MAINTAINER_MODE
-static void            dump( NactAssistantExport *window );
-#endif
+static void            free_results( GList *list );
 
 GType
 nact_assistant_export_get_type( void )
@@ -241,8 +244,6 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self->private = g_new0( NactAssistantExportPrivate, 1 );
 
 	self->private->dispose_has_run = FALSE;
-	self->private->fnames = NULL;
-	self->private->errors = 0;
 
 	base_window_signal_connect(
 			BASE_WINDOW( instance ),
@@ -288,9 +289,7 @@ instance_finalize( GObject *window )
 	g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window ));
 	self = NACT_ASSISTANT_EXPORT( window );
 
-	g_free( self->private->uri );
-	na_utils_free_string_list( self->private->fnames );
-	g_free( self->private->reason );
+	free_results( self->private->results );
 
 	g_free( self->private );
 
@@ -693,7 +692,7 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
 {
 	static const gchar *thisfn = "nact_assistant_export_prepare_confirm";
 	gchar *text, *tmp, *text2;
-	gchar *label1, *label2;
+	gchar *label1, *label2, *label3;
 	GList *actions, *ia;
 	NactApplication *application;
 	NAPivot *pivot;
@@ -705,10 +704,6 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
 	g_debug( "%s: window=%p, assistant=%p, page=%p",
 			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
 
-#ifdef NA_MAINTAINER_MODE
-	dump( window );
-#endif
-
 	/* i18n: this is the title of the confirm page of the export assistant */
 	text = g_strdup( _( "About to export selected actions:" ));
 	tmp = g_strdup_printf( "<b>%s</b>\n\n", text );
@@ -764,7 +759,9 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
 	}
 	na_iprefs_set_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_FORMAT, format );
 
-	tmp = g_strdup_printf( "%s\n\n<b>%s</b>\n\n%s", text, label1, label2 );
+	label3 = na_utils_prefix_strings( "\t", label2 );
+	tmp = g_strdup_printf( "%s\n\n<b>%s</b>\n\n%s", text, label1, label3 );
+	g_free( label3 );
 	g_free( label2 );
 	g_free( label1 );
 	g_free( text );
@@ -789,11 +786,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 	NactApplication *application;
 	NAPivot *pivot;
 	GList *actions, *ia;
-	gchar *msg = NULL;
-	gchar *reason = NULL;
-	gchar *tmp, *fname;
-	NAObjectAction *action;
-	gint format;
+	ExportStruct *str;
 
 	g_debug( "%s: window=%p, assistant=%p", thisfn, ( void * ) wnd, ( void * ) assistant );
 	g_assert( NACT_IS_ASSISTANT_EXPORT( wnd ));
@@ -807,103 +800,86 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 	g_assert( window->private->uri && strlen( window->private->uri ));
 
 	for( ia = actions ; ia ; ia = ia->next ){
-		action = NA_OBJECT_ACTION( ia->data );
-		fname = NULL;
-
-		format = na_iprefs_get_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_FORMAT );
-		if( format == IPREFS_EXPORT_FORMAT_ASK ){
-			format = nact_assistant_export_ask_user( BASE_WINDOW( wnd ), action );
-			if( format == IPREFS_EXPORT_NO_EXPORT ){
-				msg = g_strdup( _( "Export canceled due to user action." ));
-			}
-		}
+		str = g_new0( ExportStruct, 1 );
+		window->private->results = g_list_append( window->private->results, str );
 
-		if( format != IPREFS_EXPORT_NO_EXPORT ){
-			fname = na_xml_writer_export( action, window->private->uri, format, &msg );
-		}
+		str->action = NA_OBJECT_ACTION( ia->data );
 
-		if( fname && strlen( fname )){
-			window->private->fnames = g_slist_prepend( window->private->fnames, fname );
-			g_debug( "%s: fname=%s", thisfn, fname );
-
-		} else {
-			window->private->errors += 1;
-			if( msg ){
-				if( reason ){
-					tmp = g_strdup_printf( "%s\n", reason );
-					g_free( reason );
-					reason = tmp;
-				}
-				tmp = g_strdup_printf( "%s%s", reason ? reason : "", msg );
-				g_free( reason );
-				reason = tmp;
-				g_free( msg );
+		str->format = na_iprefs_get_export_format( NA_IPREFS( pivot ), IPREFS_EXPORT_FORMAT );
+		if( str->format == IPREFS_EXPORT_FORMAT_ASK ){
+			str->format = nact_assistant_export_ask_user( BASE_WINDOW( wnd ), str->action );
+			if( str->format == IPREFS_EXPORT_NO_EXPORT ){
+				str->msg = g_slist_append( NULL, g_strdup( _( "Export canceled due to user action." )));
 			}
 		}
-	}
 
-	na_object_free_items_list( actions );
-
-	if( window->private->errors ){
-		if( !reason ){
-			reason = g_strdup( _( "You may not have writing permissions on selected folder." ));
+		if( str->format != IPREFS_EXPORT_NO_EXPORT ){
+			str->fname = na_xml_writer_export( str->action, window->private->uri, str->format, &str->msg );
 		}
-		window->private->reason = reason;
 	}
+
+	na_object_free_items_list( actions );
 }
 
 static void
 assist_prepare_exportdone( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page )
 {
 	static const gchar *thisfn = "nact_assistant_export_prepare_exportdone";
-	gchar *text, *tmp, *text2, *bname;
-	GSList *ifn;
-	GFile *file;
+	gchar *text, *tmp;
+	GList *ir;
+	ExportStruct *str;
+	gchar *label;
+	GSList *is;
+	gint errors;
 
 	g_debug( "%s: window=%p, assistant=%p, page=%p",
 			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
 
-#ifdef NA_MAINTAINER_MODE
-	dump( window );
-#endif
+	/* i18n: result of the export assistant */
+	text = g_strdup( _( "Selected actions have been proceeded :" ));
+	tmp = g_strdup_printf( "<b>%s</b>\n\n", text );
+	g_free( text );
+	text = tmp;
 
-	if( window->private->errors ){
-		/* i18n: error message displayed in the result page of the export assistant */
-		text = g_strdup( _( "One or more errors have been detected when exporting actions." ));
-		tmp = g_strdup_printf( _( "<b>%s</b>\n\n%s" ), text, window->private->reason );
-		g_free( text );
-		text = tmp;
+	errors = 0;
 
-	} else {
-		/* i18n: result of the export assistant */
-		text = g_strdup( _( "Selected actions have been successfully exported..." ));
-		tmp = g_strdup_printf( "<b>%s</b>\n\n", text );
-		g_free( text );
-		text = tmp;
+	for( ir = window->private->results ; ir ; ir = ir->next ){
+		str = ( ExportStruct * ) ir->data;
 
-		/* i18n: the target folder is displayed in its own line */
-		text2 = g_strdup( _( "... in folder:" ));
-		tmp = g_strdup_printf( _( "%s<b>%s</b>\n\n\t%s/\n\n" ), text, text2, window->private->uri );
-		g_free( text2 );
+		label = na_object_get_label( str->action );
+		tmp = g_strdup_printf( "%s\t%s\n", text, label );
 		g_free( text );
 		text = tmp;
+		g_free( label );
 
-		/* i18n: the export file for each actions is displayed in its own line */
-		text2 = g_strdup( _( "... as files:" ));
-		tmp = g_strdup_printf( _( "%s<b>%s</b>\n\n" ), text, text2 );
-		g_free( text2 );
-		g_free( text );
-		text = tmp;
+		if( str->fname ){
+			/* i18n: action as been successfully exported to <filename> */
+			tmp = g_strdup_printf( "%s\t\t%s\n\t\t%s\n", text, _( "Successfully exported as" ), str->fname );
+			g_free( text );
+			text = tmp;
 
-		for( ifn = window->private->fnames ; ifn ; ifn = ifn->next ){
-			file = g_file_new_for_uri(( gchar * ) ifn->data );
-			bname = g_file_get_basename( file );
-			tmp = g_strdup_printf( "%s\t%s\n", text, bname );
-			g_free( bname );
-			g_object_unref( file );
+		} else if( str->format != IPREFS_EXPORT_NO_EXPORT ){
+			errors += 1;
+		}
+
+		/* add messages */
+		for( is = str->msg ; is ; is = is->next ){
+			tmp = g_strdup_printf( "%s\t\t%s\n", text, ( gchar * ) is->data );
 			g_free( text );
 			text = tmp;
 		}
+
+		/* add a blank line between two actions */
+		tmp = g_strdup_printf( "%s\n", text );
+		g_free( text );
+		text = tmp;
+	}
+
+	if( errors ){
+		text = g_strdup_printf( "%s%s", text,
+				_( "You may not have write permissions on selected folder." ));
+		g_free( text );
+		text = tmp;
 	}
 
 	gtk_label_set_markup( GTK_LABEL( page ), text );
@@ -914,16 +890,17 @@ assist_prepare_exportdone( NactAssistantExport *window, GtkAssistant *assistant,
 	base_assistant_set_warn_on_esc( BASE_ASSISTANT( window ), FALSE );
 }
 
-#ifdef NA_MAINTAINER_MODE
 static void
-dump( NactAssistantExport *window )
+free_results( GList *list )
 {
-	static const gchar *thisfn = "nact_assistant_export_dump";
-	g_debug( "%s:          window=%p", thisfn, ( void * ) window );
-	g_debug( "%s:         private=%p", thisfn, ( void * ) window->private );
-	g_debug( "%s: dispose_has_run=%s", thisfn, window->private->dispose_has_run ? "True":"False" );
-	g_debug( "%s:             uri=%s", thisfn, window->private->uri );
-	g_debug( "%s:          errors=%d", thisfn, window->private->errors );
-	na_utils_dump_string_list( window->private->fnames );
+	GList *ir;
+	ExportStruct *str;
+
+	for( ir = list ; ir ; ir = ir->next ){
+		str = ( ExportStruct * ) ir->data;
+		g_free( str->fname );
+		na_utils_free_string_list( str->msg );
+	}
+
+	g_list_free( list );
 }
-#endif
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index 8b73f82..071c2f9 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -713,7 +713,6 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 
 	/* i18n: result of the import assistant */
 	text = g_strdup( _( "Selected files have been proceeded :" ));
-
 	tmp = g_strdup_printf( "<b>%s</b>\n\n", text );
 	g_free( text );
 	text = tmp;
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index 58d6121..ad8ee92 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -43,6 +43,7 @@
 #include <common/na-object-api.h>
 #include <common/na-xml-names.h>
 #include <common/na-xml-writer.h>
+#include <common/na-utils.h>
 
 static gchar     *label           = "";
 static gchar     *tooltip         = "";
@@ -87,7 +88,7 @@ static GOptionEntry output_entries[] = {
 
 static GOptionContext *init_options( void );
 static NAObjectAction *get_action_from_cmdline( void );
-static gboolean        write_to_gconf( NAObjectAction *action, gchar **msg );
+static gboolean        write_to_gconf( NAObjectAction *action, GSList **msg );
 static void            exit_with_usage( void );
 
 int
@@ -97,7 +98,8 @@ main( int argc, char** argv )
 	GOptionContext *context;
 	GError *error = NULL;
 	NAObjectAction *action;
-	gchar *msg = NULL;
+	GSList *msg = NULL;
+	GSList *im;
 	gchar *help;
 
 	g_type_init();
@@ -146,8 +148,10 @@ main( int argc, char** argv )
 	}
 
 	if( msg ){
-		g_printerr( "%s\n", msg );
-		g_free( msg );
+		for( im = msg ; im ; im = im->next ){
+			g_printerr( "%s\n", ( gchar * ) im->data );
+		}
+		na_utils_free_string_list( msg );
 		status = EXIT_FAILURE;
 	}
 
@@ -269,16 +273,22 @@ get_action_from_cmdline( void )
  * then writes the action
  */
 static gboolean
-write_to_gconf( NAObjectAction *action, gchar **msg )
+write_to_gconf( NAObjectAction *action, GSList **msg )
 {
 	NAGConfProvider *gconf;
 	guint ret;
+	gchar *str;
 
 	gconf = na_gconf_provider_new( NULL );
 
 	na_object_set_provider( action, NA_IIO_PROVIDER( gconf ));
 
-	ret = na_iio_provider_write_item( NULL, NA_OBJECT( action ), msg );
+	str = NULL;
+	ret = na_iio_provider_write_item( NULL, NA_OBJECT( action ), &str );
+	if( str ){
+		*msg = g_slist_append( *msg, str );
+		g_free( str );
+	}
 
 	return( ret == NA_IIO_PROVIDER_WRITE_OK );
 }
diff --git a/src/utils/nautilus-actions-schemas.c b/src/utils/nautilus-actions-schemas.c
index 5066ddf..a10a712 100644
--- a/src/utils/nautilus-actions-schemas.c
+++ b/src/utils/nautilus-actions-schemas.c
@@ -41,6 +41,7 @@
 #include <common/na-iprefs.h>
 #include <common/na-xml-names.h>
 #include <common/na-xml-writer.h>
+#include <common/na-utils.h>
 
 /*static gchar     *output_fname = NULL;
 static gboolean   output_gconf = FALSE;*/
@@ -66,7 +67,8 @@ main( int argc, char** argv )
 	GOptionContext *context;
 	gchar *help;
 	GError *error = NULL;
-	gchar *msg = NULL;
+	GSList *msg = NULL;
+	GSList *im;
 
 	g_type_init();
 
@@ -105,8 +107,10 @@ main( int argc, char** argv )
 	/*}*/
 
 	if( msg ){
-		g_printerr( "%s\n", msg );
-		g_free( msg );
+		for( im = msg ; im ; im = im->next ){
+			g_printerr( "%s\n", ( gchar * ) im->data );
+		}
+		na_utils_free_string_list( msg );
 		status = EXIT_FAILURE;
 	}
 



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