summaryrefslogtreecommitdiff
authorzecke <zecke>2004-09-27 21:44:42 (UTC)
committer zecke <zecke>2004-09-27 21:44:42 (UTC)
commit9c8f2e26e05be9230ed960d4b4ed21dc658df33e (patch) (unidiff)
treef0c16477d1d25374fb0a983da786ef96839e7db5
parentba463a1029d1c0ff553a3dc9bf544617289d95f0 (diff)
downloadopie-9c8f2e26e05be9230ed960d4b4ed21dc658df33e.zip
opie-9c8f2e26e05be9230ed960d4b4ed21dc658df33e.tar.gz
opie-9c8f2e26e05be9230ed960d4b4ed21dc658df33e.tar.bz2
Do not crash due an empty image
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp
index 4a2440a..110786a 100644
--- a/noncore/settings/networksettings2/networksettings2/netnode.cpp
+++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp
@@ -1,50 +1,53 @@
1#include <time.h> 1#include <time.h>
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qpe/resource.h>
4
5
3#include <qpainter.h> 6#include <qpainter.h>
4#include <qbitmap.h> 7#include <qbitmap.h>
5#include <qtextstream.h> 8#include <qtextstream.h>
6#include <qpixmap.h> 9#include <qpixmap.h>
7 10
8#include "resources.h" 11#include "resources.h"
9#include "netnode.h" 12#include "netnode.h"
10 13
11#include "asdevice.h" 14#include "asdevice.h"
12#include "asline.h" 15#include "asline.h"
13#include "asconnection.h" 16#include "asconnection.h"
14#include "asfullsetup.h" 17#include "asfullsetup.h"
15 18
16QString & deQuote( QString & X ) { 19QString & deQuote( QString & X ) {
17 if( X[0] == '"' ) { 20 if( X[0] == '"' ) {
18 // remove end and trailing "" and \x -> x 21 // remove end and trailing "" and \x -> x
19 QChar R; 22 QChar R;
20 long idx; 23 long idx;
21 idx = X.length()-1; 24 idx = X.length()-1;
22 X = X.mid( 1, idx ); 25 X = X.mid( 1, idx );
23 26
24 idx = 0; 27 idx = 0;
25 while( ( idx = X.find( '\\', idx ) ) >= 0 ) { 28 while( ( idx = X.find( '\\', idx ) ) >= 0 ) {
26 R = X.at( idx + 1 ); 29 R = X.at( idx + 1 );
27 X.replace( idx, 2, &R, 1 ); 30 X.replace( idx, 2, &R, 1 );
28 } 31 }
29 X = X.left( X.length()-1 ); 32 X = X.left( X.length()-1 );
30 } 33 }
31 return X; 34 return X;
32} 35}
33 36
34QString quote( QString X ) { 37QString quote( QString X ) {
35 if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { 38 if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) {
36 // need to quote this 39 // need to quote this
37 QString OutString = "\""; 40 QString OutString = "\"";
38 41
39 X.replace( QRegExp("\""), "\\\"" ); 42 X.replace( QRegExp("\""), "\\\"" );
40 X.replace( QRegExp("\\"), "\\\\" ); 43 X.replace( QRegExp("\\"), "\\\\" );
41 X.replace( QRegExp(" "), "\\ " ); 44 X.replace( QRegExp(" "), "\\ " );
42 45
43 OutString += X; 46 OutString += X;
44 OutString += "\""; 47 OutString += "\"";
45 X = OutString; 48 X = OutString;
46 } 49 }
47 return X; 50 return X;
48} 51}
49 52
50 53
@@ -208,96 +211,99 @@ ANetNodeInstance * NodeCollection::findByName( const QString & S ) {
208 if( NNI->name() == S ) 211 if( NNI->name() == S )
209 break; 212 break;
210 } 213 }
211 return NNI; 214 return NNI;
212} 215}
213 216
214ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { 217ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) {
215 ANetNodeInstance * NNNI; 218 ANetNodeInstance * NNNI;
216 219
217 if( ! NNI ) 220 if( ! NNI )
218 getToplevel(); 221 getToplevel();
219 222
220 for( QListIterator<ANetNodeInstance> it(*this); 223 for( QListIterator<ANetNodeInstance> it(*this);
221 it.current(); 224 it.current();
222 ++it ) { 225 ++it ) {
223 NNNI = it.current(); 226 NNNI = it.current();
224 if( NNNI == NNI ) { 227 if( NNNI == NNI ) {
225 ++it; 228 ++it;
226 return it.current(); 229 return it.current();
227 } 230 }
228 } 231 }
229 return 0; // no more next 232 return 0; // no more next
230} 233}
231 234
232int NodeCollection::compareItems( QCollection::Item I1, 235int NodeCollection::compareItems( QCollection::Item I1,
233 QCollection::Item I2 ) { 236 QCollection::Item I2 ) {
234 ANetNodeInstance * NNI1, * NNI2; 237 ANetNodeInstance * NNI1, * NNI2;
235 NNI1 = (ANetNodeInstance *)I1; 238 NNI1 = (ANetNodeInstance *)I1;
236 NNI2 = (ANetNodeInstance *)I2; 239 NNI2 = (ANetNodeInstance *)I2;
237 return strcmp( NNI1->name(), NNI2->name() ); 240 return strcmp( NNI1->name(), NNI2->name() );
238} 241}
239 242
240static char * State2PixmapTbl[] = { 243static char * State2PixmapTbl[] = {
241 "NULL", // Unchecked : no pixmap 244 "NULL", // Unchecked : no pixmap
242 "check", // Unknown 245 "check", // Unknown
243 "delete", // unavailable 246 "delete", // unavailable
244 "disabled", // disabled 247 "disabled", // disabled
245 "off", // off 248 "off", // off
246 "disconnected", // available 249 "disconnected", // available
247 "connected" // up 250 "connected" // up
248}; 251};
249 252
250QPixmap NodeCollection::devicePixmap( void ) { 253QPixmap NodeCollection::devicePixmap( void ) {
251 QPixmap pm = NSResources->getPixmap( 254 QPixmap pm = NSResources->getPixmap(
252 getToplevel()->nextNode()->pixmapName()+"-large"); 255 getToplevel()->nextNode()->pixmapName()+"-large");
253 256
254 QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() ); 257 QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() );
255 258
259 if( pm.isNull() || Mini.isNull() )
260 return Resource::loadPixmap("Unknown");
261
256 QPainter painter( &pm ); 262 QPainter painter( &pm );
257 painter.drawPixmap( pm.width()-Mini.width(), 263 painter.drawPixmap( pm.width()-Mini.width(),
258 pm.height()-Mini.height(), 264 pm.height()-Mini.height(),
259 Mini ); 265 Mini );
260 pm.setMask( pm.createHeuristicMask( TRUE ) ); 266 pm.setMask( pm.createHeuristicMask( TRUE ) );
261 return pm; 267 return pm;
262} 268}
263 269
264QPixmap NodeCollection::statePixmap( State_t S) { 270QPixmap NodeCollection::statePixmap( State_t S) {
265 return NSResources->getPixmap( State2PixmapTbl[S] ); 271 return NSResources->getPixmap( State2PixmapTbl[S] );
266} 272}
267 273
268QString NodeCollection::stateName( State_t S) { 274QString NodeCollection::stateName( State_t S) {
269 switch( S ) { 275 switch( S ) {
270 case Unknown : 276 case Unknown :
271 return qApp->translate( "networksettings2", "Unknown"); 277 return qApp->translate( "networksettings2", "Unknown");
272 case Unavailable : 278 case Unavailable :
273 return qApp->translate( "networksettings2", "Unavailable"); 279 return qApp->translate( "networksettings2", "Unavailable");
274 case Disabled : 280 case Disabled :
275 return qApp->translate( "networksettings2", "Disabled"); 281 return qApp->translate( "networksettings2", "Disabled");
276 case Off : 282 case Off :
277 return qApp->translate( "networksettings2", "Off"); 283 return qApp->translate( "networksettings2", "Off");
278 case Available : 284 case Available :
279 return qApp->translate( "networksettings2", "Available"); 285 return qApp->translate( "networksettings2", "Available");
280 case IsUp : 286 case IsUp :
281 return qApp->translate( "networksettings2", "IsUp"); 287 return qApp->translate( "networksettings2", "IsUp");
282 case Unchecked : /* FT */ 288 case Unchecked : /* FT */
283 default : 289 default :
284 break; 290 break;
285 } 291 }
286 return QString(""); 292 return QString("");
287} 293}
288 294
289void NodeCollection::reassign( void ) { 295void NodeCollection::reassign( void ) {
290 for( QListIterator<ANetNodeInstance> it(*this); 296 for( QListIterator<ANetNodeInstance> it(*this);
291 it.current(); 297 it.current();
292 ++it ) { 298 ++it ) {
293 it.current()->setConnection( this ); 299 it.current()->setConnection( this );
294 } 300 }
295} 301}
296 302
297bool NodeCollection::triggersVPN() { 303bool NodeCollection::triggersVPN() {
298 return getToplevel()->runtime()->asFullSetup()->triggersVPN(); 304 return getToplevel()->runtime()->asFullSetup()->triggersVPN();
299} 305}
300 306
301bool NodeCollection::hasDataForFile( const QString & S ) { 307bool NodeCollection::hasDataForFile( const QString & S ) {
302 return ( firstWithDataForFile( S ) != 0 ); 308 return ( firstWithDataForFile( S ) != 0 );
303} 309}