• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

superkaramba

  • sources
  • kde-4.12
  • kdeutils
  • superkaramba
  • src
  • sensors
textfile.cpp
Go to the documentation of this file.
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 
11 #include "textfile.h"
12 
13 #include <QTextCodec>
14 #include <QTextStream>
15 #include <QDomDocument>
16 
17 TextFileSensor::TextFileSensor(const QString &fn, bool iRdf, int interval, const QString &encoding)
18  : Sensor(interval)
19 {
20  fileName = fn;
21  rdf = iRdf;
22 
23  if (!encoding.isEmpty()) {
24  codec = QTextCodec::codecForName(encoding.toAscii().constData());
25  if (codec == 0)
26  codec = QTextCodec::codecForLocale();
27  } else
28  codec = QTextCodec::codecForLocale();
29 }
30 
31 TextFileSensor::~TextFileSensor()
32 {}
33 
34 void TextFileSensor::update()
35 {
36  QVector<QString> lines;
37  QFile file(fileName);
38  QString line;
39  if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
40  if (rdf) {
41  QDomDocument doc;
42  if (!doc.setContent(&file)) {
43  file.close();
44  return;
45  }
46  QDomElement docElem = doc.documentElement();
47  QDomNode n = docElem.firstChild();
48  if (!n.isNull()) {
49  QDomNodeList titles = docElem.elementsByTagName("title");
50  QDomNodeList links = docElem.elementsByTagName("link");
51 
52  int i;
53  for (i = 0; i < titles.count(); ++i) {
54  QDomElement element = titles.item(i).toElement();
55  lines.push_back(element.text());
56 
57  element = links.item(i).toElement();
58  lines.push_back(element.text());
59  }
60  }
61  } else {
62  QTextStream t(&file);
63  while ((line = t.readLine()) != 0) {
64  lines.push_back(line);
65  }
66  }
67  file.close();
68  }
69 
70  int lineNbr;
71  SensorParams *sp;
72  Meter *meter;
73 
74  int count = (int) lines.size();
75  QObject *obj;
76  foreach(obj, *objList) {
77  sp = (SensorParams*)(obj);
78  meter = sp->getMeter();
79  lineNbr = (sp->getParam("LINE")).toInt();
80  if (lineNbr >= 1 && lineNbr <= (int) count) {
81  meter->setValue(lines[lineNbr-1]);
82  }
83  if (-lineNbr >= 1 && -lineNbr <= (int) count) {
84  meter->setValue(lines[count+lineNbr]);
85  }
86 
87  if (lineNbr == 0) {
88  QString text;
89  for (int i = 0; i < count; i++) {
90  text += lines[i] + '\n';
91  }
92  meter->setValue(text);
93  }
94  }
95 }
96 
97 #include "textfile.moc"
SensorParams::getMeter
Meter * getMeter() const
Definition: sensorparams.cpp:31
QObject
Sensor
Definition: sensor.h:17
SensorParams
Hans Karlsson.
Definition: sensorparams.h:30
TextFileSensor::TextFileSensor
TextFileSensor(const QString &fileName, bool rdf, int interval, const QString &encoding=QString())
Definition: textfile.cpp:17
SensorParams::getParam
QString getParam(const QString &) const
Definition: sensorparams.cpp:26
textfile.h
TextFileSensor::update
void update()
Definition: textfile.cpp:34
Meter
Definition: meters/meter.h:23
Meter::setValue
virtual void setValue(int)
Definition: meters/meter.cpp:136
TextFileSensor::~TextFileSensor
~TextFileSensor()
Definition: textfile.cpp:31
Sensor::objList
QList< QObject * > * objList
Definition: sensor.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

superkaramba

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

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal