00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef HAVE_CONFIG_H
00019 # include "config.h"
00020 #endif
00021
00022 #include <stdlib.h>
00023 #include <glib.h>
00024 #include <string.h>
00025 #include <dbus/dbus-glib.h>
00026 #include "audacious/dbus.h"
00027 #include "audacious/dbus-client-bindings.h"
00028 #include "audctrl.h"
00029
00030 static GError *error = NULL;
00031
00041 void audacious_remote_playlist(DBusGProxy *proxy, gchar **list, gint num, gboolean enqueue) {
00042 GList *glist = NULL;
00043 gchar **data = list;
00044
00045 g_return_if_fail(list != NULL);
00046 g_return_if_fail(num > 0);
00047
00048 if (!enqueue)
00049 audacious_remote_playlist_clear(proxy);
00050
00051
00052 while(data) {
00053 glist = g_list_append(glist, (gpointer)data);
00054 data++;
00055 }
00056
00057 org_atheme_audacious_playlist_add(proxy, (gpointer)glist, &error);
00058
00059 g_list_free(glist);
00060 glist = NULL;
00061
00062 if (!enqueue)
00063 audacious_remote_play(proxy);
00064 }
00065
00072 gchar *audacious_remote_get_version(DBusGProxy *proxy) {
00073 char *string = NULL;
00074 org_atheme_audacious_version(proxy, &string, &error);
00075 g_clear_error(&error);
00076
00077 return (string ? string : NULL);
00078 }
00079
00086 void audacious_remote_playlist_add (DBusGProxy * proxy, GList * list)
00087 {
00088 const gchar * filenames[g_list_length (list) + 1];
00089 int count;
00090
00091 for (count = 0; list != NULL; count ++, list = list->next)
00092 filenames[count] = list->data;
00093
00094 filenames[count] = NULL;
00095
00096 org_atheme_audacious_add_list (proxy, filenames, & error);
00097 g_clear_error (& error);
00098 }
00099
00106 void audacious_remote_playlist_open_list (DBusGProxy * proxy, GList * list)
00107 {
00108 const gchar * filenames[g_list_length (list) + 1];
00109 int count;
00110
00111 for (count = 0; list != NULL; count ++, list = list->next)
00112 filenames[count] = list->data;
00113
00114 filenames[count] = NULL;
00115
00116 org_atheme_audacious_open_list (proxy, filenames, & error);
00117 g_clear_error (& error);
00118 }
00119
00127 void audacious_remote_playlist_open_list_to_temp (DBusGProxy * proxy, GList *
00128 list)
00129 {
00130 const gchar * filenames[g_list_length (list) + 1];
00131 int count;
00132
00133 for (count = 0; list != NULL; count ++, list = list->next)
00134 filenames[count] = list->data;
00135
00136 filenames[count] = NULL;
00137
00138 org_atheme_audacious_open_list_to_temp (proxy, filenames, & error);
00139 g_clear_error (& error);
00140 }
00141
00148 void audacious_remote_playlist_delete(DBusGProxy *proxy, guint pos) {
00149 org_atheme_audacious_delete(proxy, pos, &error);
00150 g_clear_error(&error);
00151 }
00152
00158 void audacious_remote_play(DBusGProxy *proxy) {
00159 org_atheme_audacious_play(proxy, &error);
00160 g_clear_error(&error);
00161 }
00162
00168 void audacious_remote_pause(DBusGProxy *proxy) {
00169 org_atheme_audacious_pause(proxy, &error);
00170 g_clear_error(&error);
00171 }
00172
00178 void audacious_remote_stop(DBusGProxy *proxy) {
00179 org_atheme_audacious_stop(proxy, &error);
00180 g_clear_error(&error);
00181 }
00182
00189 gboolean audacious_remote_is_playing(DBusGProxy *proxy) {
00190 gboolean is_playing = FALSE;
00191 org_atheme_audacious_playing(proxy, &is_playing, &error);
00192 g_clear_error(&error);
00193 return is_playing;
00194 }
00195
00204 gboolean audacious_remote_is_paused(DBusGProxy *proxy) {
00205 gboolean is_paused = FALSE;
00206 org_atheme_audacious_paused(proxy, &is_paused, &error);
00207 g_clear_error(&error);
00208 return is_paused;
00209 }
00210
00219 gint audacious_remote_get_playlist_pos(DBusGProxy *proxy) {
00220 guint pos = 0;
00221 org_atheme_audacious_position(proxy, &pos, &error);
00222 g_clear_error(&error);
00223 return pos;
00224 }
00225
00233 void audacious_remote_set_playlist_pos(DBusGProxy *proxy, guint pos) {
00234 org_atheme_audacious_jump (proxy, pos, &error);
00235 g_clear_error(&error);
00236 }
00237
00246 gint audacious_remote_get_playlist_length(DBusGProxy *proxy) {
00247 gint len = 0;
00248 org_atheme_audacious_length(proxy, &len, &error);
00249 g_clear_error(&error);
00250 return len;
00251 }
00252
00259 void audacious_remote_playlist_clear(DBusGProxy *proxy) {
00260 org_atheme_audacious_clear(proxy, &error);
00261 g_clear_error(&error);
00262 }
00263
00272 gint audacious_remote_get_output_time(DBusGProxy *proxy) {
00273 guint time = 0;
00274 org_atheme_audacious_time(proxy, &time, &error);
00275 g_clear_error(&error);
00276 return time;
00277 }
00278
00286 void audacious_remote_jump_to_time(DBusGProxy *proxy, guint pos) {
00287 org_atheme_audacious_seek (proxy, pos, &error);
00288 g_clear_error(&error);
00289 }
00290
00298 void audacious_remote_get_volume(DBusGProxy *proxy, gint * vl, gint * vr) {
00299 org_atheme_audacious_volume(proxy, vl, vr, &error);
00300 g_clear_error(&error);
00301 }
00302
00309 gint audacious_remote_get_main_volume(DBusGProxy *proxy) {
00310 gint vl = 0, vr = 0;
00311
00312 audacious_remote_get_volume(proxy, &vl, &vr);
00313
00314 return (vl > vr) ? vl : vr;
00315 }
00316
00323 gint audacious_remote_get_balance(DBusGProxy *proxy) {
00324 gint balance = 50;
00325 org_atheme_audacious_balance(proxy, &balance, &error);
00326 g_clear_error(&error);
00327 return balance;
00328 }
00329
00337 void audacious_remote_set_volume(DBusGProxy *proxy, gint vl, gint vr) {
00338 org_atheme_audacious_set_volume(proxy, vl, vr, &error);
00339 g_clear_error(&error);
00340 }
00341
00342
00349 void audacious_remote_set_main_volume(DBusGProxy *proxy, gint v) {
00350 gint b = 50, vl = 0, vr = 0;
00351
00352 b = audacious_remote_get_balance(proxy);
00353
00354 if (b < 0) {
00355 vl = v;
00356 vr = (v * (100 - abs(b))) / 100;
00357 } else if (b > 0) {
00358 vl = (v * (100 - b)) / 100;
00359 vr = v;
00360 } else
00361 vl = vr = v;
00362 audacious_remote_set_volume(proxy, vl, vr);
00363 }
00364
00371 void audacious_remote_set_balance(DBusGProxy *proxy, gint b) {
00372 gint v = 0, vl = 0, vr = 0;
00373
00374 if (b < -100)
00375 b = -100;
00376 if (b > 100)
00377 b = 100;
00378
00379 v = audacious_remote_get_main_volume(proxy);
00380
00381 if (b < 0) {
00382 vl = v;
00383 vr = (v * (100 - abs(b))) / 100;
00384 } else if (b > 0) {
00385 vl = (v * (100 - b)) / 100;
00386 vr = v;
00387 } else
00388 vl = vr = v;
00389 audacious_remote_set_volume(proxy, vl, vr);
00390 }
00391
00399 gchar *audacious_remote_get_playlist_file(DBusGProxy *proxy, guint pos) {
00400 gchar *out = NULL;
00401 org_atheme_audacious_song_filename(proxy, pos, &out, &error);
00402 g_clear_error(&error);
00403 return out;
00404 }
00405
00413 gchar *audacious_remote_get_playlist_title(DBusGProxy *proxy, guint pos) {
00414 gchar *out = NULL;
00415 org_atheme_audacious_song_title(proxy, pos, &out, &error);
00416 g_clear_error(&error);
00417 return out;
00418 }
00419
00427 gint audacious_remote_get_playlist_time(DBusGProxy *proxy, guint pos) {
00428 gint out = 0;
00429 org_atheme_audacious_song_frames(proxy, pos, &out, &error);
00430 g_clear_error(&error);
00431 return out;
00432 }
00433
00442 void audacious_remote_get_info(DBusGProxy *proxy, gint *rate, gint *freq,
00443 gint *nch) {
00444 org_atheme_audacious_info(proxy, rate, freq, nch, &error);
00445 g_clear_error(&error);
00446 }
00447
00454 void audacious_remote_main_win_toggle(DBusGProxy *proxy, gboolean show) {
00455 org_atheme_audacious_show_main_win(proxy, show, &error);
00456 g_clear_error(&error);
00457 }
00458
00465 gboolean audacious_remote_is_main_win(DBusGProxy *proxy) {
00466 gboolean visible = TRUE;
00467 org_atheme_audacious_main_win_visible(proxy, &visible, &error);
00468 g_clear_error(&error);
00469 return visible;
00470 }
00471
00477 void audacious_remote_show_prefs_box(DBusGProxy *proxy) {
00478 audacious_remote_toggle_prefs_box(proxy, TRUE);
00479 }
00480
00487 void audacious_remote_toggle_prefs_box(DBusGProxy *proxy, gboolean show) {
00488 org_atheme_audacious_show_prefs_box(proxy, show, &error);
00489 g_clear_error(&error);
00490 }
00491
00497 void audacious_remote_show_about_box(DBusGProxy *proxy) {
00498 audacious_remote_toggle_about_box(proxy, TRUE);
00499 }
00500
00507 void audacious_remote_toggle_about_box(DBusGProxy *proxy, gboolean show) {
00508 org_atheme_audacious_show_about_box(proxy, show, &error);
00509 g_clear_error(&error);
00510 }
00511
00518 void audacious_remote_toggle_aot(DBusGProxy *proxy, gboolean ontop) {
00519 org_atheme_audacious_toggle_aot(proxy, ontop, &error);
00520 g_clear_error(&error);
00521 }
00522
00528 void audacious_remote_eject(DBusGProxy *proxy) {
00529 org_atheme_audacious_eject(proxy, &error);
00530 g_clear_error(&error);
00531 }
00532
00539 void audacious_remote_playlist_prev(DBusGProxy *proxy) {
00540 org_atheme_audacious_reverse(proxy, &error);
00541 g_clear_error(&error);
00542 }
00543
00549 void audacious_remote_playlist_next(DBusGProxy *proxy) {
00550 org_atheme_audacious_advance(proxy, &error);
00551 g_clear_error(&error);
00552 }
00553
00560 void audacious_remote_playlist_add_url_string(DBusGProxy *proxy,
00561 gchar *string) {
00562 org_atheme_audacious_add_url(proxy, string, &error);
00563 g_clear_error(&error);
00564 }
00565
00572 gboolean audacious_remote_is_running(DBusGProxy *proxy) {
00573 char *string = NULL;
00574 org_atheme_audacious_version(proxy, &string, &error);
00575 g_clear_error(&error);
00576 if(string) {
00577 g_free(string);
00578 return TRUE;
00579 }
00580 else
00581 return FALSE;
00582 }
00583
00589 void audacious_remote_toggle_repeat(DBusGProxy *proxy) {
00590 org_atheme_audacious_toggle_repeat(proxy, &error);
00591 g_clear_error(&error);
00592 }
00593
00599 void audacious_remote_toggle_shuffle(DBusGProxy *proxy) {
00600 org_atheme_audacious_toggle_shuffle (proxy, &error);
00601 g_clear_error(&error);
00602 }
00603
00604 void audacious_remote_toggle_stop_after (DBusGProxy * proxy)
00605 {
00606 org_atheme_audacious_toggle_stop_after (proxy, & error);
00607 g_clear_error (& error);
00608 }
00609
00616 gboolean audacious_remote_is_repeat(DBusGProxy *proxy) {
00617 gboolean is_repeat;
00618 org_atheme_audacious_repeat(proxy, &is_repeat, &error);
00619 g_clear_error(&error);
00620 return is_repeat;
00621 }
00622
00629 gboolean audacious_remote_is_shuffle(DBusGProxy *proxy) {
00630 gboolean is_shuffle;
00631 org_atheme_audacious_shuffle(proxy, &is_shuffle, &error);
00632 g_clear_error(&error);
00633 return is_shuffle;
00634 }
00635
00636 gboolean audacious_remote_is_stop_after (DBusGProxy * proxy)
00637 {
00638 gboolean is_stop_after;
00639 org_atheme_audacious_stop_after (proxy, & is_stop_after, & error);
00640 g_clear_error (& error);
00641 return is_stop_after;
00642 }
00643
00651 void audacious_remote_get_eq(DBusGProxy *proxy, gdouble *preamp, GArray **bands) {
00652 org_atheme_audacious_get_eq(proxy, preamp, bands, &error);
00653 g_clear_error(&error);
00654 }
00655
00662 gdouble audacious_remote_get_eq_preamp(DBusGProxy *proxy) {
00663 gdouble preamp = 0.0;
00664
00665 org_atheme_audacious_get_eq_preamp(proxy, &preamp, &error);
00666 g_clear_error(&error);
00667
00668 return preamp;
00669 }
00670
00678 gdouble audacious_remote_get_eq_band(DBusGProxy *proxy, gint band) {
00679 gdouble value = 0.0;
00680
00681 org_atheme_audacious_get_eq_band(proxy, band, &value, &error);
00682 g_clear_error(&error);
00683
00684 return value;
00685 }
00686
00694 void audacious_remote_set_eq(DBusGProxy *proxy, gdouble preamp, GArray *bands) {
00695 org_atheme_audacious_set_eq(proxy, preamp, bands, &error);
00696 g_clear_error(&error);
00697 }
00698
00705 void audacious_remote_set_eq_preamp(DBusGProxy *proxy, gdouble preamp) {
00706 org_atheme_audacious_set_eq_preamp(proxy, preamp, &error);
00707 g_clear_error(&error);
00708 }
00709
00717 void audacious_remote_set_eq_band(DBusGProxy *proxy, gint band, gdouble value) {
00718 org_atheme_audacious_set_eq_band(proxy, band, value, &error);
00719 g_clear_error(&error);
00720 }
00721
00727 void audacious_remote_quit(DBusGProxy *proxy) {
00728 org_atheme_audacious_quit(proxy, &error);
00729 g_clear_error(&error);
00730 }
00731
00737 void audacious_remote_play_pause(DBusGProxy *proxy) {
00738 org_atheme_audacious_play_pause(proxy, &error);
00739 }
00740
00748 void audacious_remote_playlist_ins_url_string(DBusGProxy *proxy,
00749 gchar *string, guint pos) {
00750 org_atheme_audacious_playlist_ins_url_string (proxy, string, pos, &error);
00751 g_clear_error(&error);
00752 }
00753
00760 void audacious_remote_playqueue_add(DBusGProxy *proxy, guint pos) {
00761 org_atheme_audacious_playqueue_add (proxy, pos, &error);
00762 g_clear_error(&error);
00763 }
00764
00771 void audacious_remote_playqueue_remove(DBusGProxy *proxy, guint pos) {
00772 org_atheme_audacious_playqueue_remove (proxy, pos, &error);
00773 g_clear_error(&error);
00774 }
00775
00784 gint audacious_remote_get_playqueue_length(DBusGProxy *proxy) {
00785 gint len = 0;
00786 org_atheme_audacious_length(proxy, &len, &error);
00787 g_clear_error(&error);
00788 return len;
00789 }
00790
00796 void audacious_remote_toggle_advance(DBusGProxy *proxy) {
00797 org_atheme_audacious_toggle_auto_advance(proxy, &error);
00798 g_clear_error(&error);
00799 }
00800
00809 gboolean audacious_remote_is_advance(DBusGProxy *proxy) {
00810 gboolean is_advance = FALSE;
00811 org_atheme_audacious_auto_advance(proxy, &is_advance, &error);
00812 g_clear_error(&error);
00813 return is_advance;
00814 }
00815
00821 void audacious_remote_show_jtf_box(DBusGProxy *proxy) {
00822 audacious_remote_toggle_jtf_box(proxy, TRUE);
00823 }
00824
00831 void audacious_remote_toggle_jtf_box(DBusGProxy *proxy, gboolean show) {
00832 org_atheme_audacious_show_jtf_box(proxy, show, &error);
00833 g_clear_error(&error);
00834 }
00835
00842 void audacious_remote_toggle_filebrowser(DBusGProxy *proxy, gboolean show) {
00843 org_atheme_audacious_show_filebrowser(proxy, show, &error);
00844 g_clear_error(&error);
00845 }
00846
00853 void audacious_remote_playqueue_clear(DBusGProxy *proxy) {
00854 org_atheme_audacious_playqueue_clear(proxy, &error);
00855 g_clear_error(&error);
00856 }
00857
00865 gboolean audacious_remote_playqueue_is_queued(DBusGProxy *proxy, guint pos) {
00866 gboolean is_queued;
00867 org_atheme_audacious_playqueue_is_queued (proxy, pos, &is_queued, &error);
00868 g_clear_error(&error);
00869 return is_queued;
00870 }
00871
00879 gint audacious_remote_get_playqueue_queue_position(DBusGProxy *proxy, guint pos) {
00880 guint qpos = 0;
00881 org_atheme_audacious_queue_get_queue_pos (proxy, pos, &qpos, &error);
00882 g_clear_error(&error);
00883 return qpos;
00884 }
00885
00894 gint audacious_remote_get_playqueue_list_position(DBusGProxy *proxy, guint qpos) {
00895 guint pos = 0;
00896 org_atheme_audacious_queue_get_list_pos (proxy, qpos, &pos, &error);
00897 g_clear_error(&error);
00898 return pos;
00899 }
00900
00907 void audacious_remote_playlist_enqueue_to_temp(DBusGProxy *proxy,
00908 gchar *string) {
00909 org_atheme_audacious_playlist_enqueue_to_temp(proxy, string, &error);
00910 g_clear_error(&error);
00911 }
00912
00921 gchar *audacious_get_tuple_field_data(DBusGProxy *proxy, gchar *field,
00922 guint pos) {
00923 GValue value = {0};
00924 gchar *s = NULL;
00925
00926 org_atheme_audacious_song_tuple(proxy, pos, field, &value, &error);
00927
00928 g_clear_error(&error);
00929
00930 if (G_IS_VALUE(&value) == FALSE)
00931 return NULL;
00932
00933
00934
00935
00936
00937
00938 if (G_VALUE_HOLDS_STRING(&value))
00939
00940 s = g_strdup(g_value_get_string(&value));
00941 else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING))
00942 {
00943 GValue tmp_value = { 0, };
00944
00945 g_value_init(&tmp_value, G_TYPE_STRING);
00946 g_value_transform(&value, &tmp_value);
00947
00948
00949 s = g_strdup(g_value_get_string(&tmp_value));
00950
00951 g_value_unset(&tmp_value);
00952 }
00953 else
00954 s = g_strdup("<unknown type>");
00955
00956 g_value_unset(&value);
00957 return s;
00958 }
00959
00966 void audacious_remote_eq_activate(DBusGProxy *proxy, gboolean active) {
00967 org_atheme_audacious_equalizer_activate (proxy, active, &error);
00968 g_clear_error(&error);
00969 }
00970
00977 gchar **audacious_remote_get_tuple_fields(DBusGProxy *proxy) {
00978 gchar **res = NULL;
00979 org_atheme_audacious_get_tuple_fields (proxy, &res, &error);
00980 g_clear_error(&error);
00981 return res;
00982 }
00983
00987 gchar *audacious_remote_playlist_get_active_name(DBusGProxy *proxy) {
00988 char *string = NULL;
00989 org_atheme_audacious_get_active_playlist_name (proxy, &string, &error);
00990 g_clear_error(&error);
00991
00992 return (string ? string : NULL);
00993 }