Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
audctrl.c
Go to the documentation of this file.
1 /*
2  * Audacious: A cross-platform multimedia player
3  * Copyright (c) 2007 Ben Tucker
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; under version 3 of the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <stdlib.h>
19 #include <glib.h>
20 #include <string.h>
21 #include <dbus/dbus-glib.h>
22 #include "audacious/dbus.h"
24 #include "audctrl.h"
25 #include "config.h"
26 
27 static GError *error = NULL; //it must be hidden from outside, otherwise symbol conflict likely to happen.
28 
38 EXPORT void audacious_remote_playlist(DBusGProxy *proxy, gchar **list, gint num, gboolean enqueue) {
39  GList *glist = NULL;
40  gchar **data = list;
41 
42  g_return_if_fail(list != NULL);
43  g_return_if_fail(num > 0);
44 
45  if (!enqueue)
47 
48  // construct a GList
49  while(data) {
50  glist = g_list_append(glist, (gpointer)data);
51  data++;
52  }
53 
54  org_atheme_audacious_playlist_add(proxy, (gpointer)glist, &error);
55 
56  g_list_free(glist);
57  glist = NULL;
58 
59  if (!enqueue)
60  audacious_remote_play(proxy);
61 }
62 
69 EXPORT gchar *audacious_remote_get_version(DBusGProxy *proxy) {
70  char *string = NULL;
71  org_atheme_audacious_version(proxy, &string, &error);
72  g_clear_error(&error);
73 
74  return (string ? string : NULL);
75 }
76 
83 EXPORT void audacious_remote_playlist_add (DBusGProxy * proxy, GList * list)
84 {
85  const gchar * filenames[g_list_length (list) + 1];
86  int count;
87 
88  for (count = 0; list != NULL; count ++, list = list->next)
89  filenames[count] = list->data;
90 
91  filenames[count] = NULL;
92 
93  org_atheme_audacious_add_list (proxy, filenames, & error);
94  g_clear_error (& error);
95 }
96 
103 EXPORT void audacious_remote_playlist_open_list (DBusGProxy * proxy, GList * list)
104 {
105  const gchar * filenames[g_list_length (list) + 1];
106  int count;
107 
108  for (count = 0; list != NULL; count ++, list = list->next)
109  filenames[count] = list->data;
110 
111  filenames[count] = NULL;
112 
113  org_atheme_audacious_open_list (proxy, filenames, & error);
114  g_clear_error (& error);
115 }
116 
124 EXPORT void audacious_remote_playlist_open_list_to_temp (DBusGProxy * proxy, GList *
125  list)
126 {
127  const gchar * filenames[g_list_length (list) + 1];
128  int count;
129 
130  for (count = 0; list != NULL; count ++, list = list->next)
131  filenames[count] = list->data;
132 
133  filenames[count] = NULL;
134 
135  org_atheme_audacious_open_list_to_temp (proxy, filenames, & error);
136  g_clear_error (& error);
137 }
138 
145 EXPORT void audacious_remote_playlist_delete(DBusGProxy *proxy, guint pos) {
146  org_atheme_audacious_delete(proxy, pos, &error);
147  g_clear_error(&error);
148 }
149 
155 EXPORT void audacious_remote_play(DBusGProxy *proxy) {
157  g_clear_error(&error);
158 }
159 
165 EXPORT void audacious_remote_pause(DBusGProxy *proxy) {
167  g_clear_error(&error);
168 }
169 
175 EXPORT void audacious_remote_stop(DBusGProxy *proxy) {
177  g_clear_error(&error);
178 }
179 
186 EXPORT gboolean audacious_remote_is_playing(DBusGProxy *proxy) {
187  gboolean is_playing = FALSE;
188  org_atheme_audacious_playing(proxy, &is_playing, &error);
189  g_clear_error(&error);
190  return is_playing;
191 }
192 
201 EXPORT gboolean audacious_remote_is_paused(DBusGProxy *proxy) {
202  gboolean is_paused = FALSE;
203  org_atheme_audacious_paused(proxy, &is_paused, &error);
204  g_clear_error(&error);
205  return is_paused;
206 }
207 
216 EXPORT gint audacious_remote_get_playlist_pos(DBusGProxy *proxy) {
217  guint pos = 0;
218  org_atheme_audacious_position(proxy, &pos, &error);
219  g_clear_error(&error);
220  return pos;
221 }
222 
230 EXPORT void audacious_remote_set_playlist_pos(DBusGProxy *proxy, guint pos) {
231  org_atheme_audacious_jump (proxy, pos, &error);
232  g_clear_error(&error);
233 }
234 
243 EXPORT gint audacious_remote_get_playlist_length(DBusGProxy *proxy) {
244  gint len = 0;
245  org_atheme_audacious_length(proxy, &len, &error);
246  g_clear_error(&error);
247  return len;
248 }
249 
256 EXPORT void audacious_remote_playlist_clear(DBusGProxy *proxy) {
258  g_clear_error(&error);
259 }
260 
269 EXPORT gint audacious_remote_get_output_time(DBusGProxy *proxy) {
270  guint time = 0;
271  org_atheme_audacious_time(proxy, &time, &error);
272  g_clear_error(&error);
273  return time;
274 }
275 
283 EXPORT void audacious_remote_jump_to_time(DBusGProxy *proxy, guint pos) {
284  org_atheme_audacious_seek (proxy, pos, &error);
285  g_clear_error(&error);
286 }
287 
295 EXPORT void audacious_remote_get_volume(DBusGProxy *proxy, gint * vl, gint * vr) {
296  org_atheme_audacious_volume(proxy, vl, vr, &error);
297  g_clear_error(&error);
298 }
299 
306 EXPORT gint audacious_remote_get_main_volume(DBusGProxy *proxy) {
307  gint vl = 0, vr = 0;
308 
309  audacious_remote_get_volume(proxy, &vl, &vr);
310 
311  return (vl > vr) ? vl : vr;
312 }
313 
320 EXPORT gint audacious_remote_get_balance(DBusGProxy *proxy) {
321  gint balance = 50;
322  org_atheme_audacious_balance(proxy, &balance, &error);
323  g_clear_error(&error);
324  return balance;
325 }
326 
334 EXPORT void audacious_remote_set_volume(DBusGProxy *proxy, gint vl, gint vr) {
335  org_atheme_audacious_set_volume(proxy, vl, vr, &error);
336  g_clear_error(&error);
337 }
338 
339 
346 EXPORT void audacious_remote_set_main_volume(DBusGProxy *proxy, gint v) {
347  gint b = 50, vl = 0, vr = 0;
348 
349  b = audacious_remote_get_balance(proxy);
350 
351  if (b < 0) {
352  vl = v;
353  vr = (v * (100 - abs(b))) / 100;
354  } else if (b > 0) {
355  vl = (v * (100 - b)) / 100;
356  vr = v;
357  } else
358  vl = vr = v;
359  audacious_remote_set_volume(proxy, vl, vr);
360 }
361 
368 EXPORT void audacious_remote_set_balance(DBusGProxy *proxy, gint b) {
369  gint v = 0, vl = 0, vr = 0;
370 
371  if (b < -100)
372  b = -100;
373  if (b > 100)
374  b = 100;
375 
377 
378  if (b < 0) {
379  vl = v;
380  vr = (v * (100 - abs(b))) / 100;
381  } else if (b > 0) {
382  vl = (v * (100 - b)) / 100;
383  vr = v;
384  } else
385  vl = vr = v;
386  audacious_remote_set_volume(proxy, vl, vr);
387 }
388 
396 EXPORT gchar *audacious_remote_get_playlist_file(DBusGProxy *proxy, guint pos) {
397  gchar *out = NULL;
398  org_atheme_audacious_song_filename(proxy, pos, &out, &error);
399  g_clear_error(&error);
400  return out;
401 }
402 
410 EXPORT gchar *audacious_remote_get_playlist_title(DBusGProxy *proxy, guint pos) {
411  gchar *out = NULL;
412  org_atheme_audacious_song_title(proxy, pos, &out, &error);
413  g_clear_error(&error);
414  return out;
415 }
416 
424 EXPORT gint audacious_remote_get_playlist_time(DBusGProxy *proxy, guint pos) {
425  gint out = 0;
426  org_atheme_audacious_song_frames(proxy, pos, &out, &error);
427  g_clear_error(&error);
428  return out;
429 }
430 
439 EXPORT void audacious_remote_get_info(DBusGProxy *proxy, gint *rate, gint *freq,
440  gint *nch) {
441  org_atheme_audacious_info(proxy, rate, freq, nch, &error);
442  g_clear_error(&error);
443 }
444 
451 EXPORT void audacious_remote_main_win_toggle(DBusGProxy *proxy, gboolean show) {
453  g_clear_error(&error);
454 }
455 
462 EXPORT gboolean audacious_remote_is_main_win(DBusGProxy *proxy) {
463  gboolean visible = TRUE;
464  org_atheme_audacious_main_win_visible(proxy, &visible, &error);
465  g_clear_error(&error);
466  return visible;
467 }
468 
474 EXPORT void audacious_remote_show_prefs_box(DBusGProxy *proxy) {
476 }
477 
484 EXPORT void audacious_remote_toggle_prefs_box(DBusGProxy *proxy, gboolean show) {
486  g_clear_error(&error);
487 }
488 
494 EXPORT void audacious_remote_show_about_box(DBusGProxy *proxy) {
496 }
497 
504 EXPORT void audacious_remote_toggle_about_box(DBusGProxy *proxy, gboolean show) {
506  g_clear_error(&error);
507 }
508 
515 EXPORT void audacious_remote_toggle_aot(DBusGProxy *proxy, gboolean ontop) {
516  org_atheme_audacious_toggle_aot(proxy, ontop, &error);
517  g_clear_error(&error);
518 }
519 
525 EXPORT void audacious_remote_eject(DBusGProxy *proxy) {
527  g_clear_error(&error);
528 }
529 
536 EXPORT void audacious_remote_playlist_prev(DBusGProxy *proxy) {
538  g_clear_error(&error);
539 }
540 
546 EXPORT void audacious_remote_playlist_next(DBusGProxy *proxy) {
548  g_clear_error(&error);
549 }
550 
557 EXPORT void audacious_remote_playlist_add_url_string(DBusGProxy *proxy,
558  gchar *string) {
559  org_atheme_audacious_add_url(proxy, string, &error);
560  g_clear_error(&error);
561 }
562 
569 EXPORT gboolean audacious_remote_is_running(DBusGProxy *proxy) {
570  char *string = NULL;
571  org_atheme_audacious_version(proxy, &string, &error);
572  g_clear_error(&error);
573  if(string) {
574  g_free(string);
575  return TRUE;
576  }
577  else
578  return FALSE;
579 }
580 
586 EXPORT void audacious_remote_toggle_repeat(DBusGProxy *proxy) {
588  g_clear_error(&error);
589 }
590 
596 EXPORT void audacious_remote_toggle_shuffle(DBusGProxy *proxy) {
598  g_clear_error(&error);
599 }
600 
601 EXPORT void audacious_remote_toggle_stop_after (DBusGProxy * proxy)
602 {
604  g_clear_error (& error);
605 }
606 
613 EXPORT gboolean audacious_remote_is_repeat(DBusGProxy *proxy) {
614  gboolean is_repeat;
615  org_atheme_audacious_repeat(proxy, &is_repeat, &error);
616  g_clear_error(&error);
617  return is_repeat;
618 }
619 
626 EXPORT gboolean audacious_remote_is_shuffle(DBusGProxy *proxy) {
627  gboolean is_shuffle;
628  org_atheme_audacious_shuffle(proxy, &is_shuffle, &error);
629  g_clear_error(&error);
630  return is_shuffle;
631 }
632 
633 EXPORT gboolean audacious_remote_is_stop_after (DBusGProxy * proxy)
634 {
635  gboolean is_stop_after;
636  org_atheme_audacious_stop_after (proxy, & is_stop_after, & error);
637  g_clear_error (& error);
638  return is_stop_after;
639 }
640 
648 EXPORT void audacious_remote_get_eq(DBusGProxy *proxy, gdouble *preamp, GArray **bands) {
649  org_atheme_audacious_get_eq(proxy, preamp, bands, &error);
650  g_clear_error(&error);
651 }
652 
659 EXPORT gdouble audacious_remote_get_eq_preamp(DBusGProxy *proxy) {
660  gdouble preamp = 0.0;
661 
662  org_atheme_audacious_get_eq_preamp(proxy, &preamp, &error);
663  g_clear_error(&error);
664 
665  return preamp;
666 }
667 
675 EXPORT gdouble audacious_remote_get_eq_band(DBusGProxy *proxy, gint band) {
676  gdouble value = 0.0;
677 
678  org_atheme_audacious_get_eq_band(proxy, band, &value, &error);
679  g_clear_error(&error);
680 
681  return value;
682 }
683 
691 EXPORT void audacious_remote_set_eq(DBusGProxy *proxy, gdouble preamp, GArray *bands) {
692  org_atheme_audacious_set_eq(proxy, preamp, bands, &error);
693  g_clear_error(&error);
694 }
695 
702 EXPORT void audacious_remote_set_eq_preamp(DBusGProxy *proxy, gdouble preamp) {
703  org_atheme_audacious_set_eq_preamp(proxy, preamp, &error);
704  g_clear_error(&error);
705 }
706 
714 EXPORT void audacious_remote_set_eq_band(DBusGProxy *proxy, gint band, gdouble value) {
715  org_atheme_audacious_set_eq_band(proxy, band, value, &error);
716  g_clear_error(&error);
717 }
718 
724 EXPORT void audacious_remote_quit(DBusGProxy *proxy) {
726  g_clear_error(&error);
727 }
728 
734 EXPORT void audacious_remote_play_pause(DBusGProxy *proxy) {
736 }
737 
745 EXPORT void audacious_remote_playlist_ins_url_string(DBusGProxy *proxy,
746  gchar *string, guint pos) {
748  g_clear_error(&error);
749 }
750 
757 EXPORT void audacious_remote_playqueue_add(DBusGProxy *proxy, guint pos) {
759  g_clear_error(&error);
760 }
761 
768 EXPORT void audacious_remote_playqueue_remove(DBusGProxy *proxy, guint pos) {
770  g_clear_error(&error);
771 }
772 
781 EXPORT gint audacious_remote_get_playqueue_length(DBusGProxy *proxy) {
782  gint len = 0;
783  org_atheme_audacious_length(proxy, &len, &error);
784  g_clear_error(&error);
785  return len;
786 }
787 
793 EXPORT void audacious_remote_toggle_advance(DBusGProxy *proxy) {
795  g_clear_error(&error);
796 }
797 
806 EXPORT gboolean audacious_remote_is_advance(DBusGProxy *proxy) {
807  gboolean is_advance = FALSE;
808  org_atheme_audacious_auto_advance(proxy, &is_advance, &error);
809  g_clear_error(&error);
810  return is_advance;
811 }
812 
818 EXPORT void audacious_remote_show_jtf_box(DBusGProxy *proxy) {
820 }
821 
828 EXPORT void audacious_remote_toggle_jtf_box(DBusGProxy *proxy, gboolean show) {
830  g_clear_error(&error);
831 }
832 
839 EXPORT void audacious_remote_toggle_filebrowser(DBusGProxy *proxy, gboolean show) {
841  g_clear_error(&error);
842 }
843 
850 EXPORT void audacious_remote_playqueue_clear(DBusGProxy *proxy) {
852  g_clear_error(&error);
853 }
854 
862 EXPORT gboolean audacious_remote_playqueue_is_queued(DBusGProxy *proxy, guint pos) {
863  gboolean is_queued;
864  org_atheme_audacious_playqueue_is_queued (proxy, pos, &is_queued, &error);
865  g_clear_error(&error);
866  return is_queued;
867 }
868 
876 EXPORT gint audacious_remote_get_playqueue_queue_position(DBusGProxy *proxy, guint pos) {
877  guint qpos = 0;
878  org_atheme_audacious_queue_get_queue_pos (proxy, pos, &qpos, &error);
879  g_clear_error(&error);
880  return qpos;
881 }
882 
891 EXPORT gint audacious_remote_get_playqueue_list_position(DBusGProxy *proxy, guint qpos) {
892  guint pos = 0;
893  org_atheme_audacious_queue_get_list_pos (proxy, qpos, &pos, &error);
894  g_clear_error(&error);
895  return pos;
896 }
897 
904 EXPORT void audacious_remote_playlist_enqueue_to_temp(DBusGProxy *proxy,
905  gchar *string) {
907  g_clear_error(&error);
908 }
909 
918 EXPORT gchar *audacious_get_tuple_field_data(DBusGProxy *proxy, gchar *field,
919  guint pos) {
920  GValue value = {0};
921  gchar *s = NULL;
922 
923  org_atheme_audacious_song_tuple(proxy, pos, field, &value, &error);
924 
925  g_clear_error(&error);
926 
927  if (G_IS_VALUE(&value) == FALSE)
928  return NULL;
929 
930  /* I think the original "purpose" of using g_strescape() here
931  * has probably been to escape only \n, \t, \r, etc. but the function
932  * actually escapes all non-ASCII characters. Which is bad, since we
933  * are using UTF-8. -- ccr
934  */
935  if (G_VALUE_HOLDS_STRING(&value))
936  //s = g_strescape(g_value_get_string(&value), NULL);
937  s = g_strdup(g_value_get_string(&value));
938  else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING))
939  {
940  GValue tmp_value = { 0, };
941 
942  g_value_init(&tmp_value, G_TYPE_STRING);
943  g_value_transform(&value, &tmp_value);
944 
945  //s = g_strescape(g_value_get_string(&tmp_value), NULL);
946  s = g_strdup(g_value_get_string(&tmp_value));
947 
948  g_value_unset(&tmp_value);
949  }
950  else
951  s = g_strdup("<unknown type>");
952 
953  g_value_unset(&value);
954  return s;
955 }
956 
963 EXPORT void audacious_remote_eq_activate(DBusGProxy *proxy, gboolean active) {
965  g_clear_error(&error);
966 }
967 
974 EXPORT gchar **audacious_remote_get_tuple_fields(DBusGProxy *proxy) {
975  gchar **res = NULL;
977  g_clear_error(&error);
978  return res;
979 }
980 
984 EXPORT gchar *audacious_remote_playlist_get_active_name(DBusGProxy *proxy) {
985  char *string = NULL;
987  g_clear_error(&error);
988 
989  return (string ? string : NULL);
990 }