diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch) | |
tree | 8d927b7b47a90c4adb646482a52613f58acd6f8c /superkaramba/src/rsssensor.cpp | |
download | tdeutils-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/rsssensor.cpp')
-rw-r--r-- | superkaramba/src/rsssensor.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/superkaramba/src/rsssensor.cpp b/superkaramba/src/rsssensor.cpp new file mode 100644 index 0000000..1477062 --- /dev/null +++ b/superkaramba/src/rsssensor.cpp @@ -0,0 +1,136 @@ +/*************************************************************************** + * Copyright (C) 2003 by Ralph M. Churchill * + * mrchucho@yahoo.com * + * * + * 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 "karambaapp.h" +#include "rsssensor.h" +#include <qdom.h> +#include <qregexp.h> +#include <kurl.h> +#include <kio/netaccess.h> + +RssSensor::RssSensor( const QString &src, int interval, const QString &form, const QString &enc) + : Sensor(interval), + source(src), + format(form), + encoding(enc) + +{ + // Format: + // %t = title (DEFAULT) + // %d = desc + + if( !encoding.isEmpty() ) + { + codec = QTextCodec::codecForName( encoding.ascii() ); + if ( codec == 0) + codec = QTextCodec::codecForLocale(); + } + else + codec = QTextCodec::codecForLocale(); +} + +RssSensor::~RssSensor() +{ +} + +void RssSensor::update() +{ + QDomDocument doc; + QFile file; + QString tmpFile; + bool OK = false; + +#if defined(KDE_3_3) + if(KIO::NetAccess::download(KURL(source), tmpFile, karambaApp->parentWindow())) +#else + if(KIO::NetAccess::download(KURL(source), tmpFile)) +#endif + { + file.setName(tmpFile); + if ( file.open(IO_ReadOnly | IO_Translate) ) + { + if ( doc.setContent( &file ) ) + { + OK = true; + } + else + { + qDebug("Error on building DOM"); + } + } + else + { + qDebug("Error opening file"); + } + } + else { + qDebug( "Error Downloading: %s", source.ascii()); + } + + if ( OK ) + { + SensorParams *sp; + Meter *meter; + + QObjectListIt it( *objList ); + while (it != 0) + { + sp = (SensorParams*)(*it); + meter = sp->getMeter(); + + // this is a hack to force the + // clickmap to reset its data lists + meter->setValue(0); + + QDomElement docElem = doc.documentElement(); + QDomNode n = docElem.firstChild(); + if (!n.isNull()) + { + QDomNodeList links = docElem.elementsByTagName( "link" ); + QDomNodeList displays; + if ( format.contains( "%d", false ) > 0 ) + { + displays = docElem.elementsByTagName( "description" ); + } + else + { + displays = docElem.elementsByTagName( "title" ); + } + + QRegExp rx("^http://", false ); + for (uint i=1; i < displays.count(); ++i ) + { + QString dispTxt = displays.item( i ).toElement().text(); + QString linkTxt = links.item( i ).toElement().text(); + if( (rx.search(dispTxt) == -1) && (rx.search(linkTxt) != -1) ) + { + meter->setValue( dispTxt ); + meter->setValue( linkTxt ); + } + else + { + qDebug("Skipping"); + } + } + } + else + { + qDebug ("Document Node was null!!"); + } + + ++it; + } + } + // Cleanup + file.close(); + KIO::NetAccess::removeTempFile( tmpFile ); +} + +#include "rsssensor.moc" |