• 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 
18 RssSensor::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 
39 RssSensor::~RssSensor()
40 {
41 }
42 
43 void RssSensor::update()
44 {
45  TQDomDocument doc;
46  TQFile file;
47  TQString tmpFile;
48  bool OK = false;
49 
50 #if defined(KDE_3_3)
51  if(TDEIO::NetAccess::download(KURL(source), tmpFile, karambaApp->parentWindow()))
52 #else
53  if(TDEIO::NetAccess::download(KURL(source), tmpFile))
54 #endif
55  {
56  file.setName(tmpFile);
57  if ( file.open(IO_ReadOnly | IO_Translate) )
58  {
59  if ( doc.setContent( &file ) )
60  {
61  OK = true;
62  }
63  else
64  {
65  tqDebug("Error on building DOM");
66  }
67  }
68  else
69  {
70  tqDebug("Error opening file");
71  }
72  }
73  else {
74  tqDebug( "Error Downloading: %s", source.ascii());
75  }
76 
77  if ( OK )
78  {
79  SensorParams *sp;
80  Meter *meter;
81 
82  TQObjectListIt it( *objList );
83  while (it != 0)
84  {
85  sp = (SensorParams*)(*it);
86  meter = sp->getMeter();
87 
88  // this is a hack to force the
89  // clickmap to reset its data lists
90  meter->setValue(0);
91 
92  TQDomElement docElem = doc.documentElement();
93  TQDomNode n = docElem.firstChild();
94  if (!n.isNull())
95  {
96  TQDomNodeList links = docElem.elementsByTagName( "link" );
97  TQDomNodeList displays;
98  if ( format.contains( "%d", false ) > 0 )
99  {
100  displays = docElem.elementsByTagName( "description" );
101  }
102  else
103  {
104  displays = docElem.elementsByTagName( "title" );
105  }
106 
107  TQRegExp rx("^http://", false );
108  for (uint i=1; i < displays.count(); ++i )
109  {
110  TQString dispTxt = displays.item( i ).toElement().text();
111  TQString linkTxt = links.item( i ).toElement().text();
112  if( (rx.search(dispTxt) == -1) && (rx.search(linkTxt) != -1) )
113  {
114  meter->setValue( dispTxt );
115  meter->setValue( linkTxt );
116  }
117  else
118  {
119  tqDebug("Skipping");
120  }
121  }
122  }
123  else
124  {
125  tqDebug ("Document Node was null!!");
126  }
127 
128  ++it;
129  }
130  }
131  // Cleanup
132  file.close();
133  TDEIO::NetAccess::removeTempFile( tmpFile );
134 }
135 
136 #include "rsssensor.moc"
SensorParams
Hans Karlsson.
Definition: sensorparams.h:31

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.8.13
This website is maintained by Timothy Pearson.