author | benmeyer <benmeyer> | 2002-10-18 16:27:02 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-18 16:27:02 (UTC) |
commit | 12851a09a2761ca6e189f080e9ca69bf4974302f (patch) (side-by-side diff) | |
tree | 1b9a368fc5e424d4bf60f4c582b87b23a975c26a | |
parent | 47e60a8dc20f46dd00b9405f7fde122792018627 (diff) | |
download | opie-12851a09a2761ca6e189f080e9ca69bf4974302f.zip opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.gz opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.bz2 |
Can now remove mapping and is done so automagicly when you delete a profile
-rw-r--r-- | noncore/net/networksetup/interfaces.cpp | 64 | ||||
-rw-r--r-- | noncore/net/networksetup/interfaces.h | 4 | ||||
-rw-r--r-- | noncore/net/networksetup/interfacesetupimp.cpp | 1 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 38 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.h | 1 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces.cpp | 64 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces.h | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfacesetupimp.cpp | 1 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 38 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.h | 1 |
10 files changed, 186 insertions, 30 deletions
diff --git a/noncore/net/networksetup/interfaces.cpp b/noncore/net/networksetup/interfaces.cpp index 0927258..9155890 100644 --- a/noncore/net/networksetup/interfaces.cpp +++ b/noncore/net/networksetup/interfaces.cpp @@ -337,4 +337,3 @@ QString Interfaces::getInterfaceOption(QString option, bool &error){ * Set a value for an option in the currently selected interface. If option - * doesn't exist then it is added along with the value. If value is set to an - * empty string then option is removed. + * doesn't exist then it is added along with the value. * @param option the options to set the value. @@ -349,2 +348,13 @@ bool Interfaces::setInterfaceOption(QString option, QString value){ /** + * Removes a value for an option in the currently selected interface. + * @param option the options to set the value. + * @param value the value that option should be set to. + * @param error set to true if any error occurs, false otherwise. + * @return QString the options value. QString::null if error == true + */ +bool Interfaces::removeInterfaceOption(QString option, QString value){ + return removeOption(currentIface, option, value); +} + +/** * Removes all of the options from the currently selected interface. @@ -379,2 +389,13 @@ void Interfaces::addMapping(QString option){ /** + * Remove the currently selected map and all of its options. + * @return bool if successfull or not. + */ +bool Interfaces::removeMapping(){ + if(currentMapping == interfaces.end()) + return false; + (*currentMapping) = ""; + return removeAllOptions(currentMapping); +} + +/** * Set a map option within a mapping. @@ -389,2 +410,12 @@ bool Interfaces::setMap(QString map, QString value){ /** + * Removes a map option within a mapping. + * @param map map to use + * @param value value to go with map + * @return bool true if it is successfull. + */ +bool Interfaces::removeMap(QString map, QString value){ + return removeOption(currentMapping, map, value); +} + +/** * Get a map value within a mapping. @@ -479,5 +510,2 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString found = true; - if(value == "") - (*it) = ""; - else (*it) = QString("\t%1 %2").arg(option).arg(value); @@ -492,2 +520,28 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString } +/** + * Removes a option in a stanza + * @param start the start of the stanza + * @param option the option to use when setting value. + * @return bool true if successfull, false otherwise. + */ +bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ + if(start == interfaces.end()) + return false; + + bool found = false; + for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { + if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ + // got to the end without finding it + break; + } + if((*it).contains(option) && (*it).contains(value) &&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()); + found = true; + (*it) = ""; + } + } + return found; +} diff --git a/noncore/net/networksetup/interfaces.h b/noncore/net/networksetup/interfaces.h index 7cf04f0..e09ea71 100644 --- a/noncore/net/networksetup/interfaces.h +++ b/noncore/net/networksetup/interfaces.h @@ -43,2 +43,3 @@ public: bool setInterfaceOption(QString option, QString value); + bool removeInterfaceOption(QString option, QString value); bool removeAllInterfaceOptions(); @@ -46,4 +47,6 @@ public: bool setMapping(QString interface); + bool removeMapping(); void addMapping(QString options); bool setMap(QString map, QString value); + bool removeMap(QString map, QString value); QString getMap(QString map, bool &error); @@ -57,2 +60,3 @@ private: bool setOption(QStringList::Iterator start, QString option, QString value); + bool removeOption(QStringList::Iterator start, QString option, QString value); QString getOption(QStringList::Iterator start, QString option, bool &error); diff --git a/noncore/net/networksetup/interfacesetupimp.cpp b/noncore/net/networksetup/interfacesetupimp.cpp index bdbdfde..1327726 100644 --- a/noncore/net/networksetup/interfacesetupimp.cpp +++ b/noncore/net/networksetup/interfacesetupimp.cpp @@ -94,3 +94,2 @@ void InterfaceSetupImp::setProfile(const QString &profile){ newInterfaceName += "_" + profile; - qDebug( newInterfaceName.latin1()); // See if we have to make a interface. diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 9f07f0d..01063c2 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp @@ -34,3 +34,4 @@ -#define SCHEME "/var/lib/pcmcia/scheme"
+#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
+
MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
@@ -58,4 +59,5 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(par advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
+ scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
- QFile file(SCHEME);
+ QFile file(scheme);
if ( file.open(IO_ReadOnly) ) { // file opened successfully
@@ -97,3 +99,3 @@ MainWindowImp::~MainWindowImp(){ void MainWindowImp::loadModules(QString path){
- qDebug(path.latin1());
+ //qDebug(path.latin1());
QDir d(path);
@@ -122,3 +124,3 @@ void MainWindowImp::loadModules(QString path){ Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
- qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
+ //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
QLibrary *lib = new QLibrary(pluginFileName);
@@ -492,6 +494,24 @@ void MainWindowImp::removeProfile(){ profilesList->insertItem((*it));
- }
- // Remove any interface settings and mappings.
- //TODO
+ // Remove any interface settings and mappings.
+ Interfaces interfaces;
+ // Go through them one by one
+ QMap<Interface*, QListViewItem*>::Iterator it;
+ for( it = items.begin(); it != items.end(); ++it ){
+ QString interfaceName = it.key()->getInterfaceName();
+ qDebug(interfaceName.latin1());
+ if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){
+ interfaces.removeInterface();
+ if(interfaces.setMapping(interfaceName)){
+ if(profilesList->count() == 1)
+ interfaces.removeMapping();
+ else{
+ interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
+ }
+ }
+ interfaces.write();
+ break;
+ }
+ }
+ }
}
@@ -510,4 +530,4 @@ void MainWindowImp::changeProfile(){ currentProfileLabel->setText(newProfile);
- QFile::remove(SCHEME);
- QFile file(SCHEME);
+ QFile::remove(scheme);
+ QFile file(scheme);
if ( file.open(IO_ReadWrite) ) {
diff --git a/noncore/net/networksetup/mainwindowimp.h b/noncore/net/networksetup/mainwindowimp.h index c67c161..e5284b4 100644 --- a/noncore/net/networksetup/mainwindowimp.h +++ b/noncore/net/networksetup/mainwindowimp.h @@ -52,2 +52,3 @@ private: bool advancedUserMode;
+ QString scheme;
};
diff --git a/noncore/settings/networksettings/interfaces.cpp b/noncore/settings/networksettings/interfaces.cpp index 0927258..9155890 100644 --- a/noncore/settings/networksettings/interfaces.cpp +++ b/noncore/settings/networksettings/interfaces.cpp @@ -337,4 +337,3 @@ QString Interfaces::getInterfaceOption(QString option, bool &error){ * Set a value for an option in the currently selected interface. If option - * doesn't exist then it is added along with the value. If value is set to an - * empty string then option is removed. + * doesn't exist then it is added along with the value. * @param option the options to set the value. @@ -349,2 +348,13 @@ bool Interfaces::setInterfaceOption(QString option, QString value){ /** + * Removes a value for an option in the currently selected interface. + * @param option the options to set the value. + * @param value the value that option should be set to. + * @param error set to true if any error occurs, false otherwise. + * @return QString the options value. QString::null if error == true + */ +bool Interfaces::removeInterfaceOption(QString option, QString value){ + return removeOption(currentIface, option, value); +} + +/** * Removes all of the options from the currently selected interface. @@ -379,2 +389,13 @@ void Interfaces::addMapping(QString option){ /** + * Remove the currently selected map and all of its options. + * @return bool if successfull or not. + */ +bool Interfaces::removeMapping(){ + if(currentMapping == interfaces.end()) + return false; + (*currentMapping) = ""; + return removeAllOptions(currentMapping); +} + +/** * Set a map option within a mapping. @@ -389,2 +410,12 @@ bool Interfaces::setMap(QString map, QString value){ /** + * Removes a map option within a mapping. + * @param map map to use + * @param value value to go with map + * @return bool true if it is successfull. + */ +bool Interfaces::removeMap(QString map, QString value){ + return removeOption(currentMapping, map, value); +} + +/** * Get a map value within a mapping. @@ -479,5 +510,2 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString found = true; - if(value == "") - (*it) = ""; - else (*it) = QString("\t%1 %2").arg(option).arg(value); @@ -492,2 +520,28 @@ bool Interfaces::setOption(QStringList::Iterator start, QString option, QString } +/** + * Removes a option in a stanza + * @param start the start of the stanza + * @param option the option to use when setting value. + * @return bool true if successfull, false otherwise. + */ +bool Interfaces::removeOption(QStringList::Iterator start, QString option, QString value){ + if(start == interfaces.end()) + return false; + + bool found = false; + for ( QStringList::Iterator it = start; it != interfaces.end(); ++it ) { + if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){ + // got to the end without finding it + break; + } + if((*it).contains(option) && (*it).contains(value) &&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()); + found = true; + (*it) = ""; + } + } + return found; +} diff --git a/noncore/settings/networksettings/interfaces.h b/noncore/settings/networksettings/interfaces.h index 7cf04f0..e09ea71 100644 --- a/noncore/settings/networksettings/interfaces.h +++ b/noncore/settings/networksettings/interfaces.h @@ -43,2 +43,3 @@ public: bool setInterfaceOption(QString option, QString value); + bool removeInterfaceOption(QString option, QString value); bool removeAllInterfaceOptions(); @@ -46,4 +47,6 @@ public: bool setMapping(QString interface); + bool removeMapping(); void addMapping(QString options); bool setMap(QString map, QString value); + bool removeMap(QString map, QString value); QString getMap(QString map, bool &error); @@ -57,2 +60,3 @@ private: bool setOption(QStringList::Iterator start, QString option, QString value); + bool removeOption(QStringList::Iterator start, QString option, QString value); QString getOption(QStringList::Iterator start, QString option, bool &error); diff --git a/noncore/settings/networksettings/interfacesetupimp.cpp b/noncore/settings/networksettings/interfacesetupimp.cpp index bdbdfde..1327726 100644 --- a/noncore/settings/networksettings/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfacesetupimp.cpp @@ -94,3 +94,2 @@ void InterfaceSetupImp::setProfile(const QString &profile){ newInterfaceName += "_" + profile; - qDebug( newInterfaceName.latin1()); // See if we have to make a interface. diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 9f07f0d..01063c2 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp @@ -34,3 +34,4 @@ -#define SCHEME "/var/lib/pcmcia/scheme"
+#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
+
MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
@@ -58,4 +59,5 @@ MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(par advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
+ scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
- QFile file(SCHEME);
+ QFile file(scheme);
if ( file.open(IO_ReadOnly) ) { // file opened successfully
@@ -97,3 +99,3 @@ MainWindowImp::~MainWindowImp(){ void MainWindowImp::loadModules(QString path){
- qDebug(path.latin1());
+ //qDebug(path.latin1());
QDir d(path);
@@ -122,3 +124,3 @@ void MainWindowImp::loadModules(QString path){ Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
- qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
+ //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
QLibrary *lib = new QLibrary(pluginFileName);
@@ -492,6 +494,24 @@ void MainWindowImp::removeProfile(){ profilesList->insertItem((*it));
- }
- // Remove any interface settings and mappings.
- //TODO
+ // Remove any interface settings and mappings.
+ Interfaces interfaces;
+ // Go through them one by one
+ QMap<Interface*, QListViewItem*>::Iterator it;
+ for( it = items.begin(); it != items.end(); ++it ){
+ QString interfaceName = it.key()->getInterfaceName();
+ qDebug(interfaceName.latin1());
+ if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){
+ interfaces.removeInterface();
+ if(interfaces.setMapping(interfaceName)){
+ if(profilesList->count() == 1)
+ interfaces.removeMapping();
+ else{
+ interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
+ }
+ }
+ interfaces.write();
+ break;
+ }
+ }
+ }
}
@@ -510,4 +530,4 @@ void MainWindowImp::changeProfile(){ currentProfileLabel->setText(newProfile);
- QFile::remove(SCHEME);
- QFile file(SCHEME);
+ QFile::remove(scheme);
+ QFile file(scheme);
if ( file.open(IO_ReadWrite) ) {
diff --git a/noncore/settings/networksettings/mainwindowimp.h b/noncore/settings/networksettings/mainwindowimp.h index c67c161..e5284b4 100644 --- a/noncore/settings/networksettings/mainwindowimp.h +++ b/noncore/settings/networksettings/mainwindowimp.h @@ -52,2 +52,3 @@ private: bool advancedUserMode;
+ QString scheme;
};
|