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.
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)
35 #include <glib/gi18n.h>
39 #include <api/na-core-utils.h>
40 #include <api/na-object-api.h>
42 #include <core/na-iprefs.h>
43 #include <core/na-exporter.h>
45 #include "base-iprefs.h"
46 #include "nact-application.h"
47 #include "nact-main-window.h"
48 #include "nact-assistant-export.h"
49 #include "nact-export-ask.h"
50 #include "nact-export-format.h"
51 #include "nact-iactions-list.h"
56 * --- ------- ------------------------------------
57 * 0 Intro Introduction
58 * 1 Content Selection of the actions
59 * 2 Content Selection of the target folder
60 * 3 Content Selection of the export format
61 * 4 Confirm Summary of the operations to be done
62 * 5 Summary Export is done: summary of the done operations
66 ASSIST_PAGE_INTRO
= 0,
67 ASSIST_PAGE_ACTIONS_SELECTION
,
68 ASSIST_PAGE_FOLDER_SELECTION
,
69 ASSIST_PAGE_FORMAT_SELECTION
,
76 struct _NactAssistantExportClassPrivate
{
77 void *empty
; /* so that gcc -pedantic is happy */
80 /* private instance data
82 struct _NactAssistantExportPrivate
{
83 gboolean dispose_has_run
;
84 gboolean preferences_locked
;
97 static const gchar
*st_xmlui_filename
= PKGDATADIR
"/nact-assistant-export.ui";
99 static BaseAssistantClass
*st_parent_class
= NULL
;
101 static GType
register_type( void );
102 static void class_init( NactAssistantExportClass
*klass
);
103 static void iactions_list_iface_init( NactIActionsListInterface
*iface
);
104 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
105 static void instance_dispose( GObject
*application
);
106 static void instance_finalize( GObject
*application
);
108 static NactAssistantExport
*assist_new( BaseWindow
*parent
);
110 static gchar
*window_get_iprefs_window_id( const BaseWindow
*window
);
111 static gchar
*window_get_toplevel_name( const BaseWindow
*dialog
);
113 static void on_initial_load_dialog( NactAssistantExport
*dialog
, gpointer user_data
);
114 static void on_runtime_init_dialog( NactAssistantExport
*dialog
, gpointer user_data
);
115 static void on_all_widgets_showed( NactAssistantExport
*dialog
);
117 static void assist_initial_load_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
);
118 static void assist_runtime_init_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
);
120 static void assist_initial_load_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
);
121 static void assist_runtime_init_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
);
122 static void on_iactions_list_selection_changed( NactIActionsList
*instance
, GSList
*selected_items
);
123 static gchar
*on_iactions_list_get_treeview_name( NactIActionsList
*instance
);
125 static void assist_initial_load_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
);
126 static void assist_runtime_init_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
);
127 static GtkFileChooser
*get_folder_chooser( NactAssistantExport
*window
);
128 static void on_folder_selection_changed( GtkFileChooser
*chooser
, gpointer user_data
);
130 static void assist_initial_load_format( NactAssistantExport
*window
, GtkAssistant
*assistant
);
131 static void assist_runtime_init_format( NactAssistantExport
*window
, GtkAssistant
*assistant
);
132 static NAExportFormat
*get_export_format( NactAssistantExport
*window
);
134 static void assist_initial_load_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
);
135 static void assist_runtime_init_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
);
137 static void assist_initial_load_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
);
138 static void assist_runtime_init_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
);
140 static void assistant_prepare( BaseAssistant
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
141 static void assist_prepare_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
142 static void assistant_apply( BaseAssistant
*window
, GtkAssistant
*assistant
);
143 static void assist_prepare_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
144 static void free_results( GList
*list
);
147 nact_assistant_export_get_type( void )
149 static GType window_type
= 0;
152 window_type
= register_type();
155 return( window_type
);
159 register_type( void )
161 static const gchar
*thisfn
= "nact_assistant_export_register_type";
164 static GTypeInfo info
= {
165 sizeof( NactAssistantExportClass
),
166 ( GBaseInitFunc
) NULL
,
167 ( GBaseFinalizeFunc
) NULL
,
168 ( GClassInitFunc
) class_init
,
171 sizeof( NactAssistantExport
),
173 ( GInstanceInitFunc
) instance_init
176 static const GInterfaceInfo iactions_list_iface_info
= {
177 ( GInterfaceInitFunc
) iactions_list_iface_init
,
182 g_debug( "%s", thisfn
);
184 type
= g_type_register_static( BASE_ASSISTANT_TYPE
, "NactAssistantExport", &info
, 0 );
186 g_type_add_interface_static( type
, NACT_IACTIONS_LIST_TYPE
, &iactions_list_iface_info
);
192 class_init( NactAssistantExportClass
*klass
)
194 static const gchar
*thisfn
= "nact_assistant_export_class_init";
195 GObjectClass
*object_class
;
196 BaseWindowClass
*base_class
;
197 BaseAssistantClass
*assist_class
;
199 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
201 st_parent_class
= g_type_class_peek_parent( klass
);
203 object_class
= G_OBJECT_CLASS( klass
);
204 object_class
->dispose
= instance_dispose
;
205 object_class
->finalize
= instance_finalize
;
207 klass
->private = g_new0( NactAssistantExportClassPrivate
, 1 );
209 base_class
= BASE_WINDOW_CLASS( klass
);
210 base_class
->get_iprefs_window_id
= window_get_iprefs_window_id
;
211 base_class
->get_toplevel_name
= window_get_toplevel_name
;
213 assist_class
= BASE_ASSISTANT_CLASS( klass
);
214 assist_class
->apply
= assistant_apply
;
215 assist_class
->prepare
= assistant_prepare
;
219 iactions_list_iface_init( NactIActionsListInterface
*iface
)
221 static const gchar
*thisfn
= "nact_assistant_export_iactions_list_iface_init";
223 g_debug( "%s: iface=%p", thisfn
, ( void * ) iface
);
225 iface
->get_treeview_name
= on_iactions_list_get_treeview_name
;
229 instance_init( GTypeInstance
*instance
, gpointer klass
)
231 static const gchar
*thisfn
= "nact_assistant_export_instance_init";
232 NactAssistantExport
*self
;
234 g_debug( "%s: instance=%p (%s), klass=%p",
235 thisfn
, ( void * ) instance
, G_OBJECT_TYPE_NAME( instance
), ( void * ) klass
);
236 g_assert( NACT_IS_ASSISTANT_EXPORT( instance
));
237 self
= NACT_ASSISTANT_EXPORT( instance
);
239 self
->private = g_new0( NactAssistantExportPrivate
, 1 );
241 self
->private->dispose_has_run
= FALSE
;
243 base_window_signal_connect(
244 BASE_WINDOW( instance
),
245 G_OBJECT( instance
),
246 BASE_SIGNAL_INITIALIZE_GTK
,
247 G_CALLBACK( on_initial_load_dialog
));
249 base_window_signal_connect(
250 BASE_WINDOW( instance
),
251 G_OBJECT( instance
),
252 BASE_SIGNAL_INITIALIZE_WINDOW
,
253 G_CALLBACK( on_runtime_init_dialog
));
255 base_window_signal_connect(
256 BASE_WINDOW( instance
),
257 G_OBJECT( instance
),
258 BASE_SIGNAL_ALL_WIDGETS_SHOWED
,
259 G_CALLBACK( on_all_widgets_showed
));
263 instance_dispose( GObject
*window
)
265 static const gchar
*thisfn
= "nact_assistant_export_instance_dispose";
266 NactAssistantExport
*self
;
268 g_debug( "%s: window=%p (%s)", thisfn
, ( void * ) window
, G_OBJECT_TYPE_NAME( window
));
269 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window
));
270 self
= NACT_ASSISTANT_EXPORT( window
);
272 if( !self
->private->dispose_has_run
){
274 self
->private->dispose_has_run
= TRUE
;
276 nact_iactions_list_dispose( NACT_IACTIONS_LIST( window
));
278 /* chain up to the parent class */
279 if( G_OBJECT_CLASS( st_parent_class
)->dispose
){
280 G_OBJECT_CLASS( st_parent_class
)->dispose( window
);
286 instance_finalize( GObject
*window
)
288 static const gchar
*thisfn
= "nact_assistant_export_instance_finalize";
289 NactAssistantExport
*self
;
291 g_debug( "%s: window=%p", thisfn
, ( void * ) window
);
292 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window
));
293 self
= NACT_ASSISTANT_EXPORT( window
);
295 free_results( self
->private->results
);
297 g_free( self
->private );
299 /* chain call to parent class */
300 if( G_OBJECT_CLASS( st_parent_class
)->finalize
){
301 G_OBJECT_CLASS( st_parent_class
)->finalize( window
);
305 static NactAssistantExport
*
306 assist_new( BaseWindow
*parent
)
308 return( g_object_new( NACT_ASSISTANT_EXPORT_TYPE
,
309 BASE_PROP_PARENT
, parent
,
310 BASE_PROP_XMLUI_FILENAME
, st_xmlui_filename
,
317 * @main: the main window of the application.
320 nact_assistant_export_run( BaseWindow
*main_window
)
322 NactAssistantExport
*assist
;
324 assist
= assist_new( main_window
);
325 g_object_set( G_OBJECT( assist
), BASE_PROP_HAS_OWN_BUILDER
, TRUE
, NULL
);
327 base_window_run( BASE_WINDOW( assist
));
331 window_get_iprefs_window_id( const BaseWindow
*window
)
333 return( g_strdup( NA_IPREFS_EXPORT_ASSISTANT_WSP
));
337 window_get_toplevel_name( const BaseWindow
*dialog
)
339 return( g_strdup( "ExportAssistant" ));
343 on_initial_load_dialog( NactAssistantExport
*dialog
, gpointer user_data
)
345 static const gchar
*thisfn
= "nact_assistant_export_on_initial_load_dialog";
346 GtkAssistant
*assistant
;
347 NactApplication
*application
;
349 NASettings
*settings
;
350 gboolean esc_quit
, esc_confirm
;
351 gboolean are_locked
, mandatory
;
353 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog
));
355 g_debug( "%s: dialog=%p, user_data=%p", thisfn
, ( void * ) dialog
, ( void * ) user_data
);
357 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( dialog
)));
358 updater
= nact_application_get_updater( application
);
359 settings
= na_pivot_get_settings( NA_PIVOT( updater
));
361 are_locked
= na_settings_get_boolean( settings
, NA_IPREFS_ADMIN_PREFERENCES_LOCKED
, NULL
, &mandatory
);
362 dialog
->private->preferences_locked
= are_locked
&& mandatory
;
364 assistant
= GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( dialog
)));
366 assist_initial_load_intro( dialog
, assistant
);
367 assist_initial_load_actions_list( dialog
, assistant
);
368 assist_initial_load_target_folder( dialog
, assistant
);
369 assist_initial_load_format( dialog
, assistant
);
370 assist_initial_load_confirm( dialog
, assistant
);
371 assist_initial_load_exportdone( dialog
, assistant
);
373 esc_quit
= na_settings_get_boolean( settings
, NA_IPREFS_ASSISTANT_ESC_QUIT
, NULL
, NULL
);
374 base_assistant_set_cancel_on_esc( BASE_ASSISTANT( dialog
), esc_quit
);
375 esc_confirm
= na_settings_get_boolean( settings
, NA_IPREFS_ASSISTANT_ESC_CONFIRM
, NULL
, NULL
);
376 base_assistant_set_warn_on_esc( BASE_ASSISTANT( dialog
), esc_confirm
);
380 on_runtime_init_dialog( NactAssistantExport
*dialog
, gpointer user_data
)
382 static const gchar
*thisfn
= "nact_assistant_export_on_runtime_init_dialog";
383 GtkAssistant
*assistant
;
385 g_debug( "%s: dialog=%p, user_data=%p", thisfn
, ( void * ) dialog
, ( void * ) user_data
);
386 g_assert( NACT_IS_ASSISTANT_EXPORT( dialog
));
388 assistant
= GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( dialog
)));
390 base_window_signal_connect(
391 BASE_WINDOW( dialog
),
393 IACTIONS_LIST_SIGNAL_SELECTION_CHANGED
,
394 G_CALLBACK( on_iactions_list_selection_changed
));
396 assist_runtime_init_intro( dialog
, assistant
);
397 assist_runtime_init_actions_list( dialog
, assistant
);
398 assist_runtime_init_target_folder( dialog
, assistant
);
399 assist_runtime_init_format( dialog
, assistant
);
400 assist_runtime_init_confirm( dialog
, assistant
);
401 assist_runtime_init_exportdone( dialog
, assistant
);
405 on_all_widgets_showed( NactAssistantExport
*dialog
)
407 static const gchar
*thisfn
= "nact_assistant_export_on_all_widgets_showed";
409 g_debug( "%s: dialog=%p", thisfn
, ( void * ) dialog
);
410 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog
));
412 nact_iactions_list_bis_select_first_row( NACT_IACTIONS_LIST( dialog
));
416 assist_initial_load_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
)
421 assist_runtime_init_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
)
423 static const gchar
*thisfn
= "nact_assistant_export_runtime_init_intro";
426 g_debug( "%s: window=%p, assistant=%p", thisfn
, ( void * ) window
, ( void * ) assistant
);
428 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_INTRO
);
429 gtk_assistant_set_page_complete( assistant
, content
, TRUE
);
433 assist_initial_load_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
)
435 g_assert( NACT_IS_IACTIONS_LIST( window
));
437 nact_iactions_list_set_management_mode( NACT_IACTIONS_LIST( window
), IACTIONS_LIST_MANAGEMENT_MODE_EXPORT
);
438 nact_iactions_list_initial_load_toplevel( NACT_IACTIONS_LIST( window
));
442 assist_runtime_init_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
)
448 parent
= base_window_get_parent( BASE_WINDOW( window
));
449 g_assert( NACT_IS_MAIN_WINDOW( parent
));
450 g_assert( NACT_IS_IACTIONS_LIST( parent
));
451 tree
= nact_iactions_list_bis_get_items( NACT_IACTIONS_LIST( parent
));
453 nact_iactions_list_runtime_init_toplevel( NACT_IACTIONS_LIST( window
), tree
);
455 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_ACTIONS_SELECTION
);
457 gtk_assistant_set_page_complete( assistant
, content
, FALSE
);
461 on_iactions_list_selection_changed( NactIActionsList
*instance
, GSList
*selected_items
)
463 static const gchar
*thisfn
= "nact_assistant_export_on_actions_list_selection_changed";
465 g_debug( "%s: selection=%p, selected_items=%p (count=%d)",
466 thisfn
, ( void * ) instance
, ( void * ) selected_items
, g_slist_length( selected_items
));
468 GtkAssistant
*assistant
;
473 g_assert( NACT_IS_ASSISTANT_EXPORT( instance
));
474 assistant
= GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( instance
)));
475 pos
= gtk_assistant_get_current_page( assistant
);
476 if( pos
== ASSIST_PAGE_ACTIONS_SELECTION
){
478 enabled
= ( g_slist_length( selected_items
) > 0 );
480 content
= gtk_assistant_get_nth_page( assistant
, pos
);
481 gtk_assistant_set_page_complete( assistant
, content
, enabled
);
482 gtk_assistant_update_buttons_state( assistant
);
487 on_iactions_list_get_treeview_name( NactIActionsList
*instance
)
491 g_return_val_if_fail( NACT_IS_ASSISTANT_EXPORT( instance
), NULL
);
493 name
= g_strdup( "ActionsList" );
499 assist_initial_load_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
)
501 GtkFileChooser
*chooser
= get_folder_chooser( window
);
502 gtk_file_chooser_set_action( GTK_FILE_CHOOSER( chooser
), GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
);
503 gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( chooser
), FALSE
);
507 assist_runtime_init_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
)
509 GtkFileChooser
*chooser
;
510 NactApplication
*application
;
512 NASettings
*settings
;
516 chooser
= get_folder_chooser( window
);
517 gtk_file_chooser_unselect_all( chooser
);
519 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
520 updater
= nact_application_get_updater( application
);
521 settings
= na_pivot_get_settings( NA_PIVOT( updater
));
523 uri
= na_settings_get_string( settings
, NA_IPREFS_EXPORT_ASSISTANT_URI
, NULL
, NULL
);
524 if( uri
&& strlen( uri
)){
525 gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( chooser
), uri
);
529 base_window_signal_connect(
530 BASE_WINDOW( window
),
533 G_CALLBACK( on_folder_selection_changed
));
535 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_FOLDER_SELECTION
);
536 gtk_assistant_set_page_complete( assistant
, content
, FALSE
);
539 static GtkFileChooser
*
540 get_folder_chooser( NactAssistantExport
*window
)
542 return( GTK_FILE_CHOOSER( base_window_get_widget( BASE_WINDOW( window
), "ExportFolderChooser" )));
546 * we check the selected uri for writability
547 * this is always subject to become invalid before actually writing
548 * but this is better than nothing, doesn't ?
551 on_folder_selection_changed( GtkFileChooser
*chooser
, gpointer user_data
)
553 static const gchar
*thisfn
= "nact_assistant_export_on_folder_selection_changed";
554 GtkAssistant
*assistant
;
558 NactAssistantExport
*assist
;
560 NactApplication
*application
;
562 NASettings
*settings
;
564 g_debug( "%s: chooser=%p, user_data=%p", thisfn
, ( void * ) chooser
, ( void * ) user_data
);
565 g_assert( NACT_IS_ASSISTANT_EXPORT( user_data
));
566 assist
= NACT_ASSISTANT_EXPORT( user_data
);
568 assistant
= GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( assist
)));
569 pos
= gtk_assistant_get_current_page( assistant
);
570 if( pos
== ASSIST_PAGE_FOLDER_SELECTION
){
572 uri
= gtk_file_chooser_get_current_folder_uri( chooser
);
573 g_debug( "%s: uri=%s", thisfn
, uri
);
574 enabled
= ( uri
&& strlen( uri
) && na_core_utils_dir_is_writable_uri( uri
));
577 g_free( assist
->private->uri
);
578 assist
->private->uri
= g_strdup( uri
);
580 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( assist
)));
581 updater
= nact_application_get_updater( application
);
582 settings
= na_pivot_get_settings( NA_PIVOT( updater
));
584 na_settings_set_string( settings
, NA_IPREFS_EXPORT_ASSISTANT_URI
, uri
);
589 content
= gtk_assistant_get_nth_page( assistant
, pos
);
590 gtk_assistant_set_page_complete( assistant
, content
, enabled
);
591 gtk_assistant_update_buttons_state( assistant
);
596 assist_initial_load_format( NactAssistantExport
*window
, GtkAssistant
*assistant
)
598 NactApplication
*application
;
600 GtkWidget
*container
;
602 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
603 updater
= nact_application_get_updater( application
);
604 container
= base_window_get_widget( BASE_WINDOW( window
), "AssistantExportFormatVBox" );
605 nact_export_format_init_display( container
,
606 NA_PIVOT( updater
), EXPORT_FORMAT_DISPLAY_ASSISTANT
, !window
->private->preferences_locked
);
610 assist_runtime_init_format( NactAssistantExport
*window
, GtkAssistant
*assistant
)
613 GtkWidget
*container
;
615 NactApplication
*application
;
619 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
620 updater
= nact_application_get_updater( application
);
621 format
= na_iprefs_get_export_format( NA_PIVOT( updater
), NA_IPREFS_EXPORT_PREFERRED_FORMAT
, &mandatory
);
623 container
= base_window_get_widget( BASE_WINDOW( window
), "AssistantExportFormatVBox" );
624 nact_export_format_select( container
, !mandatory
, format
);
626 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_FORMAT_SELECTION
);
627 gtk_assistant_set_page_complete( assistant
, content
, TRUE
);
630 static NAExportFormat
*
631 get_export_format( NactAssistantExport
*window
)
633 GtkWidget
*container
;
634 NAExportFormat
*format
;
636 container
= base_window_get_widget( BASE_WINDOW( window
), "AssistantExportFormatVBox" );
637 format
= nact_export_format_get_selected( container
);
643 assist_initial_load_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
)
648 assist_runtime_init_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
)
653 assist_initial_load_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
)
658 assist_runtime_init_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
)
663 assistant_prepare( BaseAssistant
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
665 /*static const gchar *thisfn = "nact_assistant_export_on_prepare";
666 g_debug( "%s: window=%p, assistant=%p, page=%p", thisfn, window, assistant, page );*/
668 GtkAssistantPageType type
= gtk_assistant_get_page_type( assistant
, page
);
671 case GTK_ASSISTANT_PAGE_CONFIRM
:
672 assist_prepare_confirm( NACT_ASSISTANT_EXPORT( window
), assistant
, page
);
675 case GTK_ASSISTANT_PAGE_SUMMARY
:
676 assist_prepare_exportdone( NACT_ASSISTANT_EXPORT( window
), assistant
, page
);
685 assist_prepare_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
687 static const gchar
*thisfn
= "nact_assistant_export_prepare_confirm";
690 gchar
*label11
, *label12
;
691 gchar
*label21
, *label22
;
693 NAExportFormat
*format
;
694 GtkLabel
*confirm_label
;
695 NactApplication
*application
;
698 g_debug( "%s: window=%p, assistant=%p, page=%p",
699 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
701 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
702 updater
= nact_application_get_updater( application
);
704 /* i18n: this is the title of the confirm page of the export assistant */
705 text
= g_string_new( "" );
706 g_string_printf( text
, "<b>%s</b>\n\n", _( "About to export selected items:" ));
708 items
= nact_iactions_list_bis_get_selected_items( NACT_IACTIONS_LIST( window
));
709 for( it
= items
; it
; it
= it
->next
){
710 label_item
= na_object_get_label( it
->data
);
711 g_string_append_printf( text
, "\t%s\n", label_item
);
712 g_free( label_item
);
714 na_object_unref_selected_items( items
);
716 g_assert( window
->private->uri
&& strlen( window
->private->uri
));
718 /* i18n: all exported actions go to one destination folder */
719 g_string_append_printf( text
,
720 "\n\n<b>%s</b>\n\n\t%s", _( "Into the destination folder:" ), window
->private->uri
);
724 format
= get_export_format( window
);
725 label11
= na_export_format_get_label( format
);
726 label21
= na_export_format_get_description( format
);
727 na_iprefs_set_export_format( NA_PIVOT( updater
), NA_IPREFS_EXPORT_PREFERRED_FORMAT
, na_export_format_get_quark( format
));
728 label12
= na_core_utils_str_remove_char( label11
, "_" );
729 label22
= na_core_utils_str_add_prefix( "\t", label21
);
730 g_string_append_printf( text
, "\n\n<b>%s</b>\n\n%s", label12
, label22
);
736 confirm_label
= GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "AssistantExportConfirmLabel" ));
737 gtk_label_set_markup( confirm_label
, text
->str
);
738 g_string_free( text
, TRUE
);
740 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
744 * As of 1.11, nact_gconf_writer doesn't return any error message.
745 * An error is simply indicated by returning a null filename.
746 * So we provide a general error message.
749 assistant_apply( BaseAssistant
*wnd
, GtkAssistant
*assistant
)
751 static const gchar
*thisfn
= "nact_assistant_export_on_apply";
752 NactAssistantExport
*window
;
755 NactApplication
*application
;
759 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( wnd
));
761 g_debug( "%s: window=%p, assistant=%p", thisfn
, ( void * ) wnd
, ( void * ) assistant
);
763 window
= NACT_ASSISTANT_EXPORT( wnd
);
765 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
766 updater
= nact_application_get_updater( application
);
767 actions
= nact_iactions_list_bis_get_selected_items( NACT_IACTIONS_LIST( window
));
770 g_return_if_fail( window
->private->uri
&& strlen( window
->private->uri
));
772 for( ia
= actions
; ia
; ia
= ia
->next
){
773 str
= g_new0( ExportStruct
, 1 );
774 window
->private->results
= g_list_append( window
->private->results
, str
);
776 str
->item
= NA_OBJECT_ITEM( na_object_get_origin( NA_IDUPLICABLE( ia
->data
)));
778 str
->format
= na_iprefs_get_export_format( NA_PIVOT( updater
), NA_IPREFS_EXPORT_PREFERRED_FORMAT
, NULL
);
780 if( str
->format
== IPREFS_EXPORT_FORMAT_ASK
){
781 str
->format
= nact_export_ask_user( BASE_WINDOW( wnd
), str
->item
, first
);
783 if( str
->format
== IPREFS_EXPORT_NO_EXPORT
){
784 str
->msg
= g_slist_append( NULL
, g_strdup( _( "Export canceled due to user action." )));
788 if( str
->format
!= IPREFS_EXPORT_NO_EXPORT
){
789 str
->fname
= na_exporter_to_file( NA_PIVOT( updater
), str
->item
, window
->private->uri
, str
->format
, &str
->msg
);
795 na_object_unref_selected_items( actions
);
799 assist_prepare_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
801 static const gchar
*thisfn
= "nact_assistant_export_prepare_exportdone";
808 GtkTextView
*summary_textview
;
809 GtkTextBuffer
*summary_buffer
;
810 GtkTextTag
*title_tag
;
811 GtkTextIter start
, end
;
814 g_debug( "%s: window=%p, assistant=%p, page=%p",
815 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
817 /* i18n: result of the export assistant */
818 text
= g_strdup( _( "Selected actions have been proceeded :" ));
819 title_len
= g_utf8_strlen( text
, -1 );
820 tmp
= g_strdup_printf( "%s\n\n", text
);
826 for( ir
= window
->private->results
; ir
; ir
= ir
->next
){
827 str
= ( ExportStruct
* ) ir
->data
;
829 label
= na_object_get_label( str
->item
);
830 tmp
= g_strdup_printf( "%s\t%s\n", text
, label
);
836 /* i18n: action as been successfully exported to <filename> */
837 tmp
= g_strdup_printf( "%s\t\t%s\n\t\t%s\n", text
, _( "Successfully exported as" ), str
->fname
);
841 } else if( str
->format
!= IPREFS_EXPORT_NO_EXPORT
){
846 for( is
= str
->msg
; is
; is
= is
->next
){
847 tmp
= g_strdup_printf( "%s\t\t%s\n", text
, ( gchar
* ) is
->data
);
852 /* add a blank line between two actions */
853 tmp
= g_strdup_printf( "%s\n", text
);
859 text
= g_strdup_printf( "%s%s", text
,
860 _( "You may not have write permissions on selected folder." ));
865 summary_textview
= GTK_TEXT_VIEW( base_window_get_widget( BASE_WINDOW( window
), "AssistantExportSummaryTextView" ));
866 summary_buffer
= gtk_text_view_get_buffer( summary_textview
);
867 gtk_text_buffer_set_text( summary_buffer
, text
, -1 );
870 title_tag
= gtk_text_buffer_create_tag( summary_buffer
, "title",
871 "weight", PANGO_WEIGHT_BOLD
,
874 gtk_text_buffer_get_iter_at_offset( summary_buffer
, &start
, 0 );
875 gtk_text_buffer_get_iter_at_offset( summary_buffer
, &end
, title_len
);
876 gtk_text_buffer_apply_tag( summary_buffer
, title_tag
, &start
, &end
);
878 g_object_unref( title_tag
);
880 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
881 base_assistant_set_warn_on_cancel( BASE_ASSISTANT( window
), FALSE
);
882 base_assistant_set_warn_on_esc( BASE_ASSISTANT( window
), FALSE
);
886 free_results( GList
*list
)
891 for( ir
= list
; ir
; ir
= ir
->next
){
892 str
= ( ExportStruct
* ) ir
->data
;
893 g_free( str
->fname
);
894 na_core_utils_slist_free( str
->msg
);