From 69823b154b29cd62c9d53f7ebdaae4cb7dd61939 Mon Sep 17 00:00:00 2001 From: drw Date: Sat, 15 Mar 2003 16:09:22 +0000 Subject: Added several checks to ensure we have a valid server or destination. Fixes bug #727, and also prevents several other segfault situations. --- (limited to 'noncore/settings/aqpkg') 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 @@ -286,10 +286,20 @@ void SettingsImpl :: editServer( int sel ) { currentSelectedServer = sel; Server *s = dataMgr->getServer( servers->currentText() ); - serverName = s->getServerName(); - servername->setText( s->getServerName() ); - serverurl->setText( s->getServerUrl() ); - active->setChecked( s->isServerActive() ); + if ( s ) + { + serverName = s->getServerName(); + servername->setText( s->getServerName() ); + serverurl->setText( s->getServerUrl() ); + active->setChecked( s->isServerActive() ); + } + else + { + serverName = ""; + servername->setText( "" ); + serverurl->setText( "" ); + active->setChecked( false ); + } } void SettingsImpl :: newServer() @@ -305,8 +315,11 @@ void SettingsImpl :: removeServer() { changed = true; Server *s = dataMgr->getServer( servers->currentText() ); - dataMgr->getServerList().removeRef( s ); - servers->removeItem( currentSelectedServer ); + if ( s ) + { + dataMgr->getServerList().removeRef( s ); + servers->removeItem( currentSelectedServer ); + } } void SettingsImpl :: changeServerDetails() @@ -332,21 +345,22 @@ void SettingsImpl :: changeServerDetails() if ( !newserver ) { Server *s = dataMgr->getServer( servers->currentText() ); - - // Update url - s->setServerUrl( serverurl->text() ); - s->setActive( active->isChecked() ); - - - // Check if server name has changed, if it has then we need to replace the key in the map - if ( serverName != newName ) + if ( s ) { - // Update server name - s->setServerName( newName ); - } + // Update url + s->setServerUrl( serverurl->text() ); + s->setActive( active->isChecked() ); + + // Check if server name has changed, if it has then we need to replace the key in the map + if ( serverName != newName ) + { + // Update server name + s->setServerName( newName ); + } - // Update list box - servers->changeItem( newName, currentSelectedServer ); + // Update list box + servers->changeItem( newName, currentSelectedServer ); + } } else { @@ -363,12 +377,22 @@ void SettingsImpl :: changeServerDetails() void SettingsImpl :: editDestination( int sel ) { - currentSelectedDestination = sel; + currentSelectedDestination = sel; Destination *d = dataMgr->getDestination( destinations->currentText() ); - destinationName = d->getDestinationName(); - destinationname->setText( d->getDestinationName() ); - destinationurl->setText( d->getDestinationPath() ); - linkToRoot->setChecked( d->linkToRoot() ); + if ( d ) + { + destinationName = d->getDestinationName(); + destinationname->setText( d->getDestinationName() ); + destinationurl->setText( d->getDestinationPath() ); + linkToRoot->setChecked( d->linkToRoot() ); + } + else + { + destinationName = ""; + destinationname->setText( "" ); + destinationurl->setText( "" ); + linkToRoot->setChecked( false ); + } } void SettingsImpl :: newDestination() @@ -384,8 +408,11 @@ void SettingsImpl :: removeDestination() { changed = true; Destination *d = dataMgr->getDestination( destinations->currentText() ); - dataMgr->getDestinationList().removeRef( d ); - destinations->removeItem( currentSelectedDestination ); + if ( d ) + { + dataMgr->getDestinationList().removeRef( d ); + destinations->removeItem( currentSelectedDestination ); + } } void SettingsImpl :: changeDestinationDetails() @@ -401,26 +428,29 @@ void SettingsImpl :: changeDestinationDetails() if ( !newdestination ) { Destination *d = dataMgr->getDestination( destinations->currentText() ); + if ( d ) + { + // Update url + d->setDestinationPath( destinationurl->text() ); + d->linkToRoot( linkToRoot->isChecked() ); - // Update url - d->setDestinationPath( destinationurl->text() ); - d->linkToRoot( linkToRoot->isChecked() ); + // Check if server name has changed, if it has then we need to replace the key in the map + if ( destinationName != newName ) + { + // Update server name + d->setDestinationName( newName ); - // Check if server name has changed, if it has then we need to replace the key in the map - if ( destinationName != newName ) - { - // Update server name - d->setDestinationName( newName ); + // Update list box + destinations->changeItem( newName, currentSelectedDestination ); + } - // Update list box - destinations->changeItem( newName, currentSelectedDestination ); - } #ifdef QWS - QString key = newName; - key += "_linkToRoot"; - int val = d->linkToRoot(); - cfg.writeEntry( key, val ); -#endif + QString key = newName; + key += "_linkToRoot"; + int val = d->linkToRoot(); + cfg.writeEntry( key, val ); +#endif + } } else { -- cgit v0.9.0.2