summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/wlan/wlanimp.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/wlan/wlanimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp.cpp235
1 files changed, 235 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp
new file mode 100644
index 0000000..60ffeeb
--- a/dev/null
+++ b/noncore/settings/networksettings/wlan/wlanimp.cpp
@@ -0,0 +1,235 @@
1#include "wlanimp.h"
2
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>
10#include <qdir.h>
11#include <qtextstream.h>
12#include <qmessagebox.h>
13#include <qlineedit.h>
14#include <qspinbox.h>
15#include <qradiobutton.h>
16#include <qcheckbox.h>
17#include <qregexp.h>
18
19WLANImp::WLANImp( Config &cfg, QWidget* parent, const char* name):WLAN(parent, name),config(cfg){
20 readConfig();
21}
22
23void WLANImp::readConfig()
24{
25 qWarning( "WLANImp::readConfig() called." );
26 config.setGroup( "Properties" );
27 QString ssid = config.readEntry( "SSID", "any" );
28 if( ssid == "any" || ssid == "ANY" ){
29 essNon->setChecked( TRUE );
30 } else {
31 essSpecific->setChecked( TRUE );
32 essSpecificLineEdit->setText( ssid );
33 }
34 QString mode = config.readEntry( "Mode", "Managed" );
35 if( mode == "adhoc" ) {
36 network802->setChecked( TRUE );
37 } else {
38 networkInfrastructure->setChecked( TRUE );
39 }
40 networkChannel->setValue( config.readNumEntry( "CHANNEL", 1 ) );
41// config.readEntry( "RATE", "auto" );
42 config.readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( TRUE ) : wepEnabled->setChecked( FALSE );
43 config.readEntry( "AuthType", "opensystem" );
44 config.readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( TRUE ) : key128->setChecked( TRUE );
45 int defaultkey = config.readNumEntry( "dot11WEPDefaultKeyID", 0 );
46 switch( defaultkey ){
47 case 0:
48 keyRadio0->setChecked( TRUE );
49 break;
50 case 1:
51 keyRadio1->setChecked( TRUE );
52 break;
53 case 2:
54 keyRadio2->setChecked( TRUE );
55 break;
56 case 3:
57 keyRadio3->setChecked( TRUE );
58 break;
59 }
60 keyLineEdit0->setText(config.readEntry( "dot11WEPDefaultKey0" ));
61 keyLineEdit1->setText(config.readEntry( "dot11WEPDefaultKey1" ));
62 keyLineEdit2->setText(config.readEntry( "dot11WEPDefaultKey2" ));
63 keyLineEdit3->setText(config.readEntry( "dot11WEPDefaultKey3" ));
64 return;
65}
66
67bool WLANImp::writeConfig()
68{
69 qWarning( "WLANImp::writeConfig() called." );
70 config.setGroup( "Properties" );
71 if( essNon->isChecked() ) {
72 config.writeEntry( "SSID", "any" );
73 } else {
74 config.writeEntry( "SSID", essSpecificLineEdit->text() );
75 }
76 if( networkInfrastructure->isChecked() ){
77 config.writeEntry( "Mode", "Managed" );
78 } else if( network802->isChecked() ){
79 config.writeEntry( "Mode", "adhoc" );
80 }
81 config.writeEntry( "CHANNEL", networkChannel->value() );
82// config.readEntry( "RATE", "auto" );
83 wepEnabled->isChecked() ? config.writeEntry( "dot11PrivacyInvoked", "true" ) : config.writeEntry( "dot11PrivacyInvoked", "false" );
84 authOpen->isChecked() ? config.writeEntry( "AuthType", "opensystem" ) : config.writeEntry( "AuthType", "sharedkey" );
85 key40->isChecked() ? config.writeEntry( "PRIV_KEY128", "false" ) : config.writeEntry( "PRIV_KEY128", "true" );
86 if( keyRadio0->isChecked() ){
87 config.writeEntry( "dot11WEPDefaultKeyID", 0 );
88 } else if( keyRadio1->isChecked() ){
89 config.writeEntry( "dot11WEPDefaultKeyID", 1 );
90 } else if( keyRadio2->isChecked() ){
91 config.writeEntry( "dot11WEPDefaultKeyID", 2 );
92 } else if( keyRadio3->isChecked() ){
93 config.writeEntry( "dot11WEPDefaultKeyID", 3 );
94 }
95 config.writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() );
96 config.writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() );
97 config.writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() );
98 config.writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() );
99 return writeWirelessOpts( config );
100// return TRUE;
101}
102
103/**
104 */
105void WLANImp::accept()
106{
107 if ( writeConfig() )
108 QDialog::accept();
109}
110
111void WLANImp::done ( int r )
112{
113 QDialog::done ( r );
114 close ( );
115}
116
117bool WLANImp::writeWirelessOpts( Config &config, QString scheme )
118{
119 qWarning( "WLANImp::writeWirelessOpts entered." );
120 QString prev = "/etc/pcmcia/wireless.opts";
121 QFile prevFile(prev);
122 if ( !prevFile.open( IO_ReadOnly ) )
123 return FALSE;
124
125 QString tmp = "/etc/pcmcia/wireless.opts-qpe-new";
126 QFile tmpFile(tmp);
127 if ( !tmpFile.open( IO_WriteOnly ) )
128 return FALSE;
129
130 bool retval = TRUE;
131
132 QTextStream in( &prevFile );
133 QTextStream out( &tmpFile );
134
135 config.setGroup("Properties");
136
137 QString line;
138 bool found=FALSE;
139 bool done=FALSE;
140 while ( !in.atEnd() ) {
141 QString line = in.readLine();
142 QString wline = line.simplifyWhiteSpace();
143 if ( !done ) {
144 if ( found ) {
145 // skip existing entry for this scheme, and write our own.
146 if ( wline == ";;" ) {
147 found = FALSE;
148 continue;
149 } else {
150 continue;
151 }
152 } else {
153 if ( wline.left(scheme.length()+7) == scheme + ",*,*,*)" ) {
154 found=TRUE;
155 continue; // skip this line
156 } else if ( wline == "esac" || wline == "*,*,*,*)" ) {
157 // end - add new entry
158 // Not all fields have a GUI, but all are supported
159 // in the letwork configuration files.
160 static const char* txtfields[] = {
161 0
162 };
163 QString readmode = config.readEntry( "Mode", "Managed" );
164 QString mode;
165 if( readmode == "Managed" ){
166 mode = readmode;
167 } else if( readmode == "adhoc" ){
168 mode = "Ad-Hoc";
169 }
170 QString key;
171 if( wepEnabled->isChecked() ){
172 int defaultkey = config.readNumEntry( "dot11WEPDefaultKeyID", 0 );
173 switch( defaultkey ){
174 case 0:
175 key += keyLineEdit0->text();
176 break;
177 case 1:
178 key += keyLineEdit1->text();
179 break;
180 case 2:
181 key += keyLineEdit2->text();
182 break;
183 case 3:
184 key += keyLineEdit3->text();
185 break;
186 }
187 if( config.readEntry( "AuthType", "opensystem" ) == "opensystem")
188 key += " open";
189 }
190 out << scheme << ",*,*,*)" << "\n"
191 << " ESSID=" << Global::shellQuote( config.readEntry( "SSID", "any" ) ) << "\n"
192 << " MODE=" << mode << "\n"
193 << " KEY=" << Global::shellQuote( key ) << "\n"
194 << " RATE=" << "auto" << "\n"
195 ;
196 if( mode != "Managed" )
197 out << " CHANNEL=" << config.readNumEntry( "CHANNEL", 1 ) << "\n";
198 const char** f = txtfields;
199 while (*f) {
200 out << " " << *f << "=" << config.readEntry(*f,"") << "\n";
201 ++f;
202 }
203 out << " ;;\n";
204 done = TRUE;
205 }
206 }
207 }
208 out << line << "\n";
209 }
210
211 prevFile.close();
212 tmpFile.close();
213 QString initpath;
214 //system("cardctl suspend");
215 if( QDir("/etc/rc.d/init.d").exists() ){
216 initpath = "/etc/rc.d/init.d";
217 } else if( QDir("/etc/init.d").exists() ){
218 initpath = "/etc/init.d";
219 }
220 if( initpath )
221 system(QString("%1/pcmcia stop").arg(initpath));
222
223 if( system( "mv " + tmp + " " + prev ) )
224 retval = FALSE;
225//#ifdef USE_SCHEMES
226// if ( retval )
227 //SchemeChanger::changeScheme(scheme);
228//#endif
229
230 //system("cardctl resume");
231 if( initpath )
232 system(QString("%1/pcmcia start").arg(initpath));
233
234 return retval;
235}