-rw-r--r-- | noncore/settings/networksettings2/networksettings2/netnode.cpp | 6 |
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,331 +1,337 @@ | |||
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 | ||
16 | QString & deQuote( QString & X ) { | 19 | QString & 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 | ||
34 | QString quote( QString X ) { | 37 | QString 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 | ||
51 | // | 54 | // |
52 | // | 55 | // |
53 | // ANETNODE | 56 | // ANETNODE |
54 | // | 57 | // |
55 | // | 58 | // |
56 | 59 | ||
57 | void ANetNode::saveAttributes( QTextStream & TS ) { | 60 | void ANetNode::saveAttributes( QTextStream & TS ) { |
58 | saveSpecificAttribute( TS ); | 61 | saveSpecificAttribute( TS ); |
59 | } | 62 | } |
60 | 63 | ||
61 | void ANetNode::setAttribute( QString & Attr, QString & Value ){ | 64 | void ANetNode::setAttribute( QString & Attr, QString & Value ){ |
62 | setSpecificAttribute( Attr, Value ); | 65 | setSpecificAttribute( Attr, Value ); |
63 | } | 66 | } |
64 | 67 | ||
65 | // | 68 | // |
66 | // | 69 | // |
67 | // ANETNODEINSTANCE | 70 | // ANETNODEINSTANCE |
68 | // | 71 | // |
69 | // | 72 | // |
70 | 73 | ||
71 | long ANetNodeInstance::InstanceCounter = -1; | 74 | long ANetNodeInstance::InstanceCounter = -1; |
72 | 75 | ||
73 | void ANetNodeInstance::initialize( void ) { | 76 | void ANetNodeInstance::initialize( void ) { |
74 | if( InstanceCounter == -1 ) | 77 | if( InstanceCounter == -1 ) |
75 | InstanceCounter = time(0); | 78 | InstanceCounter = time(0); |
76 | // set name | 79 | // set name |
77 | QString N; | 80 | QString N; |
78 | N.sprintf( "-%ld", InstanceCounter++ ); | 81 | N.sprintf( "-%ld", InstanceCounter++ ); |
79 | N.prepend( NodeType->name() ); | 82 | N.prepend( NodeType->name() ); |
80 | setName( N.latin1() ); | 83 | setName( N.latin1() ); |
81 | } | 84 | } |
82 | 85 | ||
83 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ | 86 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ |
84 | if( Attr == "name" ) { | 87 | if( Attr == "name" ) { |
85 | setName( Value.latin1() ); | 88 | setName( Value.latin1() ); |
86 | } else { | 89 | } else { |
87 | setSpecificAttribute( Attr, Value ); | 90 | setSpecificAttribute( Attr, Value ); |
88 | } | 91 | } |
89 | } | 92 | } |
90 | 93 | ||
91 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { | 94 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { |
92 | TS << "name=" << name() << endl; | 95 | TS << "name=" << name() << endl; |
93 | saveSpecificAttribute( TS ); | 96 | saveSpecificAttribute( TS ); |
94 | } | 97 | } |
95 | 98 | ||
96 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { | 99 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { |
97 | return connection()->findNext( this ); | 100 | return connection()->findNext( this ); |
98 | } | 101 | } |
99 | 102 | ||
100 | // | 103 | // |
101 | // | 104 | // |
102 | // NODECOLLECTION | 105 | // NODECOLLECTION |
103 | // | 106 | // |
104 | // | 107 | // |
105 | 108 | ||
106 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { | 109 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { |
107 | IsModified = 0; | 110 | IsModified = 0; |
108 | Index = -1; | 111 | Index = -1; |
109 | Name=""; | 112 | Name=""; |
110 | IsNew = 1; | 113 | IsNew = 1; |
111 | CurrentState = Unchecked; | 114 | CurrentState = Unchecked; |
112 | } | 115 | } |
113 | 116 | ||
114 | NodeCollection::NodeCollection( QTextStream & TS ) : | 117 | NodeCollection::NodeCollection( QTextStream & TS ) : |
115 | QList<ANetNodeInstance>() { | 118 | QList<ANetNodeInstance>() { |
116 | long idx; | 119 | long idx; |
117 | bool InError = 0; | 120 | bool InError = 0; |
118 | QString S, A, N; | 121 | QString S, A, N; |
119 | IsModified = 0; | 122 | IsModified = 0; |
120 | Index = -1; | 123 | Index = -1; |
121 | Name=""; | 124 | Name=""; |
122 | IsNew = 0; | 125 | IsNew = 0; |
123 | CurrentState = Unchecked; | 126 | CurrentState = Unchecked; |
124 | 127 | ||
125 | do { | 128 | do { |
126 | S = TS.readLine(); | 129 | S = TS.readLine(); |
127 | if( S.isEmpty() ) { | 130 | if( S.isEmpty() ) { |
128 | if( InError ) { | 131 | if( InError ) { |
129 | // remove all nodes | 132 | // remove all nodes |
130 | clear(); | 133 | clear(); |
131 | } | 134 | } |
132 | // empty line | 135 | // empty line |
133 | break; | 136 | break; |
134 | } | 137 | } |
135 | 138 | ||
136 | idx = S.find('='); | 139 | idx = S.find('='); |
137 | S.stripWhiteSpace(); | 140 | S.stripWhiteSpace(); |
138 | A = S.left( idx ); | 141 | A = S.left( idx ); |
139 | A.lower(); | 142 | A.lower(); |
140 | N = S.mid( idx+1, S.length() ); | 143 | N = S.mid( idx+1, S.length() ); |
141 | N.stripWhiteSpace(); | 144 | N.stripWhiteSpace(); |
142 | N = deQuote( N ); | 145 | N = deQuote( N ); |
143 | 146 | ||
144 | if( A == "name" ) { | 147 | if( A == "name" ) { |
145 | Name = N; | 148 | Name = N; |
146 | } else if( A == "number" ) { | 149 | } else if( A == "number" ) { |
147 | Log(( "Profile number %s\n", N.latin1() )); | 150 | Log(( "Profile number %s\n", N.latin1() )); |
148 | setNumber( N.toLong() ); | 151 | setNumber( N.toLong() ); |
149 | } else if( A == "node" ) { | 152 | } else if( A == "node" ) { |
150 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); | 153 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); |
151 | if( NNI && ! InError ) { | 154 | if( NNI && ! InError ) { |
152 | append( NSResources->findNodeInstance( N ) ); | 155 | append( NSResources->findNodeInstance( N ) ); |
153 | } else { | 156 | } else { |
154 | // could not find a node type -> collection invalid | 157 | // could not find a node type -> collection invalid |
155 | InError = 1; | 158 | InError = 1; |
156 | } | 159 | } |
157 | } | 160 | } |
158 | } while( 1 ); | 161 | } while( 1 ); |
159 | } | 162 | } |
160 | 163 | ||
161 | 164 | ||
162 | NodeCollection::~NodeCollection( void ) { | 165 | NodeCollection::~NodeCollection( void ) { |
163 | } | 166 | } |
164 | 167 | ||
165 | const QString & NodeCollection::description( void ) { | 168 | const QString & NodeCollection::description( void ) { |
166 | ANetNodeInstance * NNI = getToplevel(); | 169 | ANetNodeInstance * NNI = getToplevel(); |
167 | return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; | 170 | return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; |
168 | } | 171 | } |
169 | 172 | ||
170 | void NodeCollection::append( ANetNodeInstance * NNI ) { | 173 | void NodeCollection::append( ANetNodeInstance * NNI ) { |
171 | NNI->setConnection( this ); | 174 | NNI->setConnection( this ); |
172 | QList<ANetNodeInstance>::append( NNI ); | 175 | QList<ANetNodeInstance>::append( NNI ); |
173 | } | 176 | } |
174 | 177 | ||
175 | void NodeCollection::save( QTextStream & TS ) { | 178 | void NodeCollection::save( QTextStream & TS ) { |
176 | 179 | ||
177 | TS << "name=" << quote( Name ) << endl; | 180 | TS << "name=" << quote( Name ) << endl; |
178 | TS << "number=" << number() << endl; | 181 | TS << "number=" << number() << endl; |
179 | ANetNodeInstance * NNI; | 182 | ANetNodeInstance * NNI; |
180 | for( QListIterator<ANetNodeInstance> it(*this); | 183 | for( QListIterator<ANetNodeInstance> it(*this); |
181 | it.current(); | 184 | it.current(); |
182 | ++it ) { | 185 | ++it ) { |
183 | NNI = it.current(); | 186 | NNI = it.current(); |
184 | TS << "node=" << NNI->name() << endl; | 187 | TS << "node=" << NNI->name() << endl; |
185 | } | 188 | } |
186 | TS << endl; | 189 | TS << endl; |
187 | IsNew = 0; | 190 | IsNew = 0; |
188 | } | 191 | } |
189 | 192 | ||
190 | ANetNodeInstance * NodeCollection::getToplevel( void ) { | 193 | ANetNodeInstance * NodeCollection::getToplevel( void ) { |
191 | ANetNodeInstance * NNI = 0; | 194 | ANetNodeInstance * NNI = 0; |
192 | for( QListIterator<ANetNodeInstance> it(*this); | 195 | for( QListIterator<ANetNodeInstance> it(*this); |
193 | it.current(); | 196 | it.current(); |
194 | ++it ) { | 197 | ++it ) { |
195 | NNI = it.current(); | 198 | NNI = it.current(); |
196 | if( NNI->nodeClass()->isToplevel() ) | 199 | if( NNI->nodeClass()->isToplevel() ) |
197 | break; | 200 | break; |
198 | } | 201 | } |
199 | return NNI; | 202 | return NNI; |
200 | } | 203 | } |
201 | 204 | ||
202 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { | 205 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { |
203 | ANetNodeInstance * NNI = 0; | 206 | ANetNodeInstance * NNI = 0; |
204 | for( QListIterator<ANetNodeInstance> it(*this); | 207 | for( QListIterator<ANetNodeInstance> it(*this); |
205 | it.current(); | 208 | it.current(); |
206 | ++it ) { | 209 | ++it ) { |
207 | NNI = it.current(); | 210 | NNI = it.current(); |
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 | ||
214 | ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { | 217 | ANetNodeInstance * 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 | ||
232 | int NodeCollection::compareItems( QCollection::Item I1, | 235 | int 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 | ||
240 | static char * State2PixmapTbl[] = { | 243 | static 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 | ||
250 | QPixmap NodeCollection::devicePixmap( void ) { | 253 | QPixmap 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 | ||
264 | QPixmap NodeCollection::statePixmap( State_t S) { | 270 | QPixmap NodeCollection::statePixmap( State_t S) { |
265 | return NSResources->getPixmap( State2PixmapTbl[S] ); | 271 | return NSResources->getPixmap( State2PixmapTbl[S] ); |
266 | } | 272 | } |
267 | 273 | ||
268 | QString NodeCollection::stateName( State_t S) { | 274 | QString 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 | ||
289 | void NodeCollection::reassign( void ) { | 295 | void 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 | ||
297 | bool NodeCollection::triggersVPN() { | 303 | bool NodeCollection::triggersVPN() { |
298 | return getToplevel()->runtime()->asFullSetup()->triggersVPN(); | 304 | return getToplevel()->runtime()->asFullSetup()->triggersVPN(); |
299 | } | 305 | } |
300 | 306 | ||
301 | bool NodeCollection::hasDataForFile( const QString & S ) { | 307 | bool NodeCollection::hasDataForFile( const QString & S ) { |
302 | return ( firstWithDataForFile( S ) != 0 ); | 308 | return ( firstWithDataForFile( S ) != 0 ); |
303 | } | 309 | } |
304 | 310 | ||
305 | ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) { | 311 | ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) { |
306 | for( QListIterator<ANetNodeInstance> it(*this); | 312 | for( QListIterator<ANetNodeInstance> it(*this); |
307 | it.current(); | 313 | it.current(); |
308 | ++it ) { | 314 | ++it ) { |
309 | if( it.current()->hasDataForFile( S ) ) { | 315 | if( it.current()->hasDataForFile( S ) ) { |
310 | Log(( "Node %s has data for %s\n", | 316 | Log(( "Node %s has data for %s\n", |
311 | it.current()->nodeClass()->name(), | 317 | it.current()->nodeClass()->name(), |
312 | S.latin1() )); | 318 | S.latin1() )); |
313 | return it.current(); | 319 | return it.current(); |
314 | } | 320 | } |
315 | } | 321 | } |
316 | return 0; | 322 | return 0; |
317 | } | 323 | } |
318 | 324 | ||
319 | // | 325 | // |
320 | // | 326 | // |
321 | // RUNTIMEINFO | 327 | // RUNTIMEINFO |
322 | // | 328 | // |
323 | // | 329 | // |
324 | 330 | ||
325 | InterfaceInfo * RuntimeInfo::assignedInterface( void ) { | 331 | InterfaceInfo * RuntimeInfo::assignedInterface( void ) { |
326 | return netNode()->nextNode()->runtime()->assignedInterface(); | 332 | return netNode()->nextNode()->runtime()->assignedInterface(); |
327 | } | 333 | } |
328 | 334 | ||
329 | AsDevice * RuntimeInfo::device( void ) { | 335 | AsDevice * RuntimeInfo::device( void ) { |
330 | return netNode()->nextNode()->runtime()->device(); | 336 | return netNode()->nextNode()->runtime()->device(); |
331 | } | 337 | } |