[PATCH] Allow to mount/unmount volume from within target URI



The attached patch is meant to allow the user to modify a volume from
within its target directory. It's not very well-tested. For instance,
I'm not sure whether not setting the volume in
libnautilus-private/nautilus-directory-async.c:link_info_done if the
volume_id is NULL causes some problems when unmounting a volume.

Sorry that I don't have the time to do more extensive testing.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-async.c,v
retrieving revision 1.218
diff -u -p -r1.218 nautilus-directory-async.c
--- libnautilus-private/nautilus-directory-async.c	12 Dec 2005 16:59:10 -0000	1.218
+++ libnautilus-private/nautilus-directory-async.c	5 Feb 2006 13:06:34 -0000
@@ -2850,21 +2850,21 @@ link_info_done (NautilusDirectory *direc
 	file->details->custom_icon = g_strdup (icon);
  	nautilus_file_clear_cached_display_name (file);
 
-	volume = NULL;
 	if (volume_id != 0) {
 		monitor = gnome_vfs_get_volume_monitor ();
+
 		volume = gnome_vfs_volume_monitor_get_volume_by_id (monitor, volume_id);
+		nautilus_file_set_volume (file, volume);
+		gnome_vfs_volume_unref (volume);
 	}
-	nautilus_file_set_volume (file, volume);
-	gnome_vfs_volume_unref (volume);
 	
-	drive = NULL;
 	if (drive_id != 0) {
 		monitor = gnome_vfs_get_volume_monitor ();
+
 		drive = gnome_vfs_volume_monitor_get_drive_by_id (monitor, drive_id);
+		nautilus_file_set_drive (file, drive);
+		gnome_vfs_drive_unref (drive);
 	}
-	nautilus_file_set_drive (file, drive);
-	gnome_vfs_drive_unref (drive);
 	
 	nautilus_directory_async_state_changed (directory);
 }
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.380
diff -u -p -r1.380 nautilus-file.c
--- libnautilus-private/nautilus-file.c	28 Jan 2006 14:55:08 -0000	1.380
+++ libnautilus-private/nautilus-file.c	5 Feb 2006 13:06:38 -0000
@@ -884,25 +884,72 @@ void
 nautilus_file_set_volume (NautilusFile *file,
 			  GnomeVFSVolume *volume)
 {
+	char *activation_uri;
+	NautilusFile *target_file;
+
 	file->details->has_volume = volume != NULL;
 	gnome_vfs_volume_ref (volume);
         g_object_set_data_full (G_OBJECT (file),
 				"nautilus_file_volume",
 				volume,
 				(GDestroyNotify)gnome_vfs_volume_unref);
-	
+
+	target_file = NULL;
+	activation_uri = NULL;
+
+	if (volume != NULL) {
+		activation_uri = gnome_vfs_volume_get_activation_uri (volume);
+	}
+
+	if (activation_uri != NULL) {
+		/* TODO prevent endless loops? */
+		target_file = nautilus_file_get (activation_uri);
+		if (target_file != NULL && target_file != file) {
+			nautilus_file_set_volume (target_file, volume);
+		}
+		g_free (activation_uri);
+	}
+
+	g_object_set_data_full (G_OBJECT (file),
+				"nautilus_file_volume_target",
+				target_file,
+				(GDestroyNotify) nautilus_file_unref);
 }
 
 void
 nautilus_file_set_drive (NautilusFile *file,
 			 GnomeVFSDrive *drive)
 {
+	char *activation_uri;
+	NautilusFile *target_file;
+
 	file->details->has_drive = drive != NULL;
 	gnome_vfs_drive_ref (drive);
         g_object_set_data_full (G_OBJECT (file),
 				"nautilus_file_drive",
 				drive,
 				(GDestroyNotify)gnome_vfs_drive_unref);
+
+	activation_uri = NULL;
+	target_file = NULL;
+
+	if (drive != NULL) {
+		activation_uri = gnome_vfs_drive_get_activation_uri (drive);
+	}
+
+	if (activation_uri != NULL) {
+		/* TODO prevent endless loops? */
+		target_file = nautilus_file_get (activation_uri);
+		if (target_file != NULL && target_file != file) {
+			nautilus_file_set_drive (target_file, drive);
+		}
+		g_free (activation_uri);
+	}
+
+	g_object_set_data_full (G_OBJECT (file),
+				"nautilus_file_drive_target",
+				target_file,
+				(GDestroyNotify) nautilus_file_unref);
 }
 
 
