• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
textfilesensor.cpp
1/***************************************************************************
2 * Copyright (C) 2003 by Hans Karlsson *
3 * karlsson.h@home.se *
4 * *
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 "textfilesensor.h"
11#include "tqdom.h"
12
13TextFileSensor::TextFileSensor( const TQString &fn, bool iRdf, int interval, const TQString &encoding )
14 : Sensor( interval )
15{
16 fileName = fn;
17 rdf = iRdf;
18
19 if( !encoding.isEmpty() )
20 {
21 codec = TQTextCodec::codecForName( encoding.ascii() );
22 if ( codec == 0)
23 codec = TQTextCodec::codecForLocale();
24 }
25 else
26 codec = TQTextCodec::codecForLocale();
27}
28
29TextFileSensor::~TextFileSensor()
30{}
31
32void TextFileSensor::update()
33{
34 TQValueVector<TQString> lines;
35 TQFile file(fileName);
36 TQString line;
37 if ( file.open(IO_ReadOnly | IO_Translate) )
38 {
39 if (rdf)
40 {
41 TQDomDocument doc;
42 if ( !doc.setContent( &file ) )
43 {
44 file.close();
45 return;
46 }
47 TQDomElement docElem = doc.documentElement();
48 TQDomNode n = docElem.firstChild();
49 if (!n.isNull())
50 {
51 TQDomNodeList titles = docElem.elementsByTagName( "title" );
52 TQDomNodeList links = docElem.elementsByTagName( "link" );
53
54 uint i;
55 for ( i = 0; i < titles.count(); ++i )
56 {
57 TQDomElement element = titles.item( i ).toElement();
58 lines.push_back(element.text());
59
60 element = links.item( i ).toElement();
61 lines.push_back(element.text());
62 }
63 }
64 }
65 else
66 {
67 TQTextStream t( &file ); // use a text stream
68 while( (line = t.readLine()) !=0 )
69 {
70 lines.push_back(line);
71 }
72 }
73 file.close();
74 }
75
76 int lineNbr;
77 SensorParams *sp;
78 Meter *meter;
79
80 int count = (int) lines.size();
81 TQObjectListIt it( *objList );
82 while (it != 0)
83 {
84 sp = (SensorParams*)(*it);
85 meter = sp->getMeter();
86 lineNbr = (sp->getParam("LINE")).toInt();
87 if ( lineNbr >= 1 && lineNbr <= (int) count )
88 {
89 meter->setValue(lines[lineNbr-1]);
90 }
91 if ( -lineNbr >= 1 && -lineNbr <= (int) count )
92 {
93 meter->setValue(lines[count+lineNbr]);
94 }
95
96 if ( lineNbr == 0 )
97 {
98 TQString text;
99 for( int i=0; i < count; i++ )
100 {
101 text += lines[i] + "\n";
102 }
103 meter->setValue( text );
104 }
105 ++it;
106 }
107}
108
109#include "textfilesensor.moc"
SensorParams
Hans Karlsson.
Definition: sensorparams.h:32

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.