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

superkaramba

  • superkaramba
  • src
rsssensor.cpp
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
11#include "karambaapp.h"
12#include "rsssensor.h"
13#include <tqdom.h>
14#include <tqregexp.h>
15#include <kurl.h>
16#include <tdeio/netaccess.h>
17
18RssSensor::RssSensor( const TQString &src, int interval, const TQString &form, const TQString &enc)
19 : Sensor(interval),
20 source(src),
21 format(form),
22 encoding(enc)
23
24{
25 // Format:
26 // %t = title (DEFAULT)
27 // %d = desc
28
29 if( !encoding.isEmpty() )
30 {
31 codec = TQTextCodec::codecForName( encoding.ascii() );
32 if ( codec == 0)
33 codec = TQTextCodec::codecForLocale();
34 }
35 else
36 codec = TQTextCodec::codecForLocale();
37}
38
39RssSensor::~RssSensor()
40{
41}
42
43void RssSensor::update()
44{
45 TQDomDocument doc;
46 TQFile file;
47 TQString tmpFile;
48 bool OK = false;
49
50 if(TDEIO::NetAccess::download(KURL(source), tmpFile, karambaApp->parentWindow()))
51 {
52 file.setName(tmpFile);
53 if ( file.open(IO_ReadOnly | IO_Translate) )
54 {
55 if ( doc.setContent( &file ) )
56 {
57 OK = true;
58 }
59 else
60 {
61 tqDebug("Error on building DOM");
62 }
63 }
64 else
65 {
66 tqDebug("Error opening file");
67 }
68 }
69 else {
70 tqDebug( "Error Downloading: %s", source.ascii());
71 }
72
73 if ( OK )
74 {
75 SensorParams *sp;
76 Meter *meter;
77
78 TQObjectListIt it( *objList );
79 while (it != 0)
80 {
81 sp = (SensorParams*)(*it);
82 meter = sp->getMeter();
83
84 // this is a hack to force the
85 // clickmap to reset its data lists
86 meter->setValue(0);
87
88 TQDomElement docElem = doc.documentElement();
89 TQDomNode n = docElem.firstChild();
90 if (!n.isNull())
91 {
92 TQDomNodeList links = docElem.elementsByTagName( "link" );
93 TQDomNodeList displays;
94 if ( format.contains( "%d", false ) > 0 )
95 {
96 displays = docElem.elementsByTagName( "description" );
97 }
98 else
99 {
100 displays = docElem.elementsByTagName( "title" );
101 }
102
103 TQRegExp rx("^http://", false );
104 for (uint i=1; i < displays.count(); ++i )
105 {
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) )
109 {
110 meter->setValue( dispTxt );
111 meter->setValue( linkTxt );
112 }
113 else
114 {
115 tqDebug("Skipping");
116 }
117 }
118 }
119 else
120 {
121 tqDebug ("Document Node was null!!");
122 }
123
124 ++it;
125 }
126 }
127 // Cleanup
128 file.close();
129 TDEIO::NetAccess::removeTempFile( tmpFile );
130}
131
132#include "rsssensor.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.8
This website is maintained by Timothy Pearson.