File: fma-assistant-import.c

package info (click to toggle)
filemanager-actions 3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 27,428 kB
  • sloc: ansic: 48,857; xml: 17,767; sh: 4,662; makefile: 1,375; lisp: 9
file content (858 lines) | stat: -rw-r--r-- 26,961 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/*
 * FileManager-Actions
 * A file-manager extension which offers configurable context menu actions.
 *
 * Copyright (C) 2005 The GNOME Foundation
 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
 * Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
 *
 * FileManager-Actions is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * FileManager-Actions is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with FileManager-Actions; see the file COPYING. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *   Frederic Ruaudel <grumz@grumz.net>
 *   Rodrigo Moya <rodrigo@gnome-db.org>
 *   Pierre Wieser <pwieser@trychlos.org>
 *   ... and many others (see AUTHORS)
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gdk/gdk.h>
#include <glib/gi18n.h>
#include <string.h>

#include <api/fma-object-api.h>
#include <api/fma-core-utils.h>

#include <core/fma-import-mode.h>
#include <core/fma-importer.h>
#include <core/fma-ioptions-list.h>
#include <core/fma-gtk-utils.h>
#include <core/fma-settings.h>

#include "fma-application.h"
#include "fma-assistant-import.h"
#include "fma-main-window.h"
#include "fma-tree-ieditable.h"

/* Import Assistant
 *
 * pos.  type     title
 * ---   -------  --------------------------------------------------
 *   0   Intro    Introduction
 *   1   Content  Selection of the files
 *   2   Content  Duplicate management: what to do with duplicates ?
 *   3   Confirm  Display the selected files before import
 *   4   Summary  Import is done: summary of the done operations
 */
enum {
	ASSIST_PAGE_INTRO = 0,
	ASSIST_PAGE_FILES_SELECTION,
	ASSIST_PAGE_DUPLICATES,
	ASSIST_PAGE_CONFIRM,
	ASSIST_PAGE_DONE
};

/* column ordering in the duplicates treeview
 */
enum {
	IMAGE_COLUMN = 0,
	LABEL_COLUMN,
	TOOLTIP_COLUMN,
	MODE_COLUMN,
	INDEX_COLUMN,
	N_COLUMN
};

/* private instance data
 */
struct _FMAAssistantImportPrivate {
	gboolean     dispose_has_run;
	GtkWidget   *file_chooser;
	GtkTreeView *duplicates_listview;
	FMAIOption  *mode;
	GList       *results;
	GList       *overridden;
};

static const gchar        *st_xmlui_filename = PKGUIDIR "/fma-assistant-import.ui";
static const gchar        *st_toplevel_name  = "ImportAssistant";
static const gchar        *st_wsp_name       = IPREFS_IMPORT_ASSISTANT_WSP;

static BaseAssistantClass *st_parent_class   = NULL;

static GType          register_type( void );
static void           class_init( FMAAssistantImportClass *klass );
static void           ioptions_list_iface_init( FMAIOptionsListInterface *iface, void *user_data );
static GList         *ioptions_list_get_modes( const FMAIOptionsList *instance, GtkWidget *container );
static void           ioptions_list_free_modes( const FMAIOptionsList *instance, GtkWidget *container, GList *modes );
static FMAIOption    *ioptions_list_get_ask_option( const FMAIOptionsList *instance, GtkWidget *container );
static void           instance_init( GTypeInstance *instance, gpointer klass );
static void           instance_dispose( GObject *application );
static void           instance_finalize( GObject *application );

static void           on_base_initialize_gtk( FMAAssistantImport *dialog );
static void           create_duplicates_treeview_model( FMAAssistantImport *dialog );
static void           on_base_initialize_base_window( FMAAssistantImport *dialog );
static void           runtime_init_intro( FMAAssistantImport *window, GtkAssistant *assistant );
static void           runtime_init_file_selector( FMAAssistantImport *window, GtkAssistant *assistant );
static void           on_file_selection_changed( GtkFileChooser *chooser, gpointer user_data );
static gboolean       has_loadable_files( GSList *uris );
static void           runtime_init_duplicates( FMAAssistantImport *window, GtkAssistant *assistant );

