1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* handlers_playqueue.c
* 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:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions, and the following disclaimer in the documentation
* provided with the distribution.
*
* This software is provided "as is" and without any warranty, express or
* implied. In no event shall the authors be liable for any damages arising from
* the use of this software.
*/
#include <stdlib.h>
#include "audtool.h"
#include "wrappers.h"
void playqueue_add (int argc, char * * argv)
{
int pos = check_args_playlist_pos (argc, argv);
obj_audacious_call_playqueue_add_sync (dbus_proxy, pos - 1, NULL, NULL);
}
void playqueue_remove (int argc, char * * argv)
{
int pos = check_args_playlist_pos (argc, argv);
obj_audacious_call_playqueue_remove_sync (dbus_proxy, pos - 1, NULL, NULL);
}
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_get_queue_position (int argc, char * * argv)
{
int pos = check_args_playlist_pos (argc, argv);
audtool_report ("%d", find_in_queue (pos - 1) + 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_display (int argc, char * * argv)
{
int qlength = get_queue_length ();
audtool_report ("%d queued tracks.", qlength);
int total = 0;
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;
total += length;
/* adjust width for multi byte characters */
int column = 60;
for (const char * p = title; * p; p = g_utf8_next_char (p))
{
int 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);
}
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 (int argc, char * * argv)
{
audtool_report ("%d", get_queue_length ());
}
void playqueue_clear (int argc, char * * argv)
{
obj_audacious_call_playqueue_clear_sync (dbus_proxy, NULL, NULL);
}
|