[Xfce4-commits] <parole:master> Better playlist handling on the browser plugin.

Ali Abdallah noreply at xfce.org
Fri Nov 27 10:04:02 CET 2009


Updating branch refs/heads/master
         to 8dd927ddb1802222e4ecca4cc69a781dfc40cc93 (commit)
       from 8a3d5d2a72b309aa8d2e4c5c56848ce4b335e68d (commit)

commit 8dd927ddb1802222e4ecca4cc69a781dfc40cc93
Author: Ali Abdallah <ali at ali-xfce.org>
Date:   Fri Nov 27 09:38:04 2009 +0100

    Better playlist handling on the browser plugin.

 browser-plugin/Makefile.am                         |    6 +-
 .../media-plugin/org.parole.media.plugin.xml       |    3 +
 browser-plugin/media-plugin/parole-plugin-player.c |   16 +++++
 browser-plugin/media-plugin/parole-plugin-player.h |    2 +
 browser-plugin/parole-plugin.c                     |   68 +++++++++++++-------
 configure.ac.in                                    |   12 ----
 parole/parole-pl-parser.c                          |   64 ++++++++++---------
 parole/parole-pl-parser.h                          |   17 +++--
 src/parole-medialist.c                             |    6 +-
 src/parole-utils.c                                 |    4 +-
 10 files changed, 117 insertions(+), 81 deletions(-)

diff --git a/browser-plugin/Makefile.am b/browser-plugin/Makefile.am
index 606b622..e1230ee 100644
--- a/browser-plugin/Makefile.am
+++ b/browser-plugin/Makefile.am
@@ -18,6 +18,8 @@ CXXFLAGS += -Wextra -Wno-missing-field-initializers	\
 	-fstack-protector -O0 -g3 -Werror
 endif
 
+CFLAGS=$(CXXFLAGS)
+
 INCLUDES =                                              \
         -fPIC                                           \
         -I$(top_builddir)                               \
@@ -30,7 +32,7 @@ INCLUDES =                                              \
         $(GTK_CFLAGS)                                   \
         $(DBUS_GLIB_CFLAGS)				\
 	$(TAGLIBC_CFLAGS)				\
-	$(LIBXFCE4UTIL_CFLAGS)
+	$(LIBXFCE4UTIL_CFLAGS)				\
 	$(DEFINES)
 
 install_libexecdir = $(BROWSER_PLUGIN_DIR)
@@ -59,4 +61,4 @@ parole_player_so_LDFLAGS =                              \
         $(DBUS_GLIB_LIBS)				\
 	$(TAGLIBC_LIBS)					\
 	$(LIBXFCE4UTIL_LIBS)				\
-	$(top_builddir)/parole/libparole.la
+	$(top_builddir)/parole/libparole.la 	
diff --git a/browser-plugin/media-plugin/org.parole.media.plugin.xml b/browser-plugin/media-plugin/org.parole.media.plugin.xml
index 264373a..f357516 100644
--- a/browser-plugin/media-plugin/org.parole.media.plugin.xml
+++ b/browser-plugin/media-plugin/org.parole.media.plugin.xml
@@ -18,6 +18,9 @@
 	<arg type="s" name="url" direction="in"/>
     </method>
     
+    <signal name="Finished">
+    </signal>
+    
     <signal name="Ready">
     </signal>
     
diff --git a/browser-plugin/media-plugin/parole-plugin-player.c b/browser-plugin/media-plugin/parole-plugin-player.c
index 481fe24..f51b302 100644
--- a/browser-plugin/media-plugin/parole-plugin-player.c
+++ b/browser-plugin/media-plugin/parole-plugin-player.c
@@ -97,6 +97,7 @@ enum
 
 enum
 {
+    SIG_FINISHED,
     SIG_EXITING,
     SIG_READY,
     LAST_SIGNAL
@@ -306,11 +307,17 @@ parole_plugin_player_media_state_cb (ParoleGst *gst, const ParoleStream *stream,
 	{
 	    parole_plugin_player_play (player);
 	}
+	else if ( player->priv->finished )
+	{
+	    player->priv->finished = FALSE;
+	    g_signal_emit (player, signals [SIG_FINISHED], 0);
+	}
     }
     else if ( state == PAROLE_MEDIA_STATE_FINISHED )
     {
 	parole_plugin_player_change_range_value (player, 0);
 	player->priv->finished = TRUE;
+	parole_gst_stop (PAROLE_GST (player->priv->gst));
     }
 }
 
