Mercurial > audlegacy
comparison src/audtool/audtool_handlers_playlist.c @ 2927:dbba106b417f trunk
Split out playlist functions.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 29 Jun 2007 08:08:30 -0500 |
parents | |
children | c32036aa4b4d |
comparison
equal
deleted
inserted
replaced
2926:f5ce83fdbf3e | 2927:dbba106b417f |
---|---|
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 playlist_reverse(gint argc, gchar **argv) | |
41 { | |
42 audacious_remote_playlist_prev(dbus_proxy); | |
43 } | |
44 | |
45 void playlist_advance(gint argc, gchar **argv) | |
46 { | |
47 audacious_remote_playlist_next(dbus_proxy); | |
48 } | |
49 | |
50 void playlist_add_url_string(gint argc, gchar **argv) | |
51 { | |
52 if (argc < 2) | |
53 { | |
54 g_print("%s: invalid parameters for playlist-addurl.\n", argv[0]); | |
55 g_print("%s: syntax: %s playlist-addurl <url>\n", argv[0], argv[0]); | |
56 return; | |
57 } | |
58 | |
59 audacious_remote_playlist_add_url_string(dbus_proxy, argv[1]); | |
60 } | |
61 | |
62 void playlist_delete(gint argc, gchar **argv) | |
63 { | |
64 gint playpos; | |
65 | |
66 if (argc < 2) | |
67 { | |
68 g_print("%s: invalid parameters for playlist-delete.\n", argv[0]); | |
69 g_print("%s: syntax: %s playlist-delete <position>\n", argv[0], argv[0]); | |
70 return; | |
71 } | |
72 | |
73 playpos = atoi(argv[1]); | |
74 | |
75 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
76 { | |
77 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
78 return; | |
79 } | |
80 | |
81 audacious_remote_playlist_delete(dbus_proxy, playpos - 1); | |
82 } | |
83 | |
84 void playlist_length(gint argc, gchar **argv) | |
85 { | |
86 gint i; | |
87 | |
88 i = audacious_remote_get_playlist_length(dbus_proxy); | |
89 | |
90 g_print("%d\n", i); | |
91 } | |
92 | |
93 void playlist_song(gint argc, gchar **argv) | |
94 { | |
95 gint playpos; | |
96 gchar *song; | |
97 | |
98 if (argc < 2) | |
99 { | |
100 g_print("%s: invalid parameters for playlist-song-title.\n", argv[0]); | |
101 g_print("%s: syntax: %s playlist-song-title <position>\n", argv[0], argv[0]); | |
102 return; | |
103 } | |
104 | |
105 playpos = atoi(argv[1]); | |
106 | |
107 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
108 { | |
109 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
110 return; | |
111 } | |
112 | |
113 song = audacious_remote_get_playlist_title(dbus_proxy, playpos - 1); | |
114 | |
115 g_print("%s\n", song); | |
116 } | |
117 | |
118 | |
119 void playlist_song_length(gint argc, gchar **argv) | |
120 { | |
121 gint playpos, frames, length; | |
122 | |
123 if (argc < 2) | |
124 { | |
125 g_print("%s: invalid parameters for playlist-song-length.\n", argv[0]); | |
126 g_print("%s: syntax: %s playlist-song-length <position>\n", argv[0], argv[0]); | |
127 return; | |
128 } | |
129 | |
130 playpos = atoi(argv[1]); | |
131 | |
132 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
133 { | |
134 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
135 return; | |
136 } | |
137 | |
138 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
139 length = frames / 1000; | |
140 | |
141 g_print("%d:%.2d\n", length / 60, length % 60); | |
142 } | |
143 | |
144 void playlist_song_length_seconds(gint argc, gchar **argv) | |
145 { | |
146 gint playpos, frames, length; | |
147 | |
148 if (argc < 2) | |
149 { | |
150 g_print("%s: invalid parameters for playlist-song-length-seconds.\n", argv[0]); | |
151 g_print("%s: syntax: %s playlist-song-length-seconds <position>\n", argv[0], argv[0]); | |
152 return; | |
153 } | |
154 | |
155 playpos = atoi(argv[1]); | |
156 | |
157 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
158 { | |
159 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
160 return; | |
161 } | |
162 | |
163 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
164 length = frames / 1000; | |
165 | |
166 g_print("%d\n", length); | |
167 } | |
168 | |
169 void playlist_song_length_frames(gint argc, gchar **argv) | |
170 { | |
171 gint playpos, frames; | |
172 | |
173 if (argc < 2) | |
174 { | |
175 g_print("%s: invalid parameters for playlist-song-length-frames.\n", argv[0]); | |
176 g_print("%s: syntax: %s playlist-song-length-frames <position>\n", argv[0], argv[0]); | |
177 return; | |
178 } | |
179 | |
180 playpos = atoi(argv[1]); | |
181 | |
182 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
183 { | |
184 g_print("%s: invalid playlist position %d\n", argv[0], playpos); | |
185 return; | |
186 } | |
187 | |
188 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
189 | |
190 g_print("%d\n", frames); | |
191 } | |
192 | |
193 void playlist_display(gint argc, gchar **argv) | |
194 { | |
195 gint i, ii, frames, length, total; | |
196 gchar *songname; | |
197 gchar *fmt = NULL, *p; | |
198 gint column; | |
199 | |
200 i = audacious_remote_get_playlist_length(dbus_proxy); | |
201 | |
202 g_print("%d track%s.\n", i, i != 1 ? "s" : ""); | |
203 | |
204 total = 0; | |
205 | |
206 for (ii = 0; ii < i; ii++) | |
207 { | |
208 songname = audacious_remote_get_playlist_title(dbus_proxy, ii); | |
209 frames = audacious_remote_get_playlist_time(dbus_proxy, ii); | |
210 length = frames / 1000; | |
211 total += length; | |
212 | |
213 /* adjust width for multi byte characters */ | |
214 column = 60; | |
215 if(songname){ | |
216 p = songname; | |
217 while(*p){ | |
218 gint stride; | |
219 stride = g_utf8_next_char(p) - p; | |
220 if(g_unichar_iswide(g_utf8_get_char(p)) | |
221 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) ) | |
222 || g_unichar_iswide_cjk(g_utf8_get_char(p)) | |
223 #endif | |
224 ){ | |
225 column += (stride - 2); | |
226 } | |
227 else { | |
228 column += (stride - 1); | |
229 } | |
230 p = g_utf8_next_char(p); | |
231 } | |
232 | |
233 } | |
234 | |
235 fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d\n", column); | |
236 g_print(fmt, ii + 1, songname, length / 60, length % 60); | |
237 g_free(fmt); | |
238 } | |
239 | |
240 g_print("Total length: %d:%.2d\n", total / 60, total % 60); | |
241 } | |
242 | |
243 void playlist_position(gint argc, gchar **argv) | |
244 { | |
245 gint i; | |
246 | |
247 i = audacious_remote_get_playlist_pos(dbus_proxy); | |
248 | |
249 g_print("%d\n", i + 1); | |
250 } | |
251 | |
252 void playlist_song_filename(gint argc, gchar **argv) | |
253 { | |
254 gint i; | |
255 | |
256 if (argc < 2) | |
257 { | |
258 g_print("%s: invalid parameters for playlist-filename.\n", argv[0]); | |
259 g_print("%s: syntax: %s playlist-filename <position>\n", argv[0], argv[0]); | |
260 return; | |
261 } | |
262 | |
263 i = atoi(argv[1]); | |
264 | |
265 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
266 { | |
267 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
268 return; | |
269 } | |
270 | |
271 g_print("%s\n", audacious_remote_get_playlist_file(dbus_proxy, i - 1)); | |
272 } | |
273 | |
274 void playlist_jump(gint argc, gchar **argv) | |
275 { | |
276 gint i; | |
277 | |
278 if (argc < 2) | |
279 { | |
280 g_print("%s: invalid parameters for playlist-jump.\n", argv[0]); | |
281 g_print("%s: syntax: %s playlist-jump <position>\n", argv[0], argv[0]); | |
282 return; | |
283 } | |
284 | |
285 i = atoi(argv[1]); | |
286 | |
287 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
288 { | |
289 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
290 return; | |
291 } | |
292 | |
293 audacious_remote_set_playlist_pos(dbus_proxy, i - 1); | |
294 } | |
295 | |
296 void playlist_clear(gint argc, gchar **argv) | |
297 { | |
298 audacious_remote_playlist_clear(dbus_proxy); | |
299 } | |
300 | |
301 void playlist_repeat_status(gint argc, gchar **argv) | |
302 { | |
303 if (audacious_remote_is_repeat(dbus_proxy)) | |
304 { | |
305 g_print("on\n"); | |
306 return; | |
307 } | |
308 else | |
309 { | |
310 g_print("off\n"); | |
311 return; | |
312 } | |
313 } | |
314 | |
315 void playlist_repeat_toggle(gint argc, gchar **argv) | |
316 { | |
317 audacious_remote_toggle_repeat(dbus_proxy); | |
318 } | |
319 | |
320 void playlist_shuffle_status(gint argc, gchar **argv) | |
321 { | |
322 if (audacious_remote_is_shuffle(dbus_proxy)) | |
323 { | |
324 g_print("on\n"); | |
325 return; | |
326 } | |
327 else | |
328 { | |
329 g_print("off\n"); | |
330 return; | |
331 } | |
332 } | |
333 | |
334 void playlist_shuffle_toggle(gint argc, gchar **argv) | |
335 { | |
336 audacious_remote_toggle_shuffle(dbus_proxy); | |
337 } | |
338 | |
339 void playlist_tuple_field_data(gint argc, gchar **argv) | |
340 { | |
341 gint i; | |
342 gpointer data; | |
343 | |
344 if (argc < 3) | |
345 { | |
346 g_print("%s: invalid parameters for playlist-tuple-data.\n", argv[0]); | |
347 g_print("%s: syntax: %s playlist-tuple-data <fieldname> <position>\n", argv[0], argv[0]); | |
348 g_print("%s: - fieldname example choices: performer, album_name,\n", argv[0]); | |
349 g_print("%s: track_name, track_number, year, date, genre, comment,\n", argv[0]); | |
350 g_print("%s: file_name, file_ext, file_path, length, formatter,\n", argv[0]); | |
351 g_print("%s: custom, mtime\n", argv[0]); | |
352 return; | |
353 } | |
354 | |
355 i = atoi(argv[2]); | |
356 | |
357 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
358 { | |
359 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
360 return; | |
361 } | |
362 | |
363 if (!(data = audacious_get_tuple_field_data(dbus_proxy, argv[1], i - 1))) | |
364 { | |
365 return; | |
366 } | |
367 | |
368 if (!strcasecmp(argv[1], "track_number") || !strcasecmp(argv[1], "year") || !strcasecmp(argv[1], "length") || !strcasecmp(argv[1], "mtime")) | |
369 { | |
370 if (*(gint *)data > 0) | |
371 { | |
372 g_print("%d\n", *(gint *)data); | |
373 } | |
374 return; | |
375 } | |
376 | |
377 g_print("%s\n", (gchar *)data); | |
378 } |