[nautilus-actions] Remove na_pivot_free_items_tree() function



commit 0c304138bcd1d73ea813e249d9d776c8e7a7f612
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Sep 17 00:28:12 2009 +0200

    Remove na_pivot_free_items_tree() function

 ChangeLog                        |   59 +++++++++++++++++++++++++++++++++
 src/common/na-iio-provider.c     |   68 +++++++++++++++++++++----------------
 src/common/na-pivot.c            |   62 +++++-----------------------------
 src/common/na-pivot.h            |    6 +--
 src/nact/nact-assistant-export.c |    2 +-
 src/nact/nact-clipboard.c        |    8 ++--
 src/nact/nact-iactions-list.c    |   20 +++++++++--
 src/nact/nact-main-window.c      |   17 +++------
 src/plugin/nautilus-actions.c    |    2 +-
 9 files changed, 138 insertions(+), 106 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8de95c2..7a8a7e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -36,6 +36,9 @@
 	* src/common/na-gconf-utils.h: New file.
 	Handle some GConf general utilities.
 
+	* src/common/na-iio-provider.c: Sort each level of the tree if
+	alphabetical order display has been requested.
+
 	* src/common/na-object.h: Splitted in na-object-fn.h,
 	na-object-class.h and na-object-api.h.
 	All NAObject-derived public functions are now declared in
@@ -47,6 +50,62 @@
 	* src/common/na-object-item.h: Splitted in na-object-item-fn.h
 	and na-object-item-class.h.
 
+	* src/common/na-pivot.c:
+	* src/common/na-pivot.h:
+	Remove na_pivot_free_items_tree(), replacing it with
+	na_object_free_items().
+
+	* src/nact/base-application-class.c:
+	* src/nact/base-application-class.h:
+	Virtual function are no more prefixed by a class prefix, but local
+	implementations or these virtuals are.
+	Properties are renamed as BASE_APPLICATION_PROP_xxxx.
+
+	* src/nact/base-window-class.c:
+	* src/nact/base-window-class.h:
+	Remove not used init() and run() virtual functions.
+	Properties are renamed as BASE_WINDOW_PROP_xxxx.
+
+	* src/nact/egg-tree-multi-dnd.c: Cleanup the code.
+
+	* src/nact/nact-application.c:
+	Properties are renamed as NACT_APPLICATION_PROP_xxxx.
+
+	* src/nact/nact-assistant-export.c:
+	* src/nact/nact-assistant-export.h:
+	* src/nact/nact-assistant-import.c:
+	* src/nact/nact-assistant-import.h:
+	Now derived from BaseAssistant class.
+
+	* src/nact/base-dialog.c: New file.
+	* src/nact/base-dialog.h: New file.
+	Define the BaseDialog class.
+
+	* src/nact/nact-assistant.c: Renamed as base-assistant.c.
+	* src/nact/nact-assistant.h: Renamed as base-assistant.h.
+	Define the BaseAssistant class.
+
+	* src/nact/nact-imenubar.c: Renamed as nact-main-menubar.c.
+	* src/nact/nact-imenubar.h: Renamed as nact-main-menubar.h.
+	Remove the NactIMenubar interface.
+
+	* src/nact/nact-iprefs.c: Renamed as base-iprefs.c.
+	* src/nact/nact-iprefs.h: Renamed as base-iprefs.h.
+	Define the BaseIPrefs interface which handles all NACT preferences.
+
+	* src/nact/nact-main-tab.h: New file.
+	Handles update of the tabs of the notebook.
+
+	* src/nact/selection.c: Renamed as nact-clipboard.c.
+	* src/nact/selection.h: Renamed as nact-clipboard.h.
+
+	* src/nact/nact-statusbar.c: Renamed as nact-main-statusbar.c.
+	* src/nact/nact-statusbar.h: Renamed as nact-main-statusbar.h.
+
+	* src/common/Makefile.am:
+	* src/nact/Makefile.am:
+	* src/test/Makefile.am: Updated accordingly.
+
 2009-08-30 Pierre Wieser <pwieser trychlos org>
 
 	* data/nautilus-actions.schemas.in:
