summaryrefslogtreecommitdiff
path: root/noncore/applets/wirelessapplet/networkinfo.cpp
Unidiff
Diffstat (limited to 'noncore/applets/wirelessapplet/networkinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp
index 22d7d83..8531fd5 100644
--- a/noncore/applets/wirelessapplet/networkinfo.cpp
+++ b/noncore/applets/wirelessapplet/networkinfo.cpp
@@ -48,12 +48,14 @@
48#define IW_UPPER 220 48#define IW_UPPER 220
49#define IW_LOWER 140 49#define IW_LOWER 140
50 50
51#define PROCNETDEV "/proc/net/dev" 51#define PROCNETDEV "/proc/net/dev"
52#define PROCNETWIRELESS "/proc/net/wireless" 52#define PROCNETWIRELESS "/proc/net/wireless"
53 53
54#define MDEBUG 0
55
54//--------------------------------------------------------------------------- 56//---------------------------------------------------------------------------
55// class MNetworkInterface 57// class MNetworkInterface
56// 58//
57 59
58MNetworkInterface::MNetworkInterface( const char* name ) 60MNetworkInterface::MNetworkInterface( const char* name )
59 :name( name ) 61 :name( name )
@@ -66,14 +68,15 @@ MNetworkInterface::MNetworkInterface( const char* name )
66MNetworkInterface::~MNetworkInterface() 68MNetworkInterface::~MNetworkInterface()
67{ 69{
68 if ( fd != -1 ) 70 if ( fd != -1 )
69 close( fd ); 71 close( fd );
70} 72}
71 73
72void MNetworkInterface::updateStatistics() 74bool MNetworkInterface::updateStatistics()
73{ 75{
76 return true;
74} 77}
75 78
76//--------------------------------------------------------------------------- 79//---------------------------------------------------------------------------
77// class MWirelessNetworkInterface 80// class MWirelessNetworkInterface
78// 81//
79 82
@@ -101,15 +104,17 @@ int MWirelessNetworkInterface::signalPercent()
101 104
102int MWirelessNetworkInterface::noisePercent() 105int MWirelessNetworkInterface::noisePercent()
103{ 106{
104 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; 107 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
105} 108}
106 109
107void MWirelessNetworkInterface::updateStatistics() 110bool MWirelessNetworkInterface::updateStatistics()
108{ 111{
109 MNetworkInterface::updateStatistics(); 112 bool base = MNetworkInterface::updateStatistics();
113 if ( !base )
114 return false;
110 115
111 const char* buffer[200]; 116 const char* buffer[200];
112 117
113 struct iwreq iwr; 118 struct iwreq iwr;
114 memset( &iwr, 0, sizeof( iwr ) ); 119 memset( &iwr, 0, sizeof( iwr ) );
115 iwr.u.essid.pointer = (caddr_t) buffer; 120 iwr.u.essid.pointer = (caddr_t) buffer;
@@ -178,57 +183,64 @@ void MWirelessNetworkInterface::updateStatistics()
178 { 183 {
179 wstream.readLine(); // skip the first two lines 184 wstream.readLine(); // skip the first two lines
180 wstream.readLine(); // because they only contain headers 185 wstream.readLine(); // because they only contain headers
181 } 186 }
182 if ( ( !hasFile ) || ( wstream.atEnd() ) ) 187 if ( ( !hasFile ) || ( wstream.atEnd() ) )
183 { 188 {
189#ifdef MDEBUG
184 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); 190 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." );
191#endif
185 quality = -1; 192 quality = -1;
186 signal = IW_LOWER; 193 signal = IW_LOWER;
187 noise = IW_LOWER; 194 noise = IW_LOWER;
188 return; 195 return false;
189 } 196 }
190 197
191 wstream >> name >> status >> quality >> c >> signal >> c >> noise; 198 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
192 199
193 if ( quality > 92 ) 200 if ( quality > 92 )
201#ifdef MDEBUG
194 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); 202 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
203#endif
195 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) 204 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
205#ifdef MDEBUG
196 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); 206 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
207#endif
197 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) 208 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
209#ifdef MDEBUG
198 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); 210 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
211#endif
212
213 return true;
214
199} 215}
200 216
201//--------------------------------------------------------------------------- 217//---------------------------------------------------------------------------
202// class Network 218// class Network
203// 219//
204 220
205MNetwork::MNetwork() 221MNetwork::MNetwork()
206{ 222{
207 //qDebug( "MNetwork::MNetwork()" );
208 procfile = PROCNETDEV; 223 procfile = PROCNETDEV;
209} 224}
210 225
211MNetwork::~MNetwork() 226MNetwork::~MNetwork()
212{ 227{
213 //qDebug( "MNetwork::~MNetwork()" );
214} 228}
215 229
216//--------------------------------------------------------------------------- 230//---------------------------------------------------------------------------
217// class WirelessNetwork 231// class WirelessNetwork
218// 232//
219 233
220MWirelessNetwork::MWirelessNetwork() 234MWirelessNetwork::MWirelessNetwork()
221{ 235{
222 //qDebug( "MWirelessNetwork::MWirelessNetwork()" );
223 procfile = PROCNETWIRELESS; 236 procfile = PROCNETWIRELESS;
224} 237}
225 238
226MWirelessNetwork::~MWirelessNetwork() 239MWirelessNetwork::~MWirelessNetwork()
227{ 240{
228 //qDebug( "MWirelessNetwork::~MWirelessNetwork()" );
229} 241}
230 242
231MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const 243MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const
232{ 244{
233 return new MWirelessNetworkInterface( n ); 245 return new MWirelessNetworkInterface( n );
234} 246}
@@ -256,13 +268,15 @@ void MNetwork::enumerateInterfaces()
256 s.readLine(); 268 s.readLine();
257 s.readLine(); 269 s.readLine();
258 while ( !s.atEnd() ) 270 while ( !s.atEnd() )
259 { 271 {
260 s >> str; 272 s >> str;
261 str.truncate( str.find( ':' ) ); 273 str.truncate( str.find( ':' ) );
274#ifdef MDEBUG
262 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); 275 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str );
276#endif
263 interfaces.insert( str, createInterface( str ) ); 277 interfaces.insert( str, createInterface( str ) );
264 s.readLine(); 278 s.readLine();
265 } 279 }
266} 280}
267 281
268MNetworkInterface* MNetwork::createInterface( const char* n ) const 282MNetworkInterface* MNetwork::createInterface( const char* n ) const