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
@@ -83,87 +83,88 @@ void WeatherPluginWidget::retreiveData()
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 )