-rw-r--r-- | noncore/todayplugins/stockticker/stockticker/helpwindow.cpp | 42 | ||||
-rw-r--r-- | noncore/todayplugins/weather/weatherpluginwidget.cpp | 5 |
2 files changed, 26 insertions, 21 deletions
diff --git a/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp index 410d642..2498bf9 100644 --- a/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp +++ b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp | |||
@@ -158,114 +158,118 @@ void HelpWindow::textChanged() | |||
158 | if ( !selectedURL.isEmpty() && pathCombo ) { | 158 | if ( !selectedURL.isEmpty() && pathCombo ) { |
159 | bool exists = FALSE; | 159 | bool exists = FALSE; |
160 | int i; | 160 | int i; |
161 | for ( i = 0; i < pathCombo->count(); ++i ) { | 161 | for ( i = 0; i < pathCombo->count(); ++i ) { |
162 | if ( pathCombo->text( i ) == selectedURL ) { | 162 | if ( pathCombo->text( i ) == selectedURL ) { |
163 | exists = TRUE; | 163 | exists = TRUE; |
164 | break; | 164 | break; |
165 | } | 165 | } |
166 | } | 166 | } |
167 | if ( !exists ) { | 167 | if ( !exists ) { |
168 | pathCombo->insertItem( selectedURL, 0 ); | 168 | pathCombo->insertItem( selectedURL, 0 ); |
169 | pathCombo->setCurrentItem( 0 ); | 169 | pathCombo->setCurrentItem( 0 ); |
170 | mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; | 170 | mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; |
171 | } else | 171 | } else |
172 | pathCombo->setCurrentItem( i ); | 172 | pathCombo->setCurrentItem( i ); |
173 | selectedURL = QString::null; | 173 | selectedURL = QString::null; |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | HelpWindow::~HelpWindow() | 177 | HelpWindow::~HelpWindow() |
178 | { | 178 | { |
179 | history.clear(); | 179 | history.clear(); |
180 | QMap<int, QString>::Iterator it = mHistory.begin(); | 180 | QMap<int, QString>::Iterator it = mHistory.begin(); |
181 | for ( ; it != mHistory.end(); ++it ) | 181 | for ( ; it != mHistory.end(); ++it ) |
182 | history.append( *it ); | 182 | history.append( *it ); |
183 | 183 | ||
184 | QFile f( QDir::currentDirPath() + "/.history" ); | 184 | QFile f( QDir::currentDirPath() + "/.history" ); |
185 | f.open( IO_WriteOnly ); | 185 | if ( f.open( IO_WriteOnly ) ) { |
186 | QDataStream s( &f ); | 186 | QDataStream s( &f ); |
187 | s << history; | 187 | s << history; |
188 | f.close(); | 188 | f.close(); |
189 | } | ||
189 | 190 | ||
190 | bookmarks.clear(); | 191 | bookmarks.clear(); |
191 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); | 192 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); |
192 | for ( ; it2 != mBookmarks.end(); ++it2 ) | 193 | for ( ; it2 != mBookmarks.end(); ++it2 ) |
193 | bookmarks.append( *it2 ); | 194 | bookmarks.append( *it2 ); |
194 | 195 | ||
195 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); | 196 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); |
196 | f2.open( IO_WriteOnly ); | 197 | if ( !f2.open( IO_WriteOnly ) ) |
198 | return; | ||
197 | QDataStream s2( &f2 ); | 199 | QDataStream s2( &f2 ); |
198 | s2 << bookmarks; | 200 | s2 << bookmarks; |
199 | f2.close(); | 201 | f2.close(); |
200 | } | 202 | } |
201 | 203 | ||
202 | void HelpWindow::openFile() | 204 | void HelpWindow::openFile() |
203 | { | 205 | { |
204 | #ifndef QT_NO_FILEDIALOG | 206 | #ifndef QT_NO_FILEDIALOG |
205 | QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); | 207 | QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); |
206 | if ( !fn.isEmpty() ) | 208 | if ( !fn.isEmpty() ) |
207 | browser->setSource( fn ); | 209 | browser->setSource( fn ); |
208 | #endif | 210 | #endif |
209 | } | 211 | } |
210 | 212 | ||
211 | void HelpWindow::newWindow() | 213 | void HelpWindow::newWindow() |
212 | { | 214 | { |
213 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); | 215 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); |
214 | } | 216 | } |
215 | 217 | ||
216 | void HelpWindow::pathSelected( const QString &_path ) | 218 | void HelpWindow::pathSelected( const QString &_path ) |
217 | { | 219 | { |
218 | browser->setSource( _path ); | 220 | browser->setSource( _path ); |
219 | QMap<int, QString>::Iterator it = mHistory.begin(); | 221 | QMap<int, QString>::Iterator it = mHistory.begin(); |
220 | bool exists = FALSE; | 222 | bool exists = FALSE; |
221 | for ( ; it != mHistory.end(); ++it ) { | 223 | for ( ; it != mHistory.end(); ++it ) { |
222 | if ( *it == _path ) { | 224 | if ( *it == _path ) { |
223 | exists = TRUE; | 225 | exists = TRUE; |
224 | break; | 226 | break; |
225 | } | 227 | } |
226 | } | 228 | } |
227 | if ( !exists ) | 229 | if ( !exists ) |
228 | mHistory[ hist->insertItem( _path ) ] = _path; | 230 | mHistory[ hist->insertItem( _path ) ] = _path; |
229 | } | 231 | } |
230 | 232 | ||
231 | void HelpWindow::readHistory() | 233 | void HelpWindow::readHistory() |
232 | { | 234 | { |
233 | if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { | 235 | if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { |
234 | QFile f( QDir::currentDirPath() + "/.history" ); | 236 | QFile f( QDir::currentDirPath() + "/.history" ); |
235 | f.open( IO_ReadOnly ); | 237 | if ( !f.open( IO_ReadOnly ) ) |
236 | QDataStream s( &f ); | 238 | return; |
237 | s >> history; | 239 | QDataStream s( &f ); |
238 | f.close(); | 240 | s >> history; |
239 | while ( history.count() > 20 ) | 241 | f.close(); |
240 | history.remove( history.begin() ); | 242 | while ( history.count() > 20 ) |
243 | history.remove( history.begin() ); | ||
241 | } | 244 | } |
242 | } | 245 | } |
243 | 246 | ||
244 | void HelpWindow::readBookmarks() | 247 | void HelpWindow::readBookmarks() |
245 | { | 248 | { |
246 | if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { | 249 | if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { |
247 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); | 250 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); |
248 | f.open( IO_ReadOnly ); | 251 | if ( !f.open( IO_ReadOnly ) ) |
249 | QDataStream s( &f ); | 252 | return; |
250 | s >> bookmarks; | 253 | QDataStream s( &f ); |
251 | f.close(); | 254 | s >> bookmarks; |
255 | f.close(); | ||
252 | } | 256 | } |
253 | } | 257 | } |
254 | 258 | ||
255 | void HelpWindow::histChosen( int i ) | 259 | void HelpWindow::histChosen( int i ) |
256 | { | 260 | { |
257 | if ( mHistory.contains( i ) ) | 261 | if ( mHistory.contains( i ) ) |
258 | browser->setSource( mHistory[ i ] ); | 262 | browser->setSource( mHistory[ i ] ); |
259 | } | 263 | } |
260 | 264 | ||
261 | void HelpWindow::bookmChosen( int i ) | 265 | void HelpWindow::bookmChosen( int i ) |
262 | { | 266 | { |
263 | if ( mBookmarks.contains( i ) ) | 267 | if ( mBookmarks.contains( i ) ) |
264 | browser->setSource( mBookmarks[ i ] ); | 268 | browser->setSource( mBookmarks[ i ] ); |
265 | } | 269 | } |
266 | 270 | ||
267 | void HelpWindow::addBookmark() | 271 | void HelpWindow::addBookmark() |
268 | { | 272 | { |
269 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); | 273 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); |
270 | } | 274 | } |
271 | 275 | ||
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 | |||
@@ -83,87 +83,88 @@ void WeatherPluginWidget::retreiveData() | |||
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; |
156 | bool ok; | 157 | bool ok; |
157 | 158 | ||
158 | int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); | 159 | int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); |
159 | if ( pos > -1 ) | 160 | if ( pos > -1 ) |
160 | { | 161 | { |
161 | if ( data.at( pos ) == 'M' ) | 162 | if ( data.at( pos ) == 'M' ) |
162 | { | 163 | { |
163 | value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); | 164 | value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); |
164 | } | 165 | } |
165 | else | 166 | else |
166 | { | 167 | { |
167 | value = data.mid( pos, 2 ).toInt( &ok ); | 168 | value = data.mid( pos, 2 ).toInt( &ok ); |
168 | } | 169 | } |
169 | if ( useMetric ) | 170 | if ( useMetric ) |