Commit b99cfe0f authored by Pierre Wieser's avatar Pierre Wieser

Define libna-runtime convenience library

It centralizes classes and methods which are only shared by the Nautilus Actions plugin.
This should help to keep the plugin as light and efficient as possible.
parent 8c3cf421
2009-10-02 Pierre Wieser <pwieser@trychlos.org>
Centralize plugin routines in a dedicated libna-runtime library.
* configure.ac: Add src/runtime/Makefile generation.
* m4/na-log-domains.m4: Define NA-runtime log domain.
* src/Makefile.am: Recurse into runtime subdirectory.
* src/common/na-gconf-keys-base.h:
* src/common/na-gconf-keys-schemas.h:
* src/common/na-gconf-monitor.c:
* src/common/na-gconf-monitor.h:
* src/common/na-gconf-provider-keys.h:
* src/common/na-gconf-provider.c:
* src/common/na-gconf-provider.h:
* src/common/na-gconf-utils.c:
* src/common/na-gconf-utils.h:
* src/common/na-gnome-vfs-uri.c:
* src/common/na-gnome-vfs-uri.h:
* src/common/na-iabout.c:
* src/common/na-iabout.h:
* src/common/na-iduplicable.c:
* src/common/na-iduplicable.h:
* src/common/na-iio-provider.c:
* src/common/na-iio-provider.h:
* src/common/na-ipivot-consumer.c:
* src/common/na-ipivot-consumer.h:
* src/common/na-object-action-class.h:
* src/common/na-object-class.h:
* src/common/na-object-id-class.h:
* src/common/na-object-item-class.h:
* src/common/na-object-profile-class.h:
* src/common/na-pivot.c:
* src/common/na-pivot.h: Moved to libna-runtime library.
* src/common/na-object-action.c:
* src/common/na-object-action.h:
* src/common/na-object-menu.c:
* src/common/na-object-menu.h:
* src/common/na-object-profile.c:
* src/common/na-object-profile.h: Remove runtime functions.
* src/common/Makefile.am: Updated accordingly.
* src/runtime/Makefile.am: New file.
2009-10-02 Pierre Wieser <pwieser@trychlos.org>
* src/nact/base-application.c:
......
......@@ -51,6 +51,7 @@ AC_CONFIG_FILES([
src/common/Makefile
src/nact/Makefile
src/plugin/Makefile
src/runtime/Makefile
src/test/Makefile
src/utils/Makefile
po/Makefile.in
......
......@@ -2,11 +2,14 @@ dnl define three distinct log domains, respectively for common code,
dnl plugin and NACT user interface - log handlers will be disabled
dnl when not in development mode
# serial 1 creation
# serial 2 define NA-runtime log domain
AC_DEFUN([NA_LOG_DOMAINS],[
AC_SUBST([NA_LOGDOMAIN_RUNTIME],[NA-runtime])
AC_DEFINE_UNQUOTED([NA_LOGDOMAIN_RUNTIME],["NA-runtime"],[Log domain of runtime library])
AC_SUBST([NA_LOGDOMAIN_COMMON],[NA-common])
AC_DEFINE_UNQUOTED([NA_LOGDOMAIN_COMMON],["NA-common"],[Log domain of common code])
AC_DEFINE_UNQUOTED([NA_LOGDOMAIN_COMMON],["NA-common"],[Log domain of common library])
AC_SUBST([NA_LOGDOMAIN_PLUGIN],[NA-plugin])
AC_DEFINE_UNQUOTED([NA_LOGDOMAIN_PLUGIN],["NA-plugin"],[Log domain of Nautilus plugin])
......
......@@ -28,6 +28,7 @@
SUBDIRS = \
common \
runtime \
nact \
plugin \
test \
......
......@@ -26,7 +26,7 @@
# Pierre Wieser <pwieser@trychlos.org>
# ... and many others (see AUTHORS)
noinst_LTLIBRARIES = libnact.la
noinst_LTLIBRARIES = libna-common.la
AM_CPPFLAGS += \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
......@@ -34,48 +34,22 @@ AM_CPPFLAGS += \
$(NAUTILUS_ACTIONS_CFLAGS) \
$(NULL)
libnact_la_SOURCES = \
na-gconf-keys-base.h \
na-gconf-keys-schemas.h \
na-gconf-monitor.c \
na-gconf-monitor.h \
na-gconf-provider.c \
na-gconf-provider.h \
na-gconf-provider-keys.h \
na-gconf-utils.c \
na-gconf-utils.h \
na-gnome-vfs-uri.c \
na-gnome-vfs-uri.h \
na-iabout.c \
na-iabout.h \
na-iduplicable.c \
na-iduplicable.h \
na-iio-provider.c \
na-iio-provider.h \
na-ipivot-consumer.c \
na-ipivot-consumer.h \
libna_common_la_SOURCES = \
na-iprefs.c \
na-iprefs.h \
na-object.c \
na-object-api.h \
na-object-class.h \
na-object-fn.h \
na-object-id.c \
na-object-id-class.h \
na-object-id-fn.h \
na-object-item.c \
na-object-item-class.h \
na-object-item-fn.h \
na-object-action.c \
na-object-action.h \
na-object-action-class.h \
na-object-menu.c \
na-object-menu.h \
na-object-profile.c \
na-object-profile.h \
na-object-profile-class.h \
na-pivot.c \
na-pivot.h \
na-utils.c \
na-utils.h \
na-xml-names.h \
......@@ -83,7 +57,7 @@ libnact_la_SOURCES = \
na-xml-writer.h \
$(NULL)
libnact_la_LIBADD = \
libna_common_la_LIBADD = \
-lxml2 \
-luuid \
$(NULL)
......@@ -333,32 +333,6 @@ na_object_action_new_with_profile( void )
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_readonly:
* @action: the #NAObjectAction object to be requested.
......@@ -428,48 +402,6 @@ na_object_action_set_readonly( NAObjectAction *action, gboolean readonly )
}
}
/**
* 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 unique
* name. The provided name is so only suitable for the specified
* @action.
*
* Returns: a newly allocated profile name, which should be g_free() by
* the caller.
*/
gchar *
na_object_action_get_new_profile_name( const NAObjectAction *action )
{
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=1 ; !ok ; ++i ){
g_free( candidate );
candidate = g_strdup_printf( "%s%d", OBJECT_PROFILE_PREFIX, i );
if( !na_object_get_item( action, candidate )){
ok = TRUE;
}
}
if( !ok ){
g_free( candidate );
candidate = NULL;
}
}
return( candidate );
}
/**
* na_object_action_attach_profile:
* @action: the #NAObjectAction action to which the profile will be attached.
......
......@@ -44,22 +44,14 @@
G_BEGIN_DECLS
/* i18n: default label for a newly created action */
#define NA_OBJECT_ACTION_DEFAULT_LABEL _( "New Nautilus action" )
/* i18n: default label for a newly created profile */
#define NA_OBJECT_PROFILE_DEFAULT_LABEL _( "New profile" )
NAObjectAction *na_object_action_new( void );
NAObjectAction *na_object_action_new_with_profile( void );
gchar *na_object_action_get_version( const NAObjectAction *action );
gboolean na_object_action_is_readonly( const NAObjectAction *action );
void na_object_action_set_version( NAObjectAction *action, const gchar *version );
void na_object_action_set_readonly( NAObjectAction *action, gboolean readonly );
gchar *na_object_action_get_new_profile_name( const NAObjectAction *action );
void na_object_action_attach_profile( NAObjectAction *action, NAObjectProfile *profile );
G_END_DECLS
......
......@@ -45,17 +45,10 @@ G_BEGIN_DECLS
/* NAObject
*/
#define na_object_dump( object ) na_object_object_dump( NA_OBJECT( object ))
#define na_object_dump_norec( object ) na_object_object_dump_norec( NA_OBJECT( object ))
#define na_object_dump_tree( tree ) na_object_object_dump_tree( tree )
#define na_object_get_clipboard_id( object ) na_object_object_get_clipboard_id( NA_OBJECT( object ))
#define na_object_ref( object ) na_object_object_ref( NA_OBJECT( object ))
/* NAIDuplicable
*/
#define na_object_duplicate( object ) na_object_iduplicable_duplicate( NA_OBJECT( object ))
#define na_object_check_edition_status( object ) na_object_iduplicable_check_edition_status( NA_OBJECT( object ))
#define na_object_is_modified( object ) na_object_iduplicable_is_modified( NA_OBJECT( object ))
#define na_object_is_valid( object ) na_object_iduplicable_is_valid( NA_OBJECT( object ))
#define na_object_get_origin( object ) na_object_iduplicable_get_origin( NA_OBJECT( object ))
......@@ -64,33 +57,11 @@ G_BEGIN_DECLS
/* NAObjectId
*/
#define na_object_get_id( object ) na_object_id_get_id( NA_OBJECT_ID( object ))
#define na_object_get_label( object ) na_object_id_get_label( NA_OBJECT_ID( object ))
#define na_object_set_id( object, id ) na_object_id_set_id( NA_OBJECT_ID( object ), id )
#define na_object_set_for_copy( object, relabel ) na_object_id_set_for_copy( NA_OBJECT_ID( object ), relabel )
#define na_object_set_new_id( object ) na_object_id_set_new_id( NA_OBJECT_ID( object ))
#define na_object_set_label( object, label ) na_object_id_set_label( NA_OBJECT_ID( object ), label )
/* NAObjectItem
*/
#define na_object_get_tooltip( object ) na_object_item_get_tooltip( NA_OBJECT_ITEM( object ))
#define na_object_get_icon( object ) na_object_item_get_icon( NA_OBJECT_ITEM( object ))
#define na_object_get_pixbuf( object ) na_object_item_get_pixbuf( NA_OBJECT_ITEM( object ))
#define na_object_get_provider( object ) na_object_item_get_provider( NA_OBJECT_ITEM( object ))
#define na_object_is_enabled( object ) na_object_item_is_enabled( NA_OBJECT_ITEM( object ))
#define na_object_get_item( object, id ) na_object_item_get_item( NA_OBJECT_ITEM( object ), id )
#define na_object_get_items( object ) na_object_item_get_items( NA_OBJECT_ITEM( object ))
#define na_object_get_items_count( object ) na_object_item_get_items_count( NA_OBJECT_ITEM( object ))
#define na_object_free_items( list ) na_object_item_free_items( list )
#define na_object_set_tooltip( object, tooltip ) na_object_item_set_tooltip( NA_OBJECT_ITEM( object ), tooltip )
#define na_object_set_icon( object, icon ) na_object_item_set_icon( NA_OBJECT_ITEM( object ), icon )
#define na_object_set_provider( object, provider ) na_object_item_set_provider( NA_OBJECT_ITEM( object ), provider )
#define na_object_set_enabled( object, enabled ) na_object_item_set_enabled( NA_OBJECT_ITEM( object ), enabled )
#define na_object_set_items( object, list ) na_object_item_set_items( NA_OBJECT_ITEM( object ), list )
#define na_object_append_item( object, item ) na_object_item_append_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ))
#define na_object_insert_item( object, item, before ) na_object_item_insert_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ), NA_OBJECT( before ))
#define na_object_remove_item( object, item ) na_object_item_remove_item( NA_OBJECT_ITEM( object ), NA_OBJECT( item ))
......
......@@ -49,10 +49,8 @@ G_BEGIN_DECLS
/* NAIDuplicable
*/
void na_object_iduplicable_check_edition_status( const NAObject *object );
NAObject *na_object_iduplicable_duplicate( const NAObject *object );
gboolean na_object_iduplicable_are_equal( const NAObject *a, const NAObject *b );
gboolean na_object_iduplicable_is_modified( const NAObject *object );
gboolean na_object_iduplicable_is_valid( const NAObject *object );
NAObject *na_object_iduplicable_get_origin( const NAObject *object );
void na_object_iduplicable_set_origin( NAObject *object, const NAObject *origin );
......
......@@ -51,7 +51,6 @@ gchar *na_object_id_get_label( const NAObjectId *object );
void na_object_id_set_id( NAObjectId *object, const gchar *id );
void na_object_id_set_for_copy( NAObjectId *object, gboolean relabel );
void na_object_id_set_new_id( NAObjectId *object );
void na_object_id_set_label( NAObjectId *object, const gchar *label );
G_END_DECLS
......
......@@ -82,9 +82,6 @@ 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 gchar *v_new_id( NAObjectId *object );
static gchar *most_derived_new_id( NAObjectId *object );
GType
na_object_id_get_type( void )
{
......@@ -372,48 +369,6 @@ na_object_id_set_for_copy( NAObjectId *object, gboolean relabel )
}
}
/**
* na_object_id_set_new_id:
* @object: the #NAObjectId object whose internal identifiant is to be
* set.
*
* Request a new id to the derived class, and set it.
*/
void
na_object_id_set_new_id( NAObjectId *object )
{
gchar *id;
g_return_if_fail( NA_IS_OBJECT_ID( object ));
if( !object->private->dispose_has_run ){
id = v_new_id( object );
if( id ){
g_object_set( G_OBJECT( object ), NAOBJECT_ID_PROP_ID, id, NULL );
g_free( id );
}
}
}
/**
* na_object_id_set_label:
* @object: the #NAObjectId object whose label is to be set.
* @label: label to be set.
*
* Sets the label of @object by taking a copy of the provided one.
*/
void
na_object_id_set_label( NAObjectId *object, const gchar *label )
{
g_return_if_fail( NA_IS_OBJECT_ID( object ));
if( !object->private->dispose_has_run ){
g_object_set( G_OBJECT( object ), NAOBJECT_ID_PROP_LABEL, label, NULL );
}
}
static void
object_dump( const NAObject *object )
{
......@@ -510,37 +465,3 @@ object_is_valid( const NAObject *object )
return( valid );
}
static gchar *
v_new_id( NAObjectId *object )
{
return( most_derived_new_id( object ));
}
static gchar *
most_derived_new_id( NAObjectId *object )
{
gchar *new_id;
GList *hierarchy, *ih;
gboolean found;
found = FALSE;
new_id = NULL;
hierarchy = g_list_reverse( na_object_get_hierarchy( NA_OBJECT( object )));
/*g_debug( "na_object_id_most_derived_id: object=%p (%s)",
( void * ) object, G_OBJECT_TYPE_NAME( object ));*/
for( ih = hierarchy ; ih && !found ; ih = ih->next ){
if( NA_OBJECT_ID_CLASS( ih->data )->new_id ){
new_id = NA_OBJECT_ID_CLASS( ih->data )->new_id( object );
found = TRUE;
}
if( G_OBJECT_CLASS_TYPE( ih->data ) == NA_OBJECT_ID_TYPE ){
break;
}
}
na_object_free_hierarchy( hierarchy );
return( new_id );
}
......@@ -49,24 +49,8 @@
G_BEGIN_DECLS
gchar *na_object_item_get_tooltip( const NAObjectItem *item );
gchar *na_object_item_get_icon( const NAObjectItem *item );
gchar *na_object_item_get_verified_icon_name( const NAObjectItem *item );
GdkPixbuf *na_object_item_get_pixbuf( const NAObjectItem *item, GtkWidget *widget );
gboolean na_object_item_is_enabled( const NAObjectItem *item );
NAIIOProvider *na_object_item_get_provider( const NAObjectItem *item );
NAObject *na_object_item_get_item( const NAObjectItem *item, const gchar *id );
GList *na_object_item_get_items( const NAObjectItem *item );
guint na_object_item_get_items_count( const NAObjectItem *item );
void na_object_item_free_items( GList *items );
void na_object_item_set_tooltip( NAObjectItem *item, const gchar *tooltip );
void na_object_item_set_icon( NAObjectItem *item, const gchar *icon_name );
void na_object_item_set_enabled( NAObjectItem *item, gboolean enabled );
void na_object_item_set_provider( NAObjectItem *item, const NAIIOProvider *provider );
void na_object_item_set_items( NAObjectItem *item, GList *items );
void na_object_item_append_item( NAObjectItem *item, const NAObject *object );
void na_object_item_insert_item( NAObjectItem *item, const NAObject *object, const NAObject *before );
void na_object_item_remove_item( NAObjectItem *item, const NAObject *object );
......
......@@ -336,54 +336,6 @@ instance_finalize( GObject *object )
}
}
/**
* na_object_item_get_tooltip:
* @item: the #NAObjectItem object to be requested.
*
* Returns the tooltip which will be display in the Nautilus context
* menu item for this @item.
*
* Returns: the tooltip of the @item as a newly allocated string. This
* returned string must be g_free() by the caller.
*/
gchar *
na_object_item_get_tooltip( const NAObjectItem *item )
{
gchar *tooltip = NULL;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
if( !item->private->dispose_has_run ){
g_object_get( G_OBJECT( item ), NAOBJECT_ITEM_PROP_TOOLTIP, &tooltip, NULL );
}
return( tooltip );
}
/**
* na_object_item_get_icon:
* @item: the #NAObjectItem object to be requested.
*
* Returns the name of the icon attached to the Nautilus context menu
* item for this @item.
*
* Returns: the icon name as a newly allocated string. This returned
* string must be g_free() by the caller.
*/
gchar *
na_object_item_get_icon( const NAObjectItem *item )
{
gchar *icon = NULL;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
if( !item->private->dispose_has_run ){
g_object_get( G_OBJECT( item ), NAOBJECT_ITEM_PROP_ICON, &icon, NULL );
}
return( icon );
}
/*
* TODO: remove this function
*/
......@@ -461,143 +413,6 @@ GdkPixbuf *na_object_item_get_pixbuf( const NAObjectItem *item, GtkWidget *widge
return( icon );
}
/**
* na_object_item_get_provider:
* @item: the #NAObjectItem object to be requested.
*
* Returns the initial provider of the item (or the last which has
* accepted a write operation). At the time of this request, this is
* the most probable provider willing to accept a next writing
* operation.
*
* Returns: a #NAIIOProvider object. The reference is
* owned by #NAPivot pivot and should not be g_object_unref() by the
* caller.
*/
NAIIOProvider *
na_object_item_get_provider( const NAObjectItem *item )
{
NAIIOProvider *provider = NULL;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
if( !item->private->dispose_has_run ){
g_object_get( G_OBJECT( item ), NAOBJECT_ITEM_PROP_PROVIDER, &provider, NULL );
}
return( provider );
}
/**
* na_object_item_get_item:
* @item: the #NAObjectItem from which we want retrieve a subitem.
* @id: the id of the searched subitem.
*
* Returns: a pointer to the #NAObject subitem with the required id.
*
* The returned #NAObject is owned by the @item object ; the
* caller should not try to g_free() nor g_object_unref() it.
*/
NAObject *
na_object_item_get_item( const NAObjectItem *item, const gchar *id )
{
GList *it;
NAObject *found = NULL;
NAObject *isub;
gchar *isubid;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
if( !item->private->dispose_has_run ){
for( it = item->private->items ; it && !found ; it = it->next ){
isub = NA_OBJECT( it->data );
isubid = na_object_get_id( isub );
if( !strcmp( id, isubid )){
found = isub;
}
g_free( isubid );
}
}
return( found );
}
/**
* na_object_item_get_items:
* @item: the #NAObjectItem from which we want a list of subitems.
*
* Returns: a newly allocated #GList of #NAObject objects which are
* embedded in the @item. Depending of the exact nature of @item, these
* may be #NAObjectMenu, #NAObjectAction or #NAObjectProfile subitems.
*
* The returned pointer should be na_object_item_free_items() or
* na_object_free_items() by the caller.
*/
GList *
na_object_item_get_items( const NAObjectItem *item )
{
GList *items = NULL;
GList *it;
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
if( !item->private->dispose_has_run ){
for( it = item->private->items ; it ; it = it->next ){
items = g_list_prepend( items, g_object_ref( it->data ));
}
items = g_list_reverse( items );
}
return( items );
}
/**
* na_object_item_get_items_count:
* @item: the #NAObjectItem from which we want a count of subitems.
*
* Returns: the count of subitems of @item.
*/
guint
na_object_item_get_items_count( const NAObjectItem *item )
{
guint count = 0;
/*g_debug( "na_object_item_get_items_count: item=%p (%s)", ( void * ) item, G_OBJECT_TYPE_NAME( item ));*/
g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), 0 );
if( !item->private->dispose_has_run ){
count = item->private->items ? g_list_length( item->private->items ) : 0;
}
return( count );
}
/**
* na_object_item_free_items:
* @list: a list of #NAObject subitems as returned by
* na_object_item_get_items().
*
* Frees the list.
*/
void
na_object_item_free_items( GList *items )
{
GList *it;
for( it = items ; it ; it = it->next ){
if( G_IS_OBJECT( it->data )){
g_object_unref( it->data );
/*} else {
g_warning( "na_object_item_free_items: %p not an object", ( void * ) it->data );*/
}
}
g_list_free( items );
}
/**
* na_object_item_is_enabled:
* @item: the #NAObjectItem object to be requested.
......
......@@ -66,9 +66,6 @@ typedef struct {
}
NAObjectMenuClass;
/* i18n: default label for a newly created menu */
#define NA_OBJECT_MENU_DEFAULT_LABEL _( "New Nautilus menu" )
GType na_object_menu_get_type( void );
NAObjectMenu *na_object_menu_new( void );
......
......@@ -357,35 +357,6 @@ na_object_iduplicable_are_equal( const NAObject *a, const NAObject *b )
return( are_equal );
}
/**
* na_object_iduplicable_is_modified:
* @object: the #NAObject object whose status is requested.
*
* Returns the current modification status of @object.
*
* This suppose that @object has been previously duplicated in order
* to get benefits provided by the IDuplicable interface.
*
* This suppose also that the edition status of @object has previously
* been checked via na_object_check_edited_status().
*
* Returns: %TRUE is the provided object has been modified regarding to
* the original one, %FALSE else.
*/
gboolean
na_object_iduplicable_is_modified( const NAObject *object )
{
gboolean is_modified = FALSE;
g_return_val_if_fail( NA_IS_OBJECT( object ), FALSE );
if( !object->private->dispose_has_run ){
is_modified = na_iduplicable_is_modified( NA_IDUPLICABLE( object ));
}
return( is_modified );
}
/**
* na_object_iduplicable_is_valid:
* @object: the #NAObject object whose validity is to be checked.
......
......@@ -40,61 +40,6 @@
static GSList *text_to_string_list( const gchar *text, const gchar *separator, const gchar *default_value );
/**
* na_utils_find_in_list:
* @list: the GSList of strings to be searched.
* @str: the searched string.
*
* Search for a string in a string list.
*
* Returns: %TRUE if the string has been found in list.
*/
gboolean
na_utils_find_in_list( GSList *list, const gchar *str )
{
GSList *il;
for( il = list ; il ; il = il->next ){
const gchar *istr = ( const gchar * ) il->data;
if( !g_utf8_collate( str, istr )){
return( TRUE );
}
}
return( FALSE );
}