[nautilus-actions: 6/19] Reload list of actions instead of trying to update each object
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Subject: [nautilus-actions: 6/19] Reload list of actions instead of trying to update each object
- Date: Tue, 9 Jun 2009 16:55:28 -0400 (EDT)
commit d47f9e673edfca3e8c21d959ea73fb2bff68b1fa
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Jun 8 12:44:58 2009 +0200
Reload list of actions instead of trying to update each object
---
ChangeLog | 14 +++++++++
src/common/nact-action-profile.c | 4 +-
src/common/nact-action-profile.h | 2 +-
src/common/nact-action.c | 60 ++++++++++++++++++++++++++++++++++----
src/common/nact-action.h | 7 ++--
src/common/nact-gconf.c | 12 ++++---
src/common/nact-object.c | 35 ++++++++++++++++++++++
src/common/nact-object.h | 2 +
src/common/nact-pivot.c | 41 +++++++++++--------------
src/common/nact-pivot.h | 2 -
src/plugin/nautilus-actions.c | 3 --
11 files changed, 137 insertions(+), 45 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0471d24..0ea915f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-06-08 Pierre Wieser <pwieser trychlos org>
+
+ * src/common/nact-action-profile.c:
+ * src/common/nact-action-profile.h:
+ * src/common/nact-action.c:
+ * src/common/nact-action.h:
+ * src/common/nact-gconf.c:
+ * src/common/nact-object.c:
+ * src/common/nact-object.h:
+ * src/common/nact-pivot.c:
+ * src/common/nact-pivot.h:
+ * src/plugin/nautilus-actions.c:
+ Reload list of actions instead of trying to update each object.
+
2009-06-07 Pierre Wieser <pwieser trychlos org>
* src/common/nact-pivot.c:
diff --git a/src/common/nact-action-profile.c b/src/common/nact-action-profile.c
index 0db7238..09eac28 100644
--- a/src/common/nact-action-profile.c
+++ b/src/common/nact-action-profile.c
@@ -498,7 +498,7 @@ do_dump_list( const gchar *thisfn, const gchar *label, GSList *list )
* Check if the given profile is empty, i.e. all its attributes are
* empty.
*/
-gboolean
+/*gboolean
nact_action_profile_is_empty( const NactActionProfile *profile )
{
g_assert( NACT_IS_ACTION_PROFILE( profile ));
@@ -525,7 +525,7 @@ nact_action_profile_is_empty( const NactActionProfile *profile )
return( FALSE );
}
return( TRUE );
-}
+}*/
/**
* Returns a pointer to the action for this profile.
diff --git a/src/common/nact-action-profile.h b/src/common/nact-action-profile.h
index 315b921..fb4786d 100644
--- a/src/common/nact-action-profile.h
+++ b/src/common/nact-action-profile.h
@@ -74,7 +74,7 @@ NactActionProfile *nact_action_profile_new( const NactObject *action, const gcha
void nact_action_profile_load( NactObject *profile );
-gboolean nact_action_profile_is_empty( const NactActionProfile *profile );
+/*gboolean nact_action_profile_is_empty( const NactActionProfile *profile );*/
NactObject *nact_action_profile_get_action( const NactActionProfile *profile );
gchar *nact_action_profile_get_name( const NactActionProfile *profile );
diff --git a/src/common/nact-action.c b/src/common/nact-action.c
index 3113ca2..4aec226 100644
--- a/src/common/nact-action.c
+++ b/src/common/nact-action.c
@@ -90,7 +90,8 @@ static void instance_get_property( GObject *object, guint property_id, GValu
static void instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
static void instance_finalize( GObject *object );
-static void free_profiles( NactAction *action );
+static void free_profiles( NactAction *action );
+static NactActionProfile *get_profile( const NactAction *action, const gchar *profile_name );
static void do_dump( const NactObject *action );
@@ -393,7 +394,7 @@ do_dump( const NactObject *action )
/**
* Check if the given action is empty, i.e. all its attributes are empty.
*/
-gboolean
+/*gboolean
nact_action_is_empty( const NactAction *action )
{
g_assert( NACT_IS_ACTION( action ));
@@ -420,7 +421,7 @@ nact_action_is_empty( const NactAction *action )
}
}
return( TRUE );
-}
+}*/
/**
* Return the globally unique identifier (UUID) of the action.
@@ -567,8 +568,8 @@ nact_action_free_profile_ids( GSList *list )
nactuti_free_string_list( list );
}
-NactObject*
-nact_action_get_profile( const NactAction *action, const gchar *profile_name )
+NactActionProfile *
+get_profile( const NactAction *action, const gchar *profile_name )
{
g_assert( NACT_IS_ACTION( action ));
g_assert( profile_name && strlen( profile_name ));
@@ -586,5 +587,52 @@ nact_action_get_profile( const NactAction *action, const gchar *profile_name )
}
g_free( name );
}
- return( NACT_OBJECT( found ));
+
+ return( found );
+}
+
+/**
+ * Does the given profile name exists ?
+ */
+gboolean
+nact_action_has_profile( const NactAction *action, const gchar *profile_name )
+{
+ g_assert( NACT_IS_ACTION( action ));
+ g_assert( profile_name && strlen( profile_name ));
+
+ return( get_profile( action, profile_name ) != NULL );
+}
+
+/**
+ * Returns the profile which has the given name.
+ * Create it if not found.
+ */
+NactObject *
+nact_action_get_profile( const NactAction *action, const gchar *profile_name )
+{
+ g_assert( NACT_IS_ACTION( action ));
+ g_assert( profile_name && strlen( profile_name ));
+
+ NactActionProfile *profile = get_profile( action, profile_name );
+ if( !profile ){
+ profile = nact_action_profile_new( NACT_OBJECT( action ), profile_name );
+ action->private->profiles = g_slist_prepend( action->private->profiles, profile );
+ }
+
+ return( NACT_OBJECT( profile ));
+}
+
+/**
+ * Remove a profile
+ */
+void
+nact_action_remove_profile( NactAction *action, const gchar *profile_name )
+{
+ g_assert( NACT_IS_ACTION( action ));
+ g_assert( profile_name && strlen( profile_name ));
+
+ NactActionProfile *profile = get_profile( action, profile_name );
+ if( profile ){
+ action->private->profiles = g_slist_remove( action->private->profiles, profile );
+ }
}
diff --git a/src/common/nact-action.h b/src/common/nact-action.h
index 3702e5c..e9633cf 100644
--- a/src/common/nact-action.h
+++ b/src/common/nact-action.h
@@ -72,9 +72,8 @@ GType nact_action_get_type( void );
NactAction *nact_action_new( const gchar *uuid );
/*NactAction *nact_action_create( const gchar *key, const gchar *parm, const NactPivotValue *value );
-void nact_action_update( NactAction *action, const gchar *parm, const NactPivotValue *value );*/
-
-gboolean nact_action_is_empty( const NactAction *action );
+void nact_action_update( NactAction *action, const gchar *parm, const NactPivotValue *value );
+gboolean nact_action_is_empty( const NactAction *action );*/
gchar *nact_action_get_uuid( const NactAction *action );
gchar *nact_action_get_label( const NactAction *action );
@@ -88,7 +87,9 @@ guint nact_action_get_profiles_count( const NactAction *action );
GSList *nact_action_get_profile_ids( const NactAction *action );
void nact_action_free_profile_ids( GSList *list );
+gboolean nact_action_has_profile( const NactAction *action, const gchar *name );
NactObject *nact_action_get_profile( const NactAction *action, const gchar *name );
+void nact_action_remove_profile( NactAction *action, const gchar *name );
G_END_DECLS
diff --git a/src/common/nact-gconf.c b/src/common/nact-gconf.c
index 0f9feaf..4f0683c 100644
--- a/src/common/nact-gconf.c
+++ b/src/common/nact-gconf.c
@@ -453,12 +453,12 @@ path_to_key( const gchar *path )
/*
* set the item properties into the object
- * as we make use of NactPivotNotify structure, 'uuid' field must be
- * read as the GConf key, i.e. the parameter name
+ * properties is a list of path to entry
*/
static void
set_item_properties( NactObject *object, GSList *properties )
{
+ static const gchar *thisfn = "nact_gconf_set_item_properties";
g_assert( NACT_IS_OBJECT( object ));
GSList *item;
@@ -466,10 +466,9 @@ set_item_properties( NactObject *object, GSList *properties )
GConfEntry *entry = ( GConfEntry * ) item->data;
NactPivotNotify *npn = entry_to_notify( entry );
- if( npn ){
+ if( npn->type ){
switch( npn->type ){
-
case NACT_PIVOT_STR:
case NACT_PIVOT_BOOL:
case NACT_PIVOT_STRLIST:
@@ -477,11 +476,14 @@ set_item_properties( NactObject *object, GSList *properties )
break;
default:
+ g_debug( "%s: uuid='%s', profile='%s', parm='%s', type=%d, data=%p",
+ thisfn, npn->uuid, npn->profile, npn->parm, npn->type, npn->data );
g_assert_not_reached();
break;
}
- nact_pivot_free_notify( npn );
}
+
+ nact_pivot_free_notify( npn );
}
}
diff --git a/src/common/nact-object.c b/src/common/nact-object.c
index 57c0d3f..5f3cf5c 100644
--- a/src/common/nact-object.c
+++ b/src/common/nact-object.c
@@ -53,7 +53,9 @@ static void class_init( NactObjectClass *klass );
static void instance_init( GTypeInstance *instance, gpointer klass );
static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
+
static void do_dump( const NactObject *object );
+static void do_empty_property( NactObject *object, const gchar *property );
GType
nact_object_get_type( void )
@@ -100,6 +102,7 @@ class_init( NactObjectClass *klass )
klass->private = g_new0( NactObjectClassPrivate, 1 );
klass->dump = do_dump;
+ klass->empty_property = do_empty_property;
}
static void
@@ -167,3 +170,35 @@ nact_object_dump( const NactObject *object )
NACT_OBJECT_GET_CLASS( object )->dump( object );
}
+
+static void
+do_empty_property( NactObject *object, const gchar *property )
+{
+ /*static const char *thisfn = "nact_object_do_empty_property";*/
+ g_assert( NACT_IS_OBJECT( object ));
+
+ GParamSpec *spec;
+ spec = g_object_class_find_property( G_OBJECT_GET_CLASS( object ), property );
+ if( spec ){
+ g_object_set( G_OBJECT( object ), property, NULL );
+ }
+}
+
+/**
+ * Empty a property.
+ *
+ * This is a virtual function which may be implemented by the derived
+ * class ; the derived class may also call its parent class to get a
+ * empty_property of parent object.
+ *
+ * @object: object whose property is to be emptied.
+ *
+ * @property: the name of the property.
+ */
+void
+nact_object_empty_property( NactObject *object, const gchar *property )
+{
+ g_assert( NACT_IS_OBJECT( object ));
+
+ NACT_OBJECT_GET_CLASS( object )->empty_property( object, property );
+}
diff --git a/src/common/nact-object.h b/src/common/nact-object.h
index c371716..d81febe 100644
--- a/src/common/nact-object.h
+++ b/src/common/nact-object.h
@@ -68,12 +68,14 @@ typedef struct {
/* virtual public functions */
void ( *dump )( const NactObject *object );
+ void ( *empty_property )( NactObject *object, const gchar *property );
}
NactObjectClass;
GType nact_object_get_type( void );
void nact_object_dump( const NactObject *object );
+void nact_object_empty_property( NactObject *object, const gchar *property );
G_END_DECLS
diff --git a/src/common/nact-pivot.c b/src/common/nact-pivot.c
index 0a6e37a..4b76b15 100644
--- a/src/common/nact-pivot.c
+++ b/src/common/nact-pivot.c
@@ -99,7 +99,7 @@ static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
static void action_changed_handler( NactPivot *pivot, gpointer user_data );
-static void update_action( GSList *actions, NactPivotNotify *notify );
+static void free_actions( GSList *list );
static NactAction *get_action( GSList *list, const gchar *uuid );
static gboolean on_action_changed_timeout( gpointer user_data );
static gulong time_val_diff( const GTimeVal *recent, const GTimeVal *old );
@@ -256,11 +256,7 @@ instance_dispose( GObject *object )
self->private->dispose_has_run = TRUE;
/* release list of actions */
- GSList *ia;
- for( ia = self->private->actions ; ia ; ia = ia->next ){
- g_object_unref( G_OBJECT( ia->data ));
- }
- g_slist_free( self->private->actions );
+ free_actions( self->private->actions );
self->private->actions = NULL;
/* chain up to the parent class */
@@ -320,6 +316,14 @@ nact_pivot_get_providers( const NactPivot *pivot, GType type )
return( list );
}
+/*
+ * this handler is trigerred by IIOProviders when an action is changed
+ * in the underlying storage subsystems
+ * we don't care of updating our internal list with each and every
+ * atomic modification
+ * instead we wait for the end of notifications serie, and then reload
+ * the whole list of actions
+ */
static void
action_changed_handler( NactPivot *self, gpointer user_data )
{
@@ -332,9 +336,6 @@ action_changed_handler( NactPivot *self, gpointer user_data )
return;
}
- /* apply the change to the list of actions */
- update_action( self->private->actions, ( NactPivotNotify * ) user_data );
-
/* set a timeout to notify nautilus at the end of the serie */
g_get_current_time( &st_last_event );
if( !st_event_source_id ){
@@ -343,22 +344,13 @@ action_changed_handler( NactPivot *self, gpointer user_data )
}
static void
-update_action( GSList *actions, NactPivotNotify *notify )
+free_actions( GSList *list )
{
- g_assert( notify );
- if( notify->uuid && strlen( notify->uuid )){
-
- NactAction *action = get_action( actions, notify->uuid );
- g_debug( "nact_pivot_update_action: uuid='%s', parm='%s', action=%p", notify->uuid, notify->parm, action );
- if( !action ){
- /* this is a creation */
-
- } else {
- /* this is an update or a deletion */
- }
+ GSList *ia;
+ for( ia = list ; ia ; ia = ia->next ){
+ g_object_unref( NACT_ACTION( ia->data ));
}
-
- nact_pivot_free_notify( notify );
+ g_slist_free( list );
}
static NactAction *
@@ -412,6 +404,9 @@ on_action_changed_timeout( gpointer user_data )
return( TRUE );
}
+ free_actions( pivot->private->actions );
+ pivot->private->actions = nact_iio_provider_load_actions( G_OBJECT( pivot ));
+
g_signal_emit_by_name( G_OBJECT( pivot->private->notified ), "notify_nautilus_of_action_changed" );
st_event_source_id = 0;
diff --git a/src/common/nact-pivot.h b/src/common/nact-pivot.h
index e67dcad..ab8a612 100644
--- a/src/common/nact-pivot.h
+++ b/src/common/nact-pivot.h
@@ -75,8 +75,6 @@ GSList *nact_pivot_get_providers( const NactPivot *pivot, GType type );
GObject *nact_pivot_get_action( NactPivot *pivot, const gchar *uuid );
-/*void nact_pivot_on_action_changed( NactPivot *pivot, const gchar *uuid, const gchar *parm, NactPivotValue *value );*/
-
/* data passed from the storage subsystem when an action is changed
*/
enum {
diff --git a/src/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index bf38a80..09cb3a3 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -469,9 +469,6 @@ action_changed_handler( NautilusActions *self, gpointer user_data )
if( !self->private->dispose_has_run ){
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( self ));
-
- /*nautilus_actions_config_free_actions_list (self->private->config_list);
- self->private->config_list = nautilus_actions_config_get_actions (NAUTILUS_ACTIONS_CONFIG (self->private->configs));*/
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]