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.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp
index 6b161ae..e283926 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces/interfaces.cpp
@@ -21,13 +21,13 @@ Interfaces::Interfaces(QString useInterfacesFile){
21 acceptedFamily.append(INTERFACES_FAMILY_IPX); 21 acceptedFamily.append(INTERFACES_FAMILY_IPX);
22 acceptedFamily.append(INTERFACES_FAMILY_INET6); 22 acceptedFamily.append(INTERFACES_FAMILY_INET6);
23 23
24 interfacesFile = useInterfacesFile; 24 interfacesFile = useInterfacesFile;
25 QFile file(interfacesFile); 25 QFile file(interfacesFile);
26 if (!file.open(IO_ReadOnly)){ 26 if (!file.open(IO_ReadOnly)){
27 qDebug("Interfaces: Can't open file: %s for reading.", interfacesFile.latin1() ); 27 odebug << "Interfaces: Can't open file: " << interfacesFile.latin1() << " for reading." << oendl;
28 currentIface = interfaces.end(); 28 currentIface = interfaces.end();
29 currentMapping = interfaces.end(); 29 currentMapping = interfaces.end();
30 return; 30 return;
31 } 31 }
32 QTextStream stream( &file ); 32 QTextStream stream( &file );
33 QString line; 33 QString line;
@@ -73,13 +73,13 @@ QStringList Interfaces::getInterfaceList(){
73 * @return true is interface is in auto 73 * @return true is interface is in auto
74 */ 74 */
75bool Interfaces::isAuto(const QString &interface) const { 75bool Interfaces::isAuto(const QString &interface) const {
76 QStringList autoLines = interfaces.grep(QRegExp(AUTO)); 76 QStringList autoLines = interfaces.grep(QRegExp(AUTO));
77 QStringList awi = autoLines.grep(QRegExp(interface)); 77 QStringList awi = autoLines.grep(QRegExp(interface));
78 if(awi.count() > 1) 78 if(awi.count() > 1)
79 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); 79 odebug << QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1() << oendl;
80 return awi.count() > 0; 80 return awi.count() > 0;
81} 81}
82 82
83/** 83/**
84 * Attempt to set the auto option for interface to setAuto. 84 * Attempt to set the auto option for interface to setAuto.
85 * @param interface the interface to set 85 * @param interface the interface to set
@@ -149,13 +149,13 @@ bool Interfaces::isInterfaceSet() const {
149 * @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
150 * Must of one of the families defined in interfaces.h 150 * Must of one of the families defined in interfaces.h
151 * @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.
152 * @return true if successful. 152 * @return true if successful.
153 */ 153 */
154bool 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()); 155 odebug << "Interfaces::addInterface(" << interface.latin1() << ")" << oendl;
156 if(0 == acceptedFamily.contains(family)) 156 if(0 == acceptedFamily.contains(family))
157 return false; 157 return false;
158 QString newInterface = interface.simplifyWhiteSpace(); 158 QString newInterface = interface.simplifyWhiteSpace();
159 newInterface = newInterface.replace(QRegExp(" "), ""); 159 newInterface = newInterface.replace(QRegExp(" "), "");
160 interfaces.append(""); 160 interfaces.append("");
161 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));
@@ -165,13 +165,13 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c
165/** 165/**
166 * Copies interface with name interface to name newInterface 166 * Copies interface with name interface to name newInterface
167 * @param newInterface name of the new interface. 167 * @param newInterface name of the new interface.
168 * @return bool true if successful 168 * @return bool true if successful
169 */ 169 */
170bool 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()); 171 odebug << "copy interface " << interface.latin1() << " to " << newInterface.latin1() << "" << oendl;
172 if(!setInterface(interface)) 172 if(!setInterface(interface))
173 return false; 173 return false;
174 174
175 // Store the old interface and bump past the stanza line. 175 // Store the old interface and bump past the stanza line.
176 QStringList::Iterator it = currentIface; 176 QStringList::Iterator it = currentIface;
177 it++; 177 it++;
@@ -272,20 +272,20 @@ QString Interfaces::getInterfaceMethod(bool &error){
272/** 272/**
273 * Sets the interface name to newName. 273 * Sets the interface name to newName.
274 * @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.
275 * @return bool true if successful. 275 * @return bool true if successful.
276 */ 276 */
277bool Interfaces::setInterfaceName(const QString &newName){ 277bool Interfaces::setInterfaceName(const QString &newName){
278 qDebug("setInterfaceName %s", newName.latin1()); 278 odebug << "setInterfaceName " << newName.latin1() << "" << oendl;
279 if(currentIface == interfaces.end()) 279 if(currentIface == interfaces.end())
280 return false; 280 return false;
281 QString name = newName.simplifyWhiteSpace(); 281 QString name = newName.simplifyWhiteSpace();
282 name = name.replace(QRegExp(" "), ""); 282 name = name.replace(QRegExp(" "), "");
283 bool returnValue = false; 283 bool returnValue = false;
284 QString tmp = 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()); 285 odebug << "setting " << tmp.latin1() << "" << oendl;
286 286
287 (*currentIface) = tmp; 287 (*currentIface) = tmp;
288 return !returnValue; 288 return !returnValue;
289} 289}
290 290
291/** 291/**
@@ -342,13 +342,13 @@ QString Interfaces::getInterfaceOption(const QString &option, bool &error){
342 * @return QString the options value. QString::null if error == true 342 * @return QString the options value. QString::null if error == true
343 */ 343 */
344bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ 344bool Interfaces::setInterfaceOption(const QString &option, const QString &value){
345 if( value.stripWhiteSpace().isEmpty() ) 345 if( value.stripWhiteSpace().isEmpty() )
346 return removeInterfaceOption( option ); 346 return removeInterfaceOption( option );
347 347
348 qDebug("iface >%s< option >%s< value >%s<", (*currentIface).latin1(), option.latin1(),value.latin1()); 348 odebug << "iface >" << (*currentIface).latin1() << "< option >" << option.latin1() << "< value >" << value.latin1() << "<" << oendl;
349 return setOption(currentIface, option, value); 349 return setOption(currentIface, option, value);
350} 350}
351 351
352/** 352/**
353 * Removes a value for an option in the currently selected interface. 353 * Removes a value for an option in the currently selected interface.
354 * @param option the options to set the value. 354 * @param option the options to set the value.
@@ -483,13 +483,13 @@ bool Interfaces::setStanza(const QString &stanza, const QString &option, QString
483 // There are more chars in the line. check -1 483 // There are more chars in the line. check -1
484 if(line.at(point) != ' ') 484 if(line.at(point) != ' ')
485 valid = false; 485 valid = false;
486 } 486 }
487 if(valid){ 487 if(valid){
488 if(found == true){ 488 if(found == true){
489 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); 489 odebug << QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1() << oendl;
490 } 490 }
491 found = true; 491 found = true;
492 iterator = it; 492 iterator = it;
493 } 493 }
494 } 494 }
495 } 495 }
@@ -502,53 +502,53 @@ bool Interfaces::setStanza(const QString &stanza, const QString &option, QString
502 * @param option the option to use when setting value. 502 * @param option the option to use when setting value.
503 * @return bool true if successful, false otherwise. 503 * @return bool true if successful, false otherwise.
504 */ 504 */
505bool 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){
506 if(start == interfaces.end()) 506 if(start == interfaces.end())
507 return false; 507 return false;
508 qDebug("setting option"); 508 odebug << "setting option" << oendl;
509 bool found = false; 509 bool found = false;
510 bool replaced = false; 510 bool replaced = false;
511 QStringList::Iterator insertAt = NULL; 511 QStringList::Iterator insertAt = NULL;
512 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 512 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
513 qDebug(" Interfaces::setOption got line >%s<",(*it).latin1()); 513 odebug << " Interfaces::setOption got line >" << (*it).latin1() << "<" << oendl;
514 // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line 514 // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line
515 // but since it works with an empty interfaces file I (tille) will not do anything more 515 // but since it works with an empty interfaces file I (tille) will not do anything more
516 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){ 516 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){
517 if (found) break; 517 if (found) break;
518// && it != start){ 518// && it != start){
519// if(!found && value != ""){ 519// if(!found && value != ""){
520// // Got to the end of the stanza without finding it, so append it. 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."); 521// odebug << " Got to the end of the stanza without finding it, so append it." << oendl;
522// interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 522// interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
523// } 523// }
524 qDebug("found 1"); 524 odebug << "found 1" << oendl;
525// interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value)); 525// interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value));
526 found = true; 526 found = true;
527 insertAt = it; 527 insertAt = it;
528 528
529 } 529 }
530 if((*it).contains(option) && it != start && (*it).at(0) != '#'){ 530 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
531 // Found it in stanza so replace it. 531 // Found it in stanza so replace it.
532 qDebug("found 2"); 532 odebug << "found 2" << oendl;
533 if(found) 533 if(found)
534 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 534 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl;
535 found = true; 535 found = true;
536 replaced = true; 536 replaced = true;
537 (*it) = QString("\t%1 %2").arg(option).arg(value); 537 (*it) = QString("\t%1 %2").arg(option).arg(value);
538 } 538 }
539 } 539 }
540 if(!found){ 540 if(!found){
541 qDebug("! found insert anyway"); 541 odebug << "! found insert anyway" << oendl;
542 QStringList::Iterator p = start; 542 QStringList::Iterator p = start;
543 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); 543 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
544 found = true; 544 found = true;
545 } 545 }
546 546
547 if(found && !replaced){ 547 if(found && !replaced){
548 qDebug("found iface but not the option so insert it here..."); 548 odebug << "found iface but not the option so insert it here..." << oendl;
549 interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value)); 549 interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value));
550 } 550 }
551 return found; 551 return found;
552} 552}
553 553
554/** 554/**
@@ -579,13 +579,13 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString
579 // got to the end without finding it 579 // got to the end without finding it
580 break; 580 break;
581 } 581 }
582 if((*it).contains(option) && it != start && (*it).at(0) != '#'){ 582 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
583 // Found it in stanza so replace it. 583 // Found it in stanza so replace it.
584 if(found) 584 if(found)
585 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 585 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl;
586 found = true; 586 found = true;
587 it = interfaces.remove( it ); // we really want to remove the line 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 588 --it; // we do ++it later in the head of the for loop
589 } 589 }
590 } 590 }
591 return found; 591 return found;
@@ -607,13 +607,13 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString
607 // got to the end without finding it 607 // got to the end without finding it
608 break; 608 break;
609 } 609 }
610 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) != '#'){
611 // Found it in stanza so replace it. 611 // Found it in stanza so replace it.
612 if(found) 612 if(found)
613 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); 613 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl;
614 found = true; 614 found = true;
615 it = interfaces.remove( it ); // we really want to remove the line 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 616 --it; // we do ++it later in the head of the for loop
617 } 617 }
618 } 618 }
619 return found; 619 return found;
@@ -660,13 +660,13 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
660 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 660 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
661 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 661 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
662 break; 662 break;
663 } 663 }
664 if((*it).contains(option) && (*it).at(0) != '#'){ 664 if((*it).contains(option) && (*it).at(0) != '#'){
665 if(found) 665 if(found)
666 qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 666 odebug << QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1() << oendl;
667 found = true; 667 found = true;
668 QString line = (*it).simplifyWhiteSpace(); 668 QString line = (*it).simplifyWhiteSpace();
669 int space = line.find(" ", option.length()); 669 int space = line.find(" ", option.length());
670 if(space != -1){ 670 if(space != -1){
671 value = line.mid(space+1, line.length()); 671 value = line.mid(space+1, line.length());
672 break; 672 break;
@@ -684,26 +684,26 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
684 */ 684 */
685bool Interfaces::write(){ 685bool Interfaces::write(){
686 QFile::remove(interfacesFile); 686 QFile::remove(interfacesFile);
687 QFile file(interfacesFile); 687 QFile file(interfacesFile);
688 688
689 if (!file.open(IO_ReadWrite)){ 689 if (!file.open(IO_ReadWrite)){
690 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); 690 odebug << QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1() << oendl;
691 return false; 691 return false;
692 } 692 }
693 QTextStream stream( &file ); 693 QTextStream stream( &file );
694 int whiteSpaceCount = 0; 694 int whiteSpaceCount = 0;
695 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 695 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
696 QString line = (*it).simplifyWhiteSpace(); 696 QString line = (*it).simplifyWhiteSpace();
697 line = line.replace(QRegExp(" "),""); 697 line = line.replace(QRegExp(" "),"");
698 if(line.length() == 0) 698 if(line.length() == 0)
699 whiteSpaceCount++; 699 whiteSpaceCount++;
700 else 700 else
701 whiteSpaceCount = 0; 701 whiteSpaceCount = 0;
702 if(whiteSpaceCount < 2){ 702 if(whiteSpaceCount < 2){
703 qDebug((*it).latin1()); 703 odebug << (*it).latin1() << oendl;
704 stream << (*it) << '\n'; 704 stream << (*it) << '\n';
705 } 705 }
706 } 706 }
707 file.close(); 707 file.close();
708 return true; 708 return true;
709} 709}