From 3048e239d24c654ec27ad8c64dc2dda2dea5b11f Mon Sep 17 00:00:00 2001 From: Philip Kovacs Date: Sat, 17 Nov 2007 03:43:21 +0000 Subject: [PATCH] Added support for Audacious 1.4.0 via --enable-audacious=yes|no|legacy: (use 'yes' for audacious >= 1.4.0, 'legacy' for prior versions). git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@988 7f574dfc-610e-0410-a909-a81674777703 --- ChangeLog | 4 ++++ configure.ac.in | 21 +++++++++++++++-- src/audacious.c | 61 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ba2bae4..33f76d40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ # $Id$ +2007-11-16 + * Added support for Audacious 1.4.0 via --enable-audacious=yes|no|legacy: + * (use 'yes' for audacious >= 1.4.0, 'legacy' for prior versions). + 2007-11-14 * Fix compilation error with --disable-x11 (bug #1830373). * Bump doc stylesheet from 4.3 to 4.4. diff --git a/configure.ac.in b/configure.ac.in index 7c582a10..8540c174 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -108,15 +108,32 @@ dnl Audacious Media Player dnl AC_ARG_ENABLE([audacious], - AC_HELP_STRING([--enable-audacious], [enable audacious player support @<:@default=no@:>@]), + AC_HELP_STRING([--enable-audacious=[[yes|no|legacy]]], + [enable audacious player support @<:@default=no@:>@]), [want_audacious="$enableval"], [want_audacious=no]) AM_CONDITIONAL(BUILD_AUDACIOUS, test x$want_audacious = xyes) if test x$want_audacious = xyes; then - PKG_CHECK_MODULES([AUDACIOUS], [audacious >= 0.1]) + PKG_CHECK_MODULES([AUDACIOUS], [audacious >= 1.4.0 dbus-glib-1 glib-2.0 gobject-2.0]) CFLAGS="$CFLAGS $AUDACIOUS_CFLAGS" LIBS="$LIBS $AUDACIOUS_LIBS" + save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$AUDACIOUS_CFLAGS -I`pkg-config --variable=audacious_include_dir audacious`/audacious" + AC_CHECK_HEADERS([audacious/audctrl.h audacious/dbus.h glib.h glib-object.h], + [], AC_MSG_ERROR([required header(s) not found])) + CPPFLAGS="$save_CPPFLAGS" AC_DEFINE(AUDACIOUS, 1, [Define for Audacious support]) +else if test x$want_audacious = xlegacy; then + PKG_CHECK_MODULES([AUDACIOUS], [audacious < 1.4.0 glib-2.0]) + CFLAGS="$CFLAGS $AUDACIOUS_CFLAGS" + LIBS="$LIBS $AUDACIOUS_LIBS" + save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$AUDACIOUS_CFLAGS -I`pkg-config --variable=audacious_include_dir audacious`/audacious" + AC_CHECK_HEADERS([audacious/beepctrl.h glib.h], [], AC_MSG_ERROR([required header(s) not found])) + CPPFLAGS="$save_CPPFLAGS" + AC_DEFINE(AUDACIOUS, 1, [Define for Audacious support]) + AC_DEFINE(AUDACIOUS_LEGACY, 1, [Define for Audacious Legacy support]) + fi fi diff --git a/src/audacious.c b/src/audacious.c index 9f40516d..c6c22067 100644 --- a/src/audacious.c +++ b/src/audacious.c @@ -26,7 +26,23 @@ #include #include +#ifndef AUDACIOUS_LEGACY +#include +#include +#include +#else #include +#define audacious_remote_is_running(x) xmms_remote_is_running(x) +#define audacious_remote_is_paused(x) xmms_remote_is_paused(x) +#define audacious_remote_is_playing(x) xmms_remote_is_playing(x) +#define audacious_remote_get_playlist_pos(x) xmms_remote_get_playlist_pos(x) +#define audacious_remote_get_playlist_title(x) xmms_remote_get_playlist_title(x) +#define audacious_remote_get_playlist_time(x) xmms_remote_get_playlist_time(x) +#define audacious_remote_get_output_time(x) xmms_remote_get_output_time(x) +#define audacious_remote_get_info(x) xmms_remote_get_info(x) +#define audacious_remote_get_playlist_file(x) xmms_remote_get_playlist_file(x) +#define audacious_remote_get_playlist_length(x) xmms_remote_get_playlist_length(x) +#endif #include "config.h" #include "conky.h" @@ -94,19 +110,42 @@ int destroy_audacious_thread(void) void *audacious_thread_func(void *pvoid) { static audacious_t items; - gint session,playpos,frames,length; + gint playpos,frames,length; gint rate,freq,chans; gchar *psong,*pfilename; +#ifndef AUDACIOUS_LEGACY + DBusGProxy *session = NULL; + DBusGConnection *connection = NULL; +#else + gint session; +#endif + + pvoid=(void *)pvoid; /* avoid warning */ session=0; psong=NULL; pfilename=NULL; +#ifndef AUDACIOUS_LEGACY + g_type_init (); + connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); + if (!connection) { + CRIT_ERR ("unable to establish dbus connection"); + } + session = dbus_g_proxy_new_for_name (connection, + AUDACIOUS_DBUS_SERVICE, + AUDACIOUS_DBUS_PATH, + AUDACIOUS_DBUS_INTERFACE); + if (!session) { + CRIT_ERR ("unable to establish dbus proxy"); + } +#endif /* AUDACIOUS_LEGACY */ + /* Loop until the main thread sets the runnable signal to 0i via timed_thread_destroy. */ while (1) { - if (!xmms_remote_is_running (session)) + if (!audacious_remote_is_running (session)) { memset(&items,0,sizeof(items)); strcpy(items[AUDACIOUS_STATUS],"Not running"); @@ -114,16 +153,16 @@ void *audacious_thread_func(void *pvoid) } /* Player status */ - if (xmms_remote_is_paused (session)) + if (audacious_remote_is_paused (session)) strcpy(items[AUDACIOUS_STATUS],"Paused"); - else if (xmms_remote_is_playing (session)) + else if (audacious_remote_is_playing (session)) strcpy(items[AUDACIOUS_STATUS],"Playing"); else strcpy(items[AUDACIOUS_STATUS],"Stopped"); /* Current song title */ - playpos = xmms_remote_get_playlist_pos (session); - psong = xmms_remote_get_playlist_title (session, playpos); + playpos = audacious_remote_get_playlist_pos (session); + psong = audacious_remote_get_playlist_title (session, playpos); if (psong) { strncpy(items[AUDACIOUS_TITLE],psong,sizeof(items[AUDACIOUS_TITLE])-1); @@ -132,7 +171,7 @@ void *audacious_thread_func(void *pvoid) } /* Current song length as MM:SS */ - frames = xmms_remote_get_playlist_time (session,playpos); + frames = audacious_remote_get_playlist_time (session,playpos); length = frames / 1000; snprintf(items[AUDACIOUS_LENGTH],sizeof(items[AUDACIOUS_LENGTH])-1, "%d:%.2d", length / 60, length % 60); @@ -140,7 +179,7 @@ void *audacious_thread_func(void *pvoid) snprintf(items[AUDACIOUS_LENGTH_SECONDS],sizeof(items[AUDACIOUS_LENGTH_SECONDS])-1, "%d", length); /* Current song position as MM:SS */ - frames = xmms_remote_get_output_time (session); + frames = audacious_remote_get_output_time (session); length = frames / 1000; snprintf(items[AUDACIOUS_POSITION],sizeof(items[AUDACIOUS_POSITION])-1, "%d:%.2d", length / 60, length % 60); @@ -149,7 +188,7 @@ void *audacious_thread_func(void *pvoid) snprintf(items[AUDACIOUS_POSITION_SECONDS],sizeof(items[AUDACIOUS_POSITION_SECONDS])-1, "%d", length); /* Current song bitrate */ - xmms_remote_get_info (session, &rate, &freq, &chans); + audacious_remote_get_info (session, &rate, &freq, &chans); snprintf(items[AUDACIOUS_BITRATE],sizeof(items[AUDACIOUS_BITRATE])-1, "%d", rate); /* Current song frequency */ @@ -159,7 +198,7 @@ void *audacious_thread_func(void *pvoid) snprintf(items[AUDACIOUS_CHANNELS],sizeof(items[AUDACIOUS_CHANNELS])-1, "%d", chans); /* Current song filename */ - pfilename = xmms_remote_get_playlist_file (session,playpos); + pfilename = audacious_remote_get_playlist_file (session,playpos); if (pfilename) { strncpy(items[AUDACIOUS_FILENAME],pfilename,sizeof(items[AUDACIOUS_FILENAME])-1); @@ -168,7 +207,7 @@ void *audacious_thread_func(void *pvoid) } /* Length of the Playlist (number of songs) */ - length = xmms_remote_get_playlist_length (session); + length = audacious_remote_get_playlist_length (session); snprintf(items[AUDACIOUS_PLAYLIST_LENGTH],sizeof(items[AUDACIOUS_PLAYLIST_LENGTH])-1, "%d", length); /* Playlist position (index of song) */