From 88b3a159060ed7057bfee4cc1ccfcf81a63a4780 Mon Sep 17 00:00:00 2001 From: benmeyer Date: Fri, 18 Oct 2002 14:28:42 +0000 Subject: More profile stuff works --- (limited to 'noncore/net') diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO index c8e2989..c587f58 100644 --- a/noncore/net/networksetup/TODO +++ b/noncore/net/networksetup/TODO @@ -1,10 +1,6 @@ Write a class that parses /proc and not ifconfig +WLAN needs to be re-written to not use Config +remove WLAN Config item [ ] Wlanmodule needs to check if an interface supports wireless extensions. -[x] When you set options in wlanmodule, hit OK, it exits all of - networksetup, doesnt bring you back to the main screen. -[x] Wlanmodule isnt writing out wireless.opts -[ ] Need a means of bringing an interface up and down (calling - out ifup/ifdown) from the gui. - -Ben- Click information, then click up or down... :-D diff --git a/noncore/net/networksetup/interfaceadvanced.ui b/noncore/net/networksetup/interfaceadvanced.ui index efe67b0..0ec67c2 100644 --- a/noncore/net/networksetup/interfaceadvanced.ui +++ b/noncore/net/networksetup/interfaceadvanced.ui @@ -18,7 +18,7 @@ maximumSize - 320 + 240 32767 @@ -189,7 +189,7 @@ QGroupBox name - GroupBox2 + dhcpInformation title diff --git a/noncore/net/networksetup/interfaceinformation.ui b/noncore/net/networksetup/interfaceinformation.ui index 76af19c..fc99fce 100644 --- a/noncore/net/networksetup/interfaceinformation.ui +++ b/noncore/net/networksetup/interfaceinformation.ui @@ -11,8 +11,8 @@ 0 0 - 199 - 244 + 219 + 255 @@ -333,6 +333,8 @@ 789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758 + + startButton stopButton diff --git a/noncore/net/networksetup/interfaceinformationimp.cpp b/noncore/net/networksetup/interfaceinformationimp.cpp index 59a6400..43483fb 100644 --- a/noncore/net/networksetup/interfaceinformationimp.cpp +++ b/noncore/net/networksetup/interfaceinformationimp.cpp @@ -3,6 +3,7 @@ #include #include +#include #include /** @@ -59,6 +60,8 @@ void InterfaceInformationImp::advanced(){ a->dhcpServerLabel->setText(interface->getDhcpServerIp()); a->leaseObtainedLabel->setText(interface->getLeaseObtained()); a->leaseExpiresLabel->setText(interface->getLeaseExpires()); + a->dhcpInformation->setEnabled(interface->isDhcp()); + a->showMaximized(); a->show(); } diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp index 1287d90..eef42df 100644 --- a/noncore/net/networksetup/interfaces.cpp +++ b/noncore/net/networksetup/interfaces.cpp @@ -345,9 +345,9 @@ bool Interfaces::setMapping(QString interface){ * 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 interfaces){ +void Interfaces::addMapping(QString option){ interfaces.append(""); - interfaces.append(QString(MAPPING " %1").arg(interfaces)); + interfaces.append(QString(MAPPING " %1").arg(option)); } /** @@ -404,11 +404,12 @@ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator if(found == true){ qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1()); } + qDebug("Found"); found = true; iterator = it; } } - return !found; + return found; } /** @@ -428,9 +429,10 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString // 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)){ + if((*it).contains(option) && it != start){ // 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()); @@ -441,7 +443,12 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString (*it) = QString("\t%1 %2").arg(option).arg(value); } } - return true; + if(!found){ + QStringList::Iterator p = start; + interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value)); + found = true; + } + return found; } /** diff --git a/noncore/net/networksetup/interfaces.h b/noncore/net/networksetup/interfaces.h index 8b4788c..e617c17 100644 --- a/noncore/net/networksetup/interfaces.h +++ b/noncore/net/networksetup/interfaces.h @@ -43,7 +43,7 @@ public: bool removeAllInterfaceOptions(); bool setMapping(QString interface); - void addMapping(QString interfaces); + void addMapping(QString options); bool setMap(QString map, QString value); QString getMap(QString map, bool &error); bool setScript(QString); diff --git a/noncore/net/networksetup/interfacesetup.ui b/noncore/net/networksetup/interfacesetup.ui index 3db9a0b..c94b1be 100644 --- a/noncore/net/networksetup/interfacesetup.ui +++ b/noncore/net/networksetup/interfacesetup.ui @@ -11,7 +11,7 @@ 0 0 - 267 + 276 280 @@ -43,68 +43,6 @@ QLayoutWidget name - Layout8 - - - - margin - 0 - - - spacing - 6 - - - QLabel - - name - TextLabel1 - - - text - Profile - - - - QComboBox - - - text - All - - - - name - profileCombo - - - - - name - Spacer20 - - - orientation - Horizontal - - - sizeType - Expanding - - - sizeHint - - 20 - 20 - - - - - - - QLayoutWidget - - name Layout9 @@ -154,7 +92,7 @@ maxValue - 336 + 87600 minValue @@ -162,7 +100,7 @@ value - 24 + 168 @@ -198,13 +136,6 @@ spacing 6 - - QLineEdit - - name - firstDNSLineEdit - - QLabel @@ -248,13 +179,6 @@ First DNS - - QLineEdit - - name - secondDNSLineEdit - - QLabel @@ -288,6 +212,20 @@ Second DNS + + QLineEdit + + name + firstDNSLineEdit + + + + QLineEdit + + name + secondDNSLineEdit + + @@ -335,7 +273,6 @@ autoStart - profileCombo dhcpCheckBox leaseTime ipAddressEdit diff --git a/noncore/net/networksetup/interfacesetupimp.cpp b/noncore/net/networksetup/interfacesetupimp.cpp index 951aeee..c16d821 100644 --- a/noncore/net/networksetup/interfacesetupimp.cpp +++ b/noncore/net/networksetup/interfacesetupimp.cpp @@ -22,7 +22,6 @@ InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interfac assert(i); interface = i; interfaces = new Interfaces(); - changeProfile(profileCombo->currentText()); bool error = false; if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ staticGroupBox->hide(); @@ -30,7 +29,6 @@ InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interfac leaseTime->hide(); leaseHoursLabel->hide(); } - connect(profileCombo, SIGNAL(highlighted(const QString &)), this, SLOT(changeProfile(const QString &))); } /** @@ -90,35 +88,34 @@ bool InterfaceSetupImp::saveSettings(){ * The Profile has changed. * @profile the new profile. */ -void InterfaceSetupImp::changeProfile(const QString &profile){ - QString newInterfaceName; - if(profile.lower() == "all") - newInterfaceName = interface->getInterfaceName(); - else - newInterfaceName = interface->getInterfaceName() + "_" + profile; - if(newInterfaceName == currentInterfaceName) - return; - else{ - saveSettings(); - currentInterfaceName = newInterfaceName; - } - bool error = interfaces->setInterface(currentInterfaceName); +void InterfaceSetupImp::setProfile(const QString &profile){ + QString newInterfaceName = interface->getInterfaceName() + profile; // See if we have to make a interface. - if(error){ - qDebug("InterfaceSetupImp: Adding a new interface from profile change."); - interfaces->addInterface(currentInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); - error = interfaces->setInterface(currentInterfaceName); - if(error){ + if(!interfaces->setInterface(newInterfaceName)){ + interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); + if(!interfaces->setInterface(newInterfaceName)){ qDebug("InterfaceSetupImp: Added interface, but still can't set."); return; } + // Add making for this new interface if need too + if(profile != ""){ + if(!interfaces->setMapping(interface->getInterfaceName())){ + interfaces->addMapping(interface->getInterfaceName()); + if(!interfaces->setMapping(interface->getInterfaceName())){ + qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); + return; + } + } + interfaces->setScript("getprofile.sh"); + interfaces->setMap("map", newInterfaceName); + } } - //qDebug( currentInterfaceName.latin1() ); // 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 diff --git a/noncore/net/networksetup/interfacesetupimp.h b/noncore/net/networksetup/interfacesetupimp.h index 6c34718..7df0d46 100644 --- a/noncore/net/networksetup/interfacesetupimp.h +++ b/noncore/net/networksetup/interfacesetupimp.h @@ -14,13 +14,14 @@ public: protected slots: void accept(); - void changeProfile(const QString &profile); + +public slots: + void setProfile(const QString &profile); private: bool saveSettings(); Interfaces *interfaces; Interface *interface; - QString currentInterfaceName; }; diff --git a/noncore/net/networksetup/mainwindow.ui b/noncore/net/networksetup/mainwindow.ui index bea999b..3d30994 100644 --- a/noncore/net/networksetup/mainwindow.ui +++ b/noncore/net/networksetup/mainwindow.ui @@ -11,7 +11,7 @@ 0 0 - 230 + 240 289 @@ -61,7 +61,7 @@ text - i + s clickable @@ -103,6 +103,20 @@ text + in + + + clickable + true + + + resizeable + true + + + + + text IP diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index a446d29..3c0af6a 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp @@ -32,6 +32,7 @@ #define TEMP_ALL "/tmp/ifconfig-a" #define TEMP_UP "/tmp/ifconfig" +#define SCHEME "/var/lib/pcmcia/scheme" MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); @@ -53,7 +54,22 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(par 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); + + 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(); + } } /** @@ -61,11 +77,10 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(par */ MainWindowImp::~MainWindowImp(){ // Save profiles. - if(profiles.count() > 1){ - Config cfg("NetworkSetup"); - cfg.setGroup("General"); - cfg.writeEntry("Profiles", profiles.join(" ")); - } + Config cfg("NetworkSetup"); + cfg.setGroup("General"); + cfg.writeEntry("Profiles", profiles.join(" ")); + // Delete Modules and Libraries QMap::Iterator it; for( it = libraries.begin(); it != libraries.end(); ++it ){ @@ -205,15 +220,23 @@ void MainWindowImp::configureClicked(){ 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(currentProfileLabel->text()); QTabWidget *tabWidget = NULL; QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); if(moduleConfigure != NULL){ if(tabWidget != NULL){ InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); - tabWidget->insertTab(configure, "TCP/IP"); + configure->setProfile(currentProfileLabel->text()); + tabWidget->insertTab(configure, "TCP/IP"); + } moduleConfigure->showMaximized(); moduleConfigure->show(); @@ -222,6 +245,7 @@ void MainWindowImp::configureClicked(){ } InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); + configure->setProfile(currentProfileLabel->text()); configure->showMaximized(); configure->show(); } @@ -244,6 +268,12 @@ void MainWindowImp::informationClicked(){ 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); @@ -320,7 +350,7 @@ void MainWindowImp::jobDone(KProcess *process){ if(macAddress == -1) macAddress = line.length(); if(hardwareName != -1) - i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); + i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); interfaceNames.insert(i->getInterfaceName(), i); updateInterface(i); @@ -349,7 +379,7 @@ void MainWindowImp::jobDone(KProcess *process){ if(!found){ Interface *i = new Interface(this, *ni, false); i->setAttached(false); - i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); + i->setHardwareName("Disconnected"); interfaceNames.insert(i->getInterfaceName(), i); updateInterface(i); connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); @@ -406,7 +436,8 @@ void MainWindowImp::updateInterface(Interface *i){ item->setPixmap(1, (Resource::loadPixmap(typeName))); item->setText(2, i->getHardwareName()); - item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); + item->setText(3, QString("(%1)").arg(i->getInterfaceName())); + item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); } void MainWindowImp::newProfileChanged(const QString& newText){ @@ -437,17 +468,27 @@ void MainWindowImp::addProfile(){ */ void MainWindowImp::removeProfile(){ if(profilesList->count() <= 1){ - QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); + QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); return; } QString profileToRemove = profilesList->currentText(); + if(profileToRemove == "All"){ + QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); + return; + } + // Can't remove the curent profile + if(profileToRemove == currentProfileLabel->text()){ + QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); + return; + + } + if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); profilesList->clear(); for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) profilesList->insertItem((*it)); } - } /** @@ -455,7 +496,29 @@ void MainWindowImp::removeProfile(){ * @param newProfile the new profile. */ void MainWindowImp::changeProfile(){ - currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); + if(profilesList->currentItem() == -1){ + QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); + return; + } + QString newProfile = profilesList->text(profilesList->currentItem()); + if(newProfile != currentProfileLabel->text()){ + currentProfileLabel->setText(newProfile); + QFile file(SCHEME); + if ( file.open(IO_ReadWrite) ) { + QTextStream stream( &file ); + stream << QString("SCHEME=%1").arg(newProfile); + file.close(); + } + // restart all up devices? + if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ + // Go through them one by one + QMap::Iterator it; + for( it = items.begin(); it != items.end(); ++it ){ + if(it.key()->getStatus() == true) + it.key()->restart(); + } + } + } } // mainwindowimp.cpp diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp index 74eef5f..517604f 100644 --- a/noncore/net/networksetup/wlan/wlanimp.cpp +++ b/noncore/net/networksetup/wlan/wlanimp.cpp @@ -97,7 +97,6 @@ bool WLANImp::writeConfig() config.writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() ); config.writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() ); return writeWirelessOpts( config ); -// return true; } /** diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp index 9d34d75..53b5857 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.cpp +++ b/noncore/net/networksetup/wlan/wlanmodule.cpp @@ -32,7 +32,7 @@ QString WLANModule::getPixmapName(Interface* ){ */ bool WLANModule::isOwner(Interface *i){ if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ - i->setHardwareName(QString("802.11b (%1)").arg(i->getInterfaceName())); + i->setHardwareName("802.11b"); return true; } return false; -- cgit v0.9.0.2