10 #include "noatunsensor.h" 12 NoatunSensor::NoatunSensor(
int interval, DCOPClient *c)
20 NoatunSensor::~NoatunSensor()
24 void NoatunSensor::update()
29 TQObjectListIt it( *objList );
35 bool running = isRunning();
43 currentTime = getTime();
44 if( currentTime == -1 )
47 songLength = getLength();
48 if( songLength == -1 )
56 meter = sp->getMeter();
61 format = sp->getParam(
"FORMAT");
62 if (format.length() == 0 )
64 format =
"%title %time / %length";
67 if( format.lower() ==
"%ms" )
69 meter->setMax( songLength );
70 meter->setValue( currentTime );
73 if ( format.lower() ==
"%full" )
80 format.replace( TQRegExp(
"%title",
false), title );
81 format.replace( TQRegExp(
"%id",
false), noatunID );
83 format.replace( TQRegExp(
"%length",
false), TQTime( 0,0,0 ).
84 addMSecs( songLength )
85 .toString(
"h:mm:ss" ) );
87 format.replace( TQRegExp(
"%time",
false), TQTime( 0,0,0 ).
88 addMSecs( currentTime )
89 .toString(
"h:mm:ss" ) );
90 format.replace( TQRegExp(
"%remain",
false), TQTime( 0,0,0 ).
91 addMSecs( songLength )
92 .addMSecs(-currentTime )
93 .toString(
"h:mm:ss" ) );
95 meter->setValue(format);
110 bool NoatunSensor::isRunning()
112 TQRegExp rx(
"(noatun)|(noatun-\\d+)");
113 QCStringList list = client->registeredApplications();
114 TQValueList<TQCString>::iterator it;
116 bool foundNoatun =
false;
118 while( foundNoatun ==
false && it != list.end() )
120 if( rx.search( *it ) != -1 )
127 return ( client->isApplicationRegistered ( noatunID ) );
131 TQString NoatunSensor::getTitle()
133 TQByteArray data, replyData;
136 TQDataStream arg(data, IO_WriteOnly);
138 if (!client->call( noatunID,
"Noatun",
"title()",
139 data, replyType, replyData))
142 tqDebug(
"there was some error using DCOP.");
146 TQDataStream reply(replyData, IO_ReadOnly);
147 if (replyType ==
"TQString")
150 result.replace( TQRegExp(
"_"),
" " );
151 result.replace( TQRegExp(
".mp3$"),
"" );
157 tqDebug(
"title returned an unexpected type of reply!");
164 int NoatunSensor::getTime()
166 TQByteArray data, replyData;
169 TQDataStream arg(data, IO_WriteOnly);
171 if (!client->call( noatunID,
"Noatun",
"position()",
172 data, replyType, replyData))
175 tqDebug(
"there was some error using DCOP.");
179 TQDataStream reply(replyData, IO_ReadOnly);
180 if (replyType ==
"int")
187 tqDebug(
"title returned an unexpected type of reply!");
194 int NoatunSensor::getLength()
196 TQByteArray data, replyData;
199 TQDataStream arg(data, IO_WriteOnly);
201 if (!client->call( noatunID,
"Noatun",
"length()",
202 data, replyType, replyData))
205 tqDebug(
"there was some error using DCOP.");
209 TQDataStream reply(replyData, IO_ReadOnly);
210 if (replyType ==
"int")
217 tqDebug(
"title returned an unexpected type of reply!");
227 meter = sp->getMeter();
229 f = sp->getParam(
"FORMAT");