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 void audacious_remote_pl_win_toggle(DBusGProxy *proxy, gboolean show) {
00466 org_atheme_audacious_show_playlist(proxy, show, &error);
00467 g_clear_error(&error);
00468 }
00469
00476 void audacious_remote_eq_win_toggle(DBusGProxy *proxy, gboolean show) {
00477 org_atheme_audacious_show_equalizer(proxy, show, &error);
00478 g_clear_error(&error);
00479 }
00480
00487 gboolean audacious_remote_is_main_win(DBusGProxy *proxy) {
00488 gboolean visible = TRUE;
00489 org_atheme_audacious_main_win_visible(proxy, &visible, &error);
00490 g_clear_error(&error);
00491 return visible;
00492 }
00493
00500 gboolean audacious_remote_is_pl_win(DBusGProxy *proxy) {
00501 gboolean visible = TRUE;
00502 org_atheme_audacious_playlist_visible(proxy, &visible, &error);
00503 g_clear_error(&error);
00504 return visible;
00505 }
00506
00513 gboolean audacious_remote_is_eq_win(DBusGProxy *proxy) {
00514 gboolean visible = FALSE;
00515 org_atheme_audacious_equalizer_visible(proxy, &visible, &error);
00516 g_clear_error(&error);
00517 return visible;
00518 }
00519
00525 void audacious_remote_show_prefs_box(DBusGProxy *proxy) {
00526 audacious_remote_toggle_prefs_box(proxy, TRUE);
00527 }
00528
00535 void audacious_remote_toggle_prefs_box(DBusGProxy *proxy, gboolean show) {
00536 org_atheme_audacious_show_prefs_box(proxy, show, &error);
00537 g_clear_error(&error);
00538 }
00539
00545 void audacious_remote_show_about_box(DBusGProxy *proxy) {
00546 audacious_remote_toggle_about_box(proxy, TRUE);
00547 }
00548
00555 void audacious_remote_toggle_about_box(DBusGProxy *proxy, gboolean show) {
00556 org_atheme_audacious_show_about_box(proxy, show, &error);
00557 g_clear_error(&error);
00558 }
00559
00566 void audacious_remote_toggle_aot(DBusGProxy *proxy, gboolean ontop) {
00567 org_atheme_audacious_toggle_aot(proxy, ontop, &error);
00568 g_clear_error(&error);
00569 }
00570
00576 void audacious_remote_eject(DBusGProxy *proxy) {
00577 org_atheme_audacious_eject(proxy, &error);
00578 g_clear_error(&error);
00579 }
00580
00587 void audacious_remote_playlist_prev(DBusGProxy *proxy) {
00588 org_atheme_audacious_reverse(proxy, &error);
00589 g_clear_error(&error);
00590 }
00591
00597 void audacious_remote_playlist_next(DBusGProxy *proxy) {
00598 org_atheme_audacious_advance(proxy, &error);
00599 g_clear_error(&error);
00600 }
00601
00608 void audacious_remote_playlist_add_url_string(DBusGProxy *proxy,
00609 gchar *string) {
00610 org_atheme_audacious_add_url(proxy, string, &error);
00611 g_clear_error(&error);
00612 }
00613
00620 gboolean audacious_remote_is_running(DBusGProxy *proxy) {
00621 char *string = NULL;
00622 org_atheme_audacious_version(proxy, &string, &error);
00623 g_clear_error(&error);
00624 if(string) {
00625 g_free(string);
00626 return TRUE;
00627 }
00628 else
00629 return FALSE;
00630 }
00631
00637 void audacious_remote_toggle_repeat(DBusGProxy *proxy) {
00638 org_atheme_audacious_toggle_repeat(proxy, &error);
00639 g_clear_error(&error);
00640 }
00641
00647 void audacious_remote_toggle_shuffle(DBusGProxy *proxy) {
00648 org_atheme_audacious_toggle_shuffle (proxy, &error);
00649 g_clear_error(&error);
00650 }
00651
00658 gboolean audacious_remote_is_repeat(DBusGProxy *proxy) {
00659 gboolean is_repeat;
00660 org_atheme_audacious_repeat(proxy, &is_repeat, &error);
00661 g_clear_error(&error);
00662 return is_repeat;
00663 }
00664
00671 gboolean audacious_remote_is_shuffle(DBusGProxy *proxy) {
00672 gboolean is_shuffle;
00673 org_atheme_audacious_shuffle(proxy, &is_shuffle, &error);
00674 g_clear_error(&error);
00675 return is_shuffle;
00676 }
00677
00685 void audacious_remote_get_eq(DBusGProxy *proxy, gdouble *preamp, GArray **bands) {
00686 org_atheme_audacious_get_eq(proxy, preamp, bands, &error);
00687 g_clear_error(&error);
00688 }
00689
00696 gdouble audacious_remote_get_eq_preamp(DBusGProxy *proxy) {
00697 gdouble preamp = 0.0;
00698
00699 org_atheme_audacious_get_eq_preamp(proxy, &preamp, &error);
00700 g_clear_error(&error);
00701
00702 return preamp;
00703 }
00704
00712 gdouble audacious_remote_get_eq_band(DBusGProxy *proxy, gint band) {
00713 gdouble value = 0.0;
00714
00715 org_atheme_audacious_get_eq_band(proxy, band, &value, &error);
00716 g_clear_error(&error);
00717
00718 return value;
00719 }
00720
00728 void audacious_remote_set_eq(DBusGProxy *proxy, gdouble preamp, GArray *bands) {
00729 org_atheme_audacious_set_eq(proxy, preamp, bands, &error);
00730 g_clear_error(&error);
00731 }
00732
00739 void audacious_remote_set_eq_preamp(DBusGProxy *proxy, gdouble preamp) {
00740 org_atheme_audacious_set_eq_preamp(proxy, preamp, &error);
00741 g_clear_error(&error);
00742 }
00743
00751 void audacious_remote_set_eq_band(DBusGProxy *proxy, gint band, gdouble value) {
00752 org_atheme_audacious_set_eq_band(proxy, band, value, &error);
00753 g_clear_error(&error);
00754 }
00755
00761 void audacious_remote_quit(DBusGProxy *proxy) {
00762 org_atheme_audacious_quit(proxy, &error);
00763 g_clear_error(&error);
00764 }
00765
00771 void audacious_remote_play_pause(DBusGProxy *proxy) {
00772 org_atheme_audacious_play_pause(proxy, &error);
00773 }
00774
00782 void audacious_remote_playlist_ins_url_string(DBusGProxy *proxy,
00783 gchar *string, guint pos) {
00784 org_atheme_audacious_playlist_ins_url_string (proxy, string, pos, &error);
00785 g_clear_error(&error);
00786 }
00787
00794 void audacious_remote_playqueue_add(DBusGProxy *proxy, guint pos) {
00795 org_atheme_audacious_playqueue_add (proxy, pos, &error);
00796 g_clear_error(&error);
00797 }
00798
00805 void audacious_remote_playqueue_remove(DBusGProxy *proxy, guint pos) {
00806 org_atheme_audacious_playqueue_remove (proxy, pos, &error);
00807 g_clear_error(&error);
00808 }
00809
00818 gint audacious_remote_get_playqueue_length(DBusGProxy *proxy) {
00819 gint len = 0;
00820 org_atheme_audacious_length(proxy, &len, &error);
00821 g_clear_error(&error);
00822 return len;
00823 }
00824
00830 void audacious_remote_toggle_advance(DBusGProxy *proxy) {
00831 org_atheme_audacious_toggle_auto_advance(proxy, &error);
00832 g_clear_error(&error);
00833 }
00834
00843 gboolean audacious_remote_is_advance(DBusGProxy *proxy) {
00844 gboolean is_advance = FALSE;
00845 org_atheme_audacious_auto_advance(proxy, &is_advance, &error);
00846 g_clear_error(&error);
00847 return is_advance;
00848 }
00849
00855 void audacious_remote_activate(DBusGProxy *proxy) {
00856 org_atheme_audacious_activate(proxy, &error);
00857 g_clear_error(&error);
00858 }
00859
00865 void audacious_remote_show_jtf_box(DBusGProxy *proxy) {
00866 audacious_remote_toggle_jtf_box(proxy, TRUE);
00867 }
00868
00875 void audacious_remote_toggle_jtf_box(DBusGProxy *proxy, gboolean show) {
00876 org_atheme_audacious_show_jtf_box(proxy, show, &error);
00877 g_clear_error(&error);
00878 }
00879
00886 void audacious_remote_toggle_filebrowser(DBusGProxy *proxy, gboolean show) {
00887 org_atheme_audacious_show_filebrowser(proxy, show, &error);
00888 g_clear_error(&error);
00889 }
00890
00897 void audacious_remote_playqueue_clear(DBusGProxy *proxy) {
00898 org_atheme_audacious_playqueue_clear(proxy, &error);
00899 g_clear_error(&error);
00900 }
00901
00909 gboolean audacious_remote_playqueue_is_queued(DBusGProxy *proxy, guint pos) {
00910 gboolean is_queued;
00911 org_atheme_audacious_playqueue_is_queued (proxy, pos, &is_queued, &error);
00912 g_clear_error(&error);
00913 return is_queued;
00914 }
00915
00923 gint audacious_remote_get_playqueue_queue_position(DBusGProxy *proxy, guint pos) {
00924 guint qpos = 0;
00925 org_atheme_audacious_queue_get_queue_pos (proxy, pos, &qpos, &error);
00926 g_clear_error(&error);
00927 return qpos;
00928 }
00929
00938 gint audacious_remote_get_playqueue_list_position(DBusGProxy *proxy, guint qpos) {
00939 guint pos = 0;
00940 org_atheme_audacious_queue_get_list_pos (proxy, qpos, &pos, &error);
00941 g_clear_error(&error);
00942 return pos;
00943 }
00944
00951 void audacious_remote_playlist_enqueue_to_temp(DBusGProxy *proxy,
00952 gchar *string) {
00953 org_atheme_audacious_playlist_enqueue_to_temp(proxy, string, &error);
00954 g_clear_error(&error);
00955 }
00956
00965 gchar *audacious_get_tuple_field_data(DBusGProxy *proxy, gchar *field,
00966 guint pos) {
00967 GValue value = {0};
00968 gchar *s = NULL;
00969
00970 org_atheme_audacious_song_tuple(proxy, pos, field, &value, &error);
00971
00972 g_clear_error(&error);
00973
00974 if (G_IS_VALUE(&value) == FALSE)
00975 return NULL;
00976
00977
00978
00979
00980
00981
00982 if (G_VALUE_HOLDS_STRING(&value))
00983
00984 s = g_strdup(g_value_get_string(&value));
00985 else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING))
00986 {
00987 GValue tmp_value = { 0, };
00988
00989 g_value_init(&tmp_value, G_TYPE_STRING);
00990 g_value_transform(&value, &tmp_value);
00991
00992
00993 s = g_strdup(g_value_get_string(&tmp_value));
00994
00995 g_value_unset(&tmp_value);
00996 }
00997 else
00998 s = g_strdup("<unknown type>");
00999
01000 g_value_unset(&value);
01001 return s;
01002 }
01003
01010 void audacious_remote_eq_activate(DBusGProxy *proxy, gboolean active) {
01011 org_atheme_audacious_equalizer_activate (proxy, active, &error);
01012 g_clear_error(&error);
01013 }
01014
01021 gchar **audacious_remote_get_tuple_fields(DBusGProxy *proxy) {
01022 gchar **res = NULL;
01023 org_atheme_audacious_get_tuple_fields (proxy, &res, &error);
01024 g_clear_error(&error);
01025 return res;
01026 }
01027
01031 gchar *audacious_remote_playlist_get_active_name(DBusGProxy *proxy) {
01032 char *string = NULL;
01033 org_atheme_audacious_get_active_playlist_name (proxy, &string, &error);
01034 g_clear_error(&error);
01035
01036 return (string ? string : NULL);
01037 }