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 #include <stdlib.h> 00019 #include <glib.h> 00020 #include <string.h> 00021 #include <dbus/dbus-glib.h> 00022 #include "audacious/dbus.h" 00023 #include "audacious/dbus-client-bindings.h" 00024 #include "audctrl.h" 00025 #include "config.h" 00026 00027 static GError *error = NULL; //it must be hidden from outside, otherwise symbol conflict likely to happen. 00028 00038 EXPORT void audacious_remote_playlist(DBusGProxy *proxy, gchar **list, gint num, gboolean enqueue) { 00039 GList *glist = NULL; 00040 gchar **data = list; 00041 00042 g_return_if_fail(list != NULL); 00043 g_return_if_fail(num > 0); 00044 00045 if (!enqueue) 00046 audacious_remote_playlist_clear(proxy); 00047 00048 // construct a GList 00049 while(data) { 00050 glist = g_list_append(glist, (gpointer)data); 00051 data++; 00052 } 00053 00054 org_atheme_audacious_playlist_add(proxy, (gpointer)glist, &error); 00055 00056 g_list_free(glist); 00057 glist = NULL; 00058 00059 if (!enqueue) 00060 audacious_remote_play(proxy); 00061 } 00062 00069 EXPORT gchar *audacious_remote_get_version(DBusGProxy *proxy) { 00070 char *string = NULL; 00071 org_atheme_audacious_version(proxy, &string, &error); 00072 g_clear_error(&error); 00073 00074 return (string ? string : NULL); 00075 } 00076 00083 EXPORT void audacious_remote_playlist_add (DBusGProxy * proxy, GList * list) 00084 { 00085 const gchar * filenames[g_list_length (list) + 1]; 00086 int count; 00087 00088 for (count = 0; list != NULL; count ++, list = list->next) 00089 filenames[count] = list->data; 00090 00091 filenames[count] = NULL; 00092 00093 org_atheme_audacious_add_list (proxy, filenames, & error); 00094 g_clear_error (& error); 00095 } 00096 00103 EXPORT void audacious_remote_playlist_open_list (DBusGProxy * proxy, GList * list) 00104 { 00105 const gchar * filenames[g_list_length (list) + 1]; 00106 int count; 00107 00108 for (count = 0; list != NULL; count ++, list = list->next) 00109 filenames[count] = list->data; 00110 00111 filenames[count] = NULL; 00112 00113 org_atheme_audacious_open_list (proxy, filenames, & error); 00114 g_clear_error (& error); 00115 } 00116 00124 EXPORT void audacious_remote_playlist_open_list_to_temp (DBusGProxy * proxy, GList * 00125 list) 00126 { 00127 const gchar * filenames[g_list_length (list) + 1]; 00128 int count; 00129 00130 for (count = 0; list != NULL; count ++, list = list->next) 00131 filenames[count] = list->data; 00132 00133 filenames[count] = NULL; 00134 00135 org_atheme_audacious_open_list_to_temp (proxy, filenames, & error); 00136 g_clear_error (& error); 00137 } 00138 00145 EXPORT void audacious_remote_playlist_delete(DBusGProxy *proxy, guint pos) { 00146 org_atheme_audacious_delete(proxy, pos, &error); 00147 g_clear_error(&error); 00148 } 00149 00155 EXPORT void audacious_remote_play(DBusGProxy *proxy) { 00156 org_atheme_audacious_play(proxy, &error); 00157 g_clear_error(&error); 00158 } 00159 00165 EXPORT void audacious_remote_pause(DBusGProxy *proxy) { 00166 org_atheme_audacious_pause(proxy, &error); 00167 g_clear_error(&error); 00168 } 00169 00175 EXPORT void audacious_remote_stop(DBusGProxy *proxy) { 00176 org_atheme_audacious_stop(proxy, &error); 00177 g_clear_error(&error); 00178 } 00179 00186 EXPORT gboolean audacious_remote_is_playing(DBusGProxy *proxy) { 00187 gboolean is_playing = FALSE; 00188 org_atheme_audacious_playing(proxy, &is_playing, &error); 00189 g_clear_error(&error); 00190 return is_playing; 00191 } 00192 00201 EXPORT gboolean audacious_remote_is_paused(DBusGProxy *proxy) { 00202 gboolean is_paused = FALSE; 00203 org_atheme_audacious_paused(proxy, &is_paused, &error); 00204 g_clear_error(&error); 00205 return is_paused; 00206 } 00207 00216 EXPORT gint audacious_remote_get_playlist_pos(DBusGProxy *proxy) { 00217 guint pos = 0; 00218 org_atheme_audacious_position(proxy, &pos, &error); 00219 g_clear_error(&error); 00220 return pos; 00221 } 00222 00230 EXPORT void audacious_remote_set_playlist_pos(DBusGProxy *proxy, guint pos) { 00231 org_atheme_audacious_jump (proxy, pos, &error); 00232 g_clear_error(&error); 00233 } 00234 00243 EXPORT gint audacious_remote_get_playlist_length(DBusGProxy *proxy) { 00244 gint len = 0; 00245 org_atheme_audacious_length(proxy, &len, &error); 00246 g_clear_error(&error); 00247 return len; 00248 } 00249 00256 EXPORT void audacious_remote_playlist_clear(DBusGProxy *proxy) { 00257 org_atheme_audacious_clear(proxy, &error); 00258 g_clear_error(&error); 00259 } 00260 00269 EXPORT gint audacious_remote_get_output_time(DBusGProxy *proxy) { 00270 guint time = 0; 00271 org_atheme_audacious_time(proxy, &time, &error); 00272 g_clear_error(&error); 00273 return time; 00274 } 00275 00283 EXPORT void audacious_remote_jump_to_time(DBusGProxy *proxy, guint pos) { 00284 org_atheme_audacious_seek (proxy, pos, &error); 00285 g_clear_error(&error); 00286 } 00287 00295 EXPORT void audacious_remote_get_volume(DBusGProxy *proxy, gint * vl, gint * vr) { 00296 org_atheme_audacious_volume(proxy, vl, vr, &error); 00297 g_clear_error(&error); 00298 } 00299 00306 EXPORT gint audacious_remote_get_main_volume(DBusGProxy *proxy) { 00307 gint vl = 0, vr = 0; 00308 00309 audacious_remote_get_volume(proxy, &vl, &vr); 00310 00311 return (vl > vr) ? vl : vr; 00312 } 00313 00320 EXPORT gint audacious_remote_get_balance(DBusGProxy *proxy) { 00321 gint balance = 50; 00322 org_atheme_audacious_balance(proxy, &balance, &error); 00323 g_clear_error(&error); 00324 return balance; 00325 } 00326 00334 EXPORT void audacious_remote_set_volume(DBusGProxy *proxy, gint vl, gint vr) { 00335 org_atheme_audacious_set_volume(proxy, vl, vr, &error); 00336 g_clear_error(&error); 00337 } 00338 00339 00346 EXPORT void audacious_remote_set_main_volume(DBusGProxy *proxy, gint v) { 00347 gint b = 50, vl = 0, vr = 0; 00348 00349 b = audacious_remote_get_balance(proxy); 00350 00351 if (b < 0) { 00352 vl = v; 00353 vr = (v * (100 - abs(b))) / 100; 00354 } else if (b > 0) { 00355 vl = (v * (100 - b)) / 100; 00356 vr = v; 00357 } else 00358 vl = vr = v; 00359 audacious_remote_set_volume(proxy, vl, vr); 00360 } 00361 00368 EXPORT void audacious_remote_set_balance(DBusGProxy *proxy, gint b) { 00369 gint v = 0, vl = 0, vr = 0; 00370 00371 if (b < -100) 00372 b = -100; 00373 if (b > 100) 00374 b = 100; 00375 00376 v = audacious_remote_get_main_volume(proxy); 00377 00378 if (b < 0) { 00379 vl = v; 00380 vr = (v * (100 - abs(b))) / 100; 00381 } else if (b > 0) { 00382 vl = (v * (100 - b)) / 100; 00383 vr = v; 00384 } else 00385 vl = vr = v; 00386 audacious_remote_set_volume(proxy, vl, vr); 00387 } 00388 00396 EXPORT gchar *audacious_remote_get_playlist_file(DBusGProxy *proxy, guint pos) { 00397 gchar *out = NULL; 00398 org_atheme_audacious_song_filename(proxy, pos, &out, &error); 00399 g_clear_error(&error); 00400 return out; 00401 } 00402 00410 EXPORT gchar *audacious_remote_get_playlist_title(DBusGProxy *proxy, guint pos) { 00411 gchar *out = NULL; 00412 org_atheme_audacious_song_title(proxy, pos, &out, &error); 00413 g_clear_error(&error); 00414 return out; 00415 } 00416 00424 EXPORT gint audacious_remote_get_playlist_time(DBusGProxy *proxy, guint pos) { 00425 gint out = 0; 00426 org_atheme_audacious_song_frames(proxy, pos, &out, &error); 00427 g_clear_error(&error); 00428 return out; 00429 } 00430 00439 EXPORT void audacious_remote_get_info(DBusGProxy *proxy, gint *rate, gint *freq, 00440 gint *nch) { 00441 org_atheme_audacious_info(proxy, rate, freq, nch, &error); 00442 g_clear_error(&error); 00443 } 00444 00451 EXPORT void audacious_remote_main_win_toggle(DBusGProxy *proxy, gboolean show) { 00452 org_atheme_audacious_show_main_win(proxy, show, &error); 00453 g_clear_error(&error); 00454 } 00455 00462 EXPORT gboolean audacious_remote_is_main_win(DBusGProxy *proxy) { 00463 gboolean visible = TRUE; 00464 org_atheme_audacious_main_win_visible(proxy, &visible, &error); 00465 g_clear_error(&error); 00466 return visible; 00467 } 00468 00474 EXPORT void audacious_remote_show_prefs_box(DBusGProxy *proxy) { 00475 audacious_remote_toggle_prefs_box(proxy, TRUE); 00476 } 00477 00484 EXPORT void audacious_remote_toggle_prefs_box(DBusGProxy *proxy, gboolean show) { 00485 org_atheme_audacious_show_prefs_box(proxy, show, &error); 00486 g_clear_error(&error); 00487 } 00488 00494 EXPORT void audacious_remote_show_about_box(DBusGProxy *proxy) { 00495 audacious_remote_toggle_about_box(proxy, TRUE); 00496 } 00497 00504 EXPORT void audacious_remote_toggle_about_box(DBusGProxy *proxy, gboolean show) { 00505 org_atheme_audacious_show_about_box(proxy, show, &error); 00506 g_clear_error(&error); 00507 } 00508 00515 EXPORT void audacious_remote_toggle_aot(DBusGProxy *proxy, gboolean ontop) { 00516 org_atheme_audacious_toggle_aot(proxy, ontop, &error); 00517 g_clear_error(&error); 00518 } 00519 00525 EXPORT void audacious_remote_eject(DBusGProxy *proxy) { 00526 org_atheme_audacious_eject(proxy, &error); 00527 g_clear_error(&error); 00528 } 00529 00536 EXPORT void audacious_remote_playlist_prev(DBusGProxy *proxy) { 00537 org_atheme_audacious_reverse(proxy, &error); 00538 g_clear_error(&error); 00539 } 00540 00546 EXPORT void audacious_remote_playlist_next(DBusGProxy *proxy) { 00547 org_atheme_audacious_advance(proxy, &error); 00548 g_clear_error(&error); 00549 } 00550 00557 EXPORT void audacious_remote_playlist_add_url_string(DBusGProxy *proxy, 00558 gchar *string) { 00559 org_atheme_audacious_add_url(proxy, string, &error); 00560 g_clear_error(&error); 00561 } 00562 00569 EXPORT gboolean audacious_remote_is_running(DBusGProxy *proxy) { 00570 char *string = NULL; 00571 org_atheme_audacious_version(proxy, &string, &error); 00572 g_clear_error(&error); 00573 if(string) { 00574 g_free(string); 00575 return TRUE; 00576 } 00577 else 00578 return FALSE; 00579 } 00580 00586 EXPORT void audacious_remote_toggle_repeat(DBusGProxy *proxy) { 00587 org_atheme_audacious_toggle_repeat(proxy, &error); 00588 g_clear_error(&error); 00589 } 00590 00596 EXPORT void audacious_remote_toggle_shuffle(DBusGProxy *proxy) { 00597 org_atheme_audacious_toggle_shuffle (proxy, &error); 00598 g_clear_error(&error); 00599 } 00600 00601 EXPORT void audacious_remote_toggle_stop_after (DBusGProxy * proxy) 00602 { 00603 org_atheme_audacious_toggle_stop_after (proxy, & error); 00604 g_clear_error (& error); 00605 } 00606 00613 EXPORT gboolean audacious_remote_is_repeat(DBusGProxy *proxy) { 00614 gboolean is_repeat; 00615 org_atheme_audacious_repeat(proxy, &is_repeat, &error); 00616 g_clear_error(&error); 00617 return is_repeat; 00618 } 00619 00626 EXPORT gboolean audacious_remote_is_shuffle(DBusGProxy *proxy) { 00627 gboolean is_shuffle; 00628 org_atheme_audacious_shuffle(proxy, &is_shuffle, &error); 00629 g_clear_error(&error); 00630 return is_shuffle; 00631 } 00632 00633 EXPORT gboolean audacious_remote_is_stop_after (DBusGProxy * proxy) 00634 { 00635 gboolean is_stop_after; 00636 org_atheme_audacious_stop_after (proxy, & is_stop_after, & error); 00637 g_clear_error (& error); 00638 return is_stop_after; 00639 } 00640 00648 EXPORT void audacious_remote_get_eq(DBusGProxy *proxy, gdouble *preamp, GArray **bands) { 00649 org_atheme_audacious_get_eq(proxy, preamp, bands, &error); 00650 g_clear_error(&error); 00651 } 00652 00659 EXPORT gdouble audacious_remote_get_eq_preamp(DBusGProxy *proxy) { 00660 gdouble preamp = 0.0; 00661 00662 org_atheme_audacious_get_eq_preamp(proxy, &preamp, &error); 00663 g_clear_error(&error); 00664 00665 return preamp; 00666 } 00667 00675 EXPORT gdouble audacious_remote_get_eq_band(DBusGProxy *proxy, gint band) { 00676 gdouble value = 0.0; 00677 00678 org_atheme_audacious_get_eq_band(proxy, band, &value, &error); 00679 g_clear_error(&error); 00680 00681 return value; 00682 } 00683 00691 EXPORT void audacious_remote_set_eq(DBusGProxy *proxy, gdouble preamp, GArray *bands) { 00692 org_atheme_audacious_set_eq(proxy, preamp, bands, &error); 00693 g_clear_error(&error); 00694 } 00695 00702 EXPORT void audacious_remote_set_eq_preamp(DBusGProxy *proxy, gdouble preamp) { 00703 org_atheme_audacious_set_eq_preamp(proxy, preamp, &error); 00704 g_clear_error(&error); 00705 } 00706 00714 EXPORT void audacious_remote_set_eq_band(DBusGProxy *proxy, gint band, gdouble value) { 00715 org_atheme_audacious_set_eq_band(proxy, band, value, &error); 00716 g_clear_error(&error); 00717 } 00718 00724 EXPORT void audacious_remote_quit(DBusGProxy *proxy) { 00725 org_atheme_audacious_quit(proxy, &error); 00726 g_clear_error(&error); 00727 } 00728 00734 EXPORT void audacious_remote_play_pause(DBusGProxy *proxy) { 00735 org_atheme_audacious_play_pause(proxy, &error); 00736 } 00737 00745 EXPORT void audacious_remote_playlist_ins_url_string(DBusGProxy *proxy, 00746 gchar *string, guint pos) { 00747 org_atheme_audacious_playlist_ins_url_string (proxy, string, pos, &error); 00748 g_clear_error(&error); 00749 } 00750 00757 EXPORT void audacious_remote_playqueue_add(DBusGProxy *proxy, guint pos) { 00758 org_atheme_audacious_playqueue_add (proxy, pos, &error); 00759 g_clear_error(&error); 00760 } 00761 00768 EXPORT void audacious_remote_playqueue_remove(DBusGProxy *proxy, guint pos) { 00769 org_atheme_audacious_playqueue_remove (proxy, pos, &error); 00770 g_clear_error(&error); 00771 } 00772 00781 EXPORT gint audacious_remote_get_playqueue_length(DBusGProxy *proxy) { 00782 gint len = 0; 00783 org_atheme_audacious_length(proxy, &len, &error); 00784 g_clear_error(&error); 00785 return len; 00786 } 00787 00793 EXPORT void audacious_remote_toggle_advance(DBusGProxy *proxy) { 00794 org_atheme_audacious_toggle_auto_advance(proxy, &error); 00795 g_clear_error(&error); 00796 } 00797 00806 EXPORT gboolean audacious_remote_is_advance(DBusGProxy *proxy) { 00807 gboolean is_advance = FALSE; 00808 org_atheme_audacious_auto_advance(proxy, &is_advance, &error); 00809 g_clear_error(&error); 00810 return is_advance; 00811 } 00812 00818 EXPORT void audacious_remote_show_jtf_box(DBusGProxy *proxy) { 00819 audacious_remote_toggle_jtf_box(proxy, TRUE); 00820 } 00821 00828 EXPORT void audacious_remote_toggle_jtf_box(DBusGProxy *proxy, gboolean show) { 00829 org_atheme_audacious_show_jtf_box(proxy, show, &error); 00830 g_clear_error(&error); 00831 } 00832 00839 EXPORT void audacious_remote_toggle_filebrowser(DBusGProxy *proxy, gboolean show) { 00840 org_atheme_audacious_show_filebrowser(proxy, show, &error); 00841 g_clear_error(&error); 00842 } 00843 00850 EXPORT void audacious_remote_playqueue_clear(DBusGProxy *proxy) { 00851 org_atheme_audacious_playqueue_clear(proxy, &error); 00852 g_clear_error(&error); 00853 } 00854 00862 EXPORT gboolean audacious_remote_playqueue_is_queued(DBusGProxy *proxy, guint pos) { 00863 gboolean is_queued; 00864 org_atheme_audacious_playqueue_is_queued (proxy, pos, &is_queued, &error); 00865 g_clear_error(&error); 00866 return is_queued; 00867 } 00868 00876 EXPORT gint audacious_remote_get_playqueue_queue_position(DBusGProxy *proxy, guint pos) { 00877 guint qpos = 0; 00878 org_atheme_audacious_queue_get_queue_pos (proxy, pos, &qpos, &error); 00879 g_clear_error(&error); 00880 return qpos; 00881 } 00882 00891 EXPORT gint audacious_remote_get_playqueue_list_position(DBusGProxy *proxy, guint qpos) { 00892 guint pos = 0; 00893 org_atheme_audacious_queue_get_list_pos (proxy, qpos, &pos, &error); 00894 g_clear_error(&error); 00895 return pos; 00896 } 00897 00904 EXPORT void audacious_remote_playlist_enqueue_to_temp(DBusGProxy *proxy, 00905 gchar *string) { 00906 org_atheme_audacious_playlist_enqueue_to_temp(proxy, string, &error); 00907 g_clear_error(&error); 00908 } 00909 00918 EXPORT gchar *audacious_get_tuple_field_data(DBusGProxy *proxy, gchar *field, 00919 guint pos) { 00920 GValue value = {0}; 00921 gchar *s = NULL; 00922 00923 org_atheme_audacious_song_tuple(proxy, pos, field, &value, &error); 00924 00925 g_clear_error(&error); 00926 00927 if (G_IS_VALUE(&value) == FALSE) 00928 return NULL; 00929 00930 /* I think the original "purpose" of using g_strescape() here 00931 * has probably been to escape only \n, \t, \r, etc. but the function 00932 * actually escapes all non-ASCII characters. Which is bad, since we 00933 * are using UTF-8. -- ccr 00934 */ 00935 if (G_VALUE_HOLDS_STRING(&value)) 00936 //s = g_strescape(g_value_get_string(&value), NULL); 00937 s = g_strdup(g_value_get_string(&value)); 00938 else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING)) 00939 { 00940 GValue tmp_value = { 0, }; 00941 00942 g_value_init(&tmp_value, G_TYPE_STRING); 00943 g_value_transform(&value, &tmp_value); 00944 00945 //s = g_strescape(g_value_get_string(&tmp_value), NULL); 00946 s = g_strdup(g_value_get_string(&tmp_value)); 00947 00948 g_value_unset(&tmp_value); 00949 } 00950 else 00951 s = g_strdup("<unknown type>"); 00952 00953 g_value_unset(&value); 00954 return s; 00955 } 00956 00963 EXPORT void audacious_remote_eq_activate(DBusGProxy *proxy, gboolean active) { 00964 org_atheme_audacious_equalizer_activate (proxy, active, &error); 00965 g_clear_error(&error); 00966 } 00967 00974 EXPORT gchar **audacious_remote_get_tuple_fields(DBusGProxy *proxy) { 00975 gchar **res = NULL; 00976 org_atheme_audacious_get_tuple_fields (proxy, &res, &error); 00977 g_clear_error(&error); 00978 return res; 00979 } 00980 00984 EXPORT gchar *audacious_remote_playlist_get_active_name(DBusGProxy *proxy) { 00985 char *string = NULL; 00986 org_atheme_audacious_get_active_playlist_name (proxy, &string, &error); 00987 g_clear_error(&error); 00988 00989 return (string ? string : NULL); 00990 }