summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces/interface.cpp287
-rw-r--r--noncore/net/networksetup/interfaces/interface.h71
-rw-r--r--noncore/net/networksetup/interfaces/interfaceadvanced.ui344
-rw-r--r--noncore/net/networksetup/interfaces/interfaceinformation.ui343
-rw-r--r--noncore/net/networksetup/interfaces/interfaceinformationimp.cpp70
-rw-r--r--noncore/net/networksetup/interfaces/interfaceinformationimp.h27
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.cpp638
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.h76
-rw-r--r--noncore/net/networksetup/interfaces/interfaces.pro12
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetup.ui284
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetupimp.cpp148
-rw-r--r--noncore/net/networksetup/interfaces/interfacesetupimp.h49
-rw-r--r--noncore/settings/networksettings/interfaces/interface.cpp287
-rw-r--r--noncore/settings/networksettings/interfaces/interface.h71
-rw-r--r--noncore/settings/networksettings/interfaces/interfaceadvanced.ui344
-rw-r--r--noncore/settings/networksettings/interfaces/interfaceinformation.ui343
-rw-r--r--noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp70
-rw-r--r--noncore/settings/networksettings/interfaces/interfaceinformationimp.h27
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.cpp638
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.h76
-rw-r--r--noncore/settings/networksettings/interfaces/interfaces.pro12
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetup.ui284
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp148
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.h49
24 files changed, 4698 insertions, 0 deletions
diff --git a/noncore/net/networksetup/interfaces/interface.cpp b/noncore/net/networksetup/interfaces/interface.cpp
new file mode 100644
index 0000000..929b3a1
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interface.cpp
@@ -0,0 +1,287 @@
1#include "interface.h"
2#include <qdatetime.h>
3#include <qfile.h>
4#include <qdir.h>
5#include <qfileinfo.h>
6#include <qtextstream.h>
7
8#define IFCONFIG "/sbin/ifconfig"
9#define DHCP_INFO_DIR "/etc/dhcpc"
10
11#include <stdio.h>
12#include <stdlib.h>
13
14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
15 refresh();
16}
17
18/**
19 * Set status
20 * @param newStatus - the new status
21 * emit updateInterface
22 */
23void 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 */
35void 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 */
45void Interface::setHardwareName(QString name){
46 hardwareName = name;
47 emit(updateInterface(this));
48};
49
50/**
51 * Set Module owner
52 * @param owner - the new owner
53 * emit updateInterface
54 */
55void Interface::setModuleOwner(Module *owner){
56 moduleOwner = owner;
57 emit(updateInterface(this));
58};
59
60
61/**
62 * Try to start the interface.
63 */
64void Interface::start(){
65 // check to see if we are already running.
66 if(true == status)
67 return;
68
69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
70 // See if it was successfull...
71 if(ret != 0)
72 return;
73
74 status = true;
75 refresh();
76}
77
78/**
79 * Try to stop the interface.
80 */
81void Interface::stop(){
82 // check to see if we are already stopped.
83 if(false == status)
84 return;
85
86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
87 if(ret != 0)
88 return;
89
90 status = true;
91 refresh();
92}
93
94/**
95 * Try to restart the interface.
96 */
97void Interface::restart(){
98 stop();
99 start();
100}
101
102/**
103 * Try to refresh the information about the interface.
104 * First call ifconfig, then check the dhcp-info file
105 * @return bool true if successfull.
106 */
107bool Interface::refresh(){
108 // See if we are up.
109 if(status == false){
110 macAddress = "";
111 ip = "0.0.0.0";
112 subnetMask = "0.0.0.0";
113 broadcast = "";
114 dhcp = false;
115 dhcpServerIp = "";
116 leaseObtained = "";
117 leaseExpires = "";
118 emit(updateInterface(this));
119 return true;
120 }
121
122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
124 if(ret != 0){
125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
126 return false;
127 }
128
129 QFile file(fileName);
130 if (!file.open(IO_ReadOnly)){
131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
132 return false;
133 }
134
135 // Set to the defaults
136 macAddress = "";
137 ip = "0.0.0.0";
138 subnetMask = "0.0.0.0";
139 broadcast = "";
140
141 QTextStream stream( &file );
142 QString line;
143 while ( !stream.eof() ) {
144 line = stream.readLine();
145 if(line.contains("HWaddr")){
146 int mac = line.find("HWaddr");
147 macAddress = line.mid(mac+7, line.length());
148 }
149 if(line.contains("inet addr")){
150 int ipl = line.find("inet addr");
151 int space = line.find(" ", ipl+10);
152 ip = line.mid(ipl+10, space-ipl-10);
153 }
154 if(line.contains("Mask")){
155 int mask = line.find("Mask");
156 subnetMask = line.mid(mask+5, line.length());
157 }
158 if(line.contains("Bcast")){
159 int mask = line.find("Bcast");
160 int space = line.find(" ", mask+6);
161 broadcast = line.mid(mask+6, space-mask-6);
162 }
163 }
164 file.close();
165 QFile::remove(fileName);
166
167 // DHCP TESTING
168 // reset DHCP info
169 dhcpServerIp = "";
170 leaseObtained = "";
171 leaseExpires = "";
172 dhcp = false;
173
174 QString dhcpDirectory(DHCP_INFO_DIR);
175 QDir d(dhcpDirectory);
176 if(!d.exists(dhcpDirectory))
177 dhcpDirectory = "/var/run";
178
179 // See if we have
180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
181 // If there is no DHCP information then exit now with no errors.
182 if(!QFile::exists(dhcpFile)){
183 emit(updateInterface(this));
184 return true;
185 }
186
187 file.setName(dhcpFile);
188 if (!file.open(IO_ReadOnly)){
189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
190 return false;
191 }
192
193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
194 int leaseTime = 0;
195 int renewalTime = 0;
196
197 stream.setDevice( &file );
198 while ( !stream.eof() ) {
199 line = stream.readLine();
200 if(line.contains("DHCPSIADDR="))
201 dhcpServerIp = line.mid(11, line.length());
202 if(line.contains("LEASETIME="))
203 leaseTime = line.mid(10, line.length()).toInt();
204 if(line.contains("RENEWALTIME="))
205 renewalTime = line.mid(12, line.length()).toInt();
206 }
207 file.close();
208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
210
211 // Get the pid of the deamond
212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
213 file.setName(dhcpFile);
214 if (!file.open(IO_ReadOnly)){
215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
216 return false;
217 }
218
219 int pid = -1;
220 stream.setDevice( &file );
221 while ( !stream.eof() ) {
222 line = stream.readLine();
223 pid = line.toInt();
224 }
225 file.close();
226
227 if( pid == -1){
228 qDebug("Interface: Could not get pid of dhcpc deamon.");
229 return false;
230 }
231
232 // Get the start running time of the deamon
233 fileName = (QString("/proc/%1/stat").arg(pid));
234 file.setName(fileName);
235 stream.setDevice( &file );
236 if (!file.open(IO_ReadOnly)){
237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
238 return false;
239 }
240 while ( !stream.eof() ) {
241 line = stream.readLine();
242 }
243 file.close();
244 long time = 0;
245 // Grab the start time
246 // pid com state ppid pgrp session tty_nr tpgid flags
247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
250 // nice 0 itrealvalue starttime
251 "%*d %*d %*d %lu", (long*) &time);
252 time = time/100;
253
254 QDateTime datetime(QDateTime::currentDateTime());
255
256 // Get the uptime of the computer.
257 QFile f("/proc/uptime");
258 if ( f.open(IO_ReadOnly) ) { // file opened successfully
259 QTextStream t( &f ); // use a text stream
260 int sec = 0;
261 t >> sec;
262 datetime = datetime.addSecs((-1*sec));
263 f.close();
264 }
265 else{
266 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
267 return false;
268 }
269
270 datetime = datetime.addSecs(time);
271 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
272
273 // Calculate the start and renew times
274 leaseObtained= datetime.toString();
275
276 // Calculate the start and renew times
277 datetime = datetime.addSecs(leaseTime);
278 leaseExpires = datetime.toString();
279
280 dhcp = true;
281
282 emit(updateInterface(this));
283 return true;
284}
285
286// interface.cpp
287
diff --git a/noncore/net/networksetup/interfaces/interface.h b/noncore/net/networksetup/interfaces/interface.h
new file mode 100644
index 0000000..dc9c6d3
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interface.h
@@ -0,0 +1,71 @@
1#ifndef INTERFACE_H
2#define INTERFACE_H
3
4#include <qstring.h>
5#include <qobject.h>
6
7class Module;
8
9class Interface : public QObject{
10 Q_OBJECT
11
12signals:
13 void updateInterface(Interface *i);
14
15public:
16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
17 virtual ~Interface(){};
18
19 virtual QString getInterfaceName(){ QString n(this->name()); return n; };
20
21 virtual bool getStatus(){ return status; };
22 virtual void setStatus(bool newStatus);
23
24 virtual bool isAttached(){ return attached; };
25 virtual void setAttached(bool isAttached=false);
26
27 virtual QString getHardwareName(){ return hardwareName; };
28 virtual void setHardwareName(QString name="Unknown");
29
30 virtual Module* getModuleOwner(){ return moduleOwner; };
31 virtual void setModuleOwner(Module *owner=NULL);
32
33 // inet information.
34 QString getMacAddress(){ return macAddress; };
35 QString getIp(){ return ip; };
36 QString getSubnetMask(){ return subnetMask; };
37 QString getBroadcast(){ return broadcast; };
38 bool isDhcp(){ return dhcp; };
39 QString getDhcpServerIp(){ return dhcpServerIp; };
40 QString getLeaseObtained(){ return leaseObtained; };
41 QString getLeaseExpires(){ return leaseExpires; };
42
43public slots:
44 bool refresh();
45 void start();
46 void stop();
47 void restart();
48
49private:
50 // Interface information
51 bool status;
52 bool attached;
53 QString hardwareName;
54 Module *moduleOwner;
55
56 // Network information
57 QString macAddress;
58 QString ip;
59 QString broadcast;
60 QString subnetMask;
61 bool dhcp;
62 QString dhcpServerIp;
63 QString leaseObtained;
64 QString leaseExpires;
65
66};
67
68#endif
69
70// interface.h
71
diff --git a/noncore/net/networksetup/interfaces/interfaceadvanced.ui b/noncore/net/networksetup/interfaces/interfaceadvanced.ui
new file mode 100644
index 0000000..0ec67c2
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfaceadvanced.ui
@@ -0,0 +1,344 @@
1<!DOCTYPE UI><UI>
2<class>InterfaceAdvanced</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>InterfaceAdvanced</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>214</width>
15 <height>286</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>maximumSize</name>
20 <size>
21 <width>240</width>
22 <height>32767</height>
23 </size>
24 </property>
25 <property stdset="1">
26 <name>caption</name>
27 <string>Advanced Interface Information</string>
28 </property>
29 <grid>
30 <property stdset="1">
31 <name>margin</name>
32 <number>11</number>
33 </property>
34 <property stdset="1">
35 <name>spacing</name>
36 <number>6</number>
37 </property>
38 <widget row="1" column="0" >
39 <class>QLabel</class>
40 <property stdset="1">
41 <name>name</name>
42 <cstring>TextLabel1</cstring>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>MAC Address</string>
47 </property>
48 </widget>
49 <widget row="0" column="1" >
50 <class>QLabel</class>
51 <property stdset="1">
52 <name>name</name>
53 <cstring>interfaceName</cstring>
54 </property>
55 <property stdset="1">
56 <name>frameShape</name>
57 <enum>Panel</enum>
58 </property>
59 <property stdset="1">
60 <name>frameShadow</name>
61 <enum>Sunken</enum>
62 </property>
63 <property stdset="1">
64 <name>text</name>
65 <string>eth0</string>
66 </property>
67 </widget>
68 <widget row="2" column="0" >
69 <class>QLabel</class>
70 <property stdset="1">
71 <name>name</name>
72 <cstring>TextLabel3</cstring>
73 </property>
74 <property stdset="1">
75 <name>text</name>
76 <string>IP Address</string>
77 </property>
78 </widget>
79 <widget row="1" column="1" >
80 <class>QLabel</class>
81 <property stdset="1">
82 <name>name</name>
83 <cstring>macAddressLabel</cstring>
84 </property>
85 <property stdset="1">
86 <name>frameShape</name>
87 <enum>Panel</enum>
88 </property>
89 <property stdset="1">
90 <name>frameShadow</name>
91 <enum>Sunken</enum>
92 </property>
93 <property stdset="1">
94 <name>text</name>
95 <string>00:00:00:00:00:00</string>
96 </property>
97 </widget>
98 <widget row="0" column="0" >
99 <class>QLabel</class>
100 <property stdset="1">
101 <name>name</name>
102 <cstring>TextLabel7</cstring>
103 </property>
104 <property stdset="1">
105 <name>text</name>
106 <string>Interface</string>
107 </property>
108 </widget>
109 <widget row="4" column="0" >
110 <class>QLabel</class>
111 <property stdset="1">
112 <name>name</name>
113 <cstring>TextLabel4</cstring>
114 </property>
115 <property stdset="1">
116 <name>enabled</name>
117 <bool>true</bool>
118 </property>
119 <property stdset="1">
120 <name>text</name>
121 <string>Subnet Mask</string>
122 </property>
123 </widget>
124 <widget row="2" column="1" >
125 <class>QLabel</class>
126 <property stdset="1">
127 <name>name</name>
128 <cstring>ipAddressLabel</cstring>
129 </property>
130 <property stdset="1">
131 <name>frameShape</name>
132 <enum>Panel</enum>
133 </property>
134 <property stdset="1">
135 <name>frameShadow</name>
136 <enum>Sunken</enum>
137 </property>
138 <property stdset="1">
139 <name>text</name>
140 <string>0.0.0.0</string>
141 </property>
142 </widget>
143 <widget row="4" column="1" >
144 <class>QLabel</class>
145 <property stdset="1">
146 <name>name</name>
147 <cstring>subnetMaskLabel</cstring>
148 </property>
149 <property stdset="1">
150 <name>frameShape</name>
151 <enum>Panel</enum>
152 </property>
153 <property stdset="1">
154 <name>frameShadow</name>
155 <enum>Sunken</enum>
156 </property>
157 <property stdset="1">
158 <name>text</name>
159 <string>0.0.0.0</string>
160 </property>
161 </widget>
162 <widget row="3" column="0" >
163 <class>QLabel</class>
164 <property stdset="1">
165 <name>name</name>
166 <cstring>TextLabel2</cstring>
167 </property>
168 <property stdset="1">
169 <name>text</name>
170 <string>Broadcast</string>
171 </property>
172 </widget>
173 <widget row="3" column="1" >
174 <class>QLabel</class>
175 <property stdset="1">
176 <name>name</name>
177 <cstring>broadcastLabel</cstring>
178 </property>
179 <property stdset="1">
180 <name>frameShape</name>
181 <enum>Panel</enum>
182 </property>
183 <property stdset="1">
184 <name>frameShadow</name>
185 <enum>Sunken</enum>
186 </property>
187 </widget>
188 <widget row="5" column="0" rowspan="1" colspan="2" >
189 <class>QGroupBox</class>
190 <property stdset="1">
191 <name>name</name>
192 <cstring>dhcpInformation</cstring>
193 </property>
194 <property stdset="1">
195 <name>title</name>
196 <string>DHCP Information</string>
197 </property>
198 <grid>
199 <property stdset="1">
200 <name>margin</name>
201 <number>11</number>
202 </property>
203 <property stdset="1">
204 <name>spacing</name>
205 <number>6</number>
206 </property>
207 <widget row="0" column="0" >
208 <class>QLabel</class>
209 <property stdset="1">
210 <name>name</name>
211 <cstring>TextLabel6</cstring>
212 </property>
213 <property stdset="1">
214 <name>text</name>
215 <string>DHCP Server</string>
216 </property>
217 </widget>
218 <widget row="2" column="1" >
219 <class>QLabel</class>
220 <property stdset="1">
221 <name>name</name>
222 <cstring>leaseExpiresLabel</cstring>
223 </property>
224 <property stdset="1">
225 <name>frameShape</name>
226 <enum>Panel</enum>
227 </property>
228 <property stdset="1">
229 <name>frameShadow</name>
230 <enum>Sunken</enum>
231 </property>
232 <property stdset="1">
233 <name>text</name>
234 <string></string>
235 </property>
236 </widget>
237 <widget row="1" column="1" >
238 <class>QLabel</class>
239 <property stdset="1">
240 <name>name</name>
241 <cstring>leaseObtainedLabel</cstring>
242 </property>
243 <property stdset="1">
244 <name>frameShape</name>
245 <enum>Panel</enum>
246 </property>
247 <property stdset="1">
248 <name>frameShadow</name>
249 <enum>Sunken</enum>
250 </property>
251 <property stdset="1">
252 <name>text</name>
253 <string></string>
254 </property>
255 </widget>
256 <widget row="2" column="0" >
257 <class>QLabel</class>
258 <property stdset="1">
259 <name>name</name>
260 <cstring>TextLabel9</cstring>
261 </property>
262 <property stdset="1">
263 <name>text</name>
264 <string>Lease Expires</string>
265 </property>
266 </widget>
267 <widget row="1" column="0" >
268 <class>QLabel</class>
269 <property stdset="1">
270 <name>name</name>
271 <cstring>TextLabel8</cstring>
272 </property>
273 <property stdset="1">
274 <name>text</name>
275 <string>Lease Obtained</string>
276 </property>
277 </widget>
278 <widget row="0" column="1" >
279 <class>QLabel</class>
280 <property stdset="1">
281 <name>name</name>
282 <cstring>dhcpServerLabel</cstring>
283 </property>
284 <property stdset="1">
285 <name>frameShape</name>
286 <enum>Panel</enum>
287 </property>
288 <property stdset="1">
289 <name>frameShadow</name>
290 <enum>Sunken</enum>
291 </property>
292 <property stdset="1">
293 <name>text</name>
294 <string></string>
295 </property>
296 </widget>
297 </grid>
298 </widget>
299 <spacer row="6" column="1" >
300 <property>
301 <name>name</name>
302 <cstring>Spacer2</cstring>
303 </property>
304 <property stdset="1">
305 <name>orientation</name>
306 <enum>Vertical</enum>
307 </property>
308 <property stdset="1">
309 <name>sizeType</name>
310 <enum>Expanding</enum>
311 </property>
312 <property>
313 <name>sizeHint</name>
314 <size>
315 <width>20</width>
316 <height>20</height>
317 </size>
318 </property>
319 </spacer>
320 </grid>
321</widget>
322<customwidgets>
323 <customwidget>
324 <class>QWidget</class>
325 <header location="local">qwidget.h</header>
326 <sizehint>
327 <width>100</width>
328 <height>100</height>
329 </sizehint>
330 <container>0</container>
331 <sizepolicy>
332 <hordata>7</hordata>
333 <verdata>7</verdata>
334 </sizepolicy>
335 <pixmap>image0</pixmap>
336 </customwidget>
337</customwidgets>
338<images>
339 <image>
340 <name>image0</name>
341 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
342 </image>
343</images>
344</UI>
diff --git a/noncore/net/networksetup/interfaces/interfaceinformation.ui b/noncore/net/networksetup/interfaces/interfaceinformation.ui
new file mode 100644
index 0000000..2838d19
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfaceinformation.ui
@@ -0,0 +1,343 @@
1<!DOCTYPE UI><UI>
2<class>InterfaceInformation</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>InterfaceInformation</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>219</width>
15 <height>255</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Interface Information</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget row="4" column="0" rowspan="1" colspan="2" >
32 <class>QLayoutWidget</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>Layout1</cstring>
36 </property>
37 <grid>
38 <property stdset="1">
39 <name>margin</name>
40 <number>0</number>
41 </property>
42 <property stdset="1">
43 <name>spacing</name>
44 <number>6</number>
45 </property>
46 <widget row="1" column="0" >
47 <class>QPushButton</class>
48 <property stdset="1">
49 <name>name</name>
50 <cstring>refreshButton</cstring>
51 </property>
52 <property stdset="1">
53 <name>text</name>
54 <string>&amp;Refresh</string>
55 </property>
56 </widget>
57 <widget row="0" column="1" >
58 <class>QPushButton</class>
59 <property stdset="1">
60 <name>name</name>
61 <cstring>stopButton</cstring>
62 </property>
63 <property stdset="1">
64 <name>text</name>
65 <string>S&amp;top</string>
66 </property>
67 </widget>
68 <widget row="1" column="1" >
69 <class>QPushButton</class>
70 <property stdset="1">
71 <name>name</name>
72 <cstring>restartButton</cstring>
73 </property>
74 <property stdset="1">
75 <name>text</name>
76 <string>R&amp;estart</string>
77 </property>
78 </widget>
79 <widget row="0" column="0" >
80 <class>QPushButton</class>
81 <property stdset="1">
82 <name>name</name>
83 <cstring>startButton</cstring>
84 </property>
85 <property stdset="1">
86 <name>text</name>
87 <string>&amp;Start</string>
88 </property>
89 </widget>
90 </grid>
91 </widget>
92 <widget row="0" column="0" >
93 <class>Line</class>
94 <property stdset="1">
95 <name>name</name>
96 <cstring>Line1</cstring>
97 </property>
98 <property stdset="1">
99 <name>orientation</name>
100 <enum>Horizontal</enum>
101 </property>
102 </widget>
103 <widget row="0" column="0" >
104 <class>QLabel</class>
105 <property stdset="1">
106 <name>name</name>
107 <cstring>TextLabel22</cstring>
108 </property>
109 <property stdset="1">
110 <name>text</name>
111 <string>IP Address</string>
112 </property>
113 </widget>
114 <widget row="1" column="0" >
115 <class>QLabel</class>
116 <property stdset="1">
117 <name>name</name>
118 <cstring>TextLabel23</cstring>
119 </property>
120 <property stdset="1">
121 <name>text</name>
122 <string>Subnet Mask</string>
123 </property>
124 </widget>
125 <widget row="2" column="0" >
126 <class>QLabel</class>
127 <property stdset="1">
128 <name>name</name>
129 <cstring>TextLabel21</cstring>
130 </property>
131 <property stdset="1">
132 <name>text</name>
133 <string>MAC Address</string>
134 </property>
135 </widget>
136 <widget row="3" column="0" >
137 <class>QLabel</class>
138 <property stdset="1">
139 <name>name</name>
140 <cstring>TextLabel24</cstring>
141 </property>
142 <property stdset="1">
143 <name>frameShape</name>
144 <enum>MShape</enum>
145 </property>
146 <property stdset="1">
147 <name>frameShadow</name>
148 <enum>MShadow</enum>
149 </property>
150 <property stdset="1">
151 <name>text</name>
152 <string>Broadcast</string>
153 </property>
154 </widget>
155 <widget row="1" column="1" >
156 <class>QLabel</class>
157 <property stdset="1">
158 <name>name</name>
159 <cstring>subnetMaskLabel</cstring>
160 </property>
161 <property stdset="1">
162 <name>frameShape</name>
163 <enum>Panel</enum>
164 </property>
165 <property stdset="1">
166 <name>frameShadow</name>
167 <enum>Sunken</enum>
168 </property>
169 <property stdset="1">
170 <name>text</name>
171 <string>0.0.0.0</string>
172 </property>
173 </widget>
174 <widget row="2" column="1" >
175 <class>QLabel</class>
176 <property stdset="1">
177 <name>name</name>
178 <cstring>macAddressLabel</cstring>
179 </property>
180 <property stdset="1">
181 <name>frameShape</name>
182 <enum>Panel</enum>
183 </property>
184 <property stdset="1">
185 <name>frameShadow</name>
186 <enum>Sunken</enum>
187 </property>
188 <property stdset="1">
189 <name>text</name>
190 <string>00:00:00:00:00:00</string>
191 </property>
192 </widget>
193 <widget row="3" column="1" >
194 <class>QLabel</class>
195 <property stdset="1">
196 <name>name</name>
197 <cstring>broadcastLabel</cstring>
198 </property>
199 <property stdset="1">
200 <name>frameShape</name>
201 <enum>Panel</enum>
202 </property>
203 <property stdset="1">
204 <name>frameShadow</name>
205 <enum>Sunken</enum>
206 </property>
207 <property stdset="1">
208 <name>text</name>
209 <string></string>
210 </property>
211 </widget>
212 <widget row="0" column="1" >
213 <class>QLabel</class>
214 <property stdset="1">
215 <name>name</name>
216 <cstring>ipAddressLabel</cstring>
217 </property>
218 <property stdset="1">
219 <name>frameShape</name>
220 <enum>Panel</enum>
221 </property>
222 <property stdset="1">
223 <name>frameShadow</name>
224 <enum>Sunken</enum>
225 </property>
226 <property stdset="1">
227 <name>text</name>
228 <string>0.0.0.0</string>
229 </property>
230 </widget>
231 <spacer row="7" column="1" >
232 <property>
233 <name>name</name>
234 <cstring>Spacer18</cstring>
235 </property>
236 <property stdset="1">
237 <name>orientation</name>
238 <enum>Vertical</enum>
239 </property>
240 <property stdset="1">
241 <name>sizeType</name>
242 <enum>Expanding</enum>
243 </property>
244 <property>
245 <name>sizeHint</name>
246 <size>
247 <width>20</width>
248 <height>20</height>
249 </size>
250 </property>
251 </spacer>
252 <widget row="6" column="0" rowspan="1" colspan="2" >
253 <class>QLayoutWidget</class>
254 <property stdset="1">
255 <name>name</name>
256 <cstring>Layout2</cstring>
257 </property>
258 <hbox>
259 <property stdset="1">
260 <name>margin</name>
261 <number>0</number>
262 </property>
263 <property stdset="1">
264 <name>spacing</name>
265 <number>6</number>
266 </property>
267 <spacer>
268 <property>
269 <name>name</name>
270 <cstring>Spacer10</cstring>
271 </property>
272 <property stdset="1">
273 <name>orientation</name>
274 <enum>Horizontal</enum>
275 </property>
276 <property stdset="1">
277 <name>sizeType</name>
278 <enum>Expanding</enum>
279 </property>
280 <property>
281 <name>sizeHint</name>
282 <size>
283 <width>20</width>
284 <height>20</height>
285 </size>
286 </property>
287 </spacer>
288 <widget>
289 <class>QPushButton</class>
290 <property stdset="1">
291 <name>name</name>
292 <cstring>advancedButton</cstring>
293 </property>
294 <property stdset="1">
295 <name>text</name>
296 <string>View &amp;Advanced Information</string>
297 </property>
298 </widget>
299 </hbox>
300 </widget>
301 <widget row="5" column="0" rowspan="1" colspan="2" >
302 <class>Line</class>
303 <property stdset="1">
304 <name>name</name>
305 <cstring>Line5</cstring>
306 </property>
307 <property stdset="1">
308 <name>orientation</name>
309 <enum>Horizontal</enum>
310 </property>
311 </widget>
312 </grid>
313</widget>
314<customwidgets>
315 <customwidget>
316 <class>QWidget</class>
317 <header location="local">qwidget.h</header>
318 <sizehint>
319 <width>100</width>
320 <height>100</height>
321 </sizehint>
322 <container>0</container>
323 <sizepolicy>
324 <hordata>7</hordata>
325 <verdata>7</verdata>
326 </sizepolicy>
327 <pixmap>image0</pixmap>
328 </customwidget>
329</customwidgets>
330<images>
331 <image>
332 <name>image0</name>
333 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
334 </image>
335</images>
336<tabstops>
337 <tabstop>startButton</tabstop>
338 <tabstop>stopButton</tabstop>
339 <tabstop>refreshButton</tabstop>
340 <tabstop>restartButton</tabstop>
341 <tabstop>advancedButton</tabstop>
342</tabstops>
343</UI>
diff --git a/noncore/net/networksetup/interfaces/interfaceinformationimp.cpp b/noncore/net/networksetup/interfaces/interfaceinformationimp.cpp
new file mode 100644
index 0000000..43483fb
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfaceinformationimp.cpp
@@ -0,0 +1,70 @@
1#include "interfaceinformationimp.h"
2#include "interfaceadvanced.h"
3
4#include <qpushbutton.h>
5#include <qlabel.h>
6#include <qgroupbox.h>
7#include <assert.h>
8
9/**
10 * Constructor for the InterfaceInformationImp class. This class pretty much
11 * just display's information about the interface that is passed to it.
12 */
13InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){
14 assert(i);
15
16 interface = i;
17 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
18 updateInterface(interface);
19 connect(startButton, SIGNAL(clicked()), interface, SLOT(start()));
20 connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop()));
21 connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart()));
22 connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh()));
23 connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced()));
24
25}
26
27/**
28 * Update the interface information and buttons.
29 * @param Intarface *i the interface to update (should be the one we already
30 * know about).
31 */
32void InterfaceInformationImp::updateInterface(Interface *i){
33 if(interface->getStatus()){
34 startButton->setEnabled(false);
35 stopButton->setEnabled(true);
36 restartButton->setEnabled(true);
37 }
38 else{
39 startButton->setEnabled(true);
40 stopButton->setEnabled(false);
41 restartButton->setEnabled(false);
42 }
43 macAddressLabel->setText(interface->getMacAddress());
44 ipAddressLabel->setText(interface->getIp());
45 subnetMaskLabel->setText(interface->getSubnetMask());
46 broadcastLabel->setText(interface->getBroadcast());
47}
48
49/**
50 * Create the advanced widget. Fill it with the current interface's information.
51 * Display it.
52 */
53void InterfaceInformationImp::advanced(){
54 InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced");
55 a->interfaceName->setText(interface->getInterfaceName());
56 a->macAddressLabel->setText(interface->getMacAddress());
57 a->ipAddressLabel->setText(interface->getIp());
58 a->subnetMaskLabel->setText(interface->getSubnetMask());
59 a->broadcastLabel->setText(interface->getBroadcast());
60 a->dhcpServerLabel->setText(interface->getDhcpServerIp());
61 a->leaseObtainedLabel->setText(interface->getLeaseObtained());
62 a->leaseExpiresLabel->setText(interface->getLeaseExpires());
63 a->dhcpInformation->setEnabled(interface->isDhcp());
64
65 a->showMaximized();
66 a->show();
67}
68
69// infoimp.cpp
70
diff --git a/noncore/net/networksetup/interfaces/interfaceinformationimp.h b/noncore/net/networksetup/interfaces/interfaceinformationimp.h
new file mode 100644
index 0000000..42213cc
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfaceinformationimp.h
@@ -0,0 +1,27 @@
1#ifndef INTERFACEINFORMATIONIMP_H
2#define INTERFACEINFORMATIONIMP_H
3
4#include "interfaceinformation.h"
5#include "interface.h"
6
7class InterfaceInformationImp : public InterfaceInformation {
8
9Q_OBJECT
10
11public:
12 InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0);
13 ~InterfaceInformationImp(){};
14
15private slots:
16 void advanced();
17 void updateInterface(Interface *i);
18
19private:
20 Interface *interface;
21
22};
23
24#endif
25
26// addserviceimp.h
27
diff --git a/noncore/net/networksetup/interfaces/interfaces.cpp b/noncore/net/networksetup/interfaces/interfaces.cpp
new file mode 100644
index 0000000..377a6db
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfaces.cpp
@@ -0,0 +1,638 @@
1#include "interfaces.h"
2
3#include <qfile.h>
4#include <qtextstream.h>
5#include <qregexp.h>
6
7#define AUTO "auto"
8#define IFACE "iface"
9#define MAPPING "mapping"
10
11/**
12 * Constructor. Reads in the interfaces file and then split the file up by
13 * the \n for interfaces variable.
14 * @param useInterfacesFile if an interface file other then the default is
15 * desired to be used it should be passed in.
16 */
17Interfaces::Interfaces(QString useInterfacesFile){
18 acceptedFamily.append(INTERFACES_FAMILY_INET);
19 acceptedFamily.append(INTERFACES_FAMILY_IPX);
20 acceptedFamily.append(INTERFACES_FAMILY_INET6);
21
22 interfacesFile = useInterfacesFile;
23 QFile file(interfacesFile);
24 if (!file.open(IO_ReadOnly)){
25 qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1());
26 currentIface = interfaces.end();
27 currentMapping = interfaces.end();
28 return;
29 }
30 QTextStream stream( &file );
31 QString line;
32 while ( !stream.eof() ) {
33 line += stream.readLine();
34 line += "\n";
35 }
36 file.close();
37 interfaces = QStringList::split("\n", line, true);
38
39 currentIface = interfaces.end();
40 currentMapping = interfaces.end();
41}
42
43
44/**
45 * Get a list of all interfaces in the interface file. Usefull for
46 * hardware that is not currently connected such as an 802.11b card
47 * not plugged in, but configured for when it is plugged in.
48 * @return Return string list of interfaces.
49 **/
50QStringList Interfaces::getInterfaceList(){
51 QStringList list;
52 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
53 QString line = (*it).simplifyWhiteSpace();
54 if(line.contains(IFACE) && line.at(0) != '#'){
55 line = line.mid(QString(IFACE).length() +1, line.length());
56 line = line.simplifyWhiteSpace();
57 int findSpace = line.find(" ");
58 if( findSpace >= 0){
59 line = line.mid(0, findSpace);
60 list.append(line);
61 }
62 }
63 }
64 return list;
65}
66
67/**
68 * Find out if interface is in an "auto" group or not.
69 * Report any duplicates such as eth0 being in two differnt auto's
70 * @param interface interface to check to see if it is on or not.
71 * @return true is interface is in auto
72 */
73bool Interfaces::isAuto(QString interface){
74 QStringList autoLines = interfaces.grep(QRegExp(AUTO));
75 QStringList awi = autoLines.grep(QRegExp(interface));
76 if(awi.count() > 1)
77 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1());
78 if(awi.count() < 1)
79 return false;
80 return true;
81}
82
83/**
84 * Attempt to set the auto option for interface to setAuto.
85 * @param interface the interface to set
86 * @param setAuto the value to set interface to.
87 * @return false if already set to setAuto.
88 * */
89bool Interfaces::setAuto(QString interface, bool setAuto){
90 // Don't need to set it if it is already set.
91 if(isAuto(interface) == setAuto)
92 return false;
93
94 bool changed = false;
95 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
96 if((*it).contains(AUTO)){
97 //We know that they are not in any group so let add to this auto.
98 if(setAuto){
99 (*it) = (*it) += " " + interface;
100 // Don't care to have such thins as: auto eth0 lo usb0
101 (*it) = (*it).simplifyWhiteSpace();
102 changed = true;
103 break;
104 }
105 else{
106 if((*it).contains(interface)){
107 (*it) = (*it).replace(QRegExp(interface), "");
108 // clean up
109 QString line = (*it).simplifyWhiteSpace();
110 line = line.replace(QRegExp(" "),"");
111 if(line == AUTO)
112 (*it) = "";
113 changed = true;
114 // Don't break because we want to make sure we remove all cases.
115 }
116 }
117 }
118 }
119 if(changed == false){
120 if(setAuto == true)
121 interfaces.append(QString(AUTO" %1").arg(interface));
122 else{
123 qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1());
124 }
125 }
126 return true;
127}
128
129/**
130 * Set the current interface to interface. This needs to be done before you
131 * can call getFamily(), getMethod, and get/setOption().
132 * @param interface the name of the interface to set. All whitespace is
133 * removed from the interface name.
134 * @return bool true if it is successfull.
135 */
136bool Interfaces::setInterface(QString interface){
137 interface = interface.simplifyWhiteSpace();
138 interface = interface.replace(QRegExp(" "), "");
139 return setStanza(IFACE, interface, currentIface);
140}
141
142/**
143 * A quick helper funtion to see if the current interface is set.
144 * @return bool true if set, false otherwise.
145 */
146bool Interfaces::isInterfaceSet(){
147 return (currentIface != interfaces.end());
148}
149
150/**
151 * Add a new interface of with the settings - family and method
152 * @param interface the name of the interface to set. All whitespace is
153 * removed from the interface name.
154 * @param family the family of this interface inet or inet, ipx or inet6
155 * Must of one of the families defined in interfaces.h
156 * @param method for the family. see interfaces man page for family methods.
157 * @return true if successfull.
158 */
159bool Interfaces::addInterface(QString interface, QString family, QString method){
160 if(acceptedFamily.contains(family)==0)
161 return false;
162 interface = interface.simplifyWhiteSpace();
163 interface = interface.replace(QRegExp(" "), "");
164 interfaces.append("");
165 interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method));
166 return true;
167}
168
169/**
170 * Copies interface with name interface to name newInterface
171 * @param newInterface name of the new interface.
172 * @return bool true if successfull
173 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){
175 if(!setInterface(interface)) return false;
176
177 QStringList::Iterator it = currentIface;
178 it++;
179
180 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false;
183 QStringList::Iterator newIface = currentIface;
184 newIface++;
185
186 for ( it; it != interfaces.end(); ++it ){
187 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
188 break;
189 newIface = interfaces.insert(newIface, *it);
190 }
191
192 return true;
193}
194
195/**
196 * Remove the currently selected interface and all of its options.
197 * @return bool if successfull or not.
198 */
199bool Interfaces::removeInterface(){
200 if(currentIface == interfaces.end())
201 return false;
202 (*currentIface) = "";
203 return removeAllInterfaceOptions();
204}
205
206/**
207 * Gets the hardware name of the interface that is currently selected.
208 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
209 * @param error set to true if any error occurs, false otherwise.
210 */
211QString Interfaces::getInterfaceName(bool &error){
212 if(currentIface == interfaces.end()){
213 error = true;
214 return QString();
215 }
216 QString line = (*currentIface);
217 line = line.mid(QString(IFACE).length() +1, line.length());
218 line = line.simplifyWhiteSpace();
219 int findSpace = line.find(" ");
220 if( findSpace < 0){
221 error = true;
222 return QString();
223 }
224 error = false;
225 return line.mid(0, findSpace);
226}
227
228/**
229 * Gets the family name of the interface that is currently selected.
230 * @return QString name of the family (inet, inet6, ipx).
231 * @param error set to true if any error occurs, false otherwise.
232 */
233QString Interfaces::getInterfaceFamily(bool &error){
234 QString name = getInterfaceName(error);
235 if(error){
236 error = true;
237 return QString();
238 }
239 QString line = (*currentIface);
240 line = line.mid(QString(IFACE).length() +1, line.length());
241 line = line.mid(name.length()+1, line.length());
242 line = line.simplifyWhiteSpace();
243 int findSpace = line.find(" ");
244 if( findSpace < 0){
245 error = true;
246 return QString();
247 }
248 error = false;
249 return line.mid(0, findSpace);
250}
251
252/**
253 * Gets the method of the interface that is currently selected.
254 * @return QString name of the method such as staic or dhcp.
255 * See the man page of interfaces for possible methods depending on the family.
256 * @param error set to true if any error occurs, false otherwise.
257 */
258QString Interfaces::getInterfaceMethod(bool &error){
259 QString name = getInterfaceName(error);
260 if(error){
261 error = true;
262 return QString();
263 }
264 QString family = getInterfaceFamily(error);
265 if(error){
266 error = true;
267 return QString();
268 }
269 QString line = (*currentIface);
270 line = line.mid(QString(IFACE).length()+1, line.length());
271 line = line.mid(name.length()+1, line.length());
272 line = line.mid(family.length()+1, line.length());
273 line = line.simplifyWhiteSpace();
274 error = false;
275 return line;
276}
277
278/**
279 * Sets the interface name to newName.
280 * @param newName the new name of the interface. All whitespace is removed.
281 * @return bool true if successfull.
282 */
283bool Interfaces::setInterfaceName(QString newName){
284 if(currentIface == interfaces.end())
285 return false;
286 newName = newName.simplifyWhiteSpace();
287 newName = newName.replace(QRegExp(" "), "");
288 bool returnValue = false;
289 (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
290 return !returnValue;
291}
292
293/**
294 * Sets the interface family to newName.
295 * @param newName the new name of the interface. Must be one of the families
296 * defined in the interfaces.h file.
297 * @return bool true if successfull.
298 */
299bool Interfaces::setInterfaceFamily(QString newName){
300 if(currentIface == interfaces.end())
301 return false;
302 if(acceptedFamily.contains(newName)==0)
303 return false;
304 bool returnValue = false;
305 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue));
306 return !returnValue;
307}
308
309/**
310 * Sets the interface method to newName
311 * @param newName the new name of the interface
312 * @return bool true if successfull.
313 */
314bool Interfaces::setInterfaceMethod(QString newName){
315 if(currentIface == interfaces.end())
316 return false;
317 bool returnValue = false;
318 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName);
319 return !returnValue;
320}
321
322/**
323 * Get a value for an option in the currently selected interface. For example
324 * calling getInterfaceOption("address") on the following stanza would
325 * return 192.168.1.1.
326 * iface eth0 static
327 * address 192.168.1.1
328 * @param option the options to get the value.
329 * @param error set to true if any error occurs, false otherwise.
330 * @return QString the options value. QString::null if error == true
331 */
332QString Interfaces::getInterfaceOption(QString option, bool &error){
333 return getOption(currentIface, option, error);
334}
335
336/**
337 * Set a value for an option in the currently selected interface. If option
338 * doesn't exist then it is added along with the value.
339 * @param option the options to set the value.
340 * @param value the value that option should be set to.
341 * @param error set to true if any error occurs, false otherwise.
342 * @return QString the options value. QString::null if error == true
343 */
344bool Interfaces::setInterfaceOption(QString option, QString value){
345 return setOption(currentIface, option, value);
346}
347
348/**
349 * Removes a value for an option in the currently selected interface.
350 * @param option the options to set the value.
351 * @param value the value that option should be set to.
352 * @param error set to true if any error occurs, false otherwise.
353 * @return QString the options value. QString::null if error == true
354 */
355bool Interfaces::removeInterfaceOption(QString option, QString value){
356 return removeOption(currentIface, option, value);
357}
358
359/**
360 * Removes all of the options from the currently selected interface.
361 * @return bool error if if successfull
362 */
363bool Interfaces::removeAllInterfaceOptions(){
364 return removeAllOptions(currentIface);
365}
366
367/**
368 * Set the current map to interface's map. This needs to be done before you
369 * can call addMapping(), set/getMap(), and get/setScript().
370 * @param interface the name of the interface to set. All whitespace is
371 * removed from the interface name.
372 * @return bool true if it is successfull.
373 */
374bool Interfaces::setMapping(QString interface){
375 interface = interface.simplifyWhiteSpace();
376 interface = interface.replace(QRegExp(" "), "");
377 return setStanza(MAPPING, interface, currentMapping);
378}
379
380/**
381 * Adds a new Mapping to the interfaces file with interfaces.
382 * @param interface the name(s) of the interfaces to set to this mapping
383 */
384void Interfaces::addMapping(QString option){
385 interfaces.append("");
386 interfaces.append(QString(MAPPING " %1").arg(option));
387}
388
389/**
390 * Remove the currently selected map and all of its options.
391 * @return bool if successfull or not.
392 */
393bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end())
395 return false;
396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping);
398}
399
400/**
401 * Set a map option within a mapping.
402 * @param map map to use
403 * @param value value to go with map
404 * @return bool true if it is successfull.
405 */
406bool Interfaces::setMap(QString map, QString value){
407 return setOption(currentMapping, map, value);
408}
409
410/**
411 * Removes a map option within a mapping.
412 * @param map map to use
413 * @param value value to go with map
414 * @return bool true if it is successfull.
415 */
416bool Interfaces::removeMap(QString map, QString value){
417 return removeOption(currentMapping, map, value);
418}
419
420/**
421 * Get a map value within a mapping.
422 * @param map map to get value of
423 * @param bool true if it is successfull.
424 * @return value that goes to the map
425 */
426QString Interfaces::getMap(QString map, bool &error){
427 return getOption(currentMapping, map, error);
428}
429
430/**
431 * Sets a script value of the current mapping to argument.
432 * @param argument the script name.
433 * @return true if successfull.
434 */
435bool Interfaces::setScript(QString argument){
436 return setOption(currentMapping, "script", argument);
437}
438
439/**
440 * @param error true if could not retrieve the current script argument.
441 * @return QString the argument of the script for the current mapping.
442 */
443QString Interfaces::getScript(bool &error){
444 return getOption(currentMapping, "script", error);
445}
446
447/**
448 * Helper function used to parse through the QStringList and put pointers in
449 * the correct place.
450 * @param stanza The stanza (auto, iface, mapping) to look for.
451 * @param option string that must be in the stanza's main line.
452 * @param interator interator to place at location of stanza if successfull.
453 * @return bool true if the stanza is found.
454 */
455bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
456 bool found = false;
457 iterator = interfaces.end();
458 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
459 QString line = (*it).simplifyWhiteSpace();
460 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){
461 uint point = line.find(option);
462 bool valid = true;
463 if(point > 0){
464 // There are more chars in the line. check +1
465 if(line.at(point-1) != ' ')
466 valid = false;
467 }
468 point += option.length();
469 if(point < line.length()-1){
470 // There are more chars in the line. check -1
471 if(line.at(point) != ' ')
472 valid = false;
473 }
474 if(valid){
475 if(found == true){
476 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
477 }
478 found = true;
479 iterator = it;
480 }
481 }
482 }
483 return found;
484}
485
486/**
487 * Sets a value of an option in a stanza
488 * @param start the start of the stanza
489 * @param option the option to use when setting value.
490 * @return bool true if successfull, false otherwise.
491 */
492bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){
493 if(start == interfaces.end())
494 return false;
495
496 bool found = false;
497 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
498 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
499 if(!found && value != ""){
500 // Got to the end of the stanza without finding it, so append it.
501 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
502 }
503 found = true;
504 break;
505 }
506 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
507 // Found it in stanza so replace it.
508 if(found)
509 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
510 found = true;
511 (*it) = QString("\t%1 %2").arg(option).arg(value);
512 }
513 }
514 if(!found){
515 QStringList::Iterator p = start;
516 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
517 found = true;
518 }
519 return found;
520}
521/**
522 * Removes a option in a stanza
523 * @param start the start of the stanza
524 * @param option the option to use when setting value.
525 * @return bool true if successfull, false otherwise.
526 */
527bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){
528 if(start == interfaces.end())
529 return false;
530
531 bool found = false;
532 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
533 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
534 // got to the end without finding it
535 break;
536 }
537 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){
538 // Found it in stanza so replace it.
539 if(found)
540 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
541 found = true;
542 (*it) = "";
543 }
544 }
545 return found;
546}
547
548/**
549 * Removes all options in a stanza
550 * @param start the start of the stanza
551 * @return bool true if successfull, false otherwise.
552 */
553bool Interfaces::removeAllOptions(QStringList::Iterator start){
554 if(start == interfaces.end())
555 return false;
556
557 QStringList::Iterator it = start;
558 it = ++it;
559 for (it; it != interfaces.end(); ++it ) {
560 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
561 break;
562 }
563 it = interfaces.remove(it);
564 it = --it;
565 }
566 // Leave a space between this interface and the next.
567 interfaces.insert(it, QString(""));
568 return true;
569}
570
571/**
572 * Gets a value of an option in a stanza
573 * @param start the start of the stanza
574 * @param option the option to use when getting the value.
575 * @param bool true if errors false otherwise.
576 * @return QString the value of option QString::null() if error == true.
577 */
578QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){
579 if(start == interfaces.end()){
580 error = false;
581 return QString();
582 }
583
584 QString value;
585 bool found = false;
586 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
587 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
588 break;
589 }
590 if((*it).contains(option) && (*it).at(0) != '#'){
591 if(found)
592 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
593 found = true;
594 QString line = (*it).simplifyWhiteSpace();
595 int space = line.find(" ", option.length());
596 if(space != -1)
597 value = line.mid(space+1, line.length());
598 else
599 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1());
600 }
601 }
602 error = !found;
603 return value;
604}
605
606/**
607 * Write out the interfaces file to the file passed into the constructor.
608 * Removes any excess blank lines over 1 line long.
609 * @return bool true if successfull, false if not.
610 */
611bool Interfaces::write(){
612 QFile::remove(interfacesFile);
613 QFile file(interfacesFile);
614
615 if (!file.open(IO_ReadWrite)){
616 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1());
617 return false;
618 }
619 QTextStream stream( &file );
620 int whiteSpaceCount = 0;
621 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
622 QString line = (*it).simplifyWhiteSpace();
623 line = line.replace(QRegExp(" "),"");
624 if(line.length() == 0)
625 whiteSpaceCount++;
626 else
627 whiteSpaceCount = 0;
628 if(whiteSpaceCount < 2){
629 qDebug((*it).latin1());
630 stream << (*it) << '\n';
631 }
632 }
633 file.close();
634 return true;
635}
636
637// interfaces.cpp
638
diff --git a/noncore/net/networksetup/interfaces/interfaces.h b/noncore/net/networksetup/interfaces/interfaces.h
new file mode 100644
index 0000000..e09ea71
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfaces.h
@@ -0,0 +1,76 @@
1#ifndef INTERFACES_H
2#define INTERFACES_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6
7#define INTERFACES_LOOPBACK "loopback"
8
9#define INTERFACES_FAMILY_INET "inet"
10#define INTERFACES_FAMILY_IPX "ipx"
11#define INTERFACES_FAMILY_INET6 "inet6"
12
13#define INTERFACES_METHOD_DHCP "dhcp"
14#define INTERFACES_METHOD_STATIC "static"
15#define INTERFACES_METHOD_PPP "ppp"
16
17/**
18 * This class provides a clean frontend for parsing the network interfaces file.
19 * It provides helper functions to minipulate the options within the file.
20 * See the interfaces man page for the syntax rules.
21 */
22class Interfaces {
23
24public:
25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
26 QStringList getInterfaceList();
27
28 bool isAuto(QString interface);
29 bool setAuto(QString interface, bool setAuto);
30
31 bool removeInterface();
32 bool addInterface(QString interface, QString family, QString method);
33 bool copyInterface(QString oldInterface, QString newInterface);
34 bool setInterface(QString interface);
35 bool isInterfaceSet();
36 QString getInterfaceName(bool &error);
37 bool setInterfaceName(QString newName);
38 QString getInterfaceFamily(bool &error);
39 bool setInterfaceFamily(QString newName);
40 QString getInterfaceMethod(bool &error);
41 bool setInterfaceMethod(QString newName);
42 QString getInterfaceOption(QString option, bool &error);
43 bool setInterfaceOption(QString option, QString value);
44 bool removeInterfaceOption(QString option, QString value);
45 bool removeAllInterfaceOptions();
46
47 bool setMapping(QString interface);
48 bool removeMapping();
49 void addMapping(QString options);
50 bool setMap(QString map, QString value);
51 bool removeMap(QString map, QString value);
52 QString getMap(QString map, bool &error);
53 bool setScript(QString);
54 QString getScript(bool &error);
55
56 bool write();
57
58private:
59 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
60 bool setOption(QStringList::Iterator start, QString option, QString value);
61 bool removeOption(QStringList::Iterator start, QString option, QString value);
62 QString getOption(QStringList::Iterator start, QString option, bool &error);
63 bool removeAllOptions(QStringList::Iterator start);
64
65 QString interfacesFile;
66 QStringList interfaces;
67 QStringList::Iterator currentIface;
68 QStringList::Iterator currentMapping;
69
70 QStringList acceptedFamily;
71};
72
73#endif
74
75// interfaces
76
diff --git a/noncore/net/networksetup/interfaces/interfaces.pro b/noncore/net/networksetup/interfaces/interfaces.pro
new file mode 100644
index 0000000..fb13278
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfaces.pro
@@ -0,0 +1,12 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug
4DESTDIR = $(OPIEDIR)/plugins/networksetup
5 HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h
6 SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp
7 INCLUDEPATH+= $(OPIEDIR)/include ../
8 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe
10 INTERFACES= interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui
11 TARGET = interfaces
12 VERSION = 1.0.0
diff --git a/noncore/net/networksetup/interfaces/interfacesetup.ui b/noncore/net/networksetup/interfaces/interfacesetup.ui
new file mode 100644
index 0000000..ab8e413
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfacesetup.ui
@@ -0,0 +1,284 @@
1<!DOCTYPE UI><UI>
2<class>InterfaceSetup</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>InterfaceSetup</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>290</width>
15 <height>280</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Interface Configuration</string>
21 </property>
22 <vbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QCheckBox</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>autoStart</cstring>
36 </property>
37 <property stdset="1">
38 <name>text</name>
39 <string>Automatically bring up</string>
40 </property>
41 </widget>
42 <widget>
43 <class>QLayoutWidget</class>
44 <property stdset="1">
45 <name>name</name>
46 <cstring>Layout9</cstring>
47 </property>
48 <hbox>
49 <property stdset="1">
50 <name>margin</name>
51 <number>0</number>
52 </property>
53 <property stdset="1">
54 <name>spacing</name>
55 <number>6</number>
56 </property>
57 <widget>
58 <class>QCheckBox</class>
59 <property stdset="1">
60 <name>name</name>
61 <cstring>dhcpCheckBox</cstring>
62 </property>
63 <property stdset="1">
64 <name>text</name>
65 <string>DHCP</string>
66 </property>
67 <property stdset="1">
68 <name>checked</name>
69 <bool>true</bool>
70 </property>
71 </widget>
72 <widget>
73 <class>QLabel</class>
74 <property stdset="1">
75 <name>name</name>
76 <cstring>leaseHoursLabel</cstring>
77 </property>
78 <property stdset="1">
79 <name>text</name>
80 <string>Requested Lease</string>
81 </property>
82 </widget>
83 <widget>
84 <class>QSpinBox</class>
85 <property stdset="1">
86 <name>name</name>
87 <cstring>leaseTime</cstring>
88 </property>
89 <property stdset="1">
90 <name>suffix</name>
91 <string> hours</string>
92 </property>
93 <property stdset="1">
94 <name>maxValue</name>
95 <number>87600</number>
96 </property>
97 <property stdset="1">
98 <name>minValue</name>
99 <number>1</number>
100 </property>
101 <property stdset="1">
102 <name>value</name>
103 <number>168</number>
104 </property>
105 </widget>
106 </hbox>
107 </widget>
108 <widget>
109 <class>QGroupBox</class>
110 <property stdset="1">
111 <name>name</name>
112 <cstring>staticGroupBox</cstring>
113 </property>
114 <property stdset="1">
115 <name>enabled</name>
116 <bool>false</bool>
117 </property>
118 <property stdset="1">
119 <name>frameShape</name>
120 <enum>Box</enum>
121 </property>
122 <property stdset="1">
123 <name>frameShadow</name>
124 <enum>Sunken</enum>
125 </property>
126 <property stdset="1">
127 <name>title</name>
128 <string>Static Ip Configuration</string>
129 </property>
130 <grid>
131 <property stdset="1">
132 <name>margin</name>
133 <number>11</number>
134 </property>
135 <property stdset="1">
136 <name>spacing</name>
137 <number>6</number>
138 </property>
139 <widget row="1" column="0" >
140 <class>QLabel</class>
141 <property stdset="1">
142 <name>name</name>
143 <cstring>TextLabel5</cstring>
144 </property>
145 <property stdset="1">
146 <name>text</name>
147 <string>Subnet Mask</string>
148 </property>
149 </widget>
150 <widget row="2" column="1" >
151 <class>QLineEdit</class>
152 <property stdset="1">
153 <name>name</name>
154 <cstring>gatewayEdit</cstring>
155 </property>
156 </widget>
157 <widget row="1" column="1" >
158 <class>QLineEdit</class>
159 <property stdset="1">
160 <name>name</name>
161 <cstring>subnetMaskEdit</cstring>
162 </property>
163 </widget>
164 <widget row="0" column="1" >
165 <class>QLineEdit</class>
166 <property stdset="1">
167 <name>name</name>
168 <cstring>ipAddressEdit</cstring>
169 </property>
170 </widget>
171 <widget row="3" column="0" >
172 <class>QLabel</class>
173 <property stdset="1">
174 <name>name</name>
175 <cstring>TextLabel2</cstring>
176 </property>
177 <property stdset="1">
178 <name>text</name>
179 <string>First DNS</string>
180 </property>
181 </widget>
182 <widget row="0" column="0" >
183 <class>QLabel</class>
184 <property stdset="1">
185 <name>name</name>
186 <cstring>TextLabel4</cstring>
187 </property>
188 <property stdset="1">
189 <name>text</name>
190 <string>IP Address</string>
191 </property>
192 </widget>
193 <widget row="2" column="0" >
194 <class>QLabel</class>
195 <property stdset="1">
196 <name>name</name>
197 <cstring>TextLabel1_2</cstring>
198 </property>
199 <property stdset="1">
200 <name>text</name>
201 <string>Gateway</string>
202 </property>
203 </widget>
204 <widget row="4" column="0" >
205 <class>QLabel</class>
206 <property stdset="1">
207 <name>name</name>
208 <cstring>TextLabel3</cstring>
209 </property>
210 <property stdset="1">
211 <name>text</name>
212 <string>Second DNS</string>
213 </property>
214 </widget>
215 <widget row="3" column="1" >
216 <class>QLineEdit</class>
217 <property stdset="1">
218 <name>name</name>
219 <cstring>firstDNSLineEdit</cstring>
220 </property>
221 </widget>
222 <widget row="4" column="1" >
223 <class>QLineEdit</class>
224 <property stdset="1">
225 <name>name</name>
226 <cstring>secondDNSLineEdit</cstring>
227 </property>
228 </widget>
229 </grid>
230 </widget>
231 <spacer>
232 <property>
233 <name>name</name>
234 <cstring>Spacer9</cstring>
235 </property>
236 <property stdset="1">
237 <name>orientation</name>
238 <enum>Vertical</enum>
239 </property>
240 <property stdset="1">
241 <name>sizeType</name>
242 <enum>Expanding</enum>
243 </property>
244 <property>
245 <name>sizeHint</name>
246 <size>
247 <width>20</width>
248 <height>20</height>
249 </size>
250 </property>
251 </spacer>
252 </vbox>
253</widget>
254<connections>
255 <connection>
256 <sender>dhcpCheckBox</sender>
257 <signal>toggled(bool)</signal>
258 <receiver>leaseHoursLabel</receiver>
259 <slot>setEnabled(bool)</slot>
260 </connection>
261 <connection>
262 <sender>dhcpCheckBox</sender>
263 <signal>toggled(bool)</signal>
264 <receiver>leaseTime</receiver>
265 <slot>setEnabled(bool)</slot>
266 </connection>
267 <connection>
268 <sender>dhcpCheckBox</sender>
269 <signal>toggled(bool)</signal>
270 <receiver>staticGroupBox</receiver>
271 <slot>setDisabled(bool)</slot>
272 </connection>
273</connections>
274<tabstops>
275 <tabstop>autoStart</tabstop>
276 <tabstop>dhcpCheckBox</tabstop>
277 <tabstop>leaseTime</tabstop>
278 <tabstop>ipAddressEdit</tabstop>
279 <tabstop>subnetMaskEdit</tabstop>
280 <tabstop>gatewayEdit</tabstop>
281 <tabstop>firstDNSLineEdit</tabstop>
282 <tabstop>secondDNSLineEdit</tabstop>
283</tabstops>
284</UI>
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
new file mode 100644
index 0000000..e717d6f
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp
@@ -0,0 +1,148 @@
1#include "interfacesetupimp.h"
2#include "interface.h"
3#include "interfaces.h"
4
5#include <qdialog.h>
6#include <qcombobox.h>
7#include <qcheckbox.h>
8#include <qlineedit.h>
9#include <qspinbox.h>
10#include <qgroupbox.h>
11#include <qlabel.h>
12
13#include <qmessagebox.h>
14
15#include <assert.h>
16
17#define DNSSCRIPT "interfacednsscript"
18
19/**
20 * Constuctor. Set up the connection and load the first profile.
21 */
22InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){
23 assert(parent);
24 assert(i);
25 interface = i;
26 interfaces = new Interfaces();
27 bool error = false;
28 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
29 staticGroupBox->hide();
30 dhcpCheckBox->hide();
31 leaseTime->hide();
32 leaseHoursLabel->hide();
33 }
34}
35
36/**
37 * Save the current settings, then write out the interfaces file and close.
38 */
39void InterfaceSetupImp::saveChanges(){
40 if(!saveSettings())
41 return;
42 interfaces->write();
43}
44
45/**
46 * Save the settings for the current Interface.
47 * @return bool true if successfull, false otherwise
48 */
49bool InterfaceSetupImp::saveSettings(){
50 // eh can't really do anything about it other then return. :-D
51 if(!interfaces->isInterfaceSet())
52 return true;
53
54 bool error = false;
55 // Loopback case
56 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
57 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
58 return true;
59 }
60
61 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){
62 QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok");
63 return false;
64 }
65 interfaces->removeAllInterfaceOptions();
66
67 // DHCP
68 if(dhcpCheckBox->isChecked()){
69 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
70 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
71 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
72 }
73 else{
74 interfaces->setInterfaceMethod("static");
75 interfaces->setInterfaceOption("address", ipAddressEdit->text());
76 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
77 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
78 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
79 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
80 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
81 }
82
83 // IP Information
84 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
85 return true;
86}
87
88/**
89 * The Profile has changed.
90 * @profile the new profile.
91 */
92void InterfaceSetupImp::setProfile(const QString &profile){
93 QString newInterfaceName = interface->getInterfaceName();
94 if(profile.length() > 0)
95 newInterfaceName += "_" + profile;
96 // See if we have to make a interface.
97 if(!interfaces->setInterface(newInterfaceName)){
98 // Add making for this new interface if need too
99 if(profile != ""){
100 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
101 if(!interfaces->setMapping(interface->getInterfaceName())){
102 interfaces->addMapping(interface->getInterfaceName());
103 if(!interfaces->setMapping(interface->getInterfaceName())){
104 qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
105 return;
106 }
107 }
108 interfaces->setMap("map", newInterfaceName);
109 interfaces->setScript("getprofile.sh");
110 }
111 else{
112 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
113 if(!interfaces->setInterface(newInterfaceName)){
114 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
115 return;
116 }
117 }
118 }
119
120 // We must have a valid interface to get this far so read some settings.
121
122 // DHCP
123 bool error = false;
124 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
125 dhcpCheckBox->setChecked(true);
126 else
127 dhcpCheckBox->setChecked(false);
128 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
129 if(error)
130 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
131 if(error)
132 leaseTime->setValue(24);
133
134 // IP Information
135 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
136 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
137 if(dns.contains(" ")){
138 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
139 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
140 }
141 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
142 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
143 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
144}
145
146
147// interfacesetup.cpp
148
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.h b/noncore/net/networksetup/interfaces/interfacesetupimp.h
new file mode 100644
index 0000000..936f2be
--- a/dev/null
+++ b/noncore/net/networksetup/interfaces/interfacesetupimp.h
@@ -0,0 +1,49 @@
1#ifndef INTERFACESETUPIMP_H
2#define INTERFACESETUPIMP_H
3
4#include "interfacesetup.h"
5#include <qdialog.h>
6
7class Interface;
8class Interfaces;
9
10class InterfaceSetupImp : public InterfaceSetup {
11 Q_OBJECT
12
13public:
14 InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0);
15 void saveChanges();
16
17public slots:
18 void setProfile(const QString &profile);
19 bool saveSettings();
20private:
21 Interfaces *interfaces;
22 Interface *interface;
23
24};
25
26
27#include <qlayout.h>
28
29class InterfaceSetupImpDialog : public QDialog {
30Q_OBJECT
31
32 public:
33 InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){
34 QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this );
35 setCaption("Interface Setup");
36 interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl);
37 InterfaceSetupLayout->addWidget( interfaceSetup );
38 };
39
40 InterfaceSetupImp *interfaceSetup;
41
42 protected slots:
43 void accept(){ interfaceSetup->saveChanges(); };
44};
45
46#endif
47
48// interfacesetupimp.h
49
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp
new file mode 100644
index 0000000..929b3a1
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interface.cpp
@@ -0,0 +1,287 @@
1#include "interface.h"
2#include <qdatetime.h>
3#include <qfile.h>
4#include <qdir.h>
5#include <qfileinfo.h>
6#include <qtextstream.h>
7
8#define IFCONFIG "/sbin/ifconfig"
9#define DHCP_INFO_DIR "/etc/dhcpc"
10
11#include <stdio.h>
12#include <stdlib.h>
13
14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
15 refresh();
16}
17
18/**
19 * Set status
20 * @param newStatus - the new status
21 * emit updateInterface
22 */
23void 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 */
35void 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 */
45void Interface::setHardwareName(QString name){
46 hardwareName = name;
47 emit(updateInterface(this));
48};
49
50/**
51 * Set Module owner
52 * @param owner - the new owner
53 * emit updateInterface
54 */
55void Interface::setModuleOwner(Module *owner){
56 moduleOwner = owner;
57 emit(updateInterface(this));
58};
59
60
61/**
62 * Try to start the interface.
63 */
64void Interface::start(){
65 // check to see if we are already running.
66 if(true == status)
67 return;
68
69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
70 // See if it was successfull...
71 if(ret != 0)
72 return;
73
74 status = true;
75 refresh();
76}
77
78/**
79 * Try to stop the interface.
80 */
81void Interface::stop(){
82 // check to see if we are already stopped.
83 if(false == status)
84 return;
85
86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
87 if(ret != 0)
88 return;
89
90 status = true;
91 refresh();
92}
93
94/**
95 * Try to restart the interface.
96 */
97void Interface::restart(){
98 stop();
99 start();
100}
101
102/**
103 * Try to refresh the information about the interface.
104 * First call ifconfig, then check the dhcp-info file
105 * @return bool true if successfull.
106 */
107bool Interface::refresh(){
108 // See if we are up.
109 if(status == false){
110 macAddress = "";
111 ip = "0.0.0.0";
112 subnetMask = "0.0.0.0";
113 broadcast = "";
114 dhcp = false;
115 dhcpServerIp = "";
116 leaseObtained = "";
117 leaseExpires = "";
118 emit(updateInterface(this));
119 return true;
120 }
121
122 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
123 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
124 if(ret != 0){
125 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
126 return false;
127 }
128
129 QFile file(fileName);
130 if (!file.open(IO_ReadOnly)){
131 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
132 return false;
133 }
134
135 // Set to the defaults
136 macAddress = "";
137 ip = "0.0.0.0";
138 subnetMask = "0.0.0.0";
139 broadcast = "";
140
141 QTextStream stream( &file );
142 QString line;
143 while ( !stream.eof() ) {
144 line = stream.readLine();
145 if(line.contains("HWaddr")){
146 int mac = line.find("HWaddr");
147 macAddress = line.mid(mac+7, line.length());
148 }
149 if(line.contains("inet addr")){
150 int ipl = line.find("inet addr");
151 int space = line.find(" ", ipl+10);
152 ip = line.mid(ipl+10, space-ipl-10);
153 }
154 if(line.contains("Mask")){
155 int mask = line.find("Mask");
156 subnetMask = line.mid(mask+5, line.length());
157 }
158 if(line.contains("Bcast")){
159 int mask = line.find("Bcast");
160 int space = line.find(" ", mask+6);
161 broadcast = line.mid(mask+6, space-mask-6);
162 }
163 }
164 file.close();
165 QFile::remove(fileName);
166
167 // DHCP TESTING
168 // reset DHCP info
169 dhcpServerIp = "";
170 leaseObtained = "";
171 leaseExpires = "";
172 dhcp = false;
173
174 QString dhcpDirectory(DHCP_INFO_DIR);
175 QDir d(dhcpDirectory);
176 if(!d.exists(dhcpDirectory))
177 dhcpDirectory = "/var/run";
178
179 // See if we have
180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
181 // If there is no DHCP information then exit now with no errors.
182 if(!QFile::exists(dhcpFile)){
183 emit(updateInterface(this));
184 return true;
185 }
186
187 file.setName(dhcpFile);
188 if (!file.open(IO_ReadOnly)){
189 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
190 return false;
191 }
192
193 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
194 int leaseTime = 0;
195 int renewalTime = 0;
196
197 stream.setDevice( &file );
198 while ( !stream.eof() ) {
199 line = stream.readLine();
200 if(line.contains("DHCPSIADDR="))
201 dhcpServerIp = line.mid(11, line.length());
202 if(line.contains("LEASETIME="))
203 leaseTime = line.mid(10, line.length()).toInt();
204 if(line.contains("RENEWALTIME="))
205 renewalTime = line.mid(12, line.length()).toInt();
206 }
207 file.close();
208 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
209 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
210
211 // Get the pid of the deamond
212 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
213 file.setName(dhcpFile);
214 if (!file.open(IO_ReadOnly)){
215 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
216 return false;
217 }
218
219 int pid = -1;
220 stream.setDevice( &file );
221 while ( !stream.eof() ) {
222 line = stream.readLine();
223 pid = line.toInt();
224 }
225 file.close();
226
227 if( pid == -1){
228 qDebug("Interface: Could not get pid of dhcpc deamon.");
229 return false;
230 }
231
232 // Get the start running time of the deamon
233 fileName = (QString("/proc/%1/stat").arg(pid));
234 file.setName(fileName);
235 stream.setDevice( &file );
236 if (!file.open(IO_ReadOnly)){
237 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
238 return false;
239 }
240 while ( !stream.eof() ) {
241 line = stream.readLine();
242 }
243 file.close();
244 long time = 0;
245 // Grab the start time
246 // pid com state ppid pgrp session tty_nr tpgid flags
247 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
248 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
249 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
250 // nice 0 itrealvalue starttime
251 "%*d %*d %*d %lu", (long*) &time);
252 time = time/100;
253
254 QDateTime datetime(QDateTime::currentDateTime());
255
256 // Get the uptime of the computer.
257 QFile f("/proc/uptime");
258 if ( f.open(IO_ReadOnly) ) { // file opened successfully
259 QTextStream t( &f ); // use a text stream
260 int sec = 0;
261 t >> sec;
262 datetime = datetime.addSecs((-1*sec));
263 f.close();
264 }
265 else{
266 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
267 return false;
268 }
269
270 datetime = datetime.addSecs(time);
271 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
272
273 // Calculate the start and renew times
274 leaseObtained= datetime.toString();
275
276 // Calculate the start and renew times
277 datetime = datetime.addSecs(leaseTime);
278 leaseExpires = datetime.toString();
279
280 dhcp = true;
281
282 emit(updateInterface(this));
283 return true;
284}
285
286// interface.cpp
287
diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h
new file mode 100644
index 0000000..dc9c6d3
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interface.h
@@ -0,0 +1,71 @@
1#ifndef INTERFACE_H
2#define INTERFACE_H
3
4#include <qstring.h>
5#include <qobject.h>
6
7class Module;
8
9class Interface : public QObject{
10 Q_OBJECT
11
12signals:
13 void updateInterface(Interface *i);
14
15public:
16 Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
17 virtual ~Interface(){};
18
19 virtual QString getInterfaceName(){ QString n(this->name()); return n; };
20
21 virtual bool getStatus(){ return status; };
22 virtual void setStatus(bool newStatus);
23
24 virtual bool isAttached(){ return attached; };
25 virtual void setAttached(bool isAttached=false);
26
27 virtual QString getHardwareName(){ return hardwareName; };
28 virtual void setHardwareName(QString name="Unknown");
29
30 virtual Module* getModuleOwner(){ return moduleOwner; };
31 virtual void setModuleOwner(Module *owner=NULL);
32
33 // inet information.
34 QString getMacAddress(){ return macAddress; };
35 QString getIp(){ return ip; };
36 QString getSubnetMask(){ return subnetMask; };
37 QString getBroadcast(){ return broadcast; };
38 bool isDhcp(){ return dhcp; };
39 QString getDhcpServerIp(){ return dhcpServerIp; };
40 QString getLeaseObtained(){ return leaseObtained; };
41 QString getLeaseExpires(){ return leaseExpires; };
42
43public slots:
44 bool refresh();
45 void start();
46 void stop();
47 void restart();
48
49private:
50 // Interface information
51 bool status;
52 bool attached;
53 QString hardwareName;
54 Module *moduleOwner;
55
56 // Network information
57 QString macAddress;
58 QString ip;
59 QString broadcast;
60 QString subnetMask;
61 bool dhcp;
62 QString dhcpServerIp;
63 QString leaseObtained;
64 QString leaseExpires;
65
66};
67
68#endif
69
70// interface.h
71
diff --git a/noncore/settings/networksettings/interfaces/interfaceadvanced.ui b/noncore/settings/networksettings/interfaces/interfaceadvanced.ui
new file mode 100644
index 0000000..0ec67c2
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfaceadvanced.ui
@@ -0,0 +1,344 @@
1<!DOCTYPE UI><UI>
2<class>InterfaceAdvanced</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>InterfaceAdvanced</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>214</width>
15 <height>286</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>maximumSize</name>
20 <size>
21 <width>240</width>
22 <height>32767</height>
23 </size>
24 </property>
25 <property stdset="1">
26 <name>caption</name>
27 <string>Advanced Interface Information</string>
28 </property>
29 <grid>
30 <property stdset="1">
31 <name>margin</name>
32 <number>11</number>
33 </property>
34 <property stdset="1">
35 <name>spacing</name>
36 <number>6</number>
37 </property>
38 <widget row="1" column="0" >
39 <class>QLabel</class>
40 <property stdset="1">
41 <name>name</name>
42 <cstring>TextLabel1</cstring>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>MAC Address</string>
47 </property>
48 </widget>
49 <widget row="0" column="1" >
50 <class>QLabel</class>
51 <property stdset="1">
52 <name>name</name>
53 <cstring>interfaceName</cstring>
54 </property>
55 <property stdset="1">
56 <name>frameShape</name>
57 <enum>Panel</enum>
58 </property>
59 <property stdset="1">
60 <name>frameShadow</name>
61 <enum>Sunken</enum>
62 </property>
63 <property stdset="1">
64 <name>text</name>
65 <string>eth0</string>
66 </property>
67 </widget>
68 <widget row="2" column="0" >
69 <class>QLabel</class>
70 <property stdset="1">
71 <name>name</name>
72 <cstring>TextLabel3</cstring>
73 </property>
74 <property stdset="1">
75 <name>text</name>
76 <string>IP Address</string>
77 </property>
78 </widget>
79 <widget row="1" column="1" >
80 <class>QLabel</class>
81 <property stdset="1">
82 <name>name</name>
83 <cstring>macAddressLabel</cstring>
84 </property>
85 <property stdset="1">
86 <name>frameShape</name>
87 <enum>Panel</enum>
88 </property>
89 <property stdset="1">
90 <name>frameShadow</name>
91 <enum>Sunken</enum>
92 </property>
93 <property stdset="1">
94 <name>text</name>
95 <string>00:00:00:00:00:00</string>
96 </property>
97 </widget>
98 <widget row="0" column="0" >
99 <class>QLabel</class>
100 <property stdset="1">
101 <name>name</name>
102 <cstring>TextLabel7</cstring>
103 </property>
104 <property stdset="1">
105 <name>text</name>
106 <string>Interface</string>
107 </property>
108 </widget>
109 <widget row="4" column="0" >
110 <class>QLabel</class>
111 <property stdset="1">
112 <name>name</name>
113 <cstring>TextLabel4</cstring>
114 </property>
115 <property stdset="1">
116 <name>enabled</name>
117 <bool>true</bool>
118 </property>
119 <property stdset="1">
120 <name>text</name>
121 <string>Subnet Mask</string>
122 </property>
123 </widget>
124 <widget row="2" column="1" >
125 <class>QLabel</class>
126 <property stdset="1">
127 <name>name</name>
128 <cstring>ipAddressLabel</cstring>
129 </property>
130 <property stdset="1">
131 <name>frameShape</name>
132 <enum>Panel</enum>
133 </property>
134 <property stdset="1">
135 <name>frameShadow</name>
136 <enum>Sunken</enum>
137 </property>
138 <property stdset="1">
139 <name>text</name>
140 <string>0.0.0.0</string>
141 </property>
142 </widget>
143 <widget row="4" column="1" >
144 <class>QLabel</class>
145 <property stdset="1">
146 <name>name</name>
147 <cstring>subnetMaskLabel</cstring>
148 </property>
149 <property stdset="1">
150 <name>frameShape</name>
151 <enum>Panel</enum>
152 </property>
153 <property stdset="1">
154 <name>frameShadow</name>
155 <enum>Sunken</enum>
156 </property>
157 <property stdset="1">
158 <name>text</name>
159 <string>0.0.0.0</string>
160 </property>
161 </widget>
162 <widget row="3" column="0" >
163 <class>QLabel</class>
164 <property stdset="1">
165 <name>name</name>
166 <cstring>TextLabel2</cstring>
167 </property>
168 <property stdset="1">
169 <name>text</name>
170 <string>Broadcast</string>
171 </property>
172 </widget>
173 <widget row="3" column="1" >
174 <class>QLabel</class>
175 <property stdset="1">
176 <name>name</name>
177 <cstring>broadcastLabel</cstring>
178 </property>
179 <property stdset="1">
180 <name>frameShape</name>
181 <enum>Panel</enum>
182 </property>
183 <property stdset="1">
184 <name>frameShadow</name>
185 <enum>Sunken</enum>
186 </property>
187 </widget>
188 <widget row="5" column="0" rowspan="1" colspan="2" >
189 <class>QGroupBox</class>
190 <property stdset="1">
191 <name>name</name>
192 <cstring>dhcpInformation</cstring>
193 </property>
194 <property stdset="1">
195 <name>title</name>
196 <string>DHCP Information</string>
197 </property>
198 <grid>
199 <property stdset="1">
200 <name>margin</name>
201 <number>11</number>
202 </property>
203 <property stdset="1">
204 <name>spacing</name>
205 <number>6</number>
206 </property>
207 <widget row="0" column="0" >
208 <class>QLabel</class>
209 <property stdset="1">
210 <name>name</name>
211 <cstring>TextLabel6</cstring>
212 </property>
213 <property stdset="1">
214 <name>text</name>
215 <string>DHCP Server</string>
216 </property>
217 </widget>
218 <widget row="2" column="1" >
219 <class>QLabel</class>
220 <property stdset="1">
221 <name>name</name>
222 <cstring>leaseExpiresLabel</cstring>
223 </property>
224 <property stdset="1">
225 <name>frameShape</name>
226 <enum>Panel</enum>
227 </property>
228 <property stdset="1">
229 <name>frameShadow</name>
230 <enum>Sunken</enum>
231 </property>
232 <property stdset="1">
233 <name>text</name>
234 <string></string>
235 </property>
236 </widget>
237 <widget row="1" column="1" >
238 <class>QLabel</class>
239 <property stdset="1">
240 <name>name</name>
241 <cstring>leaseObtainedLabel</cstring>
242 </property>
243 <property stdset="1">
244 <name>frameShape</name>
245 <enum>Panel</enum>
246 </property>
247 <property stdset="1">
248 <name>frameShadow</name>
249 <enum>Sunken</enum>
250 </property>
251 <property stdset="1">
252 <name>text</name>
253 <string></string>
254 </property>
255 </widget>
256 <widget row="2" column="0" >
257 <class>QLabel</class>
258 <property stdset="1">
259 <name>name</name>
260 <cstring>TextLabel9</cstring>
261 </property>
262 <property stdset="1">
263 <name>text</name>
264 <string>Lease Expires</string>
265 </property>
266 </widget>
267 <widget row="1" column="0" >
268 <class>QLabel</class>
269 <property stdset="1">
270 <name>name</name>
271 <cstring>TextLabel8</cstring>
272 </property>
273 <property stdset="1">
274 <name>text</name>
275 <string>Lease Obtained</string>
276 </property>
277 </widget>
278 <widget row="0" column="1" >
279 <class>QLabel</class>
280 <property stdset="1">
281 <name>name</name>
282 <cstring>dhcpServerLabel</cstring>
283 </property>
284 <property stdset="1">
285 <name>frameShape</name>
286 <enum>Panel</enum>
287 </property>
288 <property stdset="1">
289 <name>frameShadow</name>
290 <enum>Sunken</enum>
291 </property>
292 <property stdset="1">
293 <name>text</name>
294 <string></string>
295 </property>
296 </widget>
297 </grid>
298 </widget>
299 <spacer row="6" column="1" >
300 <property>
301 <name>name</name>
302 <cstring>Spacer2</cstring>
303 </property>
304 <property stdset="1">
305 <name>orientation</name>
306 <enum>Vertical</enum>
307 </property>
308 <property stdset="1">
309 <name>sizeType</name>
310 <enum>Expanding</enum>
311 </property>
312 <property>
313 <name>sizeHint</name>
314 <size>
315 <width>20</width>
316 <height>20</height>
317 </size>
318 </property>
319 </spacer>
320 </grid>
321</widget>
322<customwidgets>
323 <customwidget>
324 <class>QWidget</class>
325 <header location="local">qwidget.h</header>
326 <sizehint>
327 <width>100</width>
328 <height>100</height>
329 </sizehint>
330 <container>0</container>
331 <sizepolicy>
332 <hordata>7</hordata>
333 <verdata>7</verdata>
334 </sizepolicy>
335 <pixmap>image0</pixmap>
336 </customwidget>
337</customwidgets>
338<images>
339 <image>
340 <name>image0</name>
341 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
342 </image>
343</images>
344</UI>
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformation.ui b/noncore/settings/networksettings/interfaces/interfaceinformation.ui
new file mode 100644
index 0000000..2838d19
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfaceinformation.ui
@@ -0,0 +1,343 @@
1<!DOCTYPE UI><UI>
2<class>InterfaceInformation</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>InterfaceInformation</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>219</width>
15 <height>255</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Interface Information</string>
21 </property>
22 <grid>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget row="4" column="0" rowspan="1" colspan="2" >
32 <class>QLayoutWidget</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>Layout1</cstring>
36 </property>
37 <grid>
38 <property stdset="1">
39 <name>margin</name>
40 <number>0</number>
41 </property>
42 <property stdset="1">
43 <name>spacing</name>
44 <number>6</number>
45 </property>
46 <widget row="1" column="0" >
47 <class>QPushButton</class>
48 <property stdset="1">
49 <name>name</name>
50 <cstring>refreshButton</cstring>
51 </property>
52 <property stdset="1">
53 <name>text</name>
54 <string>&amp;Refresh</string>
55 </property>
56 </widget>
57 <widget row="0" column="1" >
58 <class>QPushButton</class>
59 <property stdset="1">
60 <name>name</name>
61 <cstring>stopButton</cstring>
62 </property>
63 <property stdset="1">
64 <name>text</name>
65 <string>S&amp;top</string>
66 </property>
67 </widget>
68 <widget row="1" column="1" >
69 <class>QPushButton</class>
70 <property stdset="1">
71 <name>name</name>
72 <cstring>restartButton</cstring>
73 </property>
74 <property stdset="1">
75 <name>text</name>
76 <string>R&amp;estart</string>
77 </property>
78 </widget>
79 <widget row="0" column="0" >
80 <class>QPushButton</class>
81 <property stdset="1">
82 <name>name</name>
83 <cstring>startButton</cstring>
84 </property>
85 <property stdset="1">
86 <name>text</name>
87 <string>&amp;Start</string>
88 </property>
89 </widget>
90 </grid>
91 </widget>
92 <widget row="0" column="0" >
93 <class>Line</class>
94 <property stdset="1">
95 <name>name</name>
96 <cstring>Line1</cstring>
97 </property>
98 <property stdset="1">
99 <name>orientation</name>
100 <enum>Horizontal</enum>
101 </property>
102 </widget>
103 <widget row="0" column="0" >
104 <class>QLabel</class>
105 <property stdset="1">
106 <name>name</name>
107 <cstring>TextLabel22</cstring>
108 </property>
109 <property stdset="1">
110 <name>text</name>
111 <string>IP Address</string>
112 </property>
113 </widget>
114 <widget row="1" column="0" >
115 <class>QLabel</class>
116 <property stdset="1">
117 <name>name</name>
118 <cstring>TextLabel23</cstring>
119 </property>
120 <property stdset="1">
121 <name>text</name>
122 <string>Subnet Mask</string>
123 </property>
124 </widget>
125 <widget row="2" column="0" >
126 <class>QLabel</class>
127 <property stdset="1">
128 <name>name</name>
129 <cstring>TextLabel21</cstring>
130 </property>
131 <property stdset="1">
132 <name>text</name>
133 <string>MAC Address</string>
134 </property>
135 </widget>
136 <widget row="3" column="0" >
137 <class>QLabel</class>
138 <property stdset="1">
139 <name>name</name>
140 <cstring>TextLabel24</cstring>
141 </property>
142 <property stdset="1">
143 <name>frameShape</name>
144 <enum>MShape</enum>
145 </property>
146 <property stdset="1">
147 <name>frameShadow</name>
148 <enum>MShadow</enum>
149 </property>
150 <property stdset="1">
151 <name>text</name>
152 <string>Broadcast</string>
153 </property>
154 </widget>
155 <widget row="1" column="1" >
156 <class>QLabel</class>
157 <property stdset="1">
158 <name>name</name>
159 <cstring>subnetMaskLabel</cstring>
160 </property>
161 <property stdset="1">
162 <name>frameShape</name>
163 <enum>Panel</enum>
164 </property>
165 <property stdset="1">
166 <name>frameShadow</name>
167 <enum>Sunken</enum>
168 </property>
169 <property stdset="1">
170 <name>text</name>
171 <string>0.0.0.0</string>
172 </property>
173 </widget>
174 <widget row="2" column="1" >
175 <class>QLabel</class>
176 <property stdset="1">
177 <name>name</name>
178 <cstring>macAddressLabel</cstring>
179 </property>
180 <property stdset="1">
181 <name>frameShape</name>
182 <enum>Panel</enum>
183 </property>
184 <property stdset="1">
185 <name>frameShadow</name>
186 <enum>Sunken</enum>
187 </property>
188 <property stdset="1">
189 <name>text</name>
190 <string>00:00:00:00:00:00</string>
191 </property>
192 </widget>
193 <widget row="3" column="1" >
194 <class>QLabel</class>
195 <property stdset="1">
196 <name>name</name>
197 <cstring>broadcastLabel</cstring>
198 </property>
199 <property stdset="1">
200 <name>frameShape</name>
201 <enum>Panel</enum>
202 </property>
203 <property stdset="1">
204 <name>frameShadow</name>
205 <enum>Sunken</enum>
206 </property>
207 <property stdset="1">
208 <name>text</name>
209 <string></string>
210 </property>
211 </widget>
212 <widget row="0" column="1" >
213 <class>QLabel</class>
214 <property stdset="1">
215 <name>name</name>
216 <cstring>ipAddressLabel</cstring>
217 </property>
218 <property stdset="1">
219 <name>frameShape</name>
220 <enum>Panel</enum>
221 </property>
222 <property stdset="1">
223 <name>frameShadow</name>
224 <enum>Sunken</enum>
225 </property>
226 <property stdset="1">
227 <name>text</name>
228 <string>0.0.0.0</string>
229 </property>
230 </widget>
231 <spacer row="7" column="1" >
232 <property>
233 <name>name</name>
234 <cstring>Spacer18</cstring>
235 </property>
236 <property stdset="1">
237 <name>orientation</name>
238 <enum>Vertical</enum>
239 </property>
240 <property stdset="1">
241 <name>sizeType</name>
242 <enum>Expanding</enum>
243 </property>
244 <property>
245 <name>sizeHint</name>
246 <size>
247 <width>20</width>
248 <height>20</height>
249 </size>
250 </property>
251 </spacer>
252 <widget row="6" column="0" rowspan="1" colspan="2" >
253 <class>QLayoutWidget</class>
254 <property stdset="1">
255 <name>name</name>
256 <cstring>Layout2</cstring>
257 </property>
258 <hbox>
259 <property stdset="1">
260 <name>margin</name>
261 <number>0</number>
262 </property>
263 <property stdset="1">
264 <name>spacing</name>
265 <number>6</number>
266 </property>
267 <spacer>
268 <property>
269 <name>name</name>
270 <cstring>Spacer10</cstring>
271 </property>
272 <property stdset="1">
273 <name>orientation</name>
274 <enum>Horizontal</enum>
275 </property>
276 <property stdset="1">
277 <name>sizeType</name>
278 <enum>Expanding</enum>
279 </property>
280 <property>
281 <name>sizeHint</name>
282 <size>
283 <width>20</width>
284 <height>20</height>
285 </size>
286 </property>
287 </spacer>
288 <widget>
289 <class>QPushButton</class>
290 <property stdset="1">
291 <name>name</name>
292 <cstring>advancedButton</cstring>
293 </property>
294 <property stdset="1">
295 <name>text</name>
296 <string>View &amp;Advanced Information</string>
297 </property>
298 </widget>
299 </hbox>
300 </widget>
301 <widget row="5" column="0" rowspan="1" colspan="2" >
302 <class>Line</class>
303 <property stdset="1">
304 <name>name</name>
305 <cstring>Line5</cstring>
306 </property>
307 <property stdset="1">
308 <name>orientation</name>
309 <enum>Horizontal</enum>
310 </property>
311 </widget>
312 </grid>
313</widget>
314<customwidgets>
315 <customwidget>
316 <class>QWidget</class>
317 <header location="local">qwidget.h</header>
318 <sizehint>
319 <width>100</width>
320 <height>100</height>
321 </sizehint>
322 <container>0</container>
323 <sizepolicy>
324 <hordata>7</hordata>
325 <verdata>7</verdata>
326 </sizepolicy>
327 <pixmap>image0</pixmap>
328 </customwidget>
329</customwidgets>
330<images>
331 <image>
332 <name>image0</name>
333 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
334 </image>
335</images>
336<tabstops>
337 <tabstop>startButton</tabstop>
338 <tabstop>stopButton</tabstop>
339 <tabstop>refreshButton</tabstop>
340 <tabstop>restartButton</tabstop>
341 <tabstop>advancedButton</tabstop>
342</tabstops>
343</UI>
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp
new file mode 100644
index 0000000..43483fb
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp
@@ -0,0 +1,70 @@
1#include "interfaceinformationimp.h"
2#include "interfaceadvanced.h"
3
4#include <qpushbutton.h>
5#include <qlabel.h>
6#include <qgroupbox.h>
7#include <assert.h>
8
9/**
10 * Constructor for the InterfaceInformationImp class. This class pretty much
11 * just display's information about the interface that is passed to it.
12 */
13InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){
14 assert(i);
15
16 interface = i;
17 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
18 updateInterface(interface);
19 connect(startButton, SIGNAL(clicked()), interface, SLOT(start()));
20 connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop()));
21 connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart()));
22 connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh()));
23 connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced()));
24
25}
26
27/**
28 * Update the interface information and buttons.
29 * @param Intarface *i the interface to update (should be the one we already
30 * know about).
31 */
32void InterfaceInformationImp::updateInterface(Interface *i){
33 if(interface->getStatus()){
34 startButton->setEnabled(false);
35 stopButton->setEnabled(true);
36 restartButton->setEnabled(true);
37 }
38 else{
39 startButton->setEnabled(true);
40 stopButton->setEnabled(false);
41 restartButton->setEnabled(false);
42 }
43 macAddressLabel->setText(interface->getMacAddress());
44 ipAddressLabel->setText(interface->getIp());
45 subnetMaskLabel->setText(interface->getSubnetMask());
46 broadcastLabel->setText(interface->getBroadcast());
47}
48
49/**
50 * Create the advanced widget. Fill it with the current interface's information.
51 * Display it.
52 */
53void InterfaceInformationImp::advanced(){
54 InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced");
55 a->interfaceName->setText(interface->getInterfaceName());
56 a->macAddressLabel->setText(interface->getMacAddress());
57 a->ipAddressLabel->setText(interface->getIp());
58 a->subnetMaskLabel->setText(interface->getSubnetMask());
59 a->broadcastLabel->setText(interface->getBroadcast());
60 a->dhcpServerLabel->setText(interface->getDhcpServerIp());
61 a->leaseObtainedLabel->setText(interface->getLeaseObtained());
62 a->leaseExpiresLabel->setText(interface->getLeaseExpires());
63 a->dhcpInformation->setEnabled(interface->isDhcp());
64
65 a->showMaximized();
66 a->show();
67}
68
69// infoimp.cpp
70
diff --git a/noncore/settings/networksettings/interfaces/interfaceinformationimp.h b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h
new file mode 100644
index 0000000..42213cc
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h
@@ -0,0 +1,27 @@
1#ifndef INTERFACEINFORMATIONIMP_H
2#define INTERFACEINFORMATIONIMP_H
3
4#include "interfaceinformation.h"
5#include "interface.h"
6
7class InterfaceInformationImp : public InterfaceInformation {
8
9Q_OBJECT
10
11public:
12 InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0);
13 ~InterfaceInformationImp(){};
14
15private slots:
16 void advanced();
17 void updateInterface(Interface *i);
18
19private:
20 Interface *interface;
21
22};
23
24#endif
25
26// addserviceimp.h
27
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp
new file mode 100644
index 0000000..377a6db
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfaces.cpp
@@ -0,0 +1,638 @@
1#include "interfaces.h"
2
3#include <qfile.h>
4#include <qtextstream.h>
5#include <qregexp.h>
6
7#define AUTO "auto"
8#define IFACE "iface"
9#define MAPPING "mapping"
10
11/**
12 * Constructor. Reads in the interfaces file and then split the file up by
13 * the \n for interfaces variable.
14 * @param useInterfacesFile if an interface file other then the default is
15 * desired to be used it should be passed in.
16 */
17Interfaces::Interfaces(QString useInterfacesFile){
18 acceptedFamily.append(INTERFACES_FAMILY_INET);
19 acceptedFamily.append(INTERFACES_FAMILY_IPX);
20 acceptedFamily.append(INTERFACES_FAMILY_INET6);
21
22 interfacesFile = useInterfacesFile;
23 QFile file(interfacesFile);
24 if (!file.open(IO_ReadOnly)){
25 qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1());
26 currentIface = interfaces.end();
27 currentMapping = interfaces.end();
28 return;
29 }
30 QTextStream stream( &file );
31 QString line;
32 while ( !stream.eof() ) {
33 line += stream.readLine();
34 line += "\n";
35 }
36 file.close();
37 interfaces = QStringList::split("\n", line, true);
38
39 currentIface = interfaces.end();
40 currentMapping = interfaces.end();
41}
42
43
44/**
45 * Get a list of all interfaces in the interface file. Usefull for
46 * hardware that is not currently connected such as an 802.11b card
47 * not plugged in, but configured for when it is plugged in.
48 * @return Return string list of interfaces.
49 **/
50QStringList Interfaces::getInterfaceList(){
51 QStringList list;
52 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
53 QString line = (*it).simplifyWhiteSpace();
54 if(line.contains(IFACE) && line.at(0) != '#'){
55 line = line.mid(QString(IFACE).length() +1, line.length());
56 line = line.simplifyWhiteSpace();
57 int findSpace = line.find(" ");
58 if( findSpace >= 0){
59 line = line.mid(0, findSpace);
60 list.append(line);
61 }
62 }
63 }
64 return list;
65}
66
67/**
68 * Find out if interface is in an "auto" group or not.
69 * Report any duplicates such as eth0 being in two differnt auto's
70 * @param interface interface to check to see if it is on or not.
71 * @return true is interface is in auto
72 */
73bool Interfaces::isAuto(QString interface){
74 QStringList autoLines = interfaces.grep(QRegExp(AUTO));
75 QStringList awi = autoLines.grep(QRegExp(interface));
76 if(awi.count() > 1)
77 qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1());
78 if(awi.count() < 1)
79 return false;
80 return true;
81}
82
83/**
84 * Attempt to set the auto option for interface to setAuto.
85 * @param interface the interface to set
86 * @param setAuto the value to set interface to.
87 * @return false if already set to setAuto.
88 * */
89bool Interfaces::setAuto(QString interface, bool setAuto){
90 // Don't need to set it if it is already set.
91 if(isAuto(interface) == setAuto)
92 return false;
93
94 bool changed = false;
95 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
96 if((*it).contains(AUTO)){
97 //We know that they are not in any group so let add to this auto.
98 if(setAuto){
99 (*it) = (*it) += " " + interface;
100 // Don't care to have such thins as: auto eth0 lo usb0
101 (*it) = (*it).simplifyWhiteSpace();
102 changed = true;
103 break;
104 }
105 else{
106 if((*it).contains(interface)){
107 (*it) = (*it).replace(QRegExp(interface), "");
108 // clean up
109 QString line = (*it).simplifyWhiteSpace();
110 line = line.replace(QRegExp(" "),"");
111 if(line == AUTO)
112 (*it) = "";
113 changed = true;
114 // Don't break because we want to make sure we remove all cases.
115 }
116 }
117 }
118 }
119 if(changed == false){
120 if(setAuto == true)
121 interfaces.append(QString(AUTO" %1").arg(interface));
122 else{
123 qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1());
124 }
125 }
126 return true;
127}
128
129/**
130 * Set the current interface to interface. This needs to be done before you
131 * can call getFamily(), getMethod, and get/setOption().
132 * @param interface the name of the interface to set. All whitespace is
133 * removed from the interface name.
134 * @return bool true if it is successfull.
135 */
136bool Interfaces::setInterface(QString interface){
137 interface = interface.simplifyWhiteSpace();
138 interface = interface.replace(QRegExp(" "), "");
139 return setStanza(IFACE, interface, currentIface);
140}
141
142/**
143 * A quick helper funtion to see if the current interface is set.
144 * @return bool true if set, false otherwise.
145 */
146bool Interfaces::isInterfaceSet(){
147 return (currentIface != interfaces.end());
148}
149
150/**
151 * Add a new interface of with the settings - family and method
152 * @param interface the name of the interface to set. All whitespace is
153 * removed from the interface name.
154 * @param family the family of this interface inet or inet, ipx or inet6
155 * Must of one of the families defined in interfaces.h
156 * @param method for the family. see interfaces man page for family methods.
157 * @return true if successfull.
158 */
159bool Interfaces::addInterface(QString interface, QString family, QString method){
160 if(acceptedFamily.contains(family)==0)
161 return false;
162 interface = interface.simplifyWhiteSpace();
163 interface = interface.replace(QRegExp(" "), "");
164 interfaces.append("");
165 interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method));
166 return true;
167}
168
169/**
170 * Copies interface with name interface to name newInterface
171 * @param newInterface name of the new interface.
172 * @return bool true if successfull
173 */
174bool Interfaces::copyInterface(QString interface, QString newInterface){
175 if(!setInterface(interface)) return false;
176
177 QStringList::Iterator it = currentIface;
178 it++;
179
180 bool error;
181 addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
182 if(!setInterface(newInterface)) return false;
183 QStringList::Iterator newIface = currentIface;
184 newIface++;
185
186 for ( it; it != interfaces.end(); ++it ){
187 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)))
188 break;
189 newIface = interfaces.insert(newIface, *it);
190 }
191
192 return true;
193}
194
195/**
196 * Remove the currently selected interface and all of its options.
197 * @return bool if successfull or not.
198 */
199bool Interfaces::removeInterface(){
200 if(currentIface == interfaces.end())
201 return false;
202 (*currentIface) = "";
203 return removeAllInterfaceOptions();
204}
205
206/**
207 * Gets the hardware name of the interface that is currently selected.
208 * @return QString name of the hardware interface (eth0, usb2, wlan1...).
209 * @param error set to true if any error occurs, false otherwise.
210 */
211QString Interfaces::getInterfaceName(bool &error){
212 if(currentIface == interfaces.end()){
213 error = true;
214 return QString();
215 }
216 QString line = (*currentIface);
217 line = line.mid(QString(IFACE).length() +1, line.length());
218 line = line.simplifyWhiteSpace();
219 int findSpace = line.find(" ");
220 if( findSpace < 0){
221 error = true;
222 return QString();
223 }
224 error = false;
225 return line.mid(0, findSpace);
226}
227
228/**
229 * Gets the family name of the interface that is currently selected.
230 * @return QString name of the family (inet, inet6, ipx).
231 * @param error set to true if any error occurs, false otherwise.
232 */
233QString Interfaces::getInterfaceFamily(bool &error){
234 QString name = getInterfaceName(error);
235 if(error){
236 error = true;
237 return QString();
238 }
239 QString line = (*currentIface);
240 line = line.mid(QString(IFACE).length() +1, line.length());
241 line = line.mid(name.length()+1, line.length());
242 line = line.simplifyWhiteSpace();
243 int findSpace = line.find(" ");
244 if( findSpace < 0){
245 error = true;
246 return QString();
247 }
248 error = false;
249 return line.mid(0, findSpace);
250}
251
252/**
253 * Gets the method of the interface that is currently selected.
254 * @return QString name of the method such as staic or dhcp.
255 * See the man page of interfaces for possible methods depending on the family.
256 * @param error set to true if any error occurs, false otherwise.
257 */
258QString Interfaces::getInterfaceMethod(bool &error){
259 QString name = getInterfaceName(error);
260 if(error){
261 error = true;
262 return QString();
263 }
264 QString family = getInterfaceFamily(error);
265 if(error){
266 error = true;
267 return QString();
268 }
269 QString line = (*currentIface);
270 line = line.mid(QString(IFACE).length()+1, line.length());
271 line = line.mid(name.length()+1, line.length());
272 line = line.mid(family.length()+1, line.length());
273 line = line.simplifyWhiteSpace();
274 error = false;
275 return line;
276}
277
278/**
279 * Sets the interface name to newName.
280 * @param newName the new name of the interface. All whitespace is removed.
281 * @return bool true if successfull.
282 */
283bool Interfaces::setInterfaceName(QString newName){
284 if(currentIface == interfaces.end())
285 return false;
286 newName = newName.simplifyWhiteSpace();
287 newName = newName.replace(QRegExp(" "), "");
288 bool returnValue = false;
289 (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue));
290 return !returnValue;
291}
292
293/**
294 * Sets the interface family to newName.
295 * @param newName the new name of the interface. Must be one of the families
296 * defined in the interfaces.h file.
297 * @return bool true if successfull.
298 */
299bool Interfaces::setInterfaceFamily(QString newName){
300 if(currentIface == interfaces.end())
301 return false;
302 if(acceptedFamily.contains(newName)==0)
303 return false;
304 bool returnValue = false;
305 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue));
306 return !returnValue;
307}
308
309/**
310 * Sets the interface method to newName
311 * @param newName the new name of the interface
312 * @return bool true if successfull.
313 */
314bool Interfaces::setInterfaceMethod(QString newName){
315 if(currentIface == interfaces.end())
316 return false;
317 bool returnValue = false;
318 (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName);
319 return !returnValue;
320}
321
322/**
323 * Get a value for an option in the currently selected interface. For example
324 * calling getInterfaceOption("address") on the following stanza would
325 * return 192.168.1.1.
326 * iface eth0 static
327 * address 192.168.1.1
328 * @param option the options to get the value.
329 * @param error set to true if any error occurs, false otherwise.
330 * @return QString the options value. QString::null if error == true
331 */
332QString Interfaces::getInterfaceOption(QString option, bool &error){
333 return getOption(currentIface, option, error);
334}
335
336/**
337 * Set a value for an option in the currently selected interface. If option
338 * doesn't exist then it is added along with the value.
339 * @param option the options to set the value.
340 * @param value the value that option should be set to.
341 * @param error set to true if any error occurs, false otherwise.
342 * @return QString the options value. QString::null if error == true
343 */
344bool Interfaces::setInterfaceOption(QString option, QString value){
345 return setOption(currentIface, option, value);
346}
347
348/**
349 * Removes a value for an option in the currently selected interface.
350 * @param option the options to set the value.
351 * @param value the value that option should be set to.
352 * @param error set to true if any error occurs, false otherwise.
353 * @return QString the options value. QString::null if error == true
354 */
355bool Interfaces::removeInterfaceOption(QString option, QString value){
356 return removeOption(currentIface, option, value);
357}
358
359/**
360 * Removes all of the options from the currently selected interface.
361 * @return bool error if if successfull
362 */
363bool Interfaces::removeAllInterfaceOptions(){
364 return removeAllOptions(currentIface);
365}
366
367/**
368 * Set the current map to interface's map. This needs to be done before you
369 * can call addMapping(), set/getMap(), and get/setScript().
370 * @param interface the name of the interface to set. All whitespace is
371 * removed from the interface name.
372 * @return bool true if it is successfull.
373 */
374bool Interfaces::setMapping(QString interface){
375 interface = interface.simplifyWhiteSpace();
376 interface = interface.replace(QRegExp(" "), "");
377 return setStanza(MAPPING, interface, currentMapping);
378}
379
380/**
381 * Adds a new Mapping to the interfaces file with interfaces.
382 * @param interface the name(s) of the interfaces to set to this mapping
383 */
384void Interfaces::addMapping(QString option){
385 interfaces.append("");
386 interfaces.append(QString(MAPPING " %1").arg(option));
387}
388
389/**
390 * Remove the currently selected map and all of its options.
391 * @return bool if successfull or not.
392 */
393bool Interfaces::removeMapping(){
394 if(currentMapping == interfaces.end())
395 return false;
396 (*currentMapping) = "";
397 return removeAllOptions(currentMapping);
398}
399
400/**
401 * Set a map option within a mapping.
402 * @param map map to use
403 * @param value value to go with map
404 * @return bool true if it is successfull.
405 */
406bool Interfaces::setMap(QString map, QString value){
407 return setOption(currentMapping, map, value);
408}
409
410/**
411 * Removes a map option within a mapping.
412 * @param map map to use
413 * @param value value to go with map
414 * @return bool true if it is successfull.
415 */
416bool Interfaces::removeMap(QString map, QString value){
417 return removeOption(currentMapping, map, value);
418}
419
420/**
421 * Get a map value within a mapping.
422 * @param map map to get value of
423 * @param bool true if it is successfull.
424 * @return value that goes to the map
425 */
426QString Interfaces::getMap(QString map, bool &error){
427 return getOption(currentMapping, map, error);
428}
429
430/**
431 * Sets a script value of the current mapping to argument.
432 * @param argument the script name.
433 * @return true if successfull.
434 */
435bool Interfaces::setScript(QString argument){
436 return setOption(currentMapping, "script", argument);
437}
438
439/**
440 * @param error true if could not retrieve the current script argument.
441 * @return QString the argument of the script for the current mapping.
442 */
443QString Interfaces::getScript(bool &error){
444 return getOption(currentMapping, "script", error);
445}
446
447/**
448 * Helper function used to parse through the QStringList and put pointers in
449 * the correct place.
450 * @param stanza The stanza (auto, iface, mapping) to look for.
451 * @param option string that must be in the stanza's main line.
452 * @param interator interator to place at location of stanza if successfull.
453 * @return bool true if the stanza is found.
454 */
455bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
456 bool found = false;
457 iterator = interfaces.end();
458 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
459 QString line = (*it).simplifyWhiteSpace();
460 if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){
461 uint point = line.find(option);
462 bool valid = true;
463 if(point > 0){
464 // There are more chars in the line. check +1
465 if(line.at(point-1) != ' ')
466 valid = false;
467 }
468 point += option.length();
469 if(point < line.length()-1){
470 // There are more chars in the line. check -1
471 if(line.at(point) != ' ')
472 valid = false;
473 }
474 if(valid){
475 if(found == true){
476 qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
477 }
478 found = true;
479 iterator = it;
480 }
481 }
482 }
483 return found;
484}
485
486/**
487 * Sets a value of an option in a stanza
488 * @param start the start of the stanza
489 * @param option the option to use when setting value.
490 * @return bool true if successfull, false otherwise.
491 */
492bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){
493 if(start == interfaces.end())
494 return false;
495
496 bool found = false;
497 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
498 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
499 if(!found && value != ""){
500 // Got to the end of the stanza without finding it, so append it.
501 interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
502 }
503 found = true;
504 break;
505 }
506 if((*it).contains(option) && it != start && (*it).at(0) != '#'){
507 // Found it in stanza so replace it.
508 if(found)
509 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
510 found = true;
511 (*it) = QString("\t%1 %2").arg(option).arg(value);
512 }
513 }
514 if(!found){
515 QStringList::Iterator p = start;
516 interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
517 found = true;
518 }
519 return found;
520}
521/**
522 * Removes a option in a stanza
523 * @param start the start of the stanza
524 * @param option the option to use when setting value.
525 * @return bool true if successfull, false otherwise.
526 */
527bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){
528 if(start == interfaces.end())
529 return false;
530
531 bool found = false;
532 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
533 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
534 // got to the end without finding it
535 break;
536 }
537 if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){
538 // Found it in stanza so replace it.
539 if(found)
540 qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1());
541 found = true;
542 (*it) = "";
543 }
544 }
545 return found;
546}
547
548/**
549 * Removes all options in a stanza
550 * @param start the start of the stanza
551 * @return bool true if successfull, false otherwise.
552 */
553bool Interfaces::removeAllOptions(QStringList::Iterator start){
554 if(start == interfaces.end())
555 return false;
556
557 QStringList::Iterator it = start;
558 it = ++it;
559 for (it; it != interfaces.end(); ++it ) {
560 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
561 break;
562 }
563 it = interfaces.remove(it);
564 it = --it;
565 }
566 // Leave a space between this interface and the next.
567 interfaces.insert(it, QString(""));
568 return true;
569}
570
571/**
572 * Gets a value of an option in a stanza
573 * @param start the start of the stanza
574 * @param option the option to use when getting the value.
575 * @param bool true if errors false otherwise.
576 * @return QString the value of option QString::null() if error == true.
577 */
578QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){
579 if(start == interfaces.end()){
580 error = false;
581 return QString();
582 }
583
584 QString value;
585 bool found = false;
586 for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) {
587 if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
588 break;
589 }
590 if((*it).contains(option) && (*it).at(0) != '#'){
591 if(found)
592 qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1());
593 found = true;
594 QString line = (*it).simplifyWhiteSpace();
595 int space = line.find(" ", option.length());
596 if(space != -1)
597 value = line.mid(space+1, line.length());
598 else
599 qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1());
600 }
601 }
602 error = !found;
603 return value;
604}
605
606/**
607 * Write out the interfaces file to the file passed into the constructor.
608 * Removes any excess blank lines over 1 line long.
609 * @return bool true if successfull, false if not.
610 */
611bool Interfaces::write(){
612 QFile::remove(interfacesFile);
613 QFile file(interfacesFile);
614
615 if (!file.open(IO_ReadWrite)){
616 qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1());
617 return false;
618 }
619 QTextStream stream( &file );
620 int whiteSpaceCount = 0;
621 for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
622 QString line = (*it).simplifyWhiteSpace();
623 line = line.replace(QRegExp(" "),"");
624 if(line.length() == 0)
625 whiteSpaceCount++;
626 else
627 whiteSpaceCount = 0;
628 if(whiteSpaceCount < 2){
629 qDebug((*it).latin1());
630 stream << (*it) << '\n';
631 }
632 }
633 file.close();
634 return true;
635}
636
637// interfaces.cpp
638
diff --git a/noncore/settings/networksettings/interfaces/interfaces.h b/noncore/settings/networksettings/interfaces/interfaces.h
new file mode 100644
index 0000000..e09ea71
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfaces.h
@@ -0,0 +1,76 @@
1#ifndef INTERFACES_H
2#define INTERFACES_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6
7#define INTERFACES_LOOPBACK "loopback"
8
9#define INTERFACES_FAMILY_INET "inet"
10#define INTERFACES_FAMILY_IPX "ipx"
11#define INTERFACES_FAMILY_INET6 "inet6"
12
13#define INTERFACES_METHOD_DHCP "dhcp"
14#define INTERFACES_METHOD_STATIC "static"
15#define INTERFACES_METHOD_PPP "ppp"
16
17/**
18 * This class provides a clean frontend for parsing the network interfaces file.
19 * It provides helper functions to minipulate the options within the file.
20 * See the interfaces man page for the syntax rules.
21 */
22class Interfaces {
23
24public:
25 Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
26 QStringList getInterfaceList();
27
28 bool isAuto(QString interface);
29 bool setAuto(QString interface, bool setAuto);
30
31 bool removeInterface();
32 bool addInterface(QString interface, QString family, QString method);
33 bool copyInterface(QString oldInterface, QString newInterface);
34 bool setInterface(QString interface);
35 bool isInterfaceSet();
36 QString getInterfaceName(bool &error);
37 bool setInterfaceName(QString newName);
38 QString getInterfaceFamily(bool &error);
39 bool setInterfaceFamily(QString newName);
40 QString getInterfaceMethod(bool &error);
41 bool setInterfaceMethod(QString newName);
42 QString getInterfaceOption(QString option, bool &error);
43 bool setInterfaceOption(QString option, QString value);
44 bool removeInterfaceOption(QString option, QString value);
45 bool removeAllInterfaceOptions();
46
47 bool setMapping(QString interface);
48 bool removeMapping();
49 void addMapping(QString options);
50 bool setMap(QString map, QString value);
51 bool removeMap(QString map, QString value);
52 QString getMap(QString map, bool &error);
53 bool setScript(QString);
54 QString getScript(bool &error);
55
56 bool write();
57
58private:
59 bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
60 bool setOption(QStringList::Iterator start, QString option, QString value);
61 bool removeOption(QStringList::Iterator start, QString option, QString value);
62 QString getOption(QStringList::Iterator start, QString option, bool &error);
63 bool removeAllOptions(QStringList::Iterator start);
64
65 QString interfacesFile;
66 QStringList interfaces;
67 QStringList::Iterator currentIface;
68 QStringList::Iterator currentMapping;
69
70 QStringList acceptedFamily;
71};
72
73#endif
74
75// interfaces
76
diff --git a/noncore/settings/networksettings/interfaces/interfaces.pro b/noncore/settings/networksettings/interfaces/interfaces.pro
new file mode 100644
index 0000000..fb13278
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfaces.pro
@@ -0,0 +1,12 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug
4DESTDIR = $(OPIEDIR)/plugins/networksetup
5 HEADERS = interface.h interfaceinformationimp.h interfaces.h interfacesetupimp.h
6 SOURCES = interface.cpp interfaces.cpp interfaceinformationimp.cpp interfacesetupimp.cpp
7 INCLUDEPATH+= $(OPIEDIR)/include ../
8 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe
10 INTERFACES= interfaceadvanced.ui interfaceinformation.ui interfacesetup.ui
11 TARGET = interfaces
12 VERSION = 1.0.0
diff --git a/noncore/settings/networksettings/interfaces/interfacesetup.ui b/noncore/settings/networksettings/interfaces/interfacesetup.ui
new file mode 100644
index 0000000..ab8e413
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfacesetup.ui
@@ -0,0 +1,284 @@
1<!DOCTYPE UI><UI>
2<class>InterfaceSetup</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>InterfaceSetup</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>290</width>
15 <height>280</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Interface Configuration</string>
21 </property>
22 <vbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QCheckBox</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>autoStart</cstring>
36 </property>
37 <property stdset="1">
38 <name>text</name>
39 <string>Automatically bring up</string>
40 </property>
41 </widget>
42 <widget>
43 <class>QLayoutWidget</class>
44 <property stdset="1">
45 <name>name</name>
46 <cstring>Layout9</cstring>
47 </property>
48 <hbox>
49 <property stdset="1">
50 <name>margin</name>
51 <number>0</number>
52 </property>
53 <property stdset="1">
54 <name>spacing</name>
55 <number>6</number>
56 </property>
57 <widget>
58 <class>QCheckBox</class>
59 <property stdset="1">
60 <name>name</name>
61 <cstring>dhcpCheckBox</cstring>
62 </property>
63 <property stdset="1">
64 <name>text</name>
65 <string>DHCP</string>
66 </property>
67 <property stdset="1">
68 <name>checked</name>
69 <bool>true</bool>
70 </property>
71 </widget>
72 <widget>
73 <class>QLabel</class>
74 <property stdset="1">
75 <name>name</name>
76 <cstring>leaseHoursLabel</cstring>
77 </property>
78 <property stdset="1">
79 <name>text</name>
80 <string>Requested Lease</string>
81 </property>
82 </widget>
83 <widget>
84 <class>QSpinBox</class>
85 <property stdset="1">
86 <name>name</name>
87 <cstring>leaseTime</cstring>
88 </property>
89 <property stdset="1">
90 <name>suffix</name>
91 <string> hours</string>
92 </property>
93 <property stdset="1">
94 <name>maxValue</name>
95 <number>87600</number>
96 </property>
97 <property stdset="1">
98 <name>minValue</name>
99 <number>1</number>
100 </property>
101 <property stdset="1">
102 <name>value</name>
103 <number>168</number>
104 </property>
105 </widget>
106 </hbox>
107 </widget>
108 <widget>
109 <class>QGroupBox</class>
110 <property stdset="1">
111 <name>name</name>
112 <cstring>staticGroupBox</cstring>
113 </property>
114 <property stdset="1">
115 <name>enabled</name>
116 <bool>false</bool>
117 </property>
118 <property stdset="1">
119 <name>frameShape</name>
120 <enum>Box</enum>
121 </property>
122 <property stdset="1">
123 <name>frameShadow</name>
124 <enum>Sunken</enum>
125 </property>
126 <property stdset="1">
127 <name>title</name>
128 <string>Static Ip Configuration</string>
129 </property>
130 <grid>
131 <property stdset="1">
132 <name>margin</name>
133 <number>11</number>
134 </property>
135 <property stdset="1">
136 <name>spacing</name>
137 <number>6</number>
138 </property>
139 <widget row="1" column="0" >
140 <class>QLabel</class>
141 <property stdset="1">
142 <name>name</name>
143 <cstring>TextLabel5</cstring>
144 </property>
145 <property stdset="1">
146 <name>text</name>
147 <string>Subnet Mask</string>
148 </property>
149 </widget>
150 <widget row="2" column="1" >
151 <class>QLineEdit</class>
152 <property stdset="1">
153 <name>name</name>
154 <cstring>gatewayEdit</cstring>
155 </property>
156 </widget>
157 <widget row="1" column="1" >
158 <class>QLineEdit</class>
159 <property stdset="1">
160 <name>name</name>
161 <cstring>subnetMaskEdit</cstring>
162 </property>
163 </widget>
164 <widget row="0" column="1" >
165 <class>QLineEdit</class>
166 <property stdset="1">
167 <name>name</name>
168 <cstring>ipAddressEdit</cstring>
169 </property>
170 </widget>
171 <widget row="3" column="0" >
172 <class>QLabel</class>
173 <property stdset="1">
174 <name>name</name>
175 <cstring>TextLabel2</cstring>
176 </property>
177 <property stdset="1">
178 <name>text</name>
179 <string>First DNS</string>
180 </property>
181 </widget>
182 <widget row="0" column="0" >
183 <class>QLabel</class>
184 <property stdset="1">
185 <name>name</name>
186 <cstring>TextLabel4</cstring>
187 </property>
188 <property stdset="1">
189 <name>text</name>
190 <string>IP Address</string>
191 </property>
192 </widget>
193 <widget row="2" column="0" >
194 <class>QLabel</class>
195 <property stdset="1">
196 <name>name</name>
197 <cstring>TextLabel1_2</cstring>
198 </property>
199 <property stdset="1">
200 <name>text</name>
201 <string>Gateway</string>
202 </property>
203 </widget>
204 <widget row="4" column="0" >
205 <class>QLabel</class>
206 <property stdset="1">
207 <name>name</name>
208 <cstring>TextLabel3</cstring>
209 </property>
210 <property stdset="1">
211 <name>text</name>
212 <string>Second DNS</string>
213 </property>
214 </widget>
215 <widget row="3" column="1" >
216 <class>QLineEdit</class>
217 <property stdset="1">
218 <name>name</name>
219 <cstring>firstDNSLineEdit</cstring>
220 </property>
221 </widget>
222 <widget row="4" column="1" >
223 <class>QLineEdit</class>
224 <property stdset="1">
225 <name>name</name>
226 <cstring>secondDNSLineEdit</cstring>
227 </property>
228 </widget>
229 </grid>
230 </widget>
231 <spacer>
232 <property>
233 <name>name</name>
234 <cstring>Spacer9</cstring>
235 </property>
236 <property stdset="1">
237 <name>orientation</name>
238 <enum>Vertical</enum>
239 </property>
240 <property stdset="1">
241 <name>sizeType</name>
242 <enum>Expanding</enum>
243 </property>
244 <property>
245 <name>sizeHint</name>
246 <size>
247 <width>20</width>
248 <height>20</height>
249 </size>
250 </property>
251 </spacer>
252 </vbox>
253</widget>
254<connections>
255 <connection>
256 <sender>dhcpCheckBox</sender>
257 <signal>toggled(bool)</signal>
258 <receiver>leaseHoursLabel</receiver>
259 <slot>setEnabled(bool)</slot>
260 </connection>
261 <connection>
262 <sender>dhcpCheckBox</sender>
263 <signal>toggled(bool)</signal>
264 <receiver>leaseTime</receiver>
265 <slot>setEnabled(bool)</slot>
266 </connection>
267 <connection>
268 <sender>dhcpCheckBox</sender>
269 <signal>toggled(bool)</signal>
270 <receiver>staticGroupBox</receiver>
271 <slot>setDisabled(bool)</slot>
272 </connection>
273</connections>
274<tabstops>
275 <tabstop>autoStart</tabstop>
276 <tabstop>dhcpCheckBox</tabstop>
277 <tabstop>leaseTime</tabstop>
278 <tabstop>ipAddressEdit</tabstop>
279 <tabstop>subnetMaskEdit</tabstop>
280 <tabstop>gatewayEdit</tabstop>
281 <tabstop>firstDNSLineEdit</tabstop>
282 <tabstop>secondDNSLineEdit</tabstop>
283</tabstops>
284</UI>
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
new file mode 100644
index 0000000..e717d6f
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -0,0 +1,148 @@
1#include "interfacesetupimp.h"
2#include "interface.h"
3#include "interfaces.h"
4
5#include <qdialog.h>
6#include <qcombobox.h>
7#include <qcheckbox.h>
8#include <qlineedit.h>
9#include <qspinbox.h>
10#include <qgroupbox.h>
11#include <qlabel.h>
12
13#include <qmessagebox.h>
14
15#include <assert.h>
16
17#define DNSSCRIPT "interfacednsscript"
18
19/**
20 * Constuctor. Set up the connection and load the first profile.
21 */
22InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){
23 assert(parent);
24 assert(i);
25 interface = i;
26 interfaces = new Interfaces();
27 bool error = false;
28 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
29 staticGroupBox->hide();
30 dhcpCheckBox->hide();
31 leaseTime->hide();
32 leaseHoursLabel->hide();
33 }
34}
35
36/**
37 * Save the current settings, then write out the interfaces file and close.
38 */
39void InterfaceSetupImp::saveChanges(){
40 if(!saveSettings())
41 return;
42 interfaces->write();
43}
44
45/**
46 * Save the settings for the current Interface.
47 * @return bool true if successfull, false otherwise
48 */
49bool InterfaceSetupImp::saveSettings(){
50 // eh can't really do anything about it other then return. :-D
51 if(!interfaces->isInterfaceSet())
52 return true;
53
54 bool error = false;
55 // Loopback case
56 if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){
57 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
58 return true;
59 }
60
61 if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){
62 QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok");
63 return false;
64 }
65 interfaces->removeAllInterfaceOptions();
66
67 // DHCP
68 if(dhcpCheckBox->isChecked()){
69 interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
70 interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value()));
71 interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60));
72 }
73 else{
74 interfaces->setInterfaceMethod("static");
75 interfaces->setInterfaceOption("address", ipAddressEdit->text());
76 interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
77 interfaces->setInterfaceOption("gateway", gatewayEdit->text());
78 QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
79 interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
80 interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
81 }
82
83 // IP Information
84 interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
85 return true;
86}
87
88/**
89 * The Profile has changed.
90 * @profile the new profile.
91 */
92void InterfaceSetupImp::setProfile(const QString &profile){
93 QString newInterfaceName = interface->getInterfaceName();
94 if(profile.length() > 0)
95 newInterfaceName += "_" + profile;
96 // See if we have to make a interface.
97 if(!interfaces->setInterface(newInterfaceName)){
98 // Add making for this new interface if need too
99 if(profile != ""){
100 interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
101 if(!interfaces->setMapping(interface->getInterfaceName())){
102 interfaces->addMapping(interface->getInterfaceName());
103 if(!interfaces->setMapping(interface->getInterfaceName())){
104 qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
105 return;
106 }
107 }
108 interfaces->setMap("map", newInterfaceName);
109 interfaces->setScript("getprofile.sh");
110 }
111 else{
112 interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP);
113 if(!interfaces->setInterface(newInterfaceName)){
114 qDebug("InterfaceSetupImp: Added interface, but still can't set.");
115 return;
116 }
117 }
118 }
119
120 // We must have a valid interface to get this far so read some settings.
121
122 // DHCP
123 bool error = false;
124 if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP)
125 dhcpCheckBox->setChecked(true);
126 else
127 dhcpCheckBox->setChecked(false);
128 leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt());
129 if(error)
130 leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60);
131 if(error)
132 leaseTime->setValue(24);
133
134 // IP Information
135 autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName()));
136 QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error);
137 if(dns.contains(" ")){
138 firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
139 secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length()));
140 }
141 ipAddressEdit->setText(interfaces->getInterfaceOption("address", error));
142 subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error));
143 gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error));
144}
145
146
147// interfacesetup.cpp
148
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.h b/noncore/settings/networksettings/interfaces/interfacesetupimp.h
new file mode 100644
index 0000000..936f2be
--- a/dev/null
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.h
@@ -0,0 +1,49 @@
1#ifndef INTERFACESETUPIMP_H
2#define INTERFACESETUPIMP_H
3
4#include "interfacesetup.h"
5#include <qdialog.h>
6
7class Interface;
8class Interfaces;
9
10class InterfaceSetupImp : public InterfaceSetup {
11 Q_OBJECT
12
13public:
14 InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0);
15 void saveChanges();
16
17public slots:
18 void setProfile(const QString &profile);
19 bool saveSettings();
20private:
21 Interfaces *interfaces;
22 Interface *interface;
23
24};
25
26
27#include <qlayout.h>
28
29class InterfaceSetupImpDialog : public QDialog {
30Q_OBJECT
31
32 public:
33 InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){
34 QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this );
35 setCaption("Interface Setup");
36 interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl);
37 InterfaceSetupLayout->addWidget( interfaceSetup );
38 };
39
40 InterfaceSetupImp *interfaceSetup;
41
42 protected slots:
43 void accept(){ interfaceSetup->saveChanges(); };
44};
45
46#endif
47
48// interfacesetupimp.h
49