[nautilus-actions] Exports the actual content of the Actions list



commit a421051704c0a95b55e0626e9647726938b39694
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Oct 29 00:59:08 2009 +0100

    Exports the actual content of the Actions list
    
    We export the current content of Actions list instead of the original content readen from
    the provider, as given by NAPivot.
    Update IActionsList in order to not display the current modification and validity status
    when not in edition mode.
    Update tree model to avoid memory leaks.

 ChangeLog                        |   24 ++++++++++++++++++++++++
 TODO                             |    4 ----
 src/common/na-object-api.h       |    1 +
 src/common/na-object-fn.h        |    1 +
 src/common/na-object.c           |   27 +++++++++++++++++++++++++++
 src/nact/base-window.c           |   23 +++++++++++++++++++++++
 src/nact/base-window.h           |    1 +
 src/nact/nact-assistant-export.c |   20 +++++++++++---------
 src/nact/nact-iactions-list.c    |   27 ++++++++++++++-------------
 src/nact/nact-tree-model.c       |   13 +++----------
 src/runtime/na-iduplicable.c     |   16 ++++++++++++++++
 src/runtime/na-iduplicable.h     |    1 +
 src/runtime/na-object-action.c   |    2 ++
 src/runtime/na-object-id.c       |    4 ++++
 src/runtime/na-object-menu.c     |   16 ++++++++++------
 src/runtime/na-object-profile.c  |   16 ++++++++++------
 16 files changed, 148 insertions(+), 48 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index af41f1e..9347c04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
 2009-10-28 Pierre Wieser <pwieser trychlos org>
 
+	* src/common/na-object-api.h (na_object_reset_status):
+	New function.
+
+	* src/common/na-object-fn.h:
+	* src/common/na-object.c (na_object_object_reset_status):
+	New function.
+
+	* src/nact/base-window.c:
+	* src/nact/base-window.h (base_window_get_parent): New function.
+
+	* src/nact/nact-assistant-export.c
+	(instance_dispose): Clear the tree model.
+	(assist_initial_load_actions_list): Export current actions list.
+
+	* src/nact/nact-iactions-list.c (display_label):
+	Only display status in edition mode.
+
+	* src/nact/nact-tree-model.c (fill_tree_store):
+	Clean up the code to avoid memory leaks.
+
+	* src/runtime/na-iduplicable.c:
+	* src/runtime/na-iduplicable.h (na_iduplicable_reset_status):
+	New function.
+
 	* src/common/na-object-api.h
 	(na_object_get_position, na_object_insert_at): New functions.
 
diff --git a/TODO b/TODO
index 2595fa6..a6f2f84 100644
--- a/TODO
+++ b/TODO
@@ -76,8 +76,4 @@
 - data factory: put together each property of each elementary data (id, label, etc.)
   along with their methods
 
-- AssistantExport exports what it finds in Pivot, but should take its origin
-  from current IActionsList (a. to have same perimeter than drag and drop and
-  b. to export what we see)
-
 - export: add a overwrite page: what to do if file already exists ?
diff --git a/src/common/na-object-api.h b/src/common/na-object-api.h
index 422a2d2..9421102 100644
--- a/src/common/na-object-api.h
+++ b/src/common/na-object-api.h
@@ -60,6 +60,7 @@ G_BEGIN_DECLS
 /* NAObject
  */
 #define na_object_reset_origin( object, origin )	na_object_object_reset_origin( NA_OBJECT( object ), ( NAObject * ) origin )
+#define na_object_reset_status( object )			na_object_object_reset_status( NA_OBJECT( object ) )
 
 /* NAObjectId
  */
diff --git a/src/common/na-object-fn.h b/src/common/na-object-fn.h
index 32020ad..38f0581 100644
--- a/src/common/na-object-fn.h
+++ b/src/common/na-object-fn.h
@@ -55,6 +55,7 @@ void      na_object_iduplicable_set_origin( NAObject *object, const NAObject *or
 /* NAObject
  */
 void      na_object_object_reset_origin( NAObject *object, const NAObject *origin );
+void      na_object_object_reset_status( NAObject *object );
 
 G_END_DECLS
 
diff --git a/src/common/na-object.c b/src/common/na-object.c
index 1332011..ffa4481 100644
--- a/src/common/na-object.c
+++ b/src/common/na-object.c
@@ -134,6 +134,33 @@ na_object_object_reset_origin( NAObject *object, const NAObject *origin )
 	}
 }
 
