summaryrefslogtreecommitdiff
path: root/noncore/applets/wirelessapplet/wireless.cpp
Side-by-side diff
Diffstat (limited to 'noncore/applets/wirelessapplet/wireless.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index 0491a86..364f3ad 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -7,53 +7,55 @@
** 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 "mgraph.h"
#include "advancedconfig.h"
/* OPIE */
+#include <opie2/odebug.h>
#include <opie2/onetwork.h>
#include <opie2/otaskbarapplet.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
+using namespace Opie::Core;
+using namespace Opie::Ui;
+using namespace Opie::Net;
/* QT */
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <qpainter.h>
#include <qlabel.h>
#include <qslider.h>
#include <qbuttongroup.h>
#include <qlayout.h>
#include <qfile.h>
#include <qtextstream.h>
/* STD */
#include <math.h>
#include <sys/types.h>
#include <signal.h>
#if defined (__GNUC__) && (__GNUC__ < 3)
#define round qRound
#endif
//#define MDEBUG
#undef MDEBUG
-using namespace Opie::Ui;
-using namespace Opie::Net;
WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name )
: QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
{
readConfig();
writeConfigEntry( "UpdateFrequency", updateFrequency );
setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
QGridLayout *grid = new QGridLayout( this, 3, 2, 6, 2, "top layout" );
/* status label */
@@ -198,84 +200,84 @@ void WirelessApplet::checkInterface()
ONetwork* net = ONetwork::instance();
net->synchronize();
ONetwork::InterfaceIterator it = net->iterator();
while ( it.current() && !it.current()->isWireless() ) ++it;
if ( it.current() && it.current()->isWireless() )
interface = static_cast<OWirelessNetworkInterface*>( it.current() );
if ( interface )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: using interface '%s'", ( const char* ) interface->name() );
+ odebug << "WIFIAPPLET: using interface '" << ( const char* ) interface->name() << "'" << oendl;
#endif
}
else
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: D'oh! No Wireless interface present... :(" );
+ odebug << "WIFIAPPLET: D'oh! No Wireless interface present... :(" << oendl;
#endif
hide();
}
}
void WirelessApplet::renewDHCP()
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: Going to request a DHCP configuration renew." );
+ odebug << "WIFIAPPLET: Going to request a DHCP configuration renew." << oendl;
#endif
QString pidfile;
if ( !interface )
return ;
QString ifacename( interface->name() );
// At first we are trying dhcpcd
pidfile.sprintf( "/var/run/dhcpcd-%s.pid", ( const char* ) ifacename );
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: dhcpcd pidfile is '%s'", ( const char* ) pidfile );
+ odebug << "WIFIAPPLET: dhcpcd pidfile is '" << ( const char* ) pidfile << "'" << oendl;
#endif
int pid;
QFile pfile( pidfile );
bool hasFile = pfile.open( IO_ReadOnly );
QTextStream s( &pfile );
if ( hasFile )
{
s >> pid;
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: sent SIGALARM to pid %d", pid );
+ odebug << "WIFIAPPLET: sent SIGALARM to pid " << pid << "" << oendl;
#endif
kill( pid, SIGALRM );
return ;
}
// No dhcpcd, so we are trying udhcpc
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: dhcpcd not available." );
+ odebug << "WIFIAPPLET: dhcpcd not available." << oendl;
#endif
pidfile.sprintf( "/var/run/udhcpc.%s.pid", ( const char* ) ifacename );
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: udhcpc pidfile is '%s'", ( const char* ) pidfile );
+ odebug << "WIFIAPPLET: udhcpc pidfile is '" << ( const char* ) pidfile << "'" << oendl;
#endif
QFile pfile2( pidfile );
hasFile = pfile2.open( IO_ReadOnly );
QTextStream s2( &pfile2 );
if ( hasFile )
{
s2 >> pid;
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: sent SIGUSR1 to pid %d", pid );
+ odebug << "WIFIAPPLET: sent SIGUSR1 to pid " << pid << "" << oendl;
#endif
kill( pid, SIGUSR1 );
return ;
}
}
void WirelessApplet::updateDHCPConfig( bool ESSID, bool FREQ, bool AP, bool MODE )
{
rocESSID = ESSID;
rocFREQ = FREQ;
rocAP = AP;
rocMODE = MODE;
@@ -294,42 +296,42 @@ void WirelessApplet::updateDelayChange( int delay )
void WirelessApplet::displayStyleChange( int style )
{
visualStyle = style;
repaint();
}
WirelessApplet::~WirelessApplet()
{}
void WirelessApplet::timerEvent( QTimerEvent* )
{
#ifdef MDEBUG
- qDebug( "WirelessApplet::timerEvent" );
+ odebug << "WirelessApplet::timerEvent" << oendl;
#endif
if ( interface )
{
if ( !ONetwork::instance()->isPresent( (const char*) interface->name() ) )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: Interface no longer present." );
+ odebug << "WIFIAPPLET: Interface no longer present." << oendl;
#endif
interface = 0L;
mustRepaint();
return;
}
if ( mustRepaint() )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: A value has changed -> repainting." );
+ odebug << "WIFIAPPLET: A value has changed -> repainting." << oendl;
#endif
repaint();
}
if ( status->isVisible() )
{
updatePopupWindow();
}
}
else
{
checkInterface();
@@ -347,32 +349,32 @@ void WirelessApplet::mousePressEvent( QMouseEvent * )
bool WirelessApplet::mustRepaint()
{
// check if there are enough changes to justify a (flickering) repaint
// has the interface changed?
if ( interface != oldiface )
{
oldiface = interface;
if ( interface )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: We had no interface but now we have one! :-)" );
+ odebug << "WIFIAPPLET: We had no interface but now we have one! :-)" << oendl;
#endif
show();
}
else
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: We had a interface but now we don't have one! ;-(" );
+ odebug << "WIFIAPPLET: We had a interface but now we don't have one! ;-(" << oendl;
#endif
hide();
return true;
}
}
int rings = numberOfRings();
if ( rings != oldrings )
{
oldrings = rings;
return true;
@@ -386,46 +388,46 @@ bool WirelessApplet::mustRepaint()
|| ( signalH != oldsignalH )
|| ( qualityH != oldqualityH ) )
{
oldnoiseH = noiseH;
oldsignalH = signalH;
oldqualityH = qualityH;
return true;
}
if ( rocESSID && ( oldESSID != interface->SSID() ) )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: ESSID has changed." );
+ odebug << "WIFIAPPLET: ESSID has changed." << oendl;
#endif
renewDHCP();
}
else if ( rocFREQ && ( oldFREQ != interface->frequency() ) )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: FREQ has changed." );
+ odebug << "WIFIAPPLET: FREQ has changed." << oendl;
#endif
renewDHCP();
}
else if ( rocAP && ( oldAP != interface->associatedAP().toString() ) )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: AP has changed." );
+ odebug << "WIFIAPPLET: AP has changed." << oendl;
#endif
renewDHCP();
}
else if ( rocMODE && ( oldMODE != interface->mode() ) )
{
#ifdef MDEBUG
- qDebug( "WIFIAPPLET: MODE has changed." );
+ odebug << "WIFIAPPLET: MODE has changed." << oendl;
#endif
renewDHCP();
}
oldESSID = interface->SSID();
oldMODE = interface->mode();
oldFREQ = interface->frequency();
oldAP = interface->associatedAP().toString();
return false;
}
@@ -441,25 +443,25 @@ void WirelessApplet::updatePopupWindow()
freqString.sprintf( "%.3f GHz", interface->frequency() );
status->statusLabel->setText( "Station: " + interface->nickName() + "<br>" +
"ESSID: " + interface->SSID() + "<br>" +
"MODE: " + interface->mode() + "<br>" +
"FREQ: " + freqString + "<br>" +
cell + " " + interface->associatedAP().toString() );
}
int WirelessApplet::numberOfRings()
{
if ( !interface ) return -1;
int qualityH = interface->signalStrength();
- qDebug( "quality = %d", qualityH );
+ odebug << "quality = " << qualityH << "" << oendl;
if ( qualityH < 1 ) return -1;
if ( qualityH < 20 ) return 0;
if ( qualityH < 40 ) return 1;
if ( qualityH < 60 ) return 2;
if ( qualityH < 65 ) return 3;
return 4;
}
void WirelessApplet::paintEvent( QPaintEvent* )
{
QPainter p( this );
int h = height();
@@ -472,25 +474,25 @@ void WirelessApplet::paintEvent( QPaintEvent* )
p.drawLine( w-m, h-m-1, m, h-m-1 );
int rings = numberOfRings();
if ( rings == -1 )
{
p.setPen( QPen( QColor( 200, 20, 20 ), 2 ) );
p.drawLine( w/2-m-m, h/2-m-m, w/2+m+m, h/2+m+m );
p.drawLine( w/2+m+m, h/2-m-m, w/2-m-m, h/2+m+m );
return;
}
- qDebug( "WirelessApplet: painting %d rings", rings );
+ odebug << "WirelessApplet: painting " << rings << " rings" << oendl;
int radius = 2;
int rstep = 4;
int maxrings = w/rstep;
p.setPen( QColor( 200, 20, 20 ) );
for ( int i = 0; i < rings; ++i )
{
p.drawEllipse( w/2 - radius/2, h/3 - radius/2, radius, radius );
radius += rstep;
};