[nautilus-actions] Refactoring: rename src/core/na-object-action-class.h to src/api/na-object-action.h



commit b2fd0629391422e34eefc1643c3f242c1db299e3
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Feb 15 17:45:30 2010 +0100

    Refactoring: rename src/core/na-object-action-class.h to src/api/na-object-action.h

 ChangeLog                                          |    1 +
 src/api/Makefile.am                                |    1 +
 .../na-object-action.h}                            |   43 +-
 src/core/Makefile.am                               |    1 +
 src/core/na-object-action.c                        |  894 +++-----------------
 5 files changed, 153 insertions(+), 787 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9c457bb..7beab25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2009-02-15 Pierre Wieser <pwieser trychlos org>
 
+	Rename src/core/na-object-action-class.h to src/api/na-object-action.h
 	Rename src/core/na-object-item-class.h to src/api/na-object-item.h
 	Rename src/core/na-object-id-class.h to src/api/na-object-id.h
 	Rename src/core/na-object-class.h to src/api/na-object.h
diff --git a/src/api/Makefile.am b/src/api/Makefile.am
index da67de2..12d4608 100644
--- a/src/api/Makefile.am
+++ b/src/api/Makefile.am
@@ -42,5 +42,6 @@ api_include_HEADERS = \
 	na-object.h											\
 	na-object-id.h										\
 	na-object-item.h									\
+	na-object-action.h									\
 	na-gconf-keys.h										\
 	$(NULL)
diff --git a/src/core/na-object-action-class.h b/src/api/na-object-action.h
similarity index 69%
rename from src/core/na-object-action-class.h
rename to src/api/na-object-action.h
index 364c3aa..ec4fe59 100644
--- a/src/core/na-object-action-class.h
+++ b/src/api/na-object-action.h
@@ -1,5 +1,5 @@
 /*
- * Nautilus ObjectActions
+ * Nautilus Actions
  * A Nautilus extension which offers configurable context menu actions.
  *
  * Copyright (C) 2005 The GNOME Foundation
@@ -28,37 +28,25 @@
  *   ... and many others (see AUTHORS)
  */
 
-#ifndef __NAUTILUS_ACTIONS_NA_PRIVATE_OBJECT_ACTION_CLASS_H__
-#define __NAUTILUS_ACTIONS_NA_PRIVATE_OBJECT_ACTION_CLASS_H__
+#ifndef __NAUTILUS_OBJECT_ACTIONS_API_NA_OBJECT_ACTION_H__
+#define __NAUTILUS_OBJECT_ACTIONS_API_NA_OBJECT_ACTION_H__
 
 /**
  * SECTION: na_object_action
  * @short_description: #NAObjectAction class definition.
- * @include: nautilus-actions/private/na-object-action-class.h
+ * @include: nautilus-actions/na-object-action.h
  *
- * This is the class which maintains data and properties of an Nautilus
+ * This is the class which maintains data and properties of a Nautilus
  * action.
  *
- * Note about the UUID :
- *
- * The uuid is only required when writing the action to GConf in order
- * to ensure unicity of subdirectories.
- *
- * UUID is transfered through import/export operations.
- *
- * Note that a user may import an action, translate it and then
- * reexport it : we so may have two different actions with the same
- * uuid. The user has so to modify the UUID before import, or to
- * select the appropriate option as an import mode.
- *
- * Note about edition status :
- *
- * As a particular rule of #NAObjectItem derived class, an action is
+ * Note about edition status:
+ * As a particular rule of #NAItem derived class, a #NAObjectAction is
  * considered modified as soon as any of its profiles has been modified
  * itself (because they are saved as a whole).
  */
 
-#include "na-object-item-class.h"
+#include "na-object-item.h"
+#include "na-object-profile.h"
 
 G_BEGIN_DECLS
 
@@ -69,7 +57,7 @@ G_BEGIN_DECLS
 #define NA_IS_OBJECT_ACTION_CLASS( klass )		( G_TYPE_CHECK_CLASS_TYPE(( klass ), NA_OBJECT_ACTION_TYPE ))
 #define NA_OBJECT_ACTION_GET_CLASS( object )	( G_TYPE_INSTANCE_GET_CLASS(( object ), NA_OBJECT_ACTION_TYPE, NAObjectActionClass ))
 
