[nautilus-actions] na_iprefs_is_level_zero_writable() is moved and renamed as na_updater_is_level_zero_writable()



commit c57dd89ba5faa0f8ca8825f68f174e1b085d4d56
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Feb 1 22:51:35 2011 +0100

    na_iprefs_is_level_zero_writable() is moved and renamed as na_updater_is_level_zero_writable()

 ChangeLog                      |   14 ++++++++++
 src/core/na-iprefs.c           |   56 ++++++---------------------------------
 src/core/na-iprefs.h           |    1 -
 src/core/na-updater.c          |   53 +++++++++++++++++++++++++++++++++++++-
 src/core/na-updater.h          |    4 +++
 src/nact/nact-menubar-priv.h   |    2 +-
 src/nact/nact-menubar.c        |    7 ++---
 src/nact/nact-sort-buttons.c   |    2 +-
 src/nact/nact-tree-model-dnd.c |    3 +-
 9 files changed, 85 insertions(+), 57 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8f2fbdc..25712a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2011-02-01 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-iprefs.c:
+	* src/core/na-iprefs.h (na_iprefs_is_level_zero_writable):
+	Moved to NAUpdater class.
+
+	* src/core/na-updater.c:
+	* src/core/na-updater.h (na_updater_is_level_zero_writable):
+	Moved from NAIPrefs.
+
+	* src/nact/nact-menubar-priv.h:
+	* src/nact/nact-menubar.c (on_base_initialize_window):
+	* src/nact/nact-sort-buttons.c (enable_buttons):
+	* src/nact/nact-tree-model-dnd.c (is_parent_accept_new_childs):
+	Updated accordingly.
+
 	Review I/O providers writability status management.
 
 	* src/api/na-iio-provider.h: Review writability reason.
diff --git a/src/core/na-iprefs.c b/src/core/na-iprefs.c
index d960d58..e2e9960 100644
--- a/src/core/na-iprefs.c
+++ b/src/core/na-iprefs.c
@@ -290,41 +290,6 @@ na_iprefs_get_io_providers( const NAPivot *pivot )
 }
 
 /*
- * na_iprefs_is_level_zero_writable:
- * @pivot: the #NAPivot application object.
- *
- * The level-zero order may not be writable if:
- * - all the configuration has been locked down by an admin
- * - the preferences has been locked down by an admin
- * - the level-zero order is a mandatory preference
- * - the user configuration file is not writable.
- *
- * All these conditions are subject to runtime modifications. The caller
- * should not keep the result, but rather re-call this function each time
- * it needs this status.
- *
- * Each condition is also subject to race conditions. So the returned
- * status may not be more valid when the caller tries to actually write
- * the level-zero preference.
- *
- * Returns: %TRUE if we are able to update the level-zero list of items,
- * %FALSE else.
- *
- * As of 3.1.0, level-zero order is written as a user preference.
- */
-gboolean
-na_iprefs_is_level_zero_writable( const NAPivot *pivot )
-{
-	g_return_val_if_fail( NA_IS_PIVOT( pivot ), FALSE );
-
-	if( na_pivot_is_configuration_locked_by_admin( pivot )){
-		return( FALSE );
-	}
-
-	return( TRUE );
-}
-
-/*
  * na_iprefs_write_level_zero:
  * @pivot: the #NAPivot application object.
  * @items: the #GList of items whose first level is to be written.
@@ -359,20 +324,17 @@ na_iprefs_write_level_zero( const NAPivot *pivot, const GList *items, GSList **m
 
 	g_debug( "%s: pivot=%p", thisfn, ( void * ) pivot);
 
-	if( na_iprefs_is_level_zero_writable( pivot )){
-
-		content = NULL;
-		for( it = items ; it ; it = it->next ){
-			id = na_object_get_id( it->data );
-			content = g_slist_prepend( content, id );
-		}
-		content = g_slist_reverse( content );
+	content = NULL;
+	for( it = items ; it ; it = it->next ){
+		id = na_object_get_id( it->data );
+		content = g_slist_prepend( content, id );
+	}
+	content = g_slist_reverse( content );
 
-		na_settings_set_string_list( na_pivot_get_settings( pivot ), NA_IPREFS_ITEMS_LEVEL_ZERO_ORDER, content );
-		written = TRUE;
+	written = na_settings_set_string_list(
+			na_pivot_get_settings( pivot ), NA_IPREFS_ITEMS_LEVEL_ZERO_ORDER, content );
 
-		na_core_utils_slist_free( content );
-	}
+	na_core_utils_slist_free( content );
 
 	return( written );
 }
diff --git a/src/core/na-iprefs.h b/src/core/na-iprefs.h
index f6495cf..0490e17 100644
--- a/src/core/na-iprefs.h
+++ b/src/core/na-iprefs.h
@@ -64,7 +64,6 @@ void     na_iprefs_set_export_format      ( const NAPivot *pivot, const gchar *p
 
 GSList  *na_iprefs_get_io_providers       ( const NAPivot * );
 
-gboolean na_iprefs_is_level_zero_writable ( const NAPivot *pivot );
 gboolean na_iprefs_write_level_zero       ( const NAPivot *pivot, const GList *items, GSList **messages );
 
 G_END_DECLS
diff --git a/src/core/na-updater.c b/src/core/na-updater.c
index 77216fa..5bd0d55 100644
--- a/src/core/na-updater.c
+++ b/src/core/na-updater.c
@@ -32,10 +32,12 @@
 #include <config.h>
 #endif
 
+#include <api/na-core-utils.h>
 #include <api/na-gconf-utils.h>
 #include <api/na-object-api.h>
 
 #include "na-io-provider.h"
+#include "na-settings.h"
 #include "na-updater.h"
 
 /* private class data
@@ -47,7 +49,8 @@ struct _NAUpdaterClassPrivate {
 /* private instance data
  */
 struct _NAUpdaterPrivate {
-	gboolean           dispose_has_run;
+	gboolean dispose_has_run;
+	gboolean is_level_zero_writable;
 };
 
 static NAPivotClass *st_parent_class = NULL;