+/**
+ * na_object_object_reset_status:
+ * @object: a #NAObject-derived object.
+ *
+ * Recursively reset status of @object and its childs.
+ *
+ * This is typically used when we want display a clean list of current
+ * items (e.g. in Export assistant).
+ */
+void
+na_object_object_reset_status( NAObject *object )
+{
+	GList *object_childs, *iobj;
+
+	g_return_if_fail( NA_IS_OBJECT( object ));
+
+	if( !object->private->dispose_has_run ){
+
+		object_childs = v_get_childs( object );
+		for( iobj = object_childs ; iobj ; iobj = iobj->next ){
+			na_iduplicable_reset_status( NA_IDUPLICABLE( iobj->data ));
+		}
+
+		na_iduplicable_reset_status( NA_IDUPLICABLE( object ));
+	}
+}
+
 static GList *
 v_get_childs( const NAObject *object )
 {
diff --git a/src/nact/base-window.c b/src/nact/base-window.c
index ca65d5b..addd7b2 100644
--- a/src/nact/base-window.c
+++ b/src/nact/base-window.c
@@ -740,6 +740,29 @@ base_window_get_named_toplevel( BaseWindow *window, const gchar *name )
 }
 
 /**
+ * base_window_get_parent:
+ * @window: this #BaseWindow instance..
+ *
+ * Returns the #BaseWindow parent of @window.
+ *
+ * The returned object is owned by @window, and should not be freed.
+ */
+BaseWindow *
+base_window_get_parent( BaseWindow *window )
+{
+	BaseWindow *parent = NULL;
+
+	g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
+
+	if( !window->private->dispose_has_run ){
+
+		parent = window->private->parent;
+	}
+
+	return( parent );
+}
+
+/**
  * base_window_get_toplevel:
  * @window: this #BaseWindow instance..
  *
diff --git a/src/nact/base-window.h b/src/nact/base-window.h
index d36515a..6c007aa 100644
--- a/src/nact/base-window.h
+++ b/src/nact/base-window.h
@@ -79,6 +79,7 @@ gboolean         base_window_run( BaseWindow *window );
 
 BaseApplication *base_window_get_application( BaseWindow *window );
 GtkWindow       *base_window_get_named_toplevel( BaseWindow *window, const gchar *name );
+BaseWindow      *base_window_get_parent( BaseWindow *window );
 GtkWindow       *base_window_get_toplevel( BaseWindow *window );
 GtkWidget       *base_window_get_widget( BaseWindow *window, const gchar *name );
 
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 93dbd28..c46bcf3 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -36,14 +36,14 @@
 #include <gtk/gtk.h>
 #include <string.h>
 
-#include <runtime/na-object-api.h>
-#include <runtime/na-pivot.h>
-
+#include <common/na-object-api.h>
 #include <common/na-iprefs.h>
 #include <common/na-utils.h>
 #include <common/na-xml-names.h>
 #include <common/na-xml-writer.h>
 
+#include <runtime/na-pivot.h>
+
 #include "base-iprefs.h"
 #include "nact-application.h"
 #include "nact-main-window.h"
@@ -272,6 +272,8 @@ instance_dispose( GObject *window )
 
 		self->private->dispose_has_run = TRUE;
 
+		nact_iactions_list_dispose( NACT_IACTIONS_LIST( window ));
+
 		/* chain up to the parent class */
 		if( G_OBJECT_CLASS( st_parent_class )->dispose ){
 			G_OBJECT_CLASS( st_parent_class )->dispose( window );
@@ -416,14 +418,14 @@ assist_initial_load_actions_list( NactAssistantExport *window, GtkAssistant *ass
 static void
 assist_runtime_init_actions_list( NactAssistantExport *window, GtkAssistant *assistant )
 {
-	GtkWidget *content;
-	NactApplication *appli;
-	NAPivot *pivot;
+	BaseWindow *parent;
 	GList *tree;
+	GtkWidget *content;
 
-	appli = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
-	pivot = nact_application_get_pivot( appli );
-	tree = na_pivot_get_items( pivot );
+	parent = base_window_get_parent( BASE_WINDOW( window ));
+	g_assert( NACT_IS_MAIN_WINDOW( parent ));
+	g_assert( NACT_IS_IACTIONS_LIST( parent ));
+	tree = nact_iactions_list_get_items( NACT_IACTIONS_LIST( parent ));
 
 	nact_iactions_list_runtime_init_toplevel( NACT_IACTIONS_LIST( window ), tree );
 
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index c762202..9509a29 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -1611,31 +1611,32 @@ display_label( GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *m
 	gchar *label;
 	gboolean modified = FALSE;
 	gboolean valid = TRUE;
+	IActionsListInstanceData *ialid;
 
 	gtk_tree_model_get( model, iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
+	g_object_unref( object );
+	g_return_if_fail( NA_IS_OBJECT( object ));
+
+	ialid = get_instance_data( instance );
+	label = na_object_get_label( object );
+	g_object_set( cell, "style-set", FALSE, NULL );
+	g_object_set( cell, "foreground-set", FALSE, NULL );
+
+	if( ialid->management_mode == IACTIONS_LIST_MANAGEMENT_MODE_EDITION ){
 
-	if( object ){
-		g_assert( NA_IS_OBJECT( object ));
-		label = na_object_get_label( object );
 		modified = na_object_is_modified( object );
 		valid = na_object_is_valid( object );
 
 		if( modified ){
 			g_object_set( cell, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL );
-		} else {
-			g_object_set( cell, "style-set", FALSE, NULL );
 		}
-		if( valid ){
-			g_object_set( cell, "foreground-set", FALSE, NULL );
-		} else {
+		if( !valid ){
 			g_object_set( cell, "foreground", "Red", "foreground-set", TRUE, NULL );
 		}
-
-		g_object_set( cell, "text", label, NULL );
-
-		g_free( label );
-		g_object_unref( object );
 	}
+
+	g_object_set( cell, "text", label, NULL );
+	g_free( label );
 }
 
 /*
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index ca0e5a6..1472955 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -704,26 +704,19 @@ fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
 		subitems = na_object_get_items_list( object );
 		for( it = subitems ; it ; it = it->next ){
 			fill_tree_store( model, treeview, it->data, only_actions, only_actions ? NULL : &iter );
-			na_object_append_item( object, it->data );
-			na_object_set_parent( it->data, object );
 		}
 	}
 
 	if( NA_IS_OBJECT_ACTION( object )){
 		g_return_if_fail( na_object_get_items_count( object ) >= 1 );
 		append_item( model, treeview, parent, &iter, object );
-		if( !only_actions ){
+		if( only_actions ){
+			na_object_set_parent( object, NULL );
+		} else {
 			subitems = na_object_get_items_list( object );
 			for( it = subitems ; it ; it = it->next ){
 				fill_tree_store( model, treeview, it->data, only_actions, &iter );
-				na_object_append_item( object, it->data );
-				na_object_set_parent( it->data, object );
 			}
-		/* need to add a reference count if action has a parent, because
-		 * the action will be unreffed when unreffing the menu
-		 */
-		} else if( na_object_get_parent( object )){
-			g_object_ref( object );
 		}
 	}
 
diff --git a/src/runtime/na-iduplicable.c b/src/runtime/na-iduplicable.c
index 7b64c2c..9894f4e 100644
--- a/src/runtime/na-iduplicable.c
+++ b/src/runtime/na-iduplicable.c
@@ -356,6 +356,22 @@ na_iduplicable_duplicate( const NAIDuplicable *object )
 }
 
 /**
+ * na_iduplicable_reset_status:
+ * @object: the #NAIDuplicable object whose status is to be reset.
+ *
+ * Reset validity and modification status of the object.
+ */
+void
+na_iduplicable_reset_status( NAIDuplicable *object )
+{
+	g_return_if_fail( st_initialized && !st_finalized );
+	g_return_if_fail( NA_IS_IDUPLICABLE( object ));
+
+	set_valid( object, TRUE );
+	set_modified( object, FALSE );
+}
+
+/**
  * na_iduplicable_is_modified:
  * @object: the #NAIDuplicable object whose status is to be returned.
  *
diff --git a/src/runtime/na-iduplicable.h b/src/runtime/na-iduplicable.h
index 661763f..add8b87 100644
--- a/src/runtime/na-iduplicable.h
+++ b/src/runtime/na-iduplicable.h
@@ -153,6 +153,7 @@ void           na_iduplicable_dispose( NAIDuplicable *object );
 void           na_iduplicable_dump( const NAIDuplicable *object );
 void           na_iduplicable_check_status( const NAIDuplicable *object );
 NAIDuplicable *na_iduplicable_duplicate( const NAIDuplicable *object );
+void           na_iduplicable_reset_status( NAIDuplicable *object );
 
 gboolean       na_iduplicable_is_modified( const NAIDuplicable *object );
 gboolean       na_iduplicable_is_valid( const NAIDuplicable *object );
diff --git a/src/runtime/na-object-action.c b/src/runtime/na-object-action.c
index 73498bd..3357795 100644
--- a/src/runtime/na-object-action.c
+++ b/src/runtime/na-object-action.c
@@ -193,6 +193,8 @@ class_init( NAObjectActionClass *klass )
 	naobject_class->are_equal = object_are_equal;
 	naobject_class->is_valid = object_is_valid;
 	naobject_class->get_childs = NULL;
+	naobject_class->ref = NULL;
+	naobject_class->unref = NULL;
 }
 
 static void
diff --git a/src/runtime/na-object-id.c b/src/runtime/na-object-id.c
index 62bce21..8319a54 100644
--- a/src/runtime/na-object-id.c
+++ b/src/runtime/na-object-id.c
@@ -153,6 +153,8 @@ class_init( NAObjectIdClass *klass )
 	naobject_class->are_equal = object_are_equal;
 	naobject_class->is_valid = object_is_valid;
 	naobject_class->get_childs = NULL;
+	naobject_class->ref = NULL;
+	naobject_class->unref = NULL;
 
 	klass->new_id = NULL;
 }
@@ -239,6 +241,8 @@ instance_dispose( GObject *object )
 	if( !self->private->dispose_has_run ){
 
 		if( self->private->parent ){
+			/*g_debug( "na_object_id_instance_dispose: object=%p, parent=%p",
+					( void * ) object, ( void * ) self->private->parent );*/
 			na_object_remove_item( self->private->parent, object );
 			self->private->parent = NULL;
 		}
diff --git a/src/runtime/na-object-menu.c b/src/runtime/na-object-menu.c
index 5216156..5cdb19b 100644
--- a/src/runtime/na-object-menu.c
+++ b/src/runtime/na-object-menu.c
@@ -95,6 +95,7 @@ class_init( NAObjectMenuClass *klass )
 {
 	static const gchar *thisfn = "na_object_menu_class_init";
 	GObjectClass *object_class;
+	NAObjectClass *naobject_class;
 
 	g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
 
@@ -106,12 +107,15 @@ class_init( NAObjectMenuClass *klass )
 
 	klass->private = g_new0( NAObjectMenuClassPrivate, 1 );
 
-	NA_OBJECT_CLASS( klass )->dump = object_dump;
-	NA_OBJECT_CLASS( klass )->new = object_new;
-	NA_OBJECT_CLASS( klass )->copy = object_copy;
-	NA_OBJECT_CLASS( klass )->are_equal = object_are_equal;
-	NA_OBJECT_CLASS( klass )->is_valid = object_is_valid;
-	NA_OBJECT_CLASS( klass )->get_childs = NULL;
+	naobject_class = NA_OBJECT_CLASS( klass );
+	naobject_class->dump = object_dump;
+	naobject_class->new = object_new;
+	naobject_class->copy = object_copy;
+	naobject_class->are_equal = object_are_equal;
+	naobject_class->is_valid = object_is_valid;
+	naobject_class->get_childs = NULL;
+	naobject_class->ref = NULL;
+	naobject_class->unref = NULL;
 }
 
 static void
diff --git a/src/runtime/na-object-profile.c b/src/runtime/na-object-profile.c
index f440e69..1aa0d79 100644
--- a/src/runtime/na-object-profile.c
+++ b/src/runtime/na-object-profile.c
@@ -145,6 +145,7 @@ class_init( NAObjectProfileClass *klass )
 	static const gchar *thisfn = "na_object_profile_class_init";
 	GObjectClass *object_class;
 	GParamSpec *spec;
+	NAObjectClass *naobject_class;
 
 	g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
 
@@ -228,12 +229,15 @@ class_init( NAObjectProfileClass *klass )
 
 	klass->private = g_new0( NAObjectProfileClassPrivate, 1 );
 
-	NA_OBJECT_CLASS( klass )->dump = object_dump;
-	NA_OBJECT_CLASS( klass )->new = object_new;
-	NA_OBJECT_CLASS( klass )->copy = object_copy;
-	NA_OBJECT_CLASS( klass )->are_equal = object_are_equal;
-	NA_OBJECT_CLASS( klass )->is_valid = object_is_valid;
-	NA_OBJECT_CLASS( klass )->get_childs = NULL;
+	naobject_class = NA_OBJECT_CLASS( klass );
+	naobject_class->dump = object_dump;
+	naobject_class->new = object_new;
+	naobject_class->copy = object_copy;
+	naobject_class->are_equal = object_are_equal;
+	naobject_class->is_valid = object_is_valid;
+	naobject_class->get_childs = NULL;
+	naobject_class->ref = NULL;
+	naobject_class->unref = NULL;
 
 	NA_OBJECT_ID_CLASS( klass )->new_id = object_id_new_id;
 }



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