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