11 #include "karambaapp.h"
12 #include "rsssensor.h"
16 #include <tdeio/netaccess.h>
18 RssSensor::RssSensor(
const TQString &src,
int interval,
const TQString &form,
const TQString &enc)
29 if( !encoding.isEmpty() )
31 codec = TQTextCodec::codecForName( encoding.ascii() );
33 codec = TQTextCodec::codecForLocale();
36 codec = TQTextCodec::codecForLocale();
39 RssSensor::~RssSensor()
43 void RssSensor::update()
50 if(TDEIO::NetAccess::download(KURL(source), tmpFile, karambaApp->parentWindow()))
52 file.setName(tmpFile);
53 if ( file.open(IO_ReadOnly | IO_Translate) )
55 if ( doc.setContent( &file ) )
61 tqDebug(
"Error on building DOM");
66 tqDebug(
"Error opening file");
70 tqDebug(
"Error Downloading: %s", source.ascii());
78 TQObjectListIt it( *objList );
82 meter = sp->getMeter();
88 TQDomElement docElem = doc.documentElement();
89 TQDomNode n = docElem.firstChild();
92 TQDomNodeList links = docElem.elementsByTagName(
"link" );
93 TQDomNodeList displays;
94 if ( format.contains(
"%d",
false ) > 0 )
96 displays = docElem.elementsByTagName(
"description" );
100 displays = docElem.elementsByTagName(
"title" );
103 TQRegExp rx(
"^http://",
false );
104 for (uint i=1; i < displays.count(); ++i )
106 TQString dispTxt = displays.item( i ).toElement().text();
107 TQString linkTxt = links.item( i ).toElement().text();
108 if( (rx.search(dispTxt) == -1) && (rx.search(linkTxt) != -1) )
110 meter->setValue( dispTxt );
111 meter->setValue( linkTxt );
121 tqDebug (
"Document Node was null!!");
129 TDEIO::NetAccess::removeTempFile( tmpFile );
132 #include "rsssensor.moc"