@@ -695,6 +702,15 @@ parole_plugin_player_class_init (ParolePluginPlayerClass *klass)
 
     object_class->constructed = parole_plugin_player_construct;
     
+    signals[SIG_FINISHED] = 
+        g_signal_new ("finished",
+                      PAROLE_TYPE_PLUGIN_PLAYER,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET (ParolePluginPlayerClass, finished),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__VOID,
+                      G_TYPE_NONE, 0, G_TYPE_NONE);
+    
     signals[SIG_EXITING] = 
         g_signal_new ("exiting",
                       PAROLE_TYPE_PLUGIN_PLAYER,
diff --git a/browser-plugin/media-plugin/parole-plugin-player.h b/browser-plugin/media-plugin/parole-plugin-player.h
index 4ada19e..e7efe7f 100644
--- a/browser-plugin/media-plugin/parole-plugin-player.h
+++ b/browser-plugin/media-plugin/parole-plugin-player.h
@@ -43,6 +43,8 @@ typedef struct
 {
     GObjectClass 			 parent_class;
     
+    void				(*finished)			      (ParolePluginPlayer *player);
+    
     void				(*exiting)			      (ParolePluginPlayer *player);
     
     void				(*ready)			      (ParolePluginPlayer *player);
diff --git a/browser-plugin/parole-plugin.c b/browser-plugin/parole-plugin.c
index 3201ab7..15bb6a2 100644
--- a/browser-plugin/parole-plugin.c
+++ b/browser-plugin/parole-plugin.c
@@ -123,6 +123,27 @@ parole_plugin_ping (gpointer data)
     return TRUE;
 }
 
+static void
+parole_plugin_send_play (ParolePlugin *plugin, const gchar *url)
+{
+    GError *error = NULL;
+    g_return_if_fail (plugin->proxy);
+    
+    g_debug ("Sending play request of stream %s", url);
+    dbus_g_proxy_call (plugin->proxy, "PlayUrl", &error,
+		       G_TYPE_STRING, url,
+		       G_TYPE_INVALID,
+		       G_TYPE_INVALID);
+		       
+    plugin->player_playing = TRUE;
+    
+    if ( error )
+    {
+	g_critical ("Failed to play stream %s : %s", url, error->message);
+	g_error_free (error);
+	plugin->player_playing = FALSE;
+    }
+}
 
 static void
 parole_plugin_player_exiting_cb (DBusGProxy *proxy, ParolePlugin *plugin)
@@ -146,6 +167,23 @@ parole_plugin_player_ready_cb (DBusGProxy *proxy, ParolePlugin *plugin)
 }
 
 static void
