[nautilus-actions] Optimize writability check



commit 9bea46878adee21e0aa53c8c14ef26ace66fd28f
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sat Jan 30 13:58:22 2010 +0100

    Optimize writability check

 TODO                                      |    6 ---
 nautilus-actions/runtime/na-io-provider.c |    1 +
 nautilus-actions/runtime/na-pivot.c       |   62 +++++++++++------------------
 3 files changed, 24 insertions(+), 45 deletions(-)
---
diff --git a/TODO b/TODO
index a9fe9f2..7945562 100644
--- a/TODO
+++ b/TODO
@@ -84,8 +84,6 @@
 
 - Nautilus bug: doesn't refresh toolbar when an item is updated
 
-- have a preference to record order of IO Providers
-
 - nact: new action assistant
 
 - desktop provider: fix default toolbar label
@@ -129,7 +127,3 @@
   the 'editable' cell property should be set only once, instead of at each redraw
   and more because we also compute this on selection change
   what we should do: compute once, and monitor to only change when needed
-
-- use nact_window_get_pivot
-
-- not all objects are disposed
diff --git a/nautilus-actions/runtime/na-io-provider.c b/nautilus-actions/runtime/na-io-provider.c
index 1ade804..a650588 100644
--- a/nautilus-actions/runtime/na-io-provider.c
+++ b/nautilus-actions/runtime/na-io-provider.c
@@ -1156,6 +1156,7 @@ na_io_provider_get_writable_provider( const NAPivot *pivot )
 
 		if( na_io_provider_is_willing_to_write( NA_IO_PROVIDER( ip->data )) &&
 			na_io_provider_is_able_to_write( NA_IO_PROVIDER( ip->data )) &&
+			na_io_provider_has_write_api( NA_IO_PROVIDER( ip->data )) &&
 			na_io_provider_is_user_writable( NA_IO_PROVIDER( ip->data ), pivot ) &&
 			!na_io_provider_is_locked_by_admin( NA_IO_PROVIDER( ip->data ), pivot ) &&
 			!na_pivot_is_configuration_locked_by_admin( pivot )){
diff --git a/nautilus-actions/runtime/na-pivot.c b/nautilus-actions/runtime/na-pivot.c
index cf27bd5..51263d4 100644
--- a/nautilus-actions/runtime/na-pivot.c
+++ b/nautilus-actions/runtime/na-pivot.c
@@ -685,7 +685,6 @@ na_pivot_is_item_writable( const NAPivot *pivot, const NAObjectItem *item, gint
 {
 	gboolean writable;
 	NAIOProvider *provider;
-	gboolean is_new;
 
 	g_return_val_if_fail( NA_IS_PIVOT( pivot ), FALSE );
 	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), FALSE );
@@ -714,15 +713,36 @@ na_pivot_is_item_writable( const NAPivot *pivot, const NAObjectItem *item, gint
 		if( writable ){
 			provider = na_object_get_provider( item );
 			if( provider ){
-				is_new = FALSE;
 				if( !na_io_provider_is_willing_to_write( provider )){
 					writable = FALSE;
 					if( reason ){
 						*reason = NA_IIO_PROVIDER_STATUS_PROVIDER_NOT_WILLING_TO;
 					}
+				} else if( na_io_provider_is_locked_by_admin( provider, pivot )){
+					writable = FALSE;
+					if( reason ){
+						*reason = NA_IIO_PROVIDER_STATUS_PROVIDER_LOCKED_BY_ADMIN;
+					}
+				} else if( !na_io_provider_is_user_writable( provider, pivot )){
+					writable = FALSE;
+					if( reason ){
+						*reason = NA_IIO_PROVIDER_STATUS_PROVIDER_LOCKED_BY_USER;
+					}
+				} else if( na_pivot_is_configuration_locked_by_admin( pivot )){
+					writable = FALSE;
+					if( reason ){
+						*reason = NA_IIO_PROVIDER_STATUS_CONFIGURATION_LOCKED_BY_ADMIN;
+					}
+				} else if( !na_io_provider_has_write_api( provider )){
+					writable = FALSE;
+					if( reason ){
+						*reason = NA_IIO_PROVIDER_STATUS_NO_API;
+					}
 				}
+
+			/* the get_writable_provider() api already takes above checks
+			 */
 			} else {
-				is_new = TRUE;
 				provider = na_io_provider_get_writable_provider( pivot );
 				if( !provider ){
 					writable = FALSE;
@@ -732,42 +752,6 @@ na_pivot_is_item_writable( const NAPivot *pivot, const NAObjectItem *item, gint
 				}
 			}
 		}
-
-		if( writable ){
-			if( na_io_provider_is_locked_by_admin( provider, pivot )){
-				writable = FALSE;
-				if( reason ){
-					*reason = NA_IIO_PROVIDER_STATUS_PROVIDER_LOCKED_BY_ADMIN;
-				}
-			}
-		}
-
-		if( writable ){
-			if( is_new && !na_io_provider_is_user_writable( provider, pivot )){
-				writable = FALSE;
-				if( reason ){
-					*reason = NA_IIO_PROVIDER_STATUS_PROVIDER_LOCKED_BY_USER;
-				}
-			}
-		}
-
-		if( writable ){
-			if( na_pivot_is_configuration_locked_by_admin( pivot )){
-				writable = FALSE;
-				if( reason ){
-					*reason = NA_IIO_PROVIDER_STATUS_CONFIGURATION_LOCKED_BY_ADMIN;
-				}
-			}
-		}
-
-		if( writable ){
-			if( !na_io_provider_has_write_api( provider )){
-				writable = FALSE;
-				if( reason ){
-					*reason = NA_IIO_PROVIDER_STATUS_NO_API;
-				}
-			}
-		}
 	}
 
 	return( writable );



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