Diffstat (limited to 'noncore/settings/networksettings/interfaces/interfaces.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.cpp | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index 71d0cf5..436e449 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp @@ -2,2 +2,3 @@ +#include <qcheckbox.h> #include <qfile.h> @@ -153,2 +154,3 @@ bool Interfaces::isInterfaceSet() const { bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ + qDebug("Interfaces::addInterface(%s)",interface.latin1()); if(0 == acceptedFamily.contains(family)) @@ -168,2 +170,3 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ + qDebug("copy interface %s to %s", interface.latin1(), newInterface.latin1()); if(!setInterface(interface)) @@ -274,2 +277,3 @@ QString Interfaces::getInterfaceMethod(bool &error){ bool Interfaces::setInterfaceName(const QString &newName){ + qDebug("setInterfaceName %s", newName.latin1()); if(currentIface == interfaces.end()) @@ -279,3 +283,6 @@ bool Interfaces::setInterfaceName(const QString &newName){ bool returnValue = false; - (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); + QString tmp = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); + qDebug("setting %s",tmp.latin1()); + + (*currentIface) = tmp; return !returnValue; @@ -329,2 +336,4 @@ QString Interfaces::getInterfaceOption(const QString &option, bool &error){ * doesn't exist then it is added along with the value. + * If value isEmpty() then we will remove the option + * * @param option the options to set the value. @@ -335,2 +344,6 @@ QString Interfaces::getInterfaceOption(const QString &option, bool &error){ bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ + if( value.stripWhiteSpace().isEmpty() ) + return removeInterfaceOption( option ); + + qDebug("iface >%s< option >%s< value >%s<", (*currentIface).latin1(), option.latin1(),value.latin1()); return setOption(currentIface, option, value); @@ -494,12 +507,23 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op return false; - + qDebug("setting option"); bool found = false; + bool replaced = false; + QStringList::Iterator insertAt = NULL; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { - if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ - if(!found && value != ""){ - // Got to the end of the stanza without finding it, so append it. - interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); - } + qDebug(" Interfaces::setOption got line >%s<",(*it).latin1()); + // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line + // but since it works with an empty interfaces file I (tille) will not do anything more + if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){ + if (found) break; +// && it != start){ +// if(!found && value != ""){ +// // Got to the end of the stanza without finding it, so append it. +// qDebug(" Got to the end of the stanza without finding it, so append it."); +// interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); +// } + qDebug("found 1"); +// interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value)); found = true; - break; + insertAt = it; + } @@ -507,2 +531,3 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op // Found it in stanza so replace it. + qDebug("found 2"); if(found) @@ -510,2 +535,3 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op found = true; + replaced = true; (*it) = QString("\t%1 %2").arg(option).arg(value); @@ -514,2 +540,3 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op if(!found){ + qDebug("! found insert anyway"); QStringList::Iterator p = start; @@ -518,2 +545,7 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op } + + if(found && !replaced){ + qDebug("found iface but not the option so insert it here..."); + interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value)); + } return found; @@ -554,3 +586,4 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString found = true; - (*it) = ""; + it = interfaces.remove( it ); // we really want to remove the line + --it; // we do ++it later in the head of the for loop } @@ -581,3 +614,4 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString found = true; - (*it) = ""; + it = interfaces.remove( it ); // we really want to remove the line + --it; // we do ++it later in the head of the for loop } |