[nautilus-actions] Also checks the unicity of action against previously imported



commit ece72fcdc101788fa87903e6d67d28c7c314fa7d
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Oct 19 07:15:53 2009 +0200

    Also checks the unicity of action against previously imported

 ChangeLog                        |   11 ++++
 src/nact/nact-assistant-import.c |   32 +++++++------
 src/nact/nact-tree-model.c       |   18 ++++----
 src/nact/nact-xml-reader.c       |   97 ++++++++++++++++++++++++--------------
 src/nact/nact-xml-reader.h       |    2 +-
 5 files changed, 101 insertions(+), 59 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f5f084b..373decc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2009-10-19 Pierre Wieser <pwieser trychlos org>
 
+	* src/nact/nact-assistant-import.c
+	(assistant_apply): Also checks the existancy against already imported.
+	(prepare_importdone): Actually states that the import was successfull.
+
+	* src/nact/nact-tree-model.c
+	(drop_uri_list): Also checks the existancy against already imported.
+
+	* src/nact/nact-xml-reader.c:
+	* src/nact/nact-xml-reader.h (nact_xml_reader_import):
+	Also checks the existancy against already imported.
+
 	* src/common/na-utils.c (na_utils_prefix_strings):
 	Fix concatenation of prefixed strings.
 
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index ac60242..ca59494 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -657,13 +657,15 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 
 	g_object_get( G_OBJECT( wnd ), BASE_WINDOW_PROP_PARENT, &mainwnd, NULL );
 
-	/* first import actions
+	/* import actions
 	 * getting results in the same order than uris
+	 * simultaneously building the actions list
 	 */
+	items = NULL;
 	for( is = uris ; is ; is = is->next ){
 
 		msg = NULL;
-		action = nact_xml_reader_import( BASE_WINDOW( window ), ( const gchar * ) is->data, mode, &msg );
+		action = nact_xml_reader_import( BASE_WINDOW( window ), items, ( const gchar * ) is->data, mode, &msg );
 
 		str = g_new0( ImportUriStruct, 1 );
 		str->uri = g_strdup(( const gchar * ) is->data );
@@ -671,22 +673,19 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 		str->msg = na_utils_duplicate_string_list( msg );
 		na_utils_free_string_list( msg );
 
+		if( str->action ){
+			na_object_check_status( str->action );
+			items = g_list_prepend( items, str->action );
+		}
+
 		window->private->results = g_slist_prepend( window->private->results, str );
 	}
 	na_utils_free_string_list( uris );
 	window->private->results = g_slist_reverse( window->private->results );
 
-	/* then insert them in the list
+	/* then insert the list
 	 * assuring that actions will be inserted in the same order as uris
 	 */
-	items = NULL;
-	for( is = window->private->results ; is ; is = is->next ){
-		str = ( ImportUriStruct * ) is->data;
-		if( str->action ){
-			na_object_check_status( str->action );
-			items = g_list_prepend( items, str->action );
-		}
-	}
 	items = g_list_reverse( items );
 	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( mainwnd ), items, NULL );
 	na_object_free_items_list( items );
@@ -729,6 +728,10 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 		g_free( bname );
 
 		if( str->action ){
+			/* i18n: indicate that the file has been successfully imported */
+			tmp = g_strdup_printf( "%s\t\t%s\n", text, _( "Import OK" ));
+			g_free( text );
+			text = tmp;
 			uuid = na_object_get_id( str->action );
 			label = na_object_get_label( str->action );
 			/* i18n: this is the globally unique identifier and the label of the newly imported action */
@@ -736,17 +739,18 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 			g_free( label );
 			g_free( uuid );
 			tmp = g_strdup_printf( "%s\t\t%s\n", text, text2 );
+			g_free( text );
+			text = tmp;
 
 			window->private->actions = g_slist_prepend( window->private->actions, str->action );
 
 		} else {
 			/* i18n: indicate that the file was not iported */
 			tmp = g_strdup_printf( "%s\t\t%s\n", text, _( "Not imported" ));
+			g_free( text );
+			text = tmp;
 		}
 
-		g_free( text );
-		text = tmp;
-
 		/* add messages if any */
 		for( im = str->msg ; im ; im = im->next ){
 			tmp = g_strdup_printf( "%s\t\t%s\n", text, ( const char * ) im->data );
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 8804e95..34db836 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -1717,10 +1717,12 @@ drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selec
 	uri_list = g_slist_reverse( na_utils_lines_to_string_list(( const gchar * ) selection_data->data ));
 	import_mode = na_iprefs_get_import_mode( NA_IPREFS( pivot ), IPREFS_IMPORT_ACTIONS_IMPORT_MODE );
 
+	object_list = NULL;
 	for( is = uri_list ; is ; is = is->next ){
 
 		action = nact_xml_reader_import(
 				model->private->window,
+				object_list,
 				( const gchar * ) is->data,
 				import_mode,
 				&msg );
@@ -1733,22 +1735,20 @@ drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selec
 					msg->data );
 			na_utils_free_string_list( msg );
 
-		} else {
-			g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), FALSE );
-			object_list = g_list_prepend( NULL, action );
-			na_object_dump( action );
-			na_object_check_status( action );
-			nact_iactions_list_insert_at_path( NACT_IACTIONS_LIST( main_window ), object_list, new_dest );
-			g_list_free( object_list );
-			drop_done = TRUE;
 		}
 
 		if( action ){
 			g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), FALSE );
