[Xfce4-commits] <parole:master> parole --device=/dev/cdrom is now enough to play media on that device. in thunar-volman the command should be parole --device=%d and Parole will handle the rest.

Ali Abdallah noreply at xfce.org
Thu Jan 14 21:40:07 CET 2010


Updating branch refs/heads/master
         to d577e6eaaa96923030b9cdd37744910b0146d312 (commit)
       from 01ed5fba8afa9263cbd489b80b2bf527d26fac6a (commit)

commit d577e6eaaa96923030b9cdd37744910b0146d312
Author: Ali Abdallah <aliov at xfce.org>
Date:   Thu Jan 14 15:15:17 2010 +0100

    parole --device=/dev/cdrom is now enough to play media on that device.
    in thunar-volman the command should be parole --device=%d and Parole will
    handle the rest.

 src/main.c          |   20 ++++++-
 src/parole-player.c |   14 ++++-
 src/parole-utils.c  |  177 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/parole-utils.h  |   10 ++-
 4 files changed, 217 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index 28e9e9f..524a731 100644
--- a/src/main.c
+++ b/src/main.c
@@ -72,14 +72,26 @@ parole_send_play_disc (const gchar *uri, const gchar *device)
 {
     DBusGProxy *proxy;
     GError *error = NULL;
+    gchar *uri_local;
+    
+    if ( uri )
+    {
+	uri_local = g_strdup (uri);
+    }
+    else
+    {
+	uri_local = parole_get_uri_from_unix_device (device);
+    }
     
     proxy = parole_get_proxy (PAROLE_DBUS_PATH, PAROLE_DBUS_INTERFACE);
     
     dbus_g_proxy_call (proxy, "PlayDisc", &error,
-		       G_TYPE_STRING, uri,
+		       G_TYPE_STRING, uri_local,
 		       G_TYPE_STRING, device,
 		       G_TYPE_INVALID,
 		       G_TYPE_INVALID);
+    
+    g_free (uri_local);
 		       
     if ( error )
     {
@@ -265,6 +277,8 @@ int main (int argc, char **argv)
 	
 	if ( filenames && filenames[0] != NULL )
 	    parole_send (filenames, device);
+	else if (device != NULL)
+	    parole_send_play_disc (NULL, device);
 	
 	if ( play )
 	    parole_send_message ("Play");
@@ -318,6 +332,10 @@ int main (int argc, char **argv)
 		parole_media_list_add_files (list, filenames);
 	    }
 	}
+	else if ( device != NULL )
+	{
+	    parole_player_play_uri_disc (player, NULL, device);
+	}
 	
 	if ( xfce_posix_signal_handler_init (&error)) 
 	{
diff --git a/src/parole-player.c b/src/parole-player.c
index 8277f61..cb97477 100644
--- a/src/parole-player.c
+++ b/src/parole-player.c
@@ -2061,7 +2061,19 @@ ParoleMediaList	*parole_player_get_media_list (ParolePlayer *player)
 
 void parole_player_play_uri_disc (ParolePlayer *player, const gchar *uri, const gchar *device)
 {
-    parole_player_disc_selected_cb (NULL, uri, device, player);
+    if ( uri )
+    {
+	parole_player_disc_selected_cb (NULL, uri, device, player);
+    }
+    else if (device)
+    {
+	gchar *uri_local = parole_get_uri_from_unix_device (device);
+	if ( uri_local )
+	{
+	    parole_player_disc_selected_cb (NULL, uri_local, device, player);
+	    g_free (uri_local);
+	}
+    }
 }
 
 void parole_player_terminate (ParolePlayer *player)
diff --git a/src/parole-utils.c b/src/parole-utils.c
index d7a0b76..f52e857 100644
--- a/src/parole-utils.c
+++ b/src/parole-utils.c
@@ -29,6 +29,15 @@
 #include <gst/gst.h>
 #include <glib.h>
 
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#if defined(__linux__)
+#include <linux/cdrom.h>
+#endif
+
 #include <libxfce4util/libxfce4util.h>
 
 #include <parole/parole.h>
@@ -414,3 +423,171 @@ void parole_get_media_files (GtkFileFilter *filter, const gchar *path,
     }
     g_object_unref (playlist_filter);
 }
