author | benmeyer <benmeyer> | 2002-11-04 16:50:27 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-11-04 16:50:27 (UTC) |
commit | b8d6cf8848e68ab1089d7b94281fa205a13c766f (patch) (side-by-side diff) | |
tree | 0e1ad7879401752385a8ca0c9fb733d28e0748b9 | |
parent | a59b7fd669c53ece7d4eb56eb5b69d8b5f298048 (diff) | |
download | opie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.zip opie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.tar.gz opie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.tar.bz2 |
Removed the Config class. Now parses wireless.opts file directly
-rw-r--r-- | noncore/net/networksetup/wlan/wlan.ui | 199 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanimp.cpp | 415 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanimp.h | 13 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlan.ui | 199 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp.cpp | 415 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp.h | 13 |
6 files changed, 556 insertions, 698 deletions
diff --git a/noncore/net/networksetup/wlan/wlan.ui b/noncore/net/networksetup/wlan/wlan.ui index 9f33559..1b29a3e 100644 --- a/noncore/net/networksetup/wlan/wlan.ui +++ b/noncore/net/networksetup/wlan/wlan.ui @@ -1,46 +1,46 @@ <!DOCTYPE UI><UI> <class>WLAN</class> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>WLAN</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>250</width> + <width>238</width> <height>286</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Wireless LAN Setting</string> </property> <property stdset="1"> <name>sizeGripEnabled</name> <bool>true</bool> </property> <property> <name>layoutMargin</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>tabWidget</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> @@ -150,152 +150,218 @@ <property stdset="1"> <name>text</name> <string>Infrastructure</string> </property> <property stdset="1"> <name>checked</name> <bool>true</bool> </property> </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel2</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>text</name> <string>Channel</string> </property> </widget> <widget row="1" column="0" rowspan="1" colspan="2" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>network802</cstring> </property> <property stdset="1"> <name>text</name> - <string>802.11 Ad-Hoc</string> + <string>Ad-Hoc</string> </property> </widget> <widget row="2" column="1" > <class>QSpinBox</class> <property stdset="1"> <name>name</name> <cstring>networkChannel</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>maxValue</name> <number>11</number> </property> <property stdset="1"> <name>minValue</name> <number>1</number> </property> + <property stdset="1"> + <name>value</name> + <number>6</number> + </property> </widget> <spacer row="2" column="2" > <property> <name>name</name> <cstring>Spacer32</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </grid> </widget> <spacer> <property> <name>name</name> <cstring>Spacer31</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>WepPage</cstring> </property> <attribute> <name>title</name> <string>Wep</string> </attribute> - <grid> + <vbox> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> - <widget row="2" column="0" rowspan="1" colspan="2" > + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>wepEnabled</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Enable Wep</string> + </property> + </widget> + <widget> + <class>QButtonGroup</class> + <property stdset="1"> + <name>name</name> + <cstring>ButtonGroup43</cstring> + </property> + <property stdset="1"> + <name>enabled</name> + <bool>false</bool> + </property> + <property stdset="1"> + <name>title</name> + <string>Authentication Type</string> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>authOpen</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Open System</string> + </property> + <property stdset="1"> + <name>checked</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>authShared</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Shared Key</string> + </property> + </widget> + </hbox> + </widget> + <widget> <class>QButtonGroup</class> <property stdset="1"> <name>name</name> <cstring>ButtonGroup44</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>title</name> <string>Key Setting</string> </property> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="0" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>keyLineEdit0</cstring> </property> </widget> <widget row="1" column="1" > <class>QLineEdit</class> <property stdset="1"> @@ -338,235 +404,114 @@ <name>name</name> <cstring>keyRadio1</cstring> </property> <property stdset="1"> <name>text</name> <string>Key 2</string> </property> </widget> <widget row="2" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>keyRadio2</cstring> </property> <property stdset="1"> <name>text</name> <string>Key 3</string> </property> </widget> <widget row="3" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>keyRadio3</cstring> </property> <property stdset="1"> <name>text</name> <string>Key 4</string> </property> </widget> </grid> </widget> - <widget row="1" column="0" > - <class>QButtonGroup</class> - <property stdset="1"> - <name>name</name> - <cstring>ButtonGroup42</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>title</name> - <string>Key Length</string> - </property> - <vbox> - <property stdset="1"> - <name>margin</name> - <number>11</number> - </property> - <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>key40</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>40 Bits</string> - </property> - <property stdset="1"> - <name>checked</name> - <bool>true</bool> - </property> - </widget> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>key128</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>128 Bits</string> - </property> - </widget> - </vbox> - </widget> - <widget row="1" column="1" > - <class>QButtonGroup</class> - <property stdset="1"> - <name>name</name> - <cstring>ButtonGroup43</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>title</name> - <string>Authentication Type</string> - </property> - <vbox> - <property stdset="1"> - <name>margin</name> - <number>11</number> - </property> - <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>authOpen</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Open System</string> - </property> - <property stdset="1"> - <name>checked</name> - <bool>true</bool> - </property> - </widget> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>authShared</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Shared Key</string> - </property> - </widget> - </vbox> - </widget> - <spacer row="3" column="1" > + <spacer> <property> <name>name</name> <cstring>Spacer30</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> - <widget row="0" column="0" rowspan="1" colspan="2" > - <class>QCheckBox</class> - <property stdset="1"> - <name>name</name> - <cstring>wepEnabled</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Enable Wep</string> - </property> - </widget> - </grid> + </vbox> </widget> </widget> </vbox> </widget> <connections> <connection> <sender>essSpecific</sender> <signal>toggled(bool)</signal> <receiver>essSpecificLineEdit</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>network802</sender> <signal>clicked()</signal> <receiver>essSpecific</receiver> <slot>animateClick()</slot> </connection> <connection> <sender>network802</sender> <signal>toggled(bool)</signal> <receiver>TextLabel2</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>network802</sender> <signal>toggled(bool)</signal> <receiver>networkChannel</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>wepEnabled</sender> <signal>toggled(bool)</signal> - <receiver>ButtonGroup42</receiver> - <slot>setEnabled(bool)</slot> - </connection> - <connection> - <sender>wepEnabled</sender> - <signal>toggled(bool)</signal> <receiver>ButtonGroup43</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>wepEnabled</sender> <signal>toggled(bool)</signal> <receiver>ButtonGroup44</receiver> <slot>setEnabled(bool)</slot> </connection> </connections> <tabstops> <tabstop>tabWidget</tabstop> <tabstop>essNon</tabstop> <tabstop>essSpecificLineEdit</tabstop> <tabstop>networkInfrastructure</tabstop> <tabstop>networkChannel</tabstop> - <tabstop>key40</tabstop> - <tabstop>key128</tabstop> <tabstop>authOpen</tabstop> <tabstop>authShared</tabstop> <tabstop>keyRadio0</tabstop> <tabstop>keyLineEdit0</tabstop> <tabstop>keyRadio1</tabstop> <tabstop>keyLineEdit1</tabstop> <tabstop>keyRadio2</tabstop> <tabstop>keyLineEdit2</tabstop> <tabstop>keyRadio3</tabstop> <tabstop>keyLineEdit3</tabstop> </tabstops> </UI> diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp index 01d7e36..689eae2 100644 --- a/noncore/net/networksetup/wlan/wlanimp.cpp +++ b/noncore/net/networksetup/wlan/wlanimp.cpp @@ -1,247 +1,232 @@ #include "wlanimp.h" +#include "interfacesetupimp.h" -/* Config class */ -#include <qpe/config.h> -/* Global namespace */ -#include <qpe/global.h> -/* system() */ -#include <stdlib.h> #include <qfile.h> #include <qdir.h> #include <qtextstream.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qspinbox.h> #include <qradiobutton.h> #include <qcheckbox.h> -#include <qregexp.h> -#include <qpe/config.h> #include <qtabwidget.h> -#include "interfacesetupimp.h" -WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl){ - config = new Config("wireless"); - interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);//, Qt::WDestructiveClose); - //configure->setProfile(currentProfile); - tabWidget->insertTab(interfaceSetup, "TCP/IP"); +/* system() */ +#include <stdlib.h> - readConfig(); +#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" -} +/** + * Constructor, read in the wireless.opts file for parsing later. + */ +WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { + interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); + tabWidget->insertTab(interfaceSetup, "TCP/IP"); -WLANImp::~WLANImp( ){ - delete config; + // Read in the config file. + QString wlanFile = WIRELESS_OPTS; + QFile file(wlanFile); + if (file.open(IO_ReadOnly)){ + QTextStream stream( &file ); + QString line = ""; + while ( !stream.eof() ) { + line += stream.readLine(); + line += "\n"; + } + file.close(); + settingsFileText = QStringList::split("\n", line, true); + parseSettingFile(); + } + else + qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); } +/** + * Change the profile for both wireless settings and network settings. + */ void WLANImp::setProfile(QString &profile){ interfaceSetup->setProfile(profile); + parseSettingFile(); } -void WLANImp::readConfig() -{ - qWarning( "WLANImp::readConfig() called." ); - config->setGroup( "Properties" ); - QString ssid = config->readEntry( "SSID", "any" ); - if( ssid == "any" || ssid == "ANY" ){ - essNon->setChecked( true ); - } else { - essSpecific->setChecked( true ); - essSpecificLineEdit->setText( ssid ); - } - QString mode = config->readEntry( "Mode", "Managed" ); - if( mode == "adhoc" ) { - network802->setChecked( true ); - } else { - networkInfrastructure->setChecked( true ); - } - networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); -// config->readEntry( "RATE", "auto" ); - config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); - config->readEntry( "AuthType", "opensystem" ); - config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); - int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); - switch( defaultkey ){ - case 0: - keyRadio0->setChecked( true ); - break; - case 1: - keyRadio1->setChecked( true ); - break; - case 2: - keyRadio2->setChecked( true ); - break; - case 3: - keyRadio3->setChecked( true ); - break; +/** + * 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"){ + essNon->setChecked(true); + essSpecific->setChecked(false); + }else{ + essSpecific->setChecked(true); + essSpecificLineEdit->setText(id); + essNon->setChecked(false); + } + } + if(line.contains("MODE=")){ + QString mode = line.mid(line.find("MODE=")+5, line.length()); + if(mode == "Managed"){ + network802->setChecked( false ); + networkInfrastructure->setChecked( true ); + } + else{ + network802->setChecked( true ); + networkInfrastructure->setChecked( false ); + } + } + if(line.contains("KEY=")){ + line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false); + int s = line.find("KEY="); + line = line.mid(s+4, line.length()); + // Find first Key + s = line.find("[1]"); + if(s != -1){ + keyLineEdit0->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + s = line.find("[2]"); + if(s != -1){ + keyLineEdit1->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + s = line.find("[3]"); + if(s != -1){ + keyLineEdit2->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + s = line.find("[4]"); + if(s != -1){ + keyLineEdit3->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + if(line.contains("key [1]")) keyRadio0->setChecked(true); + if(line.contains("key [2]")) keyRadio1->setChecked(true); + if(line.contains("key [3]")) keyRadio2->setChecked(true); + if(line.contains("key [4]")) keyRadio3->setChecked(true); + if(line.contains("open")){ + authOpen->setChecked(true); + authShared->setChecked(false); + } + else{ + authOpen->setChecked(false); + authShared->setChecked(true); + } + } + if(line.contains("CHANNEL=")){ + networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); + } } - keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); - keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" )); - keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" )); - keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" )); - return; + } } -bool WLANImp::writeConfig() -{ - qWarning( "WLANImp::writeConfig() called." ); - config->setGroup( "Properties" ); - if( essNon->isChecked() ) { - config->writeEntry( "SSID", "any" ); - } else { - config->writeEntry( "SSID", essSpecificLineEdit->text() ); - } - if( networkInfrastructure->isChecked() ){ - config->writeEntry( "Mode", "Managed" ); - } else if( network802->isChecked() ){ - config->writeEntry( "Mode", "adhoc" ); - } - config->writeEntry( "CHANNEL", networkChannel->value() ); -// config->readEntry( "RATE", "auto" ); - wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" ); - authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" ); - key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" ); - if( keyRadio0->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 0 ); - } else if( keyRadio1->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 1 ); - } else if( keyRadio2->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 2 ); - } else if( keyRadio3->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 3 ); +/** + * 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"; + + stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; + stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n'; + if(!wepEnabled->isChecked()) + stream << "#"; + stream << "\tKEY="; + stream << keyLineEdit0->text() << " [1]"; + stream << keyLineEdit1->text() << " [2]"; + stream << keyLineEdit2->text() << " [3]"; + stream << keyLineEdit3->text() << " [4]"; + stream << " key ["; + if(keyRadio0->isChecked()) stream << "1]"; + if(keyRadio1->isChecked()) stream << "2]"; + if(keyRadio2->isChecked()) stream << "3]"; + if(keyRadio3->isChecked()) stream << "4]"; + if(authOpen->isChecked()) stream << " open"; + stream << "\n"; + stream << "\tCHANNEL=" << networkChannel->value() << "\n"; + stream << "\tRATE=auto\n"; + if(line.contains("esac")) + stream << line << "\n"; } - config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() ); - config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() ); - config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() ); - config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() ); - return writeWirelessOpts( ); + if(line.contains(";;")) + output = true; + if(output) + stream << (*it) << '\n'; + } + file.close(); } /** + * Check to see if the current config is valid + * Save wireless.opts, save interfaces */ -void WLANImp::accept() -{ - if ( writeConfig() ){ - if(interfaceSetup->saveChanges()) - QDialog::accept(); - } +void WLANImp::accept(){ + if(wepEnabled->isChecked()){ + if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) + QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); + return; + } + + // Ok settings are good here, save + changeAndSaveSettingFile(); + + // Try to save the interfaces settings. + if(!interfaceSetup->saveChanges()) + return; + + // Restart the device now that the settings have changed + QString initpath; + if( QDir("/etc/rc.d/init.d").exists() ) + initpath = "/etc/rc.d/init.d"; + else if( QDir("/etc/init.d").exists() ) + initpath = "/etc/init.d"; + if( initpath ) + system(QString("%1/pcmcia stop").arg(initpath)); + if( initpath ) + system(QString("%1/pcmcia start").arg(initpath)); + + // Close out the dialog + QDialog::accept(); } -bool WLANImp::writeWirelessOpts( QString scheme ) -{ - qWarning( "WLANImp::writeWirelessOpts entered." ); - QString prev = "/etc/pcmcia/wireless.opts"; - QFile prevFile(prev); - if ( !prevFile.open( IO_ReadOnly ) ) - return false; - - QString tmp = "/etc/pcmcia/wireless.opts-qpe-new"; - QFile tmpFile(tmp); - if ( !tmpFile.open( IO_WriteOnly ) ) - return false; - - bool retval = true; - - QTextStream in( &prevFile ); - QTextStream out( &tmpFile ); - - config->setGroup("Properties"); - - QString line; - bool found=false; - bool done=false; - while ( !in.atEnd() ) { - QString line = in.readLine(); - QString wline = line.simplifyWhiteSpace(); - if ( !done ) { - if ( found ) { - // skip existing entry for this scheme, and write our own. - if ( wline == ";;" ) { - found = false; - continue; - } else { - continue; - } - } else { - if ( wline.left(scheme.length()+7) == scheme + ",*,*,*)" ) { - found=true; - continue; // skip this line - } else if ( wline == "esac" || wline == "*,*,*,*)" ) { - // end - add new entry - // Not all fields have a GUI, but all are supported - // in the letwork configuration files. - static const char* txtfields[] = { - 0 - }; - QString readmode = config->readEntry( "Mode", "Managed" ); - QString mode; - if( readmode == "Managed" ){ - mode = readmode; - } else if( readmode == "adhoc" ){ - mode = "Ad-Hoc"; - } - QString key; - if( wepEnabled->isChecked() ){ - int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); - switch( defaultkey ){ - case 0: - key += keyLineEdit0->text(); - break; - case 1: - key += keyLineEdit1->text(); - break; - case 2: - key += keyLineEdit2->text(); - break; - case 3: - key += keyLineEdit3->text(); - break; - } - if( config->readEntry( "AuthType", "opensystem" ) == "opensystem") - key += " open"; - } - out << scheme << ",*,*,*)" << "\n" - << " ESSID=" << Global::shellQuote( config->readEntry( "SSID", "any" ) ) << "\n" - << " MODE=" << mode << "\n" - << " KEY=" << Global::shellQuote( key ) << "\n" - << " RATE=" << "auto" << "\n" - ; - if( mode != "Managed" ) - out << " CHANNEL=" << config->readNumEntry( "CHANNEL", 1 ) << "\n"; - const char** f = txtfields; - while (*f) { - out << " " << *f << "=" << config->readEntry(*f,"") << "\n"; - ++f; - } - out << " ;;\n"; - done = true; - } - } - } - out << line << "\n"; - } +// wlanimp.cpp - prevFile.close(); - tmpFile.close(); - QString initpath; - //system("cardctl suspend"); - if( QDir("/etc/rc.d/init.d").exists() ){ - initpath = "/etc/rc.d/init.d"; - } else if( QDir("/etc/init.d").exists() ){ - initpath = "/etc/init.d"; - } - if( initpath ) - system(QString("%1/pcmcia stop").arg(initpath)); - - if( system( "mv " + tmp + " " + prev ) ) - retval = false; -//#ifdef USE_SCHEMES -// if ( retval ) -// SchemeChanger::changeScheme(scheme); -//#endif - - //system("cardctl resume"); - if( initpath ) - system(QString("%1/pcmcia start").arg(initpath)); - - return retval; -} diff --git a/noncore/net/networksetup/wlan/wlanimp.h b/noncore/net/networksetup/wlan/wlanimp.h index faa1674..f88e550 100644 --- a/noncore/net/networksetup/wlan/wlanimp.h +++ b/noncore/net/networksetup/wlan/wlanimp.h @@ -1,32 +1,31 @@ #ifndef WLANIMP_H #define WLANIMP_H #include "wlan.h" +#include <qstringlist.h> class InterfaceSetupImp; class Interface; class Config; class WLANImp : public WLAN { Q_OBJECT public: WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); - ~WLANImp( ); void setProfile(QString &profile); protected: void accept(); private: - void readConfig(); - bool writeConfig(); - bool writeWirelessOpts( QString scheme = "*" ); - bool writeWlanngOpts( QString scheme = "*" ); - Config* config; + void parseSettingFile(); + void changeAndSaveSettingFile(); + InterfaceSetupImp *interfaceSetup; - + QStringList settingsFileText; + QString currentProfile; }; #endif diff --git a/noncore/settings/networksettings/wlan/wlan.ui b/noncore/settings/networksettings/wlan/wlan.ui index 9f33559..1b29a3e 100644 --- a/noncore/settings/networksettings/wlan/wlan.ui +++ b/noncore/settings/networksettings/wlan/wlan.ui @@ -1,46 +1,46 @@ <!DOCTYPE UI><UI> <class>WLAN</class> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>WLAN</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>250</width> + <width>238</width> <height>286</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Wireless LAN Setting</string> </property> <property stdset="1"> <name>sizeGripEnabled</name> <bool>true</bool> </property> <property> <name>layoutMargin</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>tabWidget</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> @@ -150,152 +150,218 @@ <property stdset="1"> <name>text</name> <string>Infrastructure</string> </property> <property stdset="1"> <name>checked</name> <bool>true</bool> </property> </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel2</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>text</name> <string>Channel</string> </property> </widget> <widget row="1" column="0" rowspan="1" colspan="2" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>network802</cstring> </property> <property stdset="1"> <name>text</name> - <string>802.11 Ad-Hoc</string> + <string>Ad-Hoc</string> </property> </widget> <widget row="2" column="1" > <class>QSpinBox</class> <property stdset="1"> <name>name</name> <cstring>networkChannel</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>maxValue</name> <number>11</number> </property> <property stdset="1"> <name>minValue</name> <number>1</number> </property> + <property stdset="1"> + <name>value</name> + <number>6</number> + </property> </widget> <spacer row="2" column="2" > <property> <name>name</name> <cstring>Spacer32</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </grid> </widget> <spacer> <property> <name>name</name> <cstring>Spacer31</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>WepPage</cstring> </property> <attribute> <name>title</name> <string>Wep</string> </attribute> - <grid> + <vbox> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> - <widget row="2" column="0" rowspan="1" colspan="2" > + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>wepEnabled</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Enable Wep</string> + </property> + </widget> + <widget> + <class>QButtonGroup</class> + <property stdset="1"> + <name>name</name> + <cstring>ButtonGroup43</cstring> + </property> + <property stdset="1"> + <name>enabled</name> + <bool>false</bool> + </property> + <property stdset="1"> + <name>title</name> + <string>Authentication Type</string> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>authOpen</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Open System</string> + </property> + <property stdset="1"> + <name>checked</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>authShared</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Shared Key</string> + </property> + </widget> + </hbox> + </widget> + <widget> <class>QButtonGroup</class> <property stdset="1"> <name>name</name> <cstring>ButtonGroup44</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>title</name> <string>Key Setting</string> </property> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="0" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>keyLineEdit0</cstring> </property> </widget> <widget row="1" column="1" > <class>QLineEdit</class> <property stdset="1"> @@ -338,235 +404,114 @@ <name>name</name> <cstring>keyRadio1</cstring> </property> <property stdset="1"> <name>text</name> <string>Key 2</string> </property> </widget> <widget row="2" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>keyRadio2</cstring> </property> <property stdset="1"> <name>text</name> <string>Key 3</string> </property> </widget> <widget row="3" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>keyRadio3</cstring> </property> <property stdset="1"> <name>text</name> <string>Key 4</string> </property> </widget> </grid> </widget> - <widget row="1" column="0" > - <class>QButtonGroup</class> - <property stdset="1"> - <name>name</name> - <cstring>ButtonGroup42</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>title</name> - <string>Key Length</string> - </property> - <vbox> - <property stdset="1"> - <name>margin</name> - <number>11</number> - </property> - <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>key40</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>40 Bits</string> - </property> - <property stdset="1"> - <name>checked</name> - <bool>true</bool> - </property> - </widget> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>key128</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>128 Bits</string> - </property> - </widget> - </vbox> - </widget> - <widget row="1" column="1" > - <class>QButtonGroup</class> - <property stdset="1"> - <name>name</name> - <cstring>ButtonGroup43</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>title</name> - <string>Authentication Type</string> - </property> - <vbox> - <property stdset="1"> - <name>margin</name> - <number>11</number> - </property> - <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>authOpen</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Open System</string> - </property> - <property stdset="1"> - <name>checked</name> - <bool>true</bool> - </property> - </widget> - <widget> - <class>QRadioButton</class> - <property stdset="1"> - <name>name</name> - <cstring>authShared</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Shared Key</string> - </property> - </widget> - </vbox> - </widget> - <spacer row="3" column="1" > + <spacer> <property> <name>name</name> <cstring>Spacer30</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> - <widget row="0" column="0" rowspan="1" colspan="2" > - <class>QCheckBox</class> - <property stdset="1"> - <name>name</name> - <cstring>wepEnabled</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Enable Wep</string> - </property> - </widget> - </grid> + </vbox> </widget> </widget> </vbox> </widget> <connections> <connection> <sender>essSpecific</sender> <signal>toggled(bool)</signal> <receiver>essSpecificLineEdit</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>network802</sender> <signal>clicked()</signal> <receiver>essSpecific</receiver> <slot>animateClick()</slot> </connection> <connection> <sender>network802</sender> <signal>toggled(bool)</signal> <receiver>TextLabel2</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>network802</sender> <signal>toggled(bool)</signal> <receiver>networkChannel</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>wepEnabled</sender> <signal>toggled(bool)</signal> - <receiver>ButtonGroup42</receiver> - <slot>setEnabled(bool)</slot> - </connection> - <connection> - <sender>wepEnabled</sender> - <signal>toggled(bool)</signal> <receiver>ButtonGroup43</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>wepEnabled</sender> <signal>toggled(bool)</signal> <receiver>ButtonGroup44</receiver> <slot>setEnabled(bool)</slot> </connection> </connections> <tabstops> <tabstop>tabWidget</tabstop> <tabstop>essNon</tabstop> <tabstop>essSpecificLineEdit</tabstop> <tabstop>networkInfrastructure</tabstop> <tabstop>networkChannel</tabstop> - <tabstop>key40</tabstop> - <tabstop>key128</tabstop> <tabstop>authOpen</tabstop> <tabstop>authShared</tabstop> <tabstop>keyRadio0</tabstop> <tabstop>keyLineEdit0</tabstop> <tabstop>keyRadio1</tabstop> <tabstop>keyLineEdit1</tabstop> <tabstop>keyRadio2</tabstop> <tabstop>keyLineEdit2</tabstop> <tabstop>keyRadio3</tabstop> <tabstop>keyLineEdit3</tabstop> </tabstops> </UI> diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp index 01d7e36..689eae2 100644 --- a/noncore/settings/networksettings/wlan/wlanimp.cpp +++ b/noncore/settings/networksettings/wlan/wlanimp.cpp @@ -1,247 +1,232 @@ #include "wlanimp.h" +#include "interfacesetupimp.h" -/* Config class */ -#include <qpe/config.h> -/* Global namespace */ -#include <qpe/global.h> -/* system() */ -#include <stdlib.h> #include <qfile.h> #include <qdir.h> #include <qtextstream.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qspinbox.h> #include <qradiobutton.h> #include <qcheckbox.h> -#include <qregexp.h> -#include <qpe/config.h> #include <qtabwidget.h> -#include "interfacesetupimp.h" -WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl){ - config = new Config("wireless"); - interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);//, Qt::WDestructiveClose); - //configure->setProfile(currentProfile); - tabWidget->insertTab(interfaceSetup, "TCP/IP"); +/* system() */ +#include <stdlib.h> - readConfig(); +#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" -} +/** + * Constructor, read in the wireless.opts file for parsing later. + */ +WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { + interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); + tabWidget->insertTab(interfaceSetup, "TCP/IP"); -WLANImp::~WLANImp( ){ - delete config; + // Read in the config file. + QString wlanFile = WIRELESS_OPTS; + QFile file(wlanFile); + if (file.open(IO_ReadOnly)){ + QTextStream stream( &file ); + QString line = ""; + while ( !stream.eof() ) { + line += stream.readLine(); + line += "\n"; + } + file.close(); + settingsFileText = QStringList::split("\n", line, true); + parseSettingFile(); + } + else + qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); } +/** + * Change the profile for both wireless settings and network settings. + */ void WLANImp::setProfile(QString &profile){ interfaceSetup->setProfile(profile); + parseSettingFile(); } -void WLANImp::readConfig() -{ - qWarning( "WLANImp::readConfig() called." ); - config->setGroup( "Properties" ); - QString ssid = config->readEntry( "SSID", "any" ); - if( ssid == "any" || ssid == "ANY" ){ - essNon->setChecked( true ); - } else { - essSpecific->setChecked( true ); - essSpecificLineEdit->setText( ssid ); - } - QString mode = config->readEntry( "Mode", "Managed" ); - if( mode == "adhoc" ) { - network802->setChecked( true ); - } else { - networkInfrastructure->setChecked( true ); - } - networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); -// config->readEntry( "RATE", "auto" ); - config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); - config->readEntry( "AuthType", "opensystem" ); - config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); - int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); - switch( defaultkey ){ - case 0: - keyRadio0->setChecked( true ); - break; - case 1: - keyRadio1->setChecked( true ); - break; - case 2: - keyRadio2->setChecked( true ); - break; - case 3: - keyRadio3->setChecked( true ); - break; +/** + * 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"){ + essNon->setChecked(true); + essSpecific->setChecked(false); + }else{ + essSpecific->setChecked(true); + essSpecificLineEdit->setText(id); + essNon->setChecked(false); + } + } + if(line.contains("MODE=")){ + QString mode = line.mid(line.find("MODE=")+5, line.length()); + if(mode == "Managed"){ + network802->setChecked( false ); + networkInfrastructure->setChecked( true ); + } + else{ + network802->setChecked( true ); + networkInfrastructure->setChecked( false ); + } + } + if(line.contains("KEY=")){ + line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false); + int s = line.find("KEY="); + line = line.mid(s+4, line.length()); + // Find first Key + s = line.find("[1]"); + if(s != -1){ + keyLineEdit0->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + s = line.find("[2]"); + if(s != -1){ + keyLineEdit1->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + s = line.find("[3]"); + if(s != -1){ + keyLineEdit2->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + s = line.find("[4]"); + if(s != -1){ + keyLineEdit3->setText(line.mid(0, s)); + line = line.mid(s+3, line.length()); + } + if(line.contains("key [1]")) keyRadio0->setChecked(true); + if(line.contains("key [2]")) keyRadio1->setChecked(true); + if(line.contains("key [3]")) keyRadio2->setChecked(true); + if(line.contains("key [4]")) keyRadio3->setChecked(true); + if(line.contains("open")){ + authOpen->setChecked(true); + authShared->setChecked(false); + } + else{ + authOpen->setChecked(false); + authShared->setChecked(true); + } + } + if(line.contains("CHANNEL=")){ + networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); + } } - keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); - keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" )); - keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" )); - keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" )); - return; + } } -bool WLANImp::writeConfig() -{ - qWarning( "WLANImp::writeConfig() called." ); - config->setGroup( "Properties" ); - if( essNon->isChecked() ) { - config->writeEntry( "SSID", "any" ); - } else { - config->writeEntry( "SSID", essSpecificLineEdit->text() ); - } - if( networkInfrastructure->isChecked() ){ - config->writeEntry( "Mode", "Managed" ); - } else if( network802->isChecked() ){ - config->writeEntry( "Mode", "adhoc" ); - } - config->writeEntry( "CHANNEL", networkChannel->value() ); -// config->readEntry( "RATE", "auto" ); - wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" ); - authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" ); - key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" ); - if( keyRadio0->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 0 ); - } else if( keyRadio1->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 1 ); - } else if( keyRadio2->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 2 ); - } else if( keyRadio3->isChecked() ){ - config->writeEntry( "dot11WEPDefaultKeyID", 3 ); +/** + * 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"; + + stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; + stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n'; + if(!wepEnabled->isChecked()) + stream << "#"; + stream << "\tKEY="; + stream << keyLineEdit0->text() << " [1]"; + stream << keyLineEdit1->text() << " [2]"; + stream << keyLineEdit2->text() << " [3]"; + stream << keyLineEdit3->text() << " [4]"; + stream << " key ["; + if(keyRadio0->isChecked()) stream << "1]"; + if(keyRadio1->isChecked()) stream << "2]"; + if(keyRadio2->isChecked()) stream << "3]"; + if(keyRadio3->isChecked()) stream << "4]"; + if(authOpen->isChecked()) stream << " open"; + stream << "\n"; + stream << "\tCHANNEL=" << networkChannel->value() << "\n"; + stream << "\tRATE=auto\n"; + if(line.contains("esac")) + stream << line << "\n"; } - config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() ); - config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() ); - config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() ); - config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() ); - return writeWirelessOpts( ); + if(line.contains(";;")) + output = true; + if(output) + stream << (*it) << '\n'; + } + file.close(); } /** + * Check to see if the current config is valid + * Save wireless.opts, save interfaces */ -void WLANImp::accept() -{ - if ( writeConfig() ){ - if(interfaceSetup->saveChanges()) - QDialog::accept(); - } +void WLANImp::accept(){ + if(wepEnabled->isChecked()){ + if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) + QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); + return; + } + + // Ok settings are good here, save + changeAndSaveSettingFile(); + + // Try to save the interfaces settings. + if(!interfaceSetup->saveChanges()) + return; + + // Restart the device now that the settings have changed + QString initpath; + if( QDir("/etc/rc.d/init.d").exists() ) + initpath = "/etc/rc.d/init.d"; + else if( QDir("/etc/init.d").exists() ) + initpath = "/etc/init.d"; + if( initpath ) + system(QString("%1/pcmcia stop").arg(initpath)); + if( initpath ) + system(QString("%1/pcmcia start").arg(initpath)); + + // Close out the dialog + QDialog::accept(); } -bool WLANImp::writeWirelessOpts( QString scheme ) -{ - qWarning( "WLANImp::writeWirelessOpts entered." ); - QString prev = "/etc/pcmcia/wireless.opts"; - QFile prevFile(prev); - if ( !prevFile.open( IO_ReadOnly ) ) - return false; - - QString tmp = "/etc/pcmcia/wireless.opts-qpe-new"; - QFile tmpFile(tmp); - if ( !tmpFile.open( IO_WriteOnly ) ) - return false; - - bool retval = true; - - QTextStream in( &prevFile ); - QTextStream out( &tmpFile ); - - config->setGroup("Properties"); - - QString line; - bool found=false; - bool done=false; - while ( !in.atEnd() ) { - QString line = in.readLine(); - QString wline = line.simplifyWhiteSpace(); - if ( !done ) { - if ( found ) { - // skip existing entry for this scheme, and write our own. - if ( wline == ";;" ) { - found = false; - continue; - } else { - continue; - } - } else { - if ( wline.left(scheme.length()+7) == scheme + ",*,*,*)" ) { - found=true; - continue; // skip this line - } else if ( wline == "esac" || wline == "*,*,*,*)" ) { - // end - add new entry - // Not all fields have a GUI, but all are supported - // in the letwork configuration files. - static const char* txtfields[] = { - 0 - }; - QString readmode = config->readEntry( "Mode", "Managed" ); - QString mode; - if( readmode == "Managed" ){ - mode = readmode; - } else if( readmode == "adhoc" ){ - mode = "Ad-Hoc"; - } - QString key; - if( wepEnabled->isChecked() ){ - int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); - switch( defaultkey ){ - case 0: - key += keyLineEdit0->text(); - break; - case 1: - key += keyLineEdit1->text(); - break; - case 2: - key += keyLineEdit2->text(); - break; - case 3: - key += keyLineEdit3->text(); - break; - } - if( config->readEntry( "AuthType", "opensystem" ) == "opensystem") - key += " open"; - } - out << scheme << ",*,*,*)" << "\n" - << " ESSID=" << Global::shellQuote( config->readEntry( "SSID", "any" ) ) << "\n" - << " MODE=" << mode << "\n" - << " KEY=" << Global::shellQuote( key ) << "\n" - << " RATE=" << "auto" << "\n" - ; - if( mode != "Managed" ) - out << " CHANNEL=" << config->readNumEntry( "CHANNEL", 1 ) << "\n"; - const char** f = txtfields; - while (*f) { - out << " " << *f << "=" << config->readEntry(*f,"") << "\n"; - ++f; - } - out << " ;;\n"; - done = true; - } - } - } - out << line << "\n"; - } +// wlanimp.cpp - prevFile.close(); - tmpFile.close(); - QString initpath; - //system("cardctl suspend"); - if( QDir("/etc/rc.d/init.d").exists() ){ - initpath = "/etc/rc.d/init.d"; - } else if( QDir("/etc/init.d").exists() ){ - initpath = "/etc/init.d"; - } - if( initpath ) - system(QString("%1/pcmcia stop").arg(initpath)); - - if( system( "mv " + tmp + " " + prev ) ) - retval = false; -//#ifdef USE_SCHEMES -// if ( retval ) -// SchemeChanger::changeScheme(scheme); -//#endif - - //system("cardctl resume"); - if( initpath ) - system(QString("%1/pcmcia start").arg(initpath)); - - return retval; -} diff --git a/noncore/settings/networksettings/wlan/wlanimp.h b/noncore/settings/networksettings/wlan/wlanimp.h index faa1674..f88e550 100644 --- a/noncore/settings/networksettings/wlan/wlanimp.h +++ b/noncore/settings/networksettings/wlan/wlanimp.h @@ -1,32 +1,31 @@ #ifndef WLANIMP_H #define WLANIMP_H #include "wlan.h" +#include <qstringlist.h> class InterfaceSetupImp; class Interface; class Config; class WLANImp : public WLAN { Q_OBJECT public: WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); - ~WLANImp( ); void setProfile(QString &profile); protected: void accept(); private: - void readConfig(); - bool writeConfig(); - bool writeWirelessOpts( QString scheme = "*" ); - bool writeWlanngOpts( QString scheme = "*" ); - Config* config; + void parseSettingFile(); + void changeAndSaveSettingFile(); + InterfaceSetupImp *interfaceSetup; - + QStringList settingsFileText; + QString currentProfile; }; #endif |