[nautilus-actions] Uses na_importer_import_from_list() when dropping into NACT



commit 5bdad514829823c9899008cf2075451d4129685e
Author: pierre <pierre vfedora10 virtuals pwi>
Date:   Mon Mar 1 17:57:58 2010 +0100

    Uses na_importer_import_from_list() when dropping into NACT

 ChangeLog                        |    8 +++
 src/nact/nact-assistant-import.c |   27 ++++-----
 src/nact/nact-tree-model-dnd.c   |  120 +++++++++++++++++++++++---------------
 3 files changed, 91 insertions(+), 64 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a9b6c60..4d7eab9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2009-03-01 Pierre Wieser <pwieser trychlos org>
 
+	* src/nact/nact-assistant-import.c
+	(check_for_existance): Directly use the main window.
+
+	* src/nact/nact-tree-model-dnd.c (drop_uri_list):
+	Adapt to use na_importer_import_from_list() function.
+	Display messages in a dialog box.
+	Split the selection data on a '\r\n' separator.
+
 	* src/api/na-iimporter.h (NAIImporterListParms): New structure.
 
 	* src/core/na-importer.c:
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index 4f32d5f..ef27c8d 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -78,8 +78,8 @@ typedef struct {
 /* a structure to check for existance of imported items
  */
 typedef struct {
-	NactAssistantImport *assistant;
-	GList               *imported;
+	NactMainWindow *window;
+	GList          *imported;
 }
 	ImportCheck;
 
@@ -693,7 +693,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( wnd )));
 	updater = nact_application_get_updater( application );
 	imported_items = NULL;
-	check_str.assistant = window;
+	check_str.window = NACT_MAIN_WINDOW( mainwnd );
 	check_str.imported = imported_items;
 
 	/* import actions
@@ -708,7 +708,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 		parms.window = base_window_get_toplevel( base_application_get_main_window( BASE_APPLICATION( application )));
 		parms.messages = NULL;
 		parms.imported = NULL;
-		parms.check_fn = ( NAIImporterCheckFn ) &check_for_existance;
+		parms.check_fn = ( NAIImporterCheckFn ) check_for_existance;
 		parms.check_fn_data = &check_str;
 
 		code = na_importer_import_from_uri( NA_PIVOT( updater ), &parms );
@@ -741,33 +741,28 @@ static NAObjectItem *
 check_for_existance( const NAObjectItem *item, ImportCheck *check )
 {
 	NAObjectItem *exists;
-	NactApplication *application;
-	NactMainWindow *main_window;
 	GList *ip;
 
 	exists = NULL;
-	gchar *current_id = na_object_get_id( item );
-	g_debug( "nact_assistant_import_check_for_existance: current_id=%s", current_id );
+	gchar *importing_id = na_object_get_id( item );
+	g_debug( "nact_assistant_import_check_for_existance: item=%p (%s), importing_id=%s",
+			( void * ) item, G_OBJECT_TYPE_NAME( item ), importing_id );
 
-	/* is the imported item already in the current importation list ?
+	/* is the importing item already in the current importation list ?
 	 */
 	for( ip = check->imported ; ip && !exists ; ip = ip->next ){
 		gchar *id = na_object_get_id( ip->data );
-		if( !strcmp( current_id, id )){
+		if( !strcmp( importing_id, id )){
 			exists = NA_OBJECT_ITEM( ip->data );
 		}
 		g_free( id );
 	}
 
-	/* else, is it in the main window list ?
-	 */
 	if( !exists ){
-		application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( check->assistant )));
-		main_window = NACT_MAIN_WINDOW( base_application_get_main_window( BASE_APPLICATION( application )));
-		exists = nact_main_window_get_item( main_window, current_id );
+		exists = nact_main_window_get_item( check->window, importing_id );
 	}
 
-	g_free( current_id );
+	g_free( importing_id );
 
 	return( exists );
 }
diff --git a/src/nact/nact-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c
index 2d37c65..07002c3 100644
--- a/src/nact/nact-tree-model-dnd.c
+++ b/src/nact/nact-tree-model-dnd.c
@@ -121,13 +121,14 @@ static const gchar *st_refuse_action_menu = N_( "Unable to drop an action or a m
 static const gchar *st_parent_not_writable = N_( "Unable to drop here as parent is not writable" );
 static const gchar *st_level_zero_not_writable = N_( "Unable to drop here as level zero is not writable" );
 
-static gboolean     drop_inside( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selection_data );
-static GtkTreePath *drop_inside_adjust_dest( NactTreeModel *model, GtkTreePath *dest, NAObjectAction **parent );
-static void         drop_inside_move_dest( NactTreeModel *model, GList *rows, GtkTreePath **dest );
-static gboolean     drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selection_data );
-static char        *get_xds_atom_value( GdkDragContext *context );
-static gboolean     is_parent_accept_new_childs( NactTreeModel *model, GtkTreePath *path );
-static guint        target_atom_to_id( GdkAtom atom );
+static gboolean      drop_inside( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selection_data );
+static GtkTreePath  *drop_inside_adjust_dest( NactTreeModel *model, GtkTreePath *dest, NAObjectAction **parent );
+static void          drop_inside_move_dest( NactTreeModel *model, GList *rows, GtkTreePath **dest );
+static gboolean      drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selection_data );
+static NAObjectItem *is_dropped_already_exists( const NAObjectItem *importing, const NactMainWindow *window );
+static char         *get_xds_atom_value( GdkDragContext *context );
+static gboolean      is_parent_accept_new_childs( NactTreeModel *model, GtkTreePath *path );
+static guint         target_atom_to_id( GdkAtom atom );
 
 /**
  * nact_tree_model_dnd_idrag_dest_drag_data_received:
@@ -747,74 +748,97 @@ static gboolean
 drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selection_data )
 {
 	/*static const gchar *thisfn = "nact_tree_model_drop_uri_list";*/
