10#include "xmmssensor.h"
20 libxmms =
new TQLibrary(
"xmms.so.1" );
21 if ( !libxmms->load() )
30 *(
void**) (&xmms_remote_is_running) =
31 libxmms->resolve(
"xmms_remote_is_running" );
33 *(
void**) (&xmms_remote_is_playing) =
34 libxmms->resolve(
"xmms_remote_is_playing" );
36 *(
void**) (&xmms_remote_get_playlist_title) =
37 libxmms->resolve(
"xmms_remote_get_playlist_title" );
39 *(
void**) (&xmms_remote_get_playlist_time) =
40 libxmms->resolve(
"xmms_remote_get_playlist_time" );
42 *(
void**) (&xmms_remote_get_playlist_pos) =
43 libxmms->resolve(
"xmms_remote_get_playlist_pos" );
45 *(
void**) (&xmms_remote_get_output_time) =
46 libxmms->resolve(
"xmms_remote_get_output_time" );
50 bool isInitialized()
const
52 return libxmms != 0 &&
53 xmms_remote_is_running != 0 &&
54 xmms_remote_is_playing != 0 &&
55 xmms_remote_get_playlist_title != 0 &&
56 xmms_remote_get_playlist_time != 0 &&
57 xmms_remote_get_playlist_pos != 0 &&
58 xmms_remote_get_output_time != 0;
61 bool isRunning(
int session)
63 if ( !isInitialized() )
return false;
65 return (*xmms_remote_is_running)(session);
68 bool isPlaying(
int session)
70 if ( !isInitialized() )
return false;
72 return (*xmms_remote_is_playing)(session);
75 char* getPlaylistTitle(
int session,
int pos)
77 if ( !isInitialized() )
return "";
79 return (*xmms_remote_get_playlist_title)(session, pos);
82 int getPlaylistTime(
int session,
int pos)
84 if ( !isInitialized() )
return 0;
86 return (*xmms_remote_get_playlist_time)(session, pos);
89 int getPlaylistPos(
int session)
91 if ( !isInitialized() )
return 0;
93 return (*xmms_remote_get_playlist_pos)(session);
96 int getOutputTime(
int session)
98 if ( !isInitialized() )
return 0;
100 return (*xmms_remote_get_output_time)(session);
106 bool (*xmms_remote_is_running)(int);
107 bool (*xmms_remote_is_playing)(int);
109 char* (*xmms_remote_get_playlist_title)(int, int);
110 int (*xmms_remote_get_playlist_time)(int, int);
111 int (*xmms_remote_get_playlist_pos)(int);
112 int (*xmms_remote_get_output_time)(int);
117class XMMSSensor::XMMS
122 bool isInitialized()
const {
return false; }
127XMMSSensor::XMMSSensor(
int interval,
const TQString &encoding )
128 : Sensor( interval ), xmms( 0 )
130 if( !encoding.isEmpty() )
132 codec = TQTextCodec::codecForName( encoding.ascii() );
134 codec = TQTextCodec::codecForLocale();
137 codec = TQTextCodec::codecForLocale();
142XMMSSensor::~XMMSSensor()
147void XMMSSensor::update()
152 TQObjectListIt it( *objList );
160 bool isPlaying =
false;
161 bool isRunning = xmms->isRunning(0);
165 isPlaying = xmms->isPlaying(0);
166 pos = xmms->getPlaylistPos(0);
167 tqDebug(
"unicode start");
168 title = codec->toUnicode( TQCString( xmms->getPlaylistTitle( 0, pos ) ) );
169 tqDebug(
"unicode end");
170 if( title.isEmpty() )
173 tqDebug(
"Title: %s", title.ascii());
174 songLength = xmms->getPlaylistTime( 0, pos );
175 currentTime = xmms->getOutputTime( 0 );
182 meter = sp->getMeter();
189 format = sp->getParam(
"FORMAT");
192 if (format.length() == 0 )
194 format =
"%title %time / %length";
197 if( format ==
"%ms" )
199 meter->setMax( songLength );
200 meter->setValue( currentTime );
204 if ( format ==
"%full" )
206 meter->setValue( 1 );
213 format.replace( TQRegExp(
"%title",
false), title );
215 format.replace( TQRegExp(
"%length",
false), TQTime( 0,0,0 ).
216 addMSecs( songLength )
217 .toString(
"h:mm:ss" ) );
219 format.replace( TQRegExp(
"%time",
false), TQTime( 0,0,0 ).
220 addMSecs( currentTime )
221 .toString(
"h:mm:ss" ) );
225 format.replace( TQRegExp(
"%remain",
false), TQTime( 0,0,0 ).
226 addMSecs( songLength )
227 .addMSecs(-currentTime )
228 .toString(
"h:mm:ss" ) );
233 format.replace( TQRegExp(
"%remain",
false), TQTime( 0,0,0 ).toString(
"h:mm:ss" ) );
235 meter->setValue(format);
253 meter = sp->getMeter();
255 f = sp->getParam(
"FORMAT");
262bool XMMSSensor::hasXMMS()
const
264 return xmms->isInitialized();
267#include "xmmssensor.moc"