summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/noatunsensor.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /superkaramba/src/noatunsensor.cpp
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'superkaramba/src/noatunsensor.cpp')
-rw-r--r--superkaramba/src/noatunsensor.cpp234
1 files changed, 234 insertions, 0 deletions
diff --git a/superkaramba/src/noatunsensor.cpp b/superkaramba/src/noatunsensor.cpp
new file mode 100644
index 0000000..607da9e
--- /dev/null
+++ b/superkaramba/src/noatunsensor.cpp
@@ -0,0 +1,234 @@
+/***************************************************************************
+ * Copyright (C) 2003 by Hans Karlsson *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "noatunsensor.h"
+
+NoatunSensor::NoatunSensor( int interval, DCOPClient *c)
+ : Sensor( interval )
+{
+ client = c;
+ noatunID = "noatun";
+}
+
+
+NoatunSensor::~NoatunSensor()
+{}
+
+
+void NoatunSensor::update()
+{
+ QString format;
+ SensorParams *sp;
+ Meter *meter;
+ QObjectListIt it( *objList );
+
+ QString title;
+ int songLength = 0;
+ int currentTime = 0;
+
+ bool running = isRunning();
+
+ if( running )
+ {
+ title = getTitle();
+
+ if( title.isEmpty() )
+ title = "Noatun";
+ currentTime = getTime();
+ if( currentTime == -1 )
+ currentTime = 0;
+
+ songLength = getLength();
+ if( songLength == -1 )
+ songLength = 0;
+ }
+
+
+ while (it != 0)
+ {
+ sp = (SensorParams*)(*it);
+ meter = sp->getMeter();
+
+ if( running )
+ {
+
+ format = sp->getParam("FORMAT");
+ if (format.length() == 0 )
+ {
+ format = "%title %time / %length";
+ }
+
+ if( format.lower() == "%ms" )
+ {
+ meter->setMax( songLength );
+ meter->setValue( currentTime );
+ }
+ else
+ if ( format.lower() == "%full" )
+ {
+ meter->setValue( 1 );
+ }
+ else
+
+ {
+ format.replace( QRegExp("%title", false), title );
+ format.replace( QRegExp("%id", false), noatunID );
+
+ format.replace( QRegExp("%length", false), QTime( 0,0,0 ).
+ addMSecs( songLength )
+ .toString( "h:mm:ss" ) );
+
+ format.replace( QRegExp("%time", false), QTime( 0,0,0 ).
+ addMSecs( currentTime )
+ .toString( "h:mm:ss" ) );
+ format.replace( QRegExp("%remain", false), QTime( 0,0,0 ).
+ addMSecs( songLength )
+ .addMSecs(-currentTime )
+ .toString( "h:mm:ss" ) );
+
+ meter->setValue(format);
+ }
+ }
+ else
+
+ {
+ meter->setValue("");
+ }
+ ++it;
+
+
+ }
+
+}
+
+bool NoatunSensor::isRunning()
+{
+ QRegExp rx("(noatun)|(noatun-\\d+)");
+ QCStringList list = client->registeredApplications();
+ QValueList<QCString>::iterator it;
+ it = list.begin();
+ bool foundNoatun = false;
+ noatunID = "noatun";
+ while( foundNoatun == false && it != list.end() )
+ {
+ if( rx.search( *it ) != -1 )
+ {
+ foundNoatun = true;
+ noatunID = *it;
+ }
+ ++it;
+ }
+ return ( client->isApplicationRegistered ( noatunID ) );
+}
+
+
+QString NoatunSensor::getTitle()
+{
+ QByteArray data, replyData;
+ QCString replyType;
+ QString result;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << 5;
+ if (!client->call( noatunID, "Noatun", "title()",
+ data, replyType, replyData))
+ {
+ result = "";
+ qDebug("there was some error using DCOP.");
+ }
+ else
+ {
+ QDataStream reply(replyData, IO_ReadOnly);
+ if (replyType == "QString")
+ {
+ reply >> result;
+ result.replace( QRegExp("_")," " );
+ result.replace( QRegExp(".mp3$"),"" );
+
+ }
+ else
+ {
+ result = "";
+ qDebug("title returned an unexpected type of reply!");
+ }
+ }
+ return result;
+}
+
+
+int NoatunSensor::getTime()
+{
+ QByteArray data, replyData;
+ QCString replyType;
+ int result;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << 5;
+ if (!client->call( noatunID, "Noatun", "position()",
+ data, replyType, replyData))
+ {
+ result = 0;
+ qDebug("there was some error using DCOP.");
+ }
+ else
+ {
+ QDataStream reply(replyData, IO_ReadOnly);
+ if (replyType == "int")
+ {
+ reply >> result;
+ }
+ else
+ {
+ result = 0;
+ qDebug("title returned an unexpected type of reply!");
+ }
+ }
+ return result;
+}
+
+
+int NoatunSensor::getLength()
+{
+ QByteArray data, replyData;
+ QCString replyType;
+ int result;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << 5;
+ if (!client->call( noatunID, "Noatun", "length()",
+ data, replyType, replyData))
+ {
+ result = 0;
+ qDebug("there was some error using DCOP.");
+ }
+ else
+ {
+ QDataStream reply(replyData, IO_ReadOnly);
+ if (replyType == "int")
+ {
+ reply >> result;
+ }
+ else
+ {
+ result = 0;
+ qDebug("title returned an unexpected type of reply!");
+ }
+ }
+ return result;
+}
+
+
+void NoatunSensor::setMaxValue( SensorParams *sp)
+{
+ Meter *meter;
+ meter = sp->getMeter();
+ QString f;
+ f = sp->getParam("FORMAT");
+
+ if ( f == "%full" )
+ meter->setMax( 1 );
+
+}