[nautilus-actions] Fix freeing of edited NAAction object



commit 4d554e7fb4d3dd2feeeef5b39078d162a61892ac
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Jun 28 14:51:45 2009 +0200

    Fix freeing of edited NAAction object

 ChangeLog                                |   12 ++++++++-
 src/common/na-action-profile.c           |   14 +++++++----
 src/common/na-action-profile.h           |    2 +-
 src/common/na-action.c                   |   35 +++++++++++++++++++++++------
 src/common/na-action.h                   |    1 +
 src/common/na-gconf.c                    |   21 ++++++++++++++++-
 src/nact/nact-action-conditions-editor.c |   13 ++++++++--
 src/plugin/nautilus-actions.c            |    2 +-
 8 files changed, 78 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3ddf43a..fc72855 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,19 @@
 2009-06-28 Pierre Wieser <pwieser trychlos org>
 
 	* src/common/na-action.c:
-	UUID no more a contruction only parameter.
+	* src/common/na-action.h:
+	UUID is no more a contruction only property.
 	NAAction is now initialized with suitable default values.
+	na_action_new_with_profile: new function.
+
+	* src/common/na-action-profile.c:
+	* src/common/na-action-profile.h:
+	Profile's name is no more a construction only property.
+	na_action_profile_copy function is renamed as
+	na_action_profile_duplicate.
 
 	* src/na/na-gconf.c:
-	Fix test of writability status.
+	Temporarily suspend test of writability status.
 
 	* src/nact/nact-action-conditions-editor.c:
 	* src/nact/nact-action-conditions-editor.h:
diff --git a/src/common/na-action-profile.c b/src/common/na-action-profile.c
index 7bf0992..8d6598c 100644
--- a/src/common/na-action-profile.c
+++ b/src/common/na-action-profile.c
@@ -162,7 +162,7 @@ class_init( NAActionProfileClass *klass )
 			PROP_PROFILE_NAME_STR,
 			PROP_PROFILE_NAME_STR,
 			"Internal profile's name", "",
-			G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
 	g_object_class_install_property( object_class, PROP_PROFILE_NAME, spec );
 
 	spec = g_param_spec_string(
@@ -456,6 +456,8 @@ instance_finalize( GObject *object )
  * @action: the action to which the profile must be attached.
  *
  * @name: the internal name (identifier) of the profile.
+ * If NULL, the instance_init takes care of allocating a suitable
+ * default value.
  *
  * Returns the newly allocated NAActionProfile object.
  */
@@ -463,12 +465,14 @@ NAActionProfile *
 na_action_profile_new( const NAObject *action, const gchar *name )
 {
 	g_assert( NA_IS_ACTION( action ));
-	g_assert( name && strlen( name ));
 
 	NAActionProfile *profile =
 		g_object_new(
-				NA_ACTION_PROFILE_TYPE,
-				PROP_PROFILE_ACTION_STR, action, PROP_PROFILE_NAME_STR, name, NULL );
+				NA_ACTION_PROFILE_TYPE, PROP_PROFILE_ACTION_STR, action, NULL );
+
+	if( name && strlen( name )){
+		g_object_set( G_OBJECT( profile ), PROP_PROFILE_NAME_STR, name, NULL );
+	}
 
 	return( profile );
 }
@@ -484,7 +488,7 @@ na_action_profile_new( const NAObject *action, const gchar *name )
  * as the initial one, and thus cannot be attached to the same action.
  */
 NAActionProfile *
