author | drw <drw> | 2002-11-17 00:12:31 (UTC) |
---|---|---|
committer | drw <drw> | 2002-11-17 00:12:31 (UTC) |
commit | d28c78c564f3c6ecad91506c50e2c80e66c1a718 (patch) (side-by-side diff) | |
tree | 08d930e4872f78a4651dccd51d920dadfaaf7f39 /noncore/todayplugins | |
parent | ec642ffea22af16a924288dc64fe6a46413e49af (diff) | |
download | opie-d28c78c564f3c6ecad91506c50e2c80e66c1a718.zip opie-d28c78c564f3c6ecad91506c50e2c80e66c1a718.tar.gz opie-d28c78c564f3c6ecad91506c50e2c80e66c1a718.tar.bz2 |
Use OProcess instead of popen/pclose and re-read config upon data re-fresh
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.cpp | 65 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.h | 8 |
2 files changed, 39 insertions, 34 deletions
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp index 0fd8e57..6444ebf 100644 --- a/noncore/todayplugins/weather/weatherpluginwidget.cpp +++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp @@ -27,3 +27,2 @@ */ -#include <stdio.h> @@ -36,2 +35,4 @@ +#include <opie/oprocess.h> + #include <qpe/config.h> @@ -44,17 +45,2 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) { - Config config( "todayweatherplugin"); - config.setGroup( "Config" ); - - location = config.readEntry( "Location", "" ); - useMetric = config.readBoolEntry( "Metric", TRUE ); - frequency = config.readNumEntry( "Frequency", 5 ); - - localFile = "/tmp/"; - localFile.append( location ); - localFile.append( ".TXT" ); - - remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; - remoteFile.append( location ); - remoteFile.append( ".TXT" ); - QHBoxLayout *layout = new QHBoxLayout( this ); @@ -74,3 +60,2 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) startTimer(1000); - //retreiveData(); } @@ -98,2 +83,17 @@ void WeatherPluginWidget::retreiveData() + Config config( "todayweatherplugin"); + config.setGroup( "Config" ); + + location = config.readEntry( "Location", "" ); + useMetric = config.readBoolEntry( "Metric", TRUE ); + frequency = config.readNumEntry( "Frequency", 5 ); + + localFile = "/tmp/"; + localFile.append( location ); + localFile.append( ".TXT" ); + + remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; + remoteFile.append( location ); + remoteFile.append( ".TXT" ); + QFile file( localFile ); @@ -104,16 +104,7 @@ void WeatherPluginWidget::retreiveData() - QString command = "wget -q "; - command.append( remoteFile ); - command.append( " -O " ); - command.append( localFile ); - FILE *get = popen( command.latin1(), "r" ); - if ( get ) - { - pclose( get ); - displayWeather(); - } - else - { - weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); - } + OProcess *proc = new OProcess; + + *proc << "wget" << "-q" << remoteFile << "-O" << localFile; + connect( proc, SIGNAL( processExited( OProcess * ) ), this, SLOT( dataRetrieved( OProcess * ) ) ); + proc->start(); } @@ -321 +312,13 @@ void WeatherPluginWidget::getIcon(const QString &data ) } + +void WeatherPluginWidget::dataRetrieved( OProcess *process ) +{ + if ( process->normalExit() ) + { + displayWeather(); + } + else + { + weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); + } +} diff --git a/noncore/todayplugins/weather/weatherpluginwidget.h b/noncore/todayplugins/weather/weatherpluginwidget.h index 2c0238d..d2bbd8b 100644 --- a/noncore/todayplugins/weather/weatherpluginwidget.h +++ b/noncore/todayplugins/weather/weatherpluginwidget.h @@ -34,4 +34,3 @@ -#include <unistd.h> - +class OProcess; class QLabel; @@ -58,3 +57,3 @@ class WeatherPluginWidget : public QWidget { QLabel *weatherIcon; - + void timerEvent( QTimerEvent * ); @@ -66,2 +65,5 @@ class WeatherPluginWidget : public QWidget { void getIcon( const QString & ); + + private slots: + void dataRetrieved( OProcess * ); }; |