@@ -58,6 +61,8 @@ static void     instance_init( GTypeInstance *instance, gpointer klass );
 static void     instance_dispose( GObject *object );
 static void     instance_finalize( GObject *object );
 
+static gboolean is_level_zero_writable( const NAUpdater *updater );
+
 GType
 na_updater_get_type( void )
 {
@@ -188,10 +193,56 @@ na_updater_new( void )
 
 	updater = g_object_new( NA_UPDATER_TYPE, NULL );
 
+	updater->private->is_level_zero_writable = is_level_zero_writable( updater );
+
 	return( updater );
 }
 
 /*
+ * na_updater_is_level_zero_writable:
+ * @updater: the #NAUpdater application object.
+ *
+ * As of 3.1.0, level-zero order is written as a user preference.
+ *
+ * This function only considers the case of the level zero itself.
+ * It does not take into account whether the i/o provider (if any)
+ * is writable, or if the item iself is not read only.
+ *
+ * Returns: %TRUE if we are able to update the level-zero list of items,
+ * %FALSE else.
+ */
+gboolean
+na_updater_is_level_zero_writable( const NAUpdater *updater )
+{
+	gboolean is_writable;
+
+	g_return_val_if_fail( NA_IS_UPDATER( updater ), FALSE );
+
+	is_writable = FALSE;
+
+	if( !updater->private->dispose_has_run ){
+
+		is_writable = updater->private->is_level_zero_writable;
+	}
+
+	return( is_writable );
+}
+
+static gboolean
+is_level_zero_writable( const NAUpdater *updater )
+{
+	GSList *level_zero;
+	gboolean mandatory;
+
+	level_zero = na_settings_get_string_list(
+			na_pivot_get_settings( NA_PIVOT( updater )), NA_IPREFS_ITEMS_LEVEL_ZERO_ORDER, NULL, &mandatory );
+
+	na_core_utils_slist_free( level_zero );
+
+	return( !mandatory );
+}
+
+/*
  * na_updater_append_item:
  * @updater: this #NAUpdater object.
  * @item: a #NAObjectItem-derived object to be appended to the tree.
diff --git a/src/core/na-updater.h b/src/core/na-updater.h
index cd0e662..534a7c1 100644
--- a/src/core/na-updater.h
+++ b/src/core/na-updater.h
@@ -72,6 +72,10 @@ GType      na_updater_get_type( void );
 
 NAUpdater *na_updater_new( void );
 
+/* writability status
+ */
+gboolean   na_updater_is_level_zero_writable( const NAUpdater *updater );
+
 /* update the tree in memory
  */
 void       na_updater_append_item( NAUpdater *updater, NAObjectItem *item );
