-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 @@ -26,5 +26,4 @@ */ -#include <stdio.h> #include <qfile.h> @@ -35,4 +34,6 @@ #include <qtextstream.h> +#include <opie/oprocess.h> + #include <qpe/config.h> #include <qpe/resource.h> @@ -43,19 +44,4 @@ 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 ); @@ -73,5 +59,4 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) startTimer(1000); - //retreiveData(); } @@ -97,4 +82,19 @@ 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() ) @@ -103,18 +103,9 @@ 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(); } @@ -320,2 +311,14 @@ 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 @@ -33,6 +33,5 @@ #include <qwidget.h> -#include <unistd.h> - +class OProcess; class QLabel; class QTimer; @@ -57,5 +56,5 @@ class WeatherPluginWidget : public QWidget { QLabel *weatherLabel; QLabel *weatherIcon; - + void timerEvent( QTimerEvent * ); void retreiveData(); @@ -65,4 +64,7 @@ class WeatherPluginWidget : public QWidget { void getPressure( const QString & ); void getIcon( const QString & ); + + private slots: + void dataRetrieved( OProcess * ); }; |