static void           assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page );
static void           prepare_confirm( FMAAssistantImport *window, GtkAssistant *assistant, GtkWidget *page );
static void           assistant_apply( BaseAssistant *window, GtkAssistant *assistant );
static FMAObjectItem *check_for_existence( const FMAObjectItem *, FMAMainWindow *window );
static void           prepare_importdone( FMAAssistantImport *window, GtkAssistant *assistant, GtkWidget *page );
static void           free_results( GList *list );

static GtkWidget     *find_widget_from_page( GtkWidget *page, const gchar *name );
static GtkTreeView   *get_duplicates_treeview_from_assistant_import( FMAAssistantImport *window );
static GtkTreeView   *get_duplicates_treeview_from_page( GtkWidget *page );

GType
fma_assistant_import_get_type( void )
{
	static GType window_type = 0;

	if( !window_type ){
		window_type = register_type();
	}

	return( window_type );
}

static GType
register_type( void )
{
	static const gchar *thisfn = "fma_assistant_import_register_type";
	GType type;

	static GTypeInfo info = {
		sizeof( FMAAssistantImportClass ),
		( GBaseInitFunc ) NULL,
		( GBaseFinalizeFunc ) NULL,
		( GClassInitFunc ) class_init,
		NULL,
		NULL,
		sizeof( FMAAssistantImport ),
		0,
		( GInstanceInitFunc ) instance_init
	};

	static const GInterfaceInfo ioptions_list_iface_info = {
		( GInterfaceInitFunc ) ioptions_list_iface_init,
		NULL,
		NULL
	};

	g_debug( "%s", thisfn );

	type = g_type_register_static( BASE_TYPE_ASSISTANT, "FMAAssistantImport", &info, 0 );

	g_type_add_interface_static( type, FMA_TYPE_IOPTIONS_LIST, &ioptions_list_iface_info );

	return( type );
}

static void
class_init( FMAAssistantImportClass *klass )
{
	static const gchar *thisfn = "fma_assistant_import_class_init";
	GObjectClass *object_class;
	BaseAssistantClass *assist_class;

	g_debug( "%s: klass=%p", thisfn, ( void * ) klass );

	st_parent_class = g_type_class_peek_parent( klass );

	object_class = G_OBJECT_CLASS( klass );
	object_class->dispose = instance_dispose;
	object_class->finalize = instance_finalize;

	assist_class = BASE_ASSISTANT_CLASS( klass );
	assist_class->apply = assistant_apply;
	assist_class->prepare = assistant_prepare;
}

static void
ioptions_list_iface_init( FMAIOptionsListInterface *iface, void *user_data )
{
	static const gchar *thisfn = "fma_assistant_import_ioptions_list_iface_init";

	g_debug( "%s: iface=%p, user_data=%p", thisfn, ( void * ) iface, ( void * ) user_data );

	iface->get_options = ioptions_list_get_modes;
	iface->free_options = ioptions_list_free_modes;
	iface->get_ask_option = ioptions_list_get_ask_option;
}

static GList *
ioptions_list_get_modes( const FMAIOptionsList *instance, GtkWidget *container )
{
	GList *modes;

	g_return_val_if_fail( FMA_IS_ASSISTANT_IMPORT( instance ), NULL );

	modes = fma_importer_get_modes();

	return( modes );
}

static void
ioptions_list_free_modes( const FMAIOptionsList *instance, GtkWidget *container, GList *modes )
{
	fma_importer_free_modes( modes );
}

static FMAIOption *
ioptions_list_get_ask_option( const FMAIOptionsList *instance, GtkWidget *container )
{
	return( fma_importer_get_ask_mode());
}

static void
instance_init( GTypeInstance *instance, gpointer klass )
{
	static const gchar *thisfn = "fma_assistant_import_instance_init";
	FMAAssistantImport *self;

	g_return_if_fail( FMA_IS_ASSISTANT_IMPORT( instance ));

	g_debug( "%s: instance=%p (%s), klass=%p",
			thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );

	self = FMA_ASSISTANT_IMPORT( instance );

	self->private = g_new0( FMAAssistantImportPrivate, 1 );

	self->private->results = NULL;

	base_window_signal_connect(
			BASE_WINDOW( instance ),
			G_OBJECT( instance ),
			BASE_SIGNAL_INITIALIZE_GTK,
			G_CALLBACK( on_base_initialize_gtk ));

	base_window_signal_connect(
			BASE_WINDOW( instance ),
			G_OBJECT( instance ),
			BASE_SIGNAL_INITIALIZE_WINDOW,
			G_CALLBACK( on_base_initialize_base_window ));

	self->private->dispose_has_run = FALSE;
}

