Audacious
$Id:Doxyfile42802007-03-2104:39:00Znenolod$
|
00001 /* 00002 * Audacious: A cross-platform multimedia player 00003 * Copyright (c) 2007 Ben Tucker 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; under version 3 of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 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; //it must be hidden from outside, otherwise symbol conflict likely to happen. 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 // construct a GList 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 00610 gboolean audacious_remote_is_repeat(DBusGProxy *proxy) { 00611 gboolean is_repeat; 00612 org_atheme_audacious_repeat(proxy, &is_repeat, &error); 00613 g_clear_error(&error); 00614 return is_repeat; 00615 } 00616 00623 gboolean audacious_remote_is_shuffle(DBusGProxy *proxy) { 00624 gboolean is_shuffle; 00625 org_atheme_audacious_shuffle(proxy, &is_shuffle, &error); 00626 g_clear_error(&error); 00627 return is_shuffle; 00628 } 00629 00637 void audacious_remote_get_eq(DBusGProxy *proxy, gdouble *preamp, GArray **bands) { 00638 org_atheme_audacious_get_eq(proxy, preamp, bands, &error); 00639 g_clear_error(&error); 00640 } 00641 00648 gdouble audacious_remote_get_eq_preamp(DBusGProxy *proxy) { 00649 gdouble preamp = 0.0; 00650 00651 org_atheme_audacious_get_eq_preamp(proxy, &preamp, &error); 00652 g_clear_error(&error); 00653 00654 return preamp; 00655 } 00656 00664 gdouble audacious_remote_get_eq_band(DBusGProxy *proxy, gint band) { 00665 gdouble value = 0.0; 00666 00667 org_atheme_audacious_get_eq_band(proxy, band, &value, &error); 00668 g_clear_error(&error); 00669 00670 return value; 00671 } 00672 00680 void audacious_remote_set_eq(DBusGProxy *proxy, gdouble preamp, GArray *bands) { 00681 org_atheme_audacious_set_eq(proxy, preamp, bands, &error); 00682 g_clear_error(&error); 00683 } 00684 00691 void audacious_remote_set_eq_preamp(DBusGProxy *proxy, gdouble preamp) { 00692 org_atheme_audacious_set_eq_preamp(proxy, preamp, &error); 00693 g_clear_error(&error); 00694 } 00695 00703 void audacious_remote_set_eq_band(DBusGProxy *proxy, gint band, gdouble value) { 00704 org_atheme_audacious_set_eq_band(proxy, band, value, &error); 00705 g_clear_error(&error); 00706 } 00707 00713 void audacious_remote_quit(DBusGProxy *proxy) { 00714 org_atheme_audacious_quit(proxy, &error); 00715 g_clear_error(&error); 00716 } 00717 00723 void audacious_remote_play_pause(DBusGProxy *proxy) { 00724 org_atheme_audacious_play_pause(proxy, &error); 00725 } 00726 00734 void audacious_remote_playlist_ins_url_string(DBusGProxy *proxy, 00735 gchar *string, guint pos) { 00736 org_atheme_audacious_playlist_ins_url_string (proxy, string, pos, &error); 00737 g_clear_error(&error); 00738 } 00739 00746 void audacious_remote_playqueue_add(DBusGProxy *proxy, guint pos) { 00747 org_atheme_audacious_playqueue_add (proxy, pos, &error); 00748 g_clear_error(&error); 00749 } 00750 00757 void audacious_remote_playqueue_remove(DBusGProxy *proxy, guint pos) { 00758 org_atheme_audacious_playqueue_remove (proxy, pos, &error); 00759 g_clear_error(&error); 00760 } 00761 00770 gint audacious_remote_get_playqueue_length(DBusGProxy *proxy) { 00771 gint len = 0; 00772 org_atheme_audacious_length(proxy, &len, &error); 00773 g_clear_error(&error); 00774 return len; 00775 } 00776 00782 void audacious_remote_toggle_advance(DBusGProxy *proxy) { 00783 org_atheme_audacious_toggle_auto_advance(proxy, &error); 00784 g_clear_error(&error); 00785 } 00786 00795 gboolean audacious_remote_is_advance(DBusGProxy *proxy) { 00796 gboolean is_advance = FALSE; 00797 org_atheme_audacious_auto_advance(proxy, &is_advance, &error); 00798 g_clear_error(&error); 00799 return is_advance; 00800 } 00801 00807 void audacious_remote_show_jtf_box(DBusGProxy *proxy) { 00808 audacious_remote_toggle_jtf_box(proxy, TRUE); 00809 } 00810 00817 void audacious_remote_toggle_jtf_box(DBusGProxy *proxy, gboolean show) { 00818 org_atheme_audacious_show_jtf_box(proxy, show, &error); 00819 g_clear_error(&error); 00820 } 00821 00828 void audacious_remote_toggle_filebrowser(DBusGProxy *proxy, gboolean show) { 00829 org_atheme_audacious_show_filebrowser(proxy, show, &error); 00830 g_clear_error(&error); 00831 } 00832 00839 void audacious_remote_playqueue_clear(DBusGProxy *proxy) { 00840 org_atheme_audacious_playqueue_clear(proxy, &error); 00841 g_clear_error(&error); 00842 } 00843 00851 gboolean audacious_remote_playqueue_is_queued(DBusGProxy *proxy, guint pos) { 00852 gboolean is_queued; 00853 org_atheme_audacious_playqueue_is_queued (proxy, pos, &is_queued, &error); 00854 g_clear_error(&error); 00855 return is_queued; 00856 } 00857 00865 gint audacious_remote_get_playqueue_queue_position(DBusGProxy *proxy, guint pos) { 00866 guint qpos = 0; 00867 org_atheme_audacious_queue_get_queue_pos (proxy, pos, &qpos, &error); 00868 g_clear_error(&error); 00869 return qpos; 00870 } 00871 00880 gint audacious_remote_get_playqueue_list_position(DBusGProxy *proxy, guint qpos) { 00881 guint pos = 0; 00882 org_atheme_audacious_queue_get_list_pos (proxy, qpos, &pos, &error); 00883 g_clear_error(&error); 00884 return pos; 00885 } 00886 00893 void audacious_remote_playlist_enqueue_to_temp(DBusGProxy *proxy, 00894 gchar *string) { 00895 org_atheme_audacious_playlist_enqueue_to_temp(proxy, string, &error); 00896 g_clear_error(&error); 00897 } 00898 00907 gchar *audacious_get_tuple_field_data(DBusGProxy *proxy, gchar *field, 00908 guint pos) { 00909 GValue value = {0}; 00910 gchar *s = NULL; 00911 00912 org_atheme_audacious_song_tuple(proxy, pos, field, &value, &error); 00913 00914 g_clear_error(&error); 00915 00916 if (G_IS_VALUE(&value) == FALSE) 00917 return NULL; 00918 00919 /* I think the original "purpose" of using g_strescape() here 00920 * has probably been to escape only \n, \t, \r, etc. but the function 00921 * actually escapes all non-ASCII characters. Which is bad, since we 00922 * are using UTF-8. -- ccr 00923 */ 00924 if (G_VALUE_HOLDS_STRING(&value)) 00925 //s = g_strescape(g_value_get_string(&value), NULL); 00926 s = g_strdup(g_value_get_string(&value)); 00927 else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING)) 00928 { 00929 GValue tmp_value = { 0, }; 00930 00931 g_value_init(&tmp_value, G_TYPE_STRING); 00932 g_value_transform(&value, &tmp_value); 00933 00934 //s = g_strescape(g_value_get_string(&tmp_value), NULL); 00935 s = g_strdup(g_value_get_string(&tmp_value)); 00936 00937 g_value_unset(&tmp_value); 00938 } 00939 else 00940 s = g_strdup("<unknown type>"); 00941 00942 g_value_unset(&value); 00943 return s; 00944 } 00945 00952 void audacious_remote_eq_activate(DBusGProxy *proxy, gboolean active) { 00953 org_atheme_audacious_equalizer_activate (proxy, active, &error); 00954 g_clear_error(&error); 00955 } 00956 00963 gchar **audacious_remote_get_tuple_fields(DBusGProxy *proxy) { 00964 gchar **res = NULL; 00965 org_atheme_audacious_get_tuple_fields (proxy, &res, &error); 00966 g_clear_error(&error); 00967 return res; 00968 } 00969 00973 gchar *audacious_remote_playlist_get_active_name(DBusGProxy *proxy) { 00974 char *string = NULL; 00975 org_atheme_audacious_get_active_playlist_name (proxy, &string, &error); 00976 g_clear_error(&error); 00977 00978 return (string ? string : NULL); 00979 }