Diffstat (limited to 'noncore/net/wellenreiter/gui/wellenreiter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 81 |
1 files changed, 59 insertions, 22 deletions
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 | |||
@@ -16,12 +16,13 @@ | |||
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" |
@@ -81,34 +82,33 @@ typedef struct { | |||
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 | ||
@@ -135,60 +135,97 @@ bool Wellenreiter::hasMessage() | |||
135 | } | 135 | } |
136 | 136 | ||
137 | void Wellenreiter::timerEvent( QTimerEvent* e ) | 137 | void 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 | ||
151 | void Wellenreiter::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) | 154 | void 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 | ||
191 | void Wellenreiter::buttonClicked() | 228 | void 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 |