static void
instance_dispose( GObject *window )
{
	static const gchar *thisfn = "fma_assistant_import_instance_dispose";
	FMAAssistantImport *self;

	g_return_if_fail( FMA_IS_ASSISTANT_IMPORT( window ));

	self = FMA_ASSISTANT_IMPORT( window );

	if( !self->private->dispose_has_run ){
		g_debug( "%s: window=%p (%s)", thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ));

		self->private->dispose_has_run = TRUE;

		/* chain up to the parent class */
		if( G_OBJECT_CLASS( st_parent_class )->dispose ){
			G_OBJECT_CLASS( st_parent_class )->dispose( window );
		}
	}
}

static void
instance_finalize( GObject *window )
{
	static const gchar *thisfn = "fma_assistant_import_instance_finalize";
	FMAAssistantImport *self;

	g_return_if_fail( FMA_IS_ASSISTANT_IMPORT( window ));

	g_debug( "%s: window=%p (%s)", thisfn, ( void * ) window, G_OBJECT_TYPE_NAME( window ));

	self = FMA_ASSISTANT_IMPORT( window );

	free_results( self->private->results );

	g_free( self->private );

	/* chain call to parent class */
	if( G_OBJECT_CLASS( st_parent_class )->finalize ){
		G_OBJECT_CLASS( st_parent_class )->finalize( window );
	}
}

/**
 * fma_assistant_import_run:
 * @main: the #FMAMainWindow parent window of this assistant.
 *
 * Run the assistant.
 */
void
fma_assistant_import_run( FMAMainWindow *main_window )
{
	FMAAssistantImport *assistant;
	gboolean esc_quit, esc_confirm;

	g_return_if_fail( FMA_IS_MAIN_WINDOW( main_window ));

	esc_quit = fma_settings_get_boolean( IPREFS_ASSISTANT_ESC_QUIT, NULL, NULL );
	esc_confirm = fma_settings_get_boolean( IPREFS_ASSISTANT_ESC_CONFIRM, NULL, NULL );

	assistant = g_object_new( FMA_TYPE_ASSISTANT_IMPORT,
			BASE_PROP_MAIN_WINDOW,     main_window,
			BASE_PROP_HAS_OWN_BUILDER, TRUE,
			BASE_PROP_XMLUI_FILENAME,  st_xmlui_filename,
			BASE_PROP_TOPLEVEL_NAME,   st_toplevel_name,
			BASE_PROP_WSP_NAME,        st_wsp_name,
			BASE_PROP_QUIT_ON_ESCAPE,  esc_quit,
			BASE_PROP_WARN_ON_ESCAPE,  esc_confirm,
			NULL );

	base_window_run( BASE_WINDOW( assistant ));
}

static void
on_base_initialize_gtk( FMAAssistantImport *dialog )
{
	static const gchar *thisfn = "fma_assistant_import_on_base_initialize_gtk";

	g_return_if_fail( FMA_IS_ASSISTANT_IMPORT( dialog ));

	if( !dialog->private->dispose_has_run ){
		g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );

		create_duplicates_treeview_model( dialog );
	}
}

static void
create_duplicates_treeview_model( FMAAssistantImport *dialog )
{
	static const gchar *thisfn = "fma_assistant_import_create_duplicates_treeview_model";

	g_return_if_fail( FMA_IS_ASSISTANT_IMPORT( dialog ));
	g_return_if_fail( !dialog->private->dispose_has_run );

	g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );

	dialog->private->duplicates_listview = get_duplicates_treeview_from_assistant_import( dialog );
	g_return_if_fail( GTK_IS_TREE_VIEW( dialog->private->duplicates_listview ));

	fma_ioptions_list_gtk_init( FMA_IOPTIONS_LIST( dialog ), GTK_WIDGET( dialog->private->duplicates_listview ), TRUE );
}