-	gboolean drop_done = FALSE;
-	GSList *uri_list, *is;
+	gboolean drop_done;
+	GtkTreePath *new_dest;
 	NactApplication *application;
 	NAUpdater *updater;
-	guint import_mode;
 	NactMainWindow *main_window;
-	GtkTreePath *new_dest;
-	GList *object_list;
-	NAIImporterUriParms parms;
-	guint code;
+	NAIImporterListParms parms;
 	GConfClient *gconf;
+	GList *it;
 
-	application = NACT_APPLICATION( base_window_get_application( model->private->window ));
-	updater = nact_application_get_updater( application );
-	main_window = NACT_MAIN_WINDOW( base_application_get_main_window( BASE_APPLICATION( application )));
-
+	drop_done = FALSE;
 	model->private->drag_has_profiles = FALSE;
 	new_dest = drop_inside_adjust_dest( model, dest, NULL );
+
 	if( !new_dest ){
 		return( drop_done );
 	}
 
-	uri_list = g_slist_reverse( na_core_utils_slist_from_split(( const gchar * ) selection_data->data, "\n" ));
+	application = NACT_APPLICATION( base_window_get_application( model->private->window ));
+	updater = nact_application_get_updater( application );
+	main_window = NACT_MAIN_WINDOW( base_application_get_main_window( BASE_APPLICATION( application )));
+
+	parms.version = 1;
+	g_debug( "%s", ( const gchar * ) selection_data->data );
+	parms.uris = g_slist_reverse( na_core_utils_slist_from_split(( const gchar * ) selection_data->data, "\r\n" ));
+
 	gconf = gconf_client_get_default();
-	import_mode = na_iprefs_get_import_mode( gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE );
+	parms.mode = na_iprefs_get_import_mode( gconf, IPREFS_IMPORT_ITEMS_IMPORT_MODE );
 	g_object_unref( gconf );
-	object_list = NULL;
 
-	for( is = uri_list ; is ; is = is->next ){
+	parms.window = base_window_get_toplevel( BASE_WINDOW( main_window ));
+	parms.imported = NULL;
+	parms.check_fn = ( NAIImporterCheckFn ) is_dropped_already_exists;
+	parms.check_fn_data = main_window;
+	parms.messages = NULL;
 
-		parms.version = 1;
-		parms.uri = ( gchar * ) is->data;
-		parms.mode = import_mode;
-		parms.messages = NULL;
-		parms.imported = NULL;
-		parms.check_fn = NULL;
-		parms.check_fn_data = NULL;
+	na_importer_import_from_list( NA_PIVOT( updater ), &parms );
 
-		code = na_importer_import_from_uri( NA_PIVOT( updater ), &parms );
+	/* display first message in status bar
+	 */
+	if( parms.messages ){
+		nact_main_statusbar_display_with_timeout(
+				main_window,
+				TREE_MODEL_STATUSBAR_CONTEXT,
+				parms.messages->data );
+	}
 
-		if( parms.messages ){
-			main_window = NACT_MAIN_WINDOW( base_application_get_main_window( BASE_APPLICATION( application )));
-			nact_main_statusbar_display_with_timeout(
-					main_window,
-					TREE_MODEL_STATUSBAR_CONTEXT,
-					parms.messages->data );
-			na_core_utils_slist_free( parms.messages );
+	/* if there is more than one message, display them in a dialog box
+	 */
+	if( parms.messages && g_slist_length( parms.messages ) >= 2 ){
+		GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG( gtk_message_dialog_new(
+				parms.window,
+				GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
+				"%s", _( "Some messages have occurred during drop operation." )));
+		GString *str = g_string_new( "" );
+		GSList *im;
+		for( im = parms.messages ; im ; im = im->next ){
+			g_string_append_printf( str, "%s\n", ( const gchar * ) im->data );
 		}
+		gtk_message_dialog_format_secondary_markup( dialog, "%s", str->str );
+		g_string_free( str, TRUE );
+	}
 
-		if( parms.imported ){
-			g_return_val_if_fail( NA_IS_OBJECT_ITEM( parms.imported ), FALSE );
-			object_list = g_list_prepend( object_list, parms.imported );
-			na_object_check_status( parms.imported );
-			na_object_dump( parms.imported );
-			drop_done = TRUE;
-		}
+	/* check status of newly imported items, and insert them in the list view
+	 */
+	for( it = parms.imported ; it ; it = it->next ){
+		na_object_check_status( it->data );
+		na_object_dump( it->data );
+		drop_done = TRUE;
 	}
 
-	nact_iactions_list_bis_insert_at_path( NACT_IACTIONS_LIST( main_window ), object_list, new_dest );
-	na_object_unref_items( object_list );
+	nact_iactions_list_bis_insert_at_path( NACT_IACTIONS_LIST( main_window ), parms.imported, new_dest );
+	nact_tree_model_dump( model );
 
 	gtk_tree_path_free( new_dest );
-	nact_tree_model_dump( model );
-	na_core_utils_slist_free( uri_list );
+	na_object_unref_items( parms.imported );
+	na_core_utils_slist_free( parms.uris );
+	na_core_utils_slist_free( parms.messages );
 
 	return( drop_done );
 }
 
+static NAObjectItem *
+is_dropped_already_exists( const NAObjectItem *importing, const NactMainWindow *window )
+{
+	gchar *id = na_object_get_id( importing );
+	NAObjectItem *exists = nact_main_window_get_item( window, id );
+	g_free( id );
+
+	return( exists );
+}
+
 /*
  * this function works well, but only called from on_drag_motion handler...
  */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]