[PATCH] Don't allow to rename or delete home/desktop directory



The attached patch prevents the user from renaming his home or desktop
directory. This was only partially implemented before (user could rename
home and delete home and desktop). Therefore, the attached patch also
fixes bug 310414 [1].

[1] http://bugzilla.gnome.org/show_bug.cgi?id=310414

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.369
diff -u -p -r1.369 nautilus-file.c
--- libnautilus-private/nautilus-file.c	12 Aug 2005 18:11:29 -0000	1.369
+++ libnautilus-private/nautilus-file.c	14 Aug 2005 18:26:07 -0000
@@ -809,8 +809,17 @@ nautilus_file_can_execute (NautilusFile 
 		 GNOME_VFS_PERM_OTHER_EXEC);
 }
 
-static gboolean
-file_is_desktop (NautilusFile *file)
+/**
+ * nautilus_file_is_desktop_directory:
+ * 
+ * Check whether this file is the desktop directory.
+ * 
+ * @file: The file to check.
+ * 
+ * Return value: TRUE if this is the physical desktop directory.
+ */
+gboolean
+nautilus_file_is_desktop_directory (NautilusFile *file)
 {
 	GnomeVFSURI *dir_vfs_uri;
 
@@ -875,7 +884,9 @@ nautilus_file_can_rename (NautilusFile *
 		return FALSE;
 	}
 
-	if ((is_desktop_file (file) && !can_rename_desktop_file (file)) || file_is_desktop (file)) {
+	if ((is_desktop_file (file) && !can_rename_desktop_file (file)) ||
+	     nautilus_file_is_desktop_directory (file) ||
+	     nautilus_file_is_home (file)) {
 		return FALSE;
 	}
 	
@@ -1906,7 +1917,7 @@ prepend_automatic_emblem_names (Nautilus
 			(names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_TRASH));
 	}
 #endif
-	if (file_is_desktop (file)) {
+	if (nautilus_file_is_desktop_directory (file)) {
 		names = g_list_prepend 
 			(names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_DESKTOP));
 	}
Index: libnautilus-private/nautilus-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.h,v
retrieving revision 1.105
diff -u -p -r1.105 nautilus-file.h
--- libnautilus-private/nautilus-file.h	11 Oct 2004 12:55:13 -0000	1.105
+++ libnautilus-private/nautilus-file.h	14 Aug 2005 18:26:07 -0000
@@ -154,6 +154,7 @@ gboolean                nautilus_file_is
 gboolean                nautilus_file_is_in_trash                       (NautilusFile                   *file);
 gboolean                nautilus_file_is_in_desktop                     (NautilusFile                   *file);
 gboolean		nautilus_file_is_home				(NautilusFile                   *file);
+gboolean                nautilus_file_is_desktop_directory              (NautilusFile                   *file);
 GnomeVFSResult          nautilus_file_get_file_info_result              (NautilusFile                   *file);
 gboolean                nautilus_file_get_directory_item_count          (NautilusFile                   *file,
 									 guint                          *count,
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.703
diff -u -p -r1.703 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	1 Aug 2005 22:08:55 -0000	1.703
+++ src/file-manager/fm-directory-view.c	14 Aug 2005 18:26:13 -0000
@@ -3228,6 +3228,41 @@ special_link_in_selection (FMDirectoryVi
 	return saw_link;
 }
 
+/* desktop_or_home_dir_in_selection
+ * 
+ * Return TRUE if either the desktop or the home directory is in the selection.
+ */
+ 
+static gboolean
+desktop_or_home_dir_in_selection (FMDirectoryView *view)
+{
+	gboolean saw_desktop_or_home_dir;
+	GList *selection, *node;
+	NautilusFile *file;
+
+	g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
+
+	saw_desktop_or_home_dir = FALSE;
+
+	selection = fm_directory_view_get_selection (FM_DIRECTORY_VIEW (view));
+
+	for (node = selection; node != NULL; node = node->next) {
+		file = NAUTILUS_FILE (node->data);
+
+		saw_desktop_or_home_dir =
+			nautilus_file_is_home (file)
+			|| nautilus_file_is_desktop_directory (file);
+		
+		if (saw_desktop_or_home_dir) {
+			break;
+		}
+	}
+	
+	nautilus_file_list_free (selection);
+	
+	return saw_desktop_or_home_dir;
+}
+
 static gboolean
 can_move_uri_to_trash (FMDirectoryView *view, const char *file_uri_string)
 {
@@ -6640,6 +6675,7 @@ real_update_menus (FMDirectoryView *view
 	const char *tip, *label;
 	char *label_with_underscore;
 	gboolean selection_contains_special_link;
+	gboolean selection_contains_desktop_or_home_dir;
 	gboolean is_read_only;
 	gboolean can_create_files;
 	gboolean can_delete_files;
@@ -6657,12 +6693,14 @@ real_update_menus (FMDirectoryView *view
 	selection_count = g_list_length (selection);
 
 	selection_contains_special_link = special_link_in_selection (view);
+	selection_contains_desktop_or_home_dir = desktop_or_home_dir_in_selection (view);
 	is_read_only = fm_directory_view_is_read_only (view);
 
 	can_create_files = fm_directory_view_supports_creating_files (view);
 	can_delete_files = !is_read_only
 		&& selection_count != 0
-		&& !selection_contains_special_link;
+		&& !selection_contains_special_link
+		&& !selection_contains_desktop_or_home_dir;
 	can_copy_files = selection_count != 0
 		&& !selection_contains_special_link;	
 

Attachment: signature.asc
Description: This is a digitally signed message part



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