[nautilus-actions] Display all valid loaded items, appending them to the hierarchy



commit aa8c087b83a57710cd7de1458e885321680003e1
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Oct 8 20:14:45 2009 +0200

    Display all valid loaded items, appending them to the hierarchy

 ChangeLog                       |   19 +++++++++++++++++++
 src/nact/nact-main-menubar.c    |    6 +++---
 src/nact/nact-window.c          |   37 -------------------------------------
 src/nact/nact-window.h          |    1 -
 src/runtime/na-gconf-provider.c |    2 +-
 src/runtime/na-iio-provider.c   |   37 ++++++++++++++++++++++++++++---------
 src/runtime/na-object-item.c    |    2 +-
 src/runtime/na-object-menu-fn.h |    4 ++--
 src/runtime/na-object-menu.c    |    8 ++++----
 src/runtime/na-object.c         |    2 +-
 src/runtime/na-pivot.c          |   33 +++++++++++++++++++++++++++++++++
 src/runtime/na-pivot.h          |    2 ++
 12 files changed, 94 insertions(+), 59 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2c9dcbb..69cfa32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2009-10-08 Pierre Wieser <pwieser trychlos org>
 
+	Items loaded from an IO provider but not recorded in the hierarchical
+	tree are yet displayed, at the end of the tree.
+
+	* src/nact/nact-window.c:
+	* src/nact/nact-window.h:
+	* src/runtime/na-pivot.c:
+	* src/runtime/na-pivot.h:
+	* src/nact/nact-main-menubar.c:
+	nact_window_write_level_zero renamed as na_pivot_write_level_zero.
+
+	* src/runtime/na-iio-provider.c (na_iio_provider_get_items_tree):
+	Merge left items in the hierarchy, and update the level-zero list.
+
+	* src/runtime/na-gconf-provider.c:
+	* src/runtime/na-object-menu-fn.h:
+	* src/runtime/na-object-menu.c:
+	na_object_menu_set_items_list renamed as
+	na_object_menu_set_items_string_list.
+
 	na_object_free_items: Renamed to na_object_free_items_list.
 
 	* src/nact/nact-assistant-export.c:
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 7d1bc8b..12edadb 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -542,13 +542,13 @@ on_save_activated( GtkAction *gtk_action, NactMainWindow *window )
 	 */
 	nact_main_window_remove_deleted( window );
 
+	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+	pivot = nact_application_get_pivot( application );
 	items = nact_iactions_list_get_items( NACT_IACTIONS_LIST( window ));
-	nact_window_write_level_zero( NACT_WINDOW( window ), items );
+	na_pivot_write_level_zero( pivot, items );
 
 	/* recursively save the valid modified items
 	 */
-	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
-	pivot = nact_application_get_pivot( application );
 	save_items( window, pivot, items );
 	g_list_free( items );
 
diff --git a/src/nact/nact-window.c b/src/nact/nact-window.c
index 798d75f..5b0174f 100644
--- a/src/nact/nact-window.c
+++ b/src/nact/nact-window.c
@@ -288,43 +288,6 @@ nact_window_delete_item( NactWindow *window, NAObjectItem *item )
 }
 
 /**
- * nact_window_write_level_zero:
- * @window: this #NactWindow-derived instance.
- * @items: full current tree of items in #NactIActionsList treeview.
- *
- * Writes as a GConf preference order and content of level zero items.
- */
-void
-nact_window_write_level_zero( NactWindow *window, GList *items )
-{
-	static const gchar *thisfn = "nact_window_write_level_zero";
-	GList *it;
-	gchar *id;
-	GSList *content;
-	NactApplication *application;
-	NAPivot *pivot;
-
-	g_debug( "%s: window=%p, items=%p (%d items)", thisfn, ( void * ) window, ( void * ) items, g_list_length( items ));
-	g_return_if_fail( NACT_IS_WINDOW( window ));
-
-	if( !window->private->dispose_has_run ){
-
-		content = NULL;
-		for( it = items ; it ; it = it->next ){
-			id = na_object_get_id( it->data );
-			content = g_slist_prepend( content, id );
-		}
-		content = g_slist_reverse( content );
-
-		application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
-		pivot = nact_application_get_pivot( application );
-		na_iprefs_set_level_zero_items( NA_IPREFS( pivot ), content );
-
-		na_utils_free_string_list( content );
-	}
-}
-
-/**
  * nact_window_count_level_zero_items:
  */
 void