+
+/***
+ * FIXME, parole_device_has_cdda and parole_guess_uri_from_mount
+ *        have common code with parole-disc.c
+ ***/
+
+
+gboolean
+parole_device_has_cdda (const gchar *device)
+{   
+    gboolean ret_val = FALSE;
+ 
+#if defined(__linux__)
+    gint fd;
+    gint drive;
+    
+    TRACE ("device : %s", device);
+    
+    if ( (fd = open (device, O_RDONLY)) < 0 )
+    {
+	g_debug ("Failed to open device : %s", device);
+	return FALSE;
+    }
+    
+    if ( (drive = ioctl (fd, CDROM_DRIVE_STATUS, NULL)) )
+    {
+	if ( drive == CDS_DRIVE_NOT_READY )
+	{
+	    g_debug ("Drive :%s is not yet ready\n", device);
+	}
+	else if ( drive == CDS_DISC_OK )
+	{
+	    if ( (drive = ioctl (fd, CDROM_DISC_STATUS, NULL)) > 0 )
+	    {
+		if ( drive == CDS_AUDIO )
+		{
+		    ret_val = TRUE;
+		}
+	    }
+	}
+    }
+    
+    close (fd);
+#endif /* if defined(__linux__) */
+    return ret_val;
+}
+
+gchar *
+parole_guess_uri_from_mount (GMount *mount)
+{
+    GFile *file;
+    gchar *uri = NULL;
+    
+    g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
+    
+    file = g_mount_get_root (mount);
+    
+    if ( g_file_has_uri_scheme (file, "cdda") )
+    {
+	uri = g_strdup ("cdda://");
+    }
+    else
+    {
+	gchar **content_type;
+	int i;
+	
+	content_type = g_content_type_guess_for_tree (file);
+    
+	for ( i = 0; content_type && content_type[i]; i++)
+	{
+	    TRACE ("Checking disc content type : %s", content_type[i]);
+		
+	    if ( !g_strcmp0 (content_type[i], "x-content/video-dvd") )
+	    {
+		uri = g_strdup ("dvd:/");
+		break;
+	    }
+	    else if ( !g_strcmp0 (content_type[i], "x-content/video-vcd") )
+	    {
+		uri = g_strdup ("vcd:/");
+		break;
+	    }
+	    else if ( !g_strcmp0 (content_type[i], "x-content/video-svcd") )
+	    {
+		uri = g_strdup ("svcd:/");
+		break;
+	    }
+	    else if ( !g_strcmp0 (content_type[i], "x-content/audio-cdda") )
+	    {
+		uri = g_strdup ("cdda://");
+		break;
+	    }
+	}
+	
+	if ( content_type )
+	    g_strfreev (content_type);
+    }
+    
+    g_object_unref (file);
+    
+    TRACE ("Got uri=%s for mount=%s", uri, g_mount_get_name (mount));
+	   
+    return uri;
+}
+
+gchar *
+parole_get_uri_from_unix_device (const gchar *device)
+{
+    GVolumeMonitor *monitor;
+    GList *list;
+    guint len;
+    guint i;
+    gchar *uri = NULL;
+    
+    if ( device == NULL )
+	return NULL;
+	
+    /*Check for cdda */
+    if ( parole_device_has_cdda (device) )
+    {
+	return g_strdup ("cdda://");
+    }
+    
+    monitor = g_volume_monitor_get ();
+    
+    list = g_volume_monitor_get_volumes (monitor);
+    
+    len = g_list_length (list);
+    
+    for ( i = 0; i < len; i++)
+    {
+	GVolume *volume;
+	GDrive *drive;
+	
+	volume = g_list_nth_data (list, i);
+	
+	drive = g_volume_get_drive (volume);
+	
+	if ( g_drive_can_eject (drive) && g_drive_has_media (drive) )
+	{
+	    gchar *unix_device;
+	    unix_device = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+	    
+	    if ( !g_strcmp0 (unix_device, device) )
+	    {
+		GMount *mount;
+		mount = g_volume_get_mount (volume);
+		if ( mount )
+		{
+		    uri = parole_guess_uri_from_mount (mount);
+		    g_object_unref (mount);
+		    break;
+		}
+	    }
+	}
+	
+	g_object_unref (drive);
+    }
+    
+    g_list_foreach (list, (GFunc) g_object_unref, NULL);
+    g_list_free (list);
+    
+    g_object_unref (monitor);
+    
+    TRACE ("Got uri=%s for device=%s", uri, device);
+    
+    return uri;
+}
diff --git a/src/parole-utils.h b/src/parole-utils.h
index a7e216e..d38a2ef 100644
--- a/src/parole-utils.h
+++ b/src/parole-utils.h
@@ -30,7 +30,7 @@ gint            thunar_file_compare_by_name 		(ParoleFile *file_a,
 							 ParoleFile *file_b,
 							 gboolean         case_sensitive);
 
-gchar          *parole_get_name_without_extension 	(const gchar *name)G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+gchar          *parole_get_name_without_extension 	(const gchar *name) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 
 gchar          *parole_get_subtitle_path		(const gchar *uri) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 
@@ -39,9 +39,15 @@ gboolean	parole_is_uri_disc			(const gchar *uri);
 GdkPixbuf      *parole_icon_load			(const gchar *icon_name,
 							 gint size);
 
-void			 parole_get_media_files		(GtkFileFilter *filter,
+void		parole_get_media_files			(GtkFileFilter *filter,
 							 const gchar *path,
 							 gboolean recursive,
 							 GSList **list);
+							 
+gboolean	parole_device_has_cdda 			(const gchar *device);
+
+gchar 	       *parole_guess_uri_from_mount 		(GMount *mount);
+							 
+gchar          *parole_get_uri_from_unix_device		(const gchar *device);
 
 #endif /* __PAROLE_UTILS_ */



More information about the Xfce4-commits mailing list