comparison src/audtool/audtool_handlers_playqueue.c @ 2929:b0ca7bddaec9 trunk

Split out playqueue functions.
author William Pitcock <nenolod@atheme.org>
date Fri, 29 Jun 2007 08:17:02 -0500
parents
children 7be518cc8e60
comparison
equal deleted inserted replaced
2928:ede9a8b8deff 2929:b0ca7bddaec9
1 /*
2 * Audtool2
3 * Copyright (c) 2007 Audacious development team
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <stdlib.h>
33 #include <string.h>
34 #include <glib.h>
35 #include <mowgli.h>
36 #include <locale.h>
37 #include "libaudclient/audctrl.h"
38 #include "audtool.h"
39
40 void playqueue_add(gint argc, gchar **argv)
41 {
42 gint i;
43
44 if (argc < 2)
45 {
46 g_print("%s: invalid parameters for playqueue-add.\n", argv[0]);
47 g_print("%s: syntax: %s playqueue-add <position>\n", argv[0], argv[0]);
48 return;
49 }
50
51 i = atoi(argv[1]);
52
53 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
54 {
55 g_print("%s: invalid playlist position %d\n", argv[0], i);
56 return;
57 }
58
59 if (!(audacious_remote_playqueue_is_queued(dbus_proxy, i - 1)))
60 audacious_remote_playqueue_add(dbus_proxy, i - 1);
61 }
62
63 void playqueue_remove(gint argc, gchar **argv)
64 {
65 gint i;
66
67 if (argc < 2)
68 {
69 g_print("%s: invalid parameters for playqueue-remove.\n", argv[0]);
70 g_print("%s: syntax: %s playqueue-remove <position>\n", argv[0], argv[0]);
71 return;
72 }
73
74 i = atoi(argv[1]);
75
76 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
77 {
78 g_print("%s: invalid playlist position %d\n", argv[0], i);
79 return;
80 }
81
82 if (audacious_remote_playqueue_is_queued(dbus_proxy, i - 1))
83 audacious_remote_playqueue_remove(dbus_proxy, i - 1);
84 }
85
86 void playqueue_is_queued(gint argc, gchar **argv)
87 {
88 gint i;
89
90 if (argc < 2)
91 {
92 g_print("%s: invalid parameters for playqueue-is-queued.\n", argv[0]);
93 g_print("%s: syntax: %s playqueue-is-queued <position>\n", argv[0], argv[0]);
94 return;
95 }
96
97 i = atoi(argv[1]);
98
99 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
100 {
101 g_print("%s: invalid playlist position %d\n", argv[0], i);
102 return;
103 }
104
105 exit(!(audacious_remote_playqueue_is_queued(dbus_proxy, i - 1)));
106 }
107
108 void playqueue_get_position(gint argc, gchar **argv)
109 {
110 gint i, pos;
111
112 if (argc < 2)
113 {
114 g_print("%s: invalid parameters for playqueue-get-position.\n", argv[0]);
115 g_print("%s: syntax: %s playqueue-get-position <position>\n", argv[0], argv[0]);
116 return;
117 }
118
119 i = atoi(argv[1]);
120
121 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
122 {
123 g_print("%s: invalid playlist position %d\n", argv[0], i);
124 return;
125 }
126
127 pos = audacious_remote_get_playqueue_position(dbus_proxy, i - 1) + 1;
128
129 if (pos < 1)
130 return;
131
132 g_print("%d\n", pos);
133 }
134
135 void playqueue_get_qposition(gint argc, gchar **argv)
136 {
137 gint i, pos;
138
139 if (argc < 2)
140 {
141 g_print("%s: invalid parameters for playqueue-get-qposition.\n", argv[0]);
142 g_print("%s: syntax: %s playqueue-get-qposition <position>\n", argv[0], argv[0]);
143 return;
144 }
145
146 i = atoi(argv[1]);
147
148 if (i < 1 || i > audacious_remote_get_playqueue_length(dbus_proxy))
149 {
150 g_print("%s: invalid playlist position %d\n", argv[0], i);
151 return;
152 }
153
154 pos = audacious_remote_get_playqueue_queue_position(dbus_proxy, i - 1) + 1;
155
156 if (pos < 1)
157 return;
158
159 g_print("%d\n", pos);
160 }
161
162 void playqueue_display(gint argc, gchar **argv)
163 {
164 gint i, ii, position, frames, length, total;
165 gchar *songname;
166 gchar *fmt = NULL, *p;
167 gint column;
168
169 i = audacious_remote_get_playqueue_length(dbus_proxy);
170
171 g_print("%d queued tracks.\n", i);
172
173 total = 0;
174
175 for (ii = 0; ii < i; ii++)
176 {
177 position = audacious_remote_get_playqueue_queue_position(dbus_proxy, ii);
178 songname = audacious_remote_get_playlist_title(dbus_proxy, position);
179 frames = audacious_remote_get_playlist_time(dbus_proxy, position);
180 length = frames / 1000;
181 total += length;
182
183 /* adjust width for multi byte characters */
184 column = 60;
185 if(songname) {
186 p = songname;
187 while(*p){
188 gint stride;
189 stride = g_utf8_next_char(p) - p;
190 if(g_unichar_iswide(g_utf8_get_char(p))
191 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) )
192 || g_unichar_iswide_cjk(g_utf8_get_char(p))
193 #endif
194 ){
195 column += (stride - 2);
196 }
197 else {
198 column += (stride - 1);
199 }
200 p = g_utf8_next_char(p);
201 }
202 }
203
204 fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d\n", column);
205 g_print(fmt, ii + 1, position + 1, songname, length / 60, length % 60);
206 g_free(fmt);
207 }
208
209 g_print("Total length: %d:%.2d\n", total / 60, total % 60);
210 }
211
212 void playqueue_length(gint argc, gchar **argv)
213 {
214 gint i;
215
216 i = audacious_remote_get_playqueue_length(dbus_proxy);
217
218 g_print("%d\n", i);
219 }
220
221 void playqueue_clear(gint argc, gchar **argv)
222 {
223 audacious_remote_playqueue_clear(dbus_proxy);
224 }