-na_action_profile_copy( const NAActionProfile *profile )
+na_action_profile_duplicate( const NAActionProfile *profile )
 {
 	g_assert( NA_IS_ACTION_PROFILE( profile ));
 
diff --git a/src/common/na-action-profile.h b/src/common/na-action-profile.h
index 53ce8a2..265e093 100644
--- a/src/common/na-action-profile.h
+++ b/src/common/na-action-profile.h
@@ -88,7 +88,7 @@ typedef struct {
 GType            na_action_profile_get_type( void );
 
 NAActionProfile *na_action_profile_new( const NAObject *action, const gchar *name );
-NAActionProfile *na_action_profile_copy( const NAActionProfile *profile );
+NAActionProfile *na_action_profile_duplicate( const NAActionProfile *profile );
 void             na_action_profile_free( NAActionProfile *profile );
 
 NAObject        *na_action_profile_get_action( const NAActionProfile *profile );
diff --git a/src/common/na-action.c b/src/common/na-action.c
index afa2b4b..19ab83d 100644
--- a/src/common/na-action.c
+++ b/src/common/na-action.c
@@ -206,8 +206,8 @@ class_init( NAActionClass *klass )
 static void
 instance_init( GTypeInstance *instance, gpointer klass )
 {
-	/*static const gchar *thisfn = "na_action_instance_init";
-	g_debug( "%s: instance=%p, klass=%p", thisfn, instance, klass );*/
+	static const gchar *thisfn = "na_action_instance_init";
+	g_debug( "%s: instance=%p, klass=%p", thisfn, instance, klass );
 
 	g_assert( NA_IS_ACTION( instance ));
 	NAAction* self = NA_ACTION( instance );
@@ -216,8 +216,7 @@ instance_init( GTypeInstance *instance, gpointer klass )
 
 	self->private->dispose_has_run = FALSE;
 
-	/* initialize suitable default values, but for label which is
-	 * mandatory
+	/* initialize suitable default values
 	 */
 	self->private->version = g_strdup( NA_ACTION_LATEST_VERSION );
 	self->private->label = g_strdup( "" );
@@ -352,8 +351,8 @@ instance_finalize( GObject *object )
 /**
  * Allocates a new NAAction object.
  *
- * @uuid: the globally unique identifier (UUID) of the action. If NULL,
- * a new UUID is allocated for this action.
+ * @uuid: the globally unique identifier (UUID) of the action.
+ * If NULL, a new UUID is allocated for this action.
  *
  * Return a newly allocated NAAction object.
  */
@@ -370,6 +369,23 @@ na_action_new( const gchar *uuid )
 }
 
 /**
+ * Allocates a new NAAction object along with a default profile.
+ *
+ * Return a newly allocated NAAction object.
+ */
+NAAction *
+na_action_new_with_profile( void )
+{
+	NAAction *action = na_action_new( NULL );
+
+	NAActionProfile *profile = na_action_profile_new( NA_OBJECT( action ), NULL );
+
+	action->private->profiles = g_slist_prepend( action->private->profiles, profile );
+
+	return( action );
+}
+
+/**
  * Allocates a new NAAction object, and initializes it as an exact
  * copy of the specified action.
  *
@@ -397,7 +413,10 @@ na_action_duplicate( const NAAction *action )
 
 	GSList *ip;
 	for( ip = action->private->profiles ; ip ; ip = ip->next ){
-		/* TODO: duplicate profile */
+		duplicate->private->profiles =
+			g_slist_prepend(
+					duplicate->private->profiles,
+					na_action_profile_duplicate( NA_ACTION_PROFILE( ip->data )));
 	}
 
 	return( duplicate );
@@ -638,7 +657,7 @@ na_action_set_profiles( NAAction *action, GSList *list )
 	for( ip = list ; ip ; ip = ip->next ){
 		action->private->profiles = g_slist_prepend(
 							action->private->profiles,
-							na_action_profile_copy( NA_ACTION_PROFILE( ip->data ))
+							na_action_profile_duplicate( NA_ACTION_PROFILE( ip->data ))
 		);
 	}
 }