Index: src/file-manager/fm-actions.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-actions.h,v
retrieving revision 1.10
diff -u -p -r1.10 fm-actions.h
--- src/file-manager/fm-actions.h	12 Dec 2005 16:59:11 -0000	1.10
+++ src/file-manager/fm-actions.h	5 Feb 2006 13:06:39 -0000
@@ -60,6 +60,10 @@
 #define FM_ACTION_UNMOUNT_VOLUME "Unmount Volume"
 #define FM_ACTION_EJECT_VOLUME "Eject Volume"
 #define FM_ACTION_FORMAT_VOLUME "Format Volume"
+#define FM_ACTION_SELF_MOUNT_VOLUME "Self Mount Volume"
+#define FM_ACTION_SELF_UNMOUNT_VOLUME "Self Unmount Volume"
+#define FM_ACTION_SELF_EJECT_VOLUME "Self Eject Volume"
+#define FM_ACTION_SELF_FORMAT_VOLUME "Self Format Volume"
 #define FM_ACTION_SCRIPTS "Scripts"
 #define FM_ACTION_NEW_DOCUMENTS "New Documents"
 #define FM_ACTION_NEW_EMPTY_FILE "New Empty File"
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.734
diff -u -p -r1.734 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	26 Jan 2006 22:20:59 -0000	1.734
+++ src/file-manager/fm-directory-view.c	5 Feb 2006 13:06:45 -0000
@@ -6286,6 +6411,100 @@ action_eject_volume_callback (GtkAction 
 }
 
 static void
+action_self_mount_volume_callback (GtkAction *action,
+				   gpointer data)
+{
+	NautilusFile *file;
+	GnomeVFSDrive *drive;
+	FMDirectoryView *view;
+
+        view = FM_DIRECTORY_VIEW (data);
+
+	file = fm_directory_view_get_directory_as_file (view);
+	g_return_if_fail (file != NULL);
+
+	drive = nautilus_file_get_drive (file);
+	if (drive != NULL) {
+		gnome_vfs_drive_mount (drive, drive_mounted_callback, NULL);
+	}
+}
+
+static void
+action_self_unmount_volume_callback (GtkAction *action,
+				     gpointer data)
+{
+	NautilusFile *file;
+	GnomeVFSDrive *drive;
+	GnomeVFSVolume *volume;
+	FMDirectoryView *view;
+
+        view = FM_DIRECTORY_VIEW (data);
+
+	file = fm_directory_view_get_directory_as_file (view);
+	g_return_if_fail (file != NULL);
+
+	if (nautilus_file_has_volume (file)) {
+		volume = nautilus_file_get_volume (file);
+		if (volume != NULL) {
+			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) {
+			gnome_vfs_drive_unmount (drive, volume_or_drive_unmounted_callback, NULL);
+		}
+	}
+}
+
+static void
+action_self_eject_volume_callback (GtkAction *action,
+				   gpointer data)
+{
+	NautilusFile *file;
+	GnomeVFSDrive *drive;
+	GnomeVFSVolume *volume;
+	FMDirectoryView *view;
+
+        view = FM_DIRECTORY_VIEW (data);
+
+	file = fm_directory_view_get_directory_as_file (view);
+	g_return_if_fail (file != NULL);
+
+	if (nautilus_file_has_volume (file)) {
+		volume = nautilus_file_get_volume (file);
+		if (volume != NULL) {
+			gnome_vfs_volume_eject (volume, volume_or_drive_unmounted_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_unmounted_callback, NULL);
+		}
+	}
+}
+
+static void 
+action_self_format_volume_callback (GtkAction *action,
+				    gpointer   data)
+{
+	NautilusFile *file;
+	GnomeVFSDrive *drive;
+	FMDirectoryView *view;
+
+        view = FM_DIRECTORY_VIEW (data);
+
+	file = fm_directory_view_get_directory_as_file (view);
+	g_return_if_fail (file != NULL);
+
+	if (nautilus_file_has_drive (file)) {
+		drive = nautilus_file_get_drive (file);
+		if (gnome_vfs_drive_get_device_type (drive) == GNOME_VFS_DEVICE_TYPE_FLOPPY) {
+			g_spawn_command_line_async ("gfloppy", NULL);
+		}
+	}
+}
+
+static void
 connect_to_server_response_callback (GtkDialog *dialog,
 				     int response_id,
 				     gpointer data)
