[nautilus-actions] Optimize the build of the displayed text in export assistant



commit 396390fd5cdd35f76538b5d271e1fcb8ced26caa
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Mar 3 22:29:14 2010 +0100

    Optimize the build of the displayed text in export assistant

 ChangeLog                        |    3 ++
 TODO                             |    4 ---
 src/nact/nact-assistant-export.c |   44 ++++++++++++++++---------------------
 3 files changed, 22 insertions(+), 29 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2ff476c..28439eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2009-03-03 Pierre Wieser <pwieser trychlos org>
 
+	* src/nact/nact-assistant-export.c (assist_prepare_confirm):
+	Optimize the build of the displayed text.
+
 	* src/nact/nact-assistant-export.c (on_all_widgets_showed):
 	Select and expand the first row of the list.
 
diff --git a/TODO b/TODO
index 636041a..cad2ac7 100644
--- a/TODO
+++ b/TODO
@@ -159,8 +159,4 @@
 
 - get_xds_atom_value: test on 64bit platform, then remove debug stuff
 
-- on export assistant, select and expand first row
-
-- on export assistant, display subitems of selected menus
-
 - try to restore hierarchy on import
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 1bcf480..bef820e 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -658,10 +658,11 @@ static void
 assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page )
 {
 	static const gchar *thisfn = "nact_assistant_export_prepare_confirm";
-	gchar *text, *tmp, *text2;
+	GString *text;
+	gchar *label_item;
 	gchar *label11, *label12;
 	gchar *label21, *label22;
-	GList *actions, *ia;
+	GList *items, *it;
 	NAExportFormat *format;
 	GtkLabel *confirm_label;
 
@@ -669,29 +670,22 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
 			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
 
 	/* i18n: this is the title of the confirm page of the export assistant */
-	text = g_strdup( _( "About to export selected items:" ));
-	tmp = g_strdup_printf( "<b>%s</b>\n\n", text );
-	g_free( text );
-	text = tmp;
-
-	actions = nact_iactions_list_bis_get_selected_items( NACT_IACTIONS_LIST( window ));
-
-	for( ia = actions ; ia ; ia = ia->next ){
-		tmp = g_strdup_printf( "%s\t%s\n", text, na_object_get_label( ia->data ));
-		g_free( text );
-		text = tmp;
+	text = g_string_new( "" );
+	g_string_printf( text, "<b>%s</b>\n\n", _( "About to export selected items:" ));
+
+	items = nact_iactions_list_bis_get_selected_items( NACT_IACTIONS_LIST( window ));
+	for( it = items ; it ; it = it->next ){
+		label_item = na_object_get_label( it->data );
+		g_string_append_printf( text, "\t%s\n", label_item );
+		g_free( label_item );
 	}
-
-	na_object_unref_selected_items( actions );
+	na_object_unref_selected_items( items );
 
 	g_assert( window->private->uri && strlen( window->private->uri ));
 
 	/* i18n: all exported actions go to one destination folder */
-	text2 = g_strdup( _( "Into the destination folder:" ));
-	tmp = g_strdup_printf( "%s\n\n<b>%s</b>\n\n\t%s", text, text2, window->private->uri );
-	g_free( text2 );
-	g_free( text );
-	text = tmp;
+	g_string_append_printf( text,
+			"\n\n<b>%s</b>\n\n\t%s", _( "Into the destination folder:" ), window->private->uri );
 
 	label11 = NULL;
 	label21 = NULL;
@@ -701,17 +695,15 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
 	nact_iprefs_set_export_format( BASE_WINDOW( window ), IPREFS_EXPORT_FORMAT, na_export_format_get_quark( format ));
 	label12 = na_core_utils_str_remove_char( label11, "_" );
 	label22 = na_core_utils_str_add_prefix( "\t", label21 );
-	tmp = g_strdup_printf( "%s\n\n<b>%s</b>\n\n%s", text, label12, label22 );
+	g_string_append_printf( text, "\n\n<b>%s</b>\n\n%s", label12, label22 );
 	g_free( label22 );
 	g_free( label21 );
 	g_free( label12 );
 	g_free( label11 );
-	g_free( text );
-	text = tmp;
 
 	confirm_label = GTK_LABEL( base_window_get_widget( BASE_WINDOW( window ), "AssistantExportConfirmLabel" ));
-	gtk_label_set_markup( confirm_label, text );
-	g_free( text );
+	gtk_label_set_markup( confirm_label, text->str );
+	g_string_free( text, TRUE );
 
 	gtk_assistant_set_page_complete( assistant, page, TRUE );
 }
@@ -748,8 +740,10 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 		str->item = NA_OBJECT_ITEM( na_object_get_origin( NA_IDUPLICABLE( ia->data )));
 
 		str->format = nact_iprefs_get_export_format( BASE_WINDOW( wnd ), IPREFS_EXPORT_FORMAT );
+
 		if( str->format == IPREFS_EXPORT_FORMAT_ASK ){
 			str->format = nact_export_ask_user( BASE_WINDOW( wnd ), str->item );
+
 			if( str->format == IPREFS_EXPORT_NO_EXPORT ){
 				str->msg = g_slist_append( NULL, g_strdup( _( "Export canceled due to user action." )));
 			}



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