[nautilus-actions: 8/19] Remove unused functions and cleanup the code



commit e5a1de25df8b99551306d6bab085b695db7d062d
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Jun 9 21:32:52 2009 +0200

    Remove unused functions and cleanup the code
---
 ChangeLog                        |   13 ++-
 src/common/nact-action-profile.c |  198 +++++++++++++++++++++-----------------
 src/common/nact-action-profile.h |    2 -
 src/common/nact-action.c         |  186 ++++++++++-------------------------
 src/common/nact-action.h         |    6 -
 src/plugin/nautilus-actions.c    |    4 +-
 6 files changed, 174 insertions(+), 235 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dab7e9c..e1f8211 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,16 @@
 2009-06-09 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-action.h
+	(nact_action_get_profile_ids, nact_action_free_profile_ids,
+	 nact_action_has_profile, nact_action_get_profile,
+	 nact_action_free_profile):
+	Remove functions and cleanup the code.
+
+	* src/common/nact-action-profile.c:
+	* src/common/nact-action-profile.h
+	(nact_action_profile_load): Remove function and cleanup the code.
+
 	* src/common/nact-gconf.c:
 	* src/common/nact-object.c:
 	* src/common/nact-object.h:
diff --git a/src/common/nact-action-profile.c b/src/common/nact-action-profile.c
index e7097ea..9918847 100644
--- a/src/common/nact-action-profile.c
+++ b/src/common/nact-action-profile.c
@@ -108,9 +108,9 @@ static NactObjectClass *st_parent_class = NULL;
 static GType  register_type( void );
 static void   class_init( NactActionProfileClass *klass );
 static void   instance_init( GTypeInstance *instance, gpointer klass );
-static void   instance_dispose( GObject *object );
 static void   instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
 static void   instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
+static void   instance_dispose( GObject *object );
 static void   instance_finalize( GObject *object );
 
 static void   do_dump( const NactObject *profile );
@@ -119,58 +119,6 @@ static gchar *do_get_id( const NactObject *object );
 static gchar *do_get_label( const NactObject *object );
 static int    validate_schemes( GSList* schemes2test, NautilusFileInfo* file );
 
-NactActionProfile *
-nact_action_profile_new( const NactObject *action, const gchar *name )
-{
-	g_assert( NACT_IS_ACTION( action ));
-	g_assert( name && strlen( name ));
-
-	NactActionProfile *profile =
-		g_object_new(
-				NACT_ACTION_PROFILE_TYPE,
-				PROP_ACTION_STR, action, PROP_PROFILE_NAME_STR, name, NULL );
-
-	return( profile );
-}
-
-NactActionProfile *
-nact_action_profile_copy( const NactActionProfile *profile )
-{
-	g_assert( NACT_IS_ACTION_PROFILE( profile ));
-
-	NactActionProfile *new =
-		nact_action_profile_new( profile->private->action, profile->private->name );
-
-	g_object_set( G_OBJECT( new ),
-			PROP_LABEL_STR, profile->private->label,
-			PROP_PATH_STR, profile->private->path,
-			PROP_PARAMETERS_STR, profile->private->parameters,
-			PROP_ACCEPT_MULTIPLE_STR, profile->private->accept_multiple_files,
-			PROP_BASENAMES_STR, profile->private->basenames,
-			PROP_ISDIR_STR, profile->private->is_dir,
-			PROP_ISFILE_STR, profile->private->is_file,
-			PROP_MATCHCASE_STR, profile->private->match_case,
-			PROP_MIMETYPES_STR, profile->private->mimetypes,
-			PROP_SCHEMES_STR, profile->private->schemes,
-			NULL );
-
-	return( new );
-}
-
-void
-nact_action_profile_free( NactActionProfile *profile )
-{
-	g_assert( NACT_IS_ACTION_PROFILE( profile ));
-
-	g_free( profile->private->name );
-	g_free( profile->private->label );
-	g_free( profile->private->path );
-	g_free( profile->private->parameters );
-	nactuti_free_string_list( profile->private->basenames );
-	nactuti_free_string_list( profile->private->mimetypes );
-	nactuti_free_string_list( profile->private->schemes );
-}
-
 GType
 nact_action_profile_get_type( void )
 {
@@ -490,6 +438,82 @@ instance_finalize( GObject *object )
 	}
 }
 
