10#include "textfilesensor.h"
13TextFileSensor::TextFileSensor(
const TQString &fn,
bool iRdf,
int interval,
const TQString &encoding )
19 if( !encoding.isEmpty() )
21 codec = TQTextCodec::codecForName( encoding.ascii() );
23 codec = TQTextCodec::codecForLocale();
26 codec = TQTextCodec::codecForLocale();
29TextFileSensor::~TextFileSensor()
32void TextFileSensor::update()
34 TQValueVector<TQString> lines;
35 TQFile file(fileName);
37 if ( file.open(IO_ReadOnly | IO_Translate) )
42 if ( !doc.setContent( &file ) )
47 TQDomElement docElem = doc.documentElement();
48 TQDomNode n = docElem.firstChild();
51 TQDomNodeList titles = docElem.elementsByTagName(
"title" );
52 TQDomNodeList links = docElem.elementsByTagName(
"link" );
55 for ( i = 0; i < titles.count(); ++i )
57 TQDomElement element = titles.item( i ).toElement();
58 lines.push_back(element.text());
60 element = links.item( i ).toElement();
61 lines.push_back(element.text());
67 TQTextStream t( &file );
68 while( (line = t.readLine()) !=0 )
70 lines.push_back(line);
80 int count = (int) lines.size();
81 TQObjectListIt it( *objList );
85 meter = sp->getMeter();
86 lineNbr = (sp->getParam(
"LINE")).toInt();
87 if ( lineNbr >= 1 && lineNbr <= (
int) count )
89 meter->setValue(lines[lineNbr-1]);
91 if ( -lineNbr >= 1 && -lineNbr <= (
int) count )
93 meter->setValue(lines[count+lineNbr]);
99 for(
int i=0; i < count; i++ )
101 text += lines[i] +
"\n";
103 meter->setValue( text );
109#include "textfilesensor.moc"