author | drw <drw> | 2002-11-22 01:48:26 (UTC) |
---|---|---|
committer | drw <drw> | 2002-11-22 01:48:26 (UTC) |
commit | 772c1321e4e95a415b9de700c3474f81f98b5482 (patch) (unidiff) | |
tree | e220beb65ea90ae7aee52c0ac83ecbc69bd8191a | |
parent | 87240f18c4e7b12c56d7f61a3431221d94f59f4c (diff) | |
download | opie-772c1321e4e95a415b9de700c3474f81f98b5482.zip opie-772c1321e4e95a415b9de700c3474f81f98b5482.tar.gz opie-772c1321e4e95a415b9de700c3474f81f98b5482.tar.bz2 |
Make sure update frequency is initialized 1st time in (thanks to Simon)
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp index 6444ebf..f4ea0f2 100644 --- a/noncore/todayplugins/weather/weatherpluginwidget.cpp +++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp | |||
@@ -1,217 +1,217 @@ | |||
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 | ||
43 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) | 43 | WeatherPluginWidget::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( "todayweatherplugin/wait" ); | 52 | QImage logo1 = Resource::loadImage( "todayweatherplugin/wait" ); |
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 | ||
63 | WeatherPluginWidget::~WeatherPluginWidget() | 63 | WeatherPluginWidget::~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 | ||
72 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) | 72 | void 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 | ||
80 | void WeatherPluginWidget::retreiveData() | 80 | void WeatherPluginWidget::retreiveData() |
81 | { | 81 | { |
82 | startTimer( frequency * 60000 ); | ||
83 | |||
84 | Config config( "todayweatherplugin"); | 82 | Config config( "todayweatherplugin"); |
85 | config.setGroup( "Config" ); | 83 | config.setGroup( "Config" ); |
86 | 84 | ||
87 | location = config.readEntry( "Location", "" ); | 85 | location = config.readEntry( "Location", "" ); |
88 | useMetric = config.readBoolEntry( "Metric", TRUE ); | 86 | useMetric = config.readBoolEntry( "Metric", TRUE ); |
89 | frequency = config.readNumEntry( "Frequency", 5 ); | 87 | frequency = config.readNumEntry( "Frequency", 5 ); |
88 | |||
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 | ||
112 | void WeatherPluginWidget::displayWeather() | 112 | void WeatherPluginWidget::displayWeather() |
113 | { | 113 | { |
114 | weatherData = QString::null; | 114 | weatherData = QString::null; |
115 | 115 | ||
116 | QFile file( localFile ); | 116 | QFile file( localFile ); |
117 | if ( file.open( IO_ReadOnly ) ) | 117 | if ( file.open( IO_ReadOnly ) ) |
118 | { | 118 | { |
119 | QTextStream data( &file ); | 119 | QTextStream data( &file ); |
120 | while ( !data.eof() ) | 120 | while ( !data.eof() ) |
121 | { | 121 | { |
122 | weatherData.append( data.readLine() ); | 122 | weatherData.append( data.readLine() ); |
123 | } | 123 | } |
124 | file.close(); | 124 | file.close(); |
125 | weatherData = weatherData.simplifyWhiteSpace(); | 125 | weatherData = weatherData.simplifyWhiteSpace(); |
126 | 126 | ||
127 | QString tmpstr; | 127 | QString tmpstr; |
128 | 128 | ||
129 | tmpstr.append( tr( "Temp: " ) ); | 129 | tmpstr.append( tr( "Temp: " ) ); |
130 | getTemp( weatherData ); | 130 | getTemp( weatherData ); |
131 | tmpstr.append( dataStr ); | 131 | tmpstr.append( dataStr ); |
132 | 132 | ||
133 | tmpstr.append( tr( " Wind: " ) ); | 133 | tmpstr.append( tr( " Wind: " ) ); |
134 | getWind( weatherData ); | 134 | getWind( weatherData ); |
135 | tmpstr.append( dataStr ); | 135 | tmpstr.append( dataStr ); |
136 | 136 | ||
137 | tmpstr.append( tr( "\nPres: " ) ); | 137 | tmpstr.append( tr( "\nPres: " ) ); |
138 | getPressure( weatherData ); | 138 | getPressure( weatherData ); |
139 | tmpstr.append( dataStr ); | 139 | tmpstr.append( dataStr ); |
140 | 140 | ||
141 | weatherLabel->setText( tmpstr ); | 141 | weatherLabel->setText( tmpstr ); |
142 | 142 | ||
143 | tmpstr = "todayweatherplugin/"; | 143 | tmpstr = "todayweatherplugin/"; |
144 | getIcon( weatherData ); | 144 | getIcon( weatherData ); |
145 | tmpstr.append( dataStr ); | 145 | tmpstr.append( dataStr ); |
146 | QImage logo1 = Resource::loadImage( tmpstr ); | 146 | QImage logo1 = Resource::loadImage( tmpstr ); |
147 | QPixmap pic; | 147 | QPixmap pic; |
148 | pic.convertFromImage( logo1 ); | 148 | pic.convertFromImage( logo1 ); |
149 | weatherIcon->setPixmap( pic ); | 149 | weatherIcon->setPixmap( pic ); |
150 | } | 150 | } |
151 | else | 151 | else |
152 | { | 152 | { |
153 | weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); | 153 | weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | void WeatherPluginWidget::getTemp( const QString &data ) | 157 | void WeatherPluginWidget::getTemp( const QString &data ) |
158 | { | 158 | { |
159 | int value; | 159 | int value; |
160 | bool ok; | 160 | bool ok; |
161 | 161 | ||
162 | int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); | 162 | int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); |
163 | if ( pos > -1 ) | 163 | if ( pos > -1 ) |
164 | { | 164 | { |
165 | if ( data.at( pos ) == 'M' ) | 165 | if ( data.at( pos ) == 'M' ) |
166 | { | 166 | { |
167 | value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); | 167 | value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); |
168 | } | 168 | } |
169 | else | 169 | else |
170 | { | 170 | { |
171 | value = data.mid( pos, 2 ).toInt( &ok ); | 171 | value = data.mid( pos, 2 ).toInt( &ok ); |
172 | } | 172 | } |
173 | if ( useMetric ) | 173 | if ( useMetric ) |
174 | { | 174 | { |
175 | dataStr = QString::number( value ); | 175 | dataStr = QString::number( value ); |
176 | dataStr.append( 'C' ); | 176 | dataStr.append( 'C' ); |
177 | } | 177 | } |
178 | else | 178 | else |
179 | { | 179 | { |
180 | dataStr = QString::number( ( value * 9 / 5 ) + 32 ); | 180 | dataStr = QString::number( ( value * 9 / 5 ) + 32 ); |
181 | dataStr.append( 'F' ); | 181 | dataStr.append( 'F' ); |
182 | } | 182 | } |
183 | } | 183 | } |
184 | else | 184 | else |
185 | { | 185 | { |
186 | dataStr = tr( "n/a" ); | 186 | dataStr = tr( "n/a" ); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | void WeatherPluginWidget::getWind( const QString &data ) | 190 | void WeatherPluginWidget::getWind( const QString &data ) |
191 | { | 191 | { |
192 | int value; | 192 | int value; |
193 | bool ok; | 193 | bool ok; |
194 | 194 | ||
195 | int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); | 195 | int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); |
196 | if ( pos > -1 ) | 196 | if ( pos > -1 ) |
197 | { | 197 | { |
198 | if ( data.mid( pos, 3 ) != "VRB" ) | 198 | if ( data.mid( pos, 3 ) != "VRB" ) |
199 | { | 199 | { |
200 | value = data.mid( pos, 3 ).toInt( &ok ); | 200 | value = data.mid( pos, 3 ).toInt( &ok ); |
201 | if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) ) | 201 | if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) ) |
202 | dataStr = tr("E " ); | 202 | dataStr = tr("E " ); |
203 | else if ( value >= 23 && value < 69 ) | 203 | else if ( value >= 23 && value < 69 ) |
204 | dataStr = tr( "NE " ); | 204 | dataStr = tr( "NE " ); |
205 | else if ( value >= 69 && value < 113 ) | 205 | else if ( value >= 69 && value < 113 ) |
206 | dataStr = tr( "N " ); | 206 | dataStr = tr( "N " ); |
207 | else if ( value >= 113 && value < 157 ) | 207 | else if ( value >= 113 && value < 157 ) |
208 | dataStr = tr( "NW " ); | 208 | dataStr = tr( "NW " ); |
209 | else if ( value >= 157 && value < 203 ) | 209 | else if ( value >= 157 && value < 203 ) |
210 | dataStr = tr( "W " ); | 210 | dataStr = tr( "W " ); |
211 | else if ( value >= 203 && value < 248 ) | 211 | else if ( value >= 203 && value < 248 ) |
212 | dataStr = tr( "SW " ); | 212 | dataStr = tr( "SW " ); |
213 | else if ( value >= 248 && value < 294 ) | 213 | else if ( value >= 248 && value < 294 ) |
214 | dataStr = tr( "S " ); | 214 | dataStr = tr( "S " ); |
215 | else if ( value >= 294 && value < 238 ) | 215 | else if ( value >= 294 && value < 238 ) |
216 | dataStr = tr( "SE " ); | 216 | dataStr = tr( "SE " ); |
217 | } | 217 | } |