-rw-r--r-- | noncore/settings/networksettings/interfaces/interfaces.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index 8d3e151..a62a90c 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp | |||
@@ -10,33 +10,33 @@ | |||
10 | #define MAPPING "mapping" | 10 | #define MAPPING "mapping" |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * 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 |
14 | * the \n for interfaces variable. | 14 | * the \n for interfaces variable. |
15 | * @param useInterfacesFile if an interface file other then the default is | 15 | * @param useInterfacesFile if an interface file other then the default is |
16 | * desired to be used it should be passed in. | 16 | * desired to be used it should be passed in. |
17 | */ | 17 | */ |
18 | Interfaces::Interfaces(QString useInterfacesFile){ | 18 | Interfaces::Interfaces(QString useInterfacesFile){ |
19 | acceptedFamily.append(INTERFACES_FAMILY_INET); | 19 | acceptedFamily.append(INTERFACES_FAMILY_INET); |
20 | acceptedFamily.append(INTERFACES_FAMILY_IPX); | 20 | acceptedFamily.append(INTERFACES_FAMILY_IPX); |
21 | acceptedFamily.append(INTERFACES_FAMILY_INET6); | 21 | acceptedFamily.append(INTERFACES_FAMILY_INET6); |
22 | 22 | ||
23 | interfacesFile = useInterfacesFile; | 23 | interfacesFile = useInterfacesFile; |
24 | QFile file(interfacesFile); | 24 | QFile file(interfacesFile); |
25 | if (!file.open(IO_ReadOnly)){ | 25 | if (!file.open(IO_ReadOnly)){ |
26 | qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); | 26 | qDebug("Interfaces: Can't open file: %s for reading.", interfacesFile.latin1() ); |
27 | currentIface = interfaces.end(); | 27 | currentIface = interfaces.end(); |
28 | currentMapping = interfaces.end(); | 28 | currentMapping = interfaces.end(); |
29 | return; | 29 | return; |
30 | } | 30 | } |
31 | QTextStream stream( &file ); | 31 | QTextStream stream( &file ); |
32 | QString line; | 32 | QString line; |
33 | while ( !stream.eof() ) { | 33 | while ( !stream.eof() ) { |
34 | line += stream.readLine(); | 34 | line += stream.readLine(); |
35 | line += "\n"; | 35 | line += "\n"; |
36 | } | 36 | } |
37 | file.close(); | 37 | file.close(); |
38 | interfaces = QStringList::split("\n", line, true); | 38 | interfaces = QStringList::split("\n", line, true); |
39 | 39 | ||
40 | currentIface = interfaces.end(); | 40 | currentIface = interfaces.end(); |
41 | currentMapping = interfaces.end(); | 41 | currentMapping = interfaces.end(); |
42 | } | 42 | } |
@@ -54,44 +54,42 @@ QStringList Interfaces::getInterfaceList(){ | |||
54 | QString line = (*it).simplifyWhiteSpace(); | 54 | QString line = (*it).simplifyWhiteSpace(); |
55 | if(line.contains(IFACE) && line.at(0) != '#'){ | 55 | if(line.contains(IFACE) && line.at(0) != '#'){ |
56 | line = line.mid(QString(IFACE).length() +1, line.length()); | 56 | line = line.mid(QString(IFACE).length() +1, line.length()); |
57 | line = line.simplifyWhiteSpace(); | 57 | line = line.simplifyWhiteSpace(); |
58 | int findSpace = line.find(" "); | 58 | int findSpace = line.find(" "); |
59 | if( findSpace >= 0){ | 59 | if( findSpace >= 0){ |
60 | line = line.mid(0, findSpace); | 60 | line = line.mid(0, findSpace); |
61 | list.append(line); | 61 | list.append(line); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | } | 64 | } |
65 | return list; | 65 | return list; |
66 | } | 66 | } |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Find out if interface is in an "auto" group or not. | 69 | * Find out if interface is in an "auto" group or not. |
70 | * 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 |
71 | * @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. |
72 | * @return true is interface is in auto | 72 | * @return true is interface is in auto |
73 | */ | 73 | */ |
74 | bool Interfaces::isAuto(const QString &interface) const { | 74 | bool Interfaces::isAuto(const QString &interface) const { |
75 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); | 75 | QStringList autoLines = interfaces.grep(QRegExp(AUTO)); |
76 | QStringList awi = autoLines.grep(QRegExp(interface)); | 76 | QStringList awi = autoLines.grep(QRegExp(interface)); |
77 | if(awi.count() > 1) | 77 | if(awi.count() > 1) |
78 | 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()); |
79 | if(awi.count() < 1) | 79 | return awi.count() > 0; |
80 | return false; | ||
81 | return true; | ||
82 | } | 80 | } |
83 | 81 | ||
84 | /** | 82 | /** |
85 | * Attempt to set the auto option for interface to setAuto. | 83 | * Attempt to set the auto option for interface to setAuto. |
86 | * @param interface the interface to set | 84 | * @param interface the interface to set |
87 | * @param setAuto the value to set interface to. | 85 | * @param setAuto the value to set interface to. |
88 | * @return false if already set to setAuto. | 86 | * @return false if already set to setAuto. |
89 | * */ | 87 | * */ |
90 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ | 88 | bool Interfaces::setAuto(const QString &interface, bool setAuto){ |
91 | // Don't need to set it if it is already set. | 89 | // Don't need to set it if it is already set. |
92 | if(isAuto(interface) == setAuto) | 90 | if(isAuto(interface) == setAuto) |
93 | return false; | 91 | return false; |
94 | 92 | ||
95 | bool changed = false; | 93 | bool changed = false; |
96 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { | 94 | for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { |
97 | if((*it).contains(AUTO)){ | 95 | if((*it).contains(AUTO)){ |