8 files changed, 186 insertions, 192 deletions
diff --git a/noncore/net/networksetup/interfaces/interfaces.cpp b/noncore/net/networksetup/interfaces/interfaces.cpp index 708f399..e49998e 100644 --- a/noncore/net/networksetup/interfaces/interfaces.cpp +++ b/noncore/net/networksetup/interfaces/interfaces.cpp | |||
@@ -1,640 +1,643 @@ | |||
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 | // The three stanza's | ||
7 | #define AUTO "auto" | 8 | #define AUTO "auto" |
8 | #define IFACE "iface" | 9 | #define IFACE "iface" |
9 | #define MAPPING "mapping" | 10 | #define MAPPING "mapping" |
10 | 11 | ||
11 | /** | 12 | /** |
12 | * Constructor. Reads in the interfaces file and then split the file up by | 13 | * Constructor. Reads in the interfaces file and then split the file up by |
13 | * the \n for interfaces variable. | 14 | * the \n for interfaces variable. |
14 | * @param useInterfacesFile if an interface file other then the default is | 15 | * @param useInterfacesFile if an interface file other then the default is |
15 | * desired to be used it should be passed in. | 16 | * desired to be used it should be passed in. |
16 | */ | 17 | */ |
17 | Interfaces::Interfaces(QString useInterfacesFile){ | 18 | Interfaces::Interfaces(QString useInterfacesFile){ |
18 | acceptedFamily.append(INTERFACES_FAMILY_INET); | 19 | acceptedFamily.append(INTERFACES_FAMILY_INET); |
19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | 20 | acceptedFamily.append(INTERFACES_FAMILY_IPX); |
20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | 21 | acceptedFamily.append(INTERFACES_FAMILY_INET6); |
21 | 22 | ||
22 | interfacesFile = useInterfacesFile; | 23 | interfacesFile = useInterfacesFile; |
23 | QFile file(interfacesFile); | 24 | QFile file(interfacesFile); |
24 | if (!file.open(IO_ReadOnly)){ | 25 | if (!file.open(IO_ReadOnly)){ |
25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); | 26 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); |
26 | currentIface = interfaces.end(); | 27 | currentIface = interfaces.end(); |
27 | currentMapping = interfaces.end(); | 28 | currentMapping = interfaces.end(); |
28 | return; | 29 | return; |
29 | } | 30 | } |
30 | QTextStream stream( &file ); | 31 | QTextStream stream( &file ); |
31 | QString line; | 32 | QString line; |
32 | while ( !stream.eof() ) { | 33 | while ( !stream.eof() ) { |
33 | line += stream.readLine(); | 34 | line += stream.readLine(); |
34 | line += "\n"; | 35 | line += "\n"; |
35 | } | 36 | } |
36 | file.close(); | 37 | file.close(); |
37 | interfaces = QStringList::split("\n", line, true); | 38 | interfaces = QStringList::split("\n", line, true); |
38 | 39 | ||
39 | currentIface = interfaces.end(); | 40 | currentIface = interfaces.end(); |
40 | currentMapping = interfaces.end(); | 41 | currentMapping = interfaces.end(); |
41 | } | 42 | } |
42 | 43 | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Get a list of all interfaces in the interface file. Usefull for | 46 | * Get a list of all interfaces in the interface file. Usefull for |
46 | * hardware that is not currently connected such as an 802.11b card | 47 | * hardware that is not currently connected such as an 802.11b card |
47 | * not plugged in, but configured for when it is plugged in. | 48 | * not plugged in, but configured for when it is plugged in. |
48 | * @return Return string list of interfaces. | 49 | * @return Return string list of interfaces. |
49 | **/ | 50 | **/ |
50 | QStringList Interfaces::getInterfaceList(){ | 51 | QStringList Interfaces::getInterfaceList(){ |
51 | QStringList list; | 52 | QStringList list; |
52 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 53 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
53 | QString line = (*it).simplifyWhiteSpace(); | 54 | QString line = (*it).simplifyWhiteSpace(); |
54 | if(line.contains(IFACE) && line.at(0) != '#'){ | 55 | if(line.contains(IFACE) && line.at(0) != '#'){ |
55 | line = line.mid(QString(IFACE).length() +1, line.length()); | 56 | line = line.mid(QString(IFACE).length() +1, line.length()); |
56 | line = line.simplifyWhiteSpace(); | 57 | line = line.simplifyWhiteSpace(); |
57 | int findSpace = line.find(" "); | 58 | int findSpace = line.find(" "); |
58 | if( findSpace >= 0){ | 59 | if( findSpace >= 0){ |
59 | line = line.mid(0, findSpace); | 60 | line = line.mid(0, findSpace); |
60 | list.append(line); | 61 | list.append(line); |
61 | } | 62 | } |
62 | } | 63 | } |
63 | } | 64 | } |
64 | return list; | 65 | return list; |
65 | } | 66 | } |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * Find out if interface is in an "auto" group or not. | 69 | * Find out if interface is in an "auto" group or not. |
69 | * Report any duplicates such as eth0 being in two differnt auto's | 70 | * Report any duplicates such as eth0 being in two differnt auto's |
70 | * @param interface interface to check to see if it is on or not. | 71 | * @param interface interface to check to see if it is on or not. |
71 | * @return true is interface is in auto | 72 | * @return true is interface is in auto |
72 | */ | 73 | */ |
73 | bool Interfaces::isAuto(const QString &interface){ | 74 | bool Interfaces::isAuto(const QString &interface){ |
74 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | 75 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); |
75 | QStringList awi = autoLines.grep(QRegExp(interface)); | 76 | QStringList awi = autoLines.grep(QRegExp(interface)); |
76 | if(awi.count() > 1) | 77 | if(awi.count() > 1) |
77 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); | 78 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); |
78 | if(awi.count() < 1) | 79 | if(awi.count() < 1) |
79 | return false; | 80 | return false; |
80 | return true; | 81 | return true; |
81 | } | 82 | } |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * Attempt to set the auto option for interface to setAuto. | 85 | * Attempt to set the auto option for interface to setAuto. |
85 | * @param interface the interface to set | 86 | * @param interface the interface to set |
86 | * @param setAuto the value to set interface to. | 87 | * @param setAuto the value to set interface to. |
87 | * @return false if already set to setAuto. | 88 | * @return false if already set to setAuto. |
88 | * */ | 89 | * */ |
89 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ | 90 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ |
90 | // Don't need to set it if it is already set. | 91 | // Don't need to set it if it is already set. |
91 | if(isAuto(interface) == setAuto) | 92 | if(isAuto(interface) == setAuto) |
92 | return false; | 93 | return false; |
93 | 94 | ||
94 | bool changed = false; | 95 | bool changed = false; |
95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 96 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
96 | if((*it).contains(AUTO)){ | 97 | if((*it).contains(AUTO)){ |
97 | //We know that they are not in any group so let add to this auto. | 98 | //We know that they are not in any group so let add to this auto. |
98 | if(setAuto){ | 99 | if(setAuto){ |
99 | (*it) = (*it) += " " + interface; | 100 | (*it) = (*it) += " " + interface; |
100 | // Don't care to have such thins as: auto eth0 lo usb0 | 101 | // Don't care to have such thins as: auto eth0 lo usb0 |
101 | (*it) = (*it).simplifyWhiteSpace(); | 102 | (*it) = (*it).simplifyWhiteSpace(); |
102 | changed = true; | 103 | changed = true; |
103 | break; | 104 | break; |
104 | } | 105 | } |
106 | // else see if we need to remove from this one | ||
105 | else{ | 107 | else{ |
106 | if((*it).contains(interface)){ | 108 | if((*it).contains(interface)){ |
107 | (*it) = (*it).replace(QRegExp(interface), ""); | 109 | (*it) = (*it).replace(QRegExp(interface), ""); |
108 | // clean up | 110 | // if AUTO is the only thing left clear the line |
109 | QString line = (*it).simplifyWhiteSpace(); | 111 | if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) |
110 | line = line.replace(QRegExp(" "),""); | ||
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 | // In the case where there is no AUTO field add one. |
120 | if(setAuto == true) | 120 | if(!changed && setAuto) |
121 | interfaces.append(QString(AUTO" %1").arg(interface)); | 121 | interfaces.append(QString(AUTO" %1").arg(interface)); |
122 | else{ | ||
123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | ||
124 | } | ||
125 | } | ||
126 | return true; | 122 | return true; |
127 | } | 123 | } |
128 | 124 | ||
129 | /** | 125 | /** |
130 | * Set the current interface to interface. This needs to be done before you | 126 | * Set the current interface to interface. This needs to be done before you |
131 | * can call getFamily(), getMethod, and get/setOption(). | 127 | * can call getFamily(), getMethod, and get/setOption(). |
132 | * @param interface the name of the interface to set. All whitespace is | 128 | * @param interface the name of the interface to set. All whitespace is |
133 | * removed from the interface name. | 129 | * removed from the interface name. |
134 | * @return bool true if it is successfull. | 130 | * @return bool true if it is successfull. |
135 | */ | 131 | */ |
136 | bool Interfaces::setInterface(QString interface){ | 132 | bool Interfaces::setInterface(QString interface){ |
137 | interface = interface.simplifyWhiteSpace(); | 133 | interface = interface.simplifyWhiteSpace(); |
138 | interface = interface.replace(QRegExp(" "), ""); | 134 | interface = interface.replace(QRegExp(" "), ""); |
139 | return setStanza(IFACE, interface, currentIface); | 135 | return setStanza(IFACE, interface, currentIface); |
140 | } | 136 | } |
141 | 137 | ||
142 | /** | 138 | /** |
143 | * A quick helper funtion to see if the current interface is set. | 139 | * A quick helper funtion to see if the current interface is set. |
144 | * @return bool true if set, false otherwise. | 140 | * @return bool true if set, false otherwise. |
145 | */ | 141 | */ |
146 | bool Interfaces::isInterfaceSet(){ | 142 | bool Interfaces::isInterfaceSet(){ |
147 | return (currentIface != interfaces.end()); | 143 | return (currentIface != interfaces.end()); |
148 | } | 144 | } |
149 | 145 | ||
150 | /** | 146 | /** |
151 | * Add a new interface of with the settings - family and method | 147 | * Add a new interface of with the settings - family and method |
152 | * @param interface the name of the interface to set. All whitespace is | 148 | * @param interface the name of the interface to set. All whitespace is |
153 | * removed from the interface name. | 149 | * removed from the interface name. |
154 | * @param family the family of this interface inet or inet, ipx or inet6 | 150 | * @param family the family of this interface inet or inet, ipx or inet6 |
155 | * Must of one of the families defined in interfaces.h | 151 | * Must of one of the families defined in interfaces.h |
156 | * @param method for the family. see interfaces man page for family methods. | 152 | * @param method for the family. see interfaces man page for family methods. |
157 | * @return true if successfull. | 153 | * @return true if successfull. |
158 | */ | 154 | */ |
159 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ | 155 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ |
160 | if(acceptedFamily.contains(family)==0) | 156 | if(0 == acceptedFamily.contains(family)) |
161 | return false; | 157 | return false; |
162 | QString newInterface = interface.simplifyWhiteSpace(); | 158 | QString newInterface = interface.simplifyWhiteSpace(); |
163 | newInterface = newInterface.replace(QRegExp(" "), ""); | 159 | newInterface = newInterface.replace(QRegExp(" "), ""); |
164 | interfaces.append(""); | 160 | interfaces.append(""); |
165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); | 161 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); |
166 | return true; | 162 | return true; |
167 | } | 163 | } |
168 | 164 | ||
169 | /** | 165 | /** |
170 | * Copies interface with name interface to name newInterface | 166 | * Copies interface with name interface to name newInterface |
171 | * @param newInterface name of the new interface. | 167 | * @param newInterface name of the new interface. |
172 | * @return bool true if successfull | 168 | * @return bool true if successfull |
173 | */ | 169 | */ |
174 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ | 170 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ |
175 | if(!setInterface(interface)) return false; | 171 | if(!setInterface(interface)) |
176 | 172 | return false; | |
173 | |||
174 | // Store the old interface and bump past the stanza line. | ||
177 | QStringList::Iterator it = currentIface; | 175 | QStringList::Iterator it = currentIface; |
178 | it++; | 176 | it++; |
179 | 177 | ||
178 | // Add the new interface | ||
180 | bool error; | 179 | bool error; |
181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | 180 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); |
182 | if(!setInterface(newInterface)) return false; | 181 | if(!setInterface(newInterface)) |
182 | return false; | ||
183 | |||
183 | QStringList::Iterator newIface = currentIface; | 184 | QStringList::Iterator newIface = currentIface; |
184 | newIface++; | 185 | newIface++; |
185 | 186 | ||
187 | // Copy all of the lines | ||
186 | for ( ; it != interfaces.end(); ++it ){ | 188 | for ( ; it != interfaces.end(); ++it ){ |
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | 189 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) |
188 | break; | 190 | break; |
189 | newIface = interfaces.insert(newIface, *it); | 191 | newIface = interfaces.insert(newIface, *it); |
190 | } | 192 | } |
191 | 193 | ||
192 | return true; | 194 | return true; |
193 | } | 195 | } |
194 | 196 | ||
195 | /** | 197 | /** |
196 | * Remove the currently selected interface and all of its options. | 198 | * Remove the currently selected interface and all of its options. |
197 | * @return bool if successfull or not. | 199 | * @return bool if successfull or not. |
198 | */ | 200 | */ |
199 | bool Interfaces::removeInterface(){ | 201 | bool Interfaces::removeInterface(){ |
200 | if(currentIface == interfaces.end()) | 202 | return removeStanza(currentIface); |
201 | return false; | ||
202 | (*currentIface) = ""; | ||
203 | return removeAllInterfaceOptions(); | ||
204 | } | 203 | } |
205 | 204 | ||
206 | /** | 205 | /** |
207 | * Gets the hardware name of the interface that is currently selected. | 206 | * Gets the hardware name of the interface that is currently selected. |
208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 207 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
209 | * @param error set to true if any error occurs, false otherwise. | 208 | * @param error set to true if any error occurs, false otherwise. |
210 | */ | 209 | */ |
211 | QString Interfaces::getInterfaceName(bool &error){ | 210 | QString Interfaces::getInterfaceName(bool &error){ |
212 | if(currentIface == interfaces.end()){ | 211 | if(currentIface == interfaces.end()){ |
213 | error = true; | 212 | error = true; |
214 | return QString(); | 213 | return QString(); |
215 | } | 214 | } |
216 | QString line = (*currentIface); | 215 | QString line = (*currentIface); |
217 | line = line.mid(QString(IFACE).length() +1, line.length()); | 216 | line = line.mid(QString(IFACE).length() +1, line.length()); |
218 | line = line.simplifyWhiteSpace(); | 217 | line = line.simplifyWhiteSpace(); |
219 | int findSpace = line.find(" "); | 218 | int findSpace = line.find(" "); |
220 | if( findSpace < 0){ | 219 | if( findSpace < 0){ |
221 | error = true; | 220 | error = true; |
222 | return QString(); | 221 | return QString(); |
223 | } | 222 | } |
224 | error = false; | 223 | error = false; |
225 | return line.mid(0, findSpace); | 224 | return line.mid(0, findSpace); |
226 | } | 225 | } |
227 | 226 | ||
228 | /** | 227 | /** |
229 | * Gets the family name of the interface that is currently selected. | 228 | * Gets the family name of the interface that is currently selected. |
230 | * @return QString name of the family (inet, inet6, ipx). | 229 | * @return QString name of the family (inet, inet6, ipx). |
231 | * @param error set to true if any error occurs, false otherwise. | 230 | * @param error set to true if any error occurs, false otherwise. |
232 | */ | 231 | */ |
233 | QString Interfaces::getInterfaceFamily(bool &error){ | 232 | QString Interfaces::getInterfaceFamily(bool &error){ |
234 | QString name = getInterfaceName(error); | 233 | QString name = getInterfaceName(error); |
235 | if(error){ | 234 | if(error) |
236 | error = true; | ||
237 | return QString(); | 235 | return QString(); |
238 | } | ||
239 | QString line = (*currentIface); | 236 | QString line = (*currentIface); |
240 | line = line.mid(QString(IFACE).length() +1, line.length()); | 237 | line = line.mid(QString(IFACE).length() +1, line.length()); |
241 | line = line.mid(name.length()+1, line.length()); | 238 | line = line.mid(name.length()+1, line.length()); |
242 | line = line.simplifyWhiteSpace(); | 239 | line = line.simplifyWhiteSpace(); |
243 | int findSpace = line.find(" "); | 240 | int findSpace = line.find(" "); |
244 | if( findSpace < 0){ | 241 | if( findSpace < 0){ |
245 | error = true; | 242 | error = true; |
246 | return QString(); | 243 | return QString(); |
247 | } | 244 | } |
248 | error = false; | 245 | error = false; |
249 | return line.mid(0, findSpace); | 246 | return line.mid(0, findSpace); |
250 | } | 247 | } |
251 | 248 | ||
252 | /** | 249 | /** |
253 | * Gets the method of the interface that is currently selected. | 250 | * Gets the method of the interface that is currently selected. |
254 | * @return QString name of the method such as staic or dhcp. | 251 | * @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. | 252 | * 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. | 253 | * @param error set to true if any error occurs, false otherwise. |
257 | */ | 254 | */ |
258 | QString Interfaces::getInterfaceMethod(bool &error){ | 255 | QString Interfaces::getInterfaceMethod(bool &error){ |
259 | QString name = getInterfaceName(error); | 256 | QString name = getInterfaceName(error); |
260 | if(error){ | 257 | if(error) |
261 | error = true; | ||
262 | return QString(); | 258 | return QString(); |
263 | } | ||
264 | QString family = getInterfaceFamily(error); | 259 | QString family = getInterfaceFamily(error); |
265 | if(error){ | 260 | if(error) |
266 | error = true; | ||
267 | return QString(); | 261 | return QString(); |
268 | } | ||
269 | QString line = (*currentIface); | 262 | QString line = (*currentIface); |
270 | line = line.mid(QString(IFACE).length()+1, line.length()); | 263 | line = line.mid(QString(IFACE).length()+1, line.length()); |
271 | line = line.mid(name.length()+1, line.length()); | 264 | line = line.mid(name.length()+1, line.length()); |
272 | line = line.mid(family.length()+1, line.length()); | 265 | line = line.mid(family.length()+1, line.length()); |
273 | line = line.simplifyWhiteSpace(); | 266 | line = line.simplifyWhiteSpace(); |
274 | error = false; | 267 | error = false; |
275 | return line; | 268 | return line; |
276 | } | 269 | } |
277 | 270 | ||
278 | /** | 271 | /** |
279 | * Sets the interface name to newName. | 272 | * Sets the interface name to newName. |
280 | * @param newName the new name of the interface. All whitespace is removed. | 273 | * @param newName the new name of the interface. All whitespace is removed. |
281 | * @return bool true if successfull. | 274 | * @return bool true if successfull. |
282 | */ | 275 | */ |
283 | bool Interfaces::setInterfaceName(const QString &newName){ | 276 | bool Interfaces::setInterfaceName(const QString &newName){ |
284 | if(currentIface == interfaces.end()) | 277 | if(currentIface == interfaces.end()) |
285 | return false; | 278 | return false; |
286 | QString name = newName.simplifyWhiteSpace(); | 279 | QString name = newName.simplifyWhiteSpace(); |
287 | name = name.replace(QRegExp(" "), ""); | 280 | name = name.replace(QRegExp(" "), ""); |
288 | bool returnValue = false; | 281 | bool returnValue = false; |
289 | (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); | 282 | (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); |
290 | return !returnValue; | 283 | return !returnValue; |
291 | } | 284 | } |
292 | 285 | ||
293 | /** | 286 | /** |
294 | * Sets the interface family to newName. | 287 | * Sets the interface family to newName. |
295 | * @param newName the new name of the interface. Must be one of the families | 288 | * @param newName the new name of the interface. Must be one of the families |
296 | * defined in the interfaces.h file. | 289 | * defined in the interfaces.h file. |
297 | * @return bool true if successfull. | 290 | * @return bool true if successfull. |
298 | */ | 291 | */ |
299 | bool Interfaces::setInterfaceFamily(const QString &newName){ | 292 | bool Interfaces::setInterfaceFamily(const QString &newName){ |
300 | if(currentIface == interfaces.end()) | 293 | if(currentIface == interfaces.end()) |
301 | return false; | 294 | return false; |
302 | if(acceptedFamily.contains(newName)==0) | 295 | if(acceptedFamily.contains(newName)==0) |
303 | return false; | 296 | return false; |
304 | bool returnValue = false; | 297 | bool returnValue = false; |
305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | 298 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); |
306 | return !returnValue; | 299 | return !returnValue; |
307 | } | 300 | } |
308 | 301 | ||
309 | /** | 302 | /** |
310 | * Sets the interface method to newName | 303 | * Sets the interface method to newName |
311 | * @param newName the new name of the interface | 304 | * @param newName the new name of the interface |
312 | * @return bool true if successfull. | 305 | * @return bool true if successfull. |
313 | */ | 306 | */ |
314 | bool Interfaces::setInterfaceMethod(const QString &newName){ | 307 | bool Interfaces::setInterfaceMethod(const QString &newName){ |
315 | if(currentIface == interfaces.end()) | 308 | if(currentIface == interfaces.end()) |
316 | return false; | 309 | return false; |
317 | bool returnValue = false; | 310 | bool returnValue = false; |
318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | 311 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); |
319 | return !returnValue; | 312 | return !returnValue; |
320 | } | 313 | } |
321 | 314 | ||
322 | /** | 315 | /** |
323 | * Get a value for an option in the currently selected interface. For example | 316 | * Get a value for an option in the currently selected interface. For example |
324 | * calling getInterfaceOption("address") on the following stanza would | 317 | * calling getInterfaceOption("address") on the following stanza would |
325 | * return 192.168.1.1. | 318 | * return 192.168.1.1. |
326 | * iface eth0 static | 319 | * iface eth0 static |
327 | * address 192.168.1.1 | 320 | * address 192.168.1.1 |
328 | * @param option the options to get the value. | 321 | * @param option the options to get the value. |
329 | * @param error set to true if any error occurs, false otherwise. | 322 | * @param error set to true if any error occurs, false otherwise. |
330 | * @return QString the options value. QString::null if error == true | 323 | * @return QString the options value. QString::null if error == true |
331 | */ | 324 | */ |
332 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ | 325 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ |
333 | return getOption(currentIface, option, error); | 326 | return getOption(currentIface, option, error); |
334 | } | 327 | } |
335 | 328 | ||
336 | /** | 329 | /** |
337 | * Set a value for an option in the currently selected interface. If option | 330 | * 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. | 331 | * doesn't exist then it is added along with the value. |
339 | * @param option the options to set the value. | 332 | * @param option the options to set the value. |
340 | * @param value the value that option should be set to. | 333 | * @param value the value that option should be set to. |
341 | * @param error set to true if any error occurs, false otherwise. | 334 | * @param error set to true if any error occurs, false otherwise. |
342 | * @return QString the options value. QString::null if error == true | 335 | * @return QString the options value. QString::null if error == true |
343 | */ | 336 | */ |
344 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ | 337 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ |
345 | return setOption(currentIface, option, value); | 338 | return setOption(currentIface, option, value); |
346 | } | 339 | } |
347 | 340 | ||
348 | /** | 341 | /** |
349 | * Removes a value for an option in the currently selected interface. | 342 | * Removes a value for an option in the currently selected interface. |
350 | * @param option the options to set the value. | 343 | * @param option the options to set the value. |
351 | * @param value the value that option should be set to. | 344 | * @param value the value that option should be set to. |
352 | * @param error set to true if any error occurs, false otherwise. | 345 | * @param error set to true if any error occurs, false otherwise. |
353 | * @return QString the options value. QString::null if error == true | 346 | * @return QString the options value. QString::null if error == true |
354 | */ | 347 | */ |
355 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ | 348 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ |
356 | return removeOption(currentIface, option, value); | 349 | return removeOption(currentIface, option, value); |
357 | } | 350 | } |
358 | 351 | ||
359 | /** | 352 | /** |
360 | * Removes all of the options from the currently selected interface. | 353 | * Removes all of the options from the currently selected interface. |
361 | * @return bool error if if successfull | 354 | * @return bool error if if successfull |
362 | */ | 355 | */ |
363 | bool Interfaces::removeAllInterfaceOptions(){ | 356 | bool Interfaces::removeAllInterfaceOptions(){ |
364 | return removeAllOptions(currentIface); | 357 | return removeAllOptions(currentIface); |
365 | } | 358 | } |
366 | 359 | ||
367 | /** | 360 | /** |
368 | * Set the current map to interface's map. This needs to be done before you | 361 | * Set the current map to interface's map. This needs to be done before you |
369 | * can call addMapping(), set/getMap(), and get/setScript(). | 362 | * can call addMapping(), set/getMap(), and get/setScript(). |
370 | * @param interface the name of the interface to set. All whitespace is | 363 | * @param interface the name of the interface to set. All whitespace is |
371 | * removed from the interface name. | 364 | * removed from the interface name. |
372 | * @return bool true if it is successfull. | 365 | * @return bool true if it is successfull. |
373 | */ | 366 | */ |
374 | bool Interfaces::setMapping(const QString &interface){ | 367 | bool Interfaces::setMapping(const QString &interface){ |
375 | QString interfaceName = interface.simplifyWhiteSpace(); | 368 | QString interfaceName = interface.simplifyWhiteSpace(); |
376 | interfaceName = interfaceName.replace(QRegExp(" "), ""); | 369 | interfaceName = interfaceName.replace(QRegExp(" "), ""); |
377 | return setStanza(MAPPING, interfaceName, currentMapping); | 370 | return setStanza(MAPPING, interfaceName, currentMapping); |
378 | } | 371 | } |
379 | 372 | ||
380 | /** | 373 | /** |
381 | * Adds a new Mapping to the interfaces file with interfaces. | 374 | * Adds a new Mapping to the interfaces file with interfaces. |
382 | * @param interface the name(s) of the interfaces to set to this mapping | 375 | * @param interface the name(s) of the interfaces to set to this mapping |
383 | */ | 376 | */ |
384 | void Interfaces::addMapping(const QString &option){ | 377 | void Interfaces::addMapping(const QString &option){ |
385 | interfaces.append(""); | 378 | interfaces.append(""); |
386 | interfaces.append(QString(MAPPING " %1").arg(option)); | 379 | interfaces.append(QString(MAPPING " %1").arg(option)); |
387 | } | 380 | } |
388 | 381 | ||
389 | /** | 382 | /** |
390 | * Remove the currently selected map and all of its options. | 383 | * Remove the currently selected map and all of its options. |
391 | * @return bool if successfull or not. | 384 | * @return bool if successfull or not. |
392 | */ | 385 | */ |
393 | bool Interfaces::removeMapping(){ | 386 | bool Interfaces::removeMapping(){ |
394 | if(currentMapping == interfaces.end()) | 387 | return removeStanza(currentMapping); |
395 | return false; | ||
396 | (*currentMapping) = ""; | ||
397 | return removeAllOptions(currentMapping); | ||
398 | } | 388 | } |
399 | 389 | ||
400 | /** | 390 | /** |
401 | * Set a map option within a mapping. | 391 | * Set a map option within a mapping. |
402 | * @param map map to use | 392 | * @param map map to use |
403 | * @param value value to go with map | 393 | * @param value value to go with map |
404 | * @return bool true if it is successfull. | 394 | * @return bool true if it is successfull. |
405 | */ | 395 | */ |
406 | bool Interfaces::setMap(const QString &map, const QString &value){ | 396 | bool Interfaces::setMap(const QString &map, const QString &value){ |
407 | return setOption(currentMapping, map, value); | 397 | return setOption(currentMapping, map, value); |
408 | } | 398 | } |
409 | 399 | ||
410 | /** | 400 | /** |
411 | * Removes a map option within a mapping. | 401 | * Removes a map option within a mapping. |
412 | * @param map map to use | 402 | * @param map map to use |
413 | * @param value value to go with map | 403 | * @param value value to go with map |
414 | * @return bool true if it is successfull. | 404 | * @return bool true if it is successfull. |
415 | */ | 405 | */ |
416 | bool Interfaces::removeMap(const QString &map, const QString &value){ | 406 | bool Interfaces::removeMap(const QString &map, const QString &value){ |
417 | return removeOption(currentMapping, map, value); | 407 | return removeOption(currentMapping, map, value); |
418 | } | 408 | } |
419 | 409 | ||
420 | /** | 410 | /** |
421 | * Get a map value within a mapping. | 411 | * Get a map value within a mapping. |
422 | * @param map map to get value of | 412 | * @param map map to get value of |
423 | * @param bool true if it is successfull. | 413 | * @param bool true if it is successfull. |
424 | * @return value that goes to the map | 414 | * @return value that goes to the map |
425 | */ | 415 | */ |
426 | QString Interfaces::getMap(const QString &map, bool &error){ | 416 | QString Interfaces::getMap(const QString &map, bool &error){ |
427 | return getOption(currentMapping, map, error); | 417 | return getOption(currentMapping, map, error); |
428 | } | 418 | } |
429 | 419 | ||
430 | /** | 420 | /** |
431 | * Sets a script value of the current mapping to argument. | 421 | * Sets a script value of the current mapping to argument. |
432 | * @param argument the script name. | 422 | * @param argument the script name. |
433 | * @return true if successfull. | 423 | * @return true if successfull. |
434 | */ | 424 | */ |
435 | bool Interfaces::setScript(const QString &argument){ | 425 | bool Interfaces::setScript(const QString &argument){ |
436 | return setOption(currentMapping, "script", argument); | 426 | return setOption(currentMapping, "script", argument); |
437 | } | 427 | } |
438 | 428 | ||
439 | /** | 429 | /** |
440 | * @param error true if could not retrieve the current script argument. | 430 | * @param error true if could not retrieve the current script argument. |
441 | * @return QString the argument of the script for the current mapping. | 431 | * @return QString the argument of the script for the current mapping. |
442 | */ | 432 | */ |
443 | QString Interfaces::getScript(bool &error){ | 433 | QString Interfaces::getScript(bool &error){ |
444 | return getOption(currentMapping, "script", error); | 434 | return getOption(currentMapping, "script", error); |
445 | } | 435 | } |
446 | 436 | ||
447 | 437 | ||
448 | 438 | ||
449 | /** | 439 | /** |
450 | * Helper function used to parse through the QStringList and put pointers in | 440 | * Helper function used to parse through the QStringList and put pointers in |
451 | * the correct place. | 441 | * the correct place. |
452 | * @param stanza The stanza (auto, iface, mapping) to look for. | 442 | * @param stanza The stanza (auto, iface, mapping) to look for. |
453 | * @param option string that must be in the stanza's main line. | 443 | * @param option string that must be in the stanza's main line. |
454 | * @param interator interator to place at location of stanza if successfull. | 444 | * @param interator interator to place at location of stanza if successfull. |
455 | * @return bool true if the stanza is found. | 445 | * @return bool true if the stanza is found. |
456 | */ | 446 | */ |
457 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ | 447 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ |
458 | bool found = false; | 448 | bool found = false; |
459 | iterator = interfaces.end(); | 449 | iterator = interfaces.end(); |
460 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 450 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
461 | QString line = (*it).simplifyWhiteSpace(); | 451 | QString line = (*it).simplifyWhiteSpace(); |
462 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ | 452 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ |
463 | uint point = line.find(option); | 453 | uint point = line.find(option); |
464 | bool valid = true; | 454 | bool valid = true; |
465 | if(point > 0){ | 455 | if(point > 0){ |
466 | // There are more chars in the line. check +1 | 456 | // There are more chars in the line. check +1 |
467 | if(line.at(point-1) != ' ') | 457 | if(line.at(point-1) != ' ') |
468 | valid = false; | 458 | valid = false; |
469 | } | 459 | } |
470 | point += option.length(); | 460 | point += option.length(); |
471 | if(point < line.length()-1){ | 461 | if(point < line.length()-1){ |
472 | // There are more chars in the line. check -1 | 462 | // There are more chars in the line. check -1 |
473 | if(line.at(point) != ' ') | 463 | if(line.at(point) != ' ') |
474 | valid = false; | 464 | valid = false; |
475 | } | 465 | } |
476 | if(valid){ | 466 | if(valid){ |
477 | if(found == true){ | 467 | if(found == true){ |
478 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 468 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); |
479 | } | 469 | } |
480 | found = true; | 470 | found = true; |
481 | iterator = it; | 471 | iterator = it; |
482 | } | 472 | } |
483 | } | 473 | } |
484 | } | 474 | } |
485 | return found; | 475 | return found; |
486 | } | 476 | } |
487 | 477 | ||
488 | /** | 478 | /** |
489 | * Sets a value of an option in a stanza | 479 | * Sets a value of an option in a stanza |
490 | * @param start the start of the stanza | 480 | * @param start the start of the stanza |
491 | * @param option the option to use when setting value. | 481 | * @param option the option to use when setting value. |
492 | * @return bool true if successfull, false otherwise. | 482 | * @return bool true if successfull, false otherwise. |
493 | */ | 483 | */ |
494 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ | 484 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
495 | if(start == interfaces.end()) | 485 | if(start == interfaces.end()) |
496 | return false; | 486 | return false; |
497 | 487 | ||
498 | bool found = false; | 488 | bool found = false; |
499 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 489 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
500 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 490 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
501 | if(!found && value != ""){ | 491 | if(!found && value != ""){ |
502 | // Got to the end of the stanza without finding it, so append it. | 492 | // Got to the end of the stanza without finding it, so append it. |
503 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | 493 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); |
504 | } | 494 | } |
505 | found = true; | 495 | found = true; |
506 | break; | 496 | break; |
507 | } | 497 | } |
508 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 498 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
509 | // Found it in stanza so replace it. | 499 | // Found it in stanza so replace it. |
510 | if(found) | 500 | if(found) |
511 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 501 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
512 | found = true; | 502 | found = true; |
513 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 503 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
514 | } | 504 | } |
515 | } | 505 | } |
516 | if(!found){ | 506 | if(!found){ |
517 | QStringList::Iterator p = start; | 507 | QStringList::Iterator p = start; |
518 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 508 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
519 | found = true; | 509 | found = true; |
520 | } | 510 | } |
521 | return found; | 511 | return found; |
522 | } | 512 | } |
513 | |||
514 | /** | ||
515 | * Removes a stanza and all of its options | ||
516 | * @param stanza the stanza to remove | ||
517 | * @return bool true if successfull. | ||
518 | */ | ||
519 | bool Interfaces::removeStanza(QStringList::Iterator &stanza){ | ||
520 | if(stanza == interfaces.end()) | ||
521 | return false; | ||
522 | (*stanza) = ""; | ||
523 | return removeAllOptions(stanza); | ||
524 | } | ||
525 | |||
523 | /** | 526 | /** |
524 | * Removes a option in a stanza | 527 | * Removes a option in a stanza |
525 | * @param start the start of the stanza | 528 | * @param start the start of the stanza |
526 | * @param option the option to use when setting value. | 529 | * @param option the option to use when setting value. |
527 | * @return bool true if successfull, false otherwise. | 530 | * @return bool true if successfull, false otherwise. |
528 | */ | 531 | */ |
529 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ | 532 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
530 | if(start == interfaces.end()) | 533 | if(start == interfaces.end()) |
531 | return false; | 534 | return false; |
532 | 535 | ||
533 | bool found = false; | 536 | bool found = false; |
534 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 537 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
535 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 538 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
536 | // got to the end without finding it | 539 | // got to the end without finding it |
537 | break; | 540 | break; |
538 | } | 541 | } |
539 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 542 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
540 | // Found it in stanza so replace it. | 543 | // Found it in stanza so replace it. |
541 | if(found) | 544 | if(found) |
542 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 545 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
543 | found = true; | 546 | found = true; |
544 | (*it) = ""; | 547 | (*it) = ""; |
545 | } | 548 | } |
546 | } | 549 | } |
547 | return found; | 550 | return found; |
548 | } | 551 | } |
549 | 552 | ||
550 | /** | 553 | /** |
551 | * Removes all options in a stanza | 554 | * Removes all options in a stanza |
552 | * @param start the start of the stanza | 555 | * @param start the start of the stanza |
553 | * @return bool true if successfull, false otherwise. | 556 | * @return bool true if successfull, false otherwise. |
554 | */ | 557 | */ |
555 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ | 558 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ |
556 | if(start == interfaces.end()) | 559 | if(start == interfaces.end()) |
557 | return false; | 560 | return false; |
558 | 561 | ||
559 | QStringList::Iterator it = start; | 562 | QStringList::Iterator it = start; |
560 | it = ++it; | 563 | it = ++it; |
561 | for (; it != interfaces.end(); ++it ) { | 564 | for (; it != interfaces.end(); ++it ) { |
562 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 565 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
563 | break; | 566 | break; |
564 | } | 567 | } |
565 | it = interfaces.remove(it); | 568 | it = interfaces.remove(it); |
566 | it = --it; | 569 | it = --it; |
567 | } | 570 | } |
568 | // Leave a space between this interface and the next. | 571 | // Leave a space between this interface and the next. |
569 | interfaces.insert(it, QString("")); | 572 | interfaces.insert(it, QString("")); |
570 | return true; | 573 | return true; |
571 | } | 574 | } |
572 | 575 | ||
573 | /** | 576 | /** |
574 | * Gets a value of an option in a stanza | 577 | * Gets a value of an option in a stanza |
575 | * @param start the start of the stanza | 578 | * @param start the start of the stanza |
576 | * @param option the option to use when getting the value. | 579 | * @param option the option to use when getting the value. |
577 | * @param bool true if errors false otherwise. | 580 | * @param bool true if errors false otherwise. |
578 | * @return QString the value of option QString::null() if error == true. | 581 | * @return QString the value of option QString::null() if error == true. |
579 | */ | 582 | */ |
580 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ | 583 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ |
581 | if(start == interfaces.end()){ | 584 | if(start == interfaces.end()){ |
582 | error = false; | 585 | error = false; |
583 | return QString(); | 586 | return QString(); |
584 | } | 587 | } |
585 | 588 | ||
586 | QString value; | 589 | QString value; |
587 | bool found = false; | 590 | bool found = false; |
588 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 591 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
589 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 592 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
590 | break; | 593 | break; |
591 | } | 594 | } |
592 | if((*it).contains(option) && (*it).at(0) != '#'){ | 595 | if((*it).contains(option) && (*it).at(0) != '#'){ |
593 | if(found) | 596 | if(found) |
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()); | 597 | qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); |
595 | found = true; | 598 | found = true; |
596 | QString line = (*it).simplifyWhiteSpace(); | 599 | QString line = (*it).simplifyWhiteSpace(); |
597 | int space = line.find(" ", option.length()); | 600 | int space = line.find(" ", option.length()); |
598 | if(space != -1) | 601 | if(space != -1){ |
599 | value = line.mid(space+1, line.length()); | 602 | value = line.mid(space+1, line.length()); |
600 | else | 603 | break; |
601 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | 604 | } |
602 | } | 605 | } |
603 | } | 606 | } |
604 | error = !found; | 607 | error = !found; |
605 | return value; | 608 | return value; |
606 | } | 609 | } |
607 | 610 | ||
608 | /** | 611 | /** |
609 | * Write out the interfaces file to the file passed into the constructor. | 612 | * Write out the interfaces file to the file passed into the constructor. |
610 | * Removes any excess blank lines over 1 line long. | 613 | * Removes any excess blank lines over 1 line long. |
611 | * @return bool true if successfull, false if not. | 614 | * @return bool true if successfull, false if not. |
612 | */ | 615 | */ |
613 | bool Interfaces::write(){ | 616 | bool Interfaces::write(){ |
614 | QFile::remove(interfacesFile); | 617 | QFile::remove(interfacesFile); |
615 | QFile file(interfacesFile); | 618 | QFile file(interfacesFile); |
616 | 619 | ||
617 | if (!file.open(IO_ReadWrite)){ | 620 | if (!file.open(IO_ReadWrite)){ |
618 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | 621 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); |
619 | return false; | 622 | return false; |
620 | } | 623 | } |
621 | QTextStream stream( &file ); | 624 | QTextStream stream( &file ); |
622 | int whiteSpaceCount = 0; | 625 | int whiteSpaceCount = 0; |
623 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 626 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
624 | QString line = (*it).simplifyWhiteSpace(); | 627 | QString line = (*it).simplifyWhiteSpace(); |
625 | line = line.replace(QRegExp(" "),""); | 628 | line = line.replace(QRegExp(" "),""); |
626 | if(line.length() == 0) | 629 | if(line.length() == 0) |
627 | whiteSpaceCount++; | 630 | whiteSpaceCount++; |
628 | else | 631 | else |
629 | whiteSpaceCount = 0; | 632 | whiteSpaceCount = 0; |
630 | if(whiteSpaceCount < 2){ | 633 | if(whiteSpaceCount < 2){ |
631 | qDebug((*it).latin1()); | 634 | qDebug((*it).latin1()); |
632 | stream << (*it) << '\n'; | 635 | stream << (*it) << '\n'; |
633 | } | 636 | } |
634 | } | 637 | } |
635 | file.close(); | 638 | file.close(); |
636 | return true; | 639 | return true; |
637 | } | 640 | } |
638 | 641 | ||
639 | // interfaces.cpp | 642 | // interfaces.cpp |
640 | 643 | ||
diff --git a/noncore/net/networksetup/interfaces/interfaces.h b/noncore/net/networksetup/interfaces/interfaces.h index 26abb73..5a8feb6 100644 --- a/noncore/net/networksetup/interfaces/interfaces.h +++ b/noncore/net/networksetup/interfaces/interfaces.h | |||
@@ -1,76 +1,77 @@ | |||
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(const QString &interface); | 28 | bool isAuto(const QString &interface); |
29 | bool setAuto(const QString &interface, bool setAuto); | 29 | bool setAuto(const QString &interface, bool setAuto); |
30 | 30 | ||
31 | bool removeInterface(); | 31 | inline bool removeInterface(); |
32 | bool addInterface(const QString &interface, const QString &family, const QString &method); | 32 | bool addInterface(const QString &interface, const QString &family, const QString &method); |
33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); | 33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); |
34 | bool setInterface(QString interface); | 34 | bool setInterface(QString interface); |
35 | inline bool isInterfaceSet(); | 35 | inline bool isInterfaceSet(); |
36 | QString getInterfaceName(bool &error); | 36 | QString getInterfaceName(bool &error); |
37 | bool setInterfaceName(const QString &newName); | 37 | bool setInterfaceName(const QString &newName); |
38 | QString getInterfaceFamily(bool &error); | 38 | QString getInterfaceFamily(bool &error); |
39 | bool setInterfaceFamily(const QString &newName); | 39 | bool setInterfaceFamily(const QString &newName); |
40 | QString getInterfaceMethod(bool &error); | 40 | QString getInterfaceMethod(bool &error); |
41 | bool setInterfaceMethod(const QString &newName); | 41 | bool setInterfaceMethod(const QString &newName); |
42 | inline QString getInterfaceOption(const QString &option, bool &error); | 42 | inline QString getInterfaceOption(const QString &option, bool &error); |
43 | inline bool setInterfaceOption(const QString &option, const QString &value); | 43 | inline bool setInterfaceOption(const QString &option, const QString &value); |
44 | inline bool removeInterfaceOption(const QString &option, const QString &value); | 44 | inline bool removeInterfaceOption(const QString &option, const QString &value); |
45 | inline bool removeAllInterfaceOptions(); | 45 | inline bool removeAllInterfaceOptions(); |
46 | 46 | ||
47 | bool setMapping(const QString &interface); | 47 | bool setMapping(const QString &interface); |
48 | bool removeMapping(); | 48 | inline bool removeMapping(); |
49 | inline void addMapping(const QString &options); | 49 | inline void addMapping(const QString &options); |
50 | inline bool setMap(const QString &map, const QString &value); | 50 | inline bool setMap(const QString &map, const QString &value); |
51 | inline bool removeMap(const QString &map, const QString &value); | 51 | inline bool removeMap(const QString &map, const QString &value); |
52 | inline QString getMap(const QString &map, bool &error); | 52 | inline QString getMap(const QString &map, bool &error); |
53 | inline bool setScript(const QString &argument); | 53 | inline bool setScript(const QString &argument); |
54 | inline 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(const QString &stanza, const QString &option, QStringList::Iterator &iterator); | 59 | bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); |
60 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); | 60 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
61 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); | 61 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
62 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); | 62 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); |
63 | bool removeStanza(QStringList::Iterator &stanza); | ||
63 | bool removeAllOptions(const QStringList::Iterator &start); | 64 | bool removeAllOptions(const QStringList::Iterator &start); |
64 | 65 | ||
65 | QString interfacesFile; | 66 | QString interfacesFile; |
66 | QStringList interfaces; | 67 | QStringList interfaces; |
67 | QStringList::Iterator currentIface; | 68 | QStringList::Iterator currentIface; |
68 | QStringList::Iterator currentMapping; | 69 | QStringList::Iterator currentMapping; |
69 | 70 | ||
70 | QStringList acceptedFamily; | 71 | QStringList acceptedFamily; |
71 | }; | 72 | }; |
72 | 73 | ||
73 | #endif | 74 | #endif |
74 | 75 | ||
75 | // interfaces | 76 | // interfaces |
76 | 77 | ||
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp index 3b1a4de..4818e37 100644 --- a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp +++ b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp | |||
@@ -1,152 +1,145 @@ | |||
1 | #include "interfacesetupimp.h" | 1 | #include "interfacesetupimp.h" |
2 | #include "interface.h" | 2 | #include "interface.h" |
3 | #include "interfaces.h" | ||
4 | 3 | ||
5 | #include <qdialog.h> | ||
6 | #include <qcombobox.h> | ||
7 | #include <qcheckbox.h> | 4 | #include <qcheckbox.h> |
8 | #include <qlineedit.h> | 5 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 6 | #include <qspinbox.h> |
10 | #include <qgroupbox.h> | 7 | #include <qgroupbox.h> |
11 | #include <qlabel.h> | 8 | #include <qlabel.h> |
12 | 9 | ||
13 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
14 | 11 | ||
15 | #include <assert.h> | ||
16 | |||
17 | #define DNSSCRIPT "changedns" | 12 | #define DNSSCRIPT "changedns" |
18 | 13 | ||
19 | /** | 14 | /** |
20 | * Constuctor. Set up the connection and load the first profile. | 15 | * Constuctor. Set up the connection. A profile must be set. |
21 | */ | 16 | */ |
22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ | 17 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i){ |
23 | assert(parent); | ||
24 | assert(i); | ||
25 | interface = i; | ||
26 | interfaces = new Interfaces(); | ||
27 | bool error = false; | ||
28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
29 | staticGroupBox->hide(); | ||
30 | dhcpCheckBox->hide(); | ||
31 | leaseTime->hide(); | ||
32 | leaseHoursLabel->hide(); | ||
33 | } | ||
34 | } | 18 | } |
35 | 19 | ||
36 | /** | 20 | /** |
37 | * Save the current settings, then write out the interfaces file and close. | 21 | * Save the current settings, then write out the interfaces file and close. |
38 | */ | 22 | */ |
39 | bool InterfaceSetupImp::saveChanges(){ | 23 | bool InterfaceSetupImp::saveChanges(){ |
40 | if(!saveSettings()) | 24 | if(!saveSettings()) |
41 | return false; | 25 | return false; |
42 | interfaces->write(); | 26 | interfaces.write(); |
43 | return true; | 27 | return true; |
44 | } | 28 | } |
45 | 29 | ||
46 | /** | 30 | /** |
47 | * Save the settings for the current Interface. | 31 | * Save the settings for the current Interface. |
48 | * @return bool true if successfull, false otherwise | 32 | * @return bool true if successfull, false otherwise |
49 | */ | 33 | */ |
50 | bool InterfaceSetupImp::saveSettings(){ | 34 | bool InterfaceSetupImp::saveSettings(){ |
51 | // eh can't really do anything about it other then return. :-D | 35 | // eh can't really do anything about it other then return. :-D |
52 | if(!interfaces->isInterfaceSet()) | 36 | if(!interfaces.isInterfaceSet()) |
53 | return true; | 37 | return true; |
54 | 38 | ||
55 | bool error = false; | 39 | bool error = false; |
56 | // Loopback case | 40 | // Loopback case |
57 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 41 | if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
58 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 42 | interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
59 | return true; | 43 | return true; |
60 | } | 44 | } |
61 | 45 | ||
62 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ | 46 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ |
63 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); | 47 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); |
64 | return false; | 48 | return false; |
65 | } | 49 | } |
66 | interfaces->removeAllInterfaceOptions(); | 50 | interfaces.removeAllInterfaceOptions(); |
67 | 51 | ||
68 | // DHCP | 52 | // DHCP |
69 | if(dhcpCheckBox->isChecked()){ | 53 | if(dhcpCheckBox->isChecked()){ |
70 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 54 | interfaces.setInterfaceMethod(INTERFACES_METHOD_DHCP); |
71 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | 55 | interfaces.setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); |
72 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | 56 | interfaces.setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); |
73 | } | 57 | } |
74 | else{ | 58 | else{ |
75 | interfaces->setInterfaceMethod("static"); | 59 | interfaces.setInterfaceMethod("static"); |
76 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 60 | interfaces.setInterfaceOption("address", ipAddressEdit->text()); |
77 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 61 | interfaces.setInterfaceOption("netmask", subnetMaskEdit->text()); |
78 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 62 | interfaces.setInterfaceOption("gateway", gatewayEdit->text()); |
79 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ | 63 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ |
80 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 64 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
81 | interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); | 65 | interfaces.setInterfaceOption("up "DNSSCRIPT" -a ", dns); |
82 | interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); | 66 | interfaces.setInterfaceOption("down "DNSSCRIPT" -r ", dns); |
83 | } | 67 | } |
84 | } | 68 | } |
85 | 69 | ||
86 | // IP Information | 70 | // IP Information |
87 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 71 | interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
88 | return true; | 72 | return true; |
89 | } | 73 | } |
90 | 74 | ||
91 | /** | 75 | /** |
92 | * The Profile has changed. | 76 | * The Profile has changed. |
93 | * @profile the new profile. | 77 | * @param QString profile the new profile. |
94 | */ | 78 | */ |
95 | void InterfaceSetupImp::setProfile(const QString &profile){ | 79 | void InterfaceSetupImp::setProfile(const QString &profile){ |
80 | /* | ||
81 | bool error = false; | ||
82 | if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
83 | staticGroupBox->hide(); | ||
84 | dhcpCheckBox->hide(); | ||
85 | leaseTime->hide(); | ||
86 | leaseHoursLabel->hide(); | ||
87 | } | ||
88 | */ | ||
89 | |||
96 | QString newInterfaceName = interface->getInterfaceName(); | 90 | QString newInterfaceName = interface->getInterfaceName(); |
97 | if(profile.length() > 0) | 91 | if(profile.length() > 0) |
98 | newInterfaceName += "_" + profile; | 92 | newInterfaceName += "_" + profile; |
99 | qDebug("InterfaceSetupImp::setProfile"); | ||
100 | // See if we have to make a interface. | 93 | // See if we have to make a interface. |
101 | if(!interfaces->setInterface(newInterfaceName)){ | 94 | if(!interfaces.setInterface(newInterfaceName)){ |
102 | // Add making for this new interface if need too | 95 | // Add making for this new interface if need too |
103 | if(profile != ""){ | 96 | if(profile != ""){ |
104 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 97 | interfaces.copyInterface(interface->getInterfaceName(), newInterfaceName); |
105 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 98 | if(!interfaces.setMapping(interface->getInterfaceName())){ |
106 | interfaces->addMapping(interface->getInterfaceName()); | 99 | interfaces.addMapping(interface->getInterfaceName()); |
107 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 100 | if(!interfaces.setMapping(interface->getInterfaceName())){ |
108 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); | 101 | qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface."); |
109 | return; | 102 | return; |
110 | } | 103 | } |
111 | } | 104 | } |
112 | interfaces->setMap("map", newInterfaceName); | 105 | interfaces.setMap("map", newInterfaceName); |
113 | interfaces->setScript("getprofile.sh"); | 106 | interfaces.setScript("getprofile.sh"); |
114 | } | 107 | } |
115 | else{ | 108 | else{ |
116 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 109 | interfaces.addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
117 | if(!interfaces->setInterface(newInterfaceName)){ | 110 | if(!interfaces.setInterface(newInterfaceName)){ |
118 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | 111 | qDebug("InterfaceSetupImp: Added interface, but still can't setInterface."); |
119 | return; | 112 | return; |
120 | } | 113 | } |
121 | } | 114 | } |
122 | } | 115 | } |
123 | 116 | ||
124 | // We must have a valid interface to get this far so read some settings. | 117 | // We must have a valid interface to get this far so read some settings. |
125 | 118 | ||
126 | // DHCP | 119 | // DHCP |
127 | bool error = false; | 120 | bool error = false; |
128 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 121 | if(interfaces.getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
129 | dhcpCheckBox->setChecked(true); | 122 | dhcpCheckBox->setChecked(true); |
130 | else | 123 | else |
131 | dhcpCheckBox->setChecked(false); | 124 | dhcpCheckBox->setChecked(false); |
132 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | 125 | leaseTime->setValue(interfaces.getInterfaceOption("leasehours", error).toInt()); |
133 | if(error) | 126 | if(error) |
134 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | 127 | leaseTime->setValue(interfaces.getInterfaceOption("leasetime", error).toInt()/60/60); |
135 | if(error) | 128 | if(error) |
136 | leaseTime->setValue(24); | 129 | leaseTime->setValue(24); |
137 | 130 | ||
138 | // IP Information | 131 | // IP Information |
139 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 132 | autoStart->setChecked(interfaces.isAuto(interface->getInterfaceName())); |
140 | QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); | 133 | QString dns = interfaces.getInterfaceOption("up "DNSSCRIPT" -a", error); |
141 | if(dns.contains(" ")){ | 134 | if(dns.contains(" ")){ |
142 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 135 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
143 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 136 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
144 | } | 137 | } |
145 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 138 | ipAddressEdit->setText(interfaces.getInterfaceOption("address", error)); |
146 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 139 | subnetMaskEdit->setText(interfaces.getInterfaceOption("netmask", error)); |
147 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 140 | gatewayEdit->setText(interfaces.getInterfaceOption("gateway", error)); |
148 | } | ||
149 | 141 | ||
142 | } | ||
150 | 143 | ||
151 | // interfacesetup.cpp | 144 | // interfacesetup.cpp |
152 | 145 | ||
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.h b/noncore/net/networksetup/interfaces/interfacesetupimp.h index 60933aa..9ec526c 100644 --- a/noncore/net/networksetup/interfaces/interfacesetupimp.h +++ b/noncore/net/networksetup/interfaces/interfacesetupimp.h | |||
@@ -1,55 +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 "interfaces.h" | ||
5 | #include <qdialog.h> | 6 | #include <qdialog.h> |
6 | 7 | ||
7 | class Interface; | 8 | class Interface; |
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 | }; | 24 | }; |
25 | 25 | ||
26 | 26 | ||
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | 28 | ||
29 | class InterfaceSetupImpDialog : public QDialog { | 29 | class InterfaceSetupImpDialog : public QDialog { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | 31 | ||
32 | public: | 32 | public: |
33 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ | 33 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ |
34 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); | 34 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); |
35 | setCaption("Interface Setup"); | 35 | setCaption("Interface Setup"); |
36 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); | 36 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); |
37 | InterfaceSetupLayout->addWidget( interfaceSetup ); | 37 | InterfaceSetupLayout->addWidget( interfaceSetup ); |
38 | }; | 38 | }; |
39 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; | 39 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; |
40 | 40 | ||
41 | private: | 41 | private: |
42 | InterfaceSetupImp *interfaceSetup; | 42 | InterfaceSetupImp *interfaceSetup; |
43 | 43 | ||
44 | protected slots: | 44 | protected slots: |
45 | void accept(){ | 45 | void accept(){ |
46 | if(interfaceSetup->saveChanges()) | 46 | if(interfaceSetup->saveChanges()) |
47 | QDialog::accept(); | 47 | QDialog::accept(); |
48 | }; | 48 | }; |
49 | 49 | ||
50 | }; | 50 | }; |
51 | 51 | ||
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | // interfacesetupimp.h | 54 | // interfacesetupimp.h |
55 | 55 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index 708f399..e49998e 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp | |||
@@ -1,640 +1,643 @@ | |||
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 | // The three stanza's | ||
7 | #define AUTO "auto" | 8 | #define AUTO "auto" |
8 | #define IFACE "iface" | 9 | #define IFACE "iface" |
9 | #define MAPPING "mapping" | 10 | #define MAPPING "mapping" |
10 | 11 | ||
11 | /** | 12 | /** |
12 | * Constructor. Reads in the interfaces file and then split the file up by | 13 | * Constructor. Reads in the interfaces file and then split the file up by |
13 | * the \n for interfaces variable. | 14 | * the \n for interfaces variable. |
14 | * @param useInterfacesFile if an interface file other then the default is | 15 | * @param useInterfacesFile if an interface file other then the default is |
15 | * desired to be used it should be passed in. | 16 | * desired to be used it should be passed in. |
16 | */ | 17 | */ |
17 | Interfaces::Interfaces(QString useInterfacesFile){ | 18 | Interfaces::Interfaces(QString useInterfacesFile){ |
18 | acceptedFamily.append(INTERFACES_FAMILY_INET); | 19 | acceptedFamily.append(INTERFACES_FAMILY_INET); |
19 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | 20 | acceptedFamily.append(INTERFACES_FAMILY_IPX); |
20 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | 21 | acceptedFamily.append(INTERFACES_FAMILY_INET6); |
21 | 22 | ||
22 | interfacesFile = useInterfacesFile; | 23 | interfacesFile = useInterfacesFile; |
23 | QFile file(interfacesFile); | 24 | QFile file(interfacesFile); |
24 | if (!file.open(IO_ReadOnly)){ | 25 | if (!file.open(IO_ReadOnly)){ |
25 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); | 26 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); |
26 | currentIface = interfaces.end(); | 27 | currentIface = interfaces.end(); |
27 | currentMapping = interfaces.end(); | 28 | currentMapping = interfaces.end(); |
28 | return; | 29 | return; |
29 | } | 30 | } |
30 | QTextStream stream( &file ); | 31 | QTextStream stream( &file ); |
31 | QString line; | 32 | QString line; |
32 | while ( !stream.eof() ) { | 33 | while ( !stream.eof() ) { |
33 | line += stream.readLine(); | 34 | line += stream.readLine(); |
34 | line += "\n"; | 35 | line += "\n"; |
35 | } | 36 | } |
36 | file.close(); | 37 | file.close(); |
37 | interfaces = QStringList::split("\n", line, true); | 38 | interfaces = QStringList::split("\n", line, true); |
38 | 39 | ||
39 | currentIface = interfaces.end(); | 40 | currentIface = interfaces.end(); |
40 | currentMapping = interfaces.end(); | 41 | currentMapping = interfaces.end(); |
41 | } | 42 | } |
42 | 43 | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Get a list of all interfaces in the interface file. Usefull for | 46 | * Get a list of all interfaces in the interface file. Usefull for |
46 | * hardware that is not currently connected such as an 802.11b card | 47 | * hardware that is not currently connected such as an 802.11b card |
47 | * not plugged in, but configured for when it is plugged in. | 48 | * not plugged in, but configured for when it is plugged in. |
48 | * @return Return string list of interfaces. | 49 | * @return Return string list of interfaces. |
49 | **/ | 50 | **/ |
50 | QStringList Interfaces::getInterfaceList(){ | 51 | QStringList Interfaces::getInterfaceList(){ |
51 | QStringList list; | 52 | QStringList list; |
52 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 53 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
53 | QString line = (*it).simplifyWhiteSpace(); | 54 | QString line = (*it).simplifyWhiteSpace(); |
54 | if(line.contains(IFACE) && line.at(0) != '#'){ | 55 | if(line.contains(IFACE) && line.at(0) != '#'){ |
55 | line = line.mid(QString(IFACE).length() +1, line.length()); | 56 | line = line.mid(QString(IFACE).length() +1, line.length()); |
56 | line = line.simplifyWhiteSpace(); | 57 | line = line.simplifyWhiteSpace(); |
57 | int findSpace = line.find(" "); | 58 | int findSpace = line.find(" "); |
58 | if( findSpace >= 0){ | 59 | if( findSpace >= 0){ |
59 | line = line.mid(0, findSpace); | 60 | line = line.mid(0, findSpace); |
60 | list.append(line); | 61 | list.append(line); |
61 | } | 62 | } |
62 | } | 63 | } |
63 | } | 64 | } |
64 | return list; | 65 | return list; |
65 | } | 66 | } |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * Find out if interface is in an "auto" group or not. | 69 | * Find out if interface is in an "auto" group or not. |
69 | * Report any duplicates such as eth0 being in two differnt auto's | 70 | * Report any duplicates such as eth0 being in two differnt auto's |
70 | * @param interface interface to check to see if it is on or not. | 71 | * @param interface interface to check to see if it is on or not. |
71 | * @return true is interface is in auto | 72 | * @return true is interface is in auto |
72 | */ | 73 | */ |
73 | bool Interfaces::isAuto(const QString &interface){ | 74 | bool Interfaces::isAuto(const QString &interface){ |
74 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | 75 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); |
75 | QStringList awi = autoLines.grep(QRegExp(interface)); | 76 | QStringList awi = autoLines.grep(QRegExp(interface)); |
76 | if(awi.count() > 1) | 77 | if(awi.count() > 1) |
77 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); | 78 | qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); |
78 | if(awi.count() < 1) | 79 | if(awi.count() < 1) |
79 | return false; | 80 | return false; |
80 | return true; | 81 | return true; |
81 | } | 82 | } |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * Attempt to set the auto option for interface to setAuto. | 85 | * Attempt to set the auto option for interface to setAuto. |
85 | * @param interface the interface to set | 86 | * @param interface the interface to set |
86 | * @param setAuto the value to set interface to. | 87 | * @param setAuto the value to set interface to. |
87 | * @return false if already set to setAuto. | 88 | * @return false if already set to setAuto. |
88 | * */ | 89 | * */ |
89 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ | 90 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ |
90 | // Don't need to set it if it is already set. | 91 | // Don't need to set it if it is already set. |
91 | if(isAuto(interface) == setAuto) | 92 | if(isAuto(interface) == setAuto) |
92 | return false; | 93 | return false; |
93 | 94 | ||
94 | bool changed = false; | 95 | bool changed = false; |
95 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 96 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
96 | if((*it).contains(AUTO)){ | 97 | if((*it).contains(AUTO)){ |
97 | //We know that they are not in any group so let add to this auto. | 98 | //We know that they are not in any group so let add to this auto. |
98 | if(setAuto){ | 99 | if(setAuto){ |
99 | (*it) = (*it) += " " + interface; | 100 | (*it) = (*it) += " " + interface; |
100 | // Don't care to have such thins as: auto eth0 lo usb0 | 101 | // Don't care to have such thins as: auto eth0 lo usb0 |
101 | (*it) = (*it).simplifyWhiteSpace(); | 102 | (*it) = (*it).simplifyWhiteSpace(); |
102 | changed = true; | 103 | changed = true; |
103 | break; | 104 | break; |
104 | } | 105 | } |
106 | // else see if we need to remove from this one | ||
105 | else{ | 107 | else{ |
106 | if((*it).contains(interface)){ | 108 | if((*it).contains(interface)){ |
107 | (*it) = (*it).replace(QRegExp(interface), ""); | 109 | (*it) = (*it).replace(QRegExp(interface), ""); |
108 | // clean up | 110 | // if AUTO is the only thing left clear the line |
109 | QString line = (*it).simplifyWhiteSpace(); | 111 | if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) |
110 | line = line.replace(QRegExp(" "),""); | ||
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 | // In the case where there is no AUTO field add one. |
120 | if(setAuto == true) | 120 | if(!changed && setAuto) |
121 | interfaces.append(QString(AUTO" %1").arg(interface)); | 121 | interfaces.append(QString(AUTO" %1").arg(interface)); |
122 | else{ | ||
123 | qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); | ||
124 | } | ||
125 | } | ||
126 | return true; | 122 | return true; |
127 | } | 123 | } |
128 | 124 | ||
129 | /** | 125 | /** |
130 | * Set the current interface to interface. This needs to be done before you | 126 | * Set the current interface to interface. This needs to be done before you |
131 | * can call getFamily(), getMethod, and get/setOption(). | 127 | * can call getFamily(), getMethod, and get/setOption(). |
132 | * @param interface the name of the interface to set. All whitespace is | 128 | * @param interface the name of the interface to set. All whitespace is |
133 | * removed from the interface name. | 129 | * removed from the interface name. |
134 | * @return bool true if it is successfull. | 130 | * @return bool true if it is successfull. |
135 | */ | 131 | */ |
136 | bool Interfaces::setInterface(QString interface){ | 132 | bool Interfaces::setInterface(QString interface){ |
137 | interface = interface.simplifyWhiteSpace(); | 133 | interface = interface.simplifyWhiteSpace(); |
138 | interface = interface.replace(QRegExp(" "), ""); | 134 | interface = interface.replace(QRegExp(" "), ""); |
139 | return setStanza(IFACE, interface, currentIface); | 135 | return setStanza(IFACE, interface, currentIface); |
140 | } | 136 | } |
141 | 137 | ||
142 | /** | 138 | /** |
143 | * A quick helper funtion to see if the current interface is set. | 139 | * A quick helper funtion to see if the current interface is set. |
144 | * @return bool true if set, false otherwise. | 140 | * @return bool true if set, false otherwise. |
145 | */ | 141 | */ |
146 | bool Interfaces::isInterfaceSet(){ | 142 | bool Interfaces::isInterfaceSet(){ |
147 | return (currentIface != interfaces.end()); | 143 | return (currentIface != interfaces.end()); |
148 | } | 144 | } |
149 | 145 | ||
150 | /** | 146 | /** |
151 | * Add a new interface of with the settings - family and method | 147 | * Add a new interface of with the settings - family and method |
152 | * @param interface the name of the interface to set. All whitespace is | 148 | * @param interface the name of the interface to set. All whitespace is |
153 | * removed from the interface name. | 149 | * removed from the interface name. |
154 | * @param family the family of this interface inet or inet, ipx or inet6 | 150 | * @param family the family of this interface inet or inet, ipx or inet6 |
155 | * Must of one of the families defined in interfaces.h | 151 | * Must of one of the families defined in interfaces.h |
156 | * @param method for the family. see interfaces man page for family methods. | 152 | * @param method for the family. see interfaces man page for family methods. |
157 | * @return true if successfull. | 153 | * @return true if successfull. |
158 | */ | 154 | */ |
159 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ | 155 | bool Interfaces::addInterface(const QString &interface, const QString &family, const QString &method){ |
160 | if(acceptedFamily.contains(family)==0) | 156 | if(0 == acceptedFamily.contains(family)) |
161 | return false; | 157 | return false; |
162 | QString newInterface = interface.simplifyWhiteSpace(); | 158 | QString newInterface = interface.simplifyWhiteSpace(); |
163 | newInterface = newInterface.replace(QRegExp(" "), ""); | 159 | newInterface = newInterface.replace(QRegExp(" "), ""); |
164 | interfaces.append(""); | 160 | interfaces.append(""); |
165 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); | 161 | interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).arg(family).arg(method)); |
166 | return true; | 162 | return true; |
167 | } | 163 | } |
168 | 164 | ||
169 | /** | 165 | /** |
170 | * Copies interface with name interface to name newInterface | 166 | * Copies interface with name interface to name newInterface |
171 | * @param newInterface name of the new interface. | 167 | * @param newInterface name of the new interface. |
172 | * @return bool true if successfull | 168 | * @return bool true if successfull |
173 | */ | 169 | */ |
174 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ | 170 | bool Interfaces::copyInterface(const QString &interface, const QString &newInterface){ |
175 | if(!setInterface(interface)) return false; | 171 | if(!setInterface(interface)) |
176 | 172 | return false; | |
173 | |||
174 | // Store the old interface and bump past the stanza line. | ||
177 | QStringList::Iterator it = currentIface; | 175 | QStringList::Iterator it = currentIface; |
178 | it++; | 176 | it++; |
179 | 177 | ||
178 | // Add the new interface | ||
180 | bool error; | 179 | bool error; |
181 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); | 180 | addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); |
182 | if(!setInterface(newInterface)) return false; | 181 | if(!setInterface(newInterface)) |
182 | return false; | ||
183 | |||
183 | QStringList::Iterator newIface = currentIface; | 184 | QStringList::Iterator newIface = currentIface; |
184 | newIface++; | 185 | newIface++; |
185 | 186 | ||
187 | // Copy all of the lines | ||
186 | for ( ; it != interfaces.end(); ++it ){ | 188 | for ( ; it != interfaces.end(); ++it ){ |
187 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) | 189 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) |
188 | break; | 190 | break; |
189 | newIface = interfaces.insert(newIface, *it); | 191 | newIface = interfaces.insert(newIface, *it); |
190 | } | 192 | } |
191 | 193 | ||
192 | return true; | 194 | return true; |
193 | } | 195 | } |
194 | 196 | ||
195 | /** | 197 | /** |
196 | * Remove the currently selected interface and all of its options. | 198 | * Remove the currently selected interface and all of its options. |
197 | * @return bool if successfull or not. | 199 | * @return bool if successfull or not. |
198 | */ | 200 | */ |
199 | bool Interfaces::removeInterface(){ | 201 | bool Interfaces::removeInterface(){ |
200 | if(currentIface == interfaces.end()) | 202 | return removeStanza(currentIface); |
201 | return false; | ||
202 | (*currentIface) = ""; | ||
203 | return removeAllInterfaceOptions(); | ||
204 | } | 203 | } |
205 | 204 | ||
206 | /** | 205 | /** |
207 | * Gets the hardware name of the interface that is currently selected. | 206 | * Gets the hardware name of the interface that is currently selected. |
208 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). | 207 | * @return QString name of the hardware interface (eth0, usb2, wlan1...). |
209 | * @param error set to true if any error occurs, false otherwise. | 208 | * @param error set to true if any error occurs, false otherwise. |
210 | */ | 209 | */ |
211 | QString Interfaces::getInterfaceName(bool &error){ | 210 | QString Interfaces::getInterfaceName(bool &error){ |
212 | if(currentIface == interfaces.end()){ | 211 | if(currentIface == interfaces.end()){ |
213 | error = true; | 212 | error = true; |
214 | return QString(); | 213 | return QString(); |
215 | } | 214 | } |
216 | QString line = (*currentIface); | 215 | QString line = (*currentIface); |
217 | line = line.mid(QString(IFACE).length() +1, line.length()); | 216 | line = line.mid(QString(IFACE).length() +1, line.length()); |
218 | line = line.simplifyWhiteSpace(); | 217 | line = line.simplifyWhiteSpace(); |
219 | int findSpace = line.find(" "); | 218 | int findSpace = line.find(" "); |
220 | if( findSpace < 0){ | 219 | if( findSpace < 0){ |
221 | error = true; | 220 | error = true; |
222 | return QString(); | 221 | return QString(); |
223 | } | 222 | } |
224 | error = false; | 223 | error = false; |
225 | return line.mid(0, findSpace); | 224 | return line.mid(0, findSpace); |
226 | } | 225 | } |
227 | 226 | ||
228 | /** | 227 | /** |
229 | * Gets the family name of the interface that is currently selected. | 228 | * Gets the family name of the interface that is currently selected. |
230 | * @return QString name of the family (inet, inet6, ipx). | 229 | * @return QString name of the family (inet, inet6, ipx). |
231 | * @param error set to true if any error occurs, false otherwise. | 230 | * @param error set to true if any error occurs, false otherwise. |
232 | */ | 231 | */ |
233 | QString Interfaces::getInterfaceFamily(bool &error){ | 232 | QString Interfaces::getInterfaceFamily(bool &error){ |
234 | QString name = getInterfaceName(error); | 233 | QString name = getInterfaceName(error); |
235 | if(error){ | 234 | if(error) |
236 | error = true; | ||
237 | return QString(); | 235 | return QString(); |
238 | } | ||
239 | QString line = (*currentIface); | 236 | QString line = (*currentIface); |
240 | line = line.mid(QString(IFACE).length() +1, line.length()); | 237 | line = line.mid(QString(IFACE).length() +1, line.length()); |
241 | line = line.mid(name.length()+1, line.length()); | 238 | line = line.mid(name.length()+1, line.length()); |
242 | line = line.simplifyWhiteSpace(); | 239 | line = line.simplifyWhiteSpace(); |
243 | int findSpace = line.find(" "); | 240 | int findSpace = line.find(" "); |
244 | if( findSpace < 0){ | 241 | if( findSpace < 0){ |
245 | error = true; | 242 | error = true; |
246 | return QString(); | 243 | return QString(); |
247 | } | 244 | } |
248 | error = false; | 245 | error = false; |
249 | return line.mid(0, findSpace); | 246 | return line.mid(0, findSpace); |
250 | } | 247 | } |
251 | 248 | ||
252 | /** | 249 | /** |
253 | * Gets the method of the interface that is currently selected. | 250 | * Gets the method of the interface that is currently selected. |
254 | * @return QString name of the method such as staic or dhcp. | 251 | * @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. | 252 | * 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. | 253 | * @param error set to true if any error occurs, false otherwise. |
257 | */ | 254 | */ |
258 | QString Interfaces::getInterfaceMethod(bool &error){ | 255 | QString Interfaces::getInterfaceMethod(bool &error){ |
259 | QString name = getInterfaceName(error); | 256 | QString name = getInterfaceName(error); |
260 | if(error){ | 257 | if(error) |
261 | error = true; | ||
262 | return QString(); | 258 | return QString(); |
263 | } | ||
264 | QString family = getInterfaceFamily(error); | 259 | QString family = getInterfaceFamily(error); |
265 | if(error){ | 260 | if(error) |
266 | error = true; | ||
267 | return QString(); | 261 | return QString(); |
268 | } | ||
269 | QString line = (*currentIface); | 262 | QString line = (*currentIface); |
270 | line = line.mid(QString(IFACE).length()+1, line.length()); | 263 | line = line.mid(QString(IFACE).length()+1, line.length()); |
271 | line = line.mid(name.length()+1, line.length()); | 264 | line = line.mid(name.length()+1, line.length()); |
272 | line = line.mid(family.length()+1, line.length()); | 265 | line = line.mid(family.length()+1, line.length()); |
273 | line = line.simplifyWhiteSpace(); | 266 | line = line.simplifyWhiteSpace(); |
274 | error = false; | 267 | error = false; |
275 | return line; | 268 | return line; |
276 | } | 269 | } |
277 | 270 | ||
278 | /** | 271 | /** |
279 | * Sets the interface name to newName. | 272 | * Sets the interface name to newName. |
280 | * @param newName the new name of the interface. All whitespace is removed. | 273 | * @param newName the new name of the interface. All whitespace is removed. |
281 | * @return bool true if successfull. | 274 | * @return bool true if successfull. |
282 | */ | 275 | */ |
283 | bool Interfaces::setInterfaceName(const QString &newName){ | 276 | bool Interfaces::setInterfaceName(const QString &newName){ |
284 | if(currentIface == interfaces.end()) | 277 | if(currentIface == interfaces.end()) |
285 | return false; | 278 | return false; |
286 | QString name = newName.simplifyWhiteSpace(); | 279 | QString name = newName.simplifyWhiteSpace(); |
287 | name = name.replace(QRegExp(" "), ""); | 280 | name = name.replace(QRegExp(" "), ""); |
288 | bool returnValue = false; | 281 | bool returnValue = false; |
289 | (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); | 282 | (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); |
290 | return !returnValue; | 283 | return !returnValue; |
291 | } | 284 | } |
292 | 285 | ||
293 | /** | 286 | /** |
294 | * Sets the interface family to newName. | 287 | * Sets the interface family to newName. |
295 | * @param newName the new name of the interface. Must be one of the families | 288 | * @param newName the new name of the interface. Must be one of the families |
296 | * defined in the interfaces.h file. | 289 | * defined in the interfaces.h file. |
297 | * @return bool true if successfull. | 290 | * @return bool true if successfull. |
298 | */ | 291 | */ |
299 | bool Interfaces::setInterfaceFamily(const QString &newName){ | 292 | bool Interfaces::setInterfaceFamily(const QString &newName){ |
300 | if(currentIface == interfaces.end()) | 293 | if(currentIface == interfaces.end()) |
301 | return false; | 294 | return false; |
302 | if(acceptedFamily.contains(newName)==0) | 295 | if(acceptedFamily.contains(newName)==0) |
303 | return false; | 296 | return false; |
304 | bool returnValue = false; | 297 | bool returnValue = false; |
305 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); | 298 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); |
306 | return !returnValue; | 299 | return !returnValue; |
307 | } | 300 | } |
308 | 301 | ||
309 | /** | 302 | /** |
310 | * Sets the interface method to newName | 303 | * Sets the interface method to newName |
311 | * @param newName the new name of the interface | 304 | * @param newName the new name of the interface |
312 | * @return bool true if successfull. | 305 | * @return bool true if successfull. |
313 | */ | 306 | */ |
314 | bool Interfaces::setInterfaceMethod(const QString &newName){ | 307 | bool Interfaces::setInterfaceMethod(const QString &newName){ |
315 | if(currentIface == interfaces.end()) | 308 | if(currentIface == interfaces.end()) |
316 | return false; | 309 | return false; |
317 | bool returnValue = false; | 310 | bool returnValue = false; |
318 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); | 311 | (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); |
319 | return !returnValue; | 312 | return !returnValue; |
320 | } | 313 | } |
321 | 314 | ||
322 | /** | 315 | /** |
323 | * Get a value for an option in the currently selected interface. For example | 316 | * Get a value for an option in the currently selected interface. For example |
324 | * calling getInterfaceOption("address") on the following stanza would | 317 | * calling getInterfaceOption("address") on the following stanza would |
325 | * return 192.168.1.1. | 318 | * return 192.168.1.1. |
326 | * iface eth0 static | 319 | * iface eth0 static |
327 | * address 192.168.1.1 | 320 | * address 192.168.1.1 |
328 | * @param option the options to get the value. | 321 | * @param option the options to get the value. |
329 | * @param error set to true if any error occurs, false otherwise. | 322 | * @param error set to true if any error occurs, false otherwise. |
330 | * @return QString the options value. QString::null if error == true | 323 | * @return QString the options value. QString::null if error == true |
331 | */ | 324 | */ |
332 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ | 325 | QString Interfaces::getInterfaceOption(const QString &option, bool &error){ |
333 | return getOption(currentIface, option, error); | 326 | return getOption(currentIface, option, error); |
334 | } | 327 | } |
335 | 328 | ||
336 | /** | 329 | /** |
337 | * Set a value for an option in the currently selected interface. If option | 330 | * 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. | 331 | * doesn't exist then it is added along with the value. |
339 | * @param option the options to set the value. | 332 | * @param option the options to set the value. |
340 | * @param value the value that option should be set to. | 333 | * @param value the value that option should be set to. |
341 | * @param error set to true if any error occurs, false otherwise. | 334 | * @param error set to true if any error occurs, false otherwise. |
342 | * @return QString the options value. QString::null if error == true | 335 | * @return QString the options value. QString::null if error == true |
343 | */ | 336 | */ |
344 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ | 337 | bool Interfaces::setInterfaceOption(const QString &option, const QString &value){ |
345 | return setOption(currentIface, option, value); | 338 | return setOption(currentIface, option, value); |
346 | } | 339 | } |
347 | 340 | ||
348 | /** | 341 | /** |
349 | * Removes a value for an option in the currently selected interface. | 342 | * Removes a value for an option in the currently selected interface. |
350 | * @param option the options to set the value. | 343 | * @param option the options to set the value. |
351 | * @param value the value that option should be set to. | 344 | * @param value the value that option should be set to. |
352 | * @param error set to true if any error occurs, false otherwise. | 345 | * @param error set to true if any error occurs, false otherwise. |
353 | * @return QString the options value. QString::null if error == true | 346 | * @return QString the options value. QString::null if error == true |
354 | */ | 347 | */ |
355 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ | 348 | bool Interfaces::removeInterfaceOption(const QString &option, const QString &value){ |
356 | return removeOption(currentIface, option, value); | 349 | return removeOption(currentIface, option, value); |
357 | } | 350 | } |
358 | 351 | ||
359 | /** | 352 | /** |
360 | * Removes all of the options from the currently selected interface. | 353 | * Removes all of the options from the currently selected interface. |
361 | * @return bool error if if successfull | 354 | * @return bool error if if successfull |
362 | */ | 355 | */ |
363 | bool Interfaces::removeAllInterfaceOptions(){ | 356 | bool Interfaces::removeAllInterfaceOptions(){ |
364 | return removeAllOptions(currentIface); | 357 | return removeAllOptions(currentIface); |
365 | } | 358 | } |
366 | 359 | ||
367 | /** | 360 | /** |
368 | * Set the current map to interface's map. This needs to be done before you | 361 | * Set the current map to interface's map. This needs to be done before you |
369 | * can call addMapping(), set/getMap(), and get/setScript(). | 362 | * can call addMapping(), set/getMap(), and get/setScript(). |
370 | * @param interface the name of the interface to set. All whitespace is | 363 | * @param interface the name of the interface to set. All whitespace is |
371 | * removed from the interface name. | 364 | * removed from the interface name. |
372 | * @return bool true if it is successfull. | 365 | * @return bool true if it is successfull. |
373 | */ | 366 | */ |
374 | bool Interfaces::setMapping(const QString &interface){ | 367 | bool Interfaces::setMapping(const QString &interface){ |
375 | QString interfaceName = interface.simplifyWhiteSpace(); | 368 | QString interfaceName = interface.simplifyWhiteSpace(); |
376 | interfaceName = interfaceName.replace(QRegExp(" "), ""); | 369 | interfaceName = interfaceName.replace(QRegExp(" "), ""); |
377 | return setStanza(MAPPING, interfaceName, currentMapping); | 370 | return setStanza(MAPPING, interfaceName, currentMapping); |
378 | } | 371 | } |
379 | 372 | ||
380 | /** | 373 | /** |
381 | * Adds a new Mapping to the interfaces file with interfaces. | 374 | * Adds a new Mapping to the interfaces file with interfaces. |
382 | * @param interface the name(s) of the interfaces to set to this mapping | 375 | * @param interface the name(s) of the interfaces to set to this mapping |
383 | */ | 376 | */ |
384 | void Interfaces::addMapping(const QString &option){ | 377 | void Interfaces::addMapping(const QString &option){ |
385 | interfaces.append(""); | 378 | interfaces.append(""); |
386 | interfaces.append(QString(MAPPING " %1").arg(option)); | 379 | interfaces.append(QString(MAPPING " %1").arg(option)); |
387 | } | 380 | } |
388 | 381 | ||
389 | /** | 382 | /** |
390 | * Remove the currently selected map and all of its options. | 383 | * Remove the currently selected map and all of its options. |
391 | * @return bool if successfull or not. | 384 | * @return bool if successfull or not. |
392 | */ | 385 | */ |
393 | bool Interfaces::removeMapping(){ | 386 | bool Interfaces::removeMapping(){ |
394 | if(currentMapping == interfaces.end()) | 387 | return removeStanza(currentMapping); |
395 | return false; | ||
396 | (*currentMapping) = ""; | ||
397 | return removeAllOptions(currentMapping); | ||
398 | } | 388 | } |
399 | 389 | ||
400 | /** | 390 | /** |
401 | * Set a map option within a mapping. | 391 | * Set a map option within a mapping. |
402 | * @param map map to use | 392 | * @param map map to use |
403 | * @param value value to go with map | 393 | * @param value value to go with map |
404 | * @return bool true if it is successfull. | 394 | * @return bool true if it is successfull. |
405 | */ | 395 | */ |
406 | bool Interfaces::setMap(const QString &map, const QString &value){ | 396 | bool Interfaces::setMap(const QString &map, const QString &value){ |
407 | return setOption(currentMapping, map, value); | 397 | return setOption(currentMapping, map, value); |
408 | } | 398 | } |
409 | 399 | ||
410 | /** | 400 | /** |
411 | * Removes a map option within a mapping. | 401 | * Removes a map option within a mapping. |
412 | * @param map map to use | 402 | * @param map map to use |
413 | * @param value value to go with map | 403 | * @param value value to go with map |
414 | * @return bool true if it is successfull. | 404 | * @return bool true if it is successfull. |
415 | */ | 405 | */ |
416 | bool Interfaces::removeMap(const QString &map, const QString &value){ | 406 | bool Interfaces::removeMap(const QString &map, const QString &value){ |
417 | return removeOption(currentMapping, map, value); | 407 | return removeOption(currentMapping, map, value); |
418 | } | 408 | } |
419 | 409 | ||
420 | /** | 410 | /** |
421 | * Get a map value within a mapping. | 411 | * Get a map value within a mapping. |
422 | * @param map map to get value of | 412 | * @param map map to get value of |
423 | * @param bool true if it is successfull. | 413 | * @param bool true if it is successfull. |
424 | * @return value that goes to the map | 414 | * @return value that goes to the map |
425 | */ | 415 | */ |
426 | QString Interfaces::getMap(const QString &map, bool &error){ | 416 | QString Interfaces::getMap(const QString &map, bool &error){ |
427 | return getOption(currentMapping, map, error); | 417 | return getOption(currentMapping, map, error); |
428 | } | 418 | } |
429 | 419 | ||
430 | /** | 420 | /** |
431 | * Sets a script value of the current mapping to argument. | 421 | * Sets a script value of the current mapping to argument. |
432 | * @param argument the script name. | 422 | * @param argument the script name. |
433 | * @return true if successfull. | 423 | * @return true if successfull. |
434 | */ | 424 | */ |
435 | bool Interfaces::setScript(const QString &argument){ | 425 | bool Interfaces::setScript(const QString &argument){ |
436 | return setOption(currentMapping, "script", argument); | 426 | return setOption(currentMapping, "script", argument); |
437 | } | 427 | } |
438 | 428 | ||
439 | /** | 429 | /** |
440 | * @param error true if could not retrieve the current script argument. | 430 | * @param error true if could not retrieve the current script argument. |
441 | * @return QString the argument of the script for the current mapping. | 431 | * @return QString the argument of the script for the current mapping. |
442 | */ | 432 | */ |
443 | QString Interfaces::getScript(bool &error){ | 433 | QString Interfaces::getScript(bool &error){ |
444 | return getOption(currentMapping, "script", error); | 434 | return getOption(currentMapping, "script", error); |
445 | } | 435 | } |
446 | 436 | ||
447 | 437 | ||
448 | 438 | ||
449 | /** | 439 | /** |
450 | * Helper function used to parse through the QStringList and put pointers in | 440 | * Helper function used to parse through the QStringList and put pointers in |
451 | * the correct place. | 441 | * the correct place. |
452 | * @param stanza The stanza (auto, iface, mapping) to look for. | 442 | * @param stanza The stanza (auto, iface, mapping) to look for. |
453 | * @param option string that must be in the stanza's main line. | 443 | * @param option string that must be in the stanza's main line. |
454 | * @param interator interator to place at location of stanza if successfull. | 444 | * @param interator interator to place at location of stanza if successfull. |
455 | * @return bool true if the stanza is found. | 445 | * @return bool true if the stanza is found. |
456 | */ | 446 | */ |
457 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ | 447 | bool Interfaces::setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator){ |
458 | bool found = false; | 448 | bool found = false; |
459 | iterator = interfaces.end(); | 449 | iterator = interfaces.end(); |
460 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 450 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
461 | QString line = (*it).simplifyWhiteSpace(); | 451 | QString line = (*it).simplifyWhiteSpace(); |
462 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ | 452 | if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ |
463 | uint point = line.find(option); | 453 | uint point = line.find(option); |
464 | bool valid = true; | 454 | bool valid = true; |
465 | if(point > 0){ | 455 | if(point > 0){ |
466 | // There are more chars in the line. check +1 | 456 | // There are more chars in the line. check +1 |
467 | if(line.at(point-1) != ' ') | 457 | if(line.at(point-1) != ' ') |
468 | valid = false; | 458 | valid = false; |
469 | } | 459 | } |
470 | point += option.length(); | 460 | point += option.length(); |
471 | if(point < line.length()-1){ | 461 | if(point < line.length()-1){ |
472 | // There are more chars in the line. check -1 | 462 | // There are more chars in the line. check -1 |
473 | if(line.at(point) != ' ') | 463 | if(line.at(point) != ' ') |
474 | valid = false; | 464 | valid = false; |
475 | } | 465 | } |
476 | if(valid){ | 466 | if(valid){ |
477 | if(found == true){ | 467 | if(found == true){ |
478 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); | 468 | qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); |
479 | } | 469 | } |
480 | found = true; | 470 | found = true; |
481 | iterator = it; | 471 | iterator = it; |
482 | } | 472 | } |
483 | } | 473 | } |
484 | } | 474 | } |
485 | return found; | 475 | return found; |
486 | } | 476 | } |
487 | 477 | ||
488 | /** | 478 | /** |
489 | * Sets a value of an option in a stanza | 479 | * Sets a value of an option in a stanza |
490 | * @param start the start of the stanza | 480 | * @param start the start of the stanza |
491 | * @param option the option to use when setting value. | 481 | * @param option the option to use when setting value. |
492 | * @return bool true if successfull, false otherwise. | 482 | * @return bool true if successfull, false otherwise. |
493 | */ | 483 | */ |
494 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ | 484 | bool Interfaces::setOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
495 | if(start == interfaces.end()) | 485 | if(start == interfaces.end()) |
496 | return false; | 486 | return false; |
497 | 487 | ||
498 | bool found = false; | 488 | bool found = false; |
499 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 489 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
500 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 490 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
501 | if(!found && value != ""){ | 491 | if(!found && value != ""){ |
502 | // Got to the end of the stanza without finding it, so append it. | 492 | // Got to the end of the stanza without finding it, so append it. |
503 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); | 493 | interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); |
504 | } | 494 | } |
505 | found = true; | 495 | found = true; |
506 | break; | 496 | break; |
507 | } | 497 | } |
508 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ | 498 | if((*it).contains(option) && it != start && (*it).at(0) != '#'){ |
509 | // Found it in stanza so replace it. | 499 | // Found it in stanza so replace it. |
510 | if(found) | 500 | if(found) |
511 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 501 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
512 | found = true; | 502 | found = true; |
513 | (*it) = QString("\t%1 %2").arg(option).arg(value); | 503 | (*it) = QString("\t%1 %2").arg(option).arg(value); |
514 | } | 504 | } |
515 | } | 505 | } |
516 | if(!found){ | 506 | if(!found){ |
517 | QStringList::Iterator p = start; | 507 | QStringList::Iterator p = start; |
518 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); | 508 | interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); |
519 | found = true; | 509 | found = true; |
520 | } | 510 | } |
521 | return found; | 511 | return found; |
522 | } | 512 | } |
513 | |||
514 | /** | ||
515 | * Removes a stanza and all of its options | ||
516 | * @param stanza the stanza to remove | ||
517 | * @return bool true if successfull. | ||
518 | */ | ||
519 | bool Interfaces::removeStanza(QStringList::Iterator &stanza){ | ||
520 | if(stanza == interfaces.end()) | ||
521 | return false; | ||
522 | (*stanza) = ""; | ||
523 | return removeAllOptions(stanza); | ||
524 | } | ||
525 | |||
523 | /** | 526 | /** |
524 | * Removes a option in a stanza | 527 | * Removes a option in a stanza |
525 | * @param start the start of the stanza | 528 | * @param start the start of the stanza |
526 | * @param option the option to use when setting value. | 529 | * @param option the option to use when setting value. |
527 | * @return bool true if successfull, false otherwise. | 530 | * @return bool true if successfull, false otherwise. |
528 | */ | 531 | */ |
529 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ | 532 | bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option, const QString &value){ |
530 | if(start == interfaces.end()) | 533 | if(start == interfaces.end()) |
531 | return false; | 534 | return false; |
532 | 535 | ||
533 | bool found = false; | 536 | bool found = false; |
534 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 537 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
535 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 538 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
536 | // got to the end without finding it | 539 | // got to the end without finding it |
537 | break; | 540 | break; |
538 | } | 541 | } |
539 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ | 542 | if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ |
540 | // Found it in stanza so replace it. | 543 | // Found it in stanza so replace it. |
541 | if(found) | 544 | if(found) |
542 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); | 545 | qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); |
543 | found = true; | 546 | found = true; |
544 | (*it) = ""; | 547 | (*it) = ""; |
545 | } | 548 | } |
546 | } | 549 | } |
547 | return found; | 550 | return found; |
548 | } | 551 | } |
549 | 552 | ||
550 | /** | 553 | /** |
551 | * Removes all options in a stanza | 554 | * Removes all options in a stanza |
552 | * @param start the start of the stanza | 555 | * @param start the start of the stanza |
553 | * @return bool true if successfull, false otherwise. | 556 | * @return bool true if successfull, false otherwise. |
554 | */ | 557 | */ |
555 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ | 558 | bool Interfaces::removeAllOptions(const QStringList::Iterator &start){ |
556 | if(start == interfaces.end()) | 559 | if(start == interfaces.end()) |
557 | return false; | 560 | return false; |
558 | 561 | ||
559 | QStringList::Iterator it = start; | 562 | QStringList::Iterator it = start; |
560 | it = ++it; | 563 | it = ++it; |
561 | for (; it != interfaces.end(); ++it ) { | 564 | for (; it != interfaces.end(); ++it ) { |
562 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 565 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
563 | break; | 566 | break; |
564 | } | 567 | } |
565 | it = interfaces.remove(it); | 568 | it = interfaces.remove(it); |
566 | it = --it; | 569 | it = --it; |
567 | } | 570 | } |
568 | // Leave a space between this interface and the next. | 571 | // Leave a space between this interface and the next. |
569 | interfaces.insert(it, QString("")); | 572 | interfaces.insert(it, QString("")); |
570 | return true; | 573 | return true; |
571 | } | 574 | } |
572 | 575 | ||
573 | /** | 576 | /** |
574 | * Gets a value of an option in a stanza | 577 | * Gets a value of an option in a stanza |
575 | * @param start the start of the stanza | 578 | * @param start the start of the stanza |
576 | * @param option the option to use when getting the value. | 579 | * @param option the option to use when getting the value. |
577 | * @param bool true if errors false otherwise. | 580 | * @param bool true if errors false otherwise. |
578 | * @return QString the value of option QString::null() if error == true. | 581 | * @return QString the value of option QString::null() if error == true. |
579 | */ | 582 | */ |
580 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ | 583 | QString Interfaces::getOption(const QStringList::Iterator &start, const QString &option, bool &error){ |
581 | if(start == interfaces.end()){ | 584 | if(start == interfaces.end()){ |
582 | error = false; | 585 | error = false; |
583 | return QString(); | 586 | return QString(); |
584 | } | 587 | } |
585 | 588 | ||
586 | QString value; | 589 | QString value; |
587 | bool found = false; | 590 | bool found = false; |
588 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { | 591 | for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { |
589 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ | 592 | if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ |
590 | break; | 593 | break; |
591 | } | 594 | } |
592 | if((*it).contains(option) && (*it).at(0) != '#'){ | 595 | if((*it).contains(option) && (*it).at(0) != '#'){ |
593 | if(found) | 596 | if(found) |
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()); | 597 | qDebug(QString("Interfaces: getOption found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); |
595 | found = true; | 598 | found = true; |
596 | QString line = (*it).simplifyWhiteSpace(); | 599 | QString line = (*it).simplifyWhiteSpace(); |
597 | int space = line.find(" ", option.length()); | 600 | int space = line.find(" ", option.length()); |
598 | if(space != -1) | 601 | if(space != -1){ |
599 | value = line.mid(space+1, line.length()); | 602 | value = line.mid(space+1, line.length()); |
600 | else | 603 | break; |
601 | qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); | 604 | } |
602 | } | 605 | } |
603 | } | 606 | } |
604 | error = !found; | 607 | error = !found; |
605 | return value; | 608 | return value; |
606 | } | 609 | } |
607 | 610 | ||
608 | /** | 611 | /** |
609 | * Write out the interfaces file to the file passed into the constructor. | 612 | * Write out the interfaces file to the file passed into the constructor. |
610 | * Removes any excess blank lines over 1 line long. | 613 | * Removes any excess blank lines over 1 line long. |
611 | * @return bool true if successfull, false if not. | 614 | * @return bool true if successfull, false if not. |
612 | */ | 615 | */ |
613 | bool Interfaces::write(){ | 616 | bool Interfaces::write(){ |
614 | QFile::remove(interfacesFile); | 617 | QFile::remove(interfacesFile); |
615 | QFile file(interfacesFile); | 618 | QFile file(interfacesFile); |
616 | 619 | ||
617 | if (!file.open(IO_ReadWrite)){ | 620 | if (!file.open(IO_ReadWrite)){ |
618 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); | 621 | qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); |
619 | return false; | 622 | return false; |
620 | } | 623 | } |
621 | QTextStream stream( &file ); | 624 | QTextStream stream( &file ); |
622 | int whiteSpaceCount = 0; | 625 | int whiteSpaceCount = 0; |
623 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 626 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
624 | QString line = (*it).simplifyWhiteSpace(); | 627 | QString line = (*it).simplifyWhiteSpace(); |
625 | line = line.replace(QRegExp(" "),""); | 628 | line = line.replace(QRegExp(" "),""); |
626 | if(line.length() == 0) | 629 | if(line.length() == 0) |
627 | whiteSpaceCount++; | 630 | whiteSpaceCount++; |
628 | else | 631 | else |
629 | whiteSpaceCount = 0; | 632 | whiteSpaceCount = 0; |
630 | if(whiteSpaceCount < 2){ | 633 | if(whiteSpaceCount < 2){ |
631 | qDebug((*it).latin1()); | 634 | qDebug((*it).latin1()); |
632 | stream << (*it) << '\n'; | 635 | stream << (*it) << '\n'; |
633 | } | 636 | } |
634 | } | 637 | } |
635 | file.close(); | 638 | file.close(); |
636 | return true; | 639 | return true; |
637 | } | 640 | } |
638 | 641 | ||
639 | // interfaces.cpp | 642 | // interfaces.cpp |
640 | 643 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfaces.h b/noncore/settings/networksettings/interfaces/interfaces.h index 26abb73..5a8feb6 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.h +++ b/noncore/settings/networksettings/interfaces/interfaces.h | |||
@@ -1,76 +1,77 @@ | |||
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(const QString &interface); | 28 | bool isAuto(const QString &interface); |
29 | bool setAuto(const QString &interface, bool setAuto); | 29 | bool setAuto(const QString &interface, bool setAuto); |
30 | 30 | ||
31 | bool removeInterface(); | 31 | inline bool removeInterface(); |
32 | bool addInterface(const QString &interface, const QString &family, const QString &method); | 32 | bool addInterface(const QString &interface, const QString &family, const QString &method); |
33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); | 33 | bool copyInterface(const QString &oldInterface, const QString &newInterface); |
34 | bool setInterface(QString interface); | 34 | bool setInterface(QString interface); |
35 | inline bool isInterfaceSet(); | 35 | inline bool isInterfaceSet(); |
36 | QString getInterfaceName(bool &error); | 36 | QString getInterfaceName(bool &error); |
37 | bool setInterfaceName(const QString &newName); | 37 | bool setInterfaceName(const QString &newName); |
38 | QString getInterfaceFamily(bool &error); | 38 | QString getInterfaceFamily(bool &error); |
39 | bool setInterfaceFamily(const QString &newName); | 39 | bool setInterfaceFamily(const QString &newName); |
40 | QString getInterfaceMethod(bool &error); | 40 | QString getInterfaceMethod(bool &error); |
41 | bool setInterfaceMethod(const QString &newName); | 41 | bool setInterfaceMethod(const QString &newName); |
42 | inline QString getInterfaceOption(const QString &option, bool &error); | 42 | inline QString getInterfaceOption(const QString &option, bool &error); |
43 | inline bool setInterfaceOption(const QString &option, const QString &value); | 43 | inline bool setInterfaceOption(const QString &option, const QString &value); |
44 | inline bool removeInterfaceOption(const QString &option, const QString &value); | 44 | inline bool removeInterfaceOption(const QString &option, const QString &value); |
45 | inline bool removeAllInterfaceOptions(); | 45 | inline bool removeAllInterfaceOptions(); |
46 | 46 | ||
47 | bool setMapping(const QString &interface); | 47 | bool setMapping(const QString &interface); |
48 | bool removeMapping(); | 48 | inline bool removeMapping(); |
49 | inline void addMapping(const QString &options); | 49 | inline void addMapping(const QString &options); |
50 | inline bool setMap(const QString &map, const QString &value); | 50 | inline bool setMap(const QString &map, const QString &value); |
51 | inline bool removeMap(const QString &map, const QString &value); | 51 | inline bool removeMap(const QString &map, const QString &value); |
52 | inline QString getMap(const QString &map, bool &error); | 52 | inline QString getMap(const QString &map, bool &error); |
53 | inline bool setScript(const QString &argument); | 53 | inline bool setScript(const QString &argument); |
54 | inline 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(const QString &stanza, const QString &option, QStringList::Iterator &iterator); | 59 | bool setStanza(const QString &stanza, const QString &option, QStringList::Iterator &iterator); |
60 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); | 60 | bool setOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
61 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); | 61 | bool removeOption(const QStringList::Iterator &start, const QString &option, const QString &value); |
62 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); | 62 | QString getOption(const QStringList::Iterator &start, const QString &option, bool &error); |
63 | bool removeStanza(QStringList::Iterator &stanza); | ||
63 | bool removeAllOptions(const QStringList::Iterator &start); | 64 | bool removeAllOptions(const QStringList::Iterator &start); |
64 | 65 | ||
65 | QString interfacesFile; | 66 | QString interfacesFile; |
66 | QStringList interfaces; | 67 | QStringList interfaces; |
67 | QStringList::Iterator currentIface; | 68 | QStringList::Iterator currentIface; |
68 | QStringList::Iterator currentMapping; | 69 | QStringList::Iterator currentMapping; |
69 | 70 | ||
70 | QStringList acceptedFamily; | 71 | QStringList acceptedFamily; |
71 | }; | 72 | }; |
72 | 73 | ||
73 | #endif | 74 | #endif |
74 | 75 | ||
75 | // interfaces | 76 | // interfaces |
76 | 77 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp index 3b1a4de..4818e37 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp | |||
@@ -1,152 +1,145 @@ | |||
1 | #include "interfacesetupimp.h" | 1 | #include "interfacesetupimp.h" |
2 | #include "interface.h" | 2 | #include "interface.h" |
3 | #include "interfaces.h" | ||
4 | 3 | ||
5 | #include <qdialog.h> | ||
6 | #include <qcombobox.h> | ||
7 | #include <qcheckbox.h> | 4 | #include <qcheckbox.h> |
8 | #include <qlineedit.h> | 5 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 6 | #include <qspinbox.h> |
10 | #include <qgroupbox.h> | 7 | #include <qgroupbox.h> |
11 | #include <qlabel.h> | 8 | #include <qlabel.h> |
12 | 9 | ||
13 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
14 | 11 | ||
15 | #include <assert.h> | ||
16 | |||
17 | #define DNSSCRIPT "changedns" | 12 | #define DNSSCRIPT "changedns" |
18 | 13 | ||
19 | /** | 14 | /** |
20 | * Constuctor. Set up the connection and load the first profile. | 15 | * Constuctor. Set up the connection. A profile must be set. |
21 | */ | 16 | */ |
22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ | 17 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i){ |
23 | assert(parent); | ||
24 | assert(i); | ||
25 | interface = i; | ||
26 | interfaces = new Interfaces(); | ||
27 | bool error = false; | ||
28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
29 | staticGroupBox->hide(); | ||
30 | dhcpCheckBox->hide(); | ||
31 | leaseTime->hide(); | ||
32 | leaseHoursLabel->hide(); | ||
33 | } | ||
34 | } | 18 | } |
35 | 19 | ||
36 | /** | 20 | /** |
37 | * Save the current settings, then write out the interfaces file and close. | 21 | * Save the current settings, then write out the interfaces file and close. |
38 | */ | 22 | */ |
39 | bool InterfaceSetupImp::saveChanges(){ | 23 | bool InterfaceSetupImp::saveChanges(){ |
40 | if(!saveSettings()) | 24 | if(!saveSettings()) |
41 | return false; | 25 | return false; |
42 | interfaces->write(); | 26 | interfaces.write(); |
43 | return true; | 27 | return true; |
44 | } | 28 | } |
45 | 29 | ||
46 | /** | 30 | /** |
47 | * Save the settings for the current Interface. | 31 | * Save the settings for the current Interface. |
48 | * @return bool true if successfull, false otherwise | 32 | * @return bool true if successfull, false otherwise |
49 | */ | 33 | */ |
50 | bool InterfaceSetupImp::saveSettings(){ | 34 | bool InterfaceSetupImp::saveSettings(){ |
51 | // eh can't really do anything about it other then return. :-D | 35 | // eh can't really do anything about it other then return. :-D |
52 | if(!interfaces->isInterfaceSet()) | 36 | if(!interfaces.isInterfaceSet()) |
53 | return true; | 37 | return true; |
54 | 38 | ||
55 | bool error = false; | 39 | bool error = false; |
56 | // Loopback case | 40 | // Loopback case |
57 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 41 | if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
58 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 42 | interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
59 | return true; | 43 | return true; |
60 | } | 44 | } |
61 | 45 | ||
62 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ | 46 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ |
63 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); | 47 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); |
64 | return false; | 48 | return false; |
65 | } | 49 | } |
66 | interfaces->removeAllInterfaceOptions(); | 50 | interfaces.removeAllInterfaceOptions(); |
67 | 51 | ||
68 | // DHCP | 52 | // DHCP |
69 | if(dhcpCheckBox->isChecked()){ | 53 | if(dhcpCheckBox->isChecked()){ |
70 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 54 | interfaces.setInterfaceMethod(INTERFACES_METHOD_DHCP); |
71 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | 55 | interfaces.setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); |
72 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | 56 | interfaces.setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); |
73 | } | 57 | } |
74 | else{ | 58 | else{ |
75 | interfaces->setInterfaceMethod("static"); | 59 | interfaces.setInterfaceMethod("static"); |
76 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 60 | interfaces.setInterfaceOption("address", ipAddressEdit->text()); |
77 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 61 | interfaces.setInterfaceOption("netmask", subnetMaskEdit->text()); |
78 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 62 | interfaces.setInterfaceOption("gateway", gatewayEdit->text()); |
79 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ | 63 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ |
80 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 64 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
81 | interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); | 65 | interfaces.setInterfaceOption("up "DNSSCRIPT" -a ", dns); |
82 | interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); | 66 | interfaces.setInterfaceOption("down "DNSSCRIPT" -r ", dns); |
83 | } | 67 | } |
84 | } | 68 | } |
85 | 69 | ||
86 | // IP Information | 70 | // IP Information |
87 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 71 | interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
88 | return true; | 72 | return true; |
89 | } | 73 | } |
90 | 74 | ||
91 | /** | 75 | /** |
92 | * The Profile has changed. | 76 | * The Profile has changed. |
93 | * @profile the new profile. | 77 | * @param QString profile the new profile. |
94 | */ | 78 | */ |
95 | void InterfaceSetupImp::setProfile(const QString &profile){ | 79 | void InterfaceSetupImp::setProfile(const QString &profile){ |
80 | /* | ||
81 | bool error = false; | ||
82 | if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
83 | staticGroupBox->hide(); | ||
84 | dhcpCheckBox->hide(); | ||
85 | leaseTime->hide(); | ||
86 | leaseHoursLabel->hide(); | ||
87 | } | ||
88 | */ | ||
89 | |||
96 | QString newInterfaceName = interface->getInterfaceName(); | 90 | QString newInterfaceName = interface->getInterfaceName(); |
97 | if(profile.length() > 0) | 91 | if(profile.length() > 0) |
98 | newInterfaceName += "_" + profile; | 92 | newInterfaceName += "_" + profile; |
99 | qDebug("InterfaceSetupImp::setProfile"); | ||
100 | // See if we have to make a interface. | 93 | // See if we have to make a interface. |
101 | if(!interfaces->setInterface(newInterfaceName)){ | 94 | if(!interfaces.setInterface(newInterfaceName)){ |
102 | // Add making for this new interface if need too | 95 | // Add making for this new interface if need too |
103 | if(profile != ""){ | 96 | if(profile != ""){ |
104 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 97 | interfaces.copyInterface(interface->getInterfaceName(), newInterfaceName); |
105 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 98 | if(!interfaces.setMapping(interface->getInterfaceName())){ |
106 | interfaces->addMapping(interface->getInterfaceName()); | 99 | interfaces.addMapping(interface->getInterfaceName()); |
107 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 100 | if(!interfaces.setMapping(interface->getInterfaceName())){ |
108 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); | 101 | qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface."); |
109 | return; | 102 | return; |
110 | } | 103 | } |
111 | } | 104 | } |
112 | interfaces->setMap("map", newInterfaceName); | 105 | interfaces.setMap("map", newInterfaceName); |
113 | interfaces->setScript("getprofile.sh"); | 106 | interfaces.setScript("getprofile.sh"); |
114 | } | 107 | } |
115 | else{ | 108 | else{ |
116 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 109 | interfaces.addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
117 | if(!interfaces->setInterface(newInterfaceName)){ | 110 | if(!interfaces.setInterface(newInterfaceName)){ |
118 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | 111 | qDebug("InterfaceSetupImp: Added interface, but still can't setInterface."); |
119 | return; | 112 | return; |
120 | } | 113 | } |
121 | } | 114 | } |
122 | } | 115 | } |
123 | 116 | ||
124 | // We must have a valid interface to get this far so read some settings. | 117 | // We must have a valid interface to get this far so read some settings. |
125 | 118 | ||
126 | // DHCP | 119 | // DHCP |
127 | bool error = false; | 120 | bool error = false; |
128 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 121 | if(interfaces.getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
129 | dhcpCheckBox->setChecked(true); | 122 | dhcpCheckBox->setChecked(true); |
130 | else | 123 | else |
131 | dhcpCheckBox->setChecked(false); | 124 | dhcpCheckBox->setChecked(false); |
132 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | 125 | leaseTime->setValue(interfaces.getInterfaceOption("leasehours", error).toInt()); |
133 | if(error) | 126 | if(error) |
134 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | 127 | leaseTime->setValue(interfaces.getInterfaceOption("leasetime", error).toInt()/60/60); |
135 | if(error) | 128 | if(error) |
136 | leaseTime->setValue(24); | 129 | leaseTime->setValue(24); |
137 | 130 | ||
138 | // IP Information | 131 | // IP Information |
139 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 132 | autoStart->setChecked(interfaces.isAuto(interface->getInterfaceName())); |
140 | QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); | 133 | QString dns = interfaces.getInterfaceOption("up "DNSSCRIPT" -a", error); |
141 | if(dns.contains(" ")){ | 134 | if(dns.contains(" ")){ |
142 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 135 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
143 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 136 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
144 | } | 137 | } |
145 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 138 | ipAddressEdit->setText(interfaces.getInterfaceOption("address", error)); |
146 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 139 | subnetMaskEdit->setText(interfaces.getInterfaceOption("netmask", error)); |
147 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 140 | gatewayEdit->setText(interfaces.getInterfaceOption("gateway", error)); |
148 | } | ||
149 | 141 | ||
142 | } | ||
150 | 143 | ||
151 | // interfacesetup.cpp | 144 | // interfacesetup.cpp |
152 | 145 | ||
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.h b/noncore/settings/networksettings/interfaces/interfacesetupimp.h index 60933aa..9ec526c 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.h +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.h | |||
@@ -1,55 +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 "interfaces.h" | ||
5 | #include <qdialog.h> | 6 | #include <qdialog.h> |
6 | 7 | ||
7 | class Interface; | 8 | class Interface; |
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 | }; | 24 | }; |
25 | 25 | ||
26 | 26 | ||
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | 28 | ||
29 | class InterfaceSetupImpDialog : public QDialog { | 29 | class InterfaceSetupImpDialog : public QDialog { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | 31 | ||
32 | public: | 32 | public: |
33 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ | 33 | InterfaceSetupImpDialog(QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = false, WFlags fl = 0) : QDialog(parent, name, modal, fl){ |
34 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); | 34 | QVBoxLayout *InterfaceSetupLayout = new QVBoxLayout( this ); |
35 | setCaption("Interface Setup"); | 35 | setCaption("Interface Setup"); |
36 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); | 36 | interfaceSetup = new InterfaceSetupImp(this, "InterfaceSetup",i,fl); |
37 | InterfaceSetupLayout->addWidget( interfaceSetup ); | 37 | InterfaceSetupLayout->addWidget( interfaceSetup ); |
38 | }; | 38 | }; |
39 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; | 39 | void setProfile(QString &profile){ interfaceSetup->setProfile(profile);}; |
40 | 40 | ||
41 | private: | 41 | private: |
42 | InterfaceSetupImp *interfaceSetup; | 42 | InterfaceSetupImp *interfaceSetup; |
43 | 43 | ||
44 | protected slots: | 44 | protected slots: |
45 | void accept(){ | 45 | void accept(){ |
46 | if(interfaceSetup->saveChanges()) | 46 | if(interfaceSetup->saveChanges()) |
47 | QDialog::accept(); | 47 | QDialog::accept(); |
48 | }; | 48 | }; |
49 | 49 | ||
50 | }; | 50 | }; |
51 | 51 | ||
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | // interfacesetupimp.h | 54 | // interfacesetupimp.h |
55 | 55 | ||