comparison 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
comparison
equal deleted inserted replaced
4073:22a86d4671b5 4074:ea194fd79267
45 void playlist_advance(gint argc, gchar **argv) 45 void playlist_advance(gint argc, gchar **argv)
46 { 46 {
47 audacious_remote_playlist_next(dbus_proxy); 47 audacious_remote_playlist_next(dbus_proxy);
48 } 48 }
49 49
50 static gchar *
51 construct_uri(gchar *string)
52 {
53 gchar *filename = g_strdup(string);
54 gchar *tmp, *path;
55 gchar *uri = NULL;
56
57 // case 1: filename is raw full path or uri
58 if (filename[0] == '/' || strstr(filename, "://")) {
59 uri = g_filename_to_uri(filename, NULL, NULL);
60 if(!uri) {
61 uri = g_strdup(filename);
62 }
63 g_free(filename);
64 }
65 // case 2: filename is not raw full path nor uri.
66 // make full path with pwd. (using g_build_filename)
67 else {
68 path = g_get_current_dir();
69 tmp = g_build_filename(path, filename, NULL);
70 g_free(path); g_free(filename);
71 uri = g_filename_to_uri(tmp, NULL, NULL);
72 g_free(tmp);
73 }
74
75 return uri;
76 }
77
50 void playlist_add_url_string(gint argc, gchar **argv) 78 void playlist_add_url_string(gint argc, gchar **argv)
51 { 79 {
80 gchar *uri;
81
52 if (argc < 2) 82 if (argc < 2)
53 { 83 {
54 audtool_whine("invalid parameters for %s.", argv[0]); 84 audtool_whine("invalid parameters for %s.", argv[0]);
55 audtool_whine("syntax: %s <url>", argv[0]); 85 audtool_whine("syntax: %s <url>", argv[0]);
56 exit(1); 86 exit(1);
57 } 87 }
58 88
59 audacious_remote_playlist_add_url_string(dbus_proxy, argv[1]); 89 uri = construct_uri(argv[1]);
90 if (uri) {
91 audacious_remote_playlist_add_url_string(dbus_proxy, uri);
92 }
93 g_free(uri);
60 } 94 }
61 95
62 void playlist_delete(gint argc, gchar **argv) 96 void playlist_delete(gint argc, gchar **argv)
63 { 97 {
64 gint playpos; 98 gint playpos;
368 402
369 audtool_report("%s", data); 403 audtool_report("%s", data);
370 404
371 g_free(data); 405 g_free(data);
372 } 406 }
407
408 void playlist_ins_url_string(gint argc, gchar **argv)
409 {
410 gint pos = -1;
411 gchar *uri;
412
413 if (argc < 3)
414 {
415 audtool_whine("invalid parameters for %s.", argv[0]);
416 audtool_whine("syntax: %s <url> <position>", argv[0]);
417 exit(1);
418 }
419
420 pos = atoi(argv[2]) - 1;
421 if(pos >= 0) {
422 uri = construct_uri(argv[1]);
423 if (uri) {
424 audacious_remote_playlist_ins_url_string(dbus_proxy, uri, pos);
425 }
426 g_free(uri);
427 }
428 }
429
430 void playlist_enqueue_to_temp(gint argc, gchar **argv)
431 {
432 gchar *uri;
433
434 if (argc < 2)
435 {
436 audtool_whine("invalid parameters for %s.", argv[0]);
437 audtool_whine("syntax: %s <url>", argv[0]);
438 exit(1);
439 }
440
441 uri = construct_uri(argv[1]);
442 if (uri) {
443 audacious_remote_playlist_enqueue_to_temp(dbus_proxy, uri);
444 }
445 g_free(uri);
446 }