From a7e015198a8c5ad3b6e144a9032b059086253e00 Mon Sep 17 00:00:00 2001 From: kergoth Date: Sat, 09 Aug 2003 17:14:54 +0000 Subject: Merge from BRANCH_1_0 --- (limited to 'noncore/settings/networksettings/interfaces') 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,7 +1,7 @@ /** * $Author$ * $Date$ - */ + */ #include "interface.h" #include @@ -24,7 +24,7 @@ Interface::Interface(QObject * parent, const char * name, bool newSatus): QObjec * Set status * @param newStatus - the new status * emit updateInterface - */ + */ void Interface::setStatus(bool newStatus){ if(status != newStatus){ status = newStatus; @@ -36,27 +36,27 @@ void Interface::setStatus(bool newStatus){ * 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)); @@ -65,14 +65,14 @@ void Interface::setModuleOwner(Module *owner){ /** * 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){ @@ -89,12 +89,12 @@ void Interface::start(){ * 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")); @@ -108,7 +108,7 @@ void Interface::stop(){ /** * Try to restart the interface. - */ + */ void Interface::restart(){ stop(); start(); @@ -133,14 +133,14 @@ bool Interface::refresh(){ 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()); @@ -152,7 +152,7 @@ bool Interface::refresh(){ ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; - + QTextStream stream( &file ); QString line; while ( !stream.eof() ) { @@ -185,30 +185,30 @@ bool Interface::refresh(){ 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(); @@ -222,7 +222,7 @@ bool Interface::refresh(){ 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); @@ -244,7 +244,7 @@ bool Interface::refresh(){ 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 ); @@ -257,7 +257,7 @@ bool Interface::refresh(){ } 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 @@ -265,7 +265,7 @@ bool Interface::refresh(){ // nice 0 itrealvalue starttime "%*d %*d %*d %lu", (long*) &time); time = time/100; - + QDateTime datetime(QDateTime::currentDateTime()); // Get the uptime of the computer. @@ -281,19 +281,19 @@ bool Interface::refresh(){ 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; } 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 @@ -12,22 +12,22 @@ class Interface : public QObject{ 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); @@ -47,7 +47,7 @@ public: virtual void stop(); virtual void restart(); -private: +protected: // Interface information QString hardwareName; Module *moduleOwner; 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 @@ -18,7 +18,7 @@ maximumSize - 240 + 32767 32767 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 @@ -12,95 +12,29 @@ 0 0 219 - 255 + 323 caption Interface Information - + + layoutMargin + + + layoutSpacing + + margin - 11 + 4 spacing - 6 + 3 - - QLayoutWidget - - name - Layout1 - - - - margin - 0 - - - spacing - 6 - - - QPushButton - - name - refreshButton - - - text - &Refresh - - - - QPushButton - - name - stopButton - - - text - S&top - - - - QPushButton - - name - restartButton - - - text - R&estart - - - - QPushButton - - name - startButton - - - text - &Start - - - - - - Line - - name - Line1 - - - orientation - Horizontal - - - + QLabel name @@ -111,48 +45,48 @@ IP Address - + QLabel name - TextLabel23 + ipAddressLabel - text - Subnet Mask + frameShape + Panel - - - QLabel - name - TextLabel21 + frameShadow + Sunken text - MAC Address + 0.0.0.0 - - QLabel + + Line name - TextLabel24 + Line1 - frameShape - MShape + orientation + Horizontal + + + QLabel - frameShadow - MShadow + name + TextLabel23 text - Broadcast + Subnet Mask - + QLabel name @@ -171,7 +105,7 @@ 0.0.0.0 - + QLabel name @@ -190,7 +124,18 @@ 00:00:00:00:00:00 - + + QLabel + + name + TextLabel21 + + + text + MAC Address + + + QLabel name @@ -209,47 +154,98 @@ - + QLabel name - ipAddressLabel + TextLabel24 frameShape - Panel + MShape frameShadow - Sunken + MShadow text - 0.0.0.0 + Broadcast - - + + QLayoutWidget + name - Spacer18 + Layout1 + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + refreshButton + + + text + &Refresh + + + + QPushButton + + name + stopButton + + + text + S&top + + + + QPushButton + + name + restartButton + + + text + R&estart + + + + QPushButton + + name + startButton + + + text + &Start + + + + + + Line - orientation - Vertical + name + Line5 - sizeType - Expanding - - - sizeHint - - 20 - 20 - + orientation + Horizontal - - + + QLayoutWidget name @@ -298,18 +294,39 @@ - - Line - + + name - Line5 + Spacer18 orientation - Horizontal + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QCheckBox + + name + CheckBoxSilent + + + text + be &silent - + startButton 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,12 +1,15 @@ #include "interfaceinformationimp.h" #include "interfaceadvanced.h" +#include #include #include #include #include -#ifdef QWS +#include + +#ifdef QWS #else #define showMaximized show #endif @@ -14,7 +17,7 @@ /** * 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 &))); @@ -24,13 +27,23 @@ InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *na 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); @@ -51,7 +64,7 @@ void InterfaceInformationImp::updateInterface(Interface *){ /** * 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()); @@ -70,8 +83,9 @@ void InterfaceInformationImp::advanced(){ * 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); } 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 @@ -10,7 +10,7 @@ Q_OBJECT public: InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0); - ~InterfaceInformationImp(){}; + ~InterfaceInformationImp(); private slots: void advanced(); 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,5 +1,6 @@ #include "interfaces.h" +#include #include #include #include @@ -151,6 +152,7 @@ bool Interfaces::isInterfaceSet() const { * @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(); @@ -166,6 +168,7 @@ bool Interfaces::addInterface(const QString &interface, const QString &family, c * @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; @@ -272,12 +275,16 @@ QString Interfaces::getInterfaceMethod(bool &error){ * @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; } @@ -327,13 +334,19 @@ QString Interfaces::getInterfaceOption(const QString &option, bool &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); } /** @@ -492,30 +505,49 @@ bool Interfaces::setStanza(const QString &stanza, const QString &option, QString 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; } @@ -552,7 +584,8 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString 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; @@ -579,7 +612,8 @@ bool Interfaces::removeOption(const QStringList::Iterator &start, const QString 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; 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 @@ -44,6 +44,7 @@ InterfaceSetupImp::~InterfaceSetupImp(){ bool InterfaceSetupImp::saveChanges(){ bool error; QString iface = interfaces->getInterfaceName(error); + qDebug("InterfaceSetupImp::saveChanges saves interface %s", iface.latin1() ); if(!saveSettings()) return false; @@ -117,6 +118,9 @@ bool InterfaceSetupImp::saveSettings(){ 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"); } } -- cgit v0.9.0.2