summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interfaces/interfaces.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/interfaces/interfaces.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.cpp54
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
@@ -1,8 +1,9 @@
1#include "interfaces.h" 1#include "interfaces.h"
2 2
3#include <qcheckbox.h>
3#include <qfile.h> 4#include <qfile.h>
4#include <qtextstream.h> 5#include <qtextstream.h>
5#include <qregexp.h> 6#include <qregexp.h>
6 7
7// The three stanza's 8// The three stanza's
8#define AUTO "auto" 9#define AUTO "auto"
@@ -148,12 +149,13 @@ bool Interfaces::isInterfaceSet() const {
148 * @param family the family of this interface inet or inet, ipx or inet6 149 * @param family the family of this interface inet or inet, ipx or inet6
149 * Must of one of the families defined in interfaces.h 150 * Must of one of the families defined in interfaces.h
150 * @param method for the family. see interfaces man page for family methods. 151 * @param method for the family. see interfaces man page for family methods.
151 * @return true if successfull. 152 * @return true if successfull.
152 */ 153 */
153bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ 154bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
155 qDebug("Interfaces::addInterface(%s)",interface.latin1());
154 if(0 == acceptedFamily.contains(family)) 156 if(0 == acceptedFamily.contains(family))
155 return false; 157 return false;
156 QString newInterface = interface.simplifyWhiteSpace(); 158 QString newInterface = interface.simplifyWhiteSpace();
157 newInterface = newInterface.replace(QRegExp(" "), ""); 159 newInterface = newInterface.replace(QRegExp(" "), "");
158 interfaces.append(""); 160 interfaces.append("");
159 interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); 161 interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method));
@@ -163,12 +165,13 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c
163/** 165/**
164 * Copies interface with name interface to name newInterface 166 * Copies interface with name interface to name newInterface
165 * @param newInterface name of the new interface. 167 * @param newInterface name of the new interface.
166 * @return bool true if successfull 168 * @return bool true if successfull
167 */ 169 */
168bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ 170bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
171 qDebug("copy interface %s to %s", interface.latin1(), newInterface.latin1());
169 if(!setInterface(interface)) 172 if(!setInterface(interface))
170 return false; 173 return false;
171 174
172 // Store the old interface and bump past the stanza line. 175 // Store the old interface and bump past the stanza line.
173 QStringList::Iterator it = currentIface; 176 QStringList::Iterator it = currentIface;
174 it++; 177 it++;
@@ -269,18 +272,22 @@ QString Interfaces::getInterfaceMethod(bool &error){
269/** 272/**
270 * Sets the interface name to newName. 273 * Sets the interface name to newName.
271 * @param newName the new name of the interface. All whitespace is removed. 274 * @param newName the new name of the interface. All whitespace is removed.
272 * @return bool true if successfull. 275 * @return bool true if successfull.
273 */ 276 */
274bool Interfaces::setInterfaceName(const QString &newName){ 277bool Interfaces::setInterfaceName(const QString &newName){
278 qDebug("setInterfaceName %s", newName.latin1());
275 if(currentIface == interfaces.end()) 279 if(currentIface == interfaces.end())
276 return false; 280 return false;
277 QString name = newName.simplifyWhiteSpace(); 281 QString name = newName.simplifyWhiteSpace();
278 name = name.replace(QRegExp(" "), ""); 282 name = name.replace(QRegExp(" "), "");
279 bool returnValue = false; 283 bool returnValue = false;
280 (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); 284 QString tmp = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
285 qDebug("setting %s",tmp.latin1());
286
287 (*currentIface) = tmp;
281 return !returnValue; 288 return !returnValue;
282} 289}
283 290
284/** 291/**
285 * Sets the interface family to newName. 292 * Sets the interface family to newName.
286 * @param newName the new name of the interface. Must be one of the families 293 * @param newName the new name of the interface. Must be one of the families
@@ -324,18 +331,24 @@ QString Interfaces::getInterfaceOption(const QString &option, bool &error){
324 return getOption(currentIface, option, error); 331 return getOption(currentIface, option, error);
325} 332}
326 333
327/** 334/**
328 * Set a value for an option in the currently selected interface. If option 335 * Set a value for an option in the currently selected interface. If option
329 * doesn't exist then it is added along with the value. 336 * doesn't exist then it is added along with the value.
337 * If value isEmpty() then we will remove the option
338 *
330 * @param option the options to set the value. 339 * @param option the options to set the value.
331 * @param value the value that option should be set to. 340 * @param value the value that option should be set to.
332 * @param error set to true if any error occurs, false otherwise. 341 * @param error set to true if any error occurs, false otherwise.
333 * @return QString the options value. QString::null if error == true 342 * @return QString the options value. QString::null if error == true
334 */ 343 */
335bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ 344bool Interfaces::setInterfaceOption(const QString &option, const QString &value){
345 if( value.stripWhiteSpace().isEmpty() )
346 return removeInterfaceOption( option );
347
348 qDebug("iface >%s< option >%s< value >%s<", (*currentIface).latin1(), option.latin1(),value.latin1());
336 return setOption(currentIface, option, value); 349 return setOption(currentIface, option, value);
337} 350}
338 351
339/** 352/**
340 * Removes a value for an option in the currently selected interface. 353 * Removes a value for an option in the currently selected interface.
341 * @param option the options to set the value. 354 * @param option the options to set the value.
@@ -489,36 +502,55 @@ bool Interfaces::setStanza(const QString &stanza, const QString &option, QString
489 * @param option the option to use when setting value. 502 * @param option the option to use when setting value.
490 * @return bool true if successfull, false otherwise. 503 * @return bool true if successfull, false otherwise.
491 */ 504 */
492bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ 505bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){
493 if(start == interfaces.end()) 506 if(start == interfaces.end())
494 return false; 507 return false;
495 508 qDebug("setting option");
496 bool found = false; 509 bool found = false;
510 bool replaced = false;
511 QStringList::Iterator insertAt = NULL;
497 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 512 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
498 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 513 qDebug(" Interfaces::setOption got line >%s<",(*it).latin1());
499 if(!found && value != ""){ 514 // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line
500 // Got to the end of the stanza without finding it, so append it. 515 // but since it works with an empty interfaces file I (tille) will not do anything more
501 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 516 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){
502 } 517 if (found) break;
518// && it != start){
519// if(!found && value != ""){
520// // Got to the end of the stanza without finding it, so append it.
521// qDebug(" Got to the end of the stanza without finding it, so append it.");
522// interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
523// }
524 qDebug("found 1");
525// interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value));
503 found = true; 526 found = true;
504 break; 527 insertAt = it;
528
505 } 529 }
506 if((*it).contains(option) && it != start && (*it).at(0) != '#'){ 530 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
507 // Found it in stanza so replace it. 531 // Found it in stanza so replace it.
532 qDebug("found 2");
508 if(found) 533 if(found)
509 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 534 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
510 found = true; 535 found = true;
536 replaced = true;
511 (*it) = QString("\t%1 %2").arg(option).arg(value); 537 (*it) = QString("\t%1 %2").arg(option).arg(value);
512 } 538 }
513 } 539 }
514 if(!found){ 540 if(!found){
541 qDebug("! found insert anyway");
515 QStringList::Iterator p = start; 542 QStringList::Iterator p = start;
516 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); 543 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
517 found = true; 544 found = true;
518 } 545 }
546
547 if(found && !replaced){
548 qDebug("found iface but not the option so insert it here...");
549 interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value));
550 }
519 return found; 551 return found;
520} 552}
521 553
522/** 554/**
523 * Removes a stanza and all of its options 555 * Removes a stanza and all of its options
524 * @param stanza the stanza to remove 556 * @param stanza the stanza to remove
@@ -549,13 +581,14 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString
549 } 581 }
550 if((*it).contains(option) && it != start && (*it).at(0) != '#'){ 582 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
551 // Found it in stanza so replace it. 583 // Found it in stanza so replace it.
552 if(found) 584 if(found)
553 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 585 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
554 found = true; 586 found = true;
555 (*it) = ""; 587 it = interfaces.remove( it ); // we really want to remove the line
588 --it; // we do ++it later in the head of the for loop
556 } 589 }
557 } 590 }
558 return found; 591 return found;
559} 592}
560 593
561/** 594/**
@@ -576,13 +609,14 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString
576 } 609 }
577 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ 610 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){
578 // Found it in stanza so replace it. 611 // Found it in stanza so replace it.
579 if(found) 612 if(found)
580 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 613 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
581 found = true; 614 found = true;
582 (*it) = ""; 615 it = interfaces.remove( it ); // we really want to remove the line
616 --it; // we do ++it later in the head of the for loop
583 } 617 }
584 } 618 }
585 return found; 619 return found;
586} 620}
587 621
588/** 622/**