+/**
+ * Allocates a new profile for an action.
+ *
+ * @action: the action to which the profile must be attached.
+ *
+ * @name: the internal name (identifier) of the profile.
+ *
+ * Returns the newly allocated NactActionProfile object.
+ */
+NactActionProfile *
+nact_action_profile_new( const NactObject *action, const gchar *name )
+{
+	g_assert( NACT_IS_ACTION( action ));
+	g_assert( name && strlen( name ));
+
+	NactActionProfile *profile =
+		g_object_new(
+				NACT_ACTION_PROFILE_TYPE,
+				PROP_ACTION_STR, action, PROP_PROFILE_NAME_STR, name, NULL );
+
+	return( profile );
+}
+
+/**
+ * Duplicates a profile.
+ *
+ * @profile: the profile to be duplicated.
+ *
+ * Returns the newly allocated NactActionProfile object.
+ *
+ * Note the duplicated profile has the same internal name (identifier)
+ * as the initial one, and thus cannot be attached to the same action.
+ */
+NactActionProfile *
+nact_action_profile_copy( const NactActionProfile *profile )
+{
+	g_assert( NACT_IS_ACTION_PROFILE( profile ));
+
+	NactActionProfile *new =
+		nact_action_profile_new( profile->private->action, profile->private->name );
+
+	g_object_set( G_OBJECT( new ),
+			PROP_LABEL_STR, profile->private->label,
+			PROP_PATH_STR, profile->private->path,
+			PROP_PARAMETERS_STR, profile->private->parameters,
+			PROP_ACCEPT_MULTIPLE_STR, profile->private->accept_multiple_files,
+			PROP_BASENAMES_STR, profile->private->basenames,
+			PROP_ISDIR_STR, profile->private->is_dir,
+			PROP_ISFILE_STR, profile->private->is_file,
+			PROP_MATCHCASE_STR, profile->private->match_case,
+			PROP_MIMETYPES_STR, profile->private->mimetypes,
+			PROP_SCHEMES_STR, profile->private->schemes,
+			NULL );
+
+	return( new );
+}
+
+/**
+ * Frees a profile.
+ *
+ * @profile: the NactActionProfile object to be freed.
+ */
+void
+nact_action_profile_free( NactActionProfile *profile )
+{
+	g_assert( NACT_IS_ACTION_PROFILE( profile ));
+
+	g_free( profile->private->name );
+	g_free( profile->private->label );
+	g_free( profile->private->path );
+	g_free( profile->private->parameters );
+	nactuti_free_string_list( profile->private->basenames );
+	nactuti_free_string_list( profile->private->mimetypes );
+	nactuti_free_string_list( profile->private->schemes );
+}
+
 static void
 do_dump( const NactObject *object )
 {
@@ -544,7 +568,7 @@ do_get_id( const NactObject *profile )
 }
 
 /**
- * Return the internal id (name) of the profile.
+ * Returns the internal name (identifier) of the profile.
  *
  * @action: an NactActionProfile object.
  *
@@ -569,7 +593,7 @@ do_get_label( const NactObject *profile )
 }
 
 /**
- * Return the descriptive name (label) of the profile.
+ * Returns the descriptive name (label) of the profile.
  *
  * @action: an NactAction object.
  *
@@ -582,41 +606,14 @@ nact_action_profile_get_label( const NactActionProfile *profile )
 	return( nact_object_get_label( NACT_OBJECT( profile )));
 }
 
-/*
- * Check if the given profile is empty, i.e. all its attributes are
- * empty.
- */
-/*gboolean
-nact_action_profile_is_empty( const NactActionProfile *profile )
-{
-	g_assert( NACT_IS_ACTION_PROFILE( profile ));
-
-	if( profile->private->name && strlen( profile->private->name )){
-		return( FALSE );
-	}
-	if( profile->private->label && strlen( profile->private->label )){
-		return( FALSE );
-	}
-	if( profile->private->path && strlen( profile->private->path )){
-		return( FALSE );
-	}
-	if( profile->private->parameters && strlen( profile->private->parameters )){
-		return( FALSE );
-	}
-	if( !nactuti_is_empty_string_list( profile->private->basenames )){
-		return( FALSE );
-	}
-	if( !nactuti_is_empty_string_list( profile->private->mimetypes )){
-		return( FALSE );
-	}
-	if( !nactuti_is_empty_string_list( profile->private->schemes )){
-		return( FALSE );
-	}
-	return( TRUE );
-}*/
-
 /**
  * Returns a pointer to the action for this profile.
+ *
+ * @profile: the NactActionProfile object whose parent action is to be
+ * retrieved.
+ *
+ * Note that the returned NactNaction is owned by the profile. The
+ * caller should not try to free or unref it.
  */
 NactObject *
 nact_action_profile_get_action( const NactActionProfile *profile )