-typedef struct NAObjectActionPrivate NAObjectActionPrivate;
+typedef struct NAObjectActionPrivate      NAObjectActionPrivate;
 
 typedef struct {
 	NAObjectItem           parent;
@@ -85,8 +73,15 @@ typedef struct {
 }
 	NAObjectActionClass;
 
-GType na_object_action_get_type( void );
+GType           na_object_action_get_type( void );
+
+NAObjectAction *na_object_action_new( void );
+NAObjectAction *na_object_action_new_with_profile( void );
+
+void            na_object_action_attach_profile( NAObjectAction *action, NAObjectProfile *profile );
+
+gboolean        na_object_action_is_candidate( const NAObjectAction *action, gint target );
 
 G_END_DECLS
 
-#endif /* __NAUTILUS_ACTIONS_NA_PRIVATE_OBJECT_ACTION_CLASS_H__ */
+#endif /* __NAUTILUS_OBJECT_ACTIONS_API_NA_OBJECT_ACTION_H__ */
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index fc02454..55f634a 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -45,6 +45,7 @@ libna_core_la_SOURCES = \
 	na-object.c											\
 	na-object-id.c										\
 	na-object-item.c									\
+	na-object-action.c									\
 	\
 	na-iabout.c											\
 	na-iabout.h											\
diff --git a/src/core/na-object-action.c b/src/core/na-object-action.c
index 821f008..ed0792a 100644
--- a/src/core/na-object-action.c
+++ b/src/core/na-object-action.c
@@ -1,5 +1,5 @@
 /*
- * Nautilus Actions
+ * Nautilus ObjectActions
  * A Nautilus extension which offers configurable context menu actions.
  *
  * Copyright (C) 2005 The GNOME Foundation
@@ -32,14 +32,12 @@
 #include <config.h>
 #endif
 
-#include <string.h>
+#include <glib/gi18n.h>
 
 #include <api/na-object-api.h>
 
-#include <runtime/na-utils.h>
-
-#include "na-iduplicable.h"
-#include "na-object-action-priv.h"
+#include "na-io-factory.h"
+#include "na-data-factory.h"
 
 /* private class data
  */
@@ -47,42 +45,42 @@ struct NAObjectActionClassPrivate {
 	void *empty;						/* so that gcc -pedantic is happy */
 };
 
-/* action properties
+/* private instance data
  */
-enum {
-	NAACTION_PROP_VERSION_ID = 1,
-	NAACTION_PROP_LAST_ALLOCATED_ID,
-	NAACTION_PROP_TARGET_SELECTION_ID,
-	NAACTION_PROP_TARGET_BACKGROUND_ID,
-	NAACTION_PROP_TARGET_TOOLBAR_ID,
-	NAACTION_PROP_TOOLBAR_SAME_LABEL_ID,
-	NAACTION_PROP_TOOLBAR_LABEL_ID
+struct NAObjectActionPrivate {
+	gboolean dispose_has_run;
 };
 
+										/* i18n: default label for a new action */
+#define NEW_NAUTILUS_ACTION				N_( "New Nautilus action" )
+
+extern NadfIdGroup action_id_groups [];	/* defined in na-item-action-enum.c */
+
 static NAObjectItemClass *st_parent_class = NULL;
 
-static GType     register_type( void );
-static void      class_init( NAObjectActionClass *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      object_dump( const NAObject *object );
-static NAObject *object_new( const NAObject *action );
-static void      object_copy( NAObject *target, const NAObject *source );
-static gboolean  object_are_equal( const NAObject *a, const NAObject *b );
-static gboolean  object_is_valid( const NAObject *object );
-static gboolean  is_valid_label( const NAObjectAction *action );
-static gboolean  is_valid_short_label( const NAObjectAction *action );
+static GType    register_type( void );
+static void     class_init( NAObjectActionClass *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     idata_factory_iface_init( NAIDataFactoryInterface *iface );
+static guint    idata_factory_get_version( const NAIDataFactory *instance );
+static gchar   *idata_factory_get_default( const NAIDataFactory *instance, const NadfIdType *iddef );
+static void     idata_factory_copy( NAIDataFactory *target, const NAIDataFactory *source );
+static gboolean idata_factory_are_equal( const NAIDataFactory *a, const NAIDataFactory *b );
+static void     idata_factory_read_done( NAIDataFactory *instance, const NAIIOFactory *reader, void *reader_data, GSList **messages );
+static void     idata_factory_write_done( NAIDataFactory *instance, const NAIIOFactory *writer, void *writer_data, GSList **messages );
 
 GType
 na_object_action_get_type( void )
 {
 	static GType action_type = 0;
 
-	if( !action_type ){
+	if( action_type == 0 ){
+
 		action_type = register_type();
 	}
 
@@ -93,11 +91,12 @@ static GType
 register_type( void )
 {
 	static const gchar *thisfn = "na_object_action_register_type";
+	GType type;
 
 	static GTypeInfo info = {
 		sizeof( NAObjectActionClass ),
-		( GBaseInitFunc ) NULL,
-		( GBaseFinalizeFunc ) NULL,
+		NULL,
+		NULL,
 		( GClassInitFunc ) class_init,
 		NULL,
 		NULL,
@@ -106,9 +105,21 @@ register_type( void )
 		( GInstanceInitFunc ) instance_init
 	};
 
+	static const GInterfaceInfo idata_factory_iface_info = {
+		( GInterfaceInitFunc ) idata_factory_iface_init,
+		NULL,
+		NULL
+	};
+
 	g_debug( "%s", thisfn );
 
-	return( g_type_register_static( NA_OBJECT_ITEM_TYPE, "NAObjectAction", &info, 0 ));
+	type = g_type_register_static( NA_OBJECT_ITEM_TYPE, "NAObjectAction", &info, 0 );
+
+	g_type_add_interface_static( type, NA_IDATA_FACTORY_TYPE, &idata_factory_iface_info );
+
+	na_io_factory_register( type, action_id_groups );
+
+	return( type );
 }
 
 static void
@@ -117,208 +128,80 @@ class_init( NAObjectActionClass *klass )
 	static const gchar *thisfn = "na_object_action_class_init";
 	GObjectClass *object_class;
 	NAObjectClass *naobject_class;
-	GParamSpec *spec;
 
 	g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
 
 	st_parent_class = g_type_class_peek_parent( klass );
 
 	object_class = G_OBJECT_CLASS( klass );
-	object_class->dispose = instance_dispose;
-	object_class->finalize = instance_finalize;
 	object_class->set_property = instance_set_property;
 	object_class->get_property = instance_get_property;
+	object_class->dispose = instance_dispose;
+	object_class->finalize = instance_finalize;
 
-	spec = g_param_spec_string(
-			NAACTION_PROP_VERSION,
-			"Version",
-			"Version of the schema", "",
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NAACTION_PROP_VERSION_ID, spec );
-
-	spec = g_param_spec_int(
-			NAACTION_PROP_LAST_ALLOCATED,
-			"Last allocated counter",
-			"Last counter used in new profile name computing", 0, INT_MAX, 0,
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NAACTION_PROP_LAST_ALLOCATED_ID, spec );
-
-	spec = g_param_spec_boolean(
-			NAACTION_PROP_TARGET_SELECTION,
-			"Target file selection",
-		"Whether the NAObjectAction is candidate on file selection menus", TRUE,
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NAACTION_PROP_TARGET_SELECTION_ID, spec );
-
-	spec = g_param_spec_boolean(
-			NAACTION_PROP_TARGET_BACKGROUND,
-			"Target background",
-			"Whether the NAObjectAction is candidate on background menus", FALSE,
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NAACTION_PROP_TARGET_BACKGROUND_ID, spec );
-
-	spec = g_param_spec_boolean(
-			NAACTION_PROP_TARGET_TOOLBAR,
-			"Target toolbar",
-			"Whether the NAObjectAction is candidate on toolbar display", TRUE,
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NAACTION_PROP_TARGET_TOOLBAR_ID, spec );
-
-	spec = g_param_spec_boolean(
-			NAACTION_PROP_TOOLBAR_SAME_LABEL,
-			"Use same label",
-			"Whether the icon label in the toolbar is the same that the action main label", FALSE,
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NAACTION_PROP_TOOLBAR_SAME_LABEL_ID, spec );
-
-	spec = g_param_spec_string(
-			NAACTION_PROP_TOOLBAR_LABEL,
-			"Toolbar label",
-			"The label which is displayed besides of the icon in the Nautilus toolbar", "",
-			G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
-	g_object_class_install_property( object_class, NAACTION_PROP_TOOLBAR_LABEL_ID, spec );
+	naobject_class = NA_OBJECT_CLASS( klass );
+	naobject_class->dump = NULL;
+	naobject_class->copy = NULL;
+	naobject_class->are_equal = NULL;
+	naobject_class->is_valid = NULL;
 
 	klass->private = g_new0( NAObjectActionClassPrivate, 1 );
 
-	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_data_factory_properties( object_class );
 }
 
 static void
 instance_init( GTypeInstance *instance, gpointer klass )
 {
-	/*static const gchar *thisfn = "na_object_action_instance_init";*/
+	static const gchar *thisfn = "na_object_action_instance_init";
 	NAObjectAction *self;
 
-	/*g_debug( "%s: instance=%p, klass=%p", thisfn, ( void * ) instance, ( void * ) klass );*/
+	g_debug( "%s: instance=%p (%s), klass=%p",
+			thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
+
 	g_return_if_fail( NA_IS_OBJECT_ACTION( instance ));
+
 	self = NA_OBJECT_ACTION( instance );
 
 	self->private = g_new0( NAObjectActionPrivate, 1 );
 
-	self->private->dispose_has_run = FALSE;
-
-	/* initialize suitable default values
-	 */
-	self->private->version = g_strdup( NAUTILUS_ACTIONS_CONFIG_VERSION );
-	self->private->last_allocated = 0;
-	self->private->target_selection = TRUE;
-	self->private->target_background = FALSE;
-	self->private->target_toolbar = FALSE;
-	self->private->use_same_label = TRUE;
-	self->private->toolbar_label = g_strdup( "" );
+	na_data_factory_init( NA_IDATA_FACTORY( instance ));
 }
 
 static void
 instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec )
 {
-	NAObjectAction *self;
-
 	g_return_if_fail( NA_IS_OBJECT_ACTION( object ));
-	self = NA_OBJECT_ACTION( object );
-
-	if( !self->private->dispose_has_run ){
-
-		switch( property_id ){
-			case NAACTION_PROP_VERSION_ID:
-				g_value_set_string( value, self->private->version );
-				break;
-
-			case NAACTION_PROP_LAST_ALLOCATED_ID:
-				g_value_set_int( value, self->private->last_allocated );
-				break;
-
-			case NAACTION_PROP_TARGET_SELECTION_ID:
-				g_value_set_boolean( value, self->private->target_selection );
-				break;
+	g_return_if_fail( NA_IS_IDATA_FACTORY( object ));
 
-			case NAACTION_PROP_TARGET_BACKGROUND_ID:
-				g_value_set_boolean( value, self->private->target_background );
-				break;
+	if( !NA_OBJECT_ACTION( object )->private->dispose_has_run ){
 
-			case NAACTION_PROP_TARGET_TOOLBAR_ID:
-				g_value_set_boolean( value, self->private->target_toolbar );
-				break;
-
-			case NAACTION_PROP_TOOLBAR_SAME_LABEL_ID:
-				g_value_set_boolean( value, self->private->use_same_label );
-				break;
-
-			case NAACTION_PROP_TOOLBAR_LABEL_ID:
-				g_value_set_string( value, self->private->toolbar_label );
-				break;
-
-			default:
-				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
-				break;
-		}
+		na_data_factory_set_value( NA_IDATA_FACTORY( object ), property_id, value, spec );
 	}
 }
 
 static void
 instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec )
 {
-	NAObjectAction *self;
-
 	g_return_if_fail( NA_IS_OBJECT_ACTION( object ));
-	self = NA_OBJECT_ACTION( object );
-
-	if( !self->private->dispose_has_run ){
-
-		switch( property_id ){
-			case NAACTION_PROP_VERSION_ID:
-				g_free( self->private->version );
-				self->private->version = g_value_dup_string( value );
-				break;
-
-			case NAACTION_PROP_LAST_ALLOCATED_ID:
-				self->private->last_allocated = g_value_get_int( value );
-				break;
-
-			case NAACTION_PROP_TARGET_SELECTION_ID:
-				self->private->target_selection = g_value_get_boolean( value );
-				break;
-
-			case NAACTION_PROP_TARGET_BACKGROUND_ID:
-				self->private->target_background = g_value_get_boolean( value );
-				break;
-
-			case NAACTION_PROP_TARGET_TOOLBAR_ID:
-				self->private->target_toolbar = g_value_get_boolean( value );
-				break;
-
-			case NAACTION_PROP_TOOLBAR_SAME_LABEL_ID:
-				self->private->use_same_label = g_value_get_boolean( value );
-				break;
+	g_return_if_fail( NA_IS_IDATA_FACTORY( object ));
 
-			case NAACTION_PROP_TOOLBAR_LABEL_ID:
-				g_free( self->private->toolbar_label );
-				self->private->toolbar_label = g_value_dup_string( value );
-				break;
+	if( !NA_OBJECT_ACTION( object )->private->dispose_has_run ){
 
-			default:
-				G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
-				break;
-		}
+		na_data_factory_get_value( NA_IDATA_FACTORY( object ), property_id, value, spec );
 	}
 }
 
 static void
 instance_dispose( GObject *object )
 {
-	/*static const gchar *thisfn = "na_object_instance_dispose";*/
+	static const gchar *thisfn = "na_object_action_instance_dispose";
 	NAObjectAction *self;
 
-	/*g_debug( "%s: object=%p", thisfn, ( void * ) object );*/
+	g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
 
 	g_return_if_fail( NA_IS_OBJECT_ACTION( object ));
+
 	self = NA_OBJECT_ACTION( object );
 
 	if( !self->private->dispose_has_run ){
@@ -335,419 +218,129 @@ instance_dispose( GObject *object )
 static void
 instance_finalize( GObject *object )
 {
-	/*static const gchar *thisfn = "na_object_instance_finalize";*/
+	static const gchar *thisfn = "na_object_action_instance_finalize";
 	NAObjectAction *self;
 
-	/*g_debug( "%s: object=%p", thisfn, ( void * ) object );*/
+	g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
 
 	g_return_if_fail( NA_IS_OBJECT_ACTION( object ));
-	self = NA_OBJECT_ACTION( object );
 
-	g_free( self->private->version );
-	g_free( self->private->toolbar_label );
+	self = NA_OBJECT_ACTION( object );
 
 	g_free( self->private );
 
+	na_data_factory_finalize( NA_IDATA_FACTORY( object ));
+
 	/* chain call to parent class */
 	if( G_OBJECT_CLASS( st_parent_class )->finalize ){
 		G_OBJECT_CLASS( st_parent_class )->finalize( object );
 	}
 }
 
-/**
- * na_object_action_new:
- *
- * Allocates a new #NAObjectAction object.
- *
- * The new #NAObjectAction object is initialized with suitable default values,
- * but without any profile.
- *
- * Returns: the newly allocated #NAObjectAction object.
- */
-NAObjectAction *
-na_object_action_new( void )
-{
-	NAObjectAction *action;
-	gchar *label;
-
-	action = g_object_new( NA_OBJECT_ACTION_TYPE, NULL );
-
-	na_object_set_new_id( action, NULL );
-
-	/* i18n: default label for a new action */
-	na_object_set_label( action, NA_OBJECT_ACTION_DEFAULT_LABEL );
-
-	/* when flag is set, forces toolbar label to be the same that action label
-	 */
-	if( action->private->use_same_label ){
-		label = na_object_get_label( action );
-		na_object_action_toolbar_set_label( action, label );
-		g_free( label );
-	}
-
-	return( action );
-}
-
-/**
- * na_object_action_new_with_profile:
- *
- * Allocates a new #NAObjectAction object along with a default profile.
- *
- * Returns: the newly allocated #NAObjectAction action.
- */
-NAObjectAction *
-na_object_action_new_with_profile( void )
-{
-	NAObjectAction *action;
-	NAObjectProfile *profile;
-
-	action = na_object_action_new();
-
-	profile = na_object_profile_new();
-
-	/* i18n: name of the default profile when creating an action */
-	na_object_set_label( profile, _( "Default profile" ));
-	na_object_action_attach_profile( action, profile );
-
-	return( action );
-}
-
-/**
- * na_object_action_get_version:
- * @action: the #NAObjectAction object to be requested.
- *
- * Returns the version of the description of the action, as found when
- * reading it from the I/O storage subsystem.
- *
- * Returns: the version of the action as a newly allocated string. This
- * returned string must be g_free() by the caller.
- *
- * See na_object_set_version() for some rationale about version.
- */
-gchar *
-na_object_action_get_version( const NAObjectAction *action )
-{
-	gchar *version = NULL;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), NULL );
-
-	if( !action->private->dispose_has_run ){
-		g_object_get( G_OBJECT( action ), NAACTION_PROP_VERSION, &version, NULL );
-	}
-
-	return( version );
-}
-
-/**
- * na_object_action_is_target_selection:
- * @action: the #NAObjectAction to be requested.
- *
- * Returns: %TRUE if @action is candidate for being displayed in file
- * selection menus, %FALSE else.
- *
- * This was the historical only target of Nautilus-Actions actions.
- * It so defaults to %TRUE at object creation.
- */
-gboolean
-na_object_action_is_target_selection( const NAObjectAction *action )
-{
-	gboolean is_target = FALSE;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), 0 );
-
-	if( !action->private->dispose_has_run ){
-
-		is_target = action->private->target_selection;
-	}
-
-	return( is_target );
-}
-
-/**
- * na_object_action_is_target_background:
- * @action: the #NAObjectAction to be requested.
- *
- * Returns: %TRUE if @item is candidate for being displayed in
- * background menus, %FALSE else.
- */
-gboolean
-na_object_action_is_target_background( const NAObjectAction *action )
-{
-	gboolean is_target = FALSE;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), 0 );
-
-	if( !action->private->dispose_has_run ){
-
-		is_target = action->private->target_background;
-	}
-
-	return( is_target );
-}
-
-/**
- * na_object_action_is_target_toolbar:
- * @action: the #NAObjectAction to be requested.
- *
- * Returns: %TRUE if @item is candidate for being displayed in file
- * toolbar menus, %FALSE else.
- */
-gboolean
-na_object_action_is_target_toolbar( const NAObjectAction *action )
+static void
+idata_factory_iface_init( NAIDataFactoryInterface *iface )
 {
-	gboolean is_target = FALSE;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), 0 );
+	static const gchar *thisfn = "na_object_action_idata_factory_iface_init";
 
-	if( !action->private->dispose_has_run ){
-
-		is_target = action->private->target_toolbar;
-	}
+	g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
 
-	return( is_target );
+	iface->get_version = idata_factory_get_version;
+	iface->get_default = idata_factory_get_default;
+	iface->copy = idata_factory_copy;
+	iface->are_equal = idata_factory_are_equal;
+	iface->read_done = idata_factory_read_done;
+	iface->write_done = idata_factory_write_done;
 }
 
-/**
- * na_object_action_toolbar_use_same_label:
- * @action: the #NAObjectAction object to be requested.
- *
- * When displayed in the toolbar, does the specified @action use the
- * same label that the main action label ?
- *
- * Returns: %TRUE if the label are sames, %FALSE else.
- *
- * Defaults to %FALSE because toolbar labels should really be smaller
- * that those of menu items.
- */
-gboolean
-na_object_action_toolbar_use_same_label( const NAObjectAction *action )
+static guint
+idata_factory_get_version( const NAIDataFactory *instance )
 {
-	gboolean use_same_label = FALSE;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), FALSE );
-
-	if( !action->private->dispose_has_run ){
-
-		g_object_get( G_OBJECT( action ), NAACTION_PROP_TOOLBAR_SAME_LABEL, &use_same_label, NULL );
-	}
-
-	return( use_same_label );
+	return( 1 );
 }
 
