Mercurial > audlegacy
comparison src/audtool/audtool_handlers_test.c @ 3867:e48f2f4c116d
- many remained audacious remote functions have been implemented.
- audtool improvement in progress.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Mon, 29 Oct 2007 22:21:42 +0900 |
parents | |
children | f3341c2d6b9e |
comparison
equal
deleted
inserted
replaced
3866:5c5f56a710d1 | 3867:e48f2f4c116d |
---|---|
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 test_activate(gint argc, gchar **argv) | |
41 { | |
42 audacious_remote_activate(dbus_proxy); | |
43 } | |
44 | |
45 void test_enqueue_to_temp(gint argc, gchar **argv) | |
46 { | |
47 gint playpos; | |
48 | |
49 if (argc < 2) | |
50 { | |
51 audtool_whine("invalid parameters for %s.", argv[0]); | |
52 audtool_whine("syntax: %s <position>", argv[0]); | |
53 return; | |
54 } | |
55 | |
56 playpos = atoi(argv[1]); | |
57 | |
58 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
59 { | |
60 audtool_whine("invalid playlist position %d", playpos); | |
61 return; | |
62 } | |
63 | |
64 audacious_remote_get_playqueue_queue_position(dbus_proxy, playpos - 1); // xxx playpos - 1? | |
65 } | |
66 | |
67 void test_toggle_aot(gint argc, gchar **argv) | |
68 { | |
69 gboolean ontop; | |
70 | |
71 if (argc < 2) | |
72 { | |
73 audtool_whine("invalid parameters for %s.", argv[0]); | |
74 audtool_whine("syntax: %s <boolean>", argv[0]); | |
75 return; | |
76 } | |
77 | |
78 ontop = (gboolean)atoi(argv[1]); | |
79 printf("ontop = %d\n", ontop); | |
80 audacious_remote_toggle_aot(dbus_proxy, ontop); | |
81 } | |
82 | |
83 void test_get_skin(gint argc, gchar **argv) | |
84 { | |
85 gchar *skin = NULL; | |
86 skin = audacious_remote_get_skin(dbus_proxy); | |
87 printf("skin = %s\n", skin); | |
88 g_free(skin); | |
89 } | |
90 | |
91 void test_set_skin(gint argc, gchar **argv) | |
92 { | |
93 if (argc < 2) | |
94 { | |
95 audtool_whine("invalid parameters for %s.", argv[0]); | |
96 audtool_whine("syntax: %s <skin>", argv[0]); | |
97 return; | |
98 } | |
99 printf("argc = %d\n", argc); | |
100 printf("skin = %p\n", argv[1]); | |
101 | |
102 | |
103 if(!argv[1] || !strcmp(argv[1], "")) | |
104 return; | |
105 | |
106 audacious_remote_set_skin(dbus_proxy, argv[1]); | |
107 } | |
108 | |
109 void test_get_info(gint argc, gchar **argv) | |
110 { | |
111 gint rate, freq, nch; | |
112 | |
113 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch); | |
114 printf("rate = %d freq = %d nch = %d\n", rate, freq, nch); | |
115 } | |
116 | |
117 | |
118 | |
119 | |
120 #if 0 | |
121 void playlist_reverse(gint argc, gchar **argv) | |
122 { | |
123 audacious_remote_playlist_prev(dbus_proxy); | |
124 } | |
125 | |
126 void playlist_advance(gint argc, gchar **argv) | |
127 { | |
128 audacious_remote_playlist_next(dbus_proxy); | |
129 } | |
130 | |
131 void playlist_add_url_string(gint argc, gchar **argv) | |
132 { | |
133 if (argc < 2) | |
134 { | |
135 audtool_whine("invalid parameters for %s.", argv[0]); | |
136 audtool_whine("syntax: %s <url>", argv[0]); | |
137 return; | |
138 } | |
139 | |
140 audacious_remote_playlist_add_url_string(dbus_proxy, argv[1]); | |
141 } | |
142 | |
143 void playlist_delete(gint argc, gchar **argv) | |
144 { | |
145 gint playpos; | |
146 | |
147 if (argc < 2) | |
148 { | |
149 audtool_whine("invalid parameters for %s.", argv[0]); | |
150 audtool_whine("syntax: %s <position>", argv[0]); | |
151 return; | |
152 } | |
153 | |
154 playpos = atoi(argv[1]); | |
155 | |
156 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
157 { | |
158 audtool_whine("invalid playlist position %d", playpos); | |
159 return; | |
160 } | |
161 | |
162 audacious_remote_playlist_delete(dbus_proxy, playpos - 1); | |
163 } | |
164 | |
165 void playlist_length(gint argc, gchar **argv) | |
166 { | |
167 gint i; | |
168 | |
169 i = audacious_remote_get_playlist_length(dbus_proxy); | |
170 | |
171 audtool_report("%d", i); | |
172 } | |
173 | |
174 void playlist_song(gint argc, gchar **argv) | |
175 { | |
176 gint playpos; | |
177 gchar *song; | |
178 | |
179 if (argc < 2) | |
180 { | |
181 audtool_whine("invalid parameters for %s.", argv[0]); | |
182 audtool_whine("syntax: %s <position>", argv[0]); | |
183 return; | |
184 } | |
185 | |
186 playpos = atoi(argv[1]); | |
187 | |
188 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
189 { | |
190 audtool_whine("invalid playlist position %d", playpos); | |
191 return; | |
192 } | |
193 | |
194 song = audacious_remote_get_playlist_title(dbus_proxy, playpos - 1); | |
195 | |
196 audtool_report("%s", song); | |
197 } | |
198 | |
199 | |
200 void playlist_song_length(gint argc, gchar **argv) | |
201 { | |
202 gint playpos, frames, length; | |
203 | |
204 if (argc < 2) | |
205 { | |
206 audtool_whine("invalid parameters for %s.", argv[0]); | |
207 audtool_whine("syntax: %s <position>", argv[0]); | |
208 return; | |
209 } | |
210 | |
211 playpos = atoi(argv[1]); | |
212 | |
213 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
214 { | |
215 audtool_whine("invalid playlist position %d", playpos); | |
216 return; | |
217 } | |
218 | |
219 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
220 length = frames / 1000; | |
221 | |
222 audtool_report("%d:%.2d", length / 60, length % 60); | |
223 } | |
224 | |
225 void playlist_song_length_seconds(gint argc, gchar **argv) | |
226 { | |
227 gint playpos, frames, length; | |
228 | |
229 if (argc < 2) | |
230 { | |
231 audtool_whine("invalid parameters for %s.", argv[0]); | |
232 audtool_whine("syntax: %s <position>", argv[0]); | |
233 return; | |
234 } | |
235 | |
236 playpos = atoi(argv[1]); | |
237 | |
238 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
239 { | |
240 audtool_whine("invalid playlist position %d", playpos); | |
241 return; | |
242 } | |
243 | |
244 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
245 length = frames / 1000; | |
246 | |
247 audtool_report("%d", length); | |
248 } | |
249 | |
250 void playlist_song_length_frames(gint argc, gchar **argv) | |
251 { | |
252 gint playpos, frames; | |
253 | |
254 if (argc < 2) | |
255 { | |
256 audtool_whine("invalid parameters for %s.", argv[0]); | |
257 audtool_whine("syntax: %s <position>", argv[0]); | |
258 return; | |
259 } | |
260 | |
261 playpos = atoi(argv[1]); | |
262 | |
263 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
264 { | |
265 audtool_whine("invalid playlist position %d", playpos); | |
266 return; | |
267 } | |
268 | |
269 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
270 | |
271 audtool_report("%d", frames); | |
272 } | |
273 | |
274 void playlist_display(gint argc, gchar **argv) | |
275 { | |
276 gint i, ii, frames, length, total; | |
277 gchar *songname; | |
278 gchar *fmt = NULL, *p; | |
279 gint column; | |
280 | |
281 i = audacious_remote_get_playlist_length(dbus_proxy); | |
282 | |
283 audtool_report("%d track%s.", i, i != 1 ? "s" : ""); | |
284 | |
285 total = 0; | |
286 | |
287 for (ii = 0; ii < i; ii++) | |
288 { | |
289 songname = audacious_remote_get_playlist_title(dbus_proxy, ii); | |
290 frames = audacious_remote_get_playlist_time(dbus_proxy, ii); | |
291 length = frames / 1000; | |
292 total += length; | |
293 | |
294 /* adjust width for multi byte characters */ | |
295 column = 60; | |
296 if(songname){ | |
297 p = songname; | |
298 while(*p){ | |
299 gint stride; | |
300 stride = g_utf8_next_char(p) - p; | |
301 if(g_unichar_iswide(g_utf8_get_char(p)) | |
302 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) ) | |
303 || g_unichar_iswide_cjk(g_utf8_get_char(p)) | |
304 #endif | |
305 ){ | |
306 column += (stride - 2); | |
307 } | |
308 else { | |
309 column += (stride - 1); | |
310 } | |
311 p = g_utf8_next_char(p); | |
312 } | |
313 | |
314 } | |
315 | |
316 fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d", column); | |
317 audtool_report(fmt, ii + 1, songname, length / 60, length % 60); | |
318 g_free(fmt); | |
319 } | |
320 | |
321 audtool_report("Total length: %d:%.2d", total / 60, total % 60); | |
322 } | |
323 | |
324 void playlist_position(gint argc, gchar **argv) | |
325 { | |
326 gint i; | |
327 | |
328 i = audacious_remote_get_playlist_pos(dbus_proxy); | |
329 | |
330 audtool_report("%d", i + 1); | |
331 } | |
332 | |
333 void playlist_song_filename(gint argc, gchar **argv) | |
334 { | |
335 gint i; | |
336 | |
337 if (argc < 2) | |
338 { | |
339 audtool_whine("invalid parameters for %s.", argv[0]); | |
340 audtool_whine("syntax: %s <position>", argv[0]); | |
341 return; | |
342 } | |
343 | |
344 i = atoi(argv[1]); | |
345 | |
346 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
347 { | |
348 audtool_whine("invalid playlist position %d", i); | |
349 return; | |
350 } | |
351 | |
352 audtool_report("%s", audacious_remote_get_playlist_file(dbus_proxy, i - 1)); | |
353 } | |
354 | |
355 void playlist_jump(gint argc, gchar **argv) | |
356 { | |
357 gint i; | |
358 | |
359 if (argc < 2) | |
360 { | |
361 audtool_whine("invalid parameters for %s.", argv[0]); | |
362 audtool_whine("syntax: %s <position>", argv[0]); | |
363 return; | |
364 } | |
365 | |
366 i = atoi(argv[1]); | |
367 | |
368 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
369 { | |
370 audtool_whine("invalid playlist position %d", i); | |
371 return; | |
372 } | |
373 | |
374 audacious_remote_set_playlist_pos(dbus_proxy, i - 1); | |
375 } | |
376 | |
377 void playlist_clear(gint argc, gchar **argv) | |
378 { | |
379 audacious_remote_playlist_clear(dbus_proxy); | |
380 } | |
381 | |
382 void playlist_repeat_status(gint argc, gchar **argv) | |
383 { | |
384 if (audacious_remote_is_repeat(dbus_proxy)) | |
385 { | |
386 audtool_report("on"); | |
387 return; | |
388 } | |
389 else | |
390 { | |
391 audtool_report("off"); | |
392 return; | |
393 } | |
394 } | |
395 | |
396 void playlist_repeat_toggle(gint argc, gchar **argv) | |
397 { | |
398 audacious_remote_toggle_repeat(dbus_proxy); | |
399 } | |
400 | |
401 void playlist_shuffle_status(gint argc, gchar **argv) | |
402 { | |
403 if (audacious_remote_is_shuffle(dbus_proxy)) | |
404 { | |
405 audtool_report("on"); | |
406 return; | |
407 } | |
408 else | |
409 { | |
410 audtool_report("off"); | |
411 return; | |
412 } | |
413 } | |
414 | |
415 void playlist_shuffle_toggle(gint argc, gchar **argv) | |
416 { | |
417 audacious_remote_toggle_shuffle(dbus_proxy); | |
418 } | |
419 | |
420 void playlist_tuple_field_data(gint argc, gchar **argv) | |
421 { | |
422 gint i; | |
423 gpointer data; | |
424 | |
425 if (argc < 3) | |
426 { | |
427 audtool_whine("invalid parameters for %s.", argv[0]); | |
428 audtool_whine("syntax: %s <fieldname> <position>", argv[0]); | |
429 audtool_whine(" - fieldname example choices: performer, album_name,"); | |
430 audtool_whine(" track_name, track_number, year, date, genre, comment,"); | |
431 audtool_whine(" file_name, file_ext, file_path, length, formatter,"); | |
432 audtool_whine(" custom, mtime"); | |
433 return; | |
434 } | |
435 | |
436 i = atoi(argv[2]); | |
437 | |
438 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
439 { | |
440 audtool_whine("invalid playlist position %d", i); | |
441 return; | |
442 } | |
443 | |
444 if (!(data = audacious_get_tuple_field_data(dbus_proxy, argv[1], i - 1))) | |
445 { | |
446 return; | |
447 } | |
448 | |
449 if (!g_ascii_strcasecmp(argv[1], "track_number") || !g_ascii_strcasecmp(argv[1], "year") || !g_ascii_strcasecmp(argv[1], "length") || !g_ascii_strcasecmp(argv[1], "mtime")) | |
450 { | |
451 if (*(gint *)data > 0) | |
452 { | |
453 audtool_report("%d", *(gint *)data); | |
454 } | |
455 return; | |
456 } | |
457 | |
458 audtool_report("%s", (gchar *)data); | |
459 } | |
460 #endif |