summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/interface.cpp24
-rw-r--r--noncore/net/networksetup/interfaces/interface.h3
-rw-r--r--noncore/net/networksetup/interfaces/interfaceinformationimp.cpp13
-rw-r--r--noncore/net/networksetup/interfaces/interfaceinformationimp.h1
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.pro2
-rw-r--r--noncore/settings/networksettings/interfaces/interface.cpp24
-rw-r--r--noncore/settings/networksettings/interfaces/interface.h3
-rw-r--r--noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp13
-rw-r--r--noncore/settings/networksettings/interfaces/interfaceinformationimp.h1
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.pro2
10 files changed, 66 insertions, 20 deletions
diff --git a/noncore/net/networksetup/interfaces/interface.cpp b/noncore/net/networksetup/interfaces/interface.cpp
index 929b3a1..e4f405e 100644
--- a/noncore/net/networksetup/interfaces/interface.cpp
+++ b/noncore/net/networksetup/interfaces/interface.cpp
@@ -1,287 +1,297 @@
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 DHCP_INFO_DIR "/etc/dhcpc" 9#define DHCP_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), hardwareName("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 hardwareName = 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 emit (updateMessage("Unable to start interface,\n already started"));
67 return; 68 return;
68 69 }
70
69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 71 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
70 // See if it was successfull... 72 // See if it was successfull...
71 if(ret != 0) 73 if(ret != 0){
74 emit (updateMessage("Starting interface failed."));
72 return; 75 return;
73 76 }
77
74 status = true; 78 status = true;
75 refresh(); 79 refresh();
80 emit (updateMessage("Start successfull"));
76} 81}
77 82
78/** 83/**
79 * Try to stop the interface. 84 * Try to stop the interface.
80 */ 85 */
81void Interface::stop(){ 86void Interface::stop(){
82 // check to see if we are already stopped. 87 // check to see if we are already stopped.
83 if(false == status) 88 if(false == status){
89 emit (updateMessage("Unable to stop interface,\n already stopped"));
84 return; 90 return;
91 }
85 92
86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 93 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
87 if(ret != 0) 94 if(ret != 0){
95 emit (updateMessage("Stopping interface failed."));
88 return; 96 return;
97 }
89 98
90 status = true; 99 status = false;
91 refresh(); 100 refresh();
101 emit (updateMessage("Stop successfull"));
92} 102}
93 103
94/** 104/**
95 * Try to restart the interface. 105 * Try to restart the interface.
96 */ 106 */
97void Interface::restart(){ 107void Interface::restart(){
98 stop(); 108 stop();
99 start(); 109 start();
100} 110}
101 111
102/** 112/**
103 * Try to refresh the information about the interface. 113 * Try to refresh the information about the interface.
104 * First call ifconfig, then check the dhcp-info file 114 * First call ifconfig, then check the dhcp-info file
105 * @return bool true if successfull. 115 * @return bool true if successfull.
106 */ 116 */
107bool Interface::refresh(){ 117bool Interface::refresh(){
108 // See if we are up. 118 // See if we are up.
109 if(status == false){ 119 if(status == false){
110 macAddress = ""; 120 macAddress = "";
111 ip = "0.0.0.0"; 121 ip = "0.0.0.0";
112 subnetMask = "0.0.0.0"; 122 subnetMask = "0.0.0.0";
113 broadcast = ""; 123 broadcast = "";
114 dhcp = false; 124 dhcp = false;
115 dhcpServerIp = ""; 125 dhcpServerIp = "";
116 leaseObtained = ""; 126 leaseObtained = "";
117 leaseExpires = ""; 127 leaseExpires = "";
118 emit(updateInterface(this)); 128 emit(updateInterface(this));
119 return true; 129 return true;
120 } 130 }
121 131
122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 132 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 133 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
124 if(ret != 0){ 134 if(ret != 0){
125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 135 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
126 return false; 136 return false;
127 } 137 }
128 138
129 QFile file(fileName); 139 QFile file(fileName);
130 if (!file.open(IO_ReadOnly)){ 140 if (!file.open(IO_ReadOnly)){
131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 141 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
132 return false; 142 return false;
133 } 143 }
134 144
135 // Set to the defaults 145 // Set to the defaults
136 macAddress = ""; 146 macAddress = "";
137 ip = "0.0.0.0"; 147 ip = "0.0.0.0";
138 subnetMask = "0.0.0.0"; 148 subnetMask = "0.0.0.0";
139 broadcast = ""; 149 broadcast = "";
140 150
141 QTextStream stream( &file ); 151 QTextStream stream( &file );
142 QString line; 152 QString line;
143 while ( !stream.eof() ) { 153 while ( !stream.eof() ) {
144 line = stream.readLine(); 154 line = stream.readLine();
145 if(line.contains("HWaddr")){ 155 if(line.contains("HWaddr")){
146 int mac = line.find("HWaddr"); 156 int mac = line.find("HWaddr");
147 macAddress = line.mid(mac+7, line.length()); 157 macAddress = line.mid(mac+7, line.length());
148 } 158 }
149 if(line.contains("inet addr")){ 159 if(line.contains("inet addr")){
150 int ipl = line.find("inet addr"); 160 int ipl = line.find("inet addr");
151 int space = line.find(" ", ipl+10); 161 int space = line.find(" ", ipl+10);
152 ip = line.mid(ipl+10, space-ipl-10); 162 ip = line.mid(ipl+10, space-ipl-10);
153 } 163 }
154 if(line.contains("Mask")){ 164 if(line.contains("Mask")){
155 int mask = line.find("Mask"); 165 int mask = line.find("Mask");
156 subnetMask = line.mid(mask+5, line.length()); 166 subnetMask = line.mid(mask+5, line.length());
157 } 167 }
158 if(line.contains("Bcast")){ 168 if(line.contains("Bcast")){
159 int mask = line.find("Bcast"); 169 int mask = line.find("Bcast");
160 int space = line.find(" ", mask+6); 170 int space = line.find(" ", mask+6);
161 broadcast = line.mid(mask+6, space-mask-6); 171 broadcast = line.mid(mask+6, space-mask-6);
162 } 172 }
163 } 173 }
164 file.close(); 174 file.close();
165 QFile::remove(fileName); 175 QFile::remove(fileName);
166 176
167 // DHCP TESTING 177 // DHCP TESTING
168 // reset DHCP info 178 // reset DHCP info
169 dhcpServerIp = ""; 179 dhcpServerIp = "";
170 leaseObtained = ""; 180 leaseObtained = "";
171 leaseExpires = ""; 181 leaseExpires = "";
172 dhcp = false; 182 dhcp = false;
173 183
174 QString dhcpDirectory(DHCP_INFO_DIR); 184 QString dhcpDirectory(DHCP_INFO_DIR);
175 QDir d(dhcpDirectory); 185 QDir d(dhcpDirectory);
176 if(!d.exists(dhcpDirectory)) 186 if(!d.exists(dhcpDirectory))
177 dhcpDirectory = "/var/run"; 187 dhcpDirectory = "/var/run";
178 188
179 // See if we have 189 // See if we have
180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 190 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
181 // If there is no DHCP information then exit now with no errors. 191 // If there is no DHCP information then exit now with no errors.
182 if(!QFile::exists(dhcpFile)){ 192 if(!QFile::exists(dhcpFile)){
183 emit(updateInterface(this)); 193 emit(updateInterface(this));
184 return true; 194 return true;
185 } 195 }
186 196
187 file.setName(dhcpFile); 197 file.setName(dhcpFile);
188 if (!file.open(IO_ReadOnly)){ 198 if (!file.open(IO_ReadOnly)){
189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 199 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
190 return false; 200 return false;
191 } 201 }
192 202
193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 203 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
194 int leaseTime = 0; 204 int leaseTime = 0;
195 int renewalTime = 0; 205 int renewalTime = 0;
196 206
197 stream.setDevice( &file ); 207 stream.setDevice( &file );
198 while ( !stream.eof() ) { 208 while ( !stream.eof() ) {
199 line = stream.readLine(); 209 line = stream.readLine();
200 if(line.contains("DHCPSIADDR=")) 210 if(line.contains("DHCPSIADDR="))
201 dhcpServerIp = line.mid(11, line.length()); 211 dhcpServerIp = line.mid(11, line.length());
202 if(line.contains("LEASETIME=")) 212 if(line.contains("LEASETIME="))
203 leaseTime = line.mid(10, line.length()).toInt(); 213 leaseTime = line.mid(10, line.length()).toInt();
204 if(line.contains("RENEWALTIME=")) 214 if(line.contains("RENEWALTIME="))
205 renewalTime = line.mid(12, line.length()).toInt(); 215 renewalTime = line.mid(12, line.length()).toInt();
206 } 216 }
207 file.close(); 217 file.close();
208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 218 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 219 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
210 220
211 // Get the pid of the deamond 221 // Get the pid of the deamond
212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); 222 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
213 file.setName(dhcpFile); 223 file.setName(dhcpFile);
214 if (!file.open(IO_ReadOnly)){ 224 if (!file.open(IO_ReadOnly)){
215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 225 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
216 return false; 226 return false;
217 } 227 }
218 228
219 int pid = -1; 229 int pid = -1;
220 stream.setDevice( &file ); 230 stream.setDevice( &file );
221 while ( !stream.eof() ) { 231 while ( !stream.eof() ) {
222 line = stream.readLine(); 232 line = stream.readLine();
223 pid = line.toInt(); 233 pid = line.toInt();
224 } 234 }
225 file.close(); 235 file.close();
226 236
227 if( pid == -1){ 237 if( pid == -1){
228 qDebug("Interface: Could not get pid of dhcpc deamon."); 238 qDebug("Interface: Could not get pid of dhcpc deamon.");
229 return false; 239 return false;
230 } 240 }
231 241
232 // Get the start running time of the deamon 242 // Get the start running time of the deamon
233 fileName = (QString("/proc/%1/stat").arg(pid)); 243 fileName = (QString("/proc/%1/stat").arg(pid));
234 file.setName(fileName); 244 file.setName(fileName);
235 stream.setDevice( &file ); 245 stream.setDevice( &file );
236 if (!file.open(IO_ReadOnly)){ 246 if (!file.open(IO_ReadOnly)){
237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 247 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
238 return false; 248 return false;
239 } 249 }
240 while ( !stream.eof() ) { 250 while ( !stream.eof() ) {
241 line = stream.readLine(); 251 line = stream.readLine();
242 } 252 }
243 file.close(); 253 file.close();
244 long time = 0; 254 long time = 0;
245 // Grab the start time 255 // Grab the start time
246 // pid com state ppid pgrp session tty_nr tpgid flags 256 // pid com state ppid pgrp session tty_nr tpgid flags
247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 257 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 258 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 259 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
250 // nice 0 itrealvalue starttime 260 // nice 0 itrealvalue starttime
251 "%*d %*d %*d %lu", (long*) &time); 261 "%*d %*d %*d %lu", (long*) &time);
252 time = time/100; 262 time = time/100;
253 263
254 QDateTime datetime(QDateTime::currentDateTime()); 264 QDateTime datetime(QDateTime::currentDateTime());
255 265
256 // Get the uptime of the computer. 266 // Get the uptime of the computer.
257 QFile f("/proc/uptime"); 267 QFile f("/proc/uptime");
258 if ( f.open(IO_ReadOnly) ) { // file opened successfully 268 if ( f.open(IO_ReadOnly) ) { // file opened successfully
259 QTextStream t( &f ); // use a text stream 269 QTextStream t( &f ); // use a text stream
260 int sec = 0; 270 int sec = 0;
261 t >> sec; 271 t >> sec;
262 datetime = datetime.addSecs((-1*sec)); 272 datetime = datetime.addSecs((-1*sec));
263 f.close(); 273 f.close();
264 } 274 }
265 else{ 275 else{
266 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 276 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
267 return false; 277 return false;
268 } 278 }
269 279
270 datetime = datetime.addSecs(time); 280 datetime = datetime.addSecs(time);
271 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 281 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
272 282
273 // Calculate the start and renew times 283 // Calculate the start and renew times
274 leaseObtained= datetime.toString(); 284 leaseObtained= datetime.toString();
275 285
276 // Calculate the start and renew times 286 // Calculate the start and renew times
277 datetime = datetime.addSecs(leaseTime); 287 datetime = datetime.addSecs(leaseTime);
278 leaseExpires = datetime.toString(); 288 leaseExpires = datetime.toString();
279 289
280 dhcp = true; 290 dhcp = true;
281 291
282 emit(updateInterface(this)); 292 emit(updateInterface(this));
283 return true; 293 return true;
284} 294}
285 295
286// interface.cpp 296// interface.cpp
287 297
diff --git a/noncore/net/networksetup/interfaces/interface.h b/noncore/net/networksetup/interfaces/interface.h
index dc9c6d3..fc064fe 100644
--- a/noncore/net/networksetup/interfaces/interface.h
+++ b/noncore/net/networksetup/interfaces/interface.h
@@ -1,71 +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 void updateMessage(const QString &message);
15
15public: 16public:
16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false); 17 Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
17 virtual ~Interface(){}; 18 virtual ~Interface(){};
18 19
19 virtual QString getInterfaceName(){ QString n(this->name()); return n; }; 20 virtual QString getInterfaceName(){ QString n(this->name()); return n; };
20 21
21 virtual bool getStatus(){ return status; }; 22 virtual bool getStatus(){ return status; };
22 virtual void setStatus(bool newStatus); 23 virtual void setStatus(bool newStatus);
23 24
24 virtual bool isAttached(){ return attached; }; 25 virtual bool isAttached(){ return attached; };
25 virtual void setAttached(bool isAttached=false); 26 virtual void setAttached(bool isAttached=false);
26 27
27 virtual QString getHardwareName(){ return hardwareName; }; 28 virtual QString getHardwareName(){ return hardwareName; };
28 virtual void setHardwareName(QString name="Unknown"); 29 virtual void setHardwareName(QString name="Unknown");
29 30
30 virtual Module* getModuleOwner(){ return moduleOwner; }; 31 virtual Module* getModuleOwner(){ return moduleOwner; };
31 virtual void setModuleOwner(Module *owner=NULL); 32 virtual void setModuleOwner(Module *owner=NULL);
32 33
33 // inet information. 34 // inet information.
34 QString getMacAddress(){ return macAddress; }; 35 QString getMacAddress(){ return macAddress; };
35 QString getIp(){ return ip; }; 36 QString getIp(){ return ip; };
36 QString getSubnetMask(){ return subnetMask; }; 37 QString getSubnetMask(){ return subnetMask; };
37 QString getBroadcast(){ return broadcast; }; 38 QString getBroadcast(){ return broadcast; };
38 bool isDhcp(){ return dhcp; }; 39 bool isDhcp(){ return dhcp; };
39 QString getDhcpServerIp(){ return dhcpServerIp; }; 40 QString getDhcpServerIp(){ return dhcpServerIp; };
40 QString getLeaseObtained(){ return leaseObtained; }; 41 QString getLeaseObtained(){ return leaseObtained; };
41 QString getLeaseExpires(){ return leaseExpires; }; 42 QString getLeaseExpires(){ return leaseExpires; };
42 43
43public slots: 44public slots:
44 bool refresh(); 45 bool refresh();
45 void start(); 46 void start();
46 void stop(); 47 void stop();
47 void restart(); 48 void restart();
48 49
49private: 50private:
50 // Interface information 51 // Interface information
51 bool status; 52 bool status;
52 bool attached; 53 bool attached;
53 QString hardwareName; 54 QString hardwareName;
54 Module *moduleOwner; 55 Module *moduleOwner;
55 56
56 // Network information 57 // Network information
57 QString macAddress; 58 QString macAddress;
58 QString ip; 59 QString ip;
59 QString broadcast; 60 QString broadcast;
60 QString subnetMask; 61 QString subnetMask;
61 bool dhcp; 62 bool dhcp;
62 QString dhcpServerIp; 63 QString dhcpServerIp;
63 QString leaseObtained; 64 QString leaseObtained;
64 QString leaseExpires; 65 QString leaseExpires;
65 66
66}; 67};
67 68
68#endif 69#endif
69 70
70// interface.h 71// interface.h
71 72
diff --git a/noncore/net/networksetup/interfaces/interfaceinformationimp.cpp b/noncore/net/networksetup/interfaces/interfaceinformationimp.cpp
index 43483fb..39575c4 100644
--- a/noncore/net/networksetup/interfaces/interfaceinformationimp.cpp
+++ b/noncore/net/networksetup/interfaces/interfaceinformationimp.cpp
@@ -1,70 +1,81 @@
1#include "interfaceinformationimp.h" 1#include "interfaceinformationimp.h"
2#include "interfaceadvanced.h" 2#include "interfaceadvanced.h"
3 3
4#include <qpushbutton.h> 4#include <qpushbutton.h>
5#include <qlabel.h> 5#include <qlabel.h>
6#include <qgroupbox.h> 6#include <qgroupbox.h>
7#include <qmessagebox.h>
8
7#include <assert.h> 9#include <assert.h>
8 10
9/** 11/**
10 * Constructor for the InterfaceInformationImp class. This class pretty much 12 * Constructor for the InterfaceInformationImp class. This class pretty much
11 * just display's information about the interface that is passed to it. 13 * just display's information about the interface that is passed to it.
12 */ 14 */
13InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ 15InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){
14 assert(i); 16 assert(i);
15 17
16 interface = i; 18 interface = i;
17 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 19 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
20 connect(i, SIGNAL(updateMessage(const QString &)), this, SLOT(showMessage(const QString &)));
18 updateInterface(interface); 21 updateInterface(interface);
19 connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); 22 connect(startButton, SIGNAL(clicked()), interface, SLOT(start()));
20 connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); 23 connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop()));
21 connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); 24 connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart()));
22 connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); 25 connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh()));
23 connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); 26 connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced()));
24
25} 27}
26 28
27/** 29/**
28 * Update the interface information and buttons. 30 * Update the interface information and buttons.
29 * @param Intarface *i the interface to update (should be the one we already 31 * @param Intarface *i the interface to update (should be the one we already
30 * know about). 32 * know about).
31 */ 33 */
32void InterfaceInformationImp::updateInterface(Interface *i){ 34void InterfaceInformationImp::updateInterface(Interface *i){
33 if(interface->getStatus()){ 35 if(interface->getStatus()){
34 startButton->setEnabled(false); 36 startButton->setEnabled(false);
35 stopButton->setEnabled(true); 37 stopButton->setEnabled(true);
36 restartButton->setEnabled(true); 38 restartButton->setEnabled(true);
37 } 39 }
38 else{ 40 else{
39 startButton->setEnabled(true); 41 startButton->setEnabled(true);
40 stopButton->setEnabled(false); 42 stopButton->setEnabled(false);
41 restartButton->setEnabled(false); 43 restartButton->setEnabled(false);
42 } 44 }
43 macAddressLabel->setText(interface->getMacAddress()); 45 macAddressLabel->setText(interface->getMacAddress());
44 ipAddressLabel->setText(interface->getIp()); 46 ipAddressLabel->setText(interface->getIp());
45 subnetMaskLabel->setText(interface->getSubnetMask()); 47 subnetMaskLabel->setText(interface->getSubnetMask());
46 broadcastLabel->setText(interface->getBroadcast()); 48 broadcastLabel->setText(interface->getBroadcast());
47} 49}
48 50
49/** 51/**
50 * Create the advanced widget. Fill it with the current interface's information. 52 * Create the advanced widget. Fill it with the current interface's information.
51 * Display it. 53 * Display it.
52 */ 54 */
53void InterfaceInformationImp::advanced(){ 55void InterfaceInformationImp::advanced(){
54 InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); 56 InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced");
55 a->interfaceName->setText(interface->getInterfaceName()); 57 a->interfaceName->setText(interface->getInterfaceName());
56 a->macAddressLabel->setText(interface->getMacAddress()); 58 a->macAddressLabel->setText(interface->getMacAddress());
57 a->ipAddressLabel->setText(interface->getIp()); 59 a->ipAddressLabel->setText(interface->getIp());
58 a->subnetMaskLabel->setText(interface->getSubnetMask()); 60 a->subnetMaskLabel->setText(interface->getSubnetMask());
59 a->broadcastLabel->setText(interface->getBroadcast()); 61 a->broadcastLabel->setText(interface->getBroadcast());
60 a->dhcpServerLabel->setText(interface->getDhcpServerIp()); 62 a->dhcpServerLabel->setText(interface->getDhcpServerIp());
61 a->leaseObtainedLabel->setText(interface->getLeaseObtained()); 63 a->leaseObtainedLabel->setText(interface->getLeaseObtained());
62 a->leaseExpiresLabel->setText(interface->getLeaseExpires()); 64 a->leaseExpiresLabel->setText(interface->getLeaseExpires());
63 a->dhcpInformation->setEnabled(interface->isDhcp()); 65 a->dhcpInformation->setEnabled(interface->isDhcp());
64 66
65 a->showMaximized(); 67 a->showMaximized();
66 a->show(); 68 a->show();
67} 69}
68 70
71/**
72 * Messages from the interface if start/stop went as planned.
73 * Purly for user feedback.
74 * @param message the message to display.
75 */
76void InterfaceInformationImp::showMessage(const QString &message){
77 QMessageBox::information(this, "Message", message, QMessageBox::Ok);
78}
79
69// infoimp.cpp 80// infoimp.cpp
70 81
diff --git a/noncore/net/networksetup/interfaces/interfaceinformationimp.h b/noncore/net/networksetup/interfaces/interfaceinformationimp.h
index 42213cc..65cdfe0 100644
--- a/noncore/net/networksetup/interfaces/interfaceinformationimp.h
+++ b/noncore/net/networksetup/interfaces/interfaceinformationimp.h
@@ -1,27 +1,28 @@
1#ifndef INTERFACEINFORMATIONIMP_H 1#ifndef INTERFACEINFORMATIONIMP_H
2#define INTERFACEINFORMATIONIMP_H 2#define INTERFACEINFORMATIONIMP_H
3 3
4#include "interfaceinformation.h" 4#include "interfaceinformation.h"
5#include "interface.h" 5#include "interface.h"
6 6
7class InterfaceInformationImp : public InterfaceInformation { 7class InterfaceInformationImp : public InterfaceInformation {
8 8
9Q_OBJECT 9Q_OBJECT
10 10
11public: 11public:
12 InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); 12 InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0);
13 ~InterfaceInformationImp(){}; 13 ~InterfaceInformationImp(){};
14 14
15private slots: 15private slots:
16 void advanced(); 16 void advanced();
17 void updateInterface(Interface *i); 17 void updateInterface(Interface *i);
18 void showMessage(const QString &message);
18 19
19private: 20private:
20 Interface *interface; 21 Interface *interface;
21 22
22}; 23};
23 24
24#endif 25#endif
25 26
26// addserviceimp.h 27// addserviceimp.h
27 28
diff --git a/noncore/net/networksetup/interfaces/interfaces.pro b/noncore/net/networksetup/interfaces/interfaces.pro
index 9a024f6..d6b43fb 100644
--- a/noncore/net/networksetup/interfaces/interfaces.pro
+++ b/noncore/net/networksetup/interfaces/interfaces.pro
@@ -1,12 +1,12 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug 3 #CONFIG += qt warn_on debug
4 DESTDIR = $(QTDIR)/lib$(PROJMAK) 4 #DESTDIR = $(QTDIR)/lib$(PROJMAK)
5 HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h 5 HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h
6 SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp 6 SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp
7 INCLUDEPATH+= $(OPIEDIR)/include ../ 7 INCLUDEPATH+= $(OPIEDIR)/include ../
8 DEPENDPATH+= $(OPIEDIR)/include 8 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe 9LIBS += -lqpe
10 INTERFACES= interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui 10 INTERFACES= interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui
11 TARGET = interfaces 11 TARGET = interfaces
12 VERSION = 1.0.0 12 VERSION = 1.0.0
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp
index 929b3a1..e4f405e 100644
--- a/noncore/settings/networksettings/interfaces/interface.cpp
+++ b/noncore/settings/networksettings/interfaces/interface.cpp
@@ -1,287 +1,297 @@
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 DHCP_INFO_DIR "/etc/dhcpc" 9#define DHCP_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), hardwareName("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 hardwareName = 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 emit (updateMessage("Unable to start interface,\n already started"));
67 return; 68 return;
68 69 }
70
69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 71 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
70 // See if it was successfull... 72 // See if it was successfull...
71 if(ret != 0) 73 if(ret != 0){
74 emit (updateMessage("Starting interface failed."));
72 return; 75 return;
73 76 }
77
74 status = true; 78 status = true;
75 refresh(); 79 refresh();
80 emit (updateMessage("Start successfull"));
76} 81}
77 82
78/** 83/**
79 * Try to stop the interface. 84 * Try to stop the interface.
80 */ 85 */
81void Interface::stop(){ 86void Interface::stop(){
82 // check to see if we are already stopped. 87 // check to see if we are already stopped.
83 if(false == status) 88 if(false == status){
89 emit (updateMessage("Unable to stop interface,\n already stopped"));
84 return; 90 return;
91 }
85 92
86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 93 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
87 if(ret != 0) 94 if(ret != 0){
95 emit (updateMessage("Stopping interface failed."));
88 return; 96 return;
97 }
89 98
90 status = true; 99 status = false;
91 refresh(); 100 refresh();
101 emit (updateMessage("Stop successfull"));
92} 102}
93 103
94/** 104/**
95 * Try to restart the interface. 105 * Try to restart the interface.
96 */ 106 */
97void Interface::restart(){ 107void Interface::restart(){
98 stop(); 108 stop();
99 start(); 109 start();
100} 110}
101 111
102/** 112/**
103 * Try to refresh the information about the interface. 113 * Try to refresh the information about the interface.
104 * First call ifconfig, then check the dhcp-info file 114 * First call ifconfig, then check the dhcp-info file
105 * @return bool true if successfull. 115 * @return bool true if successfull.
106 */ 116 */
107bool Interface::refresh(){ 117bool Interface::refresh(){
108 // See if we are up. 118 // See if we are up.
109 if(status == false){ 119 if(status == false){
110 macAddress = ""; 120 macAddress = "";
111 ip = "0.0.0.0"; 121 ip = "0.0.0.0";
112 subnetMask = "0.0.0.0"; 122 subnetMask = "0.0.0.0";
113 broadcast = ""; 123 broadcast = "";
114 dhcp = false; 124 dhcp = false;
115 dhcpServerIp = ""; 125 dhcpServerIp = "";
116 leaseObtained = ""; 126 leaseObtained = "";
117 leaseExpires = ""; 127 leaseExpires = "";
118 emit(updateInterface(this)); 128 emit(updateInterface(this));
119 return true; 129 return true;
120 } 130 }
121 131
122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 132 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 133 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
124 if(ret != 0){ 134 if(ret != 0){
125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 135 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
126 return false; 136 return false;
127 } 137 }
128 138
129 QFile file(fileName); 139 QFile file(fileName);
130 if (!file.open(IO_ReadOnly)){ 140 if (!file.open(IO_ReadOnly)){
131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 141 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
132 return false; 142 return false;
133 } 143 }
134 144
135 // Set to the defaults 145 // Set to the defaults
136 macAddress = ""; 146 macAddress = "";
137 ip = "0.0.0.0"; 147 ip = "0.0.0.0";
138 subnetMask = "0.0.0.0"; 148 subnetMask = "0.0.0.0";
139 broadcast = ""; 149 broadcast = "";
140 150
141 QTextStream stream( &file ); 151 QTextStream stream( &file );
142 QString line; 152 QString line;
143 while ( !stream.eof() ) { 153 while ( !stream.eof() ) {
144 line = stream.readLine(); 154 line = stream.readLine();
145 if(line.contains("HWaddr")){ 155 if(line.contains("HWaddr")){
146 int mac = line.find("HWaddr"); 156 int mac = line.find("HWaddr");
147 macAddress = line.mid(mac+7, line.length()); 157 macAddress = line.mid(mac+7, line.length());
148 } 158 }
149 if(line.contains("inet addr")){ 159 if(line.contains("inet addr")){
150 int ipl = line.find("inet addr"); 160 int ipl = line.find("inet addr");
151 int space = line.find(" ", ipl+10); 161 int space = line.find(" ", ipl+10);
152 ip = line.mid(ipl+10, space-ipl-10); 162 ip = line.mid(ipl+10, space-ipl-10);
153 } 163 }
154 if(line.contains("Mask")){ 164 if(line.contains("Mask")){
155 int mask = line.find("Mask"); 165 int mask = line.find("Mask");
156 subnetMask = line.mid(mask+5, line.length()); 166 subnetMask = line.mid(mask+5, line.length());
157 } 167 }
158 if(line.contains("Bcast")){ 168 if(line.contains("Bcast")){
159 int mask = line.find("Bcast"); 169 int mask = line.find("Bcast");
160 int space = line.find(" ", mask+6); 170 int space = line.find(" ", mask+6);
161 broadcast = line.mid(mask+6, space-mask-6); 171 broadcast = line.mid(mask+6, space-mask-6);
162 } 172 }
163 } 173 }
164 file.close(); 174 file.close();
165 QFile::remove(fileName); 175 QFile::remove(fileName);
166 176
167 // DHCP TESTING 177 // DHCP TESTING
168 // reset DHCP info 178 // reset DHCP info
169 dhcpServerIp = ""; 179 dhcpServerIp = "";
170 leaseObtained = ""; 180 leaseObtained = "";
171 leaseExpires = ""; 181 leaseExpires = "";
172 dhcp = false; 182 dhcp = false;
173 183
174 QString dhcpDirectory(DHCP_INFO_DIR); 184 QString dhcpDirectory(DHCP_INFO_DIR);
175 QDir d(dhcpDirectory); 185 QDir d(dhcpDirectory);
176 if(!d.exists(dhcpDirectory)) 186 if(!d.exists(dhcpDirectory))
177 dhcpDirectory = "/var/run"; 187 dhcpDirectory = "/var/run";
178 188
179 // See if we have 189 // See if we have
180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 190 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
181 // If there is no DHCP information then exit now with no errors. 191 // If there is no DHCP information then exit now with no errors.
182 if(!QFile::exists(dhcpFile)){ 192 if(!QFile::exists(dhcpFile)){
183 emit(updateInterface(this)); 193 emit(updateInterface(this));
184 return true; 194 return true;
185 } 195 }
186 196
187 file.setName(dhcpFile); 197 file.setName(dhcpFile);
188 if (!file.open(IO_ReadOnly)){ 198 if (!file.open(IO_ReadOnly)){
189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 199 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
190 return false; 200 return false;
191 } 201 }
192 202
193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 203 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
194 int leaseTime = 0; 204 int leaseTime = 0;
195 int renewalTime = 0; 205 int renewalTime = 0;
196 206
197 stream.setDevice( &file ); 207 stream.setDevice( &file );
198 while ( !stream.eof() ) { 208 while ( !stream.eof() ) {
199 line = stream.readLine(); 209 line = stream.readLine();
200 if(line.contains("DHCPSIADDR=")) 210 if(line.contains("DHCPSIADDR="))
201 dhcpServerIp = line.mid(11, line.length()); 211 dhcpServerIp = line.mid(11, line.length());
202 if(line.contains("LEASETIME=")) 212 if(line.contains("LEASETIME="))
203 leaseTime = line.mid(10, line.length()).toInt(); 213 leaseTime = line.mid(10, line.length()).toInt();
204 if(line.contains("RENEWALTIME=")) 214 if(line.contains("RENEWALTIME="))
205 renewalTime = line.mid(12, line.length()).toInt(); 215 renewalTime = line.mid(12, line.length()).toInt();
206 } 216 }
207 file.close(); 217 file.close();
208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 218 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 219 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
210 220
211 // Get the pid of the deamond 221 // Get the pid of the deamond
212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); 222 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
213 file.setName(dhcpFile); 223 file.setName(dhcpFile);
214 if (!file.open(IO_ReadOnly)){ 224 if (!file.open(IO_ReadOnly)){
215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 225 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
216 return false; 226 return false;
217 } 227 }
218 228
219 int pid = -1; 229 int pid = -1;
220 stream.setDevice( &file ); 230 stream.setDevice( &file );
221 while ( !stream.eof() ) { 231 while ( !stream.eof() ) {
222 line = stream.readLine(); 232 line = stream.readLine();
223 pid = line.toInt(); 233 pid = line.toInt();
224 } 234 }
225 file.close(); 235 file.close();
226 236
227 if( pid == -1){ 237 if( pid == -1){
228 qDebug("Interface: Could not get pid of dhcpc deamon."); 238 qDebug("Interface: Could not get pid of dhcpc deamon.");
229 return false; 239 return false;
230 } 240 }
231 241
232 // Get the start running time of the deamon 242 // Get the start running time of the deamon
233 fileName = (QString("/proc/%1/stat").arg(pid)); 243 fileName = (QString("/proc/%1/stat").arg(pid));
234 file.setName(fileName); 244 file.setName(fileName);
235 stream.setDevice( &file ); 245 stream.setDevice( &file );
236 if (!file.open(IO_ReadOnly)){ 246 if (!file.open(IO_ReadOnly)){
237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 247 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
238 return false; 248 return false;
239 } 249 }
240 while ( !stream.eof() ) { 250 while ( !stream.eof() ) {
241 line = stream.readLine(); 251 line = stream.readLine();
242 } 252 }
243 file.close(); 253 file.close();
244 long time = 0; 254 long time = 0;
245 // Grab the start time 255 // Grab the start time
246 // pid com state ppid pgrp session tty_nr tpgid flags 256 // pid com state ppid pgrp session tty_nr tpgid flags
247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 257 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 258 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 259 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
250 // nice 0 itrealvalue starttime 260 // nice 0 itrealvalue starttime
251 "%*d %*d %*d %lu", (long*) &time); 261 "%*d %*d %*d %lu", (long*) &time);
252 time = time/100; 262 time = time/100;
253 263
254 QDateTime datetime(QDateTime::currentDateTime()); 264 QDateTime datetime(QDateTime::currentDateTime());
255 265
256 // Get the uptime of the computer. 266 // Get the uptime of the computer.
257 QFile f("/proc/uptime"); 267 QFile f("/proc/uptime");
258 if ( f.open(IO_ReadOnly) ) { // file opened successfully 268 if ( f.open(IO_ReadOnly) ) { // file opened successfully
259 QTextStream t( &f ); // use a text stream 269 QTextStream t( &f ); // use a text stream
260 int sec = 0; 270 int sec = 0;
261 t >> sec; 271 t >> sec;
262 datetime = datetime.addSecs((-1*sec)); 272 datetime = datetime.addSecs((-1*sec));
263 f.close(); 273 f.close();
264 } 274 }
265 else{ 275 else{
266 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 276 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
267 return false; 277 return false;
268 } 278 }
269 279
270 datetime = datetime.addSecs(time); 280 datetime = datetime.addSecs(time);
271 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 281 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
272 282
273 // Calculate the start and renew times 283 // Calculate the start and renew times
274 leaseObtained= datetime.toString(); 284 leaseObtained= datetime.toString();
275 285
276 // Calculate the start and renew times 286 // Calculate the start and renew times
277 datetime = datetime.addSecs(leaseTime); 287 datetime = datetime.addSecs(leaseTime);
278 leaseExpires = datetime.toString(); 288 leaseExpires = datetime.toString();
279 289
280 dhcp = true; 290 dhcp = true;
281 291
282 emit(updateInterface(this)); 292 emit(updateInterface(this));
283 return true; 293 return true;
284} 294}
285 295
286// interface.cpp 296// interface.cpp
287 297
diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h
index dc9c6d3..fc064fe 100644
--- a/noncore/settings/networksettings/interfaces/interface.h
+++ b/noncore/settings/networksettings/interfaces/interface.h
@@ -1,71 +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 void updateMessage(const QString &message);
15
15public: 16public:
16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false); 17 Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
17 virtual ~Interface(){}; 18 virtual ~Interface(){};
18 19
19 virtual QString getInterfaceName(){ QString n(this->name()); return n; }; 20 virtual QString getInterfaceName(){ QString n(this->name()); return n; };
20 21
21 virtual bool getStatus(){ return status; }; 22 virtual bool getStatus(){ return status; };
22 virtual void setStatus(bool newStatus); 23 virtual void setStatus(bool newStatus);
23 24
24 virtual bool isAttached(){ return attached; }; 25 virtual bool isAttached(){ return attached; };
25 virtual void setAttached(bool isAttached=false); 26 virtual void setAttached(bool isAttached=false);
26 27
27 virtual QString getHardwareName(){ return hardwareName; }; 28 virtual QString getHardwareName(){ return hardwareName; };
28 virtual void setHardwareName(QString name="Unknown"); 29 virtual void setHardwareName(QString name="Unknown");
29 30
30 virtual Module* getModuleOwner(){ return moduleOwner; }; 31 virtual Module* getModuleOwner(){ return moduleOwner; };
31 virtual void setModuleOwner(Module *owner=NULL); 32 virtual void setModuleOwner(Module *owner=NULL);
32 33
33 // inet information. 34 // inet information.
34 QString getMacAddress(){ return macAddress; }; 35 QString getMacAddress(){ return macAddress; };
35 QString getIp(){ return ip; }; 36 QString getIp(){ return ip; };
36 QString getSubnetMask(){ return subnetMask; }; 37 QString getSubnetMask(){ return subnetMask; };
37 QString getBroadcast(){ return broadcast; }; 38 QString getBroadcast(){ return broadcast; };
38 bool isDhcp(){ return dhcp; }; 39 bool isDhcp(){ return dhcp; };
39 QString getDhcpServerIp(){ return dhcpServerIp; }; 40 QString getDhcpServerIp(){ return dhcpServerIp; };
40 QString getLeaseObtained(){ return leaseObtained; }; 41 QString getLeaseObtained(){ return leaseObtained; };
41 QString getLeaseExpires(){ return leaseExpires; }; 42 QString getLeaseExpires(){ return leaseExpires; };
42 43
43public slots: 44public slots:
44 bool refresh(); 45 bool refresh();
45 void start(); 46 void start();
46 void stop(); 47 void stop();
47 void restart(); 48 void restart();
48 49
49private: 50private:
50 // Interface information 51 // Interface information
51 bool status; 52 bool status;
52 bool attached; 53 bool attached;
53 QString hardwareName; 54 QString hardwareName;
54 Module *moduleOwner; 55 Module *moduleOwner;
55 56
56 // Network information 57 // Network information
57 QString macAddress; 58 QString macAddress;
58 QString ip; 59 QString ip;
59 QString broadcast; 60 QString broadcast;
60 QString subnetMask; 61 QString subnetMask;
61 bool dhcp; 62 bool dhcp;
62 QString dhcpServerIp; 63 QString dhcpServerIp;
63 QString leaseObtained; 64 QString leaseObtained;
64 QString leaseExpires; 65 QString leaseExpires;
65 66
66}; 67};
67 68
68#endif 69#endif
69 70
70// interface.h 71// interface.h
71 72
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp
index 43483fb..39575c4 100644
--- a/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp
@@ -1,70 +1,81 @@
1#include "interfaceinformationimp.h" 1#include "interfaceinformationimp.h"
2#include "interfaceadvanced.h" 2#include "interfaceadvanced.h"
3 3
4#include <qpushbutton.h> 4#include <qpushbutton.h>
5#include <qlabel.h> 5#include <qlabel.h>
6#include <qgroupbox.h> 6#include <qgroupbox.h>
7#include <qmessagebox.h>
8
7#include <assert.h> 9#include <assert.h>
8 10
9/** 11/**
10 * Constructor for the InterfaceInformationImp class. This class pretty much 12 * Constructor for the InterfaceInformationImp class. This class pretty much
11 * just display's information about the interface that is passed to it. 13 * just display's information about the interface that is passed to it.
12 */ 14 */
13InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ 15InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){
14 assert(i); 16 assert(i);
15 17
16 interface = i; 18 interface = i;
17 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 19 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
20 connect(i, SIGNAL(updateMessage(const QString &)), this, SLOT(showMessage(const QString &)));
18 updateInterface(interface); 21 updateInterface(interface);
19 connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); 22 connect(startButton, SIGNAL(clicked()), interface, SLOT(start()));
20 connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); 23 connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop()));
21 connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); 24 connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart()));
22 connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); 25 connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh()));
23 connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); 26 connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced()));
24
25} 27}
26 28
27/** 29/**
28 * Update the interface information and buttons. 30 * Update the interface information and buttons.
29 * @param Intarface *i the interface to update (should be the one we already 31 * @param Intarface *i the interface to update (should be the one we already
30 * know about). 32 * know about).
31 */ 33 */
32void InterfaceInformationImp::updateInterface(Interface *i){ 34void InterfaceInformationImp::updateInterface(Interface *i){
33 if(interface->getStatus()){ 35 if(interface->getStatus()){
34 startButton->setEnabled(false); 36 startButton->setEnabled(false);
35 stopButton->setEnabled(true); 37 stopButton->setEnabled(true);
36 restartButton->setEnabled(true); 38 restartButton->setEnabled(true);
37 } 39 }
38 else{ 40 else{
39 startButton->setEnabled(true); 41 startButton->setEnabled(true);
40 stopButton->setEnabled(false); 42 stopButton->setEnabled(false);
41 restartButton->setEnabled(false); 43 restartButton->setEnabled(false);
42 } 44 }
43 macAddressLabel->setText(interface->getMacAddress()); 45 macAddressLabel->setText(interface->getMacAddress());
44 ipAddressLabel->setText(interface->getIp()); 46 ipAddressLabel->setText(interface->getIp());
45 subnetMaskLabel->setText(interface->getSubnetMask()); 47 subnetMaskLabel->setText(interface->getSubnetMask());
46 broadcastLabel->setText(interface->getBroadcast()); 48 broadcastLabel->setText(interface->getBroadcast());
47} 49}
48 50
49/** 51/**
50 * Create the advanced widget. Fill it with the current interface's information. 52 * Create the advanced widget. Fill it with the current interface's information.
51 * Display it. 53 * Display it.
52 */ 54 */
53void InterfaceInformationImp::advanced(){ 55void InterfaceInformationImp::advanced(){
54 InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); 56 InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced");
55 a->interfaceName->setText(interface->getInterfaceName()); 57 a->interfaceName->setText(interface->getInterfaceName());
56 a->macAddressLabel->setText(interface->getMacAddress()); 58 a->macAddressLabel->setText(interface->getMacAddress());
57 a->ipAddressLabel->setText(interface->getIp()); 59 a->ipAddressLabel->setText(interface->getIp());
58 a->subnetMaskLabel->setText(interface->getSubnetMask()); 60 a->subnetMaskLabel->setText(interface->getSubnetMask());
59 a->broadcastLabel->setText(interface->getBroadcast()); 61 a->broadcastLabel->setText(interface->getBroadcast());
60 a->dhcpServerLabel->setText(interface->getDhcpServerIp()); 62 a->dhcpServerLabel->setText(interface->getDhcpServerIp());
61 a->leaseObtainedLabel->setText(interface->getLeaseObtained()); 63 a->leaseObtainedLabel->setText(interface->getLeaseObtained());
62 a->leaseExpiresLabel->setText(interface->getLeaseExpires()); 64 a->leaseExpiresLabel->setText(interface->getLeaseExpires());
63 a->dhcpInformation->setEnabled(interface->isDhcp()); 65 a->dhcpInformation->setEnabled(interface->isDhcp());
64 66
65 a->showMaximized(); 67 a->showMaximized();
66 a->show(); 68 a->show();
67} 69}
68 70
71/**
72 * Messages from the interface if start/stop went as planned.
73 * Purly for user feedback.
74 * @param message the message to display.
75 */
76void InterfaceInformationImp::showMessage(const QString &message){
77 QMessageBox::information(this, "Message", message, QMessageBox::Ok);
78}
79
69// infoimp.cpp 80// infoimp.cpp
70 81
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformationimp.h b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h
index 42213cc..65cdfe0 100644
--- a/noncore/settings/networksettings/interfaces/interfaceinformationimp.h
+++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h
@@ -1,27 +1,28 @@
1#ifndef INTERFACEINFORMATIONIMP_H 1#ifndef INTERFACEINFORMATIONIMP_H
2#define INTERFACEINFORMATIONIMP_H 2#define INTERFACEINFORMATIONIMP_H
3 3
4#include "interfaceinformation.h" 4#include "interfaceinformation.h"
5#include "interface.h" 5#include "interface.h"
6 6
7class InterfaceInformationImp : public InterfaceInformation { 7class InterfaceInformationImp : public InterfaceInformation {
8 8
9Q_OBJECT 9Q_OBJECT
10 10
11public: 11public:
12 InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); 12 InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0);
13 ~InterfaceInformationImp(){}; 13 ~InterfaceInformationImp(){};
14 14
15private slots: 15private slots:
16 void advanced(); 16 void advanced();
17 void updateInterface(Interface *i); 17 void updateInterface(Interface *i);
18 void showMessage(const QString &message);
18 19
19private: 20private:
20 Interface *interface; 21 Interface *interface;
21 22
22}; 23};
23 24
24#endif 25#endif
25 26
26// addserviceimp.h 27// addserviceimp.h
27 28
diff --git a/noncore/settings/networksettings/interfaces/interfaces.pro b/noncore/settings/networksettings/interfaces/interfaces.pro
index 9a024f6..d6b43fb 100644
--- a/noncore/settings/networksettings/interfaces/interfaces.pro
+++ b/noncore/settings/networksettings/interfaces/interfaces.pro
@@ -1,12 +1,12 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug 3 #CONFIG += qt warn_on debug
4 DESTDIR = $(QTDIR)/lib$(PROJMAK) 4 #DESTDIR = $(QTDIR)/lib$(PROJMAK)
5 HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h 5 HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h
6 SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp 6 SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp
7 INCLUDEPATH+= $(OPIEDIR)/include ../ 7 INCLUDEPATH+= $(OPIEDIR)/include ../
8 DEPENDPATH+= $(OPIEDIR)/include 8 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe 9LIBS += -lqpe
10 INTERFACES= interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui 10 INTERFACES= interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui
11 TARGET = interfaces 11 TARGET = interfaces
12 VERSION = 1.0.0 12 VERSION = 1.0.0