@@ -632,6 +629,9 @@ nact_action_profile_get_action( const NactActionProfile *profile )
 /**
  * Returns the path of the command in the profile.
  *
+ * @profile: the NactActionProfile object whose command path is to be
+ * retrieved.
+ *
  * The returned string should be g_freed by the caller.
  */
 gchar *
@@ -648,6 +648,9 @@ nact_action_profile_get_path( const NactActionProfile *profile )
 /**
  * Returns the parameters of the command in the profile.
  *
+ * @profile: the NactActionProfile object whose command parameters are
+ * to be retrieved.
+ *
  * The returned string should be g_freed by the caller.
  */
 gchar *
@@ -686,6 +689,15 @@ validate_schemes( GSList* schemes2test, NautilusFileInfo* file )
 	return retv;
 }
 
+/**
+ * Determines if the given profile is candidate to be displayed in the
+ * Nautilus context menu, regarding the list of currently selected
+ * items.
+ *
+ * @profile: the profile to be examined.
+ *
+ * @files: the list currently selected items, as provided by Nautilus.
+ */
 gboolean
 nact_action_profile_is_candidate( const NactActionProfile *profile, GList* files )
 {
@@ -904,8 +916,14 @@ nact_action_profile_is_candidate( const NactActionProfile *profile, GList* files
 	return retv;
 }
 
-/*
- * Valid parameters :
+/**
+ * Expands the parameters path, in function of the found tokens.
+ *
+ * @profile: the selected profile.
+ *
+ * @files: the list of currently selected items, as provided by Nautilus.
+ *
+ * Valid parameters are :
  *
  * %u : gnome-vfs URI
  * %d : base dir of the selected file(s)/folder(s)
diff --git a/src/common/nact-action-profile.h b/src/common/nact-action-profile.h
index d60d155..d734716 100644
--- a/src/common/nact-action-profile.h
+++ b/src/common/nact-action-profile.h
@@ -74,8 +74,6 @@ NactActionProfile *nact_action_profile_new( const NactObject *action, const gcha
 NactActionProfile *nact_action_profile_copy( const NactActionProfile *profile );
 void               nact_action_profile_free( NactActionProfile *profile );
 
-void               nact_action_profile_load( NactObject *profile );
-
 NactObject        *nact_action_profile_get_action( const NactActionProfile *profile );
 gchar             *nact_action_profile_get_name( const NactActionProfile *profile );
 gchar             *nact_action_profile_get_label( const NactActionProfile *profile );
diff --git a/src/common/nact-action.c b/src/common/nact-action.c
index 3b7fb17..d81ee66 100644
--- a/src/common/nact-action.c
+++ b/src/common/nact-action.c
@@ -82,38 +82,19 @@ enum {
 
 static NactObjectClass *st_parent_class = NULL;
 
-static GType    register_type( void );
-static void     class_init( NactActionClass *klass );
-static void     instance_init( GTypeInstance *instance, gpointer klass );
-static void     instance_dispose( GObject *object );
-static void     instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
-static void     instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
-static void     instance_finalize( GObject *object );
+static GType  register_type( void );
+static void   class_init( NactActionClass *klass );
+static void   instance_init( GTypeInstance *instance, gpointer klass );
+static void   instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
+static void   instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
+static void   instance_dispose( GObject *object );
+static void   instance_finalize( GObject *object );
 
-static void               free_profiles( NactAction *action );
-static NactActionProfile *get_profile( const NactAction *action, const gchar *profile_name );
+static void   do_dump( const NactObject *action );
+static gchar *do_get_id( const NactObject *action );
+static gchar *do_get_label( const NactObject *action );
 
-static void     do_dump( const NactObject *action );
-static gchar   *do_get_id( const NactObject *action );
-static gchar   *do_get_label( const NactObject *action );
-
-/**
- * Allocate a new NactAction object.
- *
- * @provider: a gpointer to the instance which implements the storage
- * subsystem for this action ; the @provider must implement the
- * NactIIOProvider interface.
- *
- * @data: a gpointer to some data internal to the provider ; the
- * provider may use it to store and retrieve its data on a per-object
- * basis.
- */
-NactAction *
-nact_action_new( const gchar *uuid )
-{
-	NactAction *action = g_object_new( NACT_ACTION_TYPE, PROP_UUID_STR, uuid, NULL );
-	return( action );
-}
+static void   free_profiles( NactAction *action );
 
 GType
 nact_action_get_type( void )
@@ -330,24 +311,18 @@ instance_finalize( GObject *object )
 	}
 }
 
