[PATCH] eject improvement, update - Nautilus bugzilla # 151840.



Hello,

This patch makes it possible to eject umounted media with Nautilus.
The patch is basically a port of my old patch, the idea that eject
always should be visible still applies. The attached patch is against
CVS of today, but because I do not have a complete bleeding edge gnome
environment the patch is untested and probably broken somehow. Anyway,
this patch is probably easier to integrate than the old one that used
the old bonobo-ui code.

Let me know what you think. Thanks.

/ magnus
Index: src/file-manager/fm-actions.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-actions.h,v
retrieving revision 1.2
diff -p -u -r1.2 fm-actions.h
--- src/file-manager/fm-actions.h	22 Nov 2004 15:24:38 -0000	1.2
+++ src/file-manager/fm-actions.h	9 Jan 2005 23:13:29 -0000
@@ -50,6 +50,7 @@
 #define FM_ACTION_CONNECT_TO_SERVER_LINK "Connect To Server Link"
 #define FM_ACTION_MOUNT_VOLUME "Mount Volume"
 #define FM_ACTION_UNMOUNT_VOLUME "Unmount Volume"
+#define FM_ACTION_EJECT_VOLUME "Eject Volume"
 #define FM_ACTION_SCRIPTS "Scripts"
 #define FM_ACTION_NEW_DOCUMENTS "New Documents"
 #define FM_ACTION_EMPTY_TRASH_CONDITIONAL "Empty Trash Conditional"
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.651
diff -p -u -r1.651 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	29 Nov 2004 16:47:57 -0000	1.651
+++ src/file-manager/fm-directory-view.c	9 Jan 2005 23:13:36 -0000
@@ -5460,17 +5460,22 @@ volume_or_drive_unmounted_callback (gboo
 				    char *detailed_error,
 				    gpointer data)
 {
-	gboolean eject;
+	if (!succeeded) {
+		eel_show_error_dialog_with_details (error, NULL, 
+		                                    _("Unmount Error"), detailed_error, NULL);
+	}
+}
 
-	eject = GPOINTER_TO_INT (data);
+
+static void
+volume_or_drive_ejected_callback (gboolean succeeded,
+				    char *error,
+				    char *detailed_error,
+				    gpointer data)
+{
 	if (!succeeded) {
-		if (eject) {
-			eel_show_error_dialog_with_details (error, NULL, 
-			                                    _("Eject Error"), detailed_error, NULL);
-		} else {
-			eel_show_error_dialog_with_details (error, NULL, 
-			                                    _("Unmount Error"), detailed_error, NULL);
-		}
+		eel_show_error_dialog_with_details (error, NULL, 
+		                                    _("Eject Error"), detailed_error, NULL);
 	}
 }
 
@@ -5499,20 +5504,48 @@ action_unmount_volume_callback (GtkActio
 	if (nautilus_file_has_volume (file)) {
 		volume = nautilus_file_get_volume (file);
 		if (volume != NULL) {
-			if (eject_for_type (gnome_vfs_volume_get_device_type (volume))) {
-				gnome_vfs_volume_eject (volume, volume_or_drive_unmounted_callback, GINT_TO_POINTER (TRUE));
-			} else {
-				gnome_vfs_volume_unmount (volume, volume_or_drive_unmounted_callback, GINT_TO_POINTER (FALSE));
-			}
+			gnome_vfs_volume_unmount (volume, volume_or_drive_unmounted_callback, NULL);
 		}
 	} else if (nautilus_file_has_drive (file)) {
 		drive = nautilus_file_get_drive (file);
 		if (drive != NULL) {
-			if (eject_for_type (gnome_vfs_drive_get_device_type (drive))) {
-				gnome_vfs_drive_eject (drive, volume_or_drive_unmounted_callback, GINT_TO_POINTER (TRUE));
-			} else {
-				gnome_vfs_drive_unmount (drive, volume_or_drive_unmounted_callback, GINT_TO_POINTER (FALSE));
-			}
+			gnome_vfs_drive_unmount (drive, volume_or_drive_unmounted_callback, NULL);
+		}
+	}
+	
+	nautilus_file_list_free (selection);
+}
+
+static void
+action_eject_volume_callback (GtkAction *action,
+				gpointer data)
+{
+	NautilusFile *file;
+	GList *selection;
+	GnomeVFSDrive *drive;
+	GnomeVFSVolume *volume;
+	FMDirectoryView *view;
+
+        view = FM_DIRECTORY_VIEW (data);
+	
+	selection = fm_directory_view_get_selection (view);
+
+	if (!eel_g_list_exactly_one_item (selection)) {
+		nautilus_file_list_free (selection);
+		return;
+	}
+
+	file = NAUTILUS_FILE (selection->data);
+	
+	if (nautilus_file_has_volume (file)) {
+		volume = nautilus_file_get_volume (file);
+		if (volume != NULL) {
+			gnome_vfs_volume_eject (volume, volume_or_drive_ejected_callback, NULL);
+		}
+	} else if (nautilus_file_has_drive (file)) {
+		drive = nautilus_file_get_drive (file);
+		if (drive != NULL) {
+			gnome_vfs_drive_eject (drive, volume_or_drive_ejected_callback, NULL);
 		}
 	}
 	
@@ -5808,6 +5841,10 @@ static GtkActionEntry directory_view_ent
     N_("_Unmount Volume"), NULL,                /* label, accelerator */
     N_("Unmount the selected volume"),                   /* tooltip */ 
     G_CALLBACK (action_unmount_volume_callback) },