+parole_plugin_player_finished_cb (DBusGProxy *proxy, ParolePlugin *plugin)
+{
+    g_debug ("Player finished");
+    if ( plugin->is_playlist )
+    {
+	plugin->list = plugin->list->next;
+	if ( plugin->list->data )
+	{
+	    ParoleFile *file;
+	    file = PAROLE_FILE (plugin->list->data);
+	    parole_plugin_send_play (plugin, parole_file_get_uri (file));
+	}
+    }
+    
+}
+
+static void
 parole_plugin_stop_player (ParolePlugin *plugin)
 {
     g_return_if_fail (plugin->proxy != NULL);
@@ -249,9 +287,13 @@ parole_plugin_get_proxy (ParolePlugin *plugin)
 	g_critical ("Unable to create proxy for %s", dbus_name);
     else
     {
+	dbus_g_proxy_add_signal (plugin->proxy, "Finished", G_TYPE_INVALID);
 	dbus_g_proxy_add_signal (plugin->proxy, "Exiting", G_TYPE_INVALID);
 	dbus_g_proxy_add_signal (plugin->proxy, "Ready", G_TYPE_INVALID);
 	
+	dbus_g_proxy_connect_signal (plugin->proxy, "Finished",
+				     G_CALLBACK (parole_plugin_player_finished_cb), plugin, NULL);
+	
 	dbus_g_proxy_connect_signal (plugin->proxy, "Exiting",
 				     G_CALLBACK (parole_plugin_player_exiting_cb), plugin, NULL);
 				     
@@ -300,28 +342,6 @@ parole_plugin_run_player (ParolePlugin *plugin)
     return NPERR_NO_ERROR;
 }
 
-static void
-parole_plugin_send_play (ParolePlugin *plugin, const gchar *url)
-{
-    GError *error = NULL;
-    g_return_if_fail (plugin->proxy);
-    
-    g_debug ("Sending play request of stream %s", url);
-    dbus_g_proxy_call (plugin->proxy, "PlayUrl", &error,
-		       G_TYPE_STRING, url,
-		       G_TYPE_INVALID,
-		       G_TYPE_INVALID);
-		       
-    plugin->player_playing = TRUE;
-    
-    if ( error )
-    {
-	g_critical ("Failed to play stream %s : %s", url, error->message);
-	g_error_free (error);
-	plugin->player_playing = FALSE;
-    }
-}
-
 ParolePlugin *
 parole_plugin_new (NPP Instance)
 {
@@ -440,7 +460,9 @@ int32 parole_plugin_write (ParolePlugin *plugin,
 	{
 	    fseek (plugin->cache, offset, SEEK_SET);
 	    wrotebytes += fwrite (buffer, 1, len, plugin->cache);
+#ifdef DEBUG
 	    g_debug ("Wrotebytes=%d offset=%d data=%s", wrotebytes, offset, (gchar*)buffer);
+#endif
 	}
 	
 	if ( wrotebytes >= 0 )
@@ -448,7 +470,7 @@ int32 parole_plugin_write (ParolePlugin *plugin,
 	    ParoleFile *file;
 	    fclose (plugin->cache);
 	    plugin->cache = NULL;
-	    plugin->list = parole_pl_parser_load_file (plugin->tmp_file);
+	    plugin->list = parole_pl_parser_parse_from_file_by_extension (plugin->tmp_file);
 	    
 	    if (plugin->list != NULL && g_slist_length (plugin->list) != 0 && plugin->player_playing == FALSE )
 	    {
diff --git a/configure.ac.in b/configure.ac.in
index 6a1f2c5..94a6319 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -219,18 +219,6 @@ XDT_FEATURE_DEBUG()
 AM_CONDITIONAL([DEBUG_BROWSER_PLUGIN], [test x"$enable_debug" = x"full"])
 
 #=======================================================#
-#              Developement debugging                   #
-#=======================================================#
-AC_ARG_ENABLE([parole-debug], AC_HELP_STRING([--enable-parole-debug], [Maintainer debug mode]),
-  [ac_parole_debug=$enableval], [ac_parole_debug=no])
-AC_MSG_CHECKING([Maintainer debug mode])
-AM_CONDITIONAL([PAROLE_DEBUG], [test x"$ac_parole_debug" = x"yes"])
-AC_MSG_RESULT([$ac_parole_debug])
-if test x"$ac_parole_debug" = x"yes"; then
-    AC_DEFINE(PAROLE_ENABLE_DEBUG, 1, [wheter to enable maintainer debug mode])
-fi
-
-#=======================================================#
 #              Check for Gtk doc	                #
 #=======================================================#
 GTK_DOC_CHECK(1.9)
diff --git a/parole/parole-pl-parser.c b/parole/parole-pl-parser.c
index 5e7db07..9f61081 100644
--- a/parole/parole-pl-parser.c
+++ b/parole/parole-pl-parser.c
@@ -255,9 +255,7 @@ static ParolePlFormat
 parole_pl_parser_guess_format_from_data (const gchar *filename)
 {
     GFile *file;
-    gchar *mime_type = NULL;
-    gchar *contents;
-    gboolean result_uncertain;
+    gchar *contents = NULL;
     gsize size;
     
     ParolePlFormat format = PAROLE_PL_FORMAT_UNKNOWN;
@@ -270,21 +268,18 @@ parole_pl_parser_guess_format_from_data (const gchar *filename)
 	goto out;
     }
 
-    mime_type = g_content_type_guess (NULL, (const guchar*)contents, size,  &result_uncertain);
-    
-    
-    if ( mime_type && result_uncertain == FALSE )
-    {
-	g_debug ("mime_type %s", mime_type);
-	format = PAROLE_PL_FORMAT_PLAYLIST;
-    }
-    
+    if ( strstr (contents, "<ASX VERSION") )
+	format = PAROLE_PL_FORMAT_ASX;
+    else if ( strstr (contents, "<trackList>") || strstr (contents, "<tracklist>") )
+	format = PAROLE_PL_FORMAT_XSPF;
+    else if ( strstr (contents, "NumberOfEntries") )
+	format = PAROLE_PL_FORMAT_PLS;
+    else 
+	/* try to load the file as M3U*/
+	format = PAROLE_PL_FORMAT_M3U;
+
     g_free (contents);
-    
 out:
-    if ( mime_type )
-	g_free (mime_type);
-    
     g_object_unref (file);
     return format;
 }
@@ -566,27 +561,34 @@ gboolean parole_pl_parser_can_parse_data (const guchar *data, gint len)
     return result;
 }
 
-GSList *parole_pl_parser_load_file (const gchar *filename)
+GSList *parole_pl_parser_parse_from_file_by_extension (const gchar *filename)
 {
     ParolePlFormat format = PAROLE_PL_FORMAT_UNKNOWN;
-    GtkFileFilter *filter;
     GSList *list = NULL;
     
-    filter = parole_get_supported_playlist_filter ();
-    g_object_ref_sink (filter);
-    
-    if ( (format = parole_pl_parser_guess_format_from_extension (filename)) != PAROLE_PL_FORMAT_UNKNOWN)
-    {
-	PAROLE_DEBUG_ENUM_FULL (format, PAROLE_ENUM_TYPE_PL_FORMAT, "playlist %s ", filename);
-	list = parole_pl_parser_parse (format, filename);
-    }
-    else if ( (format = parole_pl_parser_guess_format_from_data (filename)) != PAROLE_PL_FORMAT_UNKNOWN)
+    if ( (format = parole_pl_parser_guess_format_from_extension (filename)) == PAROLE_PL_FORMAT_UNKNOWN &&
+	 (format = parole_pl_parser_guess_format_from_data (filename)) == PAROLE_PL_FORMAT_UNKNOWN ) 
     {
-	list = parole_pl_parser_parse_m3u (filename);
-	//list = g_list_concat (list, parole_pl_parser_p
+	g_debug ("Unable to guess playlist format : %s", filename);
+	goto out;
     }
 	
-    g_object_unref (filter);
+    PAROLE_DEBUG_ENUM_FULL (format, PAROLE_ENUM_TYPE_PL_FORMAT, "playlist %s ", filename);
+    list = parole_pl_parser_parse (format, filename);
+	
+out:
+    return list;
+}
+
+GSList *parole_pl_parser_parse_all_from_file (const gchar *filename)
+{
+    GSList *list = NULL;
+    
+    list = parole_pl_parser_parse_asx (filename);
+    list = g_slist_concat (list, parole_pl_parser_parse_m3u (filename));
+    list = g_slist_concat (list, parole_pl_parser_parse_pls (filename));
+    list = g_slist_concat (list, parole_pl_parser_parse_xspf (filename));
+    
     return list;
 }
 
@@ -685,7 +687,7 @@ parole_pl_parser_save_xspf (FILE *f, GSList *files)
     return TRUE;
 }
 
-gboolean parole_pl_parser_save_file (GSList *files, const gchar *filename, ParolePlFormat format)
+gboolean parole_pl_parser_save_from_files (GSList *files, const gchar *filename, ParolePlFormat format)
 {
     FILE *f;
     gboolean ret_val;
diff --git a/parole/parole-pl-parser.h b/parole/parole-pl-parser.h
index 5c8dd20..9cb4fd0 100644
--- a/parole/parole-pl-parser.h
+++ b/parole/parole-pl-parser.h
@@ -35,20 +35,21 @@ typedef enum
     PAROLE_PL_FORMAT_M3U,
     PAROLE_PL_FORMAT_PLS,
     PAROLE_PL_FORMAT_ASX,
-    PAROLE_PL_FORMAT_XSPF,
-    PAROLE_PL_FORMAT_PLAYLIST
+    PAROLE_PL_FORMAT_XSPF
     
 } ParolePlFormat;
 
-ParolePlFormat		 parole_pl_parser_guess_format_from_extension   (const gchar *filename);
+ParolePlFormat		 parole_pl_parser_guess_format_from_extension   	(const gchar *filename);
 
-gboolean		 parole_pl_parser_can_parse_data		(const guchar *data, gint len);
+gboolean		 parole_pl_parser_can_parse_data			(const guchar *data, gint len);
 
-GSList 			*parole_pl_parser_load_file		        (const gchar *filename);
+GSList 			*parole_pl_parser_parse_from_file_by_extension     	(const gchar *filename);
 
-gboolean		 parole_pl_parser_save_file		        (GSList *files,
-								         const gchar *filename,
-									 ParolePlFormat format);
+GSList                   *parole_pl_parser_parse_all_from_file			(const gchar *filename);
+
+gboolean		 parole_pl_parser_save_from_files	        	(GSList *files,
+										 const gchar *filename,
+										 ParolePlFormat format);
 
 G_END_DECLS
 
diff --git a/src/parole-medialist.c b/src/parole-medialist.c
index 90bba79..14d1b06 100644
--- a/src/parole-medialist.c
+++ b/src/parole-medialist.c
@@ -448,7 +448,7 @@ void parole_media_list_save_playlist_cb (GtkButton *button, ParolePlaylistSave *
     
     parole_media_list_close_save_dialog_cb (NULL, data);
     
-    parole_pl_parser_save_file (list, filename, format);
+    parole_pl_parser_save_from_files (list, filename, format);
     g_slist_free (list);
 out:
     g_free (filename);
@@ -1083,7 +1083,7 @@ void parole_media_list_load (ParoleMediaList *list)
 						     FALSE);
 	if ( playlist_file )
 	{
-	    fileslist = parole_pl_parser_load_file (playlist_file);
+	    fileslist = parole_pl_parser_parse_from_file_by_extension (playlist_file);
 	    g_free (playlist_file);
 	    
 	    parole_media_list_files_opened_cb (NULL, FALSE, fileslist, list);
@@ -1320,7 +1320,7 @@ void parole_media_list_save_list (ParoleMediaList *list)
 	fileslist = parole_media_list_get_files (list);
 	if ( g_slist_length (fileslist) > 0 )
 	{
-	    parole_pl_parser_save_file (fileslist, history, PAROLE_PL_FORMAT_M3U);
+	    parole_pl_parser_save_from_files (fileslist, history, PAROLE_PL_FORMAT_M3U);
 	    g_slist_foreach (fileslist, (GFunc) g_object_unref, NULL);
 	}
 	g_slist_free (fileslist);
diff --git a/src/parole-utils.c b/src/parole-utils.c
index 112eb65..826b2a3 100644
--- a/src/parole-utils.c
+++ b/src/parole-utils.c
@@ -357,7 +357,7 @@ void parole_get_media_files (GtkFileFilter *filter, const gchar *path,
 	if ( parole_file_filter (playlist_filter, file) && 
 	     parole_pl_parser_guess_format_from_extension (path) != PAROLE_PL_FORMAT_UNKNOWN )
 	{
-	    playlist = parole_pl_parser_load_file (path);
+	    playlist = parole_pl_parser_parse_from_file_by_extension (path);
 	    g_object_unref (file);
 	    if ( playlist)
 	    {
@@ -391,7 +391,7 @@ void parole_get_media_files (GtkFileFilter *filter, const gchar *path,
 		if ( parole_file_filter (playlist_filter, file) &&
 		     parole_pl_parser_guess_format_from_extension (path) != PAROLE_PL_FORMAT_UNKNOWN)
 		{
-		    playlist = parole_pl_parser_load_file (path_internal);
+		    playlist = parole_pl_parser_parse_from_file_by_extension (path_internal);
 		    g_object_unref (file);
 		    if ( playlist)
 		    {



More information about the Xfce4-commits mailing list