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.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp
index f4cfe52..d695c17 100644
--- a/noncore/net/wellenreiter/gui/scanlist.cpp
+++ b/noncore/net/wellenreiter/gui/scanlist.cpp
@@ -2,228 +2,238 @@
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 <qcursor.h> 21#include <qcursor.h>
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qtextstream.h> 23#include <qtextstream.h>
24#include <qpopupmenu.h> 24#include <qpopupmenu.h>
25 25
26#ifdef QWS 26#ifdef QWS
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <opie/odevice.h> 28#include <opie/odevice.h>
29using namespace Opie; 29using namespace Opie;
30#endif 30#endif
31 31
32 32
33#ifdef QWS 33#ifdef QWS
34#include <qpe/resource.h> 34#include <qpe/resource.h>
35#else 35#else
36#include "resource.h" 36#include "resource.h"
37#endif 37#endif
38 38
39const int col_type = 0; 39const int col_type = 0;
40const int col_essid = 0; 40const int col_essid = 0;
41const int col_sig = 1; 41const int col_sig = 1;
42const int col_ap = 2; 42const int col_ap = 2;
43const int col_channel = 3; 43const int col_channel = 3;
44const int col_wep = 4; 44const int col_wep = 4;
45const int col_traffic = 5; 45const int col_traffic = 5;
46const int col_ip = 6; 46const int col_ip = 6;
47const int col_manuf = 7; 47const int col_manuf = 7;
48const int col_firstseen = 8; 48const int col_firstseen = 8;
49const int col_lastseen = 9; 49const int col_lastseen = 9;
50const int col_location = 10;
50 51
51MScanListView::MScanListView( QWidget* parent, const char* name ) 52MScanListView::MScanListView( QWidget* parent, const char* name )
52 :OListView( parent, name ) 53 :OListView( parent, name )
53{ 54{
54 55
55 setFrameShape( QListView::StyledPanel ); 56 setFrameShape( QListView::StyledPanel );
56 setFrameShadow( QListView::Sunken ); 57 setFrameShadow( QListView::Sunken );
57 58
58 addColumn( tr( "Net/Station" ) ); 59 addColumn( tr( "Net/Station" ) );
59 setColumnAlignment( col_essid, AlignLeft || AlignVCenter ); 60 setColumnAlignment( col_essid, AlignLeft || AlignVCenter );
60 addColumn( tr( "#" ) ); 61 addColumn( tr( "#" ) );
61 setColumnAlignment( col_sig, AlignCenter ); 62 setColumnAlignment( col_sig, AlignCenter );
62 addColumn( tr( "MAC" ) ); 63 addColumn( tr( "MAC" ) );
63 setColumnAlignment( col_ap, AlignCenter ); 64 setColumnAlignment( col_ap, AlignCenter );
64 addColumn( tr( "Chn" ) ); 65 addColumn( tr( "Chn" ) );
65 setColumnAlignment( col_channel, AlignCenter ); 66 setColumnAlignment( col_channel, AlignCenter );
66 addColumn( tr( "W" ) ); 67 addColumn( tr( "W" ) );
67 setColumnAlignment( col_wep, AlignCenter ); 68 setColumnAlignment( col_wep, AlignCenter );
68 addColumn( tr( "T" ) ); 69 addColumn( tr( "T" ) );
69 setColumnAlignment( col_traffic, AlignCenter ); 70 setColumnAlignment( col_traffic, AlignCenter );
70 addColumn( tr( "IP" ) ); 71 addColumn( tr( "IP" ) );
71 setColumnAlignment( col_ip, AlignCenter ); 72 setColumnAlignment( col_ip, AlignCenter );
72 addColumn( tr( "Manufacturer" ) ); 73 addColumn( tr( "Manufacturer" ) );
73 setColumnAlignment( col_manuf, AlignCenter ); 74 setColumnAlignment( col_manuf, AlignCenter );
74 addColumn( tr( "First Seen" ) ); 75 addColumn( tr( "First Seen" ) );
75 setColumnAlignment( col_firstseen, AlignCenter ); 76 setColumnAlignment( col_firstseen, AlignCenter );
76 addColumn( tr( "Last Seen" ) ); 77 addColumn( tr( "Last Seen" ) );
77 setColumnAlignment( col_lastseen, AlignCenter ); 78 setColumnAlignment( col_lastseen, AlignCenter );
79 addColumn( tr( "Location" ) );
80 setColumnAlignment( col_location, AlignCenter );
78 setRootIsDecorated( true ); 81 setRootIsDecorated( true );
79 setAllColumnsShowFocus( true ); 82 setAllColumnsShowFocus( true );
80 83
81 connect( this, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), 84 connect( this, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ),
82 this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) ); 85 this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) );
83 86
84 #ifdef QWS 87 #ifdef QWS
85 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 88 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
86 #endif 89 #endif
87 90
88}; 91};
89 92
90 93
91MScanListView::~MScanListView() 94MScanListView::~MScanListView()
92{ 95{
93}; 96};
94 97
95 98
96OListViewItem* MScanListView::childFactory() 99OListViewItem* MScanListView::childFactory()
97{ 100{
98 return new MScanListItem( this ); 101 return new MScanListItem( this );
99} 102}
100 103
101 104
102void MScanListView::serializeTo( QDataStream& s) const 105void MScanListView::serializeTo( QDataStream& s) const
103{ 106{
104 qDebug( "serializing MScanListView" ); 107 qDebug( "serializing MScanListView" );
105 OListView::serializeTo( s ); 108 OListView::serializeTo( s );
106} 109}
107 110
108 111
109void MScanListView::serializeFrom( QDataStream& s) 112void MScanListView::serializeFrom( QDataStream& s)
110{ 113{
111 qDebug( "serializing MScanListView" ); 114 qDebug( "serializing MScanListView" );
112 OListView::serializeFrom( s ); 115 OListView::serializeFrom( s );
113} 116}
114 117
115 118
116void MScanListView::addNewItem( const QString& type, const QString& essid, const OMacAddress& mac, bool wep, int channel, int signal ) 119void MScanListView::addNewItem( const QString& type,
120 const QString& essid,
121 const OMacAddress& mac,
122 bool wep,
123 int channel,
124 int signal,
125 const GpsLocation& loc )
117{ 126{
118 QString macaddr = mac.toString(true); 127 QString macaddr = mac.toString(true);
119 128
120 #ifdef DEBUG 129 #ifdef DEBUG
121 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type, 130 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type,
122 (const char*) essid, (const char*) macaddr, channel ); 131 (const char*) essid, (const char*) macaddr, channel );
123 #endif 132 #endif
124 133
125 // search, if we already have seen this net 134 // search, if we already have seen this net
126 135
127 QString s; 136 QString s;
128 MScanListItem* network; 137 MScanListItem* network;
129 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() ); 138 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() );
130 139
131 while ( item && ( item->text( col_essid ) != essid ) ) 140 while ( item && ( item->text( col_essid ) != essid ) )
132 { 141 {
133 #ifdef DEBUG 142 #ifdef DEBUG
134 qDebug( "itemtext: %s", (const char*) item->text( col_essid ) ); 143 qDebug( "itemtext: %s", (const char*) item->text( col_essid ) );
135 #endif 144 #endif
136 item = static_cast<MScanListItem*> ( item->nextSibling() ); 145 item = static_cast<MScanListItem*> ( item->nextSibling() );
137 } 146 }
138 if ( item ) 147 if ( item )
139 { 148 {
140 // we have already seen this net, check all childs if MAC exists 149 // we have already seen this net, check all childs if MAC exists
141 150
142 network = item; 151 network = item;
143 152
144 item = static_cast<MScanListItem*> ( item->firstChild() ); 153 item = static_cast<MScanListItem*> ( item->firstChild() );
145 assert( item ); // this shouldn't fail 154 assert( item ); // this shouldn't fail
146 155
147 while ( item && ( item->text( col_ap ) != macaddr ) ) 156 while ( item && ( item->text( col_ap ) != macaddr ) )
148 { 157 {
149 #ifdef DEBUG 158 #ifdef DEBUG
150 qDebug( "subitemtext: %s", (const char*) item->text( col_ap ) ); 159 qDebug( "subitemtext: %s", (const char*) item->text( col_ap ) );
151 #endif 160 #endif
152 item = static_cast<MScanListItem*> ( item->nextSibling() ); 161 item = static_cast<MScanListItem*> ( item->nextSibling() );
153 } 162 }
154 163
155 if ( item ) 164 if ( item )
156 { 165 {
157 // we have already seen this item, it's a dupe 166 // we have already seen this item, it's a dupe
158 #ifdef DEBUG 167 #ifdef DEBUG
159 qDebug( "%s is a dupe - ignoring...", (const char*) macaddr ); 168 qDebug( "%s is a dupe - ignoring...", (const char*) macaddr );
160 #endif 169 #endif
161 item->receivedBeacon(); 170 item->receivedBeacon();
162 return; 171 return;
163 } 172 }
164 } 173 }
165 else 174 else
166 { 175 {
167 s.sprintf( "(i) New network: ESSID '%s'", (const char*) essid ); 176 s.sprintf( "(i) New network: ESSID '%s'", (const char*) essid );
168 MLogWindow::logwindow()->log( s ); 177 MLogWindow::logwindow()->log( s );
169 network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0 ); 178 network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0 );
170 } 179 }
171 180
172 181
173 // insert new station as child from network 182 // insert new station as child from network
174 // no essid to reduce clutter, maybe later we have a nick or stationname to display!? 183 // no essid to reduce clutter, maybe later we have a nick or stationname to display!?
175 184
176 #ifdef DEBUG 185 #ifdef DEBUG
177 qDebug( "inserting new station %s", (const char*) macaddr ); 186 qDebug( "inserting new station %s", (const char*) macaddr );
178 #endif 187 #endif
179 188
180 MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal ); 189 MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal );
181 station->setManufacturer( mac.manufacturer() ); 190 station->setManufacturer( mac.manufacturer() );
191 station->setLocation( loc.latitude, loc.longitude );
182 192
183 if ( type == "managed" ) 193 if ( type == "managed" )
184 { 194 {
185 s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel ); 195 s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel );
186 } 196 }
187 else 197 else
188 { 198 {
189 s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel ); 199 s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel );
190 } 200 }
191 MLogWindow::logwindow()->log( s ); 201 MLogWindow::logwindow()->log( s );
192 202
193} 203}
194 204
195 205
196void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type ) 206void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type )
197{ 207{
198 MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); 208 MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() );
199 209
200 while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) ) 210 while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) )
201 { 211 {
202 #ifdef DEBUG 212 #ifdef DEBUG
203 qDebug( "subitemtext: %s", (const char*) subitem->text( col_ap ) ); 213 qDebug( "subitemtext: %s", (const char*) subitem->text( col_ap ) );
204 #endif 214 #endif
205 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() ); 215 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() );
206 } 216 }
207 217
208 if ( subitem ) 218 if ( subitem )
209 { 219 {
210 // we have already seen this item, it's a dupe 220 // we have already seen this item, it's a dupe
211 #ifdef DEBUG 221 #ifdef DEBUG
212 qDebug( "%s is a dupe - ignoring...", (const char*) addr.toString(true) ); 222 qDebug( "%s is a dupe - ignoring...", (const char*) addr.toString(true) );
213 #endif 223 #endif
214 subitem->receivedBeacon(); //FIXME: sent data bit 224 subitem->receivedBeacon(); //FIXME: sent data bit
215 return; 225 return;
216 } 226 }
217 227
218 // Hey, it seems to be a new item :-D 228 // Hey, it seems to be a new item :-D
219 MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr.toString(true), false, -1, -1 ); 229 MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr.toString(true), false, -1, -1 );
220 station->setManufacturer( addr.manufacturer() ); 230 station->setManufacturer( addr.manufacturer() );
221 231
222 QString s; 232 QString s;
223 if ( type == "station" ) 233 if ( type == "station" )
224 { 234 {
225 s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) ); 235 s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) );
226 } 236 }
227 else 237 else
228 { 238 {
229 s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) ); 239 s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) );
@@ -423,73 +433,82 @@ void MScanListItem::serializeFrom( QDataStream& s )
423 433
424void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 434void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
425{ 435{
426 #ifdef DEBUG 436 #ifdef DEBUG
427 qDebug( "decorating scanlist item %s / %s / %s [%d]", 437 qDebug( "decorating scanlist item %s / %s / %s [%d]",
428 (const char*) type, 438 (const char*) type,
429 (const char*) essid, 439 (const char*) essid,
430 (const char*) macaddr, 440 (const char*) macaddr,
431 channel ); 441 channel );
432 #endif 442 #endif
433 443
434 // set icon for managed or adhoc mode 444 // set icon for managed or adhoc mode
435 QString name; 445 QString name;
436 name.sprintf( "wellenreiter/%s", (const char*) type ); 446 name.sprintf( "wellenreiter/%s", (const char*) type );
437 setPixmap( col_type, Resource::loadPixmap( name ) ); 447 setPixmap( col_type, Resource::loadPixmap( name ) );
438 448
439 // set icon for wep (wireless encryption protocol) 449 // set icon for wep (wireless encryption protocol)
440 if ( wep ) 450 if ( wep )
441 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! 451 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
442 452
443 // set channel and signal text 453 // set channel and signal text
444 454
445 if ( signal != -1 ) 455 if ( signal != -1 )
446 setText( col_sig, QString::number( signal ) ); 456 setText( col_sig, QString::number( signal ) );
447 if ( channel != -1 ) 457 if ( channel != -1 )
448 setText( col_channel, QString::number( channel ) ); 458 setText( col_channel, QString::number( channel ) );
449 459
450 setText( col_firstseen, QTime::currentTime().toString() ); 460 setText( col_firstseen, QTime::currentTime().toString() );
451 //setText( col_lastseen, QTime::currentTime().toString() ); 461 //setText( col_lastseen, QTime::currentTime().toString() );
452 462
453 listView()->triggerUpdate(); 463 listView()->triggerUpdate();
454 464
455 this->type = type; 465 this->type = type;
456 _type = type; 466 _type = type;
457 _essid = essid; 467 _essid = essid;
458 _macaddr = macaddr; 468 _macaddr = macaddr;
459 _channel = channel; 469 _channel = channel;
460 _beacons = 1; 470 _beacons = 1;
461 _signal = 0; 471 _signal = 0;
462} 472}
463 473
464 474
465void MScanListItem::setManufacturer( const QString& manufacturer ) 475void MScanListItem::setManufacturer( const QString& manufacturer )
466{ 476{
467 setText( col_manuf, manufacturer ); 477 setText( col_manuf, manufacturer );
468} 478}
469 479
470 480
481void MScanListItem::setLocation( const float& latitude, const float& longitude )
482{
483 if ( latitude == 0.0 || longitude == 0.0 )
484 setText( col_location, "N/A" );
485 else
486 setText( col_location, QString().sprintf( "%.2f / %.2f", latitude, longitude ) );
487}
488
489
471void MScanListItem::playSound( const QString& sound ) const 490void MScanListItem::playSound( const QString& sound ) const
472{ 491{
473 #ifdef QWS 492 #ifdef QWS
474 if ( sound == "Ignore" ) return; 493 if ( sound == "Ignore" ) return;
475 else if ( sound == "Touch" ) ODevice::inst()->touchSound(); 494 else if ( sound == "Touch" ) ODevice::inst()->touchSound();
476 else if ( sound == "Key" ) ODevice::inst()->keySound(); 495 else if ( sound == "Key" ) ODevice::inst()->keySound();
477 else if ( sound == "Alarm" ) ODevice::inst()->alarmSound(); 496 else if ( sound == "Alarm" ) ODevice::inst()->alarmSound();
478 #endif 497 #endif
479} 498}
480 499
481 500
482void MScanListItem::receivedBeacon() 501void MScanListItem::receivedBeacon()
483{ 502{
484 _beacons++; 503 _beacons++;
485 #ifdef DEBUG 504 #ifdef DEBUG
486 qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons ); 505 qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons );
487 #endif 506 #endif
488 setText( col_sig, QString::number( _beacons ) ); 507 setText( col_sig, QString::number( _beacons ) );
489 setText( col_lastseen, QTime::currentTime().toString() ); 508 setText( col_lastseen, QTime::currentTime().toString() );
490 509
491 MScanListItem* p = (MScanListItem*) parent(); 510 MScanListItem* p = (MScanListItem*) parent();
492 if ( p ) p->receivedBeacon(); 511 if ( p ) p->receivedBeacon();
493 512
494} 513}
495 514