author | benmeyer <benmeyer> | 2002-11-08 16:16:11 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-11-08 16:16:11 (UTC) |
commit | e0db2259cc26cab12c6f1131b82dd867c454a3ff (patch) (unidiff) | |
tree | e251396e5e96839aed5bf6a930dff37fefe5acc0 | |
parent | d8ac5b68b504536136347547816992b1cf605cd4 (diff) | |
download | opie-e0db2259cc26cab12c6f1131b82dd867c454a3ff.zip opie-e0db2259cc26cab12c6f1131b82dd867c454a3ff.tar.gz opie-e0db2259cc26cab12c6f1131b82dd867c454a3ff.tar.bz2 |
Code Optimizations
36 files changed, 238 insertions, 192 deletions
diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO index 8e57405..7185dbe 100644 --- a/noncore/net/networksetup/TODO +++ b/noncore/net/networksetup/TODO | |||
@@ -1,14 +1,13 @@ | |||
1 | CLEAN UP | 1 | CLEAN UP |
2 | 2 | ||
3 | Write a class that parses /proc and not ifconfig | ||
4 | |||
5 | udchcp needs to output the dhcp information so interfaces can read it | 3 | udchcp needs to output the dhcp information so interfaces can read it |
6 | 4 | ||
7 | interfacesetupimp really doesn't need a interface* pointer | 5 | interfacesetupimp really doesn't need a interface* pointer |
8 | 6 | ||
9 | Possible other modules to write: ppp, ipsec, bluetooth, ipchains | 7 | Possible other modules to write: ppp, ipsec, bluetooth, ipchains |
10 | 8 | ||
11 | PPP module needs to scan pppd.tdb to see what is currently active | 9 | PPP module needs to scan pppd.tdb to see what is currently active |
12 | 10 | ||
13 | WLAN - add possiblity to input text or hex without knowing "s:" | 11 | WLAN - add possiblity to input text or hex without knowing "s:" |
14 | 12 | ||
13 | Interface setupimp needs to use kernel calls. | ||
diff --git a/noncore/net/networksetup/addconnectionimp.cpp b/noncore/net/networksetup/addconnectionimp.cpp index 53db0fc..07545f7 100644 --- a/noncore/net/networksetup/addconnectionimp.cpp +++ b/noncore/net/networksetup/addconnectionimp.cpp | |||
@@ -1,38 +1,37 @@ | |||
1 | #include "addconnectionimp.h" | 1 | #include "addconnectionimp.h" |
2 | #include <qlistview.h> | 2 | #include <qlistview.h> |
3 | #include <qlist.h> | 3 | #include <qlist.h> |
4 | #include <qlabel.h> | 4 | #include <qlabel.h> |
5 | #include <qheader.h> | 5 | #include <qheader.h> |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Constructor | 8 | * Constructor |
9 | */ | 9 | */ |
10 | AddConnectionImp::AddConnectionImp(QWidget *parent, const char *name, WFlags f):AddConnection(parent, name, f){ | 10 | AddConnectionImp::AddConnectionImp(QWidget *parent, const char *name, WFlags f):AddConnection(parent, name, f){ |
11 | connect(registeredServicesList, SIGNAL(selectionChanged()), this, SLOT(changed())); | 11 | connect(registeredServicesList, SIGNAL(selectionChanged()), this, SLOT(changed())); |
12 | registeredServicesList->header()->hide(); | 12 | registeredServicesList->header()->hide(); |
13 | }; | 13 | }; |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * The current item changed, update the discription. | 16 | * The current item changed, update the discription. |
17 | */ | 17 | */ |
18 | void AddConnectionImp::changed(){ | 18 | void AddConnectionImp::changed(){ |
19 | QListViewItem *item = registeredServicesList->currentItem(); | 19 | QListViewItem *item = registeredServicesList->currentItem(); |
20 | if(item){ | 20 | if(item) |
21 | help->setText(list[item->text(0)]); | 21 | help->setText(list[item->text(0)]); |
22 | } | ||
23 | } | 22 | } |
24 | 23 | ||
25 | /** | 24 | /** |
26 | * Save a copy of newList for the discriptions and append them all to the view | 25 | * Save a copy of newList for the discriptions and append them all to the view |
27 | * @param newList the new list of possible interfaces | 26 | * @param newList the new list of possible interfaces |
28 | */ | 27 | */ |
29 | void AddConnectionImp::addConnections(QMap<QString, QString> newList){ | 28 | void AddConnectionImp::addConnections(const QMap<QString, QString> &newList){ |
30 | list = newList; | 29 | list = newList; |
31 | QMap<QString, QString>::Iterator it; | 30 | QMap<QString, QString>::Iterator it; |
32 | for( it = list.begin(); it != list.end(); ++it ) | 31 | for( it = list.begin(); it != list.end(); ++it ) |
33 | QListViewItem *item = new QListViewItem(registeredServicesList, it.key()); | 32 | QListViewItem *item = new QListViewItem(registeredServicesList, it.key()); |
34 | registeredServicesList->setCurrentItem(registeredServicesList->firstChild()); | 33 | registeredServicesList->setCurrentItem(registeredServicesList->firstChild()); |
35 | } | 34 | } |
36 | 35 | ||
37 | // addserviceimp.cpp | 36 | // addserviceimp.cpp |
38 | 37 | ||
diff --git a/noncore/net/networksetup/addconnectionimp.h b/noncore/net/networksetup/addconnectionimp.h index 643cd9a..680a502 100644 --- a/noncore/net/networksetup/addconnectionimp.h +++ b/noncore/net/networksetup/addconnectionimp.h | |||
@@ -1,29 +1,29 @@ | |||
1 | #ifndef ADDCONNECTIONIMP_H | 1 | #ifndef ADDCONNECTIONIMP_H |
2 | #define ADDCONNECTIONIMP_H | 2 | #define ADDCONNECTIONIMP_H |
3 | 3 | ||
4 | #include "addconnection.h" | 4 | #include "addconnection.h" |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qlist.h> | 6 | #include <qlist.h> |
7 | 7 | ||
8 | class QListViewItem; | 8 | class QListViewItem; |
9 | 9 | ||
10 | class AddConnectionImp : public AddConnection { | 10 | class AddConnectionImp : public AddConnection { |
11 | 11 | ||
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | 13 | ||
14 | public: | 14 | public: |
15 | AddConnectionImp(QWidget *parent=0, const char *name=0, WFlags f=0); | 15 | AddConnectionImp(QWidget *parent=0, const char *name=0, WFlags f=0); |
16 | void addConnections(QMap<QString, QString> newList); | 16 | void addConnections(const QMap<QString, QString> &newList); |
17 | 17 | ||
18 | private slots: | 18 | private slots: |
19 | void changed(); | 19 | void changed(); |
20 | 20 | ||
21 | private: | 21 | private: |
22 | QMap<QString, QString> list; | 22 | QMap<QString, QString> list; |
23 | 23 | ||
24 | }; | 24 | }; |
25 | 25 | ||
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | // addconectionimp.h | 28 | // addconectionimp.h |
29 | 29 | ||
diff --git a/noncore/net/networksetup/interfaces/interface.cpp b/noncore/net/networksetup/interfaces/interface.cpp index e4f405e..4129b3d 100644 --- a/noncore/net/networksetup/interfaces/interface.cpp +++ b/noncore/net/networksetup/interfaces/interface.cpp | |||
@@ -1,297 +1,297 @@ | |||
1 | #include "interface.h" | 1 | #include "interface.h" |
2 | #include <qdatetime.h> | 2 | #include <qdatetime.h> |
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qdir.h> | 4 | #include <qdir.h> |
5 | #include <qfileinfo.h> | 5 | #include <qfileinfo.h> |
6 | #include <qtextstream.h> | 6 | #include <qtextstream.h> |
7 | 7 | ||
8 | #define IFCONFIG "/sbin/ifconfig" | 8 | #define IFCONFIG "/sbin/ifconfig" |
9 | #define DHCP_INFO_DIR "/etc/dhcpc" | 9 | #define DHCP_INFO_DIR "/etc/dhcpc" |
10 | 10 | ||
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
13 | 13 | ||
14 | Interface::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){ | 14 | Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ |
15 | refresh(); | 15 | refresh(); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Set status | 19 | * Set status |
20 | * @param newStatus - the new status | 20 | * @param newStatus - the new status |
21 | * emit updateInterface | 21 | * emit updateInterface |
22 | */ | 22 | */ |
23 | void Interface::setStatus(bool newStatus){ | 23 | void Interface::setStatus(bool newStatus){ |
24 | if(status != newStatus){ | 24 | if(status != newStatus){ |
25 | status = newStatus; | 25 | status = newStatus; |
26 | refresh(); | 26 | refresh(); |
27 | } | 27 | } |
28 | }; | 28 | }; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Set if attached or not (802.11 card pulled out for example) | 31 | * Set if attached or not (802.11 card pulled out for example) |
32 | * @param isAttached - if attached | 32 | * @param isAttached - if attached |
33 | * emit updateInterface | 33 | * emit updateInterface |
34 | */ | 34 | */ |
35 | void Interface::setAttached(bool isAttached){ | 35 | void Interface::setAttached(bool isAttached){ |
36 | attached = isAttached; | 36 | attached = isAttached; |
37 | emit(updateInterface(this)); | 37 | emit(updateInterface(this)); |
38 | }; | 38 | }; |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Set Hardware name | 41 | * Set Hardware name |
42 | * @param name - the new name | 42 | * @param name - the new name |
43 | * emit updateInterface | 43 | * emit updateInterface |
44 | */ | 44 | */ |
45 | void Interface::setHardwareName(QString name){ | 45 | void Interface::setHardwareName(const QString &name){ |
46 | hardwareName = name; | 46 | hardwareName = name; |
47 | emit(updateInterface(this)); | 47 | emit(updateInterface(this)); |
48 | }; | 48 | }; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Set Module owner | 51 | * Set Module owner |
52 | * @param owner - the new owner | 52 | * @param owner - the new owner |
53 | * emit updateInterface | 53 | * emit updateInterface |
54 | */ | 54 | */ |
55 | void Interface::setModuleOwner(Module *owner){ | 55 | void Interface::setModuleOwner(Module *owner){ |
56 | moduleOwner = owner; | 56 | moduleOwner = owner; |
57 | emit(updateInterface(this)); | 57 | emit(updateInterface(this)); |
58 | }; | 58 | }; |
59 | 59 | ||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Try to start the interface. | 62 | * Try to start the interface. |
63 | */ | 63 | */ |
64 | void Interface::start(){ | 64 | void Interface::start(){ |
65 | // check to see if we are already running. | 65 | // check to see if we are already running. |
66 | if(true == status){ | 66 | if(true == status){ |
67 | emit (updateMessage("Unable to start interface,\n already started")); | 67 | emit (updateMessage("Unable to start interface,\n already started")); |
68 | return; | 68 | return; |
69 | } | 69 | } |
70 | 70 | ||
71 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); | 71 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); |
72 | // See if it was successfull... | 72 | // See if it was successfull... |
73 | if(ret != 0){ | 73 | if(ret != 0){ |
74 | emit (updateMessage("Starting interface failed.")); | 74 | emit (updateMessage("Starting interface failed.")); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | status = true; | 78 | status = true; |
79 | refresh(); | 79 | refresh(); |
80 | emit (updateMessage("Start successfull")); | 80 | emit (updateMessage("Start successfull")); |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Try to stop the interface. | 84 | * Try to stop the interface. |
85 | */ | 85 | */ |
86 | void Interface::stop(){ | 86 | void Interface::stop(){ |
87 | // check to see if we are already stopped. | 87 | // check to see if we are already stopped. |
88 | if(false == status){ | 88 | if(false == status){ |
89 | emit (updateMessage("Unable to stop interface,\n already stopped")); | 89 | emit (updateMessage("Unable to stop interface,\n already stopped")); |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | 92 | ||
93 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); | 93 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); |
94 | if(ret != 0){ | 94 | if(ret != 0){ |
95 | emit (updateMessage("Stopping interface failed.")); | 95 | emit (updateMessage("Stopping interface failed.")); |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | 98 | ||
99 | status = false; | 99 | status = false; |
100 | refresh(); | 100 | refresh(); |
101 | emit (updateMessage("Stop successfull")); | 101 | emit (updateMessage("Stop successfull")); |
102 | } | 102 | } |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Try to restart the interface. | 105 | * Try to restart the interface. |
106 | */ | 106 | */ |
107 | void Interface::restart(){ | 107 | void Interface::restart(){ |
108 | stop(); | 108 | stop(); |
109 | start(); | 109 | start(); |
110 | } | 110 | } |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Try to refresh the information about the interface. | 113 | * Try to refresh the information about the interface. |
114 | * First call ifconfig, then check the dhcp-info file | 114 | * First call ifconfig, then check the dhcp-info file |
115 | * @return bool true if successfull. | 115 | * @return bool true if successfull. |
116 | */ | 116 | */ |
117 | bool Interface::refresh(){ | 117 | bool Interface::refresh(){ |
118 | // See if we are up. | 118 | // See if we are up. |
119 | if(status == false){ | 119 | if(status == false){ |
120 | macAddress = ""; | 120 | macAddress = ""; |
121 | ip = "0.0.0.0"; | 121 | ip = "0.0.0.0"; |
122 | subnetMask = "0.0.0.0"; | 122 | subnetMask = "0.0.0.0"; |
123 | broadcast = ""; | 123 | broadcast = ""; |
124 | dhcp = false; | 124 | dhcp = false; |
125 | dhcpServerIp = ""; | 125 | dhcpServerIp = ""; |
126 | leaseObtained = ""; | 126 | leaseObtained = ""; |
127 | leaseExpires = ""; | 127 | leaseExpires = ""; |
128 | emit(updateInterface(this)); | 128 | emit(updateInterface(this)); |
129 | return true; | 129 | return true; |
130 | } | 130 | } |
131 | 131 | ||
132 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); | 132 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); |
133 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); | 133 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); |
134 | if(ret != 0){ | 134 | if(ret != 0){ |
135 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); | 135 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | 138 | ||
139 | QFile file(fileName); | 139 | QFile file(fileName); |
140 | if (!file.open(IO_ReadOnly)){ | 140 | if (!file.open(IO_ReadOnly)){ |
141 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 141 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
142 | return false; | 142 | return false; |
143 | } | 143 | } |
144 | 144 | ||
145 | // Set to the defaults | 145 | // Set to the defaults |
146 | macAddress = ""; | 146 | macAddress = ""; |
147 | ip = "0.0.0.0"; | 147 | ip = "0.0.0.0"; |
148 | subnetMask = "0.0.0.0"; | 148 | subnetMask = "0.0.0.0"; |
149 | broadcast = ""; | 149 | broadcast = ""; |
150 | 150 | ||
151 | QTextStream stream( &file ); | 151 | QTextStream stream( &file ); |
152 | QString line; | 152 | QString line; |
153 | while ( !stream.eof() ) { | 153 | while ( !stream.eof() ) { |
154 | line = stream.readLine(); | 154 | line = stream.readLine(); |
155 | if(line.contains("HWaddr")){ | 155 | if(line.contains("HWaddr")){ |
156 | int mac = line.find("HWaddr"); | 156 | int mac = line.find("HWaddr"); |
157 | macAddress = line.mid(mac+7, line.length()); | 157 | macAddress = line.mid(mac+7, line.length()); |
158 | } | 158 | } |
159 | if(line.contains("inet addr")){ | 159 | if(line.contains("inet addr")){ |
160 | int ipl = line.find("inet addr"); | 160 | int ipl = line.find("inet addr"); |
161 | int space = line.find(" ", ipl+10); | 161 | int space = line.find(" ", ipl+10); |
162 | ip = line.mid(ipl+10, space-ipl-10); | 162 | ip = line.mid(ipl+10, space-ipl-10); |
163 | } | 163 | } |
164 | if(line.contains("Mask")){ | 164 | if(line.contains("Mask")){ |
165 | int mask = line.find("Mask"); | 165 | int mask = line.find("Mask"); |
166 | subnetMask = line.mid(mask+5, line.length()); | 166 | subnetMask = line.mid(mask+5, line.length()); |
167 | } | 167 | } |
168 | if(line.contains("Bcast")){ | 168 | if(line.contains("Bcast")){ |
169 | int mask = line.find("Bcast"); | 169 | int mask = line.find("Bcast"); |
170 | int space = line.find(" ", mask+6); | 170 | int space = line.find(" ", mask+6); |
171 | broadcast = line.mid(mask+6, space-mask-6); | 171 | broadcast = line.mid(mask+6, space-mask-6); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | file.close(); | 174 | file.close(); |
175 | QFile::remove(fileName); | 175 | QFile::remove(fileName); |
176 | 176 | ||
177 | // DHCP TESTING | 177 | // DHCP TESTING |
178 | // reset DHCP info | 178 | // reset DHCP info |
179 | dhcpServerIp = ""; | 179 | dhcpServerIp = ""; |
180 | leaseObtained = ""; | 180 | leaseObtained = ""; |
181 | leaseExpires = ""; | 181 | leaseExpires = ""; |
182 | dhcp = false; | 182 | dhcp = false; |
183 | 183 | ||
184 | QString dhcpDirectory(DHCP_INFO_DIR); | 184 | QString dhcpDirectory(DHCP_INFO_DIR); |
185 | QDir d(dhcpDirectory); | 185 | QDir d(dhcpDirectory); |
186 | if(!d.exists(dhcpDirectory)) | 186 | if(!d.exists(dhcpDirectory)) |
187 | dhcpDirectory = "/var/run"; | 187 | dhcpDirectory = "/var/run"; |
188 | 188 | ||
189 | // See if we have | 189 | // See if we have |
190 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); | 190 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); |
191 | // If there is no DHCP information then exit now with no errors. | 191 | // If there is no DHCP information then exit now with no errors. |
192 | if(!QFile::exists(dhcpFile)){ | 192 | if(!QFile::exists(dhcpFile)){ |
193 | emit(updateInterface(this)); | 193 | emit(updateInterface(this)); |
194 | return true; | 194 | return true; |
195 | } | 195 | } |
196 | 196 | ||
197 | file.setName(dhcpFile); | 197 | file.setName(dhcpFile); |
198 | if (!file.open(IO_ReadOnly)){ | 198 | if (!file.open(IO_ReadOnly)){ |
199 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 199 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
200 | return false; | 200 | return false; |
201 | } | 201 | } |
202 | 202 | ||
203 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. | 203 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. |
204 | int leaseTime = 0; | 204 | int leaseTime = 0; |
205 | int renewalTime = 0; | 205 | int renewalTime = 0; |
206 | 206 | ||
207 | stream.setDevice( &file ); | 207 | stream.setDevice( &file ); |
208 | while ( !stream.eof() ) { | 208 | while ( !stream.eof() ) { |
209 | line = stream.readLine(); | 209 | line = stream.readLine(); |
210 | if(line.contains("DHCPSIADDR=")) | 210 | if(line.contains("DHCPSIADDR=")) |
211 | dhcpServerIp = line.mid(11, line.length()); | 211 | dhcpServerIp = line.mid(11, line.length()); |
212 | if(line.contains("LEASETIME=")) | 212 | if(line.contains("LEASETIME=")) |
213 | leaseTime = line.mid(10, line.length()).toInt(); | 213 | leaseTime = line.mid(10, line.length()).toInt(); |
214 | if(line.contains("RENEWALTIME=")) | 214 | if(line.contains("RENEWALTIME=")) |
215 | renewalTime = line.mid(12, line.length()).toInt(); | 215 | renewalTime = line.mid(12, line.length()).toInt(); |
216 | } | 216 | } |
217 | file.close(); | 217 | file.close(); |
218 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | 218 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); |
219 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | 219 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); |
220 | 220 | ||
221 | // Get the pid of the deamond | 221 | // Get the pid of the deamond |
222 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); | 222 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); |
223 | file.setName(dhcpFile); | 223 | file.setName(dhcpFile); |
224 | if (!file.open(IO_ReadOnly)){ | 224 | if (!file.open(IO_ReadOnly)){ |
225 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 225 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
226 | return false; | 226 | return false; |
227 | } | 227 | } |
228 | 228 | ||
229 | int pid = -1; | 229 | int pid = -1; |
230 | stream.setDevice( &file ); | 230 | stream.setDevice( &file ); |
231 | while ( !stream.eof() ) { | 231 | while ( !stream.eof() ) { |
232 | line = stream.readLine(); | 232 | line = stream.readLine(); |
233 | pid = line.toInt(); | 233 | pid = line.toInt(); |
234 | } | 234 | } |
235 | file.close(); | 235 | file.close(); |
236 | 236 | ||
237 | if( pid == -1){ | 237 | if( pid == -1){ |
238 | qDebug("Interface: Could not get pid of dhcpc deamon."); | 238 | qDebug("Interface: Could not get pid of dhcpc deamon."); |
239 | return false; | 239 | return false; |
240 | } | 240 | } |
241 | 241 | ||
242 | // Get the start running time of the deamon | 242 | // Get the start running time of the deamon |
243 | fileName = (QString("/proc/%1/stat").arg(pid)); | 243 | fileName = (QString("/proc/%1/stat").arg(pid)); |
244 | file.setName(fileName); | 244 | file.setName(fileName); |
245 | stream.setDevice( &file ); | 245 | stream.setDevice( &file ); |
246 | if (!file.open(IO_ReadOnly)){ | 246 | if (!file.open(IO_ReadOnly)){ |
247 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 247 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
248 | return false; | 248 | return false; |
249 | } | 249 | } |
250 | while ( !stream.eof() ) { | 250 | while ( !stream.eof() ) { |
251 | line = stream.readLine(); | 251 | line = stream.readLine(); |
252 | } | 252 | } |
253 | file.close(); | 253 | file.close(); |
254 | long time = 0; | 254 | long time = 0; |
255 | // Grab the start time | 255 | // Grab the start time |
256 | // pid com state ppid pgrp session tty_nr tpgid flags | 256 | // pid com state ppid pgrp session tty_nr tpgid flags |
257 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " | 257 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " |
258 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority | 258 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority |
259 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | 259 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " |
260 | // nice 0 itrealvalue starttime | 260 | // nice 0 itrealvalue starttime |
261 | "%*d %*d %*d %lu", (long*) &time); | 261 | "%*d %*d %*d %lu", (long*) &time); |
262 | time = time/100; | 262 | time = time/100; |
263 | 263 | ||
264 | QDateTime datetime(QDateTime::currentDateTime()); | 264 | QDateTime datetime(QDateTime::currentDateTime()); |
265 | 265 | ||
266 | // Get the uptime of the computer. | 266 | // Get the uptime of the computer. |
267 | QFile f("/proc/uptime"); | 267 | QFile f("/proc/uptime"); |
268 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 268 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
269 | QTextStream t( &f ); // use a text stream | 269 | QTextStream t( &f ); // use a text stream |
270 | int sec = 0; | 270 | int sec = 0; |
271 | t >> sec; | 271 | t >> sec; |
272 | datetime = datetime.addSecs((-1*sec)); | 272 | datetime = datetime.addSecs((-1*sec)); |
273 | f.close(); | 273 | f.close(); |
274 | } | 274 | } |
275 | else{ | 275 | else{ |
276 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | 276 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); |
277 | return false; | 277 | return false; |
278 | } | 278 | } |
279 | 279 | ||
280 | datetime = datetime.addSecs(time); | 280 | datetime = datetime.addSecs(time); |
281 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | 281 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); |
282 | 282 | ||
283 | // Calculate the start and renew times | 283 | // Calculate the start and renew times |
284 | leaseObtained= datetime.toString(); | 284 | leaseObtained= datetime.toString(); |
285 | 285 | ||
286 | // Calculate the start and renew times | 286 | // Calculate the start and renew times |
287 | datetime = datetime.addSecs(leaseTime); | 287 | datetime = datetime.addSecs(leaseTime); |
288 | leaseExpires = datetime.toString(); | 288 | leaseExpires = datetime.toString(); |
289 | 289 | ||
290 | dhcp = true; | 290 | dhcp = true; |
291 | 291 | ||
292 | emit(updateInterface(this)); | 292 | emit(updateInterface(this)); |
293 | return true; | 293 | return true; |
294 | } | 294 | } |
295 | 295 | ||
296 | // interface.cpp | 296 | // interface.cpp |
297 | 297 | ||
diff --git a/noncore/net/networksetup/interfaces/interface.h b/noncore/net/networksetup/interfaces/interface.h index fc064fe..989d6d8 100644 --- a/noncore/net/networksetup/interfaces/interface.h +++ b/noncore/net/networksetup/interfaces/interface.h | |||
@@ -1,72 +1,71 @@ | |||
1 | #ifndef INTERFACE_H | 1 | #ifndef INTERFACE_H |
2 | #define INTERFACE_H | 2 | #define INTERFACE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | 6 | ||
7 | class Module; | 7 | class Module; |
8 | 8 | ||
9 | class Interface : public QObject{ | 9 | class Interface : public QObject{ |
10 | Q_OBJECT | 10 | Q_OBJECT |
11 | 11 | ||
12 | signals: | 12 | signals: |
13 | void updateInterface(Interface *i); | 13 | void updateInterface(Interface *i); |
14 | void updateMessage(const QString &message); | 14 | void updateMessage(const QString &message); |
15 | 15 | ||
16 | public: | 16 | public: |
17 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); | 17 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); |
18 | virtual ~Interface(){}; | ||
19 | 18 | ||
20 | virtual QString getInterfaceName(){ QString n(this->name()); return n; }; | 19 | QString getInterfaceName(){ QString n(this->name()); return n; }; |
21 | 20 | ||
22 | virtual bool getStatus(){ return status; }; | 21 | bool getStatus(){ return status; }; |
23 | virtual void setStatus(bool newStatus); | 22 | void setStatus(bool newStatus); |
24 | 23 | ||
25 | virtual bool isAttached(){ return attached; }; | 24 | bool isAttached(){ return attached; }; |
26 | virtual void setAttached(bool isAttached=false); | 25 | void setAttached(bool isAttached=false); |
27 | 26 | ||
28 | virtual QString getHardwareName(){ return hardwareName; }; | 27 | QString getHardwareName(){ return hardwareName; }; |
29 | virtual void setHardwareName(QString name="Unknown"); | 28 | void setHardwareName(const QString &name="Unknown"); |
30 | 29 | ||
31 | virtual Module* getModuleOwner(){ return moduleOwner; }; | 30 | Module* getModuleOwner(){ return moduleOwner; }; |
32 | virtual void setModuleOwner(Module *owner=NULL); | 31 | void setModuleOwner(Module *owner=NULL); |
33 | 32 | ||
34 | // inet information. | 33 | // inet information. |
35 | QString getMacAddress(){ return macAddress; }; | 34 | QString getMacAddress(){ return macAddress; }; |
36 | QString getIp(){ return ip; }; | 35 | QString getIp(){ return ip; }; |
37 | QString getSubnetMask(){ return subnetMask; }; | 36 | QString getSubnetMask(){ return subnetMask; }; |
38 | QString getBroadcast(){ return broadcast; }; | 37 | QString getBroadcast(){ return broadcast; }; |
39 | bool isDhcp(){ return dhcp; }; | 38 | bool isDhcp(){ return dhcp; }; |
40 | QString getDhcpServerIp(){ return dhcpServerIp; }; | 39 | QString getDhcpServerIp(){ return dhcpServerIp; }; |
41 | QString getLeaseObtained(){ return leaseObtained; }; | 40 | QString getLeaseObtained(){ return leaseObtained; }; |
42 | QString getLeaseExpires(){ return leaseExpires; }; | 41 | QString getLeaseExpires(){ return leaseExpires; }; |
43 | 42 | ||
44 | public slots: | 43 | public slots: |
45 | bool refresh(); | 44 | bool refresh(); |
46 | void start(); | 45 | void start(); |
47 | void stop(); | 46 | void stop(); |
48 | void restart(); | 47 | void restart(); |
49 | 48 | ||
50 | private: | 49 | private: |
51 | // Interface information | 50 | // Interface information |
52 | bool status; | 51 | bool status; |
53 | bool attached; | 52 | bool attached; |
54 | QString hardwareName; | 53 | QString hardwareName; |
55 | Module *moduleOwner; | 54 | Module *moduleOwner; |
56 | 55 | ||
57 | // Network information | 56 | // Network information |
58 | QString macAddress; | 57 | QString macAddress; |
59 | QString ip; | 58 | QString ip; |
60 | QString broadcast; | 59 | QString broadcast; |
61 | QString subnetMask; | 60 | QString subnetMask; |
62 | bool dhcp; | 61 | bool dhcp; |
63 | QString dhcpServerIp; | 62 | QString dhcpServerIp; |
64 | QString leaseObtained; | 63 | QString leaseObtained; |
65 | QString leaseExpires; | 64 | QString leaseExpires; |
66 | 65 | ||
67 | }; | 66 | }; |
68 | 67 | ||
69 | #endif | 68 | #endif |
70 | 69 | ||
71 | // interface.h | 70 | // interface.h |
72 | 71 | ||
diff --git a/noncore/net/networksetup/interfaces/interfaces.cpp b/noncore/net/networksetup/interfaces/interfaces.cpp index f1b8067..708f399 100644 --- a/noncore/net/networksetup/interfaces/interfaces.cpp +++ b/noncore/net/networksetup/interfaces/interfaces.cpp | |||
@@ -1,638 +1,640 @@ | |||
1 | #include "interfaces.h" | 1 | #include "interfaces.h" |
2 | 2 | ||
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | #include <qregexp.h> | 5 | #include <qregexp.h> |
6 | 6 | ||
7 | #define AUTO "auto" | 7 | #define AUTO "auto" |
8 | #define IFACE "iface" | 8 | #define IFACE "iface" |
9 | #define MAPPING "mapping" | 9 | #define MAPPING "mapping" |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Constructor. Reads in the interfaces file and then split the file up by | 12 | * Constructor. Reads in the interfaces file and then split the file up by |
13 | * the \n for interfaces variable. | 13 | * the \n for interfaces variable. |
14 | * @param useInterfacesFile if an interface file other then the default is | 14 | * @param useInterfacesFile if an interface file other then the default is |
15 | * desired to be used it should be passed in. | 15 | * desired to be used it should be passed in. |
16 | */ | 16 | */ |
17 | Interfaces::Interfaces(QString useInterfacesFile){ | 17 | Interfaces::Interfaces(QString useInterfacesFile){ |
18 | acceptedFamily.append(INTERFACES_FAMILY_INET); | 18 | acceptedFamily.append(INTERFACES_FAMILY_INET); |
19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | 19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); |
20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | 20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); |
21 | 21 | ||
22 | interfacesFile = useInterfacesFile; | 22 | interfacesFile = useInterfacesFile; |
23 | QFile file(interfacesFile); | 23 | QFile file(interfacesFile); |
24 | if (!file.open(IO_ReadOnly)){ | 24 | if (!file.open(IO_ReadOnly)){ |
25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); | 25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); |
26 | currentIface = interfaces.end(); | 26 | currentIface = interfaces.end(); |
27 | currentMapping = interfaces.end(); | 27 | currentMapping = interfaces.end(); |
28 | return; | 28 | return; |
29 | } | 29 | } |
30 | QTextStream stream( &file ); | 30 | QTextStream stream( &file ); |
31 | QString line; | 31 | QString line; |
32 | while ( !stream.eof() ) { | 32 | while ( !stream.eof() ) { |
33 | line += stream.readLine(); | 33 | line += stream.readLine(); |
34 | line += "\n"; | 34 | line += "\n"; |
35 | } | 35 | } |
36 | file.close(); | 36 | file.close(); |
37 | interfaces = QStringList::split("\n", line, true); | 37 | interfaces = QStringList::split("\n", line, true); |
38 | 38 | ||
39 | currentIface = interfaces.end(); | 39 | currentIface = interfaces.end(); |
40 | currentMapping = interfaces.end(); | 40 | currentMapping = interfaces.end(); |
41 | } | 41 | } |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Get a list of all interfaces in the interface file. Usefull for | 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 | 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. | 47 | * not plugged in, but configured for when it is plugged in. |
48 | * @return Return string list of interfaces. | 48 | * @return Return string list of interfaces. |
49 | **/ | 49 | **/ |
50 | QStringList Interfaces::getInterfaceList(){ | 50 | QStringList Interfaces::getInterfaceList(){ |
51 | QStringList list; | 51 | QStringList list; |
52 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 52 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
53 | QString line = (*it).simplifyWhiteSpace(); | 53 | QString line = (*it).simplifyWhiteSpace(); |
54 | if(line.contains(IFACE) && line.at(0) != '#'){ | 54 | if(line.contains(IFACE) && line.at(0) != '#'){ |
55 | line = line.mid(QString(IFACE).length() +1, line.length()); | 55 | line = line.mid(QString(IFACE).length() +1, line.length()); |
56 | line = line.simplifyWhiteSpace(); | 56 | line = line.simplifyWhiteSpace(); |
57 | int findSpace = line.find(" "); | 57 | int findSpace = line.find(" "); |
58 | if( findSpace >= 0){ | 58 | if( findSpace >= 0){ |
59 | line = line.mid(0, findSpace); | 59 | line = line.mid(0, findSpace); |
60 | list.append(line); | 60 | list.append(line); |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | return list; | 64 | return list; |
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Find out if interface is in an "auto" group or not. | 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 | 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. | 70 | * @param interface interface to check to see if it is on or not. |
71 | * @return true is interface is in auto | 71 | * @return true is interface is in auto |
72 | */ | 72 | */ |
73 | bool Interfaces::isAuto(QString interface){ | 73 | bool Interfaces::isAuto(const QString &interface){ |
74 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | 74 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); |
75 | QStringList awi = autoLines.grep(QRegExp(interface)); | 75 | QStringList awi = autoLines.grep(QRegExp(interface)); |
76 | if(awi.count() > 1) | 76 | if(awi.count() > 1) |
77 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); | 77 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); |
78 | if(awi.count() < 1) | 78 | if(awi.count() < 1) |
79 | return false; | 79 | return false; |
80 | return true; | 80 | return true; |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Attempt to set the auto option for interface to setAuto. | 84 | * Attempt to set the auto option for interface to setAuto. |
85 | * @param interface the interface to set | 85 | * @param interface the interface to set |
86 | * @param setAuto the value to set interface to. | 86 | * @param setAuto the value to set interface to. |
87 | * @return false if already set to setAuto. | 87 | * @return false if already set to setAuto. |
88 | * */ | 88 | * */ |
89 | bool Interfaces::setAuto(QString interface, bool setAuto){ | 89 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ |
90 | // Don't need to set it if it is already set. | 90 | // Don't need to set it if it is already set. |
91 | if(isAuto(interface) == setAuto) | 91 | if(isAuto(interface) == setAuto) |
92 | return false; | 92 | return false; |
93 | 93 | ||
94 | bool changed = false; | 94 | bool changed = false; |
95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
96 | if((*it).contains(AUTO)){ | 96 | if((*it).contains(AUTO)){ |
97 | //We know that they are not in any group so let add to this auto. | 97 | //We know that they are not in any group so let add to this auto. |
98 | if(setAuto){ | 98 | if(setAuto){ |
99 | (*it) = (*it) += " " + interface; | 99 | (*it) = (*it) += " " + interface; |
100 | // Don't care to have such thins as: auto eth0 lo usb0 | 100 | // Don't care to have such thins as: auto eth0 lo usb0 |
101 | (*it) = (*it).simplifyWhiteSpace(); | 101 | (*it) = (*it).simplifyWhiteSpace(); |
102 | changed = true; | 102 | changed = true; |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | else{ | 105 | else{ |
106 | if((*it).contains(interface)){ | 106 | if((*it).contains(interface)){ |
107 | (*it) = (*it).replace(QRegExp(interface), ""); | 107 | (*it) = (*it).replace(QRegExp(interface), ""); |
108 | // clean up | 108 | // clean up |
109 | QString line = (*it).simplifyWhiteSpace(); | 109 | QString line = (*it).simplifyWhiteSpace(); |
110 | line = line.replace(QRegExp(" "),""); | 110 | line = line.replace(QRegExp(" "),""); |
111 | if(line == AUTO) | 111 | if(line == AUTO) |
112 | (*it) = ""; | 112 | (*it) = ""; |
113 | changed = true; | 113 | changed = true; |
114 | // Don't break because we want to make sure we remove all cases. | 114 | // Don't break because we want to make sure we remove all cases. |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | if(changed == false){ | 119 | if(changed == false){ |
120 | if(setAuto == true) | 120 | if(setAuto == true) |
121 | interfaces.append(QString(AUTO" %1").arg(interface)); | 121 | interfaces.append(QString(AUTO" %1").arg(interface)); |
122 | else{ | 122 | else{ |
123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | 123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | return true; | 126 | return true; |
127 | } | 127 | } |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * Set the current interface to interface. This needs to be done before you | 130 | * Set the current interface to interface. This needs to be done before you |
131 | * can call getFamily(), getMethod, and get/setOption(). | 131 | * can call getFamily(), getMethod, and get/setOption(). |
132 | * @param interface the name of the interface to set. All whitespace is | 132 | * @param interface the name of the interface to set. All whitespace is |
133 | * removed from the interface name. | 133 | * removed from the interface name. |
134 | * @return bool true if it is successfull. | 134 | * @return bool true if it is successfull. |
135 | */ | 135 | */ |
136 | bool Interfaces::setInterface(QString interface){ | 136 | bool Interfaces::setInterface(QString interface){ |
137 | interface = interface.simplifyWhiteSpace(); | 137 | interface = interface.simplifyWhiteSpace(); |
138 | interface = interface.replace(QRegExp(" "), ""); | 138 | interface = interface.replace(QRegExp(" "), ""); |
139 | return setStanza(IFACE, interface, currentIface); | 139 | return setStanza(IFACE, interface, currentIface); |
140 | } | 140 | } |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * A quick helper funtion to see if the current interface is set. | 143 | * A quick helper funtion to see if the current interface is set. |
144 | * @return bool true if set, false otherwise. | 144 | * @return bool true if set, false otherwise. |
145 | */ | 145 | */ |
146 | bool Interfaces::isInterfaceSet(){ | 146 | bool Interfaces::isInterfaceSet(){ |
147 | return (currentIface != interfaces.end()); | 147 | return (currentIface != interfaces.end()); |
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Add a new interface of with the settings - family and method | 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 | 152 | * @param interface the name of the interface to set. All whitespace is |
153 | * removed from the interface name. | 153 | * removed from the interface name. |
154 | * @param family the family of this interface inet or inet, ipx or inet6 | 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 | 155 | * Must of one of the families defined in interfaces.h |
156 | * @param method for the family. see interfaces man page for family methods. | 156 | * @param method for the family. see interfaces man page for family methods. |
157 | * @return true if successfull. | 157 | * @return true if successfull. |
158 | */ | 158 | */ |
159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ | 159 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ |
160 | if(acceptedFamily.contains(family)==0) | 160 | if(acceptedFamily.contains(family)==0) |
161 | return false; | 161 | return false; |
162 | interface = interface.simplifyWhiteSpace(); | 162 | QString newInterface = interface.simplifyWhiteSpace(); |
163 | interface = interface.replace(QRegExp(" "), ""); | 163 | newInterface = newInterface.replace(QRegExp(" "), ""); |
164 | interfaces.append(""); | 164 | interfaces.append(""); |
165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); | 165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); |
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Copies interface with name interface to name newInterface | 170 | * Copies interface with name interface to name newInterface |
171 | * @param newInterface name of the new interface. | 171 | * @param newInterface name of the new interface. |
172 | * @return bool true if successfull | 172 | * @return bool true if successfull |
173 | */ | 173 | */ |
174 | bool Interfaces::copyInterface(QString interface, QString newInterface){ | 174 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ |
175 | if(!setInterface(interface)) return false; | 175 | if(!setInterface(interface)) return false; |
176 | 176 | ||
177 | QStringList::Iterator it = currentIface; | 177 | QStringList::Iterator it = currentIface; |
178 | it++; | 178 | it++; |
179 | 179 | ||
180 | bool error; | 180 | bool error; |
181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | 181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); |
182 | if(!setInterface(newInterface)) return false; | 182 | if(!setInterface(newInterface)) return false; |
183 | QStringList::Iterator newIface = currentIface; | 183 | QStringList::Iterator newIface = currentIface; |
184 | newIface++; | 184 | newIface++; |
185 | 185 | ||
186 | for ( ; it != interfaces.end(); ++it ){ | 186 | for ( ; it != interfaces.end(); ++it ){ |
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | 187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) |
188 | break; | 188 | break; |
189 | newIface = interfaces.insert(newIface, *it); | 189 | newIface = interfaces.insert(newIface, *it); |
190 | } | 190 | } |
191 | 191 | ||
192 | return true; | 192 | return true; |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Remove the currently selected interface and all of its options. | 196 | * Remove the currently selected interface and all of its options. |
197 | * @return bool if successfull or not. | 197 | * @return bool if successfull or not. |
198 | */ | 198 | */ |
199 | bool Interfaces::removeInterface(){ | 199 | bool Interfaces::removeInterface(){ |
200 | if(currentIface == interfaces.end()) | 200 | if(currentIface == interfaces.end()) |
201 | return false; | 201 | return false; |
202 | (*currentIface) = ""; | 202 | (*currentIface) = ""; |
203 | return removeAllInterfaceOptions(); | 203 | return removeAllInterfaceOptions(); |
204 | } | 204 | } |
205 | 205 | ||
206 | /** | 206 | /** |
207 | * Gets the hardware name of the interface that is currently selected. | 207 | * Gets the hardware name of the interface that is currently selected. |
208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
209 | * @param error set to true if any error occurs, false otherwise. | 209 | * @param error set to true if any error occurs, false otherwise. |
210 | */ | 210 | */ |
211 | QString Interfaces::getInterfaceName(bool &error){ | 211 | QString Interfaces::getInterfaceName(bool &error){ |
212 | if(currentIface == interfaces.end()){ | 212 | if(currentIface == interfaces.end()){ |
213 | error = true; | 213 | error = true; |
214 | return QString(); | 214 | return QString(); |
215 | } | 215 | } |
216 | QString line = (*currentIface); | 216 | QString line = (*currentIface); |
217 | line = line.mid(QString(IFACE).length() +1, line.length()); | 217 | line = line.mid(QString(IFACE).length() +1, line.length()); |
218 | line = line.simplifyWhiteSpace(); | 218 | line = line.simplifyWhiteSpace(); |
219 | int findSpace = line.find(" "); | 219 | int findSpace = line.find(" "); |
220 | if( findSpace < 0){ | 220 | if( findSpace < 0){ |
221 | error = true; | 221 | error = true; |
222 | return QString(); | 222 | return QString(); |
223 | } | 223 | } |
224 | error = false; | 224 | error = false; |
225 | return line.mid(0, findSpace); | 225 | return line.mid(0, findSpace); |
226 | } | 226 | } |
227 | 227 | ||
228 | /** | 228 | /** |
229 | * Gets the family name of the interface that is currently selected. | 229 | * Gets the family name of the interface that is currently selected. |
230 | * @return QString name of the family (inet, inet6, ipx). | 230 | * @return QString name of the family (inet, inet6, ipx). |
231 | * @param error set to true if any error occurs, false otherwise. | 231 | * @param error set to true if any error occurs, false otherwise. |
232 | */ | 232 | */ |
233 | QString Interfaces::getInterfaceFamily(bool &error){ | 233 | QString Interfaces::getInterfaceFamily(bool &error){ |
234 | QString name = getInterfaceName(error); | 234 | QString name = getInterfaceName(error); |
235 | if(error){ | 235 | if(error){ |
236 | error = true; | 236 | error = true; |
237 | return QString(); | 237 | return QString(); |
238 | } | 238 | } |
239 | QString line = (*currentIface); | 239 | QString line = (*currentIface); |
240 | line = line.mid(QString(IFACE).length() +1, line.length()); | 240 | line = line.mid(QString(IFACE).length() +1, line.length()); |
241 | line = line.mid(name.length()+1, line.length()); | 241 | line = line.mid(name.length()+1, line.length()); |
242 | line = line.simplifyWhiteSpace(); | 242 | line = line.simplifyWhiteSpace(); |
243 | int findSpace = line.find(" "); | 243 | int findSpace = line.find(" "); |
244 | if( findSpace < 0){ | 244 | if( findSpace < 0){ |
245 | error = true; | 245 | error = true; |
246 | return QString(); | 246 | return QString(); |
247 | } | 247 | } |
248 | error = false; | 248 | error = false; |
249 | return line.mid(0, findSpace); | 249 | return line.mid(0, findSpace); |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * Gets the method of the interface that is currently selected. | 253 | * Gets the method of the interface that is currently selected. |
254 | * @return QString name of the method such as staic or dhcp. | 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. | 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. | 256 | * @param error set to true if any error occurs, false otherwise. |
257 | */ | 257 | */ |
258 | QString Interfaces::getInterfaceMethod(bool &error){ | 258 | QString Interfaces::getInterfaceMethod(bool &error){ |
259 | QString name = getInterfaceName(error); | 259 | QString name = getInterfaceName(error); |
260 | if(error){ | 260 | if(error){ |
261 | error = true; | 261 | error = true; |
262 | return QString(); | 262 | return QString(); |
263 | } | 263 | } |
264 | QString family = getInterfaceFamily(error); | 264 | QString family = getInterfaceFamily(error); |
265 | if(error){ | 265 | if(error){ |
266 | error = true; | 266 | error = true; |
267 | return QString(); | 267 | return QString(); |
268 | } | 268 | } |
269 | QString line = (*currentIface); | 269 | QString line = (*currentIface); |
270 | line = line.mid(QString(IFACE).length()+1, line.length()); | 270 | line = line.mid(QString(IFACE).length()+1, line.length()); |
271 | line = line.mid(name.length()+1, line.length()); | 271 | line = line.mid(name.length()+1, line.length()); |
272 | line = line.mid(family.length()+1, line.length()); | 272 | line = line.mid(family.length()+1, line.length()); |
273 | line = line.simplifyWhiteSpace(); | 273 | line = line.simplifyWhiteSpace(); |
274 | error = false; | 274 | error = false; |
275 | return line; | 275 | return line; |
276 | } | 276 | } |
277 | 277 | ||
278 | /** | 278 | /** |
279 | * Sets the interface name to newName. | 279 | * Sets the interface name to newName. |
280 | * @param newName the new name of the interface. All whitespace is removed. | 280 | * @param newName the new name of the interface. All whitespace is removed. |
281 | * @return bool true if successfull. | 281 | * @return bool true if successfull. |
282 | */ | 282 | */ |
283 | bool Interfaces::setInterfaceName(QString newName){ | 283 | bool Interfaces::setInterfaceName(const QString &newName){ |
284 | if(currentIface == interfaces.end()) | 284 | if(currentIface == interfaces.end()) |
285 | return false; | 285 | return false; |
286 | newName = newName.simplifyWhiteSpace(); | 286 | QString name = newName.simplifyWhiteSpace(); |
287 | newName = newName.replace(QRegExp(" "), ""); | 287 | name = name.replace(QRegExp(" "), ""); |
288 | bool returnValue = false; | 288 | bool returnValue = false; |
289 | (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); | 289 | (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); |
290 | return !returnValue; | 290 | return !returnValue; |
291 | } | 291 | } |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Sets the interface family to newName. | 294 | * Sets the interface family to newName. |
295 | * @param newName the new name of the interface. Must be one of the families | 295 | * @param newName the new name of the interface. Must be one of the families |
296 | * defined in the interfaces.h file. | 296 | * defined in the interfaces.h file. |
297 | * @return bool true if successfull. | 297 | * @return bool true if successfull. |
298 | */ | 298 | */ |
299 | bool Interfaces::setInterfaceFamily(QString newName){ | 299 | bool Interfaces::setInterfaceFamily(const QString &newName){ |
300 | if(currentIface == interfaces.end()) | 300 | if(currentIface == interfaces.end()) |
301 | return false; | 301 | return false; |
302 | if(acceptedFamily.contains(newName)==0) | 302 | if(acceptedFamily.contains(newName)==0) |
303 | return false; | 303 | return false; |
304 | bool returnValue = false; | 304 | bool returnValue = false; |
305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | 305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); |
306 | return !returnValue; | 306 | return !returnValue; |
307 | } | 307 | } |
308 | 308 | ||
309 | /** | 309 | /** |
310 | * Sets the interface method to newName | 310 | * Sets the interface method to newName |
311 | * @param newName the new name of the interface | 311 | * @param newName the new name of the interface |
312 | * @return bool true if successfull. | 312 | * @return bool true if successfull. |
313 | */ | 313 | */ |
314 | bool Interfaces::setInterfaceMethod(QString newName){ | 314 | bool Interfaces::setInterfaceMethod(const QString &newName){ |
315 | if(currentIface == interfaces.end()) | 315 | if(currentIface == interfaces.end()) |
316 | return false; | 316 | return false; |
317 | bool returnValue = false; | 317 | bool returnValue = false; |
318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | 318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); |
319 | return !returnValue; | 319 | return !returnValue; |
320 | } | 320 | } |
321 | 321 | ||
322 | /** | 322 | /** |
323 | * Get a value for an option in the currently selected interface. For example | 323 | * Get a value for an option in the currently selected interface. For example |
324 | * calling getInterfaceOption("address") on the following stanza would | 324 | * calling getInterfaceOption("address") on the following stanza would |
325 | * return 192.168.1.1. | 325 | * return 192.168.1.1. |
326 | * iface eth0 static | 326 | * iface eth0 static |
327 | * address 192.168.1.1 | 327 | * address 192.168.1.1 |
328 | * @param option the options to get the value. | 328 | * @param option the options to get the value. |
329 | * @param error set to true if any error occurs, false otherwise. | 329 | * @param error set to true if any error occurs, false otherwise. |
330 | * @return QString the options value. QString::null if error == true | 330 | * @return QString the options value. QString::null if error == true |
331 | */ | 331 | */ |
332 | QString Interfaces::getInterfaceOption(QString option, bool &error){ | 332 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ |
333 | return getOption(currentIface, option, error); | 333 | return getOption(currentIface, option, error); |
334 | } | 334 | } |
335 | 335 | ||
336 | /** | 336 | /** |
337 | * Set a value for an option in the currently selected interface. If option | 337 | * Set a value for an option in the currently selected interface. If option |
338 | * doesn't exist then it is added along with the value. | 338 | * doesn't exist then it is added along with the value. |
339 | * @param option the options to set the value. | 339 | * @param option the options to set the value. |
340 | * @param value the value that option should be set to. | 340 | * @param value the value that option should be set to. |
341 | * @param error set to true if any error occurs, false otherwise. | 341 | * @param error set to true if any error occurs, false otherwise. |
342 | * @return QString the options value. QString::null if error == true | 342 | * @return QString the options value. QString::null if error == true |
343 | */ | 343 | */ |
344 | bool Interfaces::setInterfaceOption(QString option, QString value){ | 344 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ |
345 | return setOption(currentIface, option, value); | 345 | return setOption(currentIface, option, value); |
346 | } | 346 | } |
347 | 347 | ||
348 | /** | 348 | /** |
349 | * Removes a value for an option in the currently selected interface. | 349 | * Removes a value for an option in the currently selected interface. |
350 | * @param option the options to set the value. | 350 | * @param option the options to set the value. |
351 | * @param value the value that option should be set to. | 351 | * @param value the value that option should be set to. |
352 | * @param error set to true if any error occurs, false otherwise. | 352 | * @param error set to true if any error occurs, false otherwise. |
353 | * @return QString the options value. QString::null if error == true | 353 | * @return QString the options value. QString::null if error == true |
354 | */ | 354 | */ |
355 | bool Interfaces::removeInterfaceOption(QString option, QString value){ | 355 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ |
356 | return removeOption(currentIface, option, value); | 356 | return removeOption(currentIface, option, value); |
357 | } | 357 | } |
358 | 358 | ||
359 | /** | 359 | /** |
360 | * Removes all of the options from the currently selected interface. | 360 | * Removes all of the options from the currently selected interface. |
361 | * @return bool error if if successfull | 361 | * @return bool error if if successfull |
362 | */ | 362 | */ |
363 | bool Interfaces::removeAllInterfaceOptions(){ | 363 | bool Interfaces::removeAllInterfaceOptions(){ |
364 | return removeAllOptions(currentIface); | 364 | return removeAllOptions(currentIface); |
365 | } | 365 | } |
366 | 366 | ||
367 | /** | 367 | /** |
368 | * Set the current map to interface's map. This needs to be done before you | 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(). | 369 | * can call addMapping(), set/getMap(), and get/setScript(). |
370 | * @param interface the name of the interface to set. All whitespace is | 370 | * @param interface the name of the interface to set. All whitespace is |
371 | * removed from the interface name. | 371 | * removed from the interface name. |
372 | * @return bool true if it is successfull. | 372 | * @return bool true if it is successfull. |
373 | */ | 373 | */ |
374 | bool Interfaces::setMapping(QString interface){ | 374 | bool Interfaces::setMapping(const QString &interface){ |
375 | interface = interface.simplifyWhiteSpace(); | 375 | QString interfaceName = interface.simplifyWhiteSpace(); |
376 | interface = interface.replace(QRegExp(" "), ""); | 376 | interfaceName = interfaceName.replace(QRegExp(" "), ""); |
377 | return setStanza(MAPPING, interface, currentMapping); | 377 | return setStanza(MAPPING, interfaceName, currentMapping); |
378 | } | 378 | } |
379 | 379 | ||
380 | /** | 380 | /** |
381 | * Adds a new Mapping to the interfaces file with interfaces. | 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 | 382 | * @param interface the name(s) of the interfaces to set to this mapping |
383 | */ | 383 | */ |
384 | void Interfaces::addMapping(QString option){ | 384 | void Interfaces::addMapping(const QString &option){ |
385 | interfaces.append(""); | 385 | interfaces.append(""); |
386 | interfaces.append(QString(MAPPING " %1").arg(option)); | 386 | interfaces.append(QString(MAPPING " %1").arg(option)); |
387 | } | 387 | } |
388 | 388 | ||
389 | /** | 389 | /** |
390 | * Remove the currently selected map and all of its options. | 390 | * Remove the currently selected map and all of its options. |
391 | * @return bool if successfull or not. | 391 | * @return bool if successfull or not. |
392 | */ | 392 | */ |
393 | bool Interfaces::removeMapping(){ | 393 | bool Interfaces::removeMapping(){ |
394 | if(currentMapping == interfaces.end()) | 394 | if(currentMapping == interfaces.end()) |
395 | return false; | 395 | return false; |
396 | (*currentMapping) = ""; | 396 | (*currentMapping) = ""; |
397 | return removeAllOptions(currentMapping); | 397 | return removeAllOptions(currentMapping); |
398 | } | 398 | } |
399 | 399 | ||
400 | /** | 400 | /** |
401 | * Set a map option within a mapping. | 401 | * Set a map option within a mapping. |
402 | * @param map map to use | 402 | * @param map map to use |
403 | * @param value value to go with map | 403 | * @param value value to go with map |
404 | * @return bool true if it is successfull. | 404 | * @return bool true if it is successfull. |
405 | */ | 405 | */ |
406 | bool Interfaces::setMap(QString map, QString value){ | 406 | bool Interfaces::setMap(const QString &map, const QString &value){ |
407 | return setOption(currentMapping, map, value); | 407 | return setOption(currentMapping, map, value); |
408 | } | 408 | } |
409 | 409 | ||
410 | /** | 410 | /** |
411 | * Removes a map option within a mapping. | 411 | * Removes a map option within a mapping. |
412 | * @param map map to use | 412 | * @param map map to use |
413 | * @param value value to go with map | 413 | * @param value value to go with map |
414 | * @return bool true if it is successfull. | 414 | * @return bool true if it is successfull. |
415 | */ | 415 | */ |
416 | bool Interfaces::removeMap(QString map, QString value){ | 416 | bool Interfaces::removeMap(const QString &map, const QString &value){ |
417 | return removeOption(currentMapping, map, value); | 417 | return removeOption(currentMapping, map, value); |
418 | } | 418 | } |
419 | 419 | ||
420 | /** | 420 | /** |
421 | * Get a map value within a mapping. | 421 | * Get a map value within a mapping. |
422 | * @param map map to get value of | 422 | * @param map map to get value of |
423 | * @param bool true if it is successfull. | 423 | * @param bool true if it is successfull. |
424 | * @return value that goes to the map | 424 | * @return value that goes to the map |
425 | */ | 425 | */ |
426 | QString Interfaces::getMap(QString map, bool &error){ | 426 | QString Interfaces::getMap(const QString &map, bool &error){ |
427 | return getOption(currentMapping, map, error); | 427 | return getOption(currentMapping, map, error); |
428 | } | 428 | } |
429 | 429 | ||
430 | /** | 430 | /** |
431 | * Sets a script value of the current mapping to argument. | 431 | * Sets a script value of the current mapping to argument. |
432 | * @param argument the script name. | 432 | * @param argument the script name. |
433 | * @return true if successfull. | 433 | * @return true if successfull. |
434 | */ | 434 | */ |
435 | bool Interfaces::setScript(QString argument){ | 435 | bool Interfaces::setScript(const QString &argument){ |
436 | return setOption(currentMapping, "script", argument); | 436 | return setOption(currentMapping, "script", argument); |
437 | } | 437 | } |
438 | 438 | ||
439 | /** | 439 | /** |
440 | * @param error true if could not retrieve the current script argument. | 440 | * @param error true if could not retrieve the current script argument. |
441 | * @return QString the argument of the script for the current mapping. | 441 | * @return QString the argument of the script for the current mapping. |
442 | */ | 442 | */ |
443 | QString Interfaces::getScript(bool &error){ | 443 | QString Interfaces::getScript(bool &error){ |
444 | return getOption(currentMapping, "script", error); | 444 | return getOption(currentMapping, "script", error); |
445 | } | 445 | } |
446 | 446 | ||
447 | |||
448 | |||
447 | /** | 449 | /** |
448 | * Helper function used to parse through the QStringList and put pointers in | 450 | * Helper function used to parse through the QStringList and put pointers in |
449 | * the correct place. | 451 | * the correct place. |
450 | * @param stanza The stanza (auto, iface, mapping) to look for. | 452 | * @param stanza The stanza (auto, iface, mapping) to look for. |
451 | * @param option string that must be in the stanza's main line. | 453 | * @param option string that must be in the stanza's main line. |
452 | * @param interator interator to place at location of stanza if successfull. | 454 | * @param interator interator to place at location of stanza if successfull. |
453 | * @return bool true if the stanza is found. | 455 | * @return bool true if the stanza is found. |
454 | */ | 456 | */ |
455 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ | 457 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ |
456 | bool found = false; | 458 | bool found = false; |
457 | iterator = interfaces.end(); | 459 | iterator = interfaces.end(); |
458 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 460 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
459 | QString line = (*it).simplifyWhiteSpace(); | 461 | QString line = (*it).simplifyWhiteSpace(); |
460 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ | 462 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ |
461 | uint point = line.find(option); | 463 | uint point = line.find(option); |
462 | bool valid = true; | 464 | bool valid = true; |
463 | if(point > 0){ | 465 | if(point > 0){ |
464 | // There are more chars in the line. check +1 | 466 | // There are more chars in the line. check +1 |
465 | if(line.at(point-1) != ' ') | 467 | if(line.at(point-1) != ' ') |
466 | valid = false; | 468 | valid = false; |
467 | } | 469 | } |
468 | point += option.length(); | 470 | point += option.length(); |
469 | if(point < line.length()-1){ | 471 | if(point < line.length()-1){ |
470 | // There are more chars in the line. check -1 | 472 | // There are more chars in the line. check -1 |
471 | if(line.at(point) != ' ') | 473 | if(line.at(point) != ' ') |
472 | valid = false; | 474 | valid = false; |
473 | } | 475 | } |
474 | if(valid){ | 476 | if(valid){ |
475 | if(found == true){ | 477 | if(found == true){ |
476 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 478 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); |
477 | } | 479 | } |
478 | found = true; | 480 | found = true; |
479 | iterator = it; | 481 | iterator = it; |
480 | } | 482 | } |
481 | } | 483 | } |
482 | } | 484 | } |
483 | return found; | 485 | return found; |
484 | } | 486 | } |
485 | 487 | ||
486 | /** | 488 | /** |
487 | * Sets a value of an option in a stanza | 489 | * Sets a value of an option in a stanza |
488 | * @param start the start of the stanza | 490 | * @param start the start of the stanza |
489 | * @param option the option to use when setting value. | 491 | * @param option the option to use when setting value. |
490 | * @return bool true if successfull, false otherwise. | 492 | * @return bool true if successfull, false otherwise. |
491 | */ | 493 | */ |
492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | 494 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
493 | if(start == interfaces.end()) | 495 | if(start == interfaces.end()) |
494 | return false; | 496 | return false; |
495 | 497 | ||
496 | bool found = false; | 498 | bool found = false; |
497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 499 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
498 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 500 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
499 | if(!found && value != ""){ | 501 | if(!found && value != ""){ |
500 | // Got to the end of the stanza without finding it, so append it. | 502 | // 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)); | 503 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); |
502 | } | 504 | } |
503 | found = true; | 505 | found = true; |
504 | break; | 506 | break; |
505 | } | 507 | } |
506 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 508 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
507 | // Found it in stanza so replace it. | 509 | // Found it in stanza so replace it. |
508 | if(found) | 510 | if(found) |
509 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 511 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
510 | found = true; | 512 | found = true; |
511 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 513 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
512 | } | 514 | } |
513 | } | 515 | } |
514 | if(!found){ | 516 | if(!found){ |
515 | QStringList::Iterator p = start; | 517 | QStringList::Iterator p = start; |
516 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 518 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
517 | found = true; | 519 | found = true; |
518 | } | 520 | } |
519 | return found; | 521 | return found; |
520 | } | 522 | } |
521 | /** | 523 | /** |
522 | * Removes a option in a stanza | 524 | * Removes a option in a stanza |
523 | * @param start the start of the stanza | 525 | * @param start the start of the stanza |
524 | * @param option the option to use when setting value. | 526 | * @param option the option to use when setting value. |
525 | * @return bool true if successfull, false otherwise. | 527 | * @return bool true if successfull, false otherwise. |
526 | */ | 528 | */ |
527 | bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ | 529 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
528 | if(start == interfaces.end()) | 530 | if(start == interfaces.end()) |
529 | return false; | 531 | return false; |
530 | 532 | ||
531 | bool found = false; | 533 | bool found = false; |
532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 534 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 535 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
534 | // got to the end without finding it | 536 | // got to the end without finding it |
535 | break; | 537 | break; |
536 | } | 538 | } |
537 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 539 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
538 | // Found it in stanza so replace it. | 540 | // Found it in stanza so replace it. |
539 | if(found) | 541 | if(found) |
540 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 542 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
541 | found = true; | 543 | found = true; |
542 | (*it) = ""; | 544 | (*it) = ""; |
543 | } | 545 | } |
544 | } | 546 | } |
545 | return found; | 547 | return found; |
546 | } | 548 | } |
547 | 549 | ||
548 | /** | 550 | /** |
549 | * Removes all options in a stanza | 551 | * Removes all options in a stanza |
550 | * @param start the start of the stanza | 552 | * @param start the start of the stanza |
551 | * @return bool true if successfull, false otherwise. | 553 | * @return bool true if successfull, false otherwise. |
552 | */ | 554 | */ |
553 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | 555 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ |
554 | if(start == interfaces.end()) | 556 | if(start == interfaces.end()) |
555 | return false; | 557 | return false; |
556 | 558 | ||
557 | QStringList::Iterator it = start; | 559 | QStringList::Iterator it = start; |
558 | it = ++it; | 560 | it = ++it; |
559 | for (; it != interfaces.end(); ++it ) { | 561 | for (; it != interfaces.end(); ++it ) { |
560 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 562 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
561 | break; | 563 | break; |
562 | } | 564 | } |
563 | it = interfaces.remove(it); | 565 | it = interfaces.remove(it); |
564 | it = --it; | 566 | it = --it; |
565 | } | 567 | } |
566 | // Leave a space between this interface and the next. | 568 | // Leave a space between this interface and the next. |
567 | interfaces.insert(it, QString("")); | 569 | interfaces.insert(it, QString("")); |
568 | return true; | 570 | return true; |
569 | } | 571 | } |
570 | 572 | ||
571 | /** | 573 | /** |
572 | * Gets a value of an option in a stanza | 574 | * Gets a value of an option in a stanza |
573 | * @param start the start of the stanza | 575 | * @param start the start of the stanza |
574 | * @param option the option to use when getting the value. | 576 | * @param option the option to use when getting the value. |
575 | * @param bool true if errors false otherwise. | 577 | * @param bool true if errors false otherwise. |
576 | * @return QString the value of option QString::null() if error == true. | 578 | * @return QString the value of option QString::null() if error == true. |
577 | */ | 579 | */ |
578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | 580 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ |
579 | if(start == interfaces.end()){ | 581 | if(start == interfaces.end()){ |
580 | error = false; | 582 | error = false; |
581 | return QString(); | 583 | return QString(); |
582 | } | 584 | } |
583 | 585 | ||
584 | QString value; | 586 | QString value; |
585 | bool found = false; | 587 | bool found = false; |
586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 588 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
587 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 589 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
588 | break; | 590 | break; |
589 | } | 591 | } |
590 | if((*it).contains(option) && (*it).at(0) != '#'){ | 592 | if((*it).contains(option) && (*it).at(0) != '#'){ |
591 | if(found) | 593 | 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()); | 594 | 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; | 595 | found = true; |
594 | QString line = (*it).simplifyWhiteSpace(); | 596 | QString line = (*it).simplifyWhiteSpace(); |
595 | int space = line.find(" ", option.length()); | 597 | int space = line.find(" ", option.length()); |
596 | if(space != -1) | 598 | if(space != -1) |
597 | value = line.mid(space+1, line.length()); | 599 | value = line.mid(space+1, line.length()); |
598 | else | 600 | else |
599 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | 601 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); |
600 | } | 602 | } |
601 | } | 603 | } |
602 | error = !found; | 604 | error = !found; |
603 | return value; | 605 | return value; |
604 | } | 606 | } |
605 | 607 | ||
606 | /** | 608 | /** |
607 | * Write out the interfaces file to the file passed into the constructor. | 609 | * Write out the interfaces file to the file passed into the constructor. |
608 | * Removes any excess blank lines over 1 line long. | 610 | * Removes any excess blank lines over 1 line long. |
609 | * @return bool true if successfull, false if not. | 611 | * @return bool true if successfull, false if not. |
610 | */ | 612 | */ |
611 | bool Interfaces::write(){ | 613 | bool Interfaces::write(){ |
612 | QFile::remove(interfacesFile); | 614 | QFile::remove(interfacesFile); |
613 | QFile file(interfacesFile); | 615 | QFile file(interfacesFile); |
614 | 616 | ||
615 | if (!file.open(IO_ReadWrite)){ | 617 | if (!file.open(IO_ReadWrite)){ |
616 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | 618 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); |
617 | return false; | 619 | return false; |
618 | } | 620 | } |
619 | QTextStream stream( &file ); | 621 | QTextStream stream( &file ); |
620 | int whiteSpaceCount = 0; | 622 | int whiteSpaceCount = 0; |
621 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 623 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
622 | QString line = (*it).simplifyWhiteSpace(); | 624 | QString line = (*it).simplifyWhiteSpace(); |
623 | line = line.replace(QRegExp(" "),""); | 625 | line = line.replace(QRegExp(" "),""); |
624 | if(line.length() == 0) | 626 | if(line.length() == 0) |
625 | whiteSpaceCount++; | 627 | whiteSpaceCount++; |
626 | else | 628 | else |
627 | whiteSpaceCount = 0; | 629 | whiteSpaceCount = 0; |
628 | if(whiteSpaceCount < 2){ | 630 | if(whiteSpaceCount < 2){ |
629 | qDebug((*it).latin1()); | 631 | qDebug((*it).latin1()); |
630 | stream << (*it) << '\n'; | 632 | stream << (*it) << '\n'; |
631 | } | 633 | } |
632 | } | 634 | } |
633 | file.close(); | 635 | file.close(); |
634 | return true; | 636 | return true; |
635 | } | 637 | } |
636 | 638 | ||
637 | // interfaces.cpp | 639 | // interfaces.cpp |
638 | 640 | ||
diff --git a/noncore/net/networksetup/interfaces/interfaces.h b/noncore/net/networksetup/interfaces/interfaces.h index e09ea71..26abb73 100644 --- a/noncore/net/networksetup/interfaces/interfaces.h +++ b/noncore/net/networksetup/interfaces/interfaces.h | |||
@@ -1,76 +1,76 @@ | |||
1 | #ifndef INTERFACES_H | 1 | #ifndef INTERFACES_H |
2 | #define INTERFACES_H | 2 | #define INTERFACES_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | 6 | ||
7 | #define INTERFACES_LOOPBACK "loopback" | 7 | #define INTERFACES_LOOPBACK "loopback" |
8 | 8 | ||
9 | #define INTERFACES_FAMILY_INET "inet" | 9 | #define INTERFACES_FAMILY_INET "inet" |
10 | #define INTERFACES_FAMILY_IPX "ipx" | 10 | #define INTERFACES_FAMILY_IPX "ipx" |
11 | #define INTERFACES_FAMILY_INET6 "inet6" | 11 | #define INTERFACES_FAMILY_INET6 "inet6" |
12 | 12 | ||
13 | #define INTERFACES_METHOD_DHCP "dhcp" | 13 | #define INTERFACES_METHOD_DHCP "dhcp" |
14 | #define INTERFACES_METHOD_STATIC "static" | 14 | #define INTERFACES_METHOD_STATIC "static" |
15 | #define INTERFACES_METHOD_PPP "ppp" | 15 | #define INTERFACES_METHOD_PPP "ppp" |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * This class provides a clean frontend for parsing the network interfaces file. | 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. | 19 | * It provides helper functions to minipulate the options within the file. |
20 | * See the interfaces man page for the syntax rules. | 20 | * See the interfaces man page for the syntax rules. |
21 | */ | 21 | */ |
22 | class Interfaces { | 22 | class Interfaces { |
23 | 23 | ||
24 | public: | 24 | public: |
25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); | 25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); |
26 | QStringList getInterfaceList(); | 26 | QStringList getInterfaceList(); |
27 | 27 | ||
28 | bool isAuto(QString interface); | 28 | bool isAuto(const QString &interface); |
29 | bool setAuto(QString interface, bool setAuto); | 29 | bool setAuto(const QString &interface, bool setAuto); |
30 | 30 | ||
31 | bool removeInterface(); | 31 | bool removeInterface(); |
32 | bool addInterface(QString interface, QString family, QString method); | 32 | bool addInterface(const QString &interface, const QString &family, const QString &method); |
33 | bool copyInterface(QString oldInterface, QString newInterface); | 33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); |
34 | bool setInterface(QString interface); | 34 | bool setInterface(QString interface); |
35 | bool isInterfaceSet(); | 35 | inline bool isInterfaceSet(); |
36 | QString getInterfaceName(bool &error); | 36 | QString getInterfaceName(bool &error); |
37 | bool setInterfaceName(QString newName); | 37 | bool setInterfaceName(const QString &newName); |
38 | QString getInterfaceFamily(bool &error); | 38 | QString getInterfaceFamily(bool &error); |
39 | bool setInterfaceFamily(QString newName); | 39 | bool setInterfaceFamily(const QString &newName); |
40 | QString getInterfaceMethod(bool &error); | 40 | QString getInterfaceMethod(bool &error); |
41 | bool setInterfaceMethod(QString newName); | 41 | bool setInterfaceMethod(const QString &newName); |
42 | QString getInterfaceOption(QString option, bool &error); | 42 | inline QString getInterfaceOption(const QString &option, bool &error); |
43 | bool setInterfaceOption(QString option, QString value); | 43 | inline bool setInterfaceOption(const QString &option, const QString &value); |
44 | bool removeInterfaceOption(QString option, QString value); | 44 | inline bool removeInterfaceOption(const QString &option, const QString &value); |
45 | bool removeAllInterfaceOptions(); | 45 | inline bool removeAllInterfaceOptions(); |
46 | 46 | ||
47 | bool setMapping(QString interface); | 47 | bool setMapping(const QString &interface); |
48 | bool removeMapping(); | 48 | bool removeMapping(); |
49 | void addMapping(QString options); | 49 | inline void addMapping(const QString &options); |
50 | bool setMap(QString map, QString value); | 50 | inline bool setMap(const QString &map, const QString &value); |
51 | bool removeMap(QString map, QString value); | 51 | inline bool removeMap(const QString &map, const QString &value); |
52 | QString getMap(QString map, bool &error); | 52 | inline QString getMap(const QString &map, bool &error); |
53 | bool setScript(QString); | 53 | inline bool setScript(const QString &argument); |
54 | QString getScript(bool &error); | 54 | inline QString getScript(bool &error); |
55 | 55 | ||
56 | bool write(); | 56 | bool write(); |
57 | 57 | ||
58 | private: | 58 | private: |
59 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); | 59 | bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); |
60 | bool setOption(QStringList::Iterator start, QString option, QString value); | 60 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
61 | bool removeOption(QStringList::Iterator start, QString option, QString value); | 61 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
62 | QString getOption(QStringList::Iterator start, QString option, bool &error); | 62 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); |
63 | bool removeAllOptions(QStringList::Iterator start); | 63 | bool removeAllOptions(const QStringList::Iterator &start); |
64 | 64 | ||
65 | QString interfacesFile; | 65 | QString interfacesFile; |
66 | QStringList interfaces; | 66 | QStringList interfaces; |
67 | QStringList::Iterator currentIface; | 67 | QStringList::Iterator currentIface; |
68 | QStringList::Iterator currentMapping; | 68 | QStringList::Iterator currentMapping; |
69 | 69 | ||
70 | QStringList acceptedFamily; | 70 | QStringList acceptedFamily; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | // interfaces | 75 | // interfaces |
76 | 76 | ||
diff --git a/noncore/net/networksetup/interfaces/interfacesetup.ui b/noncore/net/networksetup/interfaces/interfacesetup.ui index ab8e413..df55d25 100644 --- a/noncore/net/networksetup/interfaces/interfacesetup.ui +++ b/noncore/net/networksetup/interfaces/interfacesetup.ui | |||
@@ -1,284 +1,310 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceSetup</class> | 2 | <class>InterfaceSetup</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceSetup</cstring> | 7 | <cstring>InterfaceSetup</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>290</width> | 14 | <width>290</width> |
15 | <height>280</height> | 15 | <height>280</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>caption</name> | 19 | <name>caption</name> |
20 | <string>Interface Configuration</string> | 20 | <string>Interface Configuration</string> |
21 | </property> | 21 | </property> |
22 | <vbox> | 22 | <vbox> |
23 | <property stdset="1"> | 23 | <property stdset="1"> |
24 | <name>margin</name> | 24 | <name>margin</name> |
25 | <number>11</number> | 25 | <number>11</number> |
26 | </property> | 26 | </property> |
27 | <property stdset="1"> | 27 | <property stdset="1"> |
28 | <name>spacing</name> | 28 | <name>spacing</name> |
29 | <number>6</number> | 29 | <number>6</number> |
30 | </property> | 30 | </property> |
31 | <widget> | 31 | <widget> |
32 | <class>QCheckBox</class> | 32 | <class>QCheckBox</class> |
33 | <property stdset="1"> | 33 | <property stdset="1"> |
34 | <name>name</name> | 34 | <name>name</name> |
35 | <cstring>autoStart</cstring> | 35 | <cstring>autoStart</cstring> |
36 | </property> | 36 | </property> |
37 | <property stdset="1"> | 37 | <property stdset="1"> |
38 | <name>text</name> | 38 | <name>text</name> |
39 | <string>Automatically bring up</string> | 39 | <string>Automatically bring up</string> |
40 | </property> | 40 | </property> |
41 | </widget> | 41 | </widget> |
42 | <widget> | 42 | <widget> |
43 | <class>QLayoutWidget</class> | 43 | <class>QLayoutWidget</class> |
44 | <property stdset="1"> | 44 | <property stdset="1"> |
45 | <name>name</name> | 45 | <name>name</name> |
46 | <cstring>Layout9</cstring> | 46 | <cstring>Layout9</cstring> |
47 | </property> | 47 | </property> |
48 | <hbox> | 48 | <hbox> |
49 | <property stdset="1"> | 49 | <property stdset="1"> |
50 | <name>margin</name> | 50 | <name>margin</name> |
51 | <number>0</number> | 51 | <number>0</number> |
52 | </property> | 52 | </property> |
53 | <property stdset="1"> | 53 | <property stdset="1"> |
54 | <name>spacing</name> | 54 | <name>spacing</name> |
55 | <number>6</number> | 55 | <number>6</number> |
56 | </property> | 56 | </property> |
57 | <widget> | 57 | <widget> |
58 | <class>QCheckBox</class> | 58 | <class>QCheckBox</class> |
59 | <property stdset="1"> | 59 | <property stdset="1"> |
60 | <name>name</name> | 60 | <name>name</name> |
61 | <cstring>dhcpCheckBox</cstring> | 61 | <cstring>dhcpCheckBox</cstring> |
62 | </property> | 62 | </property> |
63 | <property stdset="1"> | 63 | <property stdset="1"> |
64 | <name>text</name> | 64 | <name>text</name> |
65 | <string>DHCP</string> | 65 | <string>DHCP</string> |
66 | </property> | 66 | </property> |
67 | <property stdset="1"> | 67 | <property stdset="1"> |
68 | <name>checked</name> | 68 | <name>checked</name> |
69 | <bool>true</bool> | 69 | <bool>true</bool> |
70 | </property> | 70 | </property> |
71 | </widget> | 71 | </widget> |
72 | <widget> | 72 | <widget> |
73 | <class>QLabel</class> | 73 | <class>QLabel</class> |
74 | <property stdset="1"> | 74 | <property stdset="1"> |
75 | <name>name</name> | 75 | <name>name</name> |
76 | <cstring>leaseHoursLabel</cstring> | 76 | <cstring>leaseHoursLabel</cstring> |
77 | </property> | 77 | </property> |
78 | <property stdset="1"> | 78 | <property stdset="1"> |
79 | <name>text</name> | 79 | <name>text</name> |
80 | <string>Requested Lease</string> | 80 | <string>Requested Lease</string> |
81 | </property> | 81 | </property> |
82 | </widget> | 82 | </widget> |
83 | <widget> | 83 | <widget> |
84 | <class>QSpinBox</class> | 84 | <class>QSpinBox</class> |
85 | <property stdset="1"> | 85 | <property stdset="1"> |
86 | <name>name</name> | 86 | <name>name</name> |
87 | <cstring>leaseTime</cstring> | 87 | <cstring>leaseTime</cstring> |
88 | </property> | 88 | </property> |
89 | <property stdset="1"> | 89 | <property stdset="1"> |
90 | <name>suffix</name> | 90 | <name>suffix</name> |
91 | <string> hours</string> | 91 | <string> hours</string> |
92 | </property> | 92 | </property> |
93 | <property stdset="1"> | 93 | <property stdset="1"> |
94 | <name>maxValue</name> | 94 | <name>maxValue</name> |
95 | <number>87600</number> | 95 | <number>87600</number> |
96 | </property> | 96 | </property> |
97 | <property stdset="1"> | 97 | <property stdset="1"> |
98 | <name>minValue</name> | 98 | <name>minValue</name> |
99 | <number>1</number> | 99 | <number>1</number> |
100 | </property> | 100 | </property> |
101 | <property stdset="1"> | 101 | <property stdset="1"> |
102 | <name>lineStep</name> | ||
103 | <number>24</number> | ||
104 | </property> | ||
105 | <property stdset="1"> | ||
102 | <name>value</name> | 106 | <name>value</name> |
103 | <number>168</number> | 107 | <number>168</number> |
104 | </property> | 108 | </property> |
105 | </widget> | 109 | </widget> |
106 | </hbox> | 110 | </hbox> |
107 | </widget> | 111 | </widget> |
108 | <widget> | 112 | <widget> |
109 | <class>QGroupBox</class> | 113 | <class>QGroupBox</class> |
110 | <property stdset="1"> | 114 | <property stdset="1"> |
111 | <name>name</name> | 115 | <name>name</name> |
112 | <cstring>staticGroupBox</cstring> | 116 | <cstring>staticGroupBox</cstring> |
113 | </property> | 117 | </property> |
114 | <property stdset="1"> | 118 | <property stdset="1"> |
115 | <name>enabled</name> | 119 | <name>enabled</name> |
116 | <bool>false</bool> | 120 | <bool>false</bool> |
117 | </property> | 121 | </property> |
118 | <property stdset="1"> | 122 | <property stdset="1"> |
119 | <name>frameShape</name> | 123 | <name>frameShape</name> |
120 | <enum>Box</enum> | 124 | <enum>Box</enum> |
121 | </property> | 125 | </property> |
122 | <property stdset="1"> | 126 | <property stdset="1"> |
123 | <name>frameShadow</name> | 127 | <name>frameShadow</name> |
124 | <enum>Sunken</enum> | 128 | <enum>Sunken</enum> |
125 | </property> | 129 | </property> |
126 | <property stdset="1"> | 130 | <property stdset="1"> |
127 | <name>title</name> | 131 | <name>title</name> |
128 | <string>Static Ip Configuration</string> | 132 | <string>Static Ip Configuration</string> |
129 | </property> | 133 | </property> |
130 | <grid> | 134 | <grid> |
131 | <property stdset="1"> | 135 | <property stdset="1"> |
132 | <name>margin</name> | 136 | <name>margin</name> |
133 | <number>11</number> | 137 | <number>11</number> |
134 | </property> | 138 | </property> |
135 | <property stdset="1"> | 139 | <property stdset="1"> |
136 | <name>spacing</name> | 140 | <name>spacing</name> |
137 | <number>6</number> | 141 | <number>6</number> |
138 | </property> | 142 | </property> |
139 | <widget row="1" column="0" > | 143 | <widget row="1" column="0" > |
140 | <class>QLabel</class> | 144 | <class>QLabel</class> |
141 | <property stdset="1"> | 145 | <property stdset="1"> |
142 | <name>name</name> | 146 | <name>name</name> |
143 | <cstring>TextLabel5</cstring> | 147 | <cstring>TextLabel5</cstring> |
144 | </property> | 148 | </property> |
145 | <property stdset="1"> | 149 | <property stdset="1"> |
146 | <name>text</name> | 150 | <name>text</name> |
147 | <string>Subnet Mask</string> | 151 | <string>Subnet Mask</string> |
148 | </property> | 152 | </property> |
149 | </widget> | 153 | </widget> |
150 | <widget row="2" column="1" > | 154 | <widget row="2" column="1" > |
151 | <class>QLineEdit</class> | 155 | <class>QLineEdit</class> |
152 | <property stdset="1"> | 156 | <property stdset="1"> |
153 | <name>name</name> | 157 | <name>name</name> |
154 | <cstring>gatewayEdit</cstring> | 158 | <cstring>gatewayEdit</cstring> |
155 | </property> | 159 | </property> |
156 | </widget> | 160 | </widget> |
157 | <widget row="1" column="1" > | 161 | <widget row="1" column="1" > |
158 | <class>QLineEdit</class> | 162 | <class>QLineEdit</class> |
159 | <property stdset="1"> | 163 | <property stdset="1"> |
160 | <name>name</name> | 164 | <name>name</name> |
161 | <cstring>subnetMaskEdit</cstring> | 165 | <cstring>subnetMaskEdit</cstring> |
162 | </property> | 166 | </property> |
163 | </widget> | 167 | </widget> |
164 | <widget row="0" column="1" > | 168 | <widget row="0" column="1" > |
165 | <class>QLineEdit</class> | 169 | <class>QLineEdit</class> |
166 | <property stdset="1"> | 170 | <property stdset="1"> |
167 | <name>name</name> | 171 | <name>name</name> |
168 | <cstring>ipAddressEdit</cstring> | 172 | <cstring>ipAddressEdit</cstring> |
169 | </property> | 173 | </property> |
170 | </widget> | 174 | </widget> |
171 | <widget row="3" column="0" > | 175 | <widget row="3" column="0" > |
172 | <class>QLabel</class> | 176 | <class>QLabel</class> |
173 | <property stdset="1"> | 177 | <property stdset="1"> |
174 | <name>name</name> | 178 | <name>name</name> |
175 | <cstring>TextLabel2</cstring> | 179 | <cstring>TextLabel2</cstring> |
176 | </property> | 180 | </property> |
177 | <property stdset="1"> | 181 | <property stdset="1"> |
178 | <name>text</name> | 182 | <name>text</name> |
179 | <string>First DNS</string> | 183 | <string>First DNS</string> |
180 | </property> | 184 | </property> |
181 | </widget> | 185 | </widget> |
182 | <widget row="0" column="0" > | 186 | <widget row="0" column="0" > |
183 | <class>QLabel</class> | 187 | <class>QLabel</class> |
184 | <property stdset="1"> | 188 | <property stdset="1"> |
185 | <name>name</name> | 189 | <name>name</name> |
186 | <cstring>TextLabel4</cstring> | 190 | <cstring>TextLabel4</cstring> |
187 | </property> | 191 | </property> |
188 | <property stdset="1"> | 192 | <property stdset="1"> |
189 | <name>text</name> | 193 | <name>text</name> |
190 | <string>IP Address</string> | 194 | <string>IP Address</string> |
191 | </property> | 195 | </property> |
192 | </widget> | 196 | </widget> |
193 | <widget row="2" column="0" > | 197 | <widget row="2" column="0" > |
194 | <class>QLabel</class> | 198 | <class>QLabel</class> |
195 | <property stdset="1"> | 199 | <property stdset="1"> |
196 | <name>name</name> | 200 | <name>name</name> |
197 | <cstring>TextLabel1_2</cstring> | 201 | <cstring>TextLabel1_2</cstring> |
198 | </property> | 202 | </property> |
199 | <property stdset="1"> | 203 | <property stdset="1"> |
200 | <name>text</name> | 204 | <name>text</name> |
201 | <string>Gateway</string> | 205 | <string>Gateway</string> |
202 | </property> | 206 | </property> |
203 | </widget> | 207 | </widget> |
204 | <widget row="4" column="0" > | 208 | <widget row="4" column="0" > |
205 | <class>QLabel</class> | 209 | <class>QLabel</class> |
206 | <property stdset="1"> | 210 | <property stdset="1"> |
207 | <name>name</name> | 211 | <name>name</name> |
208 | <cstring>TextLabel3</cstring> | 212 | <cstring>TextLabel3</cstring> |
209 | </property> | 213 | </property> |
210 | <property stdset="1"> | 214 | <property stdset="1"> |
211 | <name>text</name> | 215 | <name>text</name> |
212 | <string>Second DNS</string> | 216 | <string>Second DNS</string> |
213 | </property> | 217 | </property> |
214 | </widget> | 218 | </widget> |
215 | <widget row="3" column="1" > | 219 | <widget row="3" column="1" > |
216 | <class>QLineEdit</class> | 220 | <class>QLineEdit</class> |
217 | <property stdset="1"> | 221 | <property stdset="1"> |
218 | <name>name</name> | 222 | <name>name</name> |
219 | <cstring>firstDNSLineEdit</cstring> | 223 | <cstring>firstDNSLineEdit</cstring> |
220 | </property> | 224 | </property> |
221 | </widget> | 225 | </widget> |
222 | <widget row="4" column="1" > | 226 | <widget row="4" column="1" > |
223 | <class>QLineEdit</class> | 227 | <class>QLineEdit</class> |
224 | <property stdset="1"> | 228 | <property stdset="1"> |
225 | <name>name</name> | 229 | <name>name</name> |
226 | <cstring>secondDNSLineEdit</cstring> | 230 | <cstring>secondDNSLineEdit</cstring> |
227 | </property> | 231 | </property> |
228 | </widget> | 232 | </widget> |
229 | </grid> | 233 | </grid> |
230 | </widget> | 234 | </widget> |
231 | <spacer> | 235 | <spacer> |
232 | <property> | 236 | <property> |
233 | <name>name</name> | 237 | <name>name</name> |
234 | <cstring>Spacer9</cstring> | 238 | <cstring>Spacer9</cstring> |
235 | </property> | 239 | </property> |
236 | <property stdset="1"> | 240 | <property stdset="1"> |
237 | <name>orientation</name> | 241 | <name>orientation</name> |
238 | <enum>Vertical</enum> | 242 | <enum>Vertical</enum> |
239 | </property> | 243 | </property> |
240 | <property stdset="1"> | 244 | <property stdset="1"> |
241 | <name>sizeType</name> | 245 | <name>sizeType</name> |
242 | <enum>Expanding</enum> | 246 | <enum>Expanding</enum> |
243 | </property> | 247 | </property> |
244 | <property> | 248 | <property> |
245 | <name>sizeHint</name> | 249 | <name>sizeHint</name> |
246 | <size> | 250 | <size> |
247 | <width>20</width> | 251 | <width>20</width> |
248 | <height>20</height> | 252 | <height>20</height> |
249 | </size> | 253 | </size> |
250 | </property> | 254 | </property> |
251 | </spacer> | 255 | </spacer> |
252 | </vbox> | 256 | </vbox> |
253 | </widget> | 257 | </widget> |
258 | <customwidgets> | ||
259 | <customwidget> | ||
260 | <class>QWidget</class> | ||
261 | <header location="local">qwidget.h</header> | ||
262 | <sizehint> | ||
263 | <width>100</width> | ||
264 | <height>100</height> | ||
265 | </sizehint> | ||
266 | <container>0</container> | ||
267 | <sizepolicy> | ||
268 | <hordata>7</hordata> | ||
269 | <verdata>7</verdata> | ||
270 | </sizepolicy> | ||
271 | <pixmap>image0</pixmap> | ||
272 | </customwidget> | ||
273 | </customwidgets> | ||
274 | <images> | ||
275 | <image> | ||
276 | <name>image0</name> | ||
277 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
278 | </image> | ||
279 | </images> | ||
254 | <connections> | 280 | <connections> |
255 | <connection> | 281 | <connection> |
256 | <sender>dhcpCheckBox</sender> | 282 | <sender>dhcpCheckBox</sender> |
257 | <signal>toggled(bool)</signal> | 283 | <signal>toggled(bool)</signal> |
258 | <receiver>leaseHoursLabel</receiver> | 284 | <receiver>leaseHoursLabel</receiver> |
259 | <slot>setEnabled(bool)</slot> | 285 | <slot>setEnabled(bool)</slot> |
260 | </connection> | 286 | </connection> |
261 | <connection> | 287 | <connection> |
262 | <sender>dhcpCheckBox</sender> | 288 | <sender>dhcpCheckBox</sender> |
263 | <signal>toggled(bool)</signal> | 289 | <signal>toggled(bool)</signal> |
264 | <receiver>leaseTime</receiver> | 290 | <receiver>leaseTime</receiver> |
265 | <slot>setEnabled(bool)</slot> | 291 | <slot>setEnabled(bool)</slot> |
266 | </connection> | 292 | </connection> |
267 | <connection> | 293 | <connection> |
268 | <sender>dhcpCheckBox</sender> | 294 | <sender>dhcpCheckBox</sender> |
269 | <signal>toggled(bool)</signal> | 295 | <signal>toggled(bool)</signal> |
270 | <receiver>staticGroupBox</receiver> | 296 | <receiver>staticGroupBox</receiver> |
271 | <slot>setDisabled(bool)</slot> | 297 | <slot>setDisabled(bool)</slot> |
272 | </connection> | 298 | </connection> |
273 | </connections> | 299 | </connections> |
274 | <tabstops> | 300 | <tabstops> |
275 | <tabstop>autoStart</tabstop> | 301 | <tabstop>autoStart</tabstop> |
276 | <tabstop>dhcpCheckBox</tabstop> | 302 | <tabstop>dhcpCheckBox</tabstop> |
277 | <tabstop>leaseTime</tabstop> | 303 | <tabstop>leaseTime</tabstop> |
278 | <tabstop>ipAddressEdit</tabstop> | 304 | <tabstop>ipAddressEdit</tabstop> |
279 | <tabstop>subnetMaskEdit</tabstop> | 305 | <tabstop>subnetMaskEdit</tabstop> |
280 | <tabstop>gatewayEdit</tabstop> | 306 | <tabstop>gatewayEdit</tabstop> |
281 | <tabstop>firstDNSLineEdit</tabstop> | 307 | <tabstop>firstDNSLineEdit</tabstop> |
282 | <tabstop>secondDNSLineEdit</tabstop> | 308 | <tabstop>secondDNSLineEdit</tabstop> |
283 | </tabstops> | 309 | </tabstops> |
284 | </UI> | 310 | </UI> |
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.h b/noncore/net/networksetup/interfaces/interfacesetupimp.h index a88e190..60933aa 100644 --- a/noncore/net/networksetup/interfaces/interfacesetupimp.h +++ b/noncore/net/networksetup/interfaces/interfacesetupimp.h | |||
@@ -1,56 +1,55 @@ | |||
1 | #ifndef INTERFACESETUPIMP_H | 1 | #ifndef INTERFACESETUPIMP_H |
2 | #define INTERFACESETUPIMP_H | 2 | #define INTERFACESETUPIMP_H |
3 | 3 | ||
4 | #include "interfacesetup.h" | 4 | #include "interfacesetup.h" |
5 | #include <qdialog.h> | 5 | #include <qdialog.h> |
6 | 6 | ||
7 | class Interface; | 7 | class Interface; |
8 | class Interfaces; | 8 | class Interfaces; |
9 | 9 | ||
10 | class InterfaceSetupImp : public InterfaceSetup { | 10 | class InterfaceSetupImp : public InterfaceSetup { |
11 | Q_OBJECT | 11 | Q_OBJECT |
12 | 12 | ||
13 | public: | 13 | public: |
14 | InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0); | 14 | InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0); |
15 | bool saveChanges(); | 15 | bool saveChanges(); |
16 | 16 | ||
17 | public slots: | 17 | public slots: |
18 | void setProfile(const QString &profile); | 18 | void setProfile(const QString &profile); |
19 | bool saveSettings(); | 19 | bool saveSettings(); |
20 | 20 | ||
21 | private: | 21 | private: |
22 | Interfaces *interfaces; | 22 | Interfaces *interfaces; |
23 | Interface *interface; | 23 | Interface *interface; |
24 | |||
25 | }; | 24 | }; |
26 | 25 | ||
27 | 26 | ||
28 | #include <qlayout.h> | 27 | #include <qlayout.h> |
29 | 28 | ||
30 | class InterfaceSetupImpDialog : public QDialog { | 29 | class InterfaceSetupImpDialog : public QDialog { |
31 | Q_OBJECT | 30 | Q_OBJECT |
32 | 31 | ||
33 | public: | 32 | public: |
34 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ | 33 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ |
35 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); | 34 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); |
36 | setCaption("Interface Setup"); | 35 | setCaption("Interface Setup"); |
37 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); | 36 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); |
38 | InterfaceSetupLayout->addWidget( interfaceSetup ); | 37 | InterfaceSetupLayout->addWidget( interfaceSetup ); |
39 | }; | 38 | }; |
40 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; | 39 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; |
41 | 40 | ||
42 | private: | 41 | private: |
43 | InterfaceSetupImp *interfaceSetup; | 42 | InterfaceSetupImp *interfaceSetup; |
44 | 43 | ||
45 | protected slots: | 44 | protected slots: |
46 | void accept(){ | 45 | void accept(){ |
47 | if(interfaceSetup->saveChanges()) | 46 | if(interfaceSetup->saveChanges()) |
48 | QDialog::accept(); | 47 | QDialog::accept(); |
49 | }; | 48 | }; |
50 | 49 | ||
51 | }; | 50 | }; |
52 | 51 | ||
53 | #endif | 52 | #endif |
54 | 53 | ||
55 | // interfacesetupimp.h | 54 | // interfacesetupimp.h |
56 | 55 | ||
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 48ef9b3..7b93554 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -1,473 +1,473 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include "addconnectionimp.h" | 2 | #include "addconnectionimp.h" |
3 | #include "interfaceinformationimp.h" | 3 | #include "interfaceinformationimp.h" |
4 | #include "interfacesetupimp.h" | 4 | #include "interfacesetupimp.h" |
5 | #include "interfaces.h" | 5 | #include "interfaces.h" |
6 | #include "module.h" | 6 | #include "module.h" |
7 | 7 | ||
8 | #include <qpushbutton.h> | 8 | #include <qpushbutton.h> |
9 | #include <qlistbox.h> | 9 | #include <qlistbox.h> |
10 | #include <qlineedit.h> | 10 | #include <qlineedit.h> |
11 | #include <qlistview.h> | 11 | #include <qlistview.h> |
12 | #include <qheader.h> | 12 | #include <qheader.h> |
13 | #include <qlabel.h> | 13 | #include <qlabel.h> |
14 | 14 | ||
15 | #include <qmainwindow.h> | 15 | #include <qmainwindow.h> |
16 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
17 | 17 | ||
18 | #include <qpe/config.h> | 18 | #include <qpe/config.h> |
19 | #include <qpe/qlibrary.h> | 19 | #include <qpe/qlibrary.h> |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
22 | 22 | ||
23 | #include <qlist.h> | 23 | #include <qlist.h> |
24 | #include <qdir.h> | 24 | #include <qdir.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
27 | 27 | ||
28 | #include <net/if.h> | 28 | #include <net/if.h> |
29 | #include <sys/ioctl.h> | 29 | #include <sys/ioctl.h> |
30 | 30 | ||
31 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" | 31 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
32 | 32 | ||
33 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 33 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false), scheme(DEFAULT_SCHEME){ |
34 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 34 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
35 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 35 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
36 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 36 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
37 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 37 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
38 | 38 | ||
39 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 39 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
40 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 40 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
41 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 41 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
42 | 42 | ||
43 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 43 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
44 | // Load connections. | 44 | // Load connections. |
45 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); | 45 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); |
46 | getAllInterfaces(); | 46 | getAllInterfaces(); |
47 | 47 | ||
48 | Interfaces i; | 48 | Interfaces i; |
49 | QStringList list = i.getInterfaceList(); | 49 | QStringList list = i.getInterfaceList(); |
50 | QMap<QString, Interface*>::Iterator it; | 50 | QMap<QString, Interface*>::Iterator it; |
51 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 51 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
52 | bool found = false; | 52 | bool found = false; |
53 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 53 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
54 | if(it.key() == (*ni)) | 54 | if(it.key() == (*ni)) |
55 | found = true; | 55 | found = true; |
56 | } | 56 | } |
57 | if(!found){ | 57 | if(!found){ |
58 | if(!(*ni).contains("_")){ | 58 | if(!(*ni).contains("_")){ |
59 | Interface *i = new Interface(this, *ni, false); | 59 | Interface *i = new Interface(this, *ni, false); |
60 | i->setAttached(false); | 60 | i->setAttached(false); |
61 | i->setHardwareName("Disconnected"); | 61 | i->setHardwareName("Disconnected"); |
62 | interfaceNames.insert(i->getInterfaceName(), i); | 62 | interfaceNames.insert(i->getInterfaceName(), i); |
63 | updateInterface(i); | 63 | updateInterface(i); |
64 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 64 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | //getInterfaceList(); | 69 | //getInterfaceList(); |
70 | connectionList->header()->hide(); | 70 | connectionList->header()->hide(); |
71 | 71 | ||
72 | Config cfg("NetworkSetup"); | 72 | Config cfg("NetworkSetup"); |
73 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 73 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
74 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 74 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
75 | profilesList->insertItem((*it)); | 75 | profilesList->insertItem((*it)); |
76 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 76 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
77 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 77 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
78 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | 78 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); |
79 | 79 | ||
80 | QFile file(scheme); | 80 | QFile file(scheme); |
81 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 81 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
82 | QTextStream stream( &file ); // use a text stream | 82 | QTextStream stream( &file ); // use a text stream |
83 | while ( !stream.eof() ) { // until end of file... | 83 | while ( !stream.eof() ) { // until end of file... |
84 | QString line = stream.readLine(); // line of text excluding '\n' | 84 | QString line = stream.readLine(); // line of text excluding '\n' |
85 | if(line.contains("SCHEME")){ | 85 | if(line.contains("SCHEME")){ |
86 | line = line.mid(7, line.length()); | 86 | line = line.mid(7, line.length()); |
87 | currentProfileLabel->setText(line); | 87 | currentProfileLabel->setText(line); |
88 | break; | 88 | break; |
89 | } | 89 | } |
90 | } | 90 | } |
91 | file.close(); | 91 | file.close(); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Deconstructor. Save profiles. Delete loaded libraries. | 96 | * Deconstructor. Save profiles. Delete loaded libraries. |
97 | */ | 97 | */ |
98 | MainWindowImp::~MainWindowImp(){ | 98 | MainWindowImp::~MainWindowImp(){ |
99 | // Save profiles. | 99 | // Save profiles. |
100 | Config cfg("NetworkSetup"); | 100 | Config cfg("NetworkSetup"); |
101 | cfg.setGroup("General"); | 101 | cfg.setGroup("General"); |
102 | cfg.writeEntry("Profiles", profiles.join(" ")); | 102 | cfg.writeEntry("Profiles", profiles.join(" ")); |
103 | 103 | ||
104 | // Delete all interfaces that don't have owners. | 104 | // Delete all interfaces that don't have owners. |
105 | QMap<Interface*, QListViewItem*>::Iterator iIt; | 105 | QMap<Interface*, QListViewItem*>::Iterator iIt; |
106 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ | 106 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ |
107 | if(iIt.key()->getModuleOwner() == NULL) | 107 | if(iIt.key()->getModuleOwner() == NULL) |
108 | delete iIt.key(); | 108 | delete iIt.key(); |
109 | } | 109 | } |
110 | 110 | ||
111 | // Delete Modules and Libraries | 111 | // Delete Modules and Libraries |
112 | QMap<Module*, QLibrary*>::Iterator it; | 112 | QMap<Module*, QLibrary*>::Iterator it; |
113 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 113 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
114 | delete it.key(); | 114 | delete it.key(); |
115 | // I wonder why I can't delete the libraries | 115 | // I wonder why I can't delete the libraries |
116 | // What fucking shit this is. | 116 | // What fucking shit this is. |
117 | //delete it.data(); | 117 | //delete it.data(); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Query the kernel for all of the interfaces. | 122 | * Query the kernel for all of the interfaces. |
123 | */ | 123 | */ |
124 | void MainWindowImp::getAllInterfaces(){ | 124 | void MainWindowImp::getAllInterfaces(){ |
125 | int sockfd = socket(AF_INET, SOCK_DGRAM, 0); | 125 | int sockfd = socket(AF_INET, SOCK_DGRAM, 0); |
126 | if(sockfd == -1) | 126 | if(sockfd == -1) |
127 | return; | 127 | return; |
128 | 128 | ||
129 | char buf[8*1024]; | 129 | char buf[8*1024]; |
130 | struct ifconf ifc; | 130 | struct ifconf ifc; |
131 | ifc.ifc_len = sizeof(buf); | 131 | ifc.ifc_len = sizeof(buf); |
132 | ifc.ifc_req = (struct ifreq *) buf; | 132 | ifc.ifc_req = (struct ifreq *) buf; |
133 | int result=ioctl(sockfd, SIOCGIFCONF, &ifc); | 133 | int result=ioctl(sockfd, SIOCGIFCONF, &ifc); |
134 | 134 | ||
135 | for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ | 135 | for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ |
136 | struct ifreq *ifr =(struct ifreq *) ptr; | 136 | struct ifreq *ifr =(struct ifreq *) ptr; |
137 | int len = sizeof(struct sockaddr); | 137 | int len = sizeof(struct sockaddr); |
138 | #ifdef HAVE_SOCKADDR_SA_LEN | 138 | #ifdef HAVE_SOCKADDR_SA_LEN |
139 | if (ifr->ifr_addr.sa_len > len) | 139 | if (ifr->ifr_addr.sa_len > len) |
140 | len = ifr->ifr_addr.sa_len; /* length > 16 */ | 140 | len = ifr->ifr_addr.sa_len; /* length > 16 */ |
141 | #endif | 141 | #endif |
142 | ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ | 142 | ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ |
143 | 143 | ||
144 | int flags; | 144 | int flags; |
145 | struct sockaddr_in *sinptr; | 145 | struct sockaddr_in *sinptr; |
146 | Interface *i = NULL; | 146 | Interface *i = NULL; |
147 | switch (ifr->ifr_addr.sa_family){ | 147 | switch (ifr->ifr_addr.sa_family){ |
148 | case AF_INET: | 148 | case AF_INET: |
149 | sinptr = (struct sockaddr_in *) &ifr->ifr_addr; | 149 | sinptr = (struct sockaddr_in *) &ifr->ifr_addr; |
150 | flags=0; | 150 | flags=0; |
151 | 151 | ||
152 | struct ifreq ifcopy; | 152 | struct ifreq ifcopy; |
153 | ifcopy=*ifr; | 153 | ifcopy=*ifr; |
154 | result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); | 154 | result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); |
155 | flags=ifcopy.ifr_flags; | 155 | flags=ifcopy.ifr_flags; |
156 | i = new Interface(this, ifr->ifr_name, false); | 156 | i = new Interface(this, ifr->ifr_name, false); |
157 | i->setAttached(true); | 157 | i->setAttached(true); |
158 | if ((flags & IFF_UP) == IFF_UP) | 158 | if ((flags & IFF_UP) == IFF_UP) |
159 | i->setStatus(true); | 159 | i->setStatus(true); |
160 | else | 160 | else |
161 | i->setStatus(false); | 161 | i->setStatus(false); |
162 | 162 | ||
163 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) | 163 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) |
164 | i->setHardwareName("Ethernet"); | 164 | i->setHardwareName("Ethernet"); |
165 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) | 165 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) |
166 | i->setHardwareName("Point to Point"); | 166 | i->setHardwareName("Point to Point"); |
167 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) | 167 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) |
168 | i->setHardwareName("Multicast"); | 168 | i->setHardwareName("Multicast"); |
169 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) | 169 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) |
170 | i->setHardwareName("Loopback"); | 170 | i->setHardwareName("Loopback"); |
171 | else | 171 | else |
172 | i->setHardwareName("Unknown"); | 172 | i->setHardwareName("Unknown"); |
173 | 173 | ||
174 | interfaceNames.insert(i->getInterfaceName(), i); | 174 | interfaceNames.insert(i->getInterfaceName(), i); |
175 | updateInterface(i); | 175 | updateInterface(i); |
176 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 176 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
177 | break; | 177 | break; |
178 | 178 | ||
179 | default: | 179 | default: |
180 | qDebug(ifr->ifr_name); | 180 | qDebug(ifr->ifr_name); |
181 | qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); | 181 | qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); |
182 | break; | 182 | break; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Load all modules that are found in the path | 188 | * Load all modules that are found in the path |
189 | * @param path a directory that is scaned for any plugins that can be loaded | 189 | * @param path a directory that is scaned for any plugins that can be loaded |
190 | * and attempts to load them | 190 | * and attempts to load them |
191 | */ | 191 | */ |
192 | void MainWindowImp::loadModules(QString path){ | 192 | void MainWindowImp::loadModules(const QString &path){ |
193 | //qDebug(path.latin1()); | 193 | //qDebug(path.latin1()); |
194 | QDir d(path); | 194 | QDir d(path); |
195 | if(!d.exists()) | 195 | if(!d.exists()) |
196 | return; | 196 | return; |
197 | 197 | ||
198 | // Don't want sym links | 198 | // Don't want sym links |
199 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 199 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
200 | const QFileInfoList *list = d.entryInfoList(); | 200 | const QFileInfoList *list = d.entryInfoList(); |
201 | QFileInfoListIterator it( *list ); | 201 | QFileInfoListIterator it( *list ); |
202 | QFileInfo *fi; | 202 | QFileInfo *fi; |
203 | while ( (fi=it.current()) ) { | 203 | while ( (fi=it.current()) ) { |
204 | if(fi->fileName().contains(".so")){ | 204 | if(fi->fileName().contains(".so")){ |
205 | loadPlugin(path + "/" + fi->fileName()); | 205 | loadPlugin(path + "/" + fi->fileName()); |
206 | } | 206 | } |
207 | ++it; | 207 | ++it; |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * Attempt to load a function and resolve a function. | 212 | * Attempt to load a function and resolve a function. |
213 | * @param pluginFileName - the name of the file in which to attempt to load | 213 | * @param pluginFileName - the name of the file in which to attempt to load |
214 | * @param resolveString - function pointer to resolve | 214 | * @param resolveString - function pointer to resolve |
215 | * @return pointer to the function with name resolveString or NULL | 215 | * @return pointer to the function with name resolveString or NULL |
216 | */ | 216 | */ |
217 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 217 | Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ |
218 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 218 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
219 | QLibrary *lib = new QLibrary(pluginFileName); | 219 | QLibrary *lib = new QLibrary(pluginFileName); |
220 | void *functionPointer = lib->resolve(resolveString); | 220 | void *functionPointer = lib->resolve(resolveString); |
221 | if( !functionPointer ){ | 221 | if( !functionPointer ){ |
222 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 222 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
223 | delete lib; | 223 | delete lib; |
224 | return NULL; | 224 | return NULL; |
225 | } | 225 | } |
226 | 226 | ||
227 | // Try to get an object. | 227 | // Try to get an object. |
228 | Module *object = ((Module* (*)()) functionPointer)(); | 228 | Module *object = ((Module* (*)()) functionPointer)(); |
229 | if(object == NULL){ | 229 | if(object == NULL){ |
230 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 230 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
231 | delete lib; | 231 | delete lib; |
232 | return NULL; | 232 | return NULL; |
233 | } | 233 | } |
234 | 234 | ||
235 | // Store for deletion later | 235 | // Store for deletion later |
236 | libraries.insert(object, lib); | 236 | libraries.insert(object, lib); |
237 | return object; | 237 | return object; |
238 | } | 238 | } |
239 | 239 | ||
240 | /** | 240 | /** |
241 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 241 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
242 | * load the plugin and append it to the list | 242 | * load the plugin and append it to the list |
243 | */ | 243 | */ |
244 | void MainWindowImp::addClicked(){ | 244 | void MainWindowImp::addClicked(){ |
245 | QMap<Module*, QLibrary*>::Iterator it; | 245 | QMap<Module*, QLibrary*>::Iterator it; |
246 | QMap<QString, QString> list; | 246 | QMap<QString, QString> list; |
247 | QMap<QString, Module*> newInterfaceOwners; | 247 | QMap<QString, Module*> newInterfaceOwners; |
248 | //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 248 | //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); |
249 | //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); | 249 | //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
250 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 250 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
251 | if(it.key()){ | 251 | if(it.key()){ |
252 | (it.key())->possibleNewInterfaces(list); | 252 | (it.key())->possibleNewInterfaces(list); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | // See if the list has anything that we can add. | 255 | // See if the list has anything that we can add. |
256 | if(list.count() == 0){ | 256 | if(list.count() == 0){ |
257 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); | 257 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); |
258 | return; | 258 | return; |
259 | } | 259 | } |
260 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 260 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
261 | addNewConnection.addConnections(list); | 261 | addNewConnection.addConnections(list); |
262 | addNewConnection.showMaximized(); | 262 | addNewConnection.showMaximized(); |
263 | if(QDialog::Accepted == addNewConnection.exec()){ | 263 | if(QDialog::Accepted == addNewConnection.exec()){ |
264 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 264 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
265 | if(!item) | 265 | if(!item) |
266 | return; | 266 | return; |
267 | 267 | ||
268 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 268 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
269 | if(it.key()){ | 269 | if(it.key()){ |
270 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 270 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
271 | if(i){ | 271 | if(i){ |
272 | interfaceNames.insert(i->getInterfaceName(), i); | 272 | interfaceNames.insert(i->getInterfaceName(), i); |
273 | updateInterface(i); | 273 | updateInterface(i); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | /** | 280 | /** |
281 | * Prompt the user to see if they really want to do this. | 281 | * Prompt the user to see if they really want to do this. |
282 | * If they do then remove from the list and unload. | 282 | * If they do then remove from the list and unload. |
283 | */ | 283 | */ |
284 | void MainWindowImp::removeClicked(){ | 284 | void MainWindowImp::removeClicked(){ |
285 | QListViewItem *item = connectionList->currentItem(); | 285 | QListViewItem *item = connectionList->currentItem(); |
286 | if(!item) { | 286 | if(!item) { |
287 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 287 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
288 | return; | 288 | return; |
289 | } | 289 | } |
290 | 290 | ||
291 | Interface *i = interfaceItems[item]; | 291 | Interface *i = interfaceItems[item]; |
292 | if(i->getModuleOwner() == NULL){ | 292 | if(i->getModuleOwner() == NULL){ |
293 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); | 293 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); |
294 | } | 294 | } |
295 | else{ | 295 | else{ |
296 | if(!i->getModuleOwner()->remove(i)) | 296 | if(!i->getModuleOwner()->remove(i)) |
297 | QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); | 297 | QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); |
298 | else{ | 298 | else{ |
299 | QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); | 299 | QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); |
300 | // TODO memory managment.... | 300 | // TODO memory managment.... |
301 | // who deletes the interface? | 301 | // who deletes the interface? |
302 | } | 302 | } |
303 | } | 303 | } |
304 | } | 304 | } |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * Pull up the configure about the currently selected interface. | 307 | * Pull up the configure about the currently selected interface. |
308 | * Report an error if no interface is selected. | 308 | * Report an error if no interface is selected. |
309 | * If the interface has a module owner then request its configure. | 309 | * If the interface has a module owner then request its configure. |
310 | */ | 310 | */ |
311 | void MainWindowImp::configureClicked(){ | 311 | void MainWindowImp::configureClicked(){ |
312 | QListViewItem *item = connectionList->currentItem(); | 312 | QListViewItem *item = connectionList->currentItem(); |
313 | if(!item){ | 313 | if(!item){ |
314 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); | 314 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); |
315 | return; | 315 | return; |
316 | } | 316 | } |
317 | 317 | ||
318 | Interface *i = interfaceItems[item]; | 318 | Interface *i = interfaceItems[item]; |
319 | if(i->getModuleOwner()){ | 319 | if(i->getModuleOwner()){ |
320 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); | 320 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); |
321 | if(moduleConfigure != NULL){ | 321 | if(moduleConfigure != NULL){ |
322 | moduleConfigure->showMaximized(); | 322 | moduleConfigure->showMaximized(); |
323 | moduleConfigure->show(); | 323 | moduleConfigure->show(); |
324 | return; | 324 | return; |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); | 328 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); |
329 | QString currentProfileText = currentProfileLabel->text(); | 329 | QString currentProfileText = currentProfileLabel->text(); |
330 | if(currentProfileText.upper() == "ALL"); | 330 | if(currentProfileText.upper() == "ALL"); |
331 | currentProfileText = ""; | 331 | currentProfileText = ""; |
332 | configure->setProfile(currentProfileText); | 332 | configure->setProfile(currentProfileText); |
333 | configure->showMaximized(); | 333 | configure->showMaximized(); |
334 | configure->show(); | 334 | configure->show(); |
335 | } | 335 | } |
336 | 336 | ||
337 | /** | 337 | /** |
338 | * Pull up the information about the currently selected interface. | 338 | * Pull up the information about the currently selected interface. |
339 | * Report an error if no interface is selected. | 339 | * Report an error if no interface is selected. |
340 | * If the interface has a module owner then request its configure. | 340 | * If the interface has a module owner then request its configure. |
341 | */ | 341 | */ |
342 | void MainWindowImp::informationClicked(){ | 342 | void MainWindowImp::informationClicked(){ |
343 | QListViewItem *item = connectionList->currentItem(); | 343 | QListViewItem *item = connectionList->currentItem(); |
344 | if(!item){ | 344 | if(!item){ |
345 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 345 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
346 | return; | 346 | return; |
347 | } | 347 | } |
348 | 348 | ||
349 | Interface *i = interfaceItems[item]; | 349 | Interface *i = interfaceItems[item]; |
350 | if(!i->isAttached()){ | 350 | if(!i->isAttached()){ |
351 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); | 351 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
352 | return; | 352 | return; |
353 | } | 353 | } |
354 | 354 | ||
355 | if(i->getModuleOwner()){ | 355 | if(i->getModuleOwner()){ |
356 | QWidget *moduleInformation = i->getModuleOwner()->information(i); | 356 | QWidget *moduleInformation = i->getModuleOwner()->information(i); |
357 | if(moduleInformation != NULL){ | 357 | if(moduleInformation != NULL){ |
358 | moduleInformation->showMaximized(); | 358 | moduleInformation->showMaximized(); |
359 | moduleInformation->show(); | 359 | moduleInformation->show(); |
360 | return; | 360 | return; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 363 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
364 | information->showMaximized(); | 364 | information->showMaximized(); |
365 | information->show(); | 365 | information->show(); |
366 | } | 366 | } |
367 | 367 | ||
368 | /** | 368 | /** |
369 | * Update this interface. If no QListViewItem exists create one. | 369 | * Update this interface. If no QListViewItem exists create one. |
370 | * @param Interface* pointer to the interface that needs to be updated. | 370 | * @param Interface* pointer to the interface that needs to be updated. |
371 | */ | 371 | */ |
372 | void MainWindowImp::updateInterface(Interface *i){ | 372 | void MainWindowImp::updateInterface(Interface *i){ |
373 | if(!advancedUserMode){ | 373 | if(!advancedUserMode){ |
374 | if(i->getInterfaceName() == "lo") | 374 | if(i->getInterfaceName() == "lo") |
375 | return; | 375 | return; |
376 | } | 376 | } |
377 | 377 | ||
378 | QListViewItem *item = NULL; | 378 | QListViewItem *item = NULL; |
379 | 379 | ||
380 | // Find the interface, making it if needed. | 380 | // Find the interface, making it if needed. |
381 | if(items.find(i) == items.end()){ | 381 | if(items.find(i) == items.end()){ |
382 | item = new QListViewItem(connectionList, "", "", ""); | 382 | item = new QListViewItem(connectionList, "", "", ""); |
383 | // See if you can't find a module owner for this interface | 383 | // See if you can't find a module owner for this interface |
384 | QMap<Module*, QLibrary*>::Iterator it; | 384 | QMap<Module*, QLibrary*>::Iterator it; |
385 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 385 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
386 | if(it.key()->isOwner(i)) | 386 | if(it.key()->isOwner(i)) |
387 | i->setModuleOwner(it.key()); | 387 | i->setModuleOwner(it.key()); |
388 | } | 388 | } |
389 | items.insert(i, item); | 389 | items.insert(i, item); |
390 | interfaceItems.insert(item, i); | 390 | interfaceItems.insert(item, i); |
391 | } | 391 | } |
392 | else | 392 | else |
393 | item = items[i]; | 393 | item = items[i]; |
394 | 394 | ||
395 | // Update the icons and information | 395 | // Update the icons and information |
396 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 396 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
397 | 397 | ||
398 | QString typeName = "lan"; | 398 | QString typeName = "lan"; |
399 | if(i->getHardwareName().contains("Local Loopback")) | 399 | if(i->getHardwareName().contains("Local Loopback")) |
400 | typeName = "lo"; | 400 | typeName = "lo"; |
401 | if(i->getInterfaceName().contains("irda")) | 401 | if(i->getInterfaceName().contains("irda")) |
402 | typeName = "irda"; | 402 | typeName = "irda"; |
403 | if(i->getInterfaceName().contains("wlan")) | 403 | if(i->getInterfaceName().contains("wlan")) |
404 | typeName = "wlan"; | 404 | typeName = "wlan"; |
405 | if(i->getInterfaceName().contains("usb")) | 405 | if(i->getInterfaceName().contains("usb")) |
406 | typeName = "usb"; | 406 | typeName = "usb"; |
407 | 407 | ||
408 | if(!i->isAttached()) | 408 | if(!i->isAttached()) |
409 | typeName = "connect_no"; | 409 | typeName = "connect_no"; |
410 | // Actually try to use the Module | 410 | // Actually try to use the Module |
411 | if(i->getModuleOwner() != NULL) | 411 | if(i->getModuleOwner() != NULL) |
412 | typeName = i->getModuleOwner()->getPixmapName(i); | 412 | typeName = i->getModuleOwner()->getPixmapName(i); |
413 | 413 | ||
414 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 414 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
415 | item->setText(2, i->getHardwareName()); | 415 | item->setText(2, i->getHardwareName()); |
416 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 416 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
417 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 417 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
418 | } | 418 | } |
419 | 419 | ||
420 | void MainWindowImp::newProfileChanged(const QString& newText){ | 420 | void MainWindowImp::newProfileChanged(const QString& newText){ |
421 | if(newText.length() > 0) | 421 | if(newText.length() > 0) |
422 | newProfileButton->setEnabled(true); | 422 | newProfileButton->setEnabled(true); |
423 | else | 423 | else |
424 | newProfileButton->setEnabled(false); | 424 | newProfileButton->setEnabled(false); |
425 | } | 425 | } |
426 | 426 | ||
427 | /** | 427 | /** |
428 | * Adds a new profile to the list of profiles. | 428 | * Adds a new profile to the list of profiles. |
429 | * Don't add profiles that already exists. | 429 | * Don't add profiles that already exists. |
430 | * Appends to the list and QStringList | 430 | * Appends to the list and QStringList |
431 | */ | 431 | */ |
432 | void MainWindowImp::addProfile(){ | 432 | void MainWindowImp::addProfile(){ |
433 | QString newProfileName = newProfile->text(); | 433 | QString newProfileName = newProfile->text(); |
434 | if(profiles.grep(newProfileName).count() > 0){ | 434 | if(profiles.grep(newProfileName).count() > 0){ |
435 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); | 435 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); |
436 | return; | 436 | return; |
437 | } | 437 | } |
438 | profiles.append(newProfileName); | 438 | profiles.append(newProfileName); |
439 | profilesList->insertItem(newProfileName); | 439 | profilesList->insertItem(newProfileName); |
440 | } | 440 | } |
441 | 441 | ||
442 | /** | 442 | /** |
443 | * Removes the currently selected profile in the combo. | 443 | * Removes the currently selected profile in the combo. |
444 | * Doesn't delete if there are less then 2 profiles. | 444 | * Doesn't delete if there are less then 2 profiles. |
445 | */ | 445 | */ |
446 | void MainWindowImp::removeProfile(){ | 446 | void MainWindowImp::removeProfile(){ |
447 | if(profilesList->count() <= 1){ | 447 | if(profilesList->count() <= 1){ |
448 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); | 448 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); |
449 | return; | 449 | return; |
450 | } | 450 | } |
451 | QString profileToRemove = profilesList->currentText(); | 451 | QString profileToRemove = profilesList->currentText(); |
452 | if(profileToRemove == "All"){ | 452 | if(profileToRemove == "All"){ |
453 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); | 453 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); |
454 | return; | 454 | return; |
455 | } | 455 | } |
456 | // Can't remove the curent profile | 456 | // Can't remove the curent profile |
457 | if(profileToRemove == currentProfileLabel->text()){ | 457 | if(profileToRemove == currentProfileLabel->text()){ |
458 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); | 458 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); |
459 | return; | 459 | return; |
460 | 460 | ||
461 | } | 461 | } |
462 | 462 | ||
463 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 463 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
464 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 464 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
465 | profilesList->clear(); | 465 | profilesList->clear(); |
466 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 466 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
467 | profilesList->insertItem((*it)); | 467 | profilesList->insertItem((*it)); |
468 | 468 | ||
469 | // Remove any interface settings and mappings. | 469 | // Remove any interface settings and mappings. |
470 | Interfaces interfaces; | 470 | Interfaces interfaces; |
471 | // Go through them one by one | 471 | // Go through them one by one |
472 | QMap<Interface*, QListViewItem*>::Iterator it; | 472 | QMap<Interface*, QListViewItem*>::Iterator it; |
473 | for( it = items.begin(); it != items.end(); ++it ){ | 473 | for( it = items.begin(); it != items.end(); ++it ){ |
diff --git a/noncore/net/networksetup/mainwindowimp.h b/noncore/net/networksetup/mainwindowimp.h index 382428c..4f09d6c 100644 --- a/noncore/net/networksetup/mainwindowimp.h +++ b/noncore/net/networksetup/mainwindowimp.h | |||
@@ -1,58 +1,58 @@ | |||
1 | #ifndef MAINWINOWIMP_H | 1 | #ifndef MAINWINOWIMP_H |
2 | #define MAINWINOWIMP_H | 2 | #define MAINWINOWIMP_H |
3 | 3 | ||
4 | #include "mainwindow.h" | 4 | #include "mainwindow.h" |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | class Module; | 8 | class Module; |
9 | class Interface; | 9 | class Interface; |
10 | class QLibrary; | 10 | class QLibrary; |
11 | class KProcess; | 11 | class KProcess; |
12 | 12 | ||
13 | class MainWindowImp : public MainWindow { | 13 | class MainWindowImp : public MainWindow { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | MainWindowImp(QWidget *parent=0, const char *name=0); | 17 | MainWindowImp(QWidget *parent=0, const char *name=0); |
18 | ~MainWindowImp(); | 18 | ~MainWindowImp(); |
19 | 19 | ||
20 | private slots: | 20 | private slots: |
21 | void getAllInterfaces(); | 21 | void getAllInterfaces(); |
22 | 22 | ||
23 | void addClicked(); | 23 | void addClicked(); |
24 | void removeClicked(); | 24 | void removeClicked(); |
25 | void configureClicked(); | 25 | void configureClicked(); |
26 | void informationClicked(); | 26 | void informationClicked(); |
27 | 27 | ||
28 | void addProfile(); | 28 | void addProfile(); |
29 | void removeProfile(); | 29 | void removeProfile(); |
30 | void changeProfile(); | 30 | void changeProfile(); |
31 | 31 | ||
32 | void updateInterface(Interface *i); | 32 | void updateInterface(Interface *i); |
33 | void newProfileChanged(const QString& newText); | 33 | void newProfileChanged(const QString& newText); |
34 | 34 | ||
35 | private: | 35 | private: |
36 | void loadModules(QString path); | 36 | void loadModules(const QString &path); |
37 | 37 | ||
38 | Module* loadPlugin(QString pluginFileName, | 38 | Module* loadPlugin(const QString &pluginFileName, |
39 | QString resolveString = "create_plugin"); | 39 | const QString &resolveString = "create_plugin"); |
40 | 40 | ||
41 | // For our local list of names | 41 | // For our local list of names |
42 | QMap<QString, Interface*> interfaceNames; | 42 | QMap<QString, Interface*> interfaceNames; |
43 | 43 | ||
44 | QMap<Module*, QLibrary*> libraries; | 44 | QMap<Module*, QLibrary*> libraries; |
45 | QMap<Interface*, QListViewItem*> items; | 45 | QMap<Interface*, QListViewItem*> items; |
46 | QMap<QListViewItem*, Interface*> interfaceItems; | 46 | QMap<QListViewItem*, Interface*> interfaceItems; |
47 | 47 | ||
48 | QMap<KProcess*, QString> threads; | 48 | QMap<KProcess*, QString> threads; |
49 | QStringList profiles; | 49 | QStringList profiles; |
50 | 50 | ||
51 | bool advancedUserMode; | 51 | bool advancedUserMode; |
52 | QString scheme; | 52 | QString scheme; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | // mainwindowimp.h | 57 | // mainwindowimp.h |
58 | 58 | ||
diff --git a/noncore/net/networksetup/module.h b/noncore/net/networksetup/module.h index 92b125a..2e6272b 100644 --- a/noncore/net/networksetup/module.h +++ b/noncore/net/networksetup/module.h | |||
@@ -1,86 +1,86 @@ | |||
1 | #ifndef NETCONF_MODULE_H | 1 | #ifndef NETCONF_MODULE_H |
2 | #define NETCONF_MODULE_H | 2 | #define NETCONF_MODULE_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qlist.h> | 5 | #include <qlist.h> |
6 | #include <qmap.h> | 6 | #include <qmap.h> |
7 | #include "interface.h" | 7 | #include "interface.h" |
8 | 8 | ||
9 | class QWidget; | 9 | class QWidget; |
10 | class QTabWidget; | 10 | class QTabWidget; |
11 | 11 | ||
12 | class Module : QObject{ | 12 | class Module : QObject{ |
13 | 13 | ||
14 | signals: | 14 | signals: |
15 | void updateInterface(Interface *i); | 15 | void updateInterface(Interface *i); |
16 | 16 | ||
17 | public: | 17 | public: |
18 | Module(){}; | 18 | Module(){}; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * The current profile has been changed and the module should do any | 21 | * The current profile has been changed and the module should do any |
22 | * neccesary changes also. | 22 | * neccesary changes also. |
23 | * @param newProfile what the profile should be changed to. | 23 | * @param newProfile what the profile should be changed to. |
24 | */ | 24 | */ |
25 | virtual void setProfile(QString newProfile) = 0; | 25 | virtual void setProfile(const QString &newProfile) = 0; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * get the icon name for this device. | 28 | * get the icon name for this device. |
29 | * @param Interface* can be used in determining the icon. | 29 | * @param Interface* can be used in determining the icon. |
30 | * @return QString the icon name (minus .png, .gif etc) | 30 | * @return QString the icon name (minus .png, .gif etc) |
31 | */ | 31 | */ |
32 | virtual QString getPixmapName(Interface *) = 0; | 32 | virtual QString getPixmapName(Interface *) = 0; |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Check to see if the interface i is owned by this module. | 35 | * Check to see if the interface i is owned by this module. |
36 | * @param Interface* interface to check against | 36 | * @param Interface* interface to check against |
37 | * @return bool true if i is owned by this module, false otherwise. | 37 | * @return bool true if i is owned by this module, false otherwise. |
38 | */ | 38 | */ |
39 | virtual bool isOwner(Interface *){ return false; }; | 39 | virtual bool isOwner(Interface *){ return false; }; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Create and return the WLANConfigure Module | 42 | * Create and return the WLANConfigure Module |
43 | * @param Interface *i the interface to configure. | 43 | * @param Interface *i the interface to configure. |
44 | * @return QWidget* pointer to this modules configure. | 44 | * @return QWidget* pointer to this modules configure. |
45 | */ | 45 | */ |
46 | virtual QWidget *configure(Interface *){ return NULL; } ; | 46 | virtual QWidget *configure(Interface *){ return NULL; } ; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Create, and return the Information Module | 49 | * Create, and return the Information Module |
50 | * @param Interface *i the interface to get info on. | 50 | * @param Interface *i the interface to get info on. |
51 | * @return QWidget* pointer to this modules info. | 51 | * @return QWidget* pointer to this modules info. |
52 | */ | 52 | */ |
53 | virtual QWidget *information(Interface *){ return NULL; }; | 53 | virtual QWidget *information(Interface *){ return NULL; }; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Get all active (up or down) interfaces | 56 | * Get all active (up or down) interfaces |
57 | * @return QList<Interface> A list of interfaces that exsist that havn't | 57 | * @return QList<Interface> A list of interfaces that exsist that havn't |
58 | * been called by isOwner() | 58 | * been called by isOwner() |
59 | */ | 59 | */ |
60 | virtual QList<Interface> getInterfaces() = 0; | 60 | virtual QList<Interface> getInterfaces() = 0; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp), | 63 | * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp), |
64 | * modem ppp) | 64 | * modem ppp) |
65 | */ | 65 | */ |
66 | virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0; | 66 | virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Attempts to create a new interface from name | 69 | * Attempts to create a new interface from name |
70 | * @return Interface* NULL if it was unable to be created. | 70 | * @return Interface* NULL if it was unable to be created. |
71 | * @param name the type of interface to create | 71 | * @param name the type of interface to create |
72 | */ | 72 | */ |
73 | virtual Interface *addNewInterface(QString name) = 0; | 73 | virtual Interface *addNewInterface(const QString &name) = 0; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Attempts to remove the interface, doesn't delete i | 76 | * Attempts to remove the interface, doesn't delete i |
77 | * @return bool true if successfull, false otherwise. | 77 | * @return bool true if successfull, false otherwise. |
78 | */ | 78 | */ |
79 | virtual bool remove(Interface* i) = 0; | 79 | virtual bool remove(Interface* i) = 0; |
80 | 80 | ||
81 | }; | 81 | }; |
82 | 82 | ||
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | // module.h | 85 | // module.h |
86 | 86 | ||
diff --git a/noncore/net/networksetup/wlan/infoimp.h b/noncore/net/networksetup/wlan/infoimp.h index 5311bea..8f7f0d6 100644 --- a/noncore/net/networksetup/wlan/infoimp.h +++ b/noncore/net/networksetup/wlan/infoimp.h | |||
@@ -1,27 +1,27 @@ | |||
1 | #ifndef INFOIMP_H | 1 | #ifndef INFOIMP_H |
2 | #define INFOIMP_H | 2 | #define INFOIMP_H |
3 | 3 | ||
4 | #include "info.h" | 4 | #include "info.h" |
5 | 5 | ||
6 | class QTimer; | 6 | class QTimer; |
7 | class WExtensions; | 7 | //class WExtensions; |
8 | 8 | ||
9 | class WlanInfoImp : public WlanInfo { | 9 | class WlanInfoImp : public WlanInfo { |
10 | Q_OBJECT | 10 | Q_OBJECT |
11 | 11 | ||
12 | public: | 12 | public: |
13 | WlanInfoImp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 13 | WlanInfoImp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
14 | 14 | ||
15 | private slots: | 15 | private slots: |
16 | void update(); | 16 | void update(); |
17 | 17 | ||
18 | private: | 18 | private: |
19 | //WExtensions *wExtensions; | 19 | //WExtensions *wExtensions; |
20 | QTimer *timer; | 20 | QTimer *timer; |
21 | 21 | ||
22 | }; | 22 | }; |
23 | 23 | ||
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | // infoimp.h | 26 | // infoimp.h |
27 | 27 | ||
diff --git a/noncore/net/networksetup/wlan/wextensions.cpp b/noncore/net/networksetup/wlan/wextensions.cpp index eb6fc42..6335ebc 100644 --- a/noncore/net/networksetup/wlan/wextensions.cpp +++ b/noncore/net/networksetup/wlan/wextensions.cpp | |||
@@ -1,175 +1,174 @@ | |||
1 | #include "wextensions.h" | 1 | #include "wextensions.h" |
2 | 2 | ||
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | 5 | ||
6 | #include <arpa/inet.h> | 6 | #include <arpa/inet.h> |
7 | #include <sys/socket.h> | 7 | #include <sys/socket.h> |
8 | #include <sys/ioctl.h> | 8 | #include <sys/ioctl.h> |
9 | 9 | ||
10 | #include <math.h> | 10 | #include <math.h> |
11 | 11 | ||
12 | #define PROCNETWIRELESS "/proc/net/wireless" | 12 | #define PROCNETWIRELESS "/proc/net/wireless" |
13 | #define IW_LOWER 0 | 13 | #define IW_LOWER 0 |
14 | #define IW_UPPER 256 | 14 | #define IW_UPPER 256 |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * Constructor. Sets hasWirelessExtensions | 17 | * Constructor. Sets hasWirelessExtensions |
18 | */ | 18 | */ |
19 | WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false){ | 19 | WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false), interface(interfaceName) { |
20 | interface = interfaceName; | ||
21 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); | 20 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); |
22 | if(fd == -1) | 21 | if(fd == -1) |
23 | return; | 22 | return; |
24 | 23 | ||
25 | const char* buffer[200]; | 24 | const char* buffer[200]; |
26 | memset( &iwr, 0, sizeof( iwr ) ); | 25 | memset( &iwr, 0, sizeof( iwr ) ); |
27 | iwr.u.essid.pointer = (caddr_t) buffer; | 26 | iwr.u.essid.pointer = (caddr_t) buffer; |
28 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 27 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
29 | iwr.u.essid.flags = 0; | 28 | iwr.u.essid.flags = 0; |
30 | 29 | ||
31 | // check if it is an IEEE 802.11 standard conform | 30 | // check if it is an IEEE 802.11 standard conform |
32 | // wireless device by sending SIOCGIWESSID | 31 | // wireless device by sending SIOCGIWESSID |
33 | // which also gives back the Extended Service Set ID | 32 | // which also gives back the Extended Service Set ID |
34 | // (see IEEE 802.11 for more information) | 33 | // (see IEEE 802.11 for more information) |
35 | 34 | ||
36 | const char* iname = interface.latin1(); | 35 | const char* iname = interface.latin1(); |
37 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); | 36 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); |
38 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) | 37 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) |
39 | hasWirelessExtensions = true; | 38 | hasWirelessExtensions = true; |
40 | } | 39 | } |
41 | 40 | ||
42 | /** | 41 | /** |
43 | * @return QString the station name of the access point. | 42 | * @return QString the station name of the access point. |
44 | */ | 43 | */ |
45 | QString WExtensions::station(){ | 44 | QString WExtensions::station(){ |
46 | if(!hasWirelessExtensions) | 45 | if(!hasWirelessExtensions) |
47 | return QString(); | 46 | return QString(); |
48 | const char* buffer[200]; | 47 | const char* buffer[200]; |
49 | iwr.u.data.pointer = (caddr_t) buffer; | 48 | iwr.u.data.pointer = (caddr_t) buffer; |
50 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 49 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
51 | iwr.u.data.flags = 0; | 50 | iwr.u.data.flags = 0; |
52 | if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ | 51 | if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ |
53 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | 52 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; |
54 | return QString(iwr.u.data.pointer); | 53 | return QString(iwr.u.data.pointer); |
55 | } | 54 | } |
56 | return QString(); | 55 | return QString(); |
57 | } | 56 | } |
58 | 57 | ||
59 | /** | 58 | /** |
60 | * @return QString the essid of the host 802.11 access point. | 59 | * @return QString the essid of the host 802.11 access point. |
61 | */ | 60 | */ |
62 | QString WExtensions::essid(){ | 61 | QString WExtensions::essid(){ |
63 | if(!hasWirelessExtensions) | 62 | if(!hasWirelessExtensions) |
64 | return QString(); | 63 | return QString(); |
65 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ | 64 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ |
66 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | 65 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; |
67 | return QString(iwr.u.essid.pointer); | 66 | return QString(iwr.u.essid.pointer); |
68 | } | 67 | } |
69 | return QString(); | 68 | return QString(); |
70 | } | 69 | } |
71 | 70 | ||
72 | /** | 71 | /** |
73 | * @return QString the mode of interface | 72 | * @return QString the mode of interface |
74 | */ | 73 | */ |
75 | QString WExtensions::mode(){ | 74 | QString WExtensions::mode(){ |
76 | if(!hasWirelessExtensions) | 75 | if(!hasWirelessExtensions) |
77 | return QString(); | 76 | return QString(); |
78 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) | 77 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) |
79 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); | 78 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); |
80 | return QString(); | 79 | return QString(); |
81 | } | 80 | } |
82 | 81 | ||
83 | /** | 82 | /** |
84 | * Get the frequency that the interface is running at. | 83 | * Get the frequency that the interface is running at. |
85 | * @return int the frequency that the interfacae is running at. | 84 | * @return int the frequency that the interfacae is running at. |
86 | */ | 85 | */ |
87 | double WExtensions::frequency(){ | 86 | double WExtensions::frequency(){ |
88 | if(!hasWirelessExtensions) | 87 | if(!hasWirelessExtensions) |
89 | return 0; | 88 | return 0; |
90 | if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) | 89 | if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) |
91 | return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); | 90 | return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); |
92 | return 0; | 91 | return 0; |
93 | } | 92 | } |
94 | 93 | ||
95 | /*** | 94 | /*** |
96 | * Get the current rate that the card is transmiting at. | 95 | * Get the current rate that the card is transmiting at. |
97 | */ | 96 | */ |
98 | double WExtensions::rate(){ | 97 | double WExtensions::rate(){ |
99 | if(!hasWirelessExtensions) | 98 | if(!hasWirelessExtensions) |
100 | return 0; | 99 | return 0; |
101 | if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){ | 100 | if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){ |
102 | return ((double)iwr.u.bitrate.value)/1000000; | 101 | return ((double)iwr.u.bitrate.value)/1000000; |
103 | } | 102 | } |
104 | return 0; | 103 | return 0; |
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||
108 | /** | 107 | /** |
109 | * @return QString the AccessPoint that the interface is connected to. | 108 | * @return QString the AccessPoint that the interface is connected to. |
110 | */ | 109 | */ |
111 | QString WExtensions::ap(){ | 110 | QString WExtensions::ap(){ |
112 | if(!hasWirelessExtensions) | 111 | if(!hasWirelessExtensions) |
113 | return QString(); | 112 | return QString(); |
114 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ | 113 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ |
115 | QString ap; | 114 | QString ap; |
116 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 115 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
117 | iwr.u.ap_addr.sa_data[0]&0xff, | 116 | iwr.u.ap_addr.sa_data[0]&0xff, |
118 | iwr.u.ap_addr.sa_data[1]&0xff, | 117 | iwr.u.ap_addr.sa_data[1]&0xff, |
119 | iwr.u.ap_addr.sa_data[2]&0xff, | 118 | iwr.u.ap_addr.sa_data[2]&0xff, |
120 | iwr.u.ap_addr.sa_data[3]&0xff, | 119 | iwr.u.ap_addr.sa_data[3]&0xff, |
121 | iwr.u.ap_addr.sa_data[4]&0xff, | 120 | iwr.u.ap_addr.sa_data[4]&0xff, |
122 | iwr.u.ap_addr.sa_data[5]&0xff ); | 121 | iwr.u.ap_addr.sa_data[5]&0xff ); |
123 | return ap; | 122 | return ap; |
124 | } | 123 | } |
125 | else return QString(); | 124 | else return QString(); |
126 | } | 125 | } |
127 | 126 | ||
128 | /** | 127 | /** |
129 | * Get the stats for interfaces | 128 | * Get the stats for interfaces |
130 | * @param signal the signal strength of interface | 129 | * @param signal the signal strength of interface |
131 | * @param noise the noise level of the interface | 130 | * @param noise the noise level of the interface |
132 | * @param quality the quality level of the interface | 131 | * @param quality the quality level of the interface |
133 | * @return bool true if successfull | 132 | * @return bool true if successfull |
134 | */ | 133 | */ |
135 | bool WExtensions::stats(int &signal, int &noise, int &quality){ | 134 | bool WExtensions::stats(int &signal, int &noise, int &quality){ |
136 | // gather link quality from /proc/net/wireless | 135 | // gather link quality from /proc/net/wireless |
137 | if(!QFile::exists(PROCNETWIRELESS)) | 136 | if(!QFile::exists(PROCNETWIRELESS)) |
138 | return false; | 137 | return false; |
139 | 138 | ||
140 | char c; | 139 | char c; |
141 | QString status; | 140 | QString status; |
142 | QString name; | 141 | QString name; |
143 | 142 | ||
144 | QFile wfile( PROCNETWIRELESS ); | 143 | QFile wfile( PROCNETWIRELESS ); |
145 | if(!wfile.open( IO_ReadOnly )) | 144 | if(!wfile.open( IO_ReadOnly )) |
146 | return false; | 145 | return false; |
147 | 146 | ||
148 | QTextStream wstream( &wfile ); | 147 | QTextStream wstream( &wfile ); |
149 | wstream.readLine(); // skip the first two lines | 148 | wstream.readLine(); // skip the first two lines |
150 | wstream.readLine(); // because they only contain headers | 149 | wstream.readLine(); // because they only contain headers |
151 | while(!wstream.atEnd()){ | 150 | while(!wstream.atEnd()){ |
152 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | 151 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; |
153 | if(name == QString("%1:").arg(interface)){ | 152 | if(name == QString("%1:").arg(interface)){ |
154 | if ( quality > 92 ) | 153 | if ( quality > 92 ) |
155 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | 154 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); |
156 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | 155 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) |
157 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | 156 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); |
158 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | 157 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) |
159 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | 158 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); |
160 | //qDebug(QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1()); | 159 | //qDebug(QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1()); |
161 | signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; | 160 | signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; |
162 | noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; | 161 | noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; |
163 | quality = ( quality*100 ) / 92; | 162 | quality = ( quality*100 ) / 92; |
164 | return true; | 163 | return true; |
165 | } | 164 | } |
166 | } | 165 | } |
167 | 166 | ||
168 | qDebug("WExtensions::statsCard no longer present."); | 167 | qDebug("WExtensions::statsCard no longer present."); |
169 | quality = -1; | 168 | quality = -1; |
170 | signal = IW_LOWER; | 169 | signal = IW_LOWER; |
171 | noise = IW_LOWER; | 170 | noise = IW_LOWER; |
172 | return false; | 171 | return false; |
173 | } | 172 | } |
174 | 173 | ||
175 | // wextensions.cpp | 174 | // wextensions.cpp |
diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp index 689eae2..d4b4af9 100644 --- a/noncore/net/networksetup/wlan/wlanimp.cpp +++ b/noncore/net/networksetup/wlan/wlanimp.cpp | |||
@@ -1,232 +1,232 @@ | |||
1 | #include "wlanimp.h" | 1 | #include "wlanimp.h" |
2 | #include "interfacesetupimp.h" | 2 | #include "interfacesetupimp.h" |
3 | 3 | ||
4 | #include <qfile.h> | 4 | #include <qfile.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qtextstream.h> | 6 | #include <qtextstream.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | #include <qlineedit.h> | 8 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 9 | #include <qspinbox.h> |
10 | #include <qradiobutton.h> | 10 | #include <qradiobutton.h> |
11 | #include <qcheckbox.h> | 11 | #include <qcheckbox.h> |
12 | #include <qtabwidget.h> | 12 | #include <qtabwidget.h> |
13 | 13 | ||
14 | /* system() */ | 14 | /* system() */ |
15 | #include <stdlib.h> | 15 | #include <stdlib.h> |
16 | 16 | ||
17 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" | 17 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * Constructor, read in the wireless.opts file for parsing later. | 20 | * Constructor, read in the wireless.opts file for parsing later. |
21 | */ | 21 | */ |
22 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { | 22 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { |
23 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); | 23 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); |
24 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | 24 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); |
25 | 25 | ||
26 | // Read in the config file. | 26 | // Read in the config file. |
27 | QString wlanFile = WIRELESS_OPTS; | 27 | QString wlanFile = WIRELESS_OPTS; |
28 | QFile file(wlanFile); | 28 | QFile file(wlanFile); |
29 | if (file.open(IO_ReadOnly)){ | 29 | if (file.open(IO_ReadOnly)){ |
30 | QTextStream stream( &file ); | 30 | QTextStream stream( &file ); |
31 | QString line = ""; | 31 | QString line = ""; |
32 | while ( !stream.eof() ) { | 32 | while ( !stream.eof() ) { |
33 | line += stream.readLine(); | 33 | line += stream.readLine(); |
34 | line += "\n"; | 34 | line += "\n"; |
35 | } | 35 | } |
36 | file.close(); | 36 | file.close(); |
37 | settingsFileText = QStringList::split("\n", line, true); | 37 | settingsFileText = QStringList::split("\n", line, true); |
38 | parseSettingFile(); | 38 | parseSettingFile(); |
39 | } | 39 | } |
40 | else | 40 | else |
41 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); | 41 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); |
42 | } | 42 | } |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Change the profile for both wireless settings and network settings. | 45 | * Change the profile for both wireless settings and network settings. |
46 | */ | 46 | */ |
47 | void WLANImp::setProfile(QString &profile){ | 47 | void WLANImp::setProfile(const QString &profile){ |
48 | interfaceSetup->setProfile(profile); | 48 | interfaceSetup->setProfile(profile); |
49 | parseSettingFile(); | 49 | parseSettingFile(); |
50 | } | 50 | } |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Parses the settings file that was read in and gets any setting from it. | 53 | * Parses the settings file that was read in and gets any setting from it. |
54 | */ | 54 | */ |
55 | void WLANImp::parseSettingFile(){ | 55 | void WLANImp::parseSettingFile(){ |
56 | bool foundCase = false; | 56 | bool foundCase = false; |
57 | bool found = false; | 57 | bool found = false; |
58 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { | 58 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { |
59 | QString line = (*it).simplifyWhiteSpace(); | 59 | QString line = (*it).simplifyWhiteSpace(); |
60 | if(line.contains("case")) | 60 | if(line.contains("case")) |
61 | foundCase = true; | 61 | foundCase = true; |
62 | // See if we found our scheme to write or the sceme couldn't be found | 62 | // See if we found our scheme to write or the sceme couldn't be found |
63 | if((foundCase && line.contains("esac")) || | 63 | if((foundCase && line.contains("esac")) || |
64 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) | 64 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) |
65 | found = true; | 65 | found = true; |
66 | 66 | ||
67 | if(line.contains(";;")) | 67 | if(line.contains(";;")) |
68 | found = false; | 68 | found = false; |
69 | if(found){ | 69 | if(found){ |
70 | // write out scheme | 70 | // write out scheme |
71 | if(line.contains("ESSID=")){ | 71 | if(line.contains("ESSID=")){ |
72 | QString id = line.mid(line.find("ESSID=")+6, line.length()); | 72 | QString id = line.mid(line.find("ESSID=")+6, line.length()); |
73 | if(id == "any"){ | 73 | if(id == "any"){ |
74 | essNon->setChecked(true); | 74 | essNon->setChecked(true); |
75 | essSpecific->setChecked(false); | 75 | essSpecific->setChecked(false); |
76 | }else{ | 76 | }else{ |
77 | essSpecific->setChecked(true); | 77 | essSpecific->setChecked(true); |
78 | essSpecificLineEdit->setText(id); | 78 | essSpecificLineEdit->setText(id); |
79 | essNon->setChecked(false); | 79 | essNon->setChecked(false); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | if(line.contains("MODE=")){ | 82 | if(line.contains("MODE=")){ |
83 | QString mode = line.mid(line.find("MODE=")+5, line.length()); | 83 | QString mode = line.mid(line.find("MODE=")+5, line.length()); |
84 | if(mode == "Managed"){ | 84 | if(mode == "Managed"){ |
85 | network802->setChecked( false ); | 85 | network802->setChecked( false ); |
86 | networkInfrastructure->setChecked( true ); | 86 | networkInfrastructure->setChecked( true ); |
87 | } | 87 | } |
88 | else{ | 88 | else{ |
89 | network802->setChecked( true ); | 89 | network802->setChecked( true ); |
90 | networkInfrastructure->setChecked( false ); | 90 | networkInfrastructure->setChecked( false ); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | if(line.contains("KEY=")){ | 93 | if(line.contains("KEY=")){ |
94 | line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false); | 94 | line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false); |
95 | int s = line.find("KEY="); | 95 | int s = line.find("KEY="); |
96 | line = line.mid(s+4, line.length()); | 96 | line = line.mid(s+4, line.length()); |
97 | // Find first Key | 97 | // Find first Key |
98 | s = line.find("[1]"); | 98 | s = line.find("[1]"); |
99 | if(s != -1){ | 99 | if(s != -1){ |
100 | keyLineEdit0->setText(line.mid(0, s)); | 100 | keyLineEdit0->setText(line.mid(0, s)); |
101 | line = line.mid(s+3, line.length()); | 101 | line = line.mid(s+3, line.length()); |
102 | } | 102 | } |
103 | s = line.find("[2]"); | 103 | s = line.find("[2]"); |
104 | if(s != -1){ | 104 | if(s != -1){ |
105 | keyLineEdit1->setText(line.mid(0, s)); | 105 | keyLineEdit1->setText(line.mid(0, s)); |
106 | line = line.mid(s+3, line.length()); | 106 | line = line.mid(s+3, line.length()); |
107 | } | 107 | } |
108 | s = line.find("[3]"); | 108 | s = line.find("[3]"); |
109 | if(s != -1){ | 109 | if(s != -1){ |
110 | keyLineEdit2->setText(line.mid(0, s)); | 110 | keyLineEdit2->setText(line.mid(0, s)); |
111 | line = line.mid(s+3, line.length()); | 111 | line = line.mid(s+3, line.length()); |
112 | } | 112 | } |
113 | s = line.find("[4]"); | 113 | s = line.find("[4]"); |
114 | if(s != -1){ | 114 | if(s != -1){ |
115 | keyLineEdit3->setText(line.mid(0, s)); | 115 | keyLineEdit3->setText(line.mid(0, s)); |
116 | line = line.mid(s+3, line.length()); | 116 | line = line.mid(s+3, line.length()); |
117 | } | 117 | } |
118 | if(line.contains("key [1]")) keyRadio0->setChecked(true); | 118 | if(line.contains("key [1]")) keyRadio0->setChecked(true); |
119 | if(line.contains("key [2]")) keyRadio1->setChecked(true); | 119 | if(line.contains("key [2]")) keyRadio1->setChecked(true); |
120 | if(line.contains("key [3]")) keyRadio2->setChecked(true); | 120 | if(line.contains("key [3]")) keyRadio2->setChecked(true); |
121 | if(line.contains("key [4]")) keyRadio3->setChecked(true); | 121 | if(line.contains("key [4]")) keyRadio3->setChecked(true); |
122 | if(line.contains("open")){ | 122 | if(line.contains("open")){ |
123 | authOpen->setChecked(true); | 123 | authOpen->setChecked(true); |
124 | authShared->setChecked(false); | 124 | authShared->setChecked(false); |
125 | } | 125 | } |
126 | else{ | 126 | else{ |
127 | authOpen->setChecked(false); | 127 | authOpen->setChecked(false); |
128 | authShared->setChecked(true); | 128 | authShared->setChecked(true); |
129 | } | 129 | } |
130 | } | 130 | } |
131 | if(line.contains("CHANNEL=")){ | 131 | if(line.contains("CHANNEL=")){ |
132 | networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); | 132 | networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | /** | 138 | /** |
139 | * Saves settings to the wireless.opts file using the current profile | 139 | * Saves settings to the wireless.opts file using the current profile |
140 | */ | 140 | */ |
141 | void WLANImp::changeAndSaveSettingFile(){ | 141 | void WLANImp::changeAndSaveSettingFile(){ |
142 | QString wlanFile = WIRELESS_OPTS; | 142 | QString wlanFile = WIRELESS_OPTS; |
143 | QFile::remove(wlanFile); | 143 | QFile::remove(wlanFile); |
144 | QFile file(wlanFile); | 144 | QFile file(wlanFile); |
145 | 145 | ||
146 | if (!file.open(IO_ReadWrite)){ | 146 | if (!file.open(IO_ReadWrite)){ |
147 | qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); | 147 | qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | 150 | ||
151 | QTextStream stream( &file ); | 151 | QTextStream stream( &file ); |
152 | bool foundCase = false; | 152 | bool foundCase = false; |
153 | bool found = false; | 153 | bool found = false; |
154 | bool output = true; | 154 | bool output = true; |
155 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { | 155 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { |
156 | QString line = (*it).simplifyWhiteSpace(); | 156 | QString line = (*it).simplifyWhiteSpace(); |
157 | if(line.contains("case")) | 157 | if(line.contains("case")) |
158 | foundCase = true; | 158 | foundCase = true; |
159 | // See if we found our scheme to write or the sceme couldn't be found | 159 | // See if we found our scheme to write or the sceme couldn't be found |
160 | if((foundCase && line.contains("esac") && !found) || | 160 | if((foundCase && line.contains("esac") && !found) || |
161 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ | 161 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ |
162 | // write out scheme | 162 | // write out scheme |
163 | found = true; | 163 | found = true; |
164 | output = false; | 164 | output = false; |
165 | 165 | ||
166 | if(!line.contains("esac")) | 166 | if(!line.contains("esac")) |
167 | stream << line << "\n"; | 167 | stream << line << "\n"; |
168 | 168 | ||
169 | stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; | 169 | stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; |
170 | stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n'; | 170 | stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n'; |
171 | if(!wepEnabled->isChecked()) | 171 | if(!wepEnabled->isChecked()) |
172 | stream << "#"; | 172 | stream << "#"; |
173 | stream << "\tKEY="; | 173 | stream << "\tKEY="; |
174 | stream << keyLineEdit0->text() << " [1]"; | 174 | stream << keyLineEdit0->text() << " [1]"; |
175 | stream << keyLineEdit1->text() << " [2]"; | 175 | stream << keyLineEdit1->text() << " [2]"; |
176 | stream << keyLineEdit2->text() << " [3]"; | 176 | stream << keyLineEdit2->text() << " [3]"; |
177 | stream << keyLineEdit3->text() << " [4]"; | 177 | stream << keyLineEdit3->text() << " [4]"; |
178 | stream << " key ["; | 178 | stream << " key ["; |
179 | if(keyRadio0->isChecked()) stream << "1]"; | 179 | if(keyRadio0->isChecked()) stream << "1]"; |
180 | if(keyRadio1->isChecked()) stream << "2]"; | 180 | if(keyRadio1->isChecked()) stream << "2]"; |
181 | if(keyRadio2->isChecked()) stream << "3]"; | 181 | if(keyRadio2->isChecked()) stream << "3]"; |
182 | if(keyRadio3->isChecked()) stream << "4]"; | 182 | if(keyRadio3->isChecked()) stream << "4]"; |
183 | if(authOpen->isChecked()) stream << " open"; | 183 | if(authOpen->isChecked()) stream << " open"; |
184 | stream << "\n"; | 184 | stream << "\n"; |
185 | stream << "\tCHANNEL=" << networkChannel->value() << "\n"; | 185 | stream << "\tCHANNEL=" << networkChannel->value() << "\n"; |
186 | stream << "\tRATE=auto\n"; | 186 | stream << "\tRATE=auto\n"; |
187 | if(line.contains("esac")) | 187 | if(line.contains("esac")) |
188 | stream << line << "\n"; | 188 | stream << line << "\n"; |
189 | } | 189 | } |
190 | if(line.contains(";;")) | 190 | if(line.contains(";;")) |
191 | output = true; | 191 | output = true; |
192 | if(output) | 192 | if(output) |
193 | stream << (*it) << '\n'; | 193 | stream << (*it) << '\n'; |
194 | } | 194 | } |
195 | file.close(); | 195 | file.close(); |
196 | } | 196 | } |
197 | 197 | ||
198 | /** | 198 | /** |
199 | * Check to see if the current config is valid | 199 | * Check to see if the current config is valid |
200 | * Save wireless.opts, save interfaces | 200 | * Save wireless.opts, save interfaces |
201 | */ | 201 | */ |
202 | void WLANImp::accept(){ | 202 | void WLANImp::accept(){ |
203 | if(wepEnabled->isChecked()){ | 203 | if(wepEnabled->isChecked()){ |
204 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) | 204 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) |
205 | QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); | 205 | QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | 208 | ||
209 | // Ok settings are good here, save | 209 | // Ok settings are good here, save |
210 | changeAndSaveSettingFile(); | 210 | changeAndSaveSettingFile(); |
211 | 211 | ||
212 | // Try to save the interfaces settings. | 212 | // Try to save the interfaces settings. |
213 | if(!interfaceSetup->saveChanges()) | 213 | if(!interfaceSetup->saveChanges()) |
214 | return; | 214 | return; |
215 | 215 | ||
216 | // Restart the device now that the settings have changed | 216 | // Restart the device now that the settings have changed |
217 | QString initpath; | 217 | QString initpath; |
218 | if( QDir("/etc/rc.d/init.d").exists() ) | 218 | if( QDir("/etc/rc.d/init.d").exists() ) |
219 | initpath = "/etc/rc.d/init.d"; | 219 | initpath = "/etc/rc.d/init.d"; |
220 | else if( QDir("/etc/init.d").exists() ) | 220 | else if( QDir("/etc/init.d").exists() ) |
221 | initpath = "/etc/init.d"; | 221 | initpath = "/etc/init.d"; |
222 | if( initpath ) | 222 | if( initpath ) |
223 | system(QString("%1/pcmcia stop").arg(initpath)); | 223 | system(QString("%1/pcmcia stop").arg(initpath)); |
224 | if( initpath ) | 224 | if( initpath ) |
225 | system(QString("%1/pcmcia start").arg(initpath)); | 225 | system(QString("%1/pcmcia start").arg(initpath)); |
226 | 226 | ||
227 | // Close out the dialog | 227 | // Close out the dialog |
228 | QDialog::accept(); | 228 | QDialog::accept(); |
229 | } | 229 | } |
230 | 230 | ||
231 | // wlanimp.cpp | 231 | // wlanimp.cpp |
232 | 232 | ||
diff --git a/noncore/net/networksetup/wlan/wlanimp.h b/noncore/net/networksetup/wlan/wlanimp.h index f88e550..df599af 100644 --- a/noncore/net/networksetup/wlan/wlanimp.h +++ b/noncore/net/networksetup/wlan/wlanimp.h | |||
@@ -1,31 +1,31 @@ | |||
1 | #ifndef WLANIMP_H | 1 | #ifndef WLANIMP_H |
2 | #define WLANIMP_H | 2 | #define WLANIMP_H |
3 | 3 | ||
4 | #include "wlan.h" | 4 | #include "wlan.h" |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | 6 | ||
7 | class InterfaceSetupImp; | 7 | class InterfaceSetupImp; |
8 | class Interface; | 8 | class Interface; |
9 | class Config; | 9 | class Config; |
10 | 10 | ||
11 | class WLANImp : public WLAN { | 11 | class WLANImp : public WLAN { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | 13 | ||
14 | public: | 14 | public: |
15 | WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); | 15 | WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); |
16 | void setProfile(QString &profile); | 16 | void setProfile(const QString &profile); |
17 | 17 | ||
18 | protected: | 18 | protected: |
19 | void accept(); | 19 | void accept(); |
20 | 20 | ||
21 | private: | 21 | private: |
22 | void parseSettingFile(); | 22 | void parseSettingFile(); |
23 | void changeAndSaveSettingFile(); | 23 | void changeAndSaveSettingFile(); |
24 | 24 | ||
25 | InterfaceSetupImp *interfaceSetup; | 25 | InterfaceSetupImp *interfaceSetup; |
26 | QStringList settingsFileText; | 26 | QStringList settingsFileText; |
27 | QString currentProfile; | 27 | QString currentProfile; |
28 | }; | 28 | }; |
29 | 29 | ||
30 | #endif | 30 | #endif |
31 | 31 | ||
diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp index b14fc0a..3979e60 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.cpp +++ b/noncore/net/networksetup/wlan/wlanmodule.cpp | |||
@@ -1,113 +1,113 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include "wlanimp.h" | 2 | #include "wlanimp.h" |
3 | #include "infoimp.h" | 3 | #include "infoimp.h" |
4 | #include "wextensions.h" | 4 | #include "wextensions.h" |
5 | #include "interfaceinformationimp.h" | 5 | #include "interfaceinformationimp.h" |
6 | 6 | ||
7 | #include <qlabel.h> | 7 | #include <qlabel.h> |
8 | #include <qprogressbar.h> | 8 | #include <qprogressbar.h> |
9 | #include <qtabwidget.h> | 9 | #include <qtabwidget.h> |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Constructor, find all of the possible interfaces | 12 | * Constructor, find all of the possible interfaces |
13 | */ | 13 | */ |
14 | WLANModule::WLANModule() : Module() { | 14 | WLANModule::WLANModule() : Module() { |
15 | } | 15 | } |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * Delete any interfaces that we own. | 18 | * Delete any interfaces that we own. |
19 | */ | 19 | */ |
20 | WLANModule::~WLANModule(){ | 20 | WLANModule::~WLANModule(){ |
21 | Interface *i; | 21 | Interface *i; |
22 | for ( i=list.first(); i != 0; i=list.next() ) | 22 | for ( i=list.first(); i != 0; i=list.next() ) |
23 | delete i; | 23 | delete i; |
24 | } | 24 | } |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Change the current profile | 27 | * Change the current profile |
28 | */ | 28 | */ |
29 | void WLANModule::setProfile(QString newProfile){ | 29 | void WLANModule::setProfile(const QString &newProfile){ |
30 | profile = newProfile; | 30 | profile = newProfile; |
31 | } | 31 | } |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * get the icon name for this device. | 34 | * get the icon name for this device. |
35 | * @param Interface* can be used in determining the icon. | 35 | * @param Interface* can be used in determining the icon. |
36 | * @return QString the icon name (minus .png, .gif etc) | 36 | * @return QString the icon name (minus .png, .gif etc) |
37 | */ | 37 | */ |
38 | QString WLANModule::getPixmapName(Interface* ){ | 38 | QString WLANModule::getPixmapName(Interface* ){ |
39 | return "wlan"; | 39 | return "wlan"; |
40 | } | 40 | } |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Check to see if the interface i is owned by this module. | 43 | * Check to see if the interface i is owned by this module. |
44 | * @param Interface* interface to check against | 44 | * @param Interface* interface to check against |
45 | * @return bool true if i is owned by this module, false otherwise. | 45 | * @return bool true if i is owned by this module, false otherwise. |
46 | */ | 46 | */ |
47 | bool WLANModule::isOwner(Interface *i){ | 47 | bool WLANModule::isOwner(Interface *i){ |
48 | WExtensions we(i->getInterfaceName()); | 48 | WExtensions we(i->getInterfaceName()); |
49 | if(!we.doesHaveWirelessExtensions()) | 49 | if(!we.doesHaveWirelessExtensions()) |
50 | return false; | 50 | return false; |
51 | 51 | ||
52 | i->setHardwareName("802.11b"); | 52 | i->setHardwareName("802.11b"); |
53 | list.append(i); | 53 | list.append(i); |
54 | return true; | 54 | return true; |
55 | } | 55 | } |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Create, and return the WLANConfigure Module | 58 | * Create, and return the WLANConfigure Module |
59 | * @return QWidget* pointer to this modules configure. | 59 | * @return QWidget* pointer to this modules configure. |
60 | */ | 60 | */ |
61 | QWidget *WLANModule::configure(Interface *i){ | 61 | QWidget *WLANModule::configure(Interface *i){ |
62 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, false, Qt::WDestructiveClose); | 62 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, false, Qt::WDestructiveClose); |
63 | wlanconfig->setProfile(profile); | 63 | wlanconfig->setProfile(profile); |
64 | return wlanconfig; | 64 | return wlanconfig; |
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Create, and return the Information Module | 68 | * Create, and return the Information Module |
69 | * @return QWidget* pointer to this modules info. | 69 | * @return QWidget* pointer to this modules info. |
70 | */ | 70 | */ |
71 | QWidget *WLANModule::information(Interface *i){ | 71 | QWidget *WLANModule::information(Interface *i){ |
72 | WExtensions we(i->getInterfaceName()); | 72 | WExtensions we(i->getInterfaceName()); |
73 | if(!we.doesHaveWirelessExtensions()) | 73 | if(!we.doesHaveWirelessExtensions()) |
74 | return NULL; | 74 | return NULL; |
75 | 75 | ||
76 | WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); | 76 | WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); |
77 | InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); | 77 | InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); |
78 | info->tabWidget->insertTab(information, "TCP/IP"); | 78 | info->tabWidget->insertTab(information, "TCP/IP"); |
79 | return info; | 79 | return info; |
80 | } | 80 | } |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Get all active (up or down) interfaces | 83 | * Get all active (up or down) interfaces |
84 | * @return QList<Interface> A list of interfaces that exsist that havn't | 84 | * @return QList<Interface> A list of interfaces that exsist that havn't |
85 | * been called by isOwner() | 85 | * been called by isOwner() |
86 | */ | 86 | */ |
87 | QList<Interface> WLANModule::getInterfaces(){ | 87 | QList<Interface> WLANModule::getInterfaces(){ |
88 | return list; | 88 | return list; |
89 | } | 89 | } |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Attempt to add a new interface as defined by name | 92 | * Attempt to add a new interface as defined by name |
93 | * @param name the name of the type of interface that should be created given | 93 | * @param name the name of the type of interface that should be created given |
94 | * by possibleNewInterfaces(); | 94 | * by possibleNewInterfaces(); |
95 | * @return Interface* NULL if it was unable to be created. | 95 | * @return Interface* NULL if it was unable to be created. |
96 | */ | 96 | */ |
97 | Interface *WLANModule::addNewInterface(QString ){ | 97 | Interface *WLANModule::addNewInterface(const QString &){ |
98 | // We can't add a 802.11 interface, either the hardware will be there | 98 | // We can't add a 802.11 interface, either the hardware will be there |
99 | // or it wont. | 99 | // or it wont. |
100 | return NULL; | 100 | return NULL; |
101 | } | 101 | } |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Attempts to remove the interface, doesn't delete i | 104 | * Attempts to remove the interface, doesn't delete i |
105 | * @return bool true if successfull, false otherwise. | 105 | * @return bool true if successfull, false otherwise. |
106 | */ | 106 | */ |
107 | bool WLANModule::remove(Interface*){ | 107 | bool WLANModule::remove(Interface*){ |
108 | // Can't remove a hardware device, you can stop it though. | 108 | // Can't remove a hardware device, you can stop it though. |
109 | return false; | 109 | return false; |
110 | } | 110 | } |
111 | 111 | ||
112 | // wlanmodule.cpp | 112 | // wlanmodule.cpp |
113 | 113 | ||
diff --git a/noncore/net/networksetup/wlan/wlanmodule.h b/noncore/net/networksetup/wlan/wlanmodule.h index a81ccff..3a54de6 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.h +++ b/noncore/net/networksetup/wlan/wlanmodule.h | |||
@@ -1,41 +1,41 @@ | |||
1 | #ifndef WLAN_MODULE_H | 1 | #ifndef WLAN_MODULE_H |
2 | #define WLAN_MODULE_H | 2 | #define WLAN_MODULE_H |
3 | 3 | ||
4 | #include "module.h" | 4 | #include "module.h" |
5 | 5 | ||
6 | class WLANModule : Module{ | 6 | class WLANModule : Module{ |
7 | 7 | ||
8 | signals: | 8 | signals: |
9 | void updateInterface(Interface *i); | 9 | void updateInterface(Interface *i); |
10 | 10 | ||
11 | public: | 11 | public: |
12 | WLANModule(); | 12 | WLANModule(); |
13 | ~WLANModule(); | 13 | ~WLANModule(); |
14 | 14 | ||
15 | virtual void setProfile(QString newProfile); | 15 | void setProfile(const QString &newProfile); |
16 | virtual bool isOwner(Interface *); | 16 | bool isOwner(Interface *); |
17 | virtual QWidget *configure(Interface *i); | 17 | QWidget *configure(Interface *i); |
18 | virtual QWidget *information(Interface *i); | 18 | QWidget *information(Interface *i); |
19 | virtual QList<Interface> getInterfaces(); | 19 | QList<Interface> getInterfaces(); |
20 | virtual void possibleNewInterfaces(QMap<QString, QString> &){}; | 20 | void possibleNewInterfaces(QMap<QString, QString> &){}; |
21 | virtual Interface *addNewInterface(QString name); | 21 | Interface *addNewInterface(const QString &name); |
22 | virtual bool remove(Interface* i); | 22 | bool remove(Interface* i); |
23 | virtual QString getPixmapName(Interface* i); | 23 | QString getPixmapName(Interface* i); |
24 | 24 | ||
25 | private: | 25 | private: |
26 | QList<Interface> list; | 26 | QList<Interface> list; |
27 | QString profile; | 27 | QString profile; |
28 | 28 | ||
29 | }; | 29 | }; |
30 | 30 | ||
31 | extern "C" | 31 | extern "C" |
32 | { | 32 | { |
33 | void* create_plugin() { | 33 | void* create_plugin() { |
34 | return new WLANModule(); | 34 | return new WLANModule(); |
35 | } | 35 | } |
36 | }; | 36 | }; |
37 | 37 | ||
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | // wlanmodule.h | 40 | // wlanmodule.h |
41 | 41 | ||
diff --git a/noncore/settings/networksettings/TODO b/noncore/settings/networksettings/TODO index 8e57405..7185dbe 100644 --- a/noncore/settings/networksettings/TODO +++ b/noncore/settings/networksettings/TODO | |||
@@ -1,14 +1,13 @@ | |||
1 | CLEAN UP | 1 | CLEAN UP |
2 | 2 | ||
3 | Write a class that parses /proc and not ifconfig | ||
4 | |||
5 | udchcp needs to output the dhcp information so interfaces can read it | 3 | udchcp needs to output the dhcp information so interfaces can read it |
6 | 4 | ||
7 | interfacesetupimp really doesn't need a interface* pointer | 5 | interfacesetupimp really doesn't need a interface* pointer |
8 | 6 | ||
9 | Possible other modules to write: ppp, ipsec, bluetooth, ipchains | 7 | Possible other modules to write: ppp, ipsec, bluetooth, ipchains |
10 | 8 | ||
11 | PPP module needs to scan pppd.tdb to see what is currently active | 9 | PPP module needs to scan pppd.tdb to see what is currently active |
12 | 10 | ||
13 | WLAN - add possiblity to input text or hex without knowing "s:" | 11 | WLAN - add possiblity to input text or hex without knowing "s:" |
14 | 12 | ||
13 | Interface setupimp needs to use kernel calls. | ||
diff --git a/noncore/settings/networksettings/addconnectionimp.cpp b/noncore/settings/networksettings/addconnectionimp.cpp index 53db0fc..07545f7 100644 --- a/noncore/settings/networksettings/addconnectionimp.cpp +++ b/noncore/settings/networksettings/addconnectionimp.cpp | |||
@@ -1,38 +1,37 @@ | |||
1 | #include "addconnectionimp.h" | 1 | #include "addconnectionimp.h" |
2 | #include <qlistview.h> | 2 | #include <qlistview.h> |
3 | #include <qlist.h> | 3 | #include <qlist.h> |
4 | #include <qlabel.h> | 4 | #include <qlabel.h> |
5 | #include <qheader.h> | 5 | #include <qheader.h> |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Constructor | 8 | * Constructor |
9 | */ | 9 | */ |
10 | AddConnectionImp::AddConnectionImp(QWidget *parent, const char *name, WFlags f):AddConnection(parent, name, f){ | 10 | AddConnectionImp::AddConnectionImp(QWidget *parent, const char *name, WFlags f):AddConnection(parent, name, f){ |
11 | connect(registeredServicesList, SIGNAL(selectionChanged()), this, SLOT(changed())); | 11 | connect(registeredServicesList, SIGNAL(selectionChanged()), this, SLOT(changed())); |
12 | registeredServicesList->header()->hide(); | 12 | registeredServicesList->header()->hide(); |
13 | }; | 13 | }; |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * The current item changed, update the discription. | 16 | * The current item changed, update the discription. |
17 | */ | 17 | */ |
18 | void AddConnectionImp::changed(){ | 18 | void AddConnectionImp::changed(){ |
19 | QListViewItem *item = registeredServicesList->currentItem(); | 19 | QListViewItem *item = registeredServicesList->currentItem(); |
20 | if(item){ | 20 | if(item) |
21 | help->setText(list[item->text(0)]); | 21 | help->setText(list[item->text(0)]); |
22 | } | ||
23 | } | 22 | } |
24 | 23 | ||
25 | /** | 24 | /** |
26 | * Save a copy of newList for the discriptions and append them all to the view | 25 | * Save a copy of newList for the discriptions and append them all to the view |
27 | * @param newList the new list of possible interfaces | 26 | * @param newList the new list of possible interfaces |
28 | */ | 27 | */ |
29 | void AddConnectionImp::addConnections(QMap<QString, QString> newList){ | 28 | void AddConnectionImp::addConnections(const QMap<QString, QString> &newList){ |
30 | list = newList; | 29 | list = newList; |
31 | QMap<QString, QString>::Iterator it; | 30 | QMap<QString, QString>::Iterator it; |
32 | for( it = list.begin(); it != list.end(); ++it ) | 31 | for( it = list.begin(); it != list.end(); ++it ) |
33 | QListViewItem *item = new QListViewItem(registeredServicesList, it.key()); | 32 | QListViewItem *item = new QListViewItem(registeredServicesList, it.key()); |
34 | registeredServicesList->setCurrentItem(registeredServicesList->firstChild()); | 33 | registeredServicesList->setCurrentItem(registeredServicesList->firstChild()); |
35 | } | 34 | } |
36 | 35 | ||
37 | // addserviceimp.cpp | 36 | // addserviceimp.cpp |
38 | 37 | ||
diff --git a/noncore/settings/networksettings/addconnectionimp.h b/noncore/settings/networksettings/addconnectionimp.h index 643cd9a..680a502 100644 --- a/noncore/settings/networksettings/addconnectionimp.h +++ b/noncore/settings/networksettings/addconnectionimp.h | |||
@@ -1,29 +1,29 @@ | |||
1 | #ifndef ADDCONNECTIONIMP_H | 1 | #ifndef ADDCONNECTIONIMP_H |
2 | #define ADDCONNECTIONIMP_H | 2 | #define ADDCONNECTIONIMP_H |
3 | 3 | ||
4 | #include "addconnection.h" | 4 | #include "addconnection.h" |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qlist.h> | 6 | #include <qlist.h> |
7 | 7 | ||
8 | class QListViewItem; | 8 | class QListViewItem; |
9 | 9 | ||
10 | class AddConnectionImp : public AddConnection { | 10 | class AddConnectionImp : public AddConnection { |
11 | 11 | ||
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | 13 | ||
14 | public: | 14 | public: |
15 | AddConnectionImp(QWidget *parent=0, const char *name=0, WFlags f=0); | 15 | AddConnectionImp(QWidget *parent=0, const char *name=0, WFlags f=0); |
16 | void addConnections(QMap<QString, QString> newList); | 16 | void addConnections(const QMap<QString, QString> &newList); |
17 | 17 | ||
18 | private slots: | 18 | private slots: |
19 | void changed(); | 19 | void changed(); |
20 | 20 | ||
21 | private: | 21 | private: |
22 | QMap<QString, QString> list; | 22 | QMap<QString, QString> list; |
23 | 23 | ||
24 | }; | 24 | }; |
25 | 25 | ||
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | // addconectionimp.h | 28 | // addconectionimp.h |
29 | 29 | ||
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index e4f405e..4129b3d 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp | |||
@@ -1,297 +1,297 @@ | |||
1 | #include "interface.h" | 1 | #include "interface.h" |
2 | #include <qdatetime.h> | 2 | #include <qdatetime.h> |
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qdir.h> | 4 | #include <qdir.h> |
5 | #include <qfileinfo.h> | 5 | #include <qfileinfo.h> |
6 | #include <qtextstream.h> | 6 | #include <qtextstream.h> |
7 | 7 | ||
8 | #define IFCONFIG "/sbin/ifconfig" | 8 | #define IFCONFIG "/sbin/ifconfig" |
9 | #define DHCP_INFO_DIR "/etc/dhcpc" | 9 | #define DHCP_INFO_DIR "/etc/dhcpc" |
10 | 10 | ||
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
13 | 13 | ||
14 | Interface::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){ | 14 | Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardwareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ |
15 | refresh(); | 15 | refresh(); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Set status | 19 | * Set status |
20 | * @param newStatus - the new status | 20 | * @param newStatus - the new status |
21 | * emit updateInterface | 21 | * emit updateInterface |
22 | */ | 22 | */ |
23 | void Interface::setStatus(bool newStatus){ | 23 | void Interface::setStatus(bool newStatus){ |
24 | if(status != newStatus){ | 24 | if(status != newStatus){ |
25 | status = newStatus; | 25 | status = newStatus; |
26 | refresh(); | 26 | refresh(); |
27 | } | 27 | } |
28 | }; | 28 | }; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Set if attached or not (802.11 card pulled out for example) | 31 | * Set if attached or not (802.11 card pulled out for example) |
32 | * @param isAttached - if attached | 32 | * @param isAttached - if attached |
33 | * emit updateInterface | 33 | * emit updateInterface |
34 | */ | 34 | */ |
35 | void Interface::setAttached(bool isAttached){ | 35 | void Interface::setAttached(bool isAttached){ |
36 | attached = isAttached; | 36 | attached = isAttached; |
37 | emit(updateInterface(this)); | 37 | emit(updateInterface(this)); |
38 | }; | 38 | }; |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Set Hardware name | 41 | * Set Hardware name |
42 | * @param name - the new name | 42 | * @param name - the new name |
43 | * emit updateInterface | 43 | * emit updateInterface |
44 | */ | 44 | */ |
45 | void Interface::setHardwareName(QString name){ | 45 | void Interface::setHardwareName(const QString &name){ |
46 | hardwareName = name; | 46 | hardwareName = name; |
47 | emit(updateInterface(this)); | 47 | emit(updateInterface(this)); |
48 | }; | 48 | }; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Set Module owner | 51 | * Set Module owner |
52 | * @param owner - the new owner | 52 | * @param owner - the new owner |
53 | * emit updateInterface | 53 | * emit updateInterface |
54 | */ | 54 | */ |
55 | void Interface::setModuleOwner(Module *owner){ | 55 | void Interface::setModuleOwner(Module *owner){ |
56 | moduleOwner = owner; | 56 | moduleOwner = owner; |
57 | emit(updateInterface(this)); | 57 | emit(updateInterface(this)); |
58 | }; | 58 | }; |
59 | 59 | ||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Try to start the interface. | 62 | * Try to start the interface. |
63 | */ | 63 | */ |
64 | void Interface::start(){ | 64 | void Interface::start(){ |
65 | // check to see if we are already running. | 65 | // check to see if we are already running. |
66 | if(true == status){ | 66 | if(true == status){ |
67 | emit (updateMessage("Unable to start interface,\n already started")); | 67 | emit (updateMessage("Unable to start interface,\n already started")); |
68 | return; | 68 | return; |
69 | } | 69 | } |
70 | 70 | ||
71 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); | 71 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); |
72 | // See if it was successfull... | 72 | // See if it was successfull... |
73 | if(ret != 0){ | 73 | if(ret != 0){ |
74 | emit (updateMessage("Starting interface failed.")); | 74 | emit (updateMessage("Starting interface failed.")); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | status = true; | 78 | status = true; |
79 | refresh(); | 79 | refresh(); |
80 | emit (updateMessage("Start successfull")); | 80 | emit (updateMessage("Start successfull")); |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Try to stop the interface. | 84 | * Try to stop the interface. |
85 | */ | 85 | */ |
86 | void Interface::stop(){ | 86 | void Interface::stop(){ |
87 | // check to see if we are already stopped. | 87 | // check to see if we are already stopped. |
88 | if(false == status){ | 88 | if(false == status){ |
89 | emit (updateMessage("Unable to stop interface,\n already stopped")); | 89 | emit (updateMessage("Unable to stop interface,\n already stopped")); |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | 92 | ||
93 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); | 93 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); |
94 | if(ret != 0){ | 94 | if(ret != 0){ |
95 | emit (updateMessage("Stopping interface failed.")); | 95 | emit (updateMessage("Stopping interface failed.")); |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | 98 | ||
99 | status = false; | 99 | status = false; |
100 | refresh(); | 100 | refresh(); |
101 | emit (updateMessage("Stop successfull")); | 101 | emit (updateMessage("Stop successfull")); |
102 | } | 102 | } |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Try to restart the interface. | 105 | * Try to restart the interface. |
106 | */ | 106 | */ |
107 | void Interface::restart(){ | 107 | void Interface::restart(){ |
108 | stop(); | 108 | stop(); |
109 | start(); | 109 | start(); |
110 | } | 110 | } |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Try to refresh the information about the interface. | 113 | * Try to refresh the information about the interface. |
114 | * First call ifconfig, then check the dhcp-info file | 114 | * First call ifconfig, then check the dhcp-info file |
115 | * @return bool true if successfull. | 115 | * @return bool true if successfull. |
116 | */ | 116 | */ |
117 | bool Interface::refresh(){ | 117 | bool Interface::refresh(){ |
118 | // See if we are up. | 118 | // See if we are up. |
119 | if(status == false){ | 119 | if(status == false){ |
120 | macAddress = ""; | 120 | macAddress = ""; |
121 | ip = "0.0.0.0"; | 121 | ip = "0.0.0.0"; |
122 | subnetMask = "0.0.0.0"; | 122 | subnetMask = "0.0.0.0"; |
123 | broadcast = ""; | 123 | broadcast = ""; |
124 | dhcp = false; | 124 | dhcp = false; |
125 | dhcpServerIp = ""; | 125 | dhcpServerIp = ""; |
126 | leaseObtained = ""; | 126 | leaseObtained = ""; |
127 | leaseExpires = ""; | 127 | leaseExpires = ""; |
128 | emit(updateInterface(this)); | 128 | emit(updateInterface(this)); |
129 | return true; | 129 | return true; |
130 | } | 130 | } |
131 | 131 | ||
132 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); | 132 | QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); |
133 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); | 133 | int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); |
134 | if(ret != 0){ | 134 | if(ret != 0){ |
135 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); | 135 | qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | 138 | ||
139 | QFile file(fileName); | 139 | QFile file(fileName); |
140 | if (!file.open(IO_ReadOnly)){ | 140 | if (!file.open(IO_ReadOnly)){ |
141 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 141 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
142 | return false; | 142 | return false; |
143 | } | 143 | } |
144 | 144 | ||
145 | // Set to the defaults | 145 | // Set to the defaults |
146 | macAddress = ""; | 146 | macAddress = ""; |
147 | ip = "0.0.0.0"; | 147 | ip = "0.0.0.0"; |
148 | subnetMask = "0.0.0.0"; | 148 | subnetMask = "0.0.0.0"; |
149 | broadcast = ""; | 149 | broadcast = ""; |
150 | 150 | ||
151 | QTextStream stream( &file ); | 151 | QTextStream stream( &file ); |
152 | QString line; | 152 | QString line; |
153 | while ( !stream.eof() ) { | 153 | while ( !stream.eof() ) { |
154 | line = stream.readLine(); | 154 | line = stream.readLine(); |
155 | if(line.contains("HWaddr")){ | 155 | if(line.contains("HWaddr")){ |
156 | int mac = line.find("HWaddr"); | 156 | int mac = line.find("HWaddr"); |
157 | macAddress = line.mid(mac+7, line.length()); | 157 | macAddress = line.mid(mac+7, line.length()); |
158 | } | 158 | } |
159 | if(line.contains("inet addr")){ | 159 | if(line.contains("inet addr")){ |
160 | int ipl = line.find("inet addr"); | 160 | int ipl = line.find("inet addr"); |
161 | int space = line.find(" ", ipl+10); | 161 | int space = line.find(" ", ipl+10); |
162 | ip = line.mid(ipl+10, space-ipl-10); | 162 | ip = line.mid(ipl+10, space-ipl-10); |
163 | } | 163 | } |
164 | if(line.contains("Mask")){ | 164 | if(line.contains("Mask")){ |
165 | int mask = line.find("Mask"); | 165 | int mask = line.find("Mask"); |
166 | subnetMask = line.mid(mask+5, line.length()); | 166 | subnetMask = line.mid(mask+5, line.length()); |
167 | } | 167 | } |
168 | if(line.contains("Bcast")){ | 168 | if(line.contains("Bcast")){ |
169 | int mask = line.find("Bcast"); | 169 | int mask = line.find("Bcast"); |
170 | int space = line.find(" ", mask+6); | 170 | int space = line.find(" ", mask+6); |
171 | broadcast = line.mid(mask+6, space-mask-6); | 171 | broadcast = line.mid(mask+6, space-mask-6); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | file.close(); | 174 | file.close(); |
175 | QFile::remove(fileName); | 175 | QFile::remove(fileName); |
176 | 176 | ||
177 | // DHCP TESTING | 177 | // DHCP TESTING |
178 | // reset DHCP info | 178 | // reset DHCP info |
179 | dhcpServerIp = ""; | 179 | dhcpServerIp = ""; |
180 | leaseObtained = ""; | 180 | leaseObtained = ""; |
181 | leaseExpires = ""; | 181 | leaseExpires = ""; |
182 | dhcp = false; | 182 | dhcp = false; |
183 | 183 | ||
184 | QString dhcpDirectory(DHCP_INFO_DIR); | 184 | QString dhcpDirectory(DHCP_INFO_DIR); |
185 | QDir d(dhcpDirectory); | 185 | QDir d(dhcpDirectory); |
186 | if(!d.exists(dhcpDirectory)) | 186 | if(!d.exists(dhcpDirectory)) |
187 | dhcpDirectory = "/var/run"; | 187 | dhcpDirectory = "/var/run"; |
188 | 188 | ||
189 | // See if we have | 189 | // See if we have |
190 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); | 190 | QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); |
191 | // If there is no DHCP information then exit now with no errors. | 191 | // If there is no DHCP information then exit now with no errors. |
192 | if(!QFile::exists(dhcpFile)){ | 192 | if(!QFile::exists(dhcpFile)){ |
193 | emit(updateInterface(this)); | 193 | emit(updateInterface(this)); |
194 | return true; | 194 | return true; |
195 | } | 195 | } |
196 | 196 | ||
197 | file.setName(dhcpFile); | 197 | file.setName(dhcpFile); |
198 | if (!file.open(IO_ReadOnly)){ | 198 | if (!file.open(IO_ReadOnly)){ |
199 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 199 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
200 | return false; | 200 | return false; |
201 | } | 201 | } |
202 | 202 | ||
203 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. | 203 | // leaseTime and renewalTime and used if pid and deamon exe can be accessed. |
204 | int leaseTime = 0; | 204 | int leaseTime = 0; |
205 | int renewalTime = 0; | 205 | int renewalTime = 0; |
206 | 206 | ||
207 | stream.setDevice( &file ); | 207 | stream.setDevice( &file ); |
208 | while ( !stream.eof() ) { | 208 | while ( !stream.eof() ) { |
209 | line = stream.readLine(); | 209 | line = stream.readLine(); |
210 | if(line.contains("DHCPSIADDR=")) | 210 | if(line.contains("DHCPSIADDR=")) |
211 | dhcpServerIp = line.mid(11, line.length()); | 211 | dhcpServerIp = line.mid(11, line.length()); |
212 | if(line.contains("LEASETIME=")) | 212 | if(line.contains("LEASETIME=")) |
213 | leaseTime = line.mid(10, line.length()).toInt(); | 213 | leaseTime = line.mid(10, line.length()).toInt(); |
214 | if(line.contains("RENEWALTIME=")) | 214 | if(line.contains("RENEWALTIME=")) |
215 | renewalTime = line.mid(12, line.length()).toInt(); | 215 | renewalTime = line.mid(12, line.length()).toInt(); |
216 | } | 216 | } |
217 | file.close(); | 217 | file.close(); |
218 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); | 218 | //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); |
219 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); | 219 | //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); |
220 | 220 | ||
221 | // Get the pid of the deamond | 221 | // Get the pid of the deamond |
222 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); | 222 | dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); |
223 | file.setName(dhcpFile); | 223 | file.setName(dhcpFile); |
224 | if (!file.open(IO_ReadOnly)){ | 224 | if (!file.open(IO_ReadOnly)){ |
225 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); | 225 | qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); |
226 | return false; | 226 | return false; |
227 | } | 227 | } |
228 | 228 | ||
229 | int pid = -1; | 229 | int pid = -1; |
230 | stream.setDevice( &file ); | 230 | stream.setDevice( &file ); |
231 | while ( !stream.eof() ) { | 231 | while ( !stream.eof() ) { |
232 | line = stream.readLine(); | 232 | line = stream.readLine(); |
233 | pid = line.toInt(); | 233 | pid = line.toInt(); |
234 | } | 234 | } |
235 | file.close(); | 235 | file.close(); |
236 | 236 | ||
237 | if( pid == -1){ | 237 | if( pid == -1){ |
238 | qDebug("Interface: Could not get pid of dhcpc deamon."); | 238 | qDebug("Interface: Could not get pid of dhcpc deamon."); |
239 | return false; | 239 | return false; |
240 | } | 240 | } |
241 | 241 | ||
242 | // Get the start running time of the deamon | 242 | // Get the start running time of the deamon |
243 | fileName = (QString("/proc/%1/stat").arg(pid)); | 243 | fileName = (QString("/proc/%1/stat").arg(pid)); |
244 | file.setName(fileName); | 244 | file.setName(fileName); |
245 | stream.setDevice( &file ); | 245 | stream.setDevice( &file ); |
246 | if (!file.open(IO_ReadOnly)){ | 246 | if (!file.open(IO_ReadOnly)){ |
247 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); | 247 | qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); |
248 | return false; | 248 | return false; |
249 | } | 249 | } |
250 | while ( !stream.eof() ) { | 250 | while ( !stream.eof() ) { |
251 | line = stream.readLine(); | 251 | line = stream.readLine(); |
252 | } | 252 | } |
253 | file.close(); | 253 | file.close(); |
254 | long time = 0; | 254 | long time = 0; |
255 | // Grab the start time | 255 | // Grab the start time |
256 | // pid com state ppid pgrp session tty_nr tpgid flags | 256 | // pid com state ppid pgrp session tty_nr tpgid flags |
257 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " | 257 | sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " |
258 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority | 258 | // minflt cminflt majflt cmajflt utime stime cutime cstime priority |
259 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " | 259 | "%*u %*u %*u %*u %*u %*u %*d %*d %*d " |
260 | // nice 0 itrealvalue starttime | 260 | // nice 0 itrealvalue starttime |
261 | "%*d %*d %*d %lu", (long*) &time); | 261 | "%*d %*d %*d %lu", (long*) &time); |
262 | time = time/100; | 262 | time = time/100; |
263 | 263 | ||
264 | QDateTime datetime(QDateTime::currentDateTime()); | 264 | QDateTime datetime(QDateTime::currentDateTime()); |
265 | 265 | ||
266 | // Get the uptime of the computer. | 266 | // Get the uptime of the computer. |
267 | QFile f("/proc/uptime"); | 267 | QFile f("/proc/uptime"); |
268 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 268 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
269 | QTextStream t( &f ); // use a text stream | 269 | QTextStream t( &f ); // use a text stream |
270 | int sec = 0; | 270 | int sec = 0; |
271 | t >> sec; | 271 | t >> sec; |
272 | datetime = datetime.addSecs((-1*sec)); | 272 | datetime = datetime.addSecs((-1*sec)); |
273 | f.close(); | 273 | f.close(); |
274 | } | 274 | } |
275 | else{ | 275 | else{ |
276 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); | 276 | qDebug("Interface: Can't open /proc/uptime to retrive uptime."); |
277 | return false; | 277 | return false; |
278 | } | 278 | } |
279 | 279 | ||
280 | datetime = datetime.addSecs(time); | 280 | datetime = datetime.addSecs(time); |
281 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); | 281 | //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); |
282 | 282 | ||
283 | // Calculate the start and renew times | 283 | // Calculate the start and renew times |
284 | leaseObtained= datetime.toString(); | 284 | leaseObtained= datetime.toString(); |
285 | 285 | ||
286 | // Calculate the start and renew times | 286 | // Calculate the start and renew times |
287 | datetime = datetime.addSecs(leaseTime); | 287 | datetime = datetime.addSecs(leaseTime); |
288 | leaseExpires = datetime.toString(); | 288 | leaseExpires = datetime.toString(); |
289 | 289 | ||
290 | dhcp = true; | 290 | dhcp = true; |
291 | 291 | ||
292 | emit(updateInterface(this)); | 292 | emit(updateInterface(this)); |
293 | return true; | 293 | return true; |
294 | } | 294 | } |
295 | 295 | ||
296 | // interface.cpp | 296 | // interface.cpp |
297 | 297 | ||
diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h index fc064fe..989d6d8 100644 --- a/noncore/settings/networksettings/interfaces/interface.h +++ b/noncore/settings/networksettings/interfaces/interface.h | |||
@@ -1,72 +1,71 @@ | |||
1 | #ifndef INTERFACE_H | 1 | #ifndef INTERFACE_H |
2 | #define INTERFACE_H | 2 | #define INTERFACE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | 6 | ||
7 | class Module; | 7 | class Module; |
8 | 8 | ||
9 | class Interface : public QObject{ | 9 | class Interface : public QObject{ |
10 | Q_OBJECT | 10 | Q_OBJECT |
11 | 11 | ||
12 | signals: | 12 | signals: |
13 | void updateInterface(Interface *i); | 13 | void updateInterface(Interface *i); |
14 | void updateMessage(const QString &message); | 14 | void updateMessage(const QString &message); |
15 | 15 | ||
16 | public: | 16 | public: |
17 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); | 17 | Interface(QObject * parent=0, const char * name= "unknown", bool status = false); |
18 | virtual ~Interface(){}; | ||
19 | 18 | ||
20 | virtual QString getInterfaceName(){ QString n(this->name()); return n; }; | 19 | QString getInterfaceName(){ QString n(this->name()); return n; }; |
21 | 20 | ||
22 | virtual bool getStatus(){ return status; }; | 21 | bool getStatus(){ return status; }; |
23 | virtual void setStatus(bool newStatus); | 22 | void setStatus(bool newStatus); |
24 | 23 | ||
25 | virtual bool isAttached(){ return attached; }; | 24 | bool isAttached(){ return attached; }; |
26 | virtual void setAttached(bool isAttached=false); | 25 | void setAttached(bool isAttached=false); |
27 | 26 | ||
28 | virtual QString getHardwareName(){ return hardwareName; }; | 27 | QString getHardwareName(){ return hardwareName; }; |
29 | virtual void setHardwareName(QString name="Unknown"); | 28 | void setHardwareName(const QString &name="Unknown"); |
30 | 29 | ||
31 | virtual Module* getModuleOwner(){ return moduleOwner; }; | 30 | Module* getModuleOwner(){ return moduleOwner; }; |
32 | virtual void setModuleOwner(Module *owner=NULL); | 31 | void setModuleOwner(Module *owner=NULL); |
33 | 32 | ||
34 | // inet information. | 33 | // inet information. |
35 | QString getMacAddress(){ return macAddress; }; | 34 | QString getMacAddress(){ return macAddress; }; |
36 | QString getIp(){ return ip; }; | 35 | QString getIp(){ return ip; }; |
37 | QString getSubnetMask(){ return subnetMask; }; | 36 | QString getSubnetMask(){ return subnetMask; }; |
38 | QString getBroadcast(){ return broadcast; }; | 37 | QString getBroadcast(){ return broadcast; }; |
39 | bool isDhcp(){ return dhcp; }; | 38 | bool isDhcp(){ return dhcp; }; |
40 | QString getDhcpServerIp(){ return dhcpServerIp; }; | 39 | QString getDhcpServerIp(){ return dhcpServerIp; }; |
41 | QString getLeaseObtained(){ return leaseObtained; }; | 40 | QString getLeaseObtained(){ return leaseObtained; }; |
42 | QString getLeaseExpires(){ return leaseExpires; }; | 41 | QString getLeaseExpires(){ return leaseExpires; }; |
43 | 42 | ||
44 | public slots: | 43 | public slots: |
45 | bool refresh(); | 44 | bool refresh(); |
46 | void start(); | 45 | void start(); |
47 | void stop(); | 46 | void stop(); |
48 | void restart(); | 47 | void restart(); |
49 | 48 | ||
50 | private: | 49 | private: |
51 | // Interface information | 50 | // Interface information |
52 | bool status; | 51 | bool status; |
53 | bool attached; | 52 | bool attached; |
54 | QString hardwareName; | 53 | QString hardwareName; |
55 | Module *moduleOwner; | 54 | Module *moduleOwner; |
56 | 55 | ||
57 | // Network information | 56 | // Network information |
58 | QString macAddress; | 57 | QString macAddress; |
59 | QString ip; | 58 | QString ip; |
60 | QString broadcast; | 59 | QString broadcast; |
61 | QString subnetMask; | 60 | QString subnetMask; |
62 | bool dhcp; | 61 | bool dhcp; |
63 | QString dhcpServerIp; | 62 | QString dhcpServerIp; |
64 | QString leaseObtained; | 63 | QString leaseObtained; |
65 | QString leaseExpires; | 64 | QString leaseExpires; |
66 | 65 | ||
67 | }; | 66 | }; |
68 | 67 | ||
69 | #endif | 68 | #endif |
70 | 69 | ||
71 | // interface.h | 70 | // interface.h |
72 | 71 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index f1b8067..708f399 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp | |||
@@ -1,638 +1,640 @@ | |||
1 | #include "interfaces.h" | 1 | #include "interfaces.h" |
2 | 2 | ||
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | #include <qregexp.h> | 5 | #include <qregexp.h> |
6 | 6 | ||
7 | #define AUTO "auto" | 7 | #define AUTO "auto" |
8 | #define IFACE "iface" | 8 | #define IFACE "iface" |
9 | #define MAPPING "mapping" | 9 | #define MAPPING "mapping" |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Constructor. Reads in the interfaces file and then split the file up by | 12 | * Constructor. Reads in the interfaces file and then split the file up by |
13 | * the \n for interfaces variable. | 13 | * the \n for interfaces variable. |
14 | * @param useInterfacesFile if an interface file other then the default is | 14 | * @param useInterfacesFile if an interface file other then the default is |
15 | * desired to be used it should be passed in. | 15 | * desired to be used it should be passed in. |
16 | */ | 16 | */ |
17 | Interfaces::Interfaces(QString useInterfacesFile){ | 17 | Interfaces::Interfaces(QString useInterfacesFile){ |
18 | acceptedFamily.append(INTERFACES_FAMILY_INET); | 18 | acceptedFamily.append(INTERFACES_FAMILY_INET); |
19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | 19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); |
20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | 20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); |
21 | 21 | ||
22 | interfacesFile = useInterfacesFile; | 22 | interfacesFile = useInterfacesFile; |
23 | QFile file(interfacesFile); | 23 | QFile file(interfacesFile); |
24 | if (!file.open(IO_ReadOnly)){ | 24 | if (!file.open(IO_ReadOnly)){ |
25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); | 25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); |
26 | currentIface = interfaces.end(); | 26 | currentIface = interfaces.end(); |
27 | currentMapping = interfaces.end(); | 27 | currentMapping = interfaces.end(); |
28 | return; | 28 | return; |
29 | } | 29 | } |
30 | QTextStream stream( &file ); | 30 | QTextStream stream( &file ); |
31 | QString line; | 31 | QString line; |
32 | while ( !stream.eof() ) { | 32 | while ( !stream.eof() ) { |
33 | line += stream.readLine(); | 33 | line += stream.readLine(); |
34 | line += "\n"; | 34 | line += "\n"; |
35 | } | 35 | } |
36 | file.close(); | 36 | file.close(); |
37 | interfaces = QStringList::split("\n", line, true); | 37 | interfaces = QStringList::split("\n", line, true); |
38 | 38 | ||
39 | currentIface = interfaces.end(); | 39 | currentIface = interfaces.end(); |
40 | currentMapping = interfaces.end(); | 40 | currentMapping = interfaces.end(); |
41 | } | 41 | } |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Get a list of all interfaces in the interface file. Usefull for | 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 | 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. | 47 | * not plugged in, but configured for when it is plugged in. |
48 | * @return Return string list of interfaces. | 48 | * @return Return string list of interfaces. |
49 | **/ | 49 | **/ |
50 | QStringList Interfaces::getInterfaceList(){ | 50 | QStringList Interfaces::getInterfaceList(){ |
51 | QStringList list; | 51 | QStringList list; |
52 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 52 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
53 | QString line = (*it).simplifyWhiteSpace(); | 53 | QString line = (*it).simplifyWhiteSpace(); |
54 | if(line.contains(IFACE) && line.at(0) != '#'){ | 54 | if(line.contains(IFACE) && line.at(0) != '#'){ |
55 | line = line.mid(QString(IFACE).length() +1, line.length()); | 55 | line = line.mid(QString(IFACE).length() +1, line.length()); |
56 | line = line.simplifyWhiteSpace(); | 56 | line = line.simplifyWhiteSpace(); |
57 | int findSpace = line.find(" "); | 57 | int findSpace = line.find(" "); |
58 | if( findSpace >= 0){ | 58 | if( findSpace >= 0){ |
59 | line = line.mid(0, findSpace); | 59 | line = line.mid(0, findSpace); |
60 | list.append(line); | 60 | list.append(line); |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | return list; | 64 | return list; |
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Find out if interface is in an "auto" group or not. | 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 | 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. | 70 | * @param interface interface to check to see if it is on or not. |
71 | * @return true is interface is in auto | 71 | * @return true is interface is in auto |
72 | */ | 72 | */ |
73 | bool Interfaces::isAuto(QString interface){ | 73 | bool Interfaces::isAuto(const QString &interface){ |
74 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | 74 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); |
75 | QStringList awi = autoLines.grep(QRegExp(interface)); | 75 | QStringList awi = autoLines.grep(QRegExp(interface)); |
76 | if(awi.count() > 1) | 76 | if(awi.count() > 1) |
77 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); | 77 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); |
78 | if(awi.count() < 1) | 78 | if(awi.count() < 1) |
79 | return false; | 79 | return false; |
80 | return true; | 80 | return true; |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Attempt to set the auto option for interface to setAuto. | 84 | * Attempt to set the auto option for interface to setAuto. |
85 | * @param interface the interface to set | 85 | * @param interface the interface to set |
86 | * @param setAuto the value to set interface to. | 86 | * @param setAuto the value to set interface to. |
87 | * @return false if already set to setAuto. | 87 | * @return false if already set to setAuto. |
88 | * */ | 88 | * */ |
89 | bool Interfaces::setAuto(QString interface, bool setAuto){ | 89 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ |
90 | // Don't need to set it if it is already set. | 90 | // Don't need to set it if it is already set. |
91 | if(isAuto(interface) == setAuto) | 91 | if(isAuto(interface) == setAuto) |
92 | return false; | 92 | return false; |
93 | 93 | ||
94 | bool changed = false; | 94 | bool changed = false; |
95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
96 | if((*it).contains(AUTO)){ | 96 | if((*it).contains(AUTO)){ |
97 | //We know that they are not in any group so let add to this auto. | 97 | //We know that they are not in any group so let add to this auto. |
98 | if(setAuto){ | 98 | if(setAuto){ |
99 | (*it) = (*it) += " " + interface; | 99 | (*it) = (*it) += " " + interface; |
100 | // Don't care to have such thins as: auto eth0 lo usb0 | 100 | // Don't care to have such thins as: auto eth0 lo usb0 |
101 | (*it) = (*it).simplifyWhiteSpace(); | 101 | (*it) = (*it).simplifyWhiteSpace(); |
102 | changed = true; | 102 | changed = true; |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | else{ | 105 | else{ |
106 | if((*it).contains(interface)){ | 106 | if((*it).contains(interface)){ |
107 | (*it) = (*it).replace(QRegExp(interface), ""); | 107 | (*it) = (*it).replace(QRegExp(interface), ""); |
108 | // clean up | 108 | // clean up |
109 | QString line = (*it).simplifyWhiteSpace(); | 109 | QString line = (*it).simplifyWhiteSpace(); |
110 | line = line.replace(QRegExp(" "),""); | 110 | line = line.replace(QRegExp(" "),""); |
111 | if(line == AUTO) | 111 | if(line == AUTO) |
112 | (*it) = ""; | 112 | (*it) = ""; |
113 | changed = true; | 113 | changed = true; |
114 | // Don't break because we want to make sure we remove all cases. | 114 | // Don't break because we want to make sure we remove all cases. |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | if(changed == false){ | 119 | if(changed == false){ |
120 | if(setAuto == true) | 120 | if(setAuto == true) |
121 | interfaces.append(QString(AUTO" %1").arg(interface)); | 121 | interfaces.append(QString(AUTO" %1").arg(interface)); |
122 | else{ | 122 | else{ |
123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | 123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | return true; | 126 | return true; |
127 | } | 127 | } |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * Set the current interface to interface. This needs to be done before you | 130 | * Set the current interface to interface. This needs to be done before you |
131 | * can call getFamily(), getMethod, and get/setOption(). | 131 | * can call getFamily(), getMethod, and get/setOption(). |
132 | * @param interface the name of the interface to set. All whitespace is | 132 | * @param interface the name of the interface to set. All whitespace is |
133 | * removed from the interface name. | 133 | * removed from the interface name. |
134 | * @return bool true if it is successfull. | 134 | * @return bool true if it is successfull. |
135 | */ | 135 | */ |
136 | bool Interfaces::setInterface(QString interface){ | 136 | bool Interfaces::setInterface(QString interface){ |
137 | interface = interface.simplifyWhiteSpace(); | 137 | interface = interface.simplifyWhiteSpace(); |
138 | interface = interface.replace(QRegExp(" "), ""); | 138 | interface = interface.replace(QRegExp(" "), ""); |
139 | return setStanza(IFACE, interface, currentIface); | 139 | return setStanza(IFACE, interface, currentIface); |
140 | } | 140 | } |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * A quick helper funtion to see if the current interface is set. | 143 | * A quick helper funtion to see if the current interface is set. |
144 | * @return bool true if set, false otherwise. | 144 | * @return bool true if set, false otherwise. |
145 | */ | 145 | */ |
146 | bool Interfaces::isInterfaceSet(){ | 146 | bool Interfaces::isInterfaceSet(){ |
147 | return (currentIface != interfaces.end()); | 147 | return (currentIface != interfaces.end()); |
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Add a new interface of with the settings - family and method | 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 | 152 | * @param interface the name of the interface to set. All whitespace is |
153 | * removed from the interface name. | 153 | * removed from the interface name. |
154 | * @param family the family of this interface inet or inet, ipx or inet6 | 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 | 155 | * Must of one of the families defined in interfaces.h |
156 | * @param method for the family. see interfaces man page for family methods. | 156 | * @param method for the family. see interfaces man page for family methods. |
157 | * @return true if successfull. | 157 | * @return true if successfull. |
158 | */ | 158 | */ |
159 | bool Interfaces::addInterface(QString interface, QString family, QString method){ | 159 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ |
160 | if(acceptedFamily.contains(family)==0) | 160 | if(acceptedFamily.contains(family)==0) |
161 | return false; | 161 | return false; |
162 | interface = interface.simplifyWhiteSpace(); | 162 | QString newInterface = interface.simplifyWhiteSpace(); |
163 | interface = interface.replace(QRegExp(" "), ""); | 163 | newInterface = newInterface.replace(QRegExp(" "), ""); |
164 | interfaces.append(""); | 164 | interfaces.append(""); |
165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); | 165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); |
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Copies interface with name interface to name newInterface | 170 | * Copies interface with name interface to name newInterface |
171 | * @param newInterface name of the new interface. | 171 | * @param newInterface name of the new interface. |
172 | * @return bool true if successfull | 172 | * @return bool true if successfull |
173 | */ | 173 | */ |
174 | bool Interfaces::copyInterface(QString interface, QString newInterface){ | 174 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ |
175 | if(!setInterface(interface)) return false; | 175 | if(!setInterface(interface)) return false; |
176 | 176 | ||
177 | QStringList::Iterator it = currentIface; | 177 | QStringList::Iterator it = currentIface; |
178 | it++; | 178 | it++; |
179 | 179 | ||
180 | bool error; | 180 | bool error; |
181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | 181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); |
182 | if(!setInterface(newInterface)) return false; | 182 | if(!setInterface(newInterface)) return false; |
183 | QStringList::Iterator newIface = currentIface; | 183 | QStringList::Iterator newIface = currentIface; |
184 | newIface++; | 184 | newIface++; |
185 | 185 | ||
186 | for ( ; it != interfaces.end(); ++it ){ | 186 | for ( ; it != interfaces.end(); ++it ){ |
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | 187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) |
188 | break; | 188 | break; |
189 | newIface = interfaces.insert(newIface, *it); | 189 | newIface = interfaces.insert(newIface, *it); |
190 | } | 190 | } |
191 | 191 | ||
192 | return true; | 192 | return true; |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Remove the currently selected interface and all of its options. | 196 | * Remove the currently selected interface and all of its options. |
197 | * @return bool if successfull or not. | 197 | * @return bool if successfull or not. |
198 | */ | 198 | */ |
199 | bool Interfaces::removeInterface(){ | 199 | bool Interfaces::removeInterface(){ |
200 | if(currentIface == interfaces.end()) | 200 | if(currentIface == interfaces.end()) |
201 | return false; | 201 | return false; |
202 | (*currentIface) = ""; | 202 | (*currentIface) = ""; |
203 | return removeAllInterfaceOptions(); | 203 | return removeAllInterfaceOptions(); |
204 | } | 204 | } |
205 | 205 | ||
206 | /** | 206 | /** |
207 | * Gets the hardware name of the interface that is currently selected. | 207 | * Gets the hardware name of the interface that is currently selected. |
208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
209 | * @param error set to true if any error occurs, false otherwise. | 209 | * @param error set to true if any error occurs, false otherwise. |
210 | */ | 210 | */ |
211 | QString Interfaces::getInterfaceName(bool &error){ | 211 | QString Interfaces::getInterfaceName(bool &error){ |
212 | if(currentIface == interfaces.end()){ | 212 | if(currentIface == interfaces.end()){ |
213 | error = true; | 213 | error = true; |
214 | return QString(); | 214 | return QString(); |
215 | } | 215 | } |
216 | QString line = (*currentIface); | 216 | QString line = (*currentIface); |
217 | line = line.mid(QString(IFACE).length() +1, line.length()); | 217 | line = line.mid(QString(IFACE).length() +1, line.length()); |
218 | line = line.simplifyWhiteSpace(); | 218 | line = line.simplifyWhiteSpace(); |
219 | int findSpace = line.find(" "); | 219 | int findSpace = line.find(" "); |
220 | if( findSpace < 0){ | 220 | if( findSpace < 0){ |
221 | error = true; | 221 | error = true; |
222 | return QString(); | 222 | return QString(); |
223 | } | 223 | } |
224 | error = false; | 224 | error = false; |
225 | return line.mid(0, findSpace); | 225 | return line.mid(0, findSpace); |
226 | } | 226 | } |
227 | 227 | ||
228 | /** | 228 | /** |
229 | * Gets the family name of the interface that is currently selected. | 229 | * Gets the family name of the interface that is currently selected. |
230 | * @return QString name of the family (inet, inet6, ipx). | 230 | * @return QString name of the family (inet, inet6, ipx). |
231 | * @param error set to true if any error occurs, false otherwise. | 231 | * @param error set to true if any error occurs, false otherwise. |
232 | */ | 232 | */ |
233 | QString Interfaces::getInterfaceFamily(bool &error){ | 233 | QString Interfaces::getInterfaceFamily(bool &error){ |
234 | QString name = getInterfaceName(error); | 234 | QString name = getInterfaceName(error); |
235 | if(error){ | 235 | if(error){ |
236 | error = true; | 236 | error = true; |
237 | return QString(); | 237 | return QString(); |
238 | } | 238 | } |
239 | QString line = (*currentIface); | 239 | QString line = (*currentIface); |
240 | line = line.mid(QString(IFACE).length() +1, line.length()); | 240 | line = line.mid(QString(IFACE).length() +1, line.length()); |
241 | line = line.mid(name.length()+1, line.length()); | 241 | line = line.mid(name.length()+1, line.length()); |
242 | line = line.simplifyWhiteSpace(); | 242 | line = line.simplifyWhiteSpace(); |
243 | int findSpace = line.find(" "); | 243 | int findSpace = line.find(" "); |
244 | if( findSpace < 0){ | 244 | if( findSpace < 0){ |
245 | error = true; | 245 | error = true; |
246 | return QString(); | 246 | return QString(); |
247 | } | 247 | } |
248 | error = false; | 248 | error = false; |
249 | return line.mid(0, findSpace); | 249 | return line.mid(0, findSpace); |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | 252 | /** |
253 | * Gets the method of the interface that is currently selected. | 253 | * Gets the method of the interface that is currently selected. |
254 | * @return QString name of the method such as staic or dhcp. | 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. | 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. | 256 | * @param error set to true if any error occurs, false otherwise. |
257 | */ | 257 | */ |
258 | QString Interfaces::getInterfaceMethod(bool &error){ | 258 | QString Interfaces::getInterfaceMethod(bool &error){ |
259 | QString name = getInterfaceName(error); | 259 | QString name = getInterfaceName(error); |
260 | if(error){ | 260 | if(error){ |
261 | error = true; | 261 | error = true; |
262 | return QString(); | 262 | return QString(); |
263 | } | 263 | } |
264 | QString family = getInterfaceFamily(error); | 264 | QString family = getInterfaceFamily(error); |
265 | if(error){ | 265 | if(error){ |
266 | error = true; | 266 | error = true; |
267 | return QString(); | 267 | return QString(); |
268 | } | 268 | } |
269 | QString line = (*currentIface); | 269 | QString line = (*currentIface); |
270 | line = line.mid(QString(IFACE).length()+1, line.length()); | 270 | line = line.mid(QString(IFACE).length()+1, line.length()); |
271 | line = line.mid(name.length()+1, line.length()); | 271 | line = line.mid(name.length()+1, line.length()); |
272 | line = line.mid(family.length()+1, line.length()); | 272 | line = line.mid(family.length()+1, line.length()); |
273 | line = line.simplifyWhiteSpace(); | 273 | line = line.simplifyWhiteSpace(); |
274 | error = false; | 274 | error = false; |
275 | return line; | 275 | return line; |
276 | } | 276 | } |
277 | 277 | ||
278 | /** | 278 | /** |
279 | * Sets the interface name to newName. | 279 | * Sets the interface name to newName. |
280 | * @param newName the new name of the interface. All whitespace is removed. | 280 | * @param newName the new name of the interface. All whitespace is removed. |
281 | * @return bool true if successfull. | 281 | * @return bool true if successfull. |
282 | */ | 282 | */ |
283 | bool Interfaces::setInterfaceName(QString newName){ | 283 | bool Interfaces::setInterfaceName(const QString &newName){ |
284 | if(currentIface == interfaces.end()) | 284 | if(currentIface == interfaces.end()) |
285 | return false; | 285 | return false; |
286 | newName = newName.simplifyWhiteSpace(); | 286 | QString name = newName.simplifyWhiteSpace(); |
287 | newName = newName.replace(QRegExp(" "), ""); | 287 | name = name.replace(QRegExp(" "), ""); |
288 | bool returnValue = false; | 288 | bool returnValue = false; |
289 | (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); | 289 | (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); |
290 | return !returnValue; | 290 | return !returnValue; |
291 | } | 291 | } |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Sets the interface family to newName. | 294 | * Sets the interface family to newName. |
295 | * @param newName the new name of the interface. Must be one of the families | 295 | * @param newName the new name of the interface. Must be one of the families |
296 | * defined in the interfaces.h file. | 296 | * defined in the interfaces.h file. |
297 | * @return bool true if successfull. | 297 | * @return bool true if successfull. |
298 | */ | 298 | */ |
299 | bool Interfaces::setInterfaceFamily(QString newName){ | 299 | bool Interfaces::setInterfaceFamily(const QString &newName){ |
300 | if(currentIface == interfaces.end()) | 300 | if(currentIface == interfaces.end()) |
301 | return false; | 301 | return false; |
302 | if(acceptedFamily.contains(newName)==0) | 302 | if(acceptedFamily.contains(newName)==0) |
303 | return false; | 303 | return false; |
304 | bool returnValue = false; | 304 | bool returnValue = false; |
305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | 305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); |
306 | return !returnValue; | 306 | return !returnValue; |
307 | } | 307 | } |
308 | 308 | ||
309 | /** | 309 | /** |
310 | * Sets the interface method to newName | 310 | * Sets the interface method to newName |
311 | * @param newName the new name of the interface | 311 | * @param newName the new name of the interface |
312 | * @return bool true if successfull. | 312 | * @return bool true if successfull. |
313 | */ | 313 | */ |
314 | bool Interfaces::setInterfaceMethod(QString newName){ | 314 | bool Interfaces::setInterfaceMethod(const QString &newName){ |
315 | if(currentIface == interfaces.end()) | 315 | if(currentIface == interfaces.end()) |
316 | return false; | 316 | return false; |
317 | bool returnValue = false; | 317 | bool returnValue = false; |
318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | 318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); |
319 | return !returnValue; | 319 | return !returnValue; |
320 | } | 320 | } |
321 | 321 | ||
322 | /** | 322 | /** |
323 | * Get a value for an option in the currently selected interface. For example | 323 | * Get a value for an option in the currently selected interface. For example |
324 | * calling getInterfaceOption("address") on the following stanza would | 324 | * calling getInterfaceOption("address") on the following stanza would |
325 | * return 192.168.1.1. | 325 | * return 192.168.1.1. |
326 | * iface eth0 static | 326 | * iface eth0 static |
327 | * address 192.168.1.1 | 327 | * address 192.168.1.1 |
328 | * @param option the options to get the value. | 328 | * @param option the options to get the value. |
329 | * @param error set to true if any error occurs, false otherwise. | 329 | * @param error set to true if any error occurs, false otherwise. |
330 | * @return QString the options value. QString::null if error == true | 330 | * @return QString the options value. QString::null if error == true |
331 | */ | 331 | */ |
332 | QString Interfaces::getInterfaceOption(QString option, bool &error){ | 332 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ |
333 | return getOption(currentIface, option, error); | 333 | return getOption(currentIface, option, error); |
334 | } | 334 | } |
335 | 335 | ||
336 | /** | 336 | /** |
337 | * Set a value for an option in the currently selected interface. If option | 337 | * Set a value for an option in the currently selected interface. If option |
338 | * doesn't exist then it is added along with the value. | 338 | * doesn't exist then it is added along with the value. |
339 | * @param option the options to set the value. | 339 | * @param option the options to set the value. |
340 | * @param value the value that option should be set to. | 340 | * @param value the value that option should be set to. |
341 | * @param error set to true if any error occurs, false otherwise. | 341 | * @param error set to true if any error occurs, false otherwise. |
342 | * @return QString the options value. QString::null if error == true | 342 | * @return QString the options value. QString::null if error == true |
343 | */ | 343 | */ |
344 | bool Interfaces::setInterfaceOption(QString option, QString value){ | 344 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ |
345 | return setOption(currentIface, option, value); | 345 | return setOption(currentIface, option, value); |
346 | } | 346 | } |
347 | 347 | ||
348 | /** | 348 | /** |
349 | * Removes a value for an option in the currently selected interface. | 349 | * Removes a value for an option in the currently selected interface. |
350 | * @param option the options to set the value. | 350 | * @param option the options to set the value. |
351 | * @param value the value that option should be set to. | 351 | * @param value the value that option should be set to. |
352 | * @param error set to true if any error occurs, false otherwise. | 352 | * @param error set to true if any error occurs, false otherwise. |
353 | * @return QString the options value. QString::null if error == true | 353 | * @return QString the options value. QString::null if error == true |
354 | */ | 354 | */ |
355 | bool Interfaces::removeInterfaceOption(QString option, QString value){ | 355 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ |
356 | return removeOption(currentIface, option, value); | 356 | return removeOption(currentIface, option, value); |
357 | } | 357 | } |
358 | 358 | ||
359 | /** | 359 | /** |
360 | * Removes all of the options from the currently selected interface. | 360 | * Removes all of the options from the currently selected interface. |
361 | * @return bool error if if successfull | 361 | * @return bool error if if successfull |
362 | */ | 362 | */ |
363 | bool Interfaces::removeAllInterfaceOptions(){ | 363 | bool Interfaces::removeAllInterfaceOptions(){ |
364 | return removeAllOptions(currentIface); | 364 | return removeAllOptions(currentIface); |
365 | } | 365 | } |
366 | 366 | ||
367 | /** | 367 | /** |
368 | * Set the current map to interface's map. This needs to be done before you | 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(). | 369 | * can call addMapping(), set/getMap(), and get/setScript(). |
370 | * @param interface the name of the interface to set. All whitespace is | 370 | * @param interface the name of the interface to set. All whitespace is |
371 | * removed from the interface name. | 371 | * removed from the interface name. |
372 | * @return bool true if it is successfull. | 372 | * @return bool true if it is successfull. |
373 | */ | 373 | */ |
374 | bool Interfaces::setMapping(QString interface){ | 374 | bool Interfaces::setMapping(const QString &interface){ |
375 | interface = interface.simplifyWhiteSpace(); | 375 | QString interfaceName = interface.simplifyWhiteSpace(); |
376 | interface = interface.replace(QRegExp(" "), ""); | 376 | interfaceName = interfaceName.replace(QRegExp(" "), ""); |
377 | return setStanza(MAPPING, interface, currentMapping); | 377 | return setStanza(MAPPING, interfaceName, currentMapping); |
378 | } | 378 | } |
379 | 379 | ||
380 | /** | 380 | /** |
381 | * Adds a new Mapping to the interfaces file with interfaces. | 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 | 382 | * @param interface the name(s) of the interfaces to set to this mapping |
383 | */ | 383 | */ |
384 | void Interfaces::addMapping(QString option){ | 384 | void Interfaces::addMapping(const QString &option){ |
385 | interfaces.append(""); | 385 | interfaces.append(""); |
386 | interfaces.append(QString(MAPPING " %1").arg(option)); | 386 | interfaces.append(QString(MAPPING " %1").arg(option)); |
387 | } | 387 | } |
388 | 388 | ||
389 | /** | 389 | /** |
390 | * Remove the currently selected map and all of its options. | 390 | * Remove the currently selected map and all of its options. |
391 | * @return bool if successfull or not. | 391 | * @return bool if successfull or not. |
392 | */ | 392 | */ |
393 | bool Interfaces::removeMapping(){ | 393 | bool Interfaces::removeMapping(){ |
394 | if(currentMapping == interfaces.end()) | 394 | if(currentMapping == interfaces.end()) |
395 | return false; | 395 | return false; |
396 | (*currentMapping) = ""; | 396 | (*currentMapping) = ""; |
397 | return removeAllOptions(currentMapping); | 397 | return removeAllOptions(currentMapping); |
398 | } | 398 | } |
399 | 399 | ||
400 | /** | 400 | /** |
401 | * Set a map option within a mapping. | 401 | * Set a map option within a mapping. |
402 | * @param map map to use | 402 | * @param map map to use |
403 | * @param value value to go with map | 403 | * @param value value to go with map |
404 | * @return bool true if it is successfull. | 404 | * @return bool true if it is successfull. |
405 | */ | 405 | */ |
406 | bool Interfaces::setMap(QString map, QString value){ | 406 | bool Interfaces::setMap(const QString &map, const QString &value){ |
407 | return setOption(currentMapping, map, value); | 407 | return setOption(currentMapping, map, value); |
408 | } | 408 | } |
409 | 409 | ||
410 | /** | 410 | /** |
411 | * Removes a map option within a mapping. | 411 | * Removes a map option within a mapping. |
412 | * @param map map to use | 412 | * @param map map to use |
413 | * @param value value to go with map | 413 | * @param value value to go with map |
414 | * @return bool true if it is successfull. | 414 | * @return bool true if it is successfull. |
415 | */ | 415 | */ |
416 | bool Interfaces::removeMap(QString map, QString value){ | 416 | bool Interfaces::removeMap(const QString &map, const QString &value){ |
417 | return removeOption(currentMapping, map, value); | 417 | return removeOption(currentMapping, map, value); |
418 | } | 418 | } |
419 | 419 | ||
420 | /** | 420 | /** |
421 | * Get a map value within a mapping. | 421 | * Get a map value within a mapping. |
422 | * @param map map to get value of | 422 | * @param map map to get value of |
423 | * @param bool true if it is successfull. | 423 | * @param bool true if it is successfull. |
424 | * @return value that goes to the map | 424 | * @return value that goes to the map |
425 | */ | 425 | */ |
426 | QString Interfaces::getMap(QString map, bool &error){ | 426 | QString Interfaces::getMap(const QString &map, bool &error){ |
427 | return getOption(currentMapping, map, error); | 427 | return getOption(currentMapping, map, error); |
428 | } | 428 | } |
429 | 429 | ||
430 | /** | 430 | /** |
431 | * Sets a script value of the current mapping to argument. | 431 | * Sets a script value of the current mapping to argument. |
432 | * @param argument the script name. | 432 | * @param argument the script name. |
433 | * @return true if successfull. | 433 | * @return true if successfull. |
434 | */ | 434 | */ |
435 | bool Interfaces::setScript(QString argument){ | 435 | bool Interfaces::setScript(const QString &argument){ |
436 | return setOption(currentMapping, "script", argument); | 436 | return setOption(currentMapping, "script", argument); |
437 | } | 437 | } |
438 | 438 | ||
439 | /** | 439 | /** |
440 | * @param error true if could not retrieve the current script argument. | 440 | * @param error true if could not retrieve the current script argument. |
441 | * @return QString the argument of the script for the current mapping. | 441 | * @return QString the argument of the script for the current mapping. |
442 | */ | 442 | */ |
443 | QString Interfaces::getScript(bool &error){ | 443 | QString Interfaces::getScript(bool &error){ |
444 | return getOption(currentMapping, "script", error); | 444 | return getOption(currentMapping, "script", error); |
445 | } | 445 | } |
446 | 446 | ||
447 | |||
448 | |||
447 | /** | 449 | /** |
448 | * Helper function used to parse through the QStringList and put pointers in | 450 | * Helper function used to parse through the QStringList and put pointers in |
449 | * the correct place. | 451 | * the correct place. |
450 | * @param stanza The stanza (auto, iface, mapping) to look for. | 452 | * @param stanza The stanza (auto, iface, mapping) to look for. |
451 | * @param option string that must be in the stanza's main line. | 453 | * @param option string that must be in the stanza's main line. |
452 | * @param interator interator to place at location of stanza if successfull. | 454 | * @param interator interator to place at location of stanza if successfull. |
453 | * @return bool true if the stanza is found. | 455 | * @return bool true if the stanza is found. |
454 | */ | 456 | */ |
455 | bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ | 457 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ |
456 | bool found = false; | 458 | bool found = false; |
457 | iterator = interfaces.end(); | 459 | iterator = interfaces.end(); |
458 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 460 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
459 | QString line = (*it).simplifyWhiteSpace(); | 461 | QString line = (*it).simplifyWhiteSpace(); |
460 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ | 462 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ |
461 | uint point = line.find(option); | 463 | uint point = line.find(option); |
462 | bool valid = true; | 464 | bool valid = true; |
463 | if(point > 0){ | 465 | if(point > 0){ |
464 | // There are more chars in the line. check +1 | 466 | // There are more chars in the line. check +1 |
465 | if(line.at(point-1) != ' ') | 467 | if(line.at(point-1) != ' ') |
466 | valid = false; | 468 | valid = false; |
467 | } | 469 | } |
468 | point += option.length(); | 470 | point += option.length(); |
469 | if(point < line.length()-1){ | 471 | if(point < line.length()-1){ |
470 | // There are more chars in the line. check -1 | 472 | // There are more chars in the line. check -1 |
471 | if(line.at(point) != ' ') | 473 | if(line.at(point) != ' ') |
472 | valid = false; | 474 | valid = false; |
473 | } | 475 | } |
474 | if(valid){ | 476 | if(valid){ |
475 | if(found == true){ | 477 | if(found == true){ |
476 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 478 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); |
477 | } | 479 | } |
478 | found = true; | 480 | found = true; |
479 | iterator = it; | 481 | iterator = it; |
480 | } | 482 | } |
481 | } | 483 | } |
482 | } | 484 | } |
483 | return found; | 485 | return found; |
484 | } | 486 | } |
485 | 487 | ||
486 | /** | 488 | /** |
487 | * Sets a value of an option in a stanza | 489 | * Sets a value of an option in a stanza |
488 | * @param start the start of the stanza | 490 | * @param start the start of the stanza |
489 | * @param option the option to use when setting value. | 491 | * @param option the option to use when setting value. |
490 | * @return bool true if successfull, false otherwise. | 492 | * @return bool true if successfull, false otherwise. |
491 | */ | 493 | */ |
492 | bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ | 494 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
493 | if(start == interfaces.end()) | 495 | if(start == interfaces.end()) |
494 | return false; | 496 | return false; |
495 | 497 | ||
496 | bool found = false; | 498 | bool found = false; |
497 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 499 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
498 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 500 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
499 | if(!found && value != ""){ | 501 | if(!found && value != ""){ |
500 | // Got to the end of the stanza without finding it, so append it. | 502 | // 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)); | 503 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); |
502 | } | 504 | } |
503 | found = true; | 505 | found = true; |
504 | break; | 506 | break; |
505 | } | 507 | } |
506 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 508 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
507 | // Found it in stanza so replace it. | 509 | // Found it in stanza so replace it. |
508 | if(found) | 510 | if(found) |
509 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 511 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
510 | found = true; | 512 | found = true; |
511 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 513 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
512 | } | 514 | } |
513 | } | 515 | } |
514 | if(!found){ | 516 | if(!found){ |
515 | QStringList::Iterator p = start; | 517 | QStringList::Iterator p = start; |
516 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 518 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
517 | found = true; | 519 | found = true; |
518 | } | 520 | } |
519 | return found; | 521 | return found; |
520 | } | 522 | } |
521 | /** | 523 | /** |
522 | * Removes a option in a stanza | 524 | * Removes a option in a stanza |
523 | * @param start the start of the stanza | 525 | * @param start the start of the stanza |
524 | * @param option the option to use when setting value. | 526 | * @param option the option to use when setting value. |
525 | * @return bool true if successfull, false otherwise. | 527 | * @return bool true if successfull, false otherwise. |
526 | */ | 528 | */ |
527 | bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ | 529 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
528 | if(start == interfaces.end()) | 530 | if(start == interfaces.end()) |
529 | return false; | 531 | return false; |
530 | 532 | ||
531 | bool found = false; | 533 | bool found = false; |
532 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 534 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
533 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 535 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
534 | // got to the end without finding it | 536 | // got to the end without finding it |
535 | break; | 537 | break; |
536 | } | 538 | } |
537 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 539 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
538 | // Found it in stanza so replace it. | 540 | // Found it in stanza so replace it. |
539 | if(found) | 541 | if(found) |
540 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 542 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
541 | found = true; | 543 | found = true; |
542 | (*it) = ""; | 544 | (*it) = ""; |
543 | } | 545 | } |
544 | } | 546 | } |
545 | return found; | 547 | return found; |
546 | } | 548 | } |
547 | 549 | ||
548 | /** | 550 | /** |
549 | * Removes all options in a stanza | 551 | * Removes all options in a stanza |
550 | * @param start the start of the stanza | 552 | * @param start the start of the stanza |
551 | * @return bool true if successfull, false otherwise. | 553 | * @return bool true if successfull, false otherwise. |
552 | */ | 554 | */ |
553 | bool Interfaces::removeAllOptions(QStringList::Iterator start){ | 555 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ |
554 | if(start == interfaces.end()) | 556 | if(start == interfaces.end()) |
555 | return false; | 557 | return false; |
556 | 558 | ||
557 | QStringList::Iterator it = start; | 559 | QStringList::Iterator it = start; |
558 | it = ++it; | 560 | it = ++it; |
559 | for (; it != interfaces.end(); ++it ) { | 561 | for (; it != interfaces.end(); ++it ) { |
560 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 562 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
561 | break; | 563 | break; |
562 | } | 564 | } |
563 | it = interfaces.remove(it); | 565 | it = interfaces.remove(it); |
564 | it = --it; | 566 | it = --it; |
565 | } | 567 | } |
566 | // Leave a space between this interface and the next. | 568 | // Leave a space between this interface and the next. |
567 | interfaces.insert(it, QString("")); | 569 | interfaces.insert(it, QString("")); |
568 | return true; | 570 | return true; |
569 | } | 571 | } |
570 | 572 | ||
571 | /** | 573 | /** |
572 | * Gets a value of an option in a stanza | 574 | * Gets a value of an option in a stanza |
573 | * @param start the start of the stanza | 575 | * @param start the start of the stanza |
574 | * @param option the option to use when getting the value. | 576 | * @param option the option to use when getting the value. |
575 | * @param bool true if errors false otherwise. | 577 | * @param bool true if errors false otherwise. |
576 | * @return QString the value of option QString::null() if error == true. | 578 | * @return QString the value of option QString::null() if error == true. |
577 | */ | 579 | */ |
578 | QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ | 580 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ |
579 | if(start == interfaces.end()){ | 581 | if(start == interfaces.end()){ |
580 | error = false; | 582 | error = false; |
581 | return QString(); | 583 | return QString(); |
582 | } | 584 | } |
583 | 585 | ||
584 | QString value; | 586 | QString value; |
585 | bool found = false; | 587 | bool found = false; |
586 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 588 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
587 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 589 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
588 | break; | 590 | break; |
589 | } | 591 | } |
590 | if((*it).contains(option) && (*it).at(0) != '#'){ | 592 | if((*it).contains(option) && (*it).at(0) != '#'){ |
591 | if(found) | 593 | 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()); | 594 | 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; | 595 | found = true; |
594 | QString line = (*it).simplifyWhiteSpace(); | 596 | QString line = (*it).simplifyWhiteSpace(); |
595 | int space = line.find(" ", option.length()); | 597 | int space = line.find(" ", option.length()); |
596 | if(space != -1) | 598 | if(space != -1) |
597 | value = line.mid(space+1, line.length()); | 599 | value = line.mid(space+1, line.length()); |
598 | else | 600 | else |
599 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | 601 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); |
600 | } | 602 | } |
601 | } | 603 | } |
602 | error = !found; | 604 | error = !found; |
603 | return value; | 605 | return value; |
604 | } | 606 | } |
605 | 607 | ||
606 | /** | 608 | /** |
607 | * Write out the interfaces file to the file passed into the constructor. | 609 | * Write out the interfaces file to the file passed into the constructor. |
608 | * Removes any excess blank lines over 1 line long. | 610 | * Removes any excess blank lines over 1 line long. |
609 | * @return bool true if successfull, false if not. | 611 | * @return bool true if successfull, false if not. |
610 | */ | 612 | */ |
611 | bool Interfaces::write(){ | 613 | bool Interfaces::write(){ |
612 | QFile::remove(interfacesFile); | 614 | QFile::remove(interfacesFile); |
613 | QFile file(interfacesFile); | 615 | QFile file(interfacesFile); |
614 | 616 | ||
615 | if (!file.open(IO_ReadWrite)){ | 617 | if (!file.open(IO_ReadWrite)){ |
616 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | 618 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); |
617 | return false; | 619 | return false; |
618 | } | 620 | } |
619 | QTextStream stream( &file ); | 621 | QTextStream stream( &file ); |
620 | int whiteSpaceCount = 0; | 622 | int whiteSpaceCount = 0; |
621 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 623 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
622 | QString line = (*it).simplifyWhiteSpace(); | 624 | QString line = (*it).simplifyWhiteSpace(); |
623 | line = line.replace(QRegExp(" "),""); | 625 | line = line.replace(QRegExp(" "),""); |
624 | if(line.length() == 0) | 626 | if(line.length() == 0) |
625 | whiteSpaceCount++; | 627 | whiteSpaceCount++; |
626 | else | 628 | else |
627 | whiteSpaceCount = 0; | 629 | whiteSpaceCount = 0; |
628 | if(whiteSpaceCount < 2){ | 630 | if(whiteSpaceCount < 2){ |
629 | qDebug((*it).latin1()); | 631 | qDebug((*it).latin1()); |
630 | stream << (*it) << '\n'; | 632 | stream << (*it) << '\n'; |
631 | } | 633 | } |
632 | } | 634 | } |
633 | file.close(); | 635 | file.close(); |
634 | return true; | 636 | return true; |
635 | } | 637 | } |
636 | 638 | ||
637 | // interfaces.cpp | 639 | // interfaces.cpp |
638 | 640 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaces.h b/noncore/settings/networksettings/interfaces/interfaces.h index e09ea71..26abb73 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.h +++ b/noncore/settings/networksettings/interfaces/interfaces.h | |||
@@ -1,76 +1,76 @@ | |||
1 | #ifndef INTERFACES_H | 1 | #ifndef INTERFACES_H |
2 | #define INTERFACES_H | 2 | #define INTERFACES_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | 6 | ||
7 | #define INTERFACES_LOOPBACK "loopback" | 7 | #define INTERFACES_LOOPBACK "loopback" |
8 | 8 | ||
9 | #define INTERFACES_FAMILY_INET "inet" | 9 | #define INTERFACES_FAMILY_INET "inet" |
10 | #define INTERFACES_FAMILY_IPX "ipx" | 10 | #define INTERFACES_FAMILY_IPX "ipx" |
11 | #define INTERFACES_FAMILY_INET6 "inet6" | 11 | #define INTERFACES_FAMILY_INET6 "inet6" |
12 | 12 | ||
13 | #define INTERFACES_METHOD_DHCP "dhcp" | 13 | #define INTERFACES_METHOD_DHCP "dhcp" |
14 | #define INTERFACES_METHOD_STATIC "static" | 14 | #define INTERFACES_METHOD_STATIC "static" |
15 | #define INTERFACES_METHOD_PPP "ppp" | 15 | #define INTERFACES_METHOD_PPP "ppp" |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * This class provides a clean frontend for parsing the network interfaces file. | 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. | 19 | * It provides helper functions to minipulate the options within the file. |
20 | * See the interfaces man page for the syntax rules. | 20 | * See the interfaces man page for the syntax rules. |
21 | */ | 21 | */ |
22 | class Interfaces { | 22 | class Interfaces { |
23 | 23 | ||
24 | public: | 24 | public: |
25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); | 25 | Interfaces(QString useInterfacesFile = "/etc/network/interfaces"); |
26 | QStringList getInterfaceList(); | 26 | QStringList getInterfaceList(); |
27 | 27 | ||
28 | bool isAuto(QString interface); | 28 | bool isAuto(const QString &interface); |
29 | bool setAuto(QString interface, bool setAuto); | 29 | bool setAuto(const QString &interface, bool setAuto); |
30 | 30 | ||
31 | bool removeInterface(); | 31 | bool removeInterface(); |
32 | bool addInterface(QString interface, QString family, QString method); | 32 | bool addInterface(const QString &interface, const QString &family, const QString &method); |
33 | bool copyInterface(QString oldInterface, QString newInterface); | 33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); |
34 | bool setInterface(QString interface); | 34 | bool setInterface(QString interface); |
35 | bool isInterfaceSet(); | 35 | inline bool isInterfaceSet(); |
36 | QString getInterfaceName(bool &error); | 36 | QString getInterfaceName(bool &error); |
37 | bool setInterfaceName(QString newName); | 37 | bool setInterfaceName(const QString &newName); |
38 | QString getInterfaceFamily(bool &error); | 38 | QString getInterfaceFamily(bool &error); |
39 | bool setInterfaceFamily(QString newName); | 39 | bool setInterfaceFamily(const QString &newName); |
40 | QString getInterfaceMethod(bool &error); | 40 | QString getInterfaceMethod(bool &error); |
41 | bool setInterfaceMethod(QString newName); | 41 | bool setInterfaceMethod(const QString &newName); |
42 | QString getInterfaceOption(QString option, bool &error); | 42 | inline QString getInterfaceOption(const QString &option, bool &error); |
43 | bool setInterfaceOption(QString option, QString value); | 43 | inline bool setInterfaceOption(const QString &option, const QString &value); |
44 | bool removeInterfaceOption(QString option, QString value); | 44 | inline bool removeInterfaceOption(const QString &option, const QString &value); |
45 | bool removeAllInterfaceOptions(); | 45 | inline bool removeAllInterfaceOptions(); |
46 | 46 | ||
47 | bool setMapping(QString interface); | 47 | bool setMapping(const QString &interface); |
48 | bool removeMapping(); | 48 | bool removeMapping(); |
49 | void addMapping(QString options); | 49 | inline void addMapping(const QString &options); |
50 | bool setMap(QString map, QString value); | 50 | inline bool setMap(const QString &map, const QString &value); |
51 | bool removeMap(QString map, QString value); | 51 | inline bool removeMap(const QString &map, const QString &value); |
52 | QString getMap(QString map, bool &error); | 52 | inline QString getMap(const QString &map, bool &error); |
53 | bool setScript(QString); | 53 | inline bool setScript(const QString &argument); |
54 | QString getScript(bool &error); | 54 | inline QString getScript(bool &error); |
55 | 55 | ||
56 | bool write(); | 56 | bool write(); |
57 | 57 | ||
58 | private: | 58 | private: |
59 | bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator); | 59 | bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); |
60 | bool setOption(QStringList::Iterator start, QString option, QString value); | 60 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
61 | bool removeOption(QStringList::Iterator start, QString option, QString value); | 61 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
62 | QString getOption(QStringList::Iterator start, QString option, bool &error); | 62 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); |
63 | bool removeAllOptions(QStringList::Iterator start); | 63 | bool removeAllOptions(const QStringList::Iterator &start); |
64 | 64 | ||
65 | QString interfacesFile; | 65 | QString interfacesFile; |
66 | QStringList interfaces; | 66 | QStringList interfaces; |
67 | QStringList::Iterator currentIface; | 67 | QStringList::Iterator currentIface; |
68 | QStringList::Iterator currentMapping; | 68 | QStringList::Iterator currentMapping; |
69 | 69 | ||
70 | QStringList acceptedFamily; | 70 | QStringList acceptedFamily; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | // interfaces | 75 | // interfaces |
76 | 76 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfacesetup.ui b/noncore/settings/networksettings/interfaces/interfacesetup.ui index ab8e413..df55d25 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetup.ui +++ b/noncore/settings/networksettings/interfaces/interfacesetup.ui | |||
@@ -1,284 +1,310 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>InterfaceSetup</class> | 2 | <class>InterfaceSetup</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>InterfaceSetup</cstring> | 7 | <cstring>InterfaceSetup</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>290</width> | 14 | <width>290</width> |
15 | <height>280</height> | 15 | <height>280</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>caption</name> | 19 | <name>caption</name> |
20 | <string>Interface Configuration</string> | 20 | <string>Interface Configuration</string> |
21 | </property> | 21 | </property> |
22 | <vbox> | 22 | <vbox> |
23 | <property stdset="1"> | 23 | <property stdset="1"> |
24 | <name>margin</name> | 24 | <name>margin</name> |
25 | <number>11</number> | 25 | <number>11</number> |
26 | </property> | 26 | </property> |
27 | <property stdset="1"> | 27 | <property stdset="1"> |
28 | <name>spacing</name> | 28 | <name>spacing</name> |
29 | <number>6</number> | 29 | <number>6</number> |
30 | </property> | 30 | </property> |
31 | <widget> | 31 | <widget> |
32 | <class>QCheckBox</class> | 32 | <class>QCheckBox</class> |
33 | <property stdset="1"> | 33 | <property stdset="1"> |
34 | <name>name</name> | 34 | <name>name</name> |
35 | <cstring>autoStart</cstring> | 35 | <cstring>autoStart</cstring> |
36 | </property> | 36 | </property> |
37 | <property stdset="1"> | 37 | <property stdset="1"> |
38 | <name>text</name> | 38 | <name>text</name> |
39 | <string>Automatically bring up</string> | 39 | <string>Automatically bring up</string> |
40 | </property> | 40 | </property> |
41 | </widget> | 41 | </widget> |
42 | <widget> | 42 | <widget> |
43 | <class>QLayoutWidget</class> | 43 | <class>QLayoutWidget</class> |
44 | <property stdset="1"> | 44 | <property stdset="1"> |
45 | <name>name</name> | 45 | <name>name</name> |
46 | <cstring>Layout9</cstring> | 46 | <cstring>Layout9</cstring> |
47 | </property> | 47 | </property> |
48 | <hbox> | 48 | <hbox> |
49 | <property stdset="1"> | 49 | <property stdset="1"> |
50 | <name>margin</name> | 50 | <name>margin</name> |
51 | <number>0</number> | 51 | <number>0</number> |
52 | </property> | 52 | </property> |
53 | <property stdset="1"> | 53 | <property stdset="1"> |
54 | <name>spacing</name> | 54 | <name>spacing</name> |
55 | <number>6</number> | 55 | <number>6</number> |
56 | </property> | 56 | </property> |
57 | <widget> | 57 | <widget> |
58 | <class>QCheckBox</class> | 58 | <class>QCheckBox</class> |
59 | <property stdset="1"> | 59 | <property stdset="1"> |
60 | <name>name</name> | 60 | <name>name</name> |
61 | <cstring>dhcpCheckBox</cstring> | 61 | <cstring>dhcpCheckBox</cstring> |
62 | </property> | 62 | </property> |
63 | <property stdset="1"> | 63 | <property stdset="1"> |
64 | <name>text</name> | 64 | <name>text</name> |
65 | <string>DHCP</string> | 65 | <string>DHCP</string> |
66 | </property> | 66 | </property> |
67 | <property stdset="1"> | 67 | <property stdset="1"> |
68 | <name>checked</name> | 68 | <name>checked</name> |
69 | <bool>true</bool> | 69 | <bool>true</bool> |
70 | </property> | 70 | </property> |
71 | </widget> | 71 | </widget> |
72 | <widget> | 72 | <widget> |
73 | <class>QLabel</class> | 73 | <class>QLabel</class> |
74 | <property stdset="1"> | 74 | <property stdset="1"> |
75 | <name>name</name> | 75 | <name>name</name> |
76 | <cstring>leaseHoursLabel</cstring> | 76 | <cstring>leaseHoursLabel</cstring> |
77 | </property> | 77 | </property> |
78 | <property stdset="1"> | 78 | <property stdset="1"> |
79 | <name>text</name> | 79 | <name>text</name> |
80 | <string>Requested Lease</string> | 80 | <string>Requested Lease</string> |
81 | </property> | 81 | </property> |
82 | </widget> | 82 | </widget> |
83 | <widget> | 83 | <widget> |
84 | <class>QSpinBox</class> | 84 | <class>QSpinBox</class> |
85 | <property stdset="1"> | 85 | <property stdset="1"> |
86 | <name>name</name> | 86 | <name>name</name> |
87 | <cstring>leaseTime</cstring> | 87 | <cstring>leaseTime</cstring> |
88 | </property> | 88 | </property> |
89 | <property stdset="1"> | 89 | <property stdset="1"> |
90 | <name>suffix</name> | 90 | <name>suffix</name> |
91 | <string> hours</string> | 91 | <string> hours</string> |
92 | </property> | 92 | </property> |
93 | <property stdset="1"> | 93 | <property stdset="1"> |
94 | <name>maxValue</name> | 94 | <name>maxValue</name> |
95 | <number>87600</number> | 95 | <number>87600</number> |
96 | </property> | 96 | </property> |
97 | <property stdset="1"> | 97 | <property stdset="1"> |
98 | <name>minValue</name> | 98 | <name>minValue</name> |
99 | <number>1</number> | 99 | <number>1</number> |
100 | </property> | 100 | </property> |
101 | <property stdset="1"> | 101 | <property stdset="1"> |
102 | <name>lineStep</name> | ||
103 | <number>24</number> | ||
104 | </property> | ||
105 | <property stdset="1"> | ||
102 | <name>value</name> | 106 | <name>value</name> |
103 | <number>168</number> | 107 | <number>168</number> |
104 | </property> | 108 | </property> |
105 | </widget> | 109 | </widget> |
106 | </hbox> | 110 | </hbox> |
107 | </widget> | 111 | </widget> |
108 | <widget> | 112 | <widget> |
109 | <class>QGroupBox</class> | 113 | <class>QGroupBox</class> |
110 | <property stdset="1"> | 114 | <property stdset="1"> |
111 | <name>name</name> | 115 | <name>name</name> |
112 | <cstring>staticGroupBox</cstring> | 116 | <cstring>staticGroupBox</cstring> |
113 | </property> | 117 | </property> |
114 | <property stdset="1"> | 118 | <property stdset="1"> |
115 | <name>enabled</name> | 119 | <name>enabled</name> |
116 | <bool>false</bool> | 120 | <bool>false</bool> |
117 | </property> | 121 | </property> |
118 | <property stdset="1"> | 122 | <property stdset="1"> |
119 | <name>frameShape</name> | 123 | <name>frameShape</name> |
120 | <enum>Box</enum> | 124 | <enum>Box</enum> |
121 | </property> | 125 | </property> |
122 | <property stdset="1"> | 126 | <property stdset="1"> |
123 | <name>frameShadow</name> | 127 | <name>frameShadow</name> |
124 | <enum>Sunken</enum> | 128 | <enum>Sunken</enum> |
125 | </property> | 129 | </property> |
126 | <property stdset="1"> | 130 | <property stdset="1"> |
127 | <name>title</name> | 131 | <name>title</name> |
128 | <string>Static Ip Configuration</string> | 132 | <string>Static Ip Configuration</string> |
129 | </property> | 133 | </property> |
130 | <grid> | 134 | <grid> |
131 | <property stdset="1"> | 135 | <property stdset="1"> |
132 | <name>margin</name> | 136 | <name>margin</name> |
133 | <number>11</number> | 137 | <number>11</number> |
134 | </property> | 138 | </property> |
135 | <property stdset="1"> | 139 | <property stdset="1"> |
136 | <name>spacing</name> | 140 | <name>spacing</name> |
137 | <number>6</number> | 141 | <number>6</number> |
138 | </property> | 142 | </property> |
139 | <widget row="1" column="0" > | 143 | <widget row="1" column="0" > |
140 | <class>QLabel</class> | 144 | <class>QLabel</class> |
141 | <property stdset="1"> | 145 | <property stdset="1"> |
142 | <name>name</name> | 146 | <name>name</name> |
143 | <cstring>TextLabel5</cstring> | 147 | <cstring>TextLabel5</cstring> |
144 | </property> | 148 | </property> |
145 | <property stdset="1"> | 149 | <property stdset="1"> |
146 | <name>text</name> | 150 | <name>text</name> |
147 | <string>Subnet Mask</string> | 151 | <string>Subnet Mask</string> |
148 | </property> | 152 | </property> |
149 | </widget> | 153 | </widget> |
150 | <widget row="2" column="1" > | 154 | <widget row="2" column="1" > |
151 | <class>QLineEdit</class> | 155 | <class>QLineEdit</class> |
152 | <property stdset="1"> | 156 | <property stdset="1"> |
153 | <name>name</name> | 157 | <name>name</name> |
154 | <cstring>gatewayEdit</cstring> | 158 | <cstring>gatewayEdit</cstring> |
155 | </property> | 159 | </property> |
156 | </widget> | 160 | </widget> |
157 | <widget row="1" column="1" > | 161 | <widget row="1" column="1" > |
158 | <class>QLineEdit</class> | 162 | <class>QLineEdit</class> |
159 | <property stdset="1"> | 163 | <property stdset="1"> |
160 | <name>name</name> | 164 | <name>name</name> |
161 | <cstring>subnetMaskEdit</cstring> | 165 | <cstring>subnetMaskEdit</cstring> |
162 | </property> | 166 | </property> |
163 | </widget> | 167 | </widget> |
164 | <widget row="0" column="1" > | 168 | <widget row="0" column="1" > |
165 | <class>QLineEdit</class> | 169 | <class>QLineEdit</class> |
166 | <property stdset="1"> | 170 | <property stdset="1"> |
167 | <name>name</name> | 171 | <name>name</name> |
168 | <cstring>ipAddressEdit</cstring> | 172 | <cstring>ipAddressEdit</cstring> |
169 | </property> | 173 | </property> |
170 | </widget> | 174 | </widget> |
171 | <widget row="3" column="0" > | 175 | <widget row="3" column="0" > |
172 | <class>QLabel</class> | 176 | <class>QLabel</class> |
173 | <property stdset="1"> | 177 | <property stdset="1"> |
174 | <name>name</name> | 178 | <name>name</name> |
175 | <cstring>TextLabel2</cstring> | 179 | <cstring>TextLabel2</cstring> |
176 | </property> | 180 | </property> |
177 | <property stdset="1"> | 181 | <property stdset="1"> |
178 | <name>text</name> | 182 | <name>text</name> |
179 | <string>First DNS</string> | 183 | <string>First DNS</string> |
180 | </property> | 184 | </property> |
181 | </widget> | 185 | </widget> |
182 | <widget row="0" column="0" > | 186 | <widget row="0" column="0" > |
183 | <class>QLabel</class> | 187 | <class>QLabel</class> |
184 | <property stdset="1"> | 188 | <property stdset="1"> |
185 | <name>name</name> | 189 | <name>name</name> |
186 | <cstring>TextLabel4</cstring> | 190 | <cstring>TextLabel4</cstring> |
187 | </property> | 191 | </property> |
188 | <property stdset="1"> | 192 | <property stdset="1"> |
189 | <name>text</name> | 193 | <name>text</name> |
190 | <string>IP Address</string> | 194 | <string>IP Address</string> |
191 | </property> | 195 | </property> |
192 | </widget> | 196 | </widget> |
193 | <widget row="2" column="0" > | 197 | <widget row="2" column="0" > |
194 | <class>QLabel</class> | 198 | <class>QLabel</class> |
195 | <property stdset="1"> | 199 | <property stdset="1"> |
196 | <name>name</name> | 200 | <name>name</name> |
197 | <cstring>TextLabel1_2</cstring> | 201 | <cstring>TextLabel1_2</cstring> |
198 | </property> | 202 | </property> |
199 | <property stdset="1"> | 203 | <property stdset="1"> |
200 | <name>text</name> | 204 | <name>text</name> |
201 | <string>Gateway</string> | 205 | <string>Gateway</string> |
202 | </property> | 206 | </property> |
203 | </widget> | 207 | </widget> |
204 | <widget row="4" column="0" > | 208 | <widget row="4" column="0" > |
205 | <class>QLabel</class> | 209 | <class>QLabel</class> |
206 | <property stdset="1"> | 210 | <property stdset="1"> |
207 | <name>name</name> | 211 | <name>name</name> |
208 | <cstring>TextLabel3</cstring> | 212 | <cstring>TextLabel3</cstring> |
209 | </property> | 213 | </property> |
210 | <property stdset="1"> | 214 | <property stdset="1"> |
211 | <name>text</name> | 215 | <name>text</name> |
212 | <string>Second DNS</string> | 216 | <string>Second DNS</string> |
213 | </property> | 217 | </property> |
214 | </widget> | 218 | </widget> |
215 | <widget row="3" column="1" > | 219 | <widget row="3" column="1" > |
216 | <class>QLineEdit</class> | 220 | <class>QLineEdit</class> |
217 | <property stdset="1"> | 221 | <property stdset="1"> |
218 | <name>name</name> | 222 | <name>name</name> |
219 | <cstring>firstDNSLineEdit</cstring> | 223 | <cstring>firstDNSLineEdit</cstring> |
220 | </property> | 224 | </property> |
221 | </widget> | 225 | </widget> |
222 | <widget row="4" column="1" > | 226 | <widget row="4" column="1" > |
223 | <class>QLineEdit</class> | 227 | <class>QLineEdit</class> |
224 | <property stdset="1"> | 228 | <property stdset="1"> |
225 | <name>name</name> | 229 | <name>name</name> |
226 | <cstring>secondDNSLineEdit</cstring> | 230 | <cstring>secondDNSLineEdit</cstring> |
227 | </property> | 231 | </property> |
228 | </widget> | 232 | </widget> |
229 | </grid> | 233 | </grid> |
230 | </widget> | 234 | </widget> |
231 | <spacer> | 235 | <spacer> |
232 | <property> | 236 | <property> |
233 | <name>name</name> | 237 | <name>name</name> |
234 | <cstring>Spacer9</cstring> | 238 | <cstring>Spacer9</cstring> |
235 | </property> | 239 | </property> |
236 | <property stdset="1"> | 240 | <property stdset="1"> |
237 | <name>orientation</name> | 241 | <name>orientation</name> |
238 | <enum>Vertical</enum> | 242 | <enum>Vertical</enum> |
239 | </property> | 243 | </property> |
240 | <property stdset="1"> | 244 | <property stdset="1"> |
241 | <name>sizeType</name> | 245 | <name>sizeType</name> |
242 | <enum>Expanding</enum> | 246 | <enum>Expanding</enum> |
243 | </property> | 247 | </property> |
244 | <property> | 248 | <property> |
245 | <name>sizeHint</name> | 249 | <name>sizeHint</name> |
246 | <size> | 250 | <size> |
247 | <width>20</width> | 251 | <width>20</width> |
248 | <height>20</height> | 252 | <height>20</height> |
249 | </size> | 253 | </size> |
250 | </property> | 254 | </property> |
251 | </spacer> | 255 | </spacer> |
252 | </vbox> | 256 | </vbox> |
253 | </widget> | 257 | </widget> |
258 | <customwidgets> | ||
259 | <customwidget> | ||
260 | <class>QWidget</class> | ||
261 | <header location="local">qwidget.h</header> | ||
262 | <sizehint> | ||
263 | <width>100</width> | ||
264 | <height>100</height> | ||
265 | </sizehint> | ||
266 | <container>0</container> | ||
267 | <sizepolicy> | ||
268 | <hordata>7</hordata> | ||
269 | <verdata>7</verdata> | ||
270 | </sizepolicy> | ||
271 | <pixmap>image0</pixmap> | ||
272 | </customwidget> | ||
273 | </customwidgets> | ||
274 | <images> | ||
275 | <image> | ||
276 | <name>image0</name> | ||
277 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> | ||
278 | </image> | ||
279 | </images> | ||
254 | <connections> | 280 | <connections> |
255 | <connection> | 281 | <connection> |
256 | <sender>dhcpCheckBox</sender> | 282 | <sender>dhcpCheckBox</sender> |
257 | <signal>toggled(bool)</signal> | 283 | <signal>toggled(bool)</signal> |
258 | <receiver>leaseHoursLabel</receiver> | 284 | <receiver>leaseHoursLabel</receiver> |
259 | <slot>setEnabled(bool)</slot> | 285 | <slot>setEnabled(bool)</slot> |
260 | </connection> | 286 | </connection> |
261 | <connection> | 287 | <connection> |
262 | <sender>dhcpCheckBox</sender> | 288 | <sender>dhcpCheckBox</sender> |
263 | <signal>toggled(bool)</signal> | 289 | <signal>toggled(bool)</signal> |
264 | <receiver>leaseTime</receiver> | 290 | <receiver>leaseTime</receiver> |
265 | <slot>setEnabled(bool)</slot> | 291 | <slot>setEnabled(bool)</slot> |
266 | </connection> | 292 | </connection> |
267 | <connection> | 293 | <connection> |
268 | <sender>dhcpCheckBox</sender> | 294 | <sender>dhcpCheckBox</sender> |
269 | <signal>toggled(bool)</signal> | 295 | <signal>toggled(bool)</signal> |
270 | <receiver>staticGroupBox</receiver> | 296 | <receiver>staticGroupBox</receiver> |
271 | <slot>setDisabled(bool)</slot> | 297 | <slot>setDisabled(bool)</slot> |
272 | </connection> | 298 | </connection> |
273 | </connections> | 299 | </connections> |
274 | <tabstops> | 300 | <tabstops> |
275 | <tabstop>autoStart</tabstop> | 301 | <tabstop>autoStart</tabstop> |
276 | <tabstop>dhcpCheckBox</tabstop> | 302 | <tabstop>dhcpCheckBox</tabstop> |
277 | <tabstop>leaseTime</tabstop> | 303 | <tabstop>leaseTime</tabstop> |
278 | <tabstop>ipAddressEdit</tabstop> | 304 | <tabstop>ipAddressEdit</tabstop> |
279 | <tabstop>subnetMaskEdit</tabstop> | 305 | <tabstop>subnetMaskEdit</tabstop> |
280 | <tabstop>gatewayEdit</tabstop> | 306 | <tabstop>gatewayEdit</tabstop> |
281 | <tabstop>firstDNSLineEdit</tabstop> | 307 | <tabstop>firstDNSLineEdit</tabstop> |
282 | <tabstop>secondDNSLineEdit</tabstop> | 308 | <tabstop>secondDNSLineEdit</tabstop> |
283 | </tabstops> | 309 | </tabstops> |
284 | </UI> | 310 | </UI> |
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.h b/noncore/settings/networksettings/interfaces/interfacesetupimp.h index a88e190..60933aa 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.h +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.h | |||
@@ -1,56 +1,55 @@ | |||
1 | #ifndef INTERFACESETUPIMP_H | 1 | #ifndef INTERFACESETUPIMP_H |
2 | #define INTERFACESETUPIMP_H | 2 | #define INTERFACESETUPIMP_H |
3 | 3 | ||
4 | #include "interfacesetup.h" | 4 | #include "interfacesetup.h" |
5 | #include <qdialog.h> | 5 | #include <qdialog.h> |
6 | 6 | ||
7 | class Interface; | 7 | class Interface; |
8 | class Interfaces; | 8 | class Interfaces; |
9 | 9 | ||
10 | class InterfaceSetupImp : public InterfaceSetup { | 10 | class InterfaceSetupImp : public InterfaceSetup { |
11 | Q_OBJECT | 11 | Q_OBJECT |
12 | 12 | ||
13 | public: | 13 | public: |
14 | InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0); | 14 | InterfaceSetupImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, WFlags fl = 0); |
15 | bool saveChanges(); | 15 | bool saveChanges(); |
16 | 16 | ||
17 | public slots: | 17 | public slots: |
18 | void setProfile(const QString &profile); | 18 | void setProfile(const QString &profile); |
19 | bool saveSettings(); | 19 | bool saveSettings(); |
20 | 20 | ||
21 | private: | 21 | private: |
22 | Interfaces *interfaces; | 22 | Interfaces *interfaces; |
23 | Interface *interface; | 23 | Interface *interface; |
24 | |||
25 | }; | 24 | }; |
26 | 25 | ||
27 | 26 | ||
28 | #include <qlayout.h> | 27 | #include <qlayout.h> |
29 | 28 | ||
30 | class InterfaceSetupImpDialog : public QDialog { | 29 | class InterfaceSetupImpDialog : public QDialog { |
31 | Q_OBJECT | 30 | Q_OBJECT |
32 | 31 | ||
33 | public: | 32 | public: |
34 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ | 33 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ |
35 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); | 34 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); |
36 | setCaption("Interface Setup"); | 35 | setCaption("Interface Setup"); |
37 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); | 36 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); |
38 | InterfaceSetupLayout->addWidget( interfaceSetup ); | 37 | InterfaceSetupLayout->addWidget( interfaceSetup ); |
39 | }; | 38 | }; |
40 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; | 39 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; |
41 | 40 | ||
42 | private: | 41 | private: |
43 | InterfaceSetupImp *interfaceSetup; | 42 | InterfaceSetupImp *interfaceSetup; |
44 | 43 | ||
45 | protected slots: | 44 | protected slots: |
46 | void accept(){ | 45 | void accept(){ |
47 | if(interfaceSetup->saveChanges()) | 46 | if(interfaceSetup->saveChanges()) |
48 | QDialog::accept(); | 47 | QDialog::accept(); |
49 | }; | 48 | }; |
50 | 49 | ||
51 | }; | 50 | }; |
52 | 51 | ||
53 | #endif | 52 | #endif |
54 | 53 | ||
55 | // interfacesetupimp.h | 54 | // interfacesetupimp.h |
56 | 55 | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 48ef9b3..7b93554 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,473 +1,473 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include "addconnectionimp.h" | 2 | #include "addconnectionimp.h" |
3 | #include "interfaceinformationimp.h" | 3 | #include "interfaceinformationimp.h" |
4 | #include "interfacesetupimp.h" | 4 | #include "interfacesetupimp.h" |
5 | #include "interfaces.h" | 5 | #include "interfaces.h" |
6 | #include "module.h" | 6 | #include "module.h" |
7 | 7 | ||
8 | #include <qpushbutton.h> | 8 | #include <qpushbutton.h> |
9 | #include <qlistbox.h> | 9 | #include <qlistbox.h> |
10 | #include <qlineedit.h> | 10 | #include <qlineedit.h> |
11 | #include <qlistview.h> | 11 | #include <qlistview.h> |
12 | #include <qheader.h> | 12 | #include <qheader.h> |
13 | #include <qlabel.h> | 13 | #include <qlabel.h> |
14 | 14 | ||
15 | #include <qmainwindow.h> | 15 | #include <qmainwindow.h> |
16 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
17 | 17 | ||
18 | #include <qpe/config.h> | 18 | #include <qpe/config.h> |
19 | #include <qpe/qlibrary.h> | 19 | #include <qpe/qlibrary.h> |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
22 | 22 | ||
23 | #include <qlist.h> | 23 | #include <qlist.h> |
24 | #include <qdir.h> | 24 | #include <qdir.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
27 | 27 | ||
28 | #include <net/if.h> | 28 | #include <net/if.h> |
29 | #include <sys/ioctl.h> | 29 | #include <sys/ioctl.h> |
30 | 30 | ||
31 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" | 31 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
32 | 32 | ||
33 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 33 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false), scheme(DEFAULT_SCHEME){ |
34 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 34 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
35 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 35 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
36 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 36 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
37 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 37 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
38 | 38 | ||
39 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 39 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
40 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 40 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
41 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 41 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
42 | 42 | ||
43 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 43 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
44 | // Load connections. | 44 | // Load connections. |
45 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); | 45 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); |
46 | getAllInterfaces(); | 46 | getAllInterfaces(); |
47 | 47 | ||
48 | Interfaces i; | 48 | Interfaces i; |
49 | QStringList list = i.getInterfaceList(); | 49 | QStringList list = i.getInterfaceList(); |
50 | QMap<QString, Interface*>::Iterator it; | 50 | QMap<QString, Interface*>::Iterator it; |
51 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 51 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
52 | bool found = false; | 52 | bool found = false; |
53 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 53 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
54 | if(it.key() == (*ni)) | 54 | if(it.key() == (*ni)) |
55 | found = true; | 55 | found = true; |
56 | } | 56 | } |
57 | if(!found){ | 57 | if(!found){ |
58 | if(!(*ni).contains("_")){ | 58 | if(!(*ni).contains("_")){ |
59 | Interface *i = new Interface(this, *ni, false); | 59 | Interface *i = new Interface(this, *ni, false); |
60 | i->setAttached(false); | 60 | i->setAttached(false); |
61 | i->setHardwareName("Disconnected"); | 61 | i->setHardwareName("Disconnected"); |
62 | interfaceNames.insert(i->getInterfaceName(), i); | 62 | interfaceNames.insert(i->getInterfaceName(), i); |
63 | updateInterface(i); | 63 | updateInterface(i); |
64 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 64 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | //getInterfaceList(); | 69 | //getInterfaceList(); |
70 | connectionList->header()->hide(); | 70 | connectionList->header()->hide(); |
71 | 71 | ||
72 | Config cfg("NetworkSetup"); | 72 | Config cfg("NetworkSetup"); |
73 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 73 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
74 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 74 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
75 | profilesList->insertItem((*it)); | 75 | profilesList->insertItem((*it)); |
76 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 76 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
77 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 77 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
78 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | 78 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); |
79 | 79 | ||
80 | QFile file(scheme); | 80 | QFile file(scheme); |
81 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 81 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
82 | QTextStream stream( &file ); // use a text stream | 82 | QTextStream stream( &file ); // use a text stream |
83 | while ( !stream.eof() ) { // until end of file... | 83 | while ( !stream.eof() ) { // until end of file... |
84 | QString line = stream.readLine(); // line of text excluding '\n' | 84 | QString line = stream.readLine(); // line of text excluding '\n' |
85 | if(line.contains("SCHEME")){ | 85 | if(line.contains("SCHEME")){ |
86 | line = line.mid(7, line.length()); | 86 | line = line.mid(7, line.length()); |
87 | currentProfileLabel->setText(line); | 87 | currentProfileLabel->setText(line); |
88 | break; | 88 | break; |
89 | } | 89 | } |
90 | } | 90 | } |
91 | file.close(); | 91 | file.close(); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Deconstructor. Save profiles. Delete loaded libraries. | 96 | * Deconstructor. Save profiles. Delete loaded libraries. |
97 | */ | 97 | */ |
98 | MainWindowImp::~MainWindowImp(){ | 98 | MainWindowImp::~MainWindowImp(){ |
99 | // Save profiles. | 99 | // Save profiles. |
100 | Config cfg("NetworkSetup"); | 100 | Config cfg("NetworkSetup"); |
101 | cfg.setGroup("General"); | 101 | cfg.setGroup("General"); |
102 | cfg.writeEntry("Profiles", profiles.join(" ")); | 102 | cfg.writeEntry("Profiles", profiles.join(" ")); |
103 | 103 | ||
104 | // Delete all interfaces that don't have owners. | 104 | // Delete all interfaces that don't have owners. |
105 | QMap<Interface*, QListViewItem*>::Iterator iIt; | 105 | QMap<Interface*, QListViewItem*>::Iterator iIt; |
106 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ | 106 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ |
107 | if(iIt.key()->getModuleOwner() == NULL) | 107 | if(iIt.key()->getModuleOwner() == NULL) |
108 | delete iIt.key(); | 108 | delete iIt.key(); |
109 | } | 109 | } |
110 | 110 | ||
111 | // Delete Modules and Libraries | 111 | // Delete Modules and Libraries |
112 | QMap<Module*, QLibrary*>::Iterator it; | 112 | QMap<Module*, QLibrary*>::Iterator it; |
113 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 113 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
114 | delete it.key(); | 114 | delete it.key(); |
115 | // I wonder why I can't delete the libraries | 115 | // I wonder why I can't delete the libraries |
116 | // What fucking shit this is. | 116 | // What fucking shit this is. |
117 | //delete it.data(); | 117 | //delete it.data(); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Query the kernel for all of the interfaces. | 122 | * Query the kernel for all of the interfaces. |
123 | */ | 123 | */ |
124 | void MainWindowImp::getAllInterfaces(){ | 124 | void MainWindowImp::getAllInterfaces(){ |
125 | int sockfd = socket(AF_INET, SOCK_DGRAM, 0); | 125 | int sockfd = socket(AF_INET, SOCK_DGRAM, 0); |
126 | if(sockfd == -1) | 126 | if(sockfd == -1) |
127 | return; | 127 | return; |
128 | 128 | ||
129 | char buf[8*1024]; | 129 | char buf[8*1024]; |
130 | struct ifconf ifc; | 130 | struct ifconf ifc; |
131 | ifc.ifc_len = sizeof(buf); | 131 | ifc.ifc_len = sizeof(buf); |
132 | ifc.ifc_req = (struct ifreq *) buf; | 132 | ifc.ifc_req = (struct ifreq *) buf; |
133 | int result=ioctl(sockfd, SIOCGIFCONF, &ifc); | 133 | int result=ioctl(sockfd, SIOCGIFCONF, &ifc); |
134 | 134 | ||
135 | for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ | 135 | for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ |
136 | struct ifreq *ifr =(struct ifreq *) ptr; | 136 | struct ifreq *ifr =(struct ifreq *) ptr; |
137 | int len = sizeof(struct sockaddr); | 137 | int len = sizeof(struct sockaddr); |
138 | #ifdef HAVE_SOCKADDR_SA_LEN | 138 | #ifdef HAVE_SOCKADDR_SA_LEN |
139 | if (ifr->ifr_addr.sa_len > len) | 139 | if (ifr->ifr_addr.sa_len > len) |
140 | len = ifr->ifr_addr.sa_len; /* length > 16 */ | 140 | len = ifr->ifr_addr.sa_len; /* length > 16 */ |
141 | #endif | 141 | #endif |
142 | ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ | 142 | ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ |
143 | 143 | ||
144 | int flags; | 144 | int flags; |
145 | struct sockaddr_in *sinptr; | 145 | struct sockaddr_in *sinptr; |
146 | Interface *i = NULL; | 146 | Interface *i = NULL; |
147 | switch (ifr->ifr_addr.sa_family){ | 147 | switch (ifr->ifr_addr.sa_family){ |
148 | case AF_INET: | 148 | case AF_INET: |
149 | sinptr = (struct sockaddr_in *) &ifr->ifr_addr; | 149 | sinptr = (struct sockaddr_in *) &ifr->ifr_addr; |
150 | flags=0; | 150 | flags=0; |
151 | 151 | ||
152 | struct ifreq ifcopy; | 152 | struct ifreq ifcopy; |
153 | ifcopy=*ifr; | 153 | ifcopy=*ifr; |
154 | result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); | 154 | result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); |
155 | flags=ifcopy.ifr_flags; | 155 | flags=ifcopy.ifr_flags; |
156 | i = new Interface(this, ifr->ifr_name, false); | 156 | i = new Interface(this, ifr->ifr_name, false); |
157 | i->setAttached(true); | 157 | i->setAttached(true); |
158 | if ((flags & IFF_UP) == IFF_UP) | 158 | if ((flags & IFF_UP) == IFF_UP) |
159 | i->setStatus(true); | 159 | i->setStatus(true); |
160 | else | 160 | else |
161 | i->setStatus(false); | 161 | i->setStatus(false); |
162 | 162 | ||
163 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) | 163 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) |
164 | i->setHardwareName("Ethernet"); | 164 | i->setHardwareName("Ethernet"); |
165 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) | 165 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) |
166 | i->setHardwareName("Point to Point"); | 166 | i->setHardwareName("Point to Point"); |
167 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) | 167 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) |
168 | i->setHardwareName("Multicast"); | 168 | i->setHardwareName("Multicast"); |
169 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) | 169 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) |
170 | i->setHardwareName("Loopback"); | 170 | i->setHardwareName("Loopback"); |
171 | else | 171 | else |
172 | i->setHardwareName("Unknown"); | 172 | i->setHardwareName("Unknown"); |
173 | 173 | ||
174 | interfaceNames.insert(i->getInterfaceName(), i); | 174 | interfaceNames.insert(i->getInterfaceName(), i); |
175 | updateInterface(i); | 175 | updateInterface(i); |
176 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 176 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
177 | break; | 177 | break; |
178 | 178 | ||
179 | default: | 179 | default: |
180 | qDebug(ifr->ifr_name); | 180 | qDebug(ifr->ifr_name); |
181 | qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); | 181 | qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); |
182 | break; | 182 | break; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Load all modules that are found in the path | 188 | * Load all modules that are found in the path |
189 | * @param path a directory that is scaned for any plugins that can be loaded | 189 | * @param path a directory that is scaned for any plugins that can be loaded |
190 | * and attempts to load them | 190 | * and attempts to load them |
191 | */ | 191 | */ |
192 | void MainWindowImp::loadModules(QString path){ | 192 | void MainWindowImp::loadModules(const QString &path){ |
193 | //qDebug(path.latin1()); | 193 | //qDebug(path.latin1()); |
194 | QDir d(path); | 194 | QDir d(path); |
195 | if(!d.exists()) | 195 | if(!d.exists()) |
196 | return; | 196 | return; |
197 | 197 | ||
198 | // Don't want sym links | 198 | // Don't want sym links |
199 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 199 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
200 | const QFileInfoList *list = d.entryInfoList(); | 200 | const QFileInfoList *list = d.entryInfoList(); |
201 | QFileInfoListIterator it( *list ); | 201 | QFileInfoListIterator it( *list ); |
202 | QFileInfo *fi; | 202 | QFileInfo *fi; |
203 | while ( (fi=it.current()) ) { | 203 | while ( (fi=it.current()) ) { |
204 | if(fi->fileName().contains(".so")){ | 204 | if(fi->fileName().contains(".so")){ |
205 | loadPlugin(path + "/" + fi->fileName()); | 205 | loadPlugin(path + "/" + fi->fileName()); |
206 | } | 206 | } |
207 | ++it; | 207 | ++it; |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * Attempt to load a function and resolve a function. | 212 | * Attempt to load a function and resolve a function. |
213 | * @param pluginFileName - the name of the file in which to attempt to load | 213 | * @param pluginFileName - the name of the file in which to attempt to load |
214 | * @param resolveString - function pointer to resolve | 214 | * @param resolveString - function pointer to resolve |
215 | * @return pointer to the function with name resolveString or NULL | 215 | * @return pointer to the function with name resolveString or NULL |
216 | */ | 216 | */ |
217 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 217 | Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ |
218 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 218 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
219 | QLibrary *lib = new QLibrary(pluginFileName); | 219 | QLibrary *lib = new QLibrary(pluginFileName); |
220 | void *functionPointer = lib->resolve(resolveString); | 220 | void *functionPointer = lib->resolve(resolveString); |
221 | if( !functionPointer ){ | 221 | if( !functionPointer ){ |
222 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 222 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
223 | delete lib; | 223 | delete lib; |
224 | return NULL; | 224 | return NULL; |
225 | } | 225 | } |
226 | 226 | ||
227 | // Try to get an object. | 227 | // Try to get an object. |
228 | Module *object = ((Module* (*)()) functionPointer)(); | 228 | Module *object = ((Module* (*)()) functionPointer)(); |
229 | if(object == NULL){ | 229 | if(object == NULL){ |
230 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 230 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
231 | delete lib; | 231 | delete lib; |
232 | return NULL; | 232 | return NULL; |
233 | } | 233 | } |
234 | 234 | ||
235 | // Store for deletion later | 235 | // Store for deletion later |
236 | libraries.insert(object, lib); | 236 | libraries.insert(object, lib); |
237 | return object; | 237 | return object; |
238 | } | 238 | } |
239 | 239 | ||
240 | /** | 240 | /** |
241 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 241 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
242 | * load the plugin and append it to the list | 242 | * load the plugin and append it to the list |
243 | */ | 243 | */ |
244 | void MainWindowImp::addClicked(){ | 244 | void MainWindowImp::addClicked(){ |
245 | QMap<Module*, QLibrary*>::Iterator it; | 245 | QMap<Module*, QLibrary*>::Iterator it; |
246 | QMap<QString, QString> list; | 246 | QMap<QString, QString> list; |
247 | QMap<QString, Module*> newInterfaceOwners; | 247 | QMap<QString, Module*> newInterfaceOwners; |
248 | //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 248 | //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); |
249 | //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); | 249 | //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
250 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 250 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
251 | if(it.key()){ | 251 | if(it.key()){ |
252 | (it.key())->possibleNewInterfaces(list); | 252 | (it.key())->possibleNewInterfaces(list); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | // See if the list has anything that we can add. | 255 | // See if the list has anything that we can add. |
256 | if(list.count() == 0){ | 256 | if(list.count() == 0){ |
257 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); | 257 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); |
258 | return; | 258 | return; |
259 | } | 259 | } |
260 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 260 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
261 | addNewConnection.addConnections(list); | 261 | addNewConnection.addConnections(list); |
262 | addNewConnection.showMaximized(); | 262 | addNewConnection.showMaximized(); |
263 | if(QDialog::Accepted == addNewConnection.exec()){ | 263 | if(QDialog::Accepted == addNewConnection.exec()){ |
264 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 264 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
265 | if(!item) | 265 | if(!item) |
266 | return; | 266 | return; |
267 | 267 | ||
268 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 268 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
269 | if(it.key()){ | 269 | if(it.key()){ |
270 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 270 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
271 | if(i){ | 271 | if(i){ |
272 | interfaceNames.insert(i->getInterfaceName(), i); | 272 | interfaceNames.insert(i->getInterfaceName(), i); |
273 | updateInterface(i); | 273 | updateInterface(i); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | /** | 280 | /** |
281 | * Prompt the user to see if they really want to do this. | 281 | * Prompt the user to see if they really want to do this. |
282 | * If they do then remove from the list and unload. | 282 | * If they do then remove from the list and unload. |
283 | */ | 283 | */ |
284 | void MainWindowImp::removeClicked(){ | 284 | void MainWindowImp::removeClicked(){ |
285 | QListViewItem *item = connectionList->currentItem(); | 285 | QListViewItem *item = connectionList->currentItem(); |
286 | if(!item) { | 286 | if(!item) { |
287 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 287 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
288 | return; | 288 | return; |
289 | } | 289 | } |
290 | 290 | ||
291 | Interface *i = interfaceItems[item]; | 291 | Interface *i = interfaceItems[item]; |
292 | if(i->getModuleOwner() == NULL){ | 292 | if(i->getModuleOwner() == NULL){ |
293 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); | 293 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); |
294 | } | 294 | } |
295 | else{ | 295 | else{ |
296 | if(!i->getModuleOwner()->remove(i)) | 296 | if(!i->getModuleOwner()->remove(i)) |
297 | QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); | 297 | QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); |
298 | else{ | 298 | else{ |
299 | QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); | 299 | QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); |
300 | // TODO memory managment.... | 300 | // TODO memory managment.... |
301 | // who deletes the interface? | 301 | // who deletes the interface? |
302 | } | 302 | } |
303 | } | 303 | } |
304 | } | 304 | } |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * Pull up the configure about the currently selected interface. | 307 | * Pull up the configure about the currently selected interface. |
308 | * Report an error if no interface is selected. | 308 | * Report an error if no interface is selected. |
309 | * If the interface has a module owner then request its configure. | 309 | * If the interface has a module owner then request its configure. |
310 | */ | 310 | */ |
311 | void MainWindowImp::configureClicked(){ | 311 | void MainWindowImp::configureClicked(){ |
312 | QListViewItem *item = connectionList->currentItem(); | 312 | QListViewItem *item = connectionList->currentItem(); |
313 | if(!item){ | 313 | if(!item){ |
314 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); | 314 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); |
315 | return; | 315 | return; |
316 | } | 316 | } |
317 | 317 | ||
318 | Interface *i = interfaceItems[item]; | 318 | Interface *i = interfaceItems[item]; |
319 | if(i->getModuleOwner()){ | 319 | if(i->getModuleOwner()){ |
320 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); | 320 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); |
321 | if(moduleConfigure != NULL){ | 321 | if(moduleConfigure != NULL){ |
322 | moduleConfigure->showMaximized(); | 322 | moduleConfigure->showMaximized(); |
323 | moduleConfigure->show(); | 323 | moduleConfigure->show(); |
324 | return; | 324 | return; |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); | 328 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); |
329 | QString currentProfileText = currentProfileLabel->text(); | 329 | QString currentProfileText = currentProfileLabel->text(); |
330 | if(currentProfileText.upper() == "ALL"); | 330 | if(currentProfileText.upper() == "ALL"); |
331 | currentProfileText = ""; | 331 | currentProfileText = ""; |
332 | configure->setProfile(currentProfileText); | 332 | configure->setProfile(currentProfileText); |
333 | configure->showMaximized(); | 333 | configure->showMaximized(); |
334 | configure->show(); | 334 | configure->show(); |
335 | } | 335 | } |
336 | 336 | ||
337 | /** | 337 | /** |
338 | * Pull up the information about the currently selected interface. | 338 | * Pull up the information about the currently selected interface. |
339 | * Report an error if no interface is selected. | 339 | * Report an error if no interface is selected. |
340 | * If the interface has a module owner then request its configure. | 340 | * If the interface has a module owner then request its configure. |
341 | */ | 341 | */ |
342 | void MainWindowImp::informationClicked(){ | 342 | void MainWindowImp::informationClicked(){ |
343 | QListViewItem *item = connectionList->currentItem(); | 343 | QListViewItem *item = connectionList->currentItem(); |
344 | if(!item){ | 344 | if(!item){ |
345 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 345 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
346 | return; | 346 | return; |
347 | } | 347 | } |
348 | 348 | ||
349 | Interface *i = interfaceItems[item]; | 349 | Interface *i = interfaceItems[item]; |
350 | if(!i->isAttached()){ | 350 | if(!i->isAttached()){ |
351 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); | 351 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
352 | return; | 352 | return; |
353 | } | 353 | } |
354 | 354 | ||
355 | if(i->getModuleOwner()){ | 355 | if(i->getModuleOwner()){ |
356 | QWidget *moduleInformation = i->getModuleOwner()->information(i); | 356 | QWidget *moduleInformation = i->getModuleOwner()->information(i); |
357 | if(moduleInformation != NULL){ | 357 | if(moduleInformation != NULL){ |
358 | moduleInformation->showMaximized(); | 358 | moduleInformation->showMaximized(); |
359 | moduleInformation->show(); | 359 | moduleInformation->show(); |
360 | return; | 360 | return; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 363 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
364 | information->showMaximized(); | 364 | information->showMaximized(); |
365 | information->show(); | 365 | information->show(); |
366 | } | 366 | } |
367 | 367 | ||
368 | /** | 368 | /** |
369 | * Update this interface. If no QListViewItem exists create one. | 369 | * Update this interface. If no QListViewItem exists create one. |
370 | * @param Interface* pointer to the interface that needs to be updated. | 370 | * @param Interface* pointer to the interface that needs to be updated. |
371 | */ | 371 | */ |
372 | void MainWindowImp::updateInterface(Interface *i){ | 372 | void MainWindowImp::updateInterface(Interface *i){ |
373 | if(!advancedUserMode){ | 373 | if(!advancedUserMode){ |
374 | if(i->getInterfaceName() == "lo") | 374 | if(i->getInterfaceName() == "lo") |
375 | return; | 375 | return; |
376 | } | 376 | } |
377 | 377 | ||
378 | QListViewItem *item = NULL; | 378 | QListViewItem *item = NULL; |
379 | 379 | ||
380 | // Find the interface, making it if needed. | 380 | // Find the interface, making it if needed. |
381 | if(items.find(i) == items.end()){ | 381 | if(items.find(i) == items.end()){ |
382 | item = new QListViewItem(connectionList, "", "", ""); | 382 | item = new QListViewItem(connectionList, "", "", ""); |
383 | // See if you can't find a module owner for this interface | 383 | // See if you can't find a module owner for this interface |
384 | QMap<Module*, QLibrary*>::Iterator it; | 384 | QMap<Module*, QLibrary*>::Iterator it; |
385 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 385 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
386 | if(it.key()->isOwner(i)) | 386 | if(it.key()->isOwner(i)) |
387 | i->setModuleOwner(it.key()); | 387 | i->setModuleOwner(it.key()); |
388 | } | 388 | } |
389 | items.insert(i, item); | 389 | items.insert(i, item); |
390 | interfaceItems.insert(item, i); | 390 | interfaceItems.insert(item, i); |
391 | } | 391 | } |
392 | else | 392 | else |
393 | item = items[i]; | 393 | item = items[i]; |
394 | 394 | ||
395 | // Update the icons and information | 395 | // Update the icons and information |
396 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 396 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
397 | 397 | ||
398 | QString typeName = "lan"; | 398 | QString typeName = "lan"; |
399 | if(i->getHardwareName().contains("Local Loopback")) | 399 | if(i->getHardwareName().contains("Local Loopback")) |
400 | typeName = "lo"; | 400 | typeName = "lo"; |
401 | if(i->getInterfaceName().contains("irda")) | 401 | if(i->getInterfaceName().contains("irda")) |
402 | typeName = "irda"; | 402 | typeName = "irda"; |
403 | if(i->getInterfaceName().contains("wlan")) | 403 | if(i->getInterfaceName().contains("wlan")) |
404 | typeName = "wlan"; | 404 | typeName = "wlan"; |
405 | if(i->getInterfaceName().contains("usb")) | 405 | if(i->getInterfaceName().contains("usb")) |
406 | typeName = "usb"; | 406 | typeName = "usb"; |
407 | 407 | ||
408 | if(!i->isAttached()) | 408 | if(!i->isAttached()) |
409 | typeName = "connect_no"; | 409 | typeName = "connect_no"; |
410 | // Actually try to use the Module | 410 | // Actually try to use the Module |
411 | if(i->getModuleOwner() != NULL) | 411 | if(i->getModuleOwner() != NULL) |
412 | typeName = i->getModuleOwner()->getPixmapName(i); | 412 | typeName = i->getModuleOwner()->getPixmapName(i); |
413 | 413 | ||
414 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 414 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
415 | item->setText(2, i->getHardwareName()); | 415 | item->setText(2, i->getHardwareName()); |
416 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 416 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
417 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 417 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
418 | } | 418 | } |
419 | 419 | ||
420 | void MainWindowImp::newProfileChanged(const QString& newText){ | 420 | void MainWindowImp::newProfileChanged(const QString& newText){ |
421 | if(newText.length() > 0) | 421 | if(newText.length() > 0) |
422 | newProfileButton->setEnabled(true); | 422 | newProfileButton->setEnabled(true); |
423 | else | 423 | else |
424 | newProfileButton->setEnabled(false); | 424 | newProfileButton->setEnabled(false); |
425 | } | 425 | } |
426 | 426 | ||
427 | /** | 427 | /** |
428 | * Adds a new profile to the list of profiles. | 428 | * Adds a new profile to the list of profiles. |
429 | * Don't add profiles that already exists. | 429 | * Don't add profiles that already exists. |
430 | * Appends to the list and QStringList | 430 | * Appends to the list and QStringList |
431 | */ | 431 | */ |
432 | void MainWindowImp::addProfile(){ | 432 | void MainWindowImp::addProfile(){ |
433 | QString newProfileName = newProfile->text(); | 433 | QString newProfileName = newProfile->text(); |
434 | if(profiles.grep(newProfileName).count() > 0){ | 434 | if(profiles.grep(newProfileName).count() > 0){ |
435 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); | 435 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); |
436 | return; | 436 | return; |
437 | } | 437 | } |
438 | profiles.append(newProfileName); | 438 | profiles.append(newProfileName); |
439 | profilesList->insertItem(newProfileName); | 439 | profilesList->insertItem(newProfileName); |
440 | } | 440 | } |
441 | 441 | ||
442 | /** | 442 | /** |
443 | * Removes the currently selected profile in the combo. | 443 | * Removes the currently selected profile in the combo. |
444 | * Doesn't delete if there are less then 2 profiles. | 444 | * Doesn't delete if there are less then 2 profiles. |
445 | */ | 445 | */ |
446 | void MainWindowImp::removeProfile(){ | 446 | void MainWindowImp::removeProfile(){ |
447 | if(profilesList->count() <= 1){ | 447 | if(profilesList->count() <= 1){ |
448 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); | 448 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); |
449 | return; | 449 | return; |
450 | } | 450 | } |
451 | QString profileToRemove = profilesList->currentText(); | 451 | QString profileToRemove = profilesList->currentText(); |
452 | if(profileToRemove == "All"){ | 452 | if(profileToRemove == "All"){ |
453 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); | 453 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); |
454 | return; | 454 | return; |
455 | } | 455 | } |
456 | // Can't remove the curent profile | 456 | // Can't remove the curent profile |
457 | if(profileToRemove == currentProfileLabel->text()){ | 457 | if(profileToRemove == currentProfileLabel->text()){ |
458 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); | 458 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); |
459 | return; | 459 | return; |
460 | 460 | ||
461 | } | 461 | } |
462 | 462 | ||
463 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 463 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
464 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 464 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
465 | profilesList->clear(); | 465 | profilesList->clear(); |
466 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 466 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
467 | profilesList->insertItem((*it)); | 467 | profilesList->insertItem((*it)); |
468 | 468 | ||
469 | // Remove any interface settings and mappings. | 469 | // Remove any interface settings and mappings. |
470 | Interfaces interfaces; | 470 | Interfaces interfaces; |
471 | // Go through them one by one | 471 | // Go through them one by one |
472 | QMap<Interface*, QListViewItem*>::Iterator it; | 472 | QMap<Interface*, QListViewItem*>::Iterator it; |
473 | for( it = items.begin(); it != items.end(); ++it ){ | 473 | for( it = items.begin(); it != items.end(); ++it ){ |
diff --git a/noncore/settings/networksettings/mainwindowimp.h b/noncore/settings/networksettings/mainwindowimp.h index 382428c..4f09d6c 100644 --- a/noncore/settings/networksettings/mainwindowimp.h +++ b/noncore/settings/networksettings/mainwindowimp.h | |||
@@ -1,58 +1,58 @@ | |||
1 | #ifndef MAINWINOWIMP_H | 1 | #ifndef MAINWINOWIMP_H |
2 | #define MAINWINOWIMP_H | 2 | #define MAINWINOWIMP_H |
3 | 3 | ||
4 | #include "mainwindow.h" | 4 | #include "mainwindow.h" |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | class Module; | 8 | class Module; |
9 | class Interface; | 9 | class Interface; |
10 | class QLibrary; | 10 | class QLibrary; |
11 | class KProcess; | 11 | class KProcess; |
12 | 12 | ||
13 | class MainWindowImp : public MainWindow { | 13 | class MainWindowImp : public MainWindow { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | MainWindowImp(QWidget *parent=0, const char *name=0); | 17 | MainWindowImp(QWidget *parent=0, const char *name=0); |
18 | ~MainWindowImp(); | 18 | ~MainWindowImp(); |
19 | 19 | ||
20 | private slots: | 20 | private slots: |
21 | void getAllInterfaces(); | 21 | void getAllInterfaces(); |
22 | 22 | ||
23 | void addClicked(); | 23 | void addClicked(); |
24 | void removeClicked(); | 24 | void removeClicked(); |
25 | void configureClicked(); | 25 | void configureClicked(); |
26 | void informationClicked(); | 26 | void informationClicked(); |
27 | 27 | ||
28 | void addProfile(); | 28 | void addProfile(); |
29 | void removeProfile(); | 29 | void removeProfile(); |
30 | void changeProfile(); | 30 | void changeProfile(); |
31 | 31 | ||
32 | void updateInterface(Interface *i); | 32 | void updateInterface(Interface *i); |
33 | void newProfileChanged(const QString& newText); | 33 | void newProfileChanged(const QString& newText); |
34 | 34 | ||
35 | private: | 35 | private: |
36 | void loadModules(QString path); | 36 | void loadModules(const QString &path); |
37 | 37 | ||
38 | Module* loadPlugin(QString pluginFileName, | 38 | Module* loadPlugin(const QString &pluginFileName, |
39 | QString resolveString = "create_plugin"); | 39 | const QString &resolveString = "create_plugin"); |
40 | 40 | ||
41 | // For our local list of names | 41 | // For our local list of names |
42 | QMap<QString, Interface*> interfaceNames; | 42 | QMap<QString, Interface*> interfaceNames; |
43 | 43 | ||
44 | QMap<Module*, QLibrary*> libraries; | 44 | QMap<Module*, QLibrary*> libraries; |
45 | QMap<Interface*, QListViewItem*> items; | 45 | QMap<Interface*, QListViewItem*> items; |
46 | QMap<QListViewItem*, Interface*> interfaceItems; | 46 | QMap<QListViewItem*, Interface*> interfaceItems; |
47 | 47 | ||
48 | QMap<KProcess*, QString> threads; | 48 | QMap<KProcess*, QString> threads; |
49 | QStringList profiles; | 49 | QStringList profiles; |
50 | 50 | ||
51 | bool advancedUserMode; | 51 | bool advancedUserMode; |
52 | QString scheme; | 52 | QString scheme; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | // mainwindowimp.h | 57 | // mainwindowimp.h |
58 | 58 | ||
diff --git a/noncore/settings/networksettings/module.h b/noncore/settings/networksettings/module.h index 92b125a..2e6272b 100644 --- a/noncore/settings/networksettings/module.h +++ b/noncore/settings/networksettings/module.h | |||
@@ -1,86 +1,86 @@ | |||
1 | #ifndef NETCONF_MODULE_H | 1 | #ifndef NETCONF_MODULE_H |
2 | #define NETCONF_MODULE_H | 2 | #define NETCONF_MODULE_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qlist.h> | 5 | #include <qlist.h> |
6 | #include <qmap.h> | 6 | #include <qmap.h> |
7 | #include "interface.h" | 7 | #include "interface.h" |
8 | 8 | ||
9 | class QWidget; | 9 | class QWidget; |
10 | class QTabWidget; | 10 | class QTabWidget; |
11 | 11 | ||
12 | class Module : QObject{ | 12 | class Module : QObject{ |
13 | 13 | ||
14 | signals: | 14 | signals: |
15 | void updateInterface(Interface *i); | 15 | void updateInterface(Interface *i); |
16 | 16 | ||
17 | public: | 17 | public: |
18 | Module(){}; | 18 | Module(){}; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * The current profile has been changed and the module should do any | 21 | * The current profile has been changed and the module should do any |
22 | * neccesary changes also. | 22 | * neccesary changes also. |
23 | * @param newProfile what the profile should be changed to. | 23 | * @param newProfile what the profile should be changed to. |
24 | */ | 24 | */ |
25 | virtual void setProfile(QString newProfile) = 0; | 25 | virtual void setProfile(const QString &newProfile) = 0; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * get the icon name for this device. | 28 | * get the icon name for this device. |
29 | * @param Interface* can be used in determining the icon. | 29 | * @param Interface* can be used in determining the icon. |
30 | * @return QString the icon name (minus .png, .gif etc) | 30 | * @return QString the icon name (minus .png, .gif etc) |
31 | */ | 31 | */ |
32 | virtual QString getPixmapName(Interface *) = 0; | 32 | virtual QString getPixmapName(Interface *) = 0; |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Check to see if the interface i is owned by this module. | 35 | * Check to see if the interface i is owned by this module. |
36 | * @param Interface* interface to check against | 36 | * @param Interface* interface to check against |
37 | * @return bool true if i is owned by this module, false otherwise. | 37 | * @return bool true if i is owned by this module, false otherwise. |
38 | */ | 38 | */ |
39 | virtual bool isOwner(Interface *){ return false; }; | 39 | virtual bool isOwner(Interface *){ return false; }; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Create and return the WLANConfigure Module | 42 | * Create and return the WLANConfigure Module |
43 | * @param Interface *i the interface to configure. | 43 | * @param Interface *i the interface to configure. |
44 | * @return QWidget* pointer to this modules configure. | 44 | * @return QWidget* pointer to this modules configure. |
45 | */ | 45 | */ |
46 | virtual QWidget *configure(Interface *){ return NULL; } ; | 46 | virtual QWidget *configure(Interface *){ return NULL; } ; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Create, and return the Information Module | 49 | * Create, and return the Information Module |
50 | * @param Interface *i the interface to get info on. | 50 | * @param Interface *i the interface to get info on. |
51 | * @return QWidget* pointer to this modules info. | 51 | * @return QWidget* pointer to this modules info. |
52 | */ | 52 | */ |
53 | virtual QWidget *information(Interface *){ return NULL; }; | 53 | virtual QWidget *information(Interface *){ return NULL; }; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Get all active (up or down) interfaces | 56 | * Get all active (up or down) interfaces |
57 | * @return QList<Interface> A list of interfaces that exsist that havn't | 57 | * @return QList<Interface> A list of interfaces that exsist that havn't |
58 | * been called by isOwner() | 58 | * been called by isOwner() |
59 | */ | 59 | */ |
60 | virtual QList<Interface> getInterfaces() = 0; | 60 | virtual QList<Interface> getInterfaces() = 0; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp), | 63 | * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp), |
64 | * modem ppp) | 64 | * modem ppp) |
65 | */ | 65 | */ |
66 | virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0; | 66 | virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Attempts to create a new interface from name | 69 | * Attempts to create a new interface from name |
70 | * @return Interface* NULL if it was unable to be created. | 70 | * @return Interface* NULL if it was unable to be created. |
71 | * @param name the type of interface to create | 71 | * @param name the type of interface to create |
72 | */ | 72 | */ |
73 | virtual Interface *addNewInterface(QString name) = 0; | 73 | virtual Interface *addNewInterface(const QString &name) = 0; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Attempts to remove the interface, doesn't delete i | 76 | * Attempts to remove the interface, doesn't delete i |
77 | * @return bool true if successfull, false otherwise. | 77 | * @return bool true if successfull, false otherwise. |
78 | */ | 78 | */ |
79 | virtual bool remove(Interface* i) = 0; | 79 | virtual bool remove(Interface* i) = 0; |
80 | 80 | ||
81 | }; | 81 | }; |
82 | 82 | ||
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | // module.h | 85 | // module.h |
86 | 86 | ||
diff --git a/noncore/settings/networksettings/wlan/infoimp.h b/noncore/settings/networksettings/wlan/infoimp.h index 5311bea..8f7f0d6 100644 --- a/noncore/settings/networksettings/wlan/infoimp.h +++ b/noncore/settings/networksettings/wlan/infoimp.h | |||
@@ -1,27 +1,27 @@ | |||
1 | #ifndef INFOIMP_H | 1 | #ifndef INFOIMP_H |
2 | #define INFOIMP_H | 2 | #define INFOIMP_H |
3 | 3 | ||
4 | #include "info.h" | 4 | #include "info.h" |
5 | 5 | ||
6 | class QTimer; | 6 | class QTimer; |
7 | class WExtensions; | 7 | //class WExtensions; |
8 | 8 | ||
9 | class WlanInfoImp : public WlanInfo { | 9 | class WlanInfoImp : public WlanInfo { |
10 | Q_OBJECT | 10 | Q_OBJECT |
11 | 11 | ||
12 | public: | 12 | public: |
13 | WlanInfoImp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 13 | WlanInfoImp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
14 | 14 | ||
15 | private slots: | 15 | private slots: |
16 | void update(); | 16 | void update(); |
17 | 17 | ||
18 | private: | 18 | private: |
19 | //WExtensions *wExtensions; | 19 | //WExtensions *wExtensions; |
20 | QTimer *timer; | 20 | QTimer *timer; |
21 | 21 | ||
22 | }; | 22 | }; |
23 | 23 | ||
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | // infoimp.h | 26 | // infoimp.h |
27 | 27 | ||
diff --git a/noncore/settings/networksettings/wlan/wextensions.cpp b/noncore/settings/networksettings/wlan/wextensions.cpp index eb6fc42..6335ebc 100644 --- a/noncore/settings/networksettings/wlan/wextensions.cpp +++ b/noncore/settings/networksettings/wlan/wextensions.cpp | |||
@@ -1,175 +1,174 @@ | |||
1 | #include "wextensions.h" | 1 | #include "wextensions.h" |
2 | 2 | ||
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | 5 | ||
6 | #include <arpa/inet.h> | 6 | #include <arpa/inet.h> |
7 | #include <sys/socket.h> | 7 | #include <sys/socket.h> |
8 | #include <sys/ioctl.h> | 8 | #include <sys/ioctl.h> |
9 | 9 | ||
10 | #include <math.h> | 10 | #include <math.h> |
11 | 11 | ||
12 | #define PROCNETWIRELESS "/proc/net/wireless" | 12 | #define PROCNETWIRELESS "/proc/net/wireless" |
13 | #define IW_LOWER 0 | 13 | #define IW_LOWER 0 |
14 | #define IW_UPPER 256 | 14 | #define IW_UPPER 256 |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * Constructor. Sets hasWirelessExtensions | 17 | * Constructor. Sets hasWirelessExtensions |
18 | */ | 18 | */ |
19 | WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false){ | 19 | WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false), interface(interfaceName) { |
20 | interface = interfaceName; | ||
21 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); | 20 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); |
22 | if(fd == -1) | 21 | if(fd == -1) |
23 | return; | 22 | return; |
24 | 23 | ||
25 | const char* buffer[200]; | 24 | const char* buffer[200]; |
26 | memset( &iwr, 0, sizeof( iwr ) ); | 25 | memset( &iwr, 0, sizeof( iwr ) ); |
27 | iwr.u.essid.pointer = (caddr_t) buffer; | 26 | iwr.u.essid.pointer = (caddr_t) buffer; |
28 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 27 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
29 | iwr.u.essid.flags = 0; | 28 | iwr.u.essid.flags = 0; |
30 | 29 | ||
31 | // check if it is an IEEE 802.11 standard conform | 30 | // check if it is an IEEE 802.11 standard conform |
32 | // wireless device by sending SIOCGIWESSID | 31 | // wireless device by sending SIOCGIWESSID |
33 | // which also gives back the Extended Service Set ID | 32 | // which also gives back the Extended Service Set ID |
34 | // (see IEEE 802.11 for more information) | 33 | // (see IEEE 802.11 for more information) |
35 | 34 | ||
36 | const char* iname = interface.latin1(); | 35 | const char* iname = interface.latin1(); |
37 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); | 36 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); |
38 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) | 37 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) |
39 | hasWirelessExtensions = true; | 38 | hasWirelessExtensions = true; |
40 | } | 39 | } |
41 | 40 | ||
42 | /** | 41 | /** |
43 | * @return QString the station name of the access point. | 42 | * @return QString the station name of the access point. |
44 | */ | 43 | */ |
45 | QString WExtensions::station(){ | 44 | QString WExtensions::station(){ |
46 | if(!hasWirelessExtensions) | 45 | if(!hasWirelessExtensions) |
47 | return QString(); | 46 | return QString(); |
48 | const char* buffer[200]; | 47 | const char* buffer[200]; |
49 | iwr.u.data.pointer = (caddr_t) buffer; | 48 | iwr.u.data.pointer = (caddr_t) buffer; |
50 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 49 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
51 | iwr.u.data.flags = 0; | 50 | iwr.u.data.flags = 0; |
52 | if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ | 51 | if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ |
53 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | 52 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; |
54 | return QString(iwr.u.data.pointer); | 53 | return QString(iwr.u.data.pointer); |
55 | } | 54 | } |
56 | return QString(); | 55 | return QString(); |
57 | } | 56 | } |
58 | 57 | ||
59 | /** | 58 | /** |
60 | * @return QString the essid of the host 802.11 access point. | 59 | * @return QString the essid of the host 802.11 access point. |
61 | */ | 60 | */ |
62 | QString WExtensions::essid(){ | 61 | QString WExtensions::essid(){ |
63 | if(!hasWirelessExtensions) | 62 | if(!hasWirelessExtensions) |
64 | return QString(); | 63 | return QString(); |
65 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ | 64 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ |
66 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | 65 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; |
67 | return QString(iwr.u.essid.pointer); | 66 | return QString(iwr.u.essid.pointer); |
68 | } | 67 | } |
69 | return QString(); | 68 | return QString(); |
70 | } | 69 | } |
71 | 70 | ||
72 | /** | 71 | /** |
73 | * @return QString the mode of interface | 72 | * @return QString the mode of interface |
74 | */ | 73 | */ |
75 | QString WExtensions::mode(){ | 74 | QString WExtensions::mode(){ |
76 | if(!hasWirelessExtensions) | 75 | if(!hasWirelessExtensions) |
77 | return QString(); | 76 | return QString(); |
78 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) | 77 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) |
79 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); | 78 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); |
80 | return QString(); | 79 | return QString(); |
81 | } | 80 | } |
82 | 81 | ||
83 | /** | 82 | /** |
84 | * Get the frequency that the interface is running at. | 83 | * Get the frequency that the interface is running at. |
85 | * @return int the frequency that the interfacae is running at. | 84 | * @return int the frequency that the interfacae is running at. |
86 | */ | 85 | */ |
87 | double WExtensions::frequency(){ | 86 | double WExtensions::frequency(){ |
88 | if(!hasWirelessExtensions) | 87 | if(!hasWirelessExtensions) |
89 | return 0; | 88 | return 0; |
90 | if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) | 89 | if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) |
91 | return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); | 90 | return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); |
92 | return 0; | 91 | return 0; |
93 | } | 92 | } |
94 | 93 | ||
95 | /*** | 94 | /*** |
96 | * Get the current rate that the card is transmiting at. | 95 | * Get the current rate that the card is transmiting at. |
97 | */ | 96 | */ |
98 | double WExtensions::rate(){ | 97 | double WExtensions::rate(){ |
99 | if(!hasWirelessExtensions) | 98 | if(!hasWirelessExtensions) |
100 | return 0; | 99 | return 0; |
101 | if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){ | 100 | if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){ |
102 | return ((double)iwr.u.bitrate.value)/1000000; | 101 | return ((double)iwr.u.bitrate.value)/1000000; |
103 | } | 102 | } |
104 | return 0; | 103 | return 0; |
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||
108 | /** | 107 | /** |
109 | * @return QString the AccessPoint that the interface is connected to. | 108 | * @return QString the AccessPoint that the interface is connected to. |
110 | */ | 109 | */ |
111 | QString WExtensions::ap(){ | 110 | QString WExtensions::ap(){ |
112 | if(!hasWirelessExtensions) | 111 | if(!hasWirelessExtensions) |
113 | return QString(); | 112 | return QString(); |
114 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ | 113 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ |
115 | QString ap; | 114 | QString ap; |
116 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 115 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
117 | iwr.u.ap_addr.sa_data[0]&0xff, | 116 | iwr.u.ap_addr.sa_data[0]&0xff, |
118 | iwr.u.ap_addr.sa_data[1]&0xff, | 117 | iwr.u.ap_addr.sa_data[1]&0xff, |
119 | iwr.u.ap_addr.sa_data[2]&0xff, | 118 | iwr.u.ap_addr.sa_data[2]&0xff, |
120 | iwr.u.ap_addr.sa_data[3]&0xff, | 119 | iwr.u.ap_addr.sa_data[3]&0xff, |
121 | iwr.u.ap_addr.sa_data[4]&0xff, | 120 | iwr.u.ap_addr.sa_data[4]&0xff, |
122 | iwr.u.ap_addr.sa_data[5]&0xff ); | 121 | iwr.u.ap_addr.sa_data[5]&0xff ); |
123 | return ap; | 122 | return ap; |
124 | } | 123 | } |
125 | else return QString(); | 124 | else return QString(); |
126 | } | 125 | } |
127 | 126 | ||
128 | /** | 127 | /** |
129 | * Get the stats for interfaces | 128 | * Get the stats for interfaces |
130 | * @param signal the signal strength of interface | 129 | * @param signal the signal strength of interface |
131 | * @param noise the noise level of the interface | 130 | * @param noise the noise level of the interface |
132 | * @param quality the quality level of the interface | 131 | * @param quality the quality level of the interface |
133 | * @return bool true if successfull | 132 | * @return bool true if successfull |
134 | */ | 133 | */ |
135 | bool WExtensions::stats(int &signal, int &noise, int &quality){ | 134 | bool WExtensions::stats(int &signal, int &noise, int &quality){ |
136 | // gather link quality from /proc/net/wireless | 135 | // gather link quality from /proc/net/wireless |
137 | if(!QFile::exists(PROCNETWIRELESS)) | 136 | if(!QFile::exists(PROCNETWIRELESS)) |
138 | return false; | 137 | return false; |
139 | 138 | ||
140 | char c; | 139 | char c; |
141 | QString status; | 140 | QString status; |
142 | QString name; | 141 | QString name; |
143 | 142 | ||
144 | QFile wfile( PROCNETWIRELESS ); | 143 | QFile wfile( PROCNETWIRELESS ); |
145 | if(!wfile.open( IO_ReadOnly )) | 144 | if(!wfile.open( IO_ReadOnly )) |
146 | return false; | 145 | return false; |
147 | 146 | ||
148 | QTextStream wstream( &wfile ); | 147 | QTextStream wstream( &wfile ); |
149 | wstream.readLine(); // skip the first two lines | 148 | wstream.readLine(); // skip the first two lines |
150 | wstream.readLine(); // because they only contain headers | 149 | wstream.readLine(); // because they only contain headers |
151 | while(!wstream.atEnd()){ | 150 | while(!wstream.atEnd()){ |
152 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | 151 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; |
153 | if(name == QString("%1:").arg(interface)){ | 152 | if(name == QString("%1:").arg(interface)){ |
154 | if ( quality > 92 ) | 153 | if ( quality > 92 ) |
155 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | 154 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); |
156 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | 155 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) |
157 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | 156 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); |
158 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | 157 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) |
159 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | 158 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); |
160 | //qDebug(QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1()); | 159 | //qDebug(QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1()); |
161 | signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; | 160 | signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; |
162 | noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; | 161 | noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; |
163 | quality = ( quality*100 ) / 92; | 162 | quality = ( quality*100 ) / 92; |
164 | return true; | 163 | return true; |
165 | } | 164 | } |
166 | } | 165 | } |
167 | 166 | ||
168 | qDebug("WExtensions::statsCard no longer present."); | 167 | qDebug("WExtensions::statsCard no longer present."); |
169 | quality = -1; | 168 | quality = -1; |
170 | signal = IW_LOWER; | 169 | signal = IW_LOWER; |
171 | noise = IW_LOWER; | 170 | noise = IW_LOWER; |
172 | return false; | 171 | return false; |
173 | } | 172 | } |
174 | 173 | ||
175 | // wextensions.cpp | 174 | // wextensions.cpp |
diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp index 689eae2..d4b4af9 100644 --- a/noncore/settings/networksettings/wlan/wlanimp.cpp +++ b/noncore/settings/networksettings/wlan/wlanimp.cpp | |||
@@ -1,232 +1,232 @@ | |||
1 | #include "wlanimp.h" | 1 | #include "wlanimp.h" |
2 | #include "interfacesetupimp.h" | 2 | #include "interfacesetupimp.h" |
3 | 3 | ||
4 | #include <qfile.h> | 4 | #include <qfile.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qtextstream.h> | 6 | #include <qtextstream.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | #include <qlineedit.h> | 8 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 9 | #include <qspinbox.h> |
10 | #include <qradiobutton.h> | 10 | #include <qradiobutton.h> |
11 | #include <qcheckbox.h> | 11 | #include <qcheckbox.h> |
12 | #include <qtabwidget.h> | 12 | #include <qtabwidget.h> |
13 | 13 | ||
14 | /* system() */ | 14 | /* system() */ |
15 | #include <stdlib.h> | 15 | #include <stdlib.h> |
16 | 16 | ||
17 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" | 17 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * Constructor, read in the wireless.opts file for parsing later. | 20 | * Constructor, read in the wireless.opts file for parsing later. |
21 | */ | 21 | */ |
22 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { | 22 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { |
23 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); | 23 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); |
24 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | 24 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); |
25 | 25 | ||
26 | // Read in the config file. | 26 | // Read in the config file. |
27 | QString wlanFile = WIRELESS_OPTS; | 27 | QString wlanFile = WIRELESS_OPTS; |
28 | QFile file(wlanFile); | 28 | QFile file(wlanFile); |
29 | if (file.open(IO_ReadOnly)){ | 29 | if (file.open(IO_ReadOnly)){ |
30 | QTextStream stream( &file ); | 30 | QTextStream stream( &file ); |
31 | QString line = ""; | 31 | QString line = ""; |
32 | while ( !stream.eof() ) { | 32 | while ( !stream.eof() ) { |
33 | line += stream.readLine(); | 33 | line += stream.readLine(); |
34 | line += "\n"; | 34 | line += "\n"; |
35 | } | 35 | } |
36 | file.close(); | 36 | file.close(); |
37 | settingsFileText = QStringList::split("\n", line, true); | 37 | settingsFileText = QStringList::split("\n", line, true); |
38 | parseSettingFile(); | 38 | parseSettingFile(); |
39 | } | 39 | } |
40 | else | 40 | else |
41 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); | 41 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); |
42 | } | 42 | } |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Change the profile for both wireless settings and network settings. | 45 | * Change the profile for both wireless settings and network settings. |
46 | */ | 46 | */ |
47 | void WLANImp::setProfile(QString &profile){ | 47 | void WLANImp::setProfile(const QString &profile){ |
48 | interfaceSetup->setProfile(profile); | 48 | interfaceSetup->setProfile(profile); |
49 | parseSettingFile(); | 49 | parseSettingFile(); |
50 | } | 50 | } |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Parses the settings file that was read in and gets any setting from it. | 53 | * Parses the settings file that was read in and gets any setting from it. |
54 | */ | 54 | */ |
55 | void WLANImp::parseSettingFile(){ | 55 | void WLANImp::parseSettingFile(){ |
56 | bool foundCase = false; | 56 | bool foundCase = false; |
57 | bool found = false; | 57 | bool found = false; |
58 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { | 58 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { |
59 | QString line = (*it).simplifyWhiteSpace(); | 59 | QString line = (*it).simplifyWhiteSpace(); |
60 | if(line.contains("case")) | 60 | if(line.contains("case")) |
61 | foundCase = true; | 61 | foundCase = true; |
62 | // See if we found our scheme to write or the sceme couldn't be found | 62 | // See if we found our scheme to write or the sceme couldn't be found |
63 | if((foundCase && line.contains("esac")) || | 63 | if((foundCase && line.contains("esac")) || |
64 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) | 64 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) |
65 | found = true; | 65 | found = true; |
66 | 66 | ||
67 | if(line.contains(";;")) | 67 | if(line.contains(";;")) |
68 | found = false; | 68 | found = false; |
69 | if(found){ | 69 | if(found){ |
70 | // write out scheme | 70 | // write out scheme |
71 | if(line.contains("ESSID=")){ | 71 | if(line.contains("ESSID=")){ |
72 | QString id = line.mid(line.find("ESSID=")+6, line.length()); | 72 | QString id = line.mid(line.find("ESSID=")+6, line.length()); |
73 | if(id == "any"){ | 73 | if(id == "any"){ |
74 | essNon->setChecked(true); | 74 | essNon->setChecked(true); |
75 | essSpecific->setChecked(false); | 75 | essSpecific->setChecked(false); |
76 | }else{ | 76 | }else{ |
77 | essSpecific->setChecked(true); | 77 | essSpecific->setChecked(true); |
78 | essSpecificLineEdit->setText(id); | 78 | essSpecificLineEdit->setText(id); |
79 | essNon->setChecked(false); | 79 | essNon->setChecked(false); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | if(line.contains("MODE=")){ | 82 | if(line.contains("MODE=")){ |
83 | QString mode = line.mid(line.find("MODE=")+5, line.length()); | 83 | QString mode = line.mid(line.find("MODE=")+5, line.length()); |
84 | if(mode == "Managed"){ | 84 | if(mode == "Managed"){ |
85 | network802->setChecked( false ); | 85 | network802->setChecked( false ); |
86 | networkInfrastructure->setChecked( true ); | 86 | networkInfrastructure->setChecked( true ); |
87 | } | 87 | } |
88 | else{ | 88 | else{ |
89 | network802->setChecked( true ); | 89 | network802->setChecked( true ); |
90 | networkInfrastructure->setChecked( false ); | 90 | networkInfrastructure->setChecked( false ); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | if(line.contains("KEY=")){ | 93 | if(line.contains("KEY=")){ |
94 | line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false); | 94 | line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false); |
95 | int s = line.find("KEY="); | 95 | int s = line.find("KEY="); |
96 | line = line.mid(s+4, line.length()); | 96 | line = line.mid(s+4, line.length()); |
97 | // Find first Key | 97 | // Find first Key |
98 | s = line.find("[1]"); | 98 | s = line.find("[1]"); |
99 | if(s != -1){ | 99 | if(s != -1){ |
100 | keyLineEdit0->setText(line.mid(0, s)); | 100 | keyLineEdit0->setText(line.mid(0, s)); |
101 | line = line.mid(s+3, line.length()); | 101 | line = line.mid(s+3, line.length()); |
102 | } | 102 | } |
103 | s = line.find("[2]"); | 103 | s = line.find("[2]"); |
104 | if(s != -1){ | 104 | if(s != -1){ |
105 | keyLineEdit1->setText(line.mid(0, s)); | 105 | keyLineEdit1->setText(line.mid(0, s)); |
106 | line = line.mid(s+3, line.length()); | 106 | line = line.mid(s+3, line.length()); |
107 | } | 107 | } |
108 | s = line.find("[3]"); | 108 | s = line.find("[3]"); |
109 | if(s != -1){ | 109 | if(s != -1){ |
110 | keyLineEdit2->setText(line.mid(0, s)); | 110 | keyLineEdit2->setText(line.mid(0, s)); |
111 | line = line.mid(s+3, line.length()); | 111 | line = line.mid(s+3, line.length()); |
112 | } | 112 | } |
113 | s = line.find("[4]"); | 113 | s = line.find("[4]"); |
114 | if(s != -1){ | 114 | if(s != -1){ |
115 | keyLineEdit3->setText(line.mid(0, s)); | 115 | keyLineEdit3->setText(line.mid(0, s)); |
116 | line = line.mid(s+3, line.length()); | 116 | line = line.mid(s+3, line.length()); |
117 | } | 117 | } |
118 | if(line.contains("key [1]")) keyRadio0->setChecked(true); | 118 | if(line.contains("key [1]")) keyRadio0->setChecked(true); |
119 | if(line.contains("key [2]")) keyRadio1->setChecked(true); | 119 | if(line.contains("key [2]")) keyRadio1->setChecked(true); |
120 | if(line.contains("key [3]")) keyRadio2->setChecked(true); | 120 | if(line.contains("key [3]")) keyRadio2->setChecked(true); |
121 | if(line.contains("key [4]")) keyRadio3->setChecked(true); | 121 | if(line.contains("key [4]")) keyRadio3->setChecked(true); |
122 | if(line.contains("open")){ | 122 | if(line.contains("open")){ |
123 | authOpen->setChecked(true); | 123 | authOpen->setChecked(true); |
124 | authShared->setChecked(false); | 124 | authShared->setChecked(false); |
125 | } | 125 | } |
126 | else{ | 126 | else{ |
127 | authOpen->setChecked(false); | 127 | authOpen->setChecked(false); |
128 | authShared->setChecked(true); | 128 | authShared->setChecked(true); |
129 | } | 129 | } |
130 | } | 130 | } |
131 | if(line.contains("CHANNEL=")){ | 131 | if(line.contains("CHANNEL=")){ |
132 | networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); | 132 | networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | /** | 138 | /** |
139 | * Saves settings to the wireless.opts file using the current profile | 139 | * Saves settings to the wireless.opts file using the current profile |
140 | */ | 140 | */ |
141 | void WLANImp::changeAndSaveSettingFile(){ | 141 | void WLANImp::changeAndSaveSettingFile(){ |
142 | QString wlanFile = WIRELESS_OPTS; | 142 | QString wlanFile = WIRELESS_OPTS; |
143 | QFile::remove(wlanFile); | 143 | QFile::remove(wlanFile); |
144 | QFile file(wlanFile); | 144 | QFile file(wlanFile); |
145 | 145 | ||
146 | if (!file.open(IO_ReadWrite)){ | 146 | if (!file.open(IO_ReadWrite)){ |
147 | qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); | 147 | qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | 150 | ||
151 | QTextStream stream( &file ); | 151 | QTextStream stream( &file ); |
152 | bool foundCase = false; | 152 | bool foundCase = false; |
153 | bool found = false; | 153 | bool found = false; |
154 | bool output = true; | 154 | bool output = true; |
155 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { | 155 | for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { |
156 | QString line = (*it).simplifyWhiteSpace(); | 156 | QString line = (*it).simplifyWhiteSpace(); |
157 | if(line.contains("case")) | 157 | if(line.contains("case")) |
158 | foundCase = true; | 158 | foundCase = true; |
159 | // See if we found our scheme to write or the sceme couldn't be found | 159 | // See if we found our scheme to write or the sceme couldn't be found |
160 | if((foundCase && line.contains("esac") && !found) || | 160 | if((foundCase && line.contains("esac") && !found) || |
161 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ | 161 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ |
162 | // write out scheme | 162 | // write out scheme |
163 | found = true; | 163 | found = true; |
164 | output = false; | 164 | output = false; |
165 | 165 | ||
166 | if(!line.contains("esac")) | 166 | if(!line.contains("esac")) |
167 | stream << line << "\n"; | 167 | stream << line << "\n"; |
168 | 168 | ||
169 | stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; | 169 | stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; |
170 | stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n'; | 170 | stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n'; |
171 | if(!wepEnabled->isChecked()) | 171 | if(!wepEnabled->isChecked()) |
172 | stream << "#"; | 172 | stream << "#"; |
173 | stream << "\tKEY="; | 173 | stream << "\tKEY="; |
174 | stream << keyLineEdit0->text() << " [1]"; | 174 | stream << keyLineEdit0->text() << " [1]"; |
175 | stream << keyLineEdit1->text() << " [2]"; | 175 | stream << keyLineEdit1->text() << " [2]"; |
176 | stream << keyLineEdit2->text() << " [3]"; | 176 | stream << keyLineEdit2->text() << " [3]"; |
177 | stream << keyLineEdit3->text() << " [4]"; | 177 | stream << keyLineEdit3->text() << " [4]"; |
178 | stream << " key ["; | 178 | stream << " key ["; |
179 | if(keyRadio0->isChecked()) stream << "1]"; | 179 | if(keyRadio0->isChecked()) stream << "1]"; |
180 | if(keyRadio1->isChecked()) stream << "2]"; | 180 | if(keyRadio1->isChecked()) stream << "2]"; |
181 | if(keyRadio2->isChecked()) stream << "3]"; | 181 | if(keyRadio2->isChecked()) stream << "3]"; |
182 | if(keyRadio3->isChecked()) stream << "4]"; | 182 | if(keyRadio3->isChecked()) stream << "4]"; |
183 | if(authOpen->isChecked()) stream << " open"; | 183 | if(authOpen->isChecked()) stream << " open"; |
184 | stream << "\n"; | 184 | stream << "\n"; |
185 | stream << "\tCHANNEL=" << networkChannel->value() << "\n"; | 185 | stream << "\tCHANNEL=" << networkChannel->value() << "\n"; |
186 | stream << "\tRATE=auto\n"; | 186 | stream << "\tRATE=auto\n"; |
187 | if(line.contains("esac")) | 187 | if(line.contains("esac")) |
188 | stream << line << "\n"; | 188 | stream << line << "\n"; |
189 | } | 189 | } |
190 | if(line.contains(";;")) | 190 | if(line.contains(";;")) |
191 | output = true; | 191 | output = true; |
192 | if(output) | 192 | if(output) |
193 | stream << (*it) << '\n'; | 193 | stream << (*it) << '\n'; |
194 | } | 194 | } |
195 | file.close(); | 195 | file.close(); |
196 | } | 196 | } |
197 | 197 | ||
198 | /** | 198 | /** |
199 | * Check to see if the current config is valid | 199 | * Check to see if the current config is valid |
200 | * Save wireless.opts, save interfaces | 200 | * Save wireless.opts, save interfaces |
201 | */ | 201 | */ |
202 | void WLANImp::accept(){ | 202 | void WLANImp::accept(){ |
203 | if(wepEnabled->isChecked()){ | 203 | if(wepEnabled->isChecked()){ |
204 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) | 204 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) |
205 | QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); | 205 | QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | 208 | ||
209 | // Ok settings are good here, save | 209 | // Ok settings are good here, save |
210 | changeAndSaveSettingFile(); | 210 | changeAndSaveSettingFile(); |
211 | 211 | ||
212 | // Try to save the interfaces settings. | 212 | // Try to save the interfaces settings. |
213 | if(!interfaceSetup->saveChanges()) | 213 | if(!interfaceSetup->saveChanges()) |
214 | return; | 214 | return; |
215 | 215 | ||
216 | // Restart the device now that the settings have changed | 216 | // Restart the device now that the settings have changed |
217 | QString initpath; | 217 | QString initpath; |
218 | if( QDir("/etc/rc.d/init.d").exists() ) | 218 | if( QDir("/etc/rc.d/init.d").exists() ) |
219 | initpath = "/etc/rc.d/init.d"; | 219 | initpath = "/etc/rc.d/init.d"; |
220 | else if( QDir("/etc/init.d").exists() ) | 220 | else if( QDir("/etc/init.d").exists() ) |
221 | initpath = "/etc/init.d"; | 221 | initpath = "/etc/init.d"; |
222 | if( initpath ) | 222 | if( initpath ) |
223 | system(QString("%1/pcmcia stop").arg(initpath)); | 223 | system(QString("%1/pcmcia stop").arg(initpath)); |
224 | if( initpath ) | 224 | if( initpath ) |
225 | system(QString("%1/pcmcia start").arg(initpath)); | 225 | system(QString("%1/pcmcia start").arg(initpath)); |
226 | 226 | ||
227 | // Close out the dialog | 227 | // Close out the dialog |
228 | QDialog::accept(); | 228 | QDialog::accept(); |
229 | } | 229 | } |
230 | 230 | ||
231 | // wlanimp.cpp | 231 | // wlanimp.cpp |
232 | 232 | ||
diff --git a/noncore/settings/networksettings/wlan/wlanimp.h b/noncore/settings/networksettings/wlan/wlanimp.h index f88e550..df599af 100644 --- a/noncore/settings/networksettings/wlan/wlanimp.h +++ b/noncore/settings/networksettings/wlan/wlanimp.h | |||
@@ -1,31 +1,31 @@ | |||
1 | #ifndef WLANIMP_H | 1 | #ifndef WLANIMP_H |
2 | #define WLANIMP_H | 2 | #define WLANIMP_H |
3 | 3 | ||
4 | #include "wlan.h" | 4 | #include "wlan.h" |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | 6 | ||
7 | class InterfaceSetupImp; | 7 | class InterfaceSetupImp; |
8 | class Interface; | 8 | class Interface; |
9 | class Config; | 9 | class Config; |
10 | 10 | ||
11 | class WLANImp : public WLAN { | 11 | class WLANImp : public WLAN { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | 13 | ||
14 | public: | 14 | public: |
15 | WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); | 15 | WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); |
16 | void setProfile(QString &profile); | 16 | void setProfile(const QString &profile); |
17 | 17 | ||
18 | protected: | 18 | protected: |
19 | void accept(); | 19 | void accept(); |
20 | 20 | ||
21 | private: | 21 | private: |
22 | void parseSettingFile(); | 22 | void parseSettingFile(); |
23 | void changeAndSaveSettingFile(); | 23 | void changeAndSaveSettingFile(); |
24 | 24 | ||
25 | InterfaceSetupImp *interfaceSetup; | 25 | InterfaceSetupImp *interfaceSetup; |
26 | QStringList settingsFileText; | 26 | QStringList settingsFileText; |
27 | QString currentProfile; | 27 | QString currentProfile; |
28 | }; | 28 | }; |
29 | 29 | ||
30 | #endif | 30 | #endif |
31 | 31 | ||
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp index b14fc0a..3979e60 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.cpp +++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp | |||
@@ -1,113 +1,113 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include "wlanimp.h" | 2 | #include "wlanimp.h" |
3 | #include "infoimp.h" | 3 | #include "infoimp.h" |
4 | #include "wextensions.h" | 4 | #include "wextensions.h" |
5 | #include "interfaceinformationimp.h" | 5 | #include "interfaceinformationimp.h" |
6 | 6 | ||
7 | #include <qlabel.h> | 7 | #include <qlabel.h> |
8 | #include <qprogressbar.h> | 8 | #include <qprogressbar.h> |
9 | #include <qtabwidget.h> | 9 | #include <qtabwidget.h> |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Constructor, find all of the possible interfaces | 12 | * Constructor, find all of the possible interfaces |
13 | */ | 13 | */ |
14 | WLANModule::WLANModule() : Module() { | 14 | WLANModule::WLANModule() : Module() { |
15 | } | 15 | } |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * Delete any interfaces that we own. | 18 | * Delete any interfaces that we own. |
19 | */ | 19 | */ |
20 | WLANModule::~WLANModule(){ | 20 | WLANModule::~WLANModule(){ |
21 | Interface *i; | 21 | Interface *i; |
22 | for ( i=list.first(); i != 0; i=list.next() ) | 22 | for ( i=list.first(); i != 0; i=list.next() ) |
23 | delete i; | 23 | delete i; |
24 | } | 24 | } |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Change the current profile | 27 | * Change the current profile |
28 | */ | 28 | */ |
29 | void WLANModule::setProfile(QString newProfile){ | 29 | void WLANModule::setProfile(const QString &newProfile){ |
30 | profile = newProfile; | 30 | profile = newProfile; |
31 | } | 31 | } |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * get the icon name for this device. | 34 | * get the icon name for this device. |
35 | * @param Interface* can be used in determining the icon. | 35 | * @param Interface* can be used in determining the icon. |
36 | * @return QString the icon name (minus .png, .gif etc) | 36 | * @return QString the icon name (minus .png, .gif etc) |
37 | */ | 37 | */ |
38 | QString WLANModule::getPixmapName(Interface* ){ | 38 | QString WLANModule::getPixmapName(Interface* ){ |
39 | return "wlan"; | 39 | return "wlan"; |
40 | } | 40 | } |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Check to see if the interface i is owned by this module. | 43 | * Check to see if the interface i is owned by this module. |
44 | * @param Interface* interface to check against | 44 | * @param Interface* interface to check against |
45 | * @return bool true if i is owned by this module, false otherwise. | 45 | * @return bool true if i is owned by this module, false otherwise. |
46 | */ | 46 | */ |
47 | bool WLANModule::isOwner(Interface *i){ | 47 | bool WLANModule::isOwner(Interface *i){ |
48 | WExtensions we(i->getInterfaceName()); | 48 | WExtensions we(i->getInterfaceName()); |
49 | if(!we.doesHaveWirelessExtensions()) | 49 | if(!we.doesHaveWirelessExtensions()) |
50 | return false; | 50 | return false; |
51 | 51 | ||
52 | i->setHardwareName("802.11b"); | 52 | i->setHardwareName("802.11b"); |
53 | list.append(i); | 53 | list.append(i); |
54 | return true; | 54 | return true; |
55 | } | 55 | } |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Create, and return the WLANConfigure Module | 58 | * Create, and return the WLANConfigure Module |
59 | * @return QWidget* pointer to this modules configure. | 59 | * @return QWidget* pointer to this modules configure. |
60 | */ | 60 | */ |
61 | QWidget *WLANModule::configure(Interface *i){ | 61 | QWidget *WLANModule::configure(Interface *i){ |
62 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, false, Qt::WDestructiveClose); | 62 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, false, Qt::WDestructiveClose); |
63 | wlanconfig->setProfile(profile); | 63 | wlanconfig->setProfile(profile); |
64 | return wlanconfig; | 64 | return wlanconfig; |
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Create, and return the Information Module | 68 | * Create, and return the Information Module |
69 | * @return QWidget* pointer to this modules info. | 69 | * @return QWidget* pointer to this modules info. |
70 | */ | 70 | */ |
71 | QWidget *WLANModule::information(Interface *i){ | 71 | QWidget *WLANModule::information(Interface *i){ |
72 | WExtensions we(i->getInterfaceName()); | 72 | WExtensions we(i->getInterfaceName()); |
73 | if(!we.doesHaveWirelessExtensions()) | 73 | if(!we.doesHaveWirelessExtensions()) |
74 | return NULL; | 74 | return NULL; |
75 | 75 | ||
76 | WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); | 76 | WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); |
77 | InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); | 77 | InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); |
78 | info->tabWidget->insertTab(information, "TCP/IP"); | 78 | info->tabWidget->insertTab(information, "TCP/IP"); |
79 | return info; | 79 | return info; |
80 | } | 80 | } |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Get all active (up or down) interfaces | 83 | * Get all active (up or down) interfaces |
84 | * @return QList<Interface> A list of interfaces that exsist that havn't | 84 | * @return QList<Interface> A list of interfaces that exsist that havn't |
85 | * been called by isOwner() | 85 | * been called by isOwner() |
86 | */ | 86 | */ |
87 | QList<Interface> WLANModule::getInterfaces(){ | 87 | QList<Interface> WLANModule::getInterfaces(){ |
88 | return list; | 88 | return list; |
89 | } | 89 | } |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Attempt to add a new interface as defined by name | 92 | * Attempt to add a new interface as defined by name |
93 | * @param name the name of the type of interface that should be created given | 93 | * @param name the name of the type of interface that should be created given |
94 | * by possibleNewInterfaces(); | 94 | * by possibleNewInterfaces(); |
95 | * @return Interface* NULL if it was unable to be created. | 95 | * @return Interface* NULL if it was unable to be created. |
96 | */ | 96 | */ |
97 | Interface *WLANModule::addNewInterface(QString ){ | 97 | Interface *WLANModule::addNewInterface(const QString &){ |
98 | // We can't add a 802.11 interface, either the hardware will be there | 98 | // We can't add a 802.11 interface, either the hardware will be there |
99 | // or it wont. | 99 | // or it wont. |
100 | return NULL; | 100 | return NULL; |
101 | } | 101 | } |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Attempts to remove the interface, doesn't delete i | 104 | * Attempts to remove the interface, doesn't delete i |
105 | * @return bool true if successfull, false otherwise. | 105 | * @return bool true if successfull, false otherwise. |
106 | */ | 106 | */ |
107 | bool WLANModule::remove(Interface*){ | 107 | bool WLANModule::remove(Interface*){ |
108 | // Can't remove a hardware device, you can stop it though. | 108 | // Can't remove a hardware device, you can stop it though. |
109 | return false; | 109 | return false; |
110 | } | 110 | } |
111 | 111 | ||
112 | // wlanmodule.cpp | 112 | // wlanmodule.cpp |
113 | 113 | ||
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.h b/noncore/settings/networksettings/wlan/wlanmodule.h index a81ccff..3a54de6 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.h +++ b/noncore/settings/networksettings/wlan/wlanmodule.h | |||
@@ -1,41 +1,41 @@ | |||
1 | #ifndef WLAN_MODULE_H | 1 | #ifndef WLAN_MODULE_H |
2 | #define WLAN_MODULE_H | 2 | #define WLAN_MODULE_H |
3 | 3 | ||
4 | #include "module.h" | 4 | #include "module.h" |
5 | 5 | ||
6 | class WLANModule : Module{ | 6 | class WLANModule : Module{ |
7 | 7 | ||
8 | signals: | 8 | signals: |
9 | void updateInterface(Interface *i); | 9 | void updateInterface(Interface *i); |
10 | 10 | ||
11 | public: | 11 | public: |
12 | WLANModule(); | 12 | WLANModule(); |
13 | ~WLANModule(); | 13 | ~WLANModule(); |
14 | 14 | ||
15 | virtual void setProfile(QString newProfile); | 15 | void setProfile(const QString &newProfile); |
16 | virtual bool isOwner(Interface *); | 16 | bool isOwner(Interface *); |
17 | virtual QWidget *configure(Interface *i); | 17 | QWidget *configure(Interface *i); |
18 | virtual QWidget *information(Interface *i); | 18 | QWidget *information(Interface *i); |
19 | virtual QList<Interface> getInterfaces(); | 19 | QList<Interface> getInterfaces(); |
20 | virtual void possibleNewInterfaces(QMap<QString, QString> &){}; | 20 | void possibleNewInterfaces(QMap<QString, QString> &){}; |
21 | virtual Interface *addNewInterface(QString name); | 21 | Interface *addNewInterface(const QString &name); |
22 | virtual bool remove(Interface* i); | 22 | bool remove(Interface* i); |
23 | virtual QString getPixmapName(Interface* i); | 23 | QString getPixmapName(Interface* i); |
24 | 24 | ||
25 | private: | 25 | private: |
26 | QList<Interface> list; | 26 | QList<Interface> list; |
27 | QString profile; | 27 | QString profile; |
28 | 28 | ||
29 | }; | 29 | }; |
30 | 30 | ||
31 | extern "C" | 31 | extern "C" |
32 | { | 32 | { |
33 | void* create_plugin() { | 33 | void* create_plugin() { |
34 | return new WLANModule(); | 34 | return new WLANModule(); |
35 | } | 35 | } |
36 | }; | 36 | }; |
37 | 37 | ||
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | // wlanmodule.h | 40 | // wlanmodule.h |
41 | 41 | ||