summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/wlan/wlanimp.cpp
authorbenmeyer <benmeyer>2002-11-04 16:50:27 (UTC)
committer benmeyer <benmeyer>2002-11-04 16:50:27 (UTC)
commitb8d6cf8848e68ab1089d7b94281fa205a13c766f (patch) (unidiff)
tree0e1ad7879401752385a8ca0c9fb733d28e0748b9 /noncore/settings/networksettings/wlan/wlanimp.cpp
parenta59b7fd669c53ece7d4eb56eb5b69d8b5f298048 (diff)
downloadopie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.zip
opie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.tar.gz
opie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.tar.bz2
Removed the Config class. Now parses wireless.opts file directly
Diffstat (limited to 'noncore/settings/networksettings/wlan/wlanimp.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp.cpp385
1 files changed, 185 insertions, 200 deletions
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,11 +1,6 @@
1#include "wlanimp.h" 1#include "wlanimp.h"
2#include "interfacesetupimp.h"
2 3
3/* Config class */
4#include <qpe/config.h>
5/* Global namespace */
6#include <qpe/global.h>
7/* system() */
8#include <stdlib.h>
9#include <qfile.h> 4#include <qfile.h>
10#include <qdir.h> 5#include <qdir.h>
11#include <qtextstream.h> 6#include <qtextstream.h>
@@ -14,234 +9,224 @@
14#include <qspinbox.h> 9#include <qspinbox.h>
15#include <qradiobutton.h> 10#include <qradiobutton.h>
16#include <qcheckbox.h> 11#include <qcheckbox.h>
17#include <qregexp.h>
18#include <qpe/config.h>
19#include <qtabwidget.h> 12#include <qtabwidget.h>
20#include "interfacesetupimp.h"
21 13
22WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl){ 14/* system() */
23 config = new Config("wireless"); 15#include <stdlib.h>
24 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);//, Qt::WDestructiveClose);
25 //configure->setProfile(currentProfile);
26 tabWidget->insertTab(interfaceSetup, "TCP/IP");
27 16
28 readConfig(); 17#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
29 18
30} 19/**
20 * Constructor, read in the wireless.opts file for parsing later.
21 */
22WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") {
23 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);
24 tabWidget->insertTab(interfaceSetup, "TCP/IP");
31 25
32WLANImp::~WLANImp( ){ 26 // Read in the config file.
33 delete config; 27 QString wlanFile = WIRELESS_OPTS;
28 QFile file(wlanFile);
29 if (file.open(IO_ReadOnly)){
30 QTextStream stream( &file );
31 QString line = "";
32 while ( !stream.eof() ) {
33 line += stream.readLine();
34 line += "\n";
35 }
36 file.close();
37 settingsFileText = QStringList::split("\n", line, true);
38 parseSettingFile();
39 }
40 else
41 qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1());
34} 42}
35 43
44/**
45 * Change the profile for both wireless settings and network settings.
46 */
36void WLANImp::setProfile(QString &profile){ 47void WLANImp::setProfile(QString &profile){
37 interfaceSetup->setProfile(profile); 48 interfaceSetup->setProfile(profile);
49 parseSettingFile();
38} 50}
39 51
40void WLANImp::readConfig() 52/**
41{ 53 * Parses the settings file that was read in and gets any setting from it.
42 qWarning( "WLANImp::readConfig() called." ); 54 */
43 config->setGroup( "Properties" ); 55void WLANImp::parseSettingFile(){
44 QString ssid = config->readEntry( "SSID", "any" ); 56 bool foundCase = false;
45 if( ssid == "any" || ssid == "ANY" ){ 57 bool found = false;
58 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
59 QString line = (*it).simplifyWhiteSpace();
60 if(line.contains("case"))
61 foundCase = true;
62 // See if we found our scheme to write or the sceme couldn't be found
63 if((foundCase && line.contains("esac")) ||
64 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
65 found = true;
66
67 if(line.contains(";;"))
68 found = false;
69 if(found){
70 // write out scheme
71 if(line.contains("ESSID=")){
72 QString id = line.mid(line.find("ESSID=")+6, line.length());
73 if(id == "any"){
46 essNon->setChecked( true ); 74 essNon->setChecked( true );
75 essSpecific->setChecked(false);
47 } else { 76 } else {
48 essSpecific->setChecked( true ); 77 essSpecific->setChecked( true );
49 essSpecificLineEdit->setText( ssid ); 78 essSpecificLineEdit->setText(id);
79 essNon->setChecked(false);
50 } 80 }
51 QString mode = config->readEntry( "Mode", "Managed" ); 81 }
52 if( mode == "adhoc" ) { 82 if(line.contains("MODE=")){
53 network802->setChecked( true ); 83 QString mode = line.mid(line.find("MODE=")+5, line.length());
54 } else { 84 if(mode == "Managed"){
85 network802->setChecked( false );
55 networkInfrastructure->setChecked( true ); 86 networkInfrastructure->setChecked( true );
56 } 87 }
57 networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); 88 else{
58// config->readEntry( "RATE", "auto" ); 89 network802->setChecked( true );
59 config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); 90 networkInfrastructure->setChecked( false );
60 config->readEntry( "AuthType", "opensystem" ); 91 }
61 config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); 92 }
62 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); 93 if(line.contains("KEY=")){
63 switch( defaultkey ){ 94 line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false);
64 case 0: 95 int s = line.find("KEY=");
65 keyRadio0->setChecked( true ); 96 line = line.mid(s+4, line.length());
66 break; 97 // Find first Key
67 case 1: 98 s = line.find("[1]");
68 keyRadio1->setChecked( true ); 99 if(s != -1){
69 break; 100 keyLineEdit0->setText(line.mid(0, s));
70 case 2: 101 line = line.mid(s+3, line.length());
71 keyRadio2->setChecked( true ); 102 }
72 break; 103 s = line.find("[2]");
73 case 3: 104 if(s != -1){
74 keyRadio3->setChecked( true ); 105 keyLineEdit1->setText(line.mid(0, s));
75 break; 106 line = line.mid(s+3, line.length());
76 } 107 }
77 keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); 108 s = line.find("[3]");
78 keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" )); 109 if(s != -1){
79 keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" )); 110 keyLineEdit2->setText(line.mid(0, s));
80 keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" )); 111 line = line.mid(s+3, line.length());
81 return; 112 }
113 s = line.find("[4]");
114 if(s != -1){
115 keyLineEdit3->setText(line.mid(0, s));
116 line = line.mid(s+3, line.length());
117 }
118 if(line.contains("key [1]")) keyRadio0->setChecked(true);
119 if(line.contains("key [2]")) keyRadio1->setChecked(true);
120 if(line.contains("key [3]")) keyRadio2->setChecked(true);
121 if(line.contains("key [4]")) keyRadio3->setChecked(true);
122 if(line.contains("open")){
123 authOpen->setChecked(true);
124 authShared->setChecked(false);
125 }
126 else{
127 authOpen->setChecked(false);
128 authShared->setChecked(true);
129 }
130 }
131 if(line.contains("CHANNEL=")){
132 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt());
133 }
134 }
82} 135}
83
84bool WLANImp::writeConfig()
85{
86 qWarning( "WLANImp::writeConfig() called." );
87 config->setGroup( "Properties" );
88 if( essNon->isChecked() ) {
89 config->writeEntry( "SSID", "any" );
90 } else {
91 config->writeEntry( "SSID", essSpecificLineEdit->text() );
92 }
93 if( networkInfrastructure->isChecked() ){
94 config->writeEntry( "Mode", "Managed" );
95 } else if( network802->isChecked() ){
96 config->writeEntry( "Mode", "adhoc" );
97 }
98 config->writeEntry( "CHANNEL", networkChannel->value() );
99// config->readEntry( "RATE", "auto" );
100 wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" );
101 authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" );
102 key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" );
103 if( keyRadio0->isChecked() ){
104 config->writeEntry( "dot11WEPDefaultKeyID", 0 );
105 } else if( keyRadio1->isChecked() ){
106 config->writeEntry( "dot11WEPDefaultKeyID", 1 );
107 } else if( keyRadio2->isChecked() ){
108 config->writeEntry( "dot11WEPDefaultKeyID", 2 );
109 } else if( keyRadio3->isChecked() ){
110 config->writeEntry( "dot11WEPDefaultKeyID", 3 );
111 }
112 config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() );
113 config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() );
114 config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() );
115 config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() );
116 return writeWirelessOpts( );
117} 136}
118 137
119/** 138/**
139 * Saves settings to the wireless.opts file using the current profile
120 */ 140 */
121void WLANImp::accept() 141void WLANImp::changeAndSaveSettingFile(){
122{ 142 QString wlanFile = WIRELESS_OPTS;
123 if ( writeConfig() ){ 143 QFile::remove(wlanFile);
124 if(interfaceSetup->saveChanges()) 144 QFile file(wlanFile);
125 QDialog::accept();
126 }
127}
128 145
129bool WLANImp::writeWirelessOpts( QString scheme ) 146 if (!file.open(IO_ReadWrite)){
130{ 147 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
131 qWarning( "WLANImp::writeWirelessOpts entered." ); 148 return;
132 QString prev = "/etc/pcmcia/wireless.opts"; 149 }
133 QFile prevFile(prev);
134 if ( !prevFile.open( IO_ReadOnly ) )
135 return false;
136 150
137 QString tmp = "/etc/pcmcia/wireless.opts-qpe-new"; 151 QTextStream stream( &file );
138 QFile tmpFile(tmp); 152 bool foundCase = false;
139 if ( !tmpFile.open( IO_WriteOnly ) ) 153 bool found = false;
140 return false; 154 bool output = true;
155 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
156 QString line = (*it).simplifyWhiteSpace();
157 if(line.contains("case"))
158 foundCase = true;
159 // See if we found our scheme to write or the sceme couldn't be found
160 if((foundCase && line.contains("esac") && !found) ||
161 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
162 // write out scheme
163 found = true;
164 output = false;
165
166 if(!line.contains("esac"))
167 stream << line << "\n";
168
169 stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n';
170 stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n';
171 if(!wepEnabled->isChecked())
172 stream << "#";
173 stream << "\tKEY=";
174 stream << keyLineEdit0->text() << " [1]";
175 stream << keyLineEdit1->text() << " [2]";
176 stream << keyLineEdit2->text() << " [3]";
177 stream << keyLineEdit3->text() << " [4]";
178 stream << " key [";
179 if(keyRadio0->isChecked()) stream << "1]";
180 if(keyRadio1->isChecked()) stream << "2]";
181 if(keyRadio2->isChecked()) stream << "3]";
182 if(keyRadio3->isChecked()) stream << "4]";
183 if(authOpen->isChecked()) stream << " open";
184 stream << "\n";
185 stream << "\tCHANNEL=" << networkChannel->value() << "\n";
186 stream << "\tRATE=auto\n";
187 if(line.contains("esac"))
188 stream << line << "\n";
189 }
190 if(line.contains(";;"))
191 output = true;
192 if(output)
193 stream << (*it) << '\n';
194 }
195 file.close();
196}
141 197
142 bool retval = true; 198/**
199 * Check to see if the current config is valid
200 * Save wireless.opts, save interfaces
201 */
202void WLANImp::accept(){
203 if(wepEnabled->isChecked()){
204 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() )
205 QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok);
206 return;
207 }
143 208
144 QTextStream in( &prevFile ); 209 // Ok settings are good here, save
145 QTextStream out( &tmpFile ); 210 changeAndSaveSettingFile();
146 211
147 config->setGroup("Properties"); 212 // Try to save the interfaces settings.
213 if(!interfaceSetup->saveChanges())
214 return;
148 215
149 QString line; 216 // Restart the device now that the settings have changed
150 bool found=false;
151 bool done=false;
152 while ( !in.atEnd() ) {
153 QString line = in.readLine();
154 QString wline = line.simplifyWhiteSpace();
155 if ( !done ) {
156 if ( found ) {
157 // skip existing entry for this scheme, and write our own.
158 if ( wline == ";;" ) {
159 found = false;
160 continue;
161 } else {
162 continue;
163 }
164 } else {
165 if ( wline.left(scheme.length()+7) == scheme + ",*,*,*)" ) {
166 found=true;
167 continue; // skip this line
168 } else if ( wline == "esac" || wline == "*,*,*,*)" ) {
169 // end - add new entry
170 // Not all fields have a GUI, but all are supported
171 // in the letwork configuration files.
172 static const char* txtfields[] = {
173 0
174 };
175 QString readmode = config->readEntry( "Mode", "Managed" );
176 QString mode;
177 if( readmode == "Managed" ){
178 mode = readmode;
179 } else if( readmode == "adhoc" ){
180 mode = "Ad-Hoc";
181 }
182 QString key;
183 if( wepEnabled->isChecked() ){
184 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 );
185 switch( defaultkey ){
186 case 0:
187 key += keyLineEdit0->text();
188 break;
189 case 1:
190 key += keyLineEdit1->text();
191 break;
192 case 2:
193 key += keyLineEdit2->text();
194 break;
195 case 3:
196 key += keyLineEdit3->text();
197 break;
198 }
199 if( config->readEntry( "AuthType", "opensystem" ) == "opensystem")
200 key += " open";
201 }
202 out << scheme << ",*,*,*)" << "\n"
203 << " ESSID=" << Global::shellQuote( config->readEntry( "SSID", "any" ) ) << "\n"
204 << " MODE=" << mode << "\n"
205 << " KEY=" << Global::shellQuote( key ) << "\n"
206 << " RATE=" << "auto" << "\n"
207 ;
208 if( mode != "Managed" )
209 out << " CHANNEL=" << config->readNumEntry( "CHANNEL", 1 ) << "\n";
210 const char** f = txtfields;
211 while (*f) {
212 out << " " << *f << "=" << config->readEntry(*f,"") << "\n";
213 ++f;
214 }
215 out << " ;;\n";
216 done = true;
217 }
218 }
219 }
220 out << line << "\n";
221 }
222
223 prevFile.close();
224 tmpFile.close();
225 QString initpath; 217 QString initpath;
226 //system("cardctl suspend"); 218 if( QDir("/etc/rc.d/init.d").exists() )
227 if( QDir("/etc/rc.d/init.d").exists() ){
228 initpath = "/etc/rc.d/init.d"; 219 initpath = "/etc/rc.d/init.d";
229 } else if( QDir("/etc/init.d").exists() ){ 220 else if( QDir("/etc/init.d").exists() )
230 initpath = "/etc/init.d"; 221 initpath = "/etc/init.d";
231 }
232 if( initpath ) 222 if( initpath )
233 system(QString("%1/pcmcia stop").arg(initpath)); 223 system(QString("%1/pcmcia stop").arg(initpath));
234
235 if( system( "mv " + tmp + " " + prev ) )
236 retval = false;
237//#ifdef USE_SCHEMES
238// if ( retval )
239 //SchemeChanger::changeScheme(scheme);
240//#endif
241
242 //system("cardctl resume");
243 if( initpath ) 224 if( initpath )
244 system(QString("%1/pcmcia start").arg(initpath)); 225 system(QString("%1/pcmcia start").arg(initpath));
245 226
246 return retval; 227 // Close out the dialog
228 QDialog::accept();
247} 229}
230
231// wlanimp.cpp
232