-/**
- * na_object_action_toolbar_get_label:
- * @action: the #NAObjectAction object to be requested.
- *
- * Returns: the label which would be displayed besides of the icon in
- * the Nautilus toolbar.
- *
- * The returned string should be g_free() by the caller.
- */
-gchar *
-na_object_action_toolbar_get_label( const NAObjectAction *action )
+static gchar *
+idata_factory_get_default( const NAIDataFactory *instance, const NadfIdType *iddef )
 {
-	gchar *label = NULL;
+	gchar *value;
 
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), FALSE );
+	value = NULL;
 
-	if( !action->private->dispose_has_run ){
+	switch( iddef->id ){
 
-		g_object_get( G_OBJECT( action ), NAACTION_PROP_TOOLBAR_LABEL, &label, NULL );
+		case NADF_DATA_LABEL:
+		case NADF_DATA_TOOLBAR_LABEL:
+			value = g_strdup( NEW_NAUTILUS_ACTION );
+			break;
 	}
 
-	return( label );
-}
-
-/**
- * na_object_action_set_version:
- * @action: the #NAObjectAction object to be updated.
- * @label: the label to be set.
- *
- * Sets a new version for the action.
- *
- * #NAObjectAction takes a copy of the provided version. This later may so be
- * g_free() by the caller after this function returns.
- *
- * The version describes the schema of the informations in the I/O
- * storage subsystem.
- *
- * Version is stored in the #NAObjectAction object as readen from the I/O
- * storage subsystem, even if the #NAObjectAction object itself only reflects
- * the lastest known version. Conversion is made at load time (cf.
- * na_gconf_load_action()).
- */
-void
-na_object_action_set_version( NAObjectAction *action, const gchar *version )
-{
-	g_return_if_fail( NA_IS_OBJECT_ACTION( action ));
-
-	if( !action->private->dispose_has_run ){
-		g_object_set( G_OBJECT( action ), NAACTION_PROP_VERSION, version, NULL );
-	}
+	return( value );
 }
 
-/**
- * na_object_action_set_target_selection:
- * @action: the #NAObjectAction to be updated.
- * @targeting: whether @action targets selection menus.
- *
- * Set the flag for this target.
- */
-void
-na_object_action_set_target_selection( NAObjectAction *action, gboolean targeting )
+static void
+idata_factory_copy( NAIDataFactory *target, const NAIDataFactory *source )
 {
-	g_return_if_fail( NA_IS_OBJECT_ITEM( action ));
-
-	if( !action->private->dispose_has_run ){
-
-		g_object_set( G_OBJECT( action ), NAACTION_PROP_TARGET_SELECTION, targeting, NULL );
-	}
+	na_object_item_copy( NA_OBJECT_ITEM( target ), NA_OBJECT_ITEM( source ));
 }
 
-/**
- * na_object_action_set_target_background:
- * @action: the #NAObjectAction to be updated.
- * @targeting: whether @action targets background menus.
- *
- * Set the flag for this target.
- */
-void
-na_object_action_set_target_background( NAObjectAction *action, gboolean targeting )
+static gboolean
+idata_factory_are_equal( const NAIDataFactory *a, const NAIDataFactory *b )
 {
-	g_return_if_fail( NA_IS_OBJECT_ITEM( action ));
-
-	if( !action->private->dispose_has_run ){
-
-		g_object_set( G_OBJECT( action ), NAACTION_PROP_TARGET_BACKGROUND, targeting, NULL );
-	}
+	return( na_object_item_are_equal( NA_OBJECT_ITEM( a ), NA_OBJECT_ITEM( b )));
 }
 
