@ -22,6 +22,11 @@ Ipv6SettingsTab::~Ipv6SettingsTab()
QVariantMap Ipv6SettingsTab : : readSettings ( )
QVariantMap Ipv6SettingsTab : : readSettings ( )
{
{
// If the user has invalid data in here, just return the original settings data
if ( ! checkValidity ( ) ) {
return origSettings ;
}
QVariantMap output ;
QVariantMap output ;
switch ( ui - > methodComboBox - > currentIndex ( ) ) {
switch ( ui - > methodComboBox - > currentIndex ( ) ) {
case 0 : // Automatic
case 0 : // Automatic
@ -79,6 +84,7 @@ QVariantMap Ipv6SettingsTab::readSettings()
void Ipv6SettingsTab : : loadSettings ( QVariantMap settings )
void Ipv6SettingsTab : : loadSettings ( QVariantMap settings )
{
{
origSettings = settings ; // We may need to restore these if something about the settings the user puts in is invalid.
if ( settings [ " ipv6Method " ] . isValid ( ) ) {
if ( settings [ " ipv6Method " ] . isValid ( ) ) {
switch ( settings [ " ipv6Method " ] . toInt ( ) ) {
switch ( settings [ " ipv6Method " ] . toInt ( ) ) {
case ConnectionSettingsEngine : : Ipv6Automatic :
case ConnectionSettingsEngine : : Ipv6Automatic :
@ -179,3 +185,35 @@ void Ipv6SettingsTab::onManualIpv6ConfigurationRemoveButtonClicked()
{
{
ui - > manualIpv6ConfigurationTable - > removeRow ( ui - > manualIpv6ConfigurationTable - > currentRow ( ) ) ;
ui - > manualIpv6ConfigurationTable - > removeRow ( ui - > manualIpv6ConfigurationTable - > currentRow ( ) ) ;
}
}
bool Ipv6SettingsTab : : checkValidity ( )
{
// almost copied verbatim from plasma-nm
if ( ui - > methodComboBox - > currentIndex ( ) = = 4 ) { // manual
if ( ! ui - > manualIpv6ConfigurationTable - > rowCount ( ) ) {
return false ;
}
for ( int i = 0 , rowCount = ui - > manualIpv6ConfigurationTable - > rowCount ( ) ; i < rowCount ; i + + ) {
QHostAddress ip = QHostAddress ( ui - > manualIpv6ConfigurationTable - > item ( i , 0 ) - > text ( ) ) ;
const int prefix = ui - > manualIpv6ConfigurationTable - > item ( i , 1 ) - > text ( ) . toInt ( ) ;
QHostAddress gateway = QHostAddress ( ui - > manualIpv6ConfigurationTable - > item ( i , 2 ) - > text ( ) ) ;
if ( ip . isNull ( ) | | ! ( prefix > = 1 & & prefix < = 128 ) | | ( gateway . isNull ( ) & & ! ui - > manualIpv6ConfigurationTable - > item ( i , 2 ) - > text ( ) . isEmpty ( ) ) ) {
return false ;
}
}
}
if ( ! ui - > dnsServersLineEdit - > text ( ) . isEmpty ( ) & & ( ui - > methodComboBox - > currentIndex ( ) = = 0 | | ui - > methodComboBox - > currentIndex ( ) = = 1 | | ui - > methodComboBox - > currentIndex ( ) = = 4 ) ) { // Automatic, AutomaticIPOnly, or Manual
const QStringList tmp = ui - > dnsServersLineEdit - > text ( ) . split ( QLatin1Char ( ' , ' ) ) ;
for ( const QString & str : tmp ) {
QHostAddress addr ( str ) ;
if ( addr . isNull ( ) ) {
return false ;
}
}
}
return true ;
}