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 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>
38 #include <api/na-object-api.h>
39 #include <api/na-core-utils.h>
41 #include <core/na-importer.h>
42 #include <core/na-iprefs.h>
44 #include "nact-application.h"
45 #include "nact-iprefs.h"
46 #include "nact-iactions-list.h"
47 #include "nact-assistant-import.h"
48 #include "nact-main-window.h"
53 * --- ------- --------------------------------------------------
54 * 0 Intro Introduction
55 * 1 Content Selection of the files
56 * 2 Content Duplicate management: what to do with duplicates ?
57 * 2 Confirm Display the selected files before import
58 * 3 Summary Import is done: summary of the done operations
62 ASSIST_PAGE_INTRO
= 0,
63 ASSIST_PAGE_FILES_SELECTION
,
64 ASSIST_PAGE_DUPLICATES
,
71 struct NactAssistantImportClassPrivate
{
72 void *empty
; /* so that gcc -pedantic is happy */
75 /* private instance data
77 struct NactAssistantImportPrivate
{
78 gboolean dispose_has_run
;
83 static BaseAssistantClass
*st_parent_class
= NULL
;
85 static GType
register_type( void );
86 static void class_init( NactAssistantImportClass
*klass
);
87 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
88 static void instance_dispose( GObject
*application
);
89 static void instance_finalize( GObject
*application
);
91 static NactAssistantImport
*assist_new( BaseWindow
*parent
);
93 static gchar
*window_get_iprefs_window_id( const BaseWindow
*window
);
94 static gchar
*window_get_dialog_name( const BaseWindow
*dialog
);
96 static void on_initial_load_dialog( NactAssistantImport
*dialog
, gpointer user_data
);
97 static void on_runtime_init_dialog( NactAssistantImport
*dialog
, gpointer user_data
);
98 static void runtime_init_intro( NactAssistantImport
*window
, GtkAssistant
*assistant
);
99 static void runtime_init_file_selector( NactAssistantImport
*window
, GtkAssistant
*assistant
);
100 static void on_file_selection_changed( GtkFileChooser
*chooser
, gpointer user_data
);
101 static gboolean
has_readable_files( GSList
*uris
);
102 static void runtime_init_duplicates( NactAssistantImport
*window
, GtkAssistant
*assistant
);
103 static void set_import_mode( NactAssistantImport
*window
, gint mode
);
105 static void assistant_prepare( BaseAssistant
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
106 static void prepare_confirm( NactAssistantImport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
107 static gint
get_import_mode( NactAssistantImport
*window
);
108 static gchar
*add_import_mode( NactAssistantImport
*window
, const gchar
*text
);
109 static void assistant_apply( BaseAssistant
*window
, GtkAssistant
*assistant
);
110 static NAObjectItem
*check_for_existence( const NAObjectItem
*, NactMainWindow
*window
);
111 static void prepare_importdone( NactAssistantImport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
);
112 static void free_results( GList
*list
);
115 nact_assistant_import_get_type( void )
117 static GType window_type
= 0;
120 window_type
= register_type();
123 return( window_type
);
127 register_type( void )
129 static const gchar
*thisfn
= "nact_assistant_import_register_type";
132 static GTypeInfo info
= {
133 sizeof( NactAssistantImportClass
),
134 ( GBaseInitFunc
) NULL
,
135 ( GBaseFinalizeFunc
) NULL
,
136 ( GClassInitFunc
) class_init
,
139 sizeof( NactAssistantImport
),
141 ( GInstanceInitFunc
) instance_init
144 g_debug( "%s", thisfn
);
146 type
= g_type_register_static( BASE_ASSISTANT_TYPE
, "NactAssistantImport", &info
, 0 );
152 class_init( NactAssistantImportClass
*klass
)
154 static const gchar
*thisfn
= "nact_assistant_import_class_init";
155 GObjectClass
*object_class
;
156 BaseWindowClass
*base_class
;
157 BaseAssistantClass
*assist_class
;
159 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
161 st_parent_class
= g_type_class_peek_parent( klass
);
163 object_class
= G_OBJECT_CLASS( klass
);
164 object_class
->dispose
= instance_dispose
;
165 object_class
->finalize
= instance_finalize
;
167 klass
->private = g_new0( NactAssistantImportClassPrivate
, 1 );
169 base_class
= BASE_WINDOW_CLASS( klass
);
170 base_class
->get_toplevel_name
= window_get_dialog_name
;
171 base_class
->get_iprefs_window_id
= window_get_iprefs_window_id
;
173 assist_class
= BASE_ASSISTANT_CLASS( klass
);
174 assist_class
->apply
= assistant_apply
;
175 assist_class
->prepare
= assistant_prepare
;
179 instance_init( GTypeInstance
*instance
, gpointer klass
)
181 static const gchar
*thisfn
= "nact_assistant_import_instance_init";
182 NactAssistantImport
*self
;
184 g_debug( "%s: instance=%p (%s), klass=%p",
185 thisfn
, ( void * ) instance
, G_OBJECT_TYPE_NAME( instance
), ( void * ) klass
);
186 g_return_if_fail( NACT_IS_ASSISTANT_IMPORT( instance
));
187 self
= NACT_ASSISTANT_IMPORT( instance
);
189 self
->private = g_new0( NactAssistantImportPrivate
, 1 );
191 self
->private->results
= NULL
;
193 base_window_signal_connect(
194 BASE_WINDOW( instance
),
195 G_OBJECT( instance
),
196 BASE_WINDOW_SIGNAL_INITIAL_LOAD
,
197 G_CALLBACK( on_initial_load_dialog
));
199 base_window_signal_connect(
200 BASE_WINDOW( instance
),
201 G_OBJECT( instance
),
202 BASE_WINDOW_SIGNAL_RUNTIME_INIT
,
203 G_CALLBACK( on_runtime_init_dialog
));
205 self
->private->gconf
= gconf_client_get_default();
207 self
->private->dispose_has_run
= FALSE
;
211 instance_dispose( GObject
*window
)
213 static const gchar
*thisfn
= "nact_assistant_import_instance_dispose";
214 NactAssistantImport
*self
;
216 g_debug( "%s: window=%p (%s)", thisfn
, ( void * ) window
, G_OBJECT_TYPE_NAME( window
));
217 g_return_if_fail( NACT_IS_ASSISTANT_IMPORT( window
));
218 self
= NACT_ASSISTANT_IMPORT( window
);
220 if( !self
->private->dispose_has_run
){
222 self
->private->dispose_has_run
= TRUE
;
224 g_object_unref( self
->private->gconf
);
226 /* chain up to the parent class */
227 if( G_OBJECT_CLASS( st_parent_class
)->dispose
){
228 G_OBJECT_CLASS( st_parent_class
)->dispose( window
);
234 instance_finalize( GObject
*window
)
236 static const gchar
*thisfn
= "nact_assistant_import_instance_finalize";
237 NactAssistantImport
*self
;
239 g_debug( "%s: window=%p", thisfn
, ( void * ) window
);
240 g_return_if_fail( NACT_IS_ASSISTANT_IMPORT( window
));
241 self
= NACT_ASSISTANT_IMPORT( window
);
243 free_results( self
->private->results
);
245 g_free( self
->private );
247 /* chain call to parent class */
248 if( G_OBJECT_CLASS( st_parent_class
)->finalize
){
249 G_OBJECT_CLASS( st_parent_class
)->finalize( window
);
253 static NactAssistantImport
*
254 assist_new( BaseWindow
*parent
)
256 return( g_object_new( NACT_ASSISTANT_IMPORT_TYPE
, BASE_WINDOW_PROP_PARENT
, parent
, NULL
));
260 * nact_assistant_import_run:
261 * @main: the #NactMainWindow parent window of this assistant.
266 nact_assistant_import_run( BaseWindow
*main_window
)
268 NactAssistantImport
*assist
;
270 assist
= assist_new( main_window
);
271 g_object_set( G_OBJECT( assist
), BASE_WINDOW_PROP_HAS_OWN_BUILDER
, TRUE
, NULL
);
273 base_window_run( BASE_WINDOW( assist
));
277 window_get_iprefs_window_id( const BaseWindow
*window
)
279 return( g_strdup( "import-assistant" ));
283 window_get_dialog_name( const BaseWindow
*dialog
)
285 return( g_strdup( "ImportAssistant" ));
289 on_initial_load_dialog( NactAssistantImport
*dialog
, gpointer user_data
)
291 static const gchar
*thisfn
= "nact_assistant_import_on_initial_load_dialog";
292 NactApplication
*application
;
294 gboolean esc_quit
, esc_confirm
;
296 g_debug( "%s: dialog=%p, user_data=%p", thisfn
, ( void * ) dialog
, ( void * ) user_data
);
297 g_return_if_fail( NACT_IS_ASSISTANT_IMPORT( dialog
));
299 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( dialog
)));
300 updater
= nact_application_get_updater( application
);
301 esc_quit
= na_iprefs_read_bool( NA_IPREFS( updater
), IPREFS_ASSIST_ESC_QUIT
, TRUE
);
302 base_assistant_set_cancel_on_esc( BASE_ASSISTANT( dialog
), esc_quit
);
303 esc_confirm
= na_iprefs_read_bool( NA_IPREFS( updater
), IPREFS_ASSIST_ESC_CONFIRM
, TRUE
);
304 base_assistant_set_warn_on_esc( BASE_ASSISTANT( dialog
), esc_confirm
);
308 on_runtime_init_dialog( NactAssistantImport
*dialog
, gpointer user_data
)
310 static const gchar
*thisfn
= "nact_assistant_import_on_runtime_init_dialog";
311 GtkAssistant
*assistant
;
313 g_debug( "%s: dialog=%p, user_data=%p", thisfn
, ( void * ) dialog
, ( void * ) user_data
);
314 g_return_if_fail( NACT_IS_ASSISTANT_IMPORT( dialog
));
316 if( !dialog
->private->dispose_has_run
){
318 assistant
= GTK_ASSISTANT( base_window_get_toplevel( BASE_WINDOW( dialog
)));
320 runtime_init_intro( dialog
, assistant
);
321 runtime_init_file_selector( dialog
, assistant
);
322 runtime_init_duplicates( dialog
, assistant
);
327 runtime_init_intro( NactAssistantImport
*window
, GtkAssistant
*assistant
)
329 static const gchar
*thisfn
= "nact_assistant_import_runtime_init_intro";
332 page
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_INTRO
);
334 g_debug( "%s: window=%p, assistant=%p, page=%p",
335 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
337 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
341 runtime_init_file_selector( NactAssistantImport
*window
, GtkAssistant
*assistant
)
343 static const gchar
*thisfn
= "nact_assistant_import_runtime_init_file_selector";
344 NactApplication
*application
;
350 page
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_FILES_SELECTION
);
352 g_debug( "%s: window=%p, assistant=%p, page=%p",
353 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
355 application
= NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window
)));
356 updater
= nact_application_get_updater( application
);
358 chooser
= base_window_get_widget( BASE_WINDOW( window
), "ImportFileChooser" );
359 uri
= na_iprefs_read_string( NA_IPREFS( updater
), IPREFS_IMPORT_ITEMS_FOLDER_URI
, "file:///tmp" );
360 if( uri
&& strlen( uri
)){
361 gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( chooser
), uri
);
365 base_window_signal_connect(
366 BASE_WINDOW( window
),
369 G_CALLBACK( on_file_selection_changed
));
371 gtk_assistant_set_page_complete( assistant
, page
, FALSE
);
375 on_file_selection_changed( GtkFileChooser
*chooser
, gpointer user_data
)
377 /*static const gchar *thisfn = "nact_assistant_import_on_file_selection_changed";
378 g_debug( "%s: chooser=%p, user_data=%p", thisfn, chooser, user_data );*/
380 GtkAssistant
*assistant
;
387 g_assert( NACT_IS_ASSISTANT_IMPORT( user_data
));
388 assistant
= GTK_ASSISTANT( base_window_get_toplevel( BASE_WINDOW( user_data
)));
389 pos
= gtk_assistant_get_current_page( assistant
);
390 if( pos
== ASSIST_PAGE_FILES_SELECTION
){
392 uris
= gtk_file_chooser_get_uris( chooser
);
393 enabled
= has_readable_files( uris
);
396 folder
= gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( chooser
));
397 nact_iprefs_write_string( BASE_WINDOW( user_data
), IPREFS_IMPORT_ITEMS_FOLDER_URI
, folder
);
401 na_core_utils_slist_free( uris
);
403 content
= gtk_assistant_get_nth_page( assistant
, pos
);
404 gtk_assistant_set_page_complete( assistant
, content
, enabled
);
405 gtk_assistant_update_buttons_state( assistant
);
410 * enable forward button if current selection has at least one readable file
413 has_readable_files( GSList
*uris
)
415 static const gchar
*thisfn
= "nact_assistant_import_has_readable_files";
422 GError
*error
= NULL
;
425 for( iuri
= uris
; iuri
; iuri
= iuri
->next
){
427 uri
= ( gchar
* ) iuri
->data
;
432 file
= g_file_new_for_uri( uri
);
433 info
= g_file_query_info( file
,
434 G_FILE_ATTRIBUTE_ACCESS_CAN_READ
"," G_FILE_ATTRIBUTE_STANDARD_TYPE
,
435 G_FILE_QUERY_INFO_NONE
, NULL
, &error
);
438 g_warning( "%s: g_file_query_info error: %s", thisfn
, error
->message
);
439 g_error_free( error
);
440 g_object_unref( file
);
444 type
= g_file_info_get_file_type( info
);
445 if( type
!= G_FILE_TYPE_REGULAR
){
446 g_debug( "%s: %s is not a file", thisfn
, uri
);
447 g_object_unref( info
);
451 readable
= g_file_info_get_attribute_boolean( info
, G_FILE_ATTRIBUTE_ACCESS_CAN_READ
);
453 g_debug( "%s: %s is not readable", thisfn
, uri
);
454 g_object_unref( info
);
459 g_object_unref( info
);
462 return( readables
> 0 );
466 runtime_init_duplicates( NactAssistantImport
*window
, GtkAssistant
*assistant
)
468 static const gchar
*thisfn
= "nact_assistant_import_runtime_init_duplicates";
472 g_debug( "%s: window=%p", thisfn
, ( void * ) window
);
474 mode
= na_iprefs_get_import_mode( window
->private->gconf
, IPREFS_IMPORT_ITEMS_IMPORT_MODE
);
475 set_import_mode( window
, mode
);
477 page
= gtk_assistant_get_nth_page( assistant
, ASSIST_PAGE_DUPLICATES
);
478 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
482 set_import_mode( NactAssistantImport
*window
, gint mode
)
484 GtkToggleButton
*button
;
487 case IMPORTER_MODE_ASK
:
488 button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "AskButton" ));
489 gtk_toggle_button_set_active( button
, TRUE
);
492 case IMPORTER_MODE_RENUMBER
:
493 button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "RenumberButton" ));
494 gtk_toggle_button_set_active( button
, TRUE
);
497 case IMPORTER_MODE_OVERRIDE
:
498 button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "OverrideButton" ));
499 gtk_toggle_button_set_active( button
, TRUE
);
502 case IMPORTER_MODE_NO_IMPORT
:
504 button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "NoImportButton" ));
505 gtk_toggle_button_set_active( button
, TRUE
);
511 assistant_prepare( BaseAssistant
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
513 static const gchar
*thisfn
= "nact_assistant_import_assistant_prepare";
514 GtkAssistantPageType type
;
516 g_debug( "%s: window=%p, assistant=%p, page=%p",
517 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
519 type
= gtk_assistant_get_page_type( assistant
, page
);
522 case GTK_ASSISTANT_PAGE_CONFIRM
:
523 prepare_confirm( NACT_ASSISTANT_IMPORT( window
), assistant
, page
);
526 case GTK_ASSISTANT_PAGE_SUMMARY
:
527 prepare_importdone( NACT_ASSISTANT_IMPORT( window
), assistant
, page
);
536 prepare_confirm( NactAssistantImport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
538 static const gchar
*thisfn
= "nact_assistant_import_prepare_confirm";
542 GtkLabel
*confirm_label
;
544 g_debug( "%s: window=%p, assistant=%p, page=%p",
545 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
547 /* i18n: the title of the confirm page of the import assistant */
548 text
= g_strdup( _( "About to import selected files:" ));
549 tmp
= g_strdup_printf( "<b>%s</b>\n\n", text
);
553 chooser
= base_window_get_widget( BASE_WINDOW( window
), "ImportFileChooser" );
554 uris
= gtk_file_chooser_get_uris( GTK_FILE_CHOOSER( chooser
));
556 for( is
= uris
; is
; is
= is
->next
){
557 tmp
= g_strdup_printf( "%s\t%s\n", text
, ( gchar
* ) is
->data
);
562 tmp
= add_import_mode( window
, text
);
566 confirm_label
= GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "AssistantImportConfirmLabel" ));
567 gtk_label_set_markup( confirm_label
, text
);
570 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
574 get_import_mode( NactAssistantImport
*window
)
576 GtkToggleButton
*no_import_button
;
577 GtkToggleButton
*renumber_button
;
578 GtkToggleButton
*override_button
;
579 GtkToggleButton
*ask_button
;
582 no_import_button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "NoImportButton" ));
583 renumber_button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "RenumberButton" ));
584 override_button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "OverrideButton" ));
585 ask_button
= GTK_TOGGLE_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "AskButton" ));
587 mode
= IMPORTER_MODE_NO_IMPORT
;
588 if( gtk_toggle_button_get_active( renumber_button
)){
589 mode
= IMPORTER_MODE_RENUMBER
;
591 } else if( gtk_toggle_button_get_active( override_button
)){
592 mode
= IMPORTER_MODE_OVERRIDE
;
594 } else if( gtk_toggle_button_get_active( ask_button
)){
595 mode
= IMPORTER_MODE_ASK
;
602 add_import_mode( NactAssistantImport
*window
, const gchar
*text
)
605 gchar
*label1
, *label2
, *label3
;
608 mode
= get_import_mode( window
);
614 case IMPORTER_MODE_NO_IMPORT
:
615 label1
= na_core_utils_str_remove_char( gtk_button_get_label( GTK_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "NoImportButton" ))), "_" );
616 label2
= g_strdup( gtk_label_get_text( GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "NoImportLabel"))));
619 case IMPORTER_MODE_RENUMBER
:
620 label1
= na_core_utils_str_remove_char( gtk_button_get_label( GTK_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "RenumberButton" ))), "_" );
621 label2
= g_strdup( gtk_label_get_text( GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "RenumberLabel"))));
624 case IMPORTER_MODE_OVERRIDE
:
625 label1
= na_core_utils_str_remove_char( gtk_button_get_label( GTK_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "OverrideButton" ))), "_" );
626 label2
= g_strdup( gtk_label_get_text( GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "OverrideLabel"))));
629 case IMPORTER_MODE_ASK
:
630 label1
= na_core_utils_str_remove_char( gtk_button_get_label( GTK_BUTTON( base_window_get_widget( BASE_WINDOW( window
), "AskButton" ))), "_" );
631 label2
= g_strdup( gtk_label_get_text( GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "AskLabel"))));
639 label3
= na_core_utils_str_add_prefix( "\t", label2
);
642 result
= g_strdup_printf( "%s\n\n<b>%s</b>\n\n%s", text
, label1
, label3
);
654 assistant_apply( BaseAssistant
*wnd
, GtkAssistant
*assistant
)
656 static const gchar
*thisfn
= "nact_assistant_import_assistant_apply";
657 NactAssistantImport
*window
;
658 NAImporterParms import_parms
;
660 BaseWindow
*main_window
;
662 GList
*imported_items
;
663 NAImporterResult
*result
;
664 NactApplication
*application
;
667 g_return_if_fail( NACT_IS_ASSISTANT_IMPORT( wnd
));
669 g_debug( "%s: window=%p, assistant=%p", thisfn
, ( void * ) wnd
, ( void * ) assistant
);
670 window
= NACT_ASSISTANT_IMPORT( wnd
);
672 imported_items
= NULL
;
673 memset( &import_parms
, '\0', sizeof( NAImporterParms
));
675 g_object_get( G_OBJECT( wnd
), BASE_WINDOW_PROP_PARENT
, &main_window
, NULL
);
676 import_parms
.parent
= base_window_get_toplevel( main_window
);
678 chooser
= base_window_get_widget( BASE_WINDOW( window
), "ImportFileChooser" );
679 import_parms
.uris
= gtk_file_chooser_get_uris( GTK_FILE_CHOOSER( chooser
));
680 import_parms
.mode
= get_import_mode( window
);
682 import_parms
.check_fn
= ( NAIImporterCheckFn
) check_for_existence
;
683 import_parms
.check_fn_data
= main_window
;
685 application
= NACT_APPLICATION( base_window_get_application( main_window
));
686 updater
= nact_application_get_updater( application
);
687 na_importer_import_from_list( NA_PIVOT( updater
), &import_parms
);
689 for( it
= import_parms
.results
; it
; it
= it
->next
){
690 result
= ( NAImporterResult
* ) it
->data
;
692 if( result
->imported
){
693 na_object_check_status( result
->imported
);
694 imported_items
= g_list_prepend( imported_items
, result
->imported
);
699 * getting results in the same order than uris
700 * simultaneously building the actions list
703 for( is
= uris
; is
; is
= is
->next
){
706 parms
.uri
= ( gchar
* ) is
->data
;
708 parms
.window
= base_window_get_toplevel( base_application_get_main_window( BASE_APPLICATION( application
)));
709 parms
.messages
= NULL
;
710 parms
.imported
= NULL
;
712 code
= na_importer_import_from_uri( NA_PIVOT( updater
), &parms
);
714 str
= g_new0( ImportUriStruct
, 1 );
715 str
->uri
= g_strdup( parms
.uri
);
716 str
->item
= parms
.imported
;
717 str
->msg
= na_core_utils_slist_duplicate( parms
.messages
);
718 na_core_utils_slist_free( parms
.messages
);
721 na_object_check_status( str
->item
);
722 imported_items
= g_list_prepend( imported_items
, str
->item
);
725 window
->private->results
= g_slist_prepend( window
->private->results
, str
);
729 na_core_utils_slist_free( import_parms
.uris
);
730 window
->private->results
= import_parms
.results
;
732 /* then insert the list
733 * assuring that actions will be inserted in the same order as uris
735 imported_items
= g_list_reverse( imported_items
);
736 nact_iactions_list_bis_insert_items( NACT_IACTIONS_LIST( main_window
), imported_items
, NULL
);
737 na_object_unref_items( imported_items
);
740 static NAObjectItem
*
741 check_for_existence( const NAObjectItem
*item
, NactMainWindow
*window
)
743 static const gchar
*thisfn
= "nact_assistant_import_check_for_existence";
744 NAObjectItem
*exists
;
747 importing_id
= na_object_get_id( item
);
748 g_debug( "%s: item=%p (%s), importing_id=%s",
749 thisfn
, ( void * ) item
, G_OBJECT_TYPE_NAME( item
), importing_id
);
751 exists
= nact_main_window_get_item( window
, importing_id
);
753 g_free( importing_id
);
759 prepare_importdone( NactAssistantImport
*window
, GtkAssistant
*assistant
, GtkWidget
*page
)
761 static const gchar
*thisfn
= "nact_assistant_import_prepare_importdone";
762 gchar
*text
, *tmp
, *text2
;
763 gchar
*bname
, *uuid
, *label
;
766 NAImporterResult
*result
;
769 GtkLabel
*summary_label
;
771 g_debug( "%s: window=%p, assistant=%p, page=%p",
772 thisfn
, ( void * ) window
, ( void * ) assistant
, ( void * ) page
);
774 /* i18n: result of the import assistant */
775 text
= g_strdup( _( "Selected files have been proceeded :" ));
776 tmp
= g_strdup_printf( "<b>%s</b>\n\n", text
);
780 for( is
= window
->private->results
; is
; is
= is
->next
){
781 result
= ( NAImporterResult
* ) is
->data
;
783 file
= g_file_new_for_uri( result
->uri
);
784 bname
= g_file_get_basename( file
);
785 g_object_unref( file
);
786 tmp
= g_strdup_printf( "%s\t%s\n", text
, bname
);
791 if( result
->imported
){
792 /* i18n: indicate that the file has been successfully imported */
793 tmp
= g_strdup_printf( "%s\t\t%s\n", text
, _( "Import OK" ));
796 uuid
= na_object_get_id( result
->imported
);
797 label
= na_object_get_label( result
->imported
);
798 /* i18n: this is the globally unique identifier and the label of the newly imported action */
799 text2
= g_strdup_printf( _( "UUID: %s\t%s" ), uuid
, label
);
802 tmp
= g_strdup_printf( "%s\t\t%s\n", text
, text2
);
807 /* i18n: indicate that the file was not imported */
808 tmp
= g_strdup_printf( "%s\t\t%s\n", text
, _( "Not imported" ));
813 /* add messages if any */
814 for( im
= result
->messages
; im
; im
= im
->next
){
815 tmp
= g_strdup_printf( "%s\t\t%s\n", text
, ( const char * ) im
->data
);
820 /* add a blank line between two actions */
821 tmp
= g_strdup_printf( "%s\n", text
);
826 summary_label
= GTK_LABEL( base_window_get_widget( BASE_WINDOW( window
), "AssistantImportSummaryLabel" ));
827 gtk_label_set_markup( summary_label
, text
);
830 mode
= get_import_mode( window
);
831 na_iprefs_set_import_mode( window
->private->gconf
, IPREFS_IMPORT_ITEMS_IMPORT_MODE
, mode
);
833 gtk_assistant_set_page_complete( assistant
, page
, TRUE
);
834 base_assistant_set_warn_on_cancel( BASE_ASSISTANT( window
), FALSE
);
835 base_assistant_set_warn_on_esc( BASE_ASSISTANT( window
), FALSE
);
839 free_results( GList
*list
)
843 for( it
= list
; it
; it
= it
->next
){
844 na_importer_free_result(( NAImporterResult
* ) it
->data
);