author | mickeyl <mickeyl> | 2002-08-04 19:06:53 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2002-08-04 19:06:53 (UTC) |
commit | c2d27f3bc4fdf7407337a50c92dcb04ab4ce3525 (patch) (side-by-side diff) | |
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 @@ +/* XPM */ +static char * connect0_xpm[] = { +"14 14 11 1", +" c None", +". c #FFFFFF", +"+ c #848284", +"@ c #000000", +"# c #C6C3C6", +"$ c #877F81", +"% c #191819", +"& c #897D7F", +"* c #0E0E0E", +"= c #575657", +"- c #131313", +" ", +" ", +" ", +" +@+ ", +" #@@ ", +" $%+ ", +" + ", +" @ ", +" &*= ", +" +-@ ", +" +@@ ", +" +#@@+ ", +" +#@@@ ", +" +#@@@ "}; 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 @@ +/* XPM */ +static char * connect1_xpm[] = { +"14 14 11 1", +" c None", +". c #FFFFFF", +"+ c #848284", +"@ c #FF2609", +"# c #877F81", +"$ c #000000", +"% c #897D7F", +"& c #0E0E0E", +"* c #575657", +"= c #131313", +"- c #C6C3C6", +" ", +" ", +" ", +" +@+ ", +" @@@ ", +" #@+ ", +" + ", +" $ ", +" %&* ", +" +=$ ", +" +$$ ", +" +-$$+ ", +" +-$$$ ", +" +-$$$ "}; 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 @@ +/* XPM */ +static char * connect2_xpm[] = { +"14 14 12 1", +" c None", +". c #FF2609", +"+ c #FFFFFF", +"@ c #848284", +"# c #000000", +"$ c #C6C3C6", +"% c #877F81", +"& c #191819", +"* c #897D7F", +"= c #0E0E0E", +"- c #575657", +"; c #131313", +" ", +" ", +" ... ", +" .@#@. ", +" .$##. ", +" .%&@. ", +" ... ", +" # ", +" *=- ", +" @;# ", +" @## ", +" @$##@ ", +" @$### ", +" @$### "}; 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 @@ +/* XPM */ +static char * connect3_xpm[] = { +"14 14 11 1", +" c None", +". c #FF2609", +"+ c #848284", +"@ c #000000", +"# c #C6C3C6", +"$ c #877F81", +"% c #191819", +"& c #897D7F", +"* c #0E0E0E", +"= c #575657", +"- c #131313", +" ", +" ... ", +" . . ", +" . +@+ . ", +" . #@@ . ", +" . $%+ . ", +" . + . ", +" ... ", +" &*= ", +" +-@ ", +" +@@ ", +" +#@@+ ", +" +#@@@ ", +" +#@@@ "}; 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 @@ +/* XPM */ +static char * connect4_xpm[] = { +"14 14 9 1", +" c None", +". c #FF2609", +"+ c #FFFFFF", +"@ c #848284", +"# c #000000", +"$ c #C6C3C6", +"% c #877F81", +"& c #191819", +"* c #131313", +" ... ", +" .. .. ", +" . . ", +" . @#@ . ", +" . $## . ", +" . %&@ . ", +" . @ . ", +" .. # .. ", +" ... ", +" @*# ", +" @## ", +" @$##@ ", +" @$### ", +" @$### "}; 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 @@ +/* XPM */ +static char * connect5_xpm[] = { +"14 14 9 1", +" c None", +". c #FF2609", +"+ c #FFFFFF", +"@ c #848284", +"# c #000000", +"$ c #C6C3C6", +"% c #877F81", +"& c #191819", +"* c #131313", +" . ... . ", +" . .. .. . ", +" . . . .", +" . . @#@ . .", +" . . $## . .", +" . . %&@ . .", +" . . @ . .", +" . .. # .. . ", +" . ... . ", +" @*# ", +" @## ", +" @$##@ ", +" @$### ", +" @$### "}; 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 @@ +/* XPM */ +static char * graphbackground_xpm[] = { +"49 29 8 1", +" c None", +". c #243B3C", +"+ c #263F40", +"@ c #274142", +"# c #3B575A", +"$ c #385254", +"% c #375051", +"& c #344B4C", +"..+...+...+...+...+...+...+...+...+...+...+...+..", +"..+...+...+...+...+...+...+...+...+...+...+...+..", +"@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"@@#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$$$#$@", +"..%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&.", +"..+...+...+...+...+...+...+...+...+...+...+...+.."}; 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 @@ +/********************************************************************** +** MGraph +** +** A reusable graph widget. +** +** Copyright (C) 2002, Michael Lauer +** mickey@tm.informatik.uni-frankfurt.de +** http://www.Vanille.de +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#include "mgraph.h" +#include "graphbackground.xpm" +#include <qpainter.h> +#include <qpixmap.h> + +//--------------------------------------------------------------------------- + +MGraph::MGraph( QWidget *parent, const char *name, WFlags f ) + : QFrame( parent, name, f ), min( 0 ), max( 0), values( 0 ) +{ + background = new QPixmap( (const char** ) graphbackground_xpm ); + values = new ValueList(); +} + +void MGraph::setFrameStyle( int style ) +{ + QFrame::setFrameStyle( style ); + setFixedSize( background->width() + frameWidth()*2, background->height() + frameWidth()*2 ); +} + +void MGraph::addValue( int value, bool followMax ) +{ + values->append( value ); + if ( followMax && (value > max) ) + setMax( value ); + if ( values->count() == background->width()-2 ) // compensate for graph display element border + values->remove( values->begin() ); + repaint( false ); +} + +void MGraph::drawContents( QPainter* p ) +{ + p->drawPixmap( frameWidth(), frameWidth(), (const QPixmap&) *background ); + p->setPen( QColor( 40, 235, 40 ) ); + + int x = frameWidth() + 2; // compensate for graph display element border + int y = 0; + + ValueList::ConstIterator it; + for ( it = values->begin(); it != values->end(); ++it ) + { + y = frameWidth() + background->height() -3 - ( ( *(it)*(background->height()-4 ) /max ) ); + p->drawPoint( x++, y ); + } +} + +MGraph::~MGraph() +{ + delete background; + delete values; +} + 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 @@ +/********************************************************************** +** MGraph +** +** A reusable graph widget +** +** Copyright (C) 2002, Michael Lauer +** mickey@tm.informatik.uni-frankfurt.de +** http://www.Vanille.de +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#ifndef MGRAPH_H +#define MGRAPH_H + +#include <qframe.h> +#include <qvaluelist.h> + +typedef QValueList<int> ValueList; + +class MGraph : public QFrame +{ + Q_OBJECT +public: + MGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0); + ~MGraph(); + + void addValue( int value, bool followMax = true ); + void setMax( int value ) { max = value; }; + void setMin( int value ) { min = value; }; + + virtual void setFrameStyle( int style ); + +protected: + virtual void drawContents( QPainter* ); + int min; + int max; + ValueList* values; + + QPixmap* background; + +private: + +}; + +#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 @@ +/********************************************************************** +** MNetwork* classes +** +** Encapsulate network information +** +** Copyright (C) 2002, Michael Lauer +** mickey@tm.informatik.uni-frankfurt.de +** http://www.Vanille.de +** +** Based on portions of the Wireless Extensions +** Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com> +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#include "networkinfo.h" + +#include <arpa/inet.h> +#include <sys/socket.h> +#include <linux/if_ether.h> +#include <netinet/ip.h> +#include <sys/ioctl.h> +#include <linux/wireless.h> + +#include <unistd.h> +#include <math.h> +#include <errno.h> +#include <string.h> + +#include <stdlib.h> + +#include <qstring.h> +#include <qfile.h> +#include <qtextstream.h> + +/* estimated wireless signal strength and noise level values + based on experimentation with Orinoco and Prism2 cards. + Seem to be correct, but please inform me, if you got values + outside these boundaries. :Mickey: */ + +#define IW_UPPER 220 +#define IW_LOWER 140 + +#define PROCNETDEV "/proc/net/dev" +#define PROCNETWIRELESS "/proc/net/wireless" + +//--------------------------------------------------------------------------- +// class MNetworkInterface +// + +MNetworkInterface::MNetworkInterface( const char* name ) + :name( name ) +{ + struct ifreq ifr; + struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; + fd = socket( AF_INET, SOCK_DGRAM, 0 ); +} + +MNetworkInterface::~MNetworkInterface() +{ + if ( fd != -1 ) + close( fd ); +} + +void MNetworkInterface::updateStatistics() +{ +} + +//--------------------------------------------------------------------------- +// class MWirelessNetworkInterface +// + +MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n ) + :MNetworkInterface( n ) +{ + signal = 0; + noise = 0; + quality = 0; +} + +MWirelessNetworkInterface::~MWirelessNetworkInterface() +{ +} + +int MWirelessNetworkInterface::qualityPercent() +{ + return ( quality*100 ) / 92; +} + +int MWirelessNetworkInterface::signalPercent() +{ + return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; +} + +int MWirelessNetworkInterface::noisePercent() +{ + return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; +} + +void MWirelessNetworkInterface::updateStatistics() +{ + MNetworkInterface::updateStatistics(); + + const char* buffer[200]; + + struct iwreq iwr; + memset( &iwr, 0, sizeof( iwr ) ); + iwr.u.essid.pointer = (caddr_t) buffer; + iwr.u.essid.length = IW_ESSID_MAX_SIZE; + iwr.u.essid.flags = 0; + + // check if it is an IEEE 802.11 standard conform + // wireless device by sending SIOCGIWESSID + // which also gives back the Extended Service Set ID + // (see IEEE 802.11 for more information) + + strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); + int result = ioctl( fd, SIOCGIWESSID, &iwr ); + if ( result == 0 ) + { + hasWirelessExtensions = true; + iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; + essid = iwr.u.essid.pointer; + } + else essid = "*** Unknown ***"; + + // Address of associated access-point + + result = ioctl( fd, SIOCGIWAP, &iwr ); + if ( result == 0 ) + { + APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", + iwr.u.ap_addr.sa_data[0]&0xff, + iwr.u.ap_addr.sa_data[1]&0xff, + iwr.u.ap_addr.sa_data[2]&0xff, + iwr.u.ap_addr.sa_data[3]&0xff, + iwr.u.ap_addr.sa_data[4]&0xff, + iwr.u.ap_addr.sa_data[5]&0xff ); + } else APAddr = "*** Unknown ***"; + + iwr.u.data.pointer = (caddr_t) buffer; + iwr.u.data.length = IW_ESSID_MAX_SIZE; + iwr.u.data.flags = 0; + + result = ioctl( fd, SIOCGIWNICKN, &iwr ); + if ( result == 0 ) + { + iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; + nick = iwr.u.data.pointer; + } else nick = "*** Unknown ***"; + + result = ioctl( fd, SIOCGIWMODE, &iwr ); + if ( result == 0 ) + mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; + else mode = "*** Unknown ***"; + + result = ioctl( fd, SIOCGIWFREQ, &iwr ); + if ( result == 0 ) + freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; + else freq = 0; + + // gather link quality from /proc/net/wireless + + char c; + QString status; + QString name; + QFile wfile( PROCNETWIRELESS ); + wfile.open( IO_ReadOnly ); + QTextStream wstream( &wfile ); + wstream.readLine(); // skip the first two lines + wstream.readLine(); // because they only contain headers + + if ( wstream.atEnd() ) + { + qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); + quality = -1; + signal = IW_LOWER; + noise = IW_LOWER; + return; + } + + wstream >> name >> status >> quality >> c >> signal >> c >> noise; + + if ( quality > 92 ) + qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); + if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) + qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); + if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) + qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); +} + +//--------------------------------------------------------------------------- +// class Network +// + +MNetwork::MNetwork() +{ + qDebug( "MNetwork::MNetwork()" ); + procfile = "/proc/net/dev"; +} + +MNetwork::~MNetwork() +{ + qDebug( "MNetwork::~MNetwork()" ); +} + +//--------------------------------------------------------------------------- +// class WirelessNetwork +// + +MWirelessNetwork::MWirelessNetwork() +{ + qDebug( "MWirelessNetwork::MWirelessNetwork()" ); + procfile = "/proc/net/wireless"; +} + +MWirelessNetwork::~MWirelessNetwork() +{ + qDebug( "MWirelessNetwork::~MWirelessNetwork()" ); +} + +MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const +{ + return new MWirelessNetworkInterface( n ); +} + +//--------------------------------------------------------------------------- +// class NetworkInterface +// + +MNetworkInterface* MNetwork::getFirstInterface() +{ + enumerateInterfaces(); + InterfaceMapIterator it( interfaces ); + return ( it.count() > 0 ) ? it.toFirst() : 0; +} + +void MNetwork::enumerateInterfaces() +{ + interfaces.clear(); + QString str; + QFile f( procfile ); + f.open( IO_ReadOnly ); + QTextStream s( &f ); + s.readLine(); + s.readLine(); + while ( !s.atEnd() ) + { + s >> str; + str.truncate( str.find( ':' ) ); + qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); + interfaces.insert( str, createInterface( str ) ); + s.readLine(); + } +} + +MNetworkInterface* MNetwork::createInterface( const char* n ) const +{ + return new MNetworkInterface( n ); +} 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 @@ +/********************************************************************** +** MNetwork* classes +** +** Encapsulates network information +** +** Copyright (C) 2002, Michael Lauer +** mickey@tm.informatik.uni-frankfurt.de +** http://www.Vanille.de +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#ifndef NETWORKINFO_H +#define NETWORKINFO_H + +#include <qstring.h> +#include <qdict.h> + +//--------------------------------------------------------------------------- +// class MNetworkInterface +// + +class MNetworkInterface +{ +public: + + MNetworkInterface( const char* name = "eth0" ); + virtual ~MNetworkInterface(); + + bool isLoopback() { return isLoopbackInterface; }; + const QString& getName() { return name; }; + + virtual void updateStatistics(); + +protected: + + int fd; + const QString name; + bool isLoopbackInterface; + bool isIrda; + bool isTunnel; +}; + +//--------------------------------------------------------------------------- +// class MWirelessNetworkInterface +// + +class MWirelessNetworkInterface : public MNetworkInterface +{ +public: + MWirelessNetworkInterface( const char* name = "wlan0" ); + virtual ~MWirelessNetworkInterface(); + + int noisePercent(); + int qualityPercent(); + int signalPercent(); + + QString APAddr; + QString essid; + QString mode; + QString nick; + QString rate; + double freq; + int channel; + + virtual void updateStatistics(); + +private: + int quality; + int signal; + int noise; + + bool hasWirelessExtensions; +}; + +//--------------------------------------------------------------------------- +// class MNetwork +// + +class MNetwork +{ +public: + MNetwork(); + virtual ~MNetwork(); + + typedef QDict<MNetworkInterface> InterfaceMap; + typedef QDictIterator<MNetworkInterface> InterfaceMapIterator; + + bool hasInterfaces() const { return interfaces.isEmpty(); }; + int numInterfaces() const { return interfaces.count(); }; + + MNetworkInterface* getFirstInterface(); + +protected: + QString procfile; + InterfaceMap interfaces; + + virtual MNetworkInterface* createInterface( const char* name ) const; + +private: + void enumerateInterfaces(); +}; + +//--------------------------------------------------------------------------- +// class MWirelessNetwork +// + +class MWirelessNetwork : public MNetwork +{ +public: + MWirelessNetwork(); + virtual ~MWirelessNetwork(); + +protected: + virtual MNetworkInterface* createInterface( const char* name ) + const; +}; + +#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 @@ +static char * nowireless_xpm[] = { +"14 14 6 1", +" c None", +". c #FFFFFF", +"+ c #848284", +"@ c #000000", +"# c #FF0000", +"$ c #C6C3C6", +" ", +" ", +" ", +" +@+ ", +" # $#@ ", +" ####@+ ", +" ## + ", +" ####@ ", +" # #@+ ", +" # +#@ ", +" +@@ ", +" +$@@+ ", +" +$@@@ ", +" +$@@@ "}; 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 @@ +Files: plugins/applets/libwirelessapplet.so* +Priority: optional +Section: opie/system +Maintainer: Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> +Architecture: arm +Version: $QPE_VERSION-$SUB_VERSION.1 +Depends: opie-base ($QPE_VERSION) +Description: Wireless Applet + 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 @@ +#!/bin/sh +/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 @@ +#!/bin/sh +/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 @@ +/********************************************************************** +** Copyright (C) 2002 Michael 'Mickey' Lauer +** <mickey@tm.informatik.uni-frankfurt.de> +** http://www.Vanille.de +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#include "wireless.h" + +#include <qapplication.h> +#include <qpe/qpeapplication.h> + +#include <qpoint.h> +#include <qradiobutton.h> +#include <qcheckbox.h> +#include <qpainter.h> +#include <qlabel.h> +#include <qslider.h> +#include <qbuttongroup.h> +#include <qlayout.h> +#include <qframe.h> +#include <qpixmap.h> +#include <qstring.h> +#include <qfile.h> + +#include "networkinfo.h" +#include "mgraph.h" + +#include "connect0.xpm" +#include "connect1.xpm" +#include "connect2.xpm" +#include "connect3.xpm" +#include "connect4.xpm" +#include "connect5.xpm" +#include "nowireless.xpm" + +#define STYLE_BARS 0 +#define STYLE_ANTENNA 1 + +WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) + : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) +{ + + setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); + QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" ); + + /* status label */ + + statusLabel = new QLabel( this, "statuslabel" ); + QString text( "Wireless Status:<br>" + "*** Unknown ***<br>" + "Card not inserted ?<br>" + "Or Sharp ROM ?<br>" + "CELL: 00:00:00:00:00:00" ); +/* QString text( "Station: Unknown<br>" + "ESSID: Unknown<br>" + "MODE: Unknown<br>" + "FREQ: Unknown<br>" + "CELL: AA:BB:CC:DD:EE:FF" ); */ + statusLabel->setText( text ); + statusLabel->setFixedSize( statusLabel->sizeHint() ); + grid->addWidget( statusLabel, 0, 0 ); + + /* visualization group box */ + + QButtonGroup* group = new QButtonGroup( 1, Qt::Horizontal, "Visualization", this ); + QRadioButton* r1 = new QRadioButton( "Color Bars", group ); + QRadioButton* r2 = new QRadioButton( "Antenna", group ); + r1->setFocusPolicy( QWidget::NoFocus ); + r2->setFocusPolicy( QWidget::NoFocus ); + group->setFocusPolicy( QWidget::NoFocus ); + group->setButton( STYLE_ANTENNA ); + grid->addWidget( group, 0, 1 ); + + /* quality graph */ + + mgraph = new MGraph( this ); + mgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + mgraph->setMin( 0 ); + mgraph->setMax( 92 ); + grid->addWidget( mgraph, 1, 0 ); + mgraph->setFocusPolicy( QWidget::NoFocus ); + + /* dhcp renew CheckBox */ + + //FIXME: under construction + //QCheckBox* dhcpCheckBox = new QCheckBox( "DHCP renew", this ); + //dhcpCheckBox->setFocusPolicy( QWidget::NoFocus ); + //grid->addWidget( dhcpCheckBox, 2, 0, Qt::AlignCenter ); + + /* update Frequency Label */ + + updateLabel = new QLabel( this ); + updateLabel->setText( "Update every 500 ms" ); + grid->addWidget( updateLabel, 2, 1 ); + + /* update Frequency Slider */ + + QSlider* updateSlider = new QSlider( QSlider::Horizontal, this ); + updateSlider->setRange( 50, 999 ); + updateSlider->setValue( 500 ); + updateSlider->setTickmarks( QSlider::Both ); + updateSlider->setTickInterval( 100 ); + updateSlider->setSteps( 50, 50 ); + updateSlider->setFocusPolicy( QWidget::NoFocus ); + grid->addWidget( updateSlider, 1, 1 ); + connect( updateSlider, SIGNAL( valueChanged( int ) ), + this, SLOT( updateDelayChange( int ) ) ); + + setFixedSize( sizeHint() ); + setFocusPolicy( QWidget::NoFocus ); + + connect( group, SIGNAL( clicked( int ) ), + applet, SLOT( styleChange( int ) ) ); + +} + +void WirelessControl::updateDelayChange( int delay ) +{ + QString text; + text.sprintf( "Update every %3d ms", delay ); + updateLabel->setText( text ); + applet->updateDelayChange( delay ); +} + +void WirelessControl::show ( bool ) +{ + QPoint curPos = applet->mapToGlobal( QPoint ( 0, 0 ) ); + + int w = sizeHint().width(); + int x = curPos.x() - ( w / 2 ); + + if ( ( x + w ) > QPEApplication::desktop()->width() ) + x = QPEApplication::desktop ( )-> width ( ) - w; + + move( x, curPos.y () - sizeHint().height () ); + QFrame::show(); +} + + +//=========================================================================== + +WirelessApplet::WirelessApplet( QWidget *parent, const char *name ) + : QWidget( parent, name ), visualStyle( STYLE_ANTENNA ), interface( 0 ) +{ + setFixedHeight( 18 ); + setFixedWidth( 14 ); + status = new WirelessControl( this, 0, "wireless status" ); + + network = new MWirelessNetwork(); + + timer = startTimer( 500 ); +} + +void WirelessApplet::checkInterface() +{ + interface = network->getFirstInterface(); + if ( interface ) + { + qDebug( "WIFIAPPLET: using interface '%s'", (const char*) + interface->getName() ); + } + else + { + qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" ); + } +} + +void WirelessApplet::updateDelayChange( int delay ) +{ + killTimer( timer ); + timer = startTimer( delay ); +} + +WirelessApplet::~WirelessApplet() +{ +} + +void WirelessApplet::styleChange( int style ) +{ + visualStyle = style; + repaint(); +} + +void WirelessApplet::timerEvent( QTimerEvent* ) +{ + MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; + + if ( iface ) + { + iface->updateStatistics(); + if ( mustRepaint() ) + { + //qDebug( "WIFIAPPLET: A value has changed -> repainting." ); + repaint(); + } + + if ( status->isVisible() ) + updatePopupWindow(); + } else checkInterface(); +} + +void WirelessApplet::mousePressEvent( QMouseEvent *) +{ + if ( status->isVisible() ) + status->hide(); + else + status->show( true ); +} + +bool WirelessApplet::mustRepaint() +{ + MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; + + // check if there are enough changes to justify a (flickering) repaint + + // has the interface changed? + + if ( iface != oldiface ) + { + oldiface = iface; + return true; + } + + const char** pixmap = getQualityPixmap(); + + if ( pixmap && ( pixmap != oldpixmap ) ) + { + oldpixmap = pixmap; + return true; + } + + int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; + int signalH = iface->signalPercent() * ( height() - 3 ) / 100; + int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; + + if ( ( noiseH != oldnoiseH ) + || ( signalH != oldsignalH ) + || ( qualityH != oldqualityH ) ) + { + oldnoiseH = noiseH; + oldsignalH = signalH; + oldqualityH = qualityH; + return true; + } + + return false; +} + +void WirelessApplet::updatePopupWindow() +{ + MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; + int qualityH = iface->qualityPercent(); + + if ( status->mgraph ) + status->mgraph->addValue( qualityH, false ); + + QString freqString; + QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; + freqString.sprintf( "%.3f GHz", iface->freq ); + status->statusLabel->setText( "Station: " + iface->nick + "<br>" + + "ESSID: " + iface->essid + "<br>" + + "MODE: " + iface->mode + "<br>" + + "FREQ: " + freqString + "<br>" + + cell + " " + iface->APAddr ); +} + +const char** WirelessApplet::getQualityPixmap() +{ + MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; + + if ( !iface ) return ( const char** ) nowireless_xpm; + int qualityH = iface->qualityPercent(); + if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; + + if ( visualStyle == STYLE_ANTENNA ) + { + if ( qualityH < 1 ) return ( const char** ) connect0_xpm; + if ( qualityH < 17 ) return ( const char** ) connect1_xpm; + if ( qualityH < 34 ) return ( const char** ) connect2_xpm; + if ( qualityH < 50 ) return ( const char** ) connect3_xpm; + if ( qualityH < 65 ) return ( const char** ) connect4_xpm; + return ( const char** ) connect5_xpm; + } + + return 0; // please draw your bars +} + +void WirelessApplet::paintEvent( QPaintEvent* ) +{ + MWirelessNetworkInterface* iface = ( MWirelessNetworkInterface* ) interface; + + QPainter p(this); + QColor color; + + const char** pixmap = getQualityPixmap(); + + if ( pixmap ) + p.drawPixmap( 0, 1, pixmap ); + else + { + + int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; + int signalH = iface->signalPercent() * ( height() - 3 ) / 100; + int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; + + double intensity; + int pixelHeight; + int pixelWidth = 2; + int Hue; + int barSpace = 3; + int leftoffset = 0; + int bottomoffset = 2; + + // draw noise indicator + pixelHeight = noiseH; + Hue = 50; + for ( int i = 0; i < pixelHeight; ++i ) + { + intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; + color.setHsv( Hue, 255, intensity ); + p.setPen ( color ); + p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); + } + + // draw signal indicator + pixelHeight = signalH; + Hue = 100; + leftoffset += pixelWidth + barSpace; + for ( int i = 0; i < pixelHeight; ++i ) + { + intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; + color.setHsv( Hue, 255, intensity ); + p.setPen ( color ); + p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); + } + + // draw quality indicator + pixelHeight = qualityH; + Hue = 250; + leftoffset += pixelWidth + barSpace; + for ( int i = 0; i < pixelHeight; ++i ) + { + intensity = 50 + ( (double) i / (double) pixelHeight ) * 205; + color.setHsv( Hue, 255, intensity ); + p.setPen ( color ); + p.drawLine( leftoffset, height()-bottomoffset-i, pixelWidth+leftoffset, height()-bottomoffset-i ); + } + } +} 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 @@ +/********************************************************************** +** Copyright (C) 2002 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> +** All rights reserved. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#ifndef __WIRELESS_APPLET_H__ +#define __WIRELESS_APPLET_H__ + +#include <qwidget.h> +#include <qframe.h> +#include <qpixmap.h> + +class MNetwork; +class MWirelessNetwork; +class MNetworkInterface; +class MWirelessNetworkInterface; +class Y; +class QLabel; +class WirelessApplet; +class MGraph; + +class WirelessControl : public QFrame +{ + Q_OBJECT +public: + WirelessControl( WirelessApplet* icon, QWidget *parent=0, const char *name=0 ); + void show( bool ); + + MGraph* mgraph; + QLabel* statusLabel; + QLabel* updateLabel; + +public slots: + void updateDelayChange( int ); + +private: + WirelessApplet* applet; +}; + +class WirelessApplet : public QWidget +{ + Q_OBJECT +public: + WirelessApplet( QWidget *parent = 0, const char *name=0 ); + ~WirelessApplet(); + WirelessControl* status; + + virtual void timerEvent( QTimerEvent* ); + void updateDelayChange( int delay ); + +public slots: + void styleChange( int ); + +private: + void mousePressEvent( QMouseEvent * ); + void paintEvent( QPaintEvent* ); + void checkInterface(); + + bool mustRepaint(); + void updatePopupWindow(); + const char** getQualityPixmap(); + +private: + QPixmap snapshotPixmap; + int visualStyle; + int timer; + + MWirelessNetwork* network; + MNetworkInterface* interface; + +private: + const char** oldpixmap; + MWirelessNetworkInterface* oldiface; + int oldqualityH; + int oldsignalH; + int oldnoiseH; +}; + +#endif // __WIRELESS_APPLET_H__ + 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include "wireless.h" +#include "wirelessappletimpl.h" + + +WirelessAppletImpl::WirelessAppletImpl() + : wireless(0), ref(0) +{ +} + +WirelessAppletImpl::~WirelessAppletImpl() +{ + delete wireless; +} + +QWidget *WirelessAppletImpl::applet( QWidget *parent ) +{ + if ( !wireless ) + wireless = new WirelessApplet( parent ); + return wireless; +} + +int WirelessAppletImpl::position() const +{ + return 6; +} + +QRESULT WirelessAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) +{ + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = this; + else if ( uuid == IID_TaskbarApplet ) + *iface = this; + + if ( *iface ) + (*iface)->addRef(); + return QS_OK; +} + +Q_EXPORT_INTERFACE() +{ + Q_CREATE_INSTANCE( WirelessAppletImpl ) +} + + 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef WIRELESSAPPLETIMPL_H +#define WIRELESSAPPLETIMPL_H + +#include <qpe/taskbarappletinterface.h> + +class WirelessApplet; + +class WirelessAppletImpl : public TaskbarAppletInterface +{ +public: + WirelessAppletImpl(); + virtual ~WirelessAppletImpl(); + + QRESULT queryInterface( const QUuid&, QUnknownInterface** ); + Q_REFCOUNT + + virtual QWidget *applet( QWidget *parent ); + virtual int position() const; + +private: + WirelessApplet *wireless; + ulong ref; +}; + +#endif |