• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
xmmssensor.cpp
1/***************************************************************************
2* Copyright (C) 2003 by Hans Karlsson *
3* karlsson.h@home.se *
4* *
5* This program is free software; you can redistribute it and/or modify *
6* it under the terms of the GNU General Public License as published by *
7* the Free Software Foundation; either version 2 of the License, or *
8* (at your option) any later version. *
9***************************************************************************/
10#include "xmmssensor.h"
11
12#ifdef HAVE_XMMS
13#include <tqlibrary.h>
14
15class XMMSSensor::XMMS
16{
17public:
18 XMMS() : libxmms( 0 )
19 {
20 libxmms = new TQLibrary( "xmms.so.1" );
21 if ( !libxmms->load() )
22 {
23 delete libxmms;
24 libxmms = 0;
25 }
26
27 if ( libxmms != 0 )
28 {
29 // resolve functions
30 *(void**) (&xmms_remote_is_running) =
31 libxmms->resolve( "xmms_remote_is_running" );
32
33 *(void**) (&xmms_remote_is_playing) =
34 libxmms->resolve( "xmms_remote_is_playing" );
35
36 *(void**) (&xmms_remote_get_playlist_title) =
37 libxmms->resolve( "xmms_remote_get_playlist_title" );
38
39 *(void**) (&xmms_remote_get_playlist_time) =
40 libxmms->resolve( "xmms_remote_get_playlist_time" );
41
42 *(void**) (&xmms_remote_get_playlist_pos) =
43 libxmms->resolve( "xmms_remote_get_playlist_pos" );
44
45 *(void**) (&xmms_remote_get_output_time) =
46 libxmms->resolve( "xmms_remote_get_output_time" );
47 }
48 }
49
50 bool isInitialized() const
51 {
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;
59 }
60
61 bool isRunning(int session)
62 {
63 if ( !isInitialized() ) return false;
64
65 return (*xmms_remote_is_running)(session);
66 }
67
68 bool isPlaying(int session)
69 {
70 if ( !isInitialized() ) return false;
71
72 return (*xmms_remote_is_playing)(session);
73 }
74
75 char* getPlaylistTitle(int session, int pos)
76 {
77 if ( !isInitialized() ) return "";
78
79 return (*xmms_remote_get_playlist_title)(session, pos);
80 }
81
82 int getPlaylistTime(int session, int pos)
83 {
84 if ( !isInitialized() ) return 0;
85
86 return (*xmms_remote_get_playlist_time)(session, pos);
87 }
88
89 int getPlaylistPos(int session)
90 {
91 if ( !isInitialized() ) return 0;
92
93 return (*xmms_remote_get_playlist_pos)(session);
94 }
95
96 int getOutputTime(int session)
97 {
98 if ( !isInitialized() ) return 0;
99
100 return (*xmms_remote_get_output_time)(session);
101 }
102
103private:
104 TQLibrary* libxmms;
105
106 bool (*xmms_remote_is_running)(int);
107 bool (*xmms_remote_is_playing)(int);
108
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);
113};
114
115#else // No XMMS
116
117class XMMSSensor::XMMS
118{
119public:
120 XMMS() {}
121
122 bool isInitialized() const { return false; }
123};
124#endif // HAVE_XMMS
125
126
127XMMSSensor::XMMSSensor( int interval, const TQString &encoding )
128 : Sensor( interval ), xmms( 0 )
129{
130 if( !encoding.isEmpty() )
131 {
132 codec = TQTextCodec::codecForName( encoding.ascii() );
133 if ( codec == 0)
134 codec = TQTextCodec::codecForLocale();
135 }
136 else
137 codec = TQTextCodec::codecForLocale();
138
139 xmms = new XMMS();
140
141}
142XMMSSensor::~XMMSSensor()
143{
144 delete xmms;
145}
146
147void XMMSSensor::update()
148{
149 TQString format;
150 SensorParams *sp;
151 Meter *meter;
152 TQObjectListIt it( *objList );
153
154#ifdef HAVE_XMMS
155
156 int pos;
157 TQString title;
158 int songLength = 0;
159 int currentTime = 0;
160 bool isPlaying = false;
161 bool isRunning = xmms->isRunning(0);
162
163 if( isRunning )
164 {
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() )
171 title = "XMMS";
172
173 tqDebug("Title: %s", title.ascii());
174 songLength = xmms->getPlaylistTime( 0, pos );
175 currentTime = xmms->getOutputTime( 0 );
176 }
177#endif // HAVE_XMMS
178
179 while (it != 0)
180 {
181 sp = (SensorParams*)(*it);
182 meter = sp->getMeter();
183
184#ifdef HAVE_XMMS
185
186 if( isRunning )
187 {
188
189 format = sp->getParam("FORMAT");
190
191
192 if (format.length() == 0 )
193 {
194 format = "%title %time / %length";
195 }
196
197 if( format == "%ms" )
198 {
199 meter->setMax( songLength );
200 meter->setValue( currentTime );
201 }
202 else
203
204 if ( format == "%full" )
205 {
206 meter->setValue( 1 );
207 }
208 else
209
210 {
211
212
213 format.replace( TQRegExp("%title", false), title );
214
215 format.replace( TQRegExp("%length", false), TQTime( 0,0,0 ).
216 addMSecs( songLength )
217 .toString( "h:mm:ss" ) );
218
219 format.replace( TQRegExp("%time", false), TQTime( 0,0,0 ).
220 addMSecs( currentTime )
221 .toString( "h:mm:ss" ) );
222
223 if( isPlaying )
224 {
225 format.replace( TQRegExp("%remain", false), TQTime( 0,0,0 ).
226 addMSecs( songLength )
227 .addMSecs(-currentTime )
228 .toString( "h:mm:ss" ) );
229 }
230
231 else
232 {
233 format.replace( TQRegExp("%remain", false), TQTime( 0,0,0 ).toString("h:mm:ss" ) );
234 }
235 meter->setValue(format);
236 }
237 }
238 else
239#endif // HAVE_XMMS
240
241 {
242 meter->setValue("");
243 }
244 ++it;
245
246 }
247
248}
249
250void XMMSSensor::setMaxValue( SensorParams *sp)
251{
252 Meter *meter;
253 meter = sp->getMeter();
254 TQString f;
255 f = sp->getParam("FORMAT");
256
257 if ( f == "%full" )
258 meter->setMax( 1 );
259
260}
261
262bool XMMSSensor::hasXMMS() const
263{
264 return xmms->isInitialized();
265}
266
267#include "xmmssensor.moc"
SensorParams
Hans Karlsson.
Definition: sensorparams.h:32

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.