author | drw <drw> | 2003-03-15 16:09:22 (UTC) |
---|---|---|
committer | drw <drw> | 2003-03-15 16:09:22 (UTC) |
commit | 69823b154b29cd62c9d53f7ebdaae4cb7dd61939 (patch) (side-by-side diff) | |
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 @@ -241,211 +241,241 @@ QWidget *SettingsImpl :: initProxyTab() label = new QLabel( tr( "Password:" ), container ); layout->addWidget( label, 3, 0 ); txtPassword = new QLineEdit( container ); layout->addWidget( txtPassword, 3, 1 ); QPushButton *btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), container ); connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); return control; } void SettingsImpl :: setupData() { // add servers QString serverName; QListIterator<Server> it( dataMgr->getServerList() ); for ( ; it.current(); ++it ) { serverName = it.current()->getServerName(); if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) continue; servers->insertItem( serverName ); } // add destinations QListIterator<Destination> it2( dataMgr->getDestinationList() ); for ( ; it2.current(); ++it2 ) destinations->insertItem( it2.current()->getDestinationName() ); // setup proxy tab txtHttpProxy->setText( dataMgr->getHttpProxy() ); txtFtpProxy->setText( dataMgr->getFtpProxy() ); txtUsername->setText( dataMgr->getProxyUsername() ); txtPassword->setText( dataMgr->getProxyPassword() ); chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); } //------------------ Servers tab ---------------------- void SettingsImpl :: editServer( int sel ) { currentSelectedServer = sel; Server *s = dataMgr->getServer( servers->currentText() ); + 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() { newserver = true; servername->setText( "" ); serverurl->setText( "" ); servername->setFocus(); active->setChecked( true ); } void SettingsImpl :: removeServer() { changed = true; Server *s = dataMgr->getServer( servers->currentText() ); + if ( s ) + { dataMgr->getServerList().removeRef( s ); servers->removeItem( currentSelectedServer ); } +} void SettingsImpl :: changeServerDetails() { changed = true; QString newName = servername->text(); // Convert any spaces to underscores char *tmpStr = new char[newName.length() + 1]; for ( unsigned int i = 0 ; i < newName.length() ; ++i ) { if ( newName[i] == ' ' ) tmpStr[i] = '_'; else tmpStr[i] = newName[i].latin1(); } tmpStr[newName.length()] = '\0'; newName = tmpStr; delete tmpStr; if ( !newserver ) { Server *s = dataMgr->getServer( servers->currentText() ); - + if ( s ) + { // 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 ); } + } else { Server s( newName, serverurl->text() ); dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); dataMgr->getServerList().last()->setActive( active->isChecked() ); servers->insertItem( newName ); servers->setCurrentItem( servers->count() ); newserver = false; } } //------------------ Destinations tab ---------------------- void SettingsImpl :: editDestination( int sel ) { currentSelectedDestination = sel; Destination *d = dataMgr->getDestination( destinations->currentText() ); + 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() { newdestination = true; destinationname->setText( "" ); destinationurl->setText( "" ); destinationname->setFocus(); linkToRoot->setChecked( true ); } void SettingsImpl :: removeDestination() { changed = true; Destination *d = dataMgr->getDestination( destinations->currentText() ); + if ( d ) + { dataMgr->getDestinationList().removeRef( d ); destinations->removeItem( currentSelectedDestination ); } +} void SettingsImpl :: changeDestinationDetails() { changed = true; #ifdef QWS Config cfg( "aqpkg" ); cfg.setGroup( "destinations" ); #endif QString newName = destinationname->text(); if ( !newdestination ) { Destination *d = dataMgr->getDestination( destinations->currentText() ); - + if ( d ) + { // 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 ); // Update list box destinations->changeItem( newName, currentSelectedDestination ); } + #ifdef QWS QString key = newName; key += "_linkToRoot"; int val = d->linkToRoot(); cfg.writeEntry( key, val ); #endif } + } else { dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); destinations->insertItem( newName ); destinations->setCurrentItem( destinations->count() ); newdestination = false; #ifdef QWS QString key = newName; key += "_linkToRoot"; cfg.writeEntry( key, true ); #endif } } //------------------ Proxy tab ---------------------- void SettingsImpl :: proxyApplyChanges() { changed = true; dataMgr->setHttpProxy( txtHttpProxy->text() ); dataMgr->setFtpProxy( txtFtpProxy->text() ); dataMgr->setProxyUsername( txtUsername->text() ); dataMgr->setProxyPassword( txtPassword->text() ); dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() ); dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() ); } |