Diffstat (limited to 'noncore/settings/networksettings/interfaces') (more/less context) (ignore whitespace changes)
8 files changed, 254 insertions, 185 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index cc45525..69b55d1 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp @@ -1,302 +1,302 @@ /** * $Author$ * $Date$ - */ + */ #include "interface.h" #include <qdatetime.h> #include <qfile.h> #include <qdir.h> #include <qfileinfo.h> #include <qtextstream.h> #define IFCONFIG "/sbin/ifconfig" #define DHCP_INFO_DIR "/etc/dhcpc" #include <stdio.h> #include <stdlib.h> Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ refresh(); } /** * Set status * @param newStatus - the new status * emit updateInterface - */ + */ void Interface::setStatus(bool newStatus){ if(status != newStatus){ status = newStatus; refresh(); } }; /** * Set if attached or not (802.11 card pulled out for example) * @param isAttached - if attached * emit updateInterface - */ + */ void Interface::setAttached(bool isAttached){ attached = isAttached; emit(updateInterface(this)); }; - + /** * Set Hardware name * @param name - the new name * emit updateInterface - */ + */ void Interface::setHardwareName(const QString &name){ hardwareName = name; emit(updateInterface(this)); }; - + /** * Set Module owner * @param owner - the new owner * emit updateInterface - */ + */ void Interface::setModuleOwner(Module *owner){ moduleOwner = owner; emit(updateInterface(this)); }; /** * Try to start the interface. - */ + */ void Interface::start(){ - // check to see if we are already running. + // check to see if we are already running. if(true == status){ emit (updateMessage("Unable to start interface,\n already started")); return; } - + int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); // See if it was successfull... if(ret != 0){ emit (updateMessage("Starting interface failed")); return; } status = true; refresh(); emit (updateMessage("Start successfull")); } /** * Try to stop the interface. */ void Interface::stop(){ - // check to see if we are already stopped. + // check to see if we are already stopped. if(false == status){ emit (updateMessage("Unable to stop interface,\n already stopped")); return; } - + int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); if(ret != 0){ emit (updateMessage("Stopping interface failed")); return; } status = false; refresh(); emit (updateMessage("Stop successfull")); } /** * Try to restart the interface. - */ + */ void Interface::restart(){ stop(); start(); } /** * Try to refresh the information about the interface. * First call ifconfig, then check the dhcp-info file * @return bool true if successfull. */ bool Interface::refresh(){ // See if we are up. if(status == false){ macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; dhcp = false; dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; emit(updateInterface(this)); return true; } - + QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); - int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); + int ret = system(QString("LANG=C %1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); if(ret != 0){ qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); return false; } - + QFile file(fileName); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } // Set to the defaults macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; - + QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("HWaddr")){ int mac = line.find("HWaddr"); macAddress = line.mid(mac+7, line.length()); } if(line.contains("inet addr")){ int ipl = line.find("inet addr"); int space = line.find(" ", ipl+10); ip = line.mid(ipl+10, space-ipl-10); } if(line.contains("Mask")){ int mask = line.find("Mask"); subnetMask = line.mid(mask+5, line.length()); } if(line.contains("Bcast")){ int mask = line.find("Bcast"); int space = line.find(" ", mask+6); broadcast = line.mid(mask+6, space-mask-6); } } file.close(); QFile::remove(fileName); // DHCP TESTING // reset DHCP info dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; dhcp = false; - + QString dhcpDirectory(DHCP_INFO_DIR); QDir d(dhcpDirectory); if(!d.exists(dhcpDirectory)) dhcpDirectory = "/var/run"; - - // See if we have + + // See if we have QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); // If there is no DHCP information then exit now with no errors. if(!QFile::exists(dhcpFile)){ emit(updateInterface(this)); return true; } - + file.setName(dhcpFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); return false; } - + // leaseTime and renewalTime and used if pid and deamon exe can be accessed. int leaseTime = 0; int renewalTime = 0; - + stream.setDevice( &file ); while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("DHCPSIADDR=")) dhcpServerIp = line.mid(11, line.length()); if(line.contains("LEASETIME=")) leaseTime = line.mid(10, line.length()).toInt(); if(line.contains("RENEWALTIME=")) renewalTime = line.mid(12, line.length()).toInt(); } file.close(); //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); - + // Get the pid of the deamond dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); file.setName(dhcpFile); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); return false; } int pid = -1; stream.setDevice( &file ); while ( !stream.eof() ) { line = stream.readLine(); pid = line.toInt(); } file.close(); if( pid == -1){ qDebug("Interface: Could not get pid of dhcpc deamon."); return false; } - // Get the start running time of the deamon + // Get the start running time of the deamon fileName = (QString("/proc/%1/stat").arg(pid)); file.setName(fileName); stream.setDevice( &file ); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } while ( !stream.eof() ) { line = stream.readLine(); } file.close(); long time = 0; - // Grab the start time + // Grab the start time // pid com state ppid pgrp session tty_nr tpgid flags sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " // minflt cminflt majflt cmajflt utime stime cutime cstime priority "%*u %*u %*u %*u %*u %*u %*d %*d %*d " // nice 0 itrealvalue starttime "%*d %*d %*d %lu", (long*) &time); time = time/100; - + QDateTime datetime(QDateTime::currentDateTime()); // Get the uptime of the computer. QFile f("/proc/uptime"); if ( f.open(IO_ReadOnly) ) { // file opened successfully QTextStream t( &f ); // use a text stream int sec = 0; t >> sec; datetime = datetime.addSecs((-1*sec)); f.close(); } else{ qDebug("Interface: Can't open /proc/uptime to retrive uptime."); return false; } - + datetime = datetime.addSecs(time); //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); - - // Calculate the start and renew times + + // Calculate the start and renew times leaseObtained = datetime.toString(); - - // Calculate the start and renew times + + // Calculate the start and renew times datetime = datetime.addSecs(leaseTime); leaseExpires = datetime.toString(); - + dhcp = true; - + emit(updateInterface(this)); return true; } // interface.cpp diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h index 7e98deb..ec82851 100644 --- a/noncore/settings/networksettings/interfaces/interface.h +++ b/noncore/settings/networksettings/interfaces/interface.h @@ -1,73 +1,73 @@ #ifndef INTERFACE_H #define INTERFACE_H #include <qstring.h> #include <qobject.h> class Module; class Interface : public QObject{ Q_OBJECT signals: void updateInterface(Interface *i); void updateMessage(const QString &message); - + public: Interface(QObject * parent=0, const char * name= "unknown", bool status = false); - + QString getInterfaceName() const { QString n(this->name()); return n; }; void setInterfaceName( const QString &n ) { this->setName(n); }; - + bool getStatus() const { return status; }; void setStatus(bool newStatus); bool isAttached() const { return attached; }; void setAttached(bool isAttached=false); - + QString getHardwareName() const { return hardwareName; }; void setHardwareName(const QString &name="Unknown"); - + Module* getModuleOwner() const { return moduleOwner; }; void setModuleOwner(Module *owner=NULL); // inet information. QString getMacAddress() const { return macAddress; }; QString getIp() const { return ip; }; QString getSubnetMask() const { return subnetMask; }; QString getBroadcast() const { return broadcast; }; bool isDhcp() const { return dhcp; }; QString getDhcpServerIp() const { return dhcpServerIp; }; QString getLeaseObtained() const { return leaseObtained; }; QString getLeaseExpires() const { return leaseExpires; }; public slots: virtual bool refresh(); virtual void start(); virtual void stop(); virtual void restart(); -private: +protected: // Interface information QString hardwareName; Module *moduleOwner; bool status; bool attached; // Network information bool dhcp; QString dhcpServerIp; QString leaseObtained; QString leaseExpires; QString macAddress; QString ip; QString broadcast; QString subnetMask; }; #endif // interface.h diff --git a/noncore/settings/networksettings/interfaces/interfaceadvanced.ui b/noncore/settings/networksettings/interfaces/interfaceadvanced.ui index 2e106cb..12dbb1d 100644 --- a/noncore/settings/networksettings/interfaces/interfaceadvanced.ui +++ b/noncore/settings/networksettings/interfaces/interfaceadvanced.ui @@ -1,213 +1,213 @@ <!DOCTYPE UI><UI> <class>InterfaceAdvanced</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>InterfaceAdvanced</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> <width>214</width> <height>290</height> </rect> </property> <property stdset="1"> <name>maximumSize</name> <size> - <width>240</width> + <width>32767</width> <height>32767</height> </size> </property> <property stdset="1"> <name>caption</name> <string>Advanced 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="0" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>interfaceName</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>eth0</string> </property> </widget> <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel3</cstring> </property> <property stdset="1"> <name>text</name> <string>IP Address</string> </property> </widget> <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel7</cstring> </property> <property stdset="1"> <name>text</name> <string>Interface</string> </property> </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel4</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> </property> <property stdset="1"> <name>text</name> <string>Subnet Mask</string> </property> </widget> <widget row="1" 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> <widget row="2" 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> <spacer row="6" column="1" > <property> <name>name</name> <cstring>Spacer2</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="5" column="0" rowspan="1" colspan="2" > <class>QGroupBox</class> <property stdset="1"> <name>name</name> <cstring>dhcpInformation</cstring> </property> <property stdset="1"> <name>title</name> <string>DHCP 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="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel6</cstring> </property> <property stdset="1"> <name>text</name> <string>DHCP Server</string> </property> </widget> <widget row="2" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>leaseExpiresLabel</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="1" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>leaseObtainedLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> diff --git a/noncore/settings/networksettings/interfaces/interfaceinformation.ui b/noncore/settings/networksettings/interfaces/interfaceinformation.ui index 763ad90..207200e 100644 --- a/noncore/settings/networksettings/interfaces/interfaceinformation.ui +++ b/noncore/settings/networksettings/interfaces/interfaceinformation.ui @@ -1,321 +1,338 @@ <!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> + <height>323</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Interface Information</string> </property> - <grid> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> + <vbox> <property stdset="1"> <name>margin</name> - <number>11</number> + <number>4</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>3</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> - </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>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>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> - </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" > + <widget> <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" > + <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel23</cstring> + <cstring>ipAddressLabel</cstring> </property> <property stdset="1"> - <name>text</name> - <string>Subnet Mask</string> + <name>frameShape</name> + <enum>Panel</enum> </property> - </widget> - <widget row="2" column="0" > - <class>QLabel</class> <property stdset="1"> - <name>name</name> - <cstring>TextLabel21</cstring> + <name>frameShadow</name> + <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> - <string>MAC Address</string> + <string>0.0.0.0</string> </property> </widget> - <widget row="3" column="0" > - <class>QLabel</class> + <widget> + <class>Line</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel24</cstring> + <cstring>Line1</cstring> </property> <property stdset="1"> - <name>frameShape</name> - <enum>MShape</enum> + <name>orientation</name> + <enum>Horizontal</enum> </property> + </widget> + <widget> + <class>QLabel</class> <property stdset="1"> - <name>frameShadow</name> - <enum>MShadow</enum> + <name>name</name> + <cstring>TextLabel23</cstring> </property> <property stdset="1"> <name>text</name> - <string>Broadcast</string> + <string>Subnet Mask</string> </property> </widget> - <widget row="1" column="1" > + <widget> <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" > + <widget> <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" > + <widget> + <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> <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" > + <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>ipAddressLabel</cstring> + <cstring>TextLabel24</cstring> </property> <property stdset="1"> <name>frameShape</name> - <enum>Panel</enum> + <enum>MShape</enum> </property> <property stdset="1"> <name>frameShadow</name> - <enum>Sunken</enum> + <enum>MShadow</enum> </property> <property stdset="1"> <name>text</name> - <string>0.0.0.0</string> + <string>Broadcast</string> </property> </widget> - <spacer row="7" column="1" > - <property> + <widget> + <class>QLayoutWidget</class> + <property stdset="1"> <name>name</name> - <cstring>Spacer18</cstring> + <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> + </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>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>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> + </property> + </widget> + </grid> + </widget> + <widget> + <class>Line</class> <property stdset="1"> - <name>orientation</name> - <enum>Vertical</enum> + <name>name</name> + <cstring>Line5</cstring> </property> <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> + <name>orientation</name> + <enum>Horizontal</enum> </property> - </spacer> - <widget row="6" column="0" rowspan="1" colspan="2" > + </widget> + <widget> <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> </property> </widget> </hbox> </widget> - <widget row="5" column="0" rowspan="1" colspan="2" > - <class>Line</class> - <property stdset="1"> + <spacer> + <property> <name>name</name> - <cstring>Line5</cstring> + <cstring>Spacer18</cstring> </property> <property stdset="1"> <name>orientation</name> - <enum>Horizontal</enum> + <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> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>CheckBoxSilent</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>be &silent</string> </property> </widget> - </grid> + </vbox> </widget> <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/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp index e00dcce..37c3a91 100644 --- a/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp @@ -1,79 +1,93 @@ #include "interfaceinformationimp.h" #include "interfaceadvanced.h" +#include <qcheckbox.h> #include <qpushbutton.h> #include <qlabel.h> #include <qgroupbox.h> #include <qmessagebox.h> -#ifdef QWS +#include <qpe/config.h> + +#ifdef QWS #else #define showMaximized show #endif /** * Constructor for the InterfaceInformationImp class. This class pretty much * just display's information about the interface that is passed to it. - */ + */ InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f), interface(i){ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); connect(i, SIGNAL(updateMessage(const QString &)), this, SLOT(showMessage(const QString &))); updateInterface(interface); connect(startButton, SIGNAL(clicked()), interface, SLOT(start())); connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop())); connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart())); connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh())); connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced())); + Config cfg("networksettings", Config::User); + cfg.setGroup("interface"); + CheckBoxSilent->setChecked( cfg.readBoolEntry("silent", false) ); +} + +InterfaceInformationImp::~InterfaceInformationImp() +{ + Config cfg("networksettings", Config::User); + cfg.setGroup("interface"); + cfg.writeEntry("silent", CheckBoxSilent->isChecked() ); } /** * Update the interface information and buttons. * @param Intarface *i the interface to update (should be the one we already * know about). - */ + */ void InterfaceInformationImp::updateInterface(Interface *){ if(interface->getStatus()){ startButton->setEnabled(false); stopButton->setEnabled(true); restartButton->setEnabled(true); } else{ startButton->setEnabled(true); stopButton->setEnabled(false); restartButton->setEnabled(false); } macAddressLabel->setText(interface->getMacAddress()); ipAddressLabel->setText(interface->getIp()); subnetMaskLabel->setText(interface->getSubnetMask()); broadcastLabel->setText(interface->getBroadcast()); } /** * Create the advanced widget. Fill it with the current interface's information. * Display it. - */ + */ void InterfaceInformationImp::advanced(){ InterfaceAdvanced *a = new InterfaceAdvanced(this, "InterfaceAdvanced", Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); a->interfaceName->setText(interface->getInterfaceName()); a->macAddressLabel->setText(interface->getMacAddress()); a->ipAddressLabel->setText(interface->getIp()); a->subnetMaskLabel->setText(interface->getSubnetMask()); a->broadcastLabel->setText(interface->getBroadcast()); a->dhcpServerLabel->setText(interface->getDhcpServerIp()); a->leaseObtainedLabel->setText(interface->getLeaseObtained()); a->leaseExpiresLabel->setText(interface->getLeaseExpires()); a->dhcpInformation->setEnabled(interface->isDhcp()); a->showMaximized(); } /** * Messages from the interface if start/stop went as planned. * Purly for user feedback. * @param message the message to display. - */ + */ void InterfaceInformationImp::showMessage(const QString &message){ + if (CheckBoxSilent->isChecked()) return; QMessageBox::information(this, "Message", message, QMessageBox::Ok); } // infoimp.cpp diff --git a/noncore/settings/networksettings/interfaces/interfaceinformationimp.h b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h index 65cdfe0..9c93d1d 100644 --- a/noncore/settings/networksettings/interfaces/interfaceinformationimp.h +++ b/noncore/settings/networksettings/interfaces/interfaceinformationimp.h @@ -1,28 +1,28 @@ #ifndef INTERFACEINFORMATIONIMP_H #define INTERFACEINFORMATIONIMP_H #include "interfaceinformation.h" #include "interface.h" class InterfaceInformationImp : public InterfaceInformation { Q_OBJECT public: InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); - ~InterfaceInformationImp(){}; + ~InterfaceInformationImp(); private slots: void advanced(); void updateInterface(Interface *i); void showMessage(const QString &message); private: Interface *interface; }; #endif // addserviceimp.h diff --git a/noncore/settings/networksettings/interfaces/interfaces.cpp b/noncore/settings/networksettings/interfaces/interfaces.cpp index 71d0cf5..436e449 100644 --- a/noncore/settings/networksettings/interfaces/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces/interfaces.cpp @@ -1,678 +1,712 @@ #include "interfaces.h" +#include <qcheckbox.h> #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> // The three stanza's #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("Interfaces: Can't open file: %s for reading.", 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) && 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(const QString &interface) const { 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()); return awi.count() > 0; } /** * 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(const 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 see if we need to remove from this one else{ if((*it).contains(interface)){ (*it) = (*it).replace(QRegExp(interface), ""); // if AUTO is the only thing left clear the line if(((*it).simplifyWhiteSpace()).replace(QRegExp(" "),"") == AUTO) (*it) = ""; changed = true; // Don't break because we want to make sure we remove all cases. } } } } // In the case where there is no AUTO field add one. if(!changed && setAuto) interfaces.append(QString(AUTO" %1").arg(interface)); 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() const { return (interfaces.end() != currentIface); } /** * 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(const QString &interface, const QString &family, const QString &method){ + qDebug("Interfaces::addInterface(%s)",interface.latin1()); if(0 == acceptedFamily.contains(family)) return false; QString newInterface = interface.simplifyWhiteSpace(); newInterface = newInterface.replace(QRegExp(" "), ""); interfaces.append(""); interfaces.append(QString(IFACE " %1 %2 %3").arg(newInterface).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(const QString &interface, const QString &newInterface){ + qDebug("copy interface %s to %s", interface.latin1(), newInterface.latin1()); if(!setInterface(interface)) return false; // Store the old interface and bump past the stanza line. QStringList::Iterator it = currentIface; it++; // Add the new interface bool error; addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error)); if(!setInterface(newInterface)) return false; QStringList::Iterator newIface = currentIface; newIface++; // Copy all of the lines for ( ; 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(){ return removeStanza(currentIface); } /** * 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) 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(); } error = false; return line.mid(0, findSpace); } /** * Gets the method of the interface that is currently selected. * @return QString name of the method such as staic or dhcp. * See the man page of interfaces for possible methods depending on the family. * @param error set to true if any error occurs, false otherwise. */ QString Interfaces::getInterfaceMethod(bool &error){ QString name = getInterfaceName(error); if(error) return QString(); QString family = getInterfaceFamily(error); if(error) return QString(); 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(const QString &newName){ + qDebug("setInterfaceName %s", newName.latin1()); if(currentIface == interfaces.end()) return false; QString name = newName.simplifyWhiteSpace(); name = name.replace(QRegExp(" "), ""); bool returnValue = false; - (*currentIface) = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); + QString tmp = QString("iface %1 %2 %3").arg(name).arg(getInterfaceFamily(returnValue)).arg(getInterfaceMethod(returnValue)); + qDebug("setting %s",tmp.latin1()); + + (*currentIface) = tmp; 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(const 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(const 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(const 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. + * If value isEmpty() then we will remove the option + * * @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(const QString &option, const QString &value){ - return setOption(currentIface, option, value); + if( value.stripWhiteSpace().isEmpty() ) + return removeInterfaceOption( option ); + + qDebug("iface >%s< option >%s< value >%s<", (*currentIface).latin1(), option.latin1(),value.latin1()); + 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 error set to true if any error occurs, false otherwise. * @return QString the options value. QString::null if error == true */ bool Interfaces::removeInterfaceOption(const QString &option){ return removeOption(currentIface, option); } /** * 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(const QString &option, const 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(const QString &interface){ QString interfaceName = interface.simplifyWhiteSpace(); interfaceName = interfaceName.replace(QRegExp(" "), ""); return setStanza(MAPPING, interfaceName, 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(const 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(){ return removeStanza(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(const QString &map, const 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(const QString &map, const 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(const 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(const 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(const QString &stanza, const 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) && 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(const QStringList::Iterator &start, const QString &option, const QString &value){ if(start == interfaces.end()) return false; - + qDebug("setting option"); bool found = false; + bool replaced = false; + QStringList::Iterator insertAt = NULL; 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; - } + qDebug(" Interfaces::setOption got line >%s<",(*it).latin1()); + // FIXME: was not completly stupid just wrong sice all options got inserted bevore the iface line + // but since it works with an empty interfaces file I (tille) will not do anything more + if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) ){ + if (found) break; +// && it != start){ +// if(!found && value != ""){ +// // Got to the end of the stanza without finding it, so append it. +// qDebug(" Got to the end of the stanza without finding it, so append it."); +// interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value)); +// } + qDebug("found 1"); +// interfaces.insert(++it, QString("\t%1 %2").arg(option).arg(value)); + found = true; + insertAt = it; + + } if((*it).contains(option) && it != start && (*it).at(0) != '#'){ // Found it in stanza so replace it. + qDebug("found 2"); 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; + replaced = true; (*it) = QString("\t%1 %2").arg(option).arg(value); } } if(!found){ + qDebug("! found insert anyway"); QStringList::Iterator p = start; interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); found = true; } + + if(found && !replaced){ + qDebug("found iface but not the option so insert it here..."); + interfaces.insert(++insertAt, QString("\t%1 %2").arg(option).arg(value)); + } return found; } /** * Removes a stanza and all of its options * @param stanza the stanza to remove * @return bool true if successfull. */ bool Interfaces::removeStanza(QStringList::Iterator &stanza){ if(stanza == interfaces.end()) return false; (*stanza) = ""; return removeAllOptions(stanza); } /** * Removes a option in a stanza * @param start the start of the stanza * @param option the option to remove * @return bool true if successfull, false otherwise. */ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString &option){ 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 != 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) = ""; + it = interfaces.remove( it ); // we really want to remove the line + --it; // we do ++it later in the head of the for loop } } 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(const QStringList::Iterator &start, const QString &option, const 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 && (*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) = ""; + it = interfaces.remove( it ); // we really want to remove the line + --it; // we do ++it later in the head of the for loop } } 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(const QStringList::Iterator &start){ if(start == interfaces.end()) return false; QStringList::Iterator it = start; it = ++it; for (; 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(const QStringList::Iterator &start, const 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) && (*it).at(0) != '#'){ if(found) qDebug(QString("Interfaces: getOption 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()); break; } } } 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/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp index b40d101..e844d8a 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp @@ -1,202 +1,206 @@ #include "interfacesetupimp.h" #include "interface.h" #include <qcheckbox.h> #include <qlineedit.h> #include <qspinbox.h> #include <qgroupbox.h> #include <qlabel.h> #include <qmessagebox.h> #include <opie/oprocess.h> #ifdef QWS #include <opie/owait.h> #include <qpe/global.h> #include <qapplication.h> #endif #define DNSSCRIPT "changedns" /** * Constuctor. Set up the connection. A profile must be set. */ InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, Interfaces *j, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i), interfaces(j), delInterfaces(false){ if (j == 0) { delInterfaces = true; interfaces = new Interfaces; } } /** * Destructor */ InterfaceSetupImp::~InterfaceSetupImp(){ if(delInterfaces) { delete interfaces; } } /** * Save the current settings, then write out the interfaces file and close. */ bool InterfaceSetupImp::saveChanges(){ bool error; QString iface = interfaces->getInterfaceName(error); + qDebug("InterfaceSetupImp::saveChanges saves interface %s", iface.latin1() ); if(!saveSettings()) return false; interfaces->write(); if (interface->getStatus()) { QString ifup; ifup += "ifdown "; ifup += iface; ifup += "; ifup "; ifup += iface; ifup += ";"; OProcess restart; restart << "sh"; restart << "-c"; restart << ifup; OWait *owait = new OWait(); Global::statusMessage( tr( "Restarting interface" ) ); owait->show(); qApp->processEvents(); if (!restart.start(OProcess::Block, OProcess::NoCommunication) ) { qWarning("unstable to spawn ifdown/ifup"); } owait->hide(); delete owait; interface->refresh(); } return true; } /** * Save the settings for the current Interface. * @return bool true if successfull, false otherwise */ bool InterfaceSetupImp::saveSettings(){ // eh can't really do anything about it other then return. :-D if(!interfaces->isInterfaceSet()) return true; bool error = false; // Loopback case if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); return true; } if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); return false; } // DHCP if(dhcpCheckBox->isChecked()) { interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); interfaces->removeInterfaceOption("address"); interfaces->removeInterfaceOption("netmask"); interfaces->removeInterfaceOption("gateway"); interfaces->removeInterfaceOption("up "DNSSCRIPT" -a "); interfaces->removeInterfaceOption("down "DNSSCRIPT" -r "); } else{ interfaces->setInterfaceMethod("static"); interfaces->setInterfaceOption("address", ipAddressEdit->text()); interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); interfaces->setInterfaceOption("gateway", gatewayEdit->text()); if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); + }else{ + interfaces->removeInterfaceOption("up "DNSSCRIPT" -a "); + interfaces->removeInterfaceOption("down "DNSSCRIPT" -r"); } } // IP Information interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); return true; } /** * The Profile has changed. * @param QString profile the new profile. */ void InterfaceSetupImp::setProfile(const QString &profile){ /* bool error = false; if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ staticGroupBox->hide(); dhcpCheckBox->hide(); leaseTime->hide(); leaseHoursLabel->hide(); } */ QString newInterfaceName = interface->getInterfaceName(); if(profile.length() > 0) newInterfaceName += "_" + profile; // See if we have to make a interface. if(!interfaces->setInterface(newInterfaceName)){ // Add making for this new interface if need too if(profile != ""){ interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); if(!interfaces->setMapping(interface->getInterfaceName())){ interfaces->addMapping(interface->getInterfaceName()); if(!interfaces->setMapping(interface->getInterfaceName())){ qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface."); return; } } interfaces->setMap("map", newInterfaceName); interfaces->setScript("getprofile.sh"); } else{ interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); if(!interfaces->setInterface(newInterfaceName)){ qDebug("InterfaceSetupImp: Added interface, but still can't setInterface."); return; } } } // We must have a valid interface to get this far so read some settings. // DHCP bool error = false; if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) dhcpCheckBox->setChecked(true); else dhcpCheckBox->setChecked(false); // IP Information autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); qDebug("dns >%s<",dns.latin1()); if(dns.contains(" ")){ firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); }else firstDNSLineEdit->setText(dns); ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); if (subnetMaskEdit->text().isEmpty()) subnetMaskEdit->setText( "255.255.255.0" ); gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1()); qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1()); } // interfacesetup.cpp |