summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interface.cpp16
-rw-r--r--noncore/net/networksetup/interface.h4
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp7
-rw-r--r--noncore/settings/networksettings/interface.cpp16
-rw-r--r--noncore/settings/networksettings/interface.h4
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp7
6 files changed, 26 insertions, 28 deletions
diff --git a/noncore/net/networksetup/interface.cpp b/noncore/net/networksetup/interface.cpp
index 1e01da4..a84b91f 100644
--- a/noncore/net/networksetup/interface.cpp
+++ b/noncore/net/networksetup/interface.cpp
@@ -1,260 +1,260 @@
1#include "interface.h" 1#include "interface.h"
2#include <qdatetime.h> 2#include <qdatetime.h>
3#include <qfile.h> 3#include <qfile.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <qfileinfo.h> 5#include <qfileinfo.h>
6#include <qtextstream.h> 6#include <qtextstream.h>
7 7
8#define IFCONFIG "/sbin/ifconfig" 8#define IFCONFIG "/sbin/ifconfig"
9#define HDCP_INFO_DIR "/etc/dhcpc" 9#define HDCP_INFO_DIR "/etc/dhcpc"
10 10
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13 13
14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ 14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
15 refresh(); 15 refresh();
16} 16}
17 17
18/** 18/**
19 * Set status 19 * Set status
20 * @param newStatus - the new status 20 * @param newStatus - the new status
21 * emit updateInterface 21 * emit updateInterface
22 */ 22 */
23void Interface::setStatus(bool newStatus){ 23void Interface::setStatus(bool newStatus){
24 if(status != newStatus){ 24 if(status != newStatus){
25 status = newStatus; 25 status = newStatus;
26 refresh(); 26 refresh();
27 } 27 }
28}; 28};
29 29
30/** 30/**
31 * Set if attached or not (802.11 card pulled out for example) 31 * Set if attached or not (802.11 card pulled out for example)
32 * @param isAttached - if attached 32 * @param isAttached - if attached
33 * emit updateInterface 33 * emit updateInterface
34 */ 34 */
35void Interface::setAttached(bool isAttached){ 35void Interface::setAttached(bool isAttached){
36 attached = isAttached; 36 attached = isAttached;
37 emit(updateInterface(this)); 37 emit(updateInterface(this));
38}; 38};
39 39
40/** 40/**
41 * Set Hardware name 41 * Set Hardware name
42 * @param name - the new name 42 * @param name - the new name
43 * emit updateInterface 43 * emit updateInterface
44 */ 44 */
45void Interface::setHardwareName(QString name){ 45void Interface::setHardwareName(QString name){
46 hardareName = name; 46 hardwareName = name;
47 emit(updateInterface(this)); 47 emit(updateInterface(this));
48}; 48};
49 49
50/** 50/**
51 * Set Module owner 51 * Set Module owner
52 * @param owner - the new owner 52 * @param owner - the new owner
53 * emit updateInterface 53 * emit updateInterface
54 */ 54 */
55void Interface::setModuleOwner(Module *owner){ 55void Interface::setModuleOwner(Module *owner){
56 moduleOwner = owner; 56 moduleOwner = owner;
57 emit(updateInterface(this)); 57 emit(updateInterface(this));
58}; 58};
59 59
60 60
61/** 61/**
62 * Try to start the interface. 62 * Try to start the interface.
63 */ 63 */
64void Interface::start(){ 64void Interface::start(){
65 // check to see if we are already running. 65 // check to see if we are already running.
66 if(true == status) 66 if(true == status)
67 return; 67 return;
68 68
69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); 69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
70 // See if it was successfull... 70 // See if it was successfull...
71 if(ret != 0) 71 if(ret != 0)
72 return; 72 return;
73 73
74 status = true; 74 status = true;
75 refresh(); 75 refresh();
76} 76}
77 77
78/** 78/**
79 * Try to stop the interface. 79 * Try to stop the interface.
80 */ 80 */
81void Interface::stop(){ 81void Interface::stop(){
82 // check to see if we are already stopped. 82 // check to see if we are already stopped.
83 if(false == status) 83 if(false == status)
84 return; 84 return;
85 85
86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); 86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
87 if(ret != 0) 87 if(ret != 0)
88 return; 88 return;
89 89
90 status = true; 90 status = true;
91 refresh(); 91 refresh();
92} 92}
93 93
94/** 94/**
95 * Try to restart the interface. 95 * Try to restart the interface.
96 */ 96 */
97void Interface::restart(){ 97void Interface::restart(){
98 stop(); 98 stop();
99 start(); 99 start();
100} 100}
101 101
102/** 102/**
103 * Try to refresh the information about the interface. 103 * Try to refresh the information about the interface.
104 * First call ifconfig, then check the dhcp-info file 104 * First call ifconfig, then check the dhcp-info file
105 * @return bool true if successfull. 105 * @return bool true if successfull.
106 */ 106 */
107bool Interface::refresh(){ 107bool Interface::refresh(){
108 // See if we are up. 108 // See if we are up.
109 if(status == false){ 109 if(status == false){
110 macAddress = ""; 110 macAddress = "";
111 ip = "0.0.0.0"; 111 ip = "0.0.0.0";
112 subnetMask = "0.0.0.0"; 112 subnetMask = "0.0.0.0";
113 broadcast = ""; 113 broadcast = "";
114 dhcp = false; 114 dhcp = false;
115 dhcpServerIp = ""; 115 dhcpServerIp = "";
116 leaseObtained = ""; 116 leaseObtained = "";
117 leaseExpires = ""; 117 leaseExpires = "";
118 emit(updateInterface(this)); 118 emit(updateInterface(this));
119 return true; 119 return true;
120 } 120 }
121 121
122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); 122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); 123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
124 if(ret != 0){ 124 if(ret != 0){
125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
126 return false; 126 return false;
127 } 127 }
128 128
129 QFile file(fileName); 129 QFile file(fileName);
130 if (!file.open(IO_ReadOnly)){ 130 if (!file.open(IO_ReadOnly)){
131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
132 return false; 132 return false;
133 } 133 }
134 134
135 // Set to the defaults 135 // Set to the defaults
136 macAddress = ""; 136 macAddress = "";
137 ip = "0.0.0.0"; 137 ip = "0.0.0.0";
138 subnetMask = "0.0.0.0"; 138 subnetMask = "0.0.0.0";
139 broadcast = ""; 139 broadcast = "";
140 140
141 QTextStream stream( &file ); 141 QTextStream stream( &file );
142 QString line; 142 QString line;
143 while ( !stream.eof() ) { 143 while ( !stream.eof() ) {
144 line = stream.readLine(); 144 line = stream.readLine();
145 if(line.contains("HWaddr")){ 145 if(line.contains("HWaddr")){
146 int mac = line.find("HWaddr"); 146 int mac = line.find("HWaddr");
147 macAddress = line.mid(mac+7, line.length()); 147 macAddress = line.mid(mac+7, line.length());
148 } 148 }
149 if(line.contains("inet addr")){ 149 if(line.contains("inet addr")){
150 int ipl = line.find("inet addr"); 150 int ipl = line.find("inet addr");
151 int space = line.find(" ", ipl+10); 151 int space = line.find(" ", ipl+10);
152 ip = line.mid(ipl+10, space-ipl-10); 152 ip = line.mid(ipl+10, space-ipl-10);
153 } 153 }
154 if(line.contains("Mask")){ 154 if(line.contains("Mask")){
155 int mask = line.find("Mask"); 155 int mask = line.find("Mask");
156 subnetMask = line.mid(mask+5, line.length()); 156 subnetMask = line.mid(mask+5, line.length());
157 } 157 }
158 if(line.contains("Bcast")){ 158 if(line.contains("Bcast")){
159 int mask = line.find("Bcast"); 159 int mask = line.find("Bcast");
160 int space = line.find(" ", mask+6); 160 int space = line.find(" ", mask+6);
161 broadcast = line.mid(mask+6, space-mask-6); 161 broadcast = line.mid(mask+6, space-mask-6);
162 } 162 }
163 } 163 }
164 file.close(); 164 file.close();
165 QFile::remove(fileName); 165 QFile::remove(fileName);
166 166
167 // DHCP TESTING 167 // DHCP TESTING
168 // reset DHCP info 168 // reset DHCP info
169 dhcpServerIp = ""; 169 dhcpServerIp = "";
170 leaseObtained = ""; 170 leaseObtained = "";
171 leaseExpires = ""; 171 leaseExpires = "";
172 dhcp = false; 172 dhcp = false;
173 173
174 QString dhcpDirectory(HDCP_INFO_DIR); 174 QString dhcpDirectory(HDCP_INFO_DIR);
175 QDir d(dhcpDirectory); 175 QDir d(dhcpDirectory);
176 if(!d.exists(dhcpDirectory)) 176 if(!d.exists(dhcpDirectory))
177 dhcpDirectory = "/var/run"; 177 dhcpDirectory = "/var/run";
178 178
179 // See if we have 179 // See if we have
180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); 180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
181 // If there is no DHCP information then exit now with no errors. 181 // If there is no DHCP information then exit now with no errors.
182 if(!QFile::exists(dhcpFile)){ 182 if(!QFile::exists(dhcpFile)){
183 emit(updateInterface(this)); 183 emit(updateInterface(this));
184 return true; 184 return true;
185 } 185 }
186 186
187 file.setName(dhcpFile); 187 file.setName(dhcpFile);
188 if (!file.open(IO_ReadOnly)){ 188 if (!file.open(IO_ReadOnly)){
189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
190 return false; 190 return false;
191 } 191 }
192 192
193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
194 int leaseTime = 0; 194 int leaseTime = 0;
195 int renewalTime = 0; 195 int renewalTime = 0;
196 196
197 stream.setDevice( &file ); 197 stream.setDevice( &file );
198 while ( !stream.eof() ) { 198 while ( !stream.eof() ) {
199 line = stream.readLine(); 199 line = stream.readLine();
200 if(line.contains("DHCPSIADDR=")) 200 if(line.contains("DHCPSIADDR="))
201 dhcpServerIp = line.mid(11, line.length()); 201 dhcpServerIp = line.mid(11, line.length());
202 if(line.contains("LEASETIME=")) 202 if(line.contains("LEASETIME="))
203 leaseTime = line.mid(10, line.length()).toInt(); 203 leaseTime = line.mid(10, line.length()).toInt();
204 if(line.contains("RENEWALTIME=")) 204 if(line.contains("RENEWALTIME="))
205 renewalTime = line.mid(12, line.length()).toInt(); 205 renewalTime = line.mid(12, line.length()).toInt();
206 } 206 }
207 file.close(); 207 file.close();
208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
210 210
211 // Get the pid of the deamond 211 // Get the pid of the deamond
212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); 212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
213 file.setName(dhcpFile); 213 file.setName(dhcpFile);
214 if (!file.open(IO_ReadOnly)){ 214 if (!file.open(IO_ReadOnly)){
215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
216 return false; 216 return false;
217 } 217 }
218 218
219 int pid = -1; 219 int pid = -1;
220 stream.setDevice( &file ); 220 stream.setDevice( &file );
221 while ( !stream.eof() ) { 221 while ( !stream.eof() ) {
222 line = stream.readLine(); 222 line = stream.readLine();
223 pid = line.toInt(); 223 pid = line.toInt();
224 } 224 }
225 file.close(); 225 file.close();
226 226
227 if( pid == -1){ 227 if( pid == -1){
228 qDebug("Interface: Could not get pid of dhcpc deamon."); 228 qDebug("Interface: Could not get pid of dhcpc deamon.");
229 return false; 229 return false;
230 } 230 }
231 231
232 // Get the start running time of the deamon 232 // Get the start running time of the deamon
233 fileName = (QString("/proc/%1/stat").arg(pid)); 233 fileName = (QString("/proc/%1/stat").arg(pid));
234 file.setName(fileName); 234 file.setName(fileName);
235 stream.setDevice( &file ); 235 stream.setDevice( &file );
236 if (!file.open(IO_ReadOnly)){ 236 if (!file.open(IO_ReadOnly)){
237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
238 return false; 238 return false;
239 } 239 }
240 while ( !stream.eof() ) { 240 while ( !stream.eof() ) {
241 line = stream.readLine(); 241 line = stream.readLine();
242 } 242 }
243 file.close(); 243 file.close();
244 long time = 0; 244 long time = 0;
245 // Grab the start time 245 // Grab the start time
246 // pid com state ppid pgrp session tty_nr tpgid flags 246 // pid com state ppid pgrp session tty_nr tpgid flags
247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
250 // nice 0 itrealvalue starttime 250 // nice 0 itrealvalue starttime
251 "%*d %*d %*d %lu", (long*) &time); 251 "%*d %*d %*d %lu", (long*) &time);
252 time = time/100; 252 time = time/100;
253 253
254 QDateTime datetime(QDateTime::currentDateTime()); 254 QDateTime datetime(QDateTime::currentDateTime());
255 255
256 // Get the uptime of the computer. 256 // Get the uptime of the computer.
257 QFile f("/proc/uptime"); 257 QFile f("/proc/uptime");
258 if ( f.open(IO_ReadOnly) ) { // file opened successfully 258 if ( f.open(IO_ReadOnly) ) { // file opened successfully
259 QTextStream t( &f ); // use a text stream 259 QTextStream t( &f ); // use a text stream
260 int sec = 0; 260 int sec = 0;
diff --git a/noncore/net/networksetup/interface.h b/noncore/net/networksetup/interface.h
index 980171a..7943fd6 100644
--- a/noncore/net/networksetup/interface.h
+++ b/noncore/net/networksetup/interface.h
@@ -1,72 +1,72 @@
1#ifndef INTERFACE_H 1#ifndef INTERFACE_H
2#define INTERFACE_H 2#define INTERFACE_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qobject.h> 5#include <qobject.h>
6 6
7class Module; 7class Module;
8 8
9class Interface : public QObject{ 9class Interface : public QObject{
10 Q_OBJECT 10 Q_OBJECT
11 11
12signals: 12signals:
13 void updateInterface(Interface *i); 13 void updateInterface(Interface *i);
14 14
15public: 15public:
16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false); 16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
17 virtual ~Interface(){}; 17 virtual ~Interface(){};
18 18
19 virtual QString getInterfaceName(){ QString n(this->name()); return n; }; 19 virtual QString getInterfaceName(){ QString n(this->name()); return n; };
20 20
21 virtual bool getStatus(){ return status; }; 21 virtual bool getStatus(){ return status; };
22 virtual void setStatus(bool newStatus); 22 virtual void setStatus(bool newStatus);
23 23
24 virtual bool isAttached(){ return attached; }; 24 virtual bool isAttached(){ return attached; };
25 virtual void setAttached(bool isAttached=false); 25 virtual void setAttached(bool isAttached=false);
26 26
27 virtual QString getHardwareName(){ return hardareName; }; 27 virtual QString getHardwareName(){ return hardwareName; };
28 virtual void setHardwareName(QString name="Unknown"); 28 virtual void setHardwareName(QString name="Unknown");
29 29
30 virtual Module* getModuleOwner(){ return moduleOwner; }; 30 virtual Module* getModuleOwner(){ return moduleOwner; };
31 virtual void setModuleOwner(Module *owner=NULL); 31 virtual void setModuleOwner(Module *owner=NULL);
32 32
33 // inet information. 33 // inet information.
34 QString getMacAddress(){ return macAddress; }; 34 QString getMacAddress(){ return macAddress; };
35 QString getIp(){ return ip; }; 35 QString getIp(){ return ip; };
36 QString getSubnetMask(){ return subnetMask; }; 36 QString getSubnetMask(){ return subnetMask; };
37 QString getBroadcast(){ return broadcast; }; 37 QString getBroadcast(){ return broadcast; };
38 bool isDhcp(){ return dhcp; }; 38 bool isDhcp(){ return dhcp; };
39 QString getDhcpServerIp(){ return dhcpServerIp; }; 39 QString getDhcpServerIp(){ return dhcpServerIp; };
40 QString getLeaseObtained(){ return leaseObtained; }; 40 QString getLeaseObtained(){ return leaseObtained; };
41 QString getLeaseExpires(){ return leaseExpires; }; 41 QString getLeaseExpires(){ return leaseExpires; };
42 42
43public slots: 43public slots:
44 bool refresh(); 44 bool refresh();
45 void start(); 45 void start();
46 void stop(); 46 void stop();
47 void restart(); 47 void restart();
48 48
49private: 49private:
50 // Interface information 50 // Interface information
51 bool status; 51 bool status;
52 bool attached; 52 bool attached;
53 QString interfaceName; 53 QString interfaceName;
54 QString hardareName; 54 QString hardwareName;
55 Module *moduleOwner; 55 Module *moduleOwner;
56 56
57 // Network information 57 // Network information
58 QString macAddress; 58 QString macAddress;
59 QString ip; 59 QString ip;
60 QString broadcast; 60 QString broadcast;
61 QString subnetMask; 61 QString subnetMask;
62 bool dhcp; 62 bool dhcp;
63 QString dhcpServerIp; 63 QString dhcpServerIp;
64 QString leaseObtained; 64 QString leaseObtained;
65 QString leaseExpires; 65 QString leaseExpires;
66 66
67}; 67};
68 68
69#endif 69#endif
70 70
71// interface.h 71// interface.h
72 72
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index 117bac1..a446d29 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -263,187 +263,186 @@ void MainWindowImp::informationClicked(){
263 information->show(); 263 information->show();
264} 264}
265 265
266/** 266/**
267 * Aquire the list of active interfaces from ifconfig 267 * Aquire the list of active interfaces from ifconfig
268 * Call ifconfig and ifconfig -a 268 * Call ifconfig and ifconfig -a
269 */ 269 */
270void MainWindowImp::getInterfaceList(){ 270void MainWindowImp::getInterfaceList(){
271 KShellProcess *processAll = new KShellProcess(); 271 KShellProcess *processAll = new KShellProcess();
272 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 272 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
273 connect(processAll, SIGNAL(processExited(KProcess *)), 273 connect(processAll, SIGNAL(processExited(KProcess *)),
274 this, SLOT(jobDone(KProcess *))); 274 this, SLOT(jobDone(KProcess *)));
275 threads.insert(processAll, TEMP_ALL); 275 threads.insert(processAll, TEMP_ALL);
276 276
277 KShellProcess *process = new KShellProcess(); 277 KShellProcess *process = new KShellProcess();
278 *process << "/sbin/ifconfig" << " > " TEMP_UP; 278 *process << "/sbin/ifconfig" << " > " TEMP_UP;
279 connect(process, SIGNAL(processExited(KProcess *)), 279 connect(process, SIGNAL(processExited(KProcess *)),
280 this, SLOT(jobDone(KProcess *))); 280 this, SLOT(jobDone(KProcess *)));
281 threads.insert(process, TEMP_UP); 281 threads.insert(process, TEMP_UP);
282 282
283 processAll->start(KShellProcess::NotifyOnExit); 283 processAll->start(KShellProcess::NotifyOnExit);
284 process->start(KShellProcess::NotifyOnExit); 284 process->start(KShellProcess::NotifyOnExit);
285} 285}
286 286
287void MainWindowImp::jobDone(KProcess *process){ 287void MainWindowImp::jobDone(KProcess *process){
288 QString fileName = threads[process]; 288 QString fileName = threads[process];
289 threads.remove(process); 289 threads.remove(process);
290 delete process; 290 delete process;
291 291
292 QFile file(fileName); 292 QFile file(fileName);
293 if (!file.open(IO_ReadOnly)){ 293 if (!file.open(IO_ReadOnly)){
294 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 294 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
295 return; 295 return;
296 } 296 }
297 297
298 QTextStream stream( &file ); 298 QTextStream stream( &file );
299 QString line; 299 QString line;
300 while ( !stream.eof() ) { 300 while ( !stream.eof() ) {
301 line = stream.readLine(); 301 line = stream.readLine();
302 int space = line.find(" "); 302 int space = line.find(" ");
303 if(space > 1){ 303 if(space > 1){
304 // We have found an interface 304 // We have found an interface
305 QString interfaceName = line.mid(0, space); 305 QString interfaceName = line.mid(0, space);
306 Interface *i; 306 Interface *i;
307 // We have found an interface 307 // We have found an interface
308 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 308 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
309 // See if we already have it 309 // See if we already have it
310 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 310 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
311 if(fileName == TEMP_ALL) 311 if(fileName == TEMP_ALL)
312 i = new Interface(this, interfaceName, false); 312 i = new Interface(this, interfaceName, false);
313 else 313 else
314 i = new Interface(this, interfaceName, true); 314 i = new Interface(this, interfaceName, true);
315 i->setAttached(true); 315 i->setAttached(true);
316 316
317 QString hardName = "Ethernet"; 317 QString hardName = "Ethernet";
318 int hardwareName = line.find("Link encap:"); 318 int hardwareName = line.find("Link encap:");
319 int macAddress = line.find("HWaddr"); 319 int macAddress = line.find("HWaddr");
320 if(macAddress == -1) 320 if(macAddress == -1)
321 macAddress = line.length(); 321 macAddress = line.length();
322 if(hardwareName != -1) 322 if(hardwareName != -1)
323 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); 323 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
324 324
325 interfaceNames.insert(i->getInterfaceName(), i); 325 interfaceNames.insert(i->getInterfaceName(), i);
326 updateInterface(i); 326 updateInterface(i);
327 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 327 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
328 } 328 }
329 // It was an interface we already had. 329 // It was an interface we already had.
330 else{ 330 else{
331 i = interfaceNames[interfaceName];
332 if(fileName != TEMP_ALL) 331 if(fileName != TEMP_ALL)
333 i->setStatus(true); 332 (interfaceNames[interfaceName])->setStatus(true);
334 } 333 }
335 } 334 }
336 } 335 }
337 file.close(); 336 file.close();
338 QFile::remove(fileName); 337 QFile::remove(fileName);
339 338
340 if(threads.count() == 0){ 339 if(threads.count() == 0){
341 Interfaces i; 340 Interfaces i;
342 QStringList list = i.getInterfaceList(); 341 QStringList list = i.getInterfaceList();
343 QMap<QString, Interface*>::Iterator it; 342 QMap<QString, Interface*>::Iterator it;
344 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 343 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
345 bool found = false; 344 bool found = false;
346 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 345 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
347 if(it.key() == (*ni)) 346 if(it.key() == (*ni))
348 found = true; 347 found = true;
349 } 348 }
350 if(!found){ 349 if(!found){
351 Interface *i = new Interface(this, *ni, false); 350 Interface *i = new Interface(this, *ni, false);
352 i->setAttached(false); 351 i->setAttached(false);
353 i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); 352 i->setHardwareName(QString("Disconnected (%1)").arg(*ni));
354 interfaceNames.insert(i->getInterfaceName(), i); 353 interfaceNames.insert(i->getInterfaceName(), i);
355 updateInterface(i); 354 updateInterface(i);
356 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 355 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
357 } 356 }
358 } 357 }
359 } 358 }
360} 359}
361 360
362/** 361/**
363 * Update this interface. If no QListViewItem exists create one. 362 * Update this interface. If no QListViewItem exists create one.
364 * @param Interface* pointer to the interface that needs to be updated. 363 * @param Interface* pointer to the interface that needs to be updated.
365 */ 364 */
366void MainWindowImp::updateInterface(Interface *i){ 365void MainWindowImp::updateInterface(Interface *i){
367 if(!advancedUserMode){ 366 if(!advancedUserMode){
368 if(i->getInterfaceName() == "lo") 367 if(i->getInterfaceName() == "lo")
369 return; 368 return;
370 } 369 }
371 370
372 QListViewItem *item = NULL; 371 QListViewItem *item = NULL;
373 372
374 // Find the interface, making it if needed. 373 // Find the interface, making it if needed.
375 if(items.find(i) == items.end()){ 374 if(items.find(i) == items.end()){
376 item = new QListViewItem(connectionList, "", "", ""); 375 item = new QListViewItem(connectionList, "", "", "");
377 // See if you can't find a module owner for this interface 376 // See if you can't find a module owner for this interface
378 QMap<Module*, QLibrary*>::Iterator it; 377 QMap<Module*, QLibrary*>::Iterator it;
379 for( it = libraries.begin(); it != libraries.end(); ++it ){ 378 for( it = libraries.begin(); it != libraries.end(); ++it ){
380 if(it.key()->isOwner(i)) 379 if(it.key()->isOwner(i))
381 i->setModuleOwner(it.key()); 380 i->setModuleOwner(it.key());
382 } 381 }
383 items.insert(i, item); 382 items.insert(i, item);
384 interfaceItems.insert(item, i); 383 interfaceItems.insert(item, i);
385 } 384 }
386 else 385 else
387 item = items[i]; 386 item = items[i];
388 387
389 // Update the icons and information 388 // Update the icons and information
390 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 389 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
391 390
392 QString typeName = "lan"; 391 QString typeName = "lan";
393 if(i->getHardwareName().contains("Local Loopback")) 392 if(i->getHardwareName().contains("Local Loopback"))
394 typeName = "lo"; 393 typeName = "lo";
395 if(i->getInterfaceName().contains("irda")) 394 if(i->getInterfaceName().contains("irda"))
396 typeName = "irda"; 395 typeName = "irda";
397 if(i->getInterfaceName().contains("wlan")) 396 if(i->getInterfaceName().contains("wlan"))
398 typeName = "wlan"; 397 typeName = "wlan";
399 if(i->getInterfaceName().contains("usb")) 398 if(i->getInterfaceName().contains("usb"))
400 typeName = "usb"; 399 typeName = "usb";
401 400
402 if(!i->isAttached()) 401 if(!i->isAttached())
403 typeName = "connect_no"; 402 typeName = "connect_no";
404 // Actually try to use the Module 403 // Actually try to use the Module
405 if(i->getModuleOwner() != NULL) 404 if(i->getModuleOwner() != NULL)
406 typeName = i->getModuleOwner()->getPixmapName(i); 405 typeName = i->getModuleOwner()->getPixmapName(i);
407 406
408 item->setPixmap(1, (Resource::loadPixmap(typeName))); 407 item->setPixmap(1, (Resource::loadPixmap(typeName)));
409 item->setText(2, i->getHardwareName()); 408 item->setText(2, i->getHardwareName());
410 item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); 409 item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
411} 410}
412 411
413void MainWindowImp::newProfileChanged(const QString& newText){ 412void MainWindowImp::newProfileChanged(const QString& newText){
414 if(newText.length() > 0) 413 if(newText.length() > 0)
415 newProfileButton->setEnabled(true); 414 newProfileButton->setEnabled(true);
416 else 415 else
417 newProfileButton->setEnabled(false); 416 newProfileButton->setEnabled(false);
418} 417}
419 418
420/** 419/**
421 * Adds a new profile to the list of profiles. 420 * Adds a new profile to the list of profiles.
422 * Don't add profiles that already exists. 421 * Don't add profiles that already exists.
423 * Appends to the list and QStringList 422 * Appends to the list and QStringList
424 */ 423 */
425void MainWindowImp::addProfile(){ 424void MainWindowImp::addProfile(){
426 QString newProfileName = newProfile->text(); 425 QString newProfileName = newProfile->text();
427 if(profiles.grep(newProfileName).count() > 0){ 426 if(profiles.grep(newProfileName).count() > 0){
428 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); 427 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
429 return; 428 return;
430 } 429 }
431 profiles.append(newProfileName); 430 profiles.append(newProfileName);
432 profilesList->insertItem(newProfileName); 431 profilesList->insertItem(newProfileName);
433} 432}
434 433
435/** 434/**
436 * Removes the currently selected profile in the combo. 435 * Removes the currently selected profile in the combo.
437 * Doesn't delete if there are less then 2 profiles. 436 * Doesn't delete if there are less then 2 profiles.
438 */ 437 */
439void MainWindowImp::removeProfile(){ 438void MainWindowImp::removeProfile(){
440 if(profilesList->count() <= 1){ 439 if(profilesList->count() <= 1){
441 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); 440 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
442 return; 441 return;
443 } 442 }
444 QString profileToRemove = profilesList->currentText(); 443 QString profileToRemove = profilesList->currentText();
445 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 444 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
446 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 445 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
447 profilesList->clear(); 446 profilesList->clear();
448 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 447 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
449 profilesList->insertItem((*it)); 448 profilesList->insertItem((*it));
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp
index 1e01da4..a84b91f 100644
--- a/noncore/settings/networksettings/interface.cpp
+++ b/noncore/settings/networksettings/interface.cpp
@@ -1,260 +1,260 @@
1#include "interface.h" 1#include "interface.h"
2#include <qdatetime.h> 2#include <qdatetime.h>
3#include <qfile.h> 3#include <qfile.h>
4#include <qdir.h> 4#include <qdir.h>
5#include <qfileinfo.h> 5#include <qfileinfo.h>
6#include <qtextstream.h> 6#include <qtextstream.h>
7 7
8#define IFCONFIG "/sbin/ifconfig" 8#define IFCONFIG "/sbin/ifconfig"
9#define HDCP_INFO_DIR "/etc/dhcpc" 9#define HDCP_INFO_DIR "/etc/dhcpc"
10 10
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13 13
14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ 14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
15 refresh(); 15 refresh();
16} 16}
17 17
18/** 18/**
19 * Set status 19 * Set status
20 * @param newStatus - the new status 20 * @param newStatus - the new status
21 * emit updateInterface 21 * emit updateInterface
22 */ 22 */
23void Interface::setStatus(bool newStatus){ 23void Interface::setStatus(bool newStatus){
24 if(status != newStatus){ 24 if(status != newStatus){
25 status = newStatus; 25 status = newStatus;
26 refresh(); 26 refresh();
27 } 27 }
28}; 28};
29 29
30/** 30/**
31 * Set if attached or not (802.11 card pulled out for example) 31 * Set if attached or not (802.11 card pulled out for example)
32 * @param isAttached - if attached 32 * @param isAttached - if attached
33 * emit updateInterface 33 * emit updateInterface
34 */ 34 */
35void Interface::setAttached(bool isAttached){ 35void Interface::setAttached(bool isAttached){
36 attached = isAttached; 36 attached = isAttached;
37 emit(updateInterface(this)); 37 emit(updateInterface(this));
38}; 38};
39 39
40/** 40/**
41 * Set Hardware name 41 * Set Hardware name
42 * @param name - the new name 42 * @param name - the new name
43 * emit updateInterface 43 * emit updateInterface
44 */ 44 */
45void Interface::setHardwareName(QString name){ 45void Interface::setHardwareName(QString name){
46 hardareName = name; 46 hardwareName = name;
47 emit(updateInterface(this)); 47 emit(updateInterface(this));
48}; 48};
49 49
50/** 50/**
51 * Set Module owner 51 * Set Module owner
52 * @param owner - the new owner 52 * @param owner - the new owner
53 * emit updateInterface 53 * emit updateInterface
54 */ 54 */
55void Interface::setModuleOwner(Module *owner){ 55void Interface::setModuleOwner(Module *owner){
56 moduleOwner = owner; 56 moduleOwner = owner;
57 emit(updateInterface(this)); 57 emit(updateInterface(this));
58}; 58};
59 59
60 60
61/** 61/**
62 * Try to start the interface. 62 * Try to start the interface.
63 */ 63 */
64void Interface::start(){ 64void Interface::start(){
65 // check to see if we are already running. 65 // check to see if we are already running.
66 if(true == status) 66 if(true == status)
67 return; 67 return;
68 68
69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); 69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
70 // See if it was successfull... 70 // See if it was successfull...
71 if(ret != 0) 71 if(ret != 0)
72 return; 72 return;
73 73
74 status = true; 74 status = true;
75 refresh(); 75 refresh();
76} 76}
77 77
78/** 78/**
79 * Try to stop the interface. 79 * Try to stop the interface.
80 */ 80 */
81void Interface::stop(){ 81void Interface::stop(){
82 // check to see if we are already stopped. 82 // check to see if we are already stopped.
83 if(false == status) 83 if(false == status)
84 return; 84 return;
85 85
86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); 86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
87 if(ret != 0) 87 if(ret != 0)
88 return; 88 return;
89 89
90 status = true; 90 status = true;
91 refresh(); 91 refresh();
92} 92}
93 93
94/** 94/**
95 * Try to restart the interface. 95 * Try to restart the interface.
96 */ 96 */
97void Interface::restart(){ 97void Interface::restart(){
98 stop(); 98 stop();
99 start(); 99 start();
100} 100}
101 101
102/** 102/**
103 * Try to refresh the information about the interface. 103 * Try to refresh the information about the interface.
104 * First call ifconfig, then check the dhcp-info file 104 * First call ifconfig, then check the dhcp-info file
105 * @return bool true if successfull. 105 * @return bool true if successfull.
106 */ 106 */
107bool Interface::refresh(){ 107bool Interface::refresh(){
108 // See if we are up. 108 // See if we are up.
109 if(status == false){ 109 if(status == false){
110 macAddress = ""; 110 macAddress = "";
111 ip = "0.0.0.0"; 111 ip = "0.0.0.0";
112 subnetMask = "0.0.0.0"; 112 subnetMask = "0.0.0.0";
113 broadcast = ""; 113 broadcast = "";
114 dhcp = false; 114 dhcp = false;
115 dhcpServerIp = ""; 115 dhcpServerIp = "";
116 leaseObtained = ""; 116 leaseObtained = "";
117 leaseExpires = ""; 117 leaseExpires = "";
118 emit(updateInterface(this)); 118 emit(updateInterface(this));
119 return true; 119 return true;
120 } 120 }
121 121
122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); 122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1()); 123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
124 if(ret != 0){ 124 if(ret != 0){
125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
126 return false; 126 return false;
127 } 127 }
128 128
129 QFile file(fileName); 129 QFile file(fileName);
130 if (!file.open(IO_ReadOnly)){ 130 if (!file.open(IO_ReadOnly)){
131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
132 return false; 132 return false;
133 } 133 }
134 134
135 // Set to the defaults 135 // Set to the defaults
136 macAddress = ""; 136 macAddress = "";
137 ip = "0.0.0.0"; 137 ip = "0.0.0.0";
138 subnetMask = "0.0.0.0"; 138 subnetMask = "0.0.0.0";
139 broadcast = ""; 139 broadcast = "";
140 140
141 QTextStream stream( &file ); 141 QTextStream stream( &file );
142 QString line; 142 QString line;
143 while ( !stream.eof() ) { 143 while ( !stream.eof() ) {
144 line = stream.readLine(); 144 line = stream.readLine();
145 if(line.contains("HWaddr")){ 145 if(line.contains("HWaddr")){
146 int mac = line.find("HWaddr"); 146 int mac = line.find("HWaddr");
147 macAddress = line.mid(mac+7, line.length()); 147 macAddress = line.mid(mac+7, line.length());
148 } 148 }
149 if(line.contains("inet addr")){ 149 if(line.contains("inet addr")){
150 int ipl = line.find("inet addr"); 150 int ipl = line.find("inet addr");
151 int space = line.find(" ", ipl+10); 151 int space = line.find(" ", ipl+10);
152 ip = line.mid(ipl+10, space-ipl-10); 152 ip = line.mid(ipl+10, space-ipl-10);
153 } 153 }
154 if(line.contains("Mask")){ 154 if(line.contains("Mask")){
155 int mask = line.find("Mask"); 155 int mask = line.find("Mask");
156 subnetMask = line.mid(mask+5, line.length()); 156 subnetMask = line.mid(mask+5, line.length());
157 } 157 }
158 if(line.contains("Bcast")){ 158 if(line.contains("Bcast")){
159 int mask = line.find("Bcast"); 159 int mask = line.find("Bcast");
160 int space = line.find(" ", mask+6); 160 int space = line.find(" ", mask+6);
161 broadcast = line.mid(mask+6, space-mask-6); 161 broadcast = line.mid(mask+6, space-mask-6);
162 } 162 }
163 } 163 }
164 file.close(); 164 file.close();
165 QFile::remove(fileName); 165 QFile::remove(fileName);
166 166
167 // DHCP TESTING 167 // DHCP TESTING
168 // reset DHCP info 168 // reset DHCP info
169 dhcpServerIp = ""; 169 dhcpServerIp = "";
170 leaseObtained = ""; 170 leaseObtained = "";
171 leaseExpires = ""; 171 leaseExpires = "";
172 dhcp = false; 172 dhcp = false;
173 173
174 QString dhcpDirectory(HDCP_INFO_DIR); 174 QString dhcpDirectory(HDCP_INFO_DIR);
175 QDir d(dhcpDirectory); 175 QDir d(dhcpDirectory);
176 if(!d.exists(dhcpDirectory)) 176 if(!d.exists(dhcpDirectory))
177 dhcpDirectory = "/var/run"; 177 dhcpDirectory = "/var/run";
178 178
179 // See if we have 179 // See if we have
180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); 180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
181 // If there is no DHCP information then exit now with no errors. 181 // If there is no DHCP information then exit now with no errors.
182 if(!QFile::exists(dhcpFile)){ 182 if(!QFile::exists(dhcpFile)){
183 emit(updateInterface(this)); 183 emit(updateInterface(this));
184 return true; 184 return true;
185 } 185 }
186 186
187 file.setName(dhcpFile); 187 file.setName(dhcpFile);
188 if (!file.open(IO_ReadOnly)){ 188 if (!file.open(IO_ReadOnly)){
189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
190 return false; 190 return false;
191 } 191 }
192 192
193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
194 int leaseTime = 0; 194 int leaseTime = 0;
195 int renewalTime = 0; 195 int renewalTime = 0;
196 196
197 stream.setDevice( &file ); 197 stream.setDevice( &file );
198 while ( !stream.eof() ) { 198 while ( !stream.eof() ) {
199 line = stream.readLine(); 199 line = stream.readLine();
200 if(line.contains("DHCPSIADDR=")) 200 if(line.contains("DHCPSIADDR="))
201 dhcpServerIp = line.mid(11, line.length()); 201 dhcpServerIp = line.mid(11, line.length());
202 if(line.contains("LEASETIME=")) 202 if(line.contains("LEASETIME="))
203 leaseTime = line.mid(10, line.length()).toInt(); 203 leaseTime = line.mid(10, line.length()).toInt();
204 if(line.contains("RENEWALTIME=")) 204 if(line.contains("RENEWALTIME="))
205 renewalTime = line.mid(12, line.length()).toInt(); 205 renewalTime = line.mid(12, line.length()).toInt();
206 } 206 }
207 file.close(); 207 file.close();
208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
210 210
211 // Get the pid of the deamond 211 // Get the pid of the deamond
212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); 212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
213 file.setName(dhcpFile); 213 file.setName(dhcpFile);
214 if (!file.open(IO_ReadOnly)){ 214 if (!file.open(IO_ReadOnly)){
215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
216 return false; 216 return false;
217 } 217 }
218 218
219 int pid = -1; 219 int pid = -1;
220 stream.setDevice( &file ); 220 stream.setDevice( &file );
221 while ( !stream.eof() ) { 221 while ( !stream.eof() ) {
222 line = stream.readLine(); 222 line = stream.readLine();
223 pid = line.toInt(); 223 pid = line.toInt();
224 } 224 }
225 file.close(); 225 file.close();
226 226
227 if( pid == -1){ 227 if( pid == -1){
228 qDebug("Interface: Could not get pid of dhcpc deamon."); 228 qDebug("Interface: Could not get pid of dhcpc deamon.");
229 return false; 229 return false;
230 } 230 }
231 231
232 // Get the start running time of the deamon 232 // Get the start running time of the deamon
233 fileName = (QString("/proc/%1/stat").arg(pid)); 233 fileName = (QString("/proc/%1/stat").arg(pid));
234 file.setName(fileName); 234 file.setName(fileName);
235 stream.setDevice( &file ); 235 stream.setDevice( &file );
236 if (!file.open(IO_ReadOnly)){ 236 if (!file.open(IO_ReadOnly)){
237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
238 return false; 238 return false;
239 } 239 }
240 while ( !stream.eof() ) { 240 while ( !stream.eof() ) {
241 line = stream.readLine(); 241 line = stream.readLine();
242 } 242 }
243 file.close(); 243 file.close();
244 long time = 0; 244 long time = 0;
245 // Grab the start time 245 // Grab the start time
246 // pid com state ppid pgrp session tty_nr tpgid flags 246 // pid com state ppid pgrp session tty_nr tpgid flags
247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
250 // nice 0 itrealvalue starttime 250 // nice 0 itrealvalue starttime
251 "%*d %*d %*d %lu", (long*) &time); 251 "%*d %*d %*d %lu", (long*) &time);
252 time = time/100; 252 time = time/100;
253 253
254 QDateTime datetime(QDateTime::currentDateTime()); 254 QDateTime datetime(QDateTime::currentDateTime());
255 255
256 // Get the uptime of the computer. 256 // Get the uptime of the computer.
257 QFile f("/proc/uptime"); 257 QFile f("/proc/uptime");
258 if ( f.open(IO_ReadOnly) ) { // file opened successfully 258 if ( f.open(IO_ReadOnly) ) { // file opened successfully
259 QTextStream t( &f ); // use a text stream 259 QTextStream t( &f ); // use a text stream
260 int sec = 0; 260 int sec = 0;
diff --git a/noncore/settings/networksettings/interface.h b/noncore/settings/networksettings/interface.h
index 980171a..7943fd6 100644
--- a/noncore/settings/networksettings/interface.h
+++ b/noncore/settings/networksettings/interface.h
@@ -1,72 +1,72 @@
1#ifndef INTERFACE_H 1#ifndef INTERFACE_H
2#define INTERFACE_H 2#define INTERFACE_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qobject.h> 5#include <qobject.h>
6 6
7class Module; 7class Module;
8 8
9class Interface : public QObject{ 9class Interface : public QObject{
10 Q_OBJECT 10 Q_OBJECT
11 11
12signals: 12signals:
13 void updateInterface(Interface *i); 13 void updateInterface(Interface *i);
14 14
15public: 15public:
16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false); 16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
17 virtual ~Interface(){}; 17 virtual ~Interface(){};
18 18
19 virtual QString getInterfaceName(){ QString n(this->name()); return n; }; 19 virtual QString getInterfaceName(){ QString n(this->name()); return n; };
20 20
21 virtual bool getStatus(){ return status; }; 21 virtual bool getStatus(){ return status; };
22 virtual void setStatus(bool newStatus); 22 virtual void setStatus(bool newStatus);
23 23
24 virtual bool isAttached(){ return attached; }; 24 virtual bool isAttached(){ return attached; };
25 virtual void setAttached(bool isAttached=false); 25 virtual void setAttached(bool isAttached=false);
26 26
27 virtual QString getHardwareName(){ return hardareName; }; 27 virtual QString getHardwareName(){ return hardwareName; };
28 virtual void setHardwareName(QString name="Unknown"); 28 virtual void setHardwareName(QString name="Unknown");
29 29
30 virtual Module* getModuleOwner(){ return moduleOwner; }; 30 virtual Module* getModuleOwner(){ return moduleOwner; };
31 virtual void setModuleOwner(Module *owner=NULL); 31 virtual void setModuleOwner(Module *owner=NULL);
32 32
33 // inet information. 33 // inet information.
34 QString getMacAddress(){ return macAddress; }; 34 QString getMacAddress(){ return macAddress; };
35 QString getIp(){ return ip; }; 35 QString getIp(){ return ip; };
36 QString getSubnetMask(){ return subnetMask; }; 36 QString getSubnetMask(){ return subnetMask; };
37 QString getBroadcast(){ return broadcast; }; 37 QString getBroadcast(){ return broadcast; };
38 bool isDhcp(){ return dhcp; }; 38 bool isDhcp(){ return dhcp; };
39 QString getDhcpServerIp(){ return dhcpServerIp; }; 39 QString getDhcpServerIp(){ return dhcpServerIp; };
40 QString getLeaseObtained(){ return leaseObtained; }; 40 QString getLeaseObtained(){ return leaseObtained; };
41 QString getLeaseExpires(){ return leaseExpires; }; 41 QString getLeaseExpires(){ return leaseExpires; };
42 42
43public slots: 43public slots:
44 bool refresh(); 44 bool refresh();
45 void start(); 45 void start();
46 void stop(); 46 void stop();
47 void restart(); 47 void restart();
48 48
49private: 49private:
50 // Interface information 50 // Interface information
51 bool status; 51 bool status;
52 bool attached; 52 bool attached;
53 QString interfaceName; 53 QString interfaceName;
54 QString hardareName; 54 QString hardwareName;
55 Module *moduleOwner; 55 Module *moduleOwner;
56 56
57 // Network information 57 // Network information
58 QString macAddress; 58 QString macAddress;
59 QString ip; 59 QString ip;
60 QString broadcast; 60 QString broadcast;
61 QString subnetMask; 61 QString subnetMask;
62 bool dhcp; 62 bool dhcp;
63 QString dhcpServerIp; 63 QString dhcpServerIp;
64 QString leaseObtained; 64 QString leaseObtained;
65 QString leaseExpires; 65 QString leaseExpires;
66 66
67}; 67};
68 68
69#endif 69#endif
70 70
71// interface.h 71// interface.h
72 72
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 117bac1..a446d29 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -263,187 +263,186 @@ void MainWindowImp::informationClicked(){
263 information->show(); 263 information->show();
264} 264}
265 265
266/** 266/**
267 * Aquire the list of active interfaces from ifconfig 267 * Aquire the list of active interfaces from ifconfig
268 * Call ifconfig and ifconfig -a 268 * Call ifconfig and ifconfig -a
269 */ 269 */
270void MainWindowImp::getInterfaceList(){ 270void MainWindowImp::getInterfaceList(){
271 KShellProcess *processAll = new KShellProcess(); 271 KShellProcess *processAll = new KShellProcess();
272 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 272 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
273 connect(processAll, SIGNAL(processExited(KProcess *)), 273 connect(processAll, SIGNAL(processExited(KProcess *)),
274 this, SLOT(jobDone(KProcess *))); 274 this, SLOT(jobDone(KProcess *)));
275 threads.insert(processAll, TEMP_ALL); 275 threads.insert(processAll, TEMP_ALL);
276 276
277 KShellProcess *process = new KShellProcess(); 277 KShellProcess *process = new KShellProcess();
278 *process << "/sbin/ifconfig" << " > " TEMP_UP; 278 *process << "/sbin/ifconfig" << " > " TEMP_UP;
279 connect(process, SIGNAL(processExited(KProcess *)), 279 connect(process, SIGNAL(processExited(KProcess *)),
280 this, SLOT(jobDone(KProcess *))); 280 this, SLOT(jobDone(KProcess *)));
281 threads.insert(process, TEMP_UP); 281 threads.insert(process, TEMP_UP);
282 282
283 processAll->start(KShellProcess::NotifyOnExit); 283 processAll->start(KShellProcess::NotifyOnExit);
284 process->start(KShellProcess::NotifyOnExit); 284 process->start(KShellProcess::NotifyOnExit);
285} 285}
286 286
287void MainWindowImp::jobDone(KProcess *process){ 287void MainWindowImp::jobDone(KProcess *process){
288 QString fileName = threads[process]; 288 QString fileName = threads[process];
289 threads.remove(process); 289 threads.remove(process);
290 delete process; 290 delete process;
291 291
292 QFile file(fileName); 292 QFile file(fileName);
293 if (!file.open(IO_ReadOnly)){ 293 if (!file.open(IO_ReadOnly)){
294 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 294 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
295 return; 295 return;
296 } 296 }
297 297
298 QTextStream stream( &file ); 298 QTextStream stream( &file );
299 QString line; 299 QString line;
300 while ( !stream.eof() ) { 300 while ( !stream.eof() ) {
301 line = stream.readLine(); 301 line = stream.readLine();
302 int space = line.find(" "); 302 int space = line.find(" ");
303 if(space > 1){ 303 if(space > 1){
304 // We have found an interface 304 // We have found an interface
305 QString interfaceName = line.mid(0, space); 305 QString interfaceName = line.mid(0, space);
306 Interface *i; 306 Interface *i;
307 // We have found an interface 307 // We have found an interface
308 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 308 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
309 // See if we already have it 309 // See if we already have it
310 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 310 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
311 if(fileName == TEMP_ALL) 311 if(fileName == TEMP_ALL)
312 i = new Interface(this, interfaceName, false); 312 i = new Interface(this, interfaceName, false);
313 else 313 else
314 i = new Interface(this, interfaceName, true); 314 i = new Interface(this, interfaceName, true);
315 i->setAttached(true); 315 i->setAttached(true);
316 316
317 QString hardName = "Ethernet"; 317 QString hardName = "Ethernet";
318 int hardwareName = line.find("Link encap:"); 318 int hardwareName = line.find("Link encap:");
319 int macAddress = line.find("HWaddr"); 319 int macAddress = line.find("HWaddr");
320 if(macAddress == -1) 320 if(macAddress == -1)
321 macAddress = line.length(); 321 macAddress = line.length();
322 if(hardwareName != -1) 322 if(hardwareName != -1)
323 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); 323 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
324 324
325 interfaceNames.insert(i->getInterfaceName(), i); 325 interfaceNames.insert(i->getInterfaceName(), i);
326 updateInterface(i); 326 updateInterface(i);
327 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 327 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
328 } 328 }
329 // It was an interface we already had. 329 // It was an interface we already had.
330 else{ 330 else{
331 i = interfaceNames[interfaceName];
332 if(fileName != TEMP_ALL) 331 if(fileName != TEMP_ALL)
333 i->setStatus(true); 332 (interfaceNames[interfaceName])->setStatus(true);
334 } 333 }
335 } 334 }
336 } 335 }
337 file.close(); 336 file.close();
338 QFile::remove(fileName); 337 QFile::remove(fileName);
339 338
340 if(threads.count() == 0){ 339 if(threads.count() == 0){
341 Interfaces i; 340 Interfaces i;
342 QStringList list = i.getInterfaceList(); 341 QStringList list = i.getInterfaceList();
343 QMap<QString, Interface*>::Iterator it; 342 QMap<QString, Interface*>::Iterator it;
344 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 343 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
345 bool found = false; 344 bool found = false;
346 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 345 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
347 if(it.key() == (*ni)) 346 if(it.key() == (*ni))
348 found = true; 347 found = true;
349 } 348 }
350 if(!found){ 349 if(!found){
351 Interface *i = new Interface(this, *ni, false); 350 Interface *i = new Interface(this, *ni, false);
352 i->setAttached(false); 351 i->setAttached(false);
353 i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); 352 i->setHardwareName(QString("Disconnected (%1)").arg(*ni));
354 interfaceNames.insert(i->getInterfaceName(), i); 353 interfaceNames.insert(i->getInterfaceName(), i);
355 updateInterface(i); 354 updateInterface(i);
356 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 355 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
357 } 356 }
358 } 357 }
359 } 358 }
360} 359}
361 360
362/** 361/**
363 * Update this interface. If no QListViewItem exists create one. 362 * Update this interface. If no QListViewItem exists create one.
364 * @param Interface* pointer to the interface that needs to be updated. 363 * @param Interface* pointer to the interface that needs to be updated.
365 */ 364 */
366void MainWindowImp::updateInterface(Interface *i){ 365void MainWindowImp::updateInterface(Interface *i){
367 if(!advancedUserMode){ 366 if(!advancedUserMode){
368 if(i->getInterfaceName() == "lo") 367 if(i->getInterfaceName() == "lo")
369 return; 368 return;
370 } 369 }
371 370
372 QListViewItem *item = NULL; 371 QListViewItem *item = NULL;
373 372
374 // Find the interface, making it if needed. 373 // Find the interface, making it if needed.
375 if(items.find(i) == items.end()){ 374 if(items.find(i) == items.end()){
376 item = new QListViewItem(connectionList, "", "", ""); 375 item = new QListViewItem(connectionList, "", "", "");
377 // See if you can't find a module owner for this interface 376 // See if you can't find a module owner for this interface
378 QMap<Module*, QLibrary*>::Iterator it; 377 QMap<Module*, QLibrary*>::Iterator it;
379 for( it = libraries.begin(); it != libraries.end(); ++it ){ 378 for( it = libraries.begin(); it != libraries.end(); ++it ){
380 if(it.key()->isOwner(i)) 379 if(it.key()->isOwner(i))
381 i->setModuleOwner(it.key()); 380 i->setModuleOwner(it.key());
382 } 381 }
383 items.insert(i, item); 382 items.insert(i, item);
384 interfaceItems.insert(item, i); 383 interfaceItems.insert(item, i);
385 } 384 }
386 else 385 else
387 item = items[i]; 386 item = items[i];
388 387
389 // Update the icons and information 388 // Update the icons and information
390 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 389 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
391 390
392 QString typeName = "lan"; 391 QString typeName = "lan";
393 if(i->getHardwareName().contains("Local Loopback")) 392 if(i->getHardwareName().contains("Local Loopback"))
394 typeName = "lo"; 393 typeName = "lo";
395 if(i->getInterfaceName().contains("irda")) 394 if(i->getInterfaceName().contains("irda"))
396 typeName = "irda"; 395 typeName = "irda";
397 if(i->getInterfaceName().contains("wlan")) 396 if(i->getInterfaceName().contains("wlan"))
398 typeName = "wlan"; 397 typeName = "wlan";
399 if(i->getInterfaceName().contains("usb")) 398 if(i->getInterfaceName().contains("usb"))
400 typeName = "usb"; 399 typeName = "usb";
401 400
402 if(!i->isAttached()) 401 if(!i->isAttached())
403 typeName = "connect_no"; 402 typeName = "connect_no";
404 // Actually try to use the Module 403 // Actually try to use the Module
405 if(i->getModuleOwner() != NULL) 404 if(i->getModuleOwner() != NULL)
406 typeName = i->getModuleOwner()->getPixmapName(i); 405 typeName = i->getModuleOwner()->getPixmapName(i);
407 406
408 item->setPixmap(1, (Resource::loadPixmap(typeName))); 407 item->setPixmap(1, (Resource::loadPixmap(typeName)));
409 item->setText(2, i->getHardwareName()); 408 item->setText(2, i->getHardwareName());
410 item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); 409 item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
411} 410}
412 411
413void MainWindowImp::newProfileChanged(const QString& newText){ 412void MainWindowImp::newProfileChanged(const QString& newText){
414 if(newText.length() > 0) 413 if(newText.length() > 0)
415 newProfileButton->setEnabled(true); 414 newProfileButton->setEnabled(true);
416 else 415 else
417 newProfileButton->setEnabled(false); 416 newProfileButton->setEnabled(false);
418} 417}
419 418
420/** 419/**
421 * Adds a new profile to the list of profiles. 420 * Adds a new profile to the list of profiles.
422 * Don't add profiles that already exists. 421 * Don't add profiles that already exists.
423 * Appends to the list and QStringList 422 * Appends to the list and QStringList
424 */ 423 */
425void MainWindowImp::addProfile(){ 424void MainWindowImp::addProfile(){
426 QString newProfileName = newProfile->text(); 425 QString newProfileName = newProfile->text();
427 if(profiles.grep(newProfileName).count() > 0){ 426 if(profiles.grep(newProfileName).count() > 0){
428 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); 427 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
429 return; 428 return;
430 } 429 }
431 profiles.append(newProfileName); 430 profiles.append(newProfileName);
432 profilesList->insertItem(newProfileName); 431 profilesList->insertItem(newProfileName);
433} 432}
434 433
435/** 434/**
436 * Removes the currently selected profile in the combo. 435 * Removes the currently selected profile in the combo.
437 * Doesn't delete if there are less then 2 profiles. 436 * Doesn't delete if there are less then 2 profiles.
438 */ 437 */
439void MainWindowImp::removeProfile(){ 438void MainWindowImp::removeProfile(){
440 if(profilesList->count() <= 1){ 439 if(profilesList->count() <= 1){
441 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); 440 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
442 return; 441 return;
443 } 442 }
444 QString profileToRemove = profilesList->currentText(); 443 QString profileToRemove = profilesList->currentText();
445 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 444 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
446 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 445 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
447 profilesList->clear(); 446 profilesList->clear();
448 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 447 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
449 profilesList->insertItem((*it)); 448 profilesList->insertItem((*it));