changeset 2579:364714f2d555 trunk

[svn] - urldecode playlist paths
author nenolod
date Mon, 26 Feb 2007 01:14:48 -0800
parents 33911de063cb
children 48288757d7c7
files ChangeLog src/audacious/build_stamp.c src/audacious/playlist.c src/audacious/vfs.c
diffstat 4 files changed, 100 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Feb 25 22:41:59 2007 -0800
+++ b/ChangeLog	Mon Feb 26 01:14:48 2007 -0800
@@ -1,3 +1,11 @@
+2007-02-26 06:41:59 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [4166]
+  - change the order that hints are processed in.
+  
+  trunk/src/audacious/widgets/skin.c |  137 ++++++++++++++++++-------------------
+  1 file changed, 67 insertions(+), 70 deletions(-)
+
+
 2007-02-26 06:03:15 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [4164]
   - avoid an exception
--- a/src/audacious/build_stamp.c	Sun Feb 25 22:41:59 2007 -0800
+++ b/src/audacious/build_stamp.c	Mon Feb 26 01:14:48 2007 -0800
@@ -1,2 +1,2 @@
 #include <glib.h>
-const gchar *svn_stamp = "20070226-4164";
+const gchar *svn_stamp = "20070226-4166";
--- a/src/audacious/playlist.c	Sun Feb 25 22:41:59 2007 -0800
+++ b/src/audacious/playlist.c	Mon Feb 26 01:14:48 2007 -0800
@@ -879,6 +879,49 @@
     return playlist_ins_url(playlist, url, -1);
 }
 
+static gchar *
+_playlist_urldecode_basic_path(const gchar * encoded_path)
+{
+    const gchar *cur, *ext;
+    gchar *path, *tmp;
+    gint realchar;
+
+    if (!encoded_path)
+        return NULL;
+
+    if (!str_has_prefix_nocase(encoded_path, "file:"))
+        return NULL;
+
+    cur = encoded_path + 5;
+
+    if (str_has_prefix_nocase(cur, "//localhost"))
+        cur += 11;
+
+    if (*cur == '/')
+        while (cur[1] == '/')
+            cur++;
+
+    tmp = g_malloc0(strlen(cur) + 1);
+
+    while ((ext = strchr(cur, '%')) != NULL) {
+        strncat(tmp, cur, ext - cur);
+        ext++;
+        cur = ext + 2;
+        if (!sscanf(ext, "%2x", &realchar)) {
+            /* Assume it is a literal '%'.  Several file
+             * managers send unencoded file: urls on drag
+             * and drop. */
+            realchar = '%';
+            cur -= 2;
+        }
+        tmp[strlen(tmp)] = realchar;
+    }
+
+    path = g_strconcat(tmp, cur, NULL);
+    g_free(tmp);
+    return path;
+}
+
 guint
 playlist_ins_dir(Playlist * playlist, const gchar * path,
                     gint pos,
@@ -887,10 +930,11 @@
     guint entries = 0;
     GList *list, *node;
     GHashTable *htab;
+    gchar *path2 = _playlist_urldecode_basic_path(path);
 
     htab = g_hash_table_new(devino_hash, devino_compare);
 
-    list = playlist_dir_find_files(path, background, htab);
+    list = playlist_dir_find_files(path2, background, htab);
     list = g_list_sort(list, (GCompareFunc) path_compare);
 
     g_hash_table_foreach_remove(htab, devino_destroy, NULL);
@@ -904,6 +948,7 @@
     }
 
     g_list_free(list);
+    g_free(path2);
 
     playlist_recalc_total_time(playlist);
     playlist_generate_shuffle_list(playlist);
--- a/src/audacious/vfs.c	Sun Feb 25 22:41:59 2007 -0800
+++ b/src/audacious/vfs.c	Mon Feb 26 01:14:48 2007 -0800
@@ -16,6 +16,7 @@
  */
 
 #include "vfs.h"
+#include "strings.h"
 #include <stdio.h>
 
 #include <unistd.h>
@@ -322,6 +323,49 @@
     return NULL;
 }
 
+static gchar *
+_vfs_urldecode_basic_path(const gchar * encoded_path)
+{
+    const gchar *cur, *ext;
+    gchar *path, *tmp;
+    gint realchar;
+
+    if (!encoded_path)
+        return NULL;
+
+    if (!str_has_prefix_nocase(encoded_path, "file:"))
+        return NULL;
+
+    cur = encoded_path + 5;
+
+    if (str_has_prefix_nocase(cur, "//localhost"))
+        cur += 11;
+
+    if (*cur == '/')
+        while (cur[1] == '/')
+            cur++;
+
+    tmp = g_malloc0(strlen(cur) + 1);
+
+    while ((ext = strchr(cur, '%')) != NULL) {
+        strncat(tmp, cur, ext - cur);
+        ext++;
+        cur = ext + 2;
+        if (!sscanf(ext, "%2x", &realchar)) {
+            /* Assume it is a literal '%'.  Several file
+             * managers send unencoded file: urls on drag
+             * and drop. */
+            realchar = '%';
+            cur -= 2;
+        }
+        tmp[strlen(tmp)] = realchar;
+    }
+
+    path = g_strconcat(tmp, cur, NULL);
+    g_free(tmp);
+    return path;
+}
+
 /**
  * vfs_file_test:
  * @path: A path to test.
@@ -337,10 +381,7 @@
     gchar *path2;
     gboolean ret;
 
-    if (strlen(path) > 5)
-        path2 = xmms_urldecode_plain(path + 5); /* skip file: */
-    else
-        path2 = g_strdup(path);
+    path2 = _vfs_urldecode_basic_path(path);
 
     ret = g_file_test(path2, test);