1
/***************************************************************************
2
* Copyright (C) 2003 by Hans Karlsson *
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 "noatunsensor.h"
12
NoatunSensor::NoatunSensor( int interval, DCOPClient *c)
20
NoatunSensor::~NoatunSensor()
24
void NoatunSensor::update()
29
QObjectListIt it( *objList );
35
bool running = isRunning();
43
currentTime = getTime();
44
if( currentTime == -1 )
47
songLength = getLength();
48
if( songLength == -1 )
55
sp = (SensorParams*)(*it);
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( QRegExp("%title", false), title );
81
format.replace( QRegExp("%id", false), noatunID );
83
format.replace( QRegExp("%length", false), QTime( 0,0,0 ).
84
addMSecs( songLength )
85
.toString( "h:mm:ss" ) );
87
format.replace( QRegExp("%time", false), QTime( 0,0,0 ).
88
addMSecs( currentTime )
89
.toString( "h:mm:ss" ) );
90
format.replace( QRegExp("%remain", false), QTime( 0,0,0 ).
91
addMSecs( songLength )
92
.addMSecs(-currentTime )
93
.toString( "h:mm:ss" ) );
95
meter->setValue(format);
110
bool NoatunSensor::isRunning()
112
QRegExp rx("(noatun)|(noatun-\\d+)");
113
QCStringList list = client->registeredApplications();
114
QValueList<QCString>::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
QString NoatunSensor::getTitle()
133
QByteArray data, replyData;
136
QDataStream arg(data, IO_WriteOnly);
138
if (!client->call( noatunID, "Noatun", "title()",
139
data, replyType, replyData))
142
qDebug("there was some error using DCOP.");
146
QDataStream reply(replyData, IO_ReadOnly);
147
if (replyType == "QString")
150
result.replace( QRegExp("_")," " );
151
result.replace( QRegExp(".mp3$"),"" );
157
qDebug("title returned an unexpected type of reply!");
164
int NoatunSensor::getTime()
166
QByteArray data, replyData;
169
QDataStream arg(data, IO_WriteOnly);
171
if (!client->call( noatunID, "Noatun", "position()",
172
data, replyType, replyData))
175
qDebug("there was some error using DCOP.");
179
QDataStream reply(replyData, IO_ReadOnly);
180
if (replyType == "int")
187
qDebug("title returned an unexpected type of reply!");
194
int NoatunSensor::getLength()
196
QByteArray data, replyData;
199
QDataStream arg(data, IO_WriteOnly);
201
if (!client->call( noatunID, "Noatun", "length()",
202
data, replyType, replyData))
205
qDebug("there was some error using DCOP.");
209
QDataStream reply(replyData, IO_ReadOnly);
210
if (replyType == "int")
217
qDebug("title returned an unexpected type of reply!");
224
void NoatunSensor::setMaxValue( SensorParams *sp)
227
meter = sp->getMeter();
229
f = sp->getParam("FORMAT");