[Xfce4-commits] <parole:master> Handle m3u files which do not use absolute filenames (Bug 10038)

Sean Davis noreply at xfce.org
Tue Apr 30 11:36:01 CEST 2013


Updating branch refs/heads/master
         to f5c42c8707e552ba3e27fd1ab2caba1338f2c9cd (commit)
       from 980b0e2196837e1f5797977e9c4baa5069dd0681 (commit)

commit f5c42c8707e552ba3e27fd1ab2caba1338f2c9cd
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Tue Apr 30 05:35:19 2013 -0400

    Handle m3u files which do not use absolute filenames (Bug 10038)

 src/misc/parole-pl-parser.c |   49 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/src/misc/parole-pl-parser.c b/src/misc/parole-pl-parser.c
index b35eadf..70dde3a 100644
--- a/src/misc/parole-pl-parser.c
+++ b/src/misc/parole-pl-parser.c
@@ -56,6 +56,10 @@ typedef struct
     
 } ParoleParserData;
 
+gchar *g_substr (const gchar* string, gint start, gint end);
+
+gchar *g_char_dirname (const gchar *filename);
+
 static gchar*
 parole_filename_to_utf8(const gchar* filename)
 {
@@ -306,12 +310,44 @@ out:
     return data.list;
 }
 
+gchar *
+g_substr (const gchar* string,
+          gint         start,
+          gint         end)
+{
+    gsize len = (end - start + 1);
+    gchar *output = g_malloc0 (len + 1);
+    return g_utf8_strncpy (output, &string[start], len);
+}
+
+gchar *
+g_char_dirname (const gchar *filename)
+{
+    int index;
+    const gchar *ptr;
+    char *find;
+    gchar *f_name;
+    
+    f_name = g_strdup(filename);
+
+    find = "/";
+    ptr = strrchr((char *) f_name, find[0]);
+    
+    if (ptr)
+    {
+        index = ptr - f_name;
+        return g_substr(filename, 0, index);
+    }
+    return NULL;
+}
+
 static GSList *
 parole_pl_parser_parse_m3u (const gchar *filename)
 {
     GFile *file;
     gchar **lines;
     gchar *contents;
+    gchar *path, *pl_filename;
     GSList *list = NULL;
     gsize size;
     guint num_lines;
@@ -319,6 +355,7 @@ parole_pl_parser_parse_m3u (const gchar *filename)
     guint i;
     
     file = g_file_new_for_path (filename);
+    path = g_char_dirname(filename);
     
     if ( !g_file_load_contents (file, NULL, &contents, &size, NULL, NULL) )
 	goto out;
@@ -353,10 +390,20 @@ parole_pl_parser_parse_m3u (const gchar *filename)
     {
 	if ( lines[i][0] == '\0' || lines[i][0] == '#')
 	    continue;
+	    
+    if ( lines[i][0] != '/' )
+    {
+        pl_filename = g_strjoin("", path, lines[i], NULL);
+        list = g_slist_append (list, parole_file_new (pl_filename));
+    }
 
-	list = g_slist_append (list, parole_file_new (lines[i]));
+    else {
+	    list = g_slist_append (list, parole_file_new (lines[i]));
+	}
     }
 
+    if (pl_filename)
+        g_free(pl_filename);
     g_strfreev (lines);
 out:
 


More information about the Xfce4-commits mailing list