author | mickeyl <mickeyl> | 2002-08-04 19:06:53 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2002-08-04 19:06:53 (UTC) |
commit | c2d27f3bc4fdf7407337a50c92dcb04ab4ce3525 (patch) (unidiff) | |
tree | 3913529e3ce4ba338e030e922fe094470211e5b5 | |
parent | 55019d84057f9c2bd2b2483da2c128a0a927e003 (diff) | |
download | opie-c2d27f3bc4fdf7407337a50c92dcb04ab4ce3525.zip opie-c2d27f3bc4fdf7407337a50c92dcb04ab4ce3525.tar.gz opie-c2d27f3bc4fdf7407337a50c92dcb04ab4ce3525.tar.bz2 |
wireless monitoring applet added to opie-cvs
19 files changed, 1312 insertions, 0 deletions
diff --git a/noncore/applets/wirelessapplet/connect0.xpm b/noncore/applets/wirelessapplet/connect0.xpm new file mode 100644 index 0000000..f2c0bb7 --- a/dev/null +++ b/noncore/applets/wirelessapplet/connect0.xpm | |||
@@ -0,0 +1,28 @@ | |||
1 | /* XPM */ | ||
2 | static char * connect0_xpm[] = { | ||
3 | "14 14 11 1", | ||
4 | " c None", | ||
5 | ".c #FFFFFF", | ||
6 | "+c #848284", | ||
7 | "@c #000000", | ||
8 | "#c #C6C3C6", | ||
9 | "$c #877F81", | ||
10 | "%c #191819", | ||
11 | "&c #897D7F", | ||
12 | "*c #0E0E0E", | ||
13 | "=c #575657", | ||
14 | "-c #131313", | ||
15 | " ", | ||
16 | " ", | ||
17 | " ", | ||
18 | " +@+ ", | ||
19 | " #@@ ", | ||
20 | " $%+ ", | ||
21 | " + ", | ||
22 | " @ ", | ||
23 | " &*= ", | ||
24 | " +-@ ", | ||
25 | " +@@ ", | ||
26 | " +#@@+ ", | ||
27 | " +#@@@ ", | ||
28 | " +#@@@ "}; | ||
diff --git a/noncore/applets/wirelessapplet/connect1.xpm b/noncore/applets/wirelessapplet/connect1.xpm new file mode 100644 index 0000000..d831437 --- a/dev/null +++ b/noncore/applets/wirelessapplet/connect1.xpm | |||
@@ -0,0 +1,28 @@ | |||
1 | /* XPM */ | ||
2 | static char * connect1_xpm[] = { | ||
3 | "14 14 11 1", | ||
4 | " c None", | ||
5 | ".c #FFFFFF", | ||
6 | "+c #848284", | ||
7 | "@c #FF2609", | ||
8 | "#c #877F81", | ||
9 | "$c #000000", | ||
10 | "%c #897D7F", | ||
11 | "&c #0E0E0E", | ||
12 | "*c #575657", | ||
13 | "=c #131313", | ||
14 | "-c #C6C3C6", | ||
15 | " ", | ||
16 | " ", | ||
17 | " ", | ||
18 | " +@+ ", | ||
19 | " @@@ ", | ||
20 | " #@+ ", | ||
21 | " + ", | ||
22 | " $ ", | ||
23 | " %&* ", | ||
24 | " +=$ ", | ||
25 | " +$$ ", | ||
26 | " +-$$+ ", | ||
27 | " +-$$$ ", | ||
28 | " +-$$$ "}; | ||
diff --git a/noncore/applets/wirelessapplet/connect2.xpm b/noncore/applets/wirelessapplet/connect2.xpm new file mode 100644 index 0000000..9e42f33 --- a/dev/null +++ b/noncore/applets/wirelessapplet/connect2.xpm | |||
@@ -0,0 +1,29 @@ | |||
1 | /* XPM */ | ||
2 | static char * connect2_xpm[] = { | ||
3 | "14 14 12 1", | ||
4 | " c None", | ||
5 | ".c #FF2609", | ||
6 | "+c #FFFFFF", | ||
7 | "@c #848284", | ||
8 | "#c #000000", | ||
9 | "$c #C6C3C6", | ||
10 | "%c #877F81", | ||
11 | "&c #191819", | ||
12 | "*c #897D7F", | ||
13 | "=c #0E0E0E", | ||
14 | "-c #575657", | ||
15 | ";c #131313", | ||
16 | " ", | ||
17 | " ", | ||
18 | " ... ", | ||
19 | " .@#@. ", | ||
20 | " .$##. ", | ||
21 | " .%&@. ", | ||
22 | " ... ", | ||
23 | " # ", | ||
24 | " *=- ", | ||
25 | " @;# ", | ||
26 | " @## ", | ||
27 | " @$##@ ", | ||
28 | " @$### ", | ||
29 | " @$### "}; | ||
diff --git a/noncore/applets/wirelessapplet/connect3.xpm b/noncore/applets/wirelessapplet/connect3.xpm new file mode 100644 index 0000000..263443d --- a/dev/null +++ b/noncore/applets/wirelessapplet/connect3.xpm | |||
@@ -0,0 +1,28 @@ | |||
1 | /* XPM */ | ||
2 | static char * connect3_xpm[] = { | ||
3 | "14 14 11 1", | ||
4 | " c None", | ||
5 | ".c #FF2609", | ||
6 | "+c #848284", | ||
7 | "@c #000000", | ||
8 | "#c #C6C3C6", | ||
9 | "$c #877F81", | ||
10 | "%c #191819", | ||
11 | "&c #897D7F", | ||
12 | "*c #0E0E0E", | ||
13 | "=c #575657", | ||
14 | "-c #131313", | ||
15 | " ", | ||
16 | " ... ", | ||
17 | " . . ", | ||
18 | " . +@+ . ", | ||
19 | " . #@@ . ", | ||
20 | " . $%+ . ", | ||
21 | " . + . ", | ||
22 | " ... ", | ||
23 | " &*= ", | ||
24 | " +-@ ", | ||
25 | " +@@ ", | ||
26 | " +#@@+ ", | ||
27 | " +#@@@ ", | ||
28 | " +#@@@ "}; | ||
diff --git a/noncore/applets/wirelessapplet/connect4.xpm b/noncore/applets/wirelessapplet/connect4.xpm new file mode 100644 index 0000000..471ed64 --- a/dev/null +++ b/noncore/applets/wirelessapplet/connect4.xpm | |||
@@ -0,0 +1,26 @@ | |||
1 | /* XPM */ | ||
2 | static char * connect4_xpm[] = { | ||
3 | "14 14 9 1", | ||
4 | " c None", | ||
5 | ".c #FF2609", | ||
6 | "+c #FFFFFF", | ||
7 | "@c #848284", | ||
8 | "#c #000000", | ||
9 | "$c #C6C3C6", | ||
10 | "%c #877F81", | ||
11 | "&c #191819", | ||
12 | "*c #131313", | ||
13 | " ... ", | ||
14 | " .. .. ", | ||
15 | " . . ", | ||
16 | " . @#@ . ", | ||
17 | " . $## . ", | ||
18 | " . %&@ . ", | ||
19 | " . @ . ", | ||
20 | " .. # .. ", | ||
21 | " ... ", | ||
22 | " @*# ", | ||
23 | " @## ", | ||
24 | " @$##@ ", | ||
25 | " @$### ", | ||
26 | " @$### "}; | ||
diff --git a/noncore/applets/wirelessapplet/connect5.xpm b/noncore/applets/wirelessapplet/connect5.xpm new file mode 100644 index 0000000..a67be9a --- a/dev/null +++ b/noncore/applets/wirelessapplet/connect5.xpm | |||
@@ -0,0 +1,26 @@ | |||
1 | /* XPM */ | ||
2 | static char * connect5_xpm[] = { | ||
3 | "14 14 9 1", | ||
4 | " c None", | ||
5 | ".c #FF2609", | ||
6 | "+c #FFFFFF", | ||
7 | "@c #848284", | ||
8 | "#c #000000", | ||
9 | "$c #C6C3C6", | ||
10 | "%c #877F81", | ||
11 | "&c #191819", | ||
12 | "*c #131313", | ||
13 | " . ... . ", | ||
14 | " . .. .. . ", | ||
15 | " . . . .", | ||
16 | " . . @#@ . .", | ||
17 | " . . $## . .", | ||
18 | " . . %&@ . .", | ||
19 | " . . @ . .", | ||
20 | " . .. # .. . ", | ||
21 | " . ... . ", | ||
22 | " @*# ", | ||
23 | " @## ", | ||
24 | " @$##@ ", | ||
25 | " @$### ", | ||
26 | " @$### "}; | ||
diff --git a/noncore/applets/wirelessapplet/graphbackground.xpm b/noncore/applets/wirelessapplet/graphbackground.xpm new file mode 100644 index 0000000..5de8605 --- a/dev/null +++ b/noncore/applets/wirelessapplet/graphbackground.xpm | |||
@@ -0,0 +1,40 @@ | |||
1 | /* XPM */ | ||
2 | static char * graphbackground_xpm[] = { | ||
3 | "49 29 8 1", | ||
4 | " c None", | ||
5 | ".c #243B3C", | ||
6 | "+c #263F40", | ||
7 | "@c #274142", | ||
8 | "#c #3B575A", | ||
9 | "$c #385254", | ||
10 | "%c #375051", | ||
11 | "&c #344B4C", | ||
12 | "..+...+...+...+...+...+...+...+...+...+...+...+..", | ||
13 | "..+...+...+...+...+...+...+...+...+...+...+...+..", | ||
14 | "@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", | ||
15 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
16 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
17 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
18 | "@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", | ||
19 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
20 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
21 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
22 | "@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", | ||
23 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
24 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
25 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
26 | "@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", | ||
27 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
28 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
29 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
30 | "@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", | ||
31 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
32 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
33 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
34 | "@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", | ||
35 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
36 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
37 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
38 | "@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", | ||
39 | "..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", | ||
40 | "..+...+...+...+...+...+...+...+...+...+...+...+.."}; | ||
diff --git a/noncore/applets/wirelessapplet/mgraph.cpp b/noncore/applets/wirelessapplet/mgraph.cpp new file mode 100644 index 0000000..b4b86b0 --- a/dev/null +++ b/noncore/applets/wirelessapplet/mgraph.cpp | |||
@@ -0,0 +1,71 @@ | |||
1 | /********************************************************************** | ||
2 | ** MGraph | ||
3 | ** | ||
4 | ** A reusable graph widget. | ||
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 | #include "mgraph.h" | ||
21 | #include "graphbackground.xpm" | ||
22 | #include <qpainter.h> | ||
23 | #include <qpixmap.h> | ||
24 | |||
25 | //--------------------------------------------------------------------------- | ||
26 | |||
27 | MGraph::MGraph( QWidget *parent, const char *name, WFlags f ) | ||
28 | : QFrame( parent, name, f ), min( 0 ), max( 0), values( 0 ) | ||
29 | { | ||
30 | background = new QPixmap( (const char** ) graphbackground_xpm ); | ||
31 | values = new ValueList(); | ||
32 | } | ||
33 | |||
34 | void MGraph::setFrameStyle( int style ) | ||
35 | { | ||
36 | QFrame::setFrameStyle( style ); | ||
37 | setFixedSize( background->width() + frameWidth()*2, background->height() + frameWidth()*2 ); | ||
38 | } | ||
39 | |||
40 | void MGraph::addValue( int value, bool followMax ) | ||
41 | { | ||
42 | values->append( value ); | ||
43 | if ( followMax && (value > max) ) | ||
44 | setMax( value ); | ||
45 | if ( values->count() == background->width()-2 ) // compensate for graph display element border | ||
46 | values->remove( values->begin() ); | ||
47 | repaint( false ); | ||
48 | } | ||
49 | |||
50 | void MGraph::drawContents( QPainter* p ) | ||
51 | { | ||
52 | p->drawPixmap( frameWidth(), frameWidth(), (const QPixmap&) *background ); | ||
53 | p->setPen( QColor( 40, 235, 40 ) ); | ||
54 | |||
55 | int x = frameWidth() + 2; // compensate for graph display element border | ||
56 | int y = 0; | ||
57 | |||
58 | ValueList::ConstIterator it; | ||
59 | for ( it = values->begin(); it != values->end(); ++it ) | ||
60 | { | ||
61 | y = frameWidth() + background->height() -3 - ( ( *(it)*(background->height()-4 ) /max ) ); | ||
62 | p->drawPoint( x++, y ); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | MGraph::~MGraph() | ||
67 | { | ||
68 | delete background; | ||
69 | delete values; | ||
70 | } | ||
71 | |||
diff --git a/noncore/applets/wirelessapplet/mgraph.h b/noncore/applets/wirelessapplet/mgraph.h new file mode 100644 index 0000000..e0e9c4e --- a/dev/null +++ b/noncore/applets/wirelessapplet/mgraph.h | |||
@@ -0,0 +1,53 @@ | |||
1 | /********************************************************************** | ||
2 | ** MGraph | ||
3 | ** | ||
4 | ** A reusable graph widget | ||
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 MGRAPH_H | ||
21 | #define MGRAPH_H | ||
22 | |||
23 | #include <qframe.h> | ||
24 | #include <qvaluelist.h> | ||
25 | |||
26 | typedef QValueList<int> ValueList; | ||
27 | |||
28 | class MGraph : public QFrame | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | public: | ||
32 | MGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0); | ||
33 | ~MGraph(); | ||
34 | |||
35 | void addValue( int value, bool followMax = true ); | ||
36 | void setMax( int value ) { max = value; }; | ||
37 | void setMin( int value ) { min = value; }; | ||
38 | |||
39 | virtual void setFrameStyle( int style ); | ||
40 | |||
41 | protected: | ||
42 | virtual void drawContents( QPainter* ); | ||
43 | int min; | ||
44 | int max; | ||
45 | ValueList* values; | ||
46 | |||
47 | QPixmap* background; | ||
48 | |||
49 | private: | ||
50 | |||
51 | }; | ||
52 | |||
53 | #endif | ||
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp new file mode 100644 index 0000000..dc5c3be --- a/dev/null +++ b/noncore/applets/wirelessapplet/networkinfo.cpp | |||
@@ -0,0 +1,267 @@ | |||
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 | //--------------------------------------------------------------------------- | ||
55 | // class MNetworkInterface | ||
56 | // | ||
57 | |||
58 | MNetworkInterface::MNetworkInterface( const char* name ) | ||
59 | :name( name ) | ||
60 | { | ||
61 | struct ifreq ifr; | ||
62 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; | ||
63 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); | ||
64 | } | ||
65 | |||
66 | MNetworkInterface::~MNetworkInterface() | ||
67 | { | ||
68 | if ( fd != -1 ) | ||
69 | close( fd ); | ||
70 | } | ||
71 | |||
72 | void MNetworkInterface::updateStatistics() | ||
73 | { | ||
74 | } | ||
75 | |||
76 | //--------------------------------------------------------------------------- | ||
77 | // class MWirelessNetworkInterface | ||
78 | // | ||
79 | |||
80 | MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n ) | ||
81 | :MNetworkInterface( n ) | ||
82 | { | ||
83 | signal = 0; | ||
84 | noise = 0; | ||
85 | quality = 0; | ||
86 | } | ||
87 | |||
88 | MWirelessNetworkInterface::~MWirelessNetworkInterface() | ||
89 | { | ||
90 | } | ||
91 | |||
92 | int MWirelessNetworkInterface::qualityPercent() | ||
93 | { | ||
94 | return ( quality*100 ) / 92; | ||
95 | } | ||
96 | |||
97 | int MWirelessNetworkInterface::signalPercent() | ||
98 | { | ||
99 | return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; | ||
100 | } | ||
101 | |||
102 | int MWirelessNetworkInterface::noisePercent() | ||
103 | { | ||
104 | return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; | ||
105 | } | ||
106 | |||
107 | void MWirelessNetworkInterface::updateStatistics() | ||
108 | { | ||
109 | MNetworkInterface::updateStatistics(); | ||
110 | |||
111 | const char* buffer[200]; | ||
112 | |||
113 | struct iwreq iwr; | ||
114 | memset( &iwr, 0, sizeof( iwr ) ); | ||
115 | iwr.u.essid.pointer = (caddr_t) buffer; | ||
116 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | ||
117 | iwr.u.essid.flags = 0; | ||
118 | |||
119 | // check if it is an IEEE 802.11 standard conform | ||
120 | // wireless device by sending SIOCGIWESSID | ||
121 | // which also gives back the Extended Service Set ID | ||
122 | // (see IEEE 802.11 for more information) | ||
123 | |||
124 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); | ||
125 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); | ||
126 | if ( result == 0 ) | ||
127 | { | ||
128 | hasWirelessExtensions = true; | ||
129 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | ||
130 | essid = iwr.u.essid.pointer; | ||
131 | } | ||
132 | else essid = "*** Unknown ***"; | ||
133 | |||
134 | // Address of associated access-point | ||
135 | |||
136 | result = ioctl( fd, SIOCGIWAP, &iwr ); | ||
137 | if ( result == 0 ) | ||
138 | { | ||
139 | APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | ||
140 | iwr.u.ap_addr.sa_data[0]&0xff, | ||
141 | iwr.u.ap_addr.sa_data[1]&0xff, | ||
142 | iwr.u.ap_addr.sa_data[2]&0xff, | ||
143 | iwr.u.ap_addr.sa_data[3]&0xff, | ||
144 | iwr.u.ap_addr.sa_data[4]&0xff, | ||
145 | iwr.u.ap_addr.sa_data[5]&0xff ); | ||
146 | } else APAddr = "*** Unknown ***"; | ||
147 | |||
148 | iwr.u.data.pointer = (caddr_t) buffer; | ||
149 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | ||
150 | iwr.u.data.flags = 0; | ||
151 | |||
152 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); | ||
153 | if ( result == 0 ) | ||
154 | { | ||
155 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | ||
156 | nick = iwr.u.data.pointer; | ||
157 | } else nick = "*** Unknown ***"; | ||
158 | |||
159 | result = ioctl( fd, SIOCGIWMODE, &iwr ); | ||
160 | if ( result == 0 ) | ||
161 | mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; | ||
162 | else mode = "*** Unknown ***"; | ||
163 | |||
164 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); | ||
165 | if ( result == 0 ) | ||
166 | freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; | ||
167 | else freq = 0; | ||
168 | |||
169 | // gather link quality from /proc/net/wireless | ||
170 | |||
171 | char c; | ||
172 | QString status; | ||
173 | QString name; | ||
174 | QFile wfile( PROCNETWIRELESS ); | ||
175 | wfile.open( IO_ReadOnly ); | ||
176 | QTextStream wstream( &wfile ); | ||
177 | wstream.readLine(); // skip the first two lines | ||
178 | wstream.readLine(); // because they only contain headers | ||
179 | |||
180 | if ( wstream.atEnd() ) | ||
181 | { | ||
182 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); | ||
183 | quality = -1; | ||
184 | signal = IW_LOWER; | ||
185 | noise = IW_LOWER; | ||
186 | return; | ||
187 | } | ||
188 | |||
189 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | ||
190 | |||
191 | if ( quality > 92 ) | ||
192 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | ||
193 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | ||
194 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | ||
195 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | ||
196 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | ||
197 | } | ||
198 | |||
199 | //--------------------------------------------------------------------------- | ||
200 | // class Network | ||
201 | // | ||
202 | |||
203 | MNetwork::MNetwork() | ||
204 | { | ||
205 | qDebug( "MNetwork::MNetwork()" ); | ||
206 | procfile = "/proc/net/dev"; | ||
207 | } | ||
208 | |||
209 | MNetwork::~MNetwork() | ||
210 | { | ||
211 | qDebug( "MNetwork::~MNetwork()" ); | ||
212 | } | ||
213 | |||
214 | //--------------------------------------------------------------------------- | ||
215 | // class WirelessNetwork | ||
216 | // | ||
217 | |||
218 | MWirelessNetwork::MWirelessNetwork() | ||
219 | { | ||
220 | qDebug( "MWirelessNetwork::MWirelessNetwork()" ); | ||
221 | procfile = "/proc/net/wireless"; | ||
222 | } | ||
223 | |||
224 | MWirelessNetwork::~MWirelessNetwork() | ||
225 | { | ||
226 | qDebug( "MWirelessNetwork::~MWirelessNetwork()" ); | ||
227 | } | ||
228 | |||
229 | MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const | ||
230 | { | ||
231 | return new MWirelessNetworkInterface( n ); | ||
232 | } | ||
233 | |||
234 | //--------------------------------------------------------------------------- | ||
235 | // class NetworkInterface | ||
236 | // | ||
237 | |||
238 | MNetworkInterface* MNetwork::getFirstInterface() | ||
239 | { | ||
240 | enumerateInterfaces(); | ||
241 | InterfaceMapIterator it( interfaces ); | ||
242 | return ( it.count() > 0 ) ? it.toFirst() : 0; | ||
243 | } | ||
244 | |||
245 | void MNetwork::enumerateInterfaces() | ||
246 | { | ||
247 | interfaces.clear(); | ||
248 | QString str; | ||
249 | QFile f( procfile ); | ||
250 | f.open( IO_ReadOnly ); | ||
251 | QTextStream s( &f ); | ||
252 | s.readLine(); | ||
253 | s.readLine(); | ||
254 | while ( !s.atEnd() ) | ||
255 | { | ||
256 | s >> str; | ||
257 | str.truncate( str.find( ':' ) ); | ||
258 | qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); | ||
259 | interfaces.insert( str, createInterface( str ) ); | ||
260 | s.readLine(); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | MNetworkInterface* MNetwork::createInterface( const char* n ) const | ||
265 | { | ||
266 | return new MNetworkInterface( n ); | ||
267 | } | ||
diff --git a/noncore/applets/wirelessapplet/networkinfo.h b/noncore/applets/wirelessapplet/networkinfo.h new file mode 100644 index 0000000..c5eb743 --- a/dev/null +++ b/noncore/applets/wirelessapplet/networkinfo.h | |||
@@ -0,0 +1,126 @@ | |||
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 void 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 void 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/nowireless.xpm b/noncore/applets/wirelessapplet/nowireless.xpm new file mode 100644 index 0000000..a76322d --- a/dev/null +++ b/noncore/applets/wirelessapplet/nowireless.xpm | |||
@@ -0,0 +1,22 @@ | |||
1 | static char * nowireless_xpm[] = { | ||
2 | "14 14 6 1", | ||
3 | " c None", | ||
4 | ". c #FFFFFF", | ||
5 | "+ c #848284", | ||
6 | "@ c #000000", | ||
7 | "# c #FF0000", | ||
8 | "$ c #C6C3C6", | ||
9 | " ", | ||
10 | " ", | ||
11 | " ", | ||
12 | " +@+ ", | ||
13 | " # $#@ ", | ||
14 | " ####@+ ", | ||
15 | " ## + ", | ||
16 | " ####@ ", | ||
17 | " # #@+ ", | ||
18 | " # +#@ ", | ||
19 | " +@@ ", | ||
20 | " +$@@+ ", | ||
21 | " +$@@@ ", | ||
22 | " +$@@@ "}; | ||
diff --git a/noncore/applets/wirelessapplet/opie-wirelessapplet.control b/noncore/applets/wirelessapplet/opie-wirelessapplet.control new file mode 100644 index 0000000..7db12d5 --- a/dev/null +++ b/noncore/applets/wirelessapplet/opie-wirelessapplet.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: plugins/applets/libwirelessapplet.so* | ||
2 | Priority: optional | ||
3 | Section: opie/system | ||
4 | Maintainer: Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-$SUB_VERSION.1 | ||
7 | Depends: opie-base ($QPE_VERSION) | ||
8 | Description: Wireless Applet | ||
9 | A wireless network card status taskbar applet for the Opie environment | ||
diff --git a/noncore/applets/wirelessapplet/opie-wirelessapplet.postinst b/noncore/applets/wirelessapplet/opie-wirelessapplet.postinst new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/noncore/applets/wirelessapplet/opie-wirelessapplet.postinst | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/sh | ||
2 | /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" | ||
diff --git a/noncore/applets/wirelessapplet/opie-wirelessapplet.postrm b/noncore/applets/wirelessapplet/opie-wirelessapplet.postrm new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/noncore/applets/wirelessapplet/opie-wirelessapplet.postrm | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/sh | ||
2 | /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" | ||
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp new file mode 100644 index 0000000..15ccc58 --- a/dev/null +++ b/noncore/applets/wirelessapplet/wireless.cpp | |||
@@ -0,0 +1,358 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer | ||
3 | ** <mickey@tm.informatik.uni-frankfurt.de> | ||
4 | ** http://www.Vanille.de | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | **********************************************************************/ | ||
15 | |||
16 | #include "wireless.h" | ||
17 | |||
18 | #include <qapplication.h> | ||
19 | #include <qpe/qpeapplication.h> | ||
20 | |||
21 | #include <qpoint.h> | ||
22 | #include <qradiobutton.h> | ||
23 | #include <qcheckbox.h> | ||
24 | #include <qpainter.h> | ||
25 | #include <qlabel.h> | ||
26 | #include <qslider.h> | ||
27 | #include <qbuttongroup.h> | ||
28 | #include <qlayout.h> | ||
29 | #include <qframe.h> | ||
30 | #include <qpixmap.h> | ||
31 | #include <qstring.h> | ||
32 | #include <qfile.h> | ||
33 | |||
34 | #include "networkinfo.h" | ||
35 | #include "mgraph.h" | ||
36 | |||
37 | #include "connect0.xpm" | ||
38 | #include "connect1.xpm" | ||
39 | #include "connect2.xpm" | ||
40 | #include "connect3.xpm" | ||
41 | #include "connect4.xpm" | ||
42 | #include "connect5.xpm" | ||
43 | #include "nowireless.xpm" | ||
44 | |||
45 | #define STYLE_BARS 0 | ||
46 | #define STYLE_ANTENNA 1 | ||
47 | |||
48 | WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) | ||
49 | : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) | ||
50 | { | ||
51 | |||
52 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | ||
53 | QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); | ||
54 | |||
55 | /* status label */ | ||
56 | |||
57 | statusLabel = new QLabel( this, "statuslabel" ); | ||
58 | QString text( "Wireless Status:<br>" | ||
59 | "*** Unknown ***<br>" | ||
60 | "Card not inserted ?<br>" | ||
61 | "Or Sharp ROM ?<br>" | ||
62 | "CELL: 00:00:00:00:00:00" ); | ||
63 | /* QString text( "Station: Unknown<br>" | ||
64 | "ESSID: Unknown<br>" | ||
65 | "MODE: Unknown<br>" | ||
66 | "FREQ: Unknown<br>" | ||
67 | "CELL: AA:BB:CC:DD:EE:FF" ); */ | ||
68 | statusLabel->setText( text ); | ||
69 | statusLabel->setFixedSize( statusLabel->sizeHint() ); | ||
70 | grid->addWidget( statusLabel, 0, 0 ); | ||
71 | |||
72 | /* visualization group box */ | ||
73 | |||
74 | QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); | ||
75 | QRadioButton* r1 = new QRadioButton( "Color Bars", group ); | ||
76 | QRadioButton* r2 = new QRadioButton( "Antenna", group ); | ||
77 | r1->setFocusPolicy( QWidget::NoFocus ); | ||
78 | r2->setFocusPolicy( QWidget::NoFocus ); | ||
79 | group->setFocusPolicy( QWidget::NoFocus ); | ||
80 | group->setButton( STYLE_ANTENNA ); | ||
81 | grid->addWidget( group, 0, 1 ); | ||
82 | |||
83 | /* quality graph */ | ||
84 | |||
85 | mgraph = new MGraph( this ); | ||
86 | mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
87 | mgraph->setMin( 0 ); | ||
88 | mgraph->setMax( 92 ); | ||
89 | grid->addWidget( mgraph, 1, 0 ); | ||
90 | mgraph->setFocusPolicy( QWidget::NoFocus ); | ||
91 | |||
92 | /* dhcp renew CheckBox */ | ||
93 | |||
94 | //FIXME: under construction | ||
95 | //QCheckBox* dhcpCheckBox = new QCheckBox( "DHCP renew", this ); | ||
96 | //dhcpCheckBox->setFocusPolicy( QWidget::NoFocus ); | ||
97 | //grid->addWidget( dhcpCheckBox, 2, 0, Qt::AlignCenter ); | ||
98 | |||
99 | /* update Frequency Label */ | ||
100 | |||
101 | updateLabel = new QLabel( this ); | ||
102 | updateLabel->setText( "Update every 500 ms" ); | ||
103 | grid->addWidget( updateLabel, 2, 1 ); | ||
104 | |||
105 | /* update Frequency Slider */ | ||
106 | |||
107 | QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); | ||
108 | updateSlider->setRange( 50, 999 ); | ||
109 | updateSlider->setValue( 500 ); | ||
110 | updateSlider->setTickmarks( QSlider::Both ); | ||
111 | updateSlider->setTickInterval( 100 ); | ||
112 | updateSlider->setSteps( 50, 50 ); | ||
113 | updateSlider->setFocusPolicy( QWidget::NoFocus ); | ||
114 | grid->addWidget( updateSlider, 1, 1 ); | ||
115 | connect( updateSlider, SIGNAL( valueChanged( int ) ), | ||
116 | this, SLOT( updateDelayChange( int ) ) ); | ||
117 | |||
118 | setFixedSize( sizeHint() ); | ||
119 | setFocusPolicy( QWidget::NoFocus ); | ||
120 | |||
121 | connect( group, SIGNAL( clicked( int ) ), | ||
122 | applet, SLOT( styleChange( int ) ) ); | ||
123 | |||
124 | } | ||
125 | |||
126 | void WirelessControl::updateDelayChange( int delay ) | ||
127 | { | ||
128 | QString text; | ||
129 | text.sprintf( "Update every %3d ms", delay ); | ||
130 | updateLabel->setText( text ); | ||
131 | applet->updateDelayChange( delay ); | ||
132 | } | ||
133 | |||
134 | void WirelessControl::show ( bool ) | ||
135 | { | ||
136 | QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); | ||
137 | |||
138 | int w = sizeHint().width(); | ||
139 | int x = curPos.x() - ( w / 2 ); | ||
140 | |||
141 | if ( ( x + w ) > QPEApplication::desktop()->width() ) | ||
142 | x = QPEApplication::desktop ( )-> width ( ) - w; | ||
143 | |||
144 | move( x, curPos.y () - sizeHint().height () ); | ||
145 | QFrame::show(); | ||
146 | } | ||
147 | |||
148 | |||
149 | //=========================================================================== | ||
150 | |||
151 | WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) | ||
152 | : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), interface( 0 ) | ||
153 | { | ||
154 | setFixedHeight( 18 ); | ||
155 | setFixedWidth( 14 ); | ||
156 | status = new WirelessControl( this, 0, "wireless status" ); | ||
157 | |||
158 | network = new MWirelessNetwork(); | ||
159 | |||
160 | timer = startTimer( 500 ); | ||
161 | } | ||
162 | |||
163 | void WirelessApplet::checkInterface() | ||
164 | { | ||
165 | interface = network->getFirstInterface(); | ||
166 | if ( interface ) | ||
167 | { | ||
168 | qDebug( "WIFIAPPLET: using interface '%s'", (const char*) | ||
169 | interface->getName() ); | ||
170 | } | ||
171 | else | ||
172 | { | ||
173 | qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | void WirelessApplet::updateDelayChange( int delay ) | ||
178 | { | ||
179 | killTimer( timer ); | ||
180 | timer = startTimer( delay ); | ||
181 | } | ||
182 | |||
183 | WirelessApplet::~WirelessApplet() | ||
184 | { | ||
185 | } | ||
186 | |||
187 | void WirelessApplet::styleChange( int style ) | ||
188 | { | ||
189 | visualStyle = style; | ||
190 | repaint(); | ||
191 | } | ||
192 | |||
193 | void WirelessApplet::timerEvent( QTimerEvent* ) | ||
194 | { | ||
195 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | ||
196 | |||
197 | if ( iface ) | ||
198 | { | ||
199 | iface->updateStatistics(); | ||
200 | if ( mustRepaint() ) | ||
201 | { | ||
202 | //qDebug( "WIFIAPPLET: A value has changed -> repainting." ); | ||
203 | repaint(); | ||
204 | } | ||
205 | |||
206 | if ( status->isVisible() ) | ||
207 | updatePopupWindow(); | ||
208 | } else checkInterface(); | ||
209 | } | ||
210 | |||
211 | void WirelessApplet::mousePressEvent( QMouseEvent *) | ||
212 | { | ||
213 | if ( status->isVisible() ) | ||
214 | status->hide(); | ||
215 | else | ||
216 | status->show( true ); | ||
217 | } | ||
218 | |||
219 | bool WirelessApplet::mustRepaint() | ||
220 | { | ||
221 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | ||
222 | |||
223 | // check if there are enough changes to justify a (flickering) repaint | ||
224 | |||
225 | // has the interface changed? | ||
226 | |||
227 | if ( iface != oldiface ) | ||
228 | { | ||
229 | oldiface = iface; | ||
230 | return true; | ||
231 | } | ||
232 | |||
233 | const char** pixmap = getQualityPixmap(); | ||
234 | |||
235 | if ( pixmap && ( pixmap != oldpixmap ) ) | ||
236 | { | ||
237 | oldpixmap = pixmap; | ||
238 | return true; | ||
239 | } | ||
240 | |||
241 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; | ||
242 | int signalH = iface->signalPercent() * ( height() - 3 ) / 100; | ||
243 | int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; | ||
244 | |||
245 | if ( ( noiseH != oldnoiseH ) | ||
246 | || ( signalH != oldsignalH ) | ||
247 | || ( qualityH != oldqualityH ) ) | ||
248 | { | ||
249 | oldnoiseH = noiseH; | ||
250 | oldsignalH = signalH; | ||
251 | oldqualityH = qualityH; | ||
252 | return true; | ||
253 | } | ||
254 | |||
255 | return false; | ||
256 | } | ||
257 | |||
258 | void WirelessApplet::updatePopupWindow() | ||
259 | { | ||
260 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | ||
261 | int qualityH = iface->qualityPercent(); | ||
262 | |||
263 | if ( status->mgraph ) | ||
264 | status->mgraph->addValue( qualityH, false ); | ||
265 | |||
266 | QString freqString; | ||
267 | QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; | ||
268 | freqString.sprintf( "%.3f GHz", iface->freq ); | ||
269 | status->statusLabel->setText( "Station: " + iface->nick + "<br>" + | ||
270 | "ESSID: " + iface->essid + "<br>" + | ||
271 | "MODE: " + iface->mode + "<br>" + | ||
272 | "FREQ: " + freqString + "<br>" + | ||
273 | cell + " " + iface->APAddr ); | ||
274 | } | ||
275 | |||
276 | const char** WirelessApplet::getQualityPixmap() | ||
277 | { | ||
278 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | ||
279 | |||
280 | if ( !iface ) return ( const char** ) nowireless_xpm; | ||
281 | int qualityH = iface->qualityPercent(); | ||
282 | if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; | ||
283 | |||
284 | if ( visualStyle == STYLE_ANTENNA ) | ||
285 | { | ||
286 | if ( qualityH < 1 ) return ( const char** ) connect0_xpm; | ||
287 | if ( qualityH < 17 ) return ( const char** ) connect1_xpm; | ||
288 | if ( qualityH < 34 ) return ( const char** ) connect2_xpm; | ||
289 | if ( qualityH < 50 ) return ( const char** ) connect3_xpm; | ||
290 | if ( qualityH < 65 ) return ( const char** ) connect4_xpm; | ||
291 | return ( const char** ) connect5_xpm; | ||
292 | } | ||
293 | |||
294 | return 0; // please draw your bars | ||
295 | } | ||
296 | |||
297 | void WirelessApplet::paintEvent( QPaintEvent* ) | ||
298 | { | ||
299 | MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; | ||
300 | |||
301 | QPainter p(this); | ||
302 | QColor color; | ||
303 | |||
304 | const char** pixmap = getQualityPixmap(); | ||
305 | |||
306 | if ( pixmap ) | ||
307 | p.drawPixmap( 0, 1, pixmap ); | ||
308 | else | ||
309 | { | ||
310 | |||
311 | int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; | ||
312 | int signalH = iface->signalPercent() * ( height() - 3 ) / 100; | ||
313 | int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; | ||
314 | |||
315 | double intensity; | ||
316 | int pixelHeight; | ||
317 | int pixelWidth = 2; | ||
318 | int Hue; | ||
319 | int barSpace = 3; | ||
320 | int leftoffset = 0; | ||
321 | int bottomoffset = 2; | ||
322 | |||
323 | // draw noise indicator | ||
324 | pixelHeight = noiseH; | ||
325 | Hue = 50; | ||
326 | for ( int i = 0; i < pixelHeight; ++i ) | ||
327 | { | ||
328 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; | ||
329 | color.setHsv( Hue, 255, intensity ); | ||
330 | p.setPen ( color ); | ||
331 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); | ||
332 | } | ||
333 | |||
334 | // draw signal indicator | ||
335 | pixelHeight = signalH; | ||
336 | Hue = 100; | ||
337 | leftoffset += pixelWidth + barSpace; | ||
338 | for ( int i = 0; i < pixelHeight; ++i ) | ||
339 | { | ||
340 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; | ||
341 | color.setHsv( Hue, 255, intensity ); | ||
342 | p.setPen ( color ); | ||
343 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); | ||
344 | } | ||
345 | |||
346 | // draw quality indicator | ||
347 | pixelHeight = qualityH; | ||
348 | Hue = 250; | ||
349 | leftoffset += pixelWidth + barSpace; | ||
350 | for ( int i = 0; i < pixelHeight; ++i ) | ||
351 | { | ||
352 | intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; | ||
353 | color.setHsv( Hue, 255, intensity ); | ||
354 | p.setPen ( color ); | ||
355 | p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); | ||
356 | } | ||
357 | } | ||
358 | } | ||
diff --git a/noncore/applets/wirelessapplet/wireless.h b/noncore/applets/wirelessapplet/wireless.h new file mode 100644 index 0000000..d45ac68 --- a/dev/null +++ b/noncore/applets/wirelessapplet/wireless.h | |||
@@ -0,0 +1,89 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
3 | ** All rights reserved. | ||
4 | ** | ||
5 | ** This file may be distributed and/or modified under the terms of the | ||
6 | ** GNU General Public License version 2 as published by the Free Software | ||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
8 | ** packaging of this file. | ||
9 | ** | ||
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | ** | ||
13 | **********************************************************************/ | ||
14 | |||
15 | #ifndef __WIRELESS_APPLET_H__ | ||
16 | #define __WIRELESS_APPLET_H__ | ||
17 | |||
18 | #include <qwidget.h> | ||
19 | #include <qframe.h> | ||
20 | #include <qpixmap.h> | ||
21 | |||
22 | class MNetwork; | ||
23 | class MWirelessNetwork; | ||
24 | class MNetworkInterface; | ||
25 | class MWirelessNetworkInterface; | ||
26 | class Y; | ||
27 | class QLabel; | ||
28 | class WirelessApplet; | ||
29 | class MGraph; | ||
30 | |||
31 | class WirelessControl : public QFrame | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | public: | ||
35 | WirelessControl( WirelessApplet* icon, QWidget *parent=0, const char *name=0 ); | ||
36 | void show( bool ); | ||
37 | |||
38 | MGraph* mgraph; | ||
39 | QLabel* statusLabel; | ||
40 | QLabel* updateLabel; | ||
41 | |||
42 | public slots: | ||
43 | void updateDelayChange( int ); | ||
44 | |||
45 | private: | ||
46 | WirelessApplet* applet; | ||
47 | }; | ||
48 | |||
49 | class WirelessApplet : public QWidget | ||
50 | { | ||
51 | Q_OBJECT | ||
52 | public: | ||
53 | WirelessApplet( QWidget *parent = 0, const char *name=0 ); | ||
54 | ~WirelessApplet(); | ||
55 | WirelessControl* status; | ||
56 | |||
57 | virtual void timerEvent( QTimerEvent* ); | ||
58 | void updateDelayChange( int delay ); | ||
59 | |||
60 | public slots: | ||
61 | void styleChange( int ); | ||
62 | |||
63 | private: | ||
64 | void mousePressEvent( QMouseEvent * ); | ||
65 | void paintEvent( QPaintEvent* ); | ||
66 | void checkInterface(); | ||
67 | |||
68 | bool mustRepaint(); | ||
69 | void updatePopupWindow(); | ||
70 | const char** getQualityPixmap(); | ||
71 | |||
72 | private: | ||
73 | QPixmap snapshotPixmap; | ||
74 | int visualStyle; | ||
75 | int timer; | ||
76 | |||
77 | MWirelessNetwork* network; | ||
78 | MNetworkInterface* interface; | ||
79 | |||
80 | private: | ||
81 | const char** oldpixmap; | ||
82 | MWirelessNetworkInterface* oldiface; | ||
83 | int oldqualityH; | ||
84 | int oldsignalH; | ||
85 | int oldnoiseH; | ||
86 | }; | ||
87 | |||
88 | #endif // __WIRELESS_APPLET_H__ | ||
89 | |||
diff --git a/noncore/applets/wirelessapplet/wirelessappletimpl.cpp b/noncore/applets/wirelessapplet/wirelessappletimpl.cpp new file mode 100644 index 0000000..eb00459 --- a/dev/null +++ b/noncore/applets/wirelessapplet/wirelessappletimpl.cpp | |||
@@ -0,0 +1,64 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "wireless.h" | ||
21 | #include "wirelessappletimpl.h" | ||
22 | |||
23 | |||
24 | WirelessAppletImpl::WirelessAppletImpl() | ||
25 | : wireless(0), ref(0) | ||
26 | { | ||
27 | } | ||
28 | |||
29 | WirelessAppletImpl::~WirelessAppletImpl() | ||
30 | { | ||
31 | delete wireless; | ||
32 | } | ||
33 | |||
34 | QWidget *WirelessAppletImpl::applet( QWidget *parent ) | ||
35 | { | ||
36 | if ( !wireless ) | ||
37 | wireless = new WirelessApplet( parent ); | ||
38 | return wireless; | ||
39 | } | ||
40 | |||
41 | int WirelessAppletImpl::position() const | ||
42 | { | ||
43 | return 6; | ||
44 | } | ||
45 | |||
46 | QRESULT WirelessAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) | ||
47 | { | ||
48 | *iface = 0; | ||
49 | if ( uuid == IID_QUnknown ) | ||
50 | *iface = this; | ||
51 | else if ( uuid == IID_TaskbarApplet ) | ||
52 | *iface = this; | ||
53 | |||
54 | if ( *iface ) | ||
55 | (*iface)->addRef(); | ||
56 | return QS_OK; | ||
57 | } | ||
58 | |||
59 | Q_EXPORT_INTERFACE() | ||
60 | { | ||
61 | Q_CREATE_INSTANCE( WirelessAppletImpl ) | ||
62 | } | ||
63 | |||
64 | |||
diff --git a/noncore/applets/wirelessapplet/wirelessappletimpl.h b/noncore/applets/wirelessapplet/wirelessappletimpl.h new file mode 100644 index 0000000..7008d51 --- a/dev/null +++ b/noncore/applets/wirelessapplet/wirelessappletimpl.h | |||
@@ -0,0 +1,44 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef WIRELESSAPPLETIMPL_H | ||
21 | #define WIRELESSAPPLETIMPL_H | ||
22 | |||
23 | #include <qpe/taskbarappletinterface.h> | ||
24 | |||
25 | class WirelessApplet; | ||
26 | |||
27 | class WirelessAppletImpl : public TaskbarAppletInterface | ||
28 | { | ||
29 | public: | ||
30 | WirelessAppletImpl(); | ||
31 | virtual ~WirelessAppletImpl(); | ||
32 | |||
33 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
34 | Q_REFCOUNT | ||
35 | |||
36 | virtual QWidget *applet( QWidget *parent ); | ||
37 | virtual int position() const; | ||
38 | |||
39 | private: | ||
40 | WirelessApplet *wireless; | ||
41 | ulong ref; | ||
42 | }; | ||
43 | |||
44 | #endif | ||