-rw-r--r-- | noncore/net/networksetup/interfaces/interface.cpp | 4 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 10 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanimp.cpp | 8 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 10 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp.cpp | 8 |
6 files changed, 18 insertions, 26 deletions
diff --git a/noncore/net/networksetup/interfaces/interface.cpp b/noncore/net/networksetup/interfaces/interface.cpp index 7ffa76f..d964961 100644 --- a/noncore/net/networksetup/interfaces/interface.cpp +++ b/noncore/net/networksetup/interfaces/interface.cpp @@ -10,150 +10,150 @@ #include <stdio.h> #include <stdlib.h> Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ refresh(); } /** * Set status * @param newStatus - the new status * emit updateInterface */ void Interface::setStatus(bool newStatus){ if(status != newStatus){ status = newStatus; refresh(); } }; /** * Set if attached or not (802.11 card pulled out for example) * @param isAttached - if attached * emit updateInterface */ void Interface::setAttached(bool isAttached){ attached = isAttached; emit(updateInterface(this)); }; /** * Set Hardware name * @param name - the new name * emit updateInterface */ void Interface::setHardwareName(const QString &name){ hardwareName = name; emit(updateInterface(this)); }; /** * Set Module owner * @param owner - the new owner * emit updateInterface */ void Interface::setModuleOwner(Module *owner){ moduleOwner = owner; emit(updateInterface(this)); }; /** * Try to start the interface. */ void Interface::start(){ // check to see if we are already running. if(true == status){ emit (updateMessage("Unable to start interface,\n already started")); return; } int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); // See if it was successfull... if(ret != 0){ - emit (updateMessage("Starting interface failed.")); + emit (updateMessage("Starting interface failed")); return; } status = true; refresh(); emit (updateMessage("Start successfull")); } /** * Try to stop the interface. */ void Interface::stop(){ // check to see if we are already stopped. if(false == status){ emit (updateMessage("Unable to stop interface,\n already stopped")); return; } int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); if(ret != 0){ - emit (updateMessage("Stopping interface failed.")); + emit (updateMessage("Stopping interface failed")); return; } status = false; refresh(); emit (updateMessage("Stop successfull")); } /** * Try to restart the interface. */ void Interface::restart(){ stop(); start(); } /** * Try to refresh the information about the interface. * First call ifconfig, then check the dhcp-info file * @return bool true if successfull. */ bool Interface::refresh(){ // See if we are up. if(status == false){ macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; dhcp = false; dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; emit(updateInterface(this)); return true; } QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); if(ret != 0){ qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); return false; } QFile file(fileName); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } // Set to the defaults macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("HWaddr")){ int mac = line.find("HWaddr"); macAddress = line.mid(mac+7, line.length()); } if(line.contains("inet addr")){ diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 7b93554..9a17743 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp @@ -259,220 +259,216 @@ void MainWindowImp::addClicked(){ }
AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
addNewConnection.addConnections(list);
addNewConnection.showMaximized();
if(QDialog::Accepted == addNewConnection.exec()){
QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
if(!item)
return;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()){
Interface *i = (it.key())->addNewInterface(item->text(0));
if(i){
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
}
}
}
}
}
/**
* Prompt the user to see if they really want to do this.
* If they do then remove from the list and unload.
*/
void MainWindowImp::removeClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item) {
QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner() == NULL){
QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
}
else{
if(!i->getModuleOwner()->remove(i))
QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok);
else{
QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
// TODO memory managment....
// who deletes the interface?
}
}
}
/**
* Pull up the configure about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure.
*/
void MainWindowImp::configureClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner()){
QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
if(moduleConfigure != NULL){
moduleConfigure->showMaximized();
- moduleConfigure->show();
return;
}
}
InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose);
QString currentProfileText = currentProfileLabel->text();
if(currentProfileText.upper() == "ALL");
currentProfileText = "";
configure->setProfile(currentProfileText);
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.
*/
void MainWindowImp::informationClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(!i->isAttached()){
QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
return;
}
if(i->getModuleOwner()){
QWidget *moduleInformation = i->getModuleOwner()->information(i);
if(moduleInformation != NULL){
moduleInformation->showMaximized();
- moduleInformation->show();
return;
}
}
- InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
- information->showMaximized();
- information->show();
+ InterfaceInformationImp information(0, "InterfaceSetupImp", i);
+ information.showMaximized();
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
*/
void MainWindowImp::updateInterface(Interface *i){
if(!advancedUserMode){
if(i->getInterfaceName() == "lo")
return;
}
QListViewItem *item = NULL;
// Find the interface, making it if needed.
if(items.find(i) == items.end()){
item = new QListViewItem(connectionList, "", "", "");
// See if you can't find a module owner for this interface
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()->isOwner(i))
i->setModuleOwner(it.key());
}
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
// Update the icons and information
item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
if(i->getInterfaceName().contains("irda"))
typeName = "irda";
if(i->getInterfaceName().contains("wlan"))
typeName = "wlan";
if(i->getInterfaceName().contains("usb"))
typeName = "usb";
if(!i->isAttached())
typeName = "connect_no";
// Actually try to use the Module
if(i->getModuleOwner() != NULL)
typeName = i->getModuleOwner()->getPixmapName(i);
- item->setPixmap(1, (Resource::loadPixmap(typeName)));
+ item->setPixmap(1, (Resource::loadPixmap(QString("networksetup/") + typeName)));
item->setText(2, i->getHardwareName());
item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
}
void MainWindowImp::newProfileChanged(const QString& newText){
if(newText.length() > 0)
newProfileButton->setEnabled(true);
else
newProfileButton->setEnabled(false);
}
/**
* Adds a new profile to the list of profiles.
* Don't add profiles that already exists.
* Appends to the list and QStringList
*/
void MainWindowImp::addProfile(){
QString newProfileName = newProfile->text();
if(profiles.grep(newProfileName).count() > 0){
QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
return;
}
profiles.append(newProfileName);
profilesList->insertItem(newProfileName);
}
/**
* Removes the currently selected profile in the combo.
* 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.", QMessageBox::Ok);
return;
}
QString profileToRemove = profilesList->currentText();
if(profileToRemove == "All"){
QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::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), QMessageBox::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.
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)){
diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp index cc18fba..648932f 100644 --- a/noncore/net/networksetup/wlan/wlanimp.cpp +++ b/noncore/net/networksetup/wlan/wlanimp.cpp @@ -38,135 +38,135 @@ WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, W file.close(); settingsFileText = QStringList::split("\n", line, true); parseSettingFile(); } else qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int))); } void WLANImp::typeChanged(int mod){ networkChannel->setEnabled(mod); channelLabel->setEnabled(mod); } /** * Change the profile for both wireless settings and network settings. */ void WLANImp::setProfile(const QString &profile){ interfaceSetup->setProfile(profile); parseSettingFile(); } /** * Parses the settings file that was read in and gets any setting from it. */ void WLANImp::parseSettingFile(){ bool foundCase = false; bool found = false; for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains("case")) foundCase = true; // See if we found our scheme to write or the sceme couldn't be found if((foundCase && line.contains("esac")) || (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) found = true; if(line.contains(";;")) found = false; if(found){ // write out scheme if(line.contains("ESSID=")){ QString id = line.mid(line.find("ESSID=")+6, line.length()); if(id == "any"){ essAny->setChecked(false); }else{ essAny->setChecked(true); essSpecificLineEdit->setText(id); } } if(line.contains("MODE=")){ QString mode = line.mid(line.find("MODE=")+5, line.length()); if(mode == "Managed"){ networkType->setCurrentItem(0); channelLabel->setEnabled(false); networkChannel->setEnabled(false); } else{ networkType->setCurrentItem(1); networkChannel->setEnabled(true); channelLabel->setEnabled(true); } } if(line.contains("#KEY0=")) - keyLineEdit0->setText(line.mid(5, line.length())); + keyLineEdit0->setText(line.mid(6, line.length())); if(line.contains("#KEY1=")) - keyLineEdit1->setText(line.mid(5, line.length())); + keyLineEdit1->setText(line.mid(6, line.length())); if(line.contains("#KEY2=")) - keyLineEdit2->setText(line.mid(5, line.length())); + keyLineEdit2->setText(line.mid(6, line.length())); if(line.contains("#KEY3=")) - keyLineEdit3->setText(line.mid(5, line.length())); + keyLineEdit3->setText(line.mid(6, line.length())); if(line.contains("KEY=")){ wepEnabled->setChecked(true); QString key; if(line.right(5) == (" open")){ key = line.mid(4, line.length()-5); authOpen->setChecked(true); authShared->setChecked(false); } else{ authOpen->setChecked(false); authShared->setChecked(true); key = line.mid(4, line.length()); } if(key == keyLineEdit0->text()) keyRadio0->setChecked(true); if(key == keyLineEdit1->text()) keyRadio1->setChecked(true); if(key == keyLineEdit2->text()) keyRadio2->setChecked(true); if(key == keyLineEdit3->text()) keyRadio3->setChecked(true); } if(line.contains("CHANNEL=")){ networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); } } } } /** * Saves settings to the wireless.opts file using the current profile */ void WLANImp::changeAndSaveSettingFile(){ QString wlanFile = WIRELESS_OPTS; QFile::remove(wlanFile); QFile file(wlanFile); if (!file.open(IO_ReadWrite)){ qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); return; } QTextStream stream( &file ); bool foundCase = false; bool found = false; bool output = true; for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains("case")) foundCase = true; // See if we found our scheme to write or the sceme couldn't be found if((foundCase && line.contains("esac") && !found) || (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ // write out scheme found = true; output = false; if(!line.contains("esac")) stream << line << "\n"; if(!essAny->isChecked() == true){ stream << "\tESSID=any\n"; stream << "\tMODE=Managed\n"; } else{ stream << "\tESSID=" << essSpecificLineEdit->text() << '\n'; stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n'; stream << "\tCHANNEL=" << networkChannel->value() << "\n"; diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index 7ffa76f..d964961 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp @@ -10,150 +10,150 @@ #include <stdio.h> #include <stdlib.h> Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ refresh(); } /** * Set status * @param newStatus - the new status * emit updateInterface */ void Interface::setStatus(bool newStatus){ if(status != newStatus){ status = newStatus; refresh(); } }; /** * Set if attached or not (802.11 card pulled out for example) * @param isAttached - if attached * emit updateInterface */ void Interface::setAttached(bool isAttached){ attached = isAttached; emit(updateInterface(this)); }; /** * Set Hardware name * @param name - the new name * emit updateInterface */ void Interface::setHardwareName(const QString &name){ hardwareName = name; emit(updateInterface(this)); }; /** * Set Module owner * @param owner - the new owner * emit updateInterface */ void Interface::setModuleOwner(Module *owner){ moduleOwner = owner; emit(updateInterface(this)); }; /** * Try to start the interface. */ void Interface::start(){ // check to see if we are already running. if(true == status){ emit (updateMessage("Unable to start interface,\n already started")); return; } int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); // See if it was successfull... if(ret != 0){ - emit (updateMessage("Starting interface failed.")); + emit (updateMessage("Starting interface failed")); return; } status = true; refresh(); emit (updateMessage("Start successfull")); } /** * Try to stop the interface. */ void Interface::stop(){ // check to see if we are already stopped. if(false == status){ emit (updateMessage("Unable to stop interface,\n already stopped")); return; } int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); if(ret != 0){ - emit (updateMessage("Stopping interface failed.")); + emit (updateMessage("Stopping interface failed")); return; } status = false; refresh(); emit (updateMessage("Stop successfull")); } /** * Try to restart the interface. */ void Interface::restart(){ stop(); start(); } /** * Try to refresh the information about the interface. * First call ifconfig, then check the dhcp-info file * @return bool true if successfull. */ bool Interface::refresh(){ // See if we are up. if(status == false){ macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; dhcp = false; dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; emit(updateInterface(this)); return true; } QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); if(ret != 0){ qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); return false; } QFile file(fileName); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); return false; } // Set to the defaults macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("HWaddr")){ int mac = line.find("HWaddr"); macAddress = line.mid(mac+7, line.length()); } if(line.contains("inet addr")){ diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 7b93554..9a17743 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp @@ -259,220 +259,216 @@ void MainWindowImp::addClicked(){ }
AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
addNewConnection.addConnections(list);
addNewConnection.showMaximized();
if(QDialog::Accepted == addNewConnection.exec()){
QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
if(!item)
return;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()){
Interface *i = (it.key())->addNewInterface(item->text(0));
if(i){
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
}
}
}
}
}
/**
* Prompt the user to see if they really want to do this.
* If they do then remove from the list and unload.
*/
void MainWindowImp::removeClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item) {
QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner() == NULL){
QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
}
else{
if(!i->getModuleOwner()->remove(i))
QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok);
else{
QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
// TODO memory managment....
// who deletes the interface?
}
}
}
/**
* Pull up the configure about the currently selected interface.
* Report an error if no interface is selected.
* If the interface has a module owner then request its configure.
*/
void MainWindowImp::configureClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner()){
QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
if(moduleConfigure != NULL){
moduleConfigure->showMaximized();
- moduleConfigure->show();
return;
}
}
InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose);
QString currentProfileText = currentProfileLabel->text();
if(currentProfileText.upper() == "ALL");
currentProfileText = "";
configure->setProfile(currentProfileText);
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.
*/
void MainWindowImp::informationClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
return;
}
Interface *i = interfaceItems[item];
if(!i->isAttached()){
QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
return;
}
if(i->getModuleOwner()){
QWidget *moduleInformation = i->getModuleOwner()->information(i);
if(moduleInformation != NULL){
moduleInformation->showMaximized();
- moduleInformation->show();
return;
}
}
- InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
- information->showMaximized();
- information->show();
+ InterfaceInformationImp information(0, "InterfaceSetupImp", i);
+ information.showMaximized();
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
*/
void MainWindowImp::updateInterface(Interface *i){
if(!advancedUserMode){
if(i->getInterfaceName() == "lo")
return;
}
QListViewItem *item = NULL;
// Find the interface, making it if needed.
if(items.find(i) == items.end()){
item = new QListViewItem(connectionList, "", "", "");
// See if you can't find a module owner for this interface
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()->isOwner(i))
i->setModuleOwner(it.key());
}
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
// Update the icons and information
item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
if(i->getInterfaceName().contains("irda"))
typeName = "irda";
if(i->getInterfaceName().contains("wlan"))
typeName = "wlan";
if(i->getInterfaceName().contains("usb"))
typeName = "usb";
if(!i->isAttached())
typeName = "connect_no";
// Actually try to use the Module
if(i->getModuleOwner() != NULL)
typeName = i->getModuleOwner()->getPixmapName(i);
- item->setPixmap(1, (Resource::loadPixmap(typeName)));
+ item->setPixmap(1, (Resource::loadPixmap(QString("networksetup/") + typeName)));
item->setText(2, i->getHardwareName());
item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
}
void MainWindowImp::newProfileChanged(const QString& newText){
if(newText.length() > 0)
newProfileButton->setEnabled(true);
else
newProfileButton->setEnabled(false);
}
/**
* Adds a new profile to the list of profiles.
* Don't add profiles that already exists.
* Appends to the list and QStringList
*/
void MainWindowImp::addProfile(){
QString newProfileName = newProfile->text();
if(profiles.grep(newProfileName).count() > 0){
QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
return;
}
profiles.append(newProfileName);
profilesList->insertItem(newProfileName);
}
/**
* Removes the currently selected profile in the combo.
* 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.", QMessageBox::Ok);
return;
}
QString profileToRemove = profilesList->currentText();
if(profileToRemove == "All"){
QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::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), QMessageBox::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.
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)){
diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp index cc18fba..648932f 100644 --- a/noncore/settings/networksettings/wlan/wlanimp.cpp +++ b/noncore/settings/networksettings/wlan/wlanimp.cpp @@ -38,135 +38,135 @@ WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, W file.close(); settingsFileText = QStringList::split("\n", line, true); parseSettingFile(); } else qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int))); } void WLANImp::typeChanged(int mod){ networkChannel->setEnabled(mod); channelLabel->setEnabled(mod); } /** * Change the profile for both wireless settings and network settings. */ void WLANImp::setProfile(const QString &profile){ interfaceSetup->setProfile(profile); parseSettingFile(); } /** * Parses the settings file that was read in and gets any setting from it. */ void WLANImp::parseSettingFile(){ bool foundCase = false; bool found = false; for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains("case")) foundCase = true; // See if we found our scheme to write or the sceme couldn't be found if((foundCase && line.contains("esac")) || (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) found = true; if(line.contains(";;")) found = false; if(found){ // write out scheme if(line.contains("ESSID=")){ QString id = line.mid(line.find("ESSID=")+6, line.length()); if(id == "any"){ essAny->setChecked(false); }else{ essAny->setChecked(true); essSpecificLineEdit->setText(id); } } if(line.contains("MODE=")){ QString mode = line.mid(line.find("MODE=")+5, line.length()); if(mode == "Managed"){ networkType->setCurrentItem(0); channelLabel->setEnabled(false); networkChannel->setEnabled(false); } else{ networkType->setCurrentItem(1); networkChannel->setEnabled(true); channelLabel->setEnabled(true); } } if(line.contains("#KEY0=")) - keyLineEdit0->setText(line.mid(5, line.length())); + keyLineEdit0->setText(line.mid(6, line.length())); if(line.contains("#KEY1=")) - keyLineEdit1->setText(line.mid(5, line.length())); + keyLineEdit1->setText(line.mid(6, line.length())); if(line.contains("#KEY2=")) - keyLineEdit2->setText(line.mid(5, line.length())); + keyLineEdit2->setText(line.mid(6, line.length())); if(line.contains("#KEY3=")) - keyLineEdit3->setText(line.mid(5, line.length())); + keyLineEdit3->setText(line.mid(6, line.length())); if(line.contains("KEY=")){ wepEnabled->setChecked(true); QString key; if(line.right(5) == (" open")){ key = line.mid(4, line.length()-5); authOpen->setChecked(true); authShared->setChecked(false); } else{ authOpen->setChecked(false); authShared->setChecked(true); key = line.mid(4, line.length()); } if(key == keyLineEdit0->text()) keyRadio0->setChecked(true); if(key == keyLineEdit1->text()) keyRadio1->setChecked(true); if(key == keyLineEdit2->text()) keyRadio2->setChecked(true); if(key == keyLineEdit3->text()) keyRadio3->setChecked(true); } if(line.contains("CHANNEL=")){ networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); } } } } /** * Saves settings to the wireless.opts file using the current profile */ void WLANImp::changeAndSaveSettingFile(){ QString wlanFile = WIRELESS_OPTS; QFile::remove(wlanFile); QFile file(wlanFile); if (!file.open(IO_ReadWrite)){ qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); return; } QTextStream stream( &file ); bool foundCase = false; bool found = false; bool output = true; for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { QString line = (*it).simplifyWhiteSpace(); if(line.contains("case")) foundCase = true; // See if we found our scheme to write or the sceme couldn't be found if((foundCase && line.contains("esac") && !found) || (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ // write out scheme found = true; output = false; if(!line.contains("esac")) stream << line << "\n"; if(!essAny->isChecked() == true){ stream << "\tESSID=any\n"; stream << "\tMODE=Managed\n"; } else{ stream << "\tESSID=" << essSpecificLineEdit->text() << '\n'; stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n'; stream << "\tCHANNEL=" << networkChannel->value() << "\n"; |