diff --git a/src/common/na-action.h b/src/common/na-action.h
index c8eb992..259b3db 100644
--- a/src/common/na-action.h
+++ b/src/common/na-action.h
@@ -81,6 +81,7 @@ typedef struct {
 GType     na_action_get_type( void );
 
 NAAction *na_action_new( const gchar *uuid );
+NAAction *na_action_new_with_profile( void );
 NAAction *na_action_duplicate( const NAAction *action );
 
 gchar    *na_action_get_uuid( const NAAction *action );
diff --git a/src/common/na-gconf.c b/src/common/na-gconf.c
index 466105e..8601c4a 100644
--- a/src/common/na-gconf.c
+++ b/src/common/na-gconf.c
@@ -917,11 +917,26 @@ do_write_action( NAIIOProvider *provider, const GObject *obj_action, gchar **mes
  * FALSE without error for our keys !
  * So I have to actually try a fake write to the key to get the real
  * writability status...
+ *
+ * TODO: having a NAPivot as Nautilus extension and another NAPivot in
+ * the UI leads to a sort of notification loop: extension's pivot is
+ * not aware of UI's one, and so get notifications from GConf, reloads
+ * the list of actions, retrying to test the writability.
+ * In the meanwhile, UI's pivot has reauthorized notifications, and is
+ * notified of extension's pivot tests, and so on......
+ *
+ * -> Nautilus extension's pivot should not test for writability, as it
+ *    uses actions as read-only, reloading the whole list when one
+ *    action is modified ; this can break the loop
+ *
+ * -> the UI may use the pivot inside of Nautilus extension via a sort
+ *    of API, falling back to its own pivot, when the extension is not
+ *    present.
  */
 static gboolean
 key_is_writable( NAGConf *gconf, const gchar *path )
 {
-	static const gchar *thisfn = "na_gconf_key_is_writable";
+	/*static const gchar *thisfn = "na_gconf_key_is_writable";
 	GError *error = NULL;
 
 	remove_gconf_watched_dir( gconf );
@@ -947,7 +962,9 @@ key_is_writable( NAGConf *gconf, const gchar *path )
 	g_debug( "%s: ret_gconf=%s, ret_try=%s", thisfn, ret_gconf ? "True":"False", ret_try ? "True":"False" );
 
 	install_gconf_watched_dir( gconf );
-	return( ret_try );
+	return( ret_try );*/
+
+	return( TRUE );
 }
 
 static gboolean
diff --git a/src/nact/nact-action-conditions-editor.c b/src/nact/nact-action-conditions-editor.c
index 3d9c7c1..a8f05fb 100644
--- a/src/nact/nact-action-conditions-editor.c
+++ b/src/nact/nact-action-conditions-editor.c
@@ -179,6 +179,7 @@ instance_init( GTypeInstance *instance, gpointer klass )
 	self->private = g_new0( NactActionConditionsEditorPrivate, 1 );
 
 	self->private->dispose_has_run = FALSE;
+	self->private->action = NULL;
 }
 
 static void
@@ -194,6 +195,8 @@ instance_dispose( GObject *dialog )
 
 		self->private->dispose_has_run = TRUE;
 
+		g_object_unref( self->private->action );
+
 		/* chain up to the parent class */
 		G_OBJECT_CLASS( st_parent_class )->dispose( dialog );
 	}
@@ -206,7 +209,9 @@ instance_finalize( GObject *dialog )
 	g_debug( "%s: dialog=%p", thisfn, dialog );
 
 	g_assert( NACT_IS_ACTION_CONDITIONS_EDITOR( dialog ));
-	/*NactActionConditionsEditor *self = ( NactActionConditionsEditor * ) dialog;*/
+	NactActionConditionsEditor *self = ( NactActionConditionsEditor * ) dialog;
+
+	g_free( self->private );
 
 	/* chain call to parent class */
 	if( st_parent_class->finalize ){
@@ -241,6 +246,9 @@ action_conditions_editor_new( BaseApplication *application )
 gboolean
 nact_action_conditions_editor_run_editor( NactWindow *parent, gpointer user_data )
 {
+	static const gchar *thisfn = "nact_action_conditions_editor_run_editor";
+	g_debug( "%s: parent=%p, user_data=%p", thisfn, parent, user_data );
+
 	g_assert( NACT_IS_MAIN_WINDOW( parent ));
 
 	BaseApplication *application = BASE_APPLICATION( base_window_get_application( BASE_WINDOW( parent )));
@@ -252,7 +260,7 @@ nact_action_conditions_editor_run_editor( NactWindow *parent, gpointer user_data
 	NAAction *action = NA_ACTION( user_data );
 
 	if( !action ){
-		dialog->private->action = na_action_new( NULL );
+		dialog->private->action = na_action_new_with_profile();
 		dialog->private->is_new = TRUE;
 
 	} else {
@@ -262,7 +270,6 @@ nact_action_conditions_editor_run_editor( NactWindow *parent, gpointer user_data
 
 	base_window_run( BASE_WINDOW( dialog ));
 
-	g_object_unref( dialog->private->action );
 	return( TRUE );
 }
 
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index 1c00a80..075ca75 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -328,7 +328,7 @@ create_menu_item( NAAction *action, NAActionProfile *profile, GList *files )
 	gchar *tooltip = na_action_get_tooltip( action );
 	gchar* icon_name = na_action_get_verified_icon_name( action );
 
-	NAActionProfile *dup4menu = na_action_profile_copy( profile );
+	NAActionProfile *dup4menu = na_action_profile_duplicate( profile );
 
 	item = nautilus_menu_item_new( name, label, tooltip, icon_name );
 



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