• 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
rss.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2003 by Ralph M. Churchill *
3  * mrchucho@yahoo.com *
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 "rss.h"
11 #include "rss.moc"
12 
13 #include <QDomDocument>
14 #include <QTextCodec>
15 #include <QFile>
16 
17 #include <KUrl>
18 #include <kio/netaccess.h>
19 
20 RssSensor::RssSensor(const QString &src, int interval, const QString &form, const QString &enc)
21  : Sensor(interval),
22  source(src),
23  format(form),
24  encoding(enc)
25 
26 {
27  // Format:
28  // %t = title (DEFAULT)
29  // %d = desc
30 
31  if (!encoding.isEmpty()) {
32  codec = QTextCodec::codecForName(encoding.toAscii().constData());
33  if (codec == 0)
34  codec = QTextCodec::codecForLocale();
35  } else
36  codec = QTextCodec::codecForLocale();
37 }
38 
39 RssSensor::~RssSensor()
40 {}
41 
42 void RssSensor::update()
43 {
44  QDomDocument doc;
45  QFile file;
46  QString tmpFile;
47  bool OK = false;
48 
49  if (KIO::NetAccess::download(KUrl(source), tmpFile, 0)) {
50  file.setFileName(tmpFile);
51  if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
52  if (doc.setContent(&file)) {
53  OK = true;
54  } else {
55  qDebug("Error on building DOM");
56  }
57  } else {
58  qDebug("Error opening file");
59  }
60  } else {
61  qDebug("Error Downloading: %s", source.toAscii().constData());
62  }
63 
64  if (OK) {
65  SensorParams *sp;
66  Meter *meter;
67 
68  QObject *obj;
69  foreach(obj, *objList) {
70  sp = (SensorParams*)(obj);
71  meter = sp->getMeter();
72 
73  // this is a hack to force the
74  // clickmap to reset its data lists
75  meter->setValue(0);
76 
77  QDomElement docElem = doc.documentElement();
78  QDomNode n = docElem.firstChild();
79  if (!n.isNull()) {
80  QDomNodeList links = docElem.elementsByTagName("link");
81  QDomNodeList displays;
82  if (format.contains("%d", Qt::CaseInsensitive) > 0) {
83  displays = docElem.elementsByTagName("description");
84  } else {
85  displays = docElem.elementsByTagName("title");
86  }
87 
88  QRegExp rx("^http://", Qt::CaseInsensitive);
89  for (int i = 1; i < displays.count(); ++i) {
90  QString dispTxt = displays.item(i).toElement().text();
91  QString linkTxt = links.item(i).toElement().text();
92  if ((rx.indexIn(dispTxt) == -1) && (rx.indexIn(linkTxt) != -1)) {
93  meter->setValue(dispTxt);
94  meter->setValue(linkTxt);
95  } else {
96  qDebug("Skipping");
97  }
98  }
99  } else {
100  qDebug("Document Node was null!!");
101  }
102  }
103  }
104  // Cleanup
105  file.close();
106  KIO::NetAccess::removeTempFile(tmpFile);
107 }
108 
rss.h
RssSensor::RssSensor
RssSensor(const QString &source, int interval, const QString &format, const QString &encoding=QString())
Definition: rss.cpp:20
SensorParams::getMeter
Meter * getMeter() const
Definition: sensorparams.cpp:31
QObject
Sensor
Definition: sensor.h:17
RssSensor::update
void update()
Definition: rss.cpp:42
SensorParams
Hans Karlsson.
Definition: sensorparams.h:30
RssSensor::~RssSensor
~RssSensor()
Definition: rss.cpp:39
Meter
Definition: meters/meter.h:23
Meter::setValue
virtual void setValue(int)
Definition: meters/meter.cpp:136
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