-/**
- * na_object_action_set_target_toolbar:
- * @action: the #NAObjectAction to be updated.
- * @targeting: whether @action targets toolbar display.
- *
- * Set the flag for this target.
- */
-void
-na_object_action_set_target_toolbar( NAObjectAction *action, gboolean targeting )
+static void
+idata_factory_read_done( NAIDataFactory *instance, const NAIIOFactory *reader, void *reader_data, GSList **messages )
 {
-	g_return_if_fail( NA_IS_OBJECT_ITEM( action ));
+	g_debug( "na_object_action_idata_factory_read_done: instance=%p", ( void * ) instance );
 
-	if( !action->private->dispose_has_run ){
-
-		g_object_set( G_OBJECT( action ), NAACTION_PROP_TARGET_TOOLBAR, targeting, NULL );
-	}
+	na_object_dump( instance );
 }
 
-/**
- * na_object_action_toolbar_set_same_label:
- * @action: the #NAObjectAction object to be updated.
- * @use_same_label: whether the icon label is the same that the action label.
- *
- * Sets the new value.
- *
- * Please note that this value is only used in NACT user interface, which
- * takes care of maintaining the main action label along with the toolbar
- * item label.
- *
- * At runtime, we only ask for the toolbar item label.
- */
-void
-na_object_action_toolbar_set_same_label( NAObjectAction *action, gboolean use_same_label )
+static void
+idata_factory_write_done( NAIDataFactory *instance, const NAIIOFactory *writer, void *writer_data, GSList **messages )
 {
-	g_return_if_fail( NA_IS_OBJECT_ACTION( action ));
-
-	if( !action->private->dispose_has_run ){
 
-		g_object_set( G_OBJECT( action ), NAACTION_PROP_TOOLBAR_SAME_LABEL, use_same_label, NULL );
-	}
 }
 
 /**
- * na_object_action_toolbar_set_label:
- * @action: the #NAObjectAction object to be updated.
- * @label: the label to be set.
+ * na_object_action_new:
  *
- * Sets the new value.
- */
-void
-na_object_action_toolbar_set_label( NAObjectAction *action, const gchar *label )
-{
-	g_return_if_fail( NA_IS_OBJECT_ACTION( action ));
-
-	if( !action->private->dispose_has_run ){
-
-		g_object_set( G_OBJECT( action ), NAACTION_PROP_TOOLBAR_LABEL, label, NULL );
-	}
-}
-
-/**
- * na_object_action_reset_last_allocated:
- * @action: the #NAObjectAction object.
+ * Allocates a new #NAObjectAction object.
  *
- * Resets the last_allocated counter for computing new profile names.
+ * The new #NAObjectAction object is initialized with suitable default values,
+ * but without any profile.
  *
- * This should be called after having successfully saved the action.
+ * Returns: the newly allocated #NAObjectAction object.
  */
