[nautilus-actions] Rewrite the pivot update when the item exists



commit a31a70f0cd5ba45a0b9b81c43593ed9240604f7c
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Feb 28 00:05:08 2010 +0100

    Rewrite the pivot update when the item exists

 ChangeLog                    |   12 ++++++++++++
 src/core/na-updater.c        |   31 +++++++++++++++++++++----------
 src/core/na-updater.h        |    2 +-
 src/io-gconf/nagp-writer.c   |   12 ++++++++++--
 src/nact/nact-main-menubar.c |   41 +++++++++++++++++++++++++++++++++++++----
 5 files changed, 81 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4be942a..975e7f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2009-02-27 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-updater.c:
+	* src/core/na-updater.h
+	(na_updater_add_item): Removed function.
+	(na_updater_insert_item): New function.
+
+	* src/io-gconf/nagp-writer.c (nagp_writer_write_data):
+	Fix the path of written data.
+
+	* src/nact/nact-main-menubar.c (on_new_profile_activated): 
+	Do not attach the profile as this is done by the tree model.
+	(save_item): Copy the tree item to the pivot one if it exists.
+
 	* src/core/na-object-item.c (instance_dispose):
 	Set the subitems pointer to NULL before unreffing the children.
 
diff --git a/src/core/na-updater.c b/src/core/na-updater.c
index dc74746..f21e21a 100644
--- a/src/core/na-updater.c
+++ b/src/core/na-updater.c
@@ -186,28 +186,39 @@ na_updater_new( void )
 }
 
 /**
- * na_updater_add_item:
- * @updater: this #NAUpdater instance.
- * @item: the #NAObjectItem to be added to the list.
- *
- * Adds a new item to the list.
+ * na_updater_insert_item:
+ * @updater: this #NAUpdater object.
+ * @item: a #NAObjectItem-derived object to be inserted in the tree.
+ * @parent_id: the id of the parent, or %NULL.
+ * @pos: the position in the children of the parent, starting at zero, or -1.
  *
- * We take the provided pointer. The provided @item should so not
- * be g_object_unref() by the caller.
+ * Insert a new item in the global tree.
  */
 void
-na_updater_add_item( NAUpdater *updater, const NAObjectItem *item )
+na_updater_insert_item( NAUpdater *updater, NAObjectItem *item, const gchar *parent_id, gint pos )
 {
 	GList *tree;
+	NAObjectItem *parent;
 
 	g_return_if_fail( NA_IS_UPDATER( updater ));
 	g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
 
 	if( !updater->private->dispose_has_run ){
 
+		parent = NULL;
 		g_object_get( G_OBJECT( updater ), NAPIVOT_PROP_TREE, &tree, NULL );
-		tree = g_list_append( tree, ( gpointer ) item );
-		g_object_set( G_OBJECT( updater ), NAPIVOT_PROP_TREE, &tree, NULL );
+
+		if( parent_id ){
+			parent = na_pivot_get_item( NA_PIVOT( updater ), parent_id );
+		}
+
+		if( parent ){
+			na_object_insert_at( parent, item, pos );
+
+		} else {
+			tree = g_list_append( tree, item );
+			g_object_set( G_OBJECT( updater ), NAPIVOT_PROP_TREE, &tree, NULL );
+		}
 	}
 }
 
diff --git a/src/core/na-updater.h b/src/core/na-updater.h
index 096894a..3a4eac8 100644
--- a/src/core/na-updater.h
+++ b/src/core/na-updater.h
@@ -73,7 +73,7 @@ NAUpdater *na_updater_new( void );
 
 /* update the tree in memory
  */
-void       na_updater_add_item   ( NAUpdater *updater, const NAObjectItem *item );
+void       na_updater_insert_item( NAUpdater *updater, NAObjectItem *item, const gchar *parent_id, gint pos );
 void       na_updater_remove_item( NAUpdater *updater, NAObject *item );
 
 /* read from / write to the physical storage subsystem
diff --git a/src/io-gconf/nagp-writer.c b/src/io-gconf/nagp-writer.c
index 665af09..acf42bc 100644
--- a/src/io-gconf/nagp-writer.c
+++ b/src/io-gconf/nagp-writer.c
@@ -335,7 +335,7 @@ nagp_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
 	guint code;
 	NADataDef *def;
 	gchar *id;
-	gchar *parent_path, *path;
+	gchar *parent_path, *dir_path, *path;
 	gchar *msg;
 	gchar *str_value;
 	gboolean bool_value;
@@ -343,6 +343,8 @@ nagp_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
 	guint uint_value;
 	GConfClient *gconf;
 
+	/*g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));*/
+
 	msg = NULL;
 	code = NA_IIO_PROVIDER_CODE_OK;
 	def = na_data_boxed_get_data_def( boxed );
