? depcomp
? nautilus_head_play_dvd_cd.diff
Index: src/file-manager/fm-actions.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-actions.h,v
retrieving revision 1.8
diff -u -r1.8 fm-actions.h
--- src/file-manager/fm-actions.h	1 Jul 2005 10:30:33 -0000	1.8
+++ src/file-manager/fm-actions.h	9 Jul 2005 11:54:57 -0000
@@ -57,6 +57,8 @@
 #define FM_ACTION_MOUNT_VOLUME "Mount Volume"
 #define FM_ACTION_UNMOUNT_VOLUME "Unmount Volume"
 #define FM_ACTION_EJECT_VOLUME "Eject Volume"
+#define FM_ACTION_PLAY_AUDIO_CD "Play CD"
+#define FM_ACTION_PLAY_DVD_VIDEO "Play DVD"
 #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.700
diff -u -r1.700 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	6 Jul 2005 12:18:28 -0000	1.700
+++ src/file-manager/fm-directory-view.c	9 Jul 2005 11:55:15 -0000
@@ -5833,6 +5833,170 @@
 	nautilus_file_list_free (selection);
 }
 
+#define GCONF_ROOT_AUTOPLAY  "/desktop/gnome/volume_manager/"
+
+/* copied from gnome-volume-manager/src/manager.c maybe there is a better way than
+ * duplicating this code? */
+/*
+ * gvm_run_command - run the given command, replacing %d with the device node
+ * and %m with the given path
+ */
+static void
+gvm_run_command (const char *device, const char *command, const char *path)
+{
+	char *argv[4];
+	gchar *new_command;
+	GError *error = NULL;
+	GString *exec = g_string_new (NULL);
+	char *p, *q;
+
+	/* perform s/%d/device/ and s/%m/path/ */
+	new_command = g_strdup (command);
+	q = new_command;
+	p = new_command;
+	while ((p = strchr (p, '%')) != NULL) {
+		if (*(p + 1) == 'd') {
+			*p = '\0';
+			g_string_append (exec, q);
+			g_string_append (exec, device);
+			q = p + 2;
+			p = p + 2;
+		} else if (*(p + 1) == 'm') {
+			*p = '\0';
+			g_string_append (exec, q);
+			g_string_append (exec, path);
+			q = p + 2;
+			p = p + 2;
+		}
+	}
+	g_string_append (exec, q);
+
+	argv[0] = "/bin/sh";
+	argv[1] = "-c";
+	argv[2] = exec->str;
+	argv[3] = NULL;
+
+	g_spawn_async (g_get_home_dir (), argv, NULL, 0, NULL, NULL,
+		       NULL, &error);
+	if (error)
+		warn ("failed to exec %s: %s\n", exec->str, error->message);
+
+	g_string_free (exec, TRUE);
+	g_free (new_command);
+}
+
+static void
+run_command (GnomeVFSVolume *volume, const char *command)
+{
+	char *device_path = gnome_vfs_volume_get_device_path (volume);
+	char *uri = gnome_vfs_volume_get_activation_uri (volume);
+	char *mount_path = gnome_vfs_get_local_path_from_uri (uri);
+	g_free (uri);
+
+	gvm_run_command (device_path, command,
+				 mount_path);
+
+	g_free (mount_path);
+	g_free (device_path);
+}
+
+static void
+play_autoplay_media (GnomeVFSVolume *volume, const char *autoplay_key)
+{
+	GConfClient *gconf_client = gconf_client_get_default ();
+	char *command = gconf_client_get_string (gconf_client,
+			autoplay_key, NULL);
+	run_command (volume, command);
+	g_free (command);
+	g_object_unref (gconf_client);
+}
+
+static void
+play_dvd (GnomeVFSVolume *volume)
+{
+	play_autoplay_media (volume,
+			GCONF_ROOT_AUTOPLAY "autoplay_dvd_command");
+}
+
+static void
+play_cda (GnomeVFSVolume *volume)
+{
+	play_autoplay_media (volume,
+			GCONF_ROOT_AUTOPLAY "autoplay_cda_command");
+}
+
+enum PlayMode
+{
+	PlayCD,
+	PlayDVD
+};
+
+/*
+ * That function is just to avoid code
+ * duplication between action_play_dvd_video_callback ()
+ * and action_play_cda_callback ()
+ * maybe there's a better way.
+ */
+static void play_dvd_or_audio_cd (enum PlayMode play_mode,
+		gpointer data)
+{
+	NautilusFile *file;
+	GList *selection;
+	GList *volumes;
+	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_drive (file)) {
+		drive = nautilus_file_get_drive (file);
+		volumes = gnome_vfs_drive_get_mounted_volumes (drive);
+		if (volumes != NULL)
+		{
+			volume = GNOME_VFS_VOLUME (volumes->data);
+			if (volume != NULL)
+			{
+				if (play_mode == PlayCD)
+				{
+					play_cda (volume);
+				}
+				else
+				{
+					play_dvd (volume);
+				}
+			}
+		}
+		g_list_foreach (volumes, (GFunc)gnome_vfs_volume_unref, NULL);
+		g_list_free (volumes);
+	}
+
+	nautilus_file_list_free (selection);
+}
+
+static void
+action_play_dvd_video_callback (GtkAction *action,
+				gpointer data)
+{
+	play_dvd_or_audio_cd (PlayDVD, data);
+}
+
+static void
+action_play_cda_callback (GtkAction *action,
+				gpointer data)
+{
+	play_dvd_or_audio_cd (PlayCD, data);
+}
+
 static void
 connect_to_server_response_callback (GtkDialog *dialog,
 				     int response_id,
@@ -6228,6 +6392,14 @@
     N_("Open File and Close window"), "<alt><shift>Down",                /* label, accelerator */
     NULL,                   /* tooltip */ 
     G_CALLBACK (action_open_close_parent_callback) },
