author | drw <drw> | 2002-11-17 00:12:31 (UTC) |
---|---|---|
committer | drw <drw> | 2002-11-17 00:12:31 (UTC) |
commit | d28c78c564f3c6ecad91506c50e2c80e66c1a718 (patch) (unidiff) | |
tree | 08d930e4872f78a4651dccd51d920dadfaaf7f39 /noncore | |
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 | |||
@@ -25,7 +25,6 @@ | |||
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | #include <stdio.h> | ||
29 | 28 | ||
30 | #include <qfile.h> | 29 | #include <qfile.h> |
31 | #include <qimage.h> | 30 | #include <qimage.h> |
@@ -34,6 +33,8 @@ | |||
34 | #include <qpixmap.h> | 33 | #include <qpixmap.h> |
35 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
36 | 35 | ||
36 | #include <opie/oprocess.h> | ||
37 | |||
37 | #include <qpe/config.h> | 38 | #include <qpe/config.h> |
38 | #include <qpe/resource.h> | 39 | #include <qpe/resource.h> |
39 | 40 | ||
@@ -42,21 +43,6 @@ | |||
42 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) | 43 | WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) |
43 | : QWidget( parent, name ) | 44 | : QWidget( parent, name ) |
44 | { | 45 | { |
45 | Config config( "todayweatherplugin"); | ||
46 | config.setGroup( "Config" ); | ||
47 | |||
48 | location = config.readEntry( "Location", "" ); | ||
49 | useMetric = config.readBoolEntry( "Metric", TRUE ); | ||
50 | frequency = config.readNumEntry( "Frequency", 5 ); | ||
51 | |||
52 | localFile = "/tmp/"; | ||
53 | localFile.append( location ); | ||
54 | localFile.append( ".TXT" ); | ||
55 | |||
56 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; | ||
57 | remoteFile.append( location ); | ||
58 | remoteFile.append( ".TXT" ); | ||
59 | |||
60 | QHBoxLayout *layout = new QHBoxLayout( this ); | 46 | QHBoxLayout *layout = new QHBoxLayout( this ); |
61 | layout->setAutoAdd( TRUE ); | 47 | layout->setAutoAdd( TRUE ); |
62 | layout->setSpacing( 2 ); | 48 | layout->setSpacing( 2 ); |
@@ -72,7 +58,6 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) | |||
72 | weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); | 58 | weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); |
73 | 59 | ||
74 | startTimer(1000); | 60 | startTimer(1000); |
75 | //retreiveData(); | ||
76 | } | 61 | } |
77 | 62 | ||
78 | WeatherPluginWidget::~WeatherPluginWidget() | 63 | WeatherPluginWidget::~WeatherPluginWidget() |
@@ -96,26 +81,32 @@ void WeatherPluginWidget::retreiveData() | |||
96 | { | 81 | { |
97 | startTimer( frequency * 60000 ); | 82 | startTimer( frequency * 60000 ); |
98 | 83 | ||
84 | Config config( "todayweatherplugin"); | ||
85 | config.setGroup( "Config" ); | ||
86 | |||
87 | location = config.readEntry( "Location", "" ); | ||
88 | useMetric = config.readBoolEntry( "Metric", TRUE ); | ||
89 | frequency = config.readNumEntry( "Frequency", 5 ); | ||
90 | |||
91 | localFile = "/tmp/"; | ||
92 | localFile.append( location ); | ||
93 | localFile.append( ".TXT" ); | ||
94 | |||
95 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; | ||
96 | remoteFile.append( location ); | ||
97 | remoteFile.append( ".TXT" ); | ||
98 | |||
99 | QFile file( localFile ); | 99 | QFile file( localFile ); |
100 | if ( file.exists() ) | 100 | if ( file.exists() ) |
101 | { | 101 | { |
102 | file.remove(); | 102 | file.remove(); |
103 | } | 103 | } |
104 | 104 | ||
105 | QString command = "wget -q "; | 105 | OProcess *proc = new OProcess; |
106 | command.append( remoteFile ); | 106 | |
107 | command.append( " -O " ); | 107 | *proc << "wget" << "-q" << remoteFile << "-O" << localFile; |
108 | command.append( localFile ); | 108 | connect( proc, SIGNAL( processExited( OProcess * ) ), this, SLOT( dataRetrieved( OProcess * ) ) ); |
109 | FILE *get = popen( command.latin1(), "r" ); | 109 | proc->start(); |
110 | if ( get ) | ||
111 | { | ||
112 | pclose( get ); | ||
113 | displayWeather(); | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); | ||
118 | } | ||
119 | } | 110 | } |
120 | 111 | ||
121 | void WeatherPluginWidget::displayWeather() | 112 | void WeatherPluginWidget::displayWeather() |
@@ -319,3 +310,15 @@ void WeatherPluginWidget::getIcon(const QString &data ) | |||
319 | dataStr = "sleet"; | 310 | dataStr = "sleet"; |
320 | } | 311 | } |
321 | } | 312 | } |
313 | |||
314 | void WeatherPluginWidget::dataRetrieved( OProcess *process ) | ||
315 | { | ||
316 | if ( process->normalExit() ) | ||
317 | { | ||
318 | displayWeather(); | ||
319 | } | ||
320 | else | ||
321 | { | ||
322 | weatherLabel->setText( tr( "Current weather data not available.\nTry looking out the window." ) ); | ||
323 | } | ||
324 | } | ||
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 @@ | |||
32 | #include <qstring.h> | 32 | #include <qstring.h> |
33 | #include <qwidget.h> | 33 | #include <qwidget.h> |
34 | 34 | ||
35 | #include <unistd.h> | 35 | class OProcess; |
36 | |||
37 | class QLabel; | 36 | class QLabel; |
38 | class QTimer; | 37 | class QTimer; |
39 | 38 | ||
@@ -56,7 +55,7 @@ class WeatherPluginWidget : public QWidget { | |||
56 | 55 | ||
57 | QLabel *weatherLabel; | 56 | QLabel *weatherLabel; |
58 | QLabel *weatherIcon; | 57 | QLabel *weatherIcon; |
59 | 58 | ||
60 | void timerEvent( QTimerEvent * ); | 59 | void timerEvent( QTimerEvent * ); |
61 | void retreiveData(); | 60 | void retreiveData(); |
62 | void displayWeather(); | 61 | void displayWeather(); |
@@ -64,6 +63,9 @@ class WeatherPluginWidget : public QWidget { | |||
64 | void getWind( const QString & ); | 63 | void getWind( const QString & ); |
65 | void getPressure( const QString & ); | 64 | void getPressure( const QString & ); |
66 | void getIcon( const QString & ); | 65 | void getIcon( const QString & ); |
66 | |||
67 | private slots: | ||
68 | void dataRetrieved( OProcess * ); | ||
67 | }; | 69 | }; |
68 | 70 | ||
69 | #endif | 71 | #endif |