author | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
commit | a7e015198a8c5ad3b6e144a9032b059086253e00 (patch) (unidiff) | |
tree | b712b6f11310d88744fe393a92b3160b741a7efe /noncore/settings/networksettings/interfaces | |
parent | beba0e73306815337bf04dee39502233595e9739 (diff) | |
download | opie-a7e015198a8c5ad3b6e144a9032b059086253e00.zip opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.gz opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.bz2 |
Merge from BRANCH_1_0
Diffstat (limited to 'noncore/settings/networksettings/interfaces') (more/less context) (ignore whitespace changes)
8 files changed, 254 insertions, 185 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index cc45525..69b55d1 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp | |||
@@ -1,302 +1,302 @@ | |||
1 | /** | 1 | /** |
2 | * $Author$ | 2 | * $Author$ |
3 | * $Date$ | 3 | * $Date$ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "interface.h" | 6 | #include "interface.h" |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <qfile.h> | 8 | #include <qfile.h> |
9 | #include <qdir.h> | 9 | #include <qdir.h> |
10 | #include <qfileinfo.h> | 10 | #include <qfileinfo.h> |
11 | #include <qtextstream.h> | 11 | #include <qtextstream.h> |
12 | 12 | ||
13 | #define IFCONFIG "/sbin/ifconfig" | 13 | #define IFCONFIG "/sbin/ifconfig" |
14 | #define DHCP_INFO_DIR "/etc/dhcpc" | 14 | #define DHCP_INFO_DIR "/etc/dhcpc" |
15 | 15 | ||
16 | #include <stdio.h> | 16 | #include <stdio.h> |
17 | #include <stdlib.h> | 17 | #include <stdlib.h> |
18 | 18 | ||
19 | Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ | 19 | Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ |
20 | refresh(); | 20 | refresh(); |
21 | } | 21 | } |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Set status | 24 | * Set status |
25 | * @param newStatus - the new status | 25 | * @param newStatus - the new status |
26 | * emit updateInterface | 26 | * emit updateInterface |
27 | */ | 27 | */ |
28 | void Interface::setStatus(bool newStatus){ | 28 | void Interface::setStatus(bool newStatus){ |
29 | if(status != newStatus){ | 29 | if(status != newStatus){ |
30 | status = newStatus; | 30 | status = newStatus; |
31 | refresh(); | 31 | refresh(); |
32 | } | 32 | } |
33 | }; | 33 | }; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Set if attached or not (802.11 card pulled out for example) | 36 | * Set if attached or not (802.11 card pulled out for example) |
37 | * @param isAttached - if attached | 37 | * @param isAttached - if attached |
38 | * emit updateInterface | 38 | * emit updateInterface |
39 | */ | 39 | */ |
40 | void Interface::setAttached(bool isAttached){ | 40 | void Interface::setAttached(bool isAttached){ |
41 | attached = isAttached; | 41 | attached = isAttached; |
42 | emit(updateInterface(this)); | 42 | emit(updateInterface(this)); |
43 | }; | 43 | }; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Set Hardware name | 46 | * Set Hardware name |
47 | * @param name - the new name | 47 | * @param name - the new name |
48 | * emit updateInterface | 48 | * emit updateInterface |
49 | */ | 49 | */ |
50 | void Interface::setHardwareName(const QString &name){ | 50 | void Interface::setHardwareName(const QString &name){ |
51 | hardwareName = name; | 51 | hardwareName = name; |
52 | emit(updateInterface(this)); | 52 | emit(updateInterface(this)); |
53 | }; | 53 | }; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Set Module owner | 56 | * Set Module owner |
57 | * @param owner - the new owner | 57 | * @param owner - the new owner |
58 | * emit updateInterface | 58 | * emit updateInterface |
59 | */ | 59 | */ |
60 | void Interface::setModuleOwner(Module *owner){ | 60 | void Interface::setModuleOwner(Module *owner){ |
61 | moduleOwner = owner; | 61 | moduleOwner = owner; |
62 | emit(updateInterface(this)); | 62 | emit(updateInterface(this)); |
63 | }; | 63 | }; |
64 | 64 | ||
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Try to start the interface. | 67 | * Try to start the interface. |
68 | */ | 68 | */ |
69 | void Interface::start(){ | 69 | void Interface::start(){ |
70 | // check to see if we are already running. | 70 | // check to see if we are already running. |
71 | if(true == status){ | 71 | if(true == status){ |
72 | emit (updateMessage("Unable to start interface,\n already started")); | 72 | emit (updateMessage("Unable to start interface,\n already started")); |
73 | return; | 73 | return; |
74 | } | 74 | } |
75 | 75 | ||
76 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); | 76 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); |
77 | // See if it was successfull... | 77 | // See if it was successfull... |
78 | if(ret != 0){ | 78 | if(ret != 0){ |
79 | emit (updateMessage("Starting interface failed")); | 79 | emit (updateMessage("Starting interface failed")); |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | 82 | ||
83 | status = true; | 83 | status = true; |
84 | refresh(); | 84 | refresh(); |
85 | emit (updateMessage("Start successfull")); | 85 | emit (updateMessage("Start successfull")); |
86 | } | 86 | } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * Try to stop the interface. | 89 | * Try to stop the interface. |
90 | */ | 90 | */ |
91 | void Interface::stop(){ | 91 | void Interface::stop(){ |
92 | // check to see if we are already stopped. | 92 | // check to see if we are already stopped. |
93 | if(false == status){ | 93 | if(false == status){ |
94 | emit (updateMessage("Unable to stop interface,\n already stopped")); | 94 | emit (updateMessage("Unable to stop interface,\n already stopped")); |
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | 97 | ||
98 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); | 98 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); |
99 | if(ret != 0){ | 99 | if(ret != 0){ |
100 | emit (updateMessage("Stopping interface failed")); | 100 | emit (updateMessage("Stopping interface failed")); |
101 | return; | 101 | return; |
102 | } | 102 | } |
103 | 103 | ||
104 | status = false; | 104 | status = false; |
105 | refresh(); | 105 | refresh(); |
106 | emit (updateMessage("Stop successfull")); | 106 | emit (updateMessage("Stop successfull")); |
107 | } | 107 | } |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * Try to restart the interface. | 110 | * Try to restart the interface. |
111 | */ | 111 | */ |
112 | void Interface::restart(){ | 112 | void Interface::restart(){ |
113 | stop(); | 113 | stop(); |
114 | start(); | 114 | start(); |
115 | } | 115 | } |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Try to refresh the information about the interface. | 118 | * Try to refresh the information about the interface. |
119 | * First call ifconfig, then check the dhcp-info file | 119 | * First call ifconfig, then check the dhcp-info file |
120 | * @return bool true if successfull. | 120 | * @return bool true if successfull. |
121 | */ | 121 | */ |
122 | bool Interface::refresh(){ | 122 | bool Interface::refresh(){ |
123 | // See if we are up. | 123 | // See if we are up. |
124 | if(status == false){ | 124 | if(status == false){ |
125 | macAddress = ""; | 125 | macAddress = ""; |
126 | ip = "0.0.0.0"; | 126 | ip = "0.0.0.0"; |
127 | subnetMask = "0.0.0.0"; | 127 | subnetMask = "0.0.0.0"; |
128 | broadcast = ""; | 128 | broadcast = ""; |
129 | dhcp = false; | 129 | dhcp = false; |
130 | dhcpServerIp = ""; | 130 | dhcpServerIp = ""; |
131 | leaseObtained = ""; | 131 | leaseObtained = ""; |
132 | leaseExpires = ""; | 132 | leaseExpires = ""; |
133 | emit(updateInterface(this)); | 133 | emit(updateInterface(this)); |
134 | return true; | 134 | return true; |
135 | } | 135 | } |
136 | 136 | ||
137 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); | 137 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); |
138 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); | 138 | int ret = system(QString("LANG=C %1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); |
139 | if(ret != 0){ | 139 | if(ret != 0){ |
140 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); | 140 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); |
141 | return false; | 141 | return false; |
142 | } | 142 | } |
143 | 143 | ||
144 | QFile file(fileName); | 144 | QFile file(fileName); |
145 | if (!file.open(IO_ReadOnly)){ | 145 | if (!file.open(IO_ReadOnly)){ |
146 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 146 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
147 | return false; | 147 | return false; |
148 | } | 148 | } |
149 | 149 | ||
150 | // Set to the defaults | 150 | // Set to the defaults |
151 | macAddress = ""; | 151 | macAddress = ""; |
152 | ip = "0.0.0.0"; | 152 | ip = "0.0.0.0"; |
153 | subnetMask = "0.0.0.0"; | 153 | subnetMask = "0.0.0.0"; |
154 | broadcast = ""; | 154 | broadcast = ""; |
155 | 155 | ||
156 | QTextStream stream( &file ); | 156 | QTextStream stream( &file ); |
157 | QString line; | 157 | QString line; |
158 | while ( !stream.eof() ) { | 158 | while ( !stream.eof() ) { |
159 | line = stream.readLine(); | 159 | line = stream.readLine(); |
160 | if(line.contains("HWaddr")){ | 160 | if(line.contains("HWaddr")){ |
161 | int mac = line.find("HWaddr"); | 161 | int mac = line.find("HWaddr"); |
162 | macAddress = line.mid(mac+7, line.length()); | 162 | macAddress = line.mid(mac+7, line.length()); |
163 | } | 163 | } |
164 | if(line.contains("inet addr")){ | 164 | if(line.contains("inet addr")){ |
165 | int ipl = line.find("inet addr"); | 165 | int ipl = line.find("inet addr"); |
166 | int space = line.find(" ", ipl+10); | 166 | int space = line.find(" ", ipl+10); |
167 | ip = line.mid(ipl+10, space-ipl-10); | 167 | ip = line.mid(ipl+10, space-ipl-10); |
168 | } | 168 | } |
169 | if(line.contains("Mask")){ | 169 | if(line.contains("Mask")){ |
170 | int mask = line.find("Mask"); | 170 | int mask = line.find("Mask"); |
171 | subnetMask = line.mid(mask+5, line.length()); | 171 | subnetMask = line.mid(mask+5, line.length()); |
172 | } | 172 | } |
173 | if(line.contains("Bcast")){ | 173 | if(line.contains("Bcast")){ |
174 | int mask = line.find("Bcast"); | 174 | int mask = line.find("Bcast"); |
175 | int space = line.find(" ", mask+6); | 175 | int space = line.find(" ", mask+6); |
176 | broadcast = line.mid(mask+6, space-mask-6); | 176 | broadcast = line.mid(mask+6, space-mask-6); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | file.close(); | 179 | file.close(); |
180 | QFile::remove(fileName); | 180 | QFile::remove(fileName); |
181 | 181 | ||
182 | // DHCP TESTING | 182 | // DHCP TESTING |
183 | // reset DHCP info | 183 | // reset DHCP info |
184 | dhcpServerIp = ""; | 184 | dhcpServerIp = ""; |
185 | leaseObtained = ""; | 185 | leaseObtained = ""; |
186 | leaseExpires = ""; | 186 | leaseExpires = ""; |
187 | dhcp = false; | 187 | dhcp = false; |
188 | 188 | ||
189 | QString dhcpDirectory(DHCP_INFO_DIR); | 189 | QString dhcpDirectory(DHCP_INFO_DIR); |
190 | QDir d(dhcpDirectory); | 190 | QDir d(dhcpDirectory); |
191 | if(!d.exists(dhcpDirectory)) | 191 | if(!d.exists(dhcpDirectory)) |
192 | dhcpDirectory = "/var/run"; | 192 | dhcpDirectory = "/var/run"; |
193 | 193 | ||
194 | // See if we have | 194 | // See if we have |
195 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); | 195 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); |
196 | // If there is no DHCP information then exit now with no errors. | 196 | // If there is no DHCP information then exit now with no errors. |
197 | if(!QFile::exists(dhcpFile)){ | 197 | if(!QFile::exists(dhcpFile)){ |
198 | emit(updateInterface(this)); | 198 | emit(updateInterface(this)); |
199 | return true; | 199 | return true; |
200 | } | 200 | } |
201 | 201 | ||
202 | file.setName(dhcpFile); | 202 | file.setName(dhcpFile); |
203 | if (!file.open(IO_ReadOnly)){ | 203 | if (!file.open(IO_ReadOnly)){ |
204 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 204 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
205 | return false; | 205 | return false; |
206 | } | 206 | } |
207 | 207 | ||
208 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. | 208 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. |
209 | int leaseTime = 0; | 209 | int leaseTime = 0; |
210 | int renewalTime = 0; | 210 | int renewalTime = 0; |
211 | 211 | ||
212 | stream.setDevice( &file ); | 212 | stream.setDevice( &file ); |
213 | while ( !stream.eof() ) { | 213 | while ( !stream.eof() ) { |
214 | line = stream.readLine(); | 214 | line = stream.readLine(); |
215 | if(line.contains("DHCPSIADDR=")) | 215 | if(line.contains("DHCPSIADDR=")) |
216 | dhcpServerIp = line.mid(11, line.length()); | 216 | dhcpServerIp = line.mid(11, line.length()); |
217 | if(line.contains("LEASETIME=")) | 217 | if(line.contains("LEASETIME=")) |
218 | leaseTime = line.mid(10, line.length()).toInt(); | 218 | leaseTime = line.mid(10, line.length()).toInt(); |
219 | if(line.contains("RENEWALTIME=")) | 219 | if(line.contains("RENEWALTIME=")) |
220 | renewalTime = line.mid(12, line.length()).toInt(); | 220 | renewalTime = line.mid(12, line.length()).toInt(); |
221 | } | 221 | } |
222 | file.close(); | 222 | file.close(); |
223 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | 223 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); |
224 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | 224 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); |
225 | 225 | ||
226 | // Get the pid of the deamond | 226 | // Get the pid of the deamond |
227 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); | 227 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); |
228 | file.setName(dhcpFile); | 228 | file.setName(dhcpFile); |
229 | if (!file.open(IO_ReadOnly)){ | 229 | if (!file.open(IO_ReadOnly)){ |
230 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 230 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
231 | return false; | 231 | return false; |
232 | } | 232 | } |
233 | 233 | ||
234 | int pid = -1; | 234 | int pid = -1; |
235 | stream.setDevice( &file ); | 235 | stream.setDevice( &file ); |
236 | while ( !stream.eof() ) { | 236 | while ( !stream.eof() ) { |
237 | line = stream.readLine(); | 237 | line = stream.readLine(); |
238 | pid = line.toInt(); | 238 | pid = line.toInt(); |
239 | } | 239 | } |
240 | file.close(); | 240 | file.close(); |
241 | 241 | ||
242 | if( pid == -1){ | 242 | if( pid == -1){ |
243 | qDebug("Interface: Could not get pid of dhcpc deamon."); | 243 | qDebug("Interface: Could not get pid of dhcpc deamon."); |
244 | return false; | 244 | return false; |
245 | } | 245 | } |
246 | 246 | ||
247 | // Get the start running time of the deamon | 247 | // Get the start running time of the deamon |
248 | fileName = (QString("/proc/%1/stat").arg(pid)); | 248 | fileName = (QString("/proc/%1/stat").arg(pid)); |
249 | file.setName(fileName); | 249 | file.setName(fileName); |
250 | stream.setDevice( &file ); | 250 | stream.setDevice( &file ); |
251 | if (!file.open(IO_ReadOnly)){ | 251 | if (!file.open(IO_ReadOnly)){ |
252 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 252 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
253 | return false; | 253 | return false; |
254 | } | 254 | } |
255 | while ( !stream.eof() ) { | 255 | while ( !stream.eof() ) { |
256 | line = stream.readLine(); | 256 | line = stream.readLine(); |
257 | } | 257 | } |
258 | file.close(); | 258 | file.close(); |
259 | long time = 0; | 259 | long time = 0; |
260 | // Grab the start time | 260 | // Grab the start time |
261 | // pid com state ppid pgrp session tty_nr tpgid flags | 261 | // pid com state ppid pgrp session tty_nr tpgid flags |
262 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " | 262 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " |
263 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority | 263 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority |
264 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | 264 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " |
265 | // nice 0 itrealvalue starttime | 265 | // nice 0 itrealvalue starttime |
266 | "%*d %*d %*d %lu", (long*) &time); | 266 | "%*d %*d %*d %lu", (long*) &time); |
267 | time = time/100; | 267 | time = time/100; |
268 | 268 | ||
269 | QDateTime datetime(QDateTime::currentDateTime()); | 269 | QDateTime datetime(QDateTime::currentDateTime()); |
270 | 270 | ||
271 | // Get the uptime of the computer. | 271 | // Get the uptime of the computer. |
272 | QFile f("/proc/uptime"); | 272 | QFile f("/proc/uptime"); |
273 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 273 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
274 | QTextStream t( &f ); // use a text stream | 274 | QTextStream t( &f ); // use a text stream |
275 | int sec = 0; | 275 | int sec = 0; |
276 | t >> sec; | 276 | t >> sec; |
277 | datetime = datetime.addSecs((-1*sec)); | 277 | datetime = datetime.addSecs((-1*sec)); |
278 | f.close(); | 278 | f.close(); |
279 | } | 279 | } |
280 | else{ | 280 | else{ |
281 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | 281 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); |
282 | return false; | 282 | return false; |
283 | } | 283 | } |
284 | 284 | ||
285 | datetime = datetime.addSecs(time); | 285 | datetime = datetime.addSecs(time); |
286 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | 286 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); |
287 | 287 | ||
288 | // Calculate the start and renew times | 288 | // Calculate the start and renew times |
289 | leaseObtained= datetime.toString(); | 289 | leaseObtained= datetime.toString(); |
290 | 290 | ||
291 | // Calculate the start and renew times | 291 | // Calculate the start and renew times |
292 | datetime = datetime.addSecs(leaseTime); | 292 | datetime = datetime.addSecs(leaseTime); |
293 | leaseExpires = datetime.toString(); | 293 | leaseExpires = datetime.toString(); |
294 | 294 | ||
295 | dhcp = true; | 295 | dhcp = true; |
296 | 296 | ||
297 | emit(updateInterface(this)); | 297 | emit(updateInterface(this)); |
298 | return true; | 298 | return true; |
299 | } | 299 | } |
300 | 300 | ||
301 | // interface.cpp | 301 | // interface.cpp |
302 | 302 | ||
diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h index 7e98deb..ec82851 100644 --- a/noncore/settings/networksettings/interfaces/interface.h +++ b/noncore/settings/networksettings/interfaces/interface.h | |||
@@ -1,73 +1,73 @@ | |||
1 | #ifndef INTERFACE_H | 1 | #ifndef INTERFACE_H |
2 | #define INTERFACE_H | 2 | #define INTERFACE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | 6 | ||
7 | class Module; | 7 | class Module; |
8 | 8 | ||
9 | class Interface : public QObject{ | 9 | class Interface : public QObject{ |
10 | Q_OBJECT | 10 | Q_OBJECT |
11 | 11 | ||
12 | signals: | 12 | signals: |
13 | void updateInterface(Interface *i); | 13 | void updateInterface(Interface *i); |
14 | void updateMessage(const QString &message); | 14 | void updateMessage(const QString &message); |
15 | 15 | ||
16 | public: | 16 | public: |
17 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); | 17 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); |
18 | 18 | ||
19 | QString getInterfaceName() const { QString n(this->name()); return n; }; | 19 | QString getInterfaceName() const { QString n(this->name()); return n; }; |
20 | void setInterfaceName( const QString &n ) { this->setName(n); }; | 20 | void setInterfaceName( const QString &n ) { this->setName(n); }; |
21 | 21 | ||
22 | bool getStatus() const { return status; }; | 22 | bool getStatus() const { return status; }; |
23 | void setStatus(bool newStatus); | 23 | void setStatus(bool newStatus); |
24 | 24 | ||
25 | bool isAttached() const { return attached; }; | 25 | bool isAttached() const { return attached; }; |
26 | void setAttached(bool isAttached=false); | 26 | void setAttached(bool isAttached=false); |
27 | 27 | ||
28 | QString getHardwareName() const { return hardwareName; }; | 28 | QString getHardwareName() const { return hardwareName; }; |
29 | void setHardwareName(const QString &name="Unknown"); | 29 | void setHardwareName(const QString &name="Unknown"); |
30 | 30 | ||
31 | Module* getModuleOwner() const { return moduleOwner; }; | 31 | Module* getModuleOwner() const { return moduleOwner; }; |
32 | void setModuleOwner(Module *owner=NULL); | 32 | void setModuleOwner(Module *owner=NULL); |
33 | 33 | ||
34 | // inet information. | 34 | // inet information. |
35 | QString getMacAddress() const { return macAddress; }; | 35 | QString getMacAddress() const { return macAddress; }; |
36 | QString getIp() const { return ip; }; | 36 | QString getIp() const { return ip; }; |
37 | QString getSubnetMask() const { return subnetMask; }; | 37 | QString getSubnetMask() const { return subnetMask; }; |
38 | QString getBroadcast() const { return broadcast; }; | 38 | QString getBroadcast() const { return broadcast; }; |
39 | bool isDhcp() const { return dhcp; }; | 39 | bool isDhcp() const { return dhcp; }; |
40 | QString getDhcpServerIp() const { return dhcpServerIp; }; | 40 | QString getDhcpServerIp() const { return dhcpServerIp; }; |
41 | QString getLeaseObtained() const { return leaseObtained; }; | 41 | QString getLeaseObtained() const { return leaseObtained; }; |
42 | QString getLeaseExpires() const { return leaseExpires; }; | 42 | QString getLeaseExpires() const { return leaseExpires; }; |
43 | 43 | ||
44 | public slots: | 44 | public slots: |
45 | virtual bool refresh(); | 45 | virtual bool refresh(); |
46 | virtual void start(); | 46 | virtual void start(); |
47 | virtual void stop(); | 47 | virtual void stop(); |
48 | virtual void restart(); | 48 | virtual void restart(); |
49 | 49 | ||
50 | private: | 50 | protected: |
51 | // Interface information | 51 | // Interface information |
52 | QString hardwareName; | 52 | QString hardwareName; |
53 | Module *moduleOwner; | 53 | Module *moduleOwner; |
54 | bool status; | 54 | bool status; |
55 | bool attached; | 55 | bool attached; |
56 | 56 | ||
57 | // Network information | 57 | // Network information |
58 | bool dhcp; | 58 | bool dhcp; |
59 | QString dhcpServerIp; | 59 | QString dhcpServerIp; |
60 | QString leaseObtained; | 60 | QString leaseObtained; |
61 | QString leaseExpires; | 61 | QString leaseExpires; |
62 | 62 | ||
63 | QString macAddress; | 63 | QString macAddress; |
64 | QString ip; | 64 | QString ip; |
65 | QString broadcast; | 65 | QString broadcast; |
66 | QString subnetMask; | 66 | QString subnetMask; |
67 | 67 | ||
68 | }; | 68 | }; |
69 | 69 | ||
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | // interface.h | 72 | // interface.h |
73 | 73 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaceadvanced.ui b/noncore/settings/networksettings/interfaces/interfaceadvanced.ui index 2e106cb..12dbb1d 100644 --- a/noncore/settings/networksettings/interfaces/interfaceadvanced.ui +++ b/noncore/settings/networksettings/interfaces/interfaceadvanced.ui | |||
@@ -1,117 +1,117 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceAdvanced</class> | 2 | <class>InterfaceAdvanced</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceAdvanced</cstring> | 7 | <cstring>InterfaceAdvanced</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>214</width> | 14 | <width>214</width> |
15 | <height>290</height> | 15 | <height>290</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>maximumSize</name> | 19 | <name>maximumSize</name> |
20 | <size> | 20 | <size> |
21 | <width>240</width> | 21 | <width>32767</width> |
22 | <height>32767</height> | 22 | <height>32767</height> |
23 | </size> | 23 | </size> |
24 | </property> | 24 | </property> |
25 | <property stdset="1"> | 25 | <property stdset="1"> |
26 | <name>caption</name> | 26 | <name>caption</name> |
27 | <string>Advanced Interface Information</string> | 27 | <string>Advanced Interface Information</string> |
28 | </property> | 28 | </property> |
29 | <grid> | 29 | <grid> |
30 | <property stdset="1"> | 30 | <property stdset="1"> |
31 | <name>margin</name> | 31 | <name>margin</name> |
32 | <number>11</number> | 32 | <number>11</number> |
33 | </property> | 33 | </property> |
34 | <property stdset="1"> | 34 | <property stdset="1"> |
35 | <name>spacing</name> | 35 | <name>spacing</name> |
36 | <number>6</number> | 36 | <number>6</number> |
37 | </property> | 37 | </property> |
38 | <widget row="0" column="1" > | 38 | <widget row="0" column="1" > |
39 | <class>QLabel</class> | 39 | <class>QLabel</class> |
40 | <property stdset="1"> | 40 | <property stdset="1"> |
41 | <name>name</name> | 41 | <name>name</name> |
42 | <cstring>interfaceName</cstring> | 42 | <cstring>interfaceName</cstring> |
43 | </property> | 43 | </property> |
44 | <property stdset="1"> | 44 | <property stdset="1"> |
45 | <name>frameShape</name> | 45 | <name>frameShape</name> |
46 | <enum>Panel</enum> | 46 | <enum>Panel</enum> |
47 | </property> | 47 | </property> |
48 | <property stdset="1"> | 48 | <property stdset="1"> |
49 | <name>frameShadow</name> | 49 | <name>frameShadow</name> |
50 | <enum>Sunken</enum> | 50 | <enum>Sunken</enum> |
51 | </property> | 51 | </property> |
52 | <property stdset="1"> | 52 | <property stdset="1"> |
53 | <name>text</name> | 53 | <name>text</name> |
54 | <string>eth0</string> | 54 | <string>eth0</string> |
55 | </property> | 55 | </property> |
56 | </widget> | 56 | </widget> |
57 | <widget row="1" column="0" > | 57 | <widget row="1" column="0" > |
58 | <class>QLabel</class> | 58 | <class>QLabel</class> |
59 | <property stdset="1"> | 59 | <property stdset="1"> |
60 | <name>name</name> | 60 | <name>name</name> |
61 | <cstring>TextLabel3</cstring> | 61 | <cstring>TextLabel3</cstring> |
62 | </property> | 62 | </property> |
63 | <property stdset="1"> | 63 | <property stdset="1"> |
64 | <name>text</name> | 64 | <name>text</name> |
65 | <string>IP Address</string> | 65 | <string>IP Address</string> |
66 | </property> | 66 | </property> |
67 | </widget> | 67 | </widget> |
68 | <widget row="0" column="0" > | 68 | <widget row="0" column="0" > |
69 | <class>QLabel</class> | 69 | <class>QLabel</class> |
70 | <property stdset="1"> | 70 | <property stdset="1"> |
71 | <name>name</name> | 71 | <name>name</name> |
72 | <cstring>TextLabel7</cstring> | 72 | <cstring>TextLabel7</cstring> |
73 | </property> | 73 | </property> |
74 | <property stdset="1"> | 74 | <property stdset="1"> |
75 | <name>text</name> | 75 | <name>text</name> |
76 | <string>Interface</string> | 76 | <string>Interface</string> |
77 | </property> | 77 | </property> |
78 | </widget> | 78 | </widget> |
79 | <widget row="2" column="0" > | 79 | <widget row="2" column="0" > |
80 | <class>QLabel</class> | 80 | <class>QLabel</class> |
81 | <property stdset="1"> | 81 | <property stdset="1"> |
82 | <name>name</name> | 82 | <name>name</name> |
83 | <cstring>TextLabel4</cstring> | 83 | <cstring>TextLabel4</cstring> |
84 | </property> | 84 | </property> |
85 | <property stdset="1"> | 85 | <property stdset="1"> |
86 | <name>enabled</name> | 86 | <name>enabled</name> |
87 | <bool>true</bool> | 87 | <bool>true</bool> |
88 | </property> | 88 | </property> |
89 | <property stdset="1"> | 89 | <property stdset="1"> |
90 | <name>text</name> | 90 | <name>text</name> |
91 | <string>Subnet Mask</string> | 91 | <string>Subnet Mask</string> |
92 | </property> | 92 | </property> |
93 | </widget> | 93 | </widget> |
94 | <widget row="1" column="1" > | 94 | <widget row="1" column="1" > |
95 | <class>QLabel</class> | 95 | <class>QLabel</class> |
96 | <property stdset="1"> | 96 | <property stdset="1"> |
97 | <name>name</name> | 97 | <name>name</name> |
98 | <cstring>ipAddressLabel</cstring> | 98 | <cstring>ipAddressLabel</cstring> |
99 | </property> | 99 | </property> |
100 | <property stdset="1"> | 100 | <property stdset="1"> |
101 | <name>frameShape</name> | 101 | <name>frameShape</name> |
102 | <enum>Panel</enum> | 102 | <enum>Panel</enum> |
103 | </property> | 103 | </property> |
104 | <property stdset="1"> | 104 | <property stdset="1"> |
105 | <name>frameShadow</name> | 105 | <name>frameShadow</name> |
106 | <enum>Sunken</enum> | 106 | <enum>Sunken</enum> |
107 | </property> | 107 | </property> |
108 | <property stdset="1"> | 108 | <property stdset="1"> |
109 | <name>text</name> | 109 | <name>text</name> |
110 | <string>0.0.0.0</string> | 110 | <string>0.0.0.0</string> |
111 | </property> | 111 | </property> |
112 | </widget> | 112 | </widget> |
113 | <widget row="2" column="1" > | 113 | <widget row="2" column="1" > |
114 | <class>QLabel</class> | 114 | <class>QLabel</class> |
115 | <property stdset="1"> | 115 | <property stdset="1"> |
116 | <name>name</name> | 116 | <name>name</name> |
117 | <cstring>subnetMaskLabel</cstring> | 117 | <cstring>subnetMaskLabel</cstring> |
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformation.ui b/noncore/settings/networksettings/interfaces/interfaceinformation.ui index 763ad90..207200e 100644 --- a/noncore/settings/networksettings/interfaces/interfaceinformation.ui +++ b/noncore/settings/networksettings/interfaces/interfaceinformation.ui | |||
@@ -1,321 +1,338 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceInformation</class> | 2 | <class>InterfaceInformation</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceInformation</cstring> | 7 | <cstring>InterfaceInformation</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>219</width> | 14 | <width>219</width> |
15 | <height>255</height> | 15 | <height>323</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>caption</name> | 19 | <name>caption</name> |
20 | <string>Interface Information</string> | 20 | <string>Interface Information</string> |
21 | </property> | 21 | </property> |
22 | <grid> | 22 | <property> |
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <vbox> | ||
23 | <property stdset="1"> | 29 | <property stdset="1"> |
24 | <name>margin</name> | 30 | <name>margin</name> |
25 | <number>11</number> | 31 | <number>4</number> |
26 | </property> | 32 | </property> |
27 | <property stdset="1"> | 33 | <property stdset="1"> |
28 | <name>spacing</name> | 34 | <name>spacing</name> |
29 | <number>6</number> | 35 | <number>3</number> |
30 | </property> | 36 | </property> |
31 | <widget row="4" column="0" rowspan="1" colspan="2" > | 37 | <widget> |
32 | <class>QLayoutWidget</class> | ||
33 | <property stdset="1"> | ||
34 | <name>name</name> | ||
35 | <cstring>Layout1</cstring> | ||
36 | </property> | ||
37 | <grid> | ||
38 | <property stdset="1"> | ||
39 | <name>margin</name> | ||
40 | <number>0</number> | ||
41 | </property> | ||
42 | <property stdset="1"> | ||
43 | <name>spacing</name> | ||
44 | <number>6</number> | ||
45 | </property> | ||
46 | <widget row="1" column="0" > | ||
47 | <class>QPushButton</class> | ||
48 | <property stdset="1"> | ||
49 | <name>name</name> | ||
50 | <cstring>refreshButton</cstring> | ||
51 | </property> | ||
52 | <property stdset="1"> | ||
53 | <name>text</name> | ||
54 | <string>&Refresh</string> | ||
55 | </property> | ||
56 | </widget> | ||
57 | <widget row="0" column="1" > | ||
58 | <class>QPushButton</class> | ||
59 | <property stdset="1"> | ||
60 | <name>name</name> | ||
61 | <cstring>stopButton</cstring> | ||
62 | </property> | ||
63 | <property stdset="1"> | ||
64 | <name>text</name> | ||
65 | <string>S&top</string> | ||
66 | </property> | ||
67 | </widget> | ||
68 | <widget row="1" column="1" > | ||
69 | <class>QPushButton</class> | ||
70 | <property stdset="1"> | ||
71 | <name>name</name> | ||
72 | <cstring>restartButton</cstring> | ||
73 | </property> | ||
74 | <property stdset="1"> | ||
75 | <name>text</name> | ||
76 | <string>R&estart</string> | ||
77 | </property> | ||
78 | </widget> | ||
79 | <widget row="0" column="0" > | ||
80 | <class>QPushButton</class> | ||
81 | <property stdset="1"> | ||
82 | <name>name</name> | ||
83 | <cstring>startButton</cstring> | ||
84 | </property> | ||
85 | <property stdset="1"> | ||
86 | <name>text</name> | ||
87 | <string>&Start</string> | ||
88 | </property> | ||
89 | </widget> | ||
90 | </grid> | ||
91 | </widget> | ||
92 | <widget row="0" column="0" > | ||
93 | <class>Line</class> | ||
94 | <property stdset="1"> | ||
95 | <name>name</name> | ||
96 | <cstring>Line1</cstring> | ||
97 | </property> | ||
98 | <property stdset="1"> | ||
99 | <name>orientation</name> | ||
100 | <enum>Horizontal</enum> | ||
101 | </property> | ||
102 | </widget> | ||
103 | <widget row="0" column="0" > | ||
104 | <class>QLabel</class> | 38 | <class>QLabel</class> |
105 | <property stdset="1"> | 39 | <property stdset="1"> |
106 | <name>name</name> | 40 | <name>name</name> |
107 | <cstring>TextLabel22</cstring> | 41 | <cstring>TextLabel22</cstring> |
108 | </property> | 42 | </property> |
109 | <property stdset="1"> | 43 | <property stdset="1"> |
110 | <name>text</name> | 44 | <name>text</name> |
111 | <string>IP Address</string> | 45 | <string>IP Address</string> |
112 | </property> | 46 | </property> |
113 | </widget> | 47 | </widget> |
114 | <widget row="1" column="0" > | 48 | <widget> |
115 | <class>QLabel</class> | 49 | <class>QLabel</class> |
116 | <property stdset="1"> | 50 | <property stdset="1"> |
117 | <name>name</name> | 51 | <name>name</name> |
118 | <cstring>TextLabel23</cstring> | 52 | <cstring>ipAddressLabel</cstring> |
119 | </property> | 53 | </property> |
120 | <property stdset="1"> | 54 | <property stdset="1"> |
121 | <name>text</name> | 55 | <name>frameShape</name> |
122 | <string>Subnet Mask</string> | 56 | <enum>Panel</enum> |
123 | </property> | 57 | </property> |
124 | </widget> | ||
125 | <widget row="2" column="0" > | ||
126 | <class>QLabel</class> | ||
127 | <property stdset="1"> | 58 | <property stdset="1"> |
128 | <name>name</name> | 59 | <name>frameShadow</name> |
129 | <cstring>TextLabel21</cstring> | 60 | <enum>Sunken</enum> |
130 | </property> | 61 | </property> |
131 | <property stdset="1"> | 62 | <property stdset="1"> |
132 | <name>text</name> | 63 | <name>text</name> |
133 | <string>MAC Address</string> | 64 | <string>0.0.0.0</string> |
134 | </property> | 65 | </property> |
135 | </widget> | 66 | </widget> |
136 | <widget row="3" column="0" > | 67 | <widget> |
137 | <class>QLabel</class> | 68 | <class>Line</class> |
138 | <property stdset="1"> | 69 | <property stdset="1"> |
139 | <name>name</name> | 70 | <name>name</name> |
140 | <cstring>TextLabel24</cstring> | 71 | <cstring>Line1</cstring> |
141 | </property> | 72 | </property> |
142 | <property stdset="1"> | 73 | <property stdset="1"> |
143 | <name>frameShape</name> | 74 | <name>orientation</name> |
144 | <enum>MShape</enum> | 75 | <enum>Horizontal</enum> |
145 | </property> | 76 | </property> |
77 | </widget> | ||
78 | <widget> | ||
79 | <class>QLabel</class> | ||
146 | <property stdset="1"> | 80 | <property stdset="1"> |
147 | <name>frameShadow</name> | 81 | <name>name</name> |
148 | <enum>MShadow</enum> | 82 | <cstring>TextLabel23</cstring> |
149 | </property> | 83 | </property> |
150 | <property stdset="1"> | 84 | <property stdset="1"> |
151 | <name>text</name> | 85 | <name>text</name> |
152 | <string>Broadcast</string> | 86 | <string>Subnet Mask</string> |
153 | </property> | 87 | </property> |
154 | </widget> | 88 | </widget> |
155 | <widget row="1" column="1" > | 89 | <widget> |
156 | <class>QLabel</class> | 90 | <class>QLabel</class> |
157 | <property stdset="1"> | 91 | <property stdset="1"> |
158 | <name>name</name> | 92 | <name>name</name> |
159 | <cstring>subnetMaskLabel</cstring> | 93 | <cstring>subnetMaskLabel</cstring> |
160 | </property> | 94 | </property> |
161 | <property stdset="1"> | 95 | <property stdset="1"> |
162 | <name>frameShape</name> | 96 | <name>frameShape</name> |
163 | <enum>Panel</enum> | 97 | <enum>Panel</enum> |
164 | </property> | 98 | </property> |
165 | <property stdset="1"> | 99 | <property stdset="1"> |
166 | <name>frameShadow</name> | 100 | <name>frameShadow</name> |
167 | <enum>Sunken</enum> | 101 | <enum>Sunken</enum> |
168 | </property> | 102 | </property> |
169 | <property stdset="1"> | 103 | <property stdset="1"> |
170 | <name>text</name> | 104 | <name>text</name> |
171 | <string>0.0.0.0</string> | 105 | <string>0.0.0.0</string> |
172 | </property> | 106 | </property> |
173 | </widget> | 107 | </widget> |
174 | <widget row="2" column="1" > | 108 | <widget> |
175 | <class>QLabel</class> | 109 | <class>QLabel</class> |
176 | <property stdset="1"> | 110 | <property stdset="1"> |
177 | <name>name</name> | 111 | <name>name</name> |
178 | <cstring>macAddressLabel</cstring> | 112 | <cstring>macAddressLabel</cstring> |
179 | </property> | 113 | </property> |
180 | <property stdset="1"> | 114 | <property stdset="1"> |
181 | <name>frameShape</name> | 115 | <name>frameShape</name> |
182 | <enum>Panel</enum> | 116 | <enum>Panel</enum> |
183 | </property> | 117 | </property> |
184 | <property stdset="1"> | 118 | <property stdset="1"> |
185 | <name>frameShadow</name> | 119 | <name>frameShadow</name> |
186 | <enum>Sunken</enum> | 120 | <enum>Sunken</enum> |
187 | </property> | 121 | </property> |
188 | <property stdset="1"> | 122 | <property stdset="1"> |
189 | <name>text</name> | 123 | <name>text</name> |
190 | <string>00:00:00:00:00:00</string> | 124 | <string>00:00:00:00:00:00</string> |
191 | </property> | 125 | </property> |
192 | </widget> | 126 | </widget> |
193 | <widget row="3" column="1" > | 127 | <widget> |
128 | <class>QLabel</class> | ||
129 | <property stdset="1"> | ||
130 | <name>name</name> | ||
131 | <cstring>TextLabel21</cstring> | ||
132 | </property> | ||
133 | <property stdset="1"> | ||
134 | <name>text</name> | ||
135 | <string>MAC Address</string> | ||
136 | </property> | ||
137 | </widget> | ||
138 | <widget> | ||
194 | <class>QLabel</class> | 139 | <class>QLabel</class> |
195 | <property stdset="1"> | 140 | <property stdset="1"> |
196 | <name>name</name> | 141 | <name>name</name> |
197 | <cstring>broadcastLabel</cstring> | 142 | <cstring>broadcastLabel</cstring> |
198 | </property> | 143 | </property> |
199 | <property stdset="1"> | 144 | <property stdset="1"> |
200 | <name>frameShape</name> | 145 | <name>frameShape</name> |
201 | <enum>Panel</enum> | 146 | <enum>Panel</enum> |
202 | </property> | 147 | </property> |
203 | <property stdset="1"> | 148 | <property stdset="1"> |
204 | <name>frameShadow</name> | 149 | <name>frameShadow</name> |
205 | <enum>Sunken</enum> | 150 | <enum>Sunken</enum> |
206 | </property> | 151 | </property> |
207 | <property stdset="1"> | 152 | <property stdset="1"> |
208 | <name>text</name> | 153 | <name>text</name> |
209 | <string></string> | 154 | <string></string> |
210 | </property> | 155 | </property> |
211 | </widget> | 156 | </widget> |
212 | <widget row="0" column="1" > | 157 | <widget> |
213 | <class>QLabel</class> | 158 | <class>QLabel</class> |
214 | <property stdset="1"> | 159 | <property stdset="1"> |
215 | <name>name</name> | 160 | <name>name</name> |
216 | <cstring>ipAddressLabel</cstring> | 161 | <cstring>TextLabel24</cstring> |
217 | </property> | 162 | </property> |
218 | <property stdset="1"> | 163 | <property stdset="1"> |
219 | <name>frameShape</name> | 164 | <name>frameShape</name> |
220 | <enum>Panel</enum> | 165 | <enum>MShape</enum> |
221 | </property> | 166 | </property> |
222 | <property stdset="1"> | 167 | <property stdset="1"> |
223 | <name>frameShadow</name> | 168 | <name>frameShadow</name> |
224 | <enum>Sunken</enum> | 169 | <enum>MShadow</enum> |
225 | </property> | 170 | </property> |
226 | <property stdset="1"> | 171 | <property stdset="1"> |
227 | <name>text</name> | 172 | <name>text</name> |
228 | <string>0.0.0.0</string> | 173 | <string>Broadcast</string> |
229 | </property> | 174 | </property> |
230 | </widget> | 175 | </widget> |
231 | <spacer row="7" column="1" > | 176 | <widget> |
232 | <property> | 177 | <class>QLayoutWidget</class> |
178 | <property stdset="1"> | ||
233 | <name>name</name> | 179 | <name>name</name> |
234 | <cstring>Spacer18</cstring> | 180 | <cstring>Layout1</cstring> |
235 | </property> | 181 | </property> |
182 | <grid> | ||
183 | <property stdset="1"> | ||
184 | <name>margin</name> | ||
185 | <number>0</number> | ||
186 | </property> | ||
187 | <property stdset="1"> | ||
188 | <name>spacing</name> | ||
189 | <number>6</number> | ||
190 | </property> | ||
191 | <widget row="1" column="0" > | ||
192 | <class>QPushButton</class> | ||
193 | <property stdset="1"> | ||
194 | <name>name</name> | ||
195 | <cstring>refreshButton</cstring> | ||
196 | </property> | ||
197 | <property stdset="1"> | ||
198 | <name>text</name> | ||
199 | <string>&Refresh</string> | ||
200 | </property> | ||
201 | </widget> | ||
202 | <widget row="0" column="1" > | ||
203 | <class>QPushButton</class> | ||
204 | <property stdset="1"> | ||
205 | <name>name</name> | ||
206 | <cstring>stopButton</cstring> | ||
207 | </property> | ||
208 | <property stdset="1"> | ||
209 | <name>text</name> | ||
210 | <string>S&top</string> | ||
211 | </property> | ||
212 | </widget> | ||
213 | <widget row="1" column="1" > | ||
214 | <class>QPushButton</class> | ||
215 | <property stdset="1"> | ||
216 | <name>name</name> | ||
217 | <cstring>restartButton</cstring> | ||
218 | </property> | ||
219 | <property stdset="1"> | ||
220 | <name>text</name> | ||
221 | <string>R&estart</string> | ||
222 | </property> | ||
223 | </widget> | ||
224 | <widget row="0" column="0" > | ||
225 | <class>QPushButton</class> | ||
226 | <property stdset="1"> | ||
227 | <name>name</name> | ||
228 | <cstring>startButton</cstring> | ||
229 | </property> | ||
230 | <property stdset="1"> | ||
231 | <name>text</name> | ||
232 | <string>&Start</string> | ||
233 | </property> | ||
234 | </widget> | ||
235 | </grid> | ||
236 | </widget> | ||
237 | <widget> | ||
238 | <class>Line</class> | ||
236 | <property stdset="1"> | 239 | <property stdset="1"> |
237 | <name>orientation</name> | 240 | <name>name</name> |
238 | <enum>Vertical</enum> | 241 | <cstring>Line5</cstring> |
239 | </property> | 242 | </property> |
240 | <property stdset="1"> | 243 | <property stdset="1"> |
241 | <name>sizeType</name> | 244 | <name>orientation</name> |
242 | <enum>Expanding</enum> | 245 | <enum>Horizontal</enum> |
243 | </property> | ||
244 | <property> | ||
245 | <name>sizeHint</name> | ||
246 | <size> | ||
247 | <width>20</width> | ||
248 | <height>20</height> | ||
249 | </size> | ||
250 | </property> | 246 | </property> |
251 | </spacer> | 247 | </widget> |
252 | <widget row="6" column="0" rowspan="1" colspan="2" > | 248 | <widget> |
253 | <class>QLayoutWidget</class> | 249 | <class>QLayoutWidget</class> |
254 | <property stdset="1"> | 250 | <property stdset="1"> |
255 | <name>name</name> | 251 | <name>name</name> |
256 | <cstring>Layout2</cstring> | 252 | <cstring>Layout2</cstring> |
257 | </property> | 253 | </property> |
258 | <hbox> | 254 | <hbox> |
259 | <property stdset="1"> | 255 | <property stdset="1"> |
260 | <name>margin</name> | 256 | <name>margin</name> |
261 | <number>0</number> | 257 | <number>0</number> |
262 | </property> | 258 | </property> |
263 | <property stdset="1"> | 259 | <property stdset="1"> |
264 | <name>spacing</name> | 260 | <name>spacing</name> |
265 | <number>6</number> | 261 | <number>6</number> |
266 | </property> | 262 | </property> |
267 | <spacer> | 263 | <spacer> |
268 | <property> | 264 | <property> |
269 | <name>name</name> | 265 | <name>name</name> |
270 | <cstring>Spacer10</cstring> | 266 | <cstring>Spacer10</cstring> |
271 | </property> | 267 | </property> |
272 | <property stdset="1"> | 268 | <property stdset="1"> |
273 | <name>orientation</name> | 269 | <name>orientation</name> |
274 | <enum>Horizontal</enum> | 270 | <enum>Horizontal</enum> |
275 | </property> | 271 | </property> |
276 | <property stdset="1"> | 272 | <property stdset="1"> |
277 | <name>sizeType</name> | 273 | <name>sizeType</name> |
278 | <enum>Expanding</enum> | 274 | <enum>Expanding</enum> |
279 | </property> | 275 | </property> |
280 | <property> | 276 | <property> |
281 | <name>sizeHint</name> | 277 | <name>sizeHint</name> |
282 | <size> | 278 | <size> |
283 | <width>20</width> | 279 | <width>20</width> |
284 | <height>20</height> | 280 | <height>20</height> |
285 | </size> | 281 | </size> |
286 | </property> | 282 | </property> |
287 | </spacer> | 283 | </spacer> |
288 | <widget> | 284 | <widget> |
289 | <class>QPushButton</class> | 285 | <class>QPushButton</class> |
290 | <property stdset="1"> | 286 | <property stdset="1"> |
291 | <name>name</name> | 287 | <name>name</name> |
292 | <cstring>advancedButton</cstring> | 288 | <cstring>advancedButton</cstring> |
293 | </property> | 289 | </property> |
294 | <property stdset="1"> | 290 | <property stdset="1"> |
295 | <name>text</name> | 291 | <name>text</name> |
296 | <string>&View Advanced Information</string> | 292 | <string>&View Advanced Information</string> |
297 | </property> | 293 | </property> |
298 | </widget> | 294 | </widget> |
299 | </hbox> | 295 | </hbox> |
300 | </widget> | 296 | </widget> |
301 | <widget row="5" column="0" rowspan="1" colspan="2" > | 297 | <spacer> |
302 | <class>Line</class> | 298 | <property> |
303 | <property stdset="1"> | ||
304 | <name>name</name> | 299 | <name>name</name> |
305 | <cstring>Line5</cstring> | 300 | <cstring>Spacer18</cstring> |
306 | </property> | 301 | </property> |
307 | <property stdset="1"> | 302 | <property stdset="1"> |
308 | <name>orientation</name> | 303 | <name>orientation</name> |
309 | <enum>Horizontal</enum> | 304 | <enum>Vertical</enum> |
305 | </property> | ||
306 | <property stdset="1"> | ||
307 | <name>sizeType</name> | ||
308 | <enum>Expanding</enum> | ||
309 | </property> | ||
310 | <property> | ||
311 | <name>sizeHint</name> | ||
312 | <size> | ||
313 | <width>20</width> | ||
314 | <height>20</height> | ||
315 | </size> | ||
316 | </property> | ||
317 | </spacer> | ||
318 | <widget> | ||
319 | <class>QCheckBox</class> | ||
320 | <property stdset="1"> | ||
321 | <name>name</name> | ||
322 | <cstring>CheckBoxSilent</cstring> | ||
323 | </property> | ||
324 | <property stdset="1"> | ||
325 | <name>text</name> | ||
326 | <string>be &silent</string> | ||
310 | </property> | 327 | </property> |
311 | </widget> | 328 | </widget> |
312 | </grid> | 329 | </vbox> |
313 | </widget> | 330 | </widget> |
314 | <tabstops> | 331 | <tabstops> |
315 | <tabstop>startButton</tabstop> | 332 | <tabstop>startButton</tabstop> |
316 | <tabstop>stopButton</tabstop> | 333 | <tabstop>stopButton</tabstop> |
317 | <tabstop>refreshButton</tabstop> | 334 | <tabstop>refreshButton</tabstop> |
318 | <tabstop>restartButton</tabstop> | 335 | <tabstop>restartButton</tabstop> |
319 | <tabstop>advancedButton</tabstop> | 336 | <tabstop>advancedButton</tabstop> |
320 | </tabstops> | 337 | </tabstops> |
321 | </UI> | 338 | </UI> |
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp index e00dcce..37c3a91 100644 --- a/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp | |||
@@ -1,79 +1,93 @@ | |||
1 | #include "interfaceinformationimp.h" | 1 | #include "interfaceinformationimp.h" |
2 | #include "interfaceadvanced.h" | 2 | #include "interfaceadvanced.h" |
3 | 3 | ||
4 | #include <qcheckbox.h> | ||
4 | #include <qpushbutton.h> | 5 | #include <qpushbutton.h> |
5 | #include <qlabel.h> | 6 | #include <qlabel.h> |
6 | #include <qgroupbox.h> | 7 | #include <qgroupbox.h> |
7 | #include <qmessagebox.h> | 8 | #include <qmessagebox.h> |
8 | 9 | ||
9 | #ifdef QWS | 10 | #include <qpe/config.h> |
11 | |||
12 | #ifdef QWS | ||
10 | #else | 13 | #else |
11 | #define showMaximized show | 14 | #define showMaximized show |
12 | #endif | 15 | #endif |
13 | 16 | ||
14 | /** | 17 | /** |
15 | * Constructor for the InterfaceInformationImp class. This class pretty much | 18 | * Constructor for the InterfaceInformationImp class. This class pretty much |
16 | * just display's information about the interface that is passed to it. | 19 | * just display's information about the interface that is passed to it. |
17 | */ | 20 | */ |
18 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f), interface(i){ | 21 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f), interface(i){ |
19 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 22 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
20 | connect(i, SIGNAL(updateMessage(const QString &)), this, SLOT(showMessage(const QString &))); | 23 | connect(i, SIGNAL(updateMessage(const QString &)), this, SLOT(showMessage(const QString &))); |
21 | updateInterface(interface); | 24 | updateInterface(interface); |
22 | connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); | 25 | connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); |
23 | connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); | 26 | connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); |
24 | connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); | 27 | connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); |
25 | connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); | 28 | connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); |
26 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); | 29 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); |
30 | Config cfg("networksettings", Config::User); | ||
31 | cfg.setGroup("interface"); | ||
32 | CheckBoxSilent->setChecked( cfg.readBoolEntry("silent", false) ); | ||
33 | } | ||
34 | |||
35 | InterfaceInformationImp::~InterfaceInformationImp() | ||
36 | { | ||
37 | Config cfg("networksettings", Config::User); | ||
38 | cfg.setGroup("interface"); | ||
39 | cfg.writeEntry("silent", CheckBoxSilent->isChecked() ); | ||
27 | } | 40 | } |
28 | 41 | ||
29 | /** | 42 | /** |
30 | * Update the interface information and buttons. | 43 | * Update the interface information and buttons. |
31 | * @param Intarface *i the interface to update (should be the one we already | 44 | * @param Intarface *i the interface to update (should be the one we already |
32 | * know about). | 45 | * know about). |
33 | */ | 46 | */ |
34 | void InterfaceInformationImp::updateInterface(Interface *){ | 47 | void InterfaceInformationImp::updateInterface(Interface *){ |
35 | if(interface->getStatus()){ | 48 | if(interface->getStatus()){ |
36 | startButton->setEnabled(false); | 49 | startButton->setEnabled(false); |
37 | stopButton->setEnabled(true); | 50 | stopButton->setEnabled(true); |
38 | restartButton->setEnabled(true); | 51 | restartButton->setEnabled(true); |
39 | } | 52 | } |
40 | else{ | 53 | else{ |
41 | startButton->setEnabled(true); | 54 | startButton->setEnabled(true); |
42 | stopButton->setEnabled(false); | 55 | stopButton->setEnabled(false); |
43 | restartButton->setEnabled(false); | 56 | restartButton->setEnabled(false); |
44 | } | 57 | } |
45 | macAddressLabel->setText(interface->getMacAddress()); | 58 | macAddressLabel->setText(interface->getMacAddress()); |
46 | ipAddressLabel->setText(interface->getIp()); | 59 | ipAddressLabel->setText(interface->getIp()); |
47 | subnetMaskLabel->setText(interface->getSubnetMask()); | 60 | subnetMaskLabel->setText(interface->getSubnetMask()); |
48 | broadcastLabel->setText(interface->getBroadcast()); | 61 | broadcastLabel->setText(interface->getBroadcast()); |
49 | } | 62 | } |
50 | 63 | ||
51 | /** | 64 | /** |
52 | * Create the advanced widget. Fill it with the current interface's information. | 65 | * Create the advanced widget. Fill it with the current interface's information. |
53 | * Display it. | 66 | * Display it. |
54 | */ | 67 | */ |
55 | void InterfaceInformationImp::advanced(){ | 68 | void InterfaceInformationImp::advanced(){ |
56 | InterfaceAdvanced *a = new InterfaceAdvanced(this, "InterfaceAdvanced", Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); | 69 | InterfaceAdvanced *a = new InterfaceAdvanced(this, "InterfaceAdvanced", Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); |
57 | a->interfaceName->setText(interface->getInterfaceName()); | 70 | a->interfaceName->setText(interface->getInterfaceName()); |
58 | a->macAddressLabel->setText(interface->getMacAddress()); | 71 | a->macAddressLabel->setText(interface->getMacAddress()); |
59 | a->ipAddressLabel->setText(interface->getIp()); | 72 | a->ipAddressLabel->setText(interface->getIp()); |
60 | a->subnetMaskLabel->setText(interface->getSubnetMask()); | 73 | a->subnetMaskLabel->setText(interface->getSubnetMask()); |
61 | a->broadcastLabel->setText(interface->getBroadcast()); | 74 | a->broadcastLabel->setText(interface->getBroadcast()); |
62 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); | 75 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); |
63 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); | 76 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); |
64 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); | 77 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); |
65 | a->dhcpInformation->setEnabled(interface->isDhcp()); | 78 | a->dhcpInformation->setEnabled(interface->isDhcp()); |
66 | a->showMaximized(); | 79 | a->showMaximized(); |
67 | } | 80 | } |
68 | 81 | ||
69 | /** | 82 | /** |
70 | * Messages from the interface if start/stop went as planned. | 83 | * Messages from the interface if start/stop went as planned. |
71 | * Purly for user feedback. | 84 | * Purly for user feedback. |
72 | * @param message the message to display. | 85 | * @param message the message to display. |
73 | */ | 86 | */ |
74 | void InterfaceInformationImp::showMessage(const QString &message){ | 87 | void InterfaceInformationImp::showMessage(const QString &message){ |
88 | if (CheckBoxSilent->isChecked()) return; | ||
75 | QMessageBox::information(this, "Message", message, QMessageBox::Ok); | 89 | QMessageBox::information(this, "Message", message, QMessageBox::Ok); |
76 | } | 90 | } |
77 | 91 | ||
78 | // infoimp.cpp | 92 | // infoimp.cpp |
79 | 93 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformationimp.h b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h index 65cdfe0..9c93d1d 100644 --- a/noncore/settings/networksettings/interfaces/interfaceinformationimp.h +++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h | |||
@@ -1,28 +1,28 @@ | |||
1 | #ifndef INTERFACEINFORMATIONIMP_H | 1 | #ifndef INTERFACEINFORMATIONIMP_H |
2 | #define INTERFACEINFORMATIONIMP_H | 2 | #define INTERFACEINFORMATIONIMP_H |
3 | 3 | ||
4 | #include "interfaceinformation.h" | 4 | #include "interfaceinformation.h" |
5 | #include "interface.h" | 5 | #include "interface.h" |
6 | 6 | ||
7 | class InterfaceInformationImp : public InterfaceInformation { | 7 | class InterfaceInformationImp : public InterfaceInformation { |
8 | 8 | ||
9 | Q_OBJECT | 9 | Q_OBJECT |
10 | 10 | ||
11 | public: | 11 | public: |
12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); | 12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); |
13 | ~InterfaceInformationImp(){}; | 13 | ~InterfaceInformationImp(); |
14 | 14 | ||
15 | private slots: | 15 | private slots: |
16 | void advanced(); | 16 | void advanced(); |
17 | void updateInterface(Interface *i); | 17 | void updateInterface(Interface *i); |
18 | void showMessage(const QString &message); | 18 | void showMessage(const QString &message); |
19 | 19 | ||
20 | private: | 20 | private: |
21 | Interface *interface; | 21 | Interface *interface; |
22 | 22 | ||
23 | }; | 23 | }; |
24 | 24 | ||
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | // addserviceimp.h | 27 | // addserviceimp.h |
28 | 28 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index 71d0cf5..436e449 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp | |||
@@ -1,678 +1,712 @@ | |||
1 | #include "interfaces.h" | 1 | #include "interfaces.h" |
2 | 2 | ||
3 | #include <qcheckbox.h> | ||
3 | #include <qfile.h> | 4 | #include <qfile.h> |
4 | #include <qtextstream.h> | 5 | #include <qtextstream.h> |
5 | #include <qregexp.h> | 6 | #include <qregexp.h> |
6 | 7 | ||
7 | // The three stanza's | 8 | // The three stanza's |
8 | #define AUTO "auto" | 9 | #define AUTO "auto" |
9 | #define IFACE "iface" | 10 | #define IFACE "iface" |
10 | #define MAPPING "mapping" | 11 | #define MAPPING "mapping" |
11 | 12 | ||
12 | /** | 13 | /** |
13 | * Constructor. Reads in the interfaces file and then split the file up by | 14 | * Constructor. Reads in the interfaces file and then split the file up by |
14 | * the \n for interfaces variable. | 15 | * the \n for interfaces variable. |
15 | * @param useInterfacesFile if an interface file other then the default is | 16 | * @param useInterfacesFile if an interface file other then the default is |
16 | * desired to be used it should be passed in. | 17 | * desired to be used it should be passed in. |
17 | */ | 18 | */ |
18 | Interfaces::Interfaces(QString useInterfacesFile){ | 19 | Interfaces::Interfaces(QString useInterfacesFile){ |
19 | acceptedFamily.append(INTERFACES_FAMILY_INET); | 20 | acceptedFamily.append(INTERFACES_FAMILY_INET); |
20 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | 21 | acceptedFamily.append(INTERFACES_FAMILY_IPX); |
21 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | 22 | acceptedFamily.append(INTERFACES_FAMILY_INET6); |
22 | 23 | ||
23 | interfacesFile = useInterfacesFile; | 24 | interfacesFile = useInterfacesFile; |
24 | QFile file(interfacesFile); | 25 | QFile file(interfacesFile); |
25 | if (!file.open(IO_ReadOnly)){ | 26 | if (!file.open(IO_ReadOnly)){ |
26 | qDebug("Interfaces: Can't open file: %s for reading.", interfacesFile.latin1() ); | 27 | qDebug("Interfaces: Can't open file: %s for reading.", interfacesFile.latin1() ); |
27 | currentIface = interfaces.end(); | 28 | currentIface = interfaces.end(); |
28 | currentMapping = interfaces.end(); | 29 | currentMapping = interfaces.end(); |
29 | return; | 30 | return; |
30 | } | 31 | } |
31 | QTextStream stream( &file ); | 32 | QTextStream stream( &file ); |
32 | QString line; | 33 | QString line; |
33 | while ( !stream.eof() ) { | 34 | while ( !stream.eof() ) { |
34 | line += stream.readLine(); | 35 | line += stream.readLine(); |
35 | line += "\n"; | 36 | line += "\n"; |
36 | } | 37 | } |
37 | file.close(); | 38 | file.close(); |
38 | interfaces = QStringList::split("\n", line, true); | 39 | interfaces = QStringList::split("\n", line, true); |
39 | 40 | ||
40 | currentIface = interfaces.end(); | 41 | currentIface = interfaces.end(); |
41 | currentMapping = interfaces.end(); | 42 | currentMapping = interfaces.end(); |
42 | } | 43 | } |
43 | 44 | ||
44 | 45 | ||
45 | /** | 46 | /** |
46 | * Get a list of all interfaces in the interface file. Usefull for | 47 | * Get a list of all interfaces in the interface file. Usefull for |
47 | * hardware that is not currently connected such as an 802.11b card | 48 | * hardware that is not currently connected such as an 802.11b card |
48 | * not plugged in, but configured for when it is plugged in. | 49 | * not plugged in, but configured for when it is plugged in. |
49 | * @return Return string list of interfaces. | 50 | * @return Return string list of interfaces. |
50 | **/ | 51 | **/ |
51 | QStringList Interfaces::getInterfaceList(){ | 52 | QStringList Interfaces::getInterfaceList(){ |
52 | QStringList list; | 53 | QStringList list; |
53 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 54 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
54 | QString line = (*it).simplifyWhiteSpace(); | 55 | QString line = (*it).simplifyWhiteSpace(); |
55 | if(line.contains(IFACE) && line.at(0) != '#'){ | 56 | if(line.contains(IFACE) && line.at(0) != '#'){ |
56 | line = line.mid(QString(IFACE).length() +1, line.length()); | 57 | line = line.mid(QString(IFACE).length() +1, line.length()); |
57 | line = line.simplifyWhiteSpace(); | 58 | line = line.simplifyWhiteSpace(); |
58 | int findSpace = line.find(" "); | 59 | int findSpace = line.find(" "); |
59 | if( findSpace >= 0){ | 60 | if( findSpace >= 0){ |
60 | line = line.mid(0, findSpace); | 61 | line = line.mid(0, findSpace); |
61 | list.append(line); | 62 | list.append(line); |
62 | } | 63 | } |
63 | } | 64 | } |
64 | } | 65 | } |
65 | return list; | 66 | return list; |
66 | } | 67 | } |
67 | 68 | ||
68 | /** | 69 | /** |
69 | * Find out if interface is in an "auto" group or not. | 70 | * Find out if interface is in an "auto" group or not. |
70 | * Report any duplicates such as eth0 being in two differnt auto's | 71 | * Report any duplicates such as eth0 being in two differnt auto's |
71 | * @param interface interface to check to see if it is on or not. | 72 | * @param interface interface to check to see if it is on or not. |
72 | * @return true is interface is in auto | 73 | * @return true is interface is in auto |
73 | */ | 74 | */ |
74 | bool Interfaces::isAuto(const QString &interface) const { | 75 | bool Interfaces::isAuto(const QString &interface) const { |
75 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | 76 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); |
76 | QStringList awi = autoLines.grep(QRegExp(interface)); | 77 | QStringList awi = autoLines.grep(QRegExp(interface)); |
77 | if(awi.count() > 1) | 78 | if(awi.count() > 1) |
78 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); | 79 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); |
79 | return awi.count() > 0; | 80 | return awi.count() > 0; |
80 | } | 81 | } |
81 | 82 | ||
82 | /** | 83 | /** |
83 | * Attempt to set the auto option for interface to setAuto. | 84 | * Attempt to set the auto option for interface to setAuto. |
84 | * @param interface the interface to set | 85 | * @param interface the interface to set |
85 | * @param setAuto the value to set interface to. | 86 | * @param setAuto the value to set interface to. |
86 | * @return false if already set to setAuto. | 87 | * @return false if already set to setAuto. |
87 | * */ | 88 | * */ |
88 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ | 89 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ |
89 | // Don't need to set it if it is already set. | 90 | // Don't need to set it if it is already set. |
90 | if(isAuto(interface) == setAuto) | 91 | if(isAuto(interface) == setAuto) |
91 | return false; | 92 | return false; |
92 | 93 | ||
93 | bool changed = false; | 94 | bool changed = false; |
94 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
95 | if((*it).contains(AUTO)){ | 96 | if((*it).contains(AUTO)){ |
96 | //We know that they are not in any group so let add to this auto. | 97 | //We know that they are not in any group so let add to this auto. |
97 | if(setAuto){ | 98 | if(setAuto){ |
98 | (*it) = (*it) += " " + interface; | 99 | (*it) = (*it) += " " + interface; |
99 | // Don't care to have such thins as: auto eth0 lo usb0 | 100 | // Don't care to have such thins as: auto eth0 lo usb0 |
100 | (*it) = (*it).simplifyWhiteSpace(); | 101 | (*it) = (*it).simplifyWhiteSpace(); |
101 | changed = true; | 102 | changed = true; |
102 | break; | 103 | break; |
103 | } | 104 | } |
104 | // else see if we need to remove from this one | 105 | // else see if we need to remove from this one |
105 | else{ | 106 | else{ |
106 | if((*it).contains(interface)){ | 107 | if((*it).contains(interface)){ |
107 | (*it) = (*it).replace(QRegExp(interface), ""); | 108 | (*it) = (*it).replace(QRegExp(interface), ""); |
108 | // if AUTO is the only thing left clear the line | 109 | // if AUTO is the only thing left clear the line |
109 | if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) | 110 | if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) |
110 | (*it) = ""; | 111 | (*it) = ""; |
111 | changed = true; | 112 | changed = true; |
112 | // Don't break because we want to make sure we remove all cases. | 113 | // Don't break because we want to make sure we remove all cases. |
113 | } | 114 | } |
114 | } | 115 | } |
115 | } | 116 | } |
116 | } | 117 | } |
117 | // In the case where there is no AUTO field add one. | 118 | // In the case where there is no AUTO field add one. |
118 | if(!changed && setAuto) | 119 | if(!changed && setAuto) |
119 | interfaces.append(QString(AUTO" %1").arg(interface)); | 120 | interfaces.append(QString(AUTO" %1").arg(interface)); |
120 | return true; | 121 | return true; |
121 | } | 122 | } |
122 | 123 | ||
123 | /** | 124 | /** |
124 | * Set the current interface to interface. This needs to be done before you | 125 | * Set the current interface to interface. This needs to be done before you |
125 | * can call getFamily(), getMethod, and get/setOption(). | 126 | * can call getFamily(), getMethod, and get/setOption(). |
126 | * @param interface the name of the interface to set. All whitespace is | 127 | * @param interface the name of the interface to set. All whitespace is |
127 | * removed from the interface name. | 128 | * removed from the interface name. |
128 | * @return bool true if it is successfull. | 129 | * @return bool true if it is successfull. |
129 | */ | 130 | */ |
130 | bool Interfaces::setInterface(QString interface){ | 131 | bool Interfaces::setInterface(QString interface){ |
131 | interface = interface.simplifyWhiteSpace(); | 132 | interface = interface.simplifyWhiteSpace(); |
132 | interface = interface.replace(QRegExp(" "), ""); | 133 | interface = interface.replace(QRegExp(" "), ""); |
133 | return setStanza(IFACE, interface, currentIface); | 134 | return setStanza(IFACE, interface, currentIface); |
134 | } | 135 | } |
135 | 136 | ||
136 | /** | 137 | /** |
137 | * A quick helper funtion to see if the current interface is set. | 138 | * A quick helper funtion to see if the current interface is set. |
138 | * @return bool true if set, false otherwise. | 139 | * @return bool true if set, false otherwise. |
139 | */ | 140 | */ |
140 | bool Interfaces::isInterfaceSet() const { | 141 | bool Interfaces::isInterfaceSet() const { |
141 | return (interfaces.end() != currentIface); | 142 | return (interfaces.end() != currentIface); |
142 | } | 143 | } |
143 | 144 | ||
144 | /** | 145 | /** |
145 | * Add a new interface of with the settings - family and method | 146 | * Add a new interface of with the settings - family and method |
146 | * @param interface the name of the interface to set. All whitespace is | 147 | * @param interface the name of the interface to set. All whitespace is |
147 | * removed from the interface name. | 148 | * removed from the interface name. |
148 | * @param family the family of this interface inet or inet, ipx or inet6 | 149 | * @param family the family of this interface inet or inet, ipx or inet6 |
149 | * Must of one of the families defined in interfaces.h | 150 | * Must of one of the families defined in interfaces.h |
150 | * @param method for the family. see interfaces man page for family methods. | 151 | * @param method for the family. see interfaces man page for family methods. |
151 | * @return true if successfull. | 152 | * @return true if successfull. |
152 | */ | 153 | */ |
153 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ | 154 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ |
155 | qDebug("Interfaces::addInterface(%s)",interface.latin1()); | ||
154 | if(0 == acceptedFamily.contains(family)) | 156 | if(0 == acceptedFamily.contains(family)) |
155 | return false; | 157 | return false; |
156 | QString newInterface = interface.simplifyWhiteSpace(); | 158 | QString newInterface = interface.simplifyWhiteSpace(); |
157 | newInterface = newInterface.replace(QRegExp(" "), ""); | 159 | newInterface = newInterface.replace(QRegExp(" "), ""); |
158 | interfaces.append(""); | 160 | interfaces.append(""); |
159 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); | 161 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); |
160 | return true; | 162 | return true; |
161 | } | 163 | } |
162 | 164 | ||
163 | /** | 165 | /** |
164 | * Copies interface with name interface to name newInterface | 166 | * Copies interface with name interface to name newInterface |
165 | * @param newInterface name of the new interface. | 167 | * @param newInterface name of the new interface. |
166 | * @return bool true if successfull | 168 | * @return bool true if successfull |
167 | */ | 169 | */ |
168 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ | 170 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ |
171 | qDebug("copy interface %s to %s", interface.latin1(), newInterface.latin1()); | ||
169 | if(!setInterface(interface)) | 172 | if(!setInterface(interface)) |
170 | return false; | 173 | return false; |
171 | 174 | ||
172 | // Store the old interface and bump past the stanza line. | 175 | // Store the old interface and bump past the stanza line. |
173 | QStringList::Iterator it = currentIface; | 176 | QStringList::Iterator it = currentIface; |
174 | it++; | 177 | it++; |
175 | 178 | ||
176 | // Add the new interface | 179 | // Add the new interface |
177 | bool error; | 180 | bool error; |
178 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | 181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); |
179 | if(!setInterface(newInterface)) | 182 | if(!setInterface(newInterface)) |
180 | return false; | 183 | return false; |
181 | 184 | ||
182 | QStringList::Iterator newIface = currentIface; | 185 | QStringList::Iterator newIface = currentIface; |
183 | newIface++; | 186 | newIface++; |
184 | 187 | ||
185 | // Copy all of the lines | 188 | // Copy all of the lines |
186 | for ( ; it != interfaces.end(); ++it ){ | 189 | for ( ; it != interfaces.end(); ++it ){ |
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | 190 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) |
188 | break; | 191 | break; |
189 | newIface = interfaces.insert(newIface, *it); | 192 | newIface = interfaces.insert(newIface, *it); |
190 | } | 193 | } |
191 | 194 | ||
192 | return true; | 195 | return true; |
193 | } | 196 | } |
194 | 197 | ||
195 | /** | 198 | /** |
196 | * Remove the currently selected interface and all of its options. | 199 | * Remove the currently selected interface and all of its options. |
197 | * @return bool if successfull or not. | 200 | * @return bool if successfull or not. |
198 | */ | 201 | */ |
199 | bool Interfaces::removeInterface(){ | 202 | bool Interfaces::removeInterface(){ |
200 | return removeStanza(currentIface); | 203 | return removeStanza(currentIface); |
201 | } | 204 | } |
202 | 205 | ||
203 | /** | 206 | /** |
204 | * Gets the hardware name of the interface that is currently selected. | 207 | * Gets the hardware name of the interface that is currently selected. |
205 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
206 | * @param error set to true if any error occurs, false otherwise. | 209 | * @param error set to true if any error occurs, false otherwise. |
207 | */ | 210 | */ |
208 | QString Interfaces::getInterfaceName(bool &error){ | 211 | QString Interfaces::getInterfaceName(bool &error){ |
209 | if(currentIface == interfaces.end()){ | 212 | if(currentIface == interfaces.end()){ |
210 | error = true; | 213 | error = true; |
211 | return QString(); | 214 | return QString(); |
212 | } | 215 | } |
213 | QString line = (*currentIface); | 216 | QString line = (*currentIface); |
214 | line = line.mid(QString(IFACE).length() +1, line.length()); | 217 | line = line.mid(QString(IFACE).length() +1, line.length()); |
215 | line = line.simplifyWhiteSpace(); | 218 | line = line.simplifyWhiteSpace(); |
216 | int findSpace = line.find(" "); | 219 | int findSpace = line.find(" "); |
217 | if( findSpace < 0){ | 220 | if( findSpace < 0){ |
218 | error = true; | 221 | error = true; |
219 | return QString(); | 222 | return QString(); |
220 | } | 223 | } |
221 | error = false; | 224 | error = false; |
222 | return line.mid(0, findSpace); | 225 | return line.mid(0, findSpace); |
223 | } | 226 | } |
224 | 227 | ||
225 | /** | 228 | /** |
226 | * Gets the family name of the interface that is currently selected. | 229 | * Gets the family name of the interface that is currently selected. |
227 | * @return QString name of the family (inet, inet6, ipx). | 230 | * @return QString name of the family (inet, inet6, ipx). |
228 | * @param error set to true if any error occurs, false otherwise. | 231 | * @param error set to true if any error occurs, false otherwise. |
229 | */ | 232 | */ |
230 | QString Interfaces::getInterfaceFamily(bool &error){ | 233 | QString Interfaces::getInterfaceFamily(bool &error){ |
231 | QString name = getInterfaceName(error); | 234 | QString name = getInterfaceName(error); |
232 | if(error) | 235 | if(error) |
233 | return QString(); | 236 | return QString(); |
234 | QString line = (*currentIface); | 237 | QString line = (*currentIface); |
235 | line = line.mid(QString(IFACE).length() +1, line.length()); | 238 | line = line.mid(QString(IFACE).length() +1, line.length()); |
236 | line = line.mid(name.length()+1, line.length()); | 239 | line = line.mid(name.length()+1, line.length()); |
237 | line = line.simplifyWhiteSpace(); | 240 | line = line.simplifyWhiteSpace(); |
238 | int findSpace = line.find(" "); | 241 | int findSpace = line.find(" "); |
239 | if( findSpace < 0){ | 242 | if( findSpace < 0){ |
240 | error = true; | 243 | error = true; |
241 | return QString(); | 244 | return QString(); |
242 | } | 245 | } |
243 | error = false; | 246 | error = false; |
244 | return line.mid(0, findSpace); | 247 | return line.mid(0, findSpace); |
245 | } | 248 | } |
246 | 249 | ||
247 | /** | 250 | /** |
248 | * Gets the method of the interface that is currently selected. | 251 | * Gets the method of the interface that is currently selected. |
249 | * @return QString name of the method such as staic or dhcp. | 252 | * @return QString name of the method such as staic or dhcp. |
250 | * See the man page of interfaces for possible methods depending on the family. | 253 | * See the man page of interfaces for possible methods depending on the family. |
251 | * @param error set to true if any error occurs, false otherwise. | 254 | * @param error set to true if any error occurs, false otherwise. |
252 | */ | 255 | */ |
253 | QString Interfaces::getInterfaceMethod(bool &error){ | 256 | QString Interfaces::getInterfaceMethod(bool &error){ |
254 | QString name = getInterfaceName(error); | 257 | QString name = getInterfaceName(error); |
255 | if(error) | 258 | if(error) |
256 | return QString(); | 259 | return QString(); |
257 | QString family = getInterfaceFamily(error); | 260 | QString family = getInterfaceFamily(error); |
258 | if(error) | 261 | if(error) |
259 | return QString(); | 262 | return QString(); |
260 | QString line = (*currentIface); | 263 | QString line = (*currentIface); |
261 | line = line.mid(QString(IFACE).length()+1, line.length()); | 264 | line = line.mid(QString(IFACE).length()+1, line.length()); |
262 | line = line.mid(name.length()+1, line.length()); | 265 | line = line.mid(name.length()+1, line.length()); |
263 | line = line.mid(family.length()+1, line.length()); | 266 | line = line.mid(family.length()+1, line.length()); |
264 | line = line.simplifyWhiteSpace(); | 267 | line = line.simplifyWhiteSpace(); |
265 | error = false; | 268 | error = false; |
266 | return line; | 269 | return line; |
267 | } | 270 | } |
268 | 271 | ||
269 | /** | 272 | /** |
270 | * Sets the interface name to newName. | 273 | * Sets the interface name to newName. |
271 | * @param newName the new name of the interface. All whitespace is removed. | 274 | * @param newName the new name of the interface. All whitespace is removed. |
272 | * @return bool true if successfull. | 275 | * @return bool true if successfull. |
273 | */ | 276 | */ |
274 | bool Interfaces::setInterfaceName(const QString &newName){ | 277 | bool Interfaces::setInterfaceName(const QString &newName){ |
278 | qDebug("setInterfaceName %s", newName.latin1()); | ||
275 | if(currentIface == interfaces.end()) | 279 | if(currentIface == interfaces.end()) |
276 | return false; | 280 | return false; |
277 | QString name = newName.simplifyWhiteSpace(); | 281 | QString name = newName.simplifyWhiteSpace(); |
278 | name = name.replace(QRegExp(" "), ""); | 282 | name = name.replace(QRegExp(" "), ""); |
279 | bool returnValue = false; | 283 | bool returnValue = false; |
280 | (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); | 284 | QString tmp = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); |
285 | qDebug("setting %s",tmp.latin1()); | ||
286 | |||
287 | (*currentIface) = tmp; | ||
281 | return !returnValue; | 288 | return !returnValue; |
282 | } | 289 | } |
283 | 290 | ||
284 | /** | 291 | /** |
285 | * Sets the interface family to newName. | 292 | * Sets the interface family to newName. |
286 | * @param newName the new name of the interface. Must be one of the families | 293 | * @param newName the new name of the interface. Must be one of the families |
287 | * defined in the interfaces.h file. | 294 | * defined in the interfaces.h file. |
288 | * @return bool true if successfull. | 295 | * @return bool true if successfull. |
289 | */ | 296 | */ |
290 | bool Interfaces::setInterfaceFamily(const QString &newName){ | 297 | bool Interfaces::setInterfaceFamily(const QString &newName){ |
291 | if(currentIface == interfaces.end()) | 298 | if(currentIface == interfaces.end()) |
292 | return false; | 299 | return false; |
293 | if(acceptedFamily.contains(newName)==0) | 300 | if(acceptedFamily.contains(newName)==0) |
294 | return false; | 301 | return false; |
295 | bool returnValue = false; | 302 | bool returnValue = false; |
296 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | 303 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); |
297 | return !returnValue; | 304 | return !returnValue; |
298 | } | 305 | } |
299 | 306 | ||
300 | /** | 307 | /** |
301 | * Sets the interface method to newName | 308 | * Sets the interface method to newName |
302 | * @param newName the new name of the interface | 309 | * @param newName the new name of the interface |
303 | * @return bool true if successfull. | 310 | * @return bool true if successfull. |
304 | */ | 311 | */ |
305 | bool Interfaces::setInterfaceMethod(const QString &newName){ | 312 | bool Interfaces::setInterfaceMethod(const QString &newName){ |
306 | if(currentIface == interfaces.end()) | 313 | if(currentIface == interfaces.end()) |
307 | return false; | 314 | return false; |
308 | bool returnValue = false; | 315 | bool returnValue = false; |
309 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | 316 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); |
310 | return !returnValue; | 317 | return !returnValue; |
311 | } | 318 | } |
312 | 319 | ||
313 | /** | 320 | /** |
314 | * Get a value for an option in the currently selected interface. For example | 321 | * Get a value for an option in the currently selected interface. For example |
315 | * calling getInterfaceOption("address") on the following stanza would | 322 | * calling getInterfaceOption("address") on the following stanza would |
316 | * return 192.168.1.1. | 323 | * return 192.168.1.1. |
317 | * iface eth0 static | 324 | * iface eth0 static |
318 | * address 192.168.1.1 | 325 | * address 192.168.1.1 |
319 | * @param option the options to get the value. | 326 | * @param option the options to get the value. |
320 | * @param error set to true if any error occurs, false otherwise. | 327 | * @param error set to true if any error occurs, false otherwise. |
321 | * @return QString the options value. QString::null if error == true | 328 | * @return QString the options value. QString::null if error == true |
322 | */ | 329 | */ |
323 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ | 330 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ |
324 | return getOption(currentIface, option, error); | 331 | return getOption(currentIface, option, error); |
325 | } | 332 | } |
326 | 333 | ||
327 | /** | 334 | /** |
328 | * Set a value for an option in the currently selected interface. If option | 335 | * Set a value for an option in the currently selected interface. If option |
329 | * doesn't exist then it is added along with the value. | 336 | * doesn't exist then it is added along with the value. |
337 | * If value isEmpty() then we will remove the option | ||
338 | * | ||
330 | * @param option the options to set the value. | 339 | * @param option the options to set the value. |
331 | * @param value the value that option should be set to. | 340 | * @param value the value that option should be set to. |
332 | * @param error set to true if any error occurs, false otherwise. | 341 | * @param error set to true if any error occurs, false otherwise. |
333 | * @return QString the options value. QString::null if error == true | 342 | * @return QString the options value. QString::null if error == true |
334 | */ | 343 | */ |
335 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ | 344 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ |
336 | return setOption(currentIface, option, value); | 345 | if( value.stripWhiteSpace().isEmpty() ) |
346 | return removeInterfaceOption( option ); | ||
347 | |||
348 | qDebug("iface >%s< option >%s< value >%s<", (*currentIface).latin1(), option.latin1(),value.latin1()); | ||
349 | return setOption(currentIface, option, value); | ||
337 | } | 350 | } |
338 | 351 | ||
339 | /** | 352 | /** |
340 | * Removes a value for an option in the currently selected interface. | 353 | * Removes a value for an option in the currently selected interface. |
341 | * @param option the options to set the value. | 354 | * @param option the options to set the value. |
342 | * @param error set to true if any error occurs, false otherwise. | 355 | * @param error set to true if any error occurs, false otherwise. |
343 | * @return QString the options value. QString::null if error == true | 356 | * @return QString the options value. QString::null if error == true |
344 | */ | 357 | */ |
345 | bool Interfaces::removeInterfaceOption(const QString &option){ | 358 | bool Interfaces::removeInterfaceOption(const QString &option){ |
346 | return removeOption(currentIface, option); | 359 | return removeOption(currentIface, option); |
347 | } | 360 | } |
348 | 361 | ||
349 | /** | 362 | /** |
350 | * Removes a value for an option in the currently selected interface. | 363 | * Removes a value for an option in the currently selected interface. |
351 | * @param option the options to set the value. | 364 | * @param option the options to set the value. |
352 | * @param value the value that option should be set to. | 365 | * @param value the value that option should be set to. |
353 | * @param error set to true if any error occurs, false otherwise. | 366 | * @param error set to true if any error occurs, false otherwise. |
354 | * @return QString the options value. QString::null if error == true | 367 | * @return QString the options value. QString::null if error == true |
355 | */ | 368 | */ |
356 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ | 369 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ |
357 | return removeOption(currentIface, option, value); | 370 | return removeOption(currentIface, option, value); |
358 | } | 371 | } |
359 | 372 | ||
360 | /** | 373 | /** |
361 | * Removes all of the options from the currently selected interface. | 374 | * Removes all of the options from the currently selected interface. |
362 | * @return bool error if if successfull | 375 | * @return bool error if if successfull |
363 | */ | 376 | */ |
364 | bool Interfaces::removeAllInterfaceOptions(){ | 377 | bool Interfaces::removeAllInterfaceOptions(){ |
365 | return removeAllOptions(currentIface); | 378 | return removeAllOptions(currentIface); |
366 | } | 379 | } |
367 | 380 | ||
368 | /** | 381 | /** |
369 | * Set the current map to interface's map. This needs to be done before you | 382 | * Set the current map to interface's map. This needs to be done before you |
370 | * can call addMapping(), set/getMap(), and get/setScript(). | 383 | * can call addMapping(), set/getMap(), and get/setScript(). |
371 | * @param interface the name of the interface to set. All whitespace is | 384 | * @param interface the name of the interface to set. All whitespace is |
372 | * removed from the interface name. | 385 | * removed from the interface name. |
373 | * @return bool true if it is successfull. | 386 | * @return bool true if it is successfull. |
374 | */ | 387 | */ |
375 | bool Interfaces::setMapping(const QString &interface){ | 388 | bool Interfaces::setMapping(const QString &interface){ |
376 | QString interfaceName = interface.simplifyWhiteSpace(); | 389 | QString interfaceName = interface.simplifyWhiteSpace(); |
377 | interfaceName = interfaceName.replace(QRegExp(" "), ""); | 390 | interfaceName = interfaceName.replace(QRegExp(" "), ""); |
378 | return setStanza(MAPPING, interfaceName, currentMapping); | 391 | return setStanza(MAPPING, interfaceName, currentMapping); |
379 | } | 392 | } |
380 | 393 | ||
381 | /** | 394 | /** |
382 | * Adds a new Mapping to the interfaces file with interfaces. | 395 | * Adds a new Mapping to the interfaces file with interfaces. |
383 | * @param interface the name(s) of the interfaces to set to this mapping | 396 | * @param interface the name(s) of the interfaces to set to this mapping |
384 | */ | 397 | */ |
385 | void Interfaces::addMapping(const QString &option){ | 398 | void Interfaces::addMapping(const QString &option){ |
386 | interfaces.append(""); | 399 | interfaces.append(""); |
387 | interfaces.append(QString(MAPPING " %1").arg(option)); | 400 | interfaces.append(QString(MAPPING " %1").arg(option)); |
388 | } | 401 | } |
389 | 402 | ||
390 | /** | 403 | /** |
391 | * Remove the currently selected map and all of its options. | 404 | * Remove the currently selected map and all of its options. |
392 | * @return bool if successfull or not. | 405 | * @return bool if successfull or not. |
393 | */ | 406 | */ |
394 | bool Interfaces::removeMapping(){ | 407 | bool Interfaces::removeMapping(){ |
395 | return removeStanza(currentMapping); | 408 | return removeStanza(currentMapping); |
396 | } | 409 | } |
397 | 410 | ||
398 | /** | 411 | /** |
399 | * Set a map option within a mapping. | 412 | * Set a map option within a mapping. |
400 | * @param map map to use | 413 | * @param map map to use |
401 | * @param value value to go with map | 414 | * @param value value to go with map |
402 | * @return bool true if it is successfull. | 415 | * @return bool true if it is successfull. |
403 | */ | 416 | */ |
404 | bool Interfaces::setMap(const QString &map, const QString &value){ | 417 | bool Interfaces::setMap(const QString &map, const QString &value){ |
405 | return setOption(currentMapping, map, value); | 418 | return setOption(currentMapping, map, value); |
406 | } | 419 | } |
407 | 420 | ||
408 | /** | 421 | /** |
409 | * Removes a map option within a mapping. | 422 | * Removes a map option within a mapping. |
410 | * @param map map to use | 423 | * @param map map to use |
411 | * @param value value to go with map | 424 | * @param value value to go with map |
412 | * @return bool true if it is successfull. | 425 | * @return bool true if it is successfull. |
413 | */ | 426 | */ |
414 | bool Interfaces::removeMap(const QString &map, const QString &value){ | 427 | bool Interfaces::removeMap(const QString &map, const QString &value){ |
415 | return removeOption(currentMapping, map, value); | 428 | return removeOption(currentMapping, map, value); |
416 | } | 429 | } |
417 | 430 | ||
418 | /** | 431 | /** |
419 | * Get a map value within a mapping. | 432 | * Get a map value within a mapping. |
420 | * @param map map to get value of | 433 | * @param map map to get value of |
421 | * @param bool true if it is successfull. | 434 | * @param bool true if it is successfull. |
422 | * @return value that goes to the map | 435 | * @return value that goes to the map |
423 | */ | 436 | */ |
424 | QString Interfaces::getMap(const QString &map, bool &error){ | 437 | QString Interfaces::getMap(const QString &map, bool &error){ |
425 | return getOption(currentMapping, map, error); | 438 | return getOption(currentMapping, map, error); |
426 | } | 439 | } |
427 | 440 | ||
428 | /** | 441 | /** |
429 | * Sets a script value of the current mapping to argument. | 442 | * Sets a script value of the current mapping to argument. |
430 | * @param argument the script name. | 443 | * @param argument the script name. |
431 | * @return true if successfull. | 444 | * @return true if successfull. |
432 | */ | 445 | */ |
433 | bool Interfaces::setScript(const QString &argument){ | 446 | bool Interfaces::setScript(const QString &argument){ |
434 | return setOption(currentMapping, "script", argument); | 447 | return setOption(currentMapping, "script", argument); |
435 | } | 448 | } |
436 | 449 | ||
437 | /** | 450 | /** |
438 | * @param error true if could not retrieve the current script argument. | 451 | * @param error true if could not retrieve the current script argument. |
439 | * @return QString the argument of the script for the current mapping. | 452 | * @return QString the argument of the script for the current mapping. |
440 | */ | 453 | */ |
441 | QString Interfaces::getScript(bool &error){ | 454 | QString Interfaces::getScript(bool &error){ |
442 | return getOption(currentMapping, "script", error); | 455 | return getOption(currentMapping, "script", error); |
443 | } | 456 | } |
444 | 457 | ||
445 | 458 | ||
446 | 459 | ||
447 | /** | 460 | /** |
448 | * Helper function used to parse through the QStringList and put pointers in | 461 | * Helper function used to parse through the QStringList and put pointers in |
449 | * the correct place. | 462 | * the correct place. |
450 | * @param stanza The stanza (auto, iface, mapping) to look for. | 463 | * @param stanza The stanza (auto, iface, mapping) to look for. |
451 | * @param option string that must be in the stanza's main line. | 464 | * @param option string that must be in the stanza's main line. |
452 | * @param interator interator to place at location of stanza if successfull. | 465 | * @param interator interator to place at location of stanza if successfull. |
453 | * @return bool true if the stanza is found. | 466 | * @return bool true if the stanza is found. |
454 | */ | 467 | */ |
455 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ | 468 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ |
456 | bool found = false; | 469 | bool found = false; |
457 | iterator = interfaces.end(); | 470 | iterator = interfaces.end(); |
458 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 471 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
459 | QString line = (*it).simplifyWhiteSpace(); | 472 | QString line = (*it).simplifyWhiteSpace(); |
460 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ | 473 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ |
461 | uint point = line.find(option); | 474 | uint point = line.find(option); |
462 | bool valid = true; | 475 | bool valid = true; |
463 | if(point > 0){ | 476 | if(point > 0){ |
464 | // There are more chars in the line. check +1 | 477 | // There are more chars in the line. check +1 |
465 | if(line.at(point-1) != ' ') | 478 | if(line.at(point-1) != ' ') |
466 | valid = false; | 479 | valid = false; |
467 | } | 480 | } |
468 | point += option.length(); | 481 | point += option.length(); |
469 | if(point < line.length()-1){ | 482 | if(point < line.length()-1){ |
470 | // There are more chars in the line. check -1 | 483 | // There are more chars in the line. check -1 |
471 | if(line.at(point) != ' ') | 484 | if(line.at(point) != ' ') |
472 | valid = false; | 485 | valid = false; |
473 | } | 486 | } |
474 | if(valid){ | 487 | if(valid){ |
475 | if(found == true){ | 488 | if(found == true){ |
476 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 489 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); |
477 | } | 490 | } |
478 | found = true; | 491 | found = true; |
479 | iterator = it; | 492 | iterator = it; |
480 | } | 493 | } |
481 | } | 494 | } |
482 | } | 495 | } |
483 | return found; | 496 | return found; |
484 | } | 497 | } |
485 | 498 | ||
486 | /** | 499 | /** |
487 | * Sets a value of an option in a stanza | 500 | * Sets a value of an option in a stanza |
488 | * @param start the start of the stanza | 501 | * @param start the start of the stanza |
489 | * @param option the option to use when setting value. | 502 | * @param option the option to use when setting value. |
490 | * @return bool true if successfull, false otherwise. | 503 | * @return bool true if successfull, false otherwise. |
491 | */ | 504 | */ |
492 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ | 505 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
493 | if(start == interfaces.end()) | 506 | if(start == interfaces.end()) |
494 | return false; | 507 | return false; |
495 | 508 | qDebug("setting option"); | |
496 | bool found = false; | 509 | bool found = false; |
510 | bool replaced = false; | ||
511 | QStringList::Iterator insertAt = NULL; | ||
497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 512 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
498 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 513 | qDebug(" Interfaces::setOption got line >%s<",(*it).latin1()); |
499 | if(!found && value != ""){ | 514 | // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line |
500 | // Got to the end of the stanza without finding it, so append it. | 515 | // but since it works with an empty interfaces file I (tille) will not do anything more |
501 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | 516 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){ |
502 | } | 517 | if (found) break; |
503 | found = true; | 518 | // && it != start){ |
504 | break; | 519 | // if(!found && value != ""){ |
505 | } | 520 | // // Got to the end of the stanza without finding it, so append it. |
521 | // qDebug(" Got to the end of the stanza without finding it, so append it."); | ||
522 | // interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | ||
523 | // } | ||
524 | qDebug("found 1"); | ||
525 | // interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value)); | ||
526 | found = true; | ||
527 | insertAt = it; | ||
528 | |||
529 | } | ||
506 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 530 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
507 | // Found it in stanza so replace it. | 531 | // Found it in stanza so replace it. |
532 | qDebug("found 2"); | ||
508 | if(found) | 533 | if(found) |
509 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 534 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
510 | found = true; | 535 | found = true; |
536 | replaced = true; | ||
511 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 537 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
512 | } | 538 | } |
513 | } | 539 | } |
514 | if(!found){ | 540 | if(!found){ |
541 | qDebug("! found insert anyway"); | ||
515 | QStringList::Iterator p = start; | 542 | QStringList::Iterator p = start; |
516 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 543 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
517 | found = true; | 544 | found = true; |
518 | } | 545 | } |
546 | |||
547 | if(found && !replaced){ | ||
548 | qDebug("found iface but not the option so insert it here..."); | ||
549 | interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value)); | ||
550 | } | ||
519 | return found; | 551 | return found; |
520 | } | 552 | } |
521 | 553 | ||
522 | /** | 554 | /** |
523 | * Removes a stanza and all of its options | 555 | * Removes a stanza and all of its options |
524 | * @param stanza the stanza to remove | 556 | * @param stanza the stanza to remove |
525 | * @return bool true if successfull. | 557 | * @return bool true if successfull. |
526 | */ | 558 | */ |
527 | bool Interfaces::removeStanza(QStringList::Iterator &stanza){ | 559 | bool Interfaces::removeStanza(QStringList::Iterator &stanza){ |
528 | if(stanza == interfaces.end()) | 560 | if(stanza == interfaces.end()) |
529 | return false; | 561 | return false; |
530 | (*stanza) = ""; | 562 | (*stanza) = ""; |
531 | return removeAllOptions(stanza); | 563 | return removeAllOptions(stanza); |
532 | } | 564 | } |
533 | 565 | ||
534 | /** | 566 | /** |
535 | * Removes a option in a stanza | 567 | * Removes a option in a stanza |
536 | * @param start the start of the stanza | 568 | * @param start the start of the stanza |
537 | * @param option the option to remove | 569 | * @param option the option to remove |
538 | * @return bool true if successfull, false otherwise. | 570 | * @return bool true if successfull, false otherwise. |
539 | */ | 571 | */ |
540 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){ | 572 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){ |
541 | if(start == interfaces.end()) | 573 | if(start == interfaces.end()) |
542 | return false; | 574 | return false; |
543 | 575 | ||
544 | bool found = false; | 576 | bool found = false; |
545 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 577 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
546 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 578 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
547 | // got to the end without finding it | 579 | // got to the end without finding it |
548 | break; | 580 | break; |
549 | } | 581 | } |
550 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 582 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
551 | // Found it in stanza so replace it. | 583 | // Found it in stanza so replace it. |
552 | if(found) | 584 | if(found) |
553 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 585 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
554 | found = true; | 586 | found = true; |
555 | (*it) = ""; | 587 | it = interfaces.remove( it ); // we really want to remove the line |
588 | --it; // we do ++it later in the head of the for loop | ||
556 | } | 589 | } |
557 | } | 590 | } |
558 | return found; | 591 | return found; |
559 | } | 592 | } |
560 | 593 | ||
561 | /** | 594 | /** |
562 | * Removes a option in a stanza | 595 | * Removes a option in a stanza |
563 | * @param start the start of the stanza | 596 | * @param start the start of the stanza |
564 | * @param option the option to use when setting value. | 597 | * @param option the option to use when setting value. |
565 | * @return bool true if successfull, false otherwise. | 598 | * @return bool true if successfull, false otherwise. |
566 | */ | 599 | */ |
567 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ | 600 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
568 | if(start == interfaces.end()) | 601 | if(start == interfaces.end()) |
569 | return false; | 602 | return false; |
570 | 603 | ||
571 | bool found = false; | 604 | bool found = false; |
572 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 605 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
573 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 606 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
574 | // got to the end without finding it | 607 | // got to the end without finding it |
575 | break; | 608 | break; |
576 | } | 609 | } |
577 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 610 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
578 | // Found it in stanza so replace it. | 611 | // Found it in stanza so replace it. |
579 | if(found) | 612 | if(found) |
580 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 613 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
581 | found = true; | 614 | found = true; |
582 | (*it) = ""; | 615 | it = interfaces.remove( it ); // we really want to remove the line |
616 | --it; // we do ++it later in the head of the for loop | ||
583 | } | 617 | } |
584 | } | 618 | } |
585 | return found; | 619 | return found; |
586 | } | 620 | } |
587 | 621 | ||
588 | /** | 622 | /** |
589 | * Removes all options in a stanza | 623 | * Removes all options in a stanza |
590 | * @param start the start of the stanza | 624 | * @param start the start of the stanza |
591 | * @return bool true if successfull, false otherwise. | 625 | * @return bool true if successfull, false otherwise. |
592 | */ | 626 | */ |
593 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ | 627 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ |
594 | if(start == interfaces.end()) | 628 | if(start == interfaces.end()) |
595 | return false; | 629 | return false; |
596 | 630 | ||
597 | QStringList::Iterator it = start; | 631 | QStringList::Iterator it = start; |
598 | it = ++it; | 632 | it = ++it; |
599 | for (; it != interfaces.end(); ++it ) { | 633 | for (; it != interfaces.end(); ++it ) { |
600 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 634 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
601 | break; | 635 | break; |
602 | } | 636 | } |
603 | it = interfaces.remove(it); | 637 | it = interfaces.remove(it); |
604 | it = --it; | 638 | it = --it; |
605 | } | 639 | } |
606 | // Leave a space between this interface and the next. | 640 | // Leave a space between this interface and the next. |
607 | interfaces.insert(it, QString("")); | 641 | interfaces.insert(it, QString("")); |
608 | return true; | 642 | return true; |
609 | } | 643 | } |
610 | 644 | ||
611 | /** | 645 | /** |
612 | * Gets a value of an option in a stanza | 646 | * Gets a value of an option in a stanza |
613 | * @param start the start of the stanza | 647 | * @param start the start of the stanza |
614 | * @param option the option to use when getting the value. | 648 | * @param option the option to use when getting the value. |
615 | * @param bool true if errors false otherwise. | 649 | * @param bool true if errors false otherwise. |
616 | * @return QString the value of option QString::null() if error == true. | 650 | * @return QString the value of option QString::null() if error == true. |
617 | */ | 651 | */ |
618 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ | 652 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ |
619 | if(start == interfaces.end()){ | 653 | if(start == interfaces.end()){ |
620 | error = false; | 654 | error = false; |
621 | return QString(); | 655 | return QString(); |
622 | } | 656 | } |
623 | 657 | ||
624 | QString value; | 658 | QString value; |
625 | bool found = false; | 659 | bool found = false; |
626 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 660 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
627 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 661 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
628 | break; | 662 | break; |
629 | } | 663 | } |
630 | if((*it).contains(option) && (*it).at(0) != '#'){ | 664 | if((*it).contains(option) && (*it).at(0) != '#'){ |
631 | if(found) | 665 | if(found) |
632 | qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); | 666 | qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); |
633 | found = true; | 667 | found = true; |
634 | QString line = (*it).simplifyWhiteSpace(); | 668 | QString line = (*it).simplifyWhiteSpace(); |
635 | int space = line.find(" ", option.length()); | 669 | int space = line.find(" ", option.length()); |
636 | if(space != -1){ | 670 | if(space != -1){ |
637 | value = line.mid(space+1, line.length()); | 671 | value = line.mid(space+1, line.length()); |
638 | break; | 672 | break; |
639 | } | 673 | } |
640 | } | 674 | } |
641 | } | 675 | } |
642 | error = !found; | 676 | error = !found; |
643 | return value; | 677 | return value; |
644 | } | 678 | } |
645 | 679 | ||
646 | /** | 680 | /** |
647 | * Write out the interfaces file to the file passed into the constructor. | 681 | * Write out the interfaces file to the file passed into the constructor. |
648 | * Removes any excess blank lines over 1 line long. | 682 | * Removes any excess blank lines over 1 line long. |
649 | * @return bool true if successfull, false if not. | 683 | * @return bool true if successfull, false if not. |
650 | */ | 684 | */ |
651 | bool Interfaces::write(){ | 685 | bool Interfaces::write(){ |
652 | QFile::remove(interfacesFile); | 686 | QFile::remove(interfacesFile); |
653 | QFile file(interfacesFile); | 687 | QFile file(interfacesFile); |
654 | 688 | ||
655 | if (!file.open(IO_ReadWrite)){ | 689 | if (!file.open(IO_ReadWrite)){ |
656 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | 690 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); |
657 | return false; | 691 | return false; |
658 | } | 692 | } |
659 | QTextStream stream( &file ); | 693 | QTextStream stream( &file ); |
660 | int whiteSpaceCount = 0; | 694 | int whiteSpaceCount = 0; |
661 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 695 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
662 | QString line = (*it).simplifyWhiteSpace(); | 696 | QString line = (*it).simplifyWhiteSpace(); |
663 | line = line.replace(QRegExp(" "),""); | 697 | line = line.replace(QRegExp(" "),""); |
664 | if(line.length() == 0) | 698 | if(line.length() == 0) |
665 | whiteSpaceCount++; | 699 | whiteSpaceCount++; |
666 | else | 700 | else |
667 | whiteSpaceCount = 0; | 701 | whiteSpaceCount = 0; |
668 | if(whiteSpaceCount < 2){ | 702 | if(whiteSpaceCount < 2){ |
669 | qDebug((*it).latin1()); | 703 | qDebug((*it).latin1()); |
670 | stream << (*it) << '\n'; | 704 | stream << (*it) << '\n'; |
671 | } | 705 | } |
672 | } | 706 | } |
673 | file.close(); | 707 | file.close(); |
674 | return true; | 708 | return true; |
675 | } | 709 | } |
676 | 710 | ||
677 | // interfaces.cpp | 711 | // interfaces.cpp |
678 | 712 | ||
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,202 +1,206 @@ | |||
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 | } |
168 | } | 172 | } |
169 | 173 | ||
170 | // We must have a valid interface to get this far so read some settings. | 174 | // We must have a valid interface to get this far so read some settings. |
171 | 175 | ||
172 | // DHCP | 176 | // DHCP |
173 | bool error = false; | 177 | bool error = false; |
174 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 178 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
175 | dhcpCheckBox->setChecked(true); | 179 | dhcpCheckBox->setChecked(true); |
176 | else | 180 | else |
177 | dhcpCheckBox->setChecked(false); | 181 | dhcpCheckBox->setChecked(false); |
178 | 182 | ||
179 | // IP Information | 183 | // IP Information |
180 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 184 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); |
181 | QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); | 185 | QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); |
182 | qDebug("dns >%s<",dns.latin1()); | 186 | qDebug("dns >%s<",dns.latin1()); |
183 | if(dns.contains(" ")){ | 187 | if(dns.contains(" ")){ |
184 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 188 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
185 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 189 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
186 | }else firstDNSLineEdit->setText(dns); | 190 | }else firstDNSLineEdit->setText(dns); |
187 | 191 | ||
188 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 192 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); |
189 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 193 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); |
190 | if (subnetMaskEdit->text().isEmpty()) | 194 | if (subnetMaskEdit->text().isEmpty()) |
191 | subnetMaskEdit->setText( "255.255.255.0" ); | 195 | subnetMaskEdit->setText( "255.255.255.0" ); |
192 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 196 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); |
193 | 197 | ||
194 | 198 | ||
195 | 199 | ||
196 | qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1()); | 200 | qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1()); |
197 | qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1()); | 201 | qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1()); |
198 | 202 | ||
199 | } | 203 | } |
200 | 204 | ||
201 | // interfacesetup.cpp | 205 | // interfacesetup.cpp |
202 | 206 | ||