summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-10-18 15:40:50 (UTC)
committer benmeyer <benmeyer>2002-10-18 15:40:50 (UTC)
commitc16dcab3fe45ae7193cbdfb2f62bf7e5482d449b (patch) (unidiff)
tree39e69706b24b032364ad4483d2f33688e7054390
parent0910b94b5b6618c84b3eb6c457c9137d63a7277f (diff)
downloadopie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.zip
opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.gz
opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.bz2
Profiles copy
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces.cpp50
-rw-r--r--noncore/net/networksetup/interfaces.h1
-rw-r--r--noncore/net/networksetup/interfacesetupimp.cpp21
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp24
-rw-r--r--noncore/settings/networksettings/interfaces.cpp50
-rw-r--r--noncore/settings/networksettings/interfaces.h1
-rw-r--r--noncore/settings/networksettings/interfacesetupimp.cpp21
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp24
8 files changed, 148 insertions, 44 deletions
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp
index eef42df..0927258 100644
--- a/noncore/net/networksetup/interfaces.cpp
+++ b/noncore/net/networksetup/interfaces.cpp
@@ -146,48 +146,74 @@ bool Interfaces::setInterface(QString interface){
146bool Interfaces::isInterfaceSet(){ 146bool Interfaces::isInterfaceSet(){
147 return (currentIface != interfaces.end()); 147 return (currentIface != interfaces.end());
148} 148}
149 149
150/** 150/**
151 * Add a new interface of with the settings - family and method 151 * Add a new interface of with the settings - family and method
152 * @param interface the name of the interface to set. All whitespace is 152 * @param interface the name of the interface to set. All whitespace is
153 * removed from the interface name. 153 * removed from the interface name.
154 * @param family the family of this interface inet or inet, ipx or inet6 154 * @param family the family of this interface inet or inet, ipx or inet6
155 * Must of one of the families defined in interfaces.h 155 * Must of one of the families defined in interfaces.h
156 * @param method for the family. see interfaces man page for family methods. 156 * @param method for the family. see interfaces man page for family methods.
157 * @return true if successfull. 157 * @return true if successfull.
158 */ 158 */
159bool Interfaces::addInterface(QString interface, QString family, QString method){ 159bool Interfaces::addInterface(QString interface, QString family, QString method){
160 if(acceptedFamily.contains(family)==0) 160 if(acceptedFamily.contains(family)==0)
161 return false; 161 return false;
162 interface = interface.simplifyWhiteSpace(); 162 interface = interface.simplifyWhiteSpace();
163 interface = interface.replace(QRegExp(" "), ""); 163 interface = interface.replace(QRegExp(" "), "");
164 interfaces.append(""); 164 interfaces.append("");
165 interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); 165 interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method));
166 return true; 166 return true;
167} 167}
168 168
169/** 169/**
170 * Copies interface with name interface to name newInterface
171 * @param newInterface name of the new interface.
172 * @return bool true if successfull
173 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){
175 if(!setInterface(interface)) return false;
176
177 QStringList::Iterator it = currentIface;
178 it++;
179
180 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false;
183 QStringList::Iterator newIface = currentIface;
184 newIface++;
185
186 for ( it; it != interfaces.end(); ++it ){
187 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
188 break;
189 newIface = interfaces.insert(newIface, *it);
190 }
191
192 return true;
193}
194
195/**
170 * Remove the currently selected interface and all of its options. 196 * Remove the currently selected interface and all of its options.
171 * @return bool if successfull or not. 197 * @return bool if successfull or not.
172 */ 198 */
173bool Interfaces::removeInterface(){ 199bool Interfaces::removeInterface(){
174 if(currentIface == interfaces.end()) 200 if(currentIface == interfaces.end())
175 return false; 201 return false;
176 (*currentIface) = ""; 202 (*currentIface) = "";
177 return removeAllInterfaceOptions(); 203 return removeAllInterfaceOptions();
178} 204}
179 205
180/** 206/**
181 * Gets the hardware name of the interface that is currently selected. 207 * Gets the hardware name of the interface that is currently selected.
182 * @return QString name of the hardware interface (eth0, usb2, wlan1...). 208 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
183 * @param error set to true if any error occurs, false otherwise. 209 * @param error set to true if any error occurs, false otherwise.
184 */ 210 */
185QString Interfaces::getInterfaceName(bool &error){ 211QString Interfaces::getInterfaceName(bool &error){
186 if(currentIface == interfaces.end()){ 212 if(currentIface == interfaces.end()){
187 error = true; 213 error = true;
188 return QString(); 214 return QString();
189 } 215 }
190 QString line = (*currentIface); 216 QString line = (*currentIface);
191 line = line.mid(QString(IFACE).length() +1, line.length()); 217 line = line.mid(QString(IFACE).length() +1, line.length());
192 line = line.simplifyWhiteSpace(); 218 line = line.simplifyWhiteSpace();
193 int findSpace = line.find(" "); 219 int findSpace = line.find(" ");
@@ -380,54 +406,68 @@ bool Interfaces::setScript(QString argument){
380} 406}
381 407
382/** 408/**
383 * @param error true if could not retrieve the current script argument. 409 * @param error true if could not retrieve the current script argument.
384 * @return QString the argument of the script for the current mapping. 410 * @return QString the argument of the script for the current mapping.
385 */ 411 */
386QString Interfaces::getScript(bool &error){ 412QString Interfaces::getScript(bool &error){
387 return getOption(currentMapping, "script", error); 413 return getOption(currentMapping, "script", error);
388} 414}
389 415
390/** 416/**
391 * Helper function used to parse through the QStringList and put pointers in 417 * Helper function used to parse through the QStringList and put pointers in
392 * the correct place. 418 * the correct place.
393 * @param stanza The stanza (auto, iface, mapping) to look for. 419 * @param stanza The stanza (auto, iface, mapping) to look for.
394 * @param option string that must be in the stanza's main line. 420 * @param option string that must be in the stanza's main line.
395 * @param interator interator to place at location of stanza if successfull. 421 * @param interator interator to place at location of stanza if successfull.
396 * @return bool true if the stanza is found. 422 * @return bool true if the stanza is found.
397 */ 423 */
398bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ 424bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
399 bool found = false; 425 bool found = false;
400 iterator = interfaces.end(); 426 iterator = interfaces.end();
401 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 427 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
402 QString line = (*it).simplifyWhiteSpace(); 428 QString line = (*it).simplifyWhiteSpace();
403 if(line.contains(stanza) && line.contains(option)){ 429 if(line.contains(stanza) && line.contains(option)){
404 if(found == true){ 430 uint point = line.find(option);
405 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); 431 bool valid = true;
432 if(point > 0){
433 // There are more chars in the line. check +1
434 if(line.at(point-1) != ' ')
435 valid = false;
436 }
437 point += option.length();
438 if(point < line.length()-1){
439 // There are more chars in the line. check -1
440 if(line.at(point) != ' ')
441 valid = false;
442 }
443 if(valid){
444 if(found == true){
445 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
446 }
447 found = true;
448 iterator = it;
406 } 449 }
407 qDebug("Found");
408 found = true;
409 iterator = it;
410 } 450 }
411 } 451 }
412 return found; 452 return found;
413} 453}
414 454
415/** 455/**
416 * Sets a value of an option in a stanza 456 * Sets a value of an option in a stanza
417 * @param start the start of the stanza 457 * @param start the start of the stanza
418 * @param option the option to use when setting value. 458 * @param option the option to use when setting value.
419 * @return bool true if successfull, false otherwise. 459 * @return bool true if successfull, false otherwise.
420 */ 460 */
421bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ 461bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){
422 if(start == interfaces.end()) 462 if(start == interfaces.end())
423 return false; 463 return false;
424 464
425 bool found = false; 465 bool found = false;
426 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 466 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
427 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 467 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
428 if(!found && value != ""){ 468 if(!found && value != ""){
429 // Got to the end of the stanza without finding it, so append it. 469 // Got to the end of the stanza without finding it, so append it.
430 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 470 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
431 } 471 }
432 found = true; 472 found = true;
433 break; 473 break;
diff --git a/noncore/net/networksetup/interfaces.h b/noncore/net/networksetup/interfaces.h
index e617c17..7cf04f0 100644
--- a/noncore/net/networksetup/interfaces.h
+++ b/noncore/net/networksetup/interfaces.h
@@ -9,48 +9,49 @@
9#define INTERFACES_FAMILY_INET "inet" 9#define INTERFACES_FAMILY_INET "inet"
10#define INTERFACES_FAMILY_IPX "ipx" 10#define INTERFACES_FAMILY_IPX "ipx"
11#define INTERFACES_FAMILY_INET6 "inet6" 11#define INTERFACES_FAMILY_INET6 "inet6"
12 12
13#define INTERFACES_METHOD_DHCP "dhcp" 13#define INTERFACES_METHOD_DHCP "dhcp"
14#define INTERFACES_METHOD_STATIC "static" 14#define INTERFACES_METHOD_STATIC "static"
15#define INTERFACES_METHOD_PPP "ppp" 15#define INTERFACES_METHOD_PPP "ppp"
16 16
17/** 17/**
18 * This class provides a clean frontend for parsing the network interfaces file. 18 * This class provides a clean frontend for parsing the network interfaces file.
19 * It provides helper functions to minipulate the options within the file. 19 * It provides helper functions to minipulate the options within the file.
20 * See the interfaces man page for the syntax rules. 20 * See the interfaces man page for the syntax rules.
21 */ 21 */
22class Interfaces { 22class Interfaces {
23 23
24public: 24public:
25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); 25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
26 QStringList getInterfaceList(); 26 QStringList getInterfaceList();
27 27
28 bool isAuto(QString interface); 28 bool isAuto(QString interface);
29 bool setAuto(QString interface, bool setAuto); 29 bool setAuto(QString interface, bool setAuto);
30 30
31 bool removeInterface(); 31 bool removeInterface();
32 bool addInterface(QString interface, QString family, QString method); 32 bool addInterface(QString interface, QString family, QString method);
33 bool copyInterface(QString oldInterface, QString newInterface);
33 bool setInterface(QString interface); 34 bool setInterface(QString interface);
34 bool isInterfaceSet(); 35 bool isInterfaceSet();
35 QString getInterfaceName(bool &error); 36 QString getInterfaceName(bool &error);
36 bool setInterfaceName(QString newName); 37 bool setInterfaceName(QString newName);
37 QString getInterfaceFamily(bool &error); 38 QString getInterfaceFamily(bool &error);
38 bool setInterfaceFamily(QString newName); 39 bool setInterfaceFamily(QString newName);
39 QString getInterfaceMethod(bool &error); 40 QString getInterfaceMethod(bool &error);
40 bool setInterfaceMethod(QString newName); 41 bool setInterfaceMethod(QString newName);
41 QString getInterfaceOption(QString option, bool &error); 42 QString getInterfaceOption(QString option, bool &error);
42 bool setInterfaceOption(QString option, QString value); 43 bool setInterfaceOption(QString option, QString value);
43 bool removeAllInterfaceOptions(); 44 bool removeAllInterfaceOptions();
44 45
45 bool setMapping(QString interface); 46 bool setMapping(QString interface);
46 void addMapping(QString options); 47 void addMapping(QString options);
47 bool setMap(QString map, QString value); 48 bool setMap(QString map, QString value);
48 QString getMap(QString map, bool &error); 49 QString getMap(QString map, bool &error);
49 bool setScript(QString); 50 bool setScript(QString);
50 QString getScript(bool &error); 51 QString getScript(bool &error);
51 52
52 bool write(); 53 bool write();
53 54
54private: 55private:
55 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); 56 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
56 bool setOption(QStringList::Iterator start, QString option, QString value); 57 bool setOption(QStringList::Iterator start, QString option, QString value);
diff --git a/noncore/net/networksetup/interfacesetupimp.cpp b/noncore/net/networksetup/interfacesetupimp.cpp
index c16d821..bdbdfde 100644
--- a/noncore/net/networksetup/interfacesetupimp.cpp
+++ b/noncore/net/networksetup/interfacesetupimp.cpp
@@ -68,68 +68,73 @@ bool InterfaceSetupImp::saveSettings(){
68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); 69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); 70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
71 } 71 }
72 else{ 72 else{
73 interfaces->setInterfaceMethod("static"); 73 interfaces->setInterfaceMethod("static");
74 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 74 interfaces->setInterfaceOption("address", ipAddressEdit->text());
75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
76 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 76 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); 78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); 79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
80 } 80 }
81 81
82 // IP Information 82 // IP Information
83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
84 return true; 84 return true;
85} 85}
86 86
87/** 87/**
88 * The Profile has changed. 88 * The Profile has changed.
89 * @profile the new profile. 89 * @profile the new profile.
90 */ 90 */
91void InterfaceSetupImp::setProfile(const QString &profile){ 91void InterfaceSetupImp::setProfile(const QString &profile){
92 QString newInterfaceName = interface->getInterfaceName() + profile; 92 QString newInterfaceName = interface->getInterfaceName();
93 93 if(profile.length() > 0)
94 newInterfaceName += "_" + profile;
95 qDebug( newInterfaceName.latin1());
94 // See if we have to make a interface. 96 // See if we have to make a interface.
95 if(!interfaces->setInterface(newInterfaceName)){ 97 if(!interfaces->setInterface(newInterfaceName)){
96 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
97 if(!interfaces->setInterface(newInterfaceName)){
98 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
99 return;
100 }
101 // Add making for this new interface if need too 98 // Add making for this new interface if need too
102 if(profile != ""){ 99 if(profile != ""){
100 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
103 if(!interfaces->setMapping(interface->getInterfaceName())){ 101 if(!interfaces->setMapping(interface->getInterfaceName())){
104 interfaces->addMapping(interface->getInterfaceName()); 102 interfaces->addMapping(interface->getInterfaceName());
105 if(!interfaces->setMapping(interface->getInterfaceName())){ 103 if(!interfaces->setMapping(interface->getInterfaceName())){
106 qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); 104 qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
107 return; 105 return;
108 } 106 }
109 } 107 }
110 interfaces->setScript("getprofile.sh");
111 interfaces->setMap("map", newInterfaceName); 108 interfaces->setMap("map", newInterfaceName);
109 interfaces->setScript("getprofile.sh");
110 }
111 else{
112 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
113 if(!interfaces->setInterface(newInterfaceName)){
114 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
115 return;
116 }
112 } 117 }
113 } 118 }
114 119
115 // We must have a valid interface to get this far so read some settings. 120 // We must have a valid interface to get this far so read some settings.
116 121
117 // DHCP 122 // DHCP
118 bool error = false; 123 bool error = false;
119 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 124 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
120 dhcpCheckBox->setChecked(true); 125 dhcpCheckBox->setChecked(true);
121 else 126 else
122 dhcpCheckBox->setChecked(false); 127 dhcpCheckBox->setChecked(false);
123 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); 128 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
124 if(error) 129 if(error)
125 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); 130 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
126 if(error) 131 if(error)
127 leaseTime->setValue(24); 132 leaseTime->setValue(24);
128 133
129 // IP Information 134 // IP Information
130 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 135 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
131 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); 136 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
132 if(dns.contains(" ")){ 137 if(dns.contains(" ")){
133 firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); 138 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
134 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); 139 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
135 } 140 }
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index 3c0af6a..9f07f0d 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -207,66 +207,66 @@ void MainWindowImp::removeClicked(){
207 } 207 }
208 } 208 }
209} 209}
210 210
211/** 211/**
212 * Pull up the configure about the currently selected interface. 212 * Pull up the configure about the currently selected interface.
213 * Report an error if no interface is selected. 213 * Report an error if no interface is selected.
214 * If the interface has a module owner then request its configure with a empty 214 * If the interface has a module owner then request its configure with a empty
215 * tab. If tab is !NULL then append the interfaces setup widget to it. 215 * tab. If tab is !NULL then append the interfaces setup widget to it.
216 */ 216 */
217void MainWindowImp::configureClicked(){ 217void MainWindowImp::configureClicked(){
218 QListViewItem *item = connectionList->currentItem(); 218 QListViewItem *item = connectionList->currentItem();
219 if(!item){ 219 if(!item){
220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
221 return; 221 return;
222 } 222 }
223 223
224 QString currentProfile = currentProfileLabel->text(); 224 QString currentProfile = currentProfileLabel->text();
225 if(profilesList->count() <= 1 || currentProfile == "All"){ 225 if(profilesList->count() <= 1 || currentProfile == "All"){
226 currentProfile = ""; 226 currentProfile = "";
227 } 227 }
228 228
229 Interface *i = interfaceItems[item]; 229 Interface *i = interfaceItems[item];
230 if(i->getModuleOwner()){ 230 if(i->getModuleOwner()){
231 i->getModuleOwner()->setProfile(currentProfileLabel->text()); 231 i->getModuleOwner()->setProfile(currentProfile);
232 QTabWidget *tabWidget = NULL; 232 QTabWidget *tabWidget = NULL;
233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
234 if(moduleConfigure != NULL){ 234 if(moduleConfigure != NULL){
235 if(tabWidget != NULL){ 235 if(tabWidget != NULL){
236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
237 configure->setProfile(currentProfileLabel->text()); 237 configure->setProfile(currentProfile);
238 tabWidget->insertTab(configure, "TCP/IP"); 238 tabWidget->insertTab(configure, "TCP/IP");
239 239
240 } 240 }
241 moduleConfigure->showMaximized(); 241 moduleConfigure->showMaximized();
242 moduleConfigure->show(); 242 moduleConfigure->show();
243 return; 243 return;
244 } 244 }
245 } 245 }
246 246
247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
248 configure->setProfile(currentProfileLabel->text()); 248 configure->setProfile(currentProfile);
249 configure->showMaximized(); 249 configure->showMaximized();
250 configure->show(); 250 configure->show();
251} 251}
252 252
253/** 253/**
254 * Pull up the information about the currently selected interface. 254 * Pull up the information about the currently selected interface.
255 * Report an error if no interface is selected. 255 * Report an error if no interface is selected.
256 * If the interface has a module owner then request its configure with a empty 256 * If the interface has a module owner then request its configure with a empty
257 * tab. If tab is !NULL then append the interfaces setup widget to it. 257 * tab. If tab is !NULL then append the interfaces setup widget to it.
258 */ 258 */
259void MainWindowImp::informationClicked(){ 259void MainWindowImp::informationClicked(){
260 QListViewItem *item = connectionList->currentItem(); 260 QListViewItem *item = connectionList->currentItem();
261 if(!item){ 261 if(!item){
262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
263 return; 263 return;
264 } 264 }
265 265
266 Interface *i = interfaceItems[item]; 266 Interface *i = interfaceItems[item];
267 if(!i->isAttached()){ 267 if(!i->isAttached()){
268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); 268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok);
269 return; 269 return;
270 } 270 }
271 271
272 QStringList list; 272 QStringList list;
@@ -356,54 +356,56 @@ void MainWindowImp::jobDone(KProcess *process){
356 updateInterface(i); 356 updateInterface(i);
357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
358 } 358 }
359 // It was an interface we already had. 359 // It was an interface we already had.
360 else{ 360 else{
361 if(fileName != TEMP_ALL) 361 if(fileName != TEMP_ALL)
362 (interfaceNames[interfaceName])->setStatus(true); 362 (interfaceNames[interfaceName])->setStatus(true);
363 } 363 }
364 } 364 }
365 } 365 }
366 file.close(); 366 file.close();
367 QFile::remove(fileName); 367 QFile::remove(fileName);
368 368
369 if(threads.count() == 0){ 369 if(threads.count() == 0){
370 Interfaces i; 370 Interfaces i;
371 QStringList list = i.getInterfaceList(); 371 QStringList list = i.getInterfaceList();
372 QMap<QString, Interface*>::Iterator it; 372 QMap<QString, Interface*>::Iterator it;
373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
374 bool found = false; 374 bool found = false;
375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
376 if(it.key() == (*ni)) 376 if(it.key() == (*ni))
377 found = true; 377 found = true;
378 } 378 }
379 if(!found){ 379 if(!found){
380 Interface *i = new Interface(this, *ni, false); 380 if(!(*ni).contains("_")){
381 i->setAttached(false); 381 Interface *i = new Interface(this, *ni, false);
382 i->setHardwareName("Disconnected"); 382 i->setAttached(false);
383 interfaceNames.insert(i->getInterfaceName(), i); 383 i->setHardwareName("Disconnected");
384 updateInterface(i); 384 interfaceNames.insert(i->getInterfaceName(), i);
385 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 385 updateInterface(i);
386 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
387 }
386 } 388 }
387 } 389 }
388 } 390 }
389} 391}
390 392
391/** 393/**
392 * Update this interface. If no QListViewItem exists create one. 394 * Update this interface. If no QListViewItem exists create one.
393 * @param Interface* pointer to the interface that needs to be updated. 395 * @param Interface* pointer to the interface that needs to be updated.
394 */ 396 */
395void MainWindowImp::updateInterface(Interface *i){ 397void MainWindowImp::updateInterface(Interface *i){
396 if(!advancedUserMode){ 398 if(!advancedUserMode){
397 if(i->getInterfaceName() == "lo") 399 if(i->getInterfaceName() == "lo")
398 return; 400 return;
399 } 401 }
400 402
401 QListViewItem *item = NULL; 403 QListViewItem *item = NULL;
402 404
403 // Find the interface, making it if needed. 405 // Find the interface, making it if needed.
404 if(items.find(i) == items.end()){ 406 if(items.find(i) == items.end()){
405 item = new QListViewItem(connectionList, "", "", ""); 407 item = new QListViewItem(connectionList, "", "", "");
406 // See if you can't find a module owner for this interface 408 // See if you can't find a module owner for this interface
407 QMap<Module*, QLibrary*>::Iterator it; 409 QMap<Module*, QLibrary*>::Iterator it;
408 for( it = libraries.begin(); it != libraries.end(); ++it ){ 410 for( it = libraries.begin(); it != libraries.end(); ++it ){
409 if(it.key()->isOwner(i)) 411 if(it.key()->isOwner(i))
@@ -468,58 +470,62 @@ void MainWindowImp::addProfile(){
468 */ 470 */
469void MainWindowImp::removeProfile(){ 471void MainWindowImp::removeProfile(){
470 if(profilesList->count() <= 1){ 472 if(profilesList->count() <= 1){
471 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); 473 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok");
472 return; 474 return;
473 } 475 }
474 QString profileToRemove = profilesList->currentText(); 476 QString profileToRemove = profilesList->currentText();
475 if(profileToRemove == "All"){ 477 if(profileToRemove == "All"){
476 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); 478 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok");
477 return; 479 return;
478 } 480 }
479 // Can't remove the curent profile 481 // Can't remove the curent profile
480 if(profileToRemove == currentProfileLabel->text()){ 482 if(profileToRemove == currentProfileLabel->text()){
481 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); 483 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok");
482 return; 484 return;
483 485
484 } 486 }
485 487
486 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 488 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
487 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 489 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
488 profilesList->clear(); 490 profilesList->clear();
489 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 491 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
490 profilesList->insertItem((*it)); 492 profilesList->insertItem((*it));
491 } 493 }
494
495 // Remove any interface settings and mappings.
496 //TODO
492} 497}
493 498
494/** 499/**
495 * A new profile has been selected, change. 500 * A new profile has been selected, change.
496 * @param newProfile the new profile. 501 * @param newProfile the new profile.
497 */ 502 */
498void MainWindowImp::changeProfile(){ 503void MainWindowImp::changeProfile(){
499 if(profilesList->currentItem() == -1){ 504 if(profilesList->currentItem() == -1){
500 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); 505 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok");
501 return; 506 return;
502 } 507 }
503 QString newProfile = profilesList->text(profilesList->currentItem()); 508 QString newProfile = profilesList->text(profilesList->currentItem());
504 if(newProfile != currentProfileLabel->text()){ 509 if(newProfile != currentProfileLabel->text()){
505 currentProfileLabel->setText(newProfile); 510 currentProfileLabel->setText(newProfile);
511 QFile::remove(SCHEME);
506 QFile file(SCHEME); 512 QFile file(SCHEME);
507 if ( file.open(IO_ReadWrite) ) { 513 if ( file.open(IO_ReadWrite) ) {
508 QTextStream stream( &file ); 514 QTextStream stream( &file );
509 stream << QString("SCHEME=%1").arg(newProfile); 515 stream << QString("SCHEME=%1").arg(newProfile);
510 file.close(); 516 file.close();
511 } 517 }
512 // restart all up devices? 518 // restart all up devices?
513 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 519 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
514 // Go through them one by one 520 // Go through them one by one
515 QMap<Interface*, QListViewItem*>::Iterator it; 521 QMap<Interface*, QListViewItem*>::Iterator it;
516 for( it = items.begin(); it != items.end(); ++it ){ 522 for( it = items.begin(); it != items.end(); ++it ){
517 if(it.key()->getStatus() == true) 523 if(it.key()->getStatus() == true)
518 it.key()->restart(); 524 it.key()->restart();
519 } 525 }
520 } 526 }
521 } 527 }
522} 528}
523 529
524// mainwindowimp.cpp 530// mainwindowimp.cpp
525 531
diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp
index eef42df..0927258 100644
--- a/noncore/settings/networksettings/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces.cpp
@@ -146,48 +146,74 @@ bool Interfaces::setInterface(QString interface){
146bool Interfaces::isInterfaceSet(){ 146bool Interfaces::isInterfaceSet(){
147 return (currentIface != interfaces.end()); 147 return (currentIface != interfaces.end());
148} 148}
149 149
150/** 150/**
151 * Add a new interface of with the settings - family and method 151 * Add a new interface of with the settings - family and method
152 * @param interface the name of the interface to set. All whitespace is 152 * @param interface the name of the interface to set. All whitespace is
153 * removed from the interface name. 153 * removed from the interface name.
154 * @param family the family of this interface inet or inet, ipx or inet6 154 * @param family the family of this interface inet or inet, ipx or inet6
155 * Must of one of the families defined in interfaces.h 155 * Must of one of the families defined in interfaces.h
156 * @param method for the family. see interfaces man page for family methods. 156 * @param method for the family. see interfaces man page for family methods.
157 * @return true if successfull. 157 * @return true if successfull.
158 */ 158 */
159bool Interfaces::addInterface(QString interface, QString family, QString method){ 159bool Interfaces::addInterface(QString interface, QString family, QString method){
160 if(acceptedFamily.contains(family)==0) 160 if(acceptedFamily.contains(family)==0)
161 return false; 161 return false;
162 interface = interface.simplifyWhiteSpace(); 162 interface = interface.simplifyWhiteSpace();
163 interface = interface.replace(QRegExp(" "), ""); 163 interface = interface.replace(QRegExp(" "), "");
164 interfaces.append(""); 164 interfaces.append("");
165 interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); 165 interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method));
166 return true; 166 return true;
167} 167}
168 168
169/** 169/**
170 * Copies interface with name interface to name newInterface
171 * @param newInterface name of the new interface.
172 * @return bool true if successfull
173 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){
175 if(!setInterface(interface)) return false;
176
177 QStringList::Iterator it = currentIface;
178 it++;
179
180 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false;
183 QStringList::Iterator newIface = currentIface;
184 newIface++;
185
186 for ( it; it != interfaces.end(); ++it ){
187 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
188 break;
189 newIface = interfaces.insert(newIface, *it);
190 }
191
192 return true;
193}
194
195/**
170 * Remove the currently selected interface and all of its options. 196 * Remove the currently selected interface and all of its options.
171 * @return bool if successfull or not. 197 * @return bool if successfull or not.
172 */ 198 */
173bool Interfaces::removeInterface(){ 199bool Interfaces::removeInterface(){
174 if(currentIface == interfaces.end()) 200 if(currentIface == interfaces.end())
175 return false; 201 return false;
176 (*currentIface) = ""; 202 (*currentIface) = "";
177 return removeAllInterfaceOptions(); 203 return removeAllInterfaceOptions();
178} 204}
179 205
180/** 206/**
181 * Gets the hardware name of the interface that is currently selected. 207 * Gets the hardware name of the interface that is currently selected.
182 * @return QString name of the hardware interface (eth0, usb2, wlan1...). 208 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
183 * @param error set to true if any error occurs, false otherwise. 209 * @param error set to true if any error occurs, false otherwise.
184 */ 210 */
185QString Interfaces::getInterfaceName(bool &error){ 211QString Interfaces::getInterfaceName(bool &error){
186 if(currentIface == interfaces.end()){ 212 if(currentIface == interfaces.end()){
187 error = true; 213 error = true;
188 return QString(); 214 return QString();
189 } 215 }
190 QString line = (*currentIface); 216 QString line = (*currentIface);
191 line = line.mid(QString(IFACE).length() +1, line.length()); 217 line = line.mid(QString(IFACE).length() +1, line.length());
192 line = line.simplifyWhiteSpace(); 218 line = line.simplifyWhiteSpace();
193 int findSpace = line.find(" "); 219 int findSpace = line.find(" ");
@@ -380,54 +406,68 @@ bool Interfaces::setScript(QString argument){
380} 406}
381 407
382/** 408/**
383 * @param error true if could not retrieve the current script argument. 409 * @param error true if could not retrieve the current script argument.
384 * @return QString the argument of the script for the current mapping. 410 * @return QString the argument of the script for the current mapping.
385 */ 411 */
386QString Interfaces::getScript(bool &error){ 412QString Interfaces::getScript(bool &error){
387 return getOption(currentMapping, "script", error); 413 return getOption(currentMapping, "script", error);
388} 414}
389 415
390/** 416/**
391 * Helper function used to parse through the QStringList and put pointers in 417 * Helper function used to parse through the QStringList and put pointers in
392 * the correct place. 418 * the correct place.
393 * @param stanza The stanza (auto, iface, mapping) to look for. 419 * @param stanza The stanza (auto, iface, mapping) to look for.
394 * @param option string that must be in the stanza's main line. 420 * @param option string that must be in the stanza's main line.
395 * @param interator interator to place at location of stanza if successfull. 421 * @param interator interator to place at location of stanza if successfull.
396 * @return bool true if the stanza is found. 422 * @return bool true if the stanza is found.
397 */ 423 */
398bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ 424bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
399 bool found = false; 425 bool found = false;
400 iterator = interfaces.end(); 426 iterator = interfaces.end();
401 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 427 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
402 QString line = (*it).simplifyWhiteSpace(); 428 QString line = (*it).simplifyWhiteSpace();
403 if(line.contains(stanza) && line.contains(option)){ 429 if(line.contains(stanza) && line.contains(option)){
404 if(found == true){ 430 uint point = line.find(option);
405 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); 431 bool valid = true;
432 if(point > 0){
433 // There are more chars in the line. check +1
434 if(line.at(point-1) != ' ')
435 valid = false;
436 }
437 point += option.length();
438 if(point < line.length()-1){
439 // There are more chars in the line. check -1
440 if(line.at(point) != ' ')
441 valid = false;
442 }
443 if(valid){
444 if(found == true){
445 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
446 }
447 found = true;
448 iterator = it;
406 } 449 }
407 qDebug("Found");
408 found = true;
409 iterator = it;
410 } 450 }
411 } 451 }
412 return found; 452 return found;
413} 453}
414 454
415/** 455/**
416 * Sets a value of an option in a stanza 456 * Sets a value of an option in a stanza
417 * @param start the start of the stanza 457 * @param start the start of the stanza
418 * @param option the option to use when setting value. 458 * @param option the option to use when setting value.
419 * @return bool true if successfull, false otherwise. 459 * @return bool true if successfull, false otherwise.
420 */ 460 */
421bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ 461bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){
422 if(start == interfaces.end()) 462 if(start == interfaces.end())
423 return false; 463 return false;
424 464
425 bool found = false; 465 bool found = false;
426 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 466 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
427 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 467 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
428 if(!found && value != ""){ 468 if(!found && value != ""){
429 // Got to the end of the stanza without finding it, so append it. 469 // Got to the end of the stanza without finding it, so append it.
430 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 470 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
431 } 471 }
432 found = true; 472 found = true;
433 break; 473 break;
diff --git a/noncore/settings/networksettings/interfaces.h b/noncore/settings/networksettings/interfaces.h
index e617c17..7cf04f0 100644
--- a/noncore/settings/networksettings/interfaces.h
+++ b/noncore/settings/networksettings/interfaces.h
@@ -9,48 +9,49 @@
9#define INTERFACES_FAMILY_INET "inet" 9#define INTERFACES_FAMILY_INET "inet"
10#define INTERFACES_FAMILY_IPX "ipx" 10#define INTERFACES_FAMILY_IPX "ipx"
11#define INTERFACES_FAMILY_INET6 "inet6" 11#define INTERFACES_FAMILY_INET6 "inet6"
12 12
13#define INTERFACES_METHOD_DHCP "dhcp" 13#define INTERFACES_METHOD_DHCP "dhcp"
14#define INTERFACES_METHOD_STATIC "static" 14#define INTERFACES_METHOD_STATIC "static"
15#define INTERFACES_METHOD_PPP "ppp" 15#define INTERFACES_METHOD_PPP "ppp"
16 16
17/** 17/**
18 * This class provides a clean frontend for parsing the network interfaces file. 18 * This class provides a clean frontend for parsing the network interfaces file.
19 * It provides helper functions to minipulate the options within the file. 19 * It provides helper functions to minipulate the options within the file.
20 * See the interfaces man page for the syntax rules. 20 * See the interfaces man page for the syntax rules.
21 */ 21 */
22class Interfaces { 22class Interfaces {
23 23
24public: 24public:
25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); 25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
26 QStringList getInterfaceList(); 26 QStringList getInterfaceList();
27 27
28 bool isAuto(QString interface); 28 bool isAuto(QString interface);
29 bool setAuto(QString interface, bool setAuto); 29 bool setAuto(QString interface, bool setAuto);
30 30
31 bool removeInterface(); 31 bool removeInterface();
32 bool addInterface(QString interface, QString family, QString method); 32 bool addInterface(QString interface, QString family, QString method);
33 bool copyInterface(QString oldInterface, QString newInterface);
33 bool setInterface(QString interface); 34 bool setInterface(QString interface);
34 bool isInterfaceSet(); 35 bool isInterfaceSet();
35 QString getInterfaceName(bool &error); 36 QString getInterfaceName(bool &error);
36 bool setInterfaceName(QString newName); 37 bool setInterfaceName(QString newName);
37 QString getInterfaceFamily(bool &error); 38 QString getInterfaceFamily(bool &error);
38 bool setInterfaceFamily(QString newName); 39 bool setInterfaceFamily(QString newName);
39 QString getInterfaceMethod(bool &error); 40 QString getInterfaceMethod(bool &error);
40 bool setInterfaceMethod(QString newName); 41 bool setInterfaceMethod(QString newName);
41 QString getInterfaceOption(QString option, bool &error); 42 QString getInterfaceOption(QString option, bool &error);
42 bool setInterfaceOption(QString option, QString value); 43 bool setInterfaceOption(QString option, QString value);
43 bool removeAllInterfaceOptions(); 44 bool removeAllInterfaceOptions();
44 45
45 bool setMapping(QString interface); 46 bool setMapping(QString interface);
46 void addMapping(QString options); 47 void addMapping(QString options);
47 bool setMap(QString map, QString value); 48 bool setMap(QString map, QString value);
48 QString getMap(QString map, bool &error); 49 QString getMap(QString map, bool &error);
49 bool setScript(QString); 50 bool setScript(QString);
50 QString getScript(bool &error); 51 QString getScript(bool &error);
51 52
52 bool write(); 53 bool write();
53 54
54private: 55private:
55 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); 56 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
56 bool setOption(QStringList::Iterator start, QString option, QString value); 57 bool setOption(QStringList::Iterator start, QString option, QString value);
diff --git a/noncore/settings/networksettings/interfacesetupimp.cpp b/noncore/settings/networksettings/interfacesetupimp.cpp
index c16d821..bdbdfde 100644
--- a/noncore/settings/networksettings/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfacesetupimp.cpp
@@ -68,68 +68,73 @@ bool InterfaceSetupImp::saveSettings(){
68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 68 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); 69 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); 70 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
71 } 71 }
72 else{ 72 else{
73 interfaces->setInterfaceMethod("static"); 73 interfaces->setInterfaceMethod("static");
74 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 74 interfaces->setInterfaceOption("address", ipAddressEdit->text());
75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 75 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
76 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 76 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 77 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); 78 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); 79 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
80 } 80 }
81 81
82 // IP Information 82 // IP Information
83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 83 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
84 return true; 84 return true;
85} 85}
86 86
87/** 87/**
88 * The Profile has changed. 88 * The Profile has changed.
89 * @profile the new profile. 89 * @profile the new profile.
90 */ 90 */
91void InterfaceSetupImp::setProfile(const QString &profile){ 91void InterfaceSetupImp::setProfile(const QString &profile){
92 QString newInterfaceName = interface->getInterfaceName() + profile; 92 QString newInterfaceName = interface->getInterfaceName();
93 93 if(profile.length() > 0)
94 newInterfaceName += "_" + profile;
95 qDebug( newInterfaceName.latin1());
94 // See if we have to make a interface. 96 // See if we have to make a interface.
95 if(!interfaces->setInterface(newInterfaceName)){ 97 if(!interfaces->setInterface(newInterfaceName)){
96 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
97 if(!interfaces->setInterface(newInterfaceName)){
98 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
99 return;
100 }
101 // Add making for this new interface if need too 98 // Add making for this new interface if need too
102 if(profile != ""){ 99 if(profile != ""){
100 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
103 if(!interfaces->setMapping(interface->getInterfaceName())){ 101 if(!interfaces->setMapping(interface->getInterfaceName())){
104 interfaces->addMapping(interface->getInterfaceName()); 102 interfaces->addMapping(interface->getInterfaceName());
105 if(!interfaces->setMapping(interface->getInterfaceName())){ 103 if(!interfaces->setMapping(interface->getInterfaceName())){
106 qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); 104 qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
107 return; 105 return;
108 } 106 }
109 } 107 }
110 interfaces->setScript("getprofile.sh");
111 interfaces->setMap("map", newInterfaceName); 108 interfaces->setMap("map", newInterfaceName);
109 interfaces->setScript("getprofile.sh");
110 }
111 else{
112 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
113 if(!interfaces->setInterface(newInterfaceName)){
114 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
115 return;
116 }
112 } 117 }
113 } 118 }
114 119
115 // We must have a valid interface to get this far so read some settings. 120 // We must have a valid interface to get this far so read some settings.
116 121
117 // DHCP 122 // DHCP
118 bool error = false; 123 bool error = false;
119 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 124 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
120 dhcpCheckBox->setChecked(true); 125 dhcpCheckBox->setChecked(true);
121 else 126 else
122 dhcpCheckBox->setChecked(false); 127 dhcpCheckBox->setChecked(false);
123 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); 128 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
124 if(error) 129 if(error)
125 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); 130 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
126 if(error) 131 if(error)
127 leaseTime->setValue(24); 132 leaseTime->setValue(24);
128 133
129 // IP Information 134 // IP Information
130 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 135 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
131 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); 136 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
132 if(dns.contains(" ")){ 137 if(dns.contains(" ")){
133 firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); 138 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
134 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); 139 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
135 } 140 }
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 3c0af6a..9f07f0d 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -207,66 +207,66 @@ void MainWindowImp::removeClicked(){
207 } 207 }
208 } 208 }
209} 209}
210 210
211/** 211/**
212 * Pull up the configure about the currently selected interface. 212 * Pull up the configure about the currently selected interface.
213 * Report an error if no interface is selected. 213 * Report an error if no interface is selected.
214 * If the interface has a module owner then request its configure with a empty 214 * If the interface has a module owner then request its configure with a empty
215 * tab. If tab is !NULL then append the interfaces setup widget to it. 215 * tab. If tab is !NULL then append the interfaces setup widget to it.
216 */ 216 */
217void MainWindowImp::configureClicked(){ 217void MainWindowImp::configureClicked(){
218 QListViewItem *item = connectionList->currentItem(); 218 QListViewItem *item = connectionList->currentItem();
219 if(!item){ 219 if(!item){
220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
221 return; 221 return;
222 } 222 }
223 223
224 QString currentProfile = currentProfileLabel->text(); 224 QString currentProfile = currentProfileLabel->text();
225 if(profilesList->count() <= 1 || currentProfile == "All"){ 225 if(profilesList->count() <= 1 || currentProfile == "All"){
226 currentProfile = ""; 226 currentProfile = "";
227 } 227 }
228 228
229 Interface *i = interfaceItems[item]; 229 Interface *i = interfaceItems[item];
230 if(i->getModuleOwner()){ 230 if(i->getModuleOwner()){
231 i->getModuleOwner()->setProfile(currentProfileLabel->text()); 231 i->getModuleOwner()->setProfile(currentProfile);
232 QTabWidget *tabWidget = NULL; 232 QTabWidget *tabWidget = NULL;
233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
234 if(moduleConfigure != NULL){ 234 if(moduleConfigure != NULL){
235 if(tabWidget != NULL){ 235 if(tabWidget != NULL){
236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
237 configure->setProfile(currentProfileLabel->text()); 237 configure->setProfile(currentProfile);
238 tabWidget->insertTab(configure, "TCP/IP"); 238 tabWidget->insertTab(configure, "TCP/IP");
239 239
240 } 240 }
241 moduleConfigure->showMaximized(); 241 moduleConfigure->showMaximized();
242 moduleConfigure->show(); 242 moduleConfigure->show();
243 return; 243 return;
244 } 244 }
245 } 245 }
246 246
247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
248 configure->setProfile(currentProfileLabel->text()); 248 configure->setProfile(currentProfile);
249 configure->showMaximized(); 249 configure->showMaximized();
250 configure->show(); 250 configure->show();
251} 251}
252 252
253/** 253/**
254 * Pull up the information about the currently selected interface. 254 * Pull up the information about the currently selected interface.
255 * Report an error if no interface is selected. 255 * Report an error if no interface is selected.
256 * If the interface has a module owner then request its configure with a empty 256 * If the interface has a module owner then request its configure with a empty
257 * tab. If tab is !NULL then append the interfaces setup widget to it. 257 * tab. If tab is !NULL then append the interfaces setup widget to it.
258 */ 258 */
259void MainWindowImp::informationClicked(){ 259void MainWindowImp::informationClicked(){
260 QListViewItem *item = connectionList->currentItem(); 260 QListViewItem *item = connectionList->currentItem();
261 if(!item){ 261 if(!item){
262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
263 return; 263 return;
264 } 264 }
265 265
266 Interface *i = interfaceItems[item]; 266 Interface *i = interfaceItems[item];
267 if(!i->isAttached()){ 267 if(!i->isAttached()){
268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); 268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok);
269 return; 269 return;
270 } 270 }
271 271
272 QStringList list; 272 QStringList list;
@@ -356,54 +356,56 @@ void MainWindowImp::jobDone(KProcess *process){
356 updateInterface(i); 356 updateInterface(i);
357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
358 } 358 }
359 // It was an interface we already had. 359 // It was an interface we already had.
360 else{ 360 else{
361 if(fileName != TEMP_ALL) 361 if(fileName != TEMP_ALL)
362 (interfaceNames[interfaceName])->setStatus(true); 362 (interfaceNames[interfaceName])->setStatus(true);
363 } 363 }
364 } 364 }
365 } 365 }
366 file.close(); 366 file.close();
367 QFile::remove(fileName); 367 QFile::remove(fileName);
368 368
369 if(threads.count() == 0){ 369 if(threads.count() == 0){
370 Interfaces i; 370 Interfaces i;
371 QStringList list = i.getInterfaceList(); 371 QStringList list = i.getInterfaceList();
372 QMap<QString, Interface*>::Iterator it; 372 QMap<QString, Interface*>::Iterator it;
373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
374 bool found = false; 374 bool found = false;
375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
376 if(it.key() == (*ni)) 376 if(it.key() == (*ni))
377 found = true; 377 found = true;
378 } 378 }
379 if(!found){ 379 if(!found){
380 Interface *i = new Interface(this, *ni, false); 380 if(!(*ni).contains("_")){
381 i->setAttached(false); 381 Interface *i = new Interface(this, *ni, false);
382 i->setHardwareName("Disconnected"); 382 i->setAttached(false);
383 interfaceNames.insert(i->getInterfaceName(), i); 383 i->setHardwareName("Disconnected");
384 updateInterface(i); 384 interfaceNames.insert(i->getInterfaceName(), i);
385 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 385 updateInterface(i);
386 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
387 }
386 } 388 }
387 } 389 }
388 } 390 }
389} 391}
390 392
391/** 393/**
392 * Update this interface. If no QListViewItem exists create one. 394 * Update this interface. If no QListViewItem exists create one.
393 * @param Interface* pointer to the interface that needs to be updated. 395 * @param Interface* pointer to the interface that needs to be updated.
394 */ 396 */
395void MainWindowImp::updateInterface(Interface *i){ 397void MainWindowImp::updateInterface(Interface *i){
396 if(!advancedUserMode){ 398 if(!advancedUserMode){
397 if(i->getInterfaceName() == "lo") 399 if(i->getInterfaceName() == "lo")
398 return; 400 return;
399 } 401 }
400 402
401 QListViewItem *item = NULL; 403 QListViewItem *item = NULL;
402 404
403 // Find the interface, making it if needed. 405 // Find the interface, making it if needed.
404 if(items.find(i) == items.end()){ 406 if(items.find(i) == items.end()){
405 item = new QListViewItem(connectionList, "", "", ""); 407 item = new QListViewItem(connectionList, "", "", "");
406 // See if you can't find a module owner for this interface 408 // See if you can't find a module owner for this interface
407 QMap<Module*, QLibrary*>::Iterator it; 409 QMap<Module*, QLibrary*>::Iterator it;
408 for( it = libraries.begin(); it != libraries.end(); ++it ){ 410 for( it = libraries.begin(); it != libraries.end(); ++it ){
409 if(it.key()->isOwner(i)) 411 if(it.key()->isOwner(i))
@@ -468,58 +470,62 @@ void MainWindowImp::addProfile(){
468 */ 470 */
469void MainWindowImp::removeProfile(){ 471void MainWindowImp::removeProfile(){
470 if(profilesList->count() <= 1){ 472 if(profilesList->count() <= 1){
471 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); 473 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok");
472 return; 474 return;
473 } 475 }
474 QString profileToRemove = profilesList->currentText(); 476 QString profileToRemove = profilesList->currentText();
475 if(profileToRemove == "All"){ 477 if(profileToRemove == "All"){
476 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); 478 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok");
477 return; 479 return;
478 } 480 }
479 // Can't remove the curent profile 481 // Can't remove the curent profile
480 if(profileToRemove == currentProfileLabel->text()){ 482 if(profileToRemove == currentProfileLabel->text()){
481 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); 483 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok");
482 return; 484 return;
483 485
484 } 486 }
485 487
486 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 488 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
487 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 489 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
488 profilesList->clear(); 490 profilesList->clear();
489 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 491 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
490 profilesList->insertItem((*it)); 492 profilesList->insertItem((*it));
491 } 493 }
494
495 // Remove any interface settings and mappings.
496 //TODO
492} 497}
493 498
494/** 499/**
495 * A new profile has been selected, change. 500 * A new profile has been selected, change.
496 * @param newProfile the new profile. 501 * @param newProfile the new profile.
497 */ 502 */
498void MainWindowImp::changeProfile(){ 503void MainWindowImp::changeProfile(){
499 if(profilesList->currentItem() == -1){ 504 if(profilesList->currentItem() == -1){
500 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); 505 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok");
501 return; 506 return;
502 } 507 }
503 QString newProfile = profilesList->text(profilesList->currentItem()); 508 QString newProfile = profilesList->text(profilesList->currentItem());
504 if(newProfile != currentProfileLabel->text()){ 509 if(newProfile != currentProfileLabel->text()){
505 currentProfileLabel->setText(newProfile); 510 currentProfileLabel->setText(newProfile);
511 QFile::remove(SCHEME);
506 QFile file(SCHEME); 512 QFile file(SCHEME);
507 if ( file.open(IO_ReadWrite) ) { 513 if ( file.open(IO_ReadWrite) ) {
508 QTextStream stream( &file ); 514 QTextStream stream( &file );
509 stream << QString("SCHEME=%1").arg(newProfile); 515 stream << QString("SCHEME=%1").arg(newProfile);
510 file.close(); 516 file.close();
511 } 517 }
512 // restart all up devices? 518 // restart all up devices?
513 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 519 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
514 // Go through them one by one 520 // Go through them one by one
515 QMap<Interface*, QListViewItem*>::Iterator it; 521 QMap<Interface*, QListViewItem*>::Iterator it;
516 for( it = items.begin(); it != items.end(); ++it ){ 522 for( it = items.begin(); it != items.end(); ++it ){
517 if(it.key()->getStatus() == true) 523 if(it.key()->getStatus() == true)
518 it.key()->restart(); 524 it.key()->restart();
519 } 525 }
520 } 526 }
521 } 527 }
522} 528}
523 529
524// mainwindowimp.cpp 530// mainwindowimp.cpp
525 531