static void
on_base_initialize_base_window( FMAAssistantImport *dialog )
{
	static const gchar *thisfn = "fma_assistant_import_on_base_initialize_base_window";
	GtkAssistant *assistant;

	g_return_if_fail( FMA_IS_ASSISTANT_IMPORT( dialog ));

	if( !dialog->private->dispose_has_run ){
		g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );

		assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( dialog )));

		runtime_init_intro( dialog, assistant );
		runtime_init_file_selector( dialog, assistant );
		runtime_init_duplicates( dialog, assistant );
	}
}

static void
runtime_init_intro( FMAAssistantImport *window, GtkAssistant *assistant )
{
	static const gchar *thisfn = "fma_assistant_import_runtime_init_intro";
	GtkWidget *page;

	page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_INTRO );

	g_debug( "%s: window=%p, assistant=%p, page=%p",
			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );

	gtk_assistant_set_page_complete( assistant, page, TRUE );
}

/*
 * Starting with Gtk 3.2, the widgets of the page are no more attached
 * to the GtkAssistant, but only to the page.
 */
static void
runtime_init_file_selector( FMAAssistantImport *window, GtkAssistant *assistant )
{
	static const gchar *thisfn = "fma_assistant_import_runtime_init_file_selector";
	GtkWidget *page;
	GtkWidget *chooser;
	gchar *uri;

	page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FILES_SELECTION );
	g_return_if_fail( GTK_IS_CONTAINER( page ));

	chooser = fma_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "ImportFileChooser" );
	g_return_if_fail( GTK_IS_FILE_CHOOSER( chooser ));

	g_debug( "%s: window=%p, assistant=%p, page=%p, chooser=%p",
			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page, ( void * ) chooser );


	uri = fma_settings_get_string( IPREFS_IMPORT_ASSISTANT_URI, NULL, NULL );
	if( uri && strlen( uri )){
		gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( chooser ), uri );
	}
	g_free( uri );

	base_window_signal_connect(
			BASE_WINDOW( window ),
			G_OBJECT( chooser ),
			"selection-changed",
			G_CALLBACK( on_file_selection_changed ));

	window->private->file_chooser = chooser;

	gtk_assistant_set_page_complete( assistant, page, FALSE );
}

static void
on_file_selection_changed( GtkFileChooser *chooser, gpointer user_data )
{
	static const gchar *thisfn = "fma_assistant_import_on_file_selection_changed";
	GtkAssistant *assistant;
	gint pos;
	GSList *uris;
	gboolean enabled;
	gchar *folder;
	GtkWidget *content;

	g_assert( FMA_IS_ASSISTANT_IMPORT( user_data ));
	assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( user_data )));
	pos = gtk_assistant_get_current_page( assistant );
	if( pos == ASSIST_PAGE_FILES_SELECTION ){

		uris = gtk_file_chooser_get_uris( chooser );
		enabled = has_loadable_files( uris );

		if( enabled ){
			/*
			 * if user has selected the 'Recently used' place in the file chooser,
			 * then the current folder uri is null
			 * (Gtk+ 3.2.0, don't know before...)
			 */
			folder = gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( chooser ));
			g_debug( "%s: current folder uri=%s", thisfn, folder );
			if( folder && strlen( folder )){
				fma_settings_set_string( IPREFS_IMPORT_ASSISTANT_URI, folder );
			}
			g_free( folder );
		}

		fma_core_utils_slist_free( uris );

		content = gtk_assistant_get_nth_page( assistant, pos );
		gtk_assistant_set_page_complete( assistant, content, enabled );
		gtk_assistant_update_buttons_state( assistant );
	}
}

/*
 * enable forward button if current selection has at least one loadable file
 */
static gboolean
has_loadable_files( GSList *uris )
{
	GSList *iuri;
	gchar *uri;
	int loadables = 0;

	for( iuri = uris ; iuri ; iuri = iuri->next ){
		uri = ( gchar * ) iuri->data;

		if( !strlen( uri )){
			continue;
		}

		if( fma_core_utils_file_is_loadable( uri )){
			loadables += 1;
		}
	}

	return( loadables > 0 );
}