diff --git a/src/nact/nact-window.h b/src/nact/nact-window.h
index cb0ab48..91a4c6d 100644
--- a/src/nact/nact-window.h
+++ b/src/nact/nact-window.h
@@ -77,7 +77,6 @@ NAPivot *nact_window_get_pivot( NactWindow *window );
 gboolean nact_window_save_item( NactWindow *window, NAObjectItem *item );
 gboolean nact_window_delete_item( NactWindow *window, NAObjectItem *item );
 
-void     nact_window_write_level_zero( NactWindow *window, GList *items );
 void     nact_window_count_level_zero_items( GList *items, guint *actions, guint *profiles, guint *menus );
 
 gboolean nact_window_warn_modified( NactWindow *window );
diff --git a/src/runtime/na-gconf-provider.c b/src/runtime/na-gconf-provider.c
index fddbc6e..37b4823 100644
--- a/src/runtime/na-gconf-provider.c
+++ b/src/runtime/na-gconf-provider.c
@@ -699,7 +699,7 @@ read_item_menu_properties( NAGConfProvider *provider, GSList *entries, NAObjectM
 	read_object_item_properties( provider, entries, NA_OBJECT_ITEM( menu ) );
 
 	if( na_gconf_utils_get_string_list_from_entries( entries, MENU_ITEMS_ENTRY, &items )){
-		na_object_menu_set_items_list( menu, items );
+		na_object_menu_set_items_string_list( menu, items );
 		na_utils_free_string_list( items );
 	}
 }
diff --git a/src/runtime/na-iio-provider.c b/src/runtime/na-iio-provider.c
index ccd53a6..1f1cbb5 100644
--- a/src/runtime/na-iio-provider.c
+++ b/src/runtime/na-iio-provider.c
@@ -52,7 +52,7 @@ static GType    register_type( void );
 static void     interface_base_init( NAIIOProviderInterface *klass );
 static void     interface_base_finalize( NAIIOProviderInterface *klass );
 
-static GList   *build_hierarchy( GList *tree, GSList *level_zero, gboolean list_if_empty );
+static GList   *build_hierarchy( GList **tree, GSList *level_zero, gboolean list_if_empty );
 static gint     search_item( const NAObject *obj, const gchar *uuid );
 static GList   *get_merged_items_list( const NAPivot *pivot, GList *providers );
 
@@ -173,9 +173,23 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
 		na_pivot_free_providers( providers );
 
 		level_zero = na_iprefs_get_level_zero_items( NA_IPREFS( pivot ));
-		hierarchy = build_hierarchy( merged, level_zero, TRUE );
+		hierarchy = build_hierarchy( &merged, level_zero, TRUE );
+
+		/* items that stay left in the merged list are simply appended
+		 * to the built hierarchy, and level zero is updated accordingly
+		 */
+		if( merged ){
+			g_debug( "%s: %d items left appended to the hierarchy", thisfn, g_list_length( merged ));
+			hierarchy = g_list_concat( hierarchy, merged );
+		}
+
+		if( merged || !level_zero || !g_slist_length( level_zero )){
+			g_debug( "%s: rewriting level-zero", thisfn );
+			na_pivot_write_level_zero( pivot, hierarchy );
+		}
+
 		na_utils_free_string_list( level_zero );
-		na_object_free_items_list( merged );
+		/*na_object_free_items_list( merged );*/
 
 		g_debug( "%s: tree before alphabetical reordering (if any)", thisfn );
 		na_object_dump_tree( hierarchy );
@@ -207,7 +221,7 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
  * when releasing initial merged tree
  */
 static GList *
