summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-10-18 16:27:02 (UTC)
committer benmeyer <benmeyer>2002-10-18 16:27:02 (UTC)
commit12851a09a2761ca6e189f080e9ca69bf4974302f (patch) (side-by-side diff)
tree1b9a368fc5e424d4bf60f4c582b87b23a975c26a
parent47e60a8dc20f46dd00b9405f7fde122792018627 (diff)
downloadopie-12851a09a2761ca6e189f080e9ca69bf4974302f.zip
opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.gz
opie-12851a09a2761ca6e189f080e9ca69bf4974302f.tar.bz2
Can now remove mapping and is done so automagicly when you delete a profile
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/interfaces.cpp64
-rw-r--r--noncore/net/networksetup/interfaces.h4
-rw-r--r--noncore/net/networksetup/interfacesetupimp.cpp1
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp38
-rw-r--r--noncore/net/networksetup/mainwindowimp.h1
-rw-r--r--noncore/settings/networksettings/interfaces.cpp64
-rw-r--r--noncore/settings/networksettings/interfaces.h4
-rw-r--r--noncore/settings/networksettings/interfacesetupimp.cpp1
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp38
-rw-r--r--noncore/settings/networksettings/mainwindowimp.h1
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
@@ -314,100 +314,131 @@ bool Interfaces::setInterfaceFamily(QString newName){
bool Interfaces::setInterfaceMethod(QString newName){
if(currentIface == interfaces.end())
return false;
bool returnValue = false;
(*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName);
return !returnValue;
}
/**
* Get a value for an option in the currently selected interface. For example
* calling getInterfaceOption("address") on the following stanza would
* return 192.168.1.1.
* iface eth0 static
* address 192.168.1.1
* @param option the options to get the value.
* @param error set to true if any error occurs, false otherwise.
* @return QString the options value. QString::null if error == true
*/
QString Interfaces::getInterfaceOption(QString option, bool &error){
return getOption(currentIface, option, 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.
* @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::setInterfaceOption(QString option, QString value){
return setOption(currentIface, option, 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.
* @return bool error if if successfull
*/
bool Interfaces::removeAllInterfaceOptions(){
return removeAllOptions(currentIface);
}
/**
* Set the current map to interface's map. This needs to be done before you
* can call addMapping(), set/getMap(), and get/setScript().
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @return bool true if it is successfull.
*/
bool Interfaces::setMapping(QString interface){
interface = interface.simplifyWhiteSpace();
interface = interface.replace(QRegExp(" "), "");
return setStanza(MAPPING, interface, currentMapping);
}
/**
* Adds a new Mapping to the interfaces file with interfaces.
* @param interface the name(s) of the interfaces to set to this mapping
*/
void Interfaces::addMapping(QString option){
interfaces.append("");
interfaces.append(QString(MAPPING " %1").arg(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.
* @param map map to use
* @param value value to go with map
* @return bool true if it is successfull.
*/
bool Interfaces::setMap(QString map, QString value){
return setOption(currentMapping, map, 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.
* @param map map to get value of
* @param bool true if it is successfull.
* @return value that goes to the map
*/
QString Interfaces::getMap(QString map, bool &error){
return getOption(currentMapping, map, error);
}
/**
* Sets a script value of the current mapping to argument.
* @param argument the script name.
* @return true if successfull.
*/
bool Interfaces::setScript(QString argument){
return setOption(currentMapping, "script", argument);
}
/**
* @param error true if could not retrieve the current script argument.
* @return QString the argument of the script for the current mapping.
*/
QString Interfaces::getScript(bool &error){
return getOption(currentMapping, "script", error);
@@ -456,61 +487,84 @@ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator
* Sets a value of an 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::setOption(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){
if(!found && value != ""){
// Got to the end of the stanza without finding it, so append it.
interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
}
found = true;
break;
}
if((*it).contains(option) && 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;
- if(value == "")
- (*it) = "";
- else
(*it) = QString("\t%1 %2").arg(option).arg(value);
}
}
if(!found){
QStringList::Iterator p = start;
interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
found = true;
}
return found;
}
+/**
+ * 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;
+}
/**
* Removes all options in a stanza
* @param start the start of the stanza
* @return bool true if successfull, false otherwise.
*/
bool Interfaces::removeAllOptions(QStringList::Iterator start){
if(start == interfaces.end())
return false;
QStringList::Iterator it = start;
it = ++it;
for (it; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
break;
}
it = interfaces.remove(it);
it = --it;
}
// Leave a space between this interface and the next.
interfaces.insert(it, QString(""));
return true;
}
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
@@ -20,53 +20,57 @@
* See the interfaces man page for the syntax rules.
*/
class Interfaces {
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);
QString getInterfaceOption(QString option, bool &error);
bool setInterfaceOption(QString option, QString value);
+ bool removeInterfaceOption(QString option, QString value);
bool removeAllInterfaceOptions();
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);
bool setScript(QString);
QString getScript(bool &error);
bool write();
private:
bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
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);
bool removeAllOptions(QStringList::Iterator start);
QString interfacesFile;
QStringList interfaces;
QStringList::Iterator currentIface;
QStringList::Iterator currentMapping;
QStringList acceptedFamily;
};
#endif
// interfaces
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
@@ -71,49 +71,48 @@ bool InterfaceSetupImp::saveSettings(){
}
else{
interfaces->setInterfaceMethod("static");
interfaces->setInterfaceOption("address", ipAddressEdit->text());
interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
interfaces->setInterfaceOption("gateway", gatewayEdit->text());
QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
}
// IP Information
interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
/**
* The Profile has changed.
* @profile the new profile.
*/
void InterfaceSetupImp::setProfile(const QString &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)){
// 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->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 9f07f0d..01063c2 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -11,137 +11,139 @@
#include <qpushbutton.h>
#include <qtabwidget.h>
#include <qlistbox.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qheader.h>
#include <qlabel.h>
#include <qmainwindow.h>
#include <qmessagebox.h>
#include <qpe/config.h>
#include <qpe/qlibrary.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>
#include <qlist.h>
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#define TEMP_ALL "/tmp/ifconfig-a"
#define TEMP_UP "/tmp/ifconfig"
-#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){
connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
// Load connections.
loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
getInterfaceList();
connectionList->header()->hide();
Config cfg("NetworkSetup");
profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
profilesList->insertItem((*it));
currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
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
QTextStream stream( &file ); // use a text stream
while ( !stream.eof() ) { // until end of file...
QString line = stream.readLine(); // line of text excluding '\n'
if(line.contains("SCHEME")){
line = line.mid(7, line.length());
currentProfileLabel->setText(line);
break;
}
}
file.close();
}
}
/**
* Deconstructor. Save profiles. Delete loaded libraries.
*/
MainWindowImp::~MainWindowImp(){
// Save profiles.
Config cfg("NetworkSetup");
cfg.setGroup("General");
cfg.writeEntry("Profiles", profiles.join(" "));
// Delete Modules and Libraries
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
delete it.key();
delete it.data();
}
}
/**
* Load all modules that are found in the path
* @param path a directory that is scaned for any plugins that can be loaded
* and attempts to load them
*/
void MainWindowImp::loadModules(QString path){
- qDebug(path.latin1());
+ //qDebug(path.latin1());
QDir d(path);
if(!d.exists())
return;
// Don't want sym links
d.setFilter( QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if(fi->fileName().contains(".so")){
loadPlugin(path + "/" + fi->fileName());
}
++it;
}
}
/**
* Attempt to load a function and resolve a function.
* @param pluginFileName - the name of the file in which to attempt to load
* @param resolveString - function pointer to resolve
* @return pointer to the function with name resolveString or NULL
*/
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);
void *functionPointer = lib->resolve(resolveString);
if( !functionPointer ){
qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
delete lib;
return NULL;
}
// Try to get an object.
Module *object = ((Module* (*)()) functionPointer)();
if(object == NULL){
qDebug("MainWindowImp: Couldn't create object, but did load library!");
delete lib;
return NULL;
}
// Store for deletion later
libraries.insert(object, lib);
return object;
}
/**
* The Add button was clicked. Bring up the add dialog and if OK is hit
* load the plugin and append it to the list
@@ -469,63 +471,81 @@ void MainWindowImp::addProfile(){
* Doesn't delete if there are less then 2 profiles.
*/
void MainWindowImp::removeProfile(){
if(profilesList->count() <= 1){
QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok");
return;
}
QString profileToRemove = profilesList->currentText();
if(profileToRemove == "All"){
QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok");
return;
}
// Can't remove the curent profile
if(profileToRemove == currentProfileLabel->text()){
QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok");
return;
}
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
+ // 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;
+ }
+ }
+ }
}
/**
* 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);
+ 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();
}
}
}
}
// mainwindowimp.cpp
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
@@ -29,30 +29,31 @@ private slots:
void addProfile();
void removeProfile();
void changeProfile();
void updateInterface(Interface *i);
void newProfileChanged(const QString& newText);
private:
void loadModules(QString path);
Module* loadPlugin(QString pluginFileName,
QString resolveString = "create_plugin");
// For our local list of names
QMap<QString, Interface*> interfaceNames;
QMap<Module*, QLibrary*> libraries;
QMap<Interface*, QListViewItem*> items;
QMap<QListViewItem*, Interface*> interfaceItems;
QMap<KProcess*, QString> threads;
QStringList profiles;
bool advancedUserMode;
+ QString scheme;
};
#endif
// mainwindowimp.h
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
@@ -314,100 +314,131 @@ bool Interfaces::setInterfaceFamily(QString newName){
bool Interfaces::setInterfaceMethod(QString newName){
if(currentIface == interfaces.end())
return false;
bool returnValue = false;
(*currentIface) = QString("iface %1 %2 %3").arg(getInterfaceName(returnValue)).arg(getInterfaceFamily(returnValue)).arg(newName);
return !returnValue;
}
/**
* Get a value for an option in the currently selected interface. For example
* calling getInterfaceOption("address") on the following stanza would
* return 192.168.1.1.
* iface eth0 static
* address 192.168.1.1
* @param option the options to get the value.
* @param error set to true if any error occurs, false otherwise.
* @return QString the options value. QString::null if error == true
*/
QString Interfaces::getInterfaceOption(QString option, bool &error){
return getOption(currentIface, option, 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.
* @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::setInterfaceOption(QString option, QString value){
return setOption(currentIface, option, 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.
* @return bool error if if successfull
*/
bool Interfaces::removeAllInterfaceOptions(){
return removeAllOptions(currentIface);
}
/**
* Set the current map to interface's map. This needs to be done before you
* can call addMapping(), set/getMap(), and get/setScript().
* @param interface the name of the interface to set. All whitespace is
* removed from the interface name.
* @return bool true if it is successfull.
*/
bool Interfaces::setMapping(QString interface){
interface = interface.simplifyWhiteSpace();
interface = interface.replace(QRegExp(" "), "");
return setStanza(MAPPING, interface, currentMapping);
}
/**
* Adds a new Mapping to the interfaces file with interfaces.
* @param interface the name(s) of the interfaces to set to this mapping
*/
void Interfaces::addMapping(QString option){
interfaces.append("");
interfaces.append(QString(MAPPING " %1").arg(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.
* @param map map to use
* @param value value to go with map
* @return bool true if it is successfull.
*/
bool Interfaces::setMap(QString map, QString value){
return setOption(currentMapping, map, 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.
* @param map map to get value of
* @param bool true if it is successfull.
* @return value that goes to the map
*/
QString Interfaces::getMap(QString map, bool &error){
return getOption(currentMapping, map, error);
}
/**
* Sets a script value of the current mapping to argument.
* @param argument the script name.
* @return true if successfull.
*/
bool Interfaces::setScript(QString argument){
return setOption(currentMapping, "script", argument);
}
/**
* @param error true if could not retrieve the current script argument.
* @return QString the argument of the script for the current mapping.
*/
QString Interfaces::getScript(bool &error){
return getOption(currentMapping, "script", error);
@@ -456,61 +487,84 @@ bool Interfaces::setStanza(QString stanza, QString option, QStringList::Iterator
* Sets a value of an 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::setOption(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){
if(!found && value != ""){
// Got to the end of the stanza without finding it, so append it.
interfaces.insert(--it, QString("\t%1 %2").arg(option).arg(value));
}
found = true;
break;
}
if((*it).contains(option) && 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;
- if(value == "")
- (*it) = "";
- else
(*it) = QString("\t%1 %2").arg(option).arg(value);
}
}
if(!found){
QStringList::Iterator p = start;
interfaces.insert(++p, QString("\t%1 %2").arg(option).arg(value));
found = true;
}
return found;
}
+/**
+ * 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;
+}
/**
* Removes all options in a stanza
* @param start the start of the stanza
* @return bool true if successfull, false otherwise.
*/
bool Interfaces::removeAllOptions(QStringList::Iterator start){
if(start == interfaces.end())
return false;
QStringList::Iterator it = start;
it = ++it;
for (it; it != interfaces.end(); ++it ) {
if(((*it).contains(IFACE) || (*it).contains(MAPPING) || (*it).contains(AUTO)) && it != start){
break;
}
it = interfaces.remove(it);
it = --it;
}
// Leave a space between this interface and the next.
interfaces.insert(it, QString(""));
return true;
}
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
@@ -20,53 +20,57 @@
* See the interfaces man page for the syntax rules.
*/
class Interfaces {
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);
QString getInterfaceOption(QString option, bool &error);
bool setInterfaceOption(QString option, QString value);
+ bool removeInterfaceOption(QString option, QString value);
bool removeAllInterfaceOptions();
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);
bool setScript(QString);
QString getScript(bool &error);
bool write();
private:
bool setStanza(QString stanza, QString option,QStringList::Iterator &iterator);
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);
bool removeAllOptions(QStringList::Iterator start);
QString interfacesFile;
QStringList interfaces;
QStringList::Iterator currentIface;
QStringList::Iterator currentMapping;
QStringList acceptedFamily;
};
#endif
// interfaces
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
@@ -71,49 +71,48 @@ bool InterfaceSetupImp::saveSettings(){
}
else{
interfaces->setInterfaceMethod("static");
interfaces->setInterfaceOption("address", ipAddressEdit->text());
interfaces->setInterfaceOption("netmask", subnetMaskEdit->text());
interfaces->setInterfaceOption("gateway", gatewayEdit->text());
QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text();
interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns);
interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns);
}
// IP Information
interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked());
return true;
}
/**
* The Profile has changed.
* @profile the new profile.
*/
void InterfaceSetupImp::setProfile(const QString &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)){
// 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->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 9f07f0d..01063c2 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -11,137 +11,139 @@
#include <qpushbutton.h>
#include <qtabwidget.h>
#include <qlistbox.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qheader.h>
#include <qlabel.h>
#include <qmainwindow.h>
#include <qmessagebox.h>
#include <qpe/config.h>
#include <qpe/qlibrary.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>
#include <qlist.h>
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#define TEMP_ALL "/tmp/ifconfig-a"
#define TEMP_UP "/tmp/ifconfig"
-#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){
connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
// Load connections.
loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
getInterfaceList();
connectionList->header()->hide();
Config cfg("NetworkSetup");
profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
profilesList->insertItem((*it));
currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
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
QTextStream stream( &file ); // use a text stream
while ( !stream.eof() ) { // until end of file...
QString line = stream.readLine(); // line of text excluding '\n'
if(line.contains("SCHEME")){
line = line.mid(7, line.length());
currentProfileLabel->setText(line);
break;
}
}
file.close();
}
}
/**
* Deconstructor. Save profiles. Delete loaded libraries.
*/
MainWindowImp::~MainWindowImp(){
// Save profiles.
Config cfg("NetworkSetup");
cfg.setGroup("General");
cfg.writeEntry("Profiles", profiles.join(" "));
// Delete Modules and Libraries
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
delete it.key();
delete it.data();
}
}
/**
* Load all modules that are found in the path
* @param path a directory that is scaned for any plugins that can be loaded
* and attempts to load them
*/
void MainWindowImp::loadModules(QString path){
- qDebug(path.latin1());
+ //qDebug(path.latin1());
QDir d(path);
if(!d.exists())
return;
// Don't want sym links
d.setFilter( QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if(fi->fileName().contains(".so")){
loadPlugin(path + "/" + fi->fileName());
}
++it;
}
}
/**
* Attempt to load a function and resolve a function.
* @param pluginFileName - the name of the file in which to attempt to load
* @param resolveString - function pointer to resolve
* @return pointer to the function with name resolveString or NULL
*/
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);
void *functionPointer = lib->resolve(resolveString);
if( !functionPointer ){
qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
delete lib;
return NULL;
}
// Try to get an object.
Module *object = ((Module* (*)()) functionPointer)();
if(object == NULL){
qDebug("MainWindowImp: Couldn't create object, but did load library!");
delete lib;
return NULL;
}
// Store for deletion later
libraries.insert(object, lib);
return object;
}
/**
* The Add button was clicked. Bring up the add dialog and if OK is hit
* load the plugin and append it to the list
@@ -469,63 +471,81 @@ void MainWindowImp::addProfile(){
* Doesn't delete if there are less then 2 profiles.
*/
void MainWindowImp::removeProfile(){
if(profilesList->count() <= 1){
QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok");
return;
}
QString profileToRemove = profilesList->currentText();
if(profileToRemove == "All"){
QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok");
return;
}
// Can't remove the curent profile
if(profileToRemove == currentProfileLabel->text()){
QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok");
return;
}
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
+ // 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;
+ }
+ }
+ }
}
/**
* 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);
+ 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();
}
}
}
}
// mainwindowimp.cpp
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
@@ -29,30 +29,31 @@ private slots:
void addProfile();
void removeProfile();
void changeProfile();
void updateInterface(Interface *i);
void newProfileChanged(const QString& newText);
private:
void loadModules(QString path);
Module* loadPlugin(QString pluginFileName,
QString resolveString = "create_plugin");
// For our local list of names
QMap<QString, Interface*> interfaceNames;
QMap<Module*, QLibrary*> libraries;
QMap<Interface*, QListViewItem*> items;
QMap<QListViewItem*, Interface*> interfaceItems;
QMap<KProcess*, QString> threads;
QStringList profiles;
bool advancedUserMode;
+ QString scheme;
};
#endif
// mainwindowimp.h