Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 152 |
1 files changed, 85 insertions, 67 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 698a941..d76353a 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -116,8 +116,9 @@ void NetworkSettingsData::loadSettings( void ) { | |||
116 | 116 | ||
117 | if( S == "connection" ) { | 117 | if( S == "connection" ) { |
118 | // load connections -> collections of nodes | 118 | // load connections -> collections of nodes |
119 | NodeCollection * NC = new NodeCollection( TS ); | 119 | bool Dangling; |
120 | NSResources->addConnection( NC ); | 120 | NodeCollection * NC = new NodeCollection( TS, Dangling ); |
121 | NSResources->addConnection( NC, Dangling ); | ||
121 | } else { | 122 | } else { |
122 | ANetNode * NN = 0; | 123 | ANetNode * NN = 0; |
123 | ANetNodeInstance* NNI = 0; | 124 | ANetNodeInstance* NNI = 0; |
@@ -133,45 +134,45 @@ void NetworkSettingsData::loadSettings( void ) { | |||
133 | 134 | ||
134 | if( NN == 0 && NNI == 0 ) { | 135 | if( NN == 0 && NNI == 0 ) { |
135 | LeftOvers.append( Line ); | 136 | LeftOvers.append( Line ); |
136 | } | 137 | do { |
138 | Line = TS.readLine(); | ||
139 | // store even delimiter | ||
140 | LeftOvers.append( Line ); | ||
141 | } while ( ! Line.isEmpty() ); | ||
142 | |||
143 | //next section | ||
144 | continue; | ||
145 | } | ||
137 | 146 | ||
147 | // read entries of this section | ||
138 | do { | 148 | do { |
139 | S = Line = TS.readLine(); | 149 | S = Line = TS.readLine(); |
140 | 150 | ||
141 | if( NN || NNI ) { | 151 | if( S.isEmpty() ) { |
142 | if( S.isEmpty() ) { | 152 | // empty line |
143 | // empty line | 153 | break; |
144 | break; | 154 | } |
145 | } | 155 | idx = S.find( '=' ); |
146 | idx = S.find( '=' ); | 156 | if( idx > 0 ) { |
147 | if( idx > 0 ) { | 157 | Attr = S.left( idx ); |
148 | Attr = S.left( idx ); | 158 | Value = S.mid( idx+1, S.length() ); |
149 | Value = S.mid( idx+1, S.length() ); | 159 | } else { |
150 | } else { | 160 | Value=""; |
151 | Value=""; | 161 | Attr = S; |
152 | Attr = S; | 162 | } |
153 | } | ||
154 | 163 | ||
155 | Value.stripWhiteSpace(); | 164 | Value.stripWhiteSpace(); |
156 | Attr.stripWhiteSpace(); | 165 | Attr.stripWhiteSpace(); |
157 | Attr.lower(); | 166 | Attr.lower(); |
158 | // dequote Attr | 167 | // dequote Attr |
159 | Value = deQuote(Value); | 168 | Value = deQuote(Value); |
160 | 169 | ||
161 | if( NN ) { | 170 | if( NN ) { |
162 | // set the attribute | 171 | // set the attribute |
163 | NN->setAttribute( Attr, Value ); | 172 | NN->setAttribute( Attr, Value ); |
164 | } else { | ||
165 | // set the attribute | ||
166 | NNI->setAttribute( Attr, Value ); | ||
167 | } | ||
168 | } else { | 173 | } else { |
169 | LeftOvers.append( Line ); | 174 | // set the attribute |
170 | // add empty line too as delimiter | 175 | NNI->setAttribute( Attr, Value ); |
171 | if( S.isEmpty() ) { | ||
172 | // empty line | ||
173 | break; | ||
174 | } | ||
175 | } | 176 | } |
176 | } while( 1 ); | 177 | } while( 1 ); |
177 | 178 | ||
@@ -181,6 +182,7 @@ void NetworkSettingsData::loadSettings( void ) { | |||
181 | NNI->setNew( FALSE ); | 182 | NNI->setNew( FALSE ); |
182 | NSResources->addNodeInstance( NNI ); | 183 | NSResources->addNodeInstance( NNI ); |
183 | } | 184 | } |
185 | |||
184 | if( NN ) { | 186 | if( NN ) { |
185 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); | 187 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); |
186 | } | 188 | } |
@@ -211,46 +213,61 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
211 | 213 | ||
212 | QTextStream TS( &F ); | 214 | QTextStream TS( &F ); |
213 | 215 | ||
214 | // save leftovers | ||
215 | for ( QStringList::Iterator it = LeftOvers.begin(); | ||
216 | it != LeftOvers.end(); ++it ) { | ||
217 | TS << (*it) << endl; | ||
218 | } | ||
219 | |||
220 | // save global configs | 216 | // save global configs |
221 | for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); | 217 | for( QDictIterator<ANetNode> it( NSResources->netNodes() ); |
222 | it.current(); | 218 | it.current(); |
223 | ++it ) { | 219 | ++it ) { |
224 | TS << "[nodetype " | 220 | TS << "[nodetype " |
225 | << quote( QString( it.current()->NetNode->name() ) ) | 221 | << quote( QString( it.current()->name() ) ) |
226 | << "]" | 222 | << "]" |
227 | << endl; | 223 | << endl; |
228 | 224 | ||
229 | it.current()->NetNode->saveAttributes( TS ); | 225 | it.current()->saveAttributes( TS ); |
230 | TS << endl; | 226 | TS << endl; |
231 | } | 227 | } |
232 | 228 | ||
229 | // save leftovers | ||
230 | for ( QStringList::Iterator it = LeftOvers.begin(); | ||
231 | it != LeftOvers.end(); ++it ) { | ||
232 | TS << (*it) << endl; | ||
233 | } | ||
234 | |||
235 | // save all netnode instances | ||
236 | { ANetNodeInstance * NNI; | ||
237 | for( QDictIterator<ANetNodeInstance> nit( | ||
238 | NSResources->netNodeInstances()); | ||
239 | nit.current(); | ||
240 | ++nit ) { | ||
241 | // header | ||
242 | NNI = nit.current(); | ||
243 | TS << '[' | ||
244 | << QString(NNI->nodeClass()->name()) | ||
245 | << ']' | ||
246 | << endl; | ||
247 | NNI->saveAttributes( TS ); | ||
248 | TS << endl; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | // good connections | ||
233 | { Name2Connection_t & M = NSResources->connections(); | 253 | { Name2Connection_t & M = NSResources->connections(); |
234 | ANetNodeInstance * NNI; | ||
235 | 254 | ||
236 | // for all connections | 255 | // for all connections |
237 | for( QDictIterator<NodeCollection> it(M); | 256 | for( QDictIterator<NodeCollection> it(M); |
238 | it.current(); | 257 | it.current(); |
239 | ++it ) { | 258 | ++it ) { |
240 | // all nodes in those connections | 259 | TS << "[connection]" << endl; |
241 | for( QListIterator<ANetNodeInstance> nit(*(it.current())); | 260 | it.current()->save(TS); |
242 | nit.current(); | 261 | } |
243 | ++nit ) { | 262 | } |
244 | // header | ||
245 | NNI = nit.current(); | ||
246 | TS << '[' | ||
247 | << QString(NNI->nodeClass()->name()) | ||
248 | << ']' | ||
249 | << endl; | ||
250 | NNI->saveAttributes( TS ); | ||
251 | TS << endl; | ||
252 | } | ||
253 | 263 | ||
264 | // save dangling connections | ||
265 | { Name2Connection_t & M = NSResources->danglingConnections(); | ||
266 | |||
267 | // for all connections | ||
268 | for( QDictIterator<NodeCollection> it(M); | ||
269 | it.current(); | ||
270 | ++it ) { | ||
254 | TS << "[connection]" << endl; | 271 | TS << "[connection]" << endl; |
255 | it.current()->save(TS); | 272 | it.current()->save(TS); |
256 | } | 273 | } |
@@ -289,14 +306,15 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
289 | // regenerate system files | 306 | // regenerate system files |
290 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | 307 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
291 | 308 | ||
292 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 309 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
293 | nnit.current(); | 310 | nnit.current(); |
294 | ++nnit ) { | 311 | ++nnit ) { |
295 | { QStringList SL; | 312 | bool FirstItem = 1; |
296 | bool FirstItem = 1; | 313 | bool Generated = 0; |
297 | bool Generated = 0; | ||
298 | 314 | ||
299 | CurDevNN = nnit.current()->NetNode; | 315 | CurDevNN = nnit.current(); |
316 | |||
317 | { QStringList SL; | ||
300 | SL = CurDevNN->properFiles(); | 318 | SL = CurDevNN->properFiles(); |
301 | 319 | ||
302 | for ( QStringList::Iterator it = SL.begin(); | 320 | for ( QStringList::Iterator it = SL.begin(); |
@@ -395,10 +413,10 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
395 | SF = sfit.current(); | 413 | SF = sfit.current(); |
396 | 414 | ||
397 | // reset all | 415 | // reset all |
398 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 416 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
399 | nnit.current(); | 417 | nnit.current(); |
400 | ++nnit ) { | 418 | ++nnit ) { |
401 | nnit.current()->NetNode->setDone(0); | 419 | nnit.current()->setDone(0); |
402 | } | 420 | } |
403 | 421 | ||
404 | for( QDictIterator<ANetNodeInstance> nniit( | 422 | for( QDictIterator<ANetNodeInstance> nniit( |
@@ -420,11 +438,11 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
420 | 438 | ||
421 | // are there netnodes that have instances and need | 439 | // are there netnodes that have instances and need |
422 | // to write data in this system file ? | 440 | // to write data in this system file ? |
423 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 441 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
424 | ! needToGenerate && nnit.current(); | 442 | ! needToGenerate && nnit.current(); |
425 | ++nnit ) { | 443 | ++nnit ) { |
426 | 444 | ||
427 | NN = nnit.current()->NetNode; | 445 | NN = nnit.current(); |
428 | 446 | ||
429 | if( NN->hasDataForFile( *SF ) ) { | 447 | if( NN->hasDataForFile( *SF ) ) { |
430 | // netnode can have data | 448 | // netnode can have data |