author | benmeyer <benmeyer> | 2002-10-18 18:12:53 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-18 18:12:53 (UTC) |
commit | a63b3b36cf4d665b67733e069bfaad8f96388276 (patch) (side-by-side diff) | |
tree | 0089ca8d5bacd31982d8bec367d091b4f58cace1 /noncore | |
parent | 5ec0d959ca9d3ade0c7271885028fd4309cf2b4c (diff) | |
download | opie-a63b3b36cf4d665b67733e069bfaad8f96388276.zip opie-a63b3b36cf4d665b67733e069bfaad8f96388276.tar.gz opie-a63b3b36cf4d665b67733e069bfaad8f96388276.tar.bz2 |
interfaces now watches for # in most cases
-rw-r--r-- | noncore/net/networksetup/interfaceinformation.ui | 12 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces.cpp | 10 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 4 | ||||
-rw-r--r-- | noncore/net/networksetup/module.h | 8 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaceinformation.ui | 12 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces.cpp | 10 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/module.h | 8 |
8 files changed, 34 insertions, 34 deletions
diff --git a/noncore/net/networksetup/interfaceinformation.ui b/noncore/net/networksetup/interfaceinformation.ui index fc99fce..2838d19 100644 --- a/noncore/net/networksetup/interfaceinformation.ui +++ b/noncore/net/networksetup/interfaceinformation.ui @@ -1,345 +1,343 @@ <!DOCTYPE UI><UI> <class>InterfaceInformation</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>InterfaceInformation</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> <width>219</width> <height>255</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Interface Information</string> </property> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="4" column="0" rowspan="1" colspan="2" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout1</cstring> </property> <grid> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="1" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>refreshButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Refresh</string> + <string>&Refresh</string> </property> </widget> <widget row="0" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>stopButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Stop</string> + <string>S&top</string> </property> </widget> <widget row="1" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>restartButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Restart</string> + <string>R&estart</string> </property> </widget> <widget row="0" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>startButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Start</string> + <string>&Start</string> </property> </widget> </grid> </widget> <widget row="0" column="0" > <class>Line</class> <property stdset="1"> <name>name</name> <cstring>Line1</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> </widget> <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel22</cstring> </property> <property stdset="1"> <name>text</name> <string>IP Address</string> </property> </widget> <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel23</cstring> </property> <property stdset="1"> <name>text</name> <string>Subnet Mask</string> </property> </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel21</cstring> </property> <property stdset="1"> <name>text</name> <string>MAC Address</string> </property> </widget> <widget row="3" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel24</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>MShape</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>MShadow</enum> </property> <property stdset="1"> <name>text</name> <string>Broadcast</string> </property> </widget> <widget row="1" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>subnetMaskLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>0.0.0.0</string> </property> </widget> <widget row="2" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>macAddressLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>00:00:00:00:00:00</string> </property> </widget> <widget row="3" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>broadcastLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string></string> </property> </widget> <widget row="0" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>ipAddressLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>0.0.0.0</string> </property> </widget> <spacer row="7" column="1" > <property> <name>name</name> <cstring>Spacer18</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget row="6" column="0" rowspan="1" colspan="2" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout2</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <spacer> <property> <name>name</name> <cstring>Spacer10</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>advancedButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>View Advanced Information</string> + <string>View &Advanced Information</string> </property> </widget> </hbox> </widget> <widget row="5" column="0" rowspan="1" colspan="2" > <class>Line</class> <property stdset="1"> <name>name</name> <cstring>Line5</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> </widget> </grid> </widget> <customwidgets> <customwidget> <class>QWidget</class> <header location="local">qwidget.h</header> <sizehint> <width>100</width> <height>100</height> </sizehint> <container>0</container> <sizepolicy> <hordata>7</hordata> <verdata>7</verdata> </sizepolicy> <pixmap>image0</pixmap> </customwidget> </customwidgets> <images> <image> <name>image0</name> <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> </image> </images> -<connections> -</connections> <tabstops> <tabstop>startButton</tabstop> <tabstop>stopButton</tabstop> <tabstop>refreshButton</tabstop> <tabstop>restartButton</tabstop> <tabstop>advancedButton</tabstop> </tabstops> </UI> diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp index 9155890..377a6db 100644 --- a/noncore/net/networksetup/interfaces.cpp +++ b/noncore/net/networksetup/interfaces.cpp @@ -1,246 +1,246 @@ #include "interfaces.h" #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> #define AUTO "auto" #define IFACE "iface" #define MAPPING "mapping" /** * Constructor. Reads in the interfaces file and then split the file up by * the \n for interfaces variable. * @param useInterfacesFile if an interface file other then the default is * desired to be used it should be passed in. */ Interfaces::Interfaces(QString useInterfacesFile){ acceptedFamily.append(INTERFACES_FAMILY_INET); acceptedFamily.append(INTERFACES_FAMILY_IPX); acceptedFamily.append(INTERFACES_FAMILY_INET6); interfacesFile = useInterfacesFile; QFile file(interfacesFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); currentIface = interfaces.end(); currentMapping = interfaces.end(); return; } QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line += stream.readLine(); line += "\n"; } file.close(); interfaces = QStringList::split("\n", line, true); currentIface = interfaces.end(); currentMapping = interfaces.end(); } /** * Get a list of all interfaces in the interface file. Usefull for * hardware that is not currently connected such as an 802.11b card * not plugged in, but configured for when it is plugged in. * @return Return string list of interfaces. **/ QStringList Interfaces::getInterfaceList(){ QStringList list; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); - if(line.contains(IFACE)){ + if(line.contains(IFACE) && line.at(0) != '#'){ line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace >= 0){ line = line.mid(0, findSpace); list.append(line); } } } return list; } /** * Find out if interface is in an "auto" group or not. * Report any duplicates such as eth0 being in two differnt auto's * @param interface interface to check to see if it is on or not. * @return true is interface is in auto */ bool Interfaces::isAuto(QString interface){ QStringList autoLines = interfaces.grep(QRegExp(AUTO)); QStringList awi = autoLines.grep(QRegExp(interface)); if(awi.count() > 1) qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); if(awi.count() < 1) return false; return true; } /** * Attempt to set the auto option for interface to setAuto. * @param interface the interface to set * @param setAuto the value to set interface to. * @return false if already set to setAuto. * */ bool Interfaces::setAuto(QString interface, bool setAuto){ // Don't need to set it if it is already set. if(isAuto(interface) == setAuto) return false; bool changed = false; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { if((*it).contains(AUTO)){ //We know that they are not in any group so let add to this auto. if(setAuto){ (*it) = (*it) += " " + interface; // Don't care to have such thins as: auto eth0 lo usb0 (*it) = (*it).simplifyWhiteSpace(); changed = true; break; } else{ if((*it).contains(interface)){ (*it) = (*it).replace(QRegExp(interface), ""); // clean up QString line = (*it).simplifyWhiteSpace(); line = line.replace(QRegExp(" "),""); if(line == AUTO) (*it) = ""; changed = true; // Don't break because we want to make sure we remove all cases. } } } } if(changed == false){ if(setAuto == true) interfaces.append(QString(AUTO" %1").arg(interface)); else{ qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); } } return true; } /** * Set the current interface to interface. This needs to be done before you * can call getFamily(), getMethod, and get/setOption(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setInterface(QString interface){ interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); return setStanza(IFACE, interface, currentIface); } /** * A quick helper funtion to see if the current interface is set. * @return bool true if set, false otherwise. */ bool Interfaces::isInterfaceSet(){ return (currentIface != interfaces.end()); } /** * Add a new interface of with the settings - family and method * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @param family the family of this interface inet or inet, ipx or inet6 * Must of one of the families defined in interfaces.h * @param method for the family. see interfaces man page for family methods. * @return true if successfull. */ bool Interfaces::addInterface(QString interface, QString family, QString method){ if(acceptedFamily.contains(family)==0) return false; interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); interfaces.append(""); interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); return true; } /** * Copies interface with name interface to name newInterface * @param newInterface name of the new interface. * @return bool true if successfull */ bool Interfaces::copyInterface(QString interface, QString newInterface){ if(!setInterface(interface)) return false; QStringList::Iterator it = currentIface; it++; bool error; addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); if(!setInterface(newInterface)) return false; QStringList::Iterator newIface = currentIface; newIface++; for ( it; it != interfaces.end(); ++it ){ if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) break; newIface = interfaces.insert(newIface, *it); } return true; } /** * Remove the currently selected interface and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeInterface(){ if(currentIface == interfaces.end()) return false; (*currentIface) = ""; return removeAllInterfaceOptions(); } /** * Gets the hardware name of the interface that is currently selected. * @return QString name of the hardware interface (eth0, usb2, wlan1...). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceName(bool &error){ if(currentIface == interfaces.end()){ error = true; return QString(); } QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); } error = false; return line.mid(0, findSpace); } /** * Gets the family name of the interface that is currently selected. * @return QString name of the family (inet, inet6, ipx). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceFamily(bool &error){ QString name = getInterfaceName(error); if(error){ error = true; return QString(); } QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); @@ -268,371 +268,371 @@ QString Interfaces::getInterfaceMethod(bool &error){ } QString line = (*currentIface); line = line.mid(QString(IFACE).length()+1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.mid(family.length()+1, line.length()); line = line.simplifyWhiteSpace(); error = false; return line; } /** * Sets the interface name to newName. * @param newName the new name of the interface. All whitespace is removed. * @return bool true if successfull. */ bool Interfaces::setInterfaceName(QString newName){ if(currentIface == interfaces.end()) return false; newName = newName.simplifyWhiteSpace(); newName = newName.replace(QRegExp(" "), ""); bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface family to newName. * @param newName the new name of the interface. Must be one of the families * defined in the interfaces.h file. * @return bool true if successfull. */ bool Interfaces::setInterfaceFamily(QString newName){ if(currentIface == interfaces.end()) return false; if(acceptedFamily.contains(newName)==0) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface method to newName * @param newName the new name of the interface * @return bool true if successfull. */ bool Interfaces::setInterfaceMethod(QString newName){ if(currentIface == interfaces.end()) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); return !returnValue; } /** * Get a value for an option in the currently selected interface. For example * calling getInterfaceOption("address") on the following stanza would * return 192.168.1.1. * iface eth0 static * address 192.168.1.1 * @param option the options to get the value. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ QString Interfaces::getInterfaceOption(QString option, bool &error){ return getOption(currentIface, option, error); } /** * Set a value for an option in the currently selected interface. If option * doesn't exist then it is added along with the value. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::setInterfaceOption(QString option, QString value){ return setOption(currentIface, option, value); } /** * Removes a value for an option in the currently selected interface. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::removeInterfaceOption(QString option, QString value){ return removeOption(currentIface, option, value); } /** * Removes all of the options from the currently selected interface. * @return bool error if if successfull */ bool Interfaces::removeAllInterfaceOptions(){ return removeAllOptions(currentIface); } /** * Set the current map to interface's map. This needs to be done before you * can call addMapping(), set/getMap(), and get/setScript(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setMapping(QString interface){ interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); return setStanza(MAPPING, interface, currentMapping); } /** * Adds a new Mapping to the interfaces file with interfaces. * @param interface the name(s) of the interfaces to set to this mapping */ void Interfaces::addMapping(QString option){ interfaces.append(""); interfaces.append(QString(MAPPING " %1").arg(option)); } /** * Remove the currently selected map and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeMapping(){ if(currentMapping == interfaces.end()) return false; (*currentMapping) = ""; return removeAllOptions(currentMapping); } /** * Set a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::setMap(QString map, QString value){ return setOption(currentMapping, map, value); } /** * Removes a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::removeMap(QString map, QString value){ return removeOption(currentMapping, map, value); } /** * Get a map value within a mapping. * @param map map to get value of * @param bool true if it is successfull. * @return value that goes to the map */ QString Interfaces::getMap(QString map, bool &error){ return getOption(currentMapping, map, error); } /** * Sets a script value of the current mapping to argument. * @param argument the script name. * @return true if successfull. */ bool Interfaces::setScript(QString argument){ return setOption(currentMapping, "script", argument); } /** * @param error true if could not retrieve the current script argument. * @return QString the argument of the script for the current mapping. */ QString Interfaces::getScript(bool &error){ return getOption(currentMapping, "script", error); } /** * Helper function used to parse through the QStringList and put pointers in * the correct place. * @param stanza The stanza (auto, iface, mapping) to look for. * @param option string that must be in the stanza's main line. * @param interator interator to place at location of stanza if successfull. * @return bool true if the stanza is found. */ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ bool found = false; iterator = interfaces.end(); for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); - if(line.contains(stanza) && line.contains(option)){ + if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ uint point = line.find(option); bool valid = true; if(point > 0){ // There are more chars in the line. check +1 if(line.at(point-1) != ' ') valid = false; } point += option.length(); if(point < line.length()-1){ // There are more chars in the line. check -1 if(line.at(point) != ' ') valid = false; } if(valid){ if(found == true){ qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); } found = true; iterator = it; } } } return found; } /** * Sets a value of an option in a stanza * @param start the start of the stanza * @param option the option to use when setting value. * @return bool true if successfull, false otherwise. */ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ if(start == interfaces.end()) return false; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ if(!found && value != ""){ // Got to the end of the stanza without finding it, so append it. interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); } found = true; break; } - if((*it).contains(option) && it != start){ + if((*it).contains(option) && it != start && (*it).at(0) != '#'){ // Found it in stanza so replace it. if(found) qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); found = true; (*it) = QString("\t%1 %2").arg(option).arg(value); } } if(!found){ QStringList::Iterator p = start; interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); found = true; } return found; } /** * Removes a option in a stanza * @param start the start of the stanza * @param option the option to use when setting value. * @return bool true if successfull, false otherwise. */ bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ if(start == interfaces.end()) return false; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ // got to the end without finding it break; } - if((*it).contains(option) && (*it).contains(value) &&it != start){ + if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ // Found it in stanza so replace it. if(found) qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); found = true; (*it) = ""; } } return found; } /** * Removes all options in a stanza * @param start the start of the stanza * @return bool true if successfull, false otherwise. */ bool Interfaces::removeAllOptions(QStringList::Iterator start){ if(start == interfaces.end()) return false; QStringList::Iterator it = start; it = ++it; for (it; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ break; } it = interfaces.remove(it); it = --it; } // Leave a space between this interface and the next. interfaces.insert(it, QString("")); return true; } /** * Gets a value of an option in a stanza * @param start the start of the stanza * @param option the option to use when getting the value. * @param bool true if errors false otherwise. * @return QString the value of option QString::null() if error == true. */ QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ if(start == interfaces.end()){ error = false; return QString(); } QString value; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ break; } - if((*it).contains(option)){ + if((*it).contains(option) && (*it).at(0) != '#'){ if(found) qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); found = true; QString line = (*it).simplifyWhiteSpace(); int space = line.find(" ", option.length()); if(space != -1) value = line.mid(space+1, line.length()); else qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); } } error = !found; return value; } /** * Write out the interfaces file to the file passed into the constructor. * Removes any excess blank lines over 1 line long. * @return bool true if successfull, false if not. */ bool Interfaces::write(){ QFile::remove(interfacesFile); QFile file(interfacesFile); if (!file.open(IO_ReadWrite)){ qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); return false; } QTextStream stream( &file ); int whiteSpaceCount = 0; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); line = line.replace(QRegExp(" "),""); if(line.length() == 0) whiteSpaceCount++; else whiteSpaceCount = 0; if(whiteSpaceCount < 2){ qDebug((*it).latin1()); stream << (*it) << '\n'; } } file.close(); return true; } // interfaces.cpp diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 01063c2..8e4e898 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp @@ -43,431 +43,431 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(par connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
// Load connections.
loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
getInterfaceList();
connectionList->header()->hide();
Config cfg("NetworkSetup");
profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
profilesList->insertItem((*it));
currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
QFile file(scheme);
if ( file.open(IO_ReadOnly) ) { // file opened successfully
QTextStream stream( &file ); // use a text stream
while ( !stream.eof() ) { // until end of file...
QString line = stream.readLine(); // line of text excluding '\n'
if(line.contains("SCHEME")){
line = line.mid(7, line.length());
currentProfileLabel->setText(line);
break;
}
}
file.close();
}
}
/**
* Deconstructor. Save profiles. Delete loaded libraries.
*/
MainWindowImp::~MainWindowImp(){
// Save profiles.
Config cfg("NetworkSetup");
cfg.setGroup("General");
cfg.writeEntry("Profiles", profiles.join(" "));
// Delete Modules and Libraries
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
delete it.key();
delete it.data();
}
}
/**
* Load all modules that are found in the path
* @param path a directory that is scaned for any plugins that can be loaded
* and attempts to load them
*/
void MainWindowImp::loadModules(QString path){
//qDebug(path.latin1());
QDir d(path);
if(!d.exists())
return;
// Don't want sym links
d.setFilter( QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if(fi->fileName().contains(".so")){
loadPlugin(path + "/" + fi->fileName());
}
++it;
}
}
/**
* Attempt to load a function and resolve a function.
* @param pluginFileName - the name of the file in which to attempt to load
* @param resolveString - function pointer to resolve
* @return pointer to the function with name resolveString or NULL
*/
Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
//qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
QLibrary *lib = new QLibrary(pluginFileName);
void *functionPointer = lib->resolve(resolveString);
if( !functionPointer ){
qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
delete lib;
return NULL;
}
// Try to get an object.
Module *object = ((Module* (*)()) functionPointer)();
if(object == NULL){
qDebug("MainWindowImp: Couldn't create object, but did load library!");
delete lib;
return NULL;
}
// Store for deletion later
libraries.insert(object, lib);
return object;
}
/**
* The Add button was clicked. Bring up the add dialog and if OK is hit
* load the plugin and append it to the list
*/
void MainWindowImp::addClicked(){
QMap<Module*, QLibrary*>::Iterator it;
QMap<QString, QString> list;
QMap<QString, Module*> newInterfaceOwners;
list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()){
(it.key())->possibleNewInterfaces(list);
}
}
// See if the list has anything that we can add.
if(list.count() == 0){
QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
return;
}
AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
addNewConnection.addConnections(list);
addNewConnection.showMaximized();
if(QDialog::Accepted == addNewConnection.exec()){
QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
if(!item)
return;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()){
Interface *i = (it.key())->addNewInterface(item->text(0));
if(i){
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
}
}
}
}
}
/**
* Prompt the user to see if they really want to do this.
* If they do then remove from the list and unload.
*/
void MainWindowImp::removeClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item) {
QMessageBox::information(this, "Error","Please select an interface.", "Ok");
return;
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner() == NULL){
QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
}
else{
if(!i->getModuleOwner()->remove(i))
QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
else{
QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
// TODO memory managment....
// who deletes the interface?
}
}
}
/**
* Pull up the configure about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure with a empty
* tab. If tab is !NULL then append the interfaces setup widget to it.
*/
void MainWindowImp::configureClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
return;
}
QString currentProfile = currentProfileLabel->text();
if(profilesList->count() <= 1 || currentProfile == "All"){
currentProfile = "";
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner()){
i->getModuleOwner()->setProfile(currentProfile);
QTabWidget *tabWidget = NULL;
- QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
+ QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget);
if(moduleConfigure != NULL){
if(tabWidget != NULL){
InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
configure->setProfile(currentProfile);
tabWidget->insertTab(configure, "TCP/IP");
}
moduleConfigure->showMaximized();
moduleConfigure->show();
return;
}
}
InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
configure->setProfile(currentProfile);
configure->showMaximized();
configure->show();
}
/**
* Pull up the information about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure with a empty
* tab. If tab is !NULL then append the interfaces setup widget to it.
*/
void MainWindowImp::informationClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(!i->isAttached()){
QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok);
return;
}
QStringList list;
for(uint i = 0; i < profilesList->count(); i++){
list.append(profilesList->text(i));
}
if(i->getModuleOwner()){
QTabWidget *tabWidget = NULL;
- QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
+ QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget);
if(moduleInformation != NULL){
if(tabWidget != NULL){
InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
tabWidget->insertTab(information, "TCP/IP");
}
moduleInformation->showMaximized();
moduleInformation->show();
return;
}
}
InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
information->showMaximized();
information->show();
}
/**
* Aquire the list of active interfaces from ifconfig
* Call ifconfig and ifconfig -a
*/
void MainWindowImp::getInterfaceList(){
KShellProcess *processAll = new KShellProcess();
*processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
connect(processAll, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(processAll, TEMP_ALL);
KShellProcess *process = new KShellProcess();
*process << "/sbin/ifconfig" << " > " TEMP_UP;
connect(process, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(process, TEMP_UP);
processAll->start(KShellProcess::NotifyOnExit);
process->start(KShellProcess::NotifyOnExit);
}
void MainWindowImp::jobDone(KProcess *process){
QString fileName = threads[process];
threads.remove(process);
delete process;
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
return;
}
QTextStream stream( &file );
QString line;
while ( !stream.eof() ) {
line = stream.readLine();
int space = line.find(" ");
if(space > 1){
// We have found an interface
QString interfaceName = line.mid(0, space);
Interface *i;
// We have found an interface
//qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
// See if we already have it
if(interfaceNames.find(interfaceName) == interfaceNames.end()){
if(fileName == TEMP_ALL)
i = new Interface(this, interfaceName, false);
else
i = new Interface(this, interfaceName, true);
i->setAttached(true);
QString hardName = "Ethernet";
int hardwareName = line.find("Link encap:");
int macAddress = line.find("HWaddr");
if(macAddress == -1)
macAddress = line.length();
if(hardwareName != -1)
i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) );
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
// It was an interface we already had.
else{
if(fileName != TEMP_ALL)
(interfaceNames[interfaceName])->setStatus(true);
}
}
}
file.close();
QFile::remove(fileName);
if(threads.count() == 0){
Interfaces i;
QStringList list = i.getInterfaceList();
QMap<QString, Interface*>::Iterator it;
for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
bool found = false;
for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
if(it.key() == (*ni))
found = true;
}
if(!found){
if(!(*ni).contains("_")){
Interface *i = new Interface(this, *ni, false);
i->setAttached(false);
i->setHardwareName("Disconnected");
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
}
}
}
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
*/
void MainWindowImp::updateInterface(Interface *i){
if(!advancedUserMode){
if(i->getInterfaceName() == "lo")
return;
}
QListViewItem *item = NULL;
// Find the interface, making it if needed.
if(items.find(i) == items.end()){
item = new QListViewItem(connectionList, "", "", "");
// See if you can't find a module owner for this interface
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()->isOwner(i))
i->setModuleOwner(it.key());
}
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
// Update the icons and information
item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
if(i->getInterfaceName().contains("irda"))
typeName = "irda";
if(i->getInterfaceName().contains("wlan"))
typeName = "wlan";
if(i->getInterfaceName().contains("usb"))
typeName = "usb";
if(!i->isAttached())
typeName = "connect_no";
// Actually try to use the Module
if(i->getModuleOwner() != NULL)
typeName = i->getModuleOwner()->getPixmapName(i);
item->setPixmap(1, (Resource::loadPixmap(typeName)));
item->setText(2, i->getHardwareName());
item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
}
void MainWindowImp::newProfileChanged(const QString& newText){
if(newText.length() > 0)
newProfileButton->setEnabled(true);
else
newProfileButton->setEnabled(false);
}
/**
* Adds a new profile to the list of profiles.
* Don't add profiles that already exists.
* Appends to the list and QStringList
*/
void MainWindowImp::addProfile(){
QString newProfileName = newProfile->text();
if(profiles.grep(newProfileName).count() > 0){
QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
return;
}
profiles.append(newProfileName);
profilesList->insertItem(newProfileName);
}
/**
* Removes the currently selected profile in the combo.
* Doesn't delete if there are less then 2 profiles.
*/
void MainWindowImp::removeProfile(){
diff --git a/noncore/net/networksetup/module.h b/noncore/net/networksetup/module.h index a30f492..96db5b3 100644 --- a/noncore/net/networksetup/module.h +++ b/noncore/net/networksetup/module.h @@ -1,86 +1,88 @@ #ifndef NETCONF_MODULE_H #define NETCONF_MODULE_H #include <qobject.h> #include <qlist.h> #include <qmap.h> #include "interface.h" class QWidget; class QTabWidget; class Module : QObject{ signals: void updateInterface(Interface *i); public: Module(){}; /** * The current profile has been changed and the module should do any * neccesary changes also. * @param newProfile what the profile should be changed to. */ virtual void setProfile(QString newProfile) = 0; /** * get the icon name for this device. * @param Interface* can be used in determining the icon. * @return QString the icon name (minus .png, .gif etc) */ - virtual QString getPixmapName(Interface* i) = 0; + virtual QString getPixmapName(Interface *) = 0; /** * Check to see if the interface i is owned by this module. * @param Interface* interface to check against * @return bool true if i is owned by this module, false otherwise. */ virtual bool isOwner(Interface *){ return false; }; /** * Create, set tabWiget and return the WLANConfigure Module + * @param Interface *i the interface to configure. * @param tabWidget a pointer to the tab widget that this configure has. * @return QWidget* pointer to the tab widget in this modules configure. */ - virtual QWidget *configure(QTabWidget **){ return NULL; } ; + virtual QWidget *configure(Interface *, QTabWidget **){ return NULL; } ; /** * Create, set tabWiget and return the Information Module + * @param Interface *i the interface to get info on. * @param tabWidget a pointer to the tab widget that this information has. * @return QWidget* pointer to the tab widget in this modules info. */ - virtual QWidget *information(QTabWidget **){ return NULL; }; + virtual QWidget *information(Interface *, QTabWidget **){ return NULL; }; /** * Get all active (up or down) interfaces * @return QList<Interface> A list of interfaces that exsist that havn't * been called by isOwner() */ virtual QList<Interface> getInterfaces() = 0; /** * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp), * modem ppp) */ virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0; /** * Attempts to create a new interface from name * @return Interface* NULL if it was unable to be created. * @param name the type of interface to create */ virtual Interface *addNewInterface(QString name) = 0; /** * Attempts to remove the interface, doesn't delete i * @return bool true if successfull, false otherwise. */ virtual bool remove(Interface* i) = 0; }; #endif // module.h diff --git a/noncore/settings/networksettings/interfaceinformation.ui b/noncore/settings/networksettings/interfaceinformation.ui index fc99fce..2838d19 100644 --- a/noncore/settings/networksettings/interfaceinformation.ui +++ b/noncore/settings/networksettings/interfaceinformation.ui @@ -1,345 +1,343 @@ <!DOCTYPE UI><UI> <class>InterfaceInformation</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>InterfaceInformation</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> <width>219</width> <height>255</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Interface Information</string> </property> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="4" column="0" rowspan="1" colspan="2" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout1</cstring> </property> <grid> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="1" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>refreshButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Refresh</string> + <string>&Refresh</string> </property> </widget> <widget row="0" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>stopButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Stop</string> + <string>S&top</string> </property> </widget> <widget row="1" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>restartButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Restart</string> + <string>R&estart</string> </property> </widget> <widget row="0" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>startButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>Start</string> + <string>&Start</string> </property> </widget> </grid> </widget> <widget row="0" column="0" > <class>Line</class> <property stdset="1"> <name>name</name> <cstring>Line1</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> </widget> <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel22</cstring> </property> <property stdset="1"> <name>text</name> <string>IP Address</string> </property> </widget> <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel23</cstring> </property> <property stdset="1"> <name>text</name> <string>Subnet Mask</string> </property> </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel21</cstring> </property> <property stdset="1"> <name>text</name> <string>MAC Address</string> </property> </widget> <widget row="3" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel24</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>MShape</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>MShadow</enum> </property> <property stdset="1"> <name>text</name> <string>Broadcast</string> </property> </widget> <widget row="1" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>subnetMaskLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>0.0.0.0</string> </property> </widget> <widget row="2" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>macAddressLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>00:00:00:00:00:00</string> </property> </widget> <widget row="3" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>broadcastLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string></string> </property> </widget> <widget row="0" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>ipAddressLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>0.0.0.0</string> </property> </widget> <spacer row="7" column="1" > <property> <name>name</name> <cstring>Spacer18</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget row="6" column="0" rowspan="1" colspan="2" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout2</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <spacer> <property> <name>name</name> <cstring>Spacer10</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>advancedButton</cstring> </property> <property stdset="1"> <name>text</name> - <string>View Advanced Information</string> + <string>View &Advanced Information</string> </property> </widget> </hbox> </widget> <widget row="5" column="0" rowspan="1" colspan="2" > <class>Line</class> <property stdset="1"> <name>name</name> <cstring>Line5</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> </widget> </grid> </widget> <customwidgets> <customwidget> <class>QWidget</class> <header location="local">qwidget.h</header> <sizehint> <width>100</width> <height>100</height> </sizehint> <container>0</container> <sizepolicy> <hordata>7</hordata> <verdata>7</verdata> </sizepolicy> <pixmap>image0</pixmap> </customwidget> </customwidgets> <images> <image> <name>image0</name> <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> </image> </images> -<connections> -</connections> <tabstops> <tabstop>startButton</tabstop> <tabstop>stopButton</tabstop> <tabstop>refreshButton</tabstop> <tabstop>restartButton</tabstop> <tabstop>advancedButton</tabstop> </tabstops> </UI> diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp index 9155890..377a6db 100644 --- a/noncore/settings/networksettings/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces.cpp @@ -1,246 +1,246 @@ #include "interfaces.h" #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> #define AUTO "auto" #define IFACE "iface" #define MAPPING "mapping" /** * Constructor. Reads in the interfaces file and then split the file up by * the \n for interfaces variable. * @param useInterfacesFile if an interface file other then the default is * desired to be used it should be passed in. */ Interfaces::Interfaces(QString useInterfacesFile){ acceptedFamily.append(INTERFACES_FAMILY_INET); acceptedFamily.append(INTERFACES_FAMILY_IPX); acceptedFamily.append(INTERFACES_FAMILY_INET6); interfacesFile = useInterfacesFile; QFile file(interfacesFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interfaces: Can't open file: %1 for reading.").arg(interfacesFile).latin1()); currentIface = interfaces.end(); currentMapping = interfaces.end(); return; } QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line += stream.readLine(); line += "\n"; } file.close(); interfaces = QStringList::split("\n", line, true); currentIface = interfaces.end(); currentMapping = interfaces.end(); } /** * Get a list of all interfaces in the interface file. Usefull for * hardware that is not currently connected such as an 802.11b card * not plugged in, but configured for when it is plugged in. * @return Return string list of interfaces. **/ QStringList Interfaces::getInterfaceList(){ QStringList list; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); - if(line.contains(IFACE)){ + if(line.contains(IFACE) && line.at(0) != '#'){ line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace >= 0){ line = line.mid(0, findSpace); list.append(line); } } } return list; } /** * Find out if interface is in an "auto" group or not. * Report any duplicates such as eth0 being in two differnt auto's * @param interface interface to check to see if it is on or not. * @return true is interface is in auto */ bool Interfaces::isAuto(QString interface){ QStringList autoLines = interfaces.grep(QRegExp(AUTO)); QStringList awi = autoLines.grep(QRegExp(interface)); if(awi.count() > 1) qDebug(QString("Interfaces: Found more then auto group with interface: %1.").arg(interface).latin1()); if(awi.count() < 1) return false; return true; } /** * Attempt to set the auto option for interface to setAuto. * @param interface the interface to set * @param setAuto the value to set interface to. * @return false if already set to setAuto. * */ bool Interfaces::setAuto(QString interface, bool setAuto){ // Don't need to set it if it is already set. if(isAuto(interface) == setAuto) return false; bool changed = false; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { if((*it).contains(AUTO)){ //We know that they are not in any group so let add to this auto. if(setAuto){ (*it) = (*it) += " " + interface; // Don't care to have such thins as: auto eth0 lo usb0 (*it) = (*it).simplifyWhiteSpace(); changed = true; break; } else{ if((*it).contains(interface)){ (*it) = (*it).replace(QRegExp(interface), ""); // clean up QString line = (*it).simplifyWhiteSpace(); line = line.replace(QRegExp(" "),""); if(line == AUTO) (*it) = ""; changed = true; // Don't break because we want to make sure we remove all cases. } } } } if(changed == false){ if(setAuto == true) interfaces.append(QString(AUTO" %1").arg(interface)); else{ qDebug(QString("Interfaces: Can't set interface %1 auto to false sense it is already false.").arg(interface).latin1()); } } return true; } /** * Set the current interface to interface. This needs to be done before you * can call getFamily(), getMethod, and get/setOption(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setInterface(QString interface){ interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); return setStanza(IFACE, interface, currentIface); } /** * A quick helper funtion to see if the current interface is set. * @return bool true if set, false otherwise. */ bool Interfaces::isInterfaceSet(){ return (currentIface != interfaces.end()); } /** * Add a new interface of with the settings - family and method * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @param family the family of this interface inet or inet, ipx or inet6 * Must of one of the families defined in interfaces.h * @param method for the family. see interfaces man page for family methods. * @return true if successfull. */ bool Interfaces::addInterface(QString interface, QString family, QString method){ if(acceptedFamily.contains(family)==0) return false; interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); interfaces.append(""); interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method)); return true; } /** * Copies interface with name interface to name newInterface * @param newInterface name of the new interface. * @return bool true if successfull */ bool Interfaces::copyInterface(QString interface, QString newInterface){ if(!setInterface(interface)) return false; QStringList::Iterator it = currentIface; it++; bool error; addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); if(!setInterface(newInterface)) return false; QStringList::Iterator newIface = currentIface; newIface++; for ( it; it != interfaces.end(); ++it ){ if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO))) break; newIface = interfaces.insert(newIface, *it); } return true; } /** * Remove the currently selected interface and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeInterface(){ if(currentIface == interfaces.end()) return false; (*currentIface) = ""; return removeAllInterfaceOptions(); } /** * Gets the hardware name of the interface that is currently selected. * @return QString name of the hardware interface (eth0, usb2, wlan1...). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceName(bool &error){ if(currentIface == interfaces.end()){ error = true; return QString(); } QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); } error = false; return line.mid(0, findSpace); } /** * Gets the family name of the interface that is currently selected. * @return QString name of the family (inet, inet6, ipx). * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceFamily(bool &error){ QString name = getInterfaceName(error); if(error){ error = true; return QString(); } QString line = (*currentIface); line = line.mid(QString(IFACE).length() +1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.simplifyWhiteSpace(); int findSpace = line.find(" "); if( findSpace < 0){ error = true; return QString(); @@ -268,371 +268,371 @@ QString Interfaces::getInterfaceMethod(bool &error){ } QString line = (*currentIface); line = line.mid(QString(IFACE).length()+1, line.length()); line = line.mid(name.length()+1, line.length()); line = line.mid(family.length()+1, line.length()); line = line.simplifyWhiteSpace(); error = false; return line; } /** * Sets the interface name to newName. * @param newName the new name of the interface. All whitespace is removed. * @return bool true if successfull. */ bool Interfaces::setInterfaceName(QString newName){ if(currentIface == interfaces.end()) return false; newName = newName.simplifyWhiteSpace(); newName = newName.replace(QRegExp(" "), ""); bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(newName).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface family to newName. * @param newName the new name of the interface. Must be one of the families * defined in the interfaces.h file. * @return bool true if successfull. */ bool Interfaces::setInterfaceFamily(QString newName){ if(currentIface == interfaces.end()) return false; if(acceptedFamily.contains(newName)==0) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(newName).arg(getInterfaceMethod(returnValue)); return !returnValue; } /** * Sets the interface method to newName * @param newName the new name of the interface * @return bool true if successfull. */ bool Interfaces::setInterfaceMethod(QString newName){ if(currentIface == interfaces.end()) return false; bool returnValue = false; (*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName); return !returnValue; } /** * Get a value for an option in the currently selected interface. For example * calling getInterfaceOption("address") on the following stanza would * return 192.168.1.1. * iface eth0 static * address 192.168.1.1 * @param option the options to get the value. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ QString Interfaces::getInterfaceOption(QString option, bool &error){ return getOption(currentIface, option, error); } /** * Set a value for an option in the currently selected interface. If option * doesn't exist then it is added along with the value. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::setInterfaceOption(QString option, QString value){ return setOption(currentIface, option, value); } /** * Removes a value for an option in the currently selected interface. * @param option the options to set the value. * @param value the value that option should be set to. * @param error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::removeInterfaceOption(QString option, QString value){ return removeOption(currentIface, option, value); } /** * Removes all of the options from the currently selected interface. * @return bool error if if successfull */ bool Interfaces::removeAllInterfaceOptions(){ return removeAllOptions(currentIface); } /** * Set the current map to interface's map. This needs to be done before you * can call addMapping(), set/getMap(), and get/setScript(). * @param interface the name of the interface to set. All whitespace is * removed from the interface name. * @return bool true if it is successfull. */ bool Interfaces::setMapping(QString interface){ interface = interface.simplifyWhiteSpace(); interface = interface.replace(QRegExp(" "), ""); return setStanza(MAPPING, interface, currentMapping); } /** * Adds a new Mapping to the interfaces file with interfaces. * @param interface the name(s) of the interfaces to set to this mapping */ void Interfaces::addMapping(QString option){ interfaces.append(""); interfaces.append(QString(MAPPING " %1").arg(option)); } /** * Remove the currently selected map and all of its options. * @return bool if successfull or not. */ bool Interfaces::removeMapping(){ if(currentMapping == interfaces.end()) return false; (*currentMapping) = ""; return removeAllOptions(currentMapping); } /** * Set a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::setMap(QString map, QString value){ return setOption(currentMapping, map, value); } /** * Removes a map option within a mapping. * @param map map to use * @param value value to go with map * @return bool true if it is successfull. */ bool Interfaces::removeMap(QString map, QString value){ return removeOption(currentMapping, map, value); } /** * Get a map value within a mapping. * @param map map to get value of * @param bool true if it is successfull. * @return value that goes to the map */ QString Interfaces::getMap(QString map, bool &error){ return getOption(currentMapping, map, error); } /** * Sets a script value of the current mapping to argument. * @param argument the script name. * @return true if successfull. */ bool Interfaces::setScript(QString argument){ return setOption(currentMapping, "script", argument); } /** * @param error true if could not retrieve the current script argument. * @return QString the argument of the script for the current mapping. */ QString Interfaces::getScript(bool &error){ return getOption(currentMapping, "script", error); } /** * Helper function used to parse through the QStringList and put pointers in * the correct place. * @param stanza The stanza (auto, iface, mapping) to look for. * @param option string that must be in the stanza's main line. * @param interator interator to place at location of stanza if successfull. * @return bool true if the stanza is found. */ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){ bool found = false; iterator = interfaces.end(); for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); - if(line.contains(stanza) && line.contains(option)){ + if(line.contains(stanza) && line.contains(option) && line.at(0) != '#'){ uint point = line.find(option); bool valid = true; if(point > 0){ // There are more chars in the line. check +1 if(line.at(point-1) != ' ') valid = false; } point += option.length(); if(point < line.length()-1){ // There are more chars in the line. check -1 if(line.at(point) != ' ') valid = false; } if(valid){ if(found == true){ qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); } found = true; iterator = it; } } } return found; } /** * Sets a value of an option in a stanza * @param start the start of the stanza * @param option the option to use when setting value. * @return bool true if successfull, false otherwise. */ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString value){ if(start == interfaces.end()) return false; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ if(!found && value != ""){ // Got to the end of the stanza without finding it, so append it. interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); } found = true; break; } - if((*it).contains(option) && it != start){ + if((*it).contains(option) && it != start && (*it).at(0) != '#'){ // Found it in stanza so replace it. if(found) qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); found = true; (*it) = QString("\t%1 %2").arg(option).arg(value); } } if(!found){ QStringList::Iterator p = start; interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); found = true; } return found; } /** * Removes a option in a stanza * @param start the start of the stanza * @param option the option to use when setting value. * @return bool true if successfull, false otherwise. */ bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ if(start == interfaces.end()) return false; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ // got to the end without finding it break; } - if((*it).contains(option) && (*it).contains(value) &&it != start){ + if((*it).contains(option) && (*it).contains(value) && it != start && (*it).at(0) != '#'){ // Found it in stanza so replace it. if(found) qDebug(QString("Interfaces: Set Options found more then one value for option: %1 in stanza: %1").arg(option).arg((*start)).latin1()); found = true; (*it) = ""; } } return found; } /** * Removes all options in a stanza * @param start the start of the stanza * @return bool true if successfull, false otherwise. */ bool Interfaces::removeAllOptions(QStringList::Iterator start){ if(start == interfaces.end()) return false; QStringList::Iterator it = start; it = ++it; for (it; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ break; } it = interfaces.remove(it); it = --it; } // Leave a space between this interface and the next. interfaces.insert(it, QString("")); return true; } /** * Gets a value of an option in a stanza * @param start the start of the stanza * @param option the option to use when getting the value. * @param bool true if errors false otherwise. * @return QString the value of option QString::null() if error == true. */ QString Interfaces::getOption(QStringList::Iterator start, QString option, bool &error){ if(start == interfaces.end()){ error = false; return QString(); } QString value; bool found = false; for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ break; } - if((*it).contains(option)){ + if((*it).contains(option) && (*it).at(0) != '#'){ if(found) qDebug(QString("Interfaces: Get Options found more then one value: %1 for option: %2 in stanza %3").arg((*it)).arg(option).arg((*start)).latin1()); found = true; QString line = (*it).simplifyWhiteSpace(); int space = line.find(" ", option.length()); if(space != -1) value = line.mid(space+1, line.length()); else qDebug(QString("Interfaces: Option %1 with no value").arg(option).latin1()); } } error = !found; return value; } /** * Write out the interfaces file to the file passed into the constructor. * Removes any excess blank lines over 1 line long. * @return bool true if successfull, false if not. */ bool Interfaces::write(){ QFile::remove(interfacesFile); QFile file(interfacesFile); if (!file.open(IO_ReadWrite)){ qDebug(QString("Interfaces: Can't open file: %1 for writing.").arg(interfacesFile).latin1()); return false; } QTextStream stream( &file ); int whiteSpaceCount = 0; for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); line = line.replace(QRegExp(" "),""); if(line.length() == 0) whiteSpaceCount++; else whiteSpaceCount = 0; if(whiteSpaceCount < 2){ qDebug((*it).latin1()); stream << (*it) << '\n'; } } file.close(); return true; } // interfaces.cpp diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 01063c2..8e4e898 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp @@ -43,431 +43,431 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(par connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
// Load connections.
loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
getInterfaceList();
connectionList->header()->hide();
Config cfg("NetworkSetup");
profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
profilesList->insertItem((*it));
currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
QFile file(scheme);
if ( file.open(IO_ReadOnly) ) { // file opened successfully
QTextStream stream( &file ); // use a text stream
while ( !stream.eof() ) { // until end of file...
QString line = stream.readLine(); // line of text excluding '\n'
if(line.contains("SCHEME")){
line = line.mid(7, line.length());
currentProfileLabel->setText(line);
break;
}
}
file.close();
}
}
/**
* Deconstructor. Save profiles. Delete loaded libraries.
*/
MainWindowImp::~MainWindowImp(){
// Save profiles.
Config cfg("NetworkSetup");
cfg.setGroup("General");
cfg.writeEntry("Profiles", profiles.join(" "));
// Delete Modules and Libraries
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
delete it.key();
delete it.data();
}
}
/**
* Load all modules that are found in the path
* @param path a directory that is scaned for any plugins that can be loaded
* and attempts to load them
*/
void MainWindowImp::loadModules(QString path){
//qDebug(path.latin1());
QDir d(path);
if(!d.exists())
return;
// Don't want sym links
d.setFilter( QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if(fi->fileName().contains(".so")){
loadPlugin(path + "/" + fi->fileName());
}
++it;
}
}
/**
* Attempt to load a function and resolve a function.
* @param pluginFileName - the name of the file in which to attempt to load
* @param resolveString - function pointer to resolve
* @return pointer to the function with name resolveString or NULL
*/
Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
//qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
QLibrary *lib = new QLibrary(pluginFileName);
void *functionPointer = lib->resolve(resolveString);
if( !functionPointer ){
qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
delete lib;
return NULL;
}
// Try to get an object.
Module *object = ((Module* (*)()) functionPointer)();
if(object == NULL){
qDebug("MainWindowImp: Couldn't create object, but did load library!");
delete lib;
return NULL;
}
// Store for deletion later
libraries.insert(object, lib);
return object;
}
/**
* The Add button was clicked. Bring up the add dialog and if OK is hit
* load the plugin and append it to the list
*/
void MainWindowImp::addClicked(){
QMap<Module*, QLibrary*>::Iterator it;
QMap<QString, QString> list;
QMap<QString, Module*> newInterfaceOwners;
list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()){
(it.key())->possibleNewInterfaces(list);
}
}
// See if the list has anything that we can add.
if(list.count() == 0){
QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
return;
}
AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
addNewConnection.addConnections(list);
addNewConnection.showMaximized();
if(QDialog::Accepted == addNewConnection.exec()){
QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
if(!item)
return;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()){
Interface *i = (it.key())->addNewInterface(item->text(0));
if(i){
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
}
}
}
}
}
/**
* Prompt the user to see if they really want to do this.
* If they do then remove from the list and unload.
*/
void MainWindowImp::removeClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item) {
QMessageBox::information(this, "Error","Please select an interface.", "Ok");
return;
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner() == NULL){
QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
}
else{
if(!i->getModuleOwner()->remove(i))
QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
else{
QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
// TODO memory managment....
// who deletes the interface?
}
}
}
/**
* Pull up the configure about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure with a empty
* tab. If tab is !NULL then append the interfaces setup widget to it.
*/
void MainWindowImp::configureClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
return;
}
QString currentProfile = currentProfileLabel->text();
if(profilesList->count() <= 1 || currentProfile == "All"){
currentProfile = "";
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner()){
i->getModuleOwner()->setProfile(currentProfile);
QTabWidget *tabWidget = NULL;
- QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
+ QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget);
if(moduleConfigure != NULL){
if(tabWidget != NULL){
InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
configure->setProfile(currentProfile);
tabWidget->insertTab(configure, "TCP/IP");
}
moduleConfigure->showMaximized();
moduleConfigure->show();
return;
}
}
InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
configure->setProfile(currentProfile);
configure->showMaximized();
configure->show();
}
/**
* Pull up the information about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure with a empty
* tab. If tab is !NULL then append the interfaces setup widget to it.
*/
void MainWindowImp::informationClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(!i->isAttached()){
QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok);
return;
}
QStringList list;
for(uint i = 0; i < profilesList->count(); i++){
list.append(profilesList->text(i));
}
if(i->getModuleOwner()){
QTabWidget *tabWidget = NULL;
- QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
+ QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget);
if(moduleInformation != NULL){
if(tabWidget != NULL){
InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
tabWidget->insertTab(information, "TCP/IP");
}
moduleInformation->showMaximized();
moduleInformation->show();
return;
}
}
InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
information->showMaximized();
information->show();
}
/**
* Aquire the list of active interfaces from ifconfig
* Call ifconfig and ifconfig -a
*/
void MainWindowImp::getInterfaceList(){
KShellProcess *processAll = new KShellProcess();
*processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
connect(processAll, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(processAll, TEMP_ALL);
KShellProcess *process = new KShellProcess();
*process << "/sbin/ifconfig" << " > " TEMP_UP;
connect(process, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(process, TEMP_UP);
processAll->start(KShellProcess::NotifyOnExit);
process->start(KShellProcess::NotifyOnExit);
}
void MainWindowImp::jobDone(KProcess *process){
QString fileName = threads[process];
threads.remove(process);
delete process;
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
return;
}
QTextStream stream( &file );
QString line;
while ( !stream.eof() ) {
line = stream.readLine();
int space = line.find(" ");
if(space > 1){
// We have found an interface
QString interfaceName = line.mid(0, space);
Interface *i;
// We have found an interface
//qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
// See if we already have it
if(interfaceNames.find(interfaceName) == interfaceNames.end()){
if(fileName == TEMP_ALL)
i = new Interface(this, interfaceName, false);
else
i = new Interface(this, interfaceName, true);
i->setAttached(true);
QString hardName = "Ethernet";
int hardwareName = line.find("Link encap:");
int macAddress = line.find("HWaddr");
if(macAddress == -1)
macAddress = line.length();
if(hardwareName != -1)
i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) );
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
// It was an interface we already had.
else{
if(fileName != TEMP_ALL)
(interfaceNames[interfaceName])->setStatus(true);
}
}
}
file.close();
QFile::remove(fileName);
if(threads.count() == 0){
Interfaces i;
QStringList list = i.getInterfaceList();
QMap<QString, Interface*>::Iterator it;
for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
bool found = false;
for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
if(it.key() == (*ni))
found = true;
}
if(!found){
if(!(*ni).contains("_")){
Interface *i = new Interface(this, *ni, false);
i->setAttached(false);
i->setHardwareName("Disconnected");
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
}
}
}
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
*/
void MainWindowImp::updateInterface(Interface *i){
if(!advancedUserMode){
if(i->getInterfaceName() == "lo")
return;
}
QListViewItem *item = NULL;
// Find the interface, making it if needed.
if(items.find(i) == items.end()){
item = new QListViewItem(connectionList, "", "", "");
// See if you can't find a module owner for this interface
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()->isOwner(i))
i->setModuleOwner(it.key());
}
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
// Update the icons and information
item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
if(i->getInterfaceName().contains("irda"))
typeName = "irda";
if(i->getInterfaceName().contains("wlan"))
typeName = "wlan";
if(i->getInterfaceName().contains("usb"))
typeName = "usb";
if(!i->isAttached())
typeName = "connect_no";
// Actually try to use the Module
if(i->getModuleOwner() != NULL)
typeName = i->getModuleOwner()->getPixmapName(i);
item->setPixmap(1, (Resource::loadPixmap(typeName)));
item->setText(2, i->getHardwareName());
item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
}
void MainWindowImp::newProfileChanged(const QString& newText){
if(newText.length() > 0)
newProfileButton->setEnabled(true);
else
newProfileButton->setEnabled(false);
}
/**
* Adds a new profile to the list of profiles.
* Don't add profiles that already exists.
* Appends to the list and QStringList
*/
void MainWindowImp::addProfile(){
QString newProfileName = newProfile->text();
if(profiles.grep(newProfileName).count() > 0){
QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
return;
}
profiles.append(newProfileName);
profilesList->insertItem(newProfileName);
}
/**
* Removes the currently selected profile in the combo.
* Doesn't delete if there are less then 2 profiles.
*/
void MainWindowImp::removeProfile(){
diff --git a/noncore/settings/networksettings/module.h b/noncore/settings/networksettings/module.h index a30f492..96db5b3 100644 --- a/noncore/settings/networksettings/module.h +++ b/noncore/settings/networksettings/module.h @@ -1,86 +1,88 @@ #ifndef NETCONF_MODULE_H #define NETCONF_MODULE_H #include <qobject.h> #include <qlist.h> #include <qmap.h> #include "interface.h" class QWidget; class QTabWidget; class Module : QObject{ signals: void updateInterface(Interface *i); public: Module(){}; /** * The current profile has been changed and the module should do any * neccesary changes also. * @param newProfile what the profile should be changed to. */ virtual void setProfile(QString newProfile) = 0; /** * get the icon name for this device. * @param Interface* can be used in determining the icon. * @return QString the icon name (minus .png, .gif etc) */ - virtual QString getPixmapName(Interface* i) = 0; + virtual QString getPixmapName(Interface *) = 0; /** * Check to see if the interface i is owned by this module. * @param Interface* interface to check against * @return bool true if i is owned by this module, false otherwise. */ virtual bool isOwner(Interface *){ return false; }; /** * Create, set tabWiget and return the WLANConfigure Module + * @param Interface *i the interface to configure. * @param tabWidget a pointer to the tab widget that this configure has. * @return QWidget* pointer to the tab widget in this modules configure. */ - virtual QWidget *configure(QTabWidget **){ return NULL; } ; + virtual QWidget *configure(Interface *, QTabWidget **){ return NULL; } ; /** * Create, set tabWiget and return the Information Module + * @param Interface *i the interface to get info on. * @param tabWidget a pointer to the tab widget that this information has. * @return QWidget* pointer to the tab widget in this modules info. */ - virtual QWidget *information(QTabWidget **){ return NULL; }; + virtual QWidget *information(Interface *, QTabWidget **){ return NULL; }; /** * Get all active (up or down) interfaces * @return QList<Interface> A list of interfaces that exsist that havn't * been called by isOwner() */ virtual QList<Interface> getInterfaces() = 0; /** * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp), * modem ppp) */ virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0; /** * Attempts to create a new interface from name * @return Interface* NULL if it was unable to be created. * @param name the type of interface to create */ virtual Interface *addNewInterface(QString name) = 0; /** * Attempts to remove the interface, doesn't delete i * @return bool true if successfull, false otherwise. */ virtual bool remove(Interface* i) = 0; }; #endif // module.h |