Commit 7ac570ce authored by Pierre Wieser's avatar Pierre Wieser

plugin-menu: replace NAIPivotConsumer interface with na_settings() accessors

parent 1914b48d
...@@ -94,6 +94,11 @@ ...@@ -94,6 +94,11 @@
2011-01-07 Pierre Wieser <pwieser@trychlos.org> 2011-01-07 Pierre Wieser <pwieser@trychlos.org>
* src/core/na-pivot.c (na_pivot_register): New function.
* src/plugin-menu/nautilus-actions.c:
Replace NAIPivotConsumer interface with na_settings() accessors.
* src/core/na-settings.c: * src/core/na-settings.c:
* src/core/na-settings.h: New files. * src/core/na-settings.h: New files.
......
...@@ -52,35 +52,39 @@ struct _NAPivotClassPrivate { ...@@ -52,35 +52,39 @@ struct _NAPivotClassPrivate {
/* private instance data /* private instance data
*/ */
struct _NAPivotPrivate { struct _NAPivotPrivate {
gboolean dispose_has_run; gboolean dispose_has_run;
guint loadable_set; guint loadable_set;
/* dynamically loaded modules (extension plugins) /* dynamically loaded modules (extension plugins)
*/ */
GList *modules; GList *modules;
/* The NASettings object
*/
NASettings *settings;
/* list of instances to be notified of configuration updates /* list of instances to be notified of configuration updates
* these are called 'consumers' of NAPivot * these are called 'consumers' of NAPivot
*/ */
GList *consumers; GList *consumers;
/* configuration tree of actions and menus /* configuration tree of actions and menus
*/ */
GList *tree; GList *tree;
/* whether to automatically reload the whole configuration tree /* whether to automatically reload the whole configuration tree
* when a modification is detected in one of the underlying I/O * when a modification is detected in one of the underlying I/O
* storage subsystems * storage subsystems
* defaults to FALSE * defaults to FALSE
*/ */
gboolean automatic_reload; gboolean automatic_reload;
GTimeVal last_event; GTimeVal last_event;
guint event_source_id; guint event_source_id;
/* list of monitoring objects on runtime preferences /* list of monitoring objects on runtime preferences
*/ */
GList *monitors; GList *monitors;
}; };
/* NAPivot properties /* NAPivot properties
...@@ -376,6 +380,8 @@ na_pivot_new( void ) ...@@ -376,6 +380,8 @@ na_pivot_new( void )
pivot = g_object_new( NA_PIVOT_TYPE, NULL ); pivot = g_object_new( NA_PIVOT_TYPE, NULL );
pivot->private->settings = na_settings_new();
return( pivot ); return( pivot );
} }
...@@ -767,6 +773,23 @@ free_consumers( GList *consumers ) ...@@ -767,6 +773,23 @@ free_consumers( GList *consumers )
g_list_free( consumers ); g_list_free( consumers );
} }
/*
* na_pivot_register:
* @settings: this #NAPivot instance.
* @key: the key to be monitored.
* @callback: the function to be called when the value of the key changes.
* @user_data: data to be passed to the @callback function.
*
* Registers a new consumer of the monitoring of the @key.
*
* Since: 3.1.0
*/
void
na_pivot_register( NAPivot *pivot, const gchar *key, NASettingsCallback callback, gpointer user_data )
{
}
/* /*
* na_pivot_set_automatic_reload: * na_pivot_set_automatic_reload:
* @pivot: this #NAPivot instance. * @pivot: this #NAPivot instance.
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
#include <api/na-object-api.h> #include <api/na-object-api.h>
#include "na-ipivot-consumer.h" #include "na-ipivot-consumer.h"
#include "na-settings.h"
G_BEGIN_DECLS G_BEGIN_DECLS
...@@ -111,7 +112,7 @@ GType na_pivot_get_type( void ); ...@@ -111,7 +112,7 @@ GType na_pivot_get_type( void );
/* properties /* properties
*/ */
#define NAPIVOT_PROP_TREE "na-pivot-prop-tree" #define NAPIVOT_PROP_TREE "na-pivot-prop-tree"
/* Loadable population /* Loadable population
* NACT management user interface defaults to PIVOT_LOAD_ALL * NACT management user interface defaults to PIVOT_LOAD_ALL
...@@ -124,6 +125,8 @@ enum { ...@@ -124,6 +125,8 @@ enum {
PIVOT_LOAD_ALL = 0xff PIVOT_LOAD_ALL = 0xff
}; };
#define NA_PIVOT_RUNTIME_ITEMS_LIST_CHANGED "na-pivot-runtime-items-list-changed"
NAPivot *na_pivot_new( void ); NAPivot *na_pivot_new( void );
void na_pivot_dump( const NAPivot *pivot ); void na_pivot_dump( const NAPivot *pivot );
...@@ -144,8 +147,11 @@ void na_pivot_item_changed_handler( NAIIOProvider *provider, const gcha ...@@ -144,8 +147,11 @@ void na_pivot_item_changed_handler( NAIIOProvider *provider, const gcha
gboolean na_pivot_write_level_zero( const NAPivot *pivot, GList *items, GSList **messages ); gboolean na_pivot_write_level_zero( const NAPivot *pivot, GList *items, GSList **messages );
/* NAIPivotConsumer interface management /* NAIPivotConsumer interface management
* Monitoring and preferences management
*/ */
void na_pivot_register_consumer( NAPivot *pivot, const NAIPivotConsumer *consumer ); void na_pivot_register_consumer( NAPivot *pivot, const NAIPivotConsumer *consumer );
NASettings *na_pivot_get_settings ( NAPivot *pivot );
void na_pivot_register ( NAPivot *pivot, const gchar *key, NASettingsCallback callback, gpointer user_data );
/* NAPivot properties and configuration /* NAPivot properties and configuration
*/ */
......
...@@ -45,8 +45,6 @@ ...@@ -45,8 +45,6 @@
#include <core/na-pivot.h> #include <core/na-pivot.h>
#include <core/na-iabout.h> #include <core/na-iabout.h>
#include <core/na-iprefs.h>
#include <core/na-ipivot-consumer.h>
#include <core/na-selected-info.h> #include <core/na-selected-info.h>
#include <core/na-tokens.h> #include <core/na-tokens.h>
...@@ -59,10 +57,22 @@ struct NautilusActionsClassPrivate { ...@@ -59,10 +57,22 @@ struct NautilusActionsClassPrivate {
}; };
/* private instance data /* private instance data
*
* Runtime modification management:
* We have to react to some runtime environment modifications:
*
* - whether the items list has changed (we have to reload a new pivot)
* > registering for notifications against NAPivot
*
* - whether to add the 'About Nautilus-Actions' item
* - whether to create a 'Nautilus-Actions actions' root menu
* > registering for notifications against NASettings
*/ */
struct NautilusActionsPrivate { struct NautilusActionsPrivate {
gboolean dispose_has_run; gboolean dispose_has_run;
NAPivot *pivot; NAPivot *pivot;
gboolean items_add_about_item;
gboolean items_create_root_menu;
}; };
static GObjectClass *st_parent_class = NULL; static GObjectClass *st_parent_class = NULL;
...@@ -77,12 +87,6 @@ static void instance_finalize( GObject *object ); ...@@ -77,12 +87,6 @@ static void instance_finalize( GObject *object );
static void iabout_iface_init( NAIAboutInterface *iface ); static void iabout_iface_init( NAIAboutInterface *iface );
static gchar *iabout_get_application_name( NAIAbout *instance ); static gchar *iabout_get_application_name( NAIAbout *instance );
static void ipivot_consumer_iface_init( NAIPivotConsumerInterface *iface );
static void ipivot_consumer_items_changed( NAIPivotConsumer *instance, gpointer user_data );
static void ipivot_consumer_create_root_menu_changed( NAIPivotConsumer *instance, gboolean enabled );
static void ipivot_consumer_display_about_changed( NAIPivotConsumer *instance, gboolean enabled );
static void ipivot_consumer_display_order_changed( NAIPivotConsumer *instance, gint order_mode );
static void menu_provider_iface_init( NautilusMenuProviderIface *iface ); static void menu_provider_iface_init( NautilusMenuProviderIface *iface );
static GList *menu_provider_get_background_items( NautilusMenuProvider *provider, GtkWidget *window, NautilusFileInfo *current_folder ); static GList *menu_provider_get_background_items( NautilusMenuProvider *provider, GtkWidget *window, NautilusFileInfo *current_folder );
static GList *menu_provider_get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files ); static GList *menu_provider_get_file_items( NautilusMenuProvider *provider, GtkWidget *window, GList *files );
...@@ -106,6 +110,10 @@ static GList *create_root_menu( NautilusActions *plugin, GList *nauti ...@@ -106,6 +110,10 @@ static GList *create_root_menu( NautilusActions *plugin, GList *nauti
static GList *add_about_item( NautilusActions *plugin, GList *nautilus_menu ); static GList *add_about_item( NautilusActions *plugin, GList *nautilus_menu );
static void execute_about( NautilusMenuItem *item, NautilusActions *plugin ); static void execute_about( NautilusMenuItem *item, NautilusActions *plugin );
static void on_items_list_changed( const gchar *key, gpointer newvalue, NautilusActions *plugin );
static void on_items_add_about_item_changed( const gchar *key, gpointer newvalue, NautilusActions *plugin );
static void on_items_create_root_menu_changed( const gchar *key, gpointer newvalue, NautilusActions *plugin );
GType GType
nautilus_actions_get_type( void ) nautilus_actions_get_type( void )
{ {
...@@ -142,12 +150,6 @@ nautilus_actions_register_type( GTypeModule *module ) ...@@ -142,12 +150,6 @@ nautilus_actions_register_type( GTypeModule *module )
NULL NULL
}; };
static const GInterfaceInfo ipivot_consumer_iface_info = {
( GInterfaceInitFunc ) ipivot_consumer_iface_init,
NULL,
NULL
};
g_debug( "%s: module=%p", thisfn, ( void * ) module ); g_debug( "%s: module=%p", thisfn, ( void * ) module );
g_assert( st_actions_type == 0 ); g_assert( st_actions_type == 0 );
...@@ -156,8 +158,6 @@ nautilus_actions_register_type( GTypeModule *module ) ...@@ -156,8 +158,6 @@ nautilus_actions_register_type( GTypeModule *module )
g_type_module_add_interface( module, st_actions_type, NAUTILUS_TYPE_MENU_PROVIDER, &menu_provider_iface_info ); g_type_module_add_interface( module, st_actions_type, NAUTILUS_TYPE_MENU_PROVIDER, &menu_provider_iface_info );
g_type_module_add_interface( module, st_actions_type, NA_IABOUT_TYPE, &iabout_iface_info ); g_type_module_add_interface( module, st_actions_type, NA_IABOUT_TYPE, &iabout_iface_info );
g_type_module_add_interface( module, st_actions_type, NA_IPIVOT_CONSUMER_TYPE, &ipivot_consumer_iface_info );
} }
static void static void
...@@ -202,6 +202,7 @@ instance_constructed( GObject *object ) ...@@ -202,6 +202,7 @@ instance_constructed( GObject *object )
{ {
static const gchar *thisfn = "nautilus_actions_instance_constructed"; static const gchar *thisfn = "nautilus_actions_instance_constructed";
NautilusActions *self; NautilusActions *self;
NASettings *settings;
g_debug( "%s: object=%p", thisfn, ( void * ) object ); g_debug( "%s: object=%p", thisfn, ( void * ) object );
...@@ -213,11 +214,34 @@ instance_constructed( GObject *object ) ...@@ -213,11 +214,34 @@ instance_constructed( GObject *object )
if( !self->private->dispose_has_run ){ if( !self->private->dispose_has_run ){
self->private->pivot = na_pivot_new(); self->private->pivot = na_pivot_new();
na_pivot_register_consumer( self->private->pivot, NA_IPIVOT_CONSUMER( self ));
/* setup NAPivot properties before loading items
*/
na_pivot_set_automatic_reload( self->private->pivot, TRUE ); na_pivot_set_automatic_reload( self->private->pivot, TRUE );
na_pivot_set_loadable( self->private->pivot, !PIVOT_LOAD_DISABLED & !PIVOT_LOAD_INVALID ); na_pivot_set_loadable( self->private->pivot, !PIVOT_LOAD_DISABLED & !PIVOT_LOAD_INVALID );
na_pivot_load_items( self->private->pivot ); na_pivot_load_items( self->private->pivot );
/* register against NAPivot to be notified of modifications
* of items list
*/
na_pivot_register( self->private->pivot,
NA_PIVOT_RUNTIME_ITEMS_LIST_CHANGED,
( NASettingsCallback ) on_items_list_changed, self );
/* register against NASettings to be notified of changes on
* our runtime preferences
*/
settings = na_pivot_get_settings( self->private->pivot );
self->private->items_add_about_item = na_settings_get_bool( settings, NA_SETTINGS_RUNTIME_ITEMS_ADD_ABOUT_ITEM );
na_settings_register( settings,
NA_SETTINGS_RUNTIME_ITEMS_ADD_ABOUT_ITEM,
( NASettingsCallback ) on_items_add_about_item_changed, self );
self->private->items_create_root_menu = na_settings_get_bool( settings, NA_SETTINGS_RUNTIME_ITEMS_CREATE_ROOT_MENU );
na_settings_register( settings,
NA_SETTINGS_RUNTIME_ITEMS_CREATE_ROOT_MENU,
( NASettingsCallback ) on_items_create_root_menu_changed, self );
/* chain up to the parent class */ /* chain up to the parent class */
if( G_OBJECT_CLASS( st_parent_class )->constructed ){ if( G_OBJECT_CLASS( st_parent_class )->constructed ){
G_OBJECT_CLASS( st_parent_class )->constructed( object ); G_OBJECT_CLASS( st_parent_class )->constructed( object );
...@@ -300,92 +324,6 @@ iabout_get_application_name( NAIAbout *instance ) ...@@ -300,92 +324,6 @@ iabout_get_application_name( NAIAbout *instance )
return( g_strdup( _( "Nautilus-Actions" ))); return( g_strdup( _( "Nautilus-Actions" )));
} }
static void
ipivot_consumer_iface_init( NAIPivotConsumerInterface *iface )
{
static const gchar *thisfn = "nautilus_actions_ipivot_consumer_iface_init";
g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
iface->on_items_changed = ipivot_consumer_items_changed;
iface->on_create_root_menu_changed = ipivot_consumer_create_root_menu_changed;
iface->on_display_about_changed = ipivot_consumer_display_about_changed;
iface->on_display_order_changed = ipivot_consumer_display_order_changed;
iface->on_mandatory_prefs_changed = NULL;
}
static void
ipivot_consumer_items_changed( NAIPivotConsumer *instance, gpointer user_data )
{
static const gchar *thisfn = "nautilus_actions_ipivot_consumer_items_changed";
NautilusActions *self;
g_return_if_fail( NAUTILUS_IS_ACTIONS( instance ));
self = NAUTILUS_ACTIONS( instance );
if( !self->private->dispose_has_run ){
g_debug( "%s: instance=%p, user_data=%p", thisfn, ( void * ) instance, ( void * ) user_data );
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( self ));
}
}
static void
ipivot_consumer_create_root_menu_changed( NAIPivotConsumer *instance, gboolean enabled )
{
static const gchar *thisfn = "nautilus_actions_ipivot_consumer_create_root_menu_changed";
NautilusActions *self;
g_return_if_fail( NAUTILUS_IS_ACTIONS( instance ));
self = NAUTILUS_ACTIONS( instance );
if( !self->private->dispose_has_run ){
g_debug( "%s: instance=%p, enabled=%s", thisfn, ( void * ) instance, enabled ? "True":"False" );
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( self ));
}
}
static void
ipivot_consumer_display_about_changed( NAIPivotConsumer *instance, gboolean enabled )
{
static const gchar *thisfn = "nautilus_actions_ipivot_consumer_display_about_changed";
NautilusActions *self;
g_return_if_fail( NAUTILUS_IS_ACTIONS( instance ));
self = NAUTILUS_ACTIONS( instance );
if( !self->private->dispose_has_run ){
g_debug( "%s: instance=%p, enabled=%s", thisfn, ( void * ) instance, enabled ? "True":"False" );
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( self ));
}
}
static void
ipivot_consumer_display_order_changed( NAIPivotConsumer *instance, gint order_mode )
{
static const gchar *thisfn = "nautilus_actions_ipivot_consumer_display_order_changed";
NautilusActions *self;
g_return_if_fail( NAUTILUS_IS_ACTIONS( instance ));
self = NAUTILUS_ACTIONS( instance );
if( !self->private->dispose_has_run ){
g_debug( "%s: instance=%p, order_mode=%d", thisfn, ( void * ) instance, order_mode );
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( self ));
}
}
static void static void
menu_provider_iface_init( NautilusMenuProviderIface *iface ) menu_provider_iface_init( NautilusMenuProviderIface *iface )
{ {
...@@ -527,8 +465,6 @@ get_menus_items( NautilusActions *plugin, guint target, GList *selection ) ...@@ -527,8 +465,6 @@ get_menus_items( NautilusActions *plugin, guint target, GList *selection )
GList *menus_list; GList *menus_list;
NATokens *tokens; NATokens *tokens;
GList *pivot_tree, *copy_tree; GList *pivot_tree, *copy_tree;
gboolean root_menu;
gboolean add_about;
g_return_val_if_fail( NA_IS_PIVOT( plugin->private->pivot ), NULL ); g_return_val_if_fail( NA_IS_PIVOT( plugin->private->pivot ), NULL );
...@@ -543,13 +479,11 @@ get_menus_items( NautilusActions *plugin, guint target, GList *selection ) ...@@ -543,13 +479,11 @@ get_menus_items( NautilusActions *plugin, guint target, GList *selection )
if( target != ITEM_TARGET_TOOLBAR ){ if( target != ITEM_TARGET_TOOLBAR ){
root_menu = na_iprefs_read_bool( NA_IPREFS( plugin->private->pivot ), IPREFS_CREATE_ROOT_MENU, FALSE ); if( plugin->private->items_create_root_menu ){
if( root_menu ){
menus_list = create_root_menu( plugin, menus_list ); menus_list = create_root_menu( plugin, menus_list );
} }
add_about = na_iprefs_read_bool( NA_IPREFS( plugin->private->pivot ), IPREFS_ADD_ABOUT_ITEM, TRUE ); if( plugin->private->items_add_about_item ){
if( add_about ){
menus_list = add_about_item( plugin, menus_list ); menus_list = add_about_item( plugin, menus_list );
} }
} }
...@@ -1048,3 +982,50 @@ execute_about( NautilusMenuItem *item, NautilusActions *plugin ) ...@@ -1048,3 +982,50 @@ execute_about( NautilusMenuItem *item, NautilusActions *plugin )
na_iabout_display( NA_IABOUT( plugin )); na_iabout_display( NA_IABOUT( plugin ));
} }
/*
* this is a composite callback which is called when:
* - the content of an action or a menu is modified
* - the i/o providers read order is changed
* - the 'readable' status of a i/o provider is changed
* - the level-zero order is modified
*
* there is no relevant 'newvalue' here.
*
* if pivot is in automatic reload mode, then it already has reloaded
* the items tree in the new environment
*/
static void
on_items_list_changed( const gchar *key, gpointer newvalue, NautilusActions *plugin )
{
g_return_if_fail( NAUTILUS_IS_ACTIONS( plugin ));
if( !plugin->private->dispose_has_run ){
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( plugin ));
}
}
static void
on_items_add_about_item_changed( const gchar *key, gpointer newvalue, NautilusActions *plugin )
{
g_return_if_fail( NAUTILUS_IS_ACTIONS( plugin ));
if( !plugin->private->dispose_has_run ){
plugin->private->items_add_about_item = ( gboolean ) GPOINTER_TO_UINT( newvalue );
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( plugin ));
}
}
static void
on_items_create_root_menu_changed( const gchar *key, gpointer newvalue, NautilusActions *plugin )
{
g_return_if_fail( NAUTILUS_IS_ACTIONS( plugin ));
if( !plugin->private->dispose_has_run ){
plugin->private->items_create_root_menu = ( gboolean ) GPOINTER_TO_UINT( newvalue );
nautilus_menu_provider_emit_items_updated_signal( NAUTILUS_MENU_PROVIDER( plugin ));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment