[nautilus-actions] na_updater_is_item_writable is renamed as na_updater_check_item_writability_status



commit 63cbe95090c39651dd9bcccccafc669df677782e
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sat Feb 19 16:58:57 2011 +0100

    na_updater_is_item_writable is renamed as na_updater_check_item_writability_status
    
    na_updater_check_item_writability_status new takes into account all cases, including when
    the level zero may not be writable.

 src/core/na-updater.c          |  165 ++++++++++++++++++----------------------
 src/core/na-updater.h          |    3 +-
 src/nact/nact-main-window.c    |    2 +-
 src/nact/nact-menubar-edit.c   |    4 +-
 src/nact/nact-menubar-file.c   |   10 +++
 src/nact/nact-tree-model-dnd.c |    3 +-
 6 files changed, 92 insertions(+), 95 deletions(-)
---
diff --git a/src/core/na-updater.c b/src/core/na-updater.c
index f5d7f2b..d3b193d 100644
--- a/src/core/na-updater.c
+++ b/src/core/na-updater.c
@@ -230,73 +230,11 @@ is_level_zero_writable( const NAUpdater *updater )
 }
 
 /*
- * na_updater_are_preferences_locked:
- * @updater: the #NAUpdater application object.
- *
- * Returns: %TRUE if preferences have been globally locked down by an
- * admin, %FALSE else.
- */
-gboolean
-na_updater_are_preferences_locked( const NAUpdater *updater )
-{
-	gboolean are_locked;
-
-	g_return_val_if_fail( NA_IS_UPDATER( updater ), TRUE );
-
-	are_locked = TRUE;
-
-	if( !updater->private->dispose_has_run ){
-
-		are_locked = updater->private->are_preferences_locked;
-	}
-
-	return( are_locked );
-}
-
-/*
- * na_updater_is_level_zero_writable:
- * @updater: the #NAUpdater application object.
- *
- * As of 3.1.0, level-zero is written as a user preference.
- *
- * This function considers that the level_zero is writable if it is not
- * a mandatory preference.
- * Whether preferences themselves are or not globally locked is not
- * considered here (as imho, level zero is not really and semantically
- * part of user preferences).
- *
- * 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 );
-}
-
-/*
  * na_updater_check_item_writability_status:
  * @updater: this #NAUpdater object.
  * @item: the #NAObjectItem to be written.
- * @reason: the reason for why @item may not be writable.
  *
- * Returns: %TRUE: if @item is actually writable, given the current
- * status of its provider, %FALSE else.
+ * Compute and set the writability status of the @item.
  *
  * For an item be actually writable:
  * - the item must not be itself in a read-only store, which has been
@@ -304,29 +242,26 @@ na_updater_is_level_zero_writable( const NAUpdater *updater )
  * - the provider must be willing (resp. able) to write
  * - the provider must not has been locked by the admin, nor by the user
  *
- * If the item does not have a parent, the the level zero must be writable.
+ * If the item does not have a parent, then the level zero must be writable.
  */
-gboolean
-na_updater_check_item_writability_status( const NAUpdater *updater, const NAObjectItem *item, guint *reason )
+void
+na_updater_check_item_writability_status( const NAUpdater *updater, const NAObjectItem *item )
 {
 	gboolean writable;
 	NAIOProvider *provider;
 	NAObjectItem *parent;
+	guint reason;
 
-	g_return_val_if_fail( NA_IS_UPDATER( updater ), FALSE );
-	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), FALSE );
+	g_return_if_fail( NA_IS_UPDATER( updater ));
+	g_return_if_fail( NA_IS_OBJECT_ITEM( item ));
 
 	writable = FALSE;