diff --git a/src/common/na-iio-provider.c b/src/common/na-iio-provider.c
index 834c342..5c2e968 100644
--- a/src/common/na-iio-provider.c
+++ b/src/common/na-iio-provider.c
@@ -57,7 +57,9 @@ static guint    try_write_item( const NAIIOProvider *instance, NAObject *item, g
 
 static gboolean do_is_willing_to_write( const NAIIOProvider *instance );
 static gboolean do_is_writable( const NAIIOProvider *instance, const NAObject *item );
-/*static gint     compare_actions_label_alpha_fn( const NAAction *a, const NAAction *b );*/
+
+static GSList  *sort_tree( const NAPivot *pivot, GSList *tree );
+static gint     compare_label_alpha_fn( const NAObjectId *a, const NAObjectId *b );
 
 /**
  * Registers the GType of this interface.
@@ -169,15 +171,18 @@ na_iio_provider_get_items_tree( const NAPivot *pivot )
 	level_zero = na_iprefs_get_level_zero_items( NA_IPREFS( pivot ));
 	alpha_order = na_iprefs_is_alphabetical_order( NA_IPREFS( pivot ));
 
-	/*if( alpha_order ){
-		actions = na_iio_provider_sort_actions( pivot, actions );
-	}*/
+	if( alpha_order ){
+		merged = sort_tree( pivot, merged );
+	}
 
 	na_utils_free_string_list( level_zero );
 
 	return( merged );
 }
 
