3 files changed, 42 insertions, 27 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp index 49a47ae..8de30de 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp @@ -1,196 +1,199 @@ #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. + * Save the current settings, then write out the interfaces file and close. */ bool InterfaceSetupImp::saveChanges(){ bool error; QString iface = interfaces->getInterfaceName(error); 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); } } - + // 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; + 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())); + secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); } ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); - gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); + 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 diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 8ea241d..2d714ca 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp @@ -595,66 +595,71 @@ void MainWindowImp::removeProfile(){ } } /** * A new profile has been selected, change. * @param newProfile the new profile. */ void MainWindowImp::changeProfile(){ if(profilesList->currentItem() == -1){ QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); return; } QString newProfile = profilesList->text(profilesList->currentItem()); if(newProfile != currentProfileLabel->text()){ currentProfileLabel->setText(newProfile); QFile::remove(scheme); 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<Interface*, QListViewItem*>::Iterator it; for( it = items.begin(); it != items.end(); ++it ){ if(it.key()->getStatus() == true) it.key()->restart(); } } } // TODO change the profile in the modules } void MainWindowImp::makeChannel() { channel = new QCopChannel( "QPE/Application/networksettings", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); } void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) { bool found = false; qDebug("MainWindowImp::receive QCop msg >"+msg+"<"); + if (msg == "raise") { + raise(); + return; + } + QString dest = msg.left(msg.find("(")); QCString param = msg.right(msg.length() - msg.find("(") - 1); param = param.left( param.length() - 1 ); qDebug("dest >%s< param >"+param+"<",dest.latin1()); QMap<Module*, QLibrary*>::Iterator it; for( it = libraries.begin(); it != libraries.end(); ++it ){ qDebug("plugin >%s<", it.key()->type().latin1() ); if(it.key()->type() == dest){ it.key()->receive( param, arg ); found = true; } } if (found) QPEApplication::setKeepRunning(); else qDebug("Huh what do ya want"); } diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp index 371b689..7bded85 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.cpp +++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp @@ -25,191 +25,198 @@ WLANModule::WLANModule() } /** * Delete any interfaces that we own. */ WLANModule::~WLANModule(){ Interface *i; for ( i=list.first(); i != 0; i=list.next() ) delete i; } /** * Change the current profile */ void WLANModule::setProfile(const QString &newProfile){ profile = newProfile; } /** * get the icon name for this device. * @param Interface* can be used in determining the icon. * @return QString the icon name (minus .png, .gif etc) */ QString WLANModule::getPixmapName(Interface* ){ return "wlan"; } /** * Check to see if the interface i is owned by this module. * @param Interface* interface to check against * @return bool true if i is owned by this module, false otherwise. */ bool WLANModule::isOwner(Interface *i){ WExtensions we(i->getInterfaceName()); if(!we.doesHaveWirelessExtensions()) return false; i->setHardwareName("802.11b"); list.append(i); return true; } /** * Create, and return the WLANConfigure Module * @return QWidget* pointer to this modules configure. */ QWidget *WLANModule::configure(Interface *i){ - WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, false, Qt::WDestructiveClose); + WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, true, Qt::WDestructiveClose); wlanconfig->setProfile(profile); return wlanconfig; } /** * Create, and return the Information Module * @return QWidget* pointer to this modules info. */ QWidget *WLANModule::information(Interface *i){ WExtensions we(i->getInterfaceName()); if(!we.doesHaveWirelessExtensions()) return NULL; return getInfo( i ); } /** * Get all active (up or down) interfaces * @return QList<Interface> A list of interfaces that exsist that havn't * been called by isOwner() */ QList<Interface> WLANModule::getInterfaces(){ return list; } /** * Attempt to add a new interface as defined by name * @param name the name of the type of interface that should be created given * by possibleNewInterfaces(); * @return Interface* NULL if it was unable to be created. */ Interface *WLANModule::addNewInterface(const QString &){ // We can't add a 802.11 interface, either the hardware will be there // or it wont. return NULL; } /** * Attempts to remove the interface, doesn't delete i * @return bool true if successfull, false otherwise. */ bool WLANModule::remove(Interface*){ // Can't remove a hardware device, you can stop it though. return false; } void WLANModule::receive(const QCString ¶m, const QByteArray &arg) { qDebug("WLANModule::receive "+param); QStringList params = QStringList::split(",",param); int count = params.count(); qDebug("WLANModule got %i params", count ); if (count < 2){ qDebug("Erorr less than 2 parameter"); qDebug("RETURNING"); return; } QDataStream stream(arg,IO_ReadOnly); QString interface; QString action; + QDialog *toShow; while (! stream.atEnd() ){ stream >> interface; stream >> action; qDebug("WLANModule got interface %s and acion %s", interface.latin1(), action.latin1()); // find interfaces Interface *ifa=0; for ( Interface *i=list.first(); i != 0; i=list.next() ){ if (i->getInterfaceName() == interface){ qDebug("WLANModule found interface %s",interface.latin1()); ifa = i; } } if (ifa == 0){ qDebug("WLANModule Did not find %s",interface.latin1()); - qDebug("returning"); - return; + qDebug("skipping"); + count = 0; } if (count == 2){ // those should call the interface directly QWidget *info = getInfo( ifa ); info->showMaximized(); if ( action.contains("start" ) ){ ifa->start(); } else if ( action.contains("restart" ) ){ ifa->restart(); } else if ( action.contains("stop" ) ){ ifa->stop(); }else if ( action.contains("refresh" ) ){ ifa->refresh(); } }else if (count == 3){ QString value; if (!wlanconfigWiget){ //FIXME: what if it got closed meanwhile? wlanconfigWiget = (WLANImp*) configure(ifa); + toShow = (QDialog*) wlanconfigWiget; } wlanconfigWiget->showMaximized(); stream >> value; qDebug("WLANModule is setting %s of %s to %s", action.latin1(), interface.latin1(), value.latin1() ); if ( action.contains("ESSID") ){ QComboBox *combo = wlanconfigWiget->essid; bool found = false; for ( int i = 0; i < combo->count(); i++) if ( combo->text( i ) == value ){ combo->setCurrentItem( i ); found = true; } if (!found) combo->insertItem( value, 0 ); }else if ( action.contains("Mode") ){ QComboBox *combo = wlanconfigWiget->mode; for ( int i = 0; i < combo->count(); i++) if ( combo->text( i ) == value ){ combo->setCurrentItem( i ); } }else if (action.contains("Channel")){ - wlanconfigWiget->specifyChan->setChecked( true ); - wlanconfigWiget->networkChannel->setValue( value.toInt() ); + bool ok; + int chan = value.toInt( &ok ); + if (ok){ + wlanconfigWiget->specifyChan->setChecked( true ); + wlanconfigWiget->networkChannel->setValue( chan ); + } }else if (action.contains("MacAddr")){ wlanconfigWiget->specifyAp->setChecked( true ); wlanconfigWiget->macEdit->setText( value ); }else qDebug("wlan plugin has no clue"); } }// while stream + if (toShow) toShow->exec(); } QWidget *WLANModule::getInfo( Interface *i) { qDebug("WLANModule::getInfo start"); WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); info->tabWidget->insertTab(information, "TCP/IP", 0); qDebug("WLANModule::getInfo return"); return info; } |