-static void
-free_profiles( NactAction *action )
-{
-	g_assert( NACT_IS_ACTION( action ));
-
-	nact_action_free_profiles( action->private->profiles );
-
-	action->private->profiles = NULL;
-}
-
-void
-nact_action_free_profiles( GSList * list )
+/**
+ * Allocates a new NactAction object.
+ *
+ * @uuid: the globally unique identifier (UUID) of the action.
+ *
+ * Return a newly allocated NactAction object.
+ */
+NactAction *
+nact_action_new( const gchar *uuid )
 {
-	GSList *ip;
-	for( ip = list ; ip ; ip = ip->next ){
-		g_object_unref( NACT_ACTION_PROFILE( ip->data ));
-	}
-	g_slist_free( list );
+	NactAction *action = g_object_new( NACT_ACTION_TYPE, PROP_UUID_STR, uuid, NULL );
+	return( action );
 }
 
 static void
@@ -388,7 +363,7 @@ do_get_id( const NactObject *action )
 }
 
 /**
- * Return the globally unique identifier (UUID) of the action.
+ * Returns the globally unique identifier (UUID) of the action.
  *
  * @action: an NactAction object.
  *
@@ -413,7 +388,7 @@ do_get_label( const NactObject *action )
 }
 
 /**
- * Return the label of the action.
+ * Returns the label of the action.
  *
  * @action: an NactAction object.
  *
@@ -427,7 +402,8 @@ nact_action_get_label( const NactAction *action )
 }
 
 /**
- * Return the tooltip attached to the context menu item for the action.
+ * Returns the tooltip attached to the context menu item for the
+ * action.
  *
  * @action: an NactAction object.
  *
@@ -445,12 +421,12 @@ nact_action_get_tooltip( const NactAction *action )
 }
 
 /**
- * Return the icon name attached to the context menu item for the
+ * Returns the icon name attached to the context menu item for the
  * action.
  *
  * @action: an NactAction object.
  *
- * When not null, the returned string must be g_free by the caller.
+ * When not NULL, the returned string must be g_free by the caller.
  */
 gchar *
 nact_action_get_verified_icon_name( const NactAction *action )
