author | drw <drw> | 2003-03-15 16:09:22 (UTC) |
---|---|---|
committer | drw <drw> | 2003-03-15 16:09:22 (UTC) |
commit | 69823b154b29cd62c9d53f7ebdaae4cb7dd61939 (patch) (unidiff) | |
tree | f678ad4bb0cf7005ce00e7231713372220c75cf6 | |
parent | ede78d4ab60d2c78427c4b1cc51cd9accc0aed1c (diff) | |
download | opie-69823b154b29cd62c9d53f7ebdaae4cb7dd61939.zip opie-69823b154b29cd62c9d53f7ebdaae4cb7dd61939.tar.gz opie-69823b154b29cd62c9d53f7ebdaae4cb7dd61939.tar.bz2 |
Added several checks to ensure we have a valid server or destination. Fixes bug #727, and also prevents several other segfault situations.
-rw-r--r-- | noncore/settings/aqpkg/settingsimpl.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp index 9f611da..e2afada 100644 --- a/noncore/settings/aqpkg/settingsimpl.cpp +++ b/noncore/settings/aqpkg/settingsimpl.cpp | |||
@@ -283,17 +283,27 @@ void SettingsImpl :: setupData() | |||
283 | //------------------ Servers tab ---------------------- | 283 | //------------------ Servers tab ---------------------- |
284 | 284 | ||
285 | void SettingsImpl :: editServer( int sel ) | 285 | void SettingsImpl :: editServer( int sel ) |
286 | { | 286 | { |
287 | currentSelectedServer = sel; | 287 | currentSelectedServer = sel; |
288 | Server *s = dataMgr->getServer( servers->currentText() ); | 288 | Server *s = dataMgr->getServer( servers->currentText() ); |
289 | if ( s ) | ||
290 | { | ||
289 | serverName = s->getServerName(); | 291 | serverName = s->getServerName(); |
290 | servername->setText( s->getServerName() ); | 292 | servername->setText( s->getServerName() ); |
291 | serverurl->setText( s->getServerUrl() ); | 293 | serverurl->setText( s->getServerUrl() ); |
292 | active->setChecked( s->isServerActive() ); | 294 | active->setChecked( s->isServerActive() ); |
293 | } | 295 | } |
296 | else | ||
297 | { | ||
298 | serverName = ""; | ||
299 | servername->setText( "" ); | ||
300 | serverurl->setText( "" ); | ||
301 | active->setChecked( false ); | ||
302 | } | ||
303 | } | ||
294 | 304 | ||
295 | void SettingsImpl :: newServer() | 305 | void SettingsImpl :: newServer() |
296 | { | 306 | { |
297 | newserver = true; | 307 | newserver = true; |
298 | servername->setText( "" ); | 308 | servername->setText( "" ); |
299 | serverurl->setText( "" ); | 309 | serverurl->setText( "" ); |
@@ -302,15 +312,18 @@ void SettingsImpl :: newServer() | |||
302 | } | 312 | } |
303 | 313 | ||
304 | void SettingsImpl :: removeServer() | 314 | void SettingsImpl :: removeServer() |
305 | { | 315 | { |
306 | changed = true; | 316 | changed = true; |
307 | Server *s = dataMgr->getServer( servers->currentText() ); | 317 | Server *s = dataMgr->getServer( servers->currentText() ); |
318 | if ( s ) | ||
319 | { | ||
308 | dataMgr->getServerList().removeRef( s ); | 320 | dataMgr->getServerList().removeRef( s ); |
309 | servers->removeItem( currentSelectedServer ); | 321 | servers->removeItem( currentSelectedServer ); |
310 | } | 322 | } |
323 | } | ||
311 | 324 | ||
312 | void SettingsImpl :: changeServerDetails() | 325 | void SettingsImpl :: changeServerDetails() |
313 | { | 326 | { |
314 | changed = true; | 327 | changed = true; |
315 | 328 | ||
316 | QString newName = servername->text(); | 329 | QString newName = servername->text(); |
@@ -329,28 +342,29 @@ void SettingsImpl :: changeServerDetails() | |||
329 | newName = tmpStr; | 342 | newName = tmpStr; |
330 | delete tmpStr; | 343 | delete tmpStr; |
331 | 344 | ||
332 | if ( !newserver ) | 345 | if ( !newserver ) |
333 | { | 346 | { |
334 | Server *s = dataMgr->getServer( servers->currentText() ); | 347 | Server *s = dataMgr->getServer( servers->currentText() ); |
335 | 348 | if ( s ) | |
349 | { | ||
336 | // Update url | 350 | // Update url |
337 | s->setServerUrl( serverurl->text() ); | 351 | s->setServerUrl( serverurl->text() ); |
338 | s->setActive( active->isChecked() ); | 352 | s->setActive( active->isChecked() ); |
339 | 353 | ||
340 | |||
341 | // Check if server name has changed, if it has then we need to replace the key in the map | 354 | // Check if server name has changed, if it has then we need to replace the key in the map |
342 | if ( serverName != newName ) | 355 | if ( serverName != newName ) |
343 | { | 356 | { |
344 | // Update server name | 357 | // Update server name |
345 | s->setServerName( newName ); | 358 | s->setServerName( newName ); |
346 | } | 359 | } |
347 | 360 | ||
348 | // Update list box | 361 | // Update list box |
349 | servers->changeItem( newName, currentSelectedServer ); | 362 | servers->changeItem( newName, currentSelectedServer ); |
350 | } | 363 | } |
364 | } | ||
351 | else | 365 | else |
352 | { | 366 | { |
353 | Server s( newName, serverurl->text() ); | 367 | Server s( newName, serverurl->text() ); |
354 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); | 368 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); |
355 | dataMgr->getServerList().last()->setActive( active->isChecked() ); | 369 | dataMgr->getServerList().last()->setActive( active->isChecked() ); |
356 | servers->insertItem( newName ); | 370 | servers->insertItem( newName ); |
@@ -362,17 +376,27 @@ void SettingsImpl :: changeServerDetails() | |||
362 | //------------------ Destinations tab ---------------------- | 376 | //------------------ Destinations tab ---------------------- |
363 | 377 | ||
364 | void SettingsImpl :: editDestination( int sel ) | 378 | void SettingsImpl :: editDestination( int sel ) |
365 | { | 379 | { |
366 | currentSelectedDestination = sel; | 380 | currentSelectedDestination = sel; |
367 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 381 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
382 | if ( d ) | ||
383 | { | ||
368 | destinationName = d->getDestinationName(); | 384 | destinationName = d->getDestinationName(); |
369 | destinationname->setText( d->getDestinationName() ); | 385 | destinationname->setText( d->getDestinationName() ); |
370 | destinationurl->setText( d->getDestinationPath() ); | 386 | destinationurl->setText( d->getDestinationPath() ); |
371 | linkToRoot->setChecked( d->linkToRoot() ); | 387 | linkToRoot->setChecked( d->linkToRoot() ); |
372 | } | 388 | } |
389 | else | ||
390 | { | ||
391 | destinationName = ""; | ||
392 | destinationname->setText( "" ); | ||
393 | destinationurl->setText( "" ); | ||
394 | linkToRoot->setChecked( false ); | ||
395 | } | ||
396 | } | ||
373 | 397 | ||
374 | void SettingsImpl :: newDestination() | 398 | void SettingsImpl :: newDestination() |
375 | { | 399 | { |
376 | newdestination = true; | 400 | newdestination = true; |
377 | destinationname->setText( "" ); | 401 | destinationname->setText( "" ); |
378 | destinationurl->setText( "" ); | 402 | destinationurl->setText( "" ); |
@@ -381,15 +405,18 @@ void SettingsImpl :: newDestination() | |||
381 | } | 405 | } |
382 | 406 | ||
383 | void SettingsImpl :: removeDestination() | 407 | void SettingsImpl :: removeDestination() |
384 | { | 408 | { |
385 | changed = true; | 409 | changed = true; |
386 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 410 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
411 | if ( d ) | ||
412 | { | ||
387 | dataMgr->getDestinationList().removeRef( d ); | 413 | dataMgr->getDestinationList().removeRef( d ); |
388 | destinations->removeItem( currentSelectedDestination ); | 414 | destinations->removeItem( currentSelectedDestination ); |
389 | } | 415 | } |
416 | } | ||
390 | 417 | ||
391 | void SettingsImpl :: changeDestinationDetails() | 418 | void SettingsImpl :: changeDestinationDetails() |
392 | { | 419 | { |
393 | changed = true; | 420 | changed = true; |
394 | 421 | ||
395 | #ifdef QWS | 422 | #ifdef QWS |
@@ -398,13 +425,14 @@ void SettingsImpl :: changeDestinationDetails() | |||
398 | #endif | 425 | #endif |
399 | 426 | ||
400 | QString newName = destinationname->text(); | 427 | QString newName = destinationname->text(); |
401 | if ( !newdestination ) | 428 | if ( !newdestination ) |
402 | { | 429 | { |
403 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 430 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
404 | 431 | if ( d ) | |
432 | { | ||
405 | // Update url | 433 | // Update url |
406 | d->setDestinationPath( destinationurl->text() ); | 434 | d->setDestinationPath( destinationurl->text() ); |
407 | d->linkToRoot( linkToRoot->isChecked() ); | 435 | d->linkToRoot( linkToRoot->isChecked() ); |
408 | 436 | ||
409 | // Check if server name has changed, if it has then we need to replace the key in the map | 437 | // Check if server name has changed, if it has then we need to replace the key in the map |
410 | if ( destinationName != newName ) | 438 | if ( destinationName != newName ) |
@@ -412,19 +440,21 @@ void SettingsImpl :: changeDestinationDetails() | |||
412 | // Update server name | 440 | // Update server name |
413 | d->setDestinationName( newName ); | 441 | d->setDestinationName( newName ); |
414 | 442 | ||
415 | // Update list box | 443 | // Update list box |
416 | destinations->changeItem( newName, currentSelectedDestination ); | 444 | destinations->changeItem( newName, currentSelectedDestination ); |
417 | } | 445 | } |
446 | |||
418 | #ifdef QWS | 447 | #ifdef QWS |
419 | QString key = newName; | 448 | QString key = newName; |
420 | key += "_linkToRoot"; | 449 | key += "_linkToRoot"; |
421 | int val = d->linkToRoot(); | 450 | int val = d->linkToRoot(); |
422 | cfg.writeEntry( key, val ); | 451 | cfg.writeEntry( key, val ); |
423 | #endif | 452 | #endif |
424 | } | 453 | } |
454 | } | ||
425 | else | 455 | else |
426 | { | 456 | { |
427 | dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); | 457 | dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); |
428 | destinations->insertItem( newName ); | 458 | destinations->insertItem( newName ); |
429 | destinations->setCurrentItem( destinations->count() ); | 459 | destinations->setCurrentItem( destinations->count() ); |
430 | newdestination = false; | 460 | newdestination = false; |