summaryrefslogtreecommitdiff
path: root/noncore/todayplugins
authordrw <drw>2002-11-17 00:12:31 (UTC)
committer drw <drw>2002-11-17 00:12:31 (UTC)
commitd28c78c564f3c6ecad91506c50e2c80e66c1a718 (patch) (side-by-side diff)
tree08d930e4872f78a4651dccd51d920dadfaaf7f39 /noncore/todayplugins
parentec642ffea22af16a924288dc64fe6a46413e49af (diff)
downloadopie-d28c78c564f3c6ecad91506c50e2c80e66c1a718.zip
opie-d28c78c564f3c6ecad91506c50e2c80e66c1a718.tar.gz
opie-d28c78c564f3c6ecad91506c50e2c80e66c1a718.tar.bz2
Use OProcess instead of popen/pclose and re-read config upon data re-fresh
Diffstat (limited to 'noncore/todayplugins') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.cpp65
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.h8
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
@@ -22,44 +22,30 @@
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
-#include <stdio.h>
#include <qfile.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpixmap.h>
#include <qtextstream.h>
+#include <opie/oprocess.h>
+
#include <qpe/config.h>
#include <qpe/resource.h>
#include "weatherpluginwidget.h"
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 );
weatherIcon = new QLabel( this );
weatherIcon->setMaximumWidth( 32 );
@@ -69,13 +55,12 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name )
weatherIcon->setPixmap( pic );
weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this );
weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
startTimer(1000);
- //retreiveData();
}
WeatherPluginWidget::~WeatherPluginWidget()
{
QFile file( localFile );
if ( file.exists() )
@@ -93,32 +78,38 @@ void WeatherPluginWidget::timerEvent( QTimerEvent *e )
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()
{
weatherData = QString::null;
@@ -316,6 +307,18 @@ void WeatherPluginWidget::getIcon(const QString &data )
data.find( "PE ", 20 ) > -1 ||
data.find( "IC ", 20 ) > -1 )
{
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
@@ -29,14 +29,13 @@
#ifndef WEATHER_PLUGIN_WIDGET_H
#define WEATHER_PLUGIN_WIDGET_H
#include <qstring.h>
#include <qwidget.h>
-#include <unistd.h>
-
+class OProcess;
class QLabel;
class QTimer;
class WeatherPluginWidget : public QWidget {
Q_OBJECT
@@ -53,17 +52,20 @@ class WeatherPluginWidget : public QWidget {
QString dataStr;
bool useMetric;
int frequency;
QLabel *weatherLabel;
QLabel *weatherIcon;
-
+
void timerEvent( QTimerEvent * );
void retreiveData();
void displayWeather();
void getTemp( const QString & );
void getWind( const QString & );
void getPressure( const QString & );
void getIcon( const QString & );
+
+ private slots:
+ void dataRetrieved( OProcess * );
};
#endif