[nautilus-actions] plugin-menu: replace NAIPivotConsumer interface with na_settings() accessors



commit 7ac570cea1db75410f9586c018931e777fd71808
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jan 7 19:20:33 2011 +0100

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

 ChangeLog                          |    5 +
 src/core/na-pivot.c                |   41 ++++++--
 src/core/na-pivot.h                |    8 ++-
 src/plugin-menu/nautilus-actions.c |  199 ++++++++++++++++--------------------
 4 files changed, 134 insertions(+), 119 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6ecd685..e6f2b86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -94,6 +94,11 @@
 
 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.h: New files.
 
diff --git a/src/core/na-pivot.c b/src/core/na-pivot.c
index 5d193d8..9b1851f 100644
--- a/src/core/na-pivot.c
+++ b/src/core/na-pivot.c
@@ -52,35 +52,39 @@ struct _NAPivotClassPrivate {
 /* private instance data
  */
 struct _NAPivotPrivate {
-	gboolean  dispose_has_run;
+	gboolean    dispose_has_run;
 
-	guint     loadable_set;
+	guint       loadable_set;
 
 	/* dynamically loaded modules (extension plugins)
 	 */
-	GList    *modules;
+	GList      *modules;
+
+	/* The NASettings object
+	 */
+	NASettings *settings;
 
 	/* list of instances to be notified of configuration updates
 	 * these are called 'consumers' of NAPivot
 	 */
-	GList    *consumers;
+	GList      *consumers;
 
 	/* configuration tree of actions and menus
 	 */
-	GList    *tree;
+	GList      *tree;
 
 	/* whether to automatically reload the whole configuration tree
 	 * when a modification is detected in one of the underlying I/O
 	 * storage subsystems
 	 * defaults to FALSE
 	 */
-	gboolean  automatic_reload;
-	GTimeVal  last_event;
-	guint     event_source_id;
+	gboolean    automatic_reload;
+	GTimeVal    last_event;
+	guint       event_source_id;
 
 	/* list of monitoring objects on runtime preferences
 	 */
-	GList    *monitors;
+	GList      *monitors;
 };
 
 /* NAPivot properties
@@ -376,6 +380,8 @@ na_pivot_new( void )
 
 	pivot = g_object_new( NA_PIVOT_TYPE, NULL );
 
+	pivot->private->settings = na_settings_new();
+
 	return( pivot );
 }
 
@@ -768,6 +774,23 @@ free_consumers( GList *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:
  * @pivot: this #NAPivot instance.
  * @reload: whether this #NAPivot instance should automatically reload
diff --git a/src/core/na-pivot.h b/src/core/na-pivot.h
index e82abd6..8b50d54 100644
--- a/src/core/na-pivot.h
+++ b/src/core/na-pivot.h
@@ -79,6 +79,7 @@
 #include <api/na-object-api.h>
 
 #include "na-ipivot-consumer.h"
+#include "na-settings.h"
 
 G_BEGIN_DECLS
 
@@ -111,7 +112,7 @@ GType    na_pivot_get_type( void );
 
 /* properties
  */
-#define NAPIVOT_PROP_TREE				"na-pivot-prop-tree"
+#define NAPIVOT_PROP_TREE						"na-pivot-prop-tree"
 
 /* Loadable population
  * NACT management user interface defaults to PIVOT_LOAD_ALL
@@ -124,6 +125,8 @@ enum {
 	PIVOT_LOAD_ALL      = 0xff
 };
 
+#define NA_PIVOT_RUNTIME_ITEMS_LIST_CHANGED		"na-pivot-runtime-items-list-changed"
+
 NAPivot      *na_pivot_new( void );
 void          na_pivot_dump( const NAPivot *pivot );
 
@@ -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 );
 
 /* NAIPivotConsumer interface management
+ * Monitoring and preferences management
  */
 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
  */
diff --git a/src/plugin-menu/nautilus-actions.c b/src/plugin-menu/nautilus-actions.c
index 36abe48..172b1c2 100644
--- a/src/plugin-menu/nautilus-actions.c
+++ b/src/plugin-menu/nautilus-actions.c
@@ -45,8 +45,6 @@
 
 #include <core/na-pivot.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-tokens.h>
 
@@ -59,10 +57,22 @@ struct NautilusActionsClassPrivate {
 };
 
 /* 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 {
 	gboolean dispose_has_run;
 	NAPivot *pivot;
+	gboolean items_add_about_item;
+	gboolean items_create_root_menu;
 };
 
 static GObjectClass *st_parent_class = NULL;
@@ -77,12 +87,6 @@ static void              instance_finalize( GObject *object );
 static void              iabout_iface_init( NAIAboutInterface *iface );
 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 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 );
@@ -106,6 +110,10 @@ static GList            *create_root_menu( NautilusActions *plugin, GList *nauti
 static GList            *add_about_item( NautilusActions *plugin, GList *nautilus_menu );
 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
 nautilus_actions_get_type( void )
 {
@@ -142,12 +150,6 @@ nautilus_actions_register_type( GTypeModule *module )
 		NULL
 	};
 
-	static const GInterfaceInfo ipivot_consumer_iface_info = {
-		( GInterfaceInitFunc ) ipivot_consumer_iface_init,
-		NULL,
-		NULL
-	};
-
 	g_debug( "%s: module=%p", thisfn, ( void * ) module );
 	g_assert( st_actions_type == 0 );
 
@@ -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, 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
@@ -202,6 +202,7 @@ instance_constructed( GObject *object )
 {
 	static const gchar *thisfn = "nautilus_actions_instance_constructed";
 	NautilusActions *self;
+	NASettings *settings;
 
 	g_debug( "%s: object=%p", thisfn, ( void * ) object );
 
@@ -213,11 +214,34 @@ instance_constructed( GObject *object )
 	if( !self->private->dispose_has_run ){
 
 		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_loadable( self->private->pivot, !PIVOT_LOAD_DISABLED & !PIVOT_LOAD_INVALID );
 		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 */
 		if( G_OBJECT_CLASS( st_parent_class )->constructed ){
 			G_OBJECT_CLASS( st_parent_class )->constructed( object );
@@ -301,92 +325,6 @@ iabout_get_application_name( NAIAbout *instance )
 }
 
 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
 menu_provider_iface_init( NautilusMenuProviderIface *iface )
 {
 	static const gchar *thisfn = "nautilus_actions_menu_provider_iface_init";
@@ -527,8 +465,6 @@ get_menus_items( NautilusActions *plugin, guint target, GList *selection )
 	GList *menus_list;
 	NATokens *tokens;
 	GList *pivot_tree, *copy_tree;
-	gboolean root_menu;
-	gboolean add_about;
 
 	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 )
 
 	if( target != ITEM_TARGET_TOOLBAR ){
 
-		root_menu = na_iprefs_read_bool( NA_IPREFS( plugin->private->pivot ), IPREFS_CREATE_ROOT_MENU, FALSE );
-		if( root_menu ){
+		if( plugin->private->items_create_root_menu ){
 			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( add_about ){
+		if( plugin->private->items_add_about_item ){
 			menus_list = add_about_item( plugin, menus_list );
 		}
 	}
@@ -1048,3 +982,50 @@ execute_about( NautilusMenuItem *item, NautilusActions *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 ));
+	}
+}



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