+  { "Eject Volume", NULL,                  /* name, stock id */
+    N_("_Eject"), NULL,                /* label, accelerator */
+    N_("Eject the selected volume"),                   /* tooltip */ 
+    G_CALLBACK (action_eject_volume_callback) },
   { "OpenCloseParent", NULL,                  /* name, stock id */
     N_("Open File and Close window"), "<alt><shift>Down",                /* label, accelerator */
     NULL,                   /* tooltip */ 
@@ -5984,7 +6021,7 @@ real_update_menus_volumes (FMDirectoryVi
 	NautilusFile *file;
 	gboolean show_mount;
 	gboolean show_unmount;
-	gboolean unmount_is_eject;
+	gboolean show_eject;
 	gboolean show_connect;
 	GnomeVFSVolume *volume;
 	GnomeVFSDrive *drive;
@@ -5993,7 +6030,7 @@ real_update_menus_volumes (FMDirectoryVi
 
 	show_mount = FALSE;
 	show_unmount = FALSE;
-	unmount_is_eject = FALSE;
+	show_eject = FALSE;
 	show_connect = FALSE;
 
 	if (selection_count == 1) {
@@ -6003,12 +6040,12 @@ real_update_menus_volumes (FMDirectoryVi
 			show_unmount = TRUE;
 
 			volume = nautilus_file_get_volume (file);
-			unmount_is_eject = eject_for_type (gnome_vfs_volume_get_device_type (volume));
+			show_eject = eject_for_type (gnome_vfs_volume_get_device_type (volume));
 		} else if (nautilus_file_has_drive (file)) {
 			drive = nautilus_file_get_drive (file);
+			show_eject = eject_for_type (gnome_vfs_drive_get_device_type (drive));
 			if (gnome_vfs_drive_is_mounted (drive)) {
 				show_unmount = TRUE;
-				unmount_is_eject = eject_for_type (gnome_vfs_drive_get_device_type (drive));
 			} else {
 				show_mount = TRUE;
 			}
@@ -6040,12 +6077,9 @@ real_update_menus_volumes (FMDirectoryVi
 					      FM_ACTION_UNMOUNT_VOLUME);
 	gtk_action_set_visible (action, show_unmount);
 	
-	if (show_unmount) {
-		g_object_set (action, "label", 
-			      unmount_is_eject? _("E_ject"):_("_Unmount Volume"),
-			      NULL);
-	}
-
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      FM_ACTION_EJECT_VOLUME);
+	gtk_action_set_visible (action, show_eject);
 }
 
 static void
Index: src/file-manager/nautilus-directory-view-ui.xml
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/nautilus-directory-view-ui.xml,v
retrieving revision 1.70
diff -p -u -r1.70 nautilus-directory-view-ui.xml
--- src/file-manager/nautilus-directory-view-ui.xml	22 Nov 2004 15:24:38 -0000	1.70
+++ src/file-manager/nautilus-directory-view-ui.xml	9 Jan 2005 23:13:37 -0000
@@ -145,6 +145,7 @@
         <placeholder name="Removabel Media Holder">
 		<menuitem name="Mount Volume" action="Mount Volume"/>
                 <menuitem name="Unmount Volume" action="Unmount Volume"/>
+                <menuitem name="Eject Volume" action="Eject Volume"/>
         </placeholder>
         <menuitem name="Connect To Server Link" action="Connect To Server Link"/>
 </popup>


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