summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2002-12-09 19:37:47 (UTC)
committer mickeyl <mickeyl>2002-12-09 19:37:47 (UTC)
commit046f040efcb0f313818d1dbb1dc1db9021678175 (patch) (unidiff)
tree7fe87d0cfecc6a61856285e307dfc592bbd55fbd
parent711d8c1af3ebdd6f88ff3e9ffa46624c9b63badd (diff)
downloadopie-046f040efcb0f313818d1dbb1dc1db9021678175.zip
opie-046f040efcb0f313818d1dbb1dc1db9021678175.tar.gz
opie-046f040efcb0f313818d1dbb1dc1db9021678175.tar.bz2
improved display logic
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/logwindow.cpp1
-rw-r--r--noncore/net/wellenreiter/gui/scanlistitem.cpp6
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp81
3 files changed, 65 insertions, 23 deletions
diff --git a/noncore/net/wellenreiter/gui/logwindow.cpp b/noncore/net/wellenreiter/gui/logwindow.cpp
index dafb429..c355f09 100644
--- a/noncore/net/wellenreiter/gui/logwindow.cpp
+++ b/noncore/net/wellenreiter/gui/logwindow.cpp
@@ -11,28 +11,29 @@
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 "logwindow.h" 16#include "logwindow.h"
17#include <qmultilineedit.h> 17#include <qmultilineedit.h>
18#include <qdatetime.h> 18#include <qdatetime.h>
19 19
20MLogWindow::MLogWindow( QWidget * parent, const char * name, WFlags f ) 20MLogWindow::MLogWindow( QWidget * parent, const char * name, WFlags f )
21 :QVBox( parent, name, f ) 21 :QVBox( parent, name, f )
22{ 22{
23 ledit = new QMultiLineEdit( this ); 23 ledit = new QMultiLineEdit( this );
24 24
25 // FIXME: Set properties( font, read-only, etc...) 25 // FIXME: Set properties( font, read-only, etc...)
26 26
27}; 27};
28 28
29void MLogWindow::log( QString text ) 29void MLogWindow::log( QString text )
30{ 30{
31 QTime time = QTime::currentTime(); 31 QTime time = QTime::currentTime();
32 QString line; 32 QString line;
33 line.sprintf( "[%s] %s", (const char*) time.toString(), (const char*) text ); 33 line.sprintf( "[%s] %s", (const char*) time.toString(), (const char*) text );
34 ledit->append( line ); 34 ledit->append( line );
35 qDebug( line );
35 36
36}; 37};
37 38
38 39
diff --git a/noncore/net/wellenreiter/gui/scanlistitem.cpp b/noncore/net/wellenreiter/gui/scanlistitem.cpp
index 189a12d..398b42d 100644
--- a/noncore/net/wellenreiter/gui/scanlistitem.cpp
+++ b/noncore/net/wellenreiter/gui/scanlistitem.cpp
@@ -23,47 +23,51 @@ const int col_essid = 0;
23const int col_sig = 1; 23const int col_sig = 1;
24const int col_ap = 2; 24const int col_ap = 2;
25const int col_channel = 3; 25const int col_channel = 3;
26const int col_wep = 4; 26const int col_wep = 4;
27const int col_traffic = 5; 27const int col_traffic = 5;
28 28
29MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr, 29MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr,
30 bool wep, int channel, int signal ) 30 bool wep, int channel, int signal )
31 :QListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) 31 :QListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
32{ 32{
33 qDebug( "creating scanlist item" ); 33 qDebug( "creating scanlist item" );
34 decorateItem( type, essid, macaddr, wep, channel, signal ); 34 decorateItem( type, essid, macaddr, wep, channel, signal );
35} 35}
36 36
37MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr, 37MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr,
38 bool wep, int channel, int signal ) 38 bool wep, int channel, int signal )
39 :QListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) 39 :QListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
40{ 40{
41 qDebug( "creating scanlist item" ); 41 qDebug( "creating scanlist item" );
42 decorateItem( type, essid, macaddr, wep, channel, signal ); 42 decorateItem( type, essid, macaddr, wep, channel, signal );
43} 43}
44 44
45void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 45void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
46{ 46{
47 qDebug( "decorating scanlist item" ); 47 qDebug( "decorating scanlist item %s / %s / %s [%d]",
48 (const char*) type,
49 (const char*) essid,
50 (const char*) macaddr,
51 channel );
48 52
49 // set icon for managed or adhoc mode 53 // set icon for managed or adhoc mode
50 QString name; 54 QString name;
51 name.sprintf( "wellenreiter/%s", (const char*) type ); 55 name.sprintf( "wellenreiter/%s", (const char*) type );
52 setPixmap( col_type, Resource::loadPixmap( name ) ); 56 setPixmap( col_type, Resource::loadPixmap( name ) );
53 57
54 // set icon for wep (wireless encryption protocol) 58 // set icon for wep (wireless encryption protocol)
55 if ( wep ) 59 if ( wep )
56 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); // rename the pixmap! 60 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); // rename the pixmap!
57 61
58 // set channel and signal text 62 // set channel and signal text
59 63
60 if ( signal != -1 ) 64 if ( signal != -1 )
61 setText( col_sig, QString::number( signal ) ); 65 setText( col_sig, QString::number( signal ) );
62 if ( channel != -1 ) 66 if ( channel != -1 )
63 setText( col_channel, QString::number( channel ) ); 67 setText( col_channel, QString::number( channel ) );
64 68
65 listView()->triggerUpdate(); 69 listView()->triggerUpdate();
66 70
67 this->type = type; 71 this->type = type;
68 72
69} 73}
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index 9c8630f..6d62fa8 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -1,45 +1,46 @@
1/********************************************************************** 1/**********************************************************************
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// Qt 16// Qt
17 17
18#include <qpushbutton.h> 18#include <qpushbutton.h>
19 19
20// Standard 20// Standard
21 21
22#include <assert.h>
22#include <unistd.h> 23#include <unistd.h>
23#include <sys/types.h> 24#include <sys/types.h>
24 25
25// Local 26// Local
26 27
27#include "wellenreiter.h" 28#include "wellenreiter.h"
28#include "scanlistitem.h" 29#include "scanlistitem.h"
29#include "logwindow.h" 30#include "logwindow.h"
30#include "hexwindow.h" 31#include "hexwindow.h"
31 32
32#include "../libwellenreiter/source/sock.hh" // <--- ugly path, FIX THIS! 33#include "../libwellenreiter/source/sock.hh" // <--- ugly path, FIX THIS!
33#include "../libwellenreiter/source/proto.hh" // <--- ugly path, FIX THIS! 34#include "../libwellenreiter/source/proto.hh" // <--- ugly path, FIX THIS!
34#include "../daemon/source/config.hh" // <--- ugly path, FIX THIS! 35#include "../daemon/source/config.hh" // <--- ugly path, FIX THIS!
35 36
36Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl ) 37Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl )
37 : WellenreiterBase( parent, name, fl ) 38 : WellenreiterBase( parent, name, fl )
38{ 39{
39 40
40 logwindow->log( "(i) Wellenreiter has been started." ); 41 logwindow->log( "(i) Wellenreiter has been started." );
41 42
42 connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); 43 connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
43 netview->setColumnWidthMode( 1, QListView::Manual ); 44 netview->setColumnWidthMode( 1, QListView::Manual );
44 45
45 // 46 //
@@ -63,148 +64,184 @@ Wellenreiter::~Wellenreiter()
63} 64}
64 65
65void Wellenreiter::handleMessage() 66void Wellenreiter::handleMessage()
66{ 67{
67 // FIXME: receive message and handle it 68 // FIXME: receive message and handle it
68 69
69 qDebug( "received message from daemon." ); 70 qDebug( "received message from daemon." );
70 71
71 char buffer[128]; 72 char buffer[128];
72 73
73 int result = recvcomm( &daemon_fd, (char*) &buffer, sizeof(buffer) ); 74 int result = recvcomm( &daemon_fd, (char*) &buffer, sizeof(buffer) );
74 qDebug( "received %d from recvcomm", result ); 75 qDebug( "received %d from recvcomm", result );
75 76
76/* 77/*
77typedef struct { 78typedef struct {
78 int net_type; 1 = Accesspoint ; 2 = Ad-Hoc 79 int net_type; 1 = Accesspoint ; 2 = Ad-Hoc
79 int ssid_len; Length of SSID 80 int ssid_len; Length of SSID
80 int channel; Channel 81 int channel; Channel
81 int wep; 1 = WEP enabled ; 0 = disabled 82 int wep; 1 = WEP enabled ; 0 = disabled
82 char mac[64]; MAC address of Accesspoint 83 char mac[64]; MAC address of Accesspoint
83 char bssid[128]; BSSID of Accesspoint 84 char bssid[128]; BSSID of Accesspoint
84} wl_network_t; 85} wl_network_t;
85*/ 86*/
86 87
87 qDebug( "Sniffer sent: '%s'", (const char*) &buffer ); 88 // qDebug( "Sniffer sent: '%s'", (const char*) buffer );
88 hexwindow->log( (const char*) &buffer ); 89 hexwindow->log( (const char*) &buffer );
89 90
90 if ( result == NETFOUND ) /* new network found */ 91 if ( result == NETFOUND ) /* new network found */
91 { 92 {
92 logwindow->log( "(i) found new network" );
93 qDebug( "Sniffer said: new network found." ); 93 qDebug( "Sniffer said: new network found." );
94 wl_network_t n; 94 wl_network_t n;
95 get_network_found( &n, (char*) &buffer ); 95 get_network_found( &n, (char*) &buffer );
96 96
97 qDebug( "Sniffer said: net_type is %d.", n.net_type ); 97 qDebug( "Sniffer said: net_type is %d.", n.net_type );
98 qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); 98 qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac );
99 99
100 //n.bssid[n.ssid_len] = "\0"; 100 //n.bssid[n.ssid_len] = "\0";
101 101
102 QString type; 102 QString type;
103 103
104 if ( n.net_type == 1 ) 104 if ( n.net_type == 1 )
105 type = "managed"; 105 type = "managed";
106 else 106 else
107 type = "adhoc"; 107 type = "adhoc";
108 108
109 addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); 109 addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 );
110 110
111 } 111 }
112 112
113 else 113 else
114 114
115 { 115 {
116 qDebug( "unknown sniffer command." ); 116 qDebug( "unknown sniffer command." );
117 } 117 }
118 118
119} 119}
120 120
121 121
122bool Wellenreiter::hasMessage() 122bool Wellenreiter::hasMessage()
123{ 123{
124 124
125 // FIXME: do this in libwellenreiter, not here!!! 125 // FIXME: do this in libwellenreiter, not here!!!
126 126
127 fd_set rfds; 127 fd_set rfds;
128 FD_ZERO( &rfds ); 128 FD_ZERO( &rfds );
129 FD_SET( daemon_fd, &rfds ); 129 FD_SET( daemon_fd, &rfds );
130 struct timeval tv; 130 struct timeval tv;
131 tv.tv_sec = 0; 131 tv.tv_sec = 0;
132 tv.tv_usec = 10; 132 tv.tv_usec = 10;
133 int result = select( daemon_fd+1, &rfds, NULL, NULL, &tv ); 133 int result = select( daemon_fd+1, &rfds, NULL, NULL, &tv );
134 return FD_ISSET( daemon_fd, &rfds ); 134 return FD_ISSET( daemon_fd, &rfds );
135} 135}
136 136
137void Wellenreiter::timerEvent( QTimerEvent* e ) 137void Wellenreiter::timerEvent( QTimerEvent* e )
138{ 138{
139 qDebug( "checking for message..." ); 139 qDebug( "checking for message..." );
140 140
141 if ( hasMessage() ) 141 int result = hasMessage();
142 qDebug( "hasMessage() returned %d", result );
143
144 if ( result )
142 { 145 {
143 handleMessage(); 146 handleMessage();
144 } 147 }
145 else 148 else
146 { 149 {
147 qDebug( "no message :(" ); 150 qDebug( "no message :(" );
148 } 151 }
149} 152}
150 153
151void Wellenreiter::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 154void Wellenreiter::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
152{ 155{
153 // FIXME: this code belongs in customized QListView, not into this class 156 // FIXME: this code belongs in customized QListView, not into this class
157 // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...)
154 158
155 // search, if we had an item with this essid once before 159 qDebug( "Wellenreiter::addNewItem( %s / %s / %s [%d]",
156 160 (const char*) type,
157 //MScanListItem* item = dynamic_cast<MScanListItem*>( netview->firstChild() ); 161 (const char*) essid,
158 MScanListItem* item = static_cast<MScanListItem*>( netview->firstChild() ); 162 (const char*) macaddr,
163 channel );
164
165 // search, if we already have seen this net
166
167 QString s;
168 MScanListItem* network;
169 MScanListItem* item = (MScanListItem*) netview->firstChild();
159 170
160 while ( item && ( item->text( 0 ) != essid ) ) 171 while ( item && ( item->text( 0 ) != essid ) )
161 { 172 {
162 qDebug( "itemtext: %s", (const char*) item->text( 0 ) ); 173 qDebug( "itemtext: %s", (const char*) item->text( 0 ) );
163 item = dynamic_cast<MScanListItem*>( item->itemBelow() ); 174 item = item->itemBelow();
164 } 175 }
165 if ( item ) 176 if ( item )
166 { 177 {
167 qDebug( "found!" ); 178 // we have already seen this net, check all childs if MAC exists
168 179
169 // check, if it is the same item (based on MACaddr) 180 network = item;
170 181
171 if ( macaddr == item->text( 2 ) ) 182 item = item->firstChild();
183 assert( item ); // this shouldn't fail
184
185 while ( item && ( item->text( 2 ) != macaddr ) )
172 { 186 {
173 qDebug( "already had item with mac %s", (const char*) item->text( 2 ) ); 187 qDebug( "subitemtext: %s", (const char*) item->text( 2 ) );
174 return; 188 item = item->itemBelow();
175 } 189 }
176
177 // another item belonging to the same net, so: insert the new item as child
178 190
179 new MScanListItem( item, type, essid, macaddr, wep, channel, signal ); 191 if ( item )
192 {
193 // we have already seen this item, it's a dupe
194 qDebug( "%s is a dupe - ignoring...", (const char*) macaddr );
195 return;
196 }
180 } 197 }
181
182 else 198 else
183 { 199 {
184 qDebug( "inserting new network" ); 200 s.sprintf( "(i) new network: '%s'", (const char*) essid );
185 MScanListItem* network = new MScanListItem( netview, "networks", essid, QString::null, 0, 0, 0 ); 201 logwindow->log( s );
202
203 network = new MScanListItem( netview, "networks", essid, QString::null, 0, 0, 0 );
204 }
205
206
207 // insert new station as child from network
208
209 // no essid to reduce clutter, maybe later we have a nick or stationname to display!?
210
211 qDebug( "inserting new station %s", (const char*) macaddr );
186 212
187 new MScanListItem( network, type, essid, macaddr, wep, channel, signal ); 213 new MScanListItem( network, type, "", macaddr, wep, channel, signal );
214
215 if ( type == "managed" )
216 {
217 s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel );
218 }
219 else
220 {
221 s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel );
188 } 222 }
223
224 logwindow->log( s );
225
189} 226}
190 227
191void Wellenreiter::buttonClicked() 228void Wellenreiter::buttonClicked()
192{ 229{
193 230
194 // FIXME: communicate with daemon and set button text according to state 231 // FIXME: communicate with daemon and set button text according to state
195 232
196 button->setText( "Stop Scanning" ); 233 button->setText( "Stop Scanning" );
197 234
198 // add some test stations, so that we can see if the GUI part works 235 // add some test stations, so that we can see if the GUI part works
199 236
200 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 ); 237 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 );
201 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 ); 238 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 );
202 addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 ); 239 addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 );
203 addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 ); 240 addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 );
204 addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 ); 241 addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 );
205 242
206 QString command ("98"); 243 QString command ("98");
207 244
208 //sendcomm( DAEMONADDR, DAEMONPORT, (const char*) command ); 245 //sendcomm( DAEMONADDR, DAEMONPORT, (const char*) command );
209 246
210} 247}