Convert NASettings to a private singleton
[nautilus-actions.git] / src / nact / nact-assistant-export.c
blob3c4ac2f27b14751add1cd92f9ae0061c063ffa11
1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include <glib/gi18n.h>
36 #include <string.h>
38 #include <api/na-core-utils.h>
39 #include <api/na-object-api.h>
41 #include <core/na-iprefs.h>
42 #include <core/na-exporter.h>
44 #include "nact-application.h"
45 #include "nact-main-window.h"
46 #include "nact-assistant-export.h"
47 #include "nact-export-ask.h"
48 #include "nact-export-format.h"
49 #include "nact-tree-view.h"
51 /* Export Assistant
53 * pos. type title
54 * --- ------- ------------------------------------
55 * 0 Intro Introduction
56 * 1 Content Selection of the actions
57 * 2 Content Selection of the target folder
58 * 3 Content Selection of the export format
59 * 4 Confirm Summary of the operations to be done
60 * 5 Summary Export is done: summary of the done operations
63 enum {
64 ASSIST_PAGE_INTRO = 0,
65 ASSIST_PAGE_ACTIONS_SELECTION,
66 ASSIST_PAGE_FOLDER_SELECTION,
67 ASSIST_PAGE_FORMAT_SELECTION,
68 ASSIST_PAGE_CONFIRM,
69 ASSIST_PAGE_DONE
72 /* private class data
74 struct _NactAssistantExportClassPrivate {
75 void *empty; /* so that gcc -pedantic is happy */
78 /* private instance data
80 struct _NactAssistantExportPrivate {
81 gboolean dispose_has_run;
82 NactTreeView *items_view;
83 gboolean preferences_locked;
84 gchar *uri;
85 GList *selected_items;
86 GList *results;
89 typedef struct {
90 NAObjectItem *item;
91 GSList *msg;
92 gchar *fname;
93 GQuark format;
95 ExportStruct;
97 static const gchar *st_xmlui_filename = PKGDATADIR "/nact-assistant-export.ui";
98 static const gchar *st_toplevel_name = "ExportAssistant";
99 static const gchar *st_wsp_name = NA_IPREFS_EXPORT_ASSISTANT_WSP;
101 static BaseAssistantClass *st_parent_class = NULL;
103 static GType register_type( void );
104 static void class_init( NactAssistantExportClass *klass );
105 static void instance_init( GTypeInstance *instance, gpointer klass );
106 static void instance_dispose( GObject *application );
107 static void instance_finalize( GObject *application );
109 static void on_base_initialize_gtk_toplevel( NactAssistantExport *dialog, GtkAssistant *toplevel, gpointer user_data );
110 static void on_base_initialize_base_window( NactAssistantExport *dialog, gpointer user_data );
111 static void on_base_all_widgets_showed( NactAssistantExport *dialog, gpointer user_data );
113 static void assist_runtime_init_intro( NactAssistantExport *window, GtkAssistant *assistant );
115 static void assist_runtime_init_actions_list( NactAssistantExport *window, GtkAssistant *assistant );
116 static void on_tree_view_selection_changed( NactAssistantExport *window, GList *selected_items, gpointer user_data );
117 static void assist_initial_load_target_folder( NactAssistantExport *window, GtkAssistant *assistant );
118 static void assist_runtime_init_target_folder( NactAssistantExport *window, GtkAssistant *assistant );
119 static GtkFileChooser *get_folder_chooser( NactAssistantExport *window );
120 static void on_folder_selection_changed( GtkFileChooser *chooser, gpointer user_data );
122 static void assist_initial_load_format( NactAssistantExport *window, GtkAssistant *assistant );
123 static void assist_runtime_init_format( NactAssistantExport *window, GtkAssistant *assistant );
124 static NAExportFormat *get_export_format( NactAssistantExport *window );
126 static void assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page );
127 static void assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page );
128 static void assistant_apply( BaseAssistant *window, GtkAssistant *assistant );
129 static void assist_prepare_exportdone( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page );
130 static void free_results( GList *list );
132 GType
133 nact_assistant_export_get_type( void )
135 static GType window_type = 0;
137 if( !window_type ){
138 window_type = register_type();
141 return( window_type );
144 static GType
145 register_type( void )
147 static const gchar *thisfn = "nact_assistant_export_register_type";
148 GType type;
150 static GTypeInfo info = {
151 sizeof( NactAssistantExportClass ),
152 ( GBaseInitFunc ) NULL,
153 ( GBaseFinalizeFunc ) NULL,
154 ( GClassInitFunc ) class_init,
155 NULL,
156 NULL,
157 sizeof( NactAssistantExport ),
159 ( GInstanceInitFunc ) instance_init
162 g_debug( "%s", thisfn );
164 type = g_type_register_static( BASE_ASSISTANT_TYPE, "NactAssistantExport", &info, 0 );
166 return( type );
169 static void
170 class_init( NactAssistantExportClass *klass )
172 static const gchar *thisfn = "nact_assistant_export_class_init";
173 GObjectClass *object_class;
174 BaseAssistantClass *assist_class;
176 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
178 st_parent_class = g_type_class_peek_parent( klass );
180 object_class = G_OBJECT_CLASS( klass );
181 object_class->dispose = instance_dispose;
182 object_class->finalize = instance_finalize;
184 klass->private = g_new0( NactAssistantExportClassPrivate, 1 );
186 assist_class = BASE_ASSISTANT_CLASS( klass );
187 assist_class->apply = assistant_apply;
188 assist_class->prepare = assistant_prepare;
191 static void
192 instance_init( GTypeInstance *instance, gpointer klass )
194 static const gchar *thisfn = "nact_assistant_export_instance_init";
195 NactAssistantExport *self;
197 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( instance ));
199 g_debug( "%s: instance=%p (%s), klass=%p",
200 thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
202 self = NACT_ASSISTANT_EXPORT( instance );
204 self->private = g_new0( NactAssistantExportPrivate, 1 );
206 self->private->dispose_has_run = FALSE;
208 base_window_signal_connect( BASE_WINDOW( instance ),
209 G_OBJECT( instance ), BASE_SIGNAL_INITIALIZE_GTK, G_CALLBACK( on_base_initialize_gtk_toplevel ));
211 base_window_signal_connect( BASE_WINDOW( instance ),
212 G_OBJECT( instance ), BASE_SIGNAL_INITIALIZE_WINDOW, G_CALLBACK( on_base_initialize_base_window ));
214 base_window_signal_connect( BASE_WINDOW( instance ),
215 G_OBJECT( instance ), BASE_SIGNAL_ALL_WIDGETS_SHOWED, G_CALLBACK( on_base_all_widgets_showed ));
218 static void
219 instance_dispose( GObject *window )
221 static const gchar *thisfn = "nact_assistant_export_instance_dispose";
222 NactAssistantExport *self;
224 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window ));
226 self = NACT_ASSISTANT_EXPORT( window );
228 if( !self->private->dispose_has_run ){
229 g_debug( "%s: window=%p (%s)", thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ));
231 self->private->dispose_has_run = TRUE;
233 g_object_unref( self->private->items_view );
235 if( self->private->selected_items ){
236 self->private->selected_items = na_object_free_items( self->private->selected_items );
239 /* chain up to the parent class */
240 if( G_OBJECT_CLASS( st_parent_class )->dispose ){
241 G_OBJECT_CLASS( st_parent_class )->dispose( window );
246 static void
247 instance_finalize( GObject *window )
249 static const gchar *thisfn = "nact_assistant_export_instance_finalize";
250 NactAssistantExport *self;
252 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window ));
254 g_debug( "%s: window=%p (%s)", thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ));
256 self = NACT_ASSISTANT_EXPORT( window );
258 free_results( self->private->results );
260 g_free( self->private );
262 /* chain call to parent class */
263 if( G_OBJECT_CLASS( st_parent_class )->finalize ){
264 G_OBJECT_CLASS( st_parent_class )->finalize( window );
269 * Run the assistant.
271 * @main: the main window of the application.
273 void
274 nact_assistant_export_run( BaseWindow *main_window )
276 NactAssistantExport *assistant;
277 gboolean esc_quit, esc_confirm;
279 g_return_if_fail( NACT_IS_MAIN_WINDOW( main_window ));
281 esc_quit = na_settings_get_boolean( NA_IPREFS_ASSISTANT_ESC_QUIT, NULL, NULL );
282 esc_confirm = na_settings_get_boolean( NA_IPREFS_ASSISTANT_ESC_CONFIRM, NULL, NULL );
284 assistant = g_object_new( NACT_ASSISTANT_EXPORT_TYPE,
285 BASE_PROP_PARENT, main_window,
286 BASE_PROP_HAS_OWN_BUILDER, TRUE,
287 BASE_PROP_XMLUI_FILENAME, st_xmlui_filename,
288 BASE_PROP_TOPLEVEL_NAME, st_toplevel_name,
289 BASE_PROP_WSP_NAME, st_wsp_name,
290 BASE_PROP_QUIT_ON_ESCAPE, esc_quit,
291 BASE_PROP_WARN_ON_ESCAPE, esc_confirm,
292 NULL );
294 assistant->private->items_view = nact_tree_view_new( BASE_WINDOW( assistant ), "ActionsList", TREE_MODE_SELECTION );
296 base_window_run( BASE_WINDOW( assistant ));
299 static void
300 on_base_initialize_gtk_toplevel( NactAssistantExport *dialog, GtkAssistant *assistant, gpointer user_data )
302 static const gchar *thisfn = "nact_assistant_export_on_base_initialize_gtk_toplevel";
303 gboolean are_locked, mandatory;
305 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog ));
307 if( !dialog->private->dispose_has_run ){
308 g_debug( "%s: dialog=%p, assistant=%p, user_data=%p",
309 thisfn, ( void * ) dialog, ( void * ) assistant, ( void * ) user_data );
311 are_locked = na_settings_get_boolean( NA_IPREFS_ADMIN_PREFERENCES_LOCKED, NULL, &mandatory );
312 dialog->private->preferences_locked = are_locked && mandatory;
314 assist_initial_load_target_folder( dialog, assistant );
315 assist_initial_load_format( dialog, assistant );
319 static void
320 on_base_initialize_base_window( NactAssistantExport *dialog, gpointer user_data )
322 static const gchar *thisfn = "nact_assistant_export_on_base_initialize_base_window";
323 GtkAssistant *assistant;
325 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog ));
327 if( !dialog->private->dispose_has_run ){
328 g_debug( "%s: dialog=%p, user_data=%p", thisfn, ( void * ) dialog, ( void * ) user_data );
330 assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( dialog )));
332 base_window_signal_connect( BASE_WINDOW( dialog ),
333 G_OBJECT( dialog ), TREE_SIGNAL_SELECTION_CHANGED, G_CALLBACK( on_tree_view_selection_changed ));
335 assist_runtime_init_intro( dialog, assistant );
336 assist_runtime_init_actions_list( dialog, assistant );
337 assist_runtime_init_target_folder( dialog, assistant );
338 assist_runtime_init_format( dialog, assistant );
342 static void
343 on_base_all_widgets_showed( NactAssistantExport *dialog, gpointer user_data )
345 static const gchar *thisfn = "nact_assistant_export_on_base_all_widgets_showed";
346 NactMainWindow *main_window;
347 NactTreeView *main_items_view;
348 GList *items;
350 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog ));
352 if( !dialog->private->dispose_has_run ){
353 g_debug( "%s: dialog=%p, user_data=%p", thisfn, ( void * ) dialog, ( void * ) user_data );
355 /* setup the data here so that we are sure all companion objects
356 * have connected their signal handlers
358 main_window = NACT_MAIN_WINDOW( base_window_get_parent( BASE_WINDOW( dialog )));
359 main_items_view = nact_main_window_get_items_view( main_window );
360 items = nact_tree_view_get_items( main_items_view );
361 nact_tree_view_fill( dialog->private->items_view, items );
365 static void
366 assist_runtime_init_intro( NactAssistantExport *window, GtkAssistant *assistant )
368 static const gchar *thisfn = "nact_assistant_export_runtime_init_intro";
369 GtkWidget *content;
371 g_debug( "%s: window=%p, assistant=%p", thisfn, ( void * ) window, ( void * ) assistant );
373 content = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_INTRO );
374 gtk_assistant_set_page_complete( assistant, content, TRUE );
377 static void
378 assist_runtime_init_actions_list( NactAssistantExport *window, GtkAssistant *assistant )
380 GtkWidget *content;
382 content = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_ACTIONS_SELECTION );
383 gtk_assistant_set_page_complete( assistant, content, FALSE );
386 static void
387 on_tree_view_selection_changed( NactAssistantExport *window, GList *selected_items, gpointer user_data )
389 static const gchar *thisfn = "nact_assistant_export_on_tree_view_selection_changed";
390 GtkAssistant *assistant;
391 gint pos;
392 gboolean enabled;
393 GtkWidget *content;
395 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window ));
397 g_debug( "%s: window=%p, selected_items=%p (count=%d), user_data=%p",
398 thisfn, ( void * ) window,
399 ( void * ) selected_items, g_list_length( selected_items ), ( void * ) user_data );
401 if( window->private->selected_items ){
402 window->private->selected_items = na_object_free_items( window->private->selected_items );
405 assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
406 pos = gtk_assistant_get_current_page( assistant );
408 if( pos == ASSIST_PAGE_ACTIONS_SELECTION ){
409 enabled = ( g_list_length( selected_items ) > 0 );
410 window->private->selected_items = na_object_copyref_items( selected_items );
411 content = gtk_assistant_get_nth_page( assistant, pos );
412 gtk_assistant_set_page_complete( assistant, content, enabled );
413 gtk_assistant_update_buttons_state( assistant );
417 static void
418 assist_initial_load_target_folder( NactAssistantExport *window, GtkAssistant *assistant )
420 GtkFileChooser *chooser = get_folder_chooser( window );
421 gtk_file_chooser_set_action( GTK_FILE_CHOOSER( chooser ), GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER );
422 gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( chooser ), FALSE );
425 static void
426 assist_runtime_init_target_folder( NactAssistantExport *window, GtkAssistant *assistant )
428 GtkFileChooser *chooser;
429 gchar *uri;
430 GtkWidget *content;
432 chooser = get_folder_chooser( window );
433 gtk_file_chooser_unselect_all( chooser );
435 uri = na_settings_get_string( NA_IPREFS_EXPORT_ASSISTANT_URI, NULL, NULL );
436 if( uri && strlen( uri )){
437 gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( chooser ), uri );
439 g_free( uri );
441 base_window_signal_connect( BASE_WINDOW( window ),
442 G_OBJECT( chooser ), "selection-changed", G_CALLBACK( on_folder_selection_changed ));
444 content = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FOLDER_SELECTION );
445 gtk_assistant_set_page_complete( assistant, content, FALSE );
448 static GtkFileChooser *
449 get_folder_chooser( NactAssistantExport *window )
451 return( GTK_FILE_CHOOSER( base_window_get_widget( BASE_WINDOW( window ), "ExportFolderChooser" )));
455 * we check the selected uri for writability
456 * this is always subject to become invalid before actually writing
457 * but this is better than nothing, doesn't ?
459 static void
460 on_folder_selection_changed( GtkFileChooser *chooser, gpointer user_data )
462 static const gchar *thisfn = "nact_assistant_export_on_folder_selection_changed";
463 GtkAssistant *assistant;
464 gint pos;
465 gchar *uri;
466 gboolean enabled;
467 NactAssistantExport *assist;
468 GtkWidget *content;
470 g_debug( "%s: chooser=%p, user_data=%p", thisfn, ( void * ) chooser, ( void * ) user_data );
471 g_assert( NACT_IS_ASSISTANT_EXPORT( user_data ));
472 assist = NACT_ASSISTANT_EXPORT( user_data );
474 assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( assist )));
475 pos = gtk_assistant_get_current_page( assistant );
476 if( pos == ASSIST_PAGE_FOLDER_SELECTION ){
478 uri = gtk_file_chooser_get_current_folder_uri( chooser );
479 g_debug( "%s: uri=%s", thisfn, uri );
480 enabled = ( uri && strlen( uri ) && na_core_utils_dir_is_writable_uri( uri ));
482 if( enabled ){
483 g_free( assist->private->uri );
484 assist->private->uri = g_strdup( uri );
485 na_settings_set_string( NA_IPREFS_EXPORT_ASSISTANT_URI, uri );
488 g_free( uri );
490 content = gtk_assistant_get_nth_page( assistant, pos );
491 gtk_assistant_set_page_complete( assistant, content, enabled );
492 gtk_assistant_update_buttons_state( assistant );
496 static void
497 assist_initial_load_format( NactAssistantExport *window, GtkAssistant *assistant )
499 NactApplication *application;
500 NAUpdater *updater;
501 GtkWidget *container;
503 application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
504 updater = nact_application_get_updater( application );
505 container = base_window_get_widget( BASE_WINDOW( window ), "AssistantExportFormatVBox" );
506 nact_export_format_init_display( container,
507 NA_PIVOT( updater ), EXPORT_FORMAT_DISPLAY_ASSISTANT, !window->private->preferences_locked );
510 static void
511 assist_runtime_init_format( NactAssistantExport *window, GtkAssistant *assistant )
513 GtkWidget *content;
514 GtkWidget *container;
515 GQuark format;
516 gboolean mandatory;
518 format = na_iprefs_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, &mandatory );
520 container = base_window_get_widget( BASE_WINDOW( window ), "AssistantExportFormatVBox" );
521 nact_export_format_select( container, !mandatory, format );
523 content = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
524 gtk_assistant_set_page_complete( assistant, content, TRUE );
527 static NAExportFormat *
528 get_export_format( NactAssistantExport *window )
530 GtkWidget *container;
531 NAExportFormat *format;
533 container = base_window_get_widget( BASE_WINDOW( window ), "AssistantExportFormatVBox" );
534 format = nact_export_format_get_selected( container );
536 return( format );
539 static void
540 assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page )
542 /*static const gchar *thisfn = "nact_assistant_export_on_prepare";
543 g_debug( "%s: window=%p, assistant=%p, page=%p", thisfn, window, assistant, page );*/
545 GtkAssistantPageType type = gtk_assistant_get_page_type( assistant, page );
547 switch( type ){
548 case GTK_ASSISTANT_PAGE_CONFIRM:
549 assist_prepare_confirm( NACT_ASSISTANT_EXPORT( window ), assistant, page );
550 break;
552 case GTK_ASSISTANT_PAGE_SUMMARY:
553 assist_prepare_exportdone( NACT_ASSISTANT_EXPORT( window ), assistant, page );
554 break;
556 default:
557 break;
561 static void
562 assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page )
564 static const gchar *thisfn = "nact_assistant_export_prepare_confirm";
565 GString *text;
566 gchar *label_item;
567 gchar *label11, *label12;
568 gchar *label21, *label22;
569 GList *it;
570 NAExportFormat *format;
571 GtkLabel *confirm_label;
573 g_debug( "%s: window=%p, assistant=%p, page=%p",
574 thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
576 /* i18n: this is the title of the confirm page of the export assistant */
577 text = g_string_new( "" );
578 g_string_printf( text, "<b>%s</b>\n\n", _( "About to export selected items:" ));
580 for( it = window->private->selected_items ; it ; it = it->next ){
581 label_item = na_object_get_label( it->data );
582 g_string_append_printf( text, "\t%s\n", label_item );
583 g_free( label_item );
586 g_assert( window->private->uri && strlen( window->private->uri ));
588 /* i18n: all exported actions go to one destination folder */
589 g_string_append_printf( text,
590 "\n\n<b>%s</b>\n\n\t%s", _( "Into the destination folder:" ), window->private->uri );
592 label11 = NULL;
593 label21 = NULL;
594 format = get_export_format( window );
595 label11 = na_export_format_get_label( format );
596 label21 = na_export_format_get_description( format );
597 na_iprefs_set_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, na_export_format_get_quark( format ));
598 label12 = na_core_utils_str_remove_char( label11, "_" );
599 label22 = na_core_utils_str_add_prefix( "\t", label21 );
600 g_string_append_printf( text, "\n\n<b>%s</b>\n\n%s", label12, label22 );
601 g_free( label22 );
602 g_free( label21 );
603 g_free( label12 );
604 g_free( label11 );
606 confirm_label = GTK_LABEL( base_window_get_widget( BASE_WINDOW( window ), "AssistantExportConfirmLabel" ));
607 gtk_label_set_markup( confirm_label, text->str );
608 g_string_free( text, TRUE );
610 gtk_assistant_set_page_complete( assistant, page, TRUE );
614 * As of 1.11, nact_gconf_writer doesn't return any error message.
615 * An error is simply indicated by returning a null filename.
616 * So we provide a general error message.
618 static void
619 assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
621 static const gchar *thisfn = "nact_assistant_export_on_apply";
622 NactAssistantExport *window;
623 GList *ia;
624 ExportStruct *str;
625 NactApplication *application;
626 NAUpdater *updater;
627 gboolean first;
629 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( wnd ));
631 g_debug( "%s: window=%p, assistant=%p", thisfn, ( void * ) wnd, ( void * ) assistant );
633 window = NACT_ASSISTANT_EXPORT( wnd );
635 application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
636 updater = nact_application_get_updater( application );
637 first = TRUE;
639 g_return_if_fail( window->private->uri && strlen( window->private->uri ));
641 for( ia = window->private->selected_items ; ia ; ia = ia->next ){
642 str = g_new0( ExportStruct, 1 );
643 window->private->results = g_list_append( window->private->results, str );
645 str->item = NA_OBJECT_ITEM( na_object_get_origin( NA_IDUPLICABLE( ia->data )));
647 str->format = na_iprefs_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, NULL );
649 if( str->format == IPREFS_EXPORT_FORMAT_ASK ){
650 str->format = nact_export_ask_user( BASE_WINDOW( wnd ), str->item, first );
652 if( str->format == IPREFS_EXPORT_NO_EXPORT ){
653 str->msg = g_slist_append( NULL, g_strdup( _( "Export canceled due to user action." )));
657 if( str->format != IPREFS_EXPORT_NO_EXPORT ){
658 str->fname = na_exporter_to_file( NA_PIVOT( updater ), str->item, window->private->uri, str->format, &str->msg );
661 first = FALSE;
665 static void
666 assist_prepare_exportdone( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page )
668 static const gchar *thisfn = "nact_assistant_export_prepare_exportdone";
669 gchar *text, *tmp;
670 GList *ir;
671 ExportStruct *str;
672 gchar *label;
673 GSList *is;
674 gint errors;
675 GtkTextView *summary_textview;
676 GtkTextBuffer *summary_buffer;
677 GtkTextTag *title_tag;
678 GtkTextIter start, end;
679 gint title_len;
681 g_debug( "%s: window=%p, assistant=%p, page=%p",
682 thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
684 /* i18n: result of the export assistant */
685 text = g_strdup( _( "Selected actions have been proceeded :" ));
686 title_len = g_utf8_strlen( text, -1 );
687 tmp = g_strdup_printf( "%s\n\n", text );
688 g_free( text );
689 text = tmp;
691 errors = 0;
693 for( ir = window->private->results ; ir ; ir = ir->next ){
694 str = ( ExportStruct * ) ir->data;
696 label = na_object_get_label( str->item );
697 tmp = g_strdup_printf( "%s\t%s\n", text, label );
698 g_free( text );
699 text = tmp;
700 g_free( label );
702 if( str->fname ){
703 /* i18n: action as been successfully exported to <filename> */
704 tmp = g_strdup_printf( "%s\t\t%s\n\t\t%s\n", text, _( "Successfully exported as" ), str->fname );
705 g_free( text );
706 text = tmp;
708 } else if( str->format != IPREFS_EXPORT_NO_EXPORT ){
709 errors += 1;
712 /* add messages */
713 for( is = str->msg ; is ; is = is->next ){
714 tmp = g_strdup_printf( "%s\t\t%s\n", text, ( gchar * ) is->data );
715 g_free( text );
716 text = tmp;
719 /* add a blank line between two actions */
720 tmp = g_strdup_printf( "%s\n", text );
721 g_free( text );
722 text = tmp;
725 if( errors ){
726 text = g_strdup_printf( "%s%s", text,
727 _( "You may not have write permissions on selected folder." ));
728 g_free( text );
729 text = tmp;
732 summary_textview = GTK_TEXT_VIEW( base_window_get_widget( BASE_WINDOW( window ), "AssistantExportSummaryTextView" ));
733 summary_buffer = gtk_text_view_get_buffer( summary_textview );
734 gtk_text_buffer_set_text( summary_buffer, text, -1 );
735 g_free( text );
737 title_tag = gtk_text_buffer_create_tag( summary_buffer, "title",
738 "weight", PANGO_WEIGHT_BOLD,
739 NULL );
741 gtk_text_buffer_get_iter_at_offset( summary_buffer, &start, 0 );
742 gtk_text_buffer_get_iter_at_offset( summary_buffer, &end, title_len );
743 gtk_text_buffer_apply_tag( summary_buffer, title_tag, &start, &end );
745 g_object_unref( title_tag );
747 gtk_assistant_set_page_complete( assistant, page, TRUE );
748 g_object_set( G_OBJECT( window ), BASE_PROP_WARN_ON_ESCAPE, FALSE, NULL );
751 static void
752 free_results( GList *list )
754 GList *ir;
755 ExportStruct *str;
757 for( ir = list ; ir ; ir = ir->next ){
758 str = ( ExportStruct * ) ir->data;
759 g_free( str->fname );
760 na_core_utils_slist_free( str->msg );
763 g_list_free( list );