summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/weather/weatherpluginwidget.cpp
Unidiff
Diffstat (limited to 'noncore/todayplugins/weather/weatherpluginwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp
index fe54051..27624c5 100644
--- a/noncore/todayplugins/weather/weatherpluginwidget.cpp
+++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp
@@ -59,135 +59,136 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name )
59} 59}
60 60
61WeatherPluginWidget::~WeatherPluginWidget() 61WeatherPluginWidget::~WeatherPluginWidget()
62{ 62{
63 QFile file( localFile ); 63 QFile file( localFile );
64 if ( file.exists() ) 64 if ( file.exists() )
65 { 65 {
66 file.remove(); 66 file.remove();
67 } 67 }
68} 68}
69 69
70void WeatherPluginWidget::timerEvent( QTimerEvent *e ) 70void WeatherPluginWidget::timerEvent( QTimerEvent *e )
71{ 71{
72 killTimer( e->timerId() ); 72 killTimer( e->timerId() );
73 retreiveData(); 73 retreiveData();
74} 74}
75 75
76 76
77 77
78void WeatherPluginWidget::retreiveData() 78void WeatherPluginWidget::retreiveData()
79{ 79{
80 Config config( "todayweatherplugin"); 80 Config config( "todayweatherplugin");
81 config.setGroup( "Config" ); 81 config.setGroup( "Config" );
82 82
83 location = config.readEntry( "Location", "" ); 83 location = config.readEntry( "Location", "" );
84 useMetric = config.readBoolEntry( "Metric", true ); 84 useMetric = config.readBoolEntry( "Metric", true );
85 frequency = config.readNumEntry( "Frequency", 5 ); 85 frequency = config.readNumEntry( "Frequency", 5 );
86 86
87 startTimer( frequency * 60000 ); 87 startTimer( frequency * 60000 );
88 88
89 localFile = "/tmp/"; 89 localFile = "/tmp/";
90 localFile.append( location ); 90 localFile.append( location );
91 localFile.append( ".TXT" ); 91 localFile.append( ".TXT" );
92 92
93 remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; 93 remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/";
94 remoteFile.append( location ); 94 remoteFile.append( location );
95 remoteFile.append( ".TXT" ); 95 remoteFile.append( ".TXT" );
96 96
97 QFile file( localFile ); 97 QFile file( localFile );
98 if ( file.exists() ) 98 if ( file.exists() )
99 { 99 {
100 file.remove(); 100 file.remove();
101 } 101 }
102 102
103 OProcess *proc = new OProcess; 103 OProcess *proc = new OProcess;
104 104
105 *proc << "wget" << "-q" << remoteFile << "-O" << localFile; 105 *proc << "wget" << "-q" << remoteFile << "-O" << localFile;
106 connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) ); 106 connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) );
107 proc->start(); 107 if ( !proc->start() )
108 weatherLabel->setText( tr( "Could not start wget process." ) );
108} 109}
109 110
110void WeatherPluginWidget::displayWeather() 111void WeatherPluginWidget::displayWeather()
111{ 112{
112 weatherData = QString::null; 113 weatherData = QString::null;
113 114
114 QFile file( localFile ); 115 QFile file( localFile );
115 116
116 if ( file.size() > 0 && file.open( IO_ReadOnly ) ) 117 if ( file.size() > 0 && file.open( IO_ReadOnly ) )
117 { 118 {
118 QTextStream data( &file ); 119 QTextStream data( &file );
119 while ( !data.eof() ) 120 while ( !data.eof() )
120 { 121 {
121 weatherData.append( data.readLine() ); 122 weatherData.append( data.readLine() );
122 } 123 }
123 file.close(); 124 file.close();
124 weatherData = weatherData.simplifyWhiteSpace(); 125 weatherData = weatherData.simplifyWhiteSpace();
125 126
126 QString tmpstr; 127 QString tmpstr;
127 128
128 tmpstr.append( tr( "Temp: " ) ); 129 tmpstr.append( tr( "Temp: " ) );
129 getTemp( weatherData ); 130 getTemp( weatherData );
130 tmpstr.append( dataStr ); 131 tmpstr.append( dataStr );
131 132
132 tmpstr.append( tr( " Wind: " ) ); 133 tmpstr.append( tr( " Wind: " ) );
133 getWind( weatherData ); 134 getWind( weatherData );
134 tmpstr.append( dataStr ); 135 tmpstr.append( dataStr );
135 136
136 tmpstr.append( tr( "\nPres: " ) ); 137 tmpstr.append( tr( "\nPres: " ) );
137 getPressure( weatherData ); 138 getPressure( weatherData );
138 tmpstr.append( dataStr ); 139 tmpstr.append( dataStr );
139 140
140 weatherLabel->setText( tmpstr ); 141 weatherLabel->setText( tmpstr );
141 142
142 tmpstr = "todayweatherplugin/"; 143 tmpstr = "todayweatherplugin/";
143 getIcon( weatherData ); 144 getIcon( weatherData );
144 tmpstr.append( dataStr ); 145 tmpstr.append( dataStr );
145 weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) ); 146 weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) );
146 } 147 }
147 else 148 else
148 { 149 {
149 weatherLabel->setText( tr( "Current weather data not available." ) ); 150 weatherLabel->setText( tr( "Current weather data not available." ) );
150 } 151 }
151} 152}
152 153
153void WeatherPluginWidget::getTemp( const QString &data ) 154void WeatherPluginWidget::getTemp( const QString &data )
154{ 155{
155 int value; 156 int value;
156 bool ok; 157 bool ok;
157 158
158 int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); 159 int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 );
159 if ( pos > -1 ) 160 if ( pos > -1 )
160 { 161 {
161 if ( data.at( pos ) == 'M' ) 162 if ( data.at( pos ) == 'M' )
162 { 163 {
163 value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); 164 value = -1 * data.mid( pos + 1, 2 ).toInt( &ok );
164 } 165 }
165 else 166 else
166 { 167 {
167 value = data.mid( pos, 2 ).toInt( &ok ); 168 value = data.mid( pos, 2 ).toInt( &ok );
168 } 169 }
169 if ( useMetric ) 170 if ( useMetric )
170 { 171 {
171 dataStr = QString::number( value ); 172 dataStr = QString::number( value );
172 dataStr.append( 'C' ); 173 dataStr.append( 'C' );
173 } 174 }
174 else 175 else
175 { 176 {
176 dataStr = QString::number( ( value * 9 / 5 ) + 32 ); 177 dataStr = QString::number( ( value * 9 / 5 ) + 32 );
177 dataStr.append( 'F' ); 178 dataStr.append( 'F' );
178 } 179 }
179 } 180 }
180 else 181 else
181 { 182 {
182 dataStr = tr( "n/a" ); 183 dataStr = tr( "n/a" );
183 } 184 }
184} 185}
185 186
186void WeatherPluginWidget::getWind( const QString &data ) 187void WeatherPluginWidget::getWind( const QString &data )
187{ 188{
188 int value; 189 int value;
189 bool ok; 190 bool ok;
190 191
191 int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); 192 int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 );
192 if ( pos > -1 ) 193 if ( pos > -1 )
193 { 194 {