static void
runtime_init_duplicates( FMAAssistantImport *window, GtkAssistant *assistant )
{
	static const gchar *thisfn = "fma_assistant_import_runtime_init_duplicates";
	gchar *import_mode;
	GtkWidget *page;
	gboolean mandatory;

	g_return_if_fail( GTK_IS_TREE_VIEW( window->private->duplicates_listview ));

	g_debug( "%s: window=%p, assistant=%p",
			thisfn, ( void * ) window, ( void * ) assistant );

	import_mode = fma_settings_get_string( IPREFS_IMPORT_PREFERRED_MODE, NULL, &mandatory );
	fma_ioptions_list_set_editable(
			FMA_IOPTIONS_LIST( window ), GTK_WIDGET( window->private->duplicates_listview ),
			!mandatory );
	fma_ioptions_list_set_default(
			FMA_IOPTIONS_LIST( window ), GTK_WIDGET( window->private->duplicates_listview ),
			import_mode );
	g_free( import_mode );

	page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_DUPLICATES );
	gtk_assistant_set_page_complete( assistant, page, TRUE );
}

static void
assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page )
{
	static const gchar *thisfn = "fma_assistant_import_assistant_prepare";
	GtkAssistantPageType type;

	g_debug( "%s: window=%p, assistant=%p, page=%p",
			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );

	type = gtk_assistant_get_page_type( assistant, page );

	switch( type ){
		case GTK_ASSISTANT_PAGE_CONFIRM:
			prepare_confirm( FMA_ASSISTANT_IMPORT( window ), assistant, page );
			break;

		case GTK_ASSISTANT_PAGE_SUMMARY:
			prepare_importdone( FMA_ASSISTANT_IMPORT( window ), assistant, page );
			break;

		default:
			break;
	}
}

static void
prepare_confirm( FMAAssistantImport *window, GtkAssistant *assistant, GtkWidget *page )
{
	static const gchar *thisfn = "fma_assistant_import_prepare_confirm";
	gchar *text, *tmp;
	GSList *uris, *is;
	GtkWidget *label;
	gchar *mode_label, *label2, *mode_description;

	g_debug( "%s: window=%p, assistant=%p, page=%p",
			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );

	/* adding list of uris to import
	 */
	text = NULL;
	uris = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER( window->private->file_chooser ));
	for( is = uris ; is ; is = is->next ){
		g_debug( "%s: uri=%s", thisfn, ( const gchar * ) is->data );

		if( text ){
			tmp = g_strdup_printf( "%s\n%s", text, ( const gchar * ) is->data );
			g_free( text );
			text = tmp;

		} else {
			text = g_strdup(( const gchar * ) is->data );
		}
	}
	label = find_widget_from_page( page, "p3-ConfirmFilesList" );
	g_return_if_fail( GTK_IS_LABEL( label ));
	gtk_label_set_text( GTK_LABEL( label ), text );
	g_free( text );

	/* adding import mode
	 */
	label = find_widget_from_page( page, "p3-ConfirmImportMode" );
	g_return_if_fail( GTK_IS_LABEL( label ));
	window->private->mode = fma_ioptions_list_get_selected(
			FMA_IOPTIONS_LIST( window ), GTK_WIDGET( window->private->duplicates_listview ));
	g_return_if_fail( FMA_IS_IMPORT_MODE( window->private->mode ));
	mode_label = fma_ioption_get_label( window->private->mode );
	label2 = fma_core_utils_str_remove_char( mode_label, "_" );
	mode_description = fma_ioption_get_description( window->private->mode );
	text = g_markup_printf_escaped( "%s\n<span style=\"italic\">%s</span>", label2, mode_description );
	gtk_label_set_markup( GTK_LABEL( label ), text );
	g_free( text );
	g_free( mode_description );
	g_free( mode_label );
	g_free( label2 );

	gtk_assistant_set_page_complete( assistant, page, TRUE );
}

/*
 * do import here
 */
