diff src/audtool/audtool_handlers_playlist.c @ 4074:ea194fd79267

audtool maintenance: - now playlist-addurl and relatives accept raw file name or path. - moved handlers in the test suite section to the respective sections. - tweaked help message. - modified a few less important handler names.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Fri, 07 Dec 2007 23:27:20 +0900
parents b5ee3a4a8e3b
children 0a2255b9e80b
line wrap: on
line diff
--- a/src/audtool/audtool_handlers_playlist.c	Fri Dec 07 21:40:49 2007 +0900
+++ b/src/audtool/audtool_handlers_playlist.c	Fri Dec 07 23:27:20 2007 +0900
@@ -47,8 +47,38 @@
 	audacious_remote_playlist_next(dbus_proxy);
 }
 
+static gchar *
+construct_uri(gchar *string)
+{
+    gchar *filename = g_strdup(string);
+    gchar *tmp, *path;
+    gchar *uri = NULL;
+
+    // case 1: filename is raw full path or uri
+    if (filename[0] == '/' || strstr(filename, "://")) {
+        uri = g_filename_to_uri(filename, NULL, NULL);
+        if(!uri) {
+            uri = g_strdup(filename);
+        }
+        g_free(filename);
+    }
+    // case 2: filename is not raw full path nor uri.
+    // make full path with pwd. (using g_build_filename)
+    else {
+        path = g_get_current_dir();
+        tmp = g_build_filename(path, filename, NULL);
+        g_free(path); g_free(filename);
+        uri = g_filename_to_uri(tmp, NULL, NULL);
+        g_free(tmp);
+    }
+
+    return uri;
+}
+
 void playlist_add_url_string(gint argc, gchar **argv)
 {
+    gchar *uri;
+
 	if (argc < 2)
 	{
 		audtool_whine("invalid parameters for %s.", argv[0]);
@@ -56,7 +86,11 @@
 		exit(1);
 	}
 
-	audacious_remote_playlist_add_url_string(dbus_proxy, argv[1]);
+    uri = construct_uri(argv[1]);
+    if (uri) {
+        audacious_remote_playlist_add_url_string(dbus_proxy, uri);
+    }
+    g_free(uri);
 }
 
 void playlist_delete(gint argc, gchar **argv)
@@ -370,3 +404,43 @@
 
 	g_free(data);
 }
+
+void playlist_ins_url_string(gint argc, gchar **argv)
+{
+    gint pos = -1;
+    gchar *uri;
+
+    if (argc < 3)
+    {
+        audtool_whine("invalid parameters for %s.", argv[0]);
+        audtool_whine("syntax: %s <url> <position>", argv[0]);
+        exit(1);
+    }
+
+    pos = atoi(argv[2]) - 1;
+    if(pos >= 0) {
+        uri = construct_uri(argv[1]);
+        if (uri) {
+            audacious_remote_playlist_ins_url_string(dbus_proxy, uri, pos);
+        }
+        g_free(uri);
+    }
+}
+
+void playlist_enqueue_to_temp(gint argc, gchar **argv)
+{
+    gchar *uri;
+
+    if (argc < 2)
+    {
+        audtool_whine("invalid parameters for %s.", argv[0]);
+        audtool_whine("syntax: %s <url>", argv[0]);
+        exit(1);
+    }
+
+    uri = construct_uri(argv[1]);
+    if (uri) {
+        audacious_remote_playlist_enqueue_to_temp(dbus_proxy, uri);
+    }
+    g_free(uri);
+}