comparison src/audtool/audtool_handlers_general.c @ 2922:89676d0b5efc trunk

File reorganization.
author William Pitcock <nenolod@atheme.org>
date Fri, 29 Jun 2007 07:37:39 -0500
parents src/audtool/handlers.c@77a012c3b521
children 90ca95b7277d
comparison
equal deleted inserted replaced
2919:2abf3bb3e63d 2922:89676d0b5efc
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 get_current_song(gint argc, gchar **argv)
41 {
42 gint playpos = audacious_remote_get_playlist_pos(dbus_proxy);
43 gchar *song = audacious_remote_get_playlist_title(dbus_proxy, playpos);
44
45 if (!song)
46 {
47 g_print("No song playing.\n");
48 return;
49 }
50
51 g_print("%s\n", song);
52 }
53
54 void get_current_song_filename(gint argc, gchar **argv)
55 {
56 gint playpos = audacious_remote_get_playlist_pos(dbus_proxy);
57 gchar *file = audacious_remote_get_playlist_file(dbus_proxy, playpos);
58
59 if (!file)
60 {
61 g_print("No song playing.\n");
62 return;
63 }
64
65 g_print("%s\n", file);
66 }
67
68 void get_current_song_output_length(gint argc, gchar **argv)
69 {
70 gint frames = audacious_remote_get_output_time(dbus_proxy);
71 gint length = frames / 1000;
72
73 g_print("%d:%.2d\n", length / 60, length % 60);
74 }
75
76 void get_current_song_output_length_seconds(gint argc, gchar **argv)
77 {
78 gint frames = audacious_remote_get_output_time(dbus_proxy);
79 gint length = frames / 1000;
80
81 g_print("%d\n", length);
82 }
83
84 void get_current_song_output_length_frames(gint argc, gchar **argv)
85 {
86 gint frames = audacious_remote_get_output_time(dbus_proxy);
87
88 g_print("%d\n", frames);
89 }
90
91 void get_current_song_length(gint argc, gchar **argv)
92 {
93 gint playpos = audacious_remote_get_playlist_pos(dbus_proxy);
94 gint frames = audacious_remote_get_playlist_time(dbus_proxy, playpos);
95 gint length = frames / 1000;
96
97 g_print("%d:%.2d\n", length / 60, length % 60);
98 }
99
100 void get_current_song_length_seconds(gint argc, gchar **argv)
101 {
102 gint playpos = audacious_remote_get_playlist_pos(dbus_proxy);
103 gint frames = audacious_remote_get_playlist_time(dbus_proxy, playpos);
104 gint length = frames / 1000;
105
106 g_print("%d\n", length);
107 }
108
109 void get_current_song_length_frames(gint argc, gchar **argv)
110 {
111 gint playpos = audacious_remote_get_playlist_pos(dbus_proxy);
112 gint frames = audacious_remote_get_playlist_time(dbus_proxy, playpos);
113
114 g_print("%d\n", frames);
115 }
116
117 void get_current_song_bitrate(gint argc, gchar **argv)
118 {
119 gint rate, freq, nch;
120
121 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch);
122
123 g_print("%d\n", rate);
124 }
125
126 void get_current_song_bitrate_kbps(gint argc, gchar **argv)
127 {
128 gint rate, freq, nch;
129
130 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch);
131
132 g_print("%d\n", rate / 1000);
133 }
134
135 void get_current_song_frequency(gint argc, gchar **argv)
136 {
137 gint rate, freq, nch;
138
139 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch);
140
141 g_print("%d\n", freq);
142 }
143
144 void get_current_song_frequency_khz(gint argc, gchar **argv)
145 {
146 gint rate, freq, nch;
147
148 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch);
149
150 g_print("%0.1f\n", (gfloat) freq / 1000);
151 }
152
153 void get_current_song_channels(gint argc, gchar **argv)
154 {
155 gint rate, freq, nch;
156
157 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch);
158
159 g_print("%d\n", nch);
160 }
161
162 void get_current_song_tuple_field_data(gint argc, gchar **argv)
163 {
164 gpointer data;
165
166 if (argc < 3)
167 {
168 g_print("%s: invalid parameters for current-song-tuple-data.\n", argv[0]);
169 g_print("%s: syntax: %s current-song-tuple-data <fieldname>\n", argv[0], argv[0]);
170 g_print("%s: - fieldname example choices: performer, album_name,\n", argv[0]);
171 g_print("%s: track_name, track_number, year, date, genre, comment,\n", argv[0]);
172 g_print("%s: file_name, file_ext, file_path, length, formatter,\n", argv[0]);
173 g_print("%s: custom, mtime\n", argv[0]);
174 return;
175 }
176
177 if (!(data = audacious_get_tuple_field_data(dbus_proxy, argv[2], audacious_remote_get_playlist_pos(dbus_proxy))))
178 {
179 return;
180 }
181
182 if (!strcasecmp(argv[2], "track_number") || !strcasecmp(argv[2], "year") || !strcasecmp(argv[2], "length") || !strcasecmp(argv[2], "mtime"))
183 {
184 if (*(gint *)data > 0)
185 {
186 g_print("%d\n", *(gint *)data);
187 }
188 return;
189 }
190
191 g_print("%s\n", (gchar *)data);
192 }
193
194 void playlist_reverse(gint argc, gchar **argv)
195 {
196 audacious_remote_playlist_prev(dbus_proxy);
197 }
198
199 void playlist_advance(gint argc, gchar **argv)
200 {
201 audacious_remote_playlist_next(dbus_proxy);
202 }
203
204 void playback_play(gint argc, gchar **argv)
205 {
206 audacious_remote_play(dbus_proxy);
207 }
208
209 void playback_pause(gint argc, gchar **argv)
210 {
211 audacious_remote_pause(dbus_proxy);
212 }
213
214 void playback_playpause(gint argc, gchar **argv)
215 {
216 if (audacious_remote_is_playing(dbus_proxy))
217 {
218 audacious_remote_pause(dbus_proxy);
219 }
220 else
221 {
222 audacious_remote_play(dbus_proxy);
223 }
224 }
225
226 void playback_stop(gint argc, gchar **argv)
227 {
228 audacious_remote_stop(dbus_proxy);
229 }
230
231 void playback_playing(gint argc, gchar **argv)
232 {
233 if (!audacious_remote_is_paused(dbus_proxy))
234 {
235 exit(!audacious_remote_is_playing(dbus_proxy));
236 }
237 else
238 {
239 exit(1);
240 }
241 }
242
243 void playback_paused(gint argc, gchar **argv)
244 {
245 exit(!audacious_remote_is_paused(dbus_proxy));
246 }
247
248 void playback_stopped(gint argc, gchar **argv)
249 {
250 if (!audacious_remote_is_playing(dbus_proxy) && !audacious_remote_is_paused(dbus_proxy))
251 {
252 exit(0);
253 }
254 else
255 {
256 exit(1);
257 }
258 }
259
260 void playback_status(gint argc, gchar **argv)
261 {
262 if (audacious_remote_is_paused(dbus_proxy))
263 {
264 g_print("paused\n");
265 return;
266 }
267 else if (audacious_remote_is_playing(dbus_proxy))
268 {
269 g_print("playing\n");
270 return;
271 }
272 else
273 {
274 g_print("stopped\n");
275 return;
276 }
277 }
278
279 void playback_seek(gint argc, gchar **argv)
280 {
281 if (argc < 3)
282 {
283 g_print("%s: invalid parameters for playback-seek.\n", argv[0]);
284 g_print("%s: syntax: %s playback-seek <position>\n", argv[0], argv[0]);
285 return;
286 }
287
288 audacious_remote_jump_to_time(dbus_proxy, atoi(argv[2]) * 1000);
289 }
290
291 void playback_seek_relative(gint argc, gchar **argv)
292 {
293 gint oldtime, newtime, diff;
294
295 if (argc < 3)
296 {
297 g_print("%s: invalid parameters for playback-seek-relative.\n", argv[0]);
298 g_print("%s: syntax: %s playback-seek <position>\n", argv[0], argv[0]);
299 return;
300 }
301
302 oldtime = audacious_remote_get_output_time(dbus_proxy);
303 diff = atoi(argv[2]) * 1000;
304 newtime = oldtime + diff;
305
306 audacious_remote_jump_to_time(dbus_proxy, newtime);
307 }
308
309 void playlist_add_url_string(gint argc, gchar **argv)
310 {
311 if (argc < 3)
312 {
313 g_print("%s: invalid parameters for playlist-addurl.\n", argv[0]);
314 g_print("%s: syntax: %s playlist-addurl <url>\n", argv[0], argv[0]);
315 return;
316 }
317
318 audacious_remote_playlist_add_url_string(dbus_proxy, argv[2]);
319 }
320
321 void playlist_delete(gint argc, gchar **argv)
322 {
323 gint playpos;
324
325 if (argc < 3)
326 {
327 g_print("%s: invalid parameters for playlist-delete.\n", argv[0]);
328 g_print("%s: syntax: %s playlist-delete <position>\n", argv[0], argv[0]);
329 return;
330 }
331
332 playpos = atoi(argv[2]);
333
334 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy))
335 {
336 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
337 return;
338 }
339
340 audacious_remote_playlist_delete(dbus_proxy, playpos - 1);
341 }
342
343 void playlist_length(gint argc, gchar **argv)
344 {
345 gint i;
346
347 i = audacious_remote_get_playlist_length(dbus_proxy);
348
349 g_print("%d\n", i);
350 }
351
352 void playlist_song(gint argc, gchar **argv)
353 {
354 gint playpos;
355 gchar *song;
356
357 if (argc < 3)
358 {
359 g_print("%s: invalid parameters for playlist-song-title.\n", argv[0]);
360 g_print("%s: syntax: %s playlist-song-title <position>\n", argv[0], argv[0]);
361 return;
362 }
363
364 playpos = atoi(argv[2]);
365
366 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy))
367 {
368 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
369 return;
370 }
371
372 song = audacious_remote_get_playlist_title(dbus_proxy, playpos - 1);
373
374 g_print("%s\n", song);
375 }
376
377
378 void playlist_song_length(gint argc, gchar **argv)
379 {
380 gint playpos, frames, length;
381
382 if (argc < 3)
383 {
384 g_print("%s: invalid parameters for playlist-song-length.\n", argv[0]);
385 g_print("%s: syntax: %s playlist-song-length <position>\n", argv[0], argv[0]);
386 return;
387 }
388
389 playpos = atoi(argv[2]);
390
391 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy))
392 {
393 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
394 return;
395 }
396
397 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1);
398 length = frames / 1000;
399
400 g_print("%d:%.2d\n", length / 60, length % 60);
401 }
402
403 void playlist_song_length_seconds(gint argc, gchar **argv)
404 {
405 gint playpos, frames, length;
406
407 if (argc < 3)
408 {
409 g_print("%s: invalid parameters for playlist-song-length-seconds.\n", argv[0]);
410 g_print("%s: syntax: %s playlist-song-length-seconds <position>\n", argv[0], argv[0]);
411 return;
412 }
413
414 playpos = atoi(argv[2]);
415
416 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy))
417 {
418 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
419 return;
420 }
421
422 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1);
423 length = frames / 1000;
424
425 g_print("%d\n", length);
426 }
427
428 void playlist_song_length_frames(gint argc, gchar **argv)
429 {
430 gint playpos, frames;
431
432 if (argc < 3)
433 {
434 g_print("%s: invalid parameters for playlist-song-length-frames.\n", argv[0]);
435 g_print("%s: syntax: %s playlist-song-length-frames <position>\n", argv[0], argv[0]);
436 return;
437 }
438
439 playpos = atoi(argv[2]);
440
441 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy))
442 {
443 g_print("%s: invalid playlist position %d\n", argv[0], playpos);
444 return;
445 }
446
447 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1);
448
449 g_print("%d\n", frames);
450 }
451
452 void playlist_display(gint argc, gchar **argv)
453 {
454 gint i, ii, frames, length, total;
455 gchar *songname;
456 gchar *fmt = NULL, *p;
457 gint column;
458
459 i = audacious_remote_get_playlist_length(dbus_proxy);
460
461 g_print("%d track%s.\n", i, i != 1 ? "s" : "");
462
463 total = 0;
464
465 for (ii = 0; ii < i; ii++)
466 {
467 songname = audacious_remote_get_playlist_title(dbus_proxy, ii);
468 frames = audacious_remote_get_playlist_time(dbus_proxy, ii);
469 length = frames / 1000;
470 total += length;
471
472 /* adjust width for multi byte characters */
473 column = 60;
474 if(songname){
475 p = songname;
476 while(*p){
477 gint stride;
478 stride = g_utf8_next_char(p) - p;
479 if(g_unichar_iswide(g_utf8_get_char(p))
480 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) )
481 || g_unichar_iswide_cjk(g_utf8_get_char(p))
482 #endif
483 ){
484 column += (stride - 2);
485 }
486 else {
487 column += (stride - 1);
488 }
489 p = g_utf8_next_char(p);
490 }
491
492 }
493
494 fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d\n", column);
495 g_print(fmt, ii + 1, songname, length / 60, length % 60);
496 g_free(fmt);
497 }
498
499 g_print("Total length: %d:%.2d\n", total / 60, total % 60);
500 }
501
502 void playlist_position(gint argc, gchar **argv)
503 {
504 gint i;
505
506 i = audacious_remote_get_playlist_pos(dbus_proxy);
507
508 g_print("%d\n", i + 1);
509 }
510
511 void playlist_song_filename(gint argc, gchar **argv)
512 {
513 gint i;
514
515 if (argc < 3)
516 {
517 g_print("%s: invalid parameters for playlist-filename.\n", argv[0]);
518 g_print("%s: syntax: %s playlist-filename <position>\n", argv[0], argv[0]);
519 return;
520 }
521
522 i = atoi(argv[2]);
523
524 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
525 {
526 g_print("%s: invalid playlist position %d\n", argv[0], i);
527 return;
528 }
529
530 g_print("%s\n", audacious_remote_get_playlist_file(dbus_proxy, i - 1));
531 }
532
533 void playlist_jump(gint argc, gchar **argv)
534 {
535 gint i;
536
537 if (argc < 3)
538 {
539 g_print("%s: invalid parameters for playlist-jump.\n", argv[0]);
540 g_print("%s: syntax: %s playlist-jump <position>\n", argv[0], argv[0]);
541 return;
542 }
543
544 i = atoi(argv[2]);
545
546 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
547 {
548 g_print("%s: invalid playlist position %d\n", argv[0], i);
549 return;
550 }
551
552 audacious_remote_set_playlist_pos(dbus_proxy, i - 1);
553 }
554
555 void playlist_clear(gint argc, gchar **argv)
556 {
557 audacious_remote_playlist_clear(dbus_proxy);
558 }
559
560 void playlist_repeat_status(gint argc, gchar **argv)
561 {
562 if (audacious_remote_is_repeat(dbus_proxy))
563 {
564 g_print("on\n");
565 return;
566 }
567 else
568 {
569 g_print("off\n");
570 return;
571 }
572 }
573
574 void playlist_repeat_toggle(gint argc, gchar **argv)
575 {
576 audacious_remote_toggle_repeat(dbus_proxy);
577 }
578
579 void playlist_shuffle_status(gint argc, gchar **argv)
580 {
581 if (audacious_remote_is_shuffle(dbus_proxy))
582 {
583 g_print("on\n");
584 return;
585 }
586 else
587 {
588 g_print("off\n");
589 return;
590 }
591 }
592
593 void playlist_shuffle_toggle(gint argc, gchar **argv)
594 {
595 audacious_remote_toggle_shuffle(dbus_proxy);
596 }
597
598 void playlist_tuple_field_data(gint argc, gchar **argv)
599 {
600 gint i;
601 gpointer data;
602
603 if (argc < 4)
604 {
605 g_print("%s: invalid parameters for playlist-tuple-data.\n", argv[0]);
606 g_print("%s: syntax: %s playlist-tuple-data <fieldname> <position>\n", argv[0], argv[0]);
607 g_print("%s: - fieldname example choices: performer, album_name,\n", argv[0]);
608 g_print("%s: track_name, track_number, year, date, genre, comment,\n", argv[0]);
609 g_print("%s: file_name, file_ext, file_path, length, formatter,\n", argv[0]);
610 g_print("%s: custom, mtime\n", argv[0]);
611 return;
612 }
613
614 i = atoi(argv[3]);
615
616 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
617 {
618 g_print("%s: invalid playlist position %d\n", argv[0], i);
619 return;
620 }
621
622 if (!(data = audacious_get_tuple_field_data(dbus_proxy, argv[2], i - 1)))
623 {
624 return;
625 }
626
627 if (!strcasecmp(argv[2], "track_number") || !strcasecmp(argv[2], "year") || !strcasecmp(argv[2], "length") || !strcasecmp(argv[2], "mtime"))
628 {
629 if (*(gint *)data > 0)
630 {
631 g_print("%d\n", *(gint *)data);
632 }
633 return;
634 }
635
636 g_print("%s\n", (gchar *)data);
637 }
638
639 void playqueue_add(gint argc, gchar **argv)
640 {
641 gint i;
642
643 if (argc < 3)
644 {
645 g_print("%s: invalid parameters for playqueue-add.\n", argv[0]);
646 g_print("%s: syntax: %s playqueue-add <position>\n", argv[0], argv[0]);
647 return;
648 }
649
650 i = atoi(argv[2]);
651
652 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
653 {
654 g_print("%s: invalid playlist position %d\n", argv[0], i);
655 return;
656 }
657
658 if (!(audacious_remote_playqueue_is_queued(dbus_proxy, i - 1)))
659 audacious_remote_playqueue_add(dbus_proxy, i - 1);
660 }
661
662 void playqueue_remove(gint argc, gchar **argv)
663 {
664 gint i;
665
666 if (argc < 3)
667 {
668 g_print("%s: invalid parameters for playqueue-remove.\n", argv[0]);
669 g_print("%s: syntax: %s playqueue-remove <position>\n", argv[0], argv[0]);
670 return;
671 }
672
673 i = atoi(argv[2]);
674
675 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
676 {
677 g_print("%s: invalid playlist position %d\n", argv[0], i);
678 return;
679 }
680
681 if (audacious_remote_playqueue_is_queued(dbus_proxy, i - 1))
682 audacious_remote_playqueue_remove(dbus_proxy, i - 1);
683 }
684
685 void playqueue_is_queued(gint argc, gchar **argv)
686 {
687 gint i;
688
689 if (argc < 3)
690 {
691 g_print("%s: invalid parameters for playqueue-is-queued.\n", argv[0]);
692 g_print("%s: syntax: %s playqueue-is-queued <position>\n", argv[0], argv[0]);
693 return;
694 }
695
696 i = atoi(argv[2]);
697
698 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
699 {
700 g_print("%s: invalid playlist position %d\n", argv[0], i);
701 return;
702 }
703
704 exit(!(audacious_remote_playqueue_is_queued(dbus_proxy, i - 1)));
705 }
706
707 void playqueue_get_position(gint argc, gchar **argv)
708 {
709 gint i, pos;
710
711 if (argc < 3)
712 {
713 g_print("%s: invalid parameters for playqueue-get-position.\n", argv[0]);
714 g_print("%s: syntax: %s playqueue-get-position <position>\n", argv[0], argv[0]);
715 return;
716 }
717
718 i = atoi(argv[2]);
719
720 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy))
721 {
722 g_print("%s: invalid playlist position %d\n", argv[0], i);
723 return;
724 }
725
726 pos = audacious_remote_get_playqueue_position(dbus_proxy, i - 1) + 1;
727
728 if (pos < 1)
729 return;
730
731 g_print("%d\n", pos);
732 }
733
734 void playqueue_get_qposition(gint argc, gchar **argv)
735 {
736 gint i, pos;
737
738 if (argc < 3)
739 {
740 g_print("%s: invalid parameters for playqueue-get-qposition.\n", argv[0]);
741 g_print("%s: syntax: %s playqueue-get-qposition <position>\n", argv[0], argv[0]);
742 return;
743 }
744
745 i = atoi(argv[2]);
746
747 if (i < 1 || i > audacious_remote_get_playqueue_length(dbus_proxy))
748 {
749 g_print("%s: invalid playlist position %d\n", argv[0], i);
750 return;
751 }
752
753 pos = audacious_remote_get_playqueue_queue_position(dbus_proxy, i - 1) + 1;
754
755 if (pos < 1)
756 return;
757
758 g_print("%d\n", pos);
759 }
760
761 void playqueue_display(gint argc, gchar **argv)
762 {
763 gint i, ii, position, frames, length, total;
764 gchar *songname;
765 gchar *fmt = NULL, *p;
766 gint column;
767
768 i = audacious_remote_get_playqueue_length(dbus_proxy);
769
770 g_print("%d queued tracks.\n", i);
771
772 total = 0;
773
774 for (ii = 0; ii < i; ii++)
775 {
776 position = audacious_remote_get_playqueue_queue_position(dbus_proxy, ii);
777 songname = audacious_remote_get_playlist_title(dbus_proxy, position);
778 frames = audacious_remote_get_playlist_time(dbus_proxy, position);
779 length = frames / 1000;
780 total += length;
781
782 /* adjust width for multi byte characters */
783 column = 60;
784 if(songname) {
785 p = songname;
786 while(*p){
787 gint stride;
788 stride = g_utf8_next_char(p) - p;
789 if(g_unichar_iswide(g_utf8_get_char(p))
790 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) )
791 || g_unichar_iswide_cjk(g_utf8_get_char(p))
792 #endif
793 ){
794 column += (stride - 2);
795 }
796 else {
797 column += (stride - 1);
798 }
799 p = g_utf8_next_char(p);
800 }
801 }
802
803 fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d\n", column);
804 g_print(fmt, ii + 1, position + 1, songname, length / 60, length % 60);
805 g_free(fmt);
806 }
807
808 g_print("Total length: %d:%.2d\n", total / 60, total % 60);
809 }
810
811 void playqueue_length(gint argc, gchar **argv)
812 {
813 gint i;
814
815 i = audacious_remote_get_playqueue_length(dbus_proxy);
816
817 g_print("%d\n", i);
818 }
819
820 void playqueue_clear(gint argc, gchar **argv)
821 {
822 audacious_remote_playqueue_clear(dbus_proxy);
823 }
824
825 void get_volume(gint argc, gchar **argv)
826 {
827 gint i;
828
829 i = audacious_remote_get_main_volume(dbus_proxy);
830
831 g_print("%d\n", i);
832 }
833
834 void set_volume(gint argc, gchar **argv)
835 {
836 gint i, current_volume;
837
838 if (argc < 3)
839 {
840 g_print("%s: invalid parameters for set-volume.\n", argv[0]);
841 g_print("%s: syntax: %s set-volume <level>\n", argv[0], argv[0]);
842 return;
843 }
844
845 current_volume = audacious_remote_get_main_volume(dbus_proxy);
846 switch (argv[2][0])
847 {
848 case '+':
849 case '-':
850 i = current_volume + atoi(argv[2]);
851 break;
852 default:
853 i = atoi(argv[2]);
854 break;
855 }
856
857 audacious_remote_set_main_volume(dbus_proxy, i);
858 }
859
860 void mainwin_show(gint argc, gchar **argv)
861 {
862 if (argc > 2)
863 {
864 if (!strncmp(argv[2],"on",2)) {
865 audacious_remote_main_win_toggle(dbus_proxy, TRUE);
866 return;
867 }
868 else if (!strncmp(argv[2],"off",3)) {
869 audacious_remote_main_win_toggle(dbus_proxy, FALSE);
870 return;
871 }
872 }
873 g_print("%s: invalid parameter for mainwin-show.\n",argv[0]);
874 g_print("%s: syntax: %s mainwin-show <on/off>\n",argv[0],argv[0]);
875 }
876
877 void playlist_show(gint argc, gchar **argv)
878 {
879 if (argc > 2)
880 {
881 if (!strncmp(argv[2],"on",2)) {
882 audacious_remote_pl_win_toggle(dbus_proxy, TRUE);
883 return;
884 }
885 else if (!strncmp(argv[2],"off",3)) {
886 audacious_remote_pl_win_toggle(dbus_proxy, FALSE);
887 return;
888 }
889 }
890 g_print("%s: invalid parameter for playlist-show.\n",argv[0]);
891 g_print("%s: syntax: %s playlist-show <on/off>\n",argv[0],argv[0]);
892 }
893
894 void equalizer_show(gint argc, gchar **argv)
895 {
896 if (argc > 2)
897 {
898 if (!strncmp(argv[2],"on",2)) {
899 audacious_remote_eq_win_toggle(dbus_proxy, TRUE);
900 return;
901 }
902 else if (!strncmp(argv[2],"off",3)) {
903 audacious_remote_eq_win_toggle(dbus_proxy, FALSE);
904 return;
905 }
906 }
907 g_print("%s: invalid parameter for equalizer-show.\n",argv[0]);
908 g_print("%s: syntax: %s equalizer-show <on/off>\n",argv[0],argv[0]);
909 }
910
911 void show_preferences_window(gint argc, gchar **argv)
912 {
913 audacious_remote_show_prefs_box(dbus_proxy);
914 }
915
916 void show_jtf_window(gint argc, gchar **argv)
917 {
918 audacious_remote_show_jtf_box(dbus_proxy);
919 }
920
921 void shutdown_audacious_server(gint argc, gchar **argv)
922 {
923 audacious_remote_quit(dbus_proxy);
924 }
925
926 void get_handlers_list(gint argc, gchar **argv)
927 {
928 gint i;
929
930 for (i = 0; handlers[i].name != NULL; i++)
931 {
932 if (!g_strcasecmp("<sep>", handlers[i].name))
933 g_print("%s%s:\n", i == 0 ? "" : "\n", handlers[i].desc);
934 else
935 g_print(" %-34s - %s\n", handlers[i].name, handlers[i].desc);
936 }
937
938 g_print("\nHandlers may be prefixed with `--' (GNU-style long-options) or not, your choice.\n");
939 g_print("Report bugs to http://bugs-meta.atheme.org/\n");
940 }