summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp57
1 files changed, 52 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
index fc65c5f..8d78828 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -1,115 +1,158 @@
1#include "interfacesetupimp.h" 1#include "interfacesetupimp.h"
2#include "interface.h" 2#include "interface.h"
3 3
4#include <qcheckbox.h> 4#include <qcheckbox.h>
5#include <qlineedit.h> 5#include <qlineedit.h>
6#include <qspinbox.h> 6#include <qspinbox.h>
7#include <qgroupbox.h> 7#include <qgroupbox.h>
8#include <qlabel.h> 8#include <qlabel.h>
9 9
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11 11
12#include <opie/oprocess.h>
13
14#ifdef QWS
15#include <opie/owait.h>
16#include <qpe/global.h>
17#include <qapplication.h>
18#endif
19
12#define DNSSCRIPT "changedns" 20#define DNSSCRIPT "changedns"
13 21
14/** 22/**
15 * Constuctor. Set up the connection. A profile must be set. 23 * Constuctor. Set up the connection. A profile must be set.
16 */ 24 */
17InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, Interfaces *j, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i), interfaces(j), delInterfaces(false){ 25InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, Interfaces *j, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i), interfaces(j), delInterfaces(false){
18 if (j == 0) { 26 if (j == 0) {
19 delInterfaces = true; 27 delInterfaces = true;
20 interfaces = new Interfaces; 28 interfaces = new Interfaces;
21 } 29 }
22} 30}
23 31
24/** 32/**
25 * Destructor 33 * Destructor
26 */ 34 */
27InterfaceSetupImp::~InterfaceSetupImp(){ 35InterfaceSetupImp::~InterfaceSetupImp(){
28 if(delInterfaces) { 36 if(delInterfaces) {
29 delete interfaces; 37 delete interfaces;
30 } 38 }
31} 39}
32 40
33/** 41/**
34 * Save the current settings, then write out the interfaces file and close. 42 * Save the current settings, then write out the interfaces file and close.
35 */ 43 */
36bool InterfaceSetupImp::saveChanges(){ 44bool InterfaceSetupImp::saveChanges(){
45 bool error;
46 QString iface = interfaces->getInterfaceName(error);
37 if(!saveSettings()) 47 if(!saveSettings())
38 return false; 48 return false;
49
50 qWarning("restarting interface %s\n", iface.latin1());
39 interfaces->write(); 51 interfaces->write();
52
53 QString ifup;
54 ifup += "ifdown ";
55 ifup += iface;
56 ifup += "; ifup ";
57 ifup += iface;
58 ifup += ";";
59
60 OProcess restart;
61 restart << "sh";
62 restart << "-c";
63 restart << ifup;
64
65 OWait *owait = new OWait();
66 Global::statusMessage( tr( "Restarting interface" ) );
67
68 owait->show();
69 qApp->processEvents();
70
71 if (!restart.start(OProcess::Block, OProcess::NoCommunication) ) {
72 qWarning("unstable to spawn ifdown/ifup");
73 }
74
75 owait->hide();
76 delete owait;
77
78 interface->refresh();
79
40 return true; 80 return true;
41} 81}
42 82
43/** 83/**
44 * Save the settings for the current Interface. 84 * Save the settings for the current Interface.
45 * @return bool true if successfull, false otherwise 85 * @return bool true if successfull, false otherwise
46 */ 86 */
47bool InterfaceSetupImp::saveSettings(){ 87bool InterfaceSetupImp::saveSettings(){
48 // eh can't really do anything about it other then return. :-D 88 // eh can't really do anything about it other then return. :-D
49 if(!interfaces->isInterfaceSet()) 89 if(!interfaces->isInterfaceSet())
50 return true; 90 return true;
51 91
52 bool error = false; 92 bool error = false;
53 // Loopback case 93 // Loopback case
54 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 94 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
55 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 95 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
56 return true; 96 return true;
57 } 97 }
58 98
59 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ 99 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){
60 QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); 100 QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok);
61 return false; 101 return false;
62 } 102 }
63 //interfaces.removeAllInterfaceOptions();
64
65 // DHCP 103 // DHCP
66 if(dhcpCheckBox->isChecked()) 104 if(dhcpCheckBox->isChecked()) {
67 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 105 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
68 else{ 106 interfaces->removeInterfaceOption("address");
107 interfaces->removeInterfaceOption("netmask");
108 interfaces->removeInterfaceOption("gateway");
109 interfaces->removeInterfaceOption("up "DNSSCRIPT" -a ");
110 interfaces->removeInterfaceOption("down "DNSSCRIPT" -r ");
111 } else{
69 interfaces->setInterfaceMethod("static"); 112 interfaces->setInterfaceMethod("static");
70 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 113 interfaces->setInterfaceOption("address", ipAddressEdit->text());
71 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 114 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
72 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 115 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
73 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ 116 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){
74 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 117 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
75 interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); 118 interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns);
76 interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); 119 interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns);
77 } 120 }
78 } 121 }
79 122
80 // IP Information 123 // IP Information
81 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 124 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
82 return true; 125 return true;
83} 126}
84 127
85/** 128/**
86 * The Profile has changed. 129 * The Profile has changed.
87 * @param QString profile the new profile. 130 * @param QString profile the new profile.
88 */ 131 */
89void InterfaceSetupImp::setProfile(const QString &profile){ 132void InterfaceSetupImp::setProfile(const QString &profile){
90 /* 133 /*
91 bool error = false; 134 bool error = false;
92 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 135 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
93 staticGroupBox->hide(); 136 staticGroupBox->hide();
94 dhcpCheckBox->hide(); 137 dhcpCheckBox->hide();
95 leaseTime->hide(); 138 leaseTime->hide();
96 leaseHoursLabel->hide(); 139 leaseHoursLabel->hide();
97 } 140 }
98 */ 141 */
99 142
100 QString newInterfaceName = interface->getInterfaceName(); 143 QString newInterfaceName = interface->getInterfaceName();
101 if(profile.length() > 0) 144 if(profile.length() > 0)
102 newInterfaceName += "_" + profile; 145 newInterfaceName += "_" + profile;
103 // See if we have to make a interface. 146 // See if we have to make a interface.
104 if(!interfaces->setInterface(newInterfaceName)){ 147 if(!interfaces->setInterface(newInterfaceName)){
105 // Add making for this new interface if need too 148 // Add making for this new interface if need too
106 if(profile != ""){ 149 if(profile != ""){
107 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); 150 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
108 if(!interfaces->setMapping(interface->getInterfaceName())){ 151 if(!interfaces->setMapping(interface->getInterfaceName())){
109 interfaces->addMapping(interface->getInterfaceName()); 152 interfaces->addMapping(interface->getInterfaceName());
110 if(!interfaces->setMapping(interface->getInterfaceName())){ 153 if(!interfaces->setMapping(interface->getInterfaceName())){
111 qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface."); 154 qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface.");
112 return; 155 return;
113 } 156 }
114 } 157 }
115 interfaces->setMap("map", newInterfaceName); 158 interfaces->setMap("map", newInterfaceName);
@@ -130,20 +173,24 @@ void InterfaceSetupImp::setProfile(const QString &profile){
130 bool error = false; 173 bool error = false;
131 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 174 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
132 dhcpCheckBox->setChecked(true); 175 dhcpCheckBox->setChecked(true);
133 else 176 else
134 dhcpCheckBox->setChecked(false); 177 dhcpCheckBox->setChecked(false);
135 178
136 // IP Information 179 // IP Information
137 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 180 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
138 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); 181 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error);
139 if(dns.contains(" ")){ 182 if(dns.contains(" ")){
140 firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); 183 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
141 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); 184 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
142 } 185 }
143 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); 186 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
144 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); 187 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
145 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); 188 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
189
190 qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1());
191 qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1());
192
146} 193}
147 194
148// interfacesetup.cpp 195// interfacesetup.cpp
149 196