-void
-na_object_action_reset_last_allocated( NAObjectAction *action )
+NAObjectAction *
+na_object_action_new( void )
 {
-	g_return_if_fail( NA_IS_OBJECT_ACTION( action ));
+	NAObjectAction *action;
 
-	if( !action->private->dispose_has_run ){
+	action = g_object_new( NA_OBJECT_ACTION_TYPE, NULL );
 
-		action->private->last_allocated = 0;
-	}
+	return( action );
 }
 
 /**
- * na_object_action_get_new_profile_name:
- * @action: the #NAObjectAction object which will receive a new profile.
- *
- * Returns a name suitable as a new profile name.
- *
- * The search is made by iterating over the standard profile name
- * prefix : basically, we increment a counter until finding a name
- * which is not yet allocated. The provided name is so only suitable
- * for the specified @action.
+ * na_object_action_new_with_profile:
  *
- * Returns: a newly allocated profile name, which should be g_free() by
- * the caller.
+ * Allocates a new #NAObjectAction object along with a default profile.
  *
- * When inserting a list of profiles in the action, we iter first for
- * new names, before actually do the insertion. We so keep the last
- * allocated name to avoid to allocate the same one twice.
+ * Returns: the newly allocated #NAObjectAction action.
  */
-gchar *
-na_object_action_get_new_profile_name( const NAObjectAction *action )
+NAObjectAction *
+na_object_action_new_with_profile( void )
 {
-	int i;
-	gboolean ok = FALSE;
-	gchar *candidate = NULL;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), NULL );
-
-	if( !action->private->dispose_has_run ){
-
-		for( i = action->private->last_allocated + 1 ; !ok ; ++i ){
-
-			g_free( candidate );
-			candidate = g_strdup_printf( "%s%d", OBJECT_PROFILE_PREFIX, i );
+	NAObjectAction *action;
+	NAObjectProfile *profile;
 
-			if( !na_object_get_item( action, candidate )){
-				ok = TRUE;
-				action->private->last_allocated = i;
-			}
-		}
+	action = na_object_action_new();
 
-		if( !ok ){
-			g_free( candidate );
-			candidate = NULL;
-		}
-	}
+	profile = na_object_profile_new();
+	na_object_action_attach_profile( action, profile );
 
