Commit a995e7c8 authored by Pierre Wieser's avatar Pierre Wieser

Create a whole new object model, and defines some communication interfaces

NactAction and NactActionProfile are object themselves.
NactIIOProvider is a communication interface with various storage subsystems.
NactIIOClient is a helper interface for objects which implement NactIIOProvider.
parent 7a1cb246
2009-06-02 Pierre Wieser <pwieser@trychlos.org>
Create a whole new object model, and defines some communication
interfaces.
* src/plugin/nautilus-actions.c:
* src/plugin/nautilus-actions.h:
Connect and load list of NactAction actions.
......@@ -19,10 +22,16 @@
* src/common/nact-action-profile.h:
* src/common/nact-gconf.c:
* src/common/nact-gconf.h:
* src/common/nact-storage.c:
* src/common/nact-storage.h:
Updated accordingly.
* src/common/nact-iio-client.c:
* src/common/nact-iio-client.h:
* src/common/nact-iio-provider.c:
* src/common/nact-iio-provider.c:
* src/common/nact-io-client.c:
* src/common/nact-io-client.h:
New files.
2009-06-01 Pierre Wieser <pwieser@trychlos.org>
* configure.ac: Have a more funny package string.
......
......@@ -42,8 +42,16 @@ libnact_la_SOURCES = \
nact-gconf.c \
nact-gconf.h \
nact-gconf-keys.h \
nact-storage.c \
nact-storage.h \
nact-iio-client.c \
nact-iio-client.h \
nact-iio-provider.c \
nact-iio-provider.h \
nact-io-client.c \
nact-io-client.h \
nact-object.c \
nact-object.h \
nact-pivot.c \
nact-pivot.h \
nautilus-actions-config.c \
nautilus-actions-config.h \
nautilus-actions-config-gconf.c \
......
......@@ -31,39 +31,15 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <libnautilus-extension/nautilus-file-info.h>
#include <string.h>
#include "nact-action-profile.h"
#include "uti-lists.h"
static NactStorageClass *st_parent_class = NULL;
#include <string.h>
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_finalize( GObject *object );
static gchar *get_id( const NactStorage *profile );
static void do_dump( const NactStorage *profile );
static void do_dump_list( const gchar *thisfn, const gchar *label, GSList *list );
static int validate_schemes( GSList* schemes2test, NautilusFileInfo* file );
#include <libnautilus-extension/nautilus-file-info.h>
enum {
PROP_ACTION = 1,
PROP_PROFILE_NAME,
PROP_LABEL,
PROP_PATH,
PROP_PARAMETERS,
PROP_ACCEPT_MULTIPLE,
PROP_BASENAMES,
PROP_ISDIR,
PROP_ISFILE,
PROP_MATCHCASE,
PROP_MIMETYPES,
PROP_SCHEMES
};
#include "nact-action-profile.h"
#include "nact-iio-client.h"
#include "nact-iio-provider.h"
#include "uti-lists.h"
struct NactActionProfilePrivate {
gboolean dispose_has_run;
......@@ -74,7 +50,7 @@ struct NactActionProfilePrivate {
/* profile properties
*/
gchar *name;
gchar *name; /* GConf key = id */
gchar *label;
gchar *path;
gchar *parameters;
......@@ -90,6 +66,35 @@ struct NactActionProfilePrivate {
struct NactActionProfileClassPrivate {
};
enum {
PROP_ACTION = 1,
PROP_PROFILE_NAME,
PROP_LABEL,
PROP_PATH,
PROP_PARAMETERS,
PROP_ACCEPT_MULTIPLE,
PROP_BASENAMES,
PROP_ISDIR,
PROP_ISFILE,
PROP_MATCHCASE,
PROP_MIMETYPES,
PROP_SCHEMES
};
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_finalize( GObject *object );
static void do_dump( const NactObject *profile );
static void do_dump_list( const gchar *thisfn, const gchar *label, GSList *list );
static int validate_schemes( GSList* schemes2test, NautilusFileInfo* file );
GType
nact_action_profile_get_type( void )
{
......@@ -117,7 +122,7 @@ register_type( void )
( GInstanceInitFunc ) instance_init
};
return( g_type_register_static( NACT_STORAGE_TYPE, "NactActionProfile", &info, 0 ));
return( g_type_register_static( NACT_OBJECT_TYPE, "NactActionProfile", &info, 0 ));
}
static void
......@@ -222,8 +227,7 @@ class_init( NactActionProfileClass *klass )
klass->private = g_new0( NactActionProfileClassPrivate, 1 );
NACT_STORAGE_CLASS( klass )->get_id = get_id;
NACT_STORAGE_CLASS( klass )->do_dump = do_dump;
NACT_OBJECT_CLASS( klass )->dump = do_dump;
}
static void
......@@ -412,9 +416,9 @@ instance_finalize( GObject *object )
}
NactActionProfile *
nact_action_profile_new( const NactStorage *action, const gchar *name )
nact_action_profile_new( const NactObject *action, const gchar *name )
{
g_assert( NACT_IS_STORAGE( action ));
g_assert( NACT_IS_OBJECT( action ));
g_assert( name && strlen( name ));
NactActionProfile *profile =
......@@ -422,25 +426,31 @@ nact_action_profile_new( const NactStorage *action, const gchar *name )
return( profile );
}
static gchar *
get_id( const NactStorage *profile )
/**
* Load an action.
*
* @action: a NactAction previously allocated via nact_action_new.
*/
void
nact_action_profile_load( NactObject *object )
{
g_assert( NACT_IS_ACTION_PROFILE( profile ));
gchar *id;
g_object_get( G_OBJECT( profile ), "name", &id, NULL );
return( id );
g_assert( NACT_IS_ACTION_PROFILE( object ));
/*NactActionProfile *profile = NACT_ACTION_PROFILE( object );*/
nact_iio_provider_load_profile_properties( object );
}
static void
do_dump( const NactStorage *object )
do_dump( const NactObject *object )
{
static const gchar *thisfn = "nact_action_profile_do_dump";
g_assert( NACT_IS_ACTION_PROFILE( object ));
NactActionProfile *self = NACT_ACTION_PROFILE( object );
if( st_parent_class->do_dump ){
st_parent_class->do_dump( object );
if( st_parent_class->dump ){
st_parent_class->dump( object );
}
g_debug( "%s: profile_name='%s'", thisfn, self->private->name );
......@@ -473,6 +483,43 @@ do_dump_list( const gchar *thisfn, const gchar *label, GSList *list )
g_string_free( str, TRUE );
}
/**
* Returns a pointer to the action for this profile.
*/
NactObject *
nact_action_profile_get_action( const NactActionProfile *profile )
{
g_assert( NACT_IS_ACTION_PROFILE( profile ));
gpointer action;
g_object_get( G_OBJECT( profile ), "action", &action, NULL );
return( NACT_OBJECT( action ));
}
/**
* Returns the profile name.
*
* The returned string should be g_freed by the caller.
*
* The profile name is also the GConf-key of the profile.
*/
gchar *
nact_action_profile_get_id( const NactActionProfile *profile )
{
g_assert( NACT_IS_ACTION_PROFILE( profile ));
gchar *id;
g_object_get( G_OBJECT( profile ), "name", &id, NULL );
return( id );
}
/**
* Returns the path of the command in the profile.
*
* The returned string should be g_freed by the caller.
*/
gchar *
nact_action_profile_get_path( const NactActionProfile *profile )
{
......@@ -484,6 +531,11 @@ nact_action_profile_get_path( const NactActionProfile *profile )
return( path );
}
/**
* Returns the parameters of the command in the profile.
*
* The returned string should be g_freed by the caller.
*/
gchar *
nact_action_profile_get_parameters( const NactActionProfile *profile )
{
......
......@@ -38,10 +38,10 @@
* definition of an action.
*
* As NactAction itself, NactActionProfile class is derived from
* NactStorage which takes care of i/o.
* NactObject which takes care of i/o.
*/
#include "nact-storage.h"
#include "nact-object.h"
G_BEGIN_DECLS
......@@ -55,7 +55,7 @@ G_BEGIN_DECLS
typedef struct NactActionProfilePrivate NactActionProfilePrivate;
typedef struct {
NactStorage parent;
NactObject parent;
NactActionProfilePrivate *private;
}
NactActionProfile;
......@@ -63,15 +63,19 @@ typedef struct {
typedef struct NactActionProfileClassPrivate NactActionProfileClassPrivate;
typedef struct {
NactStorageClass parent;
NactObjectClass parent;
NactActionProfileClassPrivate *private;
}
NactActionProfileClass;
GType nact_action_profile_get_type( void );
NactActionProfile *nact_action_profile_new( const NactStorage *action, const gchar *name );
NactActionProfile *nact_action_profile_new( const NactObject *action, const gchar *name );
void nact_action_profile_load( NactObject *profile );
NactObject *nact_action_profile_get_action( const NactActionProfile *profile );
gchar *nact_action_profile_get_id( const NactActionProfile *profile );
gchar *nact_action_profile_get_path( const NactActionProfile *profile );
gchar *nact_action_profile_get_parameters( const NactActionProfile *profile );
......
......@@ -31,37 +31,25 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include "nact-action.h"
#include "nact-action-profile.h"
#include "nact-iio-client.h"
#include "nact-iio-provider.h"
#include "nact-io-client.h"
#include "uti-lists.h"
static NactStorageClass *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 gchar *get_id( const NactStorage *action );
static void do_dump( const NactStorage *action );
enum {
PROP_UUID = 1,
PROP_VERSION,
PROP_LABEL,
PROP_TOOLTIP,
PROP_ICON
};
struct NactActionPrivate {
gboolean dispose_has_run;
/* io client
*/
NactIOClient *io;
/* action properties
*/
gchar *uuid;
gchar *version;
gchar *label;
gchar *tooltip;
......@@ -76,6 +64,48 @@ struct NactActionPrivate {
struct NactActionClassPrivate {
};
enum {
PROP_VERSION = 1,
PROP_LABEL,
PROP_TOOLTIP,
PROP_ICON
};
static NactObjectClass *st_parent_class = NULL;
static GType register_type( void );
static void class_init( NactActionClass *klass );
static void iio_client_iface_init( NactIIOClientInterface *iface );
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 void free_profiles( NactAction *action );
static GObject *do_get_io_client( const NactIIOClient *client );
static void do_dump( 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( gpointer provider, gpointer data )
{
NactAction *action = g_object_new( NACT_ACTION_TYPE, NULL );
action->private->io = nact_io_client_new( provider, data );
return( action );
}
GType
nact_action_get_type( void )
{
......@@ -103,7 +133,17 @@ register_type( void )
( GInstanceInitFunc ) instance_init
};
return( g_type_register_static( NACT_STORAGE_TYPE, "NactAction", &info, 0 ));
GType type = g_type_register_static( NACT_OBJECT_TYPE, "NactAction", &info, 0 );
static const GInterfaceInfo iio_client_iface_info = {
( GInterfaceInitFunc ) iio_client_iface_init,
NULL,
NULL
};
g_type_add_interface_static( type, NACT_IIO_CLIENT_TYPE, &iio_client_iface_info );
return( type );
}
static void
......@@ -123,13 +163,6 @@ class_init( NactActionClass *klass )
GParamSpec *spec;
/* the id of the object is marked as G_PARAM_CONSTRUCT_ONLY */
spec = g_param_spec_string(
"uuid",
"uuid",
"Globally unique identifier of the action", "",
G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
g_object_class_install_property( object_class, PROP_UUID, spec );
spec = g_param_spec_string(
"version",
"version",
......@@ -160,8 +193,16 @@ class_init( NactActionClass *klass )
klass->private = g_new0( NactActionClassPrivate, 1 );
NACT_STORAGE_CLASS( klass )->get_id = get_id;
NACT_STORAGE_CLASS( klass )->do_dump = do_dump;
NACT_OBJECT_CLASS( klass )->dump = do_dump;
}
static void
iio_client_iface_init( NactIIOClientInterface *iface )
{
static const gchar *thisfn = "nact_action_iio_client_iface_init";
g_debug( "%s: iface=%p", thisfn, iface );
iface->get_io_client = do_get_io_client;
}
static void
......@@ -184,10 +225,6 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
NactAction *self = NACT_ACTION( object );
switch( property_id ){
case PROP_UUID:
g_value_set_string( value, self->private->uuid );
break;
case PROP_VERSION:
g_value_set_string( value, self->private->version );
break;
......@@ -217,11 +254,6 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
NactAction *self = NACT_ACTION( object );
switch( property_id ){
case PROP_UUID:
g_free( self->private->uuid );
self->private->uuid = g_value_dup_string( value );
break;
case PROP_VERSION:
g_free( self->private->version );
self->private->version = g_value_dup_string( value );
......@@ -261,10 +293,14 @@ instance_dispose( GObject *object )
self->private->dispose_has_run = TRUE;
GSList *item;
for( item = self->private->profiles ; item != NULL ; item = item->next ){
g_object_unref( NACT_ACTION_PROFILE( item->data ));
}
/* release the io_client object */
g_object_unref( self->private->io );
/* release the profiles */
free_profiles( self );
/* release the provider data */
nact_iio_provider_release_data( NACT_IIO_CLIENT( self ));
/* chain up to the parent class */
G_OBJECT_CLASS( st_parent_class )->dispose( object );
......@@ -280,7 +316,6 @@ instance_finalize( GObject *object )
g_assert( NACT_IS_ACTION( object ));
NactAction *self = ( NactAction * ) object;
g_free( self->private->uuid );
g_free( self->private->version );
g_free( self->private->label );
g_free( self->private->tooltip );
......@@ -292,28 +327,58 @@ instance_finalize( GObject *object )
}
}
static gchar *
get_id( const NactStorage *action )
static void
free_profiles( NactAction *action )
{
g_assert( NACT_IS_ACTION( action ));
GSList *ip;
for( ip = action->private->profiles ; ip ; ip = ip->next ){
g_object_unref( NACT_ACTION_PROFILE( ip->data ));
}
g_slist_free( action->private->profiles );
action->private->profiles = NULL;
}
static GObject *
do_get_io_client( const NactIIOClient *client )
{
g_assert( NACT_IS_IIO_CLIENT( client ));
g_assert( NACT_IS_ACTION( client ));
NactAction *action = NACT_ACTION( client );
return( G_OBJECT( action->private->io ));
}
/**
* Load an action.
*
* @action: a NactAction previously allocated via nact_action_new.
*/
void
nact_action_load( NactAction *action )
{
g_assert( NACT_IS_ACTION( action ));
gchar *id;
g_object_get( G_OBJECT( action ), "uuid", &id, NULL );
return( id );
g_assert( NACT_IS_IIO_CLIENT( action ));
nact_iio_provider_load_action_properties( NACT_IIO_CLIENT( action ));
action->private->profiles = nact_iio_provider_load_profiles( NACT_IIO_CLIENT( action ));
nact_object_dump( NACT_OBJECT( action ));
}
static void
do_dump( const NactStorage *action )
do_dump( const NactObject *action )
{
static const gchar *thisfn = "nact_action_do_dump";
g_assert( NACT_IS_ACTION( action ));
NactAction *self = NACT_ACTION( action );
if( st_parent_class->do_dump ){
st_parent_class->do_dump( action );
if( st_parent_class->dump ){
st_parent_class->dump( action );
}
g_debug( "%s: uuid='%s'", thisfn, self->private->uuid );
g_debug( "%s: version='%s'", thisfn, self->private->version );
g_debug( "%s: label='%s'", thisfn, self->private->label );
g_debug( "%s: tooltip='%s'", thisfn, self->private->tooltip );
......@@ -323,43 +388,8 @@ do_dump( const NactStorage *action )
g_debug( "%s: %d profile(s) at %p", thisfn, nact_action_get_profiles_count( self ), self->private->profiles );
GSList *item;
for( item = self->private->profiles ; item != NULL ; item = item->next ){
nact_storage_dump(( const NactStorage * ) item->data );
}
}
/**
* Allocate and return the list of defined actions.
*
* Delegate to NactStorage how to search for locations of actions. The
* class will ask for this to each registered storage subsystem (GConf
* only for now).
*
* NactStorage concatenates received lists and return the result as a
* list of pre-initialized NactStorage (actually NactAction) objects,
* each of them being able to address its own location.
*/
GSList *
nact_action_load_actions( void )
{
static gchar *thisfn = "nact_action_load_actions";
g_debug( "%s", thisfn );
/* we read a first list which contains the list of actions
* as NactStorage-initialized objects
*/
GSList *actions = nact_storage_load_actions( NACT_ACTION_TYPE );
GSList *item;
for( item = actions ; item != NULL ; item = item->next ){
NactAction *obj = ( NactAction * ) item->data;
obj->private->profiles =
nact_storage_load_profiles(( NactStorage * ) obj, NACT_ACTION_PROFILE_TYPE );
nact_storage_dump( NACT_STORAGE( item->data ));
nact_object_dump(( const NactObject * ) item->data );
}
return( actions );
}
/**
......@@ -462,6 +492,18 @@ nact_action_get_profiles( const NactAction *action )
return( action->private->profiles );
}
/**
* Set the list of the profiles for the action.
*/
void
nact_action_set_profiles( NactAction *action, GSList *list )
{
g_assert( NACT_IS_ACTION( action ));
free_profiles( action );
action->private->profiles = list;
}
guint
nact_action_get_profiles_count( const NactAction *action )
{
......@@ -495,7 +537,7 @@ nact_action_free_profile_ids( GSList *list )
nactuti_free_string_list( list );
}
NactActionProfile*
NactObject*
nact_action_get_profile( const NactAction *action, const gchar *profile_name )
{
g_assert( NACT_IS_ACTION( action ));
......@@ -514,5 +556,5 @@ nact_action_get_profile( const NactAction *action, const gchar *profile_name )
}
g_free( name );
}
return( found );
return( NACT_OBJECT( found ));
}
......@@ -36,13 +36,10 @@
*
* This is the class which maintains an action.
*
* Note that an action is globally identified by its uuid.
*
* NactAction class is derived from NactStorage which takes care of i/o.
* NactAction class is derived from NactObject.
*/
#include "nact-storage.h"
#include "nact-action-profile.h"
#include "nact-object.h"
G_BEGIN_DECLS
......@@ -56,7 +53,7 @@ G_BEGIN_DECLS
typedef struct NactActionPrivate NactActionPrivate;
typedef struct {
NactStorage parent;
NactObject parent;
NactActionPrivate *private;
}
NactAction;
......@@ -64,26 +61,30 @@ typedef struct {
typedef struct NactActionClassPrivate NactActionClassPrivate;
typedef struct {
NactStorageClass parent;
NactObjectClass parent;
NactActionClassPrivate *private;
}
NactActionClass;
GType nact_action_get_type( void );
GType nact_action_get_type( void );
NactAction *nact_action_new( gpointer provider, gpointer data );
void nact_action_load( NactAction *action );
GSList *nact_action_load_actions( void );
gchar *nact_action_get_uuid( const NactAction *action );
gchar *nact_action_get_label( const NactAction *action );
gchar *nact_action_get_tooltip( const NactAction *action );
gchar *nact_action_get_verified_icon_name( const NactAction *action );
gchar *nact_action_get_uuid( const NactAction *action );
gchar *nact_action_get_label( const NactAction *action );
gchar *nact_action_get_tooltip( const NactAction *action );
gchar *nact_action_get_verified_icon_name( const NactAction *action );
GSList *nact_action_get_profiles( const NactAction *action );
void nact_action_set_profiles( NactAction *action, GSList *list );
GSList *nact_action_get_profiles( const NactAction *action );
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 );
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 );
NactActionProfile *nact_action_get_profile( const NactAction *action, const gchar *name );
NactObject *nact_action_get_profile( const NactAction *action, const gchar *name );
G_END_DECLS
......
......@@ -32,6 +32,6 @@
#define __NACT_GCONF_KEYS_H__
/* GConf general information */
#define NACT_GCONF_CONFIG NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR "/configurations"
#define NACT_GCONF_CONFIG_PATH NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR "/configurations"
#endif /* __NACT_GCONF_KEYS_H__ */
This diff is collapsed.
......@@ -32,20 +32,41 @@
#define __NACT_GCONF_H__
/*
* read/write api for the GCong storage subsystem
* NactGConf class definition.
*
* Implements the NactIIOProvider (I/O storage subsystem) interface.
*/
#include <glib.h>
#include "nact-storage.h"
#include <glib-object.h>
G_BEGIN_DECLS
void nact_gconf_dispose( gpointer io );
void nact_gconf_dump( gpointer io );
#define NACT_GCONF_TYPE ( nact_gconf_get_type())
#define NACT_GCONF( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, NACT_GCONF_TYPE, NactGConf ))
#define NACT_GCONF_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, NACT_GCONF_TYPE, NactGConfClass ))