From d28c78c564f3c6ecad91506c50e2c80e66c1a718 Mon Sep 17 00:00:00 2001 From: drw Date: Sun, 17 Nov 2002 00:12:31 +0000 Subject: Use OProcess instead of popen/pclose and re-read config upon data re-fresh --- (limited to 'noncore/todayplugins') 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 @@ -25,7 +25,6 @@ Boston, MA 02111-1307, USA. */ -#include #include #include @@ -34,6 +33,8 @@ #include #include +#include + #include #include @@ -42,21 +43,6 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) : QWidget( parent, 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 ); layout->setAutoAdd( TRUE ); layout->setSpacing( 2 ); @@ -72,7 +58,6 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); startTimer(1000); - //retreiveData(); } WeatherPluginWidget::~WeatherPluginWidget() @@ -96,26 +81,32 @@ void WeatherPluginWidget::retreiveData() { startTimer( frequency * 60000 ); + 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 ); if ( file.exists() ) { file.remove(); } - 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(); } void WeatherPluginWidget::displayWeather() @@ -319,3 +310,15 @@ void WeatherPluginWidget::getIcon(const QString &data ) dataStr = "sleet"; } } + +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 @@ -32,8 +32,7 @@ #include #include -#include - +class OProcess; class QLabel; class QTimer; @@ -56,7 +55,7 @@ class WeatherPluginWidget : public QWidget { QLabel *weatherLabel; QLabel *weatherIcon; - + void timerEvent( QTimerEvent * ); void retreiveData(); void displayWeather(); @@ -64,6 +63,9 @@ class WeatherPluginWidget : public QWidget { void getWind( const QString & ); void getPressure( const QString & ); void getIcon( const QString & ); + + private slots: + void dataRetrieved( OProcess * ); }; #endif -- cgit v0.9.0.2