From ffd524016b0b34b3cf494640ad3ec1ae3c411ca6 Mon Sep 17 00:00:00 2001 From: Pierre Wieser Date: Sat, 19 Feb 2011 15:56:39 +0100 Subject: [PATCH] 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. --- ChangeLog | 12 ++++ src/api/na-iio-provider.h | 2 + src/core/na-updater.c | 151 ++++++++++++++++++++++------------------- src/core/na-updater.h | 6 +- src/nact/nact-main-window.c | 2 +- src/nact/nact-menubar-edit.c | 4 +- src/nact/nact-tree-model-dnd.c | 2 +- 7 files changed, 103 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8da5016e..3ea72d2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2011-02-19 Pierre Wieser + * src/api/na-iio-provider.h: + Define new reason when the level zero is not writable. + + * src/core/na-updater.c: + * src/core/na-updater.h (na_updater_is_item_writable): + Renamed as na_updater_check_item_writability_status. + + * src/nact/nact-main-window.c (setup_writability_status): + * src/nact/nact-menubar-edit.c (get_deletables): + * src/nact/nact-tree-model-dnd.c (is_parent_accept_new_children): + Updated accordingly. + * src/nact/base-assistant.c (class_init): Apply patch provided by Christian Kirback. Fix #640920. diff --git a/src/api/na-iio-provider.h b/src/api/na-iio-provider.h index 7fb7d42a..3ccc81ed 100644 --- a/src/api/na-iio-provider.h +++ b/src/api/na-iio-provider.h @@ -343,6 +343,7 @@ void na_iio_provider_item_changed ( const NAIIOProvider *instance ); * @NA_IIO_PROVIDER_STATUS_LOCKED_BY_USER: i/o provider has been locked by the user. * @NA_IIO_PROVIDER_STATUS_ITEM_READONLY: item is read-only. * @NA_IIO_PROVIDER_STATUS_NO_PROVIDER_FOUND: no writable i/o provider found. + * @NA_IIO_PROVIDER_STATUS_LEVEL_ZERO: level zero is not writable. * @NA_IIO_PROVIDER_STATUS_UNDETERMINED: unknwon reason (and probably a bug). * * The reasons for which an item may not be writable. @@ -357,6 +358,7 @@ typedef enum { NA_IIO_PROVIDER_STATUS_LOCKED_BY_USER, NA_IIO_PROVIDER_STATUS_ITEM_READONLY, NA_IIO_PROVIDER_STATUS_NO_PROVIDER_FOUND, + NA_IIO_PROVIDER_STATUS_LEVEL_ZERO, NA_IIO_PROVIDER_STATUS_UNDETERMINED, /*< private >*/ NA_IIO_PROVIDER_STATUS_LAST, diff --git a/src/core/na-updater.c b/src/core/na-updater.c index b32ad562..f5d7f2bd 100644 --- a/src/core/na-updater.c +++ b/src/core/na-updater.c @@ -202,6 +202,33 @@ na_updater_new( void ) return( updater ); } +static gboolean +are_preferences_locked( const NAUpdater *updater ) +{ + gboolean are_locked; + gboolean mandatory; + NASettings *settings; + + settings = na_pivot_get_settings( NA_PIVOT( updater )); + are_locked = na_settings_get_boolean( settings, NA_IPREFS_ADMIN_PREFERENCES_LOCKED, NULL, &mandatory ); + + return( are_locked && mandatory ); +} + +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_are_preferences_locked: * @updater: the #NAUpdater application object. @@ -227,7 +254,43 @@ na_updater_are_preferences_locked( const NAUpdater *updater ) } /* - * na_updater_is_item_writable: + * 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. @@ -241,15 +304,14 @@ na_updater_are_preferences_locked( 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 * - * Note that this function does not consider if the item is to be written - * at the level zero of the tree, which may be a mandatory preference - * (i.e. locked by an admin), and so make this item unwritable. + * If the item does not have a parent, the the level zero must be writable. */ gboolean -na_updater_is_item_writable( const NAUpdater *updater, const NAObjectItem *item, guint *reason ) +na_updater_check_item_writability_status( const NAUpdater *updater, const NAObjectItem *item, guint *reason ) { gboolean writable; NAIOProvider *provider; + NAObjectItem *parent; g_return_val_if_fail( NA_IS_UPDATER( updater ), FALSE ); g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), FALSE ); @@ -299,72 +361,23 @@ na_updater_is_item_writable( const NAUpdater *updater, const NAObjectItem *item, } } } - } - - return( writable ); -} -/* - * 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; + /* if needed, the level zero must be writable + */ + if( writable ){ + 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; + } + } + } + } } - return( is_writable ); -} - -static gboolean -are_preferences_locked( const NAUpdater *updater ) -{ - gboolean are_locked; - gboolean mandatory; - NASettings *settings; - - settings = na_pivot_get_settings( NA_PIVOT( updater )); - are_locked = na_settings_get_boolean( settings, NA_IPREFS_ADMIN_PREFERENCES_LOCKED, NULL, &mandatory ); - - return( are_locked && mandatory ); -} - -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 ); + return( writable ); } /* @@ -535,7 +548,7 @@ set_writability_status( NAObjectItem *item, const NAUpdater *updater ) guint reason; GList *children; - writable = na_updater_is_item_writable( updater, item, &reason ); + writable = na_updater_check_item_writability_status( updater, item, &reason ); na_object_set_writability_status( item, writable, reason ); if( NA_IS_OBJECT_MENU( item )){ diff --git a/src/core/na-updater.h b/src/core/na-updater.h index afadf56b..9ec6adae 100644 --- a/src/core/na-updater.h +++ b/src/core/na-updater.h @@ -74,9 +74,9 @@ NAUpdater *na_updater_new( void ); /* writability status */ -gboolean na_updater_are_preferences_locked( const NAUpdater *updater ); -gboolean na_updater_is_item_writable ( const NAUpdater *updater, const NAObjectItem *item, guint *reason ); -gboolean na_updater_is_level_zero_writable( const NAUpdater *updater ); +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 47e22e3c..22dd4b34 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_is_item_writable( window->private->updater, window->private->current_item, &window->private->reason ); + window->private->editable = na_updater_check_item_writability_status( window->private->updater, 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 173d6369..3bd2e626 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_is_item_writable( updater, NA_OBJECT_ITEM( it->data ), &reason )){ + if( !na_updater_check_item_writability_status( updater, NA_OBJECT_ITEM( 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_is_item_writable( updater, NA_OBJECT_ITEM( it->data ), &reason )){ + if( !na_updater_check_item_writability_status( updater, NA_OBJECT_ITEM( 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-tree-model-dnd.c b/src/nact/nact-tree-model-dnd.c index 065400e5..0943e360 100644 --- a/src/nact/nact-tree-model-dnd.c +++ b/src/nact/nact-tree-model-dnd.c @@ -1138,7 +1138,7 @@ is_parent_accept_new_children( NactApplication *application, NactMainWindow *win /* see if the parent is writable */ - } else if( na_updater_is_item_writable( updater, parent, NULL )){ + } else if( na_updater_check_item_writability_status( updater, parent, NULL )){ accept_ok = TRUE; } else { -- 2.11.4.GIT