diff --git a/src/nact/nact-menubar-priv.h b/src/nact/nact-menubar-priv.h
index a527a79..54cf096 100644
--- a/src/nact/nact-menubar-priv.h
+++ b/src/nact/nact-menubar-priv.h
@@ -55,6 +55,7 @@ struct _NactMenubarPrivate {
 	NAUpdater      *updater;
 
 	gboolean        is_parent_writable;
+	gboolean        is_level_zero_writable;
 
 	/* *** */
 	gint            selected_menus;
@@ -72,7 +73,6 @@ struct _NactMenubarPrivate {
 	gboolean        level_zero_order_changed;
 	gulong          popup_handler;
 
-	gboolean        is_level_zero_writable;
 	gboolean        has_writable_providers;
 	guint           count_selected;
 	GList          *selected_items;
diff --git a/src/nact/nact-menubar.c b/src/nact/nact-menubar.c
index 706083b..db8fbee 100644
--- a/src/nact/nact-menubar.c
+++ b/src/nact/nact-menubar.c
@@ -502,6 +502,7 @@ on_base_initialize_window( BaseWindow *window, gpointer user_data )
 		 */
 		application = NACT_APPLICATION( base_window_get_application( bar->private->window ));
 		bar->private->updater = nact_application_get_updater( application );
+		bar->private->is_level_zero_writable = na_updater_is_level_zero_writable( bar->private->updater );
 
 		/* connect to all signal which may have an influence on the menu
 		 * items sensitivity
@@ -703,9 +704,9 @@ on_iactions_list_selection_changed( NactMainWindow *window, GList *selected )
 		first = ( NAObject *) selected->data;
 		if( first ){
 			if( NA_IS_OBJECT_PROFILE( first )){
-				first = na_object_get_parent( first );
+				first = NA_OBJECT( na_object_get_parent( first ));
 			}
-			first = na_object_get_parent( first );
+			first = NA_OBJECT( na_object_get_parent( first ));
 #if 0
 			bar->private->is_parent_writable = first ? na_object_is_writable( first ) : is_level_zero_writable();
 #endif
@@ -774,8 +775,6 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 
 	g_debug( "%s: window=%p, user_data=%p", thisfn, ( void * ) window, ( void * ) user_data );
 
-	bar->private->is_level_zero_writable = na_iprefs_is_level_zero_writable( NA_PIVOT( bar->private->updater ));
-
 	bar->private->has_writable_providers = nact_window_has_writable_providers( NACT_WINDOW( window ));
 	g_debug( "%s: has_writable_providers=%s", thisfn, bar->private->has_writable_providers ? "True":"False" );
 
diff --git a/src/nact/nact-sort-buttons.c b/src/nact/nact-sort-buttons.c
index 9c3e61c..730a7f7 100644
--- a/src/nact/nact-sort-buttons.c
+++ b/src/nact/nact-sort-buttons.c
@@ -199,7 +199,7 @@ enable_buttons( NactMainWindow *window )
 
 	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
 	updater = nact_application_get_updater( application );
-	writable = na_iprefs_is_level_zero_writable( NA_PIVOT( updater ));
+	writable = na_updater_is_level_zero_writable( updater );
 
 	i = 0;
 	while( st_toggle_group[i].btn_name ){
diff --git a/src/nact/nact-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c
index aa6524b..d202a36 100644
--- a/src/nact/nact-tree-model-dnd.c
+++ b/src/nact/nact-tree-model-dnd.c
@@ -1141,8 +1141,7 @@ is_parent_accept_new_childs( NactApplication *application, NactMainWindow *windo
 	 * ensure that level zero is writable
 	 */
 	if( parent == NULL ){
-
-		if( na_iprefs_is_level_zero_writable( NA_PIVOT( updater ))){
+		if( na_updater_is_level_zero_writable( updater )){
 			accept_ok = TRUE;
 
 		} else {



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