-	if( reason ){
-		*reason = NA_IIO_PROVIDER_STATUS_UNDETERMINED;
-	}
+	reason = NA_IIO_PROVIDER_STATUS_UNDETERMINED;
 
 	if( !updater->private->dispose_has_run ){
 
 		writable = TRUE;
-		if( reason ){
-			*reason = NA_IIO_PROVIDER_STATUS_WRITABLE;
-		}
+		reason = NA_IIO_PROVIDER_STATUS_WRITABLE;
 
 		/* Writability status of the item has been determined at load time
 		 * (cf. e.g. io-desktop/nadp-reader.c:read_done_item_is_writable()).
@@ -338,16 +273,14 @@ na_updater_check_item_writability_status( const NAUpdater *updater, const NAObje
 		if( writable ){
 			if( na_object_is_readonly( item )){
 				writable = FALSE;
-				if( reason ){
-					*reason = NA_IIO_PROVIDER_STATUS_ITEM_READONLY;
-				}
+				reason = NA_IIO_PROVIDER_STATUS_ITEM_READONLY;
 			}
 		}
 
 		if( writable ){
 			provider = na_object_get_provider( item );
 			if( provider ){
-				writable = na_io_provider_is_finally_writable( provider, reason );
+				writable = na_io_provider_is_finally_writable( provider, &reason );
 
 			/* the get_writable_provider() api already takes care of above checks
 			 */
@@ -355,9 +288,7 @@ na_updater_check_item_writability_status( const NAUpdater *updater, const NAObje
 				provider = na_io_provider_find_writable_io_provider( NA_PIVOT( updater ));
 				if( !provider ){
 					writable = FALSE;
-					if( reason ){
-						*reason = NA_IIO_PROVIDER_STATUS_NO_PROVIDER_FOUND;
-					}
+					reason = NA_IIO_PROVIDER_STATUS_NO_PROVIDER_FOUND;
 				}
 			}
 		}
@@ -368,16 +299,73 @@ na_updater_check_item_writability_status( const NAUpdater *updater, const NAObje
 			parent = ( NAObjectItem * ) na_object_get_parent( item );
 			if( !parent ){
 				if( updater->private->is_level_zero_writable ){
-					writable = FALSE;
-					if( reason ){
-						*reason = NA_IIO_PROVIDER_STATUS_LEVEL_ZERO;
-					}
+					reason = NA_IIO_PROVIDER_STATUS_LEVEL_ZERO;
 				}
 			}
 		}
 	}
 
-	return( writable );
+	na_object_set_writability_status( item, writable, reason );
+}
+
+/*
+ * na_updater_are_preferences_locked:
+ * @updater: the #NAUpdater application object.
+ *
+ * Returns: %TRUE if preferences have been globally locked down by an
+ * admin, %FALSE else.
+ */
+gboolean
+na_updater_are_preferences_locked( const NAUpdater *updater )
+{
+	gboolean are_locked;
+
+	g_return_val_if_fail( NA_IS_UPDATER( updater ), TRUE );
+
+	are_locked = TRUE;
+
+	if( !updater->private->dispose_has_run ){
+
+		are_locked = updater->private->are_preferences_locked;
+	}
+
+	return( are_locked );
+}
+
+/*
+ * na_updater_is_level_zero_writable:
+ * @updater: the #NAUpdater application object.
+ *
+ * As of 3.1.0, level-zero is written as a user preference.
+ *
+ * This function considers that the level_zero is writable if it is not
+ * a mandatory preference.
+ * Whether preferences themselves are or not globally locked is not
+ * considered here (as imho, level zero is not really and semantically
+ * part of user preferences).
+ *
+ * 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 );
 }
 
 /*
@@ -544,12 +532,9 @@ na_updater_load_items( NAUpdater *updater )
 static void
 set_writability_status( NAObjectItem *item, const NAUpdater *updater )
 {
-	gboolean writable;
-	guint reason;
 	GList *children;
 
-	writable = na_updater_check_item_writability_status( updater, item, &reason );
-	na_object_set_writability_status( item, writable, reason );
+	na_updater_check_item_writability_status( updater, item );
 
 	if( NA_IS_OBJECT_MENU( item )){
 		children = na_object_get_items( item );
diff --git a/src/core/na-updater.h b/src/core/na-updater.h
index 9ec6ada..bb923ce 100644
--- a/src/core/na-updater.h
+++ b/src/core/na-updater.h
@@ -74,9 +74,10 @@ NAUpdater *na_updater_new( void );
 
 /* writability status
  */
+void       na_updater_check_item_writability_status( const NAUpdater *updater, const NAObjectItem *item );
+
 gboolean   na_updater_are_preferences_locked       ( const NAUpdater *updater );
 gboolean   na_updater_is_level_zero_writable       ( const NAUpdater *updater );
-gboolean   na_updater_check_item_writability_status( const NAUpdater *updater, const NAObjectItem *item, guint *reason );
 
 /* update the tree in memory
  */
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 22dd4b3..ddd8491 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -1188,7 +1188,7 @@ setup_writability_status( NactMainWindow *window )
 {
 	g_return_if_fail( NA_IS_OBJECT_ITEM( window->private->current_item ));
 
-	window->private->editable = na_updater_check_item_writability_status( window->private->updater, window->private->current_item, &window->private->reason );
+	window->private->editable = na_object_is_finally_writable( window->private->current_item, &window->private->reason );
 	nact_main_statusbar_set_locked( window, !window->private->editable, window->private->reason );
 }
 
