Re: [PATCH] Fix two warning dialogs



Am Dienstag, den 12.07.2005, 15:24 -0400 schrieb Luis Villa:
> On 7/12/05, Christian Neumair <chris gnome-de org> wrote:
> > From bug 308248 [1]:
> > 
> > "In Nautilus, when dragging a CD-ROM disc or other mounted volume to the
> > trash, Nautilus presents the user with the following message:
> > 
> > 'If you want to eject the volume, please use Eject in the right-click menu of
> > the volume.'
> 
> Is there any particular reason nautilus doesn't just eject them, given
> that nautilus (1) knows what the volume is and (2) has a fair guess
> that the intent was to eject?

Stop asking those straightforward and simple questions. They glare so
much, I can't even bear it!

Proposed patch attached for ejecting volumes and computer/trash/home
removal from desktop [1], which was also heavily improved, now allowing
to remove multiple of these items from the desktop at once, and also
allowing to remove them through the context menu, because else one
couldn't remove the trash. After applying the patch, we're only bad at
providing mass unmounting (i.e. no unmount menu item for multiple
selected mounted volumes), but that can be fixed later as well.

[1] http://mail.gnome.org/archives/nautilus-list/2005-July/msg00138.html

-- 
Christian Neumair <chris gnome-de org>
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.701
diff -u -p -r1.701 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	11 Jul 2005 10:07:53 -0000	1.701
+++ src/file-manager/fm-directory-view.c	13 Jul 2005 10:00:42 -0000
@@ -3193,39 +3195,57 @@ fm_directory_view_duplicate_selection (F
 	eel_g_list_free_deep (uris);
 }
 
-/* special_link_in_selection
+
+/* selection_special_link_count
  * 
  * Return TRUE if one of our special links is in the selection.
  * Special links include the following: 
- *	 NAUTILUS_DESKTOP_LINK_TRASH, NAUTILUS_DESKTOP_LINK_HOME, NAUTILUS_DESKTOP_LINK_MOUNT
+ *	 NAUTILUS_DESKTOP_LINK_HOME,
+ *	 NAUTILUS_DESKTOP_LINK_COMPUTER,
+ *	 NAUTILUS_DESKTOP_LINK_TRASH,
+ *	 NAUTILUS_DESKTOP_LINK_VOLUME
  */
  
-static gboolean
-special_link_in_selection (FMDirectoryView *view)
+static int
+selection_special_link_count (GList *selection,
+			      int *home_computer_trash_count)
 {
-	gboolean saw_link;
-	GList *selection, *node;
+	int ret;
+	GList *node;
 	NautilusFile *file;
+	NautilusDesktopLink *link;
 
-	g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
-
-	saw_link = FALSE;
+	g_return_val_if_fail (home_computer_trash_count != NULL, 0);
 
-	selection = fm_directory_view_get_selection (FM_DIRECTORY_VIEW (view));
+	*home_computer_trash_count = 0;
+	ret = 0;
 
 	for (node = selection; node != NULL; node = node->next) {
 		file = NAUTILUS_FILE (node->data);
 
-		saw_link = NAUTILUS_IS_DESKTOP_ICON_FILE (file);
-		
-		if (saw_link) {
-			break;
+		if (NAUTILUS_IS_DESKTOP_ICON_FILE (file)) {
+			ret++;
+
+			link = nautilus_desktop_icon_file_get_link (
+				NAUTILUS_DESKTOP_ICON_FILE (file));
+
+			if (link != NULL) {
+				switch (nautilus_desktop_link_get_link_type (link)) {
+				case NAUTILUS_DESKTOP_LINK_HOME:
+				case NAUTILUS_DESKTOP_LINK_COMPUTER:
+				case NAUTILUS_DESKTOP_LINK_TRASH:
+					(*home_computer_trash_count)++;
+					break;
+				default:
+					break;
+				}
+
+				g_object_unref (link);
+			}
 		}
 	}
 	
-	nautilus_file_list_free (selection);
-	
-	return saw_link;
+	return ret;
 }
 
 static gboolean
@@ -3293,6 +3313,22 @@ file_name_from_uri (const char *uri)
 }
 
 static gboolean
