summaryrefslogtreecommitdiff
authorkergoth <kergoth>2003-04-15 00:40:18 (UTC)
committer kergoth <kergoth>2003-04-15 00:40:18 (UTC)
commit414e71d6189ffdeb07dcca8225ecf69331d0023c (patch) (side-by-side diff)
tree7f24b2508735537171aa308c20d499b696c0151a
parent54c3c91b776f277fdcf2e78621a28e98cc55ab5b (diff)
downloadopie-414e71d6189ffdeb07dcca8225ecf69331d0023c.zip
opie-414e71d6189ffdeb07dcca8225ecf69331d0023c.tar.gz
opie-414e71d6189ffdeb07dcca8225ecf69331d0023c.tar.bz2
1) When selecting dhcp, remove the static options, since we're no longer
removing all options. 2) Restart the network interface when saveChanges() is called. 3) Use OWait and a status message to give feedback to the user during the interface restart.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interfacesetupimp.cpp55
1 files changed, 51 insertions, 4 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
index fc65c5f..8d78828 100644
--- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp
@@ -1,92 +1,135 @@
#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);
if(!saveSettings())
return false;
+
+ qWarning("restarting interface %s\n", iface.latin1());
interfaces->write();
+
+ 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;
}
- //interfaces.removeAllInterfaceOptions();
-
// DHCP
- if(dhcpCheckBox->isChecked())
+ if(dhcpCheckBox->isChecked()) {
interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP);
- else{
+ 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){
@@ -122,28 +165,32 @@ void InterfaceSetupImp::setProfile(const QString &profile){
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);
if(dns.contains(" ")){
firstDNSLineEdit->setText(dns.mid(0, dns.find(" ")));
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));
+
+ qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1());
+ qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1());
+
}
// interfacesetup.cpp