[nautilus-actions] A try to implement a lockdown key as a mandatory setting



commit 12697cf662af26fdadeed0ced55d88b6205f0d8c
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Dec 9 00:26:10 2009 +0100

    A try to implement a lockdown key as a mandatory setting
    
    It happends that this key is not readable by the user, so rather useless here.

 ChangeLog                                 |   11 +++++++++++
 nautilus-actions/nact/nact-main-menubar.c |   16 +++++++++-------
 nautilus-actions/nact/nact-window.c       |   29 ++++++++++++++++++++++++++++-
 nautilus-actions/nact/nact-window.h       |    2 ++
 4 files changed, 50 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ac7a6dc..c5cef4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-12-08 Pierre Wieser <pwieser trychlos org>
+
+	A try to implement a lockdown key in GConf mandatory settings.
+
+	* nautilus-actions/nact/nact-main-menubar.c (on_update_sensitivities):
+	Disable most of File and Edit menu items if lockdown key is set.
+
+	* nautilus-actions/nact/nact-window.c:
+	* nautilus-actions/nact/nact-window.h (nact_window_is_lockdown):
+	New function.
+
 2009-12-07 Pierre Wieser <pwieser trychlos org>
 
 	* configure.ac: Bump version number.
diff --git a/nautilus-actions/nact/nact-main-menubar.c b/nautilus-actions/nact/nact-main-menubar.c
index a7344f1..05531d5 100644
--- a/nautilus-actions/nact/nact-main-menubar.c
+++ b/nautilus-actions/nact/nact-main-menubar.c
@@ -607,11 +607,13 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 	gboolean clipboard_is_empty;
 	gboolean new_item_enabled;
 	gboolean readonly;
+	gboolean locked;
 
 	g_debug( "%s: window=%p", thisfn, ( void * ) window );
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 
 	mis = ( MenubarIndicatorsStruct * ) g_object_get_data( G_OBJECT( window ), MENUBAR_PROP_INDICATORS );
+	locked = nact_window_is_lockdown( NACT_WINDOW( window ));
 
 	g_object_get(
 			G_OBJECT( window ),
@@ -628,11 +630,11 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 	/* new menu enabled if selection is a menu or an action */
 	/* new action enabled if selection is a menu or an action */
 	new_item_enabled = ( selected_row == NULL || NA_IS_OBJECT_ITEM( selected_row ));
-	enable_item( window, "NewMenuItem", new_item_enabled );
-	enable_item( window, "NewActionItem", new_item_enabled );
+	enable_item( window, "NewMenuItem", new_item_enabled && !locked );
+	enable_item( window, "NewActionItem", new_item_enabled && !locked );
 
 	/* new profile enabled if selection is relative to only one writable action */
-	enable_item( window, "NewProfileItem", item != NULL && !NA_IS_OBJECT_MENU( item ) && !readonly );
+	enable_item( window, "NewProfileItem", item != NULL && !NA_IS_OBJECT_MENU( item ) && !readonly && !locked );
 
 	/* save enabled if at least one item has been modified */
 	enable_item( window, "SaveItem", has_modified || mis->level_zero_order_changed );
@@ -649,15 +651,15 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 	/* cut/delete require a writable item */
 	cut_enabled = ( mis->treeview_has_focus || mis->popup_handler ) && count_selected > 0 && !readonly;
 	copy_enabled = ( mis->treeview_has_focus || mis->popup_handler ) && count_selected > 0;
-	duplicate_enabled = ( mis->treeview_has_focus || mis->popup_handler ) && count_selected > 0;
-	delete_enabled = ( mis->treeview_has_focus || mis->popup_handler ) && count_selected > 0 && !readonly;
+	duplicate_enabled = ( mis->treeview_has_focus || mis->popup_handler ) && count_selected > 0 && !locked;
+	delete_enabled = ( mis->treeview_has_focus || mis->popup_handler ) && count_selected > 0 && !readonly && !locked;
 
 	/* paste enabled if
 	 * - simple selection
 	 * - clipboard contains only profiles, and current selection is a profile
 	 * - clipboard contains actions or menus, and current selection is a menu or an action */
 	paste_enabled = FALSE;
-	if(( mis->treeview_has_focus || mis->popup_handler ) && count_selected <= 1 ){
+	if(( mis->treeview_has_focus || mis->popup_handler ) && count_selected <= 1 && !locked ){
 		if( !clipboard_is_empty ){
 			if( mis->clipboard_profiles ){
 				paste_enabled = item && NA_IS_OBJECT_ACTION( item ) && !readonly;
@@ -673,7 +675,7 @@ on_update_sensitivities( NactMainWindow *window, gpointer user_data )
 	 * - or current item is a menu
 	 * do not paste into if current selection is a profile */
 	paste_into_enabled = FALSE;
-	if(( mis->treeview_has_focus || mis->popup_handler ) && count_selected <= 1 ){
+	if(( mis->treeview_has_focus || mis->popup_handler ) && count_selected <= 1 && !locked ){
 		if( mis->selected_menus + mis->selected_actions ){
 			if( !clipboard_is_empty ){
 				if( mis->clipboard_profiles ){
diff --git a/nautilus-actions/nact/nact-window.c b/nautilus-actions/nact/nact-window.c
index 5436e8c..d7bab74 100644
--- a/nautilus-actions/nact/nact-window.c
+++ b/nautilus-actions/nact/nact-window.c
@@ -36,7 +36,6 @@
 #include <glib/gi18n.h>
 
 #include <api/na-iio-provider.h>
-
 #include <api/na-object-api.h>
 
 #include <runtime/na-iprefs.h>
@@ -197,6 +196,34 @@ nact_window_get_pivot( NactWindow *window )
 }
 
 /**
+ * nact_window_is_lockdown:
+ * @window: this #NactWindow instance.
+ *
+ * Returns: %TRUE if the configuration is locked to be read-only, %FALSE
+ * else.
+ */
+gboolean
+nact_window_is_lockdown( NactWindow *window )
+{
+	static const gchar *thisfn = "nact_window_is_lockdown";
+	gboolean locked;
+	NAPivot *pivot;
+
+	locked = FALSE;
+
+	g_return_val_if_fail( NACT_IS_WINDOW( window ), locked );
+
+	if( !window->private->dispose_has_run ){
+
+		pivot = nact_window_get_pivot( window );
+		locked = na_iprefs_read_bool( NA_IPREFS( pivot ), NAUTILUS_ACTIONS_GCONF_BASEDIR "/mandatory/lockdown", locked );
+		g_debug( "%s: locked=%s", thisfn, locked ? "True":"False" );
+	}
+
+	return( locked );
+}
+
+/**
  * nact_window_save_item:
  * @window: this #NactWindow instance.
  * @item: the #NAObjectItem to be saved.
diff --git a/nautilus-actions/nact/nact-window.h b/nautilus-actions/nact/nact-window.h
index ae55376..b9ae80c 100644
--- a/nautilus-actions/nact/nact-window.h
+++ b/nautilus-actions/nact/nact-window.h
@@ -75,6 +75,8 @@ GType    nact_window_get_type( void );
 
 NAPivot *nact_window_get_pivot( NactWindow *window );
 
+gboolean nact_window_is_lockdown( NactWindow *window );
+
 gboolean nact_window_save_item( NactWindow *window, NAObjectItem *item );
 gboolean nact_window_delete_item( NactWindow *window, const NAObjectItem *item );
 



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