summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.cpp77
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.h5
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetupimp.cpp103
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetupimp.h4
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.cpp77
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.h5
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp103
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.h4
8 files changed, 186 insertions, 192 deletions
diff --git a/noncore/net/networksetup/interfaces/interfaces.cpp b/noncore/net/networksetup/interfaces/interfaces.cpp
index 708f399..e49998e 100644
--- a/noncore/net/networksetup/interfaces/interfaces.cpp
+++ b/noncore/net/networksetup/interfaces/interfaces.cpp
@@ -6,2 +6,3 @@
6 6
7// The three stanza's
7#define AUTO "auto" 8#define AUTO "auto"
@@ -104,2 +105,3 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
104 } 105 }
106 // else see if we need to remove from this one
105 else{ 107 else{
@@ -107,6 +109,4 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
107 (*it) = (*it).replace(QRegExp(interface), ""); 109 (*it) = (*it).replace(QRegExp(interface), "");
108 // clean up 110 // if AUTO is the only thing left clear the line
109 QString line = (*it).simplifyWhiteSpace(); 111 if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO)
110 line = line.replace(QRegExp(" "),"");
111 if(line == AUTO)
112 (*it) = ""; 112 (*it) = "";
@@ -118,9 +118,5 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
118 } 118 }
119 if(changed == false){ 119 // In the case where there is no AUTO field add one.
120 if(setAuto == true) 120 if(!changed && setAuto)
121 interfaces.append(QString(AUTO" %1").arg(interface)); 121 interfaces.append(QString(AUTO" %1").arg(interface));
122 else{
123 qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1());
124 }
125 }
126 return true; 122 return true;
@@ -159,3 +155,3 @@ bool Interfaces::isInterfaceSet(){
159bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ 155bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
160 if(acceptedFamily.contains(family)==0) 156 if(0 == acceptedFamily.contains(family))
161 return false; 157 return false;
@@ -174,4 +170,6 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c
174bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ 170bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
175 if(!setInterface(interface)) return false; 171 if(!setInterface(interface))
176 172 return false;
173
174 // Store the old interface and bump past the stanza line.
177 QStringList::Iterator it = currentIface; 175 QStringList::Iterator it = currentIface;
@@ -179,8 +177,12 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
179 177
178 // Add the new interface
180 bool error; 179 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); 180 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false; 181 if(!setInterface(newInterface))
182 return false;
183
183 QStringList::Iterator newIface = currentIface; 184 QStringList::Iterator newIface = currentIface;
184 newIface++; 185 newIface++;
185 186
187 // Copy all of the lines
186 for ( ; it != interfaces.end(); ++it ){ 188 for ( ; it != interfaces.end(); ++it ){
@@ -199,6 +201,3 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
199bool Interfaces::removeInterface(){ 201bool Interfaces::removeInterface(){
200 if(currentIface == interfaces.end()) 202 return removeStanza(currentIface);
201 return false;
202 (*currentIface) = "";
203 return removeAllInterfaceOptions();
204} 203}
@@ -234,6 +233,4 @@ QString Interfaces::getInterfaceFamily(bool &error){
234 QString name = getInterfaceName(error); 233 QString name = getInterfaceName(error);
235 if(error){ 234 if(error)
236 error = true;
237 return QString(); 235 return QString();
238 }
239 QString line = (*currentIface); 236 QString line = (*currentIface);
@@ -259,11 +256,7 @@ QString Interfaces::getInterfaceMethod(bool &error){
259 QString name = getInterfaceName(error); 256 QString name = getInterfaceName(error);
260 if(error){ 257 if(error)
261 error = true;
262 return QString(); 258 return QString();
263 }
264 QString family = getInterfaceFamily(error); 259 QString family = getInterfaceFamily(error);
265 if(error){ 260 if(error)
266 error = true;
267 return QString(); 261 return QString();
268 }
269 QString line = (*currentIface); 262 QString line = (*currentIface);
@@ -393,6 +386,3 @@ void Interfaces::addMapping(const QString &option){
393bool Interfaces::removeMapping(){ 386bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end()) 387 return removeStanza(currentMapping);
395 return false;
396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping);
398} 388}
@@ -522,2 +512,15 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op
522} 512}
513
514/**
515 * Removes a stanza and all of its options
516 * @param stanza the stanza to remove
517 * @return bool true if successfull.
518 */
519bool Interfaces::removeStanza(QStringList::Iterator &stanza){
520 if(stanza == interfaces.end())
521 return false;
522 (*stanza) = "";
523 return removeAllOptions(stanza);
524}
525
523/** 526/**
@@ -593,3 +596,3 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
593 if(found) 596 if(found)
594 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 597 qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
595 found = true; 598 found = true;
@@ -597,6 +600,6 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
597 int space = line.find(" ", option.length()); 600 int space = line.find(" ", option.length());
598 if(space != -1) 601 if(space != -1){
599 value = line.mid(space+1, line.length()); 602 value = line.mid(space+1, line.length());
600 else 603 break;
601 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); 604 }
602 } 605 }
diff --git a/noncore/net/networksetup/interfaces/interfaces.h b/noncore/net/networksetup/interfaces/interfaces.h
index 26abb73..5a8feb6 100644
--- a/noncore/net/networksetup/interfaces/interfaces.h
+++ b/noncore/net/networksetup/interfaces/interfaces.h
@@ -30,3 +30,3 @@ public:
30 30
31 bool removeInterface(); 31 inline bool removeInterface();
32 bool addInterface(const QString &interface, const QString &family, const QString &method); 32 bool addInterface(const QString &interface, const QString &family, const QString &method);
@@ -47,3 +47,3 @@ public:
47 bool setMapping(const QString &interface); 47 bool setMapping(const QString &interface);
48 bool removeMapping(); 48 inline bool removeMapping();
49 inline void addMapping(const QString &options); 49 inline void addMapping(const QString &options);
@@ -62,2 +62,3 @@ private:
62 QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); 62 QString getOption(const QStringList::Iterator &start, const QString &option, bool &error);
63 bool removeStanza(QStringList::Iterator &stanza);
63 bool removeAllOptions(const QStringList::Iterator &start); 64 bool removeAllOptions(const QStringList::Iterator &start);
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
index 3b1a4de..4818e37 100644
--- a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
+++ b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
@@ -2,6 +2,3 @@
2#include "interface.h" 2#include "interface.h"
3#include "interfaces.h"
4 3
5#include <qdialog.h>
6#include <qcombobox.h>
7#include <qcheckbox.h> 4#include <qcheckbox.h>
@@ -14,4 +11,2 @@
14 11
15#include <assert.h>
16
17#define DNSSCRIPT "changedns" 12#define DNSSCRIPT "changedns"
@@ -19,16 +14,5 @@
19/** 14/**
20 * Constuctor. Set up the connection and load the first profile. 15 * Constuctor. Set up the connection. A profile must be set.
21 */ 16 */
22InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ 17InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i){
23 assert(parent);
24 assert(i);
25 interface = i;
26 interfaces = new Interfaces();
27 bool error = false;
28 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
29 staticGroupBox->hide();
30 dhcpCheckBox->hide();
31 leaseTime->hide();
32 leaseHoursLabel->hide();
33 }
34} 18}
@@ -41,3 +25,3 @@ bool InterfaceSetupImp::saveChanges(){
41 return false; 25 return false;
42 interfaces->write(); 26 interfaces.write();
43 return true; 27 return true;
@@ -51,3 +35,3 @@ bool InterfaceSetupImp::saveSettings(){
51 // eh can't really do anything about it other then return. :-D 35 // eh can't really do anything about it other then return. :-D
52 if(!interfaces->isInterfaceSet()) 36 if(!interfaces.isInterfaceSet())
53 return true; 37 return true;
@@ -56,4 +40,4 @@ bool InterfaceSetupImp::saveSettings(){
56 // Loopback case 40 // Loopback case
57 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 41 if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
58 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 42 interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
59 return true; 43 return true;
@@ -65,3 +49,3 @@ bool InterfaceSetupImp::saveSettings(){
65 } 49 }
66 interfaces->removeAllInterfaceOptions(); 50 interfaces.removeAllInterfaceOptions();
67 51
@@ -69,15 +53,15 @@ bool InterfaceSetupImp::saveSettings(){
69 if(dhcpCheckBox->isChecked()){ 53 if(dhcpCheckBox->isChecked()){
70 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 54 interfaces.setInterfaceMethod(INTERFACES_METHOD_DHCP);
71 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); 55 interfaces.setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
72 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); 56 interfaces.setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
73 } 57 }
74 else{ 58 else{
75 interfaces->setInterfaceMethod("static"); 59 interfaces.setInterfaceMethod("static");
76 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 60 interfaces.setInterfaceOption("address", ipAddressEdit->text());
77 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 61 interfaces.setInterfaceOption("netmask", subnetMaskEdit->text());
78 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 62 interfaces.setInterfaceOption("gateway", gatewayEdit->text());
79 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ 63 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){
80 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 64 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
81 interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); 65 interfaces.setInterfaceOption("up "DNSSCRIPT" -a ", dns);
82 interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); 66 interfaces.setInterfaceOption("down "DNSSCRIPT" -r ", dns);
83 } 67 }
@@ -86,3 +70,3 @@ bool InterfaceSetupImp::saveSettings(){
86 // IP Information 70 // IP Information
87 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 71 interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
88 return true; 72 return true;
@@ -92,5 +76,15 @@ bool InterfaceSetupImp::saveSettings(){
92 * The Profile has changed. 76 * The Profile has changed.
93 * @profile the new profile. 77 * @param QString profile the new profile.
94 */ 78 */
95void InterfaceSetupImp::setProfile(const QString &profile){ 79void InterfaceSetupImp::setProfile(const QString &profile){
80 /*
81 bool error = false;
82 if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
83 staticGroupBox->hide();
84 dhcpCheckBox->hide();
85 leaseTime->hide();
86 leaseHoursLabel->hide();
87 }
88 */
89
96 QString newInterfaceName = interface->getInterfaceName(); 90 QString newInterfaceName = interface->getInterfaceName();
@@ -98,12 +92,11 @@ void InterfaceSetupImp::setProfile(const QString &profile){
98 newInterfaceName += "_" + profile; 92 newInterfaceName += "_" + profile;
99 qDebug("InterfaceSetupImp::setProfile");
100 // See if we have to make a interface. 93 // See if we have to make a interface.
101 if(!interfaces->setInterface(newInterfaceName)){ 94 if(!interfaces.setInterface(newInterfaceName)){
102 // Add making for this new interface if need too 95 // Add making for this new interface if need too
103 if(profile != ""){ 96 if(profile != ""){
104 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); 97 interfaces.copyInterface(interface->getInterfaceName(), newInterfaceName);
105 if(!interfaces->setMapping(interface->getInterfaceName())){ 98 if(!interfaces.setMapping(interface->getInterfaceName())){
106 interfaces->addMapping(interface->getInterfaceName()); 99 interfaces.addMapping(interface->getInterfaceName());
107 if(!interfaces->setMapping(interface->getInterfaceName())){ 100 if(!interfaces.setMapping(interface->getInterfaceName())){
108 qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); 101 qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface.");
109 return; 102 return;
@@ -111,9 +104,9 @@ void InterfaceSetupImp::setProfile(const QString &profile){
111 } 104 }
112 interfaces->setMap("map", newInterfaceName); 105 interfaces.setMap("map", newInterfaceName);
113 interfaces->setScript("getprofile.sh"); 106 interfaces.setScript("getprofile.sh");
114 } 107 }
115 else{ 108 else{
116 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); 109 interfaces.addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
117 if(!interfaces->setInterface(newInterfaceName)){ 110 if(!interfaces.setInterface(newInterfaceName)){
118 qDebug("InterfaceSetupImp: Added interface, but still can't set."); 111 qDebug("InterfaceSetupImp: Added interface, but still can't setInterface.");
119 return; 112 return;
@@ -127,3 +120,3 @@ void InterfaceSetupImp::setProfile(const QString &profile){
127 bool error = false; 120 bool error = false;
128 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 121 if(interfaces.getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
129 dhcpCheckBox->setChecked(true); 122 dhcpCheckBox->setChecked(true);
@@ -131,5 +124,5 @@ void InterfaceSetupImp::setProfile(const QString &profile){
131 dhcpCheckBox->setChecked(false); 124 dhcpCheckBox->setChecked(false);
132 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); 125 leaseTime->setValue(interfaces.getInterfaceOption("leasehours", error).toInt());
133 if(error) 126 if(error)
134 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); 127 leaseTime->setValue(interfaces.getInterfaceOption("leasetime", error).toInt()/60/60);
135 if(error) 128 if(error)
@@ -138,4 +131,4 @@ void InterfaceSetupImp::setProfile(const QString &profile){
138 // IP Information 131 // IP Information
139 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 132 autoStart->setChecked(interfaces.isAuto(interface->getInterfaceName()));
140 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); 133 QString dns = interfaces.getInterfaceOption("up "DNSSCRIPT" -a", error);
141 if(dns.contains(" ")){ 134 if(dns.contains(" ")){
@@ -144,7 +137,7 @@ void InterfaceSetupImp::setProfile(const QString &profile){
144 } 137 }
145 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); 138 ipAddressEdit->setText(interfaces.getInterfaceOption("address", error));
146 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); 139 subnetMaskEdit->setText(interfaces.getInterfaceOption("netmask", error));
147 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); 140 gatewayEdit->setText(interfaces.getInterfaceOption("gateway", error));
148}
149 141
142}
150 143
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.h b/noncore/net/networksetup/interfaces/interfacesetupimp.h
index 60933aa..9ec526c 100644
--- a/noncore/net/networksetup/interfaces/interfacesetupimp.h
+++ b/noncore/net/networksetup/interfaces/interfacesetupimp.h
@@ -4,2 +4,3 @@
4#include "interfacesetup.h" 4#include "interfacesetup.h"
5#include "interfaces.h"
5#include <qdialog.h> 6#include <qdialog.h>
@@ -7,3 +8,2 @@
7class Interface; 8class Interface;
8class Interfaces;
9 9
@@ -21,3 +21,3 @@ public slots:
21private: 21private:
22 Interfaces *interfaces; 22 Interfaces interfaces;
23 Interface *interface; 23 Interface *interface;
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp
index 708f399..e49998e 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces/interfaces.cpp
@@ -6,2 +6,3 @@
6 6
7// The three stanza's
7#define AUTO "auto" 8#define AUTO "auto"
@@ -104,2 +105,3 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
104 } 105 }
106 // else see if we need to remove from this one
105 else{ 107 else{
@@ -107,6 +109,4 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
107 (*it) = (*it).replace(QRegExp(interface), ""); 109 (*it) = (*it).replace(QRegExp(interface), "");
108 // clean up 110 // if AUTO is the only thing left clear the line
109 QString line = (*it).simplifyWhiteSpace(); 111 if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO)
110 line = line.replace(QRegExp(" "),"");
111 if(line == AUTO)
112 (*it) = ""; 112 (*it) = "";
@@ -118,9 +118,5 @@ bool Interfaces::setAuto(const QString &interface, bool setAuto){
118 } 118 }
119 if(changed == false){ 119 // In the case where there is no AUTO field add one.
120 if(setAuto == true) 120 if(!changed && setAuto)
121 interfaces.append(QString(AUTO" %1").arg(interface)); 121 interfaces.append(QString(AUTO" %1").arg(interface));
122 else{
123 qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1());
124 }
125 }
126 return true; 122 return true;
@@ -159,3 +155,3 @@ bool Interfaces::isInterfaceSet(){
159bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ 155bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
160 if(acceptedFamily.contains(family)==0) 156 if(0 == acceptedFamily.contains(family))
161 return false; 157 return false;
@@ -174,4 +170,6 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c
174bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ 170bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
175 if(!setInterface(interface)) return false; 171 if(!setInterface(interface))
176 172 return false;
173
174 // Store the old interface and bump past the stanza line.
177 QStringList::Iterator it = currentIface; 175 QStringList::Iterator it = currentIface;
@@ -179,8 +177,12 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
179 177
178 // Add the new interface
180 bool error; 179 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); 180 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false; 181 if(!setInterface(newInterface))
182 return false;
183
183 QStringList::Iterator newIface = currentIface; 184 QStringList::Iterator newIface = currentIface;
184 newIface++; 185 newIface++;
185 186
187 // Copy all of the lines
186 for ( ; it != interfaces.end(); ++it ){ 188 for ( ; it != interfaces.end(); ++it ){
@@ -199,6 +201,3 @@ bool Interfaces::copyInterface(const QString &interface, const QString &newInter
199bool Interfaces::removeInterface(){ 201bool Interfaces::removeInterface(){
200 if(currentIface == interfaces.end()) 202 return removeStanza(currentIface);
201 return false;
202 (*currentIface) = "";
203 return removeAllInterfaceOptions();
204} 203}
@@ -234,6 +233,4 @@ QString Interfaces::getInterfaceFamily(bool &error){
234 QString name = getInterfaceName(error); 233 QString name = getInterfaceName(error);
235 if(error){ 234 if(error)
236 error = true;
237 return QString(); 235 return QString();
238 }
239 QString line = (*currentIface); 236 QString line = (*currentIface);
@@ -259,11 +256,7 @@ QString Interfaces::getInterfaceMethod(bool &error){
259 QString name = getInterfaceName(error); 256 QString name = getInterfaceName(error);
260 if(error){ 257 if(error)
261 error = true;
262 return QString(); 258 return QString();
263 }
264 QString family = getInterfaceFamily(error); 259 QString family = getInterfaceFamily(error);
265 if(error){ 260 if(error)
266 error = true;
267 return QString(); 261 return QString();
268 }
269 QString line = (*currentIface); 262 QString line = (*currentIface);
@@ -393,6 +386,3 @@ void Interfaces::addMapping(const QString &option){
393bool Interfaces::removeMapping(){ 386bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end()) 387 return removeStanza(currentMapping);
395 return false;
396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping);
398} 388}
@@ -522,2 +512,15 @@ bool Interfaces::setOption(const QStringList::Iterator &start, const QString &op
522} 512}
513
514/**
515 * Removes a stanza and all of its options
516 * @param stanza the stanza to remove
517 * @return bool true if successfull.
518 */
519bool Interfaces::removeStanza(QStringList::Iterator &stanza){
520 if(stanza == interfaces.end())
521 return false;
522 (*stanza) = "";
523 return removeAllOptions(stanza);
524}
525
523/** 526/**
@@ -593,3 +596,3 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
593 if(found) 596 if(found)
594 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); 597 qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
595 found = true; 598 found = true;
@@ -597,6 +600,6 @@ QString Interfaces::getOption(const QStringList::Iterator &start, const QString
597 int space = line.find(" ", option.length()); 600 int space = line.find(" ", option.length());
598 if(space != -1) 601 if(space != -1){
599 value = line.mid(space+1, line.length()); 602 value = line.mid(space+1, line.length());
600 else 603 break;
601 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); 604 }
602 } 605 }
diff --git a/noncore/settings/networksettings/interfaces/interfaces.h b/noncore/settings/networksettings/interfaces/interfaces.h
index 26abb73..5a8feb6 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.h
+++ b/noncore/settings/networksettings/interfaces/interfaces.h
@@ -30,3 +30,3 @@ public:
30 30
31 bool removeInterface(); 31 inline bool removeInterface();
32 bool addInterface(const QString &interface, const QString &family, const QString &method); 32 bool addInterface(const QString &interface, const QString &family, const QString &method);
@@ -47,3 +47,3 @@ public:
47 bool setMapping(const QString &interface); 47 bool setMapping(const QString &interface);
48 bool removeMapping(); 48 inline bool removeMapping();
49 inline void addMapping(const QString &options); 49 inline void addMapping(const QString &options);
@@ -62,2 +62,3 @@ private:
62 QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); 62 QString getOption(const QStringList::Iterator &start, const QString &option, bool &error);
63 bool removeStanza(QStringList::Iterator &stanza);
63 bool removeAllOptions(const QStringList::Iterator &start); 64 bool removeAllOptions(const QStringList::Iterator &start);
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
index 3b1a4de..4818e37 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -2,6 +2,3 @@
2#include "interface.h" 2#include "interface.h"
3#include "interfaces.h"
4 3
5#include <qdialog.h>
6#include <qcombobox.h>
7#include <qcheckbox.h> 4#include <qcheckbox.h>
@@ -14,4 +11,2 @@
14 11
15#include <assert.h>
16
17#define DNSSCRIPT "changedns" 12#define DNSSCRIPT "changedns"
@@ -19,16 +14,5 @@
19/** 14/**
20 * Constuctor. Set up the connection and load the first profile. 15 * Constuctor. Set up the connection. A profile must be set.
21 */ 16 */
22InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ 17InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i){
23 assert(parent);
24 assert(i);
25 interface = i;
26 interfaces = new Interfaces();
27 bool error = false;
28 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
29 staticGroupBox->hide();
30 dhcpCheckBox->hide();
31 leaseTime->hide();
32 leaseHoursLabel->hide();
33 }
34} 18}
@@ -41,3 +25,3 @@ bool InterfaceSetupImp::saveChanges(){
41 return false; 25 return false;
42 interfaces->write(); 26 interfaces.write();
43 return true; 27 return true;
@@ -51,3 +35,3 @@ bool InterfaceSetupImp::saveSettings(){
51 // eh can't really do anything about it other then return. :-D 35 // eh can't really do anything about it other then return. :-D
52 if(!interfaces->isInterfaceSet()) 36 if(!interfaces.isInterfaceSet())
53 return true; 37 return true;
@@ -56,4 +40,4 @@ bool InterfaceSetupImp::saveSettings(){
56 // Loopback case 40 // Loopback case
57 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 41 if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
58 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 42 interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
59 return true; 43 return true;
@@ -65,3 +49,3 @@ bool InterfaceSetupImp::saveSettings(){
65 } 49 }
66 interfaces->removeAllInterfaceOptions(); 50 interfaces.removeAllInterfaceOptions();
67 51
@@ -69,15 +53,15 @@ bool InterfaceSetupImp::saveSettings(){
69 if(dhcpCheckBox->isChecked()){ 53 if(dhcpCheckBox->isChecked()){
70 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 54 interfaces.setInterfaceMethod(INTERFACES_METHOD_DHCP);
71 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); 55 interfaces.setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
72 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); 56 interfaces.setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
73 } 57 }
74 else{ 58 else{
75 interfaces->setInterfaceMethod("static"); 59 interfaces.setInterfaceMethod("static");
76 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 60 interfaces.setInterfaceOption("address", ipAddressEdit->text());
77 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 61 interfaces.setInterfaceOption("netmask", subnetMaskEdit->text());
78 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 62 interfaces.setInterfaceOption("gateway", gatewayEdit->text());
79 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ 63 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){
80 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 64 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
81 interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); 65 interfaces.setInterfaceOption("up "DNSSCRIPT" -a ", dns);
82 interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); 66 interfaces.setInterfaceOption("down "DNSSCRIPT" -r ", dns);
83 } 67 }
@@ -86,3 +70,3 @@ bool InterfaceSetupImp::saveSettings(){
86 // IP Information 70 // IP Information
87 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 71 interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked());
88 return true; 72 return true;
@@ -92,5 +76,15 @@ bool InterfaceSetupImp::saveSettings(){
92 * The Profile has changed. 76 * The Profile has changed.
93 * @profile the new profile. 77 * @param QString profile the new profile.
94 */ 78 */
95void InterfaceSetupImp::setProfile(const QString &profile){ 79void InterfaceSetupImp::setProfile(const QString &profile){
80 /*
81 bool error = false;
82 if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){
83 staticGroupBox->hide();
84 dhcpCheckBox->hide();
85 leaseTime->hide();
86 leaseHoursLabel->hide();
87 }
88 */
89
96 QString newInterfaceName = interface->getInterfaceName(); 90 QString newInterfaceName = interface->getInterfaceName();
@@ -98,12 +92,11 @@ void InterfaceSetupImp::setProfile(const QString &profile){
98 newInterfaceName += "_" + profile; 92 newInterfaceName += "_" + profile;
99 qDebug("InterfaceSetupImp::setProfile");
100 // See if we have to make a interface. 93 // See if we have to make a interface.
101 if(!interfaces->setInterface(newInterfaceName)){ 94 if(!interfaces.setInterface(newInterfaceName)){
102 // Add making for this new interface if need too 95 // Add making for this new interface if need too
103 if(profile != ""){ 96 if(profile != ""){
104 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); 97 interfaces.copyInterface(interface->getInterfaceName(), newInterfaceName);
105 if(!interfaces->setMapping(interface->getInterfaceName())){ 98 if(!interfaces.setMapping(interface->getInterfaceName())){
106 interfaces->addMapping(interface->getInterfaceName()); 99 interfaces.addMapping(interface->getInterfaceName());
107 if(!interfaces->setMapping(interface->getInterfaceName())){ 100 if(!interfaces.setMapping(interface->getInterfaceName())){
108 qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); 101 qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface.");
109 return; 102 return;
@@ -111,9 +104,9 @@ void InterfaceSetupImp::setProfile(const QString &profile){
111 } 104 }
112 interfaces->setMap("map", newInterfaceName); 105 interfaces.setMap("map", newInterfaceName);
113 interfaces->setScript("getprofile.sh"); 106 interfaces.setScript("getprofile.sh");
114 } 107 }
115 else{ 108 else{
116 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); 109 interfaces.addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
117 if(!interfaces->setInterface(newInterfaceName)){ 110 if(!interfaces.setInterface(newInterfaceName)){
118 qDebug("InterfaceSetupImp: Added interface, but still can't set."); 111 qDebug("InterfaceSetupImp: Added interface, but still can't setInterface.");
119 return; 112 return;
@@ -127,3 +120,3 @@ void InterfaceSetupImp::setProfile(const QString &profile){
127 bool error = false; 120 bool error = false;
128 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 121 if(interfaces.getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
129 dhcpCheckBox->setChecked(true); 122 dhcpCheckBox->setChecked(true);
@@ -131,5 +124,5 @@ void InterfaceSetupImp::setProfile(const QString &profile){
131 dhcpCheckBox->setChecked(false); 124 dhcpCheckBox->setChecked(false);
132 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); 125 leaseTime->setValue(interfaces.getInterfaceOption("leasehours", error).toInt());
133 if(error) 126 if(error)
134 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); 127 leaseTime->setValue(interfaces.getInterfaceOption("leasetime", error).toInt()/60/60);
135 if(error) 128 if(error)
@@ -138,4 +131,4 @@ void InterfaceSetupImp::setProfile(const QString &profile){
138 // IP Information 131 // IP Information
139 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 132 autoStart->setChecked(interfaces.isAuto(interface->getInterfaceName()));
140 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); 133 QString dns = interfaces.getInterfaceOption("up "DNSSCRIPT" -a", error);
141 if(dns.contains(" ")){ 134 if(dns.contains(" ")){
@@ -144,7 +137,7 @@ void InterfaceSetupImp::setProfile(const QString &profile){
144 } 137 }
145 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); 138 ipAddressEdit->setText(interfaces.getInterfaceOption("address", error));
146 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); 139 subnetMaskEdit->setText(interfaces.getInterfaceOption("netmask", error));
147 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); 140 gatewayEdit->setText(interfaces.getInterfaceOption("gateway", error));
148}
149 141
142}
150 143
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.h b/noncore/settings/networksettings/interfaces/interfacesetupimp.h
index 60933aa..9ec526c 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.h
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.h
@@ -4,2 +4,3 @@
4#include "interfacesetup.h" 4#include "interfacesetup.h"
5#include "interfaces.h"
5#include <qdialog.h> 6#include <qdialog.h>
@@ -7,3 +8,2 @@
7class Interface; 8class Interface;
8class Interfaces;
9 9
@@ -21,3 +21,3 @@ public slots:
21private: 21private:
22 Interfaces *interfaces; 22 Interfaces interfaces;
23 Interface *interface; 23 Interface *interface;