summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/scanlist.cpp
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/gui/scanlist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.cpp59
1 files changed, 29 insertions, 30 deletions
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp
index d5665b4..809d0bd 100644
--- a/noncore/net/wellenreiter/gui/scanlist.cpp
+++ b/noncore/net/wellenreiter/gui/scanlist.cpp
@@ -9,25 +9,24 @@
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "scanlist.h" 16#include "scanlist.h"
17#include "configwindow.h" 17#include "configwindow.h"
18#include "logwindow.h" 18#include "logwindow.h"
19 19
20#include <assert.h> 20#include <assert.h>
21#include "manufacturers.h"
22#include <qdatetime.h> 21#include <qdatetime.h>
23#include <qtextstream.h> 22#include <qtextstream.h>
24 23
25#ifdef QWS 24#ifdef QWS
26#include <opie/odevice.h> 25#include <opie/odevice.h>
27using namespace Opie; 26using namespace Opie;
28#endif 27#endif
29 28
30 29
31#ifdef QWS 30#ifdef QWS
32#include <qpe/resource.h> 31#include <qpe/resource.h>
33#else 32#else
@@ -38,25 +37,25 @@ const int col_type = 0;
38const int col_essid = 0; 37const int col_essid = 0;
39const int col_sig = 1; 38const int col_sig = 1;
40const int col_ap = 2; 39const int col_ap = 2;
41const int col_channel = 3; 40const int col_channel = 3;
42const int col_wep = 4; 41const int col_wep = 4;
43const int col_traffic = 5; 42const int col_traffic = 5;
44const int col_ip = 6; 43const int col_ip = 6;
45const int col_manuf = 7; 44const int col_manuf = 7;
46const int col_firstseen = 8; 45const int col_firstseen = 8;
47const int col_lastseen = 9; 46const int col_lastseen = 9;
48 47
49MScanListView::MScanListView( QWidget* parent, const char* name ) 48MScanListView::MScanListView( QWidget* parent, const char* name )
50 :OListView( parent, name ), _manufacturerdb( 0 ) 49 :OListView( parent, name )
51{ 50{
52 51
53 setFrameShape( QListView::StyledPanel ); 52 setFrameShape( QListView::StyledPanel );
54 setFrameShadow( QListView::Sunken ); 53 setFrameShadow( QListView::Sunken );
55 54
56 addColumn( tr( "Net/Station" ) ); 55 addColumn( tr( "Net/Station" ) );
57 setColumnAlignment( col_essid, AlignLeft || AlignVCenter ); 56 setColumnAlignment( col_essid, AlignLeft || AlignVCenter );
58 addColumn( tr( "#" ) ); 57 addColumn( tr( "#" ) );
59 setColumnAlignment( col_sig, AlignCenter ); 58 setColumnAlignment( col_sig, AlignCenter );
60 addColumn( tr( "MAC" ) ); 59 addColumn( tr( "MAC" ) );
61 setColumnAlignment( col_ap, AlignCenter ); 60 setColumnAlignment( col_ap, AlignCenter );
62 addColumn( tr( "Chn" ) ); 61 addColumn( tr( "Chn" ) );
@@ -68,53 +67,53 @@ MScanListView::MScanListView( QWidget* parent, const char* name )
68 addColumn( tr( "IP" ) ); 67 addColumn( tr( "IP" ) );
69 setColumnAlignment( col_ip, AlignCenter ); 68 setColumnAlignment( col_ip, AlignCenter );
70 addColumn( tr( "Manufacturer" ) ); 69 addColumn( tr( "Manufacturer" ) );
71 setColumnAlignment( col_manuf, AlignCenter ); 70 setColumnAlignment( col_manuf, AlignCenter );
72 addColumn( tr( "First Seen" ) ); 71 addColumn( tr( "First Seen" ) );
73 setColumnAlignment( col_firstseen, AlignCenter ); 72 setColumnAlignment( col_firstseen, AlignCenter );
74 addColumn( tr( "Last Seen" ) ); 73 addColumn( tr( "Last Seen" ) );
75 setColumnAlignment( col_lastseen, AlignCenter ); 74 setColumnAlignment( col_lastseen, AlignCenter );
76 setRootIsDecorated( true ); 75 setRootIsDecorated( true );
77 setAllColumnsShowFocus( true ); 76 setAllColumnsShowFocus( true );
78}; 77};
79 78
79
80MScanListView::~MScanListView() 80MScanListView::~MScanListView()
81{ 81{
82}; 82};
83 83
84
84OListViewItem* MScanListView::childFactory() 85OListViewItem* MScanListView::childFactory()
85{ 86{
86 return new MScanListItem( this ); 87 return new MScanListItem( this );
87} 88}
88 89
90
89void MScanListView::serializeTo( QDataStream& s) const 91void MScanListView::serializeTo( QDataStream& s) const
90{ 92{
91 qDebug( "serializing MScanListView" ); 93 qDebug( "serializing MScanListView" );
92 OListView::serializeTo( s ); 94 OListView::serializeTo( s );
93} 95}
94 96
97
95void MScanListView::serializeFrom( QDataStream& s) 98void MScanListView::serializeFrom( QDataStream& s)
96{ 99{
97 qDebug( "serializing MScanListView" ); 100 qDebug( "serializing MScanListView" );
98 OListView::serializeFrom( s ); 101 OListView::serializeFrom( s );
99} 102}
100 103
101void MScanListView::setManufacturerDB( ManufacturerDB* manufacturerdb )
102{
103 _manufacturerdb = manufacturerdb;
104}
105 104
106void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 105void MScanListView::addNewItem( const QString& type, const QString& essid, const OMacAddress& mac, bool wep, int channel, int signal )
107{ 106{
108 // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...) 107 QString macaddr = mac.toString(true);
109 108
110 #ifdef DEBUG 109 #ifdef DEBUG
111 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type, 110 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type,
112 (const char*) essid, (const char*) macaddr, channel ); 111 (const char*) essid, (const char*) macaddr, channel );
113 #endif 112 #endif
114 113
115 // search, if we already have seen this net 114 // search, if we already have seen this net
116 115
117 QString s; 116 QString s;
118 MScanListItem* network; 117 MScanListItem* network;
119 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() ); 118 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() );
120 119
@@ -159,173 +158,171 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo
159 network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0 ); 158 network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0 );
160 } 159 }
161 160
162 161
163 // insert new station as child from network 162 // insert new station as child from network
164 // no essid to reduce clutter, maybe later we have a nick or stationname to display!? 163 // no essid to reduce clutter, maybe later we have a nick or stationname to display!?
165 164
166 #ifdef DEBUG 165 #ifdef DEBUG
167 qDebug( "inserting new station %s", (const char*) macaddr ); 166 qDebug( "inserting new station %s", (const char*) macaddr );
168 #endif 167 #endif
169 168
170 MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal ); 169 MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal );
171 if ( _manufacturerdb ) 170 station->setManufacturer( mac.manufacturer() );
172 station->setManufacturer( _manufacturerdb->lookup( macaddr ) );
173 171
174 if ( type == "managed" ) 172 if ( type == "managed" )
175 { 173 {
176 s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel ); 174 s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel );
177 } 175 }
178 else 176 else
179 { 177 {
180 s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel ); 178 s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel );
181 } 179 }
182 MLogWindow::logwindow()->log( s ); 180 MLogWindow::logwindow()->log( s );
183 181
184} 182}
185 183
186 184
187void MScanListView::addIfNotExisting( MScanListItem* network, QString addr, const QString& type ) 185void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type )
188{ 186{
189 MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); 187 MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() );
190 188
191 while ( subitem && ( subitem->text( col_ap ) != addr ) ) 189 while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) )
192 { 190 {
193 #ifdef DEBUG 191 #ifdef DEBUG
194 qDebug( "subitemtext: %s", (const char*) subitem->text( col_ap ) ); 192 qDebug( "subitemtext: %s", (const char*) subitem->text( col_ap ) );
195 #endif 193 #endif
196 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() ); 194 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() );
197 } 195 }
198 196
199 if ( subitem ) 197 if ( subitem )
200 { 198 {
201 // we have already seen this item, it's a dupe 199 // we have already seen this item, it's a dupe
202 #ifdef DEBUG 200 #ifdef DEBUG
203 qDebug( "%s is a dupe - ignoring...", (const char*) addr ); 201 qDebug( "%s is a dupe - ignoring...", (const char*) addr.toString(true) );
204 #endif 202 #endif
205 subitem->receivedBeacon(); //FIXME: sent data bit 203 subitem->receivedBeacon(); //FIXME: sent data bit
206 return; 204 return;
207 } 205 }
208 206
209 // Hey, it seems to be a new item :-D 207 // Hey, it seems to be a new item :-D
210 MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr, false, -1, -1 ); 208 MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr.toString(true), false, -1, -1 );
211 if ( _manufacturerdb ) 209 station->setManufacturer( addr.manufacturer() );
212 station->setManufacturer( _manufacturerdb->lookup( addr ) );
213 210
214 QString s; 211 QString s;
215 if ( type == "station" ) 212 if ( type == "station" )
216 { 213 {
217 s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) ); 214 s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) );
218 } 215 }
219 else 216 else
220 { 217 {
221 s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) ); 218 s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) );
222 } 219 }
223 MLogWindow::logwindow()->log( s ); 220 MLogWindow::logwindow()->log( s );
224} 221}
225 222
226 223
227void MScanListView::WDStraffic( QString from, QString to, QString viaFrom, QString viaTo ) 224void MScanListView::WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo )
228{ 225{
229 QString s; 226 QString s;
230 MScanListItem* network; 227 MScanListItem* network;
231 228
232 QListViewItemIterator it( this ); 229 QListViewItemIterator it( this );
233 while ( it.current() && 230 while ( it.current() &&
234 it.current()->text( col_ap ) != viaFrom && 231 it.current()->text( col_ap ) != viaFrom.toString(true) &&
235 it.current()->text( col_ap ) != viaTo ) ++it; 232 it.current()->text( col_ap ) != viaTo.toString(true) ) ++it;
236 233
237 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 234 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
238 235
239 if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations 236 if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations
240 { 237 {
241 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from ); 238 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from );
242 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to ); 239 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to );
243 } 240 }
244 else 241 else
245 { 242 {
246 qDebug( "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" ); 243 qDebug( "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" );
247 MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" ); 244 MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" );
248 } 245 }
249} 246}
250 247
251 248
252void MScanListView::toDStraffic( QString from, QString to, QString via ) 249void MScanListView::toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
253{ 250{
254 QString s; 251 QString s;
255 MScanListItem* network; 252 MScanListItem* network;
256 253
257 QListViewItemIterator it( this ); 254 QListViewItemIterator it( this );
258 while ( it.current() && it.current()->text( col_ap ) != via ) ++it; 255 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
259 256
260 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 257 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
261 258
262 if ( item ) // AP has shown up yet, so just add our new "from" - station 259 if ( item ) // AP has shown up yet, so just add our new "from" - station
263 { 260 {
264 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" ); 261 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" );
265 } 262 }
266 else 263 else
267 { 264 {
268 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" ); 265 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" );
269 MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" ); 266 MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" );
270 267
271 } 268 }
272} 269}
273 270
274 271
275void MScanListView::fromDStraffic( QString from, QString to, QString via ) 272void MScanListView::fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
276{ 273{
277 QString s; 274 QString s;
278 MScanListItem* network; 275 MScanListItem* network;
279 276
280 QListViewItemIterator it( this ); 277 QListViewItemIterator it( this );
281 while ( it.current() && it.current()->text( col_ap ) != via ) ++it; 278 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
282 279
283 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 280 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
284 281
285 if ( item ) // AP has shown up yet, so just add our new "from" - station 282 if ( item ) // AP has shown up yet, so just add our new "from" - station
286 { 283 {
287 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" ); 284 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" );
288 } 285 }
289 else 286 else
290 { 287 {
291 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" ); 288 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" );
292 MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" ); 289 MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" );
293 } 290 }
294} 291}
295 292
296 293
297void MScanListView::IBSStraffic( QString from, QString to, QString via ) 294void MScanListView::IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
298{ 295{
299 qWarning( "D'oh! Not yet implemented..." ); 296 qWarning( "D'oh! Not yet implemented..." );
300 MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" ); 297 MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" );
301} 298}
302 299
303 300
304void MScanListView::identify( const QString& macaddr, const QString& ip ) 301void MScanListView::identify( const OMacAddress& macaddr, const QString& ip )
305{ 302{
306 qDebug( "identify %s = %s", (const char*) macaddr, (const char*) ip ); 303 qDebug( "identify %s = %s", (const char*) macaddr.toString(), (const char*) ip );
307 304
308 QListViewItemIterator it( this ); 305 QListViewItemIterator it( this );
309 for ( ; it.current(); ++it ) 306 for ( ; it.current(); ++it )
310 { 307 {
311 if ( it.current()->text( col_ap ) == macaddr ) 308 if ( it.current()->text( col_ap ) == macaddr.toString(true) )
312 { 309 {
313 it.current()->setText( col_ip, ip ); 310 it.current()->setText( col_ip, ip );
314 return; 311 return;
315 } 312 }
316 } 313 }
317 qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" ); 314 qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" );
318 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!", 315 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!",
319 (const char*) macaddr, (const char*) ip ) ); 316 (const char*) macaddr.toString(), (const char*) ip ) );
320} 317}
321 318
322 319
323//============================================================ 320//============================================================
324// MScanListItem 321// MScanListItem
325//============================================================ 322//============================================================
326 323
327MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr, 324MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr,
328 bool wep, int channel, int signal ) 325 bool wep, int channel, int signal )
329 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ), 326 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ),
330 _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ), 327 _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ),
331 _channel( channel ), _signal( signal ), _beacons( 1 ) 328 _channel( channel ), _signal( signal ), _beacons( 1 )
@@ -441,16 +438,18 @@ void MScanListItem::playSound( const QString& sound ) const
441 #endif 438 #endif
442} 439}
443 440
444 441
445void MScanListItem::receivedBeacon() 442void MScanListItem::receivedBeacon()
446{ 443{
447 _beacons++; 444 _beacons++;
448 #ifdef DEBUG 445 #ifdef DEBUG
449 qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons ); 446 qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons );
450 #endif 447 #endif
451 setText( col_sig, QString::number( _beacons ) ); 448 setText( col_sig, QString::number( _beacons ) );
452 setText( col_lastseen, QTime::currentTime().toString() ); 449 setText( col_lastseen, QTime::currentTime().toString() );
453 if ( WellenreiterConfigWindow::instance() ) 450
454 playSound( WellenreiterConfigWindow::instance()->soundOnBeacon() ); 451 MScanListItem* p = (MScanListItem*) parent();
452 if ( p ) p->receivedBeacon();
453
455} 454}
456 455