summaryrefslogtreecommitdiff
authorzecke <zecke>2004-04-06 08:00:49 (UTC)
committer zecke <zecke>2004-04-06 08:00:49 (UTC)
commit1b7592f11a2499c3e7d6652dde1ee15fb661fce2 (patch) (unidiff)
treefc9998d8037473f7bfb27274f60fbcdb26cc9d50
parent9aeac7cefc3c8baf32944e7275b57e0a0cde1515 (diff)
downloadopie-1b7592f11a2499c3e7d6652dde1ee15fb661fce2.zip
opie-1b7592f11a2499c3e7d6652dde1ee15fb661fce2.tar.gz
opie-1b7592f11a2499c3e7d6652dde1ee15fb661fce2.tar.bz2
one include of odebug.h a day keeps my anger away... :}
Add odebug.h so that it compiles
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interface.cpp3
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.cpp2
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp1
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp1
4 files changed, 7 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp
index d2b106a..46f3e19 100644
--- a/noncore/settings/networksettings/interfaces/interface.cpp
+++ b/noncore/settings/networksettings/interfaces/interface.cpp
@@ -1,302 +1,305 @@
1/** 1/**
2 * $Author$ 2 * $Author$
3 * $Date$ 3 * $Date$
4 */ 4 */
5 5
6#include "interface.h" 6#include "interface.h"
7
8#include <opie2/odebug.h>
9
7#include <qdatetime.h> 10#include <qdatetime.h>
8#include <qfile.h> 11#include <qfile.h>
9#include <qdir.h> 12#include <qdir.h>
10#include <qfileinfo.h> 13#include <qfileinfo.h>
11#include <qtextstream.h> 14#include <qtextstream.h>
12 15
13#define IFCONFIG "/sbin/ifconfig" 16#define IFCONFIG "/sbin/ifconfig"
14#define DHCP_INFO_DIR "/etc/dhcpc" 17#define DHCP_INFO_DIR "/etc/dhcpc"
15 18
16#include <stdio.h> 19#include <stdio.h>
17#include <stdlib.h> 20#include <stdlib.h>
18 21
19Interface::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"){ 22Interface::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(); 23 refresh();
21} 24}
22 25
23/** 26/**
24 * Set status 27 * Set status
25 * @param newStatus - the new status 28 * @param newStatus - the new status
26 * emit updateInterface 29 * emit updateInterface
27 */ 30 */
28void Interface::setStatus(bool newStatus){ 31void Interface::setStatus(bool newStatus){
29 if(status != newStatus){ 32 if(status != newStatus){
30 status = newStatus; 33 status = newStatus;
31 refresh(); 34 refresh();
32 } 35 }
33}; 36};
34 37
35/** 38/**
36 * Set if attached or not (802.11 card pulled out for example) 39 * Set if attached or not (802.11 card pulled out for example)
37 * @param isAttached - if attached 40 * @param isAttached - if attached
38 * emit updateInterface 41 * emit updateInterface
39 */ 42 */
40void Interface::setAttached(bool isAttached){ 43void Interface::setAttached(bool isAttached){
41 attached = isAttached; 44 attached = isAttached;
42 emit(updateInterface(this)); 45 emit(updateInterface(this));
43}; 46};
44 47
45/** 48/**
46 * Set Hardware name 49 * Set Hardware name
47 * @param name - the new name 50 * @param name - the new name
48 * emit updateInterface 51 * emit updateInterface
49 */ 52 */
50void Interface::setHardwareName(const QString &name){ 53void Interface::setHardwareName(const QString &name){
51 hardwareName = name; 54 hardwareName = name;
52 emit(updateInterface(this)); 55 emit(updateInterface(this));
53}; 56};
54 57
55/** 58/**
56 * Set Module owner 59 * Set Module owner
57 * @param owner - the new owner 60 * @param owner - the new owner
58 * emit updateInterface 61 * emit updateInterface
59 */ 62 */
60void Interface::setModuleOwner(Module *owner){ 63void Interface::setModuleOwner(Module *owner){
61 moduleOwner = owner; 64 moduleOwner = owner;
62 emit(updateInterface(this)); 65 emit(updateInterface(this));
63}; 66};
64 67
65 68
66/** 69/**
67 * Try to start the interface. 70 * Try to start the interface.
68 */ 71 */
69void Interface::start(){ 72void Interface::start(){
70 // check to see if we are already running. 73 // check to see if we are already running.
71 if(true == status){ 74 if(true == status){
72 emit (updateMessage("Unable to start interface,\n already started")); 75 emit (updateMessage("Unable to start interface,\n already started"));
73 return; 76 return;
74 } 77 }
75 78
76 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 79 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
77 // See if it was successful... 80 // See if it was successful...
78 if(ret != 0){ 81 if(ret != 0){
79 emit (updateMessage("Starting interface failed")); 82 emit (updateMessage("Starting interface failed"));
80 return; 83 return;
81 } 84 }
82 85
83 status = true; 86 status = true;
84 refresh(); 87 refresh();
85 emit (updateMessage("Start successful")); 88 emit (updateMessage("Start successful"));
86} 89}
87 90
88/** 91/**
89 * Try to stop the interface. 92 * Try to stop the interface.
90 */ 93 */
91void Interface::stop(){ 94void Interface::stop(){
92 // check to see if we are already stopped. 95 // check to see if we are already stopped.
93 if(false == status){ 96 if(false == status){
94 emit (updateMessage("Unable to stop interface,\n already stopped")); 97 emit (updateMessage("Unable to stop interface,\n already stopped"));
95 return; 98 return;
96 } 99 }
97 100
98 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 101 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
99 if(ret != 0){ 102 if(ret != 0){
100 emit (updateMessage("Stopping interface failed")); 103 emit (updateMessage("Stopping interface failed"));
101 return; 104 return;
102 } 105 }
103 106
104 status = false; 107 status = false;
105 refresh(); 108 refresh();
106 emit (updateMessage("Stop successful")); 109 emit (updateMessage("Stop successful"));
107} 110}
108 111
109/** 112/**
110 * Try to restart the interface. 113 * Try to restart the interface.
111 */ 114 */
112void Interface::restart(){ 115void Interface::restart(){
113 stop(); 116 stop();
114 start(); 117 start();
115} 118}
116 119
117/** 120/**
118 * Try to refresh the information about the interface. 121 * Try to refresh the information about the interface.
119 * First call ifconfig, then check the dhcp-info file 122 * First call ifconfig, then check the dhcp-info file
120 * @return bool true if successful. 123 * @return bool true if successful.
121 */ 124 */
122bool Interface::refresh(){ 125bool Interface::refresh(){
123 // See if we are up. 126 // See if we are up.
124 if(status == false){ 127 if(status == false){
125 macAddress = ""; 128 macAddress = "";
126 ip = "0.0.0.0"; 129 ip = "0.0.0.0";
127 subnetMask = "0.0.0.0"; 130 subnetMask = "0.0.0.0";
128 broadcast = ""; 131 broadcast = "";
129 dhcp = false; 132 dhcp = false;
130 dhcpServerIp = ""; 133 dhcpServerIp = "";
131 leaseObtained = ""; 134 leaseObtained = "";
132 leaseExpires = ""; 135 leaseExpires = "";
133 emit(updateInterface(this)); 136 emit(updateInterface(this));
134 return true; 137 return true;
135 } 138 }
136 139
137 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 140 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
138 int ret = system(QString("LANG=C %1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 141 int ret = system(QString("LANG=C %1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
139 if(ret != 0){ 142 if(ret != 0){
140 odebug << QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1() << oendl; 143 odebug << QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1() << oendl;
141 return false; 144 return false;
142 } 145 }
143 146
144 QFile file(fileName); 147 QFile file(fileName);
145 if (!file.open(IO_ReadOnly)){ 148 if (!file.open(IO_ReadOnly)){
146 odebug << QString("Interface: Can't open file: %1").arg(fileName).latin1() << oendl; 149 odebug << QString("Interface: Can't open file: %1").arg(fileName).latin1() << oendl;
147 return false; 150 return false;
148 } 151 }
149 152
150 // Set to the defaults 153 // Set to the defaults
151 macAddress = ""; 154 macAddress = "";
152 ip = "0.0.0.0"; 155 ip = "0.0.0.0";
153 subnetMask = "0.0.0.0"; 156 subnetMask = "0.0.0.0";
154 broadcast = ""; 157 broadcast = "";
155 158
156 QTextStream stream( &file ); 159 QTextStream stream( &file );
157 QString line; 160 QString line;
158 while ( !stream.eof() ) { 161 while ( !stream.eof() ) {
159 line = stream.readLine(); 162 line = stream.readLine();
160 if(line.contains("HWaddr")){ 163 if(line.contains("HWaddr")){
161 int mac = line.find("HWaddr"); 164 int mac = line.find("HWaddr");
162 macAddress = line.mid(mac+7, line.length()); 165 macAddress = line.mid(mac+7, line.length());
163 } 166 }
164 if(line.contains("inet addr")){ 167 if(line.contains("inet addr")){
165 int ipl = line.find("inet addr"); 168 int ipl = line.find("inet addr");
166 int space = line.find(" ", ipl+10); 169 int space = line.find(" ", ipl+10);
167 ip = line.mid(ipl+10, space-ipl-10); 170 ip = line.mid(ipl+10, space-ipl-10);
168 } 171 }
169 if(line.contains("Mask")){ 172 if(line.contains("Mask")){
170 int mask = line.find("Mask"); 173 int mask = line.find("Mask");
171 subnetMask = line.mid(mask+5, line.length()); 174 subnetMask = line.mid(mask+5, line.length());
172 } 175 }
173 if(line.contains("Bcast")){ 176 if(line.contains("Bcast")){
174 int mask = line.find("Bcast"); 177 int mask = line.find("Bcast");
175 int space = line.find(" ", mask+6); 178 int space = line.find(" ", mask+6);
176 broadcast = line.mid(mask+6, space-mask-6); 179 broadcast = line.mid(mask+6, space-mask-6);
177 } 180 }
178 } 181 }
179 file.close(); 182 file.close();
180 QFile::remove(fileName); 183 QFile::remove(fileName);
181 184
182 // DHCP TESTING 185 // DHCP TESTING
183 // reset DHCP info 186 // reset DHCP info
184 dhcpServerIp = ""; 187 dhcpServerIp = "";
185 leaseObtained = ""; 188 leaseObtained = "";
186 leaseExpires = ""; 189 leaseExpires = "";
187 dhcp = false; 190 dhcp = false;
188 191
189 QString dhcpDirectory(DHCP_INFO_DIR); 192 QString dhcpDirectory(DHCP_INFO_DIR);
190 QDir d(dhcpDirectory); 193 QDir d(dhcpDirectory);
191 if(!d.exists(dhcpDirectory)) 194 if(!d.exists(dhcpDirectory))
192 dhcpDirectory = "/var/run"; 195 dhcpDirectory = "/var/run";
193 196
194 // See if we have 197 // See if we have
195 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 198 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
196 // If there is no DHCP information then exit now with no errors. 199 // If there is no DHCP information then exit now with no errors.
197 if(!QFile::exists(dhcpFile)){ 200 if(!QFile::exists(dhcpFile)){
198 emit(updateInterface(this)); 201 emit(updateInterface(this));
199 return true; 202 return true;
200 } 203 }
201 204
202 file.setName(dhcpFile); 205 file.setName(dhcpFile);
203 if (!file.open(IO_ReadOnly)){ 206 if (!file.open(IO_ReadOnly)){
204 odebug << QString("Interface: Can't open file: %1").arg(dhcpFile).latin1() << oendl; 207 odebug << QString("Interface: Can't open file: %1").arg(dhcpFile).latin1() << oendl;
205 return false; 208 return false;
206 } 209 }
207 210
208 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 211 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
209 int leaseTime = 0; 212 int leaseTime = 0;
210 int renewalTime = 0; 213 int renewalTime = 0;
211 214
212 stream.setDevice( &file ); 215 stream.setDevice( &file );
213 while ( !stream.eof() ) { 216 while ( !stream.eof() ) {
214 line = stream.readLine(); 217 line = stream.readLine();
215 if(line.contains("DHCPSIADDR=")) 218 if(line.contains("DHCPSIADDR="))
216 dhcpServerIp = line.mid(11, line.length()); 219 dhcpServerIp = line.mid(11, line.length());
217 if(line.contains("LEASETIME=")) 220 if(line.contains("LEASETIME="))
218 leaseTime = line.mid(10, line.length()).toInt(); 221 leaseTime = line.mid(10, line.length()).toInt();
219 if(line.contains("RENEWALTIME=")) 222 if(line.contains("RENEWALTIME="))
220 renewalTime = line.mid(12, line.length()).toInt(); 223 renewalTime = line.mid(12, line.length()).toInt();
221 } 224 }
222 file.close(); 225 file.close();
223 //odebug << QString("Interface: leaseTime: %1").arg(leaseTime).latin1() << oendl; 226 //odebug << QString("Interface: leaseTime: %1").arg(leaseTime).latin1() << oendl;
224 //odebug << QString("Interface: renewalTime: %1").arg(renewalTime).latin1() << oendl; 227 //odebug << QString("Interface: renewalTime: %1").arg(renewalTime).latin1() << oendl;
225 228
226 // Get the pid of the deamond 229 // Get the pid of the deamond
227 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); 230 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
228 file.setName(dhcpFile); 231 file.setName(dhcpFile);
229 if (!file.open(IO_ReadOnly)){ 232 if (!file.open(IO_ReadOnly)){
230 odebug << QString("Interface: Can't open file: %1").arg(dhcpFile).latin1() << oendl; 233 odebug << QString("Interface: Can't open file: %1").arg(dhcpFile).latin1() << oendl;
231 return false; 234 return false;
232 } 235 }
233 236
234 int pid = -1; 237 int pid = -1;
235 stream.setDevice( &file ); 238 stream.setDevice( &file );
236 while ( !stream.eof() ) { 239 while ( !stream.eof() ) {
237 line = stream.readLine(); 240 line = stream.readLine();
238 pid = line.toInt(); 241 pid = line.toInt();
239 } 242 }
240 file.close(); 243 file.close();
241 244
242 if( pid == -1){ 245 if( pid == -1){
243 odebug << "Interface: Could not get pid of dhcpc deamon." << oendl; 246 odebug << "Interface: Could not get pid of dhcpc deamon." << oendl;
244 return false; 247 return false;
245 } 248 }
246 249
247 // Get the start running time of the deamon 250 // Get the start running time of the deamon
248 fileName = (QString("/proc/%1/stat").arg(pid)); 251 fileName = (QString("/proc/%1/stat").arg(pid));
249 file.setName(fileName); 252 file.setName(fileName);
250 stream.setDevice( &file ); 253 stream.setDevice( &file );
251 if (!file.open(IO_ReadOnly)){ 254 if (!file.open(IO_ReadOnly)){
252 odebug << QString("Interface: Can't open file: %1").arg(fileName).latin1() << oendl; 255 odebug << QString("Interface: Can't open file: %1").arg(fileName).latin1() << oendl;
253 return false; 256 return false;
254 } 257 }
255 while ( !stream.eof() ) { 258 while ( !stream.eof() ) {
256 line = stream.readLine(); 259 line = stream.readLine();
257 } 260 }
258 file.close(); 261 file.close();
259 long time = 0; 262 long time = 0;
260 // Grab the start time 263 // Grab the start time
261 // pid com state ppid pgrp session tty_nr tpgid flags 264 // pid com state ppid pgrp session tty_nr tpgid flags
262 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 265 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
263 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 266 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
264 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 267 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
265 // nice 0 itrealvalue starttime 268 // nice 0 itrealvalue starttime
266 "%*d %*d %*d %lu", (long*) &time); 269 "%*d %*d %*d %lu", (long*) &time);
267 time = time/100; 270 time = time/100;
268 271
269 QDateTime datetime(QDateTime::currentDateTime()); 272 QDateTime datetime(QDateTime::currentDateTime());
270 273
271 // Get the uptime of the computer. 274 // Get the uptime of the computer.
272 QFile f("/proc/uptime"); 275 QFile f("/proc/uptime");
273 if ( f.open(IO_ReadOnly) ) { // file opened successfully 276 if ( f.open(IO_ReadOnly) ) { // file opened successfully
274 QTextStream t( &f ); // use a text stream 277 QTextStream t( &f ); // use a text stream
275 int sec = 0; 278 int sec = 0;
276 t >> sec; 279 t >> sec;
277 datetime = datetime.addSecs((-1*sec)); 280 datetime = datetime.addSecs((-1*sec));
278 f.close(); 281 f.close();
279 } 282 }
280 else{ 283 else{
281 odebug << "Interface: Can't open /proc/uptime to retrive uptime." << oendl; 284 odebug << "Interface: Can't open /proc/uptime to retrive uptime." << oendl;
282 return false; 285 return false;
283 } 286 }
284 287
285 datetime = datetime.addSecs(time); 288 datetime = datetime.addSecs(time);
286 //odebug << QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1() << oendl; 289 //odebug << QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1() << oendl;
287 290
288 // Calculate the start and renew times 291 // Calculate the start and renew times
289 leaseObtained= datetime.toString(); 292 leaseObtained= datetime.toString();
290 293
291 // Calculate the start and renew times 294 // Calculate the start and renew times
292 datetime = datetime.addSecs(leaseTime); 295 datetime = datetime.addSecs(leaseTime);
293 leaseExpires = datetime.toString(); 296 leaseExpires = datetime.toString();
294 297
295 dhcp = true; 298 dhcp = true;
296 299
297 emit(updateInterface(this)); 300 emit(updateInterface(this));
298 return true; 301 return true;
299} 302}
300 303
301// interface.cpp 304// interface.cpp
302 305
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp
index e283926..5ce4b58 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces/interfaces.cpp
@@ -1,712 +1,714 @@
1#include "interfaces.h" 1#include "interfaces.h"
2 2
3#include <opie2/odebug.h>
4
3#include <qcheckbox.h> 5#include <qcheckbox.h>
4#include <qfile.h> 6#include <qfile.h>
5#include <qtextstream.h> 7#include <qtextstream.h>
6#include <qregexp.h> 8#include <qregexp.h>
7 9
8// The three stanza's 10// The three stanza's
9#define AUTO "auto" 11#define AUTO "auto"
10#define IFACE "iface" 12#define IFACE "iface"
11#define MAPPING "mapping" 13#define MAPPING "mapping"
12 14
13/** 15/**
14 * Constructor. Reads in the interfaces file and then split the file up by 16 * Constructor. Reads in the interfaces file and then split the file up by
15 * the \n for interfaces variable. 17 * the \n for interfaces variable.
16 * @param useInterfacesFile if an interface file other then the default is 18 * @param useInterfacesFile if an interface file other then the default is
17 * desired to be used it should be passed in. 19 * desired to be used it should be passed in.
18 */ 20 */
19Interfaces::Interfaces(QString useInterfacesFile){ 21Interfaces::Interfaces(QString useInterfacesFile){
20 acceptedFamily.append(INTERFACES_FAMILY_INET); 22 acceptedFamily.append(INTERFACES_FAMILY_INET);
21 acceptedFamily.append(INTERFACES_FAMILY_IPX); 23 acceptedFamily.append(INTERFACES_FAMILY_IPX);
22 acceptedFamily.append(INTERFACES_FAMILY_INET6); 24 acceptedFamily.append(INTERFACES_FAMILY_INET6);
23 25
24 interfacesFile = useInterfacesFile; 26 interfacesFile = useInterfacesFile;
25 QFile file(interfacesFile); 27 QFile file(interfacesFile);
26 if (!file.open(IO_ReadOnly)){ 28 if (!file.open(IO_ReadOnly)){
27 odebug << "Interfaces: Can't open file: " << interfacesFile.latin1() << " for reading." << oendl; 29 odebug << "Interfaces: Can't open file: " << interfacesFile.latin1() << " for reading." << oendl;
28 currentIface = interfaces.end(); 30 currentIface = interfaces.end();
29 currentMapping = interfaces.end(); 31 currentMapping = interfaces.end();
30 return; 32 return;
31 } 33 }
32 QTextStream stream( &file ); 34 QTextStream stream( &file );
33 QString line; 35 QString line;
34 while ( !stream.eof() ) { 36 while ( !stream.eof() ) {
35 line += stream.readLine(); 37 line += stream.readLine();
36 line += "\n"; 38 line += "\n";
37 } 39 }
38 file.close(); 40 file.close();
39 interfaces = QStringList::split("\n", line, true); 41 interfaces = QStringList::split("\n", line, true);
40 42
41 currentIface = interfaces.end(); 43 currentIface = interfaces.end();
42 currentMapping = interfaces.end(); 44 currentMapping = interfaces.end();
43} 45}
44 46
45 47
46/** 48/**
47 * Get a list of all interfaces in the interface file. Useful for 49 * Get a list of all interfaces in the interface file. Useful for
48 * hardware that is not currently connected such as an 802.11b card 50 * hardware that is not currently connected such as an 802.11b card
49 * not plugged in, but configured for when it is plugged in. 51 * not plugged in, but configured for when it is plugged in.
50 * @return Return string list of interfaces. 52 * @return Return string list of interfaces.
51 **/ 53 **/
52QStringList Interfaces::getInterfaceList(){ 54QStringList Interfaces::getInterfaceList(){
53 QStringList list; 55 QStringList list;
54 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 56 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
55 QString line = (*it).simplifyWhiteSpace(); 57 QString line = (*it).simplifyWhiteSpace();
56 if(line.contains(IFACE) && line.at(0) != '#'){ 58 if(line.contains(IFACE) && line.at(0) != '#'){
57 line = line.mid(QString(IFACE).length() +1, line.length()); 59 line = line.mid(QString(IFACE).length() +1, line.length());
58 line = line.simplifyWhiteSpace(); 60 line = line.simplifyWhiteSpace();
59 int findSpace = line.find(" "); 61 int findSpace = line.find(" ");
60 if( findSpace >= 0){ 62 if( findSpace >= 0){
61 line = line.mid(0, findSpace); 63 line = line.mid(0, findSpace);
62 list.append(line); 64 list.append(line);
63 } 65 }
64 } 66 }
65 } 67 }
66 return list; 68 return list;
67} 69}
68 70
69/** 71/**
70 * Find out if interface is in an "auto" group or not. 72 * Find out if interface is in an "auto" group or not.
71 * Report any duplicates such as eth0 being in two differnt auto's 73 * Report any duplicates such as eth0 being in two differnt auto's
72 * @param interface interface to check to see if it is on or not. 74 * @param interface interface to check to see if it is on or not.
73 * @return true is interface is in auto 75 * @return true is interface is in auto
74 */ 76 */
75bool Interfaces::isAuto(const QString &interface) const { 77bool Interfaces::isAuto(const QString &interface) const {
76 QStringList autoLines = interfaces.grep(QRegExp(AUTO)); 78 QStringList autoLines = interfaces.grep(QRegExp(AUTO));
77 QStringList awi = autoLines.grep(QRegExp(interface)); 79 QStringList awi = autoLines.grep(QRegExp(interface));
78 if(awi.count() > 1) 80 if(awi.count() > 1)
79 odebug << QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1() << oendl; 81 odebug << QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1() << oendl;
80 return awi.count() > 0; 82 return awi.count() > 0;
81} 83}
82 84
83/** 85/**
84 * Attempt to set the auto option for interface to setAuto. 86 * Attempt to set the auto option for interface to setAuto.
85 * @param interface the interface to set 87 * @param interface the interface to set
86 * @param setAuto the value to set interface to. 88 * @param setAuto the value to set interface to.
87 * @return false if already set to setAuto. 89 * @return false if already set to setAuto.
88 * */ 90 * */
89bool Interfaces::setAuto(const QString &interface, bool setAuto){ 91bool Interfaces::setAuto(const QString &interface, bool setAuto){
90 // Don't need to set it if it is already set. 92 // Don't need to set it if it is already set.
91 if(isAuto(interface) == setAuto) 93 if(isAuto(interface) == setAuto)
92 return false; 94 return false;
93 95
94 bool changed = false; 96 bool changed = false;
95 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 97 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
96 if((*it).contains(AUTO)){ 98 if((*it).contains(AUTO)){
97 //We know that they are not in any group so let add to this auto. 99 //We know that they are not in any group so let add to this auto.
98 if(setAuto){ 100 if(setAuto){
99 (*it) = (*it) += " " + interface; 101 (*it) = (*it) += " " + interface;
100 // Don't care to have such thins as: auto eth0 lo usb0 102 // Don't care to have such thins as: auto eth0 lo usb0
101 (*it) = (*it).simplifyWhiteSpace(); 103 (*it) = (*it).simplifyWhiteSpace();
102 changed = true; 104 changed = true;
103 break; 105 break;
104 } 106 }
105 // else see if we need to remove from this one 107 // else see if we need to remove from this one
106 else{ 108 else{
107 if((*it).contains(interface)){ 109 if((*it).contains(interface)){
108 (*it) = (*it).replace(QRegExp(interface), ""); 110 (*it) = (*it).replace(QRegExp(interface), "");
109 // if AUTO is the only thing left clear the line 111 // if AUTO is the only thing left clear the line
110 if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) 112 if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO)
111 (*it) = ""; 113 (*it) = "";
112 changed = true; 114 changed = true;
113 // Don't break because we want to make sure we remove all cases. 115 // Don't break because we want to make sure we remove all cases.
114 } 116 }
115 } 117 }
116 } 118 }
117 } 119 }
118 // In the case where there is no AUTO field add one. 120 // In the case where there is no AUTO field add one.
119 if(!changed && setAuto) 121 if(!changed && setAuto)
120 interfaces.append(QString(AUTO" %1").arg(interface)); 122 interfaces.append(QString(AUTO" %1").arg(interface));
121 return true; 123 return true;
122} 124}
123 125
124/** 126/**
125 * Set the current interface to interface. This needs to be done before you 127 * Set the current interface to interface. This needs to be done before you
126 * can call getFamily(), getMethod, and get/setOption(). 128 * can call getFamily(), getMethod, and get/setOption().
127 * @param interface the name of the interface to set. All whitespace is 129 * @param interface the name of the interface to set. All whitespace is
128 * removed from the interface name. 130 * removed from the interface name.
129 * @return bool true if it is successful. 131 * @return bool true if it is successful.
130 */ 132 */
131bool Interfaces::setInterface(QString interface){ 133bool Interfaces::setInterface(QString interface){
132 interface = interface.simplifyWhiteSpace(); 134 interface = interface.simplifyWhiteSpace();
133 interface = interface.replace(QRegExp(" "), ""); 135 interface = interface.replace(QRegExp(" "), "");
134 return setStanza(IFACE, interface, currentIface); 136 return setStanza(IFACE, interface, currentIface);
135} 137}
136 138
137/** 139/**
138 * A quick helper funtion to see if the current interface is set. 140 * A quick helper funtion to see if the current interface is set.
139 * @return bool true if set, false otherwise. 141 * @return bool true if set, false otherwise.
140 */ 142 */
141bool Interfaces::isInterfaceSet() const { 143bool Interfaces::isInterfaceSet() const {
142 return (interfaces.end() != currentIface); 144 return (interfaces.end() != currentIface);
143} 145}
144 146
145/** 147/**
146 * Add a new interface of with the settings - family and method 148 * Add a new interface of with the settings - family and method
147 * @param interface the name of the interface to set. All whitespace is 149 * @param interface the name of the interface to set. All whitespace is
148 * removed from the interface name. 150 * removed from the interface name.
149 * @param family the family of this interface inet or inet, ipx or inet6 151 * @param family the family of this interface inet or inet, ipx or inet6
150 * Must of one of the families defined in interfaces.h 152 * Must of one of the families defined in interfaces.h
151 * @param method for the family. see interfaces man page for family methods. 153 * @param method for the family. see interfaces man page for family methods.
152 * @return true if successful. 154 * @return true if successful.
153 */ 155 */
154bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ 156bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){
155 odebug << "Interfaces::addInterface(" << interface.latin1() << ")" << oendl; 157 odebug << "Interfaces::addInterface(" << interface.latin1() << ")" << oendl;
156 if(0 == acceptedFamily.contains(family)) 158 if(0 == acceptedFamily.contains(family))
157 return false; 159 return false;
158 QString newInterface = interface.simplifyWhiteSpace(); 160 QString newInterface = interface.simplifyWhiteSpace();
159 newInterface = newInterface.replace(QRegExp(" "), ""); 161 newInterface = newInterface.replace(QRegExp(" "), "");
160 interfaces.append(""); 162 interfaces.append("");
161 interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); 163 interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method));
162 return true; 164 return true;
163} 165}
164 166
165/** 167/**
166 * Copies interface with name interface to name newInterface 168 * Copies interface with name interface to name newInterface
167 * @param newInterface name of the new interface. 169 * @param newInterface name of the new interface.
168 * @return bool true if successful 170 * @return bool true if successful
169 */ 171 */
170bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ 172bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){
171 odebug << "copy interface " << interface.latin1() << " to " << newInterface.latin1() << "" << oendl; 173 odebug << "copy interface " << interface.latin1() << " to " << newInterface.latin1() << "" << oendl;
172 if(!setInterface(interface)) 174 if(!setInterface(interface))
173 return false; 175 return false;
174 176
175 // Store the old interface and bump past the stanza line. 177 // Store the old interface and bump past the stanza line.
176 QStringList::Iterator it = currentIface; 178 QStringList::Iterator it = currentIface;
177 it++; 179 it++;
178 180
179 // Add the new interface 181 // Add the new interface
180 bool error; 182 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); 183 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) 184 if(!setInterface(newInterface))
183 return false; 185 return false;
184 186
185 QStringList::Iterator newIface = currentIface; 187 QStringList::Iterator newIface = currentIface;
186 newIface++; 188 newIface++;
187 189
188 // Copy all of the lines 190 // Copy all of the lines
189 for ( ; it != interfaces.end(); ++it ){ 191 for ( ; it != interfaces.end(); ++it ){
190 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) 192 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
191 break; 193 break;
192 newIface = interfaces.insert(newIface, *it); 194 newIface = interfaces.insert(newIface, *it);
193 } 195 }
194 196
195 return true; 197 return true;
196} 198}
197 199
198/** 200/**
199 * Remove the currently selected interface and all of its options. 201 * Remove the currently selected interface and all of its options.
200 * @return bool if successful or not. 202 * @return bool if successful or not.
201 */ 203 */
202bool Interfaces::removeInterface(){ 204bool Interfaces::removeInterface(){
203 return removeStanza(currentIface); 205 return removeStanza(currentIface);
204} 206}
205 207
206/** 208/**
207 * Gets the hardware name of the interface that is currently selected. 209 * Gets the hardware name of the interface that is currently selected.
208 * @return QString name of the hardware interface (eth0, usb2, wlan1...). 210 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
209 * @param error set to true if any error occurs, false otherwise. 211 * @param error set to true if any error occurs, false otherwise.
210 */ 212 */
211QString Interfaces::getInterfaceName(bool &error){ 213QString Interfaces::getInterfaceName(bool &error){
212 if(currentIface == interfaces.end()){ 214 if(currentIface == interfaces.end()){
213 error = true; 215 error = true;
214 return QString(); 216 return QString();
215 } 217 }
216 QString line = (*currentIface); 218 QString line = (*currentIface);
217 line = line.mid(QString(IFACE).length() +1, line.length()); 219 line = line.mid(QString(IFACE).length() +1, line.length());
218 line = line.simplifyWhiteSpace(); 220 line = line.simplifyWhiteSpace();
219 int findSpace = line.find(" "); 221 int findSpace = line.find(" ");
220 if( findSpace < 0){ 222 if( findSpace < 0){
221 error = true; 223 error = true;
222 return QString(); 224 return QString();
223 } 225 }
224 error = false; 226 error = false;
225 return line.mid(0, findSpace); 227 return line.mid(0, findSpace);
226} 228}
227 229
228/** 230/**
229 * Gets the family name of the interface that is currently selected. 231 * Gets the family name of the interface that is currently selected.
230 * @return QString name of the family (inet, inet6, ipx). 232 * @return QString name of the family (inet, inet6, ipx).
231 * @param error set to true if any error occurs, false otherwise. 233 * @param error set to true if any error occurs, false otherwise.
232 */ 234 */
233QString Interfaces::getInterfaceFamily(bool &error){ 235QString Interfaces::getInterfaceFamily(bool &error){
234 QString name = getInterfaceName(error); 236 QString name = getInterfaceName(error);
235 if(error) 237 if(error)
236 return QString(); 238 return QString();
237 QString line = (*currentIface); 239 QString line = (*currentIface);
238 line = line.mid(QString(IFACE).length() +1, line.length()); 240 line = line.mid(QString(IFACE).length() +1, line.length());
239 line = line.mid(name.length()+1, line.length()); 241 line = line.mid(name.length()+1, line.length());
240 line = line.simplifyWhiteSpace(); 242 line = line.simplifyWhiteSpace();
241 int findSpace = line.find(" "); 243 int findSpace = line.find(" ");
242 if( findSpace < 0){ 244 if( findSpace < 0){
243 error = true; 245 error = true;
244 return QString(); 246 return QString();
245 } 247 }
246 error = false; 248 error = false;
247 return line.mid(0, findSpace); 249 return line.mid(0, findSpace);
248} 250}
249 251
250/** 252/**
251 * Gets the method of the interface that is currently selected. 253 * Gets the method of the interface that is currently selected.
252 * @return QString name of the method such as staic or dhcp. 254 * @return QString name of the method such as staic or dhcp.
253 * See the man page of interfaces for possible methods depending on the family. 255 * See the man page of interfaces for possible methods depending on the family.
254 * @param error set to true if any error occurs, false otherwise. 256 * @param error set to true if any error occurs, false otherwise.
255 */ 257 */
256QString Interfaces::getInterfaceMethod(bool &error){ 258QString Interfaces::getInterfaceMethod(bool &error){
257 QString name = getInterfaceName(error); 259 QString name = getInterfaceName(error);
258 if(error) 260 if(error)
259 return QString(); 261 return QString();
260 QString family = getInterfaceFamily(error); 262 QString family = getInterfaceFamily(error);
261 if(error) 263 if(error)
262 return QString(); 264 return QString();
263 QString line = (*currentIface); 265 QString line = (*currentIface);
264 line = line.mid(QString(IFACE).length()+1, line.length()); 266 line = line.mid(QString(IFACE).length()+1, line.length());
265 line = line.mid(name.length()+1, line.length()); 267 line = line.mid(name.length()+1, line.length());
266 line = line.mid(family.length()+1, line.length()); 268 line = line.mid(family.length()+1, line.length());
267 line = line.simplifyWhiteSpace(); 269 line = line.simplifyWhiteSpace();
268 error = false; 270 error = false;
269 return line; 271 return line;
270} 272}
271 273
272/** 274/**
273 * Sets the interface name to newName. 275 * Sets the interface name to newName.
274 * @param newName the new name of the interface. All whitespace is removed. 276 * @param newName the new name of the interface. All whitespace is removed.
275 * @return bool true if successful. 277 * @return bool true if successful.
276 */ 278 */
277bool Interfaces::setInterfaceName(const QString &newName){ 279bool Interfaces::setInterfaceName(const QString &newName){
278 odebug << "setInterfaceName " << newName.latin1() << "" << oendl; 280 odebug << "setInterfaceName " << newName.latin1() << "" << oendl;
279 if(currentIface == interfaces.end()) 281 if(currentIface == interfaces.end())
280 return false; 282 return false;
281 QString name = newName.simplifyWhiteSpace(); 283 QString name = newName.simplifyWhiteSpace();
282 name = name.replace(QRegExp(" "), ""); 284 name = name.replace(QRegExp(" "), "");
283 bool returnValue = false; 285 bool returnValue = false;
284 QString tmp = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); 286 QString tmp = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
285 odebug << "setting " << tmp.latin1() << "" << oendl; 287 odebug << "setting " << tmp.latin1() << "" << oendl;
286 288
287 (*currentIface) = tmp; 289 (*currentIface) = tmp;
288 return !returnValue; 290 return !returnValue;
289} 291}
290 292
291/** 293/**
292 * Sets the interface family to newName. 294 * Sets the interface family to newName.
293 * @param newName the new name of the interface. Must be one of the families 295 * @param newName the new name of the interface. Must be one of the families
294 * defined in the interfaces.h file. 296 * defined in the interfaces.h file.
295 * @return bool true if successful. 297 * @return bool true if successful.
296 */ 298 */
297bool Interfaces::setInterfaceFamily(const QString &newName){ 299bool Interfaces::setInterfaceFamily(const QString &newName){
298 if(currentIface == interfaces.end()) 300 if(currentIface == interfaces.end())
299 return false; 301 return false;
300 if(acceptedFamily.contains(newName)==0) 302 if(acceptedFamily.contains(newName)==0)
301 return false; 303 return false;
302 bool returnValue = false; 304 bool returnValue = false;
303 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); 305 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue));
304 return !returnValue; 306 return !returnValue;
305} 307}
306 308
307/** 309/**
308 * Sets the interface method to newName 310 * Sets the interface method to newName
309 * @param newName the new name of the interface 311 * @param newName the new name of the interface
310 * @return bool true if successful. 312 * @return bool true if successful.
311 */ 313 */
312bool Interfaces::setInterfaceMethod(const QString &newName){ 314bool Interfaces::setInterfaceMethod(const QString &newName){
313 if(currentIface == interfaces.end()) 315 if(currentIface == interfaces.end())
314 return false; 316 return false;
315 bool returnValue = false; 317 bool returnValue = false;
316 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); 318 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName);
317 return !returnValue; 319 return !returnValue;
318} 320}
319 321
320/** 322/**
321 * Get a value for an option in the currently selected interface. For example 323 * Get a value for an option in the currently selected interface. For example
322 * calling getInterfaceOption("address") on the following stanza would 324 * calling getInterfaceOption("address") on the following stanza would
323 * return 192.168.1.1. 325 * return 192.168.1.1.
324 * iface eth0 static 326 * iface eth0 static
325 * address 192.168.1.1 327 * address 192.168.1.1
326 * @param option the options to get the value. 328 * @param option the options to get the value.
327 * @param error set to true if any error occurs, false otherwise. 329 * @param error set to true if any error occurs, false otherwise.
328 * @return QString the options value. QString::null if error == true 330 * @return QString the options value. QString::null if error == true
329 */ 331 */
330QString Interfaces::getInterfaceOption(const QString &option, bool &error){ 332QString Interfaces::getInterfaceOption(const QString &option, bool &error){
331 return getOption(currentIface, option, error); 333 return getOption(currentIface, option, error);
332} 334}
333 335
334/** 336/**
335 * Set a value for an option in the currently selected interface. If option 337 * Set a value for an option in the currently selected interface. If option
336 * doesn't exist then it is added along with the value. 338 * doesn't exist then it is added along with the value.
337 * If value isEmpty() then we will remove the option 339 * If value isEmpty() then we will remove the option
338 * 340 *
339 * @param option the options to set the value. 341 * @param option the options to set the value.
340 * @param value the value that option should be set to. 342 * @param value the value that option should be set to.
341 * @param error set to true if any error occurs, false otherwise. 343 * @param error set to true if any error occurs, false otherwise.
342 * @return QString the options value. QString::null if error == true 344 * @return QString the options value. QString::null if error == true
343 */ 345 */
344bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ 346bool Interfaces::setInterfaceOption(const QString &option, const QString &value){
345 if( value.stripWhiteSpace().isEmpty() ) 347 if( value.stripWhiteSpace().isEmpty() )
346 return removeInterfaceOption( option ); 348 return removeInterfaceOption( option );
347 349
348 odebug << "iface >" << (*currentIface).latin1() << "< option >" << option.latin1() << "< value >" << value.latin1() << "<" << oendl; 350 odebug << "iface >" << (*currentIface).latin1() << "< option >" << option.latin1() << "< value >" << value.latin1() << "<" << oendl;
349 return setOption(currentIface, option, value); 351 return setOption(currentIface, option, value);
350} 352}
351 353
352/** 354/**
353 * Removes a value for an option in the currently selected interface. 355 * Removes a value for an option in the currently selected interface.
354 * @param option the options to set the value. 356 * @param option the options to set the value.
355 * @param error set to true if any error occurs, false otherwise. 357 * @param error set to true if any error occurs, false otherwise.
356 * @return QString the options value. QString::null if error == true 358 * @return QString the options value. QString::null if error == true
357 */ 359 */
358bool Interfaces::removeInterfaceOption(const QString &option){ 360bool Interfaces::removeInterfaceOption(const QString &option){
359 return removeOption(currentIface, option); 361 return removeOption(currentIface, option);
360} 362}
361 363
362/** 364/**
363 * Removes a value for an option in the currently selected interface. 365 * Removes a value for an option in the currently selected interface.
364 * @param option the options to set the value. 366 * @param option the options to set the value.
365 * @param value the value that option should be set to. 367 * @param value the value that option should be set to.
366 * @param error set to true if any error occurs, false otherwise. 368 * @param error set to true if any error occurs, false otherwise.
367 * @return QString the options value. QString::null if error == true 369 * @return QString the options value. QString::null if error == true
368 */ 370 */
369bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ 371bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){
370 return removeOption(currentIface, option, value); 372 return removeOption(currentIface, option, value);
371} 373}
372 374
373/** 375/**
374 * Removes all of the options from the currently selected interface. 376 * Removes all of the options from the currently selected interface.
375 * @return bool error if if successful 377 * @return bool error if if successful
376 */ 378 */
377bool Interfaces::removeAllInterfaceOptions(){ 379bool Interfaces::removeAllInterfaceOptions(){
378 return removeAllOptions(currentIface); 380 return removeAllOptions(currentIface);
379} 381}
380 382
381/** 383/**
382 * Set the current map to interface's map. This needs to be done before you 384 * Set the current map to interface's map. This needs to be done before you
383 * can call addMapping(), set/getMap(), and get/setScript(). 385 * can call addMapping(), set/getMap(), and get/setScript().
384 * @param interface the name of the interface to set. All whitespace is 386 * @param interface the name of the interface to set. All whitespace is
385 * removed from the interface name. 387 * removed from the interface name.
386 * @return bool true if it is successful. 388 * @return bool true if it is successful.
387 */ 389 */
388bool Interfaces::setMapping(const QString &interface){ 390bool Interfaces::setMapping(const QString &interface){
389 QString interfaceName = interface.simplifyWhiteSpace(); 391 QString interfaceName = interface.simplifyWhiteSpace();
390 interfaceName = interfaceName.replace(QRegExp(" "), ""); 392 interfaceName = interfaceName.replace(QRegExp(" "), "");
391 return setStanza(MAPPING, interfaceName, currentMapping); 393 return setStanza(MAPPING, interfaceName, currentMapping);
392} 394}
393 395
394/** 396/**
395 * Adds a new Mapping to the interfaces file with interfaces. 397 * Adds a new Mapping to the interfaces file with interfaces.
396 * @param interface the name(s) of the interfaces to set to this mapping 398 * @param interface the name(s) of the interfaces to set to this mapping
397 */ 399 */
398void Interfaces::addMapping(const QString &option){ 400void Interfaces::addMapping(const QString &option){
399 interfaces.append(""); 401 interfaces.append("");
400 interfaces.append(QString(MAPPING " %1").arg(option)); 402 interfaces.append(QString(MAPPING " %1").arg(option));
401} 403}
402 404
403/** 405/**
404 * Remove the currently selected map and all of its options. 406 * Remove the currently selected map and all of its options.
405 * @return bool if successful or not. 407 * @return bool if successful or not.
406 */ 408 */
407bool Interfaces::removeMapping(){ 409bool Interfaces::removeMapping(){
408 return removeStanza(currentMapping); 410 return removeStanza(currentMapping);
409} 411}
410 412
411/** 413/**
412 * Set a map option within a mapping. 414 * Set a map option within a mapping.
413 * @param map map to use 415 * @param map map to use
414 * @param value value to go with map 416 * @param value value to go with map
415 * @return bool true if it is successful. 417 * @return bool true if it is successful.
416 */ 418 */
417bool Interfaces::setMap(const QString &map, const QString &value){ 419bool Interfaces::setMap(const QString &map, const QString &value){
418 return setOption(currentMapping, map, value); 420 return setOption(currentMapping, map, value);
419} 421}
420 422
421/** 423/**
422 * Removes a map option within a mapping. 424 * Removes a map option within a mapping.
423 * @param map map to use 425 * @param map map to use
424 * @param value value to go with map 426 * @param value value to go with map
425 * @return bool true if it is successful. 427 * @return bool true if it is successful.
426 */ 428 */
427bool Interfaces::removeMap(const QString &map, const QString &value){ 429bool Interfaces::removeMap(const QString &map, const QString &value){
428 return removeOption(currentMapping, map, value); 430 return removeOption(currentMapping, map, value);
429} 431}
430 432
431/** 433/**
432 * Get a map value within a mapping. 434 * Get a map value within a mapping.
433 * @param map map to get value of 435 * @param map map to get value of
434 * @param bool true if it is successful. 436 * @param bool true if it is successful.
435 * @return value that goes to the map 437 * @return value that goes to the map
436 */ 438 */
437QString Interfaces::getMap(const QString &map, bool &error){ 439QString Interfaces::getMap(const QString &map, bool &error){
438 return getOption(currentMapping, map, error); 440 return getOption(currentMapping, map, error);
439} 441}
440 442
441/** 443/**
442 * Sets a script value of the current mapping to argument. 444 * Sets a script value of the current mapping to argument.
443 * @param argument the script name. 445 * @param argument the script name.
444 * @return true if successful. 446 * @return true if successful.
445 */ 447 */
446bool Interfaces::setScript(const QString &argument){ 448bool Interfaces::setScript(const QString &argument){
447 return setOption(currentMapping, "script", argument); 449 return setOption(currentMapping, "script", argument);
448} 450}
449 451
450/** 452/**
451 * @param error true if could not retrieve the current script argument. 453 * @param error true if could not retrieve the current script argument.
452 * @return QString the argument of the script for the current mapping. 454 * @return QString the argument of the script for the current mapping.
453 */ 455 */
454QString Interfaces::getScript(bool &error){ 456QString Interfaces::getScript(bool &error){
455 return getOption(currentMapping, "script", error); 457 return getOption(currentMapping, "script", error);
456} 458}
457 459
458 460
459 461
460/** 462/**
461 * Helper function used to parse through the QStringList and put pointers in 463 * Helper function used to parse through the QStringList and put pointers in
462 * the correct place. 464 * the correct place.
463 * @param stanza The stanza (auto, iface, mapping) to look for. 465 * @param stanza The stanza (auto, iface, mapping) to look for.
464 * @param option string that must be in the stanza's main line. 466 * @param option string that must be in the stanza's main line.
465 * @param interator interator to place at location of stanza if successful. 467 * @param interator interator to place at location of stanza if successful.
466 * @return bool true if the stanza is found. 468 * @return bool true if the stanza is found.
467 */ 469 */
468bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ 470bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){
469 bool found = false; 471 bool found = false;
470 iterator = interfaces.end(); 472 iterator = interfaces.end();
471 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 473 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
472 QString line = (*it).simplifyWhiteSpace(); 474 QString line = (*it).simplifyWhiteSpace();
473 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ 475 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){
474 uint point = line.find(option); 476 uint point = line.find(option);
475 bool valid = true; 477 bool valid = true;
476 if(point > 0){ 478 if(point > 0){
477 // There are more chars in the line. check +1 479 // There are more chars in the line. check +1
478 if(line.at(point-1) != ' ') 480 if(line.at(point-1) != ' ')
479 valid = false; 481 valid = false;
480 } 482 }
481 point += option.length(); 483 point += option.length();
482 if(point < line.length()-1){ 484 if(point < line.length()-1){
483 // There are more chars in the line. check -1 485 // There are more chars in the line. check -1
484 if(line.at(point) != ' ') 486 if(line.at(point) != ' ')
485 valid = false; 487 valid = false;
486 } 488 }
487 if(valid){ 489 if(valid){
488 if(found == true){ 490 if(found == true){
489 odebug << QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1() << oendl; 491 odebug << QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1() << oendl;
490 } 492 }
491 found = true; 493 found = true;
492 iterator = it; 494 iterator = it;
493 } 495 }
494 } 496 }
495 } 497 }
496 return found; 498 return found;
497} 499}
498 500
499/** 501/**
500 * Sets a value of an option in a stanza 502 * Sets a value of an option in a stanza
501 * @param start the start of the stanza 503 * @param start the start of the stanza
502 * @param option the option to use when setting value. 504 * @param option the option to use when setting value.
503 * @return bool true if successful, false otherwise. 505 * @return bool true if successful, false otherwise.
504 */ 506 */
505bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ 507bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){
506 if(start == interfaces.end()) 508 if(start == interfaces.end())
507 return false; 509 return false;
508 odebug << "setting option" << oendl; 510 odebug << "setting option" << oendl;
509 bool found = false; 511 bool found = false;
510 bool replaced = false; 512 bool replaced = false;
511 QStringList::Iterator insertAt = NULL; 513 QStringList::Iterator insertAt = NULL;
512 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 514 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
513 odebug << " Interfaces::setOption got line >" << (*it).latin1() << "<" << oendl; 515 odebug << " Interfaces::setOption got line >" << (*it).latin1() << "<" << oendl;
514 // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line 516 // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line
515 // but since it works with an empty interfaces file I (tille) will not do anything more 517 // but since it works with an empty interfaces file I (tille) will not do anything more
516 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){ 518 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){
517 if (found) break; 519 if (found) break;
518// && it != start){ 520// && it != start){
519// if(!found && value != ""){ 521// if(!found && value != ""){
520// // Got to the end of the stanza without finding it, so append it. 522// // Got to the end of the stanza without finding it, so append it.
521// odebug << " Got to the end of the stanza without finding it, so append it." << oendl; 523// odebug << " Got to the end of the stanza without finding it, so append it." << oendl;
522// interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); 524// interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
523// } 525// }
524 odebug << "found 1" << oendl; 526 odebug << "found 1" << oendl;
525// interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value)); 527// interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value));
526 found = true; 528 found = true;
527 insertAt = it; 529 insertAt = it;
528 530
529 } 531 }
530 if((*it).contains(option) && it != start && (*it).at(0) != '#'){ 532 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
531 // Found it in stanza so replace it. 533 // Found it in stanza so replace it.
532 odebug << "found 2" << oendl; 534 odebug << "found 2" << oendl;
533 if(found) 535 if(found)
534 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl; 536 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl;
535 found = true; 537 found = true;
536 replaced = true; 538 replaced = true;
537 (*it) = QString("\t%1 %2").arg(option).arg(value); 539 (*it) = QString("\t%1 %2").arg(option).arg(value);
538 } 540 }
539 } 541 }
540 if(!found){ 542 if(!found){
541 odebug << "! found insert anyway" << oendl; 543 odebug << "! found insert anyway" << oendl;
542 QStringList::Iterator p = start; 544 QStringList::Iterator p = start;
543 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); 545 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
544 found = true; 546 found = true;
545 } 547 }
546 548
547 if(found && !replaced){ 549 if(found && !replaced){
548 odebug << "found iface but not the option so insert it here..." << oendl; 550 odebug << "found iface but not the option so insert it here..." << oendl;
549 interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value)); 551 interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value));
550 } 552 }
551 return found; 553 return found;
552} 554}
553 555
554/** 556/**
555 * Removes a stanza and all of its options 557 * Removes a stanza and all of its options
556 * @param stanza the stanza to remove 558 * @param stanza the stanza to remove
557 * @return bool true if successful. 559 * @return bool true if successful.
558 */ 560 */
559bool Interfaces::removeStanza(QStringList::Iterator &stanza){ 561bool Interfaces::removeStanza(QStringList::Iterator &stanza){
560 if(stanza == interfaces.end()) 562 if(stanza == interfaces.end())
561 return false; 563 return false;
562 (*stanza) = ""; 564 (*stanza) = "";
563 return removeAllOptions(stanza); 565 return removeAllOptions(stanza);
564} 566}
565 567
566/** 568/**
567 * Removes a option in a stanza 569 * Removes a option in a stanza
568 * @param start the start of the stanza 570 * @param start the start of the stanza
569 * @param option the option to remove 571 * @param option the option to remove
570 * @return bool true if successful, false otherwise. 572 * @return bool true if successful, false otherwise.
571 */ 573 */
572bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){ 574bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){
573 if(start == interfaces.end()) 575 if(start == interfaces.end())
574 return false; 576 return false;
575 577
576 bool found = false; 578 bool found = false;
577 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 579 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
578 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 580 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
579 // got to the end without finding it 581 // got to the end without finding it
580 break; 582 break;
581 } 583 }
582 if((*it).contains(option) && it != start && (*it).at(0) != '#'){ 584 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
583 // Found it in stanza so replace it. 585 // Found it in stanza so replace it.
584 if(found) 586 if(found)
585 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl; 587 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl;
586 found = true; 588 found = true;
587 it = interfaces.remove( it ); // we really want to remove the line 589 it = interfaces.remove( it ); // we really want to remove the line
588 --it; // we do ++it later in the head of the for loop 590 --it; // we do ++it later in the head of the for loop
589 } 591 }
590 } 592 }
591 return found; 593 return found;
592} 594}
593 595
594/** 596/**
595 * Removes a option in a stanza 597 * Removes a option in a stanza
596 * @param start the start of the stanza 598 * @param start the start of the stanza
597 * @param option the option to use when setting value. 599 * @param option the option to use when setting value.
598 * @return bool true if successful, false otherwise. 600 * @return bool true if successful, false otherwise.
599 */ 601 */
600bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ 602bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){
601 if(start == interfaces.end()) 603 if(start == interfaces.end())
602 return false; 604 return false;
603 605
604 bool found = false; 606 bool found = false;
605 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 607 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
606 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 608 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
607 // got to the end without finding it 609 // got to the end without finding it
608 break; 610 break;
609 } 611 }
610 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ 612 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){
611 // Found it in stanza so replace it. 613 // Found it in stanza so replace it.
612 if(found) 614 if(found)
613 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl; 615 odebug << QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1() << oendl;
614 found = true; 616 found = true;
615 it = interfaces.remove( it ); // we really want to remove the line 617 it = interfaces.remove( it ); // we really want to remove the line
616 --it; // we do ++it later in the head of the for loop 618 --it; // we do ++it later in the head of the for loop
617 } 619 }
618 } 620 }
619 return found; 621 return found;
620} 622}
621 623
622/** 624/**
623 * Removes all options in a stanza 625 * Removes all options in a stanza
624 * @param start the start of the stanza 626 * @param start the start of the stanza
625 * @return bool true if successful, false otherwise. 627 * @return bool true if successful, false otherwise.
626 */ 628 */
627bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ 629bool Interfaces::removeAllOptions(const QStringList::Iterator &start){
628 if(start == interfaces.end()) 630 if(start == interfaces.end())
629 return false; 631 return false;
630 632
631 QStringList::Iterator it = start; 633 QStringList::Iterator it = start;
632 it = ++it; 634 it = ++it;
633 for (; it != interfaces.end(); ++it ) { 635 for (; it != interfaces.end(); ++it ) {
634 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 636 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
635 break; 637 break;
636 } 638 }
637 it = interfaces.remove(it); 639 it = interfaces.remove(it);
638 it = --it; 640 it = --it;
639 } 641 }
640 // Leave a space between this interface and the next. 642 // Leave a space between this interface and the next.
641 interfaces.insert(it, QString("")); 643 interfaces.insert(it, QString(""));
642 return true; 644 return true;
643} 645}
644 646
645/** 647/**
646 * Gets a value of an option in a stanza 648 * Gets a value of an option in a stanza
647 * @param start the start of the stanza 649 * @param start the start of the stanza
648 * @param option the option to use when getting the value. 650 * @param option the option to use when getting the value.
649 * @param bool true if errors false otherwise. 651 * @param bool true if errors false otherwise.
650 * @return QString the value of option QString::null() if error == true. 652 * @return QString the value of option QString::null() if error == true.
651 */ 653 */
652QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ 654QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){
653 if(start == interfaces.end()){ 655 if(start == interfaces.end()){
654 error = false; 656 error = false;
655 return QString(); 657 return QString();
656 } 658 }
657 659
658 QString value; 660 QString value;
659 bool found = false; 661 bool found = false;
660 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { 662 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
661 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ 663 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
662 break; 664 break;
663 } 665 }
664 if((*it).contains(option) && (*it).at(0) != '#'){ 666 if((*it).contains(option) && (*it).at(0) != '#'){
665 if(found) 667 if(found)
666 odebug << QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1() << oendl; 668 odebug << QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1() << oendl;
667 found = true; 669 found = true;
668 QString line = (*it).simplifyWhiteSpace(); 670 QString line = (*it).simplifyWhiteSpace();
669 int space = line.find(" ", option.length()); 671 int space = line.find(" ", option.length());
670 if(space != -1){ 672 if(space != -1){
671 value = line.mid(space+1, line.length()); 673 value = line.mid(space+1, line.length());
672 break; 674 break;
673 } 675 }
674 } 676 }
675 } 677 }
676 error = !found; 678 error = !found;
677 return value; 679 return value;
678} 680}
679 681
680/** 682/**
681 * Write out the interfaces file to the file passed into the constructor. 683 * Write out the interfaces file to the file passed into the constructor.
682 * Removes any excess blank lines over 1 line long. 684 * Removes any excess blank lines over 1 line long.
683 * @return bool true if successful, false if not. 685 * @return bool true if successful, false if not.
684 */ 686 */
685bool Interfaces::write(){ 687bool Interfaces::write(){
686 QFile::remove(interfacesFile); 688 QFile::remove(interfacesFile);
687 QFile file(interfacesFile); 689 QFile file(interfacesFile);
688 690
689 if (!file.open(IO_ReadWrite)){ 691 if (!file.open(IO_ReadWrite)){
690 odebug << QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1() << oendl; 692 odebug << QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1() << oendl;
691 return false; 693 return false;
692 } 694 }
693 QTextStream stream( &file ); 695 QTextStream stream( &file );
694 int whiteSpaceCount = 0; 696 int whiteSpaceCount = 0;
695 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { 697 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
696 QString line = (*it).simplifyWhiteSpace(); 698 QString line = (*it).simplifyWhiteSpace();
697 line = line.replace(QRegExp(" "),""); 699 line = line.replace(QRegExp(" "),"");
698 if(line.length() == 0) 700 if(line.length() == 0)
699 whiteSpaceCount++; 701 whiteSpaceCount++;
700 else 702 else
701 whiteSpaceCount = 0; 703 whiteSpaceCount = 0;
702 if(whiteSpaceCount < 2){ 704 if(whiteSpaceCount < 2){
703 odebug << (*it).latin1() << oendl; 705 odebug << (*it).latin1() << oendl;
704 stream << (*it) << '\n'; 706 stream << (*it) << '\n';
705 } 707 }
706 } 708 }
707 file.close(); 709 file.close();
708 return true; 710 return true;
709} 711}
710 712
711// interfaces.cpp 713// interfaces.cpp
712 714
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
index ec3bad3..8498759 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -1,208 +1,209 @@
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 <opie2/oprocess.h> 12#include <opie2/oprocess.h>
13 13
14#ifdef QWS 14#ifdef QWS
15#include <opie2/owait.h> 15#include <opie2/owait.h>
16#include <opie2/odebug.h>
16#include <qpe/global.h> 17#include <qpe/global.h>
17#include <qapplication.h> 18#include <qapplication.h>
18#endif 19#endif
19 20
20#define DNSSCRIPT "changedns" 21#define DNSSCRIPT "changedns"
21 22
22/** 23/**
23 * Constuctor. Set up the connection. A profile must be set. 24 * Constuctor. Set up the connection. A profile must be set.
24 */ 25 */
25using namespace Opie::Ui; 26using namespace Opie::Ui;
26using namespace Opie::Core; 27using namespace Opie::Core;
27InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, Interfaces *j, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i), interfaces(j), delInterfaces(false){ 28InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, Interfaces *j, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i), interfaces(j), delInterfaces(false){
28 if (j == 0) { 29 if (j == 0) {
29 delInterfaces = true; 30 delInterfaces = true;
30 interfaces = new Interfaces; 31 interfaces = new Interfaces;
31 } 32 }
32} 33}
33 34
34/** 35/**
35 * Destructor 36 * Destructor
36 */ 37 */
37InterfaceSetupImp::~InterfaceSetupImp(){ 38InterfaceSetupImp::~InterfaceSetupImp(){
38 if(delInterfaces) { 39 if(delInterfaces) {
39 delete interfaces; 40 delete interfaces;
40 } 41 }
41} 42}
42 43
43/** 44/**
44 * Save the current settings, then write out the interfaces file and close. 45 * Save the current settings, then write out the interfaces file and close.
45 */ 46 */
46bool InterfaceSetupImp::saveChanges(){ 47bool InterfaceSetupImp::saveChanges(){
47 bool error; 48 bool error;
48 QString iface = interfaces->getInterfaceName(error); 49 QString iface = interfaces->getInterfaceName(error);
49 odebug << "InterfaceSetupImp::saveChanges saves interface " << iface.latin1() << "" << oendl; 50 odebug << "InterfaceSetupImp::saveChanges saves interface " << iface.latin1() << "" << oendl;
50 if(!saveSettings()) 51 if(!saveSettings())
51 return false; 52 return false;
52 53
53 interfaces->write(); 54 interfaces->write();
54 55
55 if (interface->getStatus()) { 56 if (interface->getStatus()) {
56 QString ifup; 57 QString ifup;
57 ifup += "ifdown "; 58 ifup += "ifdown ";
58 ifup += iface; 59 ifup += iface;
59 ifup += "; ifup "; 60 ifup += "; ifup ";
60 ifup += iface; 61 ifup += iface;
61 ifup += ";"; 62 ifup += ";";
62 63
63 OProcess restart; 64 OProcess restart;
64 restart << "sh"; 65 restart << "sh";
65 restart << "-c"; 66 restart << "-c";
66 restart << ifup; 67 restart << ifup;
67 68
68 OWait *owait = new OWait(); 69 OWait *owait = new OWait();
69 Global::statusMessage( tr( "Restarting interface" ) ); 70 Global::statusMessage( tr( "Restarting interface" ) );
70 71
71 owait->show(); 72 owait->show();
72 qApp->processEvents(); 73 qApp->processEvents();
73 74
74 if (!restart.start(OProcess::Block, OProcess::NoCommunication) ) { 75 if (!restart.start(OProcess::Block, OProcess::NoCommunication) ) {
75 owarn << "unstable to spawn ifdown/ifup" << oendl; 76 owarn << "unstable to spawn ifdown/ifup" << oendl;
76 } 77 }
77 78
78 owait->hide(); 79 owait->hide();
79 delete owait; 80 delete owait;
80 81
81 interface->refresh(); 82 interface->refresh();
82 } 83 }
83 return true; 84 return true;
84} 85}
85 86
86/** 87/**
87 * Save the settings for the current Interface. 88 * Save the settings for the current Interface.
88 * @return bool true if successful, false otherwise 89 * @return bool true if successful, false otherwise
89 */ 90 */
90bool InterfaceSetupImp::saveSettings(){ 91bool InterfaceSetupImp::saveSettings(){
91 // eh can't really do anything about it other then return. :-D 92 // eh can't really do anything about it other then return. :-D
92 if(!interfaces->isInterfaceSet()) 93 if(!interfaces->isInterfaceSet())
93 return true; 94 return true;
94 95
95 bool error = false; 96 bool error = false;
96 // Loopback case 97 // Loopback case
97 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 98 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
98 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 99 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
99 return true; 100 return true;
100 } 101 }
101 102
102 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ 103 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){
103 QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); 104 QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok);
104 return false; 105 return false;
105 } 106 }
106 // DHCP 107 // DHCP
107 if(dhcpCheckBox->isChecked()) { 108 if(dhcpCheckBox->isChecked()) {
108 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); 109 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
109 interfaces->removeInterfaceOption("address"); 110 interfaces->removeInterfaceOption("address");
110 interfaces->removeInterfaceOption("netmask"); 111 interfaces->removeInterfaceOption("netmask");
111 interfaces->removeInterfaceOption("gateway"); 112 interfaces->removeInterfaceOption("gateway");
112 interfaces->removeInterfaceOption("up "DNSSCRIPT" -a "); 113 interfaces->removeInterfaceOption("up "DNSSCRIPT" -a ");
113 interfaces->removeInterfaceOption("down "DNSSCRIPT" -r "); 114 interfaces->removeInterfaceOption("down "DNSSCRIPT" -r ");
114 } else{ 115 } else{
115 interfaces->setInterfaceMethod("static"); 116 interfaces->setInterfaceMethod("static");
116 interfaces->setInterfaceOption("address", ipAddressEdit->text()); 117 interfaces->setInterfaceOption("address", ipAddressEdit->text());
117 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); 118 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
118 interfaces->setInterfaceOption("gateway", gatewayEdit->text()); 119 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
119 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ 120 if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){
120 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); 121 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
121 interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); 122 interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns);
122 interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); 123 interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns);
123 }else{ 124 }else{
124 interfaces->removeInterfaceOption("up "DNSSCRIPT" -a "); 125 interfaces->removeInterfaceOption("up "DNSSCRIPT" -a ");
125 interfaces->removeInterfaceOption("down "DNSSCRIPT" -r"); 126 interfaces->removeInterfaceOption("down "DNSSCRIPT" -r");
126 } 127 }
127 } 128 }
128 129
129 // IP Information 130 // IP Information
130 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); 131 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
131 return true; 132 return true;
132} 133}
133 134
134/** 135/**
135 * The Profile has changed. 136 * The Profile has changed.
136 * @param QString profile the new profile. 137 * @param QString profile the new profile.
137 */ 138 */
138void InterfaceSetupImp::setProfile(const QString &profile){ 139void InterfaceSetupImp::setProfile(const QString &profile){
139 /* 140 /*
140 bool error = false; 141 bool error = false;
141 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ 142 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
142 staticGroupBox->hide(); 143 staticGroupBox->hide();
143 dhcpCheckBox->hide(); 144 dhcpCheckBox->hide();
144 leaseTime->hide(); 145 leaseTime->hide();
145 leaseHoursLabel->hide(); 146 leaseHoursLabel->hide();
146 } 147 }
147 */ 148 */
148 149
149 QString newInterfaceName = interface->getInterfaceName(); 150 QString newInterfaceName = interface->getInterfaceName();
150 if(profile.length() > 0) 151 if(profile.length() > 0)
151 newInterfaceName += "_" + profile; 152 newInterfaceName += "_" + profile;
152 // See if we have to make a interface. 153 // See if we have to make a interface.
153 if(!interfaces->setInterface(newInterfaceName)){ 154 if(!interfaces->setInterface(newInterfaceName)){
154 // Add making for this new interface if need too 155 // Add making for this new interface if need too
155 if(profile != ""){ 156 if(profile != ""){
156 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); 157 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
157 if(!interfaces->setMapping(interface->getInterfaceName())){ 158 if(!interfaces->setMapping(interface->getInterfaceName())){
158 interfaces->addMapping(interface->getInterfaceName()); 159 interfaces->addMapping(interface->getInterfaceName());
159 if(!interfaces->setMapping(interface->getInterfaceName())){ 160 if(!interfaces->setMapping(interface->getInterfaceName())){
160 odebug << "InterfaceSetupImp: Added Mapping, but still can't setInterface." << oendl; 161 odebug << "InterfaceSetupImp: Added Mapping, but still can't setInterface." << oendl;
161 return; 162 return;
162 } 163 }
163 } 164 }
164 interfaces->setMap("map", newInterfaceName); 165 interfaces->setMap("map", newInterfaceName);
165 interfaces->setScript("getprofile.sh"); 166 interfaces->setScript("getprofile.sh");
166 } 167 }
167 else{ 168 else{
168 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); 169 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
169 if(!interfaces->setInterface(newInterfaceName)){ 170 if(!interfaces->setInterface(newInterfaceName)){
170 odebug << "InterfaceSetupImp: Added interface, but still can't setInterface." << oendl; 171 odebug << "InterfaceSetupImp: Added interface, but still can't setInterface." << oendl;
171 return; 172 return;
172 } 173 }
173 } 174 }
174 } 175 }
175 176
176 // We must have a valid interface to get this far so read some settings. 177 // We must have a valid interface to get this far so read some settings.
177 178
178 // DHCP 179 // DHCP
179 bool error = false; 180 bool error = false;
180 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) 181 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
181 dhcpCheckBox->setChecked(true); 182 dhcpCheckBox->setChecked(true);
182 else 183 else
183 dhcpCheckBox->setChecked(false); 184 dhcpCheckBox->setChecked(false);
184 185
185 // IP Information 186 // IP Information
186 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); 187 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
187 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); 188 QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error);
188 odebug << "dns >" << dns.latin1() << "<" << oendl; 189 odebug << "dns >" << dns.latin1() << "<" << oendl;
189 if(dns.contains(" ")){ 190 if(dns.contains(" ")){
190 firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); 191 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
191 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); 192 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
192 }else firstDNSLineEdit->setText(dns); 193 }else firstDNSLineEdit->setText(dns);
193 194
194 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); 195 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
195 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); 196 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
196 if (subnetMaskEdit->text().isEmpty()) 197 if (subnetMaskEdit->text().isEmpty())
197 subnetMaskEdit->setText( "255.255.255.0" ); 198 subnetMaskEdit->setText( "255.255.255.0" );
198 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); 199 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
199 200
200 201
201 202
202 owarn << "InterfaceSetupImp::setProfile(" << profile.latin1() << ")\n" << oendl; 203 owarn << "InterfaceSetupImp::setProfile(" << profile.latin1() << ")\n" << oendl;
203 owarn << "InterfaceSetupImp::setProfile: iface is " << interfaces->getInterfaceName(error).latin1() << "\n" << oendl; 204 owarn << "InterfaceSetupImp::setProfile: iface is " << interfaces->getInterfaceName(error).latin1() << "\n" << oendl;
204 205
205} 206}
206 207
207// interfacesetup.cpp 208// interfacesetup.cpp
208 209
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 3e1a650..5184630 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,748 +1,749 @@
1 1
2#include "mainwindowimp.h" 2#include "mainwindowimp.h"
3#include "addconnectionimp.h" 3#include "addconnectionimp.h"
4#include "interfaceinformationimp.h" 4#include "interfaceinformationimp.h"
5#include "interfacesetupimp.h" 5#include "interfacesetupimp.h"
6#include "interfaces.h" 6#include "interfaces.h"
7#include "module.h" 7#include "module.h"
8 8
9/* OPIE */ 9/* OPIE */
10#include <opie2/odebug.h>
10#include <qpe/qcopenvelope_qws.h> 11#include <qpe/qcopenvelope_qws.h>
11#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
12#include <qpe/config.h> 13#include <qpe/config.h>
13#include <qpe/qlibrary.h> 14#include <qpe/qlibrary.h>
14#include <qpe/resource.h> 15#include <qpe/resource.h>
15 16
16/* QT */ 17/* QT */
17#include <qpushbutton.h> 18#include <qpushbutton.h>
18#include <qlistbox.h> 19#include <qlistbox.h>
19#include <qlineedit.h> 20#include <qlineedit.h>
20#include <qlistview.h> 21#include <qlistview.h>
21#include <qheader.h> 22#include <qheader.h>
22#include <qlabel.h> 23#include <qlabel.h>
23#include <qtabwidget.h> // in order to disable the profiles tab 24#include <qtabwidget.h> // in order to disable the profiles tab
24#include <qmessagebox.h> 25#include <qmessagebox.h>
25 26
26 27
27#if QT_VERSION < 300 28#if QT_VERSION < 300
28#include <qlist.h> 29#include <qlist.h>
29#else 30#else
30#include <qptrlist.h> 31#include <qptrlist.h>
31#endif 32#endif
32#include <qdir.h> 33#include <qdir.h>
33#include <qfile.h> 34#include <qfile.h>
34#include <qtextstream.h> 35#include <qtextstream.h>
35#include <qregexp.h> 36#include <qregexp.h>
36 37
37/* STD */ 38/* STD */
38#include <net/if.h> 39#include <net/if.h>
39#include <sys/ioctl.h> 40#include <sys/ioctl.h>
40#include <sys/socket.h> 41#include <sys/socket.h>
41 42
42#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 43#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
43#define _PROCNETDEV "/proc/net/dev" 44#define _PROCNETDEV "/proc/net/dev"
44 45
45MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) 46MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME)
46{ 47{
47 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 48 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
48 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 49 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
49 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 50 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
50 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 51 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
51 52
52 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 53 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
53 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 54 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
54 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 55 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
55 56
56 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 57 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
57 58
58 //FIXME: disable profiles for the moment: 59 //FIXME: disable profiles for the moment:
59 tabWidget->setTabEnabled( tab, false ); 60 tabWidget->setTabEnabled( tab, false );
60 61
61 // Load connections. 62 // Load connections.
62 // /usr/local/kde/lib/libinterfaces.la 63 // /usr/local/kde/lib/libinterfaces.la
63#ifdef QWS 64#ifdef QWS
64 loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); 65 loadModules(QPEApplication::qpeDir() + "plugins/networksettings");
65#else 66#else
66 loader = KLibLoader::self(); 67 loader = KLibLoader::self();
67 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); 68 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib"));
68#endif 69#endif
69 getAllInterfaces(); 70 getAllInterfaces();
70 71
71 Interfaces i; 72 Interfaces i;
72 QStringList list = i.getInterfaceList(); 73 QStringList list = i.getInterfaceList();
73 QMap<QString, Interface*>::Iterator it; 74 QMap<QString, Interface*>::Iterator it;
74 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) 75 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni )
75 { 76 {
76 /* 77 /*
77 * we skipped it in getAllInterfaces now 78 * we skipped it in getAllInterfaces now
78 * we need to ignore it as well 79 * we need to ignore it as well
79 */ 80 */
80 if (m_handledIfaces.contains( *ni) ) 81 if (m_handledIfaces.contains( *ni) )
81 { 82 {
82 odebug << "Not up iface handled by module" << oendl; 83 odebug << "Not up iface handled by module" << oendl;
83 continue; 84 continue;
84 } 85 }
85 bool found = false; 86 bool found = false;
86 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) 87 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it )
87 { 88 {
88 if(it.key() == (*ni)) 89 if(it.key() == (*ni))
89 found = true; 90 found = true;
90 } 91 }
91 if(!found) 92 if(!found)
92 { 93 {
93 if(!(*ni).contains("_")) 94 if(!(*ni).contains("_"))
94 { 95 {
95 Interface *i = new Interface(this, *ni, false); 96 Interface *i = new Interface(this, *ni, false);
96 i->setAttached(false); 97 i->setAttached(false);
97 i->setHardwareName(tr("Disconnected")); 98 i->setHardwareName(tr("Disconnected"));
98 interfaceNames.insert(i->getInterfaceName(), i); 99 interfaceNames.insert(i->getInterfaceName(), i);
99 updateInterface(i); 100 updateInterface(i);
100 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); 101 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*)));
101 } 102 }
102 } 103 }
103 } 104 }
104 105
105 //getInterfaceList(); 106 //getInterfaceList();
106 connectionList->header()->hide(); 107 connectionList->header()->hide();
107 108
108 Config cfg("NetworkSetup"); 109 Config cfg("NetworkSetup");
109 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 110 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
110 for ( QStringList::Iterator it = profiles.begin(); 111 for ( QStringList::Iterator it = profiles.begin();
111 it != profiles.end(); ++it) 112 it != profiles.end(); ++it)
112 profilesList->insertItem((*it)); 113 profilesList->insertItem((*it));
113 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 114 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
114 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 115 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
115 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 116 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
116 117
117 QFile file(scheme); 118 QFile file(scheme);
118 if ( file.open(IO_ReadOnly) ) 119 if ( file.open(IO_ReadOnly) )
119 { // file opened successfully 120 { // file opened successfully
120 QTextStream stream( &file ); // use a text stream 121 QTextStream stream( &file ); // use a text stream
121 while ( !stream.eof() ) 122 while ( !stream.eof() )
122 { // until end of file... 123 { // until end of file...
123 QString line = stream.readLine(); // line of text excluding '\n' 124 QString line = stream.readLine(); // line of text excluding '\n'
124 if(line.contains("SCHEME")) 125 if(line.contains("SCHEME"))
125 { 126 {
126 line = line.mid(7, line.length()); 127 line = line.mid(7, line.length());
127 currentProfileLabel->setText(line); 128 currentProfileLabel->setText(line);
128 break; 129 break;
129 } 130 }
130 } 131 }
131 file.close(); 132 file.close();
132 } 133 }
133 makeChannel(); 134 makeChannel();
134} 135}
135 136
136/** 137/**
137 * Deconstructor. Save profiles. Delete loaded libraries. 138 * Deconstructor. Save profiles. Delete loaded libraries.
138 */ 139 */
139MainWindowImp::~MainWindowImp() 140MainWindowImp::~MainWindowImp()
140{ 141{
141 // Save profiles. 142 // Save profiles.
142 Config cfg("NetworkSetup"); 143 Config cfg("NetworkSetup");
143 cfg.setGroup("General"); 144 cfg.setGroup("General");
144 cfg.writeEntry("Profiles", profiles.join(" ")); 145 cfg.writeEntry("Profiles", profiles.join(" "));
145 146
146 // Delete all interfaces that don't have owners. 147 // Delete all interfaces that don't have owners.
147 QMap<Interface*, QListViewItem*>::Iterator iIt; 148 QMap<Interface*, QListViewItem*>::Iterator iIt;
148 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 149 for( iIt = items.begin(); iIt != items.end(); ++iIt )
149 { 150 {
150 if(iIt.key()->getModuleOwner() == NULL) 151 if(iIt.key()->getModuleOwner() == NULL)
151 delete iIt.key(); 152 delete iIt.key();
152 } 153 }
153 154
154#ifdef QWS 155#ifdef QWS
155 // Delete Modules and Libraries 156 // Delete Modules and Libraries
156 QMap<Module*, QLibrary*>::Iterator it; 157 QMap<Module*, QLibrary*>::Iterator it;
157 for( it = libraries.begin(); it != libraries.end(); ++it ) 158 for( it = libraries.begin(); it != libraries.end(); ++it )
158 { 159 {
159 delete it.key(); 160 delete it.key();
160 // I wonder why I can't delete the libraries 161 // I wonder why I can't delete the libraries
161 // What fucking shit this is. 162 // What fucking shit this is.
162 //delete it.data(); 163 //delete it.data();
163 } 164 }
164#else 165#else
165 // klibloader automaticly deletes the libraries for us... 166 // klibloader automaticly deletes the libraries for us...
166#endif 167#endif
167} 168}
168 169
169/** 170/**
170 * Query the kernel for all of the interfaces. 171 * Query the kernel for all of the interfaces.
171 */ 172 */
172void MainWindowImp::getAllInterfaces() 173void MainWindowImp::getAllInterfaces()
173{ 174{
174 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 175 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
175 if(sockfd == -1) 176 if(sockfd == -1)
176 return; 177 return;
177 178
178 struct ifreq ifr; 179 struct ifreq ifr;
179 QStringList ifaces; 180 QStringList ifaces;
180 QFile procFile(QString(_PROCNETDEV)); 181 QFile procFile(QString(_PROCNETDEV));
181 int result; 182 int result;
182 Interface *i; 183 Interface *i;
183 184
184 if (! procFile.exists()) 185 if (! procFile.exists())
185 { 186 {
186 struct ifreq ifrs[100]; 187 struct ifreq ifrs[100];
187 struct ifconf ifc; 188 struct ifconf ifc;
188 ifc.ifc_len = sizeof(ifrs); 189 ifc.ifc_len = sizeof(ifrs);
189 ifc.ifc_req = ifrs; 190 ifc.ifc_req = ifrs;
190 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 191 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
191 192
192 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 193 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
193 { 194 {
194 struct ifreq *pifr = &ifrs[i]; 195 struct ifreq *pifr = &ifrs[i];
195 196
196 ifaces += pifr->ifr_name; 197 ifaces += pifr->ifr_name;
197 } 198 }
198 } 199 }
199 else 200 else
200 { 201 {
201 procFile.open(IO_ReadOnly); 202 procFile.open(IO_ReadOnly);
202 QString line; 203 QString line;
203 QTextStream procTs(&procFile); 204 QTextStream procTs(&procFile);
204 int loc = -1; 205 int loc = -1;
205 206
206 procTs.readLine(); // eat a line 207 procTs.readLine(); // eat a line
207 procTs.readLine(); // eat a line 208 procTs.readLine(); // eat a line
208 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 209 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
209 { 210 {
210 if((loc = line.find(":")) != -1) 211 if((loc = line.find(":")) != -1)
211 { 212 {
212 ifaces += line.left(loc); 213 ifaces += line.left(loc);
213 } 214 }
214 } 215 }
215 } 216 }
216 217
217 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 218 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
218 { 219 {
219 int flags = 0; 220 int flags = 0;
220 if ( m_handledIfaces.contains( (*it) ) ) 221 if ( m_handledIfaces.contains( (*it) ) )
221 { 222 {
222 odebug << " " << (*it).latin1() << " is handled by a module" << oendl; 223 odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
223 continue; 224 continue;
224 } 225 }
225 // int family; 226 // int family;
226 i = NULL; 227 i = NULL;
227 228
228 strcpy(ifr.ifr_name, (*it).latin1()); 229 strcpy(ifr.ifr_name, (*it).latin1());
229 230
230 struct ifreq ifcopy; 231 struct ifreq ifcopy;
231 ifcopy = ifr; 232 ifcopy = ifr;
232 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 233 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
233 flags = ifcopy.ifr_flags; 234 flags = ifcopy.ifr_flags;
234 i = new Interface(this, ifr.ifr_name, false); 235 i = new Interface(this, ifr.ifr_name, false);
235 i->setAttached(true); 236 i->setAttached(true);
236 if ((flags & IFF_UP) == IFF_UP) 237 if ((flags & IFF_UP) == IFF_UP)
237 i->setStatus(true); 238 i->setStatus(true);
238 else 239 else
239 i->setStatus(false); 240 i->setStatus(false);
240 241
241 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 242 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
242 i->setHardwareName("Ethernet"); 243 i->setHardwareName("Ethernet");
243 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 244 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
244 i->setHardwareName("Point to Point"); 245 i->setHardwareName("Point to Point");
245 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 246 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
246 i->setHardwareName("Multicast"); 247 i->setHardwareName("Multicast");
247 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 248 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
248 i->setHardwareName("Loopback"); 249 i->setHardwareName("Loopback");
249 else 250 else
250 i->setHardwareName("Unknown"); 251 i->setHardwareName("Unknown");
251 252
252 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; 253 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
253 interfaceNames.insert(i->getInterfaceName(), i); 254 interfaceNames.insert(i->getInterfaceName(), i);
254 updateInterface(i); 255 updateInterface(i);
255 connect(i, SIGNAL(updateInterface(Interface*)), 256 connect(i, SIGNAL(updateInterface(Interface*)),
256 this, SLOT(updateInterface(Interface*))); 257 this, SLOT(updateInterface(Interface*)));
257 } 258 }
258 // now lets ask the plugins too ;) 259 // now lets ask the plugins too ;)
259 QMap<Module*, QLibrary*>::Iterator it; 260 QMap<Module*, QLibrary*>::Iterator it;
260 QList<Interface> ilist; 261 QList<Interface> ilist;
261 for( it = libraries.begin(); it != libraries.end(); ++it ) 262 for( it = libraries.begin(); it != libraries.end(); ++it )
262 { 263 {
263 if(it.key()) 264 if(it.key())
264 { 265 {
265 ilist = it.key()->getInterfaces(); 266 ilist = it.key()->getInterfaces();
266 for( i = ilist.first(); i != 0; i = ilist.next() ) 267 for( i = ilist.first(); i != 0; i = ilist.next() )
267 { 268 {
268 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl; 269 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl;
269 interfaceNames.insert(i->getInterfaceName(), i); 270 interfaceNames.insert(i->getInterfaceName(), i);
270 updateInterface(i); 271 updateInterface(i);
271 connect(i, SIGNAL(updateInterface(Interface*)), 272 connect(i, SIGNAL(updateInterface(Interface*)),
272 this, SLOT(updateInterface(Interface*))); 273 this, SLOT(updateInterface(Interface*)));
273 } 274 }
274 } 275 }
275 } 276 }
276} 277}
277 278
278/** 279/**
279 * Load all modules that are found in the path 280 * Load all modules that are found in the path
280 * @param path a directory that is scaned for any plugins that can be loaded 281 * @param path a directory that is scaned for any plugins that can be loaded
281 * and attempts to load them 282 * and attempts to load them
282 */ 283 */
283void MainWindowImp::loadModules(const QString &path) 284void MainWindowImp::loadModules(const QString &path)
284{ 285{
285#ifdef DEBUG 286#ifdef DEBUG
286 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl; 287 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl;
287#endif 288#endif
288 QDir d(path); 289 QDir d(path);
289 if(!d.exists()) 290 if(!d.exists())
290 return; 291 return;
291 292
292 // Don't want sym links 293 // Don't want sym links
293 d.setFilter( QDir::Files | QDir::NoSymLinks ); 294 d.setFilter( QDir::Files | QDir::NoSymLinks );
294 const QFileInfoList *list = d.entryInfoList(); 295 const QFileInfoList *list = d.entryInfoList();
295 QFileInfoListIterator it( *list ); 296 QFileInfoListIterator it( *list );
296 QFileInfo *fi; 297 QFileInfo *fi;
297 while ( (fi=it.current()) ) 298 while ( (fi=it.current()) )
298 { 299 {
299#ifdef QWS 300#ifdef QWS
300 if(fi->fileName().contains(".so")) 301 if(fi->fileName().contains(".so"))
301 { 302 {
302#else 303#else
303 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")) 304 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_"))
304 { 305 {
305#endif 306#endif
306 loadPlugin(path + "/" + fi->fileName()); 307 loadPlugin(path + "/" + fi->fileName());
307 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl; 308 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl;
308 } 309 }
309 ++it; 310 ++it;
310 } 311 }
311} 312}
312 313
313/** 314/**
314 * Attempt to load a function and resolve a function. 315 * Attempt to load a function and resolve a function.
315 * @param pluginFileName - the name of the file in which to attempt to load 316 * @param pluginFileName - the name of the file in which to attempt to load
316 * @param resolveString - function pointer to resolve 317 * @param resolveString - function pointer to resolve
317 * @return pointer to the function with name resolveString or NULL 318 * @return pointer to the function with name resolveString or NULL
318 */ 319 */
319Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString) 320Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString)
320{ 321{
321#ifdef DEBUG 322#ifdef DEBUG
322 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl; 323 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl;
323#endif 324#endif
324#ifdef QWS 325#ifdef QWS
325 QLibrary *lib = new QLibrary(pluginFileName); 326 QLibrary *lib = new QLibrary(pluginFileName);
326 void *functionPointer = lib->resolve(resolveString); 327 void *functionPointer = lib->resolve(resolveString);
327 if( !functionPointer ) 328 if( !functionPointer )
328 { 329 {
329#ifdef DEBUG 330#ifdef DEBUG
330 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl; 331 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl;
331#endif 332#endif
332 delete lib; 333 delete lib;
333 return NULL; 334 return NULL;
334 } 335 }
335 // Try to get an object. 336 // Try to get an object.
336 Module *object = ((Module* (*)()) functionPointer)(); 337 Module *object = ((Module* (*)()) functionPointer)();
337 if(object == NULL) 338 if(object == NULL)
338 { 339 {
339#ifdef DEBUG 340#ifdef DEBUG
340 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl; 341 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
341#endif 342#endif
342 delete lib; 343 delete lib;
343 return NULL; 344 return NULL;
344 } 345 }
345 346
346 m_handledIfaces += object->handledInterfaceNames(); 347 m_handledIfaces += object->handledInterfaceNames();
347 // Store for deletion later 348 // Store for deletion later
348 libraries.insert(object, lib); 349 libraries.insert(object, lib);
349 return object; 350 return object;
350 351
351#else 352#else
352 QLibrary *lib = loader->library(pluginFileName); 353 QLibrary *lib = loader->library(pluginFileName);
353 if( !lib || !lib->hasSymbol(resolveString) ) 354 if( !lib || !lib->hasSymbol(resolveString) )
354 { 355 {
355 odebug << QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1() << oendl; 356 odebug << QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1() << oendl;
356 return NULL; 357 return NULL;
357 } 358 }
358 // Try to get an object. 359 // Try to get an object.
359 Module *object = ((Module* (*)()) lib->symbol(resolveString))(); 360 Module *object = ((Module* (*)()) lib->symbol(resolveString))();
360 if(object == NULL) 361 if(object == NULL)
361 { 362 {
362#ifdef DEBUG 363#ifdef DEBUG
363 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl; 364 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
364#endif 365#endif
365 return NULL; 366 return NULL;
366 } 367 }
367#ifdef DEBUG 368#ifdef DEBUG
368 odebug << "MainWindowImp::loadPlugin:: Found object, storing." << oendl; 369 odebug << "MainWindowImp::loadPlugin:: Found object, storing." << oendl;
369#endif 370#endif
370 // Store for deletion later 371 // Store for deletion later
371 libraries.insert(object, lib); 372 libraries.insert(object, lib);
372 return object; 373 return object;
373#endif 374#endif
374} 375}
375 376
376/** 377/**
377 * The Add button was clicked. Bring up the add dialog and if OK is hit 378 * The Add button was clicked. Bring up the add dialog and if OK is hit
378 * load the plugin and append it to the list 379 * load the plugin and append it to the list
379 */ 380 */
380void MainWindowImp::addClicked() 381void MainWindowImp::addClicked()
381{ 382{
382 QMap<Module*, QLibrary*>::Iterator it; 383 QMap<Module*, QLibrary*>::Iterator it;
383 QMap<QString, QString> list; 384 QMap<QString, QString> list;
384 QMap<QString, Module*> newInterfaceOwners; 385 QMap<QString, Module*> newInterfaceOwners;
385 386
386 for( it = libraries.begin(); it != libraries.end(); ++it ) 387 for( it = libraries.begin(); it != libraries.end(); ++it )
387 { 388 {
388 if(it.key()) 389 if(it.key())
389 { 390 {
390 (it.key())->possibleNewInterfaces(list); 391 (it.key())->possibleNewInterfaces(list);
391 } 392 }
392 } 393 }
393 // See if the list has anything that we can add. 394 // See if the list has anything that we can add.
394 if(list.count() == 0) 395 if(list.count() == 0)
395 { 396 {
396 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 397 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
397 return; 398 return;
398 } 399 }
399 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 400 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
400 addNewConnection.addConnections(list); 401 addNewConnection.addConnections(list);
401 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) ) 402 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) )
402 { 403 {
403 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 404 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
404 if(!item) 405 if(!item)
405 return; 406 return;
406 407
407 for( it = libraries.begin(); it != libraries.end(); ++it ) 408 for( it = libraries.begin(); it != libraries.end(); ++it )
408 { 409 {
409 if(it.key()) 410 if(it.key())
410 { 411 {
411 Interface *i = (it.key())->addNewInterface(item->text(0)); 412 Interface *i = (it.key())->addNewInterface(item->text(0));
412 if(i) 413 if(i)
413 { 414 {
414 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl; 415 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl;
415 interfaceNames.insert(i->getInterfaceName(), i); 416 interfaceNames.insert(i->getInterfaceName(), i);
416 updateInterface(i); 417 updateInterface(i);
417 } 418 }
418 } 419 }
419 } 420 }
420 } 421 }
421} 422}
422 423
423/** 424/**
424 * Prompt the user to see if they really want to do this. 425 * Prompt the user to see if they really want to do this.
425 * If they do then remove from the list and unload. 426 * If they do then remove from the list and unload.
426 */ 427 */
427void MainWindowImp::removeClicked() 428void MainWindowImp::removeClicked()
428{ 429{
429 QListViewItem *item = connectionList->currentItem(); 430 QListViewItem *item = connectionList->currentItem();
430 if(!item) 431 if(!item)
431 { 432 {
432 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 433 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
433 return; 434 return;
434 } 435 }
435 436
436 Interface *i = interfaceItems[item]; 437 Interface *i = interfaceItems[item];
437 if(i->getModuleOwner() == NULL) 438 if(i->getModuleOwner() == NULL)
438 { 439 {
439 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 440 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
440 } 441 }
441 else 442 else
442 { 443 {
443 if(!i->getModuleOwner()->remove(i)) 444 if(!i->getModuleOwner()->remove(i))
444 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); 445 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok);
445 else 446 else
446 { 447 {
447 delete item; 448 delete item;
448 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 449 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
449 } 450 }
450 } 451 }
451} 452}
452 453
453/** 454/**
454 * Pull up the configure about the currently selected interface. 455 * Pull up the configure about the currently selected interface.
455 * Report an error if no interface is selected. 456 * Report an error if no interface is selected.
456 * If the interface has a module owner then request its configure. 457 * If the interface has a module owner then request its configure.
457 */ 458 */
458void MainWindowImp::configureClicked() 459void MainWindowImp::configureClicked()
459{ 460{
460 QListViewItem *item = connectionList->currentItem(); 461 QListViewItem *item = connectionList->currentItem();
461 if(!item) 462 if(!item)
462 { 463 {
463 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); 464 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok);
464 return; 465 return;
465 } 466 }
466 467
467 QString currentProfileText = currentProfileLabel->text(); 468 QString currentProfileText = currentProfileLabel->text();
468 if(currentProfileText.upper() == "ALL"); 469 if(currentProfileText.upper() == "ALL");
469 currentProfileText = ""; 470 currentProfileText = "";
470 471
471 Interface *i = interfaceItems[item]; 472 Interface *i = interfaceItems[item];
472 473
473 if(i->getModuleOwner()) 474 if(i->getModuleOwner())
474 { 475 {
475 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 476 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
476 if(moduleConfigure != NULL) 477 if(moduleConfigure != NULL)
477 { 478 {
478 i->getModuleOwner()->setProfile(currentProfileText); 479 i->getModuleOwner()->setProfile(currentProfileText);
479 QPEApplication::showWidget( moduleConfigure ); 480 QPEApplication::showWidget( moduleConfigure );
480 return; 481 return;
481 } 482 }
482 } 483 }
483 484
484 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp ); 485 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp );
485 configure->setProfile(currentProfileText); 486 configure->setProfile(currentProfileText);
486 QPEApplication::showDialog( configure ); 487 QPEApplication::showDialog( configure );
487} 488}
488 489
489/** 490/**
490 * Pull up the information about the currently selected interface. 491 * Pull up the information about the currently selected interface.
491 * Report an error if no interface is selected. 492 * Report an error if no interface is selected.
492 * If the interface has a module owner then request its configure. 493 * If the interface has a module owner then request its configure.
493 */ 494 */
494void MainWindowImp::informationClicked() 495void MainWindowImp::informationClicked()
495{ 496{
496 QListViewItem *item = connectionList->currentItem(); 497 QListViewItem *item = connectionList->currentItem();
497 if(!item) 498 if(!item)
498 { 499 {
499 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 500 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
500 return; 501 return;
501 } 502 }
502 503
503 Interface *i = interfaceItems[item]; 504 Interface *i = interfaceItems[item];
504 // if(!i->isAttached()){ 505 // if(!i->isAttached()){
505 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 506 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
506 // return; 507 // return;
507 // } 508 // }
508 509
509 if(i->getModuleOwner()) 510 if(i->getModuleOwner())
510 { 511 {
511 QWidget *moduleInformation = i->getModuleOwner()->information(i); 512 QWidget *moduleInformation = i->getModuleOwner()->information(i);
512 if(moduleInformation != NULL) 513 if(moduleInformation != NULL)
513 { 514 {
514 QPEApplication::showWidget( moduleInformation ); 515 QPEApplication::showWidget( moduleInformation );
515#ifdef DEBUG 516#ifdef DEBUG
516 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl; 517 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl;
517#endif 518#endif
518 return; 519 return;
519 } 520 }
520 } 521 }
521 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp); 522 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp);
522 QPEApplication::showWidget( information ); 523 QPEApplication::showWidget( information );
523} 524}
524 525
525/** 526/**
526 * Update this interface. If no QListViewItem exists create one. 527 * Update this interface. If no QListViewItem exists create one.
527 * @param Interface* pointer to the interface that needs to be updated. 528 * @param Interface* pointer to the interface that needs to be updated.
528 */ 529 */
529void MainWindowImp::updateInterface(Interface *i) 530void MainWindowImp::updateInterface(Interface *i)
530{ 531{
531 if(!advancedUserMode) 532 if(!advancedUserMode)
532 { 533 {
533 if(i->getInterfaceName() == "lo") 534 if(i->getInterfaceName() == "lo")
534 return; 535 return;
535 } 536 }
536 537
537 QListViewItem *item = NULL; 538 QListViewItem *item = NULL;
538 539
539 // Find the interface, making it if needed. 540 // Find the interface, making it if needed.
540 if(items.find(i) == items.end()) 541 if(items.find(i) == items.end())
541 { 542 {
542 item = new QListViewItem(connectionList, "", "", ""); 543 item = new QListViewItem(connectionList, "", "", "");
543 // See if you can't find a module owner for this interface 544 // See if you can't find a module owner for this interface
544 QMap<Module*, QLibrary*>::Iterator it; 545 QMap<Module*, QLibrary*>::Iterator it;
545 for( it = libraries.begin(); it != libraries.end(); ++it ) 546 for( it = libraries.begin(); it != libraries.end(); ++it )
546 { 547 {
547 if(it.key()->isOwner(i)) 548 if(it.key()->isOwner(i))
548 i->setModuleOwner(it.key()); 549 i->setModuleOwner(it.key());
549 } 550 }
550 items.insert(i, item); 551 items.insert(i, item);
551 interfaceItems.insert(item, i); 552 interfaceItems.insert(item, i);
552 } 553 }
553 else 554 else
554 item = items[i]; 555 item = items[i];
555 556
556 // Update the icons and information 557 // Update the icons and information
557#ifdef QWS 558#ifdef QWS
558 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 559 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
559#else 560#else
560 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 561 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
561#endif 562#endif
562 563
563 QString typeName = "lan"; 564 QString typeName = "lan";
564 if(i->getInterfaceName() == "lo") 565 if(i->getInterfaceName() == "lo")
565 typeName = "lo"; 566 typeName = "lo";
566 if(i->getInterfaceName().contains("irda")) 567 if(i->getInterfaceName().contains("irda"))
567 typeName = "irda"; 568 typeName = "irda";
568 if(i->getInterfaceName().contains("wlan")) 569 if(i->getInterfaceName().contains("wlan"))
569 typeName = "wlan"; 570 typeName = "wlan";
570 if(i->getInterfaceName().contains("usb")) 571 if(i->getInterfaceName().contains("usb"))
571 typeName = "usb"; 572 typeName = "usb";
572 573
573 if(!i->isAttached()) 574 if(!i->isAttached())
574 typeName = "connect_no"; 575 typeName = "connect_no";
575 // Actually try to use the Module 576 // Actually try to use the Module
576 if(i->getModuleOwner() != NULL) 577 if(i->getModuleOwner() != NULL)
577 typeName = i->getModuleOwner()->getPixmapName(i); 578 typeName = i->getModuleOwner()->getPixmapName(i);
578 579
579#ifdef QWS 580#ifdef QWS
580 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 581 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
581#else 582#else
582 item->setPixmap(1, (SmallIcon(typeName))); 583 item->setPixmap(1, (SmallIcon(typeName)));
583#endif 584#endif
584 item->setText(2, i->getHardwareName()); 585 item->setText(2, i->getHardwareName());
585 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 586 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
586 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 587 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
587} 588}
588 589
589void MainWindowImp::newProfileChanged(const QString& newText) 590void MainWindowImp::newProfileChanged(const QString& newText)
590{ 591{
591 if(newText.length() > 0) 592 if(newText.length() > 0)
592 newProfileButton->setEnabled(true); 593 newProfileButton->setEnabled(true);
593 else 594 else
594 newProfileButton->setEnabled(false); 595 newProfileButton->setEnabled(false);
595} 596}
596 597
597/** 598/**
598 * Adds a new profile to the list of profiles. 599 * Adds a new profile to the list of profiles.
599 * Don't add profiles that already exists. 600 * Don't add profiles that already exists.
600 * Appends to the list and QStringList 601 * Appends to the list and QStringList
601 */ 602 */
602void MainWindowImp::addProfile() 603void MainWindowImp::addProfile()
603{ 604{
604 QString newProfileName = newProfile->text(); 605 QString newProfileName = newProfile->text();
605 if(profiles.grep(newProfileName).count() > 0) 606 if(profiles.grep(newProfileName).count() > 0)
606 { 607 {
607 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 608 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
608 return; 609 return;
609 } 610 }
610 profiles.append(newProfileName); 611 profiles.append(newProfileName);
611 profilesList->insertItem(newProfileName); 612 profilesList->insertItem(newProfileName);
612} 613}
613 614
614/** 615/**
615 * Removes the currently selected profile in the combo. 616 * Removes the currently selected profile in the combo.
616 * Doesn't delete if there are less then 2 profiles. 617 * Doesn't delete if there are less then 2 profiles.
617 */ 618 */
618void MainWindowImp::removeProfile() 619void MainWindowImp::removeProfile()
619{ 620{
620 if(profilesList->count() <= 1) 621 if(profilesList->count() <= 1)
621 { 622 {
622 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 623 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
623 return; 624 return;
624 } 625 }
625 QString profileToRemove = profilesList->currentText(); 626 QString profileToRemove = profilesList->currentText();
626 if(profileToRemove == "All") 627 if(profileToRemove == "All")
627 { 628 {
628 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 629 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
629 return; 630 return;
630 } 631 }
631 // Can't remove the curent profile 632 // Can't remove the curent profile
632 if(profileToRemove == currentProfileLabel->text()) 633 if(profileToRemove == currentProfileLabel->text())
633 { 634 {
634 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 635 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
635 return; 636 return;
636 637
637 } 638 }
638 639
639 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) 640 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
640 { 641 {
641 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 642 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
642 profilesList->clear(); 643 profilesList->clear();
643 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 644 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
644 profilesList->insertItem((*it)); 645 profilesList->insertItem((*it));
645 646
646 // Remove any interface settings and mappings. 647 // Remove any interface settings and mappings.
647 Interfaces interfaces; 648 Interfaces interfaces;
648 // Go through them one by one 649 // Go through them one by one
649 QMap<Interface*, QListViewItem*>::Iterator it; 650 QMap<Interface*, QListViewItem*>::Iterator it;
650 for( it = items.begin(); it != items.end(); ++it ) 651 for( it = items.begin(); it != items.end(); ++it )
651 { 652 {
652 QString interfaceName = it.key()->getInterfaceName(); 653 QString interfaceName = it.key()->getInterfaceName();
653 odebug << interfaceName.latin1() << oendl; 654 odebug << interfaceName.latin1() << oendl;
654 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)) 655 if(interfaces.setInterface(interfaceName + "_" + profileToRemove))
655 { 656 {
656 interfaces.removeInterface(); 657 interfaces.removeInterface();
657 if(interfaces.setMapping(interfaceName)) 658 if(interfaces.setMapping(interfaceName))
658 { 659 {
659 if(profilesList->count() == 1) 660 if(profilesList->count() == 1)
660 interfaces.removeMapping(); 661 interfaces.removeMapping();
661 else 662 else
662 { 663 {
663 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 664 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
664 } 665 }
665 } 666 }
666 interfaces.write(); 667 interfaces.write();
667 break; 668 break;
668 } 669 }
669 } 670 }
670 } 671 }
671} 672}
672 673
673/** 674/**
674 * A new profile has been selected, change. 675 * A new profile has been selected, change.
675 * @param newProfile the new profile. 676 * @param newProfile the new profile.
676 */ 677 */
677void MainWindowImp::changeProfile() 678void MainWindowImp::changeProfile()
678{ 679{
679 if(profilesList->currentItem() == -1) 680 if(profilesList->currentItem() == -1)
680 { 681 {
681 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 682 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
682 return; 683 return;
683 } 684 }
684 QString newProfile = profilesList->text(profilesList->currentItem()); 685 QString newProfile = profilesList->text(profilesList->currentItem());
685 if(newProfile != currentProfileLabel->text()) 686 if(newProfile != currentProfileLabel->text())
686 { 687 {
687 currentProfileLabel->setText(newProfile); 688 currentProfileLabel->setText(newProfile);
688 QFile::remove(scheme); 689 QFile::remove(scheme);
689 QFile file(scheme); 690 QFile file(scheme);
690 if ( file.open(IO_ReadWrite) ) 691 if ( file.open(IO_ReadWrite) )
691 { 692 {
692 QTextStream stream( &file ); 693 QTextStream stream( &file );
693 stream << QString("SCHEME=%1").arg(newProfile); 694 stream << QString("SCHEME=%1").arg(newProfile);
694 file.close(); 695 file.close();
695 } 696 }
696 // restart all up devices? 697 // restart all up devices?
697 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) 698 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok)
698 { 699 {
699 // Go through them one by one 700 // Go through them one by one
700 QMap<Interface*, QListViewItem*>::Iterator it; 701 QMap<Interface*, QListViewItem*>::Iterator it;
701 for( it = items.begin(); it != items.end(); ++it ) 702 for( it = items.begin(); it != items.end(); ++it )
702 { 703 {
703 if(it.key()->getStatus() == true) 704 if(it.key()->getStatus() == true)
704 it.key()->restart(); 705 it.key()->restart();
705 } 706 }
706 } 707 }
707 } 708 }
708 // TODO change the profile in the modules 709 // TODO change the profile in the modules
709} 710}
710 711
711 712
712void MainWindowImp::makeChannel() 713void MainWindowImp::makeChannel()
713{ 714{
714 channel = new QCopChannel( "QPE/Application/networksettings", this ); 715 channel = new QCopChannel( "QPE/Application/networksettings", this );
715 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 716 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
716 this, SLOT(receive(const QCString&,const QByteArray&)) ); 717 this, SLOT(receive(const QCString&,const QByteArray&)) );
717} 718}
718 719
719void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) 720void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
720{ 721{
721 bool found = false; 722 bool found = false;
722 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; 723 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl;
723 if (msg == "raise") 724 if (msg == "raise")
724 { 725 {
725 raise(); 726 raise();
726 return; 727 return;
727 } 728 }
728 729
729 QString dest = msg.left(msg.find("(")); 730 QString dest = msg.left(msg.find("("));
730 QCString param = msg.right(msg.length() - msg.find("(") - 1); 731 QCString param = msg.right(msg.length() - msg.find("(") - 1);
731 param = param.left( param.length() - 1 ); 732 param = param.left( param.length() - 1 );
732 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; 733 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl;
733 734
734 QMap<Module*, QLibrary*>::Iterator it; 735 QMap<Module*, QLibrary*>::Iterator it;
735 for( it = libraries.begin(); it != libraries.end(); ++it ) 736 for( it = libraries.begin(); it != libraries.end(); ++it )
736 { 737 {
737 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; 738 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl;
738 if(it.key()->type() == dest) 739 if(it.key()->type() == dest)
739 { 740 {
740 it.key()->receive( param, arg ); 741 it.key()->receive( param, arg );
741 found = true; 742 found = true;
742 } 743 }
743 } 744 }
744 745
745 746
746 if (found) QPEApplication::setKeepRunning(); 747 if (found) QPEApplication::setKeepRunning();
747 else odebug << "Huh what do ya want" << oendl; 748 else odebug << "Huh what do ya want" << oendl;
748} 749}