+uris_are_all_desktop (GList *uris)
+{
+	GList *l;
+
+	g_return_val_if_fail (uris != NULL, FALSE);
+
+	for (l = uris; l != NULL; l = l->next) {
+		if (!eel_uri_is_desktop (l->data)) {
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
+static gboolean
 fm_directory_view_confirm_deletion (FMDirectoryView *view, GList *uris, gboolean all)
 {
 	GtkDialog *dialog;
@@ -3307,13 +3343,13 @@ fm_directory_view_confirm_deletion (FMDi
 
 	uri_count = g_list_length (uris);
 	g_assert (uri_count > 0);
-	
+
+	if (uris_are_all_desktop (uris)) {
+		return TRUE;
+	}
+
 	if (uri_count == 1) {
 		uri = (char *) uris->data;
-		if (eel_uri_is_desktop (uri)) {
-			/* Don't ask for desktop icons */
-			return TRUE;
-		}
 		file_name = file_name_from_uri (uri);
 		prompt = _("Cannot move file to trash, do you want to delete immediately?");
 		detail = g_strdup_printf (_("The file \"%s\" cannot be moved to the trash."), file_name);
@@ -6644,10 +6692,11 @@ static void
 real_update_menus (FMDirectoryView *view)
 {
 	GList *selection;
-	gint selection_count;
+	int selection_count;
+	int special_link_count;
+	int home_computer_trash_count;
 	const char *tip, *label;
 	char *label_with_underscore;
-	gboolean selection_contains_special_link;
 	gboolean is_read_only;
 	gboolean can_create_files;
 	gboolean can_delete_files;
@@ -6664,15 +6713,16 @@ real_update_menus (FMDirectoryView *view
 	selection = fm_directory_view_get_selection (view);
 	selection_count = g_list_length (selection);
 
-	selection_contains_special_link = special_link_in_selection (view);
+	special_link_count = selection_special_link_count (selection, &home_computer_trash_count);
 	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;
+		&& (special_link_count == 0 ||
+		    home_computer_trash_count == selection_count);
 	can_copy_files = selection_count != 0
-		&& !selection_contains_special_link;	
+		&& special_link_count == 0;
 
 	can_duplicate_files = can_create_files && can_copy_files;
 	can_link_files = can_create_files && can_copy_files;
@@ -6763,6 +6813,10 @@ real_update_menus (FMDirectoryView *view
 	if (all_selected_items_in_trash (view)) {
 		label = _("_Delete from Trash");
 		tip = _("Delete all selected items permanently");
+		show_separate_delete_command = FALSE;
+	} else if (selection_count == home_computer_trash_count) {
+		label = _("_Remove from Desktop");
+		tip = _("Permanently remove all selected items from desktop");
 		show_separate_delete_command = FALSE;
 	} else {
 		label = _("Mo_ve to Trash");
Index: libnautilus-private/nautilus-desktop-link-monitor.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-desktop-link-monitor.c,v
retrieving revision 1.13
diff -u -p -r1.13 nautilus-desktop-link-monitor.c
--- libnautilus-private/nautilus-desktop-link-monitor.c	11 Jul 2005 09:53:38 -0000	1.13
+++ libnautilus-private/nautilus-desktop-link-monitor.c	13 Jul 2005 10:00:42 -0000
@@ -86,74 +86,117 @@ nautilus_desktop_link_monitor_get (void)
 	return the_link_monitor;
 }
 
-static gboolean
-eject_for_type (GnomeVFSDeviceType type)
+static void
+volume_unmounted_dialog_callback (gboolean succeeded,
+				  char *error,
+				  char *detailed_error,
+				  gpointer data)
 {
-	switch (type) {
-	case GNOME_VFS_DEVICE_TYPE_CDROM:
-	case GNOME_VFS_DEVICE_TYPE_ZIP:
-	case GNOME_VFS_DEVICE_TYPE_JAZ:
-		return TRUE;
-	default:
-		return FALSE;
+	if (!succeeded) {
+		eel_show_error_dialog_with_details (error, NULL, 
+		                                    _("Unmount Error"), detailed_error, NULL);
 	}
 }
 
 static void
-volume_delete_dialog (GtkWidget *parent_view,
-                      NautilusDesktopLink *link)
+unmount_volume (NautilusDesktopLink *link)
 {
 	GnomeVFSVolume *volume;
-	char *dialog_str;
-	char *display_name;
-
 	volume = nautilus_desktop_link_get_volume (link);
 
 	if (volume != NULL) {
-		display_name = nautilus_desktop_link_get_display_name (link);
-		dialog_str = g_strdup_printf (_("You cannot move the volume \"%s\" to the trash."),
-					      display_name);
-		g_free (display_name);
-
-		if (eject_for_type (gnome_vfs_volume_get_device_type (volume))) {
-			eel_run_simple_dialog
-				(parent_view, 
-				 FALSE,
-				 GTK_MESSAGE_ERROR,
-				 dialog_str,
-				 _("If you want to eject the volume, please use Eject in the "
-				   "right-click menu of the volume."),
-				 NULL, GTK_STOCK_OK, NULL);
-		} else {
-			eel_run_simple_dialog
-				(parent_view, 
-				 FALSE,
-				 GTK_MESSAGE_ERROR,
-				 dialog_str,
-				 _("If you want to unmount the volume, please use Unmount Volume in the "
-				   "right-click menu of the volume."),
-				 NULL, GTK_STOCK_OK, NULL);
+		gnome_vfs_volume_unmount (volume, volume_unmounted_dialog_callback, NULL);
+	}
+}
+
+static void
+special_link_delete_dialog (GtkWidget *parent_view,
+			    GList *home_computer_trash_links)
+{
+	NautilusDesktopLink *link;
+	char *names[] = { NULL, NULL, NULL};
+	char *msg;
+	gboolean saw_home, saw_computer, saw_trash;
+	GList *l;
+	int i, res;
+
+	g_return_if_fail (g_list_length (home_computer_trash_links) < 4 &&
+			  g_list_length (home_computer_trash_links) > 0);
+
+	saw_home = saw_computer = saw_trash = FALSE;
+	i = 0;
+	for (l = home_computer_trash_links; l != NULL; l = l->next, i++) {
+		link = NAUTILUS_DESKTOP_LINK (l->data);
+
+		names[i] = nautilus_desktop_link_get_display_name (link);
+
+		switch (nautilus_desktop_link_get_link_type (link)) {
+		case NAUTILUS_DESKTOP_LINK_HOME:
+			saw_home = TRUE;
+			break;
+		case NAUTILUS_DESKTOP_LINK_COMPUTER:
+			saw_computer = TRUE;
+			break;
+		case NAUTILUS_DESKTOP_LINK_TRASH:
+			saw_trash = TRUE;
+			break;
+		default:
+			g_assert_not_reached ();
 		}
+	}
 
-		gnome_vfs_volume_unref (volume);
-		g_free (dialog_str);
+	switch (i) {
+	case 1:
+		msg = g_strdup_printf (_("Permanently Remove \"%s\" From Desktop?"), names[0]);
+		break;
+	case 2:
+		msg = g_strdup_printf (_("Permanently Remove \"%s\" and \"%s\" From Desktop?"), names[0], names[1]);
+		break;
+	case 3:
+		msg = g_strdup_printf (_("Permanently Remove \"%s\", \"%s\" and \"%s\" From Desktop?"), names[0], names[1], names[2]);
+		break;
+	default:
+		g_assert_not_reached ();
+	}
+
+	res = eel_run_simple_dialog (parent_view, FALSE,
+				     GTK_MESSAGE_QUESTION,
+				     msg, NULL, NULL,
+				     GTK_STOCK_CANCEL, _("_Remove"), NULL);
+	g_free (msg);
+	g_free (names[0]);
+	g_free (names[1]);
+	g_free (names[2]);
+
+	if (res != 0) {
+		if (saw_home) {
+			eel_preferences_set_boolean (NAUTILUS_PREFERENCES_DESKTOP_HOME_VISIBLE, FALSE);
+		}
+
+		if (saw_computer) {
+			eel_preferences_set_boolean (NAUTILUS_PREFERENCES_DESKTOP_COMPUTER_VISIBLE, FALSE);
+		}
+
+		if (saw_trash) {
+			eel_preferences_set_boolean (NAUTILUS_PREFERENCES_DESKTOP_TRASH_VISIBLE, FALSE);
+		}
 	}
 }
 
 void
-nautilus_desktop_link_monitor_delete_link (NautilusDesktopLinkMonitor *monitor,
-					   NautilusDesktopLink *link,
-					   GtkWidget *parent_view)
+nautilus_desktop_link_monitor_delete_links (NautilusDesktopLinkMonitor *monitor,
+					    GList *home_computer_trash_links,
+					    GList *volume_links,
+					    GtkWidget *parent_view)
 {
-	switch (nautilus_desktop_link_get_link_type (link)) {
-	case NAUTILUS_DESKTOP_LINK_HOME:
-	case NAUTILUS_DESKTOP_LINK_COMPUTER:
-	case NAUTILUS_DESKTOP_LINK_TRASH:
-		/* just ignore. We don't allow you to delete these */
-		break;
-	default:
-		volume_delete_dialog (parent_view, link);
-		break;
+	if (home_computer_trash_links != NULL) {
+		special_link_delete_dialog (parent_view, home_computer_trash_links);
+	}
+
+	if (volume_links != NULL) {
+		g_list_foreach (volume_links,
+				(GFunc) unmount_volume,
+				NULL);
 	}
 }
 
Index: libnautilus-private/nautilus-desktop-link-monitor.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-desktop-link-monitor.h,v
retrieving revision 1.3
diff -u -p -r1.3 nautilus-desktop-link-monitor.h
--- libnautilus-private/nautilus-desktop-link-monitor.h	12 Dec 2004 20:01:33 -0000	1.3
+++ libnautilus-private/nautilus-desktop-link-monitor.h	13 Jul 2005 10:00:42 -0000
@@ -53,9 +53,10 @@ typedef struct {
 GType   nautilus_desktop_link_monitor_get_type (void);
 
 NautilusDesktopLinkMonitor *   nautilus_desktop_link_monitor_get (void);
-void nautilus_desktop_link_monitor_delete_link (NautilusDesktopLinkMonitor *monitor,
-						NautilusDesktopLink *link,
-						GtkWidget *parent_view);
+void nautilus_desktop_link_monitor_delete_links (NautilusDesktopLinkMonitor *monitor,
+						 GList *home_computer_trash_links,
+						 GList *volume_links,
+						 GtkWidget *parent_view);
 
 /* Used by nautilus-desktop-link.c */
 char * nautilus_desktop_link_monitor_make_filename_unique (NautilusDesktopLinkMonitor *monitor,
Index: libnautilus-private/nautilus-file-operations.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.c,v
retrieving revision 1.194
diff -u -p -r1.194 nautilus-file-operations.c
--- libnautilus-private/nautilus-file-operations.c	7 Jul 2005 10:16:40 -0000	1.194
+++ libnautilus-private/nautilus-file-operations.c	13 Jul 2005 10:00:43 -0000
@@ -2495,12 +2535,15 @@ nautilus_file_operations_delete (const G
 				 GtkWidget *parent_view)
 {
 	GList *uri_list;
+	GList *home_computer_trash_link_list, *volume_link_list;
 	const GList *p;
 	const char *item_uri;
 	NautilusFile *file;
 	TransferInfo *transfer_info;
 
 	uri_list = NULL;
+	home_computer_trash_link_list = NULL;
+	volume_link_list = NULL;
 	for (p = item_uris; p != NULL; p = p->next) {
 		item_uri = (const char *) p->data;
 
@@ -2513,10 +2556,20 @@ nautilus_file_operations_delete (const G
 					link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
 
 					if (link != NULL) {
-						nautilus_desktop_link_monitor_delete_link (nautilus_desktop_link_monitor_get (),
-											   link,
-											   parent_view);
-						g_object_unref (link);
+						switch (nautilus_desktop_link_get_link_type (link)) {
+						case NAUTILUS_DESKTOP_LINK_HOME:
+						case NAUTILUS_DESKTOP_LINK_COMPUTER:
+						case NAUTILUS_DESKTOP_LINK_TRASH:
+							home_computer_trash_link_list = g_list_prepend (
+								home_computer_trash_link_list, link);
+							break;
+						case NAUTILUS_DESKTOP_LINK_VOLUME:
+							volume_link_list = g_list_prepend (
+								volume_link_list, link);
+							break;
+						default:
+							g_assert_not_reached ();
+						}
 					}
 				}
 				nautilus_file_unref (file);
@@ -2527,6 +2580,23 @@ nautilus_file_operations_delete (const G
 		}
 	}
 	uri_list = g_list_reverse (uri_list);
+	home_computer_trash_link_list = g_list_reverse (home_computer_trash_link_list);
+	volume_link_list = g_list_reverse (volume_link_list);
+
+	if (home_computer_trash_link_list != NULL || volume_link_list != NULL) {
+		nautilus_desktop_link_monitor_delete_links (nautilus_desktop_link_monitor_get (),
+							    home_computer_trash_link_list,
+							    volume_link_list,
+							    parent_view);
+		g_list_foreach (home_computer_trash_link_list,
+				(GFunc) g_object_unref,
+				NULL);
+		g_list_foreach (volume_link_list,
+				(GFunc) g_object_unref,
+				NULL);
+		g_list_free (home_computer_trash_link_list);
+		g_list_free (volume_link_list);
+	}
 
 	if (uri_list == NULL) {
 		return;

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



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