summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces.cpp50
-rw-r--r--noncore/net/networksetup/interfaces.h1
-rw-r--r--noncore/net/networksetup/interfacesetupimp.cpp21
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp24
-rw-r--r--noncore/settings/networksettings/interfaces.cpp50
-rw-r--r--noncore/settings/networksettings/interfaces.h1
-rw-r--r--noncore/settings/networksettings/interfacesetupimp.cpp21
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp24
8 files changed, 148 insertions, 44 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
@@ -162,16 +162,42 @@ bool Interfaces::addInterface(QString interface, QString family, QString method)
interface = interface.simplifyWhiteSpace();
interface = interface.replace(QRegExp(" "), "");
interfaces.append("");
interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method));
return true;
}
/**
+ * 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.
*/
bool Interfaces::removeInterface(){
if(currentIface == interfaces.end())
return false;
(*currentIface) = "";
return removeAllInterfaceOptions();
@@ -396,22 +422,36 @@ QString Interfaces::getScript(bool &error){
* @return bool true if the stanza is found.
*/
bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
bool found = false;
iterator = interfaces.end();
for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
QString line = (*it).simplifyWhiteSpace();
if(line.contains(stanza) && line.contains(option)){
- if(found == true){
- qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
+ 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());
+ }
+ found = true;
+ iterator = it;
}
- qDebug("Found");
- found = true;
- iterator = it;
}
}
return found;
}
/**
* Sets a value of an option in a stanza
* @param start the start of the stanza
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
@@ -25,16 +25,17 @@ public:
Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
QStringList getInterfaceList();
bool isAuto(QString interface);
bool setAuto(QString interface, bool setAuto);
bool removeInterface();
bool addInterface(QString interface, QString family, QString method);
+ bool copyInterface(QString oldInterface, QString newInterface);
bool setInterface(QString interface);
bool isInterfaceSet();
QString getInterfaceName(bool &error);
bool setInterfaceName(QString newName);
QString getInterfaceFamily(bool &error);
bool setInterfaceFamily(QString newName);
QString getInterfaceMethod(bool &error);
bool setInterfaceMethod(QString newName);
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
@@ -84,36 +84,41 @@ bool InterfaceSetupImp::saveSettings(){
return true;
}
/**
* The Profile has changed.
* @profile the new profile.
*/
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());
if(!interfaces->setMapping(interface->getInterfaceName())){
qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
return;
}
}
- 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;
+ }
}
}
// 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)
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
@@ -223,34 +223,34 @@ void MainWindowImp::configureClicked(){
QString currentProfile = currentProfileLabel->text();
if(profilesList->count() <= 1 || currentProfile == "All"){
currentProfile = "";
}
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);
if(moduleConfigure != NULL){
if(tabWidget != NULL){
InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
tabWidget->insertTab(configure, "TCP/IP");
}
moduleConfigure->showMaximized();
moduleConfigure->show();
return;
}
}
InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
configure->showMaximized();
configure->show();
}
/**
* Pull up the information about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure with a empty
@@ -372,22 +372,24 @@ void MainWindowImp::jobDone(KProcess *process){
QMap<QString, Interface*>::Iterator it;
for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
bool found = false;
for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
if(it.key() == (*ni))
found = true;
}
if(!found){
- Interface *i = new Interface(this, *ni, false);
- i->setAttached(false);
- i->setHardwareName("Disconnected");
- interfaceNames.insert(i->getInterfaceName(), i);
- updateInterface(i);
- connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
+ if(!(*ni).contains("_")){
+ Interface *i = new Interface(this, *ni, false);
+ i->setAttached(false);
+ i->setHardwareName("Disconnected");
+ interfaceNames.insert(i->getInterfaceName(), i);
+ updateInterface(i);
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
+ }
}
}
}
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
@@ -484,30 +486,34 @@ void MainWindowImp::removeProfile(){
}
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));
}
+
+ // Remove any interface settings and mappings.
+ //TODO
}
/**
* 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.", "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){
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
@@ -162,16 +162,42 @@ bool Interfaces::addInterface(QString interface, QString family, QString method)
interface = interface.simplifyWhiteSpace();
interface = interface.replace(QRegExp(" "), "");
interfaces.append("");
interfaces.append(QString(IFACE " %1 %2 %3").arg(interface).arg(family).arg(method));
return true;
}
/**
+ * 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.
*/
bool Interfaces::removeInterface(){
if(currentIface == interfaces.end())
return false;
(*currentIface) = "";
return removeAllInterfaceOptions();
@@ -396,22 +422,36 @@ QString Interfaces::getScript(bool &error){
* @return bool true if the stanza is found.
*/
bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator &iterator){
bool found = false;
iterator = interfaces.end();
for ( QStringList::Iterator it = interfaces.begin(); it != interfaces.end(); ++it ) {
QString line = (*it).simplifyWhiteSpace();
if(line.contains(stanza) && line.contains(option)){
- if(found == true){
- qDebug(QString("Interfaces: Found multiple stanza's for search: %1 %2").arg(stanza).arg(option).latin1());
+ 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());
+ }
+ found = true;
+ iterator = it;
}
- qDebug("Found");
- found = true;
- iterator = it;
}
}
return found;
}
/**
* Sets a value of an option in a stanza
* @param start the start of the stanza
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
@@ -25,16 +25,17 @@ public:
Interfaces(QString useInterfacesFile = "/etc/network/interfaces");
QStringList getInterfaceList();
bool isAuto(QString interface);
bool setAuto(QString interface, bool setAuto);
bool removeInterface();
bool addInterface(QString interface, QString family, QString method);
+ bool copyInterface(QString oldInterface, QString newInterface);
bool setInterface(QString interface);
bool isInterfaceSet();
QString getInterfaceName(bool &error);
bool setInterfaceName(QString newName);
QString getInterfaceFamily(bool &error);
bool setInterfaceFamily(QString newName);
QString getInterfaceMethod(bool &error);
bool setInterfaceMethod(QString newName);
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
@@ -84,36 +84,41 @@ bool InterfaceSetupImp::saveSettings(){
return true;
}
/**
* The Profile has changed.
* @profile the new profile.
*/
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());
if(!interfaces->setMapping(interface->getInterfaceName())){
qDebug("InterfaceSetupImp: Added Mapping, but still can't set.");
return;
}
}
- 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;
+ }
}
}
// 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)
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
@@ -223,34 +223,34 @@ void MainWindowImp::configureClicked(){
QString currentProfile = currentProfileLabel->text();
if(profilesList->count() <= 1 || currentProfile == "All"){
currentProfile = "";
}
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);
if(moduleConfigure != NULL){
if(tabWidget != NULL){
InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
tabWidget->insertTab(configure, "TCP/IP");
}
moduleConfigure->showMaximized();
moduleConfigure->show();
return;
}
}
InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
- configure->setProfile(currentProfileLabel->text());
+ configure->setProfile(currentProfile);
configure->showMaximized();
configure->show();
}
/**
* Pull up the information about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure with a empty
@@ -372,22 +372,24 @@ void MainWindowImp::jobDone(KProcess *process){
QMap<QString, Interface*>::Iterator it;
for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
bool found = false;
for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
if(it.key() == (*ni))
found = true;
}
if(!found){
- Interface *i = new Interface(this, *ni, false);
- i->setAttached(false);
- i->setHardwareName("Disconnected");
- interfaceNames.insert(i->getInterfaceName(), i);
- updateInterface(i);
- connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
+ if(!(*ni).contains("_")){
+ Interface *i = new Interface(this, *ni, false);
+ i->setAttached(false);
+ i->setHardwareName("Disconnected");
+ interfaceNames.insert(i->getInterfaceName(), i);
+ updateInterface(i);
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
+ }
}
}
}
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
@@ -484,30 +486,34 @@ void MainWindowImp::removeProfile(){
}
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));
}
+
+ // Remove any interface settings and mappings.
+ //TODO
}
/**
* 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.", "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){