1 /***************************************************************************
2 stuff.cpp - description
5 copyright : (C) 2001 by Stefan Winter
6 email : mail@stefan-winter.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "interface_wireless.h"
22 #include <QStringList>
27 #include <arts/artsflow.h>
28 #include <arts/connect.h>
29 #include <arts/iomanager.h>
30 #include <arts/referenceclean.h>
31 #endif // WITHOUT_ARTS
38 #include <arpa/inet.h>
40 Interface_wireless::Interface_wireless ( QStringList
* ignoreInterfaces
)
42 this->ignoreInterfaces
= ignoreInterfaces
;
43 has_frequency
= false;
52 access_point_address
= "";
53 ip_addresses
.clear ( );
57 for ( int i
= 0; i
< MAX_HISTORY
; i
++ )
66 noiseLevelMin
= 32000;
68 noiseLevelMax
= -32000;
70 already_warned
= false;
74 Interface_wireless::get_device_freq ( long &freq
)
88 Interface_wireless::get_mode ( int &ext_mode
)
102 Interface_wireless::get_key ( QString
& ext_key
, int &ext_size
, int &ext_flags
)
108 ext_flags
= key_flags
;
118 Interface_wireless::get_essid ( )
124 Interface_wireless::get_has_txpower ( )
130 Interface_wireless::get_txpower_disabled ( )
132 return txpower_disabled
;
136 Interface_wireless::get_AP_info ( QString
& mac
, QString
& /*ip */ )
138 mac
= access_point_address
;
143 Interface_wireless::get_IP_info ( )
149 Interface_wireless::get_bitrate ( )
155 Interface_wireless::getMaxBitrate ( )
161 Interface_wireless::get_interface_name ( )
163 return interface_name
;
167 Interface_wireless::get_current_quality ( int &sig
, int &noi
, int &qua
)
169 if ( valid
[current
] )
171 sig
= sigLevel
[current
];
172 noi
= noiseLevel
[current
];
181 Interface_wireless::getDeviceState ( )
183 if ( !has_frequency
|| txpower_disabled
)
187 else if ( mode
== 1 )
191 else if ( qual
[current
] == 0 )
193 return NO_CONNECTION
;
195 else if ( qual
[current
] > 0 )
206 sine_wave ( double frequency
)
208 using namespace Arts
;
209 StdIOManager
*limiter
= new StdIOManager
;
210 Dispatcher
dispatcher ( limiter
);
211 MyTimeNotify
*zeit
= new MyTimeNotify ( &dispatcher
);
212 Synth_FREQUENCY freq
;
215 setValue ( freq
, frequency
);
216 connect ( freq
, sin
);
217 connect ( sin
, play
, "invalue_left" );
221 limiter
->addTimer ( 240, zeit
);
229 MyTimeNotify::notifyTime ( )
237 whois ( const char *MAC_ADR
, QStringList APList
)
239 for ( QStringList::Iterator it
= APList
.begin ( ); it
!= APList
.end ( ); ( it
++ )++ )
241 if ( ( *it
) == ( QString
) MAC_ADR
)
244 return i18n ( "UNKNOWN" );
248 NetworkParameterDataModel::rowCount ( const QModelIndex
& parent
) const
250 return dataContainer
.size ( );
254 NetworkParameterDataModel::columnCount ( const QModelIndex
& parent
) const
260 NetworkParameterDataModel::data ( const QModelIndex
& index
, int role
) const
262 if ( index
.row ( ) >= dataContainer
.size ( ) )
265 if ( role
!= Qt::DisplayRole
&& role
!= Qt::BackgroundColorRole
)
268 if ( role
== Qt::DisplayRole
)
269 switch ( index
.column ( ) )
272 return dataContainer
[index
.row ( )].ssid
;
274 return dataContainer
[index
.row ( )].mode
;
276 return ( QString ( "%1" ) ).arg ( dataContainer
[index
.row ( )].quality
);
278 if ( dataContainer
[index
.row ( )].encryption
== "off" )
279 return QString ( i18n ( "off" ) );
280 if ( dataContainer
[index
.row ( )].encryption
== "on" )
281 return QString ( i18n ( "on" ) );
282 return dataContainer
[index
.row ( )].encryption
;
287 if ( role
== Qt::BackgroundColorRole
)
288 switch ( index
.column ( ) )
291 return ( dataContainer
[index
.row ( )].ssid
== "" ? QColor ( 255, 255, 0 ) : QColor ( 0, 255, 0 ) );
293 return QColor ( 0, 255, 0 );
295 return QColor ( 0, 255, 0 );
297 if ( dataContainer
[index
.row ( )].encryption
== "on" )
298 return QColor ( 255, 255, 0 );
299 if ( checkWEP ( dataContainer
[index
.row ( )].encryption
) == NONE
)
300 return QColor ( 0, 255, 0 );
301 if ( checkWEP ( dataContainer
[index
.row ( )].encryption
) == VALID_HEX
||
302 checkWEP ( dataContainer
[index
.row ( )].encryption
) == VALID_STRING
)
303 return QColor ( 0, 255, 0 );
304 if ( checkWEP ( dataContainer
[index
.row ( )].encryption
) == INVALID
)
305 return QColor ( 255, 0, 0 );
311 // we will never get here, but let's make the compiler happy
316 NetworkParameterDataModel::checkWEP ( const QString
& key
) const
319 kDebug ( ) << "In checkWEP()\n";
323 if ( key
.length ( ) == 5 )
325 if ( key
.length ( ) == 13 )
327 if ( key
.length ( ) == 32 )
330 // a more restrictive check: is it really a hex number?
332 QRegExp
hexNumber ( "[A-F,a-f,0-9]*" );
334 if ( key
.length ( ) == 10 && hexNumber
.exactMatch ( key
) )
336 if ( key
.length ( ) == 26 && hexNumber
.exactMatch ( key
) )
338 if ( key
.length ( ) == 64 && hexNumber
.exactMatch ( key
) )
346 NetworkParameterDataModel::data ( int row
, int col
)
348 return data ( createIndex ( row
, col
, 0 ), Qt::DisplayRole
);
352 NetworkParameterDataModel::headerData ( int section
, Qt::Orientation orientation
, int role
= Qt::DisplayRole
) const
354 if ( orientation
== Qt::Vertical
)
359 return i18n ( "SSID" );
362 return i18n ( "Mode" );
365 return i18n ( "Quality" );
368 return i18n ( "Encryption" );
380 NetworkParameterDataModel::headerData ( int col
)
382 return headerData ( col
, Qt::Horizontal
);
386 NetworkParameterDataModel::setData ( const QModelIndex
& index
, const QVariant
& value
, int role
= Qt::EditRole
)
388 if ( role
!= Qt::EditRole
)
390 if ( dataContainer
.size ( ) == 0 )
391 insertColumns ( 0, 4 );
392 for ( int i
= dataContainer
.size ( ); i
<= index
.row ( ); i
++ )
394 kDebug ( ) << "intialising intermediate row " << i
<< ".\n";
395 struct NetworkParameterData
*newRow
= new NetworkParameterData
;
399 newRow
->encryption
= "off";
400 dataContainer
.append ( *newRow
);
403 kDebug ( ) << "Setting value at row " << index
.row ( ) << ", col " << index
.column ( ) << " to " << value
.
404 toString ( ) << ".\n";
406 switch ( index
.column ( ) )
409 dataContainer
[index
.row ( )].ssid
= value
.toString ( );
412 dataContainer
[index
.row ( )].mode
= value
.toString ( );
415 dataContainer
[index
.row ( )].quality
= value
.toString ( ).toInt ( );
418 dataContainer
[index
.row ( )].encryption
= value
.toString ( );
423 // emit dataChanged(index,index);
428 NetworkParameterDataModel::gotFinishedIndicator ( )
430 emit
finishedScanning ( );
434 NetworkParameterDataModel::setData ( int row
, int col
, const QVariant
& value
)
436 return setData ( createIndex ( row
, col
), value
);
439 Qt::ItemFlags
NetworkParameterDataModel::flags ( const QModelIndex
& index
) const
441 if ( index
.row ( ) >= dataContainer
.size ( ) )
443 if ( index
.column ( ) > 3 )
445 if ( index
.column ( ) != 0 && index
.column ( ) != 3 )
446 return Qt::ItemIsSelectable
;
447 if ( index
.column ( ) == 0 && !dataContainer
[index
.row ( )].ssid
.isEmpty() )
448 return Qt::ItemIsSelectable
;
449 if ( index
.column ( ) == 3 && dataContainer
[index
.row ( )].encryption
== "off" )
450 return Qt::ItemIsSelectable
;
451 return Qt::ItemIsSelectable
| Qt::ItemIsEnabled
| Qt::ItemIsEditable
;
454 #include "interface_wireless.moc"