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 BaseAssistantClass
*st_parent_class
= NULL
;
99 static GType
register_type( void );
100 static void class_init( NactAssistantExportClass
*klass
);
101 static void iactions_list_iface_init( NactIActionsListInterface
*iface
);
102 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
103 static void instance_dispose( GObject
*application
);
104 static void instance_finalize( GObject
*application
);
106 static NactAssistantExport
*assist_new( BaseWindow
*parent
);
108 static gchar
*window_get_iprefs_window_id( const BaseWindow
*window
);
109 static gchar
*window_get_toplevel_name( const BaseWindow
*dialog
);
110 static gchar
*window_get_ui_filename( const BaseWindow
*dialog
);
112 static void on_initial_load_dialog( NactAssistantExport
*dialog
, gpointer user_data
);
113 static void on_runtime_init_dialog( NactAssistantExport
*dialog
, gpointer user_data
);
114 static void on_all_widgets_showed( NactAssistantExport
*dialog
);
116 static void assist_initial_load_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
);
117 static void assist_runtime_init_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
);
119 static void assist_initial_load_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
);
120 static void assist_runtime_init_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
);
121 static void on_iactions_list_selection_changed( NactIActionsList
*instance
, GSList
*selected_items
);
122 static gchar
*on_iactions_list_get_treeview_name( NactIActionsList
*instance
);
124 static void assist_initial_load_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
);
125 static void assist_runtime_init_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
);
126 static GtkFileChooser
*get_folder_chooser( NactAssistantExport
*window
);
127 static void on_folder_selection_changed( GtkFileChooser
*chooser
, gpointer user_data
);
129 static void assist_initial_load_format( NactAssistantExport
*window
, GtkAssistant
*assistant
);
130 static void assist_runtime_init_format( NactAssistantExport
*window
, GtkAssistant
*assistant
);
131 static NAExportFormat
*get_export_format( NactAssistantExport
*window
);
133 static void assist_initial_load_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
);
134 static void assist_runtime_init_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
);
136 static void assist_initial_load_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
);
137 static void assist_runtime_init_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
);
139 static void assistant_prepare( BaseAssistant
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
140 static void assist_prepare_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
141 static void assistant_apply( BaseAssistant
*window
, GtkAssistant
*assistant
);
142 static void assist_prepare_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
143 static void free_results( GList
*list
);
146 nact_assistant_export_get_type( void )
148 static GType window_type
= 0;
151 window_type
= register_type();
154 return( window_type
);
158 register_type( void )
160 static const gchar
*thisfn
= "nact_assistant_export_register_type";
163 static GTypeInfo info
= {
164 sizeof( NactAssistantExportClass
),
165 ( GBaseInitFunc
) NULL
,
166 ( GBaseFinalizeFunc
) NULL
,
167 ( GClassInitFunc
) class_init
,
170 sizeof( NactAssistantExport
),
172 ( GInstanceInitFunc
) instance_init
175 static const GInterfaceInfo iactions_list_iface_info
= {
176 ( GInterfaceInitFunc
) iactions_list_iface_init
,
181 g_debug( "%s", thisfn
);
183 type
= g_type_register_static( BASE_ASSISTANT_TYPE
, "NactAssistantExport", &info
, 0 );
185 g_type_add_interface_static( type
, NACT_IACTIONS_LIST_TYPE
, &iactions_list_iface_info
);
191 class_init( NactAssistantExportClass
*klass
)
193 static const gchar
*thisfn
= "nact_assistant_export_class_init";
194 GObjectClass
*object_class
;
195 BaseWindowClass
*base_class
;
196 BaseAssistantClass
*assist_class
;
198 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
200 st_parent_class
= g_type_class_peek_parent( klass
);
202 object_class
= G_OBJECT_CLASS( klass
);
203 object_class
->dispose
= instance_dispose
;
204 object_class
->finalize
= instance_finalize
;
206 klass
->private = g_new0( NactAssistantExportClassPrivate
, 1 );
208 base_class
= BASE_WINDOW_CLASS( klass
);
209 base_class
->get_iprefs_window_id
= window_get_iprefs_window_id
;
210 base_class
->get_toplevel_name
= window_get_toplevel_name
;
211 base_class
->get_ui_filename
= window_get_ui_filename
;
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_WINDOW_SIGNAL_INITIAL_LOAD
,
247 G_CALLBACK( on_initial_load_dialog
));
249 base_window_signal_connect(
250 BASE_WINDOW( instance
),
251 G_OBJECT( instance
),
252 BASE_WINDOW_SIGNAL_RUNTIME_INIT
,
253 G_CALLBACK( on_runtime_init_dialog
));
255 base_window_signal_connect(
256 BASE_WINDOW( instance
),
257 G_OBJECT( instance
),
258 BASE_WINDOW_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
, BASE_WINDOW_PROP_PARENT
, parent
, NULL
));
314 * @main: the main window of the application.
317 nact_assistant_export_run( BaseWindow
*main_window
)
319 NactAssistantExport
*assist
;
321 assist
= assist_new( main_window
);
322 g_object_set( G_OBJECT( assist
), BASE_WINDOW_PROP_HAS_OWN_BUILDER
, TRUE
, NULL
);
324 base_window_run( BASE_WINDOW( assist
));
328 window_get_iprefs_window_id( const BaseWindow
*window
)
330 return( g_strdup( NA_IPREFS_EXPORT_ASSISTANT_WSP
));
334 window_get_toplevel_name( const BaseWindow
*dialog
)
336 return( g_strdup( "ExportAssistant" ));
340 window_get_ui_filename( const BaseWindow
*dialog
)
342 return( g_strdup( PKGDATADIR
"/nact-assistant-export.ui" ));
346 on_initial_load_dialog( NactAssistantExport
*dialog
, gpointer user_data
)
348 static const gchar
*thisfn
= "nact_assistant_export_on_initial_load_dialog";
349 GtkAssistant
*assistant
;
350 NactApplication
*application
;
352 NASettings
*settings
;
353 gboolean esc_quit
, esc_confirm
;
354 gboolean are_locked
, mandatory
;
356 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog
));
358 g_debug( "%s: dialog=%p, user_data=%p", thisfn
, ( void * ) dialog
, ( void * ) user_data
);
360 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( dialog
)));
361 updater
= nact_application_get_updater( application
);
362 settings
= na_pivot_get_settings( NA_PIVOT( updater
));
364 are_locked
= na_settings_get_boolean( settings
, NA_IPREFS_ADMIN_PREFERENCES_LOCKED
, NULL
, &mandatory
);
365 dialog
->private->preferences_locked
= are_locked
&& mandatory
;
367 assistant
= GTK_ASSISTANT( base_window_get_toplevel( BASE_WINDOW( dialog
)));
369 assist_initial_load_intro( dialog
, assistant
);
370 assist_initial_load_actions_list( dialog
, assistant
);
371 assist_initial_load_target_folder( dialog
, assistant
);
372 assist_initial_load_format( dialog
, assistant
);
373 assist_initial_load_confirm( dialog
, assistant
);
374 assist_initial_load_exportdone( dialog
, assistant
);
376 esc_quit
= na_settings_get_boolean( settings
, NA_IPREFS_ASSISTANT_ESC_QUIT
, NULL
, NULL
);
377 base_assistant_set_cancel_on_esc( BASE_ASSISTANT( dialog
), esc_quit
);
378 esc_confirm
= na_settings_get_boolean( settings
, NA_IPREFS_ASSISTANT_ESC_CONFIRM
, NULL
, NULL
);
379 base_assistant_set_warn_on_esc( BASE_ASSISTANT( dialog
), esc_confirm
);
383 on_runtime_init_dialog( NactAssistantExport
*dialog
, gpointer user_data
)
385 static const gchar
*thisfn
= "nact_assistant_export_on_runtime_init_dialog";
386 GtkAssistant
*assistant
;
388 g_debug( "%s: dialog=%p, user_data=%p", thisfn
, ( void * ) dialog
, ( void * ) user_data
);
389 g_assert( NACT_IS_ASSISTANT_EXPORT( dialog
));
391 assistant
= GTK_ASSISTANT( base_window_get_toplevel( BASE_WINDOW( dialog
)));
393 base_window_signal_connect(
394 BASE_WINDOW( dialog
),
396 IACTIONS_LIST_SIGNAL_SELECTION_CHANGED
,
397 G_CALLBACK( on_iactions_list_selection_changed
));
399 assist_runtime_init_intro( dialog
, assistant
);
400 assist_runtime_init_actions_list( dialog
, assistant
);
401 assist_runtime_init_target_folder( dialog
, assistant
);
402 assist_runtime_init_format( dialog
, assistant
);
403 assist_runtime_init_confirm( dialog
, assistant
);
404 assist_runtime_init_exportdone( dialog
, assistant
);
408 on_all_widgets_showed( NactAssistantExport
*dialog
)
410 static const gchar
*thisfn
= "nact_assistant_export_on_all_widgets_showed";
412 g_debug( "%s: dialog=%p", thisfn
, ( void * ) dialog
);
413 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( dialog
));
415 nact_iactions_list_bis_select_first_row( NACT_IACTIONS_LIST( dialog
));
419 assist_initial_load_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
)
424 assist_runtime_init_intro( NactAssistantExport
*window
, GtkAssistant
*assistant
)
426 static const gchar
*thisfn
= "nact_assistant_export_runtime_init_intro";
429 g_debug( "%s: window=%p, assistant=%p", thisfn
, ( void * ) window
, ( void * ) assistant
);
431 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_INTRO
);
432 gtk_assistant_set_page_complete( assistant
, content
, TRUE
);
436 assist_initial_load_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
)
438 g_assert( NACT_IS_IACTIONS_LIST( window
));
440 nact_iactions_list_set_management_mode( NACT_IACTIONS_LIST( window
), IACTIONS_LIST_MANAGEMENT_MODE_EXPORT
);
441 nact_iactions_list_initial_load_toplevel( NACT_IACTIONS_LIST( window
));
445 assist_runtime_init_actions_list( NactAssistantExport
*window
, GtkAssistant
*assistant
)
451 parent
= base_window_get_parent( BASE_WINDOW( window
));
452 g_assert( NACT_IS_MAIN_WINDOW( parent
));
453 g_assert( NACT_IS_IACTIONS_LIST( parent
));
454 tree
= nact_iactions_list_bis_get_items( NACT_IACTIONS_LIST( parent
));
456 nact_iactions_list_runtime_init_toplevel( NACT_IACTIONS_LIST( window
), tree
);
458 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_ACTIONS_SELECTION
);
460 gtk_assistant_set_page_complete( assistant
, content
, FALSE
);
464 on_iactions_list_selection_changed( NactIActionsList
*instance
, GSList
*selected_items
)
466 static const gchar
*thisfn
= "nact_assistant_export_on_actions_list_selection_changed";
468 g_debug( "%s: selection=%p, selected_items=%p (count=%d)",
469 thisfn
, ( void * ) instance
, ( void * ) selected_items
, g_slist_length( selected_items
));
471 GtkAssistant
*assistant
;
476 g_assert( NACT_IS_ASSISTANT_EXPORT( instance
));
477 assistant
= GTK_ASSISTANT( base_window_get_toplevel( BASE_WINDOW( instance
)));
478 pos
= gtk_assistant_get_current_page( assistant
);
479 if( pos
== ASSIST_PAGE_ACTIONS_SELECTION
){
481 enabled
= ( g_slist_length( selected_items
) > 0 );
483 content
= gtk_assistant_get_nth_page( assistant
, pos
);
484 gtk_assistant_set_page_complete( assistant
, content
, enabled
);
485 gtk_assistant_update_buttons_state( assistant
);
490 on_iactions_list_get_treeview_name( NactIActionsList
*instance
)
494 g_return_val_if_fail( NACT_IS_ASSISTANT_EXPORT( instance
), NULL
);
496 name
= g_strdup( "ActionsList" );
502 assist_initial_load_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
)
504 GtkFileChooser
*chooser
= get_folder_chooser( window
);
505 gtk_file_chooser_set_action( GTK_FILE_CHOOSER( chooser
), GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
);
506 gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( chooser
), FALSE
);
510 assist_runtime_init_target_folder( NactAssistantExport
*window
, GtkAssistant
*assistant
)
512 GtkFileChooser
*chooser
;
513 NactApplication
*application
;
515 NASettings
*settings
;
519 chooser
= get_folder_chooser( window
);
520 gtk_file_chooser_unselect_all( chooser
);
522 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
523 updater
= nact_application_get_updater( application
);
524 settings
= na_pivot_get_settings( NA_PIVOT( updater
));
526 uri
= na_settings_get_string( settings
, NA_IPREFS_EXPORT_ASSISTANT_URI
, NULL
, NULL
);
527 if( uri
&& strlen( uri
)){
528 gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( chooser
), uri
);
532 base_window_signal_connect(
533 BASE_WINDOW( window
),
536 G_CALLBACK( on_folder_selection_changed
));
538 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_FOLDER_SELECTION
);
539 gtk_assistant_set_page_complete( assistant
, content
, FALSE
);
542 static GtkFileChooser
*
543 get_folder_chooser( NactAssistantExport
*window
)
545 return( GTK_FILE_CHOOSER( base_window_get_widget( BASE_WINDOW( window
), "ExportFolderChooser" )));
549 * we check the selected uri for writability
550 * this is always subject to become invalid before actually writing
551 * but this is better than nothing, doesn't ?
554 on_folder_selection_changed( GtkFileChooser
*chooser
, gpointer user_data
)
556 static const gchar
*thisfn
= "nact_assistant_export_on_folder_selection_changed";
557 GtkAssistant
*assistant
;
561 NactAssistantExport
*assist
;
563 NactApplication
*application
;
565 NASettings
*settings
;
567 g_debug( "%s: chooser=%p, user_data=%p", thisfn
, ( void * ) chooser
, ( void * ) user_data
);
568 g_assert( NACT_IS_ASSISTANT_EXPORT( user_data
));
569 assist
= NACT_ASSISTANT_EXPORT( user_data
);
571 assistant
= GTK_ASSISTANT( base_window_get_toplevel( BASE_WINDOW( assist
)));
572 pos
= gtk_assistant_get_current_page( assistant
);
573 if( pos
== ASSIST_PAGE_FOLDER_SELECTION
){
575 uri
= gtk_file_chooser_get_current_folder_uri( chooser
);
576 g_debug( "%s: uri=%s", thisfn
, uri
);
577 enabled
= ( uri
&& strlen( uri
) && na_core_utils_dir_is_writable_uri( uri
));
580 g_free( assist
->private->uri
);
581 assist
->private->uri
= g_strdup( uri
);
583 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( assist
)));
584 updater
= nact_application_get_updater( application
);
585 settings
= na_pivot_get_settings( NA_PIVOT( updater
));
587 na_settings_set_string( settings
, NA_IPREFS_EXPORT_ASSISTANT_URI
, uri
);
592 content
= gtk_assistant_get_nth_page( assistant
, pos
);
593 gtk_assistant_set_page_complete( assistant
, content
, enabled
);
594 gtk_assistant_update_buttons_state( assistant
);
599 assist_initial_load_format( NactAssistantExport
*window
, GtkAssistant
*assistant
)
601 NactApplication
*application
;
603 GtkWidget
*container
;
605 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
606 updater
= nact_application_get_updater( application
);
607 container
= base_window_get_widget( BASE_WINDOW( window
), "AssistantExportFormatVBox" );
608 nact_export_format_init_display( container
,
609 NA_PIVOT( updater
), EXPORT_FORMAT_DISPLAY_ASSISTANT
, !window
->private->preferences_locked
);
613 assist_runtime_init_format( NactAssistantExport
*window
, GtkAssistant
*assistant
)
616 GtkWidget
*container
;
618 NactApplication
*application
;
622 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
623 updater
= nact_application_get_updater( application
);
624 format
= na_iprefs_get_export_format( NA_PIVOT( updater
), NA_IPREFS_EXPORT_PREFERRED_FORMAT
, &mandatory
);
626 container
= base_window_get_widget( BASE_WINDOW( window
), "AssistantExportFormatVBox" );
627 nact_export_format_select( container
, !mandatory
, format
);
629 content
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_FORMAT_SELECTION
);
630 gtk_assistant_set_page_complete( assistant
, content
, TRUE
);
633 static NAExportFormat
*
634 get_export_format( NactAssistantExport
*window
)
636 GtkWidget
*container
;
637 NAExportFormat
*format
;
639 container
= base_window_get_widget( BASE_WINDOW( window
), "AssistantExportFormatVBox" );
640 format
= nact_export_format_get_selected( container
);
646 assist_initial_load_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
)
651 assist_runtime_init_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
)
656 assist_initial_load_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
)
661 assist_runtime_init_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
)
666 assistant_prepare( BaseAssistant
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
668 /*static const gchar *thisfn = "nact_assistant_export_on_prepare";
669 g_debug( "%s: window=%p, assistant=%p, page=%p", thisfn, window, assistant, page );*/
671 GtkAssistantPageType type
= gtk_assistant_get_page_type( assistant
, page
);
674 case GTK_ASSISTANT_PAGE_CONFIRM
:
675 assist_prepare_confirm( NACT_ASSISTANT_EXPORT( window
), assistant
, page
);
678 case GTK_ASSISTANT_PAGE_SUMMARY
:
679 assist_prepare_exportdone( NACT_ASSISTANT_EXPORT( window
), assistant
, page
);
688 assist_prepare_confirm( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
690 static const gchar
*thisfn
= "nact_assistant_export_prepare_confirm";
693 gchar
*label11
, *label12
;
694 gchar
*label21
, *label22
;
696 NAExportFormat
*format
;
697 GtkLabel
*confirm_label
;
698 NactApplication
*application
;
701 g_debug( "%s: window=%p, assistant=%p, page=%p",
702 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
704 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
705 updater
= nact_application_get_updater( application
);
707 /* i18n: this is the title of the confirm page of the export assistant */
708 text
= g_string_new( "" );
709 g_string_printf( text
, "<b>%s</b>\n\n", _( "About to export selected items:" ));
711 items
= nact_iactions_list_bis_get_selected_items( NACT_IACTIONS_LIST( window
));
712 for( it
= items
; it
; it
= it
->next
){
713 label_item
= na_object_get_label( it
->data
);
714 g_string_append_printf( text
, "\t%s\n", label_item
);
715 g_free( label_item
);
717 na_object_unref_selected_items( items
);
719 g_assert( window
->private->uri
&& strlen( window
->private->uri
));
721 /* i18n: all exported actions go to one destination folder */
722 g_string_append_printf( text
,
723 "\n\n<b>%s</b>\n\n\t%s", _( "Into the destination folder:" ), window
->private->uri
);
727 format
= get_export_format( window
);
728 label11
= na_export_format_get_label( format
);
729 label21
= na_export_format_get_description( format
);
730 na_iprefs_set_export_format( NA_PIVOT( updater
), NA_IPREFS_EXPORT_PREFERRED_FORMAT
, na_export_format_get_quark( format
));
731 label12
= na_core_utils_str_remove_char( label11
, "_" );
732 label22
= na_core_utils_str_add_prefix( "\t", label21
);
733 g_string_append_printf( text
, "\n\n<b>%s</b>\n\n%s", label12
, label22
);
739 confirm_label
= GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "AssistantExportConfirmLabel" ));
740 gtk_label_set_markup( confirm_label
, text
->str
);
741 g_string_free( text
, TRUE
);
743 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
747 * As of 1.11, nact_gconf_writer doesn't return any error message.
748 * An error is simply indicated by returning a null filename.
749 * So we provide a general error message.
752 assistant_apply( BaseAssistant
*wnd
, GtkAssistant
*assistant
)
754 static const gchar
*thisfn
= "nact_assistant_export_on_apply";
755 NactAssistantExport
*window
;
758 NactApplication
*application
;
762 g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( wnd
));
764 g_debug( "%s: window=%p, assistant=%p", thisfn
, ( void * ) wnd
, ( void * ) assistant
);
766 window
= NACT_ASSISTANT_EXPORT( wnd
);
768 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
769 updater
= nact_application_get_updater( application
);
770 actions
= nact_iactions_list_bis_get_selected_items( NACT_IACTIONS_LIST( window
));
773 g_return_if_fail( window
->private->uri
&& strlen( window
->private->uri
));
775 for( ia
= actions
; ia
; ia
= ia
->next
){
776 str
= g_new0( ExportStruct
, 1 );
777 window
->private->results
= g_list_append( window
->private->results
, str
);
779 str
->item
= NA_OBJECT_ITEM( na_object_get_origin( NA_IDUPLICABLE( ia
->data
)));
781 str
->format
= na_iprefs_get_export_format( NA_PIVOT( updater
), NA_IPREFS_EXPORT_PREFERRED_FORMAT
, NULL
);
783 if( str
->format
== IPREFS_EXPORT_FORMAT_ASK
){
784 str
->format
= nact_export_ask_user( BASE_WINDOW( wnd
), str
->item
, first
);
786 if( str
->format
== IPREFS_EXPORT_NO_EXPORT
){
787 str
->msg
= g_slist_append( NULL
, g_strdup( _( "Export canceled due to user action." )));
791 if( str
->format
!= IPREFS_EXPORT_NO_EXPORT
){
792 str
->fname
= na_exporter_to_file( NA_PIVOT( updater
), str
->item
, window
->private->uri
, str
->format
, &str
->msg
);
798 na_object_unref_selected_items( actions
);
802 assist_prepare_exportdone( NactAssistantExport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
804 static const gchar
*thisfn
= "nact_assistant_export_prepare_exportdone";
811 GtkTextView
*summary_textview
;
812 GtkTextBuffer
*summary_buffer
;
813 GtkTextTag
*title_tag
;
814 GtkTextIter start
, end
;
817 g_debug( "%s: window=%p, assistant=%p, page=%p",
818 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
820 /* i18n: result of the export assistant */
821 text
= g_strdup( _( "Selected actions have been proceeded :" ));
822 title_len
= g_utf8_strlen( text
, -1 );
823 tmp
= g_strdup_printf( "%s\n\n", text
);
829 for( ir
= window
->private->results
; ir
; ir
= ir
->next
){
830 str
= ( ExportStruct
* ) ir
->data
;
832 label
= na_object_get_label( str
->item
);
833 tmp
= g_strdup_printf( "%s\t%s\n", text
, label
);
839 /* i18n: action as been successfully exported to <filename> */
840 tmp
= g_strdup_printf( "%s\t\t%s\n\t\t%s\n", text
, _( "Successfully exported as" ), str
->fname
);
844 } else if( str
->format
!= IPREFS_EXPORT_NO_EXPORT
){
849 for( is
= str
->msg
; is
; is
= is
->next
){
850 tmp
= g_strdup_printf( "%s\t\t%s\n", text
, ( gchar
* ) is
->data
);
855 /* add a blank line between two actions */
856 tmp
= g_strdup_printf( "%s\n", text
);
862 text
= g_strdup_printf( "%s%s", text
,
863 _( "You may not have write permissions on selected folder." ));
868 summary_textview
= GTK_TEXT_VIEW( base_window_get_widget( BASE_WINDOW( window
), "AssistantExportSummaryTextView" ));
869 summary_buffer
= gtk_text_view_get_buffer( summary_textview
);
870 gtk_text_buffer_set_text( summary_buffer
, text
, -1 );
873 title_tag
= gtk_text_buffer_create_tag( summary_buffer
, "title",
874 "weight", PANGO_WEIGHT_BOLD
,
877 gtk_text_buffer_get_iter_at_offset( summary_buffer
, &start
, 0 );
878 gtk_text_buffer_get_iter_at_offset( summary_buffer
, &end
, title_len
);
879 gtk_text_buffer_apply_tag( summary_buffer
, title_tag
, &start
, &end
);
881 g_object_unref( title_tag
);
883 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
884 base_assistant_set_warn_on_cancel( BASE_ASSISTANT( window
), FALSE
);
885 base_assistant_set_warn_on_esc( BASE_ASSISTANT( window
), FALSE
);
889 free_results( GList
*list
)
894 for( ir
= list
; ir
; ir
= ir
->next
){
895 str
= ( ExportStruct
* ) ir
->data
;
896 g_free( str
->fname
);
897 na_core_utils_slist_free( str
->msg
);