-rw-r--r-- | noncore/net/networksetup/TODO | 2 | ||||
-rw-r--r-- | noncore/net/networksetup/interface.cpp | 77 | ||||
-rw-r--r-- | noncore/net/networksetup/interface.h | 31 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaceadvanced.ui | 11 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaceinformationimp.cpp | 51 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaceinformationimp.h | 6 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 43 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanmodule.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/TODO | 2 | ||||
-rw-r--r-- | noncore/settings/networksettings/interface.cpp | 77 | ||||
-rw-r--r-- | noncore/settings/networksettings/interface.h | 31 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaceadvanced.ui | 11 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaceinformationimp.cpp | 51 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaceinformationimp.h | 6 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 43 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanmodule.cpp | 4 |
16 files changed, 258 insertions, 192 deletions
diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO index 7386646..c8e2989 100644 --- a/noncore/net/networksetup/TODO +++ b/noncore/net/networksetup/TODO | |||
@@ -1,8 +1,10 @@ | |||
1 | Write a class that parses /proc and not ifconfig | ||
2 | |||
1 | [ ] Wlanmodule needs to check if an interface supports wireless | 3 | [ ] Wlanmodule needs to check if an interface supports wireless |
2 | extensions. | 4 | extensions. |
3 | [x] When you set options in wlanmodule, hit OK, it exits all of | 5 | [x] When you set options in wlanmodule, hit OK, it exits all of |
4 | networksetup, doesnt bring you back to the main screen. | 6 | networksetup, doesnt bring you back to the main screen. |
5 | [x] Wlanmodule isnt writing out wireless.opts | 7 | [x] Wlanmodule isnt writing out wireless.opts |
6 | [ ] Need a means of bringing an interface up and down (calling | 8 | [ ] Need a means of bringing an interface up and down (calling |
7 | out ifup/ifdown) from the gui. | 9 | out ifup/ifdown) from the gui. |
8 | -Ben- Click information, then click up or down... :-D | 10 | -Ben- Click information, then click up or down... :-D |
diff --git a/noncore/net/networksetup/interface.cpp b/noncore/net/networksetup/interface.cpp index 1f32093..1e01da4 100644 --- a/noncore/net/networksetup/interface.cpp +++ b/noncore/net/networksetup/interface.cpp | |||
@@ -1,172 +1,215 @@ | |||
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 | ||
14 | Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ | 14 | Interface::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){ |
15 | refresh(); | 15 | refresh(); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Set status | ||
20 | * @param newStatus - the new status | ||
21 | * emit updateInterface | ||
22 | */ | ||
23 | void Interface::setStatus(bool newStatus){ | ||
24 | if(status != newStatus){ | ||
25 | status = newStatus; | ||
26 | refresh(); | ||
27 | } | ||
28 | }; | ||
29 | |||
30 | /** | ||
31 | * Set if attached or not (802.11 card pulled out for example) | ||
32 | * @param isAttached - if attached | ||
33 | * emit updateInterface | ||
34 | */ | ||
35 | void Interface::setAttached(bool isAttached){ | ||
36 | attached = isAttached; | ||
37 | emit(updateInterface(this)); | ||
38 | }; | ||
39 | |||
40 | /** | ||
41 | * Set Hardware name | ||
42 | * @param name - the new name | ||
43 | * emit updateInterface | ||
44 | */ | ||
45 | void Interface::setHardwareName(QString name){ | ||
46 | hardareName = name; | ||
47 | emit(updateInterface(this)); | ||
48 | }; | ||
49 | |||
50 | /** | ||
51 | * Set Module owner | ||
52 | * @param owner - the new owner | ||
53 | * emit updateInterface | ||
54 | */ | ||
55 | void Interface::setModuleOwner(Module *owner){ | ||
56 | moduleOwner = owner; | ||
57 | emit(updateInterface(this)); | ||
58 | }; | ||
59 | |||
60 | |||
61 | /** | ||
19 | * Try to start the interface. | 62 | * Try to start the interface. |
20 | * @return bool true if successfull. | ||
21 | */ | 63 | */ |
22 | bool Interface::start(){ | 64 | void Interface::start(){ |
23 | // check to see if we are already running. | 65 | // check to see if we are already running. |
24 | if(status) | 66 | if(true == status) |
25 | return false; | 67 | return; |
26 | 68 | ||
27 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); | 69 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); |
70 | // See if it was successfull... | ||
28 | if(ret != 0) | 71 | if(ret != 0) |
29 | return false; | 72 | return; |
30 | 73 | ||
31 | status = true; | 74 | status = true; |
32 | refresh(); | 75 | refresh(); |
33 | return true; | ||
34 | } | 76 | } |
35 | 77 | ||
36 | /** | 78 | /** |
37 | * Try to stop the interface. | 79 | * Try to stop the interface. |
38 | * @return bool true if successfull. | ||
39 | */ | 80 | */ |
40 | bool Interface::stop(){ | 81 | void Interface::stop(){ |
41 | // check to see if we are already stopped. | 82 | // check to see if we are already stopped. |
42 | if(status == false) | 83 | if(false == status) |
43 | return false; | 84 | return; |
44 | 85 | ||
45 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); | 86 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); |
46 | if(ret != 0) | 87 | if(ret != 0) |
47 | return false; | 88 | return; |
48 | 89 | ||
49 | status = true; | 90 | status = true; |
50 | refresh(); | 91 | refresh(); |
51 | return true; | ||
52 | } | 92 | } |
93 | |||
53 | /** | 94 | /** |
54 | * Try to restart the interface. | 95 | * Try to restart the interface. |
55 | * @return bool true if successfull. | ||
56 | */ | 96 | */ |
57 | bool Interface::restart(){ | 97 | void Interface::restart(){ |
58 | return (stop() && start()); | 98 | stop(); |
99 | start(); | ||
59 | } | 100 | } |
60 | 101 | ||
61 | /** | 102 | /** |
62 | * Try to refresh the information about the interface. | 103 | * Try to refresh the information about the interface. |
63 | * First call ifconfig, then check the dhcp-info file | 104 | * First call ifconfig, then check the dhcp-info file |
64 | * @return bool true if successfull. | 105 | * @return bool true if successfull. |
65 | */ | 106 | */ |
66 | bool Interface::refresh(){ | 107 | bool Interface::refresh(){ |
67 | // See if we are up. | 108 | // See if we are up. |
68 | if(status == false){ | 109 | if(status == false){ |
69 | macAddress = ""; | 110 | macAddress = ""; |
70 | ip = "0.0.0.0"; | 111 | ip = "0.0.0.0"; |
71 | subnetMask = "0.0.0.0"; | 112 | subnetMask = "0.0.0.0"; |
72 | broadcast = ""; | 113 | broadcast = ""; |
73 | dhcp = false; | 114 | dhcp = false; |
74 | dhcpServerIp = ""; | 115 | dhcpServerIp = ""; |
75 | leaseObtained = ""; | 116 | leaseObtained = ""; |
76 | leaseExpires = ""; | 117 | leaseExpires = ""; |
118 | emit(updateInterface(this)); | ||
77 | return true; | 119 | return true; |
78 | } | 120 | } |
79 | 121 | ||
80 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); | 122 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); |
81 | 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(interfaceName).arg(fileName).latin1()); |
82 | if(ret != 0){ | 124 | if(ret != 0){ |
83 | 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()); |
84 | return false; | 126 | return false; |
85 | } | 127 | } |
86 | 128 | ||
87 | QFile file(fileName); | 129 | QFile file(fileName); |
88 | if (!file.open(IO_ReadOnly)){ | 130 | if (!file.open(IO_ReadOnly)){ |
89 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 131 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
90 | return false; | 132 | return false; |
91 | } | 133 | } |
92 | 134 | ||
93 | // Set to the defaults | 135 | // Set to the defaults |
94 | macAddress = ""; | 136 | macAddress = ""; |
95 | ip = "0.0.0.0"; | 137 | ip = "0.0.0.0"; |
96 | subnetMask = "0.0.0.0"; | 138 | subnetMask = "0.0.0.0"; |
97 | broadcast = ""; | 139 | broadcast = ""; |
98 | 140 | ||
99 | QTextStream stream( &file ); | 141 | QTextStream stream( &file ); |
100 | QString line; | 142 | QString line; |
101 | while ( !stream.eof() ) { | 143 | while ( !stream.eof() ) { |
102 | line = stream.readLine(); | 144 | line = stream.readLine(); |
103 | if(line.contains("HWaddr")){ | 145 | if(line.contains("HWaddr")){ |
104 | int mac = line.find("HWaddr"); | 146 | int mac = line.find("HWaddr"); |
105 | macAddress = line.mid(mac+7, line.length()); | 147 | macAddress = line.mid(mac+7, line.length()); |
106 | } | 148 | } |
107 | if(line.contains("inet addr")){ | 149 | if(line.contains("inet addr")){ |
108 | int ipl = line.find("inet addr"); | 150 | int ipl = line.find("inet addr"); |
109 | int space = line.find(" ", ipl+10); | 151 | int space = line.find(" ", ipl+10); |
110 | ip = line.mid(ipl+10, space-ipl-10); | 152 | ip = line.mid(ipl+10, space-ipl-10); |
111 | } | 153 | } |
112 | if(line.contains("Mask")){ | 154 | if(line.contains("Mask")){ |
113 | int mask = line.find("Mask"); | 155 | int mask = line.find("Mask"); |
114 | subnetMask = line.mid(mask+5, line.length()); | 156 | subnetMask = line.mid(mask+5, line.length()); |
115 | } | 157 | } |
116 | if(line.contains("Bcast")){ | 158 | if(line.contains("Bcast")){ |
117 | int mask = line.find("Bcast"); | 159 | int mask = line.find("Bcast"); |
118 | int space = line.find(" ", mask+6); | 160 | int space = line.find(" ", mask+6); |
119 | broadcast = line.mid(mask+6, space-mask-6); | 161 | broadcast = line.mid(mask+6, space-mask-6); |
120 | } | 162 | } |
121 | } | 163 | } |
122 | file.close(); | 164 | file.close(); |
123 | QFile::remove(fileName); | 165 | QFile::remove(fileName); |
124 | 166 | ||
125 | // DHCP TESTING | 167 | // DHCP TESTING |
126 | // reset DHCP info | 168 | // reset DHCP info |
127 | dhcpServerIp = ""; | 169 | dhcpServerIp = ""; |
128 | leaseObtained = ""; | 170 | leaseObtained = ""; |
129 | leaseExpires = ""; | 171 | leaseExpires = ""; |
130 | dhcp = false; | 172 | dhcp = false; |
131 | 173 | ||
132 | QString dhcpDirectory(HDCP_INFO_DIR); | 174 | QString dhcpDirectory(HDCP_INFO_DIR); |
133 | QDir d(dhcpDirectory); | 175 | QDir d(dhcpDirectory); |
134 | if(!d.exists(dhcpDirectory)) | 176 | if(!d.exists(dhcpDirectory)) |
135 | dhcpDirectory = "/var/run"; | 177 | dhcpDirectory = "/var/run"; |
136 | 178 | ||
137 | // See if we have | 179 | // See if we have |
138 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); | 180 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); |
139 | // 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. |
140 | if(!QFile::exists(dhcpFile)){ | 182 | if(!QFile::exists(dhcpFile)){ |
183 | emit(updateInterface(this)); | ||
141 | return true; | 184 | return true; |
142 | } | 185 | } |
143 | 186 | ||
144 | file.setName(dhcpFile); | 187 | file.setName(dhcpFile); |
145 | if (!file.open(IO_ReadOnly)){ | 188 | if (!file.open(IO_ReadOnly)){ |
146 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 189 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
147 | return false; | 190 | return false; |
148 | } | 191 | } |
149 | 192 | ||
150 | // 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. |
151 | int leaseTime = 0; | 194 | int leaseTime = 0; |
152 | int renewalTime = 0; | 195 | int renewalTime = 0; |
153 | 196 | ||
154 | stream.setDevice( &file ); | 197 | stream.setDevice( &file ); |
155 | while ( !stream.eof() ) { | 198 | while ( !stream.eof() ) { |
156 | line = stream.readLine(); | 199 | line = stream.readLine(); |
157 | if(line.contains("DHCPSIADDR=")) | 200 | if(line.contains("DHCPSIADDR=")) |
158 | dhcpServerIp = line.mid(11, line.length()); | 201 | dhcpServerIp = line.mid(11, line.length()); |
159 | if(line.contains("LEASETIME=")) | 202 | if(line.contains("LEASETIME=")) |
160 | leaseTime = line.mid(10, line.length()).toInt(); | 203 | leaseTime = line.mid(10, line.length()).toInt(); |
161 | if(line.contains("RENEWALTIME=")) | 204 | if(line.contains("RENEWALTIME=")) |
162 | renewalTime = line.mid(12, line.length()).toInt(); | 205 | renewalTime = line.mid(12, line.length()).toInt(); |
163 | } | 206 | } |
164 | file.close(); | 207 | file.close(); |
165 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | 208 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); |
166 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | 209 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); |
167 | 210 | ||
168 | // Get the pid of the deamond | 211 | // Get the pid of the deamond |
169 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); | 212 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); |
170 | file.setName(dhcpFile); | 213 | file.setName(dhcpFile); |
171 | if (!file.open(IO_ReadOnly)){ | 214 | if (!file.open(IO_ReadOnly)){ |
172 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 215 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
@@ -206,37 +249,39 @@ bool Interface::refresh(){ | |||
206 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | 249 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " |
207 | // nice 0 itrealvalue starttime | 250 | // nice 0 itrealvalue starttime |
208 | "%*d %*d %*d %lu", (long*) &time); | 251 | "%*d %*d %*d %lu", (long*) &time); |
209 | time = time/100; | 252 | time = time/100; |
210 | 253 | ||
211 | QDateTime datetime(QDateTime::currentDateTime()); | 254 | QDateTime datetime(QDateTime::currentDateTime()); |
212 | 255 | ||
213 | // Get the uptime of the computer. | 256 | // Get the uptime of the computer. |
214 | QFile f("/proc/uptime"); | 257 | QFile f("/proc/uptime"); |
215 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 258 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
216 | QTextStream t( &f ); // use a text stream | 259 | QTextStream t( &f ); // use a text stream |
217 | int sec = 0; | 260 | int sec = 0; |
218 | t >> sec; | 261 | t >> sec; |
219 | datetime = datetime.addSecs((-1*sec)); | 262 | datetime = datetime.addSecs((-1*sec)); |
220 | f.close(); | 263 | f.close(); |
221 | } | 264 | } |
222 | else{ | 265 | else{ |
223 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | 266 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); |
224 | return false; | 267 | return false; |
225 | } | 268 | } |
226 | 269 | ||
227 | datetime = datetime.addSecs(time); | 270 | datetime = datetime.addSecs(time); |
228 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | 271 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); |
229 | 272 | ||
230 | // Calculate the start and renew times | 273 | // Calculate the start and renew times |
231 | leaseObtained= datetime.toString(); | 274 | leaseObtained= datetime.toString(); |
232 | 275 | ||
233 | // Calculate the start and renew times | 276 | // Calculate the start and renew times |
234 | datetime = datetime.addSecs(leaseTime); | 277 | datetime = datetime.addSecs(leaseTime); |
235 | leaseExpires = datetime.toString(); | 278 | leaseExpires = datetime.toString(); |
236 | 279 | ||
237 | dhcp = true; | 280 | dhcp = true; |
281 | |||
282 | emit(updateInterface(this)); | ||
238 | return true; | 283 | return true; |
239 | } | 284 | } |
240 | 285 | ||
241 | // interface.cpp | 286 | // interface.cpp |
242 | 287 | ||
diff --git a/noncore/net/networksetup/interface.h b/noncore/net/networksetup/interface.h index 1406e99..980171a 100644 --- a/noncore/net/networksetup/interface.h +++ b/noncore/net/networksetup/interface.h | |||
@@ -1,67 +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 | 6 | ||
6 | class Module; | 7 | class Module; |
7 | 8 | ||
8 | class Interface { | 9 | class Interface : public QObject{ |
10 | Q_OBJECT | ||
9 | 11 | ||
12 | signals: | ||
13 | void updateInterface(Interface *i); | ||
14 | |||
10 | public: | 15 | public: |
11 | Interface(QString name = "unknown", bool status = false); | 16 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); |
12 | virtual ~Interface(){}; | 17 | virtual ~Interface(){}; |
13 | 18 | ||
19 | virtual QString getInterfaceName(){ QString n(this->name()); return n; }; | ||
20 | |||
14 | virtual bool getStatus(){ return status; }; | 21 | virtual bool getStatus(){ return status; }; |
15 | virtual void setStatus(bool newSatus){ status = newSatus; refresh(); }; | 22 | virtual void setStatus(bool newStatus); |
16 | 23 | ||
17 | virtual bool isAttached(){ return attached; }; | 24 | virtual bool isAttached(){ return attached; }; |
18 | virtual void setAttached(bool isAttached=false){ attached = isAttached; }; | 25 | virtual void setAttached(bool isAttached=false); |
19 | |||
20 | virtual QString getInterfaceName(){ return interfaceName; }; | ||
21 | virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; }; | ||
22 | 26 | ||
23 | virtual QString getHardwareName(){ return hardareName; }; | 27 | virtual QString getHardwareName(){ return hardareName; }; |
24 | virtual void setHardwareName(QString name="Unknown"){ hardareName = name; }; | 28 | virtual void setHardwareName(QString name="Unknown"); |
25 | 29 | ||
26 | virtual Module* getModuleOwner(){ return moduleOwner; }; | 30 | virtual Module* getModuleOwner(){ return moduleOwner; }; |
27 | virtual void setModuleOwner(Module *owner=NULL){ moduleOwner = owner; }; | 31 | virtual void setModuleOwner(Module *owner=NULL); |
28 | 32 | ||
29 | // inet information. | 33 | // inet information. |
30 | QString getMacAddress(){ return macAddress; }; | 34 | QString getMacAddress(){ return macAddress; }; |
31 | QString getIp(){ return ip; }; | 35 | QString getIp(){ return ip; }; |
32 | QString getSubnetMask(){ return subnetMask; }; | 36 | QString getSubnetMask(){ return subnetMask; }; |
33 | QString getBroadcast(){ return broadcast; }; | 37 | QString getBroadcast(){ return broadcast; }; |
34 | bool isDhcp(){ return dhcp; }; | 38 | bool isDhcp(){ return dhcp; }; |
35 | QString getDhcpServerIp(){ return dhcpServerIp; }; | 39 | QString getDhcpServerIp(){ return dhcpServerIp; }; |
36 | QString getLeaseObtained(){ return leaseObtained; }; | 40 | QString getLeaseObtained(){ return leaseObtained; }; |
37 | QString getLeaseExpires(){ return leaseExpires; }; | 41 | QString getLeaseExpires(){ return leaseExpires; }; |
38 | 42 | ||
43 | public slots: | ||
39 | bool refresh(); | 44 | bool refresh(); |
40 | bool start(); | 45 | void start(); |
41 | bool stop(); | 46 | void stop(); |
42 | bool restart(); | 47 | void restart(); |
43 | 48 | ||
44 | private: | 49 | private: |
45 | // Interface information | 50 | // Interface information |
46 | bool status; | 51 | bool status; |
47 | bool attached; | 52 | bool attached; |
48 | QString interfaceName; | 53 | QString interfaceName; |
49 | QString hardareName; | 54 | QString hardareName; |
50 | Module *moduleOwner; | 55 | Module *moduleOwner; |
51 | 56 | ||
52 | // Network information | 57 | // Network information |
53 | QString macAddress; | 58 | QString macAddress; |
54 | QString ip; | 59 | QString ip; |
55 | QString broadcast; | 60 | QString broadcast; |
56 | QString subnetMask; | 61 | QString subnetMask; |
57 | bool dhcp; | 62 | bool dhcp; |
58 | QString dhcpServerIp; | 63 | QString dhcpServerIp; |
59 | QString leaseObtained; | 64 | QString leaseObtained; |
60 | QString leaseExpires; | 65 | QString leaseExpires; |
61 | 66 | ||
62 | }; | 67 | }; |
63 | 68 | ||
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | // interface.h | 71 | // interface.h |
67 | 72 | ||
diff --git a/noncore/net/networksetup/interfaceadvanced.ui b/noncore/net/networksetup/interfaceadvanced.ui index 7520abe..efe67b0 100644 --- a/noncore/net/networksetup/interfaceadvanced.ui +++ b/noncore/net/networksetup/interfaceadvanced.ui | |||
@@ -1,50 +1,57 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceAdvanced</class> | 2 | <class>InterfaceAdvanced</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceAdvanced</cstring> | 7 | <cstring>InterfaceAdvanced</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>188</width> | 14 | <width>214</width> |
15 | <height>277</height> | 15 | <height>286</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>maximumSize</name> | ||
20 | <size> | ||
21 | <width>320</width> | ||
22 | <height>32767</height> | ||
23 | </size> | ||
24 | </property> | ||
25 | <property stdset="1"> | ||
19 | <name>caption</name> | 26 | <name>caption</name> |
20 | <string>Advanced Interface Information</string> | 27 | <string>Advanced Interface Information</string> |
21 | </property> | 28 | </property> |
22 | <grid> | 29 | <grid> |
23 | <property stdset="1"> | 30 | <property stdset="1"> |
24 | <name>margin</name> | 31 | <name>margin</name> |
25 | <number>11</number> | 32 | <number>11</number> |
26 | </property> | 33 | </property> |
27 | <property stdset="1"> | 34 | <property stdset="1"> |
28 | <name>spacing</name> | 35 | <name>spacing</name> |
29 | <number>6</number> | 36 | <number>6</number> |
30 | </property> | 37 | </property> |
31 | <widget row="1" column="0" > | 38 | <widget row="1" column="0" > |
32 | <class>QLabel</class> | 39 | <class>QLabel</class> |
33 | <property stdset="1"> | 40 | <property stdset="1"> |
34 | <name>name</name> | 41 | <name>name</name> |
35 | <cstring>TextLabel1</cstring> | 42 | <cstring>TextLabel1</cstring> |
36 | </property> | 43 | </property> |
37 | <property stdset="1"> | 44 | <property stdset="1"> |
38 | <name>text</name> | 45 | <name>text</name> |
39 | <string>MAC Address</string> | 46 | <string>MAC Address</string> |
40 | </property> | 47 | </property> |
41 | </widget> | 48 | </widget> |
42 | <widget row="0" column="1" > | 49 | <widget row="0" column="1" > |
43 | <class>QLabel</class> | 50 | <class>QLabel</class> |
44 | <property stdset="1"> | 51 | <property stdset="1"> |
45 | <name>name</name> | 52 | <name>name</name> |
46 | <cstring>interfaceName</cstring> | 53 | <cstring>interfaceName</cstring> |
47 | </property> | 54 | </property> |
48 | <property stdset="1"> | 55 | <property stdset="1"> |
49 | <name>frameShape</name> | 56 | <name>frameShape</name> |
50 | <enum>Panel</enum> | 57 | <enum>Panel</enum> |
diff --git a/noncore/net/networksetup/interfaceinformationimp.cpp b/noncore/net/networksetup/interfaceinformationimp.cpp index e37e0f8..59a6400 100644 --- a/noncore/net/networksetup/interfaceinformationimp.cpp +++ b/noncore/net/networksetup/interfaceinformationimp.cpp | |||
@@ -1,94 +1,67 @@ | |||
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 <assert.h> | 6 | #include <assert.h> |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Constructor for the InterfaceInformationImp class. This class pretty much | 9 | * Constructor for the InterfaceInformationImp class. This class pretty much |
10 | * just display's information about the interface that is passed to it. | 10 | * just display's information about the interface that is passed to it. |
11 | */ | 11 | */ |
12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ | 12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ |
13 | assert(i); | 13 | assert(i); |
14 | 14 | ||
15 | interface = i; | 15 | interface = i; |
16 | updateInterface(); | 16 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
17 | connect(startButton, SIGNAL(clicked()), this, SLOT(start())); | 17 | updateInterface(interface); |
18 | connect(stopButton, SIGNAL(clicked()), this, SLOT(stop())); | 18 | connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); |
19 | connect(restartButton, SIGNAL(clicked()), this, SLOT(restart())); | 19 | connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); |
20 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); | 20 | connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); |
21 | connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); | ||
21 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); | 22 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); |
22 | 23 | ||
23 | } | 24 | } |
24 | 25 | ||
25 | void InterfaceInformationImp::updateInterface(){ | 26 | /** |
27 | * Update the interface information and buttons. | ||
28 | * @param Intarface *i the interface to update (should be the one we already | ||
29 | * know about). | ||
30 | */ | ||
31 | void InterfaceInformationImp::updateInterface(Interface *i){ | ||
26 | if(interface->getStatus()){ | 32 | if(interface->getStatus()){ |
27 | startButton->setEnabled(false); | 33 | startButton->setEnabled(false); |
28 | stopButton->setEnabled(true); | 34 | stopButton->setEnabled(true); |
29 | restartButton->setEnabled(true); | 35 | restartButton->setEnabled(true); |
30 | } | 36 | } |
31 | else{ | 37 | else{ |
32 | startButton->setEnabled(true); | 38 | startButton->setEnabled(true); |
33 | stopButton->setEnabled(false); | 39 | stopButton->setEnabled(false); |
34 | restartButton->setEnabled(false); | 40 | restartButton->setEnabled(false); |
35 | } | 41 | } |
36 | macAddressLabel->setText(interface->getMacAddress()); | 42 | macAddressLabel->setText(interface->getMacAddress()); |
37 | ipAddressLabel->setText(interface->getIp()); | 43 | ipAddressLabel->setText(interface->getIp()); |
38 | subnetMaskLabel->setText(interface->getSubnetMask()); | 44 | subnetMaskLabel->setText(interface->getSubnetMask()); |
39 | broadcastLabel->setText(interface->getBroadcast()); | 45 | broadcastLabel->setText(interface->getBroadcast()); |
40 | } | 46 | } |
41 | 47 | ||
42 | /** | 48 | /** |
43 | * Start the interface. Update the information if successfull | ||
44 | */ | ||
45 | void InterfaceInformationImp::start(){ | ||
46 | if(interface->start()){ | ||
47 | updateInterface(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Stop the interface. | ||
53 | */ | ||
54 | void InterfaceInformationImp::stop(){ | ||
55 | if(interface->stop()){ | ||
56 | updateInterface(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /*** | ||
61 | * Tell the interface to refresh its information. | ||
62 | **/ | ||
63 | void InterfaceInformationImp::refresh(){ | ||
64 | if(interface->refresh()) | ||
65 | updateInterface(); | ||
66 | } | ||
67 | |||
68 | void InterfaceInformationImp::restart(){ | ||
69 | if(interface->restart()){ | ||
70 | updateInterface(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Create the advanced widget. Fill it with the current interface's information. | 49 | * Create the advanced widget. Fill it with the current interface's information. |
77 | * Display it. | 50 | * Display it. |
78 | */ | 51 | */ |
79 | void InterfaceInformationImp::advanced(){ | 52 | void InterfaceInformationImp::advanced(){ |
80 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); | 53 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); |
81 | a->interfaceName->setText(interface->getInterfaceName()); | 54 | a->interfaceName->setText(interface->getInterfaceName()); |
82 | a->macAddressLabel->setText(interface->getMacAddress()); | 55 | a->macAddressLabel->setText(interface->getMacAddress()); |
83 | a->ipAddressLabel->setText(interface->getIp()); | 56 | a->ipAddressLabel->setText(interface->getIp()); |
84 | a->subnetMaskLabel->setText(interface->getSubnetMask()); | 57 | a->subnetMaskLabel->setText(interface->getSubnetMask()); |
85 | a->broadcastLabel->setText(interface->getBroadcast()); | 58 | a->broadcastLabel->setText(interface->getBroadcast()); |
86 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); | 59 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); |
87 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); | 60 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); |
88 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); | 61 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); |
89 | a->showMaximized(); | 62 | a->showMaximized(); |
90 | a->show(); | 63 | a->show(); |
91 | } | 64 | } |
92 | 65 | ||
93 | // infoimp.cpp | 66 | // infoimp.cpp |
94 | 67 | ||
diff --git a/noncore/net/networksetup/interfaceinformationimp.h b/noncore/net/networksetup/interfaceinformationimp.h index c8a478e..42213cc 100644 --- a/noncore/net/networksetup/interfaceinformationimp.h +++ b/noncore/net/networksetup/interfaceinformationimp.h | |||
@@ -1,31 +1,27 @@ | |||
1 | #ifndef INTERFACEINFORMATIONIMP_H | 1 | #ifndef INTERFACEINFORMATIONIMP_H |
2 | #define INTERFACEINFORMATIONIMP_H | 2 | #define INTERFACEINFORMATIONIMP_H |
3 | 3 | ||
4 | #include "interfaceinformation.h" | 4 | #include "interfaceinformation.h" |
5 | #include "interface.h" | 5 | #include "interface.h" |
6 | 6 | ||
7 | class InterfaceInformationImp : public InterfaceInformation { | 7 | class InterfaceInformationImp : public InterfaceInformation { |
8 | 8 | ||
9 | Q_OBJECT | 9 | Q_OBJECT |
10 | 10 | ||
11 | public: | 11 | public: |
12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); | 12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); |
13 | ~InterfaceInformationImp(){}; | 13 | ~InterfaceInformationImp(){}; |
14 | 14 | ||
15 | private slots: | 15 | private slots: |
16 | void start(); | ||
17 | void stop(); | ||
18 | void refresh(); | ||
19 | void restart(); | ||
20 | void advanced(); | 16 | void advanced(); |
17 | void updateInterface(Interface *i); | ||
21 | 18 | ||
22 | private: | 19 | private: |
23 | Interface *interface; | 20 | Interface *interface; |
24 | void updateInterface(); | ||
25 | 21 | ||
26 | }; | 22 | }; |
27 | 23 | ||
28 | #endif | 24 | #endif |
29 | 25 | ||
30 | // addserviceimp.h | 26 | // addserviceimp.h |
31 | 27 | ||
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index b46362f..117bac1 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -275,156 +275,159 @@ void MainWindowImp::getInterfaceList(){ | |||
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 | ||
287 | void MainWindowImp::jobDone(KProcess *process){ | 287 | void 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 | ||
308 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
307 | // See if we already have it | 309 | // See if we already have it |
308 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 310 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
309 | if(fileName == TEMP_ALL) | 311 | if(fileName == TEMP_ALL) |
310 | i = new Interface(interfaceName, false); | 312 | i = new Interface(this, interfaceName, false); |
311 | else | 313 | else |
312 | i = new Interface(interfaceName, true); | 314 | i = new Interface(this, interfaceName, true); |
315 | i->setAttached(true); | ||
316 | |||
317 | QString hardName = "Ethernet"; | ||
318 | int hardwareName = line.find("Link encap:"); | ||
319 | int macAddress = line.find("HWaddr"); | ||
320 | if(macAddress == -1) | ||
321 | macAddress = line.length(); | ||
322 | if(hardwareName != -1) | ||
323 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
324 | |||
325 | interfaceNames.insert(i->getInterfaceName(), i); | ||
326 | updateInterface(i); | ||
327 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
313 | } | 328 | } |
329 | // It was an interface we already had. | ||
314 | else{ | 330 | else{ |
315 | i = interfaceNames[interfaceName]; | 331 | i = interfaceNames[interfaceName]; |
316 | if(fileName != TEMP_ALL) | 332 | if(fileName != TEMP_ALL) |
317 | i->setStatus(true); | 333 | i->setStatus(true); |
318 | } | 334 | } |
319 | |||
320 | i->setAttached(true); | ||
321 | i->setInterfaceName(interfaceName); | ||
322 | |||
323 | QString hardName = "Ethernet"; | ||
324 | int hardwareName = line.find("Link encap:"); | ||
325 | int macAddress = line.find("HWaddr"); | ||
326 | if(macAddress == -1) | ||
327 | macAddress = line.length(); | ||
328 | if(hardwareName != -1) | ||
329 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
330 | // We have found an interface | ||
331 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
332 | interfaceNames.insert(i->getInterfaceName(), i); | ||
333 | updateInterface(i); | ||
334 | } | 335 | } |
335 | } | 336 | } |
336 | file.close(); | 337 | file.close(); |
337 | QFile::remove(fileName); | 338 | QFile::remove(fileName); |
338 | 339 | ||
339 | if(threads.count() == 0){ | 340 | if(threads.count() == 0){ |
340 | Interfaces i; | 341 | Interfaces i; |
341 | QStringList list = i.getInterfaceList(); | 342 | QStringList list = i.getInterfaceList(); |
342 | QMap<QString, Interface*>::Iterator it; | 343 | QMap<QString, Interface*>::Iterator it; |
343 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 344 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
344 | bool found = false; | 345 | bool found = false; |
345 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 346 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
346 | if(it.key() == (*ni)) | 347 | if(it.key() == (*ni)) |
347 | found = true; | 348 | found = true; |
348 | } | 349 | } |
349 | if(!found){ | 350 | if(!found){ |
350 | Interface *i = new Interface(*ni, false); | 351 | Interface *i = new Interface(this, *ni, false); |
351 | i->setAttached(false); | 352 | i->setAttached(false); |
352 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); | 353 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); |
353 | i->setInterfaceName(*ni); | ||
354 | interfaceNames.insert(i->getInterfaceName(), i); | 354 | interfaceNames.insert(i->getInterfaceName(), i); |
355 | updateInterface(i); | 355 | updateInterface(i); |
356 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
356 | } | 357 | } |
357 | } | 358 | } |
358 | } | 359 | } |
359 | } | 360 | } |
360 | 361 | ||
361 | /** | 362 | /** |
362 | * Update this interface. If no QListViewItem exists create one. | 363 | * Update this interface. If no QListViewItem exists create one. |
363 | * @param Interface* pointer to the interface that needs to be updated. | 364 | * @param Interface* pointer to the interface that needs to be updated. |
364 | */ | 365 | */ |
365 | void MainWindowImp::updateInterface(Interface *i){ | 366 | void MainWindowImp::updateInterface(Interface *i){ |
366 | if(!advancedUserMode){ | 367 | if(!advancedUserMode){ |
367 | if(i->getInterfaceName() == "lo") | 368 | if(i->getInterfaceName() == "lo") |
368 | return; | 369 | return; |
369 | } | 370 | } |
370 | 371 | ||
371 | QListViewItem *item = NULL; | 372 | QListViewItem *item = NULL; |
372 | 373 | ||
373 | // Find the interface, making it if needed. | 374 | // Find the interface, making it if needed. |
374 | if(items.find(i) == items.end()){ | 375 | if(items.find(i) == items.end()){ |
375 | item = new QListViewItem(connectionList, "", "", ""); | 376 | item = new QListViewItem(connectionList, "", "", ""); |
376 | // See if you can't find a module owner for this interface | 377 | // See if you can't find a module owner for this interface |
377 | QMap<Module*, QLibrary*>::Iterator it; | 378 | QMap<Module*, QLibrary*>::Iterator it; |
378 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 379 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
379 | if(it.key()->isOwner(i)) | 380 | if(it.key()->isOwner(i)) |
380 | i->setModuleOwner(it.key()); | 381 | i->setModuleOwner(it.key()); |
381 | } | 382 | } |
382 | items.insert(i, item); | 383 | items.insert(i, item); |
383 | interfaceItems.insert(item, i); | 384 | interfaceItems.insert(item, i); |
384 | } | 385 | } |
385 | else | 386 | else |
386 | item = items[i]; | 387 | item = items[i]; |
387 | 388 | ||
388 | // Update the icons and information | 389 | // Update the icons and information |
389 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 390 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
390 | 391 | ||
391 | QString typeName = "lan"; | 392 | QString typeName = "lan"; |
392 | if(i->getHardwareName().contains("Local Loopback")) | 393 | if(i->getHardwareName().contains("Local Loopback")) |
393 | typeName = "lo"; | 394 | typeName = "lo"; |
394 | if(i->getInterfaceName().contains("irda")) | 395 | if(i->getInterfaceName().contains("irda")) |
395 | typeName = "irda"; | 396 | typeName = "irda"; |
396 | if(i->getInterfaceName().contains("wlan")) | 397 | if(i->getInterfaceName().contains("wlan")) |
397 | typeName = "wlan"; | 398 | typeName = "wlan"; |
398 | 399 | if(i->getInterfaceName().contains("usb")) | |
400 | typeName = "usb"; | ||
401 | |||
399 | if(!i->isAttached()) | 402 | if(!i->isAttached()) |
400 | typeName = "connect_no"; | 403 | typeName = "connect_no"; |
401 | // Actually try to use the Module | 404 | // Actually try to use the Module |
402 | if(i->getModuleOwner() != NULL) | 405 | if(i->getModuleOwner() != NULL) |
403 | typeName = i->getModuleOwner()->getPixmapName(i); | 406 | typeName = i->getModuleOwner()->getPixmapName(i); |
404 | 407 | ||
405 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 408 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
406 | item->setText(2, i->getHardwareName()); | 409 | item->setText(2, i->getHardwareName()); |
407 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); | 410 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); |
408 | } | 411 | } |
409 | 412 | ||
410 | void MainWindowImp::newProfileChanged(const QString& newText){ | 413 | void MainWindowImp::newProfileChanged(const QString& newText){ |
411 | if(newText.length() > 0) | 414 | if(newText.length() > 0) |
412 | newProfileButton->setEnabled(true); | 415 | newProfileButton->setEnabled(true); |
413 | else | 416 | else |
414 | newProfileButton->setEnabled(false); | 417 | newProfileButton->setEnabled(false); |
415 | } | 418 | } |
416 | 419 | ||
417 | /** | 420 | /** |
418 | * Adds a new profile to the list of profiles. | 421 | * Adds a new profile to the list of profiles. |
419 | * Don't add profiles that already exists. | 422 | * Don't add profiles that already exists. |
420 | * Appends to the list and QStringList | 423 | * Appends to the list and QStringList |
421 | */ | 424 | */ |
422 | void MainWindowImp::addProfile(){ | 425 | void MainWindowImp::addProfile(){ |
423 | QString newProfileName = newProfile->text(); | 426 | QString newProfileName = newProfile->text(); |
424 | if(profiles.grep(newProfileName).count() > 0){ | 427 | if(profiles.grep(newProfileName).count() > 0){ |
425 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 428 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
426 | return; | 429 | return; |
427 | } | 430 | } |
428 | profiles.append(newProfileName); | 431 | profiles.append(newProfileName); |
429 | profilesList->insertItem(newProfileName); | 432 | profilesList->insertItem(newProfileName); |
430 | } | 433 | } |
diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp index 98d2eb6..f0394b4 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.cpp +++ b/noncore/net/networksetup/wlan/wlanmodule.cpp | |||
@@ -1,60 +1,62 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include <qpe/config.h> | 2 | #include <qpe/config.h> |
3 | #include "wlanimp.h" | 3 | #include "wlanimp.h" |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * Constructor, find all of the possible interfaces | 6 | * Constructor, find all of the possible interfaces |
7 | */ | 7 | */ |
8 | WLANModule::WLANModule() : Module() { | 8 | WLANModule::WLANModule() : Module() { |
9 | // get output from iwconfig | 9 | // get output from iwconfig |
10 | } | 10 | } |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * get the icon name for this device. | 13 | * get the icon name for this device. |
14 | * @param Interface* can be used in determining the icon. | 14 | * @param Interface* can be used in determining the icon. |
15 | * @return QString the icon name (minus .png, .gif etc) | 15 | * @return QString the icon name (minus .png, .gif etc) |
16 | */ | 16 | */ |
17 | QString WLANModule::getPixmapName(Interface* ){ | 17 | QString WLANModule::getPixmapName(Interface* ){ |
18 | return "wlan"; | 18 | return "wlan"; |
19 | } | 19 | } |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Check to see if the interface i is owned by this module. | 22 | * Check to see if the interface i is owned by this module. |
23 | * @param Interface* interface to check against | 23 | * @param Interface* interface to check against |
24 | * @return bool true if i is owned by this module, false otherwise. | 24 | * @return bool true if i is owned by this module, false otherwise. |
25 | */ | 25 | */ |
26 | bool WLANModule::isOwner(Interface *i){ | 26 | bool WLANModule::isOwner(Interface *i){ |
27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0") | 27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ |
28 | i->setHardwareName(QString("802.11b (%1)").arg(i->getInterfaceName())); | ||
28 | return true; | 29 | return true; |
30 | } | ||
29 | return false; | 31 | return false; |
30 | } | 32 | } |
31 | 33 | ||
32 | /** | 34 | /** |
33 | * Create, set tabWiget and return the WLANConfigure Module | 35 | * Create, set tabWiget and return the WLANConfigure Module |
34 | * @param tabWidget a pointer to the tab widget that this configure has. | 36 | * @param tabWidget a pointer to the tab widget that this configure has. |
35 | * @return QWidget* pointer to the tab widget in this modules configure. | 37 | * @return QWidget* pointer to the tab widget in this modules configure. |
36 | */ | 38 | */ |
37 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ | 39 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ |
38 | Config *cfg = new Config("wireless"); | 40 | Config *cfg = new Config("wireless"); |
39 | WLANImp *wlanconfig = new WLANImp(*cfg); | 41 | WLANImp *wlanconfig = new WLANImp(*cfg); |
40 | (*tabWidget) = wlanconfig->tabWidget; | 42 | (*tabWidget) = wlanconfig->tabWidget; |
41 | return wlanconfig; | 43 | return wlanconfig; |
42 | } | 44 | } |
43 | 45 | ||
44 | /** | 46 | /** |
45 | * Create, set tabWiget and return the Information Module | 47 | * Create, set tabWiget and return the Information Module |
46 | * @param tabWidget a pointer to the tab widget that this information has. | 48 | * @param tabWidget a pointer to the tab widget that this information has. |
47 | * @return QWidget* pointer to the tab widget in this modules info. | 49 | * @return QWidget* pointer to the tab widget in this modules info. |
48 | */ | 50 | */ |
49 | QWidget *WLANModule::information(QTabWidget **tabWidget){ | 51 | QWidget *WLANModule::information(QTabWidget **tabWidget){ |
50 | return NULL; | 52 | return NULL; |
51 | } | 53 | } |
52 | 54 | ||
53 | /** | 55 | /** |
54 | * Get all active (up or down) interfaces | 56 | * Get all active (up or down) interfaces |
55 | * @return QList<Interface> A list of interfaces that exsist that havn't | 57 | * @return QList<Interface> A list of interfaces that exsist that havn't |
56 | * been called by isOwner() | 58 | * been called by isOwner() |
57 | */ | 59 | */ |
58 | QList<Interface> WLANModule::getInterfaces(){ | 60 | QList<Interface> WLANModule::getInterfaces(){ |
59 | return list; | 61 | return list; |
60 | } | 62 | } |
diff --git a/noncore/settings/networksettings/TODO b/noncore/settings/networksettings/TODO index 7386646..c8e2989 100644 --- a/noncore/settings/networksettings/TODO +++ b/noncore/settings/networksettings/TODO | |||
@@ -1,8 +1,10 @@ | |||
1 | Write a class that parses /proc and not ifconfig | ||
2 | |||
1 | [ ] Wlanmodule needs to check if an interface supports wireless | 3 | [ ] Wlanmodule needs to check if an interface supports wireless |
2 | extensions. | 4 | extensions. |
3 | [x] When you set options in wlanmodule, hit OK, it exits all of | 5 | [x] When you set options in wlanmodule, hit OK, it exits all of |
4 | networksetup, doesnt bring you back to the main screen. | 6 | networksetup, doesnt bring you back to the main screen. |
5 | [x] Wlanmodule isnt writing out wireless.opts | 7 | [x] Wlanmodule isnt writing out wireless.opts |
6 | [ ] Need a means of bringing an interface up and down (calling | 8 | [ ] Need a means of bringing an interface up and down (calling |
7 | out ifup/ifdown) from the gui. | 9 | out ifup/ifdown) from the gui. |
8 | -Ben- Click information, then click up or down... :-D | 10 | -Ben- Click information, then click up or down... :-D |
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp index 1f32093..1e01da4 100644 --- a/noncore/settings/networksettings/interface.cpp +++ b/noncore/settings/networksettings/interface.cpp | |||
@@ -1,172 +1,215 @@ | |||
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 | ||
14 | Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ | 14 | Interface::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){ |
15 | refresh(); | 15 | refresh(); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Set status | ||
20 | * @param newStatus - the new status | ||
21 | * emit updateInterface | ||
22 | */ | ||
23 | void Interface::setStatus(bool newStatus){ | ||
24 | if(status != newStatus){ | ||
25 | status = newStatus; | ||
26 | refresh(); | ||
27 | } | ||
28 | }; | ||
29 | |||
30 | /** | ||
31 | * Set if attached or not (802.11 card pulled out for example) | ||
32 | * @param isAttached - if attached | ||
33 | * emit updateInterface | ||
34 | */ | ||
35 | void Interface::setAttached(bool isAttached){ | ||
36 | attached = isAttached; | ||
37 | emit(updateInterface(this)); | ||
38 | }; | ||
39 | |||
40 | /** | ||
41 | * Set Hardware name | ||
42 | * @param name - the new name | ||
43 | * emit updateInterface | ||
44 | */ | ||
45 | void Interface::setHardwareName(QString name){ | ||
46 | hardareName = name; | ||
47 | emit(updateInterface(this)); | ||
48 | }; | ||
49 | |||
50 | /** | ||
51 | * Set Module owner | ||
52 | * @param owner - the new owner | ||
53 | * emit updateInterface | ||
54 | */ | ||
55 | void Interface::setModuleOwner(Module *owner){ | ||
56 | moduleOwner = owner; | ||
57 | emit(updateInterface(this)); | ||
58 | }; | ||
59 | |||
60 | |||
61 | /** | ||
19 | * Try to start the interface. | 62 | * Try to start the interface. |
20 | * @return bool true if successfull. | ||
21 | */ | 63 | */ |
22 | bool Interface::start(){ | 64 | void Interface::start(){ |
23 | // check to see if we are already running. | 65 | // check to see if we are already running. |
24 | if(status) | 66 | if(true == status) |
25 | return false; | 67 | return; |
26 | 68 | ||
27 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); | 69 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); |
70 | // See if it was successfull... | ||
28 | if(ret != 0) | 71 | if(ret != 0) |
29 | return false; | 72 | return; |
30 | 73 | ||
31 | status = true; | 74 | status = true; |
32 | refresh(); | 75 | refresh(); |
33 | return true; | ||
34 | } | 76 | } |
35 | 77 | ||
36 | /** | 78 | /** |
37 | * Try to stop the interface. | 79 | * Try to stop the interface. |
38 | * @return bool true if successfull. | ||
39 | */ | 80 | */ |
40 | bool Interface::stop(){ | 81 | void Interface::stop(){ |
41 | // check to see if we are already stopped. | 82 | // check to see if we are already stopped. |
42 | if(status == false) | 83 | if(false == status) |
43 | return false; | 84 | return; |
44 | 85 | ||
45 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); | 86 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); |
46 | if(ret != 0) | 87 | if(ret != 0) |
47 | return false; | 88 | return; |
48 | 89 | ||
49 | status = true; | 90 | status = true; |
50 | refresh(); | 91 | refresh(); |
51 | return true; | ||
52 | } | 92 | } |
93 | |||
53 | /** | 94 | /** |
54 | * Try to restart the interface. | 95 | * Try to restart the interface. |
55 | * @return bool true if successfull. | ||
56 | */ | 96 | */ |
57 | bool Interface::restart(){ | 97 | void Interface::restart(){ |
58 | return (stop() && start()); | 98 | stop(); |
99 | start(); | ||
59 | } | 100 | } |
60 | 101 | ||
61 | /** | 102 | /** |
62 | * Try to refresh the information about the interface. | 103 | * Try to refresh the information about the interface. |
63 | * First call ifconfig, then check the dhcp-info file | 104 | * First call ifconfig, then check the dhcp-info file |
64 | * @return bool true if successfull. | 105 | * @return bool true if successfull. |
65 | */ | 106 | */ |
66 | bool Interface::refresh(){ | 107 | bool Interface::refresh(){ |
67 | // See if we are up. | 108 | // See if we are up. |
68 | if(status == false){ | 109 | if(status == false){ |
69 | macAddress = ""; | 110 | macAddress = ""; |
70 | ip = "0.0.0.0"; | 111 | ip = "0.0.0.0"; |
71 | subnetMask = "0.0.0.0"; | 112 | subnetMask = "0.0.0.0"; |
72 | broadcast = ""; | 113 | broadcast = ""; |
73 | dhcp = false; | 114 | dhcp = false; |
74 | dhcpServerIp = ""; | 115 | dhcpServerIp = ""; |
75 | leaseObtained = ""; | 116 | leaseObtained = ""; |
76 | leaseExpires = ""; | 117 | leaseExpires = ""; |
118 | emit(updateInterface(this)); | ||
77 | return true; | 119 | return true; |
78 | } | 120 | } |
79 | 121 | ||
80 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); | 122 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName); |
81 | 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(interfaceName).arg(fileName).latin1()); |
82 | if(ret != 0){ | 124 | if(ret != 0){ |
83 | 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()); |
84 | return false; | 126 | return false; |
85 | } | 127 | } |
86 | 128 | ||
87 | QFile file(fileName); | 129 | QFile file(fileName); |
88 | if (!file.open(IO_ReadOnly)){ | 130 | if (!file.open(IO_ReadOnly)){ |
89 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 131 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
90 | return false; | 132 | return false; |
91 | } | 133 | } |
92 | 134 | ||
93 | // Set to the defaults | 135 | // Set to the defaults |
94 | macAddress = ""; | 136 | macAddress = ""; |
95 | ip = "0.0.0.0"; | 137 | ip = "0.0.0.0"; |
96 | subnetMask = "0.0.0.0"; | 138 | subnetMask = "0.0.0.0"; |
97 | broadcast = ""; | 139 | broadcast = ""; |
98 | 140 | ||
99 | QTextStream stream( &file ); | 141 | QTextStream stream( &file ); |
100 | QString line; | 142 | QString line; |
101 | while ( !stream.eof() ) { | 143 | while ( !stream.eof() ) { |
102 | line = stream.readLine(); | 144 | line = stream.readLine(); |
103 | if(line.contains("HWaddr")){ | 145 | if(line.contains("HWaddr")){ |
104 | int mac = line.find("HWaddr"); | 146 | int mac = line.find("HWaddr"); |
105 | macAddress = line.mid(mac+7, line.length()); | 147 | macAddress = line.mid(mac+7, line.length()); |
106 | } | 148 | } |
107 | if(line.contains("inet addr")){ | 149 | if(line.contains("inet addr")){ |
108 | int ipl = line.find("inet addr"); | 150 | int ipl = line.find("inet addr"); |
109 | int space = line.find(" ", ipl+10); | 151 | int space = line.find(" ", ipl+10); |
110 | ip = line.mid(ipl+10, space-ipl-10); | 152 | ip = line.mid(ipl+10, space-ipl-10); |
111 | } | 153 | } |
112 | if(line.contains("Mask")){ | 154 | if(line.contains("Mask")){ |
113 | int mask = line.find("Mask"); | 155 | int mask = line.find("Mask"); |
114 | subnetMask = line.mid(mask+5, line.length()); | 156 | subnetMask = line.mid(mask+5, line.length()); |
115 | } | 157 | } |
116 | if(line.contains("Bcast")){ | 158 | if(line.contains("Bcast")){ |
117 | int mask = line.find("Bcast"); | 159 | int mask = line.find("Bcast"); |
118 | int space = line.find(" ", mask+6); | 160 | int space = line.find(" ", mask+6); |
119 | broadcast = line.mid(mask+6, space-mask-6); | 161 | broadcast = line.mid(mask+6, space-mask-6); |
120 | } | 162 | } |
121 | } | 163 | } |
122 | file.close(); | 164 | file.close(); |
123 | QFile::remove(fileName); | 165 | QFile::remove(fileName); |
124 | 166 | ||
125 | // DHCP TESTING | 167 | // DHCP TESTING |
126 | // reset DHCP info | 168 | // reset DHCP info |
127 | dhcpServerIp = ""; | 169 | dhcpServerIp = ""; |
128 | leaseObtained = ""; | 170 | leaseObtained = ""; |
129 | leaseExpires = ""; | 171 | leaseExpires = ""; |
130 | dhcp = false; | 172 | dhcp = false; |
131 | 173 | ||
132 | QString dhcpDirectory(HDCP_INFO_DIR); | 174 | QString dhcpDirectory(HDCP_INFO_DIR); |
133 | QDir d(dhcpDirectory); | 175 | QDir d(dhcpDirectory); |
134 | if(!d.exists(dhcpDirectory)) | 176 | if(!d.exists(dhcpDirectory)) |
135 | dhcpDirectory = "/var/run"; | 177 | dhcpDirectory = "/var/run"; |
136 | 178 | ||
137 | // See if we have | 179 | // See if we have |
138 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); | 180 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); |
139 | // 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. |
140 | if(!QFile::exists(dhcpFile)){ | 182 | if(!QFile::exists(dhcpFile)){ |
183 | emit(updateInterface(this)); | ||
141 | return true; | 184 | return true; |
142 | } | 185 | } |
143 | 186 | ||
144 | file.setName(dhcpFile); | 187 | file.setName(dhcpFile); |
145 | if (!file.open(IO_ReadOnly)){ | 188 | if (!file.open(IO_ReadOnly)){ |
146 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 189 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
147 | return false; | 190 | return false; |
148 | } | 191 | } |
149 | 192 | ||
150 | // 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. |
151 | int leaseTime = 0; | 194 | int leaseTime = 0; |
152 | int renewalTime = 0; | 195 | int renewalTime = 0; |
153 | 196 | ||
154 | stream.setDevice( &file ); | 197 | stream.setDevice( &file ); |
155 | while ( !stream.eof() ) { | 198 | while ( !stream.eof() ) { |
156 | line = stream.readLine(); | 199 | line = stream.readLine(); |
157 | if(line.contains("DHCPSIADDR=")) | 200 | if(line.contains("DHCPSIADDR=")) |
158 | dhcpServerIp = line.mid(11, line.length()); | 201 | dhcpServerIp = line.mid(11, line.length()); |
159 | if(line.contains("LEASETIME=")) | 202 | if(line.contains("LEASETIME=")) |
160 | leaseTime = line.mid(10, line.length()).toInt(); | 203 | leaseTime = line.mid(10, line.length()).toInt(); |
161 | if(line.contains("RENEWALTIME=")) | 204 | if(line.contains("RENEWALTIME=")) |
162 | renewalTime = line.mid(12, line.length()).toInt(); | 205 | renewalTime = line.mid(12, line.length()).toInt(); |
163 | } | 206 | } |
164 | file.close(); | 207 | file.close(); |
165 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | 208 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); |
166 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | 209 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); |
167 | 210 | ||
168 | // Get the pid of the deamond | 211 | // Get the pid of the deamond |
169 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); | 212 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName)); |
170 | file.setName(dhcpFile); | 213 | file.setName(dhcpFile); |
171 | if (!file.open(IO_ReadOnly)){ | 214 | if (!file.open(IO_ReadOnly)){ |
172 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 215 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
@@ -206,37 +249,39 @@ bool Interface::refresh(){ | |||
206 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | 249 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " |
207 | // nice 0 itrealvalue starttime | 250 | // nice 0 itrealvalue starttime |
208 | "%*d %*d %*d %lu", (long*) &time); | 251 | "%*d %*d %*d %lu", (long*) &time); |
209 | time = time/100; | 252 | time = time/100; |
210 | 253 | ||
211 | QDateTime datetime(QDateTime::currentDateTime()); | 254 | QDateTime datetime(QDateTime::currentDateTime()); |
212 | 255 | ||
213 | // Get the uptime of the computer. | 256 | // Get the uptime of the computer. |
214 | QFile f("/proc/uptime"); | 257 | QFile f("/proc/uptime"); |
215 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 258 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
216 | QTextStream t( &f ); // use a text stream | 259 | QTextStream t( &f ); // use a text stream |
217 | int sec = 0; | 260 | int sec = 0; |
218 | t >> sec; | 261 | t >> sec; |
219 | datetime = datetime.addSecs((-1*sec)); | 262 | datetime = datetime.addSecs((-1*sec)); |
220 | f.close(); | 263 | f.close(); |
221 | } | 264 | } |
222 | else{ | 265 | else{ |
223 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | 266 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); |
224 | return false; | 267 | return false; |
225 | } | 268 | } |
226 | 269 | ||
227 | datetime = datetime.addSecs(time); | 270 | datetime = datetime.addSecs(time); |
228 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | 271 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); |
229 | 272 | ||
230 | // Calculate the start and renew times | 273 | // Calculate the start and renew times |
231 | leaseObtained= datetime.toString(); | 274 | leaseObtained= datetime.toString(); |
232 | 275 | ||
233 | // Calculate the start and renew times | 276 | // Calculate the start and renew times |
234 | datetime = datetime.addSecs(leaseTime); | 277 | datetime = datetime.addSecs(leaseTime); |
235 | leaseExpires = datetime.toString(); | 278 | leaseExpires = datetime.toString(); |
236 | 279 | ||
237 | dhcp = true; | 280 | dhcp = true; |
281 | |||
282 | emit(updateInterface(this)); | ||
238 | return true; | 283 | return true; |
239 | } | 284 | } |
240 | 285 | ||
241 | // interface.cpp | 286 | // interface.cpp |
242 | 287 | ||
diff --git a/noncore/settings/networksettings/interface.h b/noncore/settings/networksettings/interface.h index 1406e99..980171a 100644 --- a/noncore/settings/networksettings/interface.h +++ b/noncore/settings/networksettings/interface.h | |||
@@ -1,67 +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 | 6 | ||
6 | class Module; | 7 | class Module; |
7 | 8 | ||
8 | class Interface { | 9 | class Interface : public QObject{ |
10 | Q_OBJECT | ||
9 | 11 | ||
12 | signals: | ||
13 | void updateInterface(Interface *i); | ||
14 | |||
10 | public: | 15 | public: |
11 | Interface(QString name = "unknown", bool status = false); | 16 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); |
12 | virtual ~Interface(){}; | 17 | virtual ~Interface(){}; |
13 | 18 | ||
19 | virtual QString getInterfaceName(){ QString n(this->name()); return n; }; | ||
20 | |||
14 | virtual bool getStatus(){ return status; }; | 21 | virtual bool getStatus(){ return status; }; |
15 | virtual void setStatus(bool newSatus){ status = newSatus; refresh(); }; | 22 | virtual void setStatus(bool newStatus); |
16 | 23 | ||
17 | virtual bool isAttached(){ return attached; }; | 24 | virtual bool isAttached(){ return attached; }; |
18 | virtual void setAttached(bool isAttached=false){ attached = isAttached; }; | 25 | virtual void setAttached(bool isAttached=false); |
19 | |||
20 | virtual QString getInterfaceName(){ return interfaceName; }; | ||
21 | virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; }; | ||
22 | 26 | ||
23 | virtual QString getHardwareName(){ return hardareName; }; | 27 | virtual QString getHardwareName(){ return hardareName; }; |
24 | virtual void setHardwareName(QString name="Unknown"){ hardareName = name; }; | 28 | virtual void setHardwareName(QString name="Unknown"); |
25 | 29 | ||
26 | virtual Module* getModuleOwner(){ return moduleOwner; }; | 30 | virtual Module* getModuleOwner(){ return moduleOwner; }; |
27 | virtual void setModuleOwner(Module *owner=NULL){ moduleOwner = owner; }; | 31 | virtual void setModuleOwner(Module *owner=NULL); |
28 | 32 | ||
29 | // inet information. | 33 | // inet information. |
30 | QString getMacAddress(){ return macAddress; }; | 34 | QString getMacAddress(){ return macAddress; }; |
31 | QString getIp(){ return ip; }; | 35 | QString getIp(){ return ip; }; |
32 | QString getSubnetMask(){ return subnetMask; }; | 36 | QString getSubnetMask(){ return subnetMask; }; |
33 | QString getBroadcast(){ return broadcast; }; | 37 | QString getBroadcast(){ return broadcast; }; |
34 | bool isDhcp(){ return dhcp; }; | 38 | bool isDhcp(){ return dhcp; }; |
35 | QString getDhcpServerIp(){ return dhcpServerIp; }; | 39 | QString getDhcpServerIp(){ return dhcpServerIp; }; |
36 | QString getLeaseObtained(){ return leaseObtained; }; | 40 | QString getLeaseObtained(){ return leaseObtained; }; |
37 | QString getLeaseExpires(){ return leaseExpires; }; | 41 | QString getLeaseExpires(){ return leaseExpires; }; |
38 | 42 | ||
43 | public slots: | ||
39 | bool refresh(); | 44 | bool refresh(); |
40 | bool start(); | 45 | void start(); |
41 | bool stop(); | 46 | void stop(); |
42 | bool restart(); | 47 | void restart(); |
43 | 48 | ||
44 | private: | 49 | private: |
45 | // Interface information | 50 | // Interface information |
46 | bool status; | 51 | bool status; |
47 | bool attached; | 52 | bool attached; |
48 | QString interfaceName; | 53 | QString interfaceName; |
49 | QString hardareName; | 54 | QString hardareName; |
50 | Module *moduleOwner; | 55 | Module *moduleOwner; |
51 | 56 | ||
52 | // Network information | 57 | // Network information |
53 | QString macAddress; | 58 | QString macAddress; |
54 | QString ip; | 59 | QString ip; |
55 | QString broadcast; | 60 | QString broadcast; |
56 | QString subnetMask; | 61 | QString subnetMask; |
57 | bool dhcp; | 62 | bool dhcp; |
58 | QString dhcpServerIp; | 63 | QString dhcpServerIp; |
59 | QString leaseObtained; | 64 | QString leaseObtained; |
60 | QString leaseExpires; | 65 | QString leaseExpires; |
61 | 66 | ||
62 | }; | 67 | }; |
63 | 68 | ||
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | // interface.h | 71 | // interface.h |
67 | 72 | ||
diff --git a/noncore/settings/networksettings/interfaceadvanced.ui b/noncore/settings/networksettings/interfaceadvanced.ui index 7520abe..efe67b0 100644 --- a/noncore/settings/networksettings/interfaceadvanced.ui +++ b/noncore/settings/networksettings/interfaceadvanced.ui | |||
@@ -1,50 +1,57 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceAdvanced</class> | 2 | <class>InterfaceAdvanced</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceAdvanced</cstring> | 7 | <cstring>InterfaceAdvanced</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>188</width> | 14 | <width>214</width> |
15 | <height>277</height> | 15 | <height>286</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>maximumSize</name> | ||
20 | <size> | ||
21 | <width>320</width> | ||
22 | <height>32767</height> | ||
23 | </size> | ||
24 | </property> | ||
25 | <property stdset="1"> | ||
19 | <name>caption</name> | 26 | <name>caption</name> |
20 | <string>Advanced Interface Information</string> | 27 | <string>Advanced Interface Information</string> |
21 | </property> | 28 | </property> |
22 | <grid> | 29 | <grid> |
23 | <property stdset="1"> | 30 | <property stdset="1"> |
24 | <name>margin</name> | 31 | <name>margin</name> |
25 | <number>11</number> | 32 | <number>11</number> |
26 | </property> | 33 | </property> |
27 | <property stdset="1"> | 34 | <property stdset="1"> |
28 | <name>spacing</name> | 35 | <name>spacing</name> |
29 | <number>6</number> | 36 | <number>6</number> |
30 | </property> | 37 | </property> |
31 | <widget row="1" column="0" > | 38 | <widget row="1" column="0" > |
32 | <class>QLabel</class> | 39 | <class>QLabel</class> |
33 | <property stdset="1"> | 40 | <property stdset="1"> |
34 | <name>name</name> | 41 | <name>name</name> |
35 | <cstring>TextLabel1</cstring> | 42 | <cstring>TextLabel1</cstring> |
36 | </property> | 43 | </property> |
37 | <property stdset="1"> | 44 | <property stdset="1"> |
38 | <name>text</name> | 45 | <name>text</name> |
39 | <string>MAC Address</string> | 46 | <string>MAC Address</string> |
40 | </property> | 47 | </property> |
41 | </widget> | 48 | </widget> |
42 | <widget row="0" column="1" > | 49 | <widget row="0" column="1" > |
43 | <class>QLabel</class> | 50 | <class>QLabel</class> |
44 | <property stdset="1"> | 51 | <property stdset="1"> |
45 | <name>name</name> | 52 | <name>name</name> |
46 | <cstring>interfaceName</cstring> | 53 | <cstring>interfaceName</cstring> |
47 | </property> | 54 | </property> |
48 | <property stdset="1"> | 55 | <property stdset="1"> |
49 | <name>frameShape</name> | 56 | <name>frameShape</name> |
50 | <enum>Panel</enum> | 57 | <enum>Panel</enum> |
diff --git a/noncore/settings/networksettings/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaceinformationimp.cpp index e37e0f8..59a6400 100644 --- a/noncore/settings/networksettings/interfaceinformationimp.cpp +++ b/noncore/settings/networksettings/interfaceinformationimp.cpp | |||
@@ -1,94 +1,67 @@ | |||
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 <assert.h> | 6 | #include <assert.h> |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Constructor for the InterfaceInformationImp class. This class pretty much | 9 | * Constructor for the InterfaceInformationImp class. This class pretty much |
10 | * just display's information about the interface that is passed to it. | 10 | * just display's information about the interface that is passed to it. |
11 | */ | 11 | */ |
12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ | 12 | InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){ |
13 | assert(i); | 13 | assert(i); |
14 | 14 | ||
15 | interface = i; | 15 | interface = i; |
16 | updateInterface(); | 16 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
17 | connect(startButton, SIGNAL(clicked()), this, SLOT(start())); | 17 | updateInterface(interface); |
18 | connect(stopButton, SIGNAL(clicked()), this, SLOT(stop())); | 18 | connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); |
19 | connect(restartButton, SIGNAL(clicked()), this, SLOT(restart())); | 19 | connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); |
20 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); | 20 | connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); |
21 | connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); | ||
21 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); | 22 | connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); |
22 | 23 | ||
23 | } | 24 | } |
24 | 25 | ||
25 | void InterfaceInformationImp::updateInterface(){ | 26 | /** |
27 | * Update the interface information and buttons. | ||
28 | * @param Intarface *i the interface to update (should be the one we already | ||
29 | * know about). | ||
30 | */ | ||
31 | void InterfaceInformationImp::updateInterface(Interface *i){ | ||
26 | if(interface->getStatus()){ | 32 | if(interface->getStatus()){ |
27 | startButton->setEnabled(false); | 33 | startButton->setEnabled(false); |
28 | stopButton->setEnabled(true); | 34 | stopButton->setEnabled(true); |
29 | restartButton->setEnabled(true); | 35 | restartButton->setEnabled(true); |
30 | } | 36 | } |
31 | else{ | 37 | else{ |
32 | startButton->setEnabled(true); | 38 | startButton->setEnabled(true); |
33 | stopButton->setEnabled(false); | 39 | stopButton->setEnabled(false); |
34 | restartButton->setEnabled(false); | 40 | restartButton->setEnabled(false); |
35 | } | 41 | } |
36 | macAddressLabel->setText(interface->getMacAddress()); | 42 | macAddressLabel->setText(interface->getMacAddress()); |
37 | ipAddressLabel->setText(interface->getIp()); | 43 | ipAddressLabel->setText(interface->getIp()); |
38 | subnetMaskLabel->setText(interface->getSubnetMask()); | 44 | subnetMaskLabel->setText(interface->getSubnetMask()); |
39 | broadcastLabel->setText(interface->getBroadcast()); | 45 | broadcastLabel->setText(interface->getBroadcast()); |
40 | } | 46 | } |
41 | 47 | ||
42 | /** | 48 | /** |
43 | * Start the interface. Update the information if successfull | ||
44 | */ | ||
45 | void InterfaceInformationImp::start(){ | ||
46 | if(interface->start()){ | ||
47 | updateInterface(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Stop the interface. | ||
53 | */ | ||
54 | void InterfaceInformationImp::stop(){ | ||
55 | if(interface->stop()){ | ||
56 | updateInterface(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /*** | ||
61 | * Tell the interface to refresh its information. | ||
62 | **/ | ||
63 | void InterfaceInformationImp::refresh(){ | ||
64 | if(interface->refresh()) | ||
65 | updateInterface(); | ||
66 | } | ||
67 | |||
68 | void InterfaceInformationImp::restart(){ | ||
69 | if(interface->restart()){ | ||
70 | updateInterface(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Create the advanced widget. Fill it with the current interface's information. | 49 | * Create the advanced widget. Fill it with the current interface's information. |
77 | * Display it. | 50 | * Display it. |
78 | */ | 51 | */ |
79 | void InterfaceInformationImp::advanced(){ | 52 | void InterfaceInformationImp::advanced(){ |
80 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); | 53 | InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced"); |
81 | a->interfaceName->setText(interface->getInterfaceName()); | 54 | a->interfaceName->setText(interface->getInterfaceName()); |
82 | a->macAddressLabel->setText(interface->getMacAddress()); | 55 | a->macAddressLabel->setText(interface->getMacAddress()); |
83 | a->ipAddressLabel->setText(interface->getIp()); | 56 | a->ipAddressLabel->setText(interface->getIp()); |
84 | a->subnetMaskLabel->setText(interface->getSubnetMask()); | 57 | a->subnetMaskLabel->setText(interface->getSubnetMask()); |
85 | a->broadcastLabel->setText(interface->getBroadcast()); | 58 | a->broadcastLabel->setText(interface->getBroadcast()); |
86 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); | 59 | a->dhcpServerLabel->setText(interface->getDhcpServerIp()); |
87 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); | 60 | a->leaseObtainedLabel->setText(interface->getLeaseObtained()); |
88 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); | 61 | a->leaseExpiresLabel->setText(interface->getLeaseExpires()); |
89 | a->showMaximized(); | 62 | a->showMaximized(); |
90 | a->show(); | 63 | a->show(); |
91 | } | 64 | } |
92 | 65 | ||
93 | // infoimp.cpp | 66 | // infoimp.cpp |
94 | 67 | ||
diff --git a/noncore/settings/networksettings/interfaceinformationimp.h b/noncore/settings/networksettings/interfaceinformationimp.h index c8a478e..42213cc 100644 --- a/noncore/settings/networksettings/interfaceinformationimp.h +++ b/noncore/settings/networksettings/interfaceinformationimp.h | |||
@@ -1,31 +1,27 @@ | |||
1 | #ifndef INTERFACEINFORMATIONIMP_H | 1 | #ifndef INTERFACEINFORMATIONIMP_H |
2 | #define INTERFACEINFORMATIONIMP_H | 2 | #define INTERFACEINFORMATIONIMP_H |
3 | 3 | ||
4 | #include "interfaceinformation.h" | 4 | #include "interfaceinformation.h" |
5 | #include "interface.h" | 5 | #include "interface.h" |
6 | 6 | ||
7 | class InterfaceInformationImp : public InterfaceInformation { | 7 | class InterfaceInformationImp : public InterfaceInformation { |
8 | 8 | ||
9 | Q_OBJECT | 9 | Q_OBJECT |
10 | 10 | ||
11 | public: | 11 | public: |
12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); | 12 | InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); |
13 | ~InterfaceInformationImp(){}; | 13 | ~InterfaceInformationImp(){}; |
14 | 14 | ||
15 | private slots: | 15 | private slots: |
16 | void start(); | ||
17 | void stop(); | ||
18 | void refresh(); | ||
19 | void restart(); | ||
20 | void advanced(); | 16 | void advanced(); |
17 | void updateInterface(Interface *i); | ||
21 | 18 | ||
22 | private: | 19 | private: |
23 | Interface *interface; | 20 | Interface *interface; |
24 | void updateInterface(); | ||
25 | 21 | ||
26 | }; | 22 | }; |
27 | 23 | ||
28 | #endif | 24 | #endif |
29 | 25 | ||
30 | // addserviceimp.h | 26 | // addserviceimp.h |
31 | 27 | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index b46362f..117bac1 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -275,156 +275,159 @@ void MainWindowImp::getInterfaceList(){ | |||
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 | ||
287 | void MainWindowImp::jobDone(KProcess *process){ | 287 | void 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 | ||
308 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
307 | // See if we already have it | 309 | // See if we already have it |
308 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 310 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
309 | if(fileName == TEMP_ALL) | 311 | if(fileName == TEMP_ALL) |
310 | i = new Interface(interfaceName, false); | 312 | i = new Interface(this, interfaceName, false); |
311 | else | 313 | else |
312 | i = new Interface(interfaceName, true); | 314 | i = new Interface(this, interfaceName, true); |
315 | i->setAttached(true); | ||
316 | |||
317 | QString hardName = "Ethernet"; | ||
318 | int hardwareName = line.find("Link encap:"); | ||
319 | int macAddress = line.find("HWaddr"); | ||
320 | if(macAddress == -1) | ||
321 | macAddress = line.length(); | ||
322 | if(hardwareName != -1) | ||
323 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
324 | |||
325 | interfaceNames.insert(i->getInterfaceName(), i); | ||
326 | updateInterface(i); | ||
327 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
313 | } | 328 | } |
329 | // It was an interface we already had. | ||
314 | else{ | 330 | else{ |
315 | i = interfaceNames[interfaceName]; | 331 | i = interfaceNames[interfaceName]; |
316 | if(fileName != TEMP_ALL) | 332 | if(fileName != TEMP_ALL) |
317 | i->setStatus(true); | 333 | i->setStatus(true); |
318 | } | 334 | } |
319 | |||
320 | i->setAttached(true); | ||
321 | i->setInterfaceName(interfaceName); | ||
322 | |||
323 | QString hardName = "Ethernet"; | ||
324 | int hardwareName = line.find("Link encap:"); | ||
325 | int macAddress = line.find("HWaddr"); | ||
326 | if(macAddress == -1) | ||
327 | macAddress = line.length(); | ||
328 | if(hardwareName != -1) | ||
329 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); | ||
330 | // We have found an interface | ||
331 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
332 | interfaceNames.insert(i->getInterfaceName(), i); | ||
333 | updateInterface(i); | ||
334 | } | 335 | } |
335 | } | 336 | } |
336 | file.close(); | 337 | file.close(); |
337 | QFile::remove(fileName); | 338 | QFile::remove(fileName); |
338 | 339 | ||
339 | if(threads.count() == 0){ | 340 | if(threads.count() == 0){ |
340 | Interfaces i; | 341 | Interfaces i; |
341 | QStringList list = i.getInterfaceList(); | 342 | QStringList list = i.getInterfaceList(); |
342 | QMap<QString, Interface*>::Iterator it; | 343 | QMap<QString, Interface*>::Iterator it; |
343 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 344 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
344 | bool found = false; | 345 | bool found = false; |
345 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 346 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
346 | if(it.key() == (*ni)) | 347 | if(it.key() == (*ni)) |
347 | found = true; | 348 | found = true; |
348 | } | 349 | } |
349 | if(!found){ | 350 | if(!found){ |
350 | Interface *i = new Interface(*ni, false); | 351 | Interface *i = new Interface(this, *ni, false); |
351 | i->setAttached(false); | 352 | i->setAttached(false); |
352 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); | 353 | i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); |
353 | i->setInterfaceName(*ni); | ||
354 | interfaceNames.insert(i->getInterfaceName(), i); | 354 | interfaceNames.insert(i->getInterfaceName(), i); |
355 | updateInterface(i); | 355 | updateInterface(i); |
356 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
356 | } | 357 | } |
357 | } | 358 | } |
358 | } | 359 | } |
359 | } | 360 | } |
360 | 361 | ||
361 | /** | 362 | /** |
362 | * Update this interface. If no QListViewItem exists create one. | 363 | * Update this interface. If no QListViewItem exists create one. |
363 | * @param Interface* pointer to the interface that needs to be updated. | 364 | * @param Interface* pointer to the interface that needs to be updated. |
364 | */ | 365 | */ |
365 | void MainWindowImp::updateInterface(Interface *i){ | 366 | void MainWindowImp::updateInterface(Interface *i){ |
366 | if(!advancedUserMode){ | 367 | if(!advancedUserMode){ |
367 | if(i->getInterfaceName() == "lo") | 368 | if(i->getInterfaceName() == "lo") |
368 | return; | 369 | return; |
369 | } | 370 | } |
370 | 371 | ||
371 | QListViewItem *item = NULL; | 372 | QListViewItem *item = NULL; |
372 | 373 | ||
373 | // Find the interface, making it if needed. | 374 | // Find the interface, making it if needed. |
374 | if(items.find(i) == items.end()){ | 375 | if(items.find(i) == items.end()){ |
375 | item = new QListViewItem(connectionList, "", "", ""); | 376 | item = new QListViewItem(connectionList, "", "", ""); |
376 | // See if you can't find a module owner for this interface | 377 | // See if you can't find a module owner for this interface |
377 | QMap<Module*, QLibrary*>::Iterator it; | 378 | QMap<Module*, QLibrary*>::Iterator it; |
378 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 379 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
379 | if(it.key()->isOwner(i)) | 380 | if(it.key()->isOwner(i)) |
380 | i->setModuleOwner(it.key()); | 381 | i->setModuleOwner(it.key()); |
381 | } | 382 | } |
382 | items.insert(i, item); | 383 | items.insert(i, item); |
383 | interfaceItems.insert(item, i); | 384 | interfaceItems.insert(item, i); |
384 | } | 385 | } |
385 | else | 386 | else |
386 | item = items[i]; | 387 | item = items[i]; |
387 | 388 | ||
388 | // Update the icons and information | 389 | // Update the icons and information |
389 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 390 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
390 | 391 | ||
391 | QString typeName = "lan"; | 392 | QString typeName = "lan"; |
392 | if(i->getHardwareName().contains("Local Loopback")) | 393 | if(i->getHardwareName().contains("Local Loopback")) |
393 | typeName = "lo"; | 394 | typeName = "lo"; |
394 | if(i->getInterfaceName().contains("irda")) | 395 | if(i->getInterfaceName().contains("irda")) |
395 | typeName = "irda"; | 396 | typeName = "irda"; |
396 | if(i->getInterfaceName().contains("wlan")) | 397 | if(i->getInterfaceName().contains("wlan")) |
397 | typeName = "wlan"; | 398 | typeName = "wlan"; |
398 | 399 | if(i->getInterfaceName().contains("usb")) | |
400 | typeName = "usb"; | ||
401 | |||
399 | if(!i->isAttached()) | 402 | if(!i->isAttached()) |
400 | typeName = "connect_no"; | 403 | typeName = "connect_no"; |
401 | // Actually try to use the Module | 404 | // Actually try to use the Module |
402 | if(i->getModuleOwner() != NULL) | 405 | if(i->getModuleOwner() != NULL) |
403 | typeName = i->getModuleOwner()->getPixmapName(i); | 406 | typeName = i->getModuleOwner()->getPixmapName(i); |
404 | 407 | ||
405 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 408 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
406 | item->setText(2, i->getHardwareName()); | 409 | item->setText(2, i->getHardwareName()); |
407 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); | 410 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); |
408 | } | 411 | } |
409 | 412 | ||
410 | void MainWindowImp::newProfileChanged(const QString& newText){ | 413 | void MainWindowImp::newProfileChanged(const QString& newText){ |
411 | if(newText.length() > 0) | 414 | if(newText.length() > 0) |
412 | newProfileButton->setEnabled(true); | 415 | newProfileButton->setEnabled(true); |
413 | else | 416 | else |
414 | newProfileButton->setEnabled(false); | 417 | newProfileButton->setEnabled(false); |
415 | } | 418 | } |
416 | 419 | ||
417 | /** | 420 | /** |
418 | * Adds a new profile to the list of profiles. | 421 | * Adds a new profile to the list of profiles. |
419 | * Don't add profiles that already exists. | 422 | * Don't add profiles that already exists. |
420 | * Appends to the list and QStringList | 423 | * Appends to the list and QStringList |
421 | */ | 424 | */ |
422 | void MainWindowImp::addProfile(){ | 425 | void MainWindowImp::addProfile(){ |
423 | QString newProfileName = newProfile->text(); | 426 | QString newProfileName = newProfile->text(); |
424 | if(profiles.grep(newProfileName).count() > 0){ | 427 | if(profiles.grep(newProfileName).count() > 0){ |
425 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 428 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
426 | return; | 429 | return; |
427 | } | 430 | } |
428 | profiles.append(newProfileName); | 431 | profiles.append(newProfileName); |
429 | profilesList->insertItem(newProfileName); | 432 | profilesList->insertItem(newProfileName); |
430 | } | 433 | } |
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp index 98d2eb6..f0394b4 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.cpp +++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp | |||
@@ -1,60 +1,62 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include <qpe/config.h> | 2 | #include <qpe/config.h> |
3 | #include "wlanimp.h" | 3 | #include "wlanimp.h" |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * Constructor, find all of the possible interfaces | 6 | * Constructor, find all of the possible interfaces |
7 | */ | 7 | */ |
8 | WLANModule::WLANModule() : Module() { | 8 | WLANModule::WLANModule() : Module() { |
9 | // get output from iwconfig | 9 | // get output from iwconfig |
10 | } | 10 | } |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * get the icon name for this device. | 13 | * get the icon name for this device. |
14 | * @param Interface* can be used in determining the icon. | 14 | * @param Interface* can be used in determining the icon. |
15 | * @return QString the icon name (minus .png, .gif etc) | 15 | * @return QString the icon name (minus .png, .gif etc) |
16 | */ | 16 | */ |
17 | QString WLANModule::getPixmapName(Interface* ){ | 17 | QString WLANModule::getPixmapName(Interface* ){ |
18 | return "wlan"; | 18 | return "wlan"; |
19 | } | 19 | } |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Check to see if the interface i is owned by this module. | 22 | * Check to see if the interface i is owned by this module. |
23 | * @param Interface* interface to check against | 23 | * @param Interface* interface to check against |
24 | * @return bool true if i is owned by this module, false otherwise. | 24 | * @return bool true if i is owned by this module, false otherwise. |
25 | */ | 25 | */ |
26 | bool WLANModule::isOwner(Interface *i){ | 26 | bool WLANModule::isOwner(Interface *i){ |
27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0") | 27 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ |
28 | i->setHardwareName(QString("802.11b (%1)").arg(i->getInterfaceName())); | ||
28 | return true; | 29 | return true; |
30 | } | ||
29 | return false; | 31 | return false; |
30 | } | 32 | } |
31 | 33 | ||
32 | /** | 34 | /** |
33 | * Create, set tabWiget and return the WLANConfigure Module | 35 | * Create, set tabWiget and return the WLANConfigure Module |
34 | * @param tabWidget a pointer to the tab widget that this configure has. | 36 | * @param tabWidget a pointer to the tab widget that this configure has. |
35 | * @return QWidget* pointer to the tab widget in this modules configure. | 37 | * @return QWidget* pointer to the tab widget in this modules configure. |
36 | */ | 38 | */ |
37 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ | 39 | QWidget *WLANModule::configure(QTabWidget **tabWidget){ |
38 | Config *cfg = new Config("wireless"); | 40 | Config *cfg = new Config("wireless"); |
39 | WLANImp *wlanconfig = new WLANImp(*cfg); | 41 | WLANImp *wlanconfig = new WLANImp(*cfg); |
40 | (*tabWidget) = wlanconfig->tabWidget; | 42 | (*tabWidget) = wlanconfig->tabWidget; |
41 | return wlanconfig; | 43 | return wlanconfig; |
42 | } | 44 | } |
43 | 45 | ||
44 | /** | 46 | /** |
45 | * Create, set tabWiget and return the Information Module | 47 | * Create, set tabWiget and return the Information Module |
46 | * @param tabWidget a pointer to the tab widget that this information has. | 48 | * @param tabWidget a pointer to the tab widget that this information has. |
47 | * @return QWidget* pointer to the tab widget in this modules info. | 49 | * @return QWidget* pointer to the tab widget in this modules info. |
48 | */ | 50 | */ |
49 | QWidget *WLANModule::information(QTabWidget **tabWidget){ | 51 | QWidget *WLANModule::information(QTabWidget **tabWidget){ |
50 | return NULL; | 52 | return NULL; |
51 | } | 53 | } |
52 | 54 | ||
53 | /** | 55 | /** |
54 | * Get all active (up or down) interfaces | 56 | * Get all active (up or down) interfaces |
55 | * @return QList<Interface> A list of interfaces that exsist that havn't | 57 | * @return QList<Interface> A list of interfaces that exsist that havn't |
56 | * been called by isOwner() | 58 | * been called by isOwner() |
57 | */ | 59 | */ |
58 | QList<Interface> WLANModule::getInterfaces(){ | 60 | QList<Interface> WLANModule::getInterfaces(){ |
59 | return list; | 61 | return list; |
60 | } | 62 | } |