Diffstat (limited to 'noncore/todayplugins/weather/weatherpluginwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp index fe54051..27624c5 100644 --- a/noncore/todayplugins/weather/weatherpluginwidget.cpp +++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp | |||
@@ -59,97 +59,98 @@ WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) | |||
59 | } | 59 | } |
60 | 60 | ||
61 | WeatherPluginWidget::~WeatherPluginWidget() | 61 | WeatherPluginWidget::~WeatherPluginWidget() |
62 | { | 62 | { |
63 | QFile file( localFile ); | 63 | QFile file( localFile ); |
64 | if ( file.exists() ) | 64 | if ( file.exists() ) |
65 | { | 65 | { |
66 | file.remove(); | 66 | file.remove(); |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) | 70 | void WeatherPluginWidget::timerEvent( QTimerEvent *e ) |
71 | { | 71 | { |
72 | killTimer( e->timerId() ); | 72 | killTimer( e->timerId() ); |
73 | retreiveData(); | 73 | retreiveData(); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | 77 | ||
78 | void WeatherPluginWidget::retreiveData() | 78 | void WeatherPluginWidget::retreiveData() |
79 | { | 79 | { |
80 | Config config( "todayweatherplugin"); | 80 | Config config( "todayweatherplugin"); |
81 | config.setGroup( "Config" ); | 81 | config.setGroup( "Config" ); |
82 | 82 | ||
83 | location = config.readEntry( "Location", "" ); | 83 | location = config.readEntry( "Location", "" ); |
84 | useMetric = config.readBoolEntry( "Metric", true ); | 84 | useMetric = config.readBoolEntry( "Metric", true ); |
85 | frequency = config.readNumEntry( "Frequency", 5 ); | 85 | frequency = config.readNumEntry( "Frequency", 5 ); |
86 | 86 | ||
87 | startTimer( frequency * 60000 ); | 87 | startTimer( frequency * 60000 ); |
88 | 88 | ||
89 | localFile = "/tmp/"; | 89 | localFile = "/tmp/"; |
90 | localFile.append( location ); | 90 | localFile.append( location ); |
91 | localFile.append( ".TXT" ); | 91 | localFile.append( ".TXT" ); |
92 | 92 | ||
93 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; | 93 | remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; |
94 | remoteFile.append( location ); | 94 | remoteFile.append( location ); |
95 | remoteFile.append( ".TXT" ); | 95 | remoteFile.append( ".TXT" ); |
96 | 96 | ||
97 | QFile file( localFile ); | 97 | QFile file( localFile ); |
98 | if ( file.exists() ) | 98 | if ( file.exists() ) |
99 | { | 99 | { |
100 | file.remove(); | 100 | file.remove(); |
101 | } | 101 | } |
102 | 102 | ||
103 | OProcess *proc = new OProcess; | 103 | OProcess *proc = new OProcess; |
104 | 104 | ||
105 | *proc << "wget" << "-q" << remoteFile << "-O" << localFile; | 105 | *proc << "wget" << "-q" << remoteFile << "-O" << localFile; |
106 | connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) ); | 106 | connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) ); |
107 | proc->start(); | 107 | if ( !proc->start() ) |
108 | weatherLabel->setText( tr( "Could not start wget process." ) ); | ||
108 | } | 109 | } |
109 | 110 | ||
110 | void WeatherPluginWidget::displayWeather() | 111 | void WeatherPluginWidget::displayWeather() |
111 | { | 112 | { |
112 | weatherData = QString::null; | 113 | weatherData = QString::null; |
113 | 114 | ||
114 | QFile file( localFile ); | 115 | QFile file( localFile ); |
115 | 116 | ||
116 | if ( file.size() > 0 && file.open( IO_ReadOnly ) ) | 117 | if ( file.size() > 0 && file.open( IO_ReadOnly ) ) |
117 | { | 118 | { |
118 | QTextStream data( &file ); | 119 | QTextStream data( &file ); |
119 | while ( !data.eof() ) | 120 | while ( !data.eof() ) |
120 | { | 121 | { |
121 | weatherData.append( data.readLine() ); | 122 | weatherData.append( data.readLine() ); |
122 | } | 123 | } |
123 | file.close(); | 124 | file.close(); |
124 | weatherData = weatherData.simplifyWhiteSpace(); | 125 | weatherData = weatherData.simplifyWhiteSpace(); |
125 | 126 | ||
126 | QString tmpstr; | 127 | QString tmpstr; |
127 | 128 | ||
128 | tmpstr.append( tr( "Temp: " ) ); | 129 | tmpstr.append( tr( "Temp: " ) ); |
129 | getTemp( weatherData ); | 130 | getTemp( weatherData ); |
130 | tmpstr.append( dataStr ); | 131 | tmpstr.append( dataStr ); |
131 | 132 | ||
132 | tmpstr.append( tr( " Wind: " ) ); | 133 | tmpstr.append( tr( " Wind: " ) ); |
133 | getWind( weatherData ); | 134 | getWind( weatherData ); |
134 | tmpstr.append( dataStr ); | 135 | tmpstr.append( dataStr ); |
135 | 136 | ||
136 | tmpstr.append( tr( "\nPres: " ) ); | 137 | tmpstr.append( tr( "\nPres: " ) ); |
137 | getPressure( weatherData ); | 138 | getPressure( weatherData ); |
138 | tmpstr.append( dataStr ); | 139 | tmpstr.append( dataStr ); |
139 | 140 | ||
140 | weatherLabel->setText( tmpstr ); | 141 | weatherLabel->setText( tmpstr ); |
141 | 142 | ||
142 | tmpstr = "todayweatherplugin/"; | 143 | tmpstr = "todayweatherplugin/"; |
143 | getIcon( weatherData ); | 144 | getIcon( weatherData ); |
144 | tmpstr.append( dataStr ); | 145 | tmpstr.append( dataStr ); |
145 | weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) ); | 146 | weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) ); |
146 | } | 147 | } |
147 | else | 148 | else |
148 | { | 149 | { |
149 | weatherLabel->setText( tr( "Current weather data not available." ) ); | 150 | weatherLabel->setText( tr( "Current weather data not available." ) ); |
150 | } | 151 | } |
151 | } | 152 | } |
152 | 153 | ||
153 | void WeatherPluginWidget::getTemp( const QString &data ) | 154 | void WeatherPluginWidget::getTemp( const QString &data ) |
154 | { | 155 | { |
155 | int value; | 156 | int value; |