+/*
+ * returns a concatened list of readen actions / menus
+ */
 static GSList *
 get_merged_items_list( const NAPivot *pivot, GSList *providers )
 {
@@ -207,26 +212,6 @@ get_merged_items_list( const NAPivot *pivot, GSList *providers )
 }
 
 /**
- * na_iio_provider_sort_action:
- * @pivot: the #NAPivot object which owns the list of registered I/O
- * storage providers.
- * @actions: the list of #NAAction action to be sorted.
- *
- * Sorts the list of actions in alphabetical order of their label.
- *
- * Returns: the sorted list.
- */
-/*GSList *
-na_iio_provider_sort_actions( const NAPivot *pivot, GSList *actions )
-{
-	GSList *sorted;
-
-	sorted = g_slist_sort( actions, ( GCompareFunc ) compare_actions_label_alpha_fn );
-
-	return( sorted );
-}*/
-
-/**
  * na_iio_provider_write_item:
  * @pivot: the #NAPivot object which owns the list of registered I/O
  * storage providers. if NULL, @action must already have registered
@@ -377,16 +362,41 @@ do_is_writable( const NAIIOProvider *instance, const NAObject *item )
 	return( FALSE );
 }
 
-/*static gint
-compare_actions_label_alpha_fn( const NAAction *a, const NAAction *b )
+static GSList *
+sort_tree( const NAPivot *pivot, GSList *tree )
+{
+	GSList *sorted;
+	GSList *items, *it;
+
+	sorted = g_slist_sort( tree, ( GCompareFunc ) compare_label_alpha_fn );
+
+	/* recursively sort each level of the tree
+	 */
+	for( it = sorted ; it ; it = it->next ){
+		if( NA_IS_OBJECT_ITEM( it->data )){
+			items = na_object_get_items( it->data );
+			items = sort_tree( pivot, items );
+			na_object_set_items( it->data, items );
+			na_object_free_items( items );
+		}
+	}
+
+	return( sorted );
+}
+
+static gint
+compare_label_alpha_fn( const NAObjectId *a, const NAObjectId *b )
 {
 	gchar *label_a, *label_b;
 	gint compare;
 
-	label_a = na_action_get_label( a );
-	label_b = na_action_get_label( b );
+	label_a = na_object_get_label( a );
+	label_b = na_object_get_label( b );
 
 	compare = g_utf8_collate( label_a, label_b );
 
+	g_free( label_b );
+	g_free( label_a );
+
 	return( compare );
-}*/
+}
diff --git a/src/common/na-pivot.c b/src/common/na-pivot.c
index 6b390fe..fb6d956 100644
--- a/src/common/na-pivot.c
+++ b/src/common/na-pivot.c
@@ -54,7 +54,7 @@ struct NAPivotClassPrivate {
 struct NAPivotPrivate {
 	gboolean dispose_has_run;
 
-	/* list of instances to be notified of an action modification
+	/* list of instances to be notified of repository updates
 	 * these are called 'consumers' of NAPivot
 	 */
 	GSList  *consumers;
@@ -269,7 +269,7 @@ instance_dispose( GObject *object )
 		self->private->providers = NULL;
 
 		/* release item tree */
-		na_pivot_free_items_tree( self->private->tree );
+		na_object_free_items( self->private->tree );
 		self->private->tree = NULL;
 
 		/* chain up to the parent class */
@@ -400,7 +400,7 @@ na_pivot_free_providers( GSList *providers )
 }
 
 /**
- * na_pivot_get_items_tree:
+ * na_pivot_get_items:
  * @pivot: this #NAPivot instance.
  *
  * Returns: the current configuration tree.
@@ -409,7 +409,7 @@ na_pivot_free_providers( GSList *providers )
  * be g_free(), nor g_object_unref() by the caller.
  */
 GSList *
-na_pivot_get_items_tree( const NAPivot *pivot )
+na_pivot_get_items( const NAPivot *pivot )
 {
 	g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
 	g_return_val_if_fail( !pivot->private->dispose_has_run, NULL );
@@ -418,64 +418,23 @@ na_pivot_get_items_tree( const NAPivot *pivot )
 }
 
 /**
- * na_pivot_reload_items_tree:
+ * na_pivot_reload_items:
  * @pivot: this #NAPivot instance.
  *
  * Reloads the hierarchical list of items from I/O providers.
  */
 void
-na_pivot_reload_items_tree( NAPivot *pivot )
+na_pivot_reload_items( NAPivot *pivot )
 {
 	g_return_if_fail( NA_IS_PIVOT( pivot ));
 	g_return_if_fail( !pivot->private->dispose_has_run );
 
-	if( pivot->private->tree ){
-		na_pivot_free_items_tree( pivot->private->tree );
-	}
+	na_object_free_items( pivot->private->tree );
 
 	pivot->private->tree = na_iio_provider_get_items_tree( pivot );
 }
 
 /**
- * na_pivot_get_duplicate_actions:
- * @pivot: this #NAPivot instance.
- *
- * Returns an exact copy of the current list of actions.
- *
- * Returns: a #GSList of #NAAction actions.
- * The caller should na_pivot_free_actions() after usage.
- */
-/*GSList *
-na_pivot_get_duplicate_actions( const NAPivot *pivot )
-{
-	GSList *list = NULL;
-	GSList *ia;
-
-	g_assert( NA_IS_PIVOT( pivot ));
-
-	for( ia = pivot->private->actions ; ia ; ia = ia->next ){
-		list = g_slist_prepend( list, na_object_duplicate( NA_OBJECT( ia->data )));
-	}
-
-	return( g_slist_reverse( list ));
-}*/
-
-/**
- * na_pivot_free_items_tree:
- * @list: a #GSList of #NAObjectItems to be released.
- *
- * Frees a hierarchical tree of items.
- */
-GSList *
-na_pivot_free_items_tree( GSList *tree )
-{
-	g_slist_foreach( tree, ( GFunc ) g_object_unref, NULL );
-	g_slist_free( tree );
-
-	return( NULL );
-}
-
-/**
  * na_pivot_add_item:
  * @pivot: this #NAPivot instance.
  * @item: the #NAObjectItem to be added to the list.
@@ -738,11 +697,11 @@ on_actions_changed_timeout( gpointer user_data )
 	/*static const gchar *thisfn = "na_pivot_on_actions_changed_timeout";
 	g_debug( "%s: pivot=%p", thisfn, user_data );*/
 	GTimeVal now;
-	const NAPivot *pivot;
+	NAPivot *pivot;
 	gulong diff;
 	GSList *ic;
 
-	g_assert( NA_IS_PIVOT( user_data ));
+	g_return_val_if_fail( NA_IS_PIVOT( user_data ), FALSE );
 	pivot = NA_PIVOT( user_data );
 
 	g_get_current_time( &now );
@@ -752,8 +711,7 @@ on_actions_changed_timeout( gpointer user_data )
 	}
 
 	if( pivot->private->automatic_reload ){
-		na_pivot_free_items_tree( pivot->private->tree );
-		pivot->private->tree = na_iio_provider_get_items_tree( pivot );
+		na_pivot_reload_items( pivot );
 	}
 
 	for( ic = pivot->private->consumers ; ic ; ic = ic->next ){
diff --git a/src/common/na-pivot.h b/src/common/na-pivot.h
index 33e825b..ba2cbc4 100644
--- a/src/common/na-pivot.h
+++ b/src/common/na-pivot.h
@@ -110,10 +110,8 @@ void      na_pivot_dump( const NAPivot *pivot );
 GSList   *na_pivot_get_providers( const NAPivot *pivot, GType type );
 void      na_pivot_free_providers( GSList *providers );
 
-GSList   *na_pivot_get_items_tree( const NAPivot *pivot );
-/*GSList   *na_pivot_get_duplicate_items_tree( const NAPivot *pivot );*/
-void      na_pivot_reload_items_tree( NAPivot *pivot );
-GSList   *na_pivot_free_items_tree( GSList *tree );
+GSList   *na_pivot_get_items( const NAPivot *pivot );
+void      na_pivot_reload_items( NAPivot *pivot );
 
 void      na_pivot_add_item( NAPivot *pivot, const NAObject *item );
 void      na_pivot_remove_item( NAPivot *pivot, NAObject *item );
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index e29390a..b18f8da 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -507,7 +507,7 @@ assist_runtime_init_actions_list( NactAssistantExport *window, GtkAssistant *ass
 
 	appli = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
 	pivot = nact_application_get_pivot( appli );
-	tree = na_pivot_get_items_tree( pivot );
+	tree = na_pivot_get_items( pivot );
 
 	nact_iactions_list_runtime_init_toplevel( NACT_IACTIONS_LIST( window ), tree );
 
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index 4ab03a3..c2e549a 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -78,7 +78,7 @@ static void          add_item_to_clipboard0( NAObject *object, gboolean copy_dat
 static void          add_item_to_clipboard( NAObject *object, GSList **copied );
 static void          export_action( const gchar *uri, const NAObject *action, GSList **exported );
 static gchar        *get_action_xml_buffer( const NAObject *action, GSList **exported );
-static void          get_from_clipboard_callback( GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, NactClipboardData *data );
+static void          get_from_clipboard_callback( GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, guchar *data );
 static void          clear_clipboard_callback( GtkClipboard *clipboard, NactClipboardData *data );
 
 /**
@@ -225,7 +225,7 @@ nact_clipboard_get( void )
 	GtkClipboard *clipboard;
 	GtkSelectionData *selection;
 	NactClipboardData *data;
-	GSList *items;
+	/*GSList *items;*/
 
 	if( nact_clipboard_is_empty()){
 		return( NULL );
@@ -372,13 +372,13 @@ get_action_xml_buffer( const NAObject *action, GSList **exported )
 }
 
 static void
-get_from_clipboard_callback( GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, NactClipboardData *data )
+get_from_clipboard_callback( GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, guchar *data )
 {
 	static const gchar *thisfn = "nact_clipboard_get_from_clipboard_callback";
 
 	g_debug( "%s: clipboard=%p, selection_data=%p, target=%s, info=%d, data=%p",
 			thisfn, ( void * ) clipboard,
-			( void * ) selection_data, gtk_atom_name( selection_data->target ), info, ( void * ) data );
+			( void * ) selection_data, gdk_atom_name( selection_data->target ), info, ( void * ) data );
 
 	gtk_selection_data_set( selection_data, selection_data->target, 8, data, sizeof( NactClipboardData ));
 }
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 8943edd..9e25d67 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -583,7 +583,13 @@ nact_iactions_list_get_selected_items( NactIActionsList *instance )
  *
  * Inserts the provided @items list in the treeview.
  *
- * The provided @items list is supposed to be homogeneous, i.e. it
+ * The provided @items list is supposed to be homogeneous, i.e. referes
+ * to a whole subtree.
+ *
+ * If the @items list contains only profiles, they can only be inserted
+ * into an action, and the profiles will eventually be renumbered.
+ * The insertion position is current, or alpha-sorted, depending on
+ *
  * If the list is not sorted, the new item is inserted just before the
  * current position.
  *
@@ -595,18 +601,24 @@ nact_iactions_list_get_selected_items( NactIActionsList *instance )
  * of profiles of the current action.
  */
 void
-nact_iactions_list_insert_items( NactIActionsList *instance, NAObject *item )
+nact_iactions_list_insert_items( NactIActionsList *instance, GSList *items )
 {
 	GtkTreeView *treeview;
 	GtkTreeSelection *selection;
 	GtkTreeModel *model;
 	GList *list_selected;
 	GtkTreePath *path = NULL;
+	NAObject *item;
 	NAObject *obj_selected = NULL;
 	GtkTreeIter iter;
 
 	g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
-	g_return_if_fail( NA_IS_OBJECT( item ));
+	/*g_return_if_fail( NA_IS_OBJECT( item ));*/
+
+	item = NA_OBJECT( items->data );
+	if( FALSE ){
+		insert_item( instance, item );
+	}
 
 	treeview = get_actions_list_treeview( instance );
 	model = gtk_tree_view_get_model( treeview );
@@ -661,7 +673,7 @@ nact_iactions_list_insert_items( NactIActionsList *instance, NAObject *item )
 	g_list_free( list_selected );
 }
 
-/**
+/*
  * nact_iactions_list_insert_item:
  * @instance: this #NactIActionsList instance.
  * @item: a #NAActionMenu, #NAAction or #NAActionProfile to be added.
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 78a7e5f..2d6e7a1 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -475,7 +475,7 @@ instance_dispose( GObject *window )
 		pos = gtk_paned_get_position( GTK_PANED( pane ));
 		base_iprefs_set_int( BASE_WINDOW( window ), "main-paned", pos );
 
-		self->private->deleted = na_pivot_free_items_tree( self->private->deleted );
+		na_object_free_items( self->private->deleted );
 
 		nact_iactions_list_dispose( NACT_IACTIONS_LIST( window ));
 		nact_iaction_tab_dispose( NACT_IACTION_TAB( window ));
@@ -656,7 +656,8 @@ nact_main_window_remove_deleted( NactMainWindow *window )
 		actually_delete_item( window, item, pivot );
 	}
 
-	window->private->deleted = na_pivot_free_items_tree( window->private->deleted );
+	na_object_free_items( window->private->deleted );
+	window->private->deleted = NULL;
 }
 
 /**
@@ -743,7 +744,7 @@ on_base_runtime_init_toplevel( NactMainWindow *window, gpointer user_data )
 
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
 	pivot = nact_application_get_pivot( application );
-	tree = na_pivot_get_items_tree( pivot );
+	tree = na_pivot_get_items( pivot );
 	g_debug( "%s: pivot_tree=%p", thisfn, ( void * ) tree );
 
 	nact_iaction_tab_runtime_init_toplevel( NACT_IACTION_TAB( window ));
@@ -953,14 +954,8 @@ ipivot_consumer_on_actions_changed( NAIPivotConsumer *instance, gpointer user_da
 	g_free( first );
 
 	if( ok ){
-
-		na_pivot_reload_items_tree( pivot );
-
-		/*na_pivot_free_actions( self->private->actions );
-
-		self->private->actions = na_pivot_get_duplicate_actions( pivot );
-
-		nact_iactions_list_fill( NACT_IACTIONS_LIST( instance ), na_pivot_get_actions( pivot ));*/
+		na_pivot_reload_items( pivot );
+		nact_iactions_list_fill( NACT_IACTIONS_LIST( instance ), na_pivot_get_items( pivot ));
 	}
 }
 
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index cc9f89c..5db114c 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -305,7 +305,7 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 	}
 
 	if( !self->private->dispose_has_run ){
-		tree = na_pivot_get_items_tree( self->private->pivot );
+		tree = na_pivot_get_items( self->private->pivot );
 
 		for( ia = tree ; ia ; ia = ia->next ){
 



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