-build_hierarchy( GList *tree, GSList *level_zero, gboolean list_if_empty )
+build_hierarchy( GList **tree, GSList *level_zero, gboolean list_if_empty )
 {
 	static const gchar *thisfn = "na_iio_provider_build_hierarchy";
 	GList *hierarchy, *it;
@@ -220,14 +234,17 @@ build_hierarchy( GList *tree, GSList *level_zero, gboolean list_if_empty )
 	if( g_slist_length( level_zero )){
 		for( ilevel = level_zero ; ilevel ; ilevel = ilevel->next ){
 			g_debug( "%s: uuid=%s", thisfn, ( gchar * ) ilevel->data );
-			it = g_list_find_custom( tree, ilevel->data, ( GCompareFunc ) search_item );
+			it = g_list_find_custom( *tree, ilevel->data, ( GCompareFunc ) search_item );
 			if( it ){
-				hierarchy = g_list_append( hierarchy, g_object_ref( it->data ));
+				hierarchy = g_list_append( hierarchy, it->data );
+
 				g_debug( "%s: uuid=%s: %s (%p) appended to hierarchy %p",
 						thisfn, ( gchar * ) ilevel->data, G_OBJECT_TYPE_NAME( it->data ), ( void * ) it->data, ( void * ) hierarchy );
 
+				*tree = g_list_remove_link( *tree, it );
+
 				if( NA_IS_OBJECT_MENU( it->data )){
-					subitems_ids = na_object_menu_get_items_list( NA_OBJECT_MENU( it->data ));
+					subitems_ids = na_object_menu_get_items_string_list( NA_OBJECT_MENU( it->data ));
 					subitems = build_hierarchy( tree, subitems_ids, FALSE );
 					na_object_set_items_list( it->data, subitems );
 					na_utils_free_string_list( subitems_ids );
@@ -239,9 +256,11 @@ build_hierarchy( GList *tree, GSList *level_zero, gboolean list_if_empty )
 	/* if level-zero list is empty, we consider that all actions go to it
 	 */
 	else if( list_if_empty ){
-		for( it = tree ; it ; it = it->next ){
-			hierarchy = g_list_append( hierarchy, g_object_ref( it->data ));
+		for( it = *tree ; it ; it = it->next ){
+			hierarchy = g_list_append( hierarchy, it->data );
 		}
+		g_list_free( *tree );
+		*tree = NULL;
 	}
 
 	return( hierarchy );
diff --git a/src/runtime/na-object-item.c b/src/runtime/na-object-item.c
index 14058ef..51284e5 100644
--- a/src/runtime/na-object-item.c
+++ b/src/runtime/na-object-item.c
@@ -285,7 +285,7 @@ instance_dispose( GObject *object )
 
 		self->private->dispose_has_run = TRUE;
 
-		na_object_item_free_items( self->private->items );
+		na_object_item_free_items_list( self->private->items );
 
 		/* chain up to the parent class */
 		if( G_OBJECT_CLASS( st_parent_class )->dispose ){
diff --git a/src/runtime/na-object-menu-fn.h b/src/runtime/na-object-menu-fn.h
index 0efdae3..f7b5e11 100644
--- a/src/runtime/na-object-menu-fn.h
+++ b/src/runtime/na-object-menu-fn.h
@@ -48,9 +48,9 @@ G_BEGIN_DECLS
 
 NAObjectMenu *na_object_menu_new( void );
 
-GSList       *na_object_menu_get_items_list( const NAObjectMenu *menu );
+GSList       *na_object_menu_get_items_string_list( const NAObjectMenu *menu );
 GSList       *na_object_menu_rebuild_items_list( const NAObjectMenu *menu );
-void          na_object_menu_set_items_list( NAObjectMenu *menu, GSList *items );
+void          na_object_menu_set_items_string_list( NAObjectMenu *menu, GSList *items );
 
 G_END_DECLS
 
diff --git a/src/runtime/na-object-menu.c b/src/runtime/na-object-menu.c
index 0149417..1151550 100644
--- a/src/runtime/na-object-menu.c
+++ b/src/runtime/na-object-menu.c
@@ -195,7 +195,7 @@ na_object_menu_new( void )
 }
 
 /**
- * na_object_menu_get_items_list:
+ * na_object_menu_get_items_string_list:
  * @menu: this #NAObjectMenu object.
  *
  * Returns: the items_ids string list, as readen from the IIOProvider.
@@ -203,7 +203,7 @@ na_object_menu_new( void )
  * The returned list should be na_utils_free_string_list() by the caller.
  */
 GSList *
-na_object_menu_get_items_list( const NAObjectMenu *menu )
+na_object_menu_get_items_string_list( const NAObjectMenu *menu )
 {
 	GSList *list = NULL;
 
@@ -254,7 +254,7 @@ na_object_menu_rebuild_items_list( const NAObjectMenu *menu )
 }
 
 /**
- * na_object_menu_set_items_list:
+ * na_object_menu_set_items_string_list:
  * @menu: this #NAObjectMenu object.
  * @items: an ordered list of UUID of subitems.
  *
@@ -264,7 +264,7 @@ na_object_menu_rebuild_items_list( const NAObjectMenu *menu )
  * be safely released by the caller after this function has returned.
  */
 void
-na_object_menu_set_items_list( NAObjectMenu *menu, GSList *items )
+na_object_menu_set_items_string_list( NAObjectMenu *menu, GSList *items )
 {
 	g_return_if_fail( NA_IS_OBJECT_MENU( menu ));
 
diff --git a/src/runtime/na-object.c b/src/runtime/na-object.c
index 8740e70..cb16fef 100644
--- a/src/runtime/na-object.c
+++ b/src/runtime/na-object.c
@@ -412,7 +412,7 @@ na_object_object_ref( NAObject *object )
 {
 	NAObject *ref = NULL;
 
-	g_return_if_fail( NA_IS_OBJECT( object ));
+	g_return_val_if_fail( NA_IS_OBJECT( object ), NULL );
 
 	if( !object->private->dispose_has_run ){
 
diff --git a/src/runtime/na-pivot.c b/src/runtime/na-pivot.c
index 3a8f58d..324031d 100644
--- a/src/runtime/na-pivot.c
+++ b/src/runtime/na-pivot.c
@@ -685,6 +685,39 @@ na_pivot_sort_alpha_desc( const NAObjectId *a, const NAObjectId *b )
 	return( -1 * na_pivot_sort_alpha_asc( a, b ));
 }
 
+/**
+ * na_pivot_write_level_zero:
+ * @pivot: this #NAPivot instance.
+ * @items: full current tree of items in #NactIActionsList treeview.
+ *
+ * Writes as a GConf preference order and content of level zero items.
+ */
+void
+na_pivot_write_level_zero( const NAPivot *pivot, GList *items )
+{
+	static const gchar *thisfn = "na_pivot_write_level_zero";
+	GList *it;
+	gchar *id;
+	GSList *content;
+
+	g_debug( "%s: pivot=%p, items=%p (%d items)", thisfn, ( void * ) pivot, ( void * ) items, g_list_length( items ));
+	g_return_if_fail( NA_IS_PIVOT( pivot ));
+
+	if( !pivot->private->dispose_has_run ){
+
+		content = NULL;
+		for( it = items ; it ; it = it->next ){
+			id = na_object_get_id( it->data );
+			content = g_slist_prepend( content, id );
+		}
+		content = g_slist_reverse( content );
+
+		na_iprefs_set_level_zero_items( NA_IPREFS( pivot ), content );
+
+		na_utils_free_string_list( content );
+	}
+}
+
 static NAObject *
 get_item_from_tree( const NAPivot *pivot, GList *tree, uuid_t uuid )
 {
diff --git a/src/runtime/na-pivot.h b/src/runtime/na-pivot.h
index ccc4a4f..d9503c8 100644
--- a/src/runtime/na-pivot.h
+++ b/src/runtime/na-pivot.h
@@ -129,6 +129,8 @@ void      na_pivot_set_automatic_reload( NAPivot *pivot, gboolean reload );
 gint      na_pivot_sort_alpha_asc( const NAObjectId *a, const NAObjectId *b );
 gint      na_pivot_sort_alpha_desc( const NAObjectId *a, const NAObjectId *b );
 
+void      na_pivot_write_level_zero( const NAPivot *pivot, GList *items );
+
 /* data passed from the storage subsystem when an action is changed
  */
 enum {



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