@@ -6682,6 +6901,22 @@ static const GtkActionEntry directory_vi
     N_("_Format"), NULL,                /* label, accelerator */
     N_("Format the selected volume"),                   /* tooltip */ 
     G_CALLBACK (action_format_volume_callback) },
+  { "Self Mount Volume", NULL,                  /* name, stock id */
+    N_("_Mount Volume"), NULL,                /* label, accelerator */
+    N_("Mount the volume associated with the open folder"),                   /* tooltip */ 
+    G_CALLBACK (action_self_mount_volume_callback) },
+  { "Self Unmount Volume", NULL,                  /* name, stock id */
+    N_("_Unmount Volume"), NULL,                /* label, accelerator */
+    N_("Unmount the volume associated with the open folder"),                   /* tooltip */ 
+    G_CALLBACK (action_self_unmount_volume_callback) },
+  { "Self Eject Volume", NULL,                  /* name, stock id */
+    N_("_Eject"), NULL,                /* label, accelerator */
+    N_("Eject the volume associated with the open folder"),                   /* tooltip */ 
+    G_CALLBACK (action_self_eject_volume_callback) },
+  { "Self Format Volume", NULL,                  /* name, stock id */
+    N_("_Format"), NULL,                /* label, accelerator */
+    N_("Format the volume associated with the open folder"),                   /* tooltip */ 
+    G_CALLBACK (action_self_format_volume_callback) },
   { "OpenCloseParent", NULL,                  /* name, stock id */
     N_("Open File and Close window"), "<alt><shift>Down",                /* label, accelerator */
     NULL,                   /* tooltip */ 
@@ -7026,6 +7261,10 @@ real_update_menus_volumes (FMDirectoryVi
 	gboolean show_eject;
 	gboolean show_connect;
 	gboolean show_format;
+	gboolean show_self_mount;
+	gboolean show_self_unmount;
+	gboolean show_self_eject;
+	gboolean show_self_format;
 	GtkAction *action;
 
 	show_mount = (selection != NULL);
@@ -7084,6 +7323,36 @@ real_update_menus_volumes (FMDirectoryVi
 	action = gtk_action_group_get_action (view->details->dir_action_group,
 					      FM_ACTION_FORMAT_VOLUME);
 	gtk_action_set_visible (action, show_format);
+
+	show_self_mount = show_self_unmount = show_self_eject = show_self_format = FALSE;
+
+	file = fm_directory_view_get_directory_as_file (view);
+	if (file != NULL) {
+		gboolean show_self_connect_dummy;
+
+		file_should_show_foreach (file,
+					  &show_self_mount,
+					  &show_self_unmount,
+					  &show_self_eject,
+					  &show_self_connect_dummy,
+					  &show_self_format);
+	}
+
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      FM_ACTION_SELF_MOUNT_VOLUME);
+	gtk_action_set_visible (action, show_self_mount);
+
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      FM_ACTION_SELF_UNMOUNT_VOLUME);
+	gtk_action_set_visible (action, show_self_unmount);
+
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      FM_ACTION_SELF_EJECT_VOLUME);
+	gtk_action_set_visible (action, show_self_eject);
+
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      FM_ACTION_SELF_FORMAT_VOLUME);
+	gtk_action_set_visible (action, show_self_format);
 }
 
 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.79
diff -u -p -r1.79 nautilus-directory-view-ui.xml
--- src/file-manager/nautilus-directory-view-ui.xml	12 Dec 2005 16:59:11 -0000	1.79
+++ src/file-manager/nautilus-directory-view-ui.xml	5 Feb 2006 13:06:46 -0000
@@ -36,6 +36,11 @@
 		</placeholder>
 		<placeholder name="File Items Placeholder">
 			<menuitem name="Properties" action="Properties"/>
+
+			<menuitem name="Self Mount Volume" action="Self Mount Volume"/>
+			<menuitem name="Self Unmount Volume" action="Self Unmount Volume"/>
+			<menuitem name="Self Eject Volume" action="Self Eject Volume"/>
+			<menuitem name="Self Format Volume" action="Self Format Volume"/>
 		</placeholder>
 		<placeholder name="Global File Items Placeholder">
 			<menuitem name="Empty Trash" action="Empty Trash"/>

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



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