@@ -492,6 +468,14 @@ nact_action_get_profiles( const NactAction *action )
 
 /**
  * Set the list of the profiles for the action.
+ *
+ * @action: the action whose profiles has to be retrieved.
+ *
+ * @list: a list of NactActionProfile objects to be installed in the
+ * action.
+ *
+ * The provided list is copied to the action, and thus can then be
+ * safely freed (see nact_action_free_profiles) by the caller.
  */
 void
 nact_action_set_profiles( NactAction *action, GSList *list )
@@ -508,6 +492,11 @@ nact_action_set_profiles( NactAction *action, GSList *list )
 	}
 }
 
+/**
+ * Returns the number of profiles which are defined for the action.
+ *
+ * @action: the action whose profiles has to be retrieved.
+ */
 guint
 nact_action_get_profiles_count( const NactAction *action )
 {
@@ -516,96 +505,27 @@ nact_action_get_profiles_count( const NactAction *action )
 	return( g_slist_length( action->private->profiles ));
 }
 
-GSList *
-nact_action_get_profile_ids( const NactAction *action )
-{
-	GSList *item;
-	GSList *profile_names = NULL;
-	gchar *name;
-	NactActionProfile *profile;
-
-	g_assert( NACT_IS_ACTION( action ));
-
-	for( item = action->private->profiles ; item != NULL ; item = item->next ){
-		profile = ( NactActionProfile * ) item->data;
-		g_object_get( G_OBJECT( profile ), "name", &name, NULL );
-		profile_names = g_slist_prepend( profile_names, name );
-	}
-
-	return( profile_names );
-}
-
-void
-nact_action_free_profile_ids( GSList *list )
-{
-	nactuti_free_string_list( list );
-}
-
-NactActionProfile *
-get_profile( const NactAction *action, const gchar *profile_name )
-{
-	g_assert( NACT_IS_ACTION( action ));
-	g_assert( profile_name && strlen( profile_name ));
-
-	GSList *item;
-	NactActionProfile *profile;
-	NactActionProfile *found = NULL;
-	gchar *name;
-
-	for( item = action->private->profiles ; item != NULL && found == NULL ; item = item->next ){
-		profile = NACT_ACTION_PROFILE( item->data );
-		g_object_get( G_OBJECT( profile ), "name", &name, NULL );
-		if( !g_strcmp0( name, profile_name )){
-			found = profile;
-		}
-		g_free( name );
-	}
-
-	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 )
+static void
+free_profiles( NactAction *action )
 {
 	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 );
-	}
+	nact_action_free_profiles( action->private->profiles );
 
-	return( NACT_OBJECT( profile ));
+	action->private->profiles = NULL;
 }
 
 /**
- * Remove a profile
+ * Frees a profiles list.
+ *
+ * @list: a list of NactActionProfile objects.
  */
 void
-nact_action_remove_profile( NactAction *action, const gchar *profile_name )
+nact_action_free_profiles( GSList * list )
 {
-	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 );
+	GSList *ip;
+	for( ip = list ; ip ; ip = ip->next ){
+		g_object_unref( NACT_ACTION_PROFILE( ip->data ));
 	}
+	g_slist_free( list );
 }
diff --git a/src/common/nact-action.h b/src/common/nact-action.h
index b1e2817..4b073a9 100644
--- a/src/common/nact-action.h
+++ b/src/common/nact-action.h
@@ -81,12 +81,6 @@ void        nact_action_set_profiles( NactAction *action, GSList *list );
 void        nact_action_free_profiles( GSList *list );
 
 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/plugin/nautilus-actions.c b/src/plugin/nautilus-actions.c
index a082221..fb6561f 100644
--- a/src/plugin/nautilus-actions.c
+++ b/src/plugin/nautilus-actions.c
@@ -329,8 +329,10 @@ get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files
 	GSList* profiles;
 	GSList *ia, *ip;
 	NautilusMenuItem *item;
-	gchar *debug_label;
 	GSList *actions = NULL;
+#ifdef NACT_MAINTAINER_MODE
+	gchar *debug_label;
+#endif
 
 	g_return_val_if_fail( NAUTILUS_IS_ACTIONS( provider ), NULL );
 	NautilusActions *self = NAUTILUS_ACTIONS( provider );



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