3 files changed, 8 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index 17653bd..f8f2d1e 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp | |||
@@ -1,511 +1,512 @@ | |||
1 | #include <time.h> | 1 | #include <time.h> |
2 | #include <qpe/qpeapplication.h> | 2 | #include <qpe/qpeapplication.h> |
3 | #include <qpe/resource.h> | 3 | #include <qpe/resource.h> |
4 | 4 | ||
5 | #include <qpainter.h> | 5 | #include <qpainter.h> |
6 | #include <qbitmap.h> | 6 | #include <qbitmap.h> |
7 | #include <qtextstream.h> | 7 | #include <qtextstream.h> |
8 | #include <qpixmap.h> | 8 | #include <qpixmap.h> |
9 | 9 | ||
10 | #include "resources.h" | 10 | #include "resources.h" |
11 | #include "netnode.h" | 11 | #include "netnode.h" |
12 | 12 | ||
13 | static char * ActionName[] = { | 13 | static char * ActionName[] = { |
14 | "Disable", | 14 | "Disable", |
15 | "Enable", | 15 | "Enable", |
16 | "Activate", | 16 | "Activate", |
17 | "Deactivate", | 17 | "Deactivate", |
18 | "Up", | 18 | "Up", |
19 | "Down" | 19 | "Down" |
20 | }; | 20 | }; |
21 | 21 | ||
22 | static char * StateName[] = { | 22 | static char * StateName[] = { |
23 | "Unchecked", | 23 | "Unchecked", |
24 | "Unknown", | 24 | "Unknown", |
25 | "Unavailable", | 25 | "Unavailable", |
26 | "Disabled", | 26 | "Disabled", |
27 | "Off", | 27 | "Off", |
28 | "Available", | 28 | "Available", |
29 | "IsUp" | 29 | "IsUp" |
30 | }; | 30 | }; |
31 | 31 | ||
32 | QString & deQuote( QString & X ) { | 32 | QString & deQuote( QString & X ) { |
33 | if( X[0] == '"' ) { | 33 | if( X[0] == '"' ) { |
34 | // remove end and trailing "" and \x -> x | 34 | // remove end and trailing "" and \x -> x |
35 | QChar R; | 35 | QChar R; |
36 | long idx; | 36 | long idx; |
37 | idx = X.length()-1; | 37 | idx = X.length()-1; |
38 | X = X.mid( 1, idx ); | 38 | X = X.mid( 1, idx ); |
39 | 39 | ||
40 | idx = 0; | 40 | idx = 0; |
41 | while( ( idx = X.find( '\\', idx ) ) >= 0 ) { | 41 | while( ( idx = X.find( '\\', idx ) ) >= 0 ) { |
42 | R = X.at( idx + 1 ); | 42 | R = X.at( idx + 1 ); |
43 | X.replace( idx, 2, &R, 1 ); | 43 | X.replace( idx, 2, &R, 1 ); |
44 | } | 44 | } |
45 | X = X.left( X.length()-1 ); | 45 | X = X.left( X.length()-1 ); |
46 | } | 46 | } |
47 | return X; | 47 | return X; |
48 | } | 48 | } |
49 | 49 | ||
50 | QString quote( QString X ) { | 50 | QString quote( QString X ) { |
51 | if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { | 51 | if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { |
52 | // need to quote this | 52 | // need to quote this |
53 | QString OutString = "\""; | 53 | QString OutString = "\""; |
54 | 54 | ||
55 | X.replace( QRegExp("\""), "\\\"" ); | 55 | X.replace( QRegExp("\""), "\\\"" ); |
56 | X.replace( QRegExp("\\"), "\\\\" ); | 56 | X.replace( QRegExp("\\"), "\\\\" ); |
57 | X.replace( QRegExp(" "), "\\ " ); | 57 | X.replace( QRegExp(" "), "\\ " ); |
58 | 58 | ||
59 | OutString += X; | 59 | OutString += X; |
60 | OutString += "\""; | 60 | OutString += "\""; |
61 | X = OutString; | 61 | X = OutString; |
62 | } | 62 | } |
63 | return X; | 63 | return X; |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | // | 67 | // |
68 | // | 68 | // |
69 | // ANETNODE | 69 | // ANETNODE |
70 | // | 70 | // |
71 | // | 71 | // |
72 | 72 | ||
73 | void ANetNode::saveAttributes( QTextStream & TS ) { | 73 | void ANetNode::saveAttributes( QTextStream & TS ) { |
74 | saveSpecificAttribute( TS ); | 74 | saveSpecificAttribute( TS ); |
75 | } | 75 | } |
76 | 76 | ||
77 | void ANetNode::setAttribute( QString & Attr, QString & Value ){ | 77 | void ANetNode::setAttribute( QString & Attr, QString & Value ){ |
78 | setSpecificAttribute( Attr, Value ); | 78 | setSpecificAttribute( Attr, Value ); |
79 | } | 79 | } |
80 | 80 | ||
81 | bool ANetNode::isToplevel( void ) { | 81 | bool ANetNode::isToplevel( void ) { |
82 | const char ** P = provides(); | 82 | const char ** P = provides(); |
83 | while( *P ) { | 83 | while( *P ) { |
84 | if( strcmp( *P, "fullsetup") == 0 ) | 84 | if( strcmp( *P, "fullsetup") == 0 ) |
85 | return 1; | 85 | return 1; |
86 | P ++; | 86 | P ++; |
87 | } | 87 | } |
88 | return 0; | 88 | return 0; |
89 | } | 89 | } |
90 | 90 | ||
91 | bool ANetNode::openFile( SystemFile & SF, | 91 | bool ANetNode::openFile( SystemFile & SF, |
92 | ANetNodeInstance * NNI ) { | 92 | ANetNodeInstance * NNI ) { |
93 | return (NNI ) ? NNI->openFile( SF ) : 0 ; | 93 | return (NNI ) ? NNI->openFile( SF ) : 0 ; |
94 | } | 94 | } |
95 | 95 | ||
96 | // | 96 | // |
97 | // | 97 | // |
98 | // ANETNODEINSTANCE | 98 | // ANETNODEINSTANCE |
99 | // | 99 | // |
100 | // | 100 | // |
101 | 101 | ||
102 | long ANetNodeInstance::InstanceCounter = -1; | 102 | long ANetNodeInstance::InstanceCounter = -1; |
103 | 103 | ||
104 | void ANetNodeInstance::initialize( void ) { | 104 | void ANetNodeInstance::initialize( void ) { |
105 | if( InstanceCounter == -1 ) | 105 | if( InstanceCounter == -1 ) |
106 | InstanceCounter = time(0); | 106 | InstanceCounter = time(0); |
107 | // set name | 107 | // set name |
108 | QString N; | 108 | QString N; |
109 | N.sprintf( "-%ld", InstanceCounter++ ); | 109 | N.sprintf( "-%ld", InstanceCounter++ ); |
110 | N.prepend( NodeType->name() ); | 110 | N.prepend( NodeType->name() ); |
111 | setName( N.latin1() ); | 111 | setName( N.latin1() ); |
112 | } | 112 | } |
113 | 113 | ||
114 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ | 114 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ |
115 | if( Attr == "__name" ) { | 115 | if( Attr == "__name" ) { |
116 | setName( Value.latin1() ); | 116 | setName( Value.latin1() ); |
117 | } else { | 117 | } else { |
118 | setSpecificAttribute( Attr, Value ); | 118 | setSpecificAttribute( Attr, Value ); |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { | 122 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { |
123 | TS << "__name=" << name() << endl; | 123 | TS << "__name=" << name() << endl; |
124 | saveSpecificAttribute( TS ); | 124 | saveSpecificAttribute( TS ); |
125 | } | 125 | } |
126 | 126 | ||
127 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { | 127 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { |
128 | return connection()->findNext( this ); | 128 | return connection()->findNext( this ); |
129 | } | 129 | } |
130 | 130 | ||
131 | // | 131 | // |
132 | // | 132 | // |
133 | // NODECOLLECTION | 133 | // NODECOLLECTION |
134 | // | 134 | // |
135 | // | 135 | // |
136 | 136 | ||
137 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { | 137 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { |
138 | IsModified = 0; | 138 | IsModified = 0; |
139 | Index = -1; | 139 | Index = -1; |
140 | Name=""; | 140 | Name=""; |
141 | IsNew = 1; | 141 | IsNew = 1; |
142 | CurrentState = Unchecked; | 142 | CurrentState = Unchecked; |
143 | AssignedInterface = 0; | 143 | AssignedInterface = 0; |
144 | } | 144 | } |
145 | 145 | ||
146 | NodeCollection::NodeCollection( QTextStream & TS ) : | 146 | NodeCollection::NodeCollection( QTextStream & TS ) : |
147 | QList<ANetNodeInstance>() { | 147 | QList<ANetNodeInstance>() { |
148 | long idx; | 148 | long idx; |
149 | bool InError = 0; | 149 | bool InError = 0; |
150 | QString S, A, N; | 150 | QString S, A, N; |
151 | IsModified = 0; | 151 | IsModified = 0; |
152 | Index = -1; | 152 | Index = -1; |
153 | Name=""; | 153 | Name=""; |
154 | IsNew = 0; | 154 | IsNew = 0; |
155 | AssignedInterface = 0; | 155 | AssignedInterface = 0; |
156 | CurrentState = Unchecked; | 156 | CurrentState = Unchecked; |
157 | 157 | ||
158 | do { | 158 | do { |
159 | S = TS.readLine(); | 159 | S = TS.readLine(); |
160 | if( S.isEmpty() ) { | 160 | if( S.isEmpty() ) { |
161 | if( InError ) { | 161 | if( InError ) { |
162 | // remove all nodes | 162 | // remove all nodes |
163 | clear(); | 163 | clear(); |
164 | } | 164 | } |
165 | // empty line | 165 | // empty line |
166 | break; | 166 | break; |
167 | } | 167 | } |
168 | 168 | ||
169 | idx = S.find('='); | 169 | idx = S.find('='); |
170 | S.stripWhiteSpace(); | 170 | S.stripWhiteSpace(); |
171 | A = S.left( idx ); | 171 | A = S.left( idx ); |
172 | A.lower(); | 172 | A.lower(); |
173 | N = S.mid( idx+1, S.length() ); | 173 | N = S.mid( idx+1, S.length() ); |
174 | N.stripWhiteSpace(); | 174 | N.stripWhiteSpace(); |
175 | N = deQuote( N ); | 175 | N = deQuote( N ); |
176 | 176 | ||
177 | if( A == "name" ) { | 177 | if( A == "name" ) { |
178 | Name = N; | 178 | Name = N; |
179 | } else if( A == "number" ) { | 179 | } else if( A == "number" ) { |
180 | setNumber( N.toLong() ); | 180 | setNumber( N.toLong() ); |
181 | } else if( A == "node" ) { | 181 | } else if( A == "node" ) { |
182 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); | 182 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); |
183 | Log(( "Find node %s : %p\n", N.latin1(), NNI )); | ||
183 | if( NNI && ! InError ) { | 184 | if( NNI && ! InError ) { |
184 | append( NSResources->findNodeInstance( N ) ); | 185 | append( NNI ); |
185 | } else { | 186 | } else { |
186 | // could not find a node type -> collection invalid | 187 | // could not find a node type -> collection invalid |
187 | InError = 1; | 188 | InError = 1; |
188 | } | 189 | } |
189 | } | 190 | } |
190 | } while( 1 ); | 191 | } while( 1 ); |
191 | 192 | ||
192 | Log(( "Profile number %s : %d nodes\n", | 193 | Log(( "Profile number %s : %d nodes\n", |
193 | N.latin1(), count() )); | 194 | Name.latin1(), count() )); |
194 | } | 195 | } |
195 | 196 | ||
196 | 197 | ||
197 | NodeCollection::~NodeCollection( void ) { | 198 | NodeCollection::~NodeCollection( void ) { |
198 | } | 199 | } |
199 | 200 | ||
200 | const QString & NodeCollection::description( void ) { | 201 | const QString & NodeCollection::description( void ) { |
201 | ANetNodeInstance * NNI = getToplevel(); | 202 | ANetNodeInstance * NNI = getToplevel(); |
202 | return (NNI) ? NNI->runtime()->description() : Name; | 203 | return (NNI) ? NNI->runtime()->description() : Name; |
203 | } | 204 | } |
204 | 205 | ||
205 | void NodeCollection::append( ANetNodeInstance * NNI ) { | 206 | void NodeCollection::append( ANetNodeInstance * NNI ) { |
206 | NNI->setConnection( this ); | 207 | NNI->setConnection( this ); |
207 | QList<ANetNodeInstance>::append( NNI ); | 208 | QList<ANetNodeInstance>::append( NNI ); |
208 | } | 209 | } |
209 | 210 | ||
210 | void NodeCollection::save( QTextStream & TS ) { | 211 | void NodeCollection::save( QTextStream & TS ) { |
211 | 212 | ||
212 | TS << "name=" << quote( Name ) << endl; | 213 | TS << "name=" << quote( Name ) << endl; |
213 | TS << "number=" << number() << endl; | 214 | TS << "number=" << number() << endl; |
214 | ANetNodeInstance * NNI; | 215 | ANetNodeInstance * NNI; |
215 | for( QListIterator<ANetNodeInstance> it(*this); | 216 | for( QListIterator<ANetNodeInstance> it(*this); |
216 | it.current(); | 217 | it.current(); |
217 | ++it ) { | 218 | ++it ) { |
218 | NNI = it.current(); | 219 | NNI = it.current(); |
219 | TS << "node=" << NNI->name() << endl; | 220 | TS << "node=" << NNI->name() << endl; |
220 | } | 221 | } |
221 | TS << endl; | 222 | TS << endl; |
222 | IsNew = 0; | 223 | IsNew = 0; |
223 | } | 224 | } |
224 | 225 | ||
225 | ANetNodeInstance * NodeCollection::getToplevel( void ) { | 226 | ANetNodeInstance * NodeCollection::getToplevel( void ) { |
226 | ANetNodeInstance * NNI = 0; | 227 | ANetNodeInstance * NNI = 0; |
227 | for( QListIterator<ANetNodeInstance> it(*this); | 228 | for( QListIterator<ANetNodeInstance> it(*this); |
228 | it.current(); | 229 | it.current(); |
229 | ++it ) { | 230 | ++it ) { |
230 | NNI = it.current(); | 231 | NNI = it.current(); |
231 | if( NNI->nodeClass()->isToplevel() ) | 232 | if( NNI->nodeClass()->isToplevel() ) |
232 | break; | 233 | break; |
233 | } | 234 | } |
234 | return NNI; | 235 | return NNI; |
235 | } | 236 | } |
236 | 237 | ||
237 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { | 238 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { |
238 | ANetNodeInstance * NNI = 0; | 239 | ANetNodeInstance * NNI = 0; |
239 | for( QListIterator<ANetNodeInstance> it(*this); | 240 | for( QListIterator<ANetNodeInstance> it(*this); |
240 | it.current(); | 241 | it.current(); |
241 | ++it ) { | 242 | ++it ) { |
242 | NNI = it.current(); | 243 | NNI = it.current(); |
243 | if( NNI->name() == S ) | 244 | if( NNI->name() == S ) |
244 | break; | 245 | break; |
245 | } | 246 | } |
246 | return NNI; | 247 | return NNI; |
247 | } | 248 | } |
248 | 249 | ||
249 | ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { | 250 | ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { |
250 | ANetNodeInstance * NNNI; | 251 | ANetNodeInstance * NNNI; |
251 | 252 | ||
252 | if( ! NNI ) | 253 | if( ! NNI ) |
253 | getToplevel(); | 254 | getToplevel(); |
254 | 255 | ||
255 | for( QListIterator<ANetNodeInstance> it(*this); | 256 | for( QListIterator<ANetNodeInstance> it(*this); |
256 | it.current(); | 257 | it.current(); |
257 | ++it ) { | 258 | ++it ) { |
258 | NNNI = it.current(); | 259 | NNNI = it.current(); |
259 | if( NNNI == NNI ) { | 260 | if( NNNI == NNI ) { |
260 | ++it; | 261 | ++it; |
261 | return it.current(); | 262 | return it.current(); |
262 | } | 263 | } |
263 | } | 264 | } |
264 | return 0; // no more next | 265 | return 0; // no more next |
265 | } | 266 | } |
266 | 267 | ||
267 | int NodeCollection::compareItems( QCollection::Item I1, | 268 | int NodeCollection::compareItems( QCollection::Item I1, |
268 | QCollection::Item I2 ) { | 269 | QCollection::Item I2 ) { |
269 | ANetNodeInstance * NNI1, * NNI2; | 270 | ANetNodeInstance * NNI1, * NNI2; |
270 | NNI1 = (ANetNodeInstance *)I1; | 271 | NNI1 = (ANetNodeInstance *)I1; |
271 | NNI2 = (ANetNodeInstance *)I2; | 272 | NNI2 = (ANetNodeInstance *)I2; |
272 | return strcmp( NNI1->name(), NNI2->name() ); | 273 | return strcmp( NNI1->name(), NNI2->name() ); |
273 | } | 274 | } |
274 | 275 | ||
275 | static char * State2PixmapTbl[] = { | 276 | static char * State2PixmapTbl[] = { |
276 | "NULL", // Unchecked : no pixmap | 277 | "NULL", // Unchecked : no pixmap |
277 | "check", // Unknown | 278 | "check", // Unknown |
278 | "delete", // unavailable | 279 | "delete", // unavailable |
279 | "disabled", // disabled | 280 | "disabled", // disabled |
280 | "off", // off | 281 | "off", // off |
281 | "disconnected", // available | 282 | "disconnected", // available |
282 | "connected" // up | 283 | "connected" // up |
283 | }; | 284 | }; |
284 | 285 | ||
285 | QPixmap NodeCollection::devicePixmap( void ) { | 286 | QPixmap NodeCollection::devicePixmap( void ) { |
286 | QPixmap pm = NSResources->getPixmap( | 287 | QPixmap pm = NSResources->getPixmap( |
287 | getToplevel()->nextNode()->pixmapName()+"-large"); | 288 | getToplevel()->nextNode()->pixmapName()+"-large"); |
288 | 289 | ||
289 | QPixmap Mini = NSResources->getPixmap( | 290 | QPixmap Mini = NSResources->getPixmap( |
290 | device()->netNode()->pixmapName() ); | 291 | device()->netNode()->pixmapName() ); |
291 | 292 | ||
292 | if( pm.isNull() || Mini.isNull() ) | 293 | if( pm.isNull() || Mini.isNull() ) |
293 | return Resource::loadPixmap("Unknown"); | 294 | return Resource::loadPixmap("Unknown"); |
294 | 295 | ||
295 | QPainter painter( &pm ); | 296 | QPainter painter( &pm ); |
296 | painter.drawPixmap( pm.width()-Mini.width(), | 297 | painter.drawPixmap( pm.width()-Mini.width(), |
297 | pm.height()-Mini.height(), | 298 | pm.height()-Mini.height(), |
298 | Mini ); | 299 | Mini ); |
299 | pm.setMask( pm.createHeuristicMask( TRUE ) ); | 300 | pm.setMask( pm.createHeuristicMask( TRUE ) ); |
300 | return pm; | 301 | return pm; |
301 | } | 302 | } |
302 | 303 | ||
303 | QPixmap NodeCollection::statePixmap( State_t S) { | 304 | QPixmap NodeCollection::statePixmap( State_t S) { |
304 | return NSResources->getPixmap( State2PixmapTbl[S] ); | 305 | return NSResources->getPixmap( State2PixmapTbl[S] ); |
305 | } | 306 | } |
306 | 307 | ||
307 | QString NodeCollection::stateName( State_t S) { | 308 | QString NodeCollection::stateName( State_t S) { |
308 | switch( S ) { | 309 | switch( S ) { |
309 | case Unknown : | 310 | case Unknown : |
310 | return qApp->translate( "networksettings2", "Unknown"); | 311 | return qApp->translate( "networksettings2", "Unknown"); |
311 | case Unavailable : | 312 | case Unavailable : |
312 | return qApp->translate( "networksettings2", "Unavailable"); | 313 | return qApp->translate( "networksettings2", "Unavailable"); |
313 | case Disabled : | 314 | case Disabled : |
314 | return qApp->translate( "networksettings2", "Disabled"); | 315 | return qApp->translate( "networksettings2", "Disabled"); |
315 | case Off : | 316 | case Off : |
316 | return qApp->translate( "networksettings2", "Inactive"); | 317 | return qApp->translate( "networksettings2", "Inactive"); |
317 | case Available : | 318 | case Available : |
318 | return qApp->translate( "networksettings2", "Available"); | 319 | return qApp->translate( "networksettings2", "Available"); |
319 | case IsUp : | 320 | case IsUp : |
320 | return qApp->translate( "networksettings2", "Up"); | 321 | return qApp->translate( "networksettings2", "Up"); |
321 | case Unchecked : /* FT */ | 322 | case Unchecked : /* FT */ |
322 | default : | 323 | default : |
323 | break; | 324 | break; |
324 | } | 325 | } |
325 | return QString(""); | 326 | return QString(""); |
326 | } | 327 | } |
327 | 328 | ||
328 | void NodeCollection::reassign( void ) { | 329 | void NodeCollection::reassign( void ) { |
329 | for( QListIterator<ANetNodeInstance> it(*this); | 330 | for( QListIterator<ANetNodeInstance> it(*this); |
330 | it.current(); | 331 | it.current(); |
331 | ++it ) { | 332 | ++it ) { |
332 | it.current()->setConnection( this ); | 333 | it.current()->setConnection( this ); |
333 | } | 334 | } |
334 | } | 335 | } |
335 | 336 | ||
336 | const QStringList & NodeCollection::triggers() { | 337 | const QStringList & NodeCollection::triggers() { |
337 | return getToplevel()->runtime()->triggers(); | 338 | return getToplevel()->runtime()->triggers(); |
338 | } | 339 | } |
339 | 340 | ||
340 | bool NodeCollection::hasDataForFile( SystemFile & S ) { | 341 | bool NodeCollection::hasDataForFile( SystemFile & S ) { |
341 | return ( firstWithDataForFile( S ) != 0 ); | 342 | return ( firstWithDataForFile( S ) != 0 ); |
342 | } | 343 | } |
343 | 344 | ||
344 | ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) { | 345 | ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) { |
345 | for( QListIterator<ANetNodeInstance> it(*this); | 346 | for( QListIterator<ANetNodeInstance> it(*this); |
346 | it.current(); | 347 | it.current(); |
347 | ++it ) { | 348 | ++it ) { |
348 | if( it.current()->hasDataForFile( S ) ) { | 349 | if( it.current()->hasDataForFile( S ) ) { |
349 | return it.current(); | 350 | return it.current(); |
350 | } | 351 | } |
351 | } | 352 | } |
352 | return 0; | 353 | return 0; |
353 | } | 354 | } |
354 | 355 | ||
355 | State_t NodeCollection::state( bool Update ) { | 356 | State_t NodeCollection::state( bool Update ) { |
356 | State_t NodeState; | 357 | State_t NodeState; |
357 | 358 | ||
358 | if( CurrentState == Unchecked || Update ) { | 359 | if( CurrentState == Unchecked || Update ) { |
359 | // collect states of all nodes until with get the 'higest' | 360 | // collect states of all nodes until with get the 'higest' |
360 | // state possible | 361 | // state possible |
361 | 362 | ||
362 | Log(( "Connection %s state %s\n", | 363 | Log(( "Connection %s state %s\n", |
363 | Name.latin1(), StateName[CurrentState] )); | 364 | Name.latin1(), StateName[CurrentState] )); |
364 | 365 | ||
365 | CurrentState = Unknown; | 366 | CurrentState = Unknown; |
366 | for( QListIterator<ANetNodeInstance> it(*this); | 367 | for( QListIterator<ANetNodeInstance> it(*this); |
367 | it.current(); | 368 | it.current(); |
368 | ++it ) { | 369 | ++it ) { |
369 | Log(( "-> Detect %s\n", it.current()->name() )); | 370 | Log(( "-> Detect %s\n", it.current()->name() )); |
370 | NodeState = it.current()->runtime()->detectState(); | 371 | NodeState = it.current()->runtime()->detectState(); |
371 | Log(( " state %s\n", StateName[NodeState] )); | 372 | Log(( " state %s\n", StateName[NodeState] )); |
372 | 373 | ||
373 | if( NodeState == Disabled || | 374 | if( NodeState == Disabled || |
374 | NodeState == IsUp ) { | 375 | NodeState == IsUp ) { |
375 | // max | 376 | // max |
376 | CurrentState = NodeState; | 377 | CurrentState = NodeState; |
377 | break; | 378 | break; |
378 | } | 379 | } |
379 | 380 | ||
380 | if( NodeState > CurrentState ) { | 381 | if( NodeState > CurrentState ) { |
381 | // higher | 382 | // higher |
382 | CurrentState = NodeState; | 383 | CurrentState = NodeState; |
383 | } | 384 | } |
384 | } | 385 | } |
385 | } | 386 | } |
386 | 387 | ||
387 | return CurrentState; | 388 | return CurrentState; |
388 | } | 389 | } |
389 | 390 | ||
390 | QString NodeCollection::setState( Action_t A, bool Force ) { | 391 | QString NodeCollection::setState( Action_t A, bool Force ) { |
391 | 392 | ||
392 | QString msg; | 393 | QString msg; |
393 | Action_t Actions[10]; | 394 | Action_t Actions[10]; |
394 | int NoOfActions = 0; | 395 | int NoOfActions = 0; |
395 | 396 | ||
396 | // get current state | 397 | // get current state |
397 | state( Force ); | 398 | state( Force ); |
398 | 399 | ||
399 | switch( A ) { | 400 | switch( A ) { |
400 | case Disable : | 401 | case Disable : |
401 | if( CurrentState < Disabled ) { | 402 | if( CurrentState < Disabled ) { |
402 | // disabled | 403 | // disabled |
403 | CurrentState = Disabled; | 404 | CurrentState = Disabled; |
404 | return QString(); | 405 | return QString(); |
405 | } | 406 | } |
406 | 407 | ||
407 | if( CurrentState == IsUp ) { | 408 | if( CurrentState == IsUp ) { |
408 | Actions[NoOfActions++] = Down; | 409 | Actions[NoOfActions++] = Down; |
409 | Actions[NoOfActions++] = Deactivate; | 410 | Actions[NoOfActions++] = Deactivate; |
410 | } else if( CurrentState == Available ) { | 411 | } else if( CurrentState == Available ) { |
411 | Actions[NoOfActions++] = Deactivate; | 412 | Actions[NoOfActions++] = Deactivate; |
412 | } | 413 | } |
413 | Actions[NoOfActions++] = Disable; | 414 | Actions[NoOfActions++] = Disable; |
414 | break; | 415 | break; |
415 | case Enable : | 416 | case Enable : |
416 | // always possible -> detected state is new state | 417 | // always possible -> detected state is new state |
417 | Actions[NoOfActions++] = Enable; | 418 | Actions[NoOfActions++] = Enable; |
418 | break; | 419 | break; |
419 | case Activate : | 420 | case Activate : |
420 | if( ! Force ) { | 421 | if( ! Force ) { |
421 | if( CurrentState >= Available ) { | 422 | if( CurrentState >= Available ) { |
422 | // already available | 423 | // already available |
423 | return QString(); | 424 | return QString(); |
424 | } | 425 | } |
425 | 426 | ||
426 | if( CurrentState != Off ) { | 427 | if( CurrentState != Off ) { |
427 | return qApp->translate( "System", | 428 | return qApp->translate( "System", |
428 | "State should be off" ); | 429 | "State should be off" ); |
429 | } | 430 | } |
430 | } | 431 | } |
431 | 432 | ||
432 | Actions[NoOfActions++] = Activate; | 433 | Actions[NoOfActions++] = Activate; |
433 | break; | 434 | break; |
434 | case Deactivate : | 435 | case Deactivate : |
435 | if( ! Force ) { | 436 | if( ! Force ) { |
436 | if( CurrentState < Off ) { | 437 | if( CurrentState < Off ) { |
437 | // already inactive | 438 | // already inactive |
438 | return QString(); | 439 | return QString(); |
439 | } | 440 | } |
440 | } | 441 | } |
441 | 442 | ||
442 | if( CurrentState == IsUp ) { | 443 | if( CurrentState == IsUp ) { |
443 | Actions[NoOfActions++] = Down; | 444 | Actions[NoOfActions++] = Down; |
444 | } | 445 | } |
445 | Actions[NoOfActions++] = Deactivate; | 446 | Actions[NoOfActions++] = Deactivate; |
446 | break; | 447 | break; |
447 | case Up : | 448 | case Up : |
448 | if( ! Force ) { | 449 | if( ! Force ) { |
449 | if( CurrentState == IsUp ) { | 450 | if( CurrentState == IsUp ) { |
450 | return QString(); | 451 | return QString(); |
451 | } | 452 | } |
452 | if( CurrentState < Off ) { | 453 | if( CurrentState < Off ) { |
453 | return qApp->translate( "System", | 454 | return qApp->translate( "System", |
454 | "State should at least be off" ); | 455 | "State should at least be off" ); |
455 | } | 456 | } |
456 | } | 457 | } |
457 | if( CurrentState == Off ) { | 458 | if( CurrentState == Off ) { |
458 | Actions[NoOfActions++] = Activate; | 459 | Actions[NoOfActions++] = Activate; |
459 | } | 460 | } |
460 | Actions[NoOfActions++] = Up; | 461 | Actions[NoOfActions++] = Up; |
461 | break; | 462 | break; |
462 | case Down : | 463 | case Down : |
463 | if( ! Force ) { | 464 | if( ! Force ) { |
464 | if( CurrentState < Available ) { | 465 | if( CurrentState < Available ) { |
465 | // OK | 466 | // OK |
466 | return QString(); | 467 | return QString(); |
467 | } | 468 | } |
468 | } | 469 | } |
469 | Actions[NoOfActions++] = Down; | 470 | Actions[NoOfActions++] = Down; |
470 | break; | 471 | break; |
471 | } | 472 | } |
472 | 473 | ||
473 | // send actions to all nodes | 474 | // send actions to all nodes |
474 | Log(( "Action %s requires %d steps\n", | 475 | Log(( "Action %s requires %d steps\n", |
475 | ActionName[A], NoOfActions )); | 476 | ActionName[A], NoOfActions )); |
476 | 477 | ||
477 | for( int i = 0 ; i < NoOfActions; i ++ ) { | 478 | for( int i = 0 ; i < NoOfActions; i ++ ) { |
478 | // setState recurses through the tree depth first | 479 | // setState recurses through the tree depth first |
479 | msg = getToplevel()->runtime()->setState( this, Actions[i], Force ); | 480 | msg = getToplevel()->runtime()->setState( this, Actions[i], Force ); |
480 | if( ! msg.isEmpty() ) { | 481 | if( ! msg.isEmpty() ) { |
481 | return msg; | 482 | return msg; |
482 | } | 483 | } |
483 | } | 484 | } |
484 | return QString(); | 485 | return QString(); |
485 | } | 486 | } |
486 | 487 | ||
487 | // | 488 | // |
488 | // | 489 | // |
489 | // RuntimeInfo | 490 | // RuntimeInfo |
490 | // | 491 | // |
491 | // | 492 | // |
492 | 493 | ||
493 | QString RuntimeInfo::setState( NodeCollection * NC, | 494 | QString RuntimeInfo::setState( NodeCollection * NC, |
494 | Action_t A, | 495 | Action_t A, |
495 | bool Force ) { | 496 | bool Force ) { |
496 | QString M; | 497 | QString M; |
497 | RuntimeInfo * Deeper = nextNode(); | 498 | RuntimeInfo * Deeper = nextNode(); |
498 | 499 | ||
499 | if( Deeper ) { | 500 | if( Deeper ) { |
500 | // first go deeper | 501 | // first go deeper |
501 | M = Deeper->setState( NC, A, Force ); | 502 | M = Deeper->setState( NC, A, Force ); |
502 | if( ! M.isEmpty() ) | 503 | if( ! M.isEmpty() ) |
503 | return M; | 504 | return M; |
504 | } | 505 | } |
505 | 506 | ||
506 | // set my own state | 507 | // set my own state |
507 | Log (( "-> Act upon %s\n", netNode()->name() )); | 508 | Log (( "-> Act upon %s\n", netNode()->name() )); |
508 | M = setMyState( NC, A, Force ); | 509 | M = setMyState( NC, A, Force ); |
509 | Log (( " result %s\n", M.latin1() )); | 510 | Log (( " result %s\n", M.latin1() )); |
510 | return M; | 511 | return M; |
511 | } | 512 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 8b3b4fe..50fb15a 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp | |||
@@ -1,470 +1,473 @@ | |||
1 | #include <unistd.h> | 1 | #include <unistd.h> |
2 | #include <errno.h> | 2 | #include <errno.h> |
3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
4 | #include <pwd.h> | 4 | #include <pwd.h> |
5 | #include <qpixmap.h> | 5 | #include <qpixmap.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <qpe/qlibrary.h> | 7 | #include <qpe/qlibrary.h> |
8 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
9 | #include <opie2/odebug.h> | 9 | #include <opie2/odebug.h> |
10 | #include <qtopia/resource.h> | 10 | #include <qtopia/resource.h> |
11 | 11 | ||
12 | #include "netnode.h" | 12 | #include "netnode.h" |
13 | #include "resources.h" | 13 | #include "resources.h" |
14 | 14 | ||
15 | #define PLUGINDIR "plugins/networksettings2" | 15 | #define PLUGINDIR "plugins/networksettings2" |
16 | #define ICONDIR "/pics/networksettings2/" | 16 | #define ICONDIR "/pics/networksettings2/" |
17 | 17 | ||
18 | // single resources instance | 18 | // single resources instance |
19 | TheNSResources * _NSResources = 0; | 19 | TheNSResources * _NSResources = 0; |
20 | 20 | ||
21 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), | 21 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), |
22 | ConnectionsMap() { | 22 | ConnectionsMap() { |
23 | 23 | ||
24 | _NSResources = this; | 24 | _NSResources = this; |
25 | 25 | ||
26 | detectCurrentUser(); | 26 | detectCurrentUser(); |
27 | 27 | ||
28 | // load available netnodes | 28 | // load available netnodes |
29 | findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); | 29 | findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); |
30 | 30 | ||
31 | // compile provides and needs lists | 31 | // compile provides and needs lists |
32 | { const char ** NeedsRun; | 32 | { const char ** NeedsRun; |
33 | QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); | 33 | QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); |
34 | bool Done; | 34 | bool Done; |
35 | 35 | ||
36 | for ( ; OuterIt.current(); ++OuterIt ) { | 36 | for ( ; OuterIt.current(); ++OuterIt ) { |
37 | // find needs list | 37 | // find needs list |
38 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; | 38 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; |
39 | ANetNode::NetNodeList & NNL = *(NNLP); | 39 | ANetNode::NetNodeList & NNL = *(NNLP); |
40 | 40 | ||
41 | // must iterate this way to avoid duplication pointers | 41 | // must iterate this way to avoid duplication pointers |
42 | for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); | 42 | for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); |
43 | InnerIt.current(); ++InnerIt ) { | 43 | InnerIt.current(); ++InnerIt ) { |
44 | if( InnerIt.current() == OuterIt.current() ) | 44 | if( InnerIt.current() == OuterIt.current() ) |
45 | // avoid recursive | 45 | // avoid recursive |
46 | continue; | 46 | continue; |
47 | 47 | ||
48 | const char ** Provides = InnerIt.current()->NetNode->provides(); | 48 | const char ** Provides = InnerIt.current()->NetNode->provides(); |
49 | NeedsRun = OuterIt.current()->NetNode->needs(); | 49 | NeedsRun = OuterIt.current()->NetNode->needs(); |
50 | 50 | ||
51 | for( ; *NeedsRun; NeedsRun ++ ) { | 51 | for( ; *NeedsRun; NeedsRun ++ ) { |
52 | const char ** PRun; | 52 | const char ** PRun; |
53 | PRun = Provides; | 53 | PRun = Provides; |
54 | for( ; *PRun; PRun ++ ) { | 54 | for( ; *PRun; PRun ++ ) { |
55 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { | 55 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { |
56 | // inner provides what outer needs | 56 | // inner provides what outer needs |
57 | NNL.resize( NNL.size() + 1 ); | 57 | NNL.resize( NNL.size() + 1 ); |
58 | NNL[NNL.size()-1] = InnerIt.current()->NetNode; | 58 | NNL[NNL.size()-1] = InnerIt.current()->NetNode; |
59 | Done = 1; // break from 2 loops | 59 | Done = 1; // break from 2 loops |
60 | break; | 60 | break; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | } | 64 | } |
65 | OuterIt.current()->NetNode->setAlternatives( NNLP ); | 65 | OuterIt.current()->NetNode->setAlternatives( NNLP ); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | // define built in Node types to Description map | 69 | // define built in Node types to Description map |
70 | addNodeType( "device", tr( "Network Device" ), | 70 | addNodeType( "device", tr( "Network Device" ), |
71 | tr( "<p>Devices that can handle IP packets</p>" ) ); | 71 | tr( "<p>Devices that can handle IP packets</p>" ) ); |
72 | addNodeType( "line", tr( "Character device" ), | 72 | addNodeType( "line", tr( "Character device" ), |
73 | tr( "<p>Devices that can handle single bytes</p>" ) ); | 73 | tr( "<p>Devices that can handle single bytes</p>" ) ); |
74 | addNodeType( "connection", tr( "IP Connection" ), | 74 | addNodeType( "connection", tr( "IP Connection" ), |
75 | tr( "<p>Nodes that provide working IP connections</p>" ) ); | 75 | tr( "<p>Nodes that provide working IP connections</p>" ) ); |
76 | addNodeType( "fullsetup", tr( "Connection Profile" ), | 76 | addNodeType( "fullsetup", tr( "Connection Profile" ), |
77 | tr( "<p>Fully configured connection profile</p>" ) ); | 77 | tr( "<p>Fully configured connection profile</p>" ) ); |
78 | addNodeType( "GPRS", tr( "Connection to GPRS device" ), | 78 | addNodeType( "GPRS", tr( "Connection to GPRS device" ), |
79 | tr( "<p>Connection to a GPRS capable device</p>" ) ); | 79 | tr( "<p>Connection to a GPRS capable device</p>" ) ); |
80 | 80 | ||
81 | // get access to the system | 81 | // get access to the system |
82 | TheSystem = new System(); | 82 | TheSystem = new System(); |
83 | 83 | ||
84 | } | 84 | } |
85 | 85 | ||
86 | TheNSResources::~TheNSResources( void ) { | 86 | TheNSResources::~TheNSResources( void ) { |
87 | delete TheSystem; | 87 | delete TheSystem; |
88 | } | 88 | } |
89 | 89 | ||
90 | void TheNSResources::addNodeType( const QString & ID, | 90 | void TheNSResources::addNodeType( const QString & ID, |
91 | const QString & Name, | 91 | const QString & Name, |
92 | const QString & Descr ) { | 92 | const QString & Descr ) { |
93 | if( NodeTypeNameMap[ID].isEmpty() ) { | 93 | if( NodeTypeNameMap[ID].isEmpty() ) { |
94 | NodeTypeNameMap.insert( ID, Name ); | 94 | NodeTypeNameMap.insert( ID, Name ); |
95 | NodeTypeDescriptionMap.insert( ID, Descr ); | 95 | NodeTypeDescriptionMap.insert( ID, Descr ); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | void TheNSResources::addSystemFile( const QString & ID, | 99 | void TheNSResources::addSystemFile( const QString & ID, |
100 | const QString & P, | 100 | const QString & P, |
101 | bool KDI ) { | 101 | bool KDI ) { |
102 | if( ! SystemFiles.find( ID ) ) { | 102 | if( ! SystemFiles.find( ID ) ) { |
103 | // new system file | 103 | // new system file |
104 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); | 104 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); |
105 | } // else existed | 105 | } // else existed |
106 | } | 106 | } |
107 | 107 | ||
108 | void TheNSResources::busy( bool ) { | 108 | void TheNSResources::busy( bool ) { |
109 | /* | 109 | /* |
110 | if( B ) { | 110 | if( B ) { |
111 | ShowWait->show(); | 111 | ShowWait->show(); |
112 | qApp->process | 112 | qApp->process |
113 | } else { | 113 | } else { |
114 | ShowWait->hide(); | 114 | ShowWait->hide(); |
115 | } | 115 | } |
116 | */ | 116 | */ |
117 | } | 117 | } |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * Load all modules that are found in the path | 120 | * Load all modules that are found in the path |
121 | * @param path a directory that is scaned for any plugins that can be loaded | 121 | * @param path a directory that is scaned for any plugins that can be loaded |
122 | * and attempts to load them | 122 | * and attempts to load them |
123 | */ | 123 | */ |
124 | void TheNSResources::findAvailableNetNodes(const QString &path){ | 124 | void TheNSResources::findAvailableNetNodes(const QString &path){ |
125 | 125 | ||
126 | Log(("Locate plugins in %s\n", path.latin1() )); | 126 | Log(("Locate plugins in %s\n", path.latin1() )); |
127 | QDir d(path); | 127 | QDir d(path); |
128 | if(!d.exists()) | 128 | if(!d.exists()) |
129 | return; | 129 | return; |
130 | 130 | ||
131 | QString lang = ::getenv("LANG"); | 131 | QString lang = ::getenv("LANG"); |
132 | 132 | ||
133 | // Don't want sym links | 133 | // Don't want sym links |
134 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 134 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
135 | const QFileInfoList *list = d.entryInfoList(); | 135 | const QFileInfoList *list = d.entryInfoList(); |
136 | QFileInfoListIterator it( *list ); | 136 | QFileInfoListIterator it( *list ); |
137 | QFileInfo *fi; | 137 | QFileInfo *fi; |
138 | 138 | ||
139 | while ( (fi=it.current()) ) { | 139 | while ( (fi=it.current()) ) { |
140 | 140 | ||
141 | if( fi->fileName().contains(".so")){ | 141 | if( fi->fileName().contains(".so")){ |
142 | /* if loaded install translation */ | 142 | /* if loaded install translation */ |
143 | if( loadNetNode(path + "/" + fi->fileName()) ) { | 143 | if( loadNetNode(path + "/" + fi->fileName()) ) { |
144 | Log(( "Loading plugin %s\n", fi->fileName().latin1())); | ||
144 | QTranslator *trans = new QTranslator(qApp); | 145 | QTranslator *trans = new QTranslator(qApp); |
145 | QString fn = QPEApplication::qpeDir()+ | 146 | QString fn = QPEApplication::qpeDir()+ |
146 | "/i18n/"+lang+"/"+ | 147 | "/i18n/"+lang+"/"+ |
147 | fi->fileName().left( fi->fileName().find(".") )+ | 148 | fi->fileName().left( fi->fileName().find(".") )+ |
148 | ".qm"; | 149 | ".qm"; |
149 | 150 | ||
150 | if( trans->load( fn ) ) | 151 | if( trans->load( fn ) ) |
151 | qApp->installTranslator( trans ); | 152 | qApp->installTranslator( trans ); |
152 | else | 153 | else |
153 | delete trans; | 154 | delete trans; |
155 | } else { | ||
156 | Log(( "Error loading plugin %s\n", fi->fileName().latin1())); | ||
154 | } | 157 | } |
155 | } | 158 | } |
156 | ++it; | 159 | ++it; |
157 | } | 160 | } |
158 | } | 161 | } |
159 | 162 | ||
160 | // used to find unique connection number | 163 | // used to find unique connection number |
161 | int TheNSResources::assignConnectionNumber( void ) { | 164 | int TheNSResources::assignConnectionNumber( void ) { |
162 | bool found = 1; | 165 | bool found = 1; |
163 | for( int trial = 0; ; trial ++ ) { | 166 | for( int trial = 0; ; trial ++ ) { |
164 | found = 1; | 167 | found = 1; |
165 | for( QDictIterator<NodeCollection> it(ConnectionsMap); | 168 | for( QDictIterator<NodeCollection> it(ConnectionsMap); |
166 | it.current(); | 169 | it.current(); |
167 | ++it ) { | 170 | ++it ) { |
168 | if( it.current()->number() == trial ) { | 171 | if( it.current()->number() == trial ) { |
169 | found = 0; | 172 | found = 0; |
170 | break; | 173 | break; |
171 | } | 174 | } |
172 | } | 175 | } |
173 | 176 | ||
174 | if( found ) { | 177 | if( found ) { |
175 | Log(("Assign profile number %d\n", trial )); | 178 | Log(("Assign profile number %d\n", trial )); |
176 | return trial; | 179 | return trial; |
177 | } | 180 | } |
178 | } | 181 | } |
179 | } | 182 | } |
180 | 183 | ||
181 | /** | 184 | /** |
182 | * Attempt to load a function and resolve a function. | 185 | * Attempt to load a function and resolve a function. |
183 | * @param pluginFileName - the name of the file in which to attempt to load | 186 | * @param pluginFileName - the name of the file in which to attempt to load |
184 | * @param resolveString - function pointer to resolve | 187 | * @param resolveString - function pointer to resolve |
185 | * @return true of loading is successful | 188 | * @return true of loading is successful |
186 | */ | 189 | */ |
187 | bool TheNSResources::loadNetNode( | 190 | bool TheNSResources::loadNetNode( |
188 | const QString &pluginFileName, const QString &resolveString){ | 191 | const QString &pluginFileName, const QString &resolveString){ |
189 | 192 | ||
190 | QLibrary *lib = new QLibrary(pluginFileName); | 193 | QLibrary *lib = new QLibrary(pluginFileName); |
191 | void * res = lib->resolve(resolveString); | 194 | void * res = lib->resolve(resolveString); |
192 | if( ! res ){ | 195 | if( ! res ){ |
193 | delete lib; | 196 | delete lib; |
194 | return 0; | 197 | return 0; |
195 | } | 198 | } |
196 | 199 | ||
197 | GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; | 200 | GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; |
198 | 201 | ||
199 | // Try to get an object. | 202 | // Try to get an object. |
200 | QList<ANetNode> PNN; | 203 | QList<ANetNode> PNN; |
201 | 204 | ||
202 | getNetNodeList( PNN ); | 205 | getNetNodeList( PNN ); |
203 | if( PNN.isEmpty() ) { | 206 | if( PNN.isEmpty() ) { |
204 | delete lib; | 207 | delete lib; |
205 | return 0; | 208 | return 0; |
206 | } | 209 | } |
207 | 210 | ||
208 | ANetNode * NNP; | 211 | ANetNode * NNP; |
209 | for( QListIterator<ANetNode> it(PNN); | 212 | for( QListIterator<ANetNode> it(PNN); |
210 | it.current(); | 213 | it.current(); |
211 | ++it ) { | 214 | ++it ) { |
212 | NetNode_t * NN; | 215 | NetNode_t * NN; |
213 | 216 | ||
214 | NNP = it.current(); | 217 | NNP = it.current(); |
215 | NN = new NetNode_t; | 218 | NN = new NetNode_t; |
216 | NN->NetNode = NNP; | 219 | NN->NetNode = NNP; |
217 | NN->TheLibrary = lib; | 220 | NN->TheLibrary = lib; |
218 | NN->NodeCountInLib = PNN.count(); | 221 | NN->NodeCountInLib = PNN.count(); |
219 | 222 | ||
220 | // store mapping | 223 | // store mapping |
221 | AllNodeTypes.insert( NN->NetNode->name(), NN ); | 224 | AllNodeTypes.insert( NN->NetNode->name(), NN ); |
222 | } | 225 | } |
223 | 226 | ||
224 | return 1; | 227 | return 1; |
225 | } | 228 | } |
226 | 229 | ||
227 | QPixmap TheNSResources::getPixmap( const QString & QS ) { | 230 | QPixmap TheNSResources::getPixmap( const QString & QS ) { |
228 | QPixmap P; | 231 | QPixmap P; |
229 | QString S("networksettings2/"); | 232 | QString S("networksettings2/"); |
230 | S += QS; | 233 | S += QS; |
231 | P = Resource::loadPixmap( S ); | 234 | P = Resource::loadPixmap( S ); |
232 | if( P.isNull() ) { | 235 | if( P.isNull() ) { |
233 | Log(( "Cannot load %s\n", S.latin1() )); | 236 | Log(( "Cannot load %s\n", S.latin1() )); |
234 | } | 237 | } |
235 | return ( P.isNull() ) ? QPixmap() : P; | 238 | return ( P.isNull() ) ? QPixmap() : P; |
236 | } | 239 | } |
237 | 240 | ||
238 | QString TheNSResources::tr( const char * s ) { | 241 | QString TheNSResources::tr( const char * s ) { |
239 | return qApp->translate( "resource", s ); | 242 | return qApp->translate( "resource", s ); |
240 | } | 243 | } |
241 | 244 | ||
242 | const QString & TheNSResources::netNode2Name( const char * s ) { | 245 | const QString & TheNSResources::netNode2Name( const char * s ) { |
243 | return NodeTypeNameMap[s]; | 246 | return NodeTypeNameMap[s]; |
244 | } | 247 | } |
245 | 248 | ||
246 | const QString & TheNSResources::netNode2Description( const char * s ) { | 249 | const QString & TheNSResources::netNode2Description( const char * s ) { |
247 | return NodeTypeDescriptionMap[s]; | 250 | return NodeTypeDescriptionMap[s]; |
248 | } | 251 | } |
249 | 252 | ||
250 | void TheNSResources::addConnection( NodeCollection * NC ) { | 253 | void TheNSResources::addConnection( NodeCollection * NC ) { |
251 | ANetNodeInstance * NNI; | 254 | ANetNodeInstance * NNI; |
252 | ConnectionsMap.insert( NC->name(), NC ); | 255 | ConnectionsMap.insert( NC->name(), NC ); |
253 | // add (new) nodes to NodeList | 256 | // add (new) nodes to NodeList |
254 | for( QListIterator<ANetNodeInstance> it(*NC); | 257 | for( QListIterator<ANetNodeInstance> it(*NC); |
255 | it.current(); | 258 | it.current(); |
256 | ++it ) { | 259 | ++it ) { |
257 | NNI = it.current(); | 260 | NNI = it.current(); |
258 | if( findNodeInstance( NNI->name() ) == 0 ) { | 261 | if( findNodeInstance( NNI->name() ) == 0 ) { |
259 | // new item | 262 | // new item |
260 | addNodeInstance( NNI ); | 263 | addNodeInstance( NNI ); |
261 | } | 264 | } |
262 | } | 265 | } |
263 | } | 266 | } |
264 | 267 | ||
265 | void TheNSResources::removeConnection( const QString & N ) { | 268 | void TheNSResources::removeConnection( const QString & N ) { |
266 | NodeCollection * NC = findConnection( N ); | 269 | NodeCollection * NC = findConnection( N ); |
267 | if( ! NC ) | 270 | if( ! NC ) |
268 | return; | 271 | return; |
269 | 272 | ||
270 | // delete netnodes in this connection | 273 | // delete netnodes in this connection |
271 | ANetNodeInstance * NNI; | 274 | ANetNodeInstance * NNI; |
272 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { | 275 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { |
273 | removeNodeInstance( NNI->name() ); | 276 | removeNodeInstance( NNI->name() ); |
274 | } | 277 | } |
275 | ConnectionsMap.remove( N ); | 278 | ConnectionsMap.remove( N ); |
276 | } | 279 | } |
277 | 280 | ||
278 | NodeCollection * TheNSResources::findConnection( const QString & S ) { | 281 | NodeCollection * TheNSResources::findConnection( const QString & S ) { |
279 | return ConnectionsMap[ S ]; | 282 | return ConnectionsMap[ S ]; |
280 | } | 283 | } |
281 | 284 | ||
282 | NodeCollection * TheNSResources::getConnection( int nr ) { | 285 | NodeCollection * TheNSResources::getConnection( int nr ) { |
283 | for( QDictIterator<NodeCollection> it(ConnectionsMap); | 286 | for( QDictIterator<NodeCollection> it(ConnectionsMap); |
284 | it.current(); | 287 | it.current(); |
285 | ++it ) { | 288 | ++it ) { |
286 | if( it.current()->number() == nr ) { | 289 | if( it.current()->number() == nr ) { |
287 | return it.current(); | 290 | return it.current(); |
288 | } | 291 | } |
289 | } | 292 | } |
290 | return 0; | 293 | return 0; |
291 | } | 294 | } |
292 | /* | 295 | /* |
293 | void TheNSResources::renumberConnections( void ) { | 296 | void TheNSResources::renumberConnections( void ) { |
294 | Name2Connection_t & M = NSResources->connections(); | 297 | Name2Connection_t & M = NSResources->connections(); |
295 | NodeCollection * NC; | 298 | NodeCollection * NC; |
296 | 299 | ||
297 | // for all connections | 300 | // for all connections |
298 | NodeCollection::resetMaxNr(); | 301 | NodeCollection::resetMaxNr(); |
299 | for( QDictIterator<NodeCollection> it(M); | 302 | for( QDictIterator<NodeCollection> it(M); |
300 | it.current(); | 303 | it.current(); |
301 | ++it ) { | 304 | ++it ) { |
302 | NC = it.current(); | 305 | NC = it.current(); |
303 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 306 | NC->setNumber( NC->maxConnectionNumber()+1 ); |
304 | NC->setModified( 1 ); | 307 | NC->setModified( 1 ); |
305 | } | 308 | } |
306 | } | 309 | } |
307 | */ | 310 | */ |
308 | 311 | ||
309 | typedef struct EnvVars { | 312 | typedef struct EnvVars { |
310 | char * Name; | 313 | char * Name; |
311 | int Len; | 314 | int Len; |
312 | } EnvVar_t; | 315 | } EnvVar_t; |
313 | 316 | ||
314 | #define AnEV(x) x, sizeof(x)-1 | 317 | #define AnEV(x) x, sizeof(x)-1 |
315 | 318 | ||
316 | static EnvVar_t EV[] = { | 319 | static EnvVar_t EV[] = { |
317 | AnEV( "HOME" ), | 320 | AnEV( "HOME" ), |
318 | AnEV( "LOGNAME" ), | 321 | AnEV( "LOGNAME" ), |
319 | AnEV( "USER" ), | 322 | AnEV( "USER" ), |
320 | AnEV( "LD_LIBRARY_PATH" ), | 323 | AnEV( "LD_LIBRARY_PATH" ), |
321 | AnEV( "PATH" ), | 324 | AnEV( "PATH" ), |
322 | AnEV( "QTDIR" ), | 325 | AnEV( "QTDIR" ), |
323 | AnEV( "OPIEDIR" ), | 326 | AnEV( "OPIEDIR" ), |
324 | AnEV( "SHELL" ), | 327 | AnEV( "SHELL" ), |
325 | { NULL, 0 } | 328 | { NULL, 0 } |
326 | }; | 329 | }; |
327 | 330 | ||
328 | void TheNSResources::detectCurrentUser( void ) { | 331 | void TheNSResources::detectCurrentUser( void ) { |
329 | // find current running qpe | 332 | // find current running qpe |
330 | QString QPEEnvFile = ""; | 333 | QString QPEEnvFile = ""; |
331 | 334 | ||
332 | CurrentUser.UserName = ""; | 335 | CurrentUser.UserName = ""; |
333 | CurrentUser.HomeDir = ""; | 336 | CurrentUser.HomeDir = ""; |
334 | 337 | ||
335 | if( getenv( "OPIEDIR" ) == 0 ) { | 338 | if( getenv( "OPIEDIR" ) == 0 ) { |
336 | // nothing known | 339 | // nothing known |
337 | { // open proc dir and find all dirs in it | 340 | { // open proc dir and find all dirs in it |
338 | QRegExp R("[0-9]+"); | 341 | QRegExp R("[0-9]+"); |
339 | QDir ProcDir( "/proc" ); | 342 | QDir ProcDir( "/proc" ); |
340 | QFileInfo FI; | 343 | QFileInfo FI; |
341 | QStringList EL = ProcDir.entryList( QDir::Dirs ); | 344 | QStringList EL = ProcDir.entryList( QDir::Dirs ); |
342 | 345 | ||
343 | // print it out | 346 | // print it out |
344 | for ( QStringList::Iterator it = EL.begin(); | 347 | for ( QStringList::Iterator it = EL.begin(); |
345 | it != EL.end(); | 348 | it != EL.end(); |
346 | ++it ) { | 349 | ++it ) { |
347 | if( R.match( (*it) ) >= 0 ) { | 350 | if( R.match( (*it) ) >= 0 ) { |
348 | QString S = ProcDir.path()+"/"+ (*it); | 351 | QString S = ProcDir.path()+"/"+ (*it); |
349 | S.append( "/exe" ); | 352 | S.append( "/exe" ); |
350 | FI.setFile( S ); | 353 | FI.setFile( S ); |
351 | // get the link | 354 | // get the link |
352 | S = FI.readLink(); | 355 | S = FI.readLink(); |
353 | if( S.right( 8 ) == "/bin/qpe" ) { | 356 | if( S.right( 8 ) == "/bin/qpe" ) { |
354 | // found running qpe | 357 | // found running qpe |
355 | QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); | 358 | QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); |
356 | break; | 359 | break; |
357 | } | 360 | } |
358 | } | 361 | } |
359 | } | 362 | } |
360 | } | 363 | } |
361 | 364 | ||
362 | if( QPEEnvFile.isEmpty() ) { | 365 | if( QPEEnvFile.isEmpty() ) { |
363 | // could not find qpe | 366 | // could not find qpe |
364 | Log(("Could not find qpe\n" )); | 367 | Log(("Could not find qpe\n" )); |
365 | return; | 368 | return; |
366 | } | 369 | } |
367 | 370 | ||
368 | // FI now contains path ProcDir to the cmd dir | 371 | // FI now contains path ProcDir to the cmd dir |
369 | { char * Buf = 0; | 372 | { char * Buf = 0; |
370 | char TB[1024]; | 373 | char TB[1024]; |
371 | long BufSize = 0; | 374 | long BufSize = 0; |
372 | int fd; | 375 | int fd; |
373 | int rd; | 376 | int rd; |
374 | 377 | ||
375 | fd = open( QPEEnvFile.latin1(), O_RDONLY ); | 378 | fd = open( QPEEnvFile.latin1(), O_RDONLY ); |
376 | if( fd < 0 ) { | 379 | if( fd < 0 ) { |
377 | Log(("Could not open %s : %d\n", | 380 | Log(("Could not open %s : %d\n", |
378 | QPEEnvFile.latin1(), errno )); | 381 | QPEEnvFile.latin1(), errno )); |
379 | return; | 382 | return; |
380 | } | 383 | } |
381 | 384 | ||
382 | while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { | 385 | while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { |
383 | Buf = (char *)realloc( Buf, BufSize+rd ); | 386 | Buf = (char *)realloc( Buf, BufSize+rd ); |
384 | memcpy( Buf+BufSize, TB, rd ); | 387 | memcpy( Buf+BufSize, TB, rd ); |
385 | BufSize += rd; | 388 | BufSize += rd; |
386 | } | 389 | } |
387 | 390 | ||
388 | char * Data = Buf; | 391 | char * Data = Buf; |
389 | char * DataEnd = Data+BufSize-1; | 392 | char * DataEnd = Data+BufSize-1; |
390 | 393 | ||
391 | // get env items out of list | 394 | // get env items out of list |
392 | while( Data < DataEnd ) { | 395 | while( Data < DataEnd ) { |
393 | 396 | ||
394 | EnvVar_t * Run = EV; | 397 | EnvVar_t * Run = EV; |
395 | while( Run->Name ) { | 398 | while( Run->Name ) { |
396 | if( strncmp( Data, Run->Name, Run->Len ) == 0 && | 399 | if( strncmp( Data, Run->Name, Run->Len ) == 0 && |
397 | Data[Run->Len] == '=' | 400 | Data[Run->Len] == '=' |
398 | ) { | 401 | ) { |
399 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | 402 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); |
400 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | 403 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = |
401 | strdup( Data ); | 404 | strdup( Data ); |
402 | 405 | ||
403 | if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { | 406 | if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { |
404 | // put OPIEDIR in env | 407 | // put OPIEDIR in env |
405 | putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); | 408 | putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); |
406 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { | 409 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { |
407 | CurrentUser.HomeDir = Data+5; | 410 | CurrentUser.HomeDir = Data+5; |
408 | } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { | 411 | } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { |
409 | CurrentUser.UserName = Data+8; | 412 | CurrentUser.UserName = Data+8; |
410 | } | 413 | } |
411 | break; | 414 | break; |
412 | } | 415 | } |
413 | Run ++; | 416 | Run ++; |
414 | } | 417 | } |
415 | 418 | ||
416 | Data += strlen( Data )+1; | 419 | Data += strlen( Data )+1; |
417 | } | 420 | } |
418 | 421 | ||
419 | free( Buf ); | 422 | free( Buf ); |
420 | 423 | ||
421 | if( ! CurrentUser.UserName.isEmpty() ) { | 424 | if( ! CurrentUser.UserName.isEmpty() ) { |
422 | // find user info | 425 | // find user info |
423 | struct passwd pwd; | 426 | struct passwd pwd; |
424 | struct passwd * pwdres; | 427 | struct passwd * pwdres; |
425 | 428 | ||
426 | if( getpwnam_r( CurrentUser.UserName.latin1(), | 429 | if( getpwnam_r( CurrentUser.UserName.latin1(), |
427 | &pwd, TB, sizeof(TB), &pwdres ) || | 430 | &pwd, TB, sizeof(TB), &pwdres ) || |
428 | pwdres == 0 ) { | 431 | pwdres == 0 ) { |
429 | Log(("Could not determine user %s : %d\n", | 432 | Log(("Could not determine user %s : %d\n", |
430 | CurrentUser.UserName.latin1(), errno )); | 433 | CurrentUser.UserName.latin1(), errno )); |
431 | return; | 434 | return; |
432 | } | 435 | } |
433 | CurrentUser.Uid = pwd.pw_uid; | 436 | CurrentUser.Uid = pwd.pw_uid; |
434 | CurrentUser.Gid = pwd.pw_gid; | 437 | CurrentUser.Gid = pwd.pw_gid; |
435 | } else{ | 438 | } else{ |
436 | CurrentUser.Uid = | 439 | CurrentUser.Uid = |
437 | CurrentUser.Gid = -1; | 440 | CurrentUser.Gid = -1; |
438 | } | 441 | } |
439 | } | 442 | } |
440 | 443 | ||
441 | } else { | 444 | } else { |
442 | char * X; | 445 | char * X; |
443 | QString S; | 446 | QString S; |
444 | 447 | ||
445 | EnvVar_t * Run = EV; | 448 | EnvVar_t * Run = EV; |
446 | while( Run->Name ) { | 449 | while( Run->Name ) { |
447 | 450 | ||
448 | if( ( X = getenv( Run->Name ) ) ) { | 451 | if( ( X = getenv( Run->Name ) ) ) { |
449 | Log(( "Env : %s = %s\n", Run->Name, X )); | 452 | Log(( "Env : %s = %s\n", Run->Name, X )); |
450 | 453 | ||
451 | S.sprintf( "%s=%s", Run->Name, X ); | 454 | S.sprintf( "%s=%s", Run->Name, X ); |
452 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); | 455 | CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); |
453 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = | 456 | CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = |
454 | strdup( S.latin1() ); | 457 | strdup( S.latin1() ); |
455 | 458 | ||
456 | if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { | 459 | if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { |
457 | CurrentUser.UserName = X; | 460 | CurrentUser.UserName = X; |
458 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { | 461 | } else if( strcmp( Run->Name, "HOME" ) == 0 ) { |
459 | CurrentUser.HomeDir = X; | 462 | CurrentUser.HomeDir = X; |
460 | } // regulare env var | 463 | } // regulare env var |
461 | } else { | 464 | } else { |
462 | Log(("Could not determine %s\n", Run->Name )); | 465 | Log(("Could not determine %s\n", Run->Name )); |
463 | } | 466 | } |
464 | Run ++; | 467 | Run ++; |
465 | } | 468 | } |
466 | 469 | ||
467 | CurrentUser.Uid = getuid(); | 470 | CurrentUser.Uid = getuid(); |
468 | CurrentUser.Gid = getgid(); | 471 | CurrentUser.Gid = getgid(); |
469 | } | 472 | } |
470 | } | 473 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 634cd39..5d90286 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h | |||
@@ -1,143 +1,144 @@ | |||
1 | #ifndef __RESOURCES__H | 1 | #ifndef __RESOURCES__H |
2 | #define __RESOURCES__H | 2 | #define __RESOURCES__H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qdict.h> | 5 | #include <qdict.h> |
6 | #include <qmap.h> | 6 | #include <qmap.h> |
7 | #include <qlist.h> | 7 | #include <qlist.h> |
8 | #include "netnode.h" | 8 | #include "netnode.h" |
9 | #include "systemfile.h" | 9 | #include "systemfile.h" |
10 | #include "system.h" | 10 | #include "system.h" |
11 | 11 | ||
12 | class QLibrary; | 12 | class QLibrary; |
13 | class QPixmap; | 13 | class QPixmap; |
14 | class ANetNode; | 14 | class ANetNode; |
15 | class ANetNodeInstance; | 15 | class ANetNodeInstance; |
16 | 16 | ||
17 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); | 17 | typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); |
18 | 18 | ||
19 | typedef struct NetNode_S { | 19 | typedef struct NetNode_S { |
20 | ANetNode * NetNode; | 20 | ANetNode * NetNode; |
21 | QLibrary * TheLibrary; | 21 | QLibrary * TheLibrary; |
22 | long NodeCountInLib; | 22 | long NodeCountInLib; |
23 | } NetNode_t; | 23 | } NetNode_t; |
24 | 24 | ||
25 | class CurrentQPEUser { | 25 | class CurrentQPEUser { |
26 | 26 | ||
27 | public : | 27 | public : |
28 | CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} | 28 | CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} |
29 | 29 | ||
30 | inline bool known( void ) | 30 | inline bool known( void ) |
31 | { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } | 31 | { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } |
32 | 32 | ||
33 | QString UserName; | 33 | QString UserName; |
34 | QString HomeDir; | 34 | QString HomeDir; |
35 | int Uid; | 35 | int Uid; |
36 | int Gid; | 36 | int Gid; |
37 | QArray<char *> EnvList; | 37 | QArray<char *> EnvList; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | typedef QDict<NetNode_t> Name2NetNode_t; | 40 | typedef QDict<NetNode_t> Name2NetNode_t; |
41 | typedef QDict<ANetNodeInstance > Name2Instance_t; | 41 | typedef QDict<ANetNodeInstance > Name2Instance_t; |
42 | typedef QDict<NodeCollection> Name2Connection_t; | 42 | typedef QDict<NodeCollection> Name2Connection_t; |
43 | typedef QDict<SystemFile> Name2SystemFile_t; | 43 | typedef QDict<SystemFile> Name2SystemFile_t; |
44 | 44 | ||
45 | class TheNSResources { | 45 | class TheNSResources { |
46 | 46 | ||
47 | public : | 47 | public : |
48 | 48 | ||
49 | TheNSResources( void ); | 49 | TheNSResources( void ); |
50 | ~TheNSResources( ); | 50 | ~TheNSResources( ); |
51 | 51 | ||
52 | // give busy feedback | 52 | // give busy feedback |
53 | void busy( bool B ); | 53 | void busy( bool B ); |
54 | 54 | ||
55 | System & system() | 55 | System & system() |
56 | { return *TheSystem; } | 56 | { return *TheSystem; } |
57 | 57 | ||
58 | int assignConnectionNumber(void); | 58 | int assignConnectionNumber(void); |
59 | QPixmap getPixmap( const QString & Name ); | 59 | QPixmap getPixmap( const QString & Name ); |
60 | 60 | ||
61 | Name2NetNode_t & netNodes( void ) | 61 | Name2NetNode_t & netNodes( void ) |
62 | { return AllNodeTypes; } | 62 | { return AllNodeTypes; } |
63 | bool netNodeExists( const QString & X ) | 63 | bool netNodeExists( const QString & X ) |
64 | { return AllNodeTypes.find(X)!=0; } | 64 | { return AllNodeTypes.find(X)!=0; } |
65 | ANetNode * findNetNode( const QString & N ) | 65 | ANetNode * findNetNode( const QString & N ) |
66 | { NetNode_t * NNT = AllNodeTypes.find(N); | 66 | { NetNode_t * NNT = AllNodeTypes.find(N); |
67 | return (NNT) ? NNT->NetNode : 0; | 67 | return (NNT) ? NNT->NetNode : 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | // define new plugin (=node) | 70 | // define new plugin (=node) |
71 | void addNodeType( const QString & ID, | 71 | void addNodeType( const QString & ID, |
72 | const QString & LongName, | 72 | const QString & LongName, |
73 | const QString & Description ); | 73 | const QString & Description ); |
74 | 74 | ||
75 | Name2SystemFile_t & systemFiles( void ) | 75 | Name2SystemFile_t & systemFiles( void ) |
76 | { return SystemFiles; } | 76 | { return SystemFiles; } |
77 | void addSystemFile( const QString & ID, | 77 | void addSystemFile( const QString & ID, |
78 | const QString & P, | 78 | const QString & P, |
79 | bool KDI ); | 79 | bool KDI ); |
80 | 80 | ||
81 | ANetNodeInstance * createNodeInstance( const QString & S ) | 81 | ANetNodeInstance * createNodeInstance( const QString & S ) |
82 | { ANetNodeInstance * NNI = 0; | 82 | { ANetNodeInstance * NNI = 0; |
83 | printf( "Find node type %s\n", S.latin1() ); | ||
83 | NetNode_t * NNT = AllNodeTypes[S]; | 84 | NetNode_t * NNT = AllNodeTypes[S]; |
84 | if( ! NNT ) { | 85 | if( ! NNT ) { |
85 | return 0; | 86 | return 0; |
86 | } | 87 | } |
87 | NNI = NNT->NetNode->createInstance(); | 88 | NNI = NNT->NetNode->createInstance(); |
88 | NNI->initialize(); | 89 | NNI->initialize(); |
89 | return NNI; | 90 | return NNI; |
90 | } | 91 | } |
91 | 92 | ||
92 | Name2Instance_t & netNodeInstances( void ) | 93 | Name2Instance_t & netNodeInstances( void ) |
93 | { return AllNodes; } | 94 | { return AllNodes; } |
94 | void addNodeInstance( ANetNodeInstance * I ) | 95 | void addNodeInstance( ANetNodeInstance * I ) |
95 | { AllNodes.insert( I->name(), I ); } | 96 | { AllNodes.insert( I->name(), I ); } |
96 | void removeNodeInstance( const QString & N ) | 97 | void removeNodeInstance( const QString & N ) |
97 | { AllNodes.remove( N );} | 98 | { AllNodes.remove( N );} |
98 | ANetNodeInstance * findNodeInstance( const QString & S ) | 99 | ANetNodeInstance * findNodeInstance( const QString & S ) |
99 | { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } | 100 | { return AllNodes[S]; } |
100 | 101 | ||
101 | const QString & netNode2Name( const char * Type ); | 102 | const QString & netNode2Name( const char * Type ); |
102 | const QString & netNode2Description( const char * Type ); | 103 | const QString & netNode2Description( const char * Type ); |
103 | 104 | ||
104 | void addConnection( NodeCollection * NC ); | 105 | void addConnection( NodeCollection * NC ); |
105 | void removeConnection( const QString & N ); | 106 | void removeConnection( const QString & N ); |
106 | NodeCollection * findConnection( const QString & N ); | 107 | NodeCollection * findConnection( const QString & N ); |
107 | NodeCollection * getConnection( int nr ); | 108 | NodeCollection * getConnection( int nr ); |
108 | Name2Connection_t & connections( void ) | 109 | Name2Connection_t & connections( void ) |
109 | { return ConnectionsMap; } | 110 | { return ConnectionsMap; } |
110 | 111 | ||
111 | inline bool userKnown( void ) | 112 | inline bool userKnown( void ) |
112 | { return CurrentUser.known(); } | 113 | { return CurrentUser.known(); } |
113 | CurrentQPEUser & currentUser( void ) | 114 | CurrentQPEUser & currentUser( void ) |
114 | { return CurrentUser; } | 115 | { return CurrentUser; } |
115 | 116 | ||
116 | private : | 117 | private : |
117 | 118 | ||
118 | void detectCurrentUser( void ); | 119 | void detectCurrentUser( void ); |
119 | QString tr( const char * path ); | 120 | QString tr( const char * path ); |
120 | void findAvailableNetNodes( const QString &path ); | 121 | void findAvailableNetNodes( const QString &path ); |
121 | bool loadNetNode( | 122 | bool loadNetNode( |
122 | const QString &pluginFileName, | 123 | const QString &pluginFileName, |
123 | const QString &resolveString = "create_plugin"); | 124 | const QString &resolveString = "create_plugin"); |
124 | 125 | ||
125 | QMap< QString, QString> NodeTypeNameMap; | 126 | QMap< QString, QString> NodeTypeNameMap; |
126 | QMap< QString, QString> NodeTypeDescriptionMap; | 127 | QMap< QString, QString> NodeTypeDescriptionMap; |
127 | Name2Connection_t ConnectionsMap; | 128 | Name2Connection_t ConnectionsMap; |
128 | System * TheSystem; | 129 | System * TheSystem; |
129 | Name2SystemFile_t SystemFiles; | 130 | Name2SystemFile_t SystemFiles; |
130 | 131 | ||
131 | // all node type classes | 132 | // all node type classes |
132 | Name2NetNode_t AllNodeTypes; | 133 | Name2NetNode_t AllNodeTypes; |
133 | 134 | ||
134 | // all nodes | 135 | // all nodes |
135 | Name2Instance_t AllNodes; | 136 | Name2Instance_t AllNodes; |
136 | 137 | ||
137 | CurrentQPEUser CurrentUser; | 138 | CurrentQPEUser CurrentUser; |
138 | }; | 139 | }; |
139 | 140 | ||
140 | extern TheNSResources * _NSResources; | 141 | extern TheNSResources * _NSResources; |
141 | #define NSResources _NSResources | 142 | #define NSResources _NSResources |
142 | 143 | ||
143 | #endif | 144 | #endif |