static void
assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
{
	static const gchar *thisfn = "fma_assistant_import_assistant_apply";
	FMAAssistantImport *window;
	FMAImporterParms importer_parms;
	BaseWindow *main_window;
	GList *import_results, *it;
	GList *insertable_items, *overridden_items;
	FMAImporterResult *result;
	FMAApplication *application;
	FMAUpdater *updater;
	FMATreeView *items_view;

	g_return_if_fail( FMA_IS_ASSISTANT_IMPORT( wnd ));

	g_debug( "%s: window=%p, assistant=%p", thisfn, ( void * ) wnd, ( void * ) assistant );

	window = FMA_ASSISTANT_IMPORT( wnd );
	g_object_get( G_OBJECT( window ), BASE_PROP_MAIN_WINDOW, &main_window, NULL );
	application = FMA_APPLICATION( base_window_get_application( BASE_WINDOW( wnd )));
	g_debug( "%s: main_window=%p (%s), application=%p (%s)",
			thisfn, main_window, main_window ? G_OBJECT_TYPE_NAME( main_window ) : "null",
			application, application ? G_OBJECT_TYPE_NAME( application ) : "null" );

	updater = fma_application_get_updater( application );

	memset( &importer_parms, '\0', sizeof( FMAImporterParms ));
	importer_parms.uris = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER( window->private->file_chooser ));
	importer_parms.check_fn = ( FMAImporterCheckFn ) check_for_existence;
	importer_parms.check_fn_data = main_window;
	importer_parms.preferred_mode = fma_import_mode_get_id( FMA_IMPORT_MODE( window->private->mode ));
	importer_parms.parent_toplevel = base_window_get_gtk_toplevel( BASE_WINDOW( wnd ));

	import_results = fma_importer_import_from_uris( FMA_PIVOT( updater ), &importer_parms );

	insertable_items = NULL;
	overridden_items = NULL;

	for( it = import_results ; it ; it = it->next ){
		result = ( FMAImporterResult * ) it->data;
		if( result->imported ){

			if( !result->exist || result->mode == IMPORTER_MODE_RENUMBER ){
				insertable_items = g_list_prepend( insertable_items, result->imported );

			} else if( result->mode == IMPORTER_MODE_OVERRIDE ){
				overridden_items = g_list_prepend( overridden_items, result->imported );
			}
		}
	}

	fma_core_utils_slist_free( importer_parms.uris );
	window->private->results = import_results;

	/* then insert the list
	 * assuring that actions will be inserted in the same order as uris
	 *
	 * the tree view (and its underlying tree store) takes a new reference
	 * on the inserted objects; the pointers so remain valid even after
	 * having released the imported_items list
	 */
	if( insertable_items ){
		insertable_items = g_list_reverse( insertable_items );
		items_view = fma_main_window_get_items_view( FMA_MAIN_WINDOW( main_window ));
		fma_tree_ieditable_insert_items( FMA_TREE_IEDITABLE( items_view ), insertable_items, NULL );
		fma_object_free_items( insertable_items );
	}

	/* contrarily, the tree store may or not take a new reference on overriding
	 * items, so do not release it here
	 */
	if( overridden_items ){
		items_view = fma_main_window_get_items_view( FMA_MAIN_WINDOW( main_window ));
		fma_tree_ieditable_set_items( FMA_TREE_IEDITABLE( items_view ), overridden_items );
		window->private->overridden = overridden_items;
	}
}

static FMAObjectItem *
check_for_existence( const FMAObjectItem *item, FMAMainWindow *window )
{
	static const gchar *thisfn = "fma_assistant_import_check_for_existence";
	FMATreeView *items_view;
	FMAObjectItem *exists;
	gchar *importing_id;

	importing_id = fma_object_get_id( item );
	g_debug( "%s: item=%p (%s), importing_id=%s",
			thisfn, ( void * ) item, G_OBJECT_TYPE_NAME( item ), importing_id );

	items_view = fma_main_window_get_items_view( window );
	exists = fma_tree_view_get_item_by_id( items_view, importing_id );

	g_free( importing_id );

	return( exists );
}

/*
 * summary page is a vbox inside of a scrolled window
 * each line in this vbox is a GtkLabel
 * Starting with 3.1.6, uri is displayed in red if an error has occured, or
 * in blue.
 */
