summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp
index 8440f20..4491b91 100644
--- a/noncore/todayplugins/weather/weatherpluginwidget.cpp
+++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp
@@ -1,325 +1,325 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 =. 3 =.
4             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qfile.h> 29#include <qfile.h>
30#include <qimage.h> 30#include <qimage.h>
31#include <qlabel.h> 31#include <qlabel.h>
32#include <qlayout.h> 32#include <qlayout.h>
33#include <qpixmap.h> 33#include <qpixmap.h>
34#include <qtextstream.h> 34#include <qtextstream.h>
35 35
36#include <opie/oprocess.h> 36#include <opie/oprocess.h>
37 37
38#include <qpe/config.h> 38#include <qpe/config.h>
39#include <qpe/resource.h> 39#include <qpe/resource.h>
40 40
41#include "weatherpluginwidget.h" 41#include "weatherpluginwidget.h"
42 42
43WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) 43WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name )
44 : QWidget( parent, name ) 44 : QWidget( parent, name )
45{ 45{
46 QHBoxLayout *layout = new QHBoxLayout( this ); 46 QHBoxLayout *layout = new QHBoxLayout( this );
47 layout->setAutoAdd( TRUE ); 47 layout->setAutoAdd( TRUE );
48 layout->setSpacing( 2 ); 48 layout->setSpacing( 2 );
49 49
50 weatherIcon = new QLabel( this ); 50 weatherIcon = new QLabel( this );
51 weatherIcon->setMaximumWidth( 32 ); 51 weatherIcon->setMaximumWidth( 32 );
52 QImage logo1 = Resource::loadImage( "Clock" ); 52 QImage logo1 = Resource::loadImage( "Clock" );
53 QPixmap pic; 53 QPixmap pic;
54 pic.convertFromImage( logo1 ); 54 pic.convertFromImage( logo1 );
55 weatherIcon->setPixmap( pic ); 55 weatherIcon->setPixmap( pic );
56 56
57 weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this ); 57 weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this );
58 weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); 58 weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
59 59
60 startTimer(1000); 60 startTimer(1000);
61} 61}
62 62
63WeatherPluginWidget::~WeatherPluginWidget() 63WeatherPluginWidget::~WeatherPluginWidget()
64{ 64{
65 QFile file( localFile ); 65 QFile file( localFile );
66 if ( file.exists() ) 66 if ( file.exists() )
67 { 67 {
68 file.remove(); 68 file.remove();
69 } 69 }
70} 70}
71 71
72void WeatherPluginWidget::timerEvent( QTimerEvent *e ) 72void WeatherPluginWidget::timerEvent( QTimerEvent *e )
73{ 73{
74 killTimer( e->timerId() ); 74 killTimer( e->timerId() );
75 retreiveData(); 75 retreiveData();
76} 76}
77 77
78 78
79 79
80void WeatherPluginWidget::retreiveData() 80void WeatherPluginWidget::retreiveData()
81{ 81{
82 Config config( "todayweatherplugin"); 82 Config config( "todayweatherplugin");
83 config.setGroup( "Config" ); 83 config.setGroup( "Config" );
84 84
85 location = config.readEntry( "Location", "" ); 85 location = config.readEntry( "Location", "" );
86 useMetric = config.readBoolEntry( "Metric", TRUE ); 86 useMetric = config.readBoolEntry( "Metric", TRUE );
87 frequency = config.readNumEntry( "Frequency", 5 ); 87 frequency = config.readNumEntry( "Frequency", 5 );
88 88
89 startTimer( frequency * 60000 ); 89 startTimer( frequency * 60000 );
90 90
91 localFile = "/tmp/"; 91 localFile = "/tmp/";
92 localFile.append( location ); 92 localFile.append( location );
93 localFile.append( ".TXT" ); 93 localFile.append( ".TXT" );
94 94
95 remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; 95 remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/";
96 remoteFile.append( location ); 96 remoteFile.append( location );
97 remoteFile.append( ".TXT" ); 97 remoteFile.append( ".TXT" );
98 98
99 QFile file( localFile ); 99 QFile file( localFile );
100 if ( file.exists() ) 100 if ( file.exists() )
101 { 101 {
102 file.remove(); 102 file.remove();
103 } 103 }
104 104
105 OProcess *proc = new OProcess; 105 OProcess *proc = new OProcess;
106 106
107 *proc << "wget" << "-q" << remoteFile << "-O" << localFile; 107 *proc << "wget" << "-q" << remoteFile << "-O" << localFile;
108 connect( proc, SIGNAL( processExited( OProcess * ) ), this, SLOT( dataRetrieved( OProcess * ) ) ); 108 connect( proc, SIGNAL( processExited( OProcess * ) ), this, SLOT( dataRetrieved( OProcess * ) ) );
109 proc->start(); 109 proc->start();
110} 110}
111 111
112void WeatherPluginWidget::displayWeather() 112void WeatherPluginWidget::displayWeather()
113{ 113{
114 weatherData = QString::null; 114 weatherData = QString::null;
115 115
116 QFile file( localFile ); 116 QFile file( localFile );
117 117
118 if ( file.size() > 0 && file.open( IO_ReadOnly ) ) 118 if ( file.size() > 0 && file.open( IO_ReadOnly ) )
119 { 119 {
120 QTextStream data( &file ); 120 QTextStream data( &file );
121 while ( !data.eof() ) 121 while ( !data.eof() )
122 { 122 {
123 weatherData.append( data.readLine() ); 123 weatherData.append( data.readLine() );
124 } 124 }
125 file.close(); 125 file.close();
126 weatherData = weatherData.simplifyWhiteSpace(); 126 weatherData = weatherData.simplifyWhiteSpace();
127 127
128 QString tmpstr; 128 QString tmpstr;
129 129
130 tmpstr.append( tr( "Temp: " ) ); 130 tmpstr.append( tr( "Temp: " ) );
131 getTemp( weatherData ); 131 getTemp( weatherData );
132 tmpstr.append( dataStr ); 132 tmpstr.append( dataStr );
133 133
134 tmpstr.append( tr( " Wind: " ) ); 134 tmpstr.append( tr( " Wind: " ) );
135 getWind( weatherData ); 135 getWind( weatherData );
136 tmpstr.append( dataStr ); 136 tmpstr.append( dataStr );
137 137
138 tmpstr.append( tr( "\nPres: " ) ); 138 tmpstr.append( tr( "\nPres: " ) );
139 getPressure( weatherData ); 139 getPressure( weatherData );
140 tmpstr.append( dataStr ); 140 tmpstr.append( dataStr );
141 141
142 weatherLabel->setText( tmpstr ); 142 weatherLabel->setText( tmpstr );
143 143
144 tmpstr = "todayweatherplugin/"; 144 tmpstr = "todayweatherplugin/";
145 getIcon( weatherData ); 145 getIcon( weatherData );
146 tmpstr.append( dataStr ); 146 tmpstr.append( dataStr );
147 QImage logo1 = Resource::loadImage( tmpstr ); 147 QImage logo1 = Resource::loadImage( tmpstr );
148 QPixmap pic; 148 QPixmap pic;
149 pic.convertFromImage( logo1 ); 149 pic.convertFromImage( logo1 );
150 weatherIcon->setPixmap( pic ); 150 weatherIcon->setPixmap( pic );
151 } 151 }
152 else 152 else
153 { 153 {
154 weatherLabel->setText( tr( "Current weather data not available." ) ); 154 weatherLabel->setText( tr( "Current weather data not available." ) );
155 } 155 }
156} 156}
157 157
158void WeatherPluginWidget::getTemp( const QString &data ) 158void WeatherPluginWidget::getTemp( const QString &data )
159{ 159{
160 int value; 160 int value;
161 bool ok; 161 bool ok;
162 162
163 int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); 163 int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 );
164 if ( pos > -1 ) 164 if ( pos > -1 )
165 { 165 {
166 if ( data.at( pos ) == 'M' ) 166 if ( data.at( pos ) == 'M' )
167 { 167 {
168 value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); 168 value = -1 * data.mid( pos + 1, 2 ).toInt( &ok );
169 } 169 }
170 else 170 else
171 { 171 {
172 value = data.mid( pos, 2 ).toInt( &ok ); 172 value = data.mid( pos, 2 ).toInt( &ok );
173 } 173 }
174 if ( useMetric ) 174 if ( useMetric )
175 { 175 {
176 dataStr = QString::number( value ); 176 dataStr = QString::number( value );
177 dataStr.append( 'C' ); 177 dataStr.append( 'C' );
178 } 178 }
179 else 179 else
180 { 180 {
181 dataStr = QString::number( ( value * 9 / 5 ) + 32 ); 181 dataStr = QString::number( ( value * 9 / 5 ) + 32 );
182 dataStr.append( 'F' ); 182 dataStr.append( 'F' );
183 } 183 }
184 } 184 }
185 else 185 else
186 { 186 {
187 dataStr = tr( "n/a" ); 187 dataStr = tr( "n/a" );
188 } 188 }
189} 189}
190 190
191void WeatherPluginWidget::getWind( const QString &data ) 191void WeatherPluginWidget::getWind( const QString &data )
192{ 192{
193 int value; 193 int value;
194 bool ok; 194 bool ok;
195 195
196 int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); 196 int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 );
197 if ( pos > -1 ) 197 if ( pos > -1 )
198 { 198 {
199 if ( data.mid( pos, 3 ) != "VRB" ) 199 if ( data.mid( pos, 3 ) != "VRB" )
200 { 200 {
201 value = data.mid( pos, 3 ).toInt( &ok ); 201 value = data.mid( pos, 3 ).toInt( &ok );
202 if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) ) 202 if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) )
203 dataStr = tr("E " ); 203 dataStr = tr("E " );
204 else if ( value >= 23 && value < 69 ) 204 else if ( value >= 23 && value < 69 )
205 dataStr = tr( "NE " ); 205 dataStr = tr( "NE " );
206 else if ( value >= 69 && value < 113 ) 206 else if ( value >= 69 && value < 113 )
207 dataStr = tr( "N " ); 207 dataStr = tr( "N " );
208 else if ( value >= 113 && value < 157 ) 208 else if ( value >= 113 && value < 157 )
209 dataStr = tr( "NW " ); 209 dataStr = tr( "NW " );
210 else if ( value >= 157 && value < 203 ) 210 else if ( value >= 157 && value < 203 )
211 dataStr = tr( "W " ); 211 dataStr = tr( "W " );
212 else if ( value >= 203 && value < 248 ) 212 else if ( value >= 203 && value < 248 )
213 dataStr = tr( "SW " ); 213 dataStr = tr( "SW " );
214 else if ( value >= 248 && value < 294 ) 214 else if ( value >= 248 && value < 294 )
215 dataStr = tr( "S " ); 215 dataStr = tr( "S " );
216 else if ( value >= 294 && value < 238 ) 216 else if ( value >= 294 && value < 238 )
217 dataStr = tr( "SE " ); 217 dataStr = tr( "SE " );
218 } 218 }
219 if ( data.mid( pos + 5, 1) == "G" || 219 if ( data.mid( pos + 5, 1) == "G" ||
220 data.mid( pos + 5, 1) == "K" ) 220 data.mid( pos + 5, 1) == "K" )
221 { 221 {
222 value = data.mid( pos + 3, 2 ).toInt( &ok ); 222 value = data.mid( pos + 3, 2 ).toInt( &ok );
223 } 223 }
224 else 224 else
225 { 225 {
226 value = data.mid( pos + 3, 3 ).toInt( &ok ); 226 value = data.mid( pos + 3, 3 ).toInt( &ok );
227 } 227 }
228 if ( useMetric ) 228 if ( useMetric )
229 { 229 {
230 value = value * 3.6 / 1.94; 230 value = value * 3.6 / 1.94;
231 dataStr.append( QString::number( value ) ); 231 dataStr.append( QString::number( value ) );
232 dataStr.append( tr( " KPH" ) ); 232 dataStr.append( tr( " KPH" ) );
233 } 233 }
234 else 234 else
235 { 235 {
236 value = value * 2.24 / 1.94; 236 value = value * 2.24 / 1.94;
237 dataStr.append( QString::number( value ) ); 237 dataStr.append( QString::number( value ) );
238 dataStr.append( tr( " MPH" ) ); 238 dataStr.append( tr( " MPH" ) );
239 } 239 }
240 } 240 }
241 else 241 else
242 { 242 {
243 dataStr = tr( "n/a" ); 243 dataStr = tr( "n/a" );
244 } 244 }
245} 245}
246 246
247void WeatherPluginWidget::getPressure( const QString &data ) 247void WeatherPluginWidget::getPressure( const QString &data )
248{ 248{
249 float value; 249 float value;
250 bool ok; 250 bool ok;
251 251
252 int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 ); 252 int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 );
253 if ( pos > -1 ) 253 if ( pos > -1 )
254 { 254 {
255 value = data.mid( pos + 1, 4 ).toFloat( &ok ); 255 value = data.mid( pos + 1, 4 ).toFloat( &ok );
256 if ( useMetric ) 256 if ( useMetric )
257 { 257 {
258 if ( data.mid( pos, 1 ) == "A" ) 258 if ( data.mid( pos, 1 ) == "A" )
259 value *= 33.8639 / 100; 259 value *= 33.8639 / 100;
260 dataStr = QString::number( value, 'f', 2 ); 260 dataStr = QString::number( value, 'f', 2 );
261 dataStr.append( tr( " hPa" ) ); 261 dataStr.append( tr( " kPa" ) );
262 } 262 }
263 else 263 else
264 { 264 {
265 if ( data.mid( pos, 1 ) == "Q" ) 265 if ( data.mid( pos, 1 ) == "Q" )
266 value /= 33.8639; 266 value /= 33.8639;
267 else 267 else
268 value /= 100; 268 value /= 100;
269 dataStr = QString::number( value, 'f', 2 ); 269 dataStr = QString::number( value, 'f', 2 );
270 dataStr.append( tr( " Hg" ) ); 270 dataStr.append( tr( " Hg" ) );
271 } 271 }
272 } 272 }
273 else 273 else
274 { 274 {
275 dataStr = tr( "n/a" ); 275 dataStr = tr( "n/a" );
276 } 276 }
277} 277}
278 278
279void WeatherPluginWidget::getIcon(const QString &data ) 279void WeatherPluginWidget::getIcon(const QString &data )
280{ 280{
281 dataStr = "psunny"; 281 dataStr = "psunny";
282 if ( data.find( "CLR ", 20 ) > -1 || 282 if ( data.find( "CLR ", 20 ) > -1 ||
283 data.find( "SKC ", 20 ) > -1 || 283 data.find( "SKC ", 20 ) > -1 ||
284 data.find( "CAVOK ", 20 ) > -1 ) 284 data.find( "CAVOK ", 20 ) > -1 )
285 { 285 {
286 dataStr = "sunny"; 286 dataStr = "sunny";
287 } 287 }
288 else if ( data.find( "SH ", 20 ) > -1 || 288 else if ( data.find( "SH ", 20 ) > -1 ||
289 data.find( "DZ ", 20 ) > -1 || 289 data.find( "DZ ", 20 ) > -1 ||
290 data.find( "RA ", 20 ) > -1 || 290 data.find( "RA ", 20 ) > -1 ||
291 data.find( "UP ", 20 ) > -1 || 291 data.find( "UP ", 20 ) > -1 ||
292 data.find( "BR ", 20 ) > -1 ) 292 data.find( "BR ", 20 ) > -1 )
293 { 293 {
294 dataStr = "shower"; 294 dataStr = "shower";
295 } 295 }
296 else if ( data.find( "TS ", 20 ) > -1 ) 296 else if ( data.find( "TS ", 20 ) > -1 )
297 { 297 {
298 dataStr = "tstorm"; 298 dataStr = "tstorm";
299 } 299 }
300 else if ( data.find( "SN ", 20 ) > -1 || 300 else if ( data.find( "SN ", 20 ) > -1 ||
301 data.find( "SG ", 20 ) > -1 ) 301 data.find( "SG ", 20 ) > -1 )
302 { 302 {
303 dataStr = "snow"; 303 dataStr = "snow";
304 } 304 }
305 else if ( data.find( "FZ ", 20 ) > -1 || 305 else if ( data.find( "FZ ", 20 ) > -1 ||
306 data.find( "GR ", 20 ) > -1 || 306 data.find( "GR ", 20 ) > -1 ||
307 data.find( "GS ", 20 ) > -1 || 307 data.find( "GS ", 20 ) > -1 ||
308 data.find( "PE ", 20 ) > -1 || 308 data.find( "PE ", 20 ) > -1 ||
309 data.find( "IC ", 20 ) > -1 ) 309 data.find( "IC ", 20 ) > -1 )
310 { 310 {
311 dataStr = "sleet"; 311 dataStr = "sleet";
312 } 312 }
313} 313}
314 314
315void WeatherPluginWidget::dataRetrieved( OProcess *process ) 315void WeatherPluginWidget::dataRetrieved( OProcess *process )
316{ 316{
317 if ( process->normalExit() ) 317 if ( process->normalExit() )
318 { 318 {
319 displayWeather(); 319 displayWeather();
320 } 320 }
321 else 321 else
322 { 322 {
323 weatherLabel->setText( tr( "Current weather data not available." ) ); 323 weatherLabel->setText( tr( "Current weather data not available." ) );
324 } 324 }
325} 325}