Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
audctrl.c
Go to the documentation of this file.
1 /*
2  * audctrl.c
3  * Copyright 2007-2011 Ben Tucker, William Pitcock, Yoshiki Yazawa,
4  * Matti Hämäläinen, and John Lindgren
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are 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 notice,
13  * this list of conditions, and the following disclaimer in the documentation
14  * provided with the distribution.
15  *
16  * This software is provided "as is" and without any warranty, express or
17  * implied. In no event shall the authors be liable for any damages arising from
18  * the use of this software.
19  */
20 
21 #include <stdlib.h>
22 #include <glib.h>
23 #include <string.h>
24 #include <dbus/dbus-glib.h>
25 
26 #include "audacious/dbus.h"
28 #include "audctrl.h"
29 
30 static GError *error = NULL; //it must be hidden from outside, otherwise symbol conflict likely to happen.
31 
41 EXPORT void audacious_remote_playlist(DBusGProxy *proxy, gchar **list, gint num, gboolean enqueue) {
42  GList *glist = NULL;
43  gchar **data = list;
44 
45  g_return_if_fail(list != NULL);
46  g_return_if_fail(num > 0);
47 
48  if (!enqueue)
50 
51  // construct a GList
52  while(data) {
53  glist = g_list_append(glist, (gpointer)data);
54  data++;
55  }
56 
57  org_atheme_audacious_playlist_add(proxy, (gpointer)glist, &error);
58 
59  g_list_free(glist);
60  glist = NULL;
61 
62  if (!enqueue)
63  audacious_remote_play(proxy);
64 }
65 
72 EXPORT gchar *audacious_remote_get_version(DBusGProxy *proxy) {
73  char *string = NULL;
74  org_atheme_audacious_version(proxy, &string, &error);
75  g_clear_error(&error);
76 
77  return (string ? string : NULL);
78 }
79 
86 EXPORT void audacious_remote_playlist_add (DBusGProxy * proxy, GList * list)
87 {
88  const gchar * filenames[g_list_length (list) + 1];
89  int count;
90 
91  for (count = 0; list != NULL; count ++, list = list->next)
92  filenames[count] = list->data;
93 
94  filenames[count] = NULL;
95 
96  org_atheme_audacious_add_list (proxy, filenames, & error);
97  g_clear_error (& error);
98 }
99 
106 EXPORT void audacious_remote_playlist_open_list (DBusGProxy * proxy, GList * list)
107 {
108  const gchar * filenames[g_list_length (list) + 1];
109  int count;
110 
111  for (count = 0; list != NULL; count ++, list = list->next)
112  filenames[count] = list->data;
113 
114  filenames[count] = NULL;
115 
116  org_atheme_audacious_open_list (proxy, filenames, & error);
117  g_clear_error (& error);
118 }
119 
127 EXPORT void audacious_remote_playlist_open_list_to_temp (DBusGProxy * proxy, GList *
128  list)
129 {
130  const gchar * filenames[g_list_length (list) + 1];
131  int count;
132 
133  for (count = 0; list != NULL; count ++, list = list->next)
134  filenames[count] = list->data;
135 
136  filenames[count] = NULL;
137 
138  org_atheme_audacious_open_list_to_temp (proxy, filenames, & error);
139  g_clear_error (& error);
140 }
141 
148 EXPORT void audacious_remote_playlist_delete(DBusGProxy *proxy, guint pos) {
149  org_atheme_audacious_delete(proxy, pos, &error);
150  g_clear_error(&error);
151 }
152 
158 EXPORT void audacious_remote_play(DBusGProxy *proxy) {
160  g_clear_error(&error);
161 }
162 
168 EXPORT void audacious_remote_pause(DBusGProxy *proxy) {
170  g_clear_error(&error);
171 }
172 
178 EXPORT void audacious_remote_stop(DBusGProxy *proxy) {
180  g_clear_error(&error);
181 }
182 
189 EXPORT gboolean audacious_remote_is_playing(DBusGProxy *proxy) {
190  gboolean is_playing = FALSE;
191  org_atheme_audacious_playing(proxy, &is_playing, &error);
192  g_clear_error(&error);
193  return is_playing;
194 }
195 
204 EXPORT gboolean audacious_remote_is_paused(DBusGProxy *proxy) {
205  gboolean is_paused = FALSE;
206  org_atheme_audacious_paused(proxy, &is_paused, &error);
207  g_clear_error(&error);
208  return is_paused;
209 }
210 
219 EXPORT gint audacious_remote_get_playlist_pos(DBusGProxy *proxy) {
220  guint pos = 0;
221  org_atheme_audacious_position(proxy, &pos, &error);
222  g_clear_error(&error);
223  return pos;
224 }
225 
233 EXPORT void audacious_remote_set_playlist_pos(DBusGProxy *proxy, guint pos) {
234  org_atheme_audacious_jump (proxy, pos, &error);
235  g_clear_error(&error);
236 }
237 
246 EXPORT gint audacious_remote_get_playlist_length(DBusGProxy *proxy) {
247  gint len = 0;
248  org_atheme_audacious_length(proxy, &len, &error);
249  g_clear_error(&error);
250  return len;
251 }
252 
259 EXPORT void audacious_remote_playlist_clear(DBusGProxy *proxy) {
261  g_clear_error(&error);
262 }
263 
272 EXPORT gint audacious_remote_get_output_time(DBusGProxy *proxy) {
273  guint time = 0;
274  org_atheme_audacious_time(proxy, &time, &error);
275  g_clear_error(&error);
276  return time;
277 }
278 
286 EXPORT void audacious_remote_jump_to_time(DBusGProxy *proxy, guint pos) {
287  org_atheme_audacious_seek (proxy, pos, &error);
288  g_clear_error(&error);
289 }
290 
298 EXPORT void audacious_remote_get_volume(DBusGProxy *proxy, gint * vl, gint * vr) {
299  org_atheme_audacious_volume(proxy, vl, vr, &error);
300  g_clear_error(&error);
301 }
302 
309 EXPORT gint audacious_remote_get_main_volume(DBusGProxy *proxy) {
310  gint vl = 0, vr = 0;
311 
312  audacious_remote_get_volume(proxy, &vl, &vr);
313 
314  return (vl > vr) ? vl : vr;
315 }
316 
323 EXPORT gint audacious_remote_get_balance(DBusGProxy *proxy) {
324  gint balance = 50;
325  org_atheme_audacious_balance(proxy, &balance, &error);
326  g_clear_error(&error);
327  return balance;
328 }
329 
337 EXPORT void audacious_remote_set_volume(DBusGProxy *proxy, gint vl, gint vr) {
338  org_atheme_audacious_set_volume(proxy, vl, vr, &error);
339  g_clear_error(&error);
340 }
341 
342 
349 EXPORT void audacious_remote_set_main_volume(DBusGProxy *proxy, gint v) {
350  gint b = 50, vl = 0, vr = 0;
351 
352  b = audacious_remote_get_balance(proxy);
353 
354  if (b < 0) {
355  vl = v;
356  vr = (v * (100 - abs(b))) / 100;
357  } else if (b > 0) {
358  vl = (v * (100 - b)) / 100;
359  vr = v;
360  } else
361  vl = vr = v;
362  audacious_remote_set_volume(proxy, vl, vr);
363 }
364 
371 EXPORT void audacious_remote_set_balance(DBusGProxy *proxy, gint b) {
372  gint v = 0, vl = 0, vr = 0;
373 
374  if (b < -100)
375  b = -100;
376  if (b > 100)
377  b = 100;
378 
380 
381  if (b < 0) {
382  vl = v;
383  vr = (v * (100 - abs(b))) / 100;
384  } else if (b > 0) {
385  vl = (v * (100 - b)) / 100;
386  vr = v;
387  } else
388  vl = vr = v;
389  audacious_remote_set_volume(proxy, vl, vr);
390 }
391 
399 EXPORT gchar *audacious_remote_get_playlist_file(DBusGProxy *proxy, guint pos) {
400  gchar *out = NULL;
401  org_atheme_audacious_song_filename(proxy, pos, &out, &error);
402  g_clear_error(&error);
403  return out;
404 }
405 
413 EXPORT gchar *audacious_remote_get_playlist_title(DBusGProxy *proxy, guint pos) {
414  gchar *out = NULL;
415  org_atheme_audacious_song_title(proxy, pos, &out, &error);
416  g_clear_error(&error);
417  return out;
418 }
419 
427 EXPORT gint audacious_remote_get_playlist_time(DBusGProxy *proxy, guint pos) {
428  gint out = 0;
429  org_atheme_audacious_song_frames(proxy, pos, &out, &error);
430  g_clear_error(&error);
431  return out;
432 }
433 
442 EXPORT void audacious_remote_get_info(DBusGProxy *proxy, gint *rate, gint *freq,
443  gint *nch) {
444  org_atheme_audacious_info(proxy, rate, freq, nch, &error);
445  g_clear_error(&error);
446 }
447 
454 EXPORT void audacious_remote_main_win_toggle(DBusGProxy *proxy, gboolean show) {
456  g_clear_error(&error);
457 }
458 
465 EXPORT gboolean audacious_remote_is_main_win(DBusGProxy *proxy) {
466  gboolean visible = TRUE;
467  org_atheme_audacious_main_win_visible(proxy, &visible, &error);
468  g_clear_error(&error);
469  return visible;
470 }
471 
477 EXPORT void audacious_remote_show_prefs_box(DBusGProxy *proxy) {
479 }
480 
487 EXPORT void audacious_remote_toggle_prefs_box(DBusGProxy *proxy, gboolean show) {
489  g_clear_error(&error);
490 }
491 
497 EXPORT void audacious_remote_show_about_box(DBusGProxy *proxy) {
499 }
500 
507 EXPORT void audacious_remote_toggle_about_box(DBusGProxy *proxy, gboolean show) {
509  g_clear_error(&error);
510 }
511 
518 EXPORT void audacious_remote_toggle_aot(DBusGProxy *proxy, gboolean ontop) {
519  org_atheme_audacious_toggle_aot(proxy, ontop, &error);
520  g_clear_error(&error);
521 }
522 
528 EXPORT void audacious_remote_eject(DBusGProxy *proxy) {
530  g_clear_error(&error);
531 }
532 
539 EXPORT void audacious_remote_playlist_prev(DBusGProxy *proxy) {
541  g_clear_error(&error);
542 }
543 
549 EXPORT void audacious_remote_playlist_next(DBusGProxy *proxy) {
551  g_clear_error(&error);
552 }
553 
560 EXPORT void audacious_remote_playlist_add_url_string(DBusGProxy *proxy,
561  gchar *string) {
562  org_atheme_audacious_add_url(proxy, string, &error);
563  g_clear_error(&error);
564 }
565 
572 EXPORT gboolean audacious_remote_is_running(DBusGProxy *proxy) {
573  char *string = NULL;
574  org_atheme_audacious_version(proxy, &string, &error);
575  g_clear_error(&error);
576  if(string) {
577  g_free(string);
578  return TRUE;
579  }
580  else
581  return FALSE;
582 }
583 
589 EXPORT void audacious_remote_toggle_repeat(DBusGProxy *proxy) {
591  g_clear_error(&error);
592 }
593 
599 EXPORT void audacious_remote_toggle_shuffle(DBusGProxy *proxy) {
601  g_clear_error(&error);
602 }
603 
604 EXPORT void audacious_remote_toggle_stop_after (DBusGProxy * proxy)
605 {
607  g_clear_error (& error);
608 }
609 
616 EXPORT gboolean audacious_remote_is_repeat(DBusGProxy *proxy) {
617  gboolean is_repeat;
618  org_atheme_audacious_repeat(proxy, &is_repeat, &error);
619  g_clear_error(&error);
620  return is_repeat;
621 }
622 
629 EXPORT gboolean audacious_remote_is_shuffle(DBusGProxy *proxy) {
630  gboolean is_shuffle;
631  org_atheme_audacious_shuffle(proxy, &is_shuffle, &error);
632  g_clear_error(&error);
633  return is_shuffle;
634 }
635 
636 EXPORT gboolean audacious_remote_is_stop_after (DBusGProxy * proxy)
637 {
638  gboolean is_stop_after;
639  org_atheme_audacious_stop_after (proxy, & is_stop_after, & error);
640  g_clear_error (& error);
641  return is_stop_after;
642 }
643 
651 EXPORT void audacious_remote_get_eq(DBusGProxy *proxy, gdouble *preamp, GArray **bands) {
652  org_atheme_audacious_get_eq(proxy, preamp, bands, &error);
653  g_clear_error(&error);
654 }
655 
662 EXPORT gdouble audacious_remote_get_eq_preamp(DBusGProxy *proxy) {
663  gdouble preamp = 0.0;
664 
665  org_atheme_audacious_get_eq_preamp(proxy, &preamp, &error);
666  g_clear_error(&error);
667 
668  return preamp;
669 }
670 
678 EXPORT gdouble audacious_remote_get_eq_band(DBusGProxy *proxy, gint band) {
679  gdouble value = 0.0;
680 
681  org_atheme_audacious_get_eq_band(proxy, band, &value, &error);
682  g_clear_error(&error);
683 
684  return value;
685 }
686 
694 EXPORT void audacious_remote_set_eq(DBusGProxy *proxy, gdouble preamp, GArray *bands) {
695  org_atheme_audacious_set_eq(proxy, preamp, bands, &error);
696  g_clear_error(&error);
697 }
698 
705 EXPORT void audacious_remote_set_eq_preamp(DBusGProxy *proxy, gdouble preamp) {
706  org_atheme_audacious_set_eq_preamp(proxy, preamp, &error);
707  g_clear_error(&error);
708 }
709 
717 EXPORT void audacious_remote_set_eq_band(DBusGProxy *proxy, gint band, gdouble value) {
718  org_atheme_audacious_set_eq_band(proxy, band, value, &error);
719  g_clear_error(&error);
720 }
721 
727 EXPORT void audacious_remote_quit(DBusGProxy *proxy) {
729  g_clear_error(&error);
730 }
731 
737 EXPORT void audacious_remote_play_pause(DBusGProxy *proxy) {
739 }
740 
748 EXPORT void audacious_remote_playlist_ins_url_string(DBusGProxy *proxy,
749  gchar *string, guint pos) {
751  g_clear_error(&error);
752 }
753 
760 EXPORT void audacious_remote_playqueue_add(DBusGProxy *proxy, guint pos) {
762  g_clear_error(&error);
763 }
764 
771 EXPORT void audacious_remote_playqueue_remove(DBusGProxy *proxy, guint pos) {
773  g_clear_error(&error);
774 }
775 
784 EXPORT gint audacious_remote_get_playqueue_length(DBusGProxy *proxy) {
785  gint len = 0;
786  org_atheme_audacious_length(proxy, &len, &error);
787  g_clear_error(&error);
788  return len;
789 }
790 
796 EXPORT void audacious_remote_toggle_advance(DBusGProxy *proxy) {
798  g_clear_error(&error);
799 }
800 
809 EXPORT gboolean audacious_remote_is_advance(DBusGProxy *proxy) {
810  gboolean is_advance = FALSE;
811  org_atheme_audacious_auto_advance(proxy, &is_advance, &error);
812  g_clear_error(&error);
813  return is_advance;
814 }
815 
821 EXPORT void audacious_remote_show_jtf_box(DBusGProxy *proxy) {
823 }
824 
831 EXPORT void audacious_remote_toggle_jtf_box(DBusGProxy *proxy, gboolean show) {
833  g_clear_error(&error);
834 }
835 
842 EXPORT void audacious_remote_toggle_filebrowser(DBusGProxy *proxy, gboolean show) {
844  g_clear_error(&error);
845 }
846 
853 EXPORT void audacious_remote_playqueue_clear(DBusGProxy *proxy) {
855  g_clear_error(&error);
856 }
857 
865 EXPORT gboolean audacious_remote_playqueue_is_queued(DBusGProxy *proxy, guint pos) {
866  gboolean is_queued;
867  org_atheme_audacious_playqueue_is_queued (proxy, pos, &is_queued, &error);
868  g_clear_error(&error);
869  return is_queued;
870 }
871 
879 EXPORT gint audacious_remote_get_playqueue_queue_position(DBusGProxy *proxy, guint pos) {
880  guint qpos = 0;
881  org_atheme_audacious_queue_get_queue_pos (proxy, pos, &qpos, &error);
882  g_clear_error(&error);
883  return qpos;
884 }
885 
894 EXPORT gint audacious_remote_get_playqueue_list_position(DBusGProxy *proxy, guint qpos) {
895  guint pos = 0;
896  org_atheme_audacious_queue_get_list_pos (proxy, qpos, &pos, &error);
897  g_clear_error(&error);
898  return pos;
899 }
900 
907 EXPORT void audacious_remote_playlist_enqueue_to_temp(DBusGProxy *proxy,
908  gchar *string) {
910  g_clear_error(&error);
911 }
912 
921 EXPORT gchar *audacious_get_tuple_field_data(DBusGProxy *proxy, gchar *field,
922  guint pos) {
923  GValue value = {0};
924  gchar *s = NULL;
925 
926  org_atheme_audacious_song_tuple(proxy, pos, field, &value, &error);
927 
928  g_clear_error(&error);
929 
930  if (G_IS_VALUE(&value) == FALSE)
931  return NULL;
932 
933  /* I think the original "purpose" of using g_strescape() here
934  * has probably been to escape only \n, \t, \r, etc. but the function
935  * actually escapes all non-ASCII characters. Which is bad, since we
936  * are using UTF-8. -- ccr
937  */
938  if (G_VALUE_HOLDS_STRING(&value))
939  //s = g_strescape(g_value_get_string(&value), NULL);
940  s = g_strdup(g_value_get_string(&value));
941  else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING))
942  {
943  GValue tmp_value = { 0, };
944 
945  g_value_init(&tmp_value, G_TYPE_STRING);
946  g_value_transform(&value, &tmp_value);
947 
948  //s = g_strescape(g_value_get_string(&tmp_value), NULL);
949  s = g_strdup(g_value_get_string(&tmp_value));
950 
951  g_value_unset(&tmp_value);
952  }
953  else
954  s = g_strdup("<unknown type>");
955 
956  g_value_unset(&value);
957  return s;
958 }
959 
966 EXPORT void audacious_remote_eq_activate(DBusGProxy *proxy, gboolean active) {
968  g_clear_error(&error);
969 }
970 
977 EXPORT gchar **audacious_remote_get_tuple_fields(DBusGProxy *proxy) {
978  gchar **res = NULL;
980  g_clear_error(&error);
981  return res;
982 }
983 
987 EXPORT gchar *audacious_remote_playlist_get_active_name(DBusGProxy *proxy) {
988  char *string = NULL;
990  g_clear_error(&error);
991 
992  return (string ? string : NULL);
993 }