static void
prepare_importdone( FMAAssistantImport *window, GtkAssistant *assistant, GtkWidget *page )
{
	static const gchar *thisfn = "fma_assistant_import_prepare_importdone";
	guint width;
	GtkWidget *vbox;
	GtkWidget *file_vbox, *file_uri, *file_report;
	GList *is;
	GSList *im;
	FMAImporterResult *result;
	gchar *text, *id, *item_label, *text2, *tmp;
	const gchar *color;
	gchar *mode_id;

	g_debug( "%s: window=%p, assistant=%p, page=%p",
			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );

	width = 15;
	vbox = find_widget_from_page( page, "p4-SummaryParent" );
	g_return_if_fail( GTK_IS_BOX( vbox ));

	/* for each uri
	 * 	- display the uri
	 *  - display a brief import log
	 */
	for( is = window->private->results ; is ; is = is->next ){
		result = ( FMAImporterResult * ) is->data;
		g_debug( "%s: uri=%s", thisfn, result->uri );

		/* display the uri
		 */
		file_vbox = gtk_box_new( GTK_ORIENTATION_VERTICAL, 4 );
		gtk_box_pack_start( GTK_BOX( vbox ), file_vbox, FALSE, FALSE, 0 );

		color = result->imported ? "blue" : "red";
		text = g_markup_printf_escaped( "<span foreground=\"%s\">%s</span>", color, result->uri );
		file_uri = gtk_label_new( NULL );
		gtk_label_set_markup( GTK_LABEL( file_uri ), text );
		g_free( text );
		g_object_set( G_OBJECT( file_uri ), "xalign", 0, NULL );
		g_object_set( G_OBJECT( file_uri ), "xpad", width, NULL );
		gtk_box_pack_start( GTK_BOX( file_vbox ), file_uri, FALSE, FALSE, 0 );

		/* display the import log
		 */
		if( result->imported ){
			/* i18n: indicate that the file has been successfully imported */
			text = g_strdup( _( "Import OK" ));
			id = fma_object_get_id( result->imported );
			item_label = fma_object_get_label( result->imported );
			/* i18n: this is the globally unique identifier and the label of the newly imported action */
			text2 = g_strdup_printf( _( "Id.: %s\t%s" ), id, item_label);
			g_free( item_label );
			g_free( id );
			tmp = g_strdup_printf( "%s\n%s", text, text2 );
			g_free( text );
			g_free( text2 );
			text = tmp;

		} else {
			/* i18n: indicate that the file was not imported */
			text = g_strdup( _( "Not imported" ));
		}

		/* add messages if any
		 */
		for( im = result->messages ; im ; im = im->next ){
			tmp = g_strdup_printf( "%s\n%s", text, ( const char * ) im->data );
			g_free( text );
			text = tmp;
		}

		file_report = gtk_label_new( text );
		gtk_label_set_line_wrap( GTK_LABEL( file_report ), TRUE );
		gtk_label_set_line_wrap_mode( GTK_LABEL( file_report ), PANGO_WRAP_WORD );
		g_object_set( G_OBJECT( file_report ), "xalign", 0, NULL );
		g_object_set( G_OBJECT( file_report ), "xpad", 2*width, NULL );
		gtk_box_pack_start( GTK_BOX( file_vbox ), file_report, FALSE, FALSE, 0 );
	}

	mode_id = fma_ioption_get_id( window->private->mode );
	fma_settings_set_string( IPREFS_IMPORT_PREFERRED_MODE, mode_id );
	g_free( mode_id );

	/* release here our reference on overriding items
	 */
	if( window->private->overridden ){
		fma_object_free_items( window->private->overridden );
	}

	g_object_set( G_OBJECT( window ), BASE_PROP_WARN_ON_ESCAPE, FALSE, NULL );
	gtk_assistant_set_page_complete( assistant, page, TRUE );
	gtk_widget_show_all( page );
}

static void
free_results( GList *list )
{
	GList *it;

	for( it = list ; it ; it = it->next ){
		fma_importer_free_result(( FMAImporterResult * ) it->data );
	}

	g_list_free( list );
}

static GtkWidget *
find_widget_from_page( GtkWidget *page, const gchar *name )
{
	GtkWidget *widget;

	g_return_val_if_fail( GTK_IS_CONTAINER( page ), NULL );

	widget = fma_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), name );

	return( widget );
}

static GtkTreeView *
get_duplicates_treeview_from_assistant_import( FMAAssistantImport *window )
{
	GtkAssistant *assistant;
	GtkWidget *page;

	g_return_val_if_fail( FMA_IS_ASSISTANT_IMPORT( window ), NULL );

	assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
	page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_DUPLICATES );

	return( get_duplicates_treeview_from_page( page ));
}

static GtkTreeView *
get_duplicates_treeview_from_page( GtkWidget *page )
{
	GtkWidget *listview;

	listview = find_widget_from_page( page, "p2-AskTreeView" );

	g_return_val_if_fail( GTK_IS_TREE_VIEW( listview ), NULL );

	return( GTK_TREE_VIEW( listview ));
}