diff --git a/src/nact/nact-menubar-edit.c b/src/nact/nact-menubar-edit.c
index 3bd2e62..d2db1aa 100644
--- a/src/nact/nact-menubar-edit.c
+++ b/src/nact/nact-menubar-edit.c
@@ -496,7 +496,7 @@ get_deletables( NAUpdater *updater, GList *selected, GSList **non_deletables )
 	to_delete = NULL;
 	for( it = selected ; it ; it = it->next ){
 
-		if( !na_updater_check_item_writability_status( updater, NA_OBJECT_ITEM( it->data ), &reason )){
+		if( !na_object_is_finally_writable( it->data, &reason )){
 			*non_deletables = g_slist_prepend(
 					*non_deletables, add_non_deletable_msg( NA_OBJECT_ITEM( it->data ), reason ));
 			continue;
@@ -529,7 +529,7 @@ get_deletables_rec( NAUpdater *updater, GList *tree )
 	msgs = NULL;
 	for( it = tree ; it ; it = it->next ){
 
-		if( !na_updater_check_item_writability_status( updater, NA_OBJECT_ITEM( it->data ), &reason )){
+		if( !na_object_is_finally_writable( it->data, &reason )){
 			msgs = g_slist_prepend(
 					msgs, add_non_deletable_msg( NA_OBJECT_ITEM( it->data ), reason ));
 			continue;
diff --git a/src/nact/nact-menubar-file.c b/src/nact/nact-menubar-file.c
index 7ae56a6..0c8343f 100644
--- a/src/nact/nact-menubar-file.c
+++ b/src/nact/nact-menubar-file.c
@@ -118,6 +118,8 @@ void
 nact_menubar_file_on_new_menu( GtkAction *gtk_action, BaseWindow *window )
 {
 	NAObjectMenu *menu;
+	NactApplication *application;
+	NAUpdater *updater;
 	NactTreeView *items_view;
 	GList *items;
 
@@ -126,6 +128,9 @@ nact_menubar_file_on_new_menu( GtkAction *gtk_action, BaseWindow *window )
 
 	menu = na_object_menu_new_with_defaults();
 	na_object_check_status( menu );
+	application = NACT_APPLICATION( base_window_get_application( window ));
+	updater = nact_application_get_updater( application );
+	na_updater_check_item_writability_status( updater, NA_OBJECT_ITEM( menu ));
 	items = g_list_prepend( NULL, menu );
 	items_view = nact_main_window_get_items_view( NACT_MAIN_WINDOW( window ));
 	nact_tree_ieditable_insert_items( NACT_TREE_IEDITABLE( items_view ), items, NULL );
@@ -143,6 +148,8 @@ void
 nact_menubar_file_on_new_action( GtkAction *gtk_action, BaseWindow *window )
 {
 	NAObjectAction *action;
+	NactApplication *application;
+	NAUpdater *updater;
 	NactTreeView *items_view;
 	GList *items;
 
@@ -151,6 +158,9 @@ nact_menubar_file_on_new_action( GtkAction *gtk_action, BaseWindow *window )
 
 	action = na_object_action_new_with_defaults();
 	na_object_check_status( action );
+	application = NACT_APPLICATION( base_window_get_application( window ));
+	updater = nact_application_get_updater( application );
+	na_updater_check_item_writability_status( updater, NA_OBJECT_ITEM( action ));
 	items = g_list_prepend( NULL, action );
 	items_view = nact_main_window_get_items_view( NACT_MAIN_WINDOW( window ));
 	nact_tree_ieditable_insert_items( NACT_TREE_IEDITABLE( items_view ), items, NULL );
diff --git a/src/nact/nact-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c
index 0943e36..eeaf35b 100644
--- a/src/nact/nact-tree-model-dnd.c
+++ b/src/nact/nact-tree-model-dnd.c
@@ -921,6 +921,7 @@ drop_uri_list( NactTreeModel *model, GtkTreePath *dest, GtkSelectionData  *selec
 
 		if( result->imported ){
 			imported = g_list_prepend( imported, result->imported );
+			na_updater_check_item_writability_status( updater, result->imported );
 		}
 	}
 
@@ -1138,7 +1139,7 @@ is_parent_accept_new_children( NactApplication *application, NactMainWindow *win
 
 	/* see if the parent is writable
 	 */
-	} else if( na_updater_check_item_writability_status( updater, parent, NULL )){
+	} else if( na_object_is_finally_writable( parent, NULL )){
 		accept_ok = TRUE;
 
 	} else {



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