summaryrefslogtreecommitdiff
path: root/src/audtool/handlers_playqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/audtool/handlers_playqueue.c')
-rw-r--r--src/audtool/handlers_playqueue.c147
1 files changed, 55 insertions, 92 deletions
diff --git a/src/audtool/handlers_playqueue.c b/src/audtool/handlers_playqueue.c
index 275404e..dd5e509 100644
--- a/src/audtool/handlers_playqueue.c
+++ b/src/audtool/handlers_playqueue.c
@@ -1,7 +1,7 @@
/*
* handlers_playqueue.c
- * Copyright 2005-2008 George Averill, William Pitcock, Yoshiki Yazawa, and
- * Matti Hämäläinen
+ * Copyright 2005-2013 George Averill, William Pitcock, Yoshiki Yazawa,
+ * Matti Hämäläinen, and John Lindgren
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -19,122 +19,85 @@
*/
#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-#include <locale.h>
-#include "libaudclient/audctrl.h"
+
#include "audtool.h"
+#include "wrappers.h"
-void playqueue_add(gint argc, gchar **argv)
+void playqueue_add (int argc, char * * argv)
{
- gint i = check_args_playlist_pos(argc, argv);
-
- if (!(audacious_remote_playqueue_is_queued(dbus_proxy, i - 1)))
- audacious_remote_playqueue_add(dbus_proxy, i - 1);
+ int pos = check_args_playlist_pos (argc, argv);
+ obj_audacious_call_playqueue_add_sync (dbus_proxy, pos - 1, NULL, NULL);
}
-void playqueue_remove(gint argc, gchar **argv)
+void playqueue_remove (int argc, char * * argv)
{
- gint i = check_args_playlist_pos(argc, argv);
+ int pos = check_args_playlist_pos (argc, argv);
+ obj_audacious_call_playqueue_remove_sync (dbus_proxy, pos - 1, NULL, NULL);
+}
- if (audacious_remote_playqueue_is_queued(dbus_proxy, i - 1))
- audacious_remote_playqueue_remove(dbus_proxy, i - 1);
+void playqueue_is_queued (int argc, char * * argv)
+{
+ int pos = check_args_playlist_pos (argc, argv);
+ find_in_queue (pos - 1); /* exits if not found */
+ audtool_report ("OK");
}
-void playqueue_is_queued(gint argc, gchar **argv)
+void playqueue_get_queue_position (int argc, char * * argv)
{
- gint i = check_args_playlist_pos(argc, argv);
+ int pos = check_args_playlist_pos (argc, argv);
+ audtool_report ("%d", find_in_queue (pos - 1) + 1);
+}
- if (audacious_remote_playqueue_is_queued(dbus_proxy, i - 1)) {
- audtool_report("OK");
- exit(0);
- }
- else
- exit(1);
+void playqueue_get_list_position (int argc, char * * argv)
+{
+ int qpos = check_args_playlist_pos (argc, argv);
+ audtool_report ("%d", get_queue_entry (qpos - 1) + 1);
}
-void playqueue_get_queue_position(gint argc, gchar **argv)
+void playqueue_display (int argc, char * * argv)
{
- gint pos, i = check_args_playlist_pos(argc, argv);
+ int qlength = get_queue_length ();
- pos = audacious_remote_get_playqueue_queue_position(dbus_proxy, i - 1) + 1;
+ audtool_report ("%d queued tracks.", qlength);
- if (pos < 1)
- return;
+ int total = 0;
- audtool_report("%d", pos);
-}
+ for (int qpos = 0; qpos < qlength; qpos ++)
+ {
+ int pos = get_queue_entry (qpos);
+ char * title = get_entry_title (pos);
+ int length = get_entry_length (pos) / 1000;
-void playqueue_get_list_position(gint argc, gchar **argv)
-{
- gint pos, i = check_args_playlist_pos(argc, argv);
+ total += length;
- pos = audacious_remote_get_playqueue_list_position(dbus_proxy, i - 1) + 1;
+ /* adjust width for multi byte characters */
+ int column = 60;
- if (pos < 1)
- return;
+ for (const char * p = title; * p; p = g_utf8_next_char (p))
+ {
+ int stride = g_utf8_next_char (p) - p;
- audtool_report("%d", pos);
-}
+ if (g_unichar_iswide (g_utf8_get_char (p)) ||
+ g_unichar_iswide_cjk (g_utf8_get_char (p)))
+ column += (stride - 2);
+ else
+ column += (stride - 1);
+ }
-void playqueue_display(gint argc, gchar **argv)
-{
- gint i, ii, position, frames, length, total;
- gchar *songname;
- gchar *fmt = NULL, *p;
- gint column;
-
- i = audacious_remote_get_playqueue_length(dbus_proxy);
-
- audtool_report("%d queued tracks.", i);
-
- total = 0;
-
- for (ii = 0; ii < i; ii++)
- {
- position = audacious_remote_get_playqueue_list_position(dbus_proxy, ii);
- songname = audacious_remote_get_playlist_title(dbus_proxy, position);
- frames = audacious_remote_get_playlist_time(dbus_proxy, position);
- length = frames / 1000;
- total += length;
-
- /* adjust width for multi byte characters */
- column = 60;
- if(songname) {
- p = songname;
- while(*p){
- gint stride;
- stride = g_utf8_next_char(p) - p;
- if(g_unichar_iswide(g_utf8_get_char(p))
- || g_unichar_iswide_cjk(g_utf8_get_char(p))
- ){
- column += (stride - 2);
- }
- else {
- column += (stride - 1);
- }
- p = g_utf8_next_char(p);
- }
- }
-
- fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d", column);
- audtool_report(fmt, ii + 1, position + 1, songname, length / 60, length % 60);
- g_free(fmt);
- }
-
- audtool_report("Total length: %d:%.2d", total / 60, total % 60);
+ char * fmt = g_strdup_printf ("%%4d | %%4d | %%-%ds | %%d:%%.2d", column);
+ audtool_report (fmt, qpos + 1, pos + 1, title, length / 60, length % 60);
+ g_free (fmt);
+ }
+
+ audtool_report ("Total length: %d:%.2d", total / 60, total % 60);
}
-void playqueue_length(gint argc, gchar **argv)
+void playqueue_length (int argc, char * * argv)
{
- gint i;
-
- i = audacious_remote_get_playqueue_length(dbus_proxy);
-
- audtool_report("%d", i);
+ audtool_report ("%d", get_queue_length ());
}
-void playqueue_clear(gint argc, gchar **argv)
+void playqueue_clear (int argc, char * * argv)
{
- audacious_remote_playqueue_clear(dbus_proxy);
+ obj_audacious_call_playqueue_clear_sync (dbus_proxy, NULL, NULL);
}