+  { "Play CD", NULL,                  /* name, stock id */
+    N_("_Play CD"), NULL,                /* label, accelerator */
+    N_("Play the selected audio CD"),                   /* tooltip */ 
+    G_CALLBACK (action_play_cda_callback) },
+  { "Play DVD", NULL,                  /* name, stock id */
+    N_("_Play DVD"), NULL,                /* label, accelerator */
+    N_("Play the selected DVD"),                   /* tooltip */ 
+    G_CALLBACK (action_play_dvd_video_callback) },
 
   /* Location-specific actions */
   { FM_ACTION_LOCATION_OPEN_ALTERNATE, NULL,                  /* name, stock id */
@@ -6457,6 +6629,63 @@
 	return TRUE;
 }
 
+/*
+ * gvm_check_dvd_only - is this a Video DVD?
+ *
+ * Returns TRUE if this was a Video DVD and FALSE otherwise.
+ * (the original in gvm was also running the autoplay action,
+ * I removed that code, so I renamed from gvm_check_dvd to
+ * gvm_check_dvd_only)
+ */
+static gboolean
+gvm_check_dvd_only (const char *udi, const char *device, const char *mount_point)
+{
+	char *path;
+	gboolean retval;
+	
+	path = g_build_path (G_DIR_SEPARATOR_S, mount_point, "video_ts", NULL);
+	retval = g_file_test (path, G_FILE_TEST_IS_DIR);
+	g_free (path);
+	
+	/* try the other name, if needed */
+	if (retval == FALSE) {
+		path = g_build_path (G_DIR_SEPARATOR_S, mount_point,
+				     "VIDEO_TS", NULL);
+		retval = g_file_test (path, G_FILE_TEST_IS_DIR);
+		g_free (path);
+	}
+	
+	return retval;
+}
+
+static gboolean
+check_dvd_video (GnomeVFSVolume *volume)
+{
+	char *device_path = gnome_vfs_volume_get_device_path (volume);
+	char *uri = gnome_vfs_volume_get_activation_uri (volume);
+	char *mount_path = gnome_vfs_get_local_path_from_uri (uri);
+	char *udi = gnome_vfs_volume_get_hal_udi (volume);
+
+	gboolean result = gvm_check_dvd_only (udi, device_path, mount_path);
+
+	g_free (device_path);
+	g_free (udi);
+	g_free (uri);
+	g_free (mount_path);
+
+	return result;
+}
+
+static gboolean
+check_audio_cd (GnomeVFSVolume *volume)
+{
+	char *activation_uri = gnome_vfs_volume_get_activation_uri (volume);
+	// we have an audioCD if the activation URI starts by 'cdda://'
+	gboolean result = (strncmp ("cdda://", activation_uri, 7) == 0);
+	g_free (activation_uri);
+	return result;
+}
+
 static void
 real_update_menus_volumes (FMDirectoryView *view,
 			   GList *selection,
@@ -6467,6 +6696,8 @@
 	gboolean show_unmount;
 	gboolean show_eject;
 	gboolean show_connect;
+	gboolean show_play_audio_cd;
+	gboolean show_play_dvd_video;
 	GnomeVFSVolume *volume;
 	GnomeVFSDrive *drive;
 	GtkAction *action;
@@ -6476,6 +6707,8 @@
 	show_unmount = FALSE;
 	show_eject = FALSE;
 	show_connect = FALSE;
+	show_play_audio_cd = FALSE;
+	show_play_dvd_video = FALSE;
 
 	if (selection_count == 1) {
 		file = NAUTILUS_FILE (selection->data);
@@ -6493,6 +6726,18 @@
 			} else {
 				show_mount = TRUE;
 			}
+			GList *volumes;
+			GnomeVFSVolume *volume = NULL;
+		
+			volumes = gnome_vfs_drive_get_mounted_volumes (drive);
+			if (volumes != NULL)
+			{
+				volume = GNOME_VFS_VOLUME (volumes->data);
+				show_play_audio_cd = check_audio_cd (volume);
+				show_play_dvd_video = check_dvd_video (volume);
+			}
+			g_list_foreach (volumes, (GFunc)gnome_vfs_volume_unref, NULL);
+			g_list_free (volumes);
 		} else if (nautilus_file_is_nautilus_link (file)) {
 			uri = nautilus_file_get_activation_uri (file);
 			if (uri != NULL &&
@@ -6530,6 +6775,14 @@
 	action = gtk_action_group_get_action (view->details->dir_action_group,
 					      FM_ACTION_EJECT_VOLUME);
 	gtk_action_set_visible (action, show_eject);
+
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      FM_ACTION_PLAY_AUDIO_CD);
+	gtk_action_set_visible (action, show_play_audio_cd);
+
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      FM_ACTION_PLAY_DVD_VIDEO);
+	gtk_action_set_visible (action, show_play_dvd_video);
 }
 
 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.76
diff -u -r1.76 nautilus-directory-view-ui.xml
--- src/file-manager/nautilus-directory-view-ui.xml	6 Jul 2005 14:02:38 -0000	1.76
+++ src/file-manager/nautilus-directory-view-ui.xml	9 Jul 2005 11:55:15 -0000
@@ -144,6 +144,8 @@
         <menuitem name="Properties" action="Properties"/>
 	<separator name="Removable separator"/>
         <placeholder name="Removabel Media Holder">
+                <menuitem name="Play CD" action="Play CD"/>
+                <menuitem name="Play DVD" action="Play DVD"/>
 		<menuitem name="Mount Volume" action="Mount Volume"/>
                 <menuitem name="Unmount Volume" action="Unmount Volume"/>
                 <menuitem name="Eject Volume" action="Eject Volume"/>
