Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/netnode.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/netnode.h | 268 |
1 files changed, 189 insertions, 79 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index ca35c27..d3d7b34 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <qlist.h> | 5 | #include <qlist.h> |
6 | #include <qdict.h> | 6 | #include <qdict.h> |
7 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
8 | #include <qstringlist.h> | ||
8 | #include <qobject.h> | 9 | #include <qobject.h> |
9 | #include <time.h> | 10 | #include <time.h> |
10 | 11 | ||
@@ -77,32 +78,58 @@ public: | |||
77 | ANetNode( const char * Name ) : QObject( 0, Name ) {} | 78 | ANetNode( const char * Name ) : QObject( 0, Name ) {} |
78 | virtual ~ANetNode(){}; | 79 | virtual ~ANetNode(){}; |
79 | 80 | ||
80 | // pixmap needed for this NetNode | 81 | // |
81 | virtual const QString pixmapName() = 0; | 82 | // |
83 | // standard methods with sensible default | ||
84 | // | ||
85 | // | ||
82 | 86 | ||
83 | // description for this NetNode | 87 | inline int done( void ) |
84 | virtual const QString nodeDescription() = 0; | 88 | { return Done; } |
89 | inline void setDone( int D ) | ||
90 | { Done = D; } | ||
85 | 91 | ||
86 | // create a blank instance of a net node | 92 | // does this Node provide a Connection |
87 | virtual ANetNodeInstance * createInstance( void ) = 0; | 93 | inline bool isToplevel( void ) |
94 | { return strcmp( provides(), "fullsetup") == 0 ; } | ||
88 | 95 | ||
89 | // return feature this NetNode provides | 96 | // set the value of an attribute |
90 | virtual const char * provides( void ) = 0; | 97 | void setAttribute( QString & Attr, QString & Value ) ; |
91 | virtual const char ** needs( void ) = 0; | 98 | void saveAttributes( QTextStream & TS ) ; |
92 | 99 | ||
93 | // generate files specific for this node (if any) | 100 | // compiled references to 'needed' NetNodes -> needs list |
94 | virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; | 101 | inline void setAlternatives( NetNodeList * Alt ) |
95 | // return TRUE if this node has data to be inserted in systemfile | 102 | { Alternatives = Alt; } |
96 | // with name S | 103 | inline NetNodeList & alternatives( void ) |
97 | virtual bool hasDataFor( const QString & S ) = 0; | 104 | { return *Alternatives; } |
98 | // generate data specific for the device for the system file S | 105 | |
99 | // called only IF data was needed | 106 | // |
100 | virtual bool generateDeviceDataForCommonFile( | 107 | // |
101 | SystemFile & SF, long DevNr ) = 0; | 108 | // Virtual methods with sensible default |
109 | // | ||
110 | // | ||
111 | |||
112 | // do instances of this noce class have data for this file | ||
113 | virtual bool hasDataForFile( const QString & ) | ||
114 | { return 0; } | ||
115 | |||
116 | // generate instance independent stuff | ||
117 | // 0 : data output, 1 no data, 2 error | ||
118 | virtual short generateFile( const QString & , | ||
119 | const QString & , | ||
120 | QTextStream & , | ||
121 | long ) | ||
122 | { return 1; } | ||
123 | |||
124 | // generate instance dependent but profile common stuff | ||
125 | // 0 : data output, 1 no data, 2 error | ||
126 | virtual short generateFile( const QString & , | ||
127 | const QString & , | ||
128 | QTextStream & , | ||
129 | ANetNodeInstance * , | ||
130 | long ) | ||
131 | { return 1; } | ||
102 | 132 | ||
103 | // does this Node provide a Connection | ||
104 | bool isToplevel( void ) | ||
105 | { return strcmp( provides(), "fullsetup") == 0 ; } | ||
106 | 133 | ||
107 | // generate NIC name based on instance nr | 134 | // generate NIC name based on instance nr |
108 | // only relevant if node instances are devices | 135 | // only relevant if node instances are devices |
@@ -114,15 +141,28 @@ public: | |||
114 | virtual long instanceCount( void ) | 141 | virtual long instanceCount( void ) |
115 | { return 1; } | 142 | { return 1; } |
116 | 143 | ||
117 | // set the value of an attribute | 144 | // return list of files that are specific for this node class |
118 | void setAttribute( QString & Attr, QString & Value ) ; | 145 | virtual QStringList * properFiles( void ) |
119 | void saveAttributes( QTextStream & TS ) ; | 146 | { return 0; } |
120 | 147 | ||
121 | // compiled references to 'needed' NetNodes -> needs list | 148 | // |
122 | void setAlternatives( NetNodeList * Alt ) | 149 | // |
123 | { Alternatives = Alt; } | 150 | // pure virtual methods with sensible default |
124 | NetNodeList & alternatives( void ) | 151 | // |
125 | { return *Alternatives; } | 152 | // |
153 | |||
154 | // pixmap needed for this NetNode | ||
155 | virtual const QString pixmapName() = 0; | ||
156 | |||
157 | // description for this NetNode | ||
158 | virtual const QString nodeDescription() = 0; | ||
159 | |||
160 | // create a blank instance of a net node | ||
161 | virtual ANetNodeInstance * createInstance( void ) = 0; | ||
162 | |||
163 | // return feature this NetNode provides | ||
164 | virtual const char * provides( void ) = 0; | ||
165 | virtual const char ** needs( void ) = 0; | ||
126 | 166 | ||
127 | protected : | 167 | protected : |
128 | 168 | ||
@@ -132,6 +172,7 @@ private : | |||
132 | 172 | ||
133 | virtual void setSpecificAttribute( QString & , QString & ) = 0; | 173 | virtual void setSpecificAttribute( QString & , QString & ) = 0; |
134 | virtual void saveSpecificAttribute( QTextStream & ) = 0; | 174 | virtual void saveSpecificAttribute( QTextStream & ) = 0; |
175 | int Done; | ||
135 | 176 | ||
136 | }; | 177 | }; |
137 | 178 | ||
@@ -143,27 +184,17 @@ public: | |||
143 | { IsModified=0; NodeType = NN; IsNew = TRUE; } | 184 | { IsModified=0; NodeType = NN; IsNew = TRUE; } |
144 | virtual ~ANetNodeInstance( void ) { } | 185 | virtual ~ANetNodeInstance( void ) { } |
145 | 186 | ||
146 | virtual RuntimeInfo * runtime( void ) = 0; | 187 | inline int done( void ) |
147 | 188 | { return Done; } | |
148 | void setConnection( NodeCollection * NC ) | 189 | inline void setDone( int D ) |
149 | { Connection = NC; } | 190 | { Done = D; } |
150 | NodeCollection * connection( void ) | ||
151 | { return Connection; } | ||
152 | |||
153 | // create edit widget under parent | ||
154 | virtual QWidget * edit( QWidget * parent ) = 0; | ||
155 | // is given data acceptable | ||
156 | virtual QString acceptable( void ) = 0; | ||
157 | 191 | ||
158 | // return data was modified | 192 | // return data was modified |
159 | void setModified( bool M ) | 193 | inline void setModified( bool M ) |
160 | { IsModified = M; } | 194 | { IsModified = M; } |
161 | bool isModified( void ) | 195 | inline bool isModified( void ) |
162 | { return IsModified; } | 196 | { return IsModified; } |
163 | 197 | ||
164 | // get data from GUI and store in node | ||
165 | virtual void commit( void ) = 0; | ||
166 | |||
167 | // get next node | 198 | // get next node |
168 | ANetNodeInstance * nextNode(); | 199 | ANetNodeInstance * nextNode(); |
169 | // return NetNode this is an instance of | 200 | // return NetNode this is an instance of |
@@ -178,38 +209,94 @@ public: | |||
178 | void saveAttributes( QTextStream & TS ) ; | 209 | void saveAttributes( QTextStream & TS ) ; |
179 | 210 | ||
180 | // return true if node isntance is NEW and not loaded | 211 | // return true if node isntance is NEW and not loaded |
181 | void setNew( bool IsN ) | 212 | inline void setNew( bool IsN ) |
182 | { IsNew = IsN; } | 213 | { IsNew = IsN; } |
183 | bool isNew( void ) | 214 | inline bool isNew( void ) |
184 | { return IsNew; } | 215 | { return IsNew; } |
185 | 216 | ||
186 | // return description for this instance | 217 | // return description for this instance |
187 | QString & description( void ) | 218 | inline QString & description( void ) |
188 | { return Description; } | 219 | { return Description; } |
189 | void setDescription( const QString & S ) | 220 | inline void setDescription( const QString & S ) |
190 | { Description = S; } | 221 | { Description = S; } |
191 | 222 | ||
192 | // pixmap for this instance -> from NetNode | 223 | // pixmap for this instance -> from NetNode |
193 | const QString pixmapName( void ) | 224 | inline const QString pixmapName( void ) |
194 | { return NodeType->pixmapName(); } | 225 | { return NodeType->pixmapName(); } |
195 | 226 | ||
196 | const char * provides( void ) | 227 | inline const char * provides( void ) |
197 | { return NodeType->provides(); } | 228 | { return NodeType->provides(); } |
198 | 229 | ||
199 | const char ** needs( void ) | 230 | inline const char ** needs( void ) |
200 | { return NodeType->needs(); } | 231 | { return NodeType->needs(); } |
201 | 232 | ||
202 | // returns node specific data -> only useful for 'buddy' | 233 | inline void setConnection( NodeCollection * NC ) |
203 | virtual void * data( void ) = 0; | 234 | { Connection = NC; } |
235 | inline NodeCollection * connection( void ) | ||
236 | { return Connection; } | ||
237 | |||
238 | // | ||
239 | // | ||
240 | // Virtual methods with sensible defaults | ||
241 | // | ||
242 | // | ||
204 | 243 | ||
205 | // return TRUE if this node has data to be inserted in systemfile | ||
206 | // with name S | ||
207 | virtual bool hasDataFor( const QString & S ) = 0; | ||
208 | 244 | ||
209 | // generate data specific for a profile and for the system file S | 245 | |
210 | // called only IF data was needed | 246 | // open proper file identified by S |
211 | virtual bool generateDataForCommonFile( | 247 | virtual QFile * openFile( const QString & ) |
212 | SystemFile & SF, long DevNr ) = 0; | 248 | { return 0; } |
249 | |||
250 | // check if this node (or sub nodes) have data for this file | ||
251 | virtual bool hasDataForFile( const QString & S ) | ||
252 | { return nodeClass()->hasDataForFile( S ); } | ||
253 | |||
254 | // generate code specific for this node but embedded | ||
255 | // in the section of the parent | ||
256 | // this is called within the code of the parent | ||
257 | virtual short generateFileEmbedded( const QString & ID, | ||
258 | const QString & Path, | ||
259 | QTextStream & TS, | ||
260 | long DevNr ) | ||
261 | { ANetNodeInstance * NNI = nextNode(); | ||
262 | return (NNI) ? NNI->generateFileEmbedded( ID, Path, TS, DevNr ) : 1; | ||
263 | } | ||
264 | |||
265 | // generate code specific for this node | ||
266 | // (or find the first node that does) | ||
267 | virtual short generateFile( const QString & ID, | ||
268 | const QString & Path, | ||
269 | QTextStream & TS, | ||
270 | long DevNr ) | ||
271 | { ANetNodeInstance * NNI = nextNode(); | ||
272 | return (NNI) ? NNI->generateFile( ID, Path, TS, DevNr ) : 1; | ||
273 | } | ||
274 | |||
275 | // return true if this node instance is triggered by this trigger | ||
276 | // could be delegated to deeper instances | ||
277 | virtual bool triggeredBy( const QString & ) | ||
278 | { return 0; } | ||
279 | |||
280 | // | ||
281 | // | ||
282 | // Pure virtual functions | ||
283 | // | ||
284 | // | ||
285 | |||
286 | // return runtime information for this node | ||
287 | virtual RuntimeInfo * runtime( void ) = 0; | ||
288 | |||
289 | // create edit widget under parent | ||
290 | virtual QWidget * edit( QWidget * parent ) = 0; | ||
291 | |||
292 | // is given data acceptable | ||
293 | virtual QString acceptable( void ) = 0; | ||
294 | |||
295 | // get data from GUI and store in node | ||
296 | virtual void commit( void ) = 0; | ||
297 | |||
298 | // returns node specific data -> only useful for 'buddy' | ||
299 | virtual void * data( void ) = 0; | ||
213 | 300 | ||
214 | protected : | 301 | protected : |
215 | 302 | ||
@@ -222,6 +309,7 @@ protected : | |||
222 | QString Description; | 309 | QString Description; |
223 | bool IsModified; | 310 | bool IsModified; |
224 | bool IsNew; | 311 | bool IsNew; |
312 | int Done; | ||
225 | 313 | ||
226 | static long InstanceCounter; | 314 | static long InstanceCounter; |
227 | }; | 315 | }; |
@@ -282,34 +370,39 @@ public : | |||
282 | NodeCollection( QTextStream & TS ); | 370 | NodeCollection( QTextStream & TS ); |
283 | ~NodeCollection( void ); | 371 | ~NodeCollection( void ); |
284 | 372 | ||
285 | int number( void ) | 373 | inline int done( void ) |
374 | { return Done; } | ||
375 | inline void setDone( int D ) | ||
376 | { Done = D; } | ||
377 | |||
378 | inline int number( void ) | ||
286 | { return Number; } | 379 | { return Number; } |
287 | void setNumber( int i ) | 380 | inline void setNumber( int i ) |
288 | { Number = i; } | 381 | { Number = i; } |
289 | bool isNew( void ) | 382 | inline bool isNew( void ) |
290 | { return IsNew; } | 383 | { return IsNew; } |
291 | void setNew( bool N ) | 384 | inline void setNew( bool N ) |
292 | { IsNew = N ; } | 385 | { IsNew = N ; } |
293 | bool isModified( void ) | 386 | inline bool isModified( void ) |
294 | { return IsModified; } | 387 | { return IsModified; } |
295 | void setModified( bool N ) | 388 | inline void setModified( bool N ) |
296 | { IsModified = N ; } | 389 | { IsModified = N ; } |
297 | 390 | ||
298 | bool handlesInterface( const QString & S ) { | 391 | inline bool handlesInterface( const QString & S ) { |
299 | return getToplevel()->runtime()->handlesInterface( S ); | 392 | return getToplevel()->runtime()->handlesInterface( S ); |
300 | } | 393 | } |
301 | 394 | ||
302 | InterfaceInfo * assignedInterface( void ) { | 395 | inline InterfaceInfo * assignedInterface( void ) { |
303 | return getToplevel()->runtime()->assignedInterface(); | 396 | return getToplevel()->runtime()->assignedInterface(); |
304 | } | 397 | } |
305 | 398 | ||
306 | AsDevice * device() { | 399 | inline AsDevice * device() { |
307 | return getToplevel()->runtime()->device(); | 400 | return getToplevel()->runtime()->device(); |
308 | } | 401 | } |
309 | 402 | ||
310 | bool triggersVPN(); | 403 | bool triggersVPN(); |
311 | 404 | ||
312 | State_t state( bool Update = 0 ) | 405 | inline State_t state( bool Update = 0 ) |
313 | { Log(( "%s state %d(=%d?)\n", Name.latin1(), CurrentState, | 406 | { Log(( "%s state %d(=%d?)\n", Name.latin1(), CurrentState, |
314 | Unchecked )); | 407 | Unchecked )); |
315 | if( CurrentState == Unchecked || Update ) { | 408 | if( CurrentState == Unchecked || Update ) { |
@@ -325,15 +418,15 @@ public : | |||
325 | // get the ixmap for this device | 418 | // get the ixmap for this device |
326 | QPixmap devicePixmap( void ); | 419 | QPixmap devicePixmap( void ); |
327 | QPixmap statePixmap( State_t S ); | 420 | QPixmap statePixmap( State_t S ); |
328 | QPixmap statePixmap( bool Update = 0 ) | 421 | inline QPixmap statePixmap( bool Update = 0 ) |
329 | { return statePixmap( state(Update) ); } | 422 | { return statePixmap( state(Update) ); } |
330 | QString stateName( State_t ); | 423 | QString stateName( State_t ); |
331 | QString stateName( bool Update = 0 ) | 424 | inline QString stateName( bool Update = 0 ) |
332 | { return stateName( state(Update) ); } | 425 | { return stateName( state(Update) ); } |
333 | 426 | ||
334 | bool setState( Action_t A, bool Force =0 ) | 427 | inline bool setState( Action_t A, bool Force =0 ) |
335 | { return getToplevel()->runtime()->setState( this, A, Force ); } | 428 | { return getToplevel()->runtime()->setState( this, A, Force ); } |
336 | bool canSetState( Action_t A ) | 429 | inline bool canSetState( Action_t A ) |
337 | { return getToplevel()->runtime()->canSetState( CurrentState, A ); } | 430 | { return getToplevel()->runtime()->canSetState( CurrentState, A ); } |
338 | 431 | ||
339 | void save( QTextStream & TS ); | 432 | void save( QTextStream & TS ); |
@@ -348,19 +441,35 @@ public : | |||
348 | ANetNodeInstance * findNext( ANetNodeInstance * NNI ); | 441 | ANetNodeInstance * findNext( ANetNodeInstance * NNI ); |
349 | ANetNodeInstance * findByName( const QString & S ); | 442 | ANetNodeInstance * findByName( const QString & S ); |
350 | 443 | ||
351 | const QString & name() | 444 | inline const QString & name() |
352 | { return Name; } | 445 | { return Name; } |
353 | 446 | ||
354 | const QString & description( void ); | 447 | const QString & description( void ); |
355 | 448 | ||
356 | void setName( const QString & N) | 449 | inline void setName( const QString & N) |
357 | { Name = N; } | 450 | { Name = N; } |
358 | 451 | ||
359 | State_t currentState( void ) | 452 | inline State_t currentState( void ) |
360 | { return CurrentState; } | 453 | { return CurrentState; } |
361 | void setCurrentState( State_t S ) | 454 | inline void setCurrentState( State_t S ) |
362 | { CurrentState = S; } | 455 | { CurrentState = S; } |
363 | 456 | ||
457 | // return TRUE if this node can have data to be inserted in | ||
458 | // file identified by S | ||
459 | bool hasDataForFile( const QString & S ); | ||
460 | ANetNodeInstance * firstWithDataForFile( const QString & S ); | ||
461 | |||
462 | // generate items for this file -> toplevel call | ||
463 | short generateFile( const QString & FID, // identification of file | ||
464 | const QString & FName, // effective filename of file | ||
465 | QTextStream & TS, // stream to file | ||
466 | long DN // device number | ||
467 | ) | ||
468 | { return getToplevel()->generateFile( FID, FName, TS, DN ); } | ||
469 | |||
470 | bool triggeredBy( const QString & Trigger ) | ||
471 | { return getToplevel()->triggeredBy( Trigger ); } | ||
472 | |||
364 | private : | 473 | private : |
365 | 474 | ||
366 | int compareItems ( QCollection::Item item1, | 475 | int compareItems ( QCollection::Item item1, |
@@ -378,6 +487,7 @@ private : | |||
378 | // index in listbox | 487 | // index in listbox |
379 | int Index; | 488 | int Index; |
380 | bool IsModified; | 489 | bool IsModified; |
490 | int Done; | ||
381 | 491 | ||
382 | }; | 492 | }; |
383 | 493 | ||