summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/configwindow.cpp
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/gui/configwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/configwindow.cpp98
1 files changed, 68 insertions, 30 deletions
diff --git a/noncore/net/wellenreiter/gui/configwindow.cpp b/noncore/net/wellenreiter/gui/configwindow.cpp
index 84d4c63..3ec190b 100644
--- a/noncore/net/wellenreiter/gui/configwindow.cpp
+++ b/noncore/net/wellenreiter/gui/configwindow.cpp
@@ -36,97 +36,108 @@
36#include <opie2/oconfig.h> 36#include <opie2/oconfig.h>
37 37
38WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0; 38WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0;
39 39
40WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f ) 40WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f )
41 :WellenreiterConfigBase( parent, name, true, f ) 41 :WellenreiterConfigBase( parent, name, true, f )
42{ 42{
43 _devicetype[ "cisco" ] = DEVTYPE_CISCO; 43 _devicetype[ "cisco" ] = DEVTYPE_CISCO;
44 _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG; 44 _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG;
45 _devicetype[ "hostap" ] = DEVTYPE_HOSTAP; 45 _devicetype[ "hostap" ] = DEVTYPE_HOSTAP;
46 _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO; 46 _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO;
47 _devicetype[ "<manual>" ] = DEVTYPE_MANUAL; 47 _devicetype[ "<manual>" ] = DEVTYPE_MANUAL;
48 _devicetype[ "<file>" ] = DEVTYPE_FILE; 48 _devicetype[ "<file>" ] = DEVTYPE_FILE;
49 49
50 // gather possible interface names from ONetwork 50 // gather possible interface names from ONetwork
51 ONetwork* net = ONetwork::instance(); 51 ONetwork* net = ONetwork::instance();
52 ONetwork::InterfaceIterator it = net->iterator(); 52 ONetwork::InterfaceIterator it = net->iterator();
53 while ( it.current() ) 53 while ( it.current() )
54 { 54 {
55 if ( it.current()->isWireless() ) 55 if ( it.current()->isWireless() )
56 interfaceName->insertItem( it.current()->name() ); 56 interfaceName->insertItem( it.current()->name() );
57 ++it; 57 ++it;
58 } 58 }
59 59
60 if ( !load() ) // no configuration present 60 load();
61 {
62 // try to guess device type
63 QFile m( "/proc/modules" );
64 if ( m.open( IO_ReadOnly ) )
65 {
66 int devicetype(0);
67 QString line;
68 QTextStream modules( &m );
69 while( !modules.atEnd() && !devicetype )
70 {
71 modules >> line;
72 if ( line.contains( "cisco" ) ) devicetype = DEVTYPE_CISCO;
73 else if ( line.contains( "hostap" ) ) devicetype = DEVTYPE_HOSTAP;
74 else if ( line.contains( "prism" ) ) devicetype = DEVTYPE_WLAN_NG;
75 else if ( line.contains( "orinoco" ) ) devicetype = DEVTYPE_ORINOCO;
76 }
77 if ( devicetype )
78 {
79 deviceType->setCurrentItem( devicetype );
80 _guess = devicetype;
81 qDebug( "Wellenreiter: guessed device type to be #%d", devicetype );
82 }
83 }
84 }
85 61
86 #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here 62 #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here
87 QPushButton* okButton = new QPushButton( "ok", this ); 63 QPushButton* okButton = new QPushButton( "ok", this );
88 okButton->show(); 64 okButton->show();
89 WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui 65 WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui
90 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); 66 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
91 #endif 67 #endif
92 68
93 WellenreiterConfigWindow::_instance = this; 69 WellenreiterConfigWindow::_instance = this;
94 70
95 connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) ); 71 connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) );
96 connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) ); 72 connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) );
97 73
98 // make the checkbox 'channelAll' control all other channels 74 // make the checkbox 'channelAll' control all other channels
99 connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) ); 75 connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) );
76
77 connect( autodetect, SIGNAL( clicked() ), this, SLOT( performAutodetection() ) );
100}; 78};
101 79
102 80
103WellenreiterConfigWindow::~WellenreiterConfigWindow() 81WellenreiterConfigWindow::~WellenreiterConfigWindow()
104{ 82{
105 save(); 83 save();
106} 84}
107 85
108 86
87void WellenreiterConfigWindow::performAutodetection()
88{
89 //TODO: insert modal splash screen here
90 // and sleep a second, so that it looks
91 // like we're actually doing something fancy... ;-)
92
93 qDebug( "WellenreiterConfigWindow::performAutodetection()" );
94
95 // try to guess device type
96 QFile m( "/proc/modules" );
97 if ( m.open( IO_ReadOnly ) )
98 {
99 int devicetype(0);
100 QString line;
101 QTextStream modules( &m );
102 while( !modules.atEnd() && !devicetype )
103 {
104 modules >> line;
105 if ( line.contains( "cisco" ) ) devicetype = DEVTYPE_CISCO;
106 else if ( line.contains( "hostap" ) ) devicetype = DEVTYPE_HOSTAP;
107 else if ( line.contains( "prism" ) ) devicetype = DEVTYPE_WLAN_NG;
108 else if ( line.contains( "orinoco" ) ) devicetype = DEVTYPE_ORINOCO;
109 }
110 if ( devicetype )
111 {
112 deviceType->setCurrentItem( devicetype );
113 _guess = devicetype;
114 qDebug( "Wellenreiter: guessed device type to be #%d", devicetype );
115 }
116 }
117}
118
119
109int WellenreiterConfigWindow::driverType() const 120int WellenreiterConfigWindow::driverType() const
110{ 121{
111 QString name = deviceType->currentText(); 122 QString name = deviceType->currentText();
112 if ( _devicetype.contains( name ) ) 123 if ( _devicetype.contains( name ) )
113 { 124 {
114 return _devicetype[name]; 125 return _devicetype[name];
115 } 126 }
116 else 127 else
117 { 128 {
118 return 0; 129 return 0;
119 } 130 }
120}; 131};
121 132
122 133
123int WellenreiterConfigWindow::hoppingInterval() const 134int WellenreiterConfigWindow::hoppingInterval() const
124{ 135{
125 return hopInterval->cleanText().toInt(); 136 return hopInterval->cleanText().toInt();
126} 137}
127 138
128 139
129bool WellenreiterConfigWindow::usePrismHeader() const 140bool WellenreiterConfigWindow::usePrismHeader() const
130{ 141{
131 return prismHeader->isChecked(); 142 return prismHeader->isChecked();
132} 143}
@@ -200,89 +211,116 @@ void WellenreiterConfigWindow::channelAllClicked(int state)
200 channel13->setChecked( b ); 211 channel13->setChecked( b );
201 channel14->setChecked( b ); 212 channel14->setChecked( b );
202} 213}
203 214
204 215
205bool WellenreiterConfigWindow::useGPS() const 216bool WellenreiterConfigWindow::useGPS() const
206{ 217{
207 return enableGPS->isChecked(); 218 return enableGPS->isChecked();
208} 219}
209 220
210 221
211const QString WellenreiterConfigWindow::gpsHost() const 222const QString WellenreiterConfigWindow::gpsHost() const
212{ 223{
213 return useGPS() ? gpsdHost->currentText() : QString::null; 224 return useGPS() ? gpsdHost->currentText() : QString::null;
214} 225}
215 226
216 227
217int WellenreiterConfigWindow::gpsPort() const 228int WellenreiterConfigWindow::gpsPort() const
218{ 229{
219 bool ok; 230 bool ok;
220 return useGPS() ? gpsdPort->value() : -1; 231 return useGPS() ? gpsdPort->value() : -1;
221} 232}
222 233
223 234
224bool WellenreiterConfigWindow::load() 235void WellenreiterConfigWindow::load()
225{ 236{
226#ifdef Q_WS_X11 237#ifdef Q_WS_X11
227 #warning Persistent Configuration not yet implemented for standalone X11 build 238 #warning Persistent Configuration not yet implemented for standalone X11 build
228 return false; 239 performAutodetection();
229#else 240#else
230 qDebug( "loading configuration settings..." ); 241 qDebug( "loading configuration settings..." );
231 242
232 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ 243 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */
233 244
234 OConfig* c = oApp->config(); 245 OConfig* c = oApp->config();
235 246
236 c->setGroup( "Interface" ); 247 c->setGroup( "Interface" );
237 //interfaceName->setCurrentText( c->readEntry( "name" ) ); 248
238 //deviceType->setCurrentText( c->readEntry( "type", "<select>" ) ); 249 QString interface = c->readEntry( "name", "<none>" );
250 if ( interface != "<none>" )
251 {
252#if QT_VERSION < 300
253 interfaceName->insertItem( interface, 0 );
254 interfaceName->setCurrentItem( 0 );
255#else
256 interfaceName->setCurrentText( interface );
257#endif
258
259 QString device = c->readEntry( "type", "<select>" );
260#if QT_VERSION < 300
261 for ( int i = 0; i < deviceType->count(); ++i )
262 {
263 if ( deviceType->text( i ) == device )
264 {
265 deviceType->setCurrentItem( i );
266 break;
267 }
268 }
269#else
270 deviceType->setCurrentText( device );
271#endif
272 }
273 else
274 {
275 performAutodetection();
276 }
277
239 prismHeader->setChecked( c->readBoolEntry( "prism", false ) ); 278 prismHeader->setChecked( c->readBoolEntry( "prism", false ) );
240 hopChannels->setChecked( c->readBoolEntry( "hop", true ) ); 279 hopChannels->setChecked( c->readBoolEntry( "hop", true ) );
241 hopInterval->setValue( c->readNumEntry( "interval", 100 ) ); 280 hopInterval->setValue( c->readNumEntry( "interval", 100 ) );
242 adaptiveHopping->setChecked( c->readBoolEntry( "adaptive", true ) ); 281 adaptiveHopping->setChecked( c->readBoolEntry( "adaptive", true ) );
243 282
244 c->setGroup( "Capture" ); 283 c->setGroup( "Capture" );
245 captureFileName->setText( c->readEntry( "filename", "/tmp/capture" ) ); 284 captureFileName->setText( c->readEntry( "filename", "/tmp/capture" ) );
246 285
247 c->setGroup( "UI" ); 286 c->setGroup( "UI" );
248 lookupVendor->setChecked( c->readBoolEntry( "lookupVendor", true ) ); 287 lookupVendor->setChecked( c->readBoolEntry( "lookupVendor", true ) );
249 openTree->setChecked( c->readBoolEntry( "openTree", true ) ); 288 openTree->setChecked( c->readBoolEntry( "openTree", true ) );
250 disablePM->setChecked( c->readBoolEntry( "disablePM", true ) ); 289 disablePM->setChecked( c->readBoolEntry( "disablePM", true ) );
251 290
252 c->setGroup( "GPS" ); 291 c->setGroup( "GPS" );
253 enableGPS->setChecked( c->readBoolEntry( "use", false ) ); 292 enableGPS->setChecked( c->readBoolEntry( "use", false ) );
254#if QT_VERSION < 300 293#if QT_VERSION < 300
255 gpsdHost->insertItem( c->readEntry( "host", "localhost" ), 0 ); 294 gpsdHost->insertItem( c->readEntry( "host", "localhost" ), 0 );
256 gpsdHost->setCurrentItem( 0 ); 295 gpsdHost->setCurrentItem( 0 );
257#else 296#else
258 gpsdHost->setCurrentText( c->readEntry( "host", "localhost" ) ); 297 gpsdHost->setCurrentText( c->readEntry( "host", "localhost" ) );
259#endif 298#endif
260 gpsdPort->setValue( c->readNumEntry( "port", 2947 ) ); 299 gpsdPort->setValue( c->readNumEntry( "port", 2947 ) );
261 startGPS->setChecked( c->readBoolEntry( "start", false ) ); 300 startGPS->setChecked( c->readBoolEntry( "start", false ) );
262 commandGPS->setText( c->readEntry( "command", "gpsd -p /dev/ttyS3 -s 57600" ) ); 301 commandGPS->setText( c->readEntry( "command", "gpsd -p /dev/ttyS3 -s 57600" ) );
263 302
264 return false; // false = perform autodetection; true = use config settings
265#endif 303#endif
266} 304}
267 305
268 306
269void WellenreiterConfigWindow::save() 307void WellenreiterConfigWindow::save()
270{ 308{
271#ifdef Q_WS_X11 309#ifdef Q_WS_X11
272 #warning Persistent Configuration not yet implemented for standalone X11 build 310 #warning Persistent Configuration not yet implemented for standalone X11 build
273#else 311#else
274 qDebug( "saving configuration settings..." ); 312 qDebug( "saving configuration settings..." );
275 313
276 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ 314 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */
277 315
278 OConfig* c = oApp->config(); 316 OConfig* c = oApp->config();
279 317
280 c->setGroup( "Interface" ); 318 c->setGroup( "Interface" );
281 c->writeEntry( "name", interfaceName->currentText() ); 319 c->writeEntry( "name", interfaceName->currentText() );
282 c->writeEntry( "type", deviceType->currentText() ); 320 c->writeEntry( "type", deviceType->currentText() );
283 c->writeEntry( "prism", prismHeader->isChecked() ); 321 c->writeEntry( "prism", prismHeader->isChecked() );
284 c->writeEntry( "hop", hopChannels->isChecked() ); 322 c->writeEntry( "hop", hopChannels->isChecked() );
285 c->writeEntry( "interval", hopInterval->value() ); 323 c->writeEntry( "interval", hopInterval->value() );
286 c->writeEntry( "adaptive", adaptiveHopping->isChecked() ); 324 c->writeEntry( "adaptive", adaptiveHopping->isChecked() );
287 325
288 c->setGroup( "Capture" ); 326 c->setGroup( "Capture" );