-rw-r--r-- | noncore/applets/wirelessapplet/networkinfo.cpp | 284 | ||||
-rw-r--r-- | noncore/applets/wirelessapplet/networkinfo.h | 126 | ||||
-rw-r--r-- | noncore/applets/wirelessapplet/wireless.cpp | 59 | ||||
-rw-r--r-- | noncore/applets/wirelessapplet/wirelessapplet.pro | 4 |
4 files changed, 28 insertions, 445 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp deleted file mode 100644 index e0c487b..0000000 --- a/noncore/applets/wirelessapplet/networkinfo.cpp +++ b/dev/null | |||
@@ -1,284 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** MNetwork* classes | ||
3 | ** | ||
4 | ** Encapsulate network information | ||
5 | ** | ||
6 | ** Copyright (C) 2002, Michael Lauer | ||
7 | ** mickey@tm.informatik.uni-frankfurt.de | ||
8 | ** http://www.Vanille.de | ||
9 | ** | ||
10 | ** Based on portions of the Wireless Extensions | ||
11 | ** Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com> | ||
12 | ** | ||
13 | ** This file may be distributed and/or modified under the terms of the | ||
14 | ** GNU General Public License version 2 as published by the Free Software | ||
15 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
16 | ** packaging of this file. | ||
17 | ** | ||
18 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
19 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
20 | ** | ||
21 | **********************************************************************/ | ||
22 | |||
23 | #include "networkinfo.h" | ||
24 | |||
25 | #include <arpa/inet.h> | ||
26 | #include <sys/socket.h> | ||
27 | #include <linux/if_ether.h> | ||
28 | #include <netinet/ip.h> | ||
29 | #include <sys/ioctl.h> | ||
30 | #include <linux/wireless.h> | ||
31 | |||
32 | #include <unistd.h> | ||
33 | #include <math.h> | ||
34 | #include <errno.h> | ||
35 | #include <string.h> | ||
36 | |||
37 | #include <stdlib.h> | ||
38 | |||
39 | #include <qstring.h> | ||
40 | #include <qfile.h> | ||
41 | #include <qtextstream.h> | ||
42 | |||
43 | /* estimated wireless signal strength and noise level values | ||
44 | based on experimentation with Orinoco and Prism2 cards. | ||
45 | Seem to be correct, but please inform me, if you got values | ||
46 | outside these boundaries. :Mickey: */ | ||
47 | |||
48 | #define IW_UPPER 220 | ||
49 | #define IW_LOWER 140 | ||
50 | |||
51 | #define PROCNETDEV "/proc/net/dev" | ||
52 | #define PROCNETWIRELESS "/proc/net/wireless" | ||
53 | |||
54 | //#define MDEBUG 0 | ||
55 | #undef MDEBUG | ||
56 | |||
57 | //--------------------------------------------------------------------------- | ||
58 | // class MNetworkInterface | ||
59 | // | ||
60 | |||
61 | MNetworkInterface::MNetworkInterface( const char* name ) | ||
62 | :name( name ) | ||
63 | { | ||
64 | struct ifreq ifr; | ||
65 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; | ||
66 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); | ||
67 | } | ||
68 | |||
69 | MNetworkInterface::~MNetworkInterface() | ||
70 | { | ||
71 | if ( fd != -1 ) | ||
72 | close( fd ); | ||
73 | } | ||
74 | |||
75 | bool MNetworkInterface::updateStatistics() | ||
76 | { | ||
77 | return true; | ||
78 | } | ||
79 | |||
80 | //--------------------------------------------------------------------------- | ||
81 | // class MWirelessNetworkInterface | ||
82 | // | ||
83 | |||
84 | MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n ) | ||
85 | :MNetworkInterface( n ) | ||
86 | { | ||
87 | signal = 0; | ||
88 | noise = 0; | ||
89 | quality = 0; | ||
90 | } | ||
91 | |||
92 | MWirelessNetworkInterface::~MWirelessNetworkInterface() | ||
93 | { | ||
94 | } | ||
95 | |||
96 | int MWirelessNetworkInterface::qualityPercent() | ||
97 | { | ||
98 | return ( quality*100 ) / 92; | ||
99 | } | ||
100 | |||
101 | int MWirelessNetworkInterface::signalPercent() | ||
102 | { | ||
103 | return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; | ||
104 | } | ||
105 | |||
106 | int MWirelessNetworkInterface::noisePercent() | ||
107 | { | ||
108 | return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; | ||
109 | } | ||
110 | |||
111 | bool MWirelessNetworkInterface::updateStatistics() | ||
112 | { | ||
113 | bool base = MNetworkInterface::updateStatistics(); | ||
114 | if ( !base ) | ||
115 | return false; | ||
116 | |||
117 | const char* buffer[200]; | ||
118 | |||
119 | struct iwreq iwr; | ||
120 | memset( &iwr, 0, sizeof( iwr ) ); | ||
121 | iwr.u.essid.pointer = (caddr_t) buffer; | ||
122 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | ||
123 | iwr.u.essid.flags = 0; | ||
124 | |||
125 | // check if it is an IEEE 802.11 standard conform | ||
126 | // wireless device by sending SIOCGIWESSID | ||
127 | // which also gives back the Extended Service Set ID | ||
128 | // (see IEEE 802.11 for more information) | ||
129 | |||
130 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); | ||
131 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); | ||
132 | if ( result == 0 ) | ||
133 | { | ||
134 | hasWirelessExtensions = true; | ||
135 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | ||
136 | essid = iwr.u.essid.pointer; | ||
137 | } | ||
138 | else essid = "*** Unknown ***"; | ||
139 | |||
140 | // Address of associated access-point | ||
141 | |||
142 | result = ioctl( fd, SIOCGIWAP, &iwr ); | ||
143 | if ( result == 0 ) | ||
144 | { | ||
145 | APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | ||
146 | iwr.u.ap_addr.sa_data[0]&0xff, | ||
147 | iwr.u.ap_addr.sa_data[1]&0xff, | ||
148 | iwr.u.ap_addr.sa_data[2]&0xff, | ||
149 | iwr.u.ap_addr.sa_data[3]&0xff, | ||
150 | iwr.u.ap_addr.sa_data[4]&0xff, | ||
151 | iwr.u.ap_addr.sa_data[5]&0xff ); | ||
152 | } else APAddr = "*** Unknown ***"; | ||
153 | |||
154 | iwr.u.data.pointer = (caddr_t) buffer; | ||
155 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | ||
156 | iwr.u.data.flags = 0; | ||
157 | |||
158 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); | ||
159 | if ( result == 0 ) | ||
160 | { | ||
161 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | ||
162 | nick = iwr.u.data.pointer; | ||
163 | } else nick = "*** Unknown ***"; | ||
164 | |||
165 | result = ioctl( fd, SIOCGIWMODE, &iwr ); | ||
166 | if ( result == 0 ) | ||
167 | mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; | ||
168 | else mode = "*** Unknown ***"; | ||
169 | |||
170 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); | ||
171 | if ( result == 0 ) | ||
172 | freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; | ||
173 | else freq = 0; | ||
174 | |||
175 | // gather link quality from /proc/net/wireless | ||
176 | |||
177 | char c; | ||
178 | QString status; | ||
179 | QString name; | ||
180 | QFile wfile( PROCNETWIRELESS ); | ||
181 | bool hasFile = wfile.open( IO_ReadOnly ); | ||
182 | QTextStream wstream( &wfile ); | ||
183 | if ( hasFile ) | ||
184 | { | ||
185 | wstream.readLine(); // skip the first two lines | ||
186 | wstream.readLine(); // because they only contain headers | ||
187 | } | ||
188 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) | ||
189 | { | ||
190 | #ifdef MDEBUG | ||
191 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); | ||
192 | #endif | ||
193 | quality = -1; | ||
194 | signal = IW_LOWER; | ||
195 | noise = IW_LOWER; | ||
196 | return false; | ||
197 | } | ||
198 | |||
199 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | ||
200 | |||
201 | #ifdef MDEBUG | ||
202 | if ( quality > 92 ) | ||
203 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | ||
204 | |||
205 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | ||
206 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | ||
207 | |||
208 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | ||
209 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | ||
210 | #endif | ||
211 | |||
212 | return true; | ||
213 | |||
214 | } | ||
215 | |||
216 | //--------------------------------------------------------------------------- | ||
217 | // class Network | ||
218 | // | ||
219 | |||
220 | MNetwork::MNetwork() | ||
221 | { | ||
222 | procfile = PROCNETDEV; | ||
223 | } | ||
224 | |||
225 | MNetwork::~MNetwork() | ||
226 | { | ||
227 | } | ||
228 | |||
229 | //--------------------------------------------------------------------------- | ||
230 | // class WirelessNetwork | ||
231 | // | ||
232 | |||
233 | MWirelessNetwork::MWirelessNetwork() | ||
234 | { | ||
235 | procfile = PROCNETWIRELESS; | ||
236 | } | ||
237 | |||
238 | MWirelessNetwork::~MWirelessNetwork() | ||
239 | { | ||
240 | } | ||
241 | |||
242 | MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const | ||
243 | { | ||
244 | return new MWirelessNetworkInterface( n ); | ||
245 | } | ||
246 | |||
247 | //--------------------------------------------------------------------------- | ||
248 | // class NetworkInterface | ||
249 | // | ||
250 | |||
251 | MNetworkInterface* MNetwork::getFirstInterface() | ||
252 | { | ||
253 | enumerateInterfaces(); | ||
254 | InterfaceMapIterator it( interfaces ); | ||
255 | return ( it.count() > 0 ) ? it.toFirst() : 0; | ||
256 | } | ||
257 | |||
258 | void MNetwork::enumerateInterfaces() | ||
259 | { | ||
260 | interfaces.clear(); | ||
261 | QString str; | ||
262 | QFile f( procfile ); | ||
263 | bool hasFile = f.open( IO_ReadOnly ); | ||
264 | if ( !hasFile ) | ||
265 | return; | ||
266 | QTextStream s( &f ); | ||
267 | s.readLine(); | ||
268 | s.readLine(); | ||
269 | while ( !s.atEnd() ) | ||
270 | { | ||
271 | s >> str; | ||
272 | str.truncate( str.find( ':' ) ); | ||
273 | #ifdef MDEBUG | ||
274 | qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); | ||
275 | #endif | ||
276 | interfaces.insert( str, createInterface( str ) ); | ||
277 | s.readLine(); | ||
278 | } | ||
279 | } | ||
280 | |||
281 | MNetworkInterface* MNetwork::createInterface( const char* n ) const | ||
282 | { | ||
283 | return new MNetworkInterface( n ); | ||
284 | } | ||
diff --git a/noncore/applets/wirelessapplet/networkinfo.h b/noncore/applets/wirelessapplet/networkinfo.h deleted file mode 100644 index 7e50bc4..0000000 --- a/noncore/applets/wirelessapplet/networkinfo.h +++ b/dev/null | |||
@@ -1,126 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** MNetwork* classes | ||
3 | ** | ||
4 | ** Encapsulates network information | ||
5 | ** | ||
6 | ** Copyright (C) 2002, Michael Lauer | ||
7 | ** mickey@tm.informatik.uni-frankfurt.de | ||
8 | ** http://www.Vanille.de | ||
9 | ** | ||
10 | ** This file may be distributed and/or modified under the terms of the | ||
11 | ** GNU General Public License version 2 as published by the Free Software | ||
12 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
13 | ** packaging of this file. | ||
14 | ** | ||
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | ** | ||
18 | **********************************************************************/ | ||
19 | |||
20 | #ifndef NETWORKINFO_H | ||
21 | #define NETWORKINFO_H | ||
22 | |||
23 | #include <qstring.h> | ||
24 | #include <qdict.h> | ||
25 | |||
26 | //--------------------------------------------------------------------------- | ||
27 | // class MNetworkInterface | ||
28 | // | ||
29 | |||
30 | class MNetworkInterface | ||
31 | { | ||
32 | public: | ||
33 | |||
34 | MNetworkInterface( const char* name = "eth0" ); | ||
35 | virtual ~MNetworkInterface(); | ||
36 | |||
37 | bool isLoopback() { return isLoopbackInterface; }; | ||
38 | const QString& getName() { return name; }; | ||
39 | |||
40 | virtual bool updateStatistics(); | ||
41 | |||
42 | protected: | ||
43 | |||
44 | int fd; | ||
45 | const QString name; | ||
46 | bool isLoopbackInterface; | ||
47 | bool isIrda; | ||
48 | bool isTunnel; | ||
49 | }; | ||
50 | |||
51 | //--------------------------------------------------------------------------- | ||
52 | // class MWirelessNetworkInterface | ||
53 | // | ||
54 | |||
55 | class MWirelessNetworkInterface : public MNetworkInterface | ||
56 | { | ||
57 | public: | ||
58 | MWirelessNetworkInterface( const char* name = "wlan0" ); | ||
59 | virtual ~MWirelessNetworkInterface(); | ||
60 | |||
61 | int noisePercent(); | ||
62 | int qualityPercent(); | ||
63 | int signalPercent(); | ||
64 | |||
65 | QString APAddr; | ||
66 | QString essid; | ||
67 | QString mode; | ||
68 | QString nick; | ||
69 | QString rate; | ||
70 | double freq; | ||
71 | int channel; | ||
72 | |||
73 | virtual bool updateStatistics(); | ||
74 | |||
75 | private: | ||
76 | int quality; | ||
77 | int signal; | ||
78 | int noise; | ||
79 | |||
80 | bool hasWirelessExtensions; | ||
81 | }; | ||
82 | |||
83 | //--------------------------------------------------------------------------- | ||
84 | // class MNetwork | ||
85 | // | ||
86 | |||
87 | class MNetwork | ||
88 | { | ||
89 | public: | ||
90 | MNetwork(); | ||
91 | virtual ~MNetwork(); | ||
92 | |||
93 | typedef QDict<MNetworkInterface> InterfaceMap; | ||
94 | typedef QDictIterator<MNetworkInterface> InterfaceMapIterator; | ||
95 | |||
96 | bool hasInterfaces() const { return interfaces.isEmpty(); }; | ||
97 | int numInterfaces() const { return interfaces.count(); }; | ||
98 | |||
99 | MNetworkInterface* getFirstInterface(); | ||
100 | |||
101 | protected: | ||
102 | QString procfile; | ||
103 | InterfaceMap interfaces; | ||
104 | |||
105 | virtual MNetworkInterface* createInterface( const char* name ) const; | ||
106 | |||
107 | private: | ||
108 | void enumerateInterfaces(); | ||
109 | }; | ||
110 | |||
111 | //--------------------------------------------------------------------------- | ||
112 | // class MWirelessNetwork | ||
113 | // | ||
114 | |||
115 | class MWirelessNetwork : public MNetwork | ||
116 | { | ||
117 | public: | ||
118 | MWirelessNetwork(); | ||
119 | virtual ~MWirelessNetwork(); | ||
120 | |||
121 | protected: | ||
122 | virtual MNetworkInterface* createInterface( const char* name ) | ||
123 | const; | ||
124 | }; | ||
125 | |||
126 | #endif | ||
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp index dc9742a..72ac380 100644 --- a/noncore/applets/wirelessapplet/wireless.cpp +++ b/noncore/applets/wirelessapplet/wireless.cpp | |||
@@ -1,564 +1,557 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer <mickey@vanille.de> | 2 | ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer <mickey@vanille.de> |
3 | ** | 3 | ** |
4 | ** This file may be distributed and/or modified under the terms of the | 4 | ** This file may be distributed and/or modified under the terms of the |
5 | ** GNU General Public License version 2 as published by the Free Software | 5 | ** GNU General Public License version 2 as published by the Free Software |
6 | ** Foundation and appearing in the file LICENSE.GPL included in the | 6 | ** Foundation and appearing in the file LICENSE.GPL included in the |
7 | ** packaging of this file. | 7 | ** packaging of this file. |
8 | ** | 8 | ** |
9 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 9 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
10 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 10 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
11 | ** | 11 | ** |
12 | **********************************************************************/ | 12 | **********************************************************************/ |
13 | 13 | ||
14 | #include "wireless.h" | 14 | #include "wireless.h" |
15 | #include "networkinfo.h" | ||
16 | #include "mgraph.h" | 15 | #include "mgraph.h" |
17 | #include "advancedconfig.h" | 16 | #include "advancedconfig.h" |
18 | #include "connect0.xpm" | 17 | #include "connect0.xpm" |
19 | #include "connect1.xpm" | 18 | #include "connect1.xpm" |
20 | #include "connect2.xpm" | 19 | #include "connect2.xpm" |
21 | #include "connect3.xpm" | 20 | #include "connect3.xpm" |
22 | #include "connect4.xpm" | 21 | #include "connect4.xpm" |
23 | #include "connect5.xpm" | 22 | #include "connect5.xpm" |
24 | #include "nowireless.xpm" | 23 | #include "nowireless.xpm" |
25 | 24 | ||
26 | /* OPIE */ | 25 | /* OPIE */ |
27 | #include <opie2/onetwork.h> | 26 | #include <opie2/onetwork.h> |
28 | #include <opie2/otaskbarapplet.h> | 27 | #include <opie2/otaskbarapplet.h> |
29 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
30 | #include <qpe/config.h> | 29 | #include <qpe/config.h> |
31 | 30 | ||
32 | /* QT */ | 31 | /* QT */ |
33 | #include <qpoint.h> | 32 | #include <qpoint.h> |
34 | #include <qradiobutton.h> | 33 | #include <qradiobutton.h> |
35 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
36 | #include <qpainter.h> | 35 | #include <qpainter.h> |
37 | #include <qlabel.h> | 36 | #include <qlabel.h> |
38 | #include <qslider.h> | 37 | #include <qslider.h> |
39 | #include <qbuttongroup.h> | 38 | #include <qbuttongroup.h> |
40 | #include <qlayout.h> | 39 | #include <qlayout.h> |
41 | #include <qframe.h> | 40 | #include <qframe.h> |
42 | #include <qpixmap.h> | 41 | #include <qpixmap.h> |
43 | #include <qstring.h> | 42 | #include <qstring.h> |
44 | #include <qfile.h> | 43 | #include <qfile.h> |
45 | #include <qtextstream.h> | 44 | #include <qtextstream.h> |
46 | 45 | ||
47 | /* STD */ | 46 | /* STD */ |
48 | #include <sys/types.h> | 47 | #include <sys/types.h> |
49 | #include <signal.h> | 48 | #include <signal.h> |
50 | 49 | ||
51 | #define STYLE_BARS 0 | 50 | #define STYLE_BARS 0 |
52 | #define STYLE_ANTENNA 1 | 51 | #define STYLE_ANTENNA 1 |
53 | 52 | ||
54 | //#define MDEBUG | 53 | #define MDEBUG |
55 | #undef MDEBUG | 54 | //#undef MDEBUG |
56 | 55 | ||
57 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) | 56 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) |
58 | : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) | 57 | : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) |
59 | { | 58 | { |
60 | 59 | ||
61 | readConfig(); | 60 | readConfig(); |
62 | writeConfigEntry( "UpdateFrequency", updateFrequency ); | 61 | writeConfigEntry( "UpdateFrequency", updateFrequency ); |
63 | writeConfigEntry( "DisplayStyle", displayStyle ); | 62 | writeConfigEntry( "DisplayStyle", displayStyle ); |
64 | 63 | ||
65 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 64 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
66 | QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); | 65 | QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); |
67 | 66 | ||
68 | /* status label */ | 67 | /* status label */ |
69 | 68 | ||
70 | statusLabel = new QLabel( this, "statuslabel" ); | 69 | statusLabel = new QLabel( this, "statuslabel" ); |
71 | QString text( "Wireless Status:<br>" | 70 | QString text( "Wireless Status:<br>" |
72 | "*** Unknown ***<br>" | 71 | "*** Unknown ***<br>" |
73 | "Card not inserted ?<br>" | 72 | "Card not inserted ?<br>" |
74 | "Or Sharp ROM ?<br>" | 73 | "Or Sharp ROM ?<br>" |
75 | "CELL: 00:00:00:00:00:00" ); | 74 | "CELL: 00:00:00:00:00:00" ); |
76 | /* QString text( "Station: Unknown<br>" | 75 | /* QString text( "Station: Unknown<br>" |
77 | "ESSID: Unknown<br>" | 76 | "ESSID: Unknown<br>" |
78 | "MODE: Unknown<br>" | 77 | "MODE: Unknown<br>" |
79 | "FREQ: Unknown<br>" | 78 | "FREQ: Unknown<br>" |
80 | "CELL: AA:BB:CC:DD:EE:FF" ); */ | 79 | "CELL: AA:BB:CC:DD:EE:FF" ); */ |
81 | statusLabel->setText( text ); | 80 | statusLabel->setText( text ); |
82 | statusLabel->setFixedSize( statusLabel->sizeHint() ); | 81 | statusLabel->setFixedSize( statusLabel->sizeHint() ); |
83 | grid->addWidget( statusLabel, 0, 0 ); | 82 | grid->addWidget( statusLabel, 0, 0 ); |
84 | 83 | ||
85 | /* visualization group box */ | 84 | /* visualization group box */ |
86 | 85 | ||
87 | QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); | 86 | QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); |
88 | QRadioButton* r1 = new QRadioButton( "Color Bars", group ); | 87 | QRadioButton* r1 = new QRadioButton( "Color Bars", group ); |
89 | QRadioButton* r2 = new QRadioButton( "Antenna", group ); | 88 | QRadioButton* r2 = new QRadioButton( "Antenna", group ); |
90 | r1->setFocusPolicy( QWidget::NoFocus ); | 89 | r1->setFocusPolicy( QWidget::NoFocus ); |
91 | r2->setFocusPolicy( QWidget::NoFocus ); | 90 | r2->setFocusPolicy( QWidget::NoFocus ); |
92 | group->setFocusPolicy( QWidget::NoFocus ); | 91 | group->setFocusPolicy( QWidget::NoFocus ); |
93 | group->setButton( displayStyle ); | 92 | group->setButton( displayStyle ); |
94 | grid->addWidget( group, 0, 1 ); | 93 | grid->addWidget( group, 0, 1 ); |
95 | 94 | ||
96 | /* quality graph */ | 95 | /* quality graph */ |
97 | 96 | ||
98 | mgraph = new MGraph( this ); | 97 | mgraph = new MGraph( this ); |
99 | mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 98 | mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
100 | mgraph->setMin( 0 ); | 99 | mgraph->setMin( 0 ); |
101 | mgraph->setMax( 92 ); | 100 | mgraph->setMax( 92 ); |
102 | grid->addWidget( mgraph, 1, 0 ); | 101 | grid->addWidget( mgraph, 1, 0 ); |
103 | mgraph->setFocusPolicy( QWidget::NoFocus ); | 102 | mgraph->setFocusPolicy( QWidget::NoFocus ); |
104 | 103 | ||
105 | /* advanced configuration Button */ | 104 | /* advanced configuration Button */ |
106 | 105 | ||
107 | QPushButton* advanced = new QPushButton( "Advanced...", this ); | 106 | QPushButton* advanced = new QPushButton( "Advanced...", this ); |
108 | advanced->setFocusPolicy( QWidget::NoFocus ); | 107 | advanced->setFocusPolicy( QWidget::NoFocus ); |
109 | grid->addWidget( advanced, 2, 0, Qt::AlignCenter ); | 108 | grid->addWidget( advanced, 2, 0, Qt::AlignCenter ); |
110 | connect( advanced, SIGNAL( clicked() ), | 109 | connect( advanced, SIGNAL( clicked() ), |
111 | this, SLOT( advancedConfigClicked() ) ); | 110 | this, SLOT( advancedConfigClicked() ) ); |
112 | 111 | ||
113 | /* update Frequency Label */ | 112 | /* update Frequency Label */ |
114 | 113 | ||
115 | updateLabel = new QLabel( this ); | 114 | updateLabel = new QLabel( this ); |
116 | text.sprintf( "Update every %d s", updateFrequency ); | 115 | text.sprintf( "Update every %d s", updateFrequency ); |
117 | updateLabel->setText( text ); | 116 | updateLabel->setText( text ); |
118 | grid->addWidget( updateLabel, 2, 1 ); | 117 | grid->addWidget( updateLabel, 2, 1 ); |
119 | 118 | ||
120 | /* update Frequency Slider */ | 119 | /* update Frequency Slider */ |
121 | 120 | ||
122 | QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); | 121 | QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); |
123 | updateSlider->setRange( 0, 9 ); | 122 | updateSlider->setRange( 0, 9 ); |
124 | updateSlider->setValue( updateFrequency ); | 123 | updateSlider->setValue( updateFrequency ); |
125 | updateSlider->setTickmarks( QSlider::Both ); | 124 | updateSlider->setTickmarks( QSlider::Both ); |
126 | updateSlider->setTickInterval( 1 ); | 125 | updateSlider->setTickInterval( 1 ); |
127 | updateSlider->setSteps( 1, 1 ); | 126 | updateSlider->setSteps( 1, 1 ); |
128 | updateSlider->setFocusPolicy( QWidget::NoFocus ); | 127 | updateSlider->setFocusPolicy( QWidget::NoFocus ); |
129 | grid->addWidget( updateSlider, 1, 1 ); | 128 | grid->addWidget( updateSlider, 1, 1 ); |
130 | connect( updateSlider, SIGNAL( valueChanged( int ) ), | 129 | connect( updateSlider, SIGNAL( valueChanged( int ) ), |
131 | this, SLOT( updateDelayChange( int ) ) ); | 130 | this, SLOT( updateDelayChange( int ) ) ); |
132 | 131 | ||
133 | setFixedSize( sizeHint() ); | 132 | setFixedSize( sizeHint() ); |
134 | setFocusPolicy( QWidget::NoFocus ); | 133 | setFocusPolicy( QWidget::NoFocus ); |
135 | 134 | ||
136 | applet->displayStyleChange( displayStyle ); | 135 | applet->displayStyleChange( displayStyle ); |
137 | applet->updateDelayChange( updateFrequency ); | 136 | applet->updateDelayChange( updateFrequency ); |
138 | 137 | ||
139 | connect( group, SIGNAL( clicked( int ) ), | 138 | connect( group, SIGNAL( clicked( int ) ), |
140 | this, SLOT( displayStyleChange( int ) ) ); | 139 | this, SLOT( displayStyleChange( int ) ) ); |
141 | 140 | ||
142 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); | 141 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); |
143 | } | 142 | } |
144 | 143 | ||
145 | void WirelessControl::advancedConfigClicked() | 144 | void WirelessControl::advancedConfigClicked() |
146 | { | 145 | { |
147 | AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE ); | 146 | AdvancedConfig * a = new AdvancedConfig( this, "dialog", TRUE ); |
148 | int result = a->exec(); | 147 | int result = a->exec(); |
149 | a->hide(); | 148 | a->hide(); |
150 | delete a; | 149 | delete a; |
151 | if ( result == QDialog::Accepted ) | 150 | if ( result == QDialog::Accepted ) |
152 | { | 151 | { |
153 | readConfig(); | 152 | readConfig(); |
154 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); | 153 | applet->updateDHCPConfig( rocESSID, rocFREQ, rocAP, rocMODE ); |
155 | } | 154 | } |
156 | } | 155 | } |
157 | 156 | ||
158 | void WirelessControl::updateDelayChange( int delay ) | 157 | void WirelessControl::updateDelayChange( int delay ) |
159 | { | 158 | { |
160 | QString text; | 159 | QString text; |
161 | text.sprintf( "Update every %d s", delay ); | 160 | text.sprintf( "Update every %d s", delay ); |
162 | updateLabel->setText( text ); | 161 | updateLabel->setText( text ); |
163 | applet->updateDelayChange( delay ); | 162 | applet->updateDelayChange( delay ); |
164 | writeConfigEntry( "UpdateFrequency", delay ); | 163 | writeConfigEntry( "UpdateFrequency", delay ); |
165 | } | 164 | } |
166 | 165 | ||
167 | void WirelessControl::displayStyleChange( int style ) | 166 | void WirelessControl::displayStyleChange( int style ) |
168 | { | 167 | { |
169 | applet->displayStyleChange( style ); | 168 | applet->displayStyleChange( style ); |
170 | writeConfigEntry( "DisplayStyle", style ); | 169 | writeConfigEntry( "DisplayStyle", style ); |
171 | } | 170 | } |
172 | 171 | ||
173 | void WirelessControl::show ( bool ) | 172 | void WirelessControl::show ( bool ) |
174 | { | 173 | { |
175 | QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); | 174 | QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); |
176 | 175 | ||
177 | int w = sizeHint().width(); | 176 | int w = sizeHint().width(); |
178 | int x = curPos.x() - ( w / 2 ); | 177 | int x = curPos.x() - ( w / 2 ); |
179 | 178 | ||
180 | if ( ( x + w ) > QPEApplication::desktop() ->width() ) | 179 | if ( ( x + w ) > QPEApplication::desktop() ->width() ) |
181 | x = QPEApplication::desktop ( ) -> width ( ) - w; | 180 | x = QPEApplication::desktop ( ) -> width ( ) - w; |
182 | 181 | ||
183 | move( x, curPos.y () - sizeHint().height () ); | 182 | move( x, curPos.y () - sizeHint().height () ); |
184 | QFrame::show(); | 183 | QFrame::show(); |
185 | } | 184 | } |
186 | 185 | ||
187 | void WirelessControl::readConfig() | 186 | void WirelessControl::readConfig() |
188 | { | 187 | { |
189 | Config cfg( "qpe" ); | 188 | Config cfg( "qpe" ); |
190 | cfg.setGroup( "Wireless" ); | 189 | cfg.setGroup( "Wireless" ); |
191 | 190 | ||
192 | updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); | 191 | updateFrequency = cfg.readNumEntry( "UpdateFrequency", 2 ); |
193 | displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA ); | 192 | displayStyle = cfg.readNumEntry( "DisplayStyle", STYLE_ANTENNA ); |
194 | rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); | 193 | rocESSID = cfg.readBoolEntry( "renew_dhcp_on_essid_change", false ); |
195 | rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); | 194 | rocFREQ = cfg.readBoolEntry( "renew_dhcp_on_freq_change", false ); |
196 | rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); | 195 | rocAP = cfg.readBoolEntry( "renew_dhcp_on_ap_change", false ); |
197 | rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false ); | 196 | rocMODE = cfg.readBoolEntry( "renew_dhcp_on_mode_change", false ); |
198 | } | 197 | } |
199 | 198 | ||
200 | void WirelessControl::writeConfigEntry( const char *entry, int val ) | 199 | void WirelessControl::writeConfigEntry( const char *entry, int val ) |
201 | { | 200 | { |
202 | Config cfg( "qpe" ); | 201 | Config cfg( "qpe" ); |
203 | cfg.setGroup( "Wireless" ); | 202 | cfg.setGroup( "Wireless" ); |
204 | cfg.writeEntry( entry, val ); | 203 | cfg.writeEntry( entry, val ); |
205 | } | 204 | } |
206 | 205 | ||
207 | //=========================================================================== | 206 | //=========================================================================== |
208 | 207 | ||
209 | WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) | 208 | WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) |
210 | : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), | 209 | : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), |
211 | timer( 0 ), interface( 0 ), oldiface( 0 ), | 210 | timer( 0 ), interface( 0 ), oldiface( 0 ), |
212 | rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) | 211 | rocESSID( false ), rocFREQ( false ), rocAP( false ), rocMODE( false ) |
213 | { | 212 | { |
214 | setFixedHeight( 18 ); | 213 | setFixedHeight( 18 ); |
215 | setFixedWidth( 14 ); | 214 | setFixedWidth( 14 ); |
216 | status = new WirelessControl( this, this, "wireless status" ); | 215 | status = new WirelessControl( this, this, "wireless status" ); |
217 | } | 216 | } |
218 | 217 | ||
219 | void WirelessApplet::checkInterface() | 218 | void WirelessApplet::checkInterface() |
220 | { | 219 | { |
221 | interface = 0L; | 220 | interface = 0L; |
222 | ONetwork* net = ONetwork::instance(); | 221 | ONetwork* net = ONetwork::instance(); |
223 | ONetwork::InterfaceIterator it = net->iterator(); | 222 | ONetwork::InterfaceIterator it = net->iterator(); |
224 | 223 | ||
225 | while ( it.current() && !it.current()->isWireless() ) ++it; | 224 | while ( it.current() && !it.current()->isWireless() ) ++it; |
226 | 225 | ||
227 | if ( it.current() && it.current()->isWireless() ) | 226 | if ( it.current() && it.current()->isWireless() ) |
228 | interface = static_cast<OWirelessNetworkInterface*>( it.current() ); | 227 | interface = static_cast<OWirelessNetworkInterface*>( it.current() ); |
229 | 228 | ||
230 | if ( interface ) | 229 | if ( interface ) |
231 | { | 230 | { |
232 | #ifdef MDEBUG | 231 | #ifdef MDEBUG |
233 | qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() ); | 232 | qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() ); |
234 | #endif | 233 | #endif |
235 | 234 | ||
236 | } | 235 | } |
237 | else | 236 | else |
238 | { | 237 | { |
239 | #ifdef MDEBUG | 238 | #ifdef MDEBUG |
240 | qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); | 239 | qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); |
241 | #endif | 240 | #endif |
242 | hide(); | 241 | hide(); |
243 | } | 242 | } |
244 | } | 243 | } |
245 | 244 | ||
246 | void WirelessApplet::renewDHCP() | 245 | void WirelessApplet::renewDHCP() |
247 | { | 246 | { |
248 | #ifdef MDEBUG | 247 | #ifdef MDEBUG |
249 | qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." ); | 248 | qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." ); |
250 | #endif | 249 | #endif |
251 | 250 | ||
252 | QString pidfile; | 251 | QString pidfile; |
253 | if ( !interface ) | 252 | if ( !interface ) |
254 | return ; | 253 | return ; |
255 | QString ifacename( interface->name() ); | 254 | QString ifacename( interface->name() ); |
256 | 255 | ||
257 | // At first we are trying dhcpcd | 256 | // At first we are trying dhcpcd |
258 | 257 | ||
259 | pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename ); | 258 | pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename ); |
260 | #ifdef MDEBUG | 259 | #ifdef MDEBUG |
261 | qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile ); | 260 | qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile ); |
262 | #endif | 261 | #endif |
263 | int pid; | 262 | int pid; |
264 | QFile pfile( pidfile ); | 263 | QFile pfile( pidfile ); |
265 | bool hasFile = pfile.open( IO_ReadOnly ); | 264 | bool hasFile = pfile.open( IO_ReadOnly ); |
266 | QTextStream s( &pfile ); | 265 | QTextStream s( &pfile ); |
267 | if ( hasFile ) | 266 | if ( hasFile ) |
268 | { | 267 | { |
269 | s >> pid; | 268 | s >> pid; |
270 | #ifdef MDEBUG | 269 | #ifdef MDEBUG |
271 | qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid ); | 270 | qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid ); |
272 | #endif | 271 | #endif |
273 | kill( pid, SIGALRM ); | 272 | kill( pid, SIGALRM ); |
274 | return ; | 273 | return ; |
275 | } | 274 | } |
276 | 275 | ||
277 | // No dhcpcd, so we are trying udhcpc | 276 | // No dhcpcd, so we are trying udhcpc |
278 | #ifdef MDEBUG | 277 | #ifdef MDEBUG |
279 | qDebug( "WIFIAPPLET: dhcpcd not available." ); | 278 | qDebug( "WIFIAPPLET: dhcpcd not available." ); |
280 | #endif | 279 | #endif |
281 | pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename ); | 280 | pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename ); |
282 | #ifdef MDEBUG | 281 | #ifdef MDEBUG |
283 | qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile ); | 282 | qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile ); |
284 | #endif | 283 | #endif |
285 | QFile pfile2( pidfile ); | 284 | QFile pfile2( pidfile ); |
286 | hasFile = pfile2.open( IO_ReadOnly ); | 285 | hasFile = pfile2.open( IO_ReadOnly ); |
287 | QTextStream s2( &pfile2 ); | 286 | QTextStream s2( &pfile2 ); |
288 | if ( hasFile ) | 287 | if ( hasFile ) |
289 | { | 288 | { |
290 | s2 >> pid; | 289 | s2 >> pid; |
291 | #ifdef MDEBUG | 290 | #ifdef MDEBUG |
292 | qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid ); | 291 | qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid ); |
293 | #endif | 292 | #endif |
294 | kill( pid, SIGUSR1 ); | 293 | kill( pid, SIGUSR1 ); |
295 | return ; | 294 | return ; |
296 | } | 295 | } |
297 | } | 296 | } |
298 | 297 | ||
299 | void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) | 298 | void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE ) |
300 | { | 299 | { |
301 | rocESSID = ESSID; | 300 | rocESSID = ESSID; |
302 | rocFREQ = FREQ; | 301 | rocFREQ = FREQ; |
303 | rocAP = AP; | 302 | rocAP = AP; |
304 | rocMODE = MODE; | 303 | rocMODE = MODE; |
305 | } | 304 | } |
306 | 305 | ||
307 | void WirelessApplet::updateDelayChange( int delay ) | 306 | void WirelessApplet::updateDelayChange( int delay ) |
308 | { | 307 | { |
309 | if ( timer ) | 308 | if ( timer ) |
310 | killTimer( timer ); | 309 | killTimer( timer ); |
311 | delay *= 1000; | 310 | delay *= 1000; |
312 | if ( delay == 0 ) | 311 | if ( delay == 0 ) |
313 | delay = 50; | 312 | delay = 50; |
314 | timer = startTimer( delay ); | 313 | timer = startTimer( delay ); |
315 | } | 314 | } |
316 | 315 | ||
317 | void WirelessApplet::displayStyleChange( int style ) | 316 | void WirelessApplet::displayStyleChange( int style ) |
318 | { | 317 | { |
319 | visualStyle = style; | 318 | visualStyle = style; |
320 | repaint(); | 319 | repaint(); |
321 | } | 320 | } |
322 | 321 | ||
323 | WirelessApplet::~WirelessApplet() | 322 | WirelessApplet::~WirelessApplet() |
324 | {} | 323 | {} |
325 | 324 | ||
326 | void WirelessApplet::timerEvent( QTimerEvent* ) | 325 | void WirelessApplet::timerEvent( QTimerEvent* ) |
327 | { | 326 | { |
328 | /* | 327 | qDebug( "WirelessApplet::timerEvent" ); |
329 | |||
330 | OWirelessNetworkInterface* iface = interface; | 328 | OWirelessNetworkInterface* iface = interface; |
331 | 329 | ||
332 | if ( iface ) | 330 | if ( iface ) |
333 | { | 331 | { |
334 | bool statResult = iface->updateStatistics(); | 332 | if ( mustRepaint() ) |
335 | if ( !statResult ) | ||
336 | { | 333 | { |
337 | interface = 0; | 334 | qDebug( "WIFIAPPLET: A value has changed -> repainting." ); |
338 | mustRepaint(); | 335 | repaint(); |
339 | return ; | ||
340 | } | 336 | } |
341 | else | ||
342 | if ( mustRepaint() ) | ||
343 | { | ||
344 | //qDebug( "WIFIAPPLET: A value has changed -> repainting." ); | ||
345 | repaint(); | ||
346 | } | ||
347 | 337 | ||
348 | if ( status->isVisible() ) | 338 | if ( status->isVisible() ) |
339 | { | ||
349 | updatePopupWindow(); | 340 | updatePopupWindow(); |
341 | } | ||
342 | } | ||
343 | else | ||
344 | { | ||
345 | checkInterface(); | ||
350 | } | 346 | } |
351 | else checkInterface(); | ||
352 | |||
353 | */ | ||
354 | } | 347 | } |
355 | 348 | ||
356 | void WirelessApplet::mousePressEvent( QMouseEvent * ) | 349 | void WirelessApplet::mousePressEvent( QMouseEvent * ) |
357 | { | 350 | { |
358 | if ( status->isVisible() ) | 351 | if ( status->isVisible() ) |
359 | status->hide(); | 352 | status->hide(); |
360 | else | 353 | else |
361 | status->show( true ); | 354 | status->show( true ); |
362 | } | 355 | } |
363 | 356 | ||
364 | bool WirelessApplet::mustRepaint() | 357 | bool WirelessApplet::mustRepaint() |
365 | { | 358 | { |
366 | OWirelessNetworkInterface* iface = interface; | 359 | OWirelessNetworkInterface* iface = interface; |
367 | 360 | ||
368 | // check if there are enough changes to justify a (flickering) repaint | 361 | // check if there are enough changes to justify a (flickering) repaint |
369 | 362 | ||
370 | // has the interface changed? | 363 | // has the interface changed? |
371 | 364 | ||
372 | if ( iface != oldiface ) | 365 | if ( iface != oldiface ) |
373 | { | 366 | { |
374 | oldiface = iface; | 367 | oldiface = iface; |
375 | if ( iface ) | 368 | if ( iface ) |
376 | { | 369 | { |
377 | #ifdef MDEBUG | 370 | #ifdef MDEBUG |
378 | qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" ); | 371 | qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" ); |
379 | #endif | 372 | #endif |
380 | show(); | 373 | show(); |
381 | } | 374 | } |
382 | else | 375 | else |
383 | { | 376 | { |
384 | #ifdef MDEBUG | 377 | #ifdef MDEBUG |
385 | qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" ); | 378 | qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" ); |
386 | #endif | 379 | #endif |
387 | hide(); | 380 | hide(); |
388 | return true; | 381 | return true; |
389 | } | 382 | } |
390 | } | 383 | } |
391 | 384 | ||
392 | const char** pixmap = getQualityPixmap(); | 385 | const char** pixmap = getQualityPixmap(); |
393 | 386 | ||
394 | if ( pixmap && ( pixmap != oldpixmap ) ) | 387 | if ( pixmap && ( pixmap != oldpixmap ) ) |
395 | { | 388 | { |
396 | oldpixmap = pixmap; | 389 | oldpixmap = pixmap; |
397 | return true; | 390 | return true; |
398 | } | 391 | } |
399 | 392 | ||
400 | int noiseH = 50; // iface->noisePercent() * ( height() - 3 ) / 100; | 393 | int noiseH = 50; // iface->noisePercent() * ( height() - 3 ) / 100; |
401 | int signalH = iface->signalStrength() * ( height() - 3 ) / 100; | 394 | int signalH = iface->signalStrength() * ( height() - 3 ) / 100; |
402 | int qualityH = 50; // iface->qualityPercent() * ( height() - 3 ) / 100; | 395 | int qualityH = 50; // iface->qualityPercent() * ( height() - 3 ) / 100; |
403 | 396 | ||
404 | if ( ( noiseH != oldnoiseH ) | 397 | if ( ( noiseH != oldnoiseH ) |
405 | || ( signalH != oldsignalH ) | 398 | || ( signalH != oldsignalH ) |
406 | || ( qualityH != oldqualityH ) ) | 399 | || ( qualityH != oldqualityH ) ) |
407 | { | 400 | { |
408 | oldnoiseH = noiseH; | 401 | oldnoiseH = noiseH; |
409 | oldsignalH = signalH; | 402 | oldsignalH = signalH; |
410 | oldqualityH = qualityH; | 403 | oldqualityH = qualityH; |
411 | return true; | 404 | return true; |
412 | } | 405 | } |
413 | 406 | ||
414 | if ( rocESSID && ( oldESSID != iface->SSID() ) ) | 407 | if ( rocESSID && ( oldESSID != iface->SSID() ) ) |
415 | { | 408 | { |
416 | #ifdef MDEBUG | 409 | #ifdef MDEBUG |
417 | qDebug( "WIFIAPPLET: ESSID has changed." ); | 410 | qDebug( "WIFIAPPLET: ESSID has changed." ); |
418 | #endif | 411 | #endif |
419 | renewDHCP(); | 412 | renewDHCP(); |
420 | } | 413 | } |
421 | else if ( rocFREQ && ( oldFREQ != iface->frequency() ) ) | 414 | else if ( rocFREQ && ( oldFREQ != iface->frequency() ) ) |
422 | { | 415 | { |
423 | #ifdef MDEBUG | 416 | #ifdef MDEBUG |
424 | qDebug( "WIFIAPPLET: FREQ has changed." ); | 417 | qDebug( "WIFIAPPLET: FREQ has changed." ); |
425 | #endif | 418 | #endif |
426 | renewDHCP(); | 419 | renewDHCP(); |
427 | } | 420 | } |
428 | else if ( rocAP && ( oldAP != iface->associatedAP().toString() ) ) | 421 | else if ( rocAP && ( oldAP != iface->associatedAP().toString() ) ) |
429 | { | 422 | { |
430 | #ifdef MDEBUG | 423 | #ifdef MDEBUG |
431 | qDebug( "WIFIAPPLET: AP has changed." ); | 424 | qDebug( "WIFIAPPLET: AP has changed." ); |
432 | #endif | 425 | #endif |
433 | renewDHCP(); | 426 | renewDHCP(); |
434 | } | 427 | } |
435 | else if ( rocMODE && ( oldMODE != iface->mode() ) ) | 428 | else if ( rocMODE && ( oldMODE != iface->mode() ) ) |
436 | { | 429 | { |
437 | #ifdef MDEBUG | 430 | #ifdef MDEBUG |
438 | qDebug( "WIFIAPPLET: MODE has changed." ); | 431 | qDebug( "WIFIAPPLET: MODE has changed." ); |
439 | #endif | 432 | #endif |
440 | renewDHCP(); | 433 | renewDHCP(); |
441 | } | 434 | } |
442 | 435 | ||
443 | oldESSID = iface->SSID(); | 436 | oldESSID = iface->SSID(); |
444 | oldMODE = iface->mode(); | 437 | oldMODE = iface->mode(); |
445 | oldFREQ = iface->frequency(); | 438 | oldFREQ = iface->frequency(); |
446 | oldAP = iface->associatedAP().toString(); | 439 | oldAP = iface->associatedAP().toString(); |
447 | 440 | ||
448 | return false; | 441 | return false; |
449 | } | 442 | } |
450 | 443 | ||
451 | void WirelessApplet::updatePopupWindow() | 444 | void WirelessApplet::updatePopupWindow() |
452 | { | 445 | { |
453 | MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; | 446 | OWirelessNetworkInterface* iface = interface; |
454 | int qualityH = iface->qualityPercent(); | 447 | int qualityH = iface->signalStrength(); |
455 | 448 | ||
456 | if ( status->mgraph ) | 449 | if ( status->mgraph ) |
457 | status->mgraph->addValue( qualityH, false ); | 450 | status->mgraph->addValue( qualityH, false ); |
458 | 451 | ||
459 | QString freqString; | 452 | QString freqString; |
460 | QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; | 453 | QString cell = ( iface->mode() == "Managed" ) ? "AP: " : "Cell: "; |
461 | freqString.sprintf( "%.3f GHz", iface->freq ); | 454 | freqString.sprintf( "%.3f GHz", iface->frequency() ); |
462 | status->statusLabel->setText( "Station: " + iface->nick + "<br>" + | 455 | status->statusLabel->setText( "Station: " + iface->nickName() + "<br>" + |
463 | "ESSID: " + iface->essid + "<br>" + | 456 | "ESSID: " + iface->SSID() + "<br>" + |
464 | "MODE: " + iface->mode + "<br>" + | 457 | "MODE: " + iface->mode() + "<br>" + |
465 | "FREQ: " + freqString + "<br>" + | 458 | "FREQ: " + freqString + "<br>" + |
466 | cell + " " + iface->APAddr ); | 459 | cell + " " + iface->associatedAP().toString() ); |
467 | } | 460 | } |
468 | 461 | ||
469 | const char** WirelessApplet::getQualityPixmap() | 462 | const char** WirelessApplet::getQualityPixmap() |
470 | { | 463 | { |
471 | MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; | 464 | OWirelessNetworkInterface* iface = interface; |
472 | 465 | ||
473 | if ( !iface ) return ( const char** ) nowireless_xpm; | 466 | if ( !iface ) return ( const char** ) nowireless_xpm; |
474 | int qualityH = iface->qualityPercent(); | 467 | int qualityH = iface->signalStrength(); |
475 | if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; | 468 | if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; |
476 | 469 | ||
477 | if ( visualStyle == STYLE_ANTENNA ) | 470 | if ( visualStyle == STYLE_ANTENNA ) |
478 | { | 471 | { |
479 | if ( qualityH < 1 ) return ( const char** ) connect0_xpm; | 472 | if ( qualityH < 1 ) return ( const char** ) connect0_xpm; |
480 | if ( qualityH < 17 ) return ( const char** ) connect1_xpm; | 473 | if ( qualityH < 17 ) return ( const char** ) connect1_xpm; |
481 | if ( qualityH < 34 ) return ( const char** ) connect2_xpm; | 474 | if ( qualityH < 34 ) return ( const char** ) connect2_xpm; |
482 | if ( qualityH < 50 ) return ( const char** ) connect3_xpm; | 475 | if ( qualityH < 50 ) return ( const char** ) connect3_xpm; |
483 | if ( qualityH < 65 ) return ( const char** ) connect4_xpm; | 476 | if ( qualityH < 65 ) return ( const char** ) connect4_xpm; |
484 | return ( const char** ) connect5_xpm; | 477 | return ( const char** ) connect5_xpm; |
485 | } | 478 | } |
486 | 479 | ||
487 | return 0; // please draw your bars | 480 | return 0; // please draw your bars |
488 | } | 481 | } |
489 | 482 | ||
490 | void WirelessApplet::paintEvent( QPaintEvent* ) | 483 | void WirelessApplet::paintEvent( QPaintEvent* ) |
491 | { | 484 | { |
492 | MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; | 485 | OWirelessNetworkInterface* iface = interface; |
493 | 486 | ||
494 | QPainter p( this ); | 487 | QPainter p( this ); |
495 | QColor color; | 488 | QColor color; |
496 | 489 | ||
497 | const char** pixmap = getQualityPixmap(); | 490 | const char** pixmap = getQualityPixmap(); |
498 | 491 | ||
499 | if ( pixmap ) | 492 | if ( pixmap ) |
500 | p.drawPixmap( 0, 1, pixmap ); | 493 | p.drawPixmap( 0, 1, pixmap ); |
501 | else | 494 | else |
502 | { | 495 | { |
503 | 496 | ||
504 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; | 497 | int noiseH = 30; // iface->noisePercent() * ( height() - 3 ) / 100; |
505 | int signalH = iface->signalPercent() * ( height() - 3 ) / 100; | 498 | int signalH = 50; // iface->signalPercent() * ( height() - 3 ) / 100; |
506 | int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; | 499 | int qualityH = iface->signalStrength(); // iface->qualityPercent() * ( height() - 3 ) / 100; |
507 | 500 | ||
508 | double intensity; | 501 | double intensity; |
509 | int pixelHeight; | 502 | int pixelHeight; |
510 | int pixelWidth = 2; | 503 | int pixelWidth = 2; |
511 | int Hue; | 504 | int Hue; |
512 | int barSpace = 3; | 505 | int barSpace = 3; |
513 | int leftoffset = 0; | 506 | int leftoffset = 0; |
514 | int bottomoffset = 2; | 507 | int bottomoffset = 2; |
515 | 508 | ||
516 | // draw noise indicator | 509 | // draw noise indicator |
517 | pixelHeight = noiseH; | 510 | pixelHeight = noiseH; |
518 | Hue = 50; | 511 | Hue = 50; |
519 | for ( int i = 0; i < pixelHeight; ++i ) | 512 | for ( int i = 0; i < pixelHeight; ++i ) |
520 | { | 513 | { |
521 | intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; | 514 | intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; |
522 | color.setHsv( Hue, 255, intensity ); | 515 | color.setHsv( Hue, 255, intensity ); |
523 | p.setPen ( color ); | 516 | p.setPen ( color ); |
524 | p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); | 517 | p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); |
525 | } | 518 | } |
526 | 519 | ||
527 | // draw signal indicator | 520 | // draw signal indicator |
528 | pixelHeight = signalH; | 521 | pixelHeight = signalH; |
529 | Hue = 100; | 522 | Hue = 100; |
530 | leftoffset += pixelWidth + barSpace; | 523 | leftoffset += pixelWidth + barSpace; |
531 | for ( int i = 0; i < pixelHeight; ++i ) | 524 | for ( int i = 0; i < pixelHeight; ++i ) |
532 | { | 525 | { |
533 | intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; | 526 | intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; |
534 | color.setHsv( Hue, 255, intensity ); | 527 | color.setHsv( Hue, 255, intensity ); |
535 | p.setPen ( color ); | 528 | p.setPen ( color ); |
536 | p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); | 529 | p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); |
537 | } | 530 | } |
538 | 531 | ||
539 | // draw quality indicator | 532 | // draw quality indicator |
540 | pixelHeight = qualityH; | 533 | pixelHeight = qualityH; |
541 | Hue = 250; | 534 | Hue = 250; |
542 | leftoffset += pixelWidth + barSpace; | 535 | leftoffset += pixelWidth + barSpace; |
543 | for ( int i = 0; i < pixelHeight; ++i ) | 536 | for ( int i = 0; i < pixelHeight; ++i ) |
544 | { | 537 | { |
545 | intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; | 538 | intensity = 50 + ( ( double ) i / ( double ) pixelHeight ) * 205; |
546 | color.setHsv( Hue, 255, intensity ); | 539 | color.setHsv( Hue, 255, intensity ); |
547 | p.setPen ( color ); | 540 | p.setPen ( color ); |
548 | p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); | 541 | p.drawLine( leftoffset, height() - bottomoffset - i, pixelWidth + leftoffset, height() - bottomoffset - i ); |
549 | } | 542 | } |
550 | } | 543 | } |
551 | } | 544 | } |
552 | 545 | ||
553 | 546 | ||
554 | int WirelessApplet::position() | 547 | int WirelessApplet::position() |
555 | { | 548 | { |
556 | return 6; | 549 | return 6; |
557 | } | 550 | } |
558 | 551 | ||
559 | 552 | ||
560 | Q_EXPORT_INTERFACE() | 553 | Q_EXPORT_INTERFACE() |
561 | { | 554 | { |
562 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<WirelessApplet> ); | 555 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<WirelessApplet> ); |
563 | } | 556 | } |
564 | 557 | ||
diff --git a/noncore/applets/wirelessapplet/wirelessapplet.pro b/noncore/applets/wirelessapplet/wirelessapplet.pro index 7bd7380..636b2d3 100644 --- a/noncore/applets/wirelessapplet/wirelessapplet.pro +++ b/noncore/applets/wirelessapplet/wirelessapplet.pro | |||
@@ -1,13 +1,13 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on release | 2 | CONFIG += qt plugin warn_on release |
3 | HEADERS = wireless.h networkinfo.h mgraph.h advancedconfig.h | 3 | HEADERS = wireless.h mgraph.h advancedconfig.h |
4 | SOURCES = wireless.cpp networkinfo.cpp mgraph.cpp advancedconfig.cpp | 4 | SOURCES = wireless.cpp mgraph.cpp advancedconfig.cpp |
5 | INTERFACES = advancedconfigbase.ui | 5 | INTERFACES = advancedconfigbase.ui |
6 | TARGET = wirelessapplet | 6 | TARGET = wirelessapplet |
7 | DESTDIR = $(OPIEDIR)/plugins/applets | 7 | DESTDIR = $(OPIEDIR)/plugins/applets |
8 | INCLUDEPATH += $(OPIEDIR)/include | 8 | INCLUDEPATH += $(OPIEDIR)/include |
9 | DEPENDPATH += $(OPIEDIR)/include | 9 | DEPENDPATH += $(OPIEDIR)/include |
10 | LIBS += -lqpe -lopiecore2 -lopienet2 | 10 | LIBS += -lqpe -lopiecore2 -lopienet2 |
11 | VERSION = 0.1.1 | 11 | VERSION = 0.1.1 |
12 | 12 | ||
13 | include ( $(OPIEDIR)/include.pro ) | 13 | include ( $(OPIEDIR)/include.pro ) |