-			na_object_unref( action );
+			object_list = g_list_prepend( object_list, action );
+			na_object_check_status( action );
+			na_object_dump( action );
+			drop_done = TRUE;
 		}
 	}
 
+	nact_iactions_list_insert_at_path( NACT_IACTIONS_LIST( main_window ), object_list, new_dest );
+	na_object_free_items_list( object_list );
+
 	gtk_tree_path_free( new_dest );
 	nact_tree_model_dump( model );
 	na_utils_free_string_list( uri_list );
diff --git a/src/nact/nact-xml-reader.c b/src/nact/nact-xml-reader.c
index 10bed94..c213b63 100644
--- a/src/nact/nact-xml-reader.c
+++ b/src/nact/nact-xml-reader.c
@@ -67,6 +67,7 @@ struct NactXMLReaderPrivate {
 	BaseWindow      *window;
 	gint             import_mode;
 	const gchar     *uri;
+	GList           *auxiliaries;
 	NAObjectAction  *action;			/* the action that we will return, or NULL */
 	GSList          *messages;
 	gboolean         uuid_set;			/* set at first uuid, then checked against */
@@ -129,40 +130,41 @@ static GConfReaderStruct reader_str[] = {
 
 static GObjectClass *st_parent_class = NULL;
 
-static GType    register_type( void );
-static void     class_init( NactXMLReaderClass *klass );
-static void     instance_init( GTypeInstance *instance, gpointer klass );
-static void     instance_dispose( GObject *object );
-static void     instance_finalize( GObject *object );
+static GType          register_type( void );
+static void           class_init( NactXMLReaderClass *klass );
+static void           instance_init( GTypeInstance *instance, gpointer klass );
+static void           instance_dispose( GObject *object );
+static void           instance_finalize( GObject *object );
 
 static NactXMLReader *gconf_reader_new( void );
 
-static void     gconf_reader_parse_schema_root( NactXMLReader *reader, xmlNode *root );
-static void     gconf_reader_parse_schemalist( NactXMLReader *reader, xmlNode *schemalist );
-static gboolean gconf_reader_parse_schema( NactXMLReader *reader, xmlNode *schema );
-static gboolean gconf_reader_parse_applyto( NactXMLReader *reader, xmlNode *node );
-static gboolean gconf_reader_check_for_entry( NactXMLReader *reader, xmlNode *node, const char *entry );
-static gboolean gconf_reader_parse_locale( NactXMLReader *reader, xmlNode *node );
-static void     gconf_reader_parse_default( NactXMLReader *reader, xmlNode *node );
-static gchar   *get_profile_name_from_schema_key( const gchar *key, const gchar *uuid );
-
-static void     gconf_reader_parse_dump_root( NactXMLReader *reader, xmlNode *root );
-static void     gconf_reader_parse_entrylist( NactXMLReader *reader, xmlNode *entrylist );
-static gboolean gconf_reader_parse_entry( NactXMLReader *reader, xmlNode *entry );
-static gboolean gconf_reader_parse_dump_key( NactXMLReader *reader, xmlNode *key );
-static void     gconf_reader_parse_dump_value( NactXMLReader *reader, xmlNode *key );
-static void     gconf_reader_parse_dump_value_list( NactXMLReader *reader, xmlNode *key );
-static gchar   *get_profile_name_from_dump_key( const gchar *key );
-
-static void     apply_values( NactXMLReader *reader );
-static void     add_message( NactXMLReader *reader, const gchar *format, ... );
-static int      strxcmp( const xmlChar *a, const char *b );
-static gchar   *get_uuid_from_key( NactXMLReader *reader, const gchar *key, guint line );
-static gboolean is_uuid_valid( const gchar *uuid );
-static gchar   *get_entry_from_key( const gchar *key );
-static void     free_reader_values( NactXMLReader *reader );
-static gboolean manage_import_mode( NactXMLReader *reader );
-static void     relabel( NactXMLReader *reader );
+static void           gconf_reader_parse_schema_root( NactXMLReader *reader, xmlNode *root );
+static void           gconf_reader_parse_schemalist( NactXMLReader *reader, xmlNode *schemalist );
+static gboolean       gconf_reader_parse_schema( NactXMLReader *reader, xmlNode *schema );
+static gboolean       gconf_reader_parse_applyto( NactXMLReader *reader, xmlNode *node );
+static gboolean       gconf_reader_check_for_entry( NactXMLReader *reader, xmlNode *node, const char *entry );
+static gboolean       gconf_reader_parse_locale( NactXMLReader *reader, xmlNode *node );
+static void           gconf_reader_parse_default( NactXMLReader *reader, xmlNode *node );
+static gchar         *get_profile_name_from_schema_key( const gchar *key, const gchar *uuid );
+
+static void           gconf_reader_parse_dump_root( NactXMLReader *reader, xmlNode *root );
+static void           gconf_reader_parse_entrylist( NactXMLReader *reader, xmlNode *entrylist );
+static gboolean       gconf_reader_parse_entry( NactXMLReader *reader, xmlNode *entry );
+static gboolean       gconf_reader_parse_dump_key( NactXMLReader *reader, xmlNode *key );
+static void           gconf_reader_parse_dump_value( NactXMLReader *reader, xmlNode *key );
+static void           gconf_reader_parse_dump_value_list( NactXMLReader *reader, xmlNode *key );
+static gchar         *get_profile_name_from_dump_key( const gchar *key );
+
+static void           apply_values( NactXMLReader *reader );
+static void           add_message( NactXMLReader *reader, const gchar *format, ... );
+static int            strxcmp( const xmlChar *a, const char *b );
+static gchar         *get_uuid_from_key( NactXMLReader *reader, const gchar *key, guint line );
+static gboolean       is_uuid_valid( const gchar *uuid );
+static gchar         *get_entry_from_key( const gchar *key );
+static void           free_reader_values( NactXMLReader *reader );
+static gboolean       manage_import_mode( NactXMLReader *reader );
+static NAObjectItem  *search_in_auxiliaries( NactXMLReader *reader, const gchar *uuid );
+static void           relabel( NactXMLReader *reader );
 
 GType
 nact_xml_reader_get_type( void )
@@ -295,17 +297,20 @@ gconf_reader_new( void )
 
 /**
  * nact_xml_reader_import:
- * window: the #NactAssistantImport instance.
+ * @window: the #NactAssistantImport instance.
+ * @items: an auxiliary list of NAObjectItems in which the existancy of
+ *  the imported action could be checked ; this typically correspond to
+ *  actions which were previously imported in the assistant
  * @uri: the uri of the file to import.
- * import_mode: the import mode.
- * msg: a list of error messages which may be set by this function.
+ * @import_mode: the import mode.
+ * @msg: a list of error messages which may be set by this function.
  *
  * Import the specified file as an NAAction XML description.
  *
  * Returns: the imported action, or NULL.
  */
 NAObjectAction *
-nact_xml_reader_import( BaseWindow *window, const gchar *uri, gint import_mode, GSList **msg )
+nact_xml_reader_import( BaseWindow *window, GList *items, const gchar *uri, gint import_mode, GSList **msg )
 {
 	static const gchar *thisfn = "nact_xml_reader_import";
 	NAObjectAction *action = NULL;
@@ -319,6 +324,7 @@ nact_xml_reader_import( BaseWindow *window, const gchar *uri, gint import_mode,
 	reader->private->window = window;
 	reader->private->import_mode = import_mode;
 	reader->private->uri = uri;
+	reader->private->auxiliaries = items;
 
 	g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
 
@@ -1278,6 +1284,9 @@ manage_import_mode( NactXMLReader *reader )
 
 	uuid = na_object_get_id( reader->private->action );
 	exists = nact_main_window_get_item( main_window, uuid );
+	if( !exists ){
+		exists = search_in_auxiliaries( reader, uuid );
+	}
 
 	if( !exists ){
 		g_free( uuid );
@@ -1320,6 +1329,24 @@ manage_import_mode( NactXMLReader *reader )
 	return( ret );
 }
 
+static NAObjectItem *
+search_in_auxiliaries( NactXMLReader *reader, const gchar *uuid )
+{
+	NAObjectItem *action;
+	gchar *aux_uuid;
+	GList *it;
+
+	action = NULL;
+	for( it = reader->private->auxiliaries ; it && !action ; it = it->next ){
+		aux_uuid = na_object_get_id( it->data );
+		if( !strcmp( aux_uuid, uuid )){
+			action = NA_OBJECT_ITEM( it->data );
+		}
+		g_free( aux_uuid );
+	}
+	return( action );
+}
+
 /*
  * set a new label because the action has been renumbered
  */
diff --git a/src/nact/nact-xml-reader.h b/src/nact/nact-xml-reader.h
index a72537b..a51fe1c 100644
--- a/src/nact/nact-xml-reader.h
+++ b/src/nact/nact-xml-reader.h
@@ -70,7 +70,7 @@ typedef struct {
 
 GType           nact_xml_reader_get_type( void );
 
-NAObjectAction *nact_xml_reader_import( BaseWindow *window, const gchar *uri, gint mode, GSList **msg );
+NAObjectAction *nact_xml_reader_import( BaseWindow *window, GList *items, const gchar *uri, gint mode, GSList **msg );
 
 G_END_DECLS
 



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