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.cpp130
1 files changed, 113 insertions, 17 deletions
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp
index cdc2c48..58a04fb 100644
--- a/noncore/net/wellenreiter/gui/scanlist.cpp
+++ b/noncore/net/wellenreiter/gui/scanlist.cpp
@@ -5,30 +5,28 @@
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 "scanlistitem.h"
18 17
19#include <assert.h> 18#include <assert.h>
20
21#include "manufacturers.h" 19#include "manufacturers.h"
22 20#include <qdatetime.h>
23#include <qtextstream.h> 21#include <qtextstream.h>
24 22
25MScanListView::MScanListView( QWidget* parent, const char* name ) 23MScanListView::MScanListView( QWidget* parent, const char* name )
26 :OListView( parent, name ), _manufacturerdb( 0 ) 24 :OListView( parent, name ), _manufacturerdb( 0 )
27{ 25{
28 26
29 setFrameShape( QListView::StyledPanel ); 27 setFrameShape( QListView::StyledPanel );
30 setFrameShadow( QListView::Sunken ); 28 setFrameShadow( QListView::Sunken );
31 29
32 addColumn( tr( "Net/Station" ) ); 30 addColumn( tr( "Net/Station" ) );
33 setColumnAlignment( 0, AlignLeft || AlignVCenter ); 31 setColumnAlignment( 0, AlignLeft || AlignVCenter );
34 addColumn( tr( "B" ) ); 32 addColumn( tr( "B" ) );
@@ -41,46 +39,58 @@ MScanListView::MScanListView( QWidget* parent, const char* name )
41 setColumnAlignment( 4, AlignCenter ); 39 setColumnAlignment( 4, AlignCenter );
42 addColumn( tr( "T" ) ); 40 addColumn( tr( "T" ) );
43 setColumnAlignment( 5, AlignCenter ); 41 setColumnAlignment( 5, AlignCenter );
44 addColumn( tr( "Manufacturer" ) ); 42 addColumn( tr( "Manufacturer" ) );
45 setColumnAlignment( 6, AlignCenter ); 43 setColumnAlignment( 6, AlignCenter );
46 addColumn( tr( "First Seen" ) ); 44 addColumn( tr( "First Seen" ) );
47 setColumnAlignment( 7, AlignCenter ); 45 setColumnAlignment( 7, AlignCenter );
48 addColumn( tr( "Last Seen" ) ); 46 addColumn( tr( "Last Seen" ) );
49 setColumnAlignment( 8, AlignCenter ); 47 setColumnAlignment( 8, AlignCenter );
50 setRootIsDecorated( true ); 48 setRootIsDecorated( true );
51 setAllColumnsShowFocus( true ); 49 setAllColumnsShowFocus( true );
52}; 50};
53 51
54MScanListView::~MScanListView() 52MScanListView::~MScanListView()
55{ 53{
56}; 54};
57 55
56void MScanListView::serializeTo( QDataStream& s) const
57{
58 qDebug( "serializing MScanListView" );
59 OListView::serializeTo( s );
60}
61
62void MScanListView::serializeFrom( QDataStream& s)
63{
64 qDebug( "serializing MScanListView" );
65 OListView::serializeFrom( s );
66}
67
58void MScanListView::setManufacturerDB( ManufacturerDB* manufacturerdb ) 68void MScanListView::setManufacturerDB( ManufacturerDB* manufacturerdb )
59{ 69{
60 _manufacturerdb = manufacturerdb; 70 _manufacturerdb = manufacturerdb;
61} 71}
62 72
63void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 73void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
64{ 74{
65 // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...) 75 // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...)
66 76
67 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", 77 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]",
68 (const char*) type, 78 (const char*) type,
69 (const char*) essid, 79 (const char*) essid,
70 (const char*) macaddr, 80 (const char*) macaddr,
71 channel ); 81 channel );
72 82
73 // search, if we already have seen this net 83 // search, if we already have seen this net
74 84
75 QString s; 85 QString s;
76 MScanListItem* network; 86 MScanListItem* network;
77 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() ); 87 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() );
78 88
79 while ( item && ( item->text( 0 ) != essid ) ) 89 while ( item && ( item->text( 0 ) != essid ) )
80 { 90 {
81 qDebug( "itemtext: %s", (const char*) item->text( 0 ) ); 91 qDebug( "itemtext: %s", (const char*) item->text( 0 ) );
82 item = static_cast<MScanListItem*> ( item->itemBelow() ); 92 item = static_cast<MScanListItem*> ( item->itemBelow() );
83 } 93 }
84 if ( item ) 94 if ( item )
85 { 95 {
86 // animate the item 96 // animate the item
@@ -89,40 +99,40 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo
89 99
90 const QPixmap* pixmap = item->pixmap( 0 ); 100 const QPixmap* pixmap = item->pixmap( 0 );
91 const QPixmap* nextpixmap = ani2; 101 const QPixmap* nextpixmap = ani2;
92 if ( pixmap == ani1 ) 102 if ( pixmap == ani1 )
93 nextpixmap = ani2; 103 nextpixmap = ani2;
94 else if ( pixmap == ani2 ) 104 else if ( pixmap == ani2 )
95 nextpixmap = ani3; 105 nextpixmap = ani3;
96 else if ( pixmap == ani3 ) 106 else if ( pixmap == ani3 )
97 nextpixmap = ani4; 107 nextpixmap = ani4;
98 else if ( pixmap == ani4 ) 108 else if ( pixmap == ani4 )
99 nextpixmap = ani1; 109 nextpixmap = ani1;
100 item->setPixmap( 0, *nextpixmap ); */ 110 item->setPixmap( 0, *nextpixmap ); */
101 111
102 //qDebug( "current pixmap %d, next %d", pixmap, nextpixmap ); 112 //qDebug( "current pixmap %d, next %d", pixmap, nextpixmap );
103 113
104 // we have already seen this net, check all childs if MAC exists 114 // we have already seen this net, check all childs if MAC exists
105 115
106 network = item; 116 network = item;
107 117
108 item = static_cast<MScanListItem*> ( item->firstChild() ); 118 item = static_cast<MScanListItem*> ( item->firstChild() );
109 assert( item ); // this shouldn't fail 119 assert( item ); // this shouldn't fail
110 120
111 while ( item && ( item->text( 2 ) != macaddr ) ) 121 while ( item && ( item->text( 2 ) != macaddr ) )
112 { 122 {
113 qDebug( "subitemtext: %s", (const char*) item->text( 2 ) ); 123 qDebug( "subitemtext: %s", (const char*) item->text( 2 ) );
114 item = static_cast<MScanListItem*> ( item->itemBelow() ); 124 item = static_cast<MScanListItem*> ( item->itemBelow() );
115 } 125 }
116 126
117 if ( item ) 127 if ( item )
118 { 128 {
119 // we have already seen this item, it's a dupe 129 // we have already seen this item, it's a dupe
120 #ifdef DEBUG 130 #ifdef DEBUG
121 qDebug( "%s is a dupe - ignoring...", (const char*) macaddr ); 131 qDebug( "%s is a dupe - ignoring...", (const char*) macaddr );
122 #endif 132 #endif
123 item->receivedBeacon(); 133 item->receivedBeacon();
124 return; 134 return;
125 } 135 }
126 } 136 }
127 else 137 else
128 { 138 {
@@ -144,24 +154,110 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo
144 154
145 if ( type == "managed" ) 155 if ( type == "managed" )
146 { 156 {
147 s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel ); 157 s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel );
148 } 158 }
149 else 159 else
150 { 160 {
151 s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel ); 161 s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel );
152 } 162 }
153 163
154} 164}
155 165
156void MScanListView::dump( QTextStream& t ) const 166#ifdef QWS
167#include <qpe/resource.h>
168#else
169#include "resource.h"
170#endif
171
172const int col_type = 0;
173const int col_essid = 0;
174const int col_sig = 1;
175const int col_ap = 2;
176const int col_channel = 3;
177const int col_wep = 4;
178const int col_traffic = 5;
179const int col_manuf = 6;
180const int col_firstseen = 7;
181const int col_lastseen = 8;
182
183MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr,
184 bool wep, int channel, int signal )
185 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ),
186 _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ),
187 _channel( channel ), _signal( signal ), _beacons( 0 )
157{ 188{
158 qDebug( "dumping scanlist..." ); 189 qDebug( "creating scanlist item" );
190 decorateItem( type, essid, macaddr, wep, channel, signal );
191}
159 192
160 QListViewItemIterator it( const_cast<MScanListView*>( this ) ); 193MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr,
161 for ( ; it.current(); ++it ) 194 bool wep, int channel, int signal )
162 { 195 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
163 static_cast<MScanListItem*>( it.current() )->dump( t ); 196{
164 } 197 qDebug( "creating scanlist item" );
198 decorateItem( type, essid, macaddr, wep, channel, signal );
199}
165 200
166 qDebug( "dump finished." ); 201void MScanListItem::serializeTo( QDataStream& s ) const
202{
203 OListViewItem::serializeTo( s );
204}
205
206void MScanListItem::serializeFrom( QDataStream& s )
207{
208 OListViewItem::serializeFrom( s );
167} 209}
210
211void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
212{
213 qDebug( "decorating scanlist item %s / %s / %s [%d]",
214 (const char*) type,
215 (const char*) essid,
216 (const char*) macaddr,
217 channel );
218
219 // set icon for managed or adhoc mode
220 QString name;
221 name.sprintf( "wellenreiter/%s", (const char*) type );
222 setPixmap( col_type, Resource::loadPixmap( name ) );
223
224 // set icon for wep (wireless encryption protocol)
225 if ( wep )
226 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
227
228 // set channel and signal text
229
230 if ( signal != -1 )
231 setText( col_sig, QString::number( signal ) );
232 if ( channel != -1 )
233 setText( col_channel, QString::number( channel ) );
234
235 setText( col_firstseen, QTime::currentTime().toString() );
236 //setText( col_lastseen, QTime::currentTime().toString() );
237
238 listView()->triggerUpdate();
239
240 this->type = type;
241 _type = type;
242 _essid = essid;
243 _macaddr = macaddr;
244 _channel = channel;
245 _beacons = 0;
246 _signal = 0;
247}
248
249void MScanListItem::setManufacturer( const QString& manufacturer )
250{
251 setText( col_manuf, manufacturer );
252}
253
254void MScanListItem::receivedBeacon()
255{
256 _beacons++;
257 #ifdef DEBUG
258 qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons );
259 #endif
260 setText( col_sig, QString::number( _beacons ) );
261 setText( col_lastseen, QTime::currentTime().toString() );
262}
263