summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-10-18 15:40:50 (UTC)
committer benmeyer <benmeyer>2002-10-18 15:40:50 (UTC)
commitc16dcab3fe45ae7193cbdfb2f62bf7e5482d449b (patch) (side-by-side diff)
tree39e69706b24b032364ad4483d2f33688e7054390
parent0910b94b5b6618c84b3eb6c457c9137d63a7277f (diff)
downloadopie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.zip
opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.gz
opie-c16dcab3fe45ae7193cbdfb2f62bf7e5482d449b.tar.bz2
Profiles copy
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces.cpp42
-rw-r--r--noncore/net/networksetup/interfaces.h1
-rw-r--r--noncore/net/networksetup/interfacesetupimp.cpp21
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp12
-rw-r--r--noncore/settings/networksettings/interfaces.cpp42
-rw-r--r--noncore/settings/networksettings/interfaces.h1
-rw-r--r--noncore/settings/networksettings/interfacesetupimp.cpp21
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp12
8 files changed, 128 insertions, 24 deletions
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp
index eef42df..0927258 100644
--- a/noncore/net/networksetup/interfaces.cpp
+++ b/noncore/net/networksetup/interfaces.cpp
@@ -168,4 +168,30 @@ bool Interfaces::addInterface(QString interface, QString family, QString method)
/**
+ * Copies interface with name interface to name newInterface
+ * @param newInterface name of the new interface.
+ * @return bool true if successfull
+ */
+bool Interfaces::copyInterface(QString interface, QString newInterface){
+ if(!setInterface(interface)) return false;
+
+ QStringList::Iterator it = currentIface;
+ it++;
+
+ bool error;
+ addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
+ if(!setInterface(newInterface)) return false;
+ QStringList::Iterator newIface = currentIface;
+ newIface++;
+
+ for ( it; 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.
@@ -402,12 +428,26 @@ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator
QString line = (*it).simplifyWhiteSpace();
if(line.contains(stanza) && line.contains(option)){
+ 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());
}
- qDebug("Found");
found = true;
iterator = it;
}
}
+ }
return found;
}
diff --git a/noncore/net/networksetup/interfaces.h b/noncore/net/networksetup/interfaces.h
index e617c17..7cf04f0 100644
--- a/noncore/net/networksetup/interfaces.h
+++ b/noncore/net/networksetup/interfaces.h
@@ -31,4 +31,5 @@ public:
bool removeInterface();
bool addInterface(QString interface, QString family, QString method);
+ bool copyInterface(QString oldInterface, QString newInterface);
bool setInterface(QString interface);
bool isInterfaceSet();
diff --git a/noncore/net/networksetup/interfacesetupimp.cpp b/noncore/net/networksetup/interfacesetupimp.cpp
index c16d821..bdbdfde 100644
--- a/noncore/net/networksetup/interfacesetupimp.cpp
+++ b/noncore/net/networksetup/interfacesetupimp.cpp
@@ -90,15 +90,13 @@ bool InterfaceSetupImp::saveSettings(){
*/
void InterfaceSetupImp::setProfile(const QString &profile){
- QString newInterfaceName = interface->getInterfaceName() + profile;
-
+ QString newInterfaceName = interface->getInterfaceName();
+ if(profile.length() > 0)
+ newInterfaceName += "_" + profile;
+ qDebug( newInterfaceName.latin1());
// See if we have to make a interface.
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 != ""){
+ interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
if(!interfaces->setMapping(interface->getInterfaceName())){
interfaces->addMapping(interface->getInterfaceName());
@@ -108,6 +106,13 @@ void InterfaceSetupImp::setProfile(const QString &profile){
}
}
- interfaces->setScript("getprofile.sh");
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 set.");
+ return;
+ }
}
}
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index 3c0af6a..9f07f0d 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -229,5 +229,5 @@ void MainWindowImp::configureClicked(){
Interface *i = interfaceItems[item];
if(i->getModuleOwner()){
- i->getModuleOwner()->setProfile(currentProfileLabel->text());
+ i->getModuleOwner()->setProfile(currentProfile);
QTabWidget *tabWidget = NULL;
QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
@@ -235,5 +235,5 @@ void MainWindowImp::configureClicked(){
if(tabWidget != NULL){
InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
tabWidget->insertTab(configure, "TCP/IP");
@@ -246,5 +246,5 @@ void MainWindowImp::configureClicked(){
InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
configure->showMaximized();
configure->show();
@@ -378,4 +378,5 @@ void MainWindowImp::jobDone(KProcess *process){
}
if(!found){
+ if(!(*ni).contains("_")){
Interface *i = new Interface(this, *ni, false);
i->setAttached(false);
@@ -388,4 +389,5 @@ void MainWindowImp::jobDone(KProcess *process){
}
}
+}
/**
@@ -490,4 +492,7 @@ void MainWindowImp::removeProfile(){
profilesList->insertItem((*it));
}
+
+ // Remove any interface settings and mappings.
+ //TODO
}
@@ -504,4 +509,5 @@ void MainWindowImp::changeProfile(){
if(newProfile != currentProfileLabel->text()){
currentProfileLabel->setText(newProfile);
+ QFile::remove(SCHEME);
QFile file(SCHEME);
if ( file.open(IO_ReadWrite) ) {
diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp
index eef42df..0927258 100644
--- a/noncore/settings/networksettings/interfaces.cpp
+++ b/noncore/settings/networksettings/interfaces.cpp
@@ -168,4 +168,30 @@ bool Interfaces::addInterface(QString interface, QString family, QString method)
/**
+ * Copies interface with name interface to name newInterface
+ * @param newInterface name of the new interface.
+ * @return bool true if successfull
+ */
+bool Interfaces::copyInterface(QString interface, QString newInterface){
+ if(!setInterface(interface)) return false;
+
+ QStringList::Iterator it = currentIface;
+ it++;
+
+ bool error;
+ addInterface(newInterface, getInterfaceFamily(error), getInterfaceMethod(error));
+ if(!setInterface(newInterface)) return false;
+ QStringList::Iterator newIface = currentIface;
+ newIface++;
+
+ for ( it; 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.
@@ -402,12 +428,26 @@ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator
QString line = (*it).simplifyWhiteSpace();
if(line.contains(stanza) && line.contains(option)){
+ 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());
}
- qDebug("Found");
found = true;
iterator = it;
}
}
+ }
return found;
}
diff --git a/noncore/settings/networksettings/interfaces.h b/noncore/settings/networksettings/interfaces.h
index e617c17..7cf04f0 100644
--- a/noncore/settings/networksettings/interfaces.h
+++ b/noncore/settings/networksettings/interfaces.h
@@ -31,4 +31,5 @@ public:
bool removeInterface();
bool addInterface(QString interface, QString family, QString method);
+ bool copyInterface(QString oldInterface, QString newInterface);
bool setInterface(QString interface);
bool isInterfaceSet();
diff --git a/noncore/settings/networksettings/interfacesetupimp.cpp b/noncore/settings/networksettings/interfacesetupimp.cpp
index c16d821..bdbdfde 100644
--- a/noncore/settings/networksettings/interfacesetupimp.cpp
+++ b/noncore/settings/networksettings/interfacesetupimp.cpp
@@ -90,15 +90,13 @@ bool InterfaceSetupImp::saveSettings(){
*/
void InterfaceSetupImp::setProfile(const QString &profile){
- QString newInterfaceName = interface->getInterfaceName() + profile;
-
+ QString newInterfaceName = interface->getInterfaceName();
+ if(profile.length() > 0)
+ newInterfaceName += "_" + profile;
+ qDebug( newInterfaceName.latin1());
// See if we have to make a interface.
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 != ""){
+ interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName);
if(!interfaces->setMapping(interface->getInterfaceName())){
interfaces->addMapping(interface->getInterfaceName());
@@ -108,6 +106,13 @@ void InterfaceSetupImp::setProfile(const QString &profile){
}
}
- interfaces->setScript("getprofile.sh");
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 set.");
+ return;
+ }
}
}
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 3c0af6a..9f07f0d 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -229,5 +229,5 @@ void MainWindowImp::configureClicked(){
Interface *i = interfaceItems[item];
if(i->getModuleOwner()){
- i->getModuleOwner()->setProfile(currentProfileLabel->text());
+ i->getModuleOwner()->setProfile(currentProfile);
QTabWidget *tabWidget = NULL;
QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
@@ -235,5 +235,5 @@ void MainWindowImp::configureClicked(){
if(tabWidget != NULL){
InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
tabWidget->insertTab(configure, "TCP/IP");
@@ -246,5 +246,5 @@ void MainWindowImp::configureClicked(){
InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
configure->showMaximized();
configure->show();
@@ -378,4 +378,5 @@ void MainWindowImp::jobDone(KProcess *process){
}
if(!found){
+ if(!(*ni).contains("_")){
Interface *i = new Interface(this, *ni, false);
i->setAttached(false);
@@ -388,4 +389,5 @@ void MainWindowImp::jobDone(KProcess *process){
}
}
+}
/**
@@ -490,4 +492,7 @@ void MainWindowImp::removeProfile(){
profilesList->insertItem((*it));
}
+
+ // Remove any interface settings and mappings.
+ //TODO
}
@@ -504,4 +509,5 @@ void MainWindowImp::changeProfile(){
if(newProfile != currentProfileLabel->text()){
currentProfileLabel->setText(newProfile);
+ QFile::remove(SCHEME);
QFile file(SCHEME);
if ( file.open(IO_ReadWrite) ) {