author | benmeyer <benmeyer> | 2002-10-18 16:27:02 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-18 16:27:02 (UTC) |
commit | 12851a09a2761ca6e189f080e9ca69bf4974302f (patch) (side-by-side diff) | |
tree | 1b9a368fc5e424d4bf60f4c582b87b23a975c26a /noncore/net/networksetup/interfaces.cpp | |
parent | 47e60a8dc20f46dd00b9405f7fde122792018627 (diff) | |
download | opie-12851a09a2761ca6e189f080e9ca69bf4974302f.zip opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.gz opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.bz2 |
Can now remove mapping and is done so automagicly when you delete a profile
Diffstat (limited to 'noncore/net/networksetup/interfaces.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/networksetup/interfaces.cpp | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp index 0927258..9155890 100644 --- a/noncore/net/networksetup/interfaces.cpp +++ b/noncore/net/networksetup/interfaces.cpp @@ -326,36 +326,46 @@ bool Interfaces::setInterfaceMethod(QString newName){ * iface eth0 static * address 192.168.1.1 * @param option the options to get the value. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ QString Interfaces::getInterfaceOption(QString option, bool &error){ return getOption(currentIface, option, error); } /** * Set a value for an option in the currently selected interface. If option - * doesn't exist then it is added along with the value. If value is set to an - * empty string then option is removed. + * doesn't exist then it is added along with the value. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::setInterfaceOption(QString option, QString value){ return setOption(currentIface, option, value); } /** + * Removes a value for an option in the currently selected interface. + * @param option the options to set the value. + * @param value the value that option should be set to. + * @param error set to true if any error occurs, false otherwise. + * @return QString the options value. QString::null if error == true + */ +bool Interfaces::removeInterfaceOption(QString option, QString value){ + return removeOption(currentIface, option, value); +} + +/** * Removes all of the options from the currently selected interface. * @return bool error if if successfull */ bool Interfaces::removeAllInterfaceOptions(){ return removeAllOptions(currentIface); } /** * Set the current map to interface's map. This needs to be done before you * can call addMapping(), set/getMap(), and get/setScript(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. @@ -368,34 +378,55 @@ bool Interfaces::setMapping(QString interface){ } /** * Adds a new Mapping to the interfaces file with interfaces. * @param interface the name(s) of the interfaces to set to this mapping */ void Interfaces::addMapping(QString option){ interfaces.append(""); interfaces.append(QString(MAPPING " %1").arg(option)); } /** + * Remove the currently selected map and all of its options. + * @return bool if successfull or not. + */ +bool Interfaces::removeMapping(){ + if(currentMapping == interfaces.end()) + return false; + (*currentMapping) = ""; + return removeAllOptions(currentMapping); +} + +/** * Set a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::setMap(QString map, QString value){ return setOption(currentMapping, map, value); } /** + * Removes a map option within a mapping. + * @param map map to use + * @param value value to go with map + * @return bool true if it is successfull. + */ +bool Interfaces::removeMap(QString map, QString value){ + return removeOption(currentMapping, map, value); +} + +/** * Get a map value within a mapping. * @param map map to get value of * @param bool true if it is successfull. * @return value that goes to the map */ QString Interfaces::getMap(QString map, bool &error){ return getOption(currentMapping, map, error); } /** * Sets a script value of the current mapping to argument. * @param argument the script name. @@ -468,37 +499,60 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString 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)); } found = true; break; } if((*it).contains(option) && it != start){ // Found it in stanza so replace it. if(found) qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); found = true; - if(value == "") - (*it) = ""; - else (*it) = QString("\t%1 %2").arg(option).arg(value); } } if(!found){ QStringList::Iterator p = start; interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); found = true; } return found; } +/** + * Removes a option in a stanza + * @param start the start of the stanza + * @param option the option to use when setting value. + * @return bool true if successfull, false otherwise. + */ +bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ + if(start == interfaces.end()) + return false; + + bool found = false; + for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { + if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ + // got to the end without finding it + break; + } + if((*it).contains(option) && (*it).contains(value) &&it != start){ + // Found it in stanza so replace it. + if(found) + qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); + found = true; + (*it) = ""; + } + } + return found; +} /** * Removes all options in a stanza * @param start the start of the stanza * @return bool true if successfull, false otherwise. */ bool Interfaces::removeAllOptions(QStringList::Iterator start){ if(start == interfaces.end()) return false; QStringList::Iterator it = start; it = ++it; |