-	return( candidate );
+	return( action );
 }
 
 /**
@@ -782,6 +375,7 @@ na_object_action_is_candidate( const NAObjectAction *action, gint target )
 {
 	gboolean is_candidate = FALSE;
 
+#if 0
 	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), is_candidate );
 
 	if( !action->private->dispose_has_run ){
@@ -791,233 +385,7 @@ na_object_action_is_candidate( const NAObjectAction *action, gint target )
 			( action->private->target_background && target == ITEM_TARGET_BACKGROUND ) ||
 			( action->private->target_toolbar && target == ITEM_TARGET_TOOLBAR );
 	}
-
-	return( is_candidate );
-}
-
-static void
-object_dump( const NAObject *action )
-{
-	static const gchar *thisfn = "na_object_action_object_dump";
-	NAObjectAction *self;
-
-	g_return_if_fail( NA_IS_OBJECT_ACTION( action ));
-	self = NA_OBJECT_ACTION( action );
-
-	if( !self->private->dispose_has_run ){
-
-		g_debug( "%s:           version='%s'", thisfn, self->private->version );
-		g_debug( "%s:    last-allocated=%d", thisfn, self->private->last_allocated );
-		g_debug( "%s:  target-selection='%s'", thisfn, self->private->target_selection ? "True" : "False" );
-		g_debug( "%s: target-background='%s'", thisfn, self->private->target_background ? "True" : "False" );
-		g_debug( "%s:    target-toolbar='%s'", thisfn, self->private->target_toolbar ? "True" : "False" );
-		g_debug( "%s:    use-same-label='%s'", thisfn, self->private->use_same_label ? "True" : "False" );
-		g_debug( "%s:     toolbar-label='%s'", thisfn, self->private->toolbar_label );
-	}
-}
-
-static NAObject *
-object_new( const NAObject *action )
-{
-	return( NA_OBJECT( na_object_action_new()));
-}
-
-void
-object_copy( NAObject *target, const NAObject *source )
-{
-	gchar *version;
-	gint last_allocated;
-	GList *profiles, *ip;
-	gboolean target_selection, target_background, target_toolbar;
-	gboolean toolbar_same_label;
-	gchar *toolbar_label;
-
-	g_return_if_fail( NA_IS_OBJECT_ACTION( target ));
-	g_return_if_fail( NA_IS_OBJECT_ACTION( source ));
-
-	if( !NA_OBJECT_ACTION( target )->private->dispose_has_run &&
-		!NA_OBJECT_ACTION( source )->private->dispose_has_run ){
-
-		g_object_get( G_OBJECT( source ),
-				NAACTION_PROP_VERSION, &version,
-				NAACTION_PROP_LAST_ALLOCATED, &last_allocated,
-				NAACTION_PROP_TARGET_SELECTION, &target_selection,
-				NAACTION_PROP_TARGET_BACKGROUND, &target_background,
-				NAACTION_PROP_TARGET_TOOLBAR, &target_toolbar,
-				NAACTION_PROP_TOOLBAR_SAME_LABEL, &toolbar_same_label,
-				NAACTION_PROP_TOOLBAR_LABEL, &toolbar_label,
-				NULL );
-
-		g_object_set( G_OBJECT( target ),
-				NAACTION_PROP_VERSION, version,
-				NAACTION_PROP_LAST_ALLOCATED, last_allocated,
-				NAACTION_PROP_TARGET_SELECTION, target_selection,
-				NAACTION_PROP_TARGET_BACKGROUND, target_background,
-				NAACTION_PROP_TARGET_TOOLBAR, target_toolbar,
-				NAACTION_PROP_TOOLBAR_SAME_LABEL, toolbar_same_label,
-				NAACTION_PROP_TOOLBAR_LABEL, toolbar_label,
-				NULL );
-
-		g_free( version );
-
-		/* profiles have been copied (duplicated) as subitems by parent class
-		 * we have to attach new profiles to target action
-		 */
-		profiles = na_object_get_items_list( target );
-		for( ip = profiles ; ip ; ip = ip->next ){
-			na_object_set_parent( ip->data, target );
-		}
-	}
-}
-
-/*
- * note 1: version is not localized (see configure.ac)
- *
- * note 2: when checking for equality of profiles, we know that NAObjectItem
- * has already checked their edition status, and that the two profiles lists
- * were the sames ; we so only report the modification status to the action
- *
- * note 3: last_allocated counter is not relevant for equality test
- */
-static gboolean
-object_are_equal( const NAObject *a, const NAObject *b )
-{
-	NAObjectAction *first, *second;
-	gboolean equal = TRUE;
-	GList *profiles, *ip;
-	gchar *id;
-	NAObjectProfile *profile;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( a ), FALSE );
-	first = NA_OBJECT_ACTION( a );
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( b ), FALSE );
-	second = NA_OBJECT_ACTION( b );
-
-	if( !NA_OBJECT_ACTION( a )->private->dispose_has_run &&
-		!NA_OBJECT_ACTION( b )->private->dispose_has_run ){
-
-		if( equal ){
-			equal = ( strcmp( first->private->version, second->private->version ) == 0 );
-		}
-
-		if( equal ){
-			equal = ( NA_OBJECT_ACTION( a )->private->target_selection && NA_OBJECT_ACTION( b )->private->target_selection ) ||
-					( !NA_OBJECT_ACTION( a )->private->target_selection && !NA_OBJECT_ACTION( b )->private->target_selection );
-		}
-
-		if( equal ){
-			equal = ( NA_OBJECT_ACTION( a )->private->target_background && NA_OBJECT_ACTION( b )->private->target_background ) ||
-					( !NA_OBJECT_ACTION( a )->private->target_background && !NA_OBJECT_ACTION( b )->private->target_background );
-		}
-
-		if( equal ){
-			equal = ( NA_OBJECT_ACTION( a )->private->target_toolbar && NA_OBJECT_ACTION( b )->private->target_toolbar ) ||
-					( !NA_OBJECT_ACTION( a )->private->target_toolbar && !NA_OBJECT_ACTION( b )->private->target_toolbar );
-		}
-
-		if( equal ){
-			equal = ( NA_OBJECT_ACTION( a )->private->use_same_label && NA_OBJECT_ACTION( b )->private->use_same_label ) ||
-					( !NA_OBJECT_ACTION( a )->private->use_same_label && !NA_OBJECT_ACTION( b )->private->use_same_label );
-		}
-
-		if( equal ){
-			equal =
-				( g_utf8_collate( NA_OBJECT_ACTION( a )->private->toolbar_label, NA_OBJECT_ACTION( b )->private->toolbar_label ) == 0 );
-		}
-
-		if( equal ){
-			profiles = na_object_get_items_list( a );
-			for( ip = profiles ; ip && equal ; ip = ip->next ){
-				id = na_object_get_id( ip->data );
-				profile = NA_OBJECT_PROFILE( na_object_get_item( b, id ));
-				equal = !na_object_is_modified( profile );
-
-#if NA_IDUPLICABLE_EDITION_STATUS_DEBUG
-				if( !equal ){
-					g_debug( "na_object_action_are_equal: profile=%p, equal=False", ( void * ) profile );
-				}
 #endif
 
-				g_free( id );
-			}
-		}
-
-#if NA_IDUPLICABLE_EDITION_STATUS_DEBUG
-		g_debug( "na_object_action_object_are_equal: a=%p (%s), b=%p (%s), are_equal=%s",
-				( void * ) a, G_OBJECT_TYPE_NAME( a ),
-				( void * ) b, G_OBJECT_TYPE_NAME( b ),
-				equal ? "True":"False" );
-#endif
-	}
-
-	return( equal );
-}
-
-/*
- * a valid NAObjectAction requires a not null, not empty label
- * this is checked here as NAObjectId doesn't have this condition
- *
- * and at least one valid profile
- * checked here because NAObjectItem doesn't have this condition
- */
-gboolean
-object_is_valid( const NAObject *action )
-{
-	gboolean is_valid = TRUE;
-	GList *profiles, *ip;
-	gint valid_profiles;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), FALSE );
-
-	if( !NA_OBJECT_ACTION( action )->private->dispose_has_run ){
-
-		if( na_object_action_is_target_toolbar( NA_OBJECT_ACTION( action ))){
-			is_valid =
-				is_valid_short_label( NA_OBJECT_ACTION( action ));
-
-		} else {
-			is_valid =
-				is_valid_label( NA_OBJECT_ACTION( action ));
-		}
-
-		if( is_valid ){
-			valid_profiles = 0;
-			profiles = na_object_get_items_list( action );
-			for( ip = profiles ; ip && !valid_profiles ; ip = ip->next ){
-				if( na_iduplicable_is_valid( ip->data )){
-					valid_profiles += 1;
-				}
-			}
-			is_valid = ( valid_profiles > 0 );
-		}
-	}
-
-	return( is_valid );
-}
-
-static gboolean
-is_valid_label( const NAObjectAction *action )
-{
-	gboolean is_valid;
-	gchar *label;
-
-	label = na_object_get_label( action );
-	is_valid = ( label && g_utf8_strlen( label, -1 ) > 0 );
-	g_free( label );
-
-	return( is_valid );
-}
-
-static gboolean
-is_valid_short_label( const NAObjectAction *action )
-{
-	gboolean is_valid;
-	gchar *label;
-
-	label = na_object_action_toolbar_get_label( action );
-	is_valid = ( label && g_utf8_strlen( label, -1 ) > 0 );
-	g_free( label );
-
-	return( is_valid );
+	return( is_candidate );
 }



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