@@ -353,9 +355,11 @@ nagp_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
 			(( WriterData * ) writer_data )->parent_id ?
 					(( WriterData * ) writer_data )->parent_id : id );
 
-	path = (( WriterData * ) writer_data )->parent_id ?
+	dir_path = (( WriterData * ) writer_data )->parent_id ?
 					gconf_concat_dir_and_key( parent_path, id ) : g_strdup( parent_path );
 
+	path = gconf_concat_dir_and_key( dir_path, def->gconf_entry );
+
 	gconf = NAGP_GCONF_PROVIDER( provider )->private->gconf;
 
 	switch( def->type ){
@@ -404,6 +408,8 @@ nagp_writer_write_data( const NAIFactoryProvider *provider, void *writer_data,
 			code = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR;
 	}
 
+	/*g_debug( "%s: gconf=%p, code=%u, path=%s", thisfn, ( void * ) gconf, code, path );*/
+
 	g_free( msg );
 	g_free( path );
 	g_free( parent_path );
@@ -440,6 +446,8 @@ nagp_writer_write_done( const NAIFactoryProvider *writer, void *writer_data,
 		}
 	}
 
+	gconf_client_suggest_sync( NAGP_GCONF_PROVIDER( writer )->private->gconf, NULL );
+
 	return( code );
 }
 
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 506bf0b..5378449 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -36,6 +36,7 @@
 
 #include <api/na-object-api.h>
 
+#include <core/na-factory-object.h>
 #include <core/na-iabout.h>
 #include <core/na-iprefs.h>
 #include <core/na-ipivot-consumer.h>
@@ -886,12 +887,13 @@ on_new_profile_activated( GtkAction *gtk_action, NactMainWindow *window )
 			NULL );
 
 	profile = na_object_profile_new_with_defaults();
+	na_object_set_label( profile, _( "New profile" ));
 
 	name = na_object_action_get_new_profile_name( action );
 	na_object_set_id( profile, name );
 	g_free( name );
 
-	na_object_attach_profile( action, profile );
+	/*na_object_attach_profile( action, profile );*/
 
 	na_object_check_status( profile );
 
@@ -974,10 +976,12 @@ nact_main_menubar_save_items( NactMainWindow *window )
 static void
 save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 {
+	static const gchar *thisfn = "nact_main_menubar_save_item";
 	NAObjectItem *origin;
 	NAObjectItem *dup_pivot;
 	GList *subitems, *it;
 	NAObjectItem *parent;
+	gchar *parent_id;
 	gint pos;
 	NAIOProvider *provider_before;
 	NAIOProvider *provider_after;
@@ -1002,10 +1006,36 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 				na_object_reset_last_allocated( item );
 			}
 
-			/* do not use NA_OBJECT_ITEM macro as this may return a
-			 * (valid) NULL value
-			 */
 			origin = ( NAObjectItem * ) na_object_get_origin( item );
+			g_debug( "%s: origin=%p", thisfn, ( void * ) origin );
+
+			if( origin ){
+				if( NA_IS_OBJECT_ACTION( item )){
+					subitems = na_object_get_items( origin );
+					na_object_unref_items( subitems );
+				}
+
+				g_debug( "un" );
+				na_factory_object_copy(
+						NA_IFACTORY_OBJECT( origin ), NA_IFACTORY_OBJECT( item ),
+						NA_IS_OBJECT_ACTION( item ));
+				g_debug( "deux" );
+
+			} else {
+				dup_pivot = NA_OBJECT_ITEM( na_object_duplicate( item ));
+				na_object_reset_origin( item, dup_pivot );
+
+				pos = -1;
+				parent_id = NULL;
+				parent = na_object_get_parent( item );
+				if( parent ){
+					parent_id = na_object_get_id( parent );
+					pos = na_object_get_position( parent, item );
+				}
+
+				na_updater_insert_item( updater, dup_pivot, parent_id, pos );
+			}
+#if 0
 			parent = NULL;
 			pos = -1;
 
@@ -1031,8 +1061,11 @@ save_item( NactMainWindow *window, NAUpdater *updater, NAObjectItem *item )
 			} else {
 				na_updater_add_item( updater, dup_pivot );
 			}
+#endif
 
+			g_debug( "trois" );
 			nact_iactions_list_bis_removed_modified( NACT_IACTIONS_LIST( window ), item );
+			g_debug( "quatre" );
 
 			provider_after = na_object_get_provider( item );
 			if( provider_after != provider_before ){



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