summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/netnode.h
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/netnode.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.h460
1 files changed, 285 insertions, 175 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
@@ -2,12 +2,13 @@
2#define NETNODE_H 2#define NETNODE_H
3 3
4#include <qtextstream.h> 4#include <qtextstream.h>
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
11#include <Utils.h> 12#include <Utils.h>
12 13
13// difference feature interfaces 14// difference feature interfaces
@@ -29,204 +30,291 @@ class InterfaceInfo;
29extern QString & deQuote( QString & X ); 30extern QString & deQuote( QString & X );
30extern QString quote( QString X ); 31extern QString quote( QString X );
31 32
32#include "systemfile.h" 33#include "systemfile.h"
33 34
34typedef enum State { 35typedef enum State {
35 // if we have not yet detected the state of the device 36 // if we have not yet detected the state of the device
36 Unchecked = 0, 37 Unchecked = 0,
37 // if we cannot determine the state 38 // if we cannot determine the state
38 Unknown = 1, 39 Unknown = 1,
39 // if connection cannot be established e.g. because 40 // if connection cannot be established e.g. because
40 // the hardware is not available 41 // the hardware is not available
41 Unavailable = 2, 42 Unavailable = 2,
42 // if the connection cannot be establishec but NOT 43 // if the connection cannot be establishec but NOT
43 // because it is physically impossible but because 44 // because it is physically impossible but because
44 // it has been disabled for FUNCTIONAL reasons 45 // it has been disabled for FUNCTIONAL reasons
45 Disabled = 3, 46 Disabled = 3,
46 // if connection is available to is currently down 47 // if connection is available to is currently down
47 // i.e. the corresponding hardware is not activated 48 // i.e. the corresponding hardware is not activated
48 Off = 4, 49 Off = 4,
49 // if connection is available to be used (i.e. the 50 // if connection is available to be used (i.e. the
50 // devices if fully ready to be used 51 // devices if fully ready to be used
51 Available = 5, 52 Available = 5,
52 // if connection is being used 53 // if connection is being used
53 IsUp = 6 54 IsUp = 6
54} State_t; 55} State_t;
55 56
56typedef enum Action { 57typedef enum Action {
57 // to make the device unavailable functionally 58 // to make the device unavailable functionally
58 Disable = 0, 59 Disable = 0,
59 // to make the device available functionally 60 // to make the device available functionally
60 Enable = 1, 61 Enable = 1,
61 // bring the hardware up 62 // bring the hardware up
62 Activate = 2, 63 Activate = 2,
63 // bring the hardware down 64 // bring the hardware down
64 Deactivate = 3, 65 Deactivate = 3,
65 // bring the connection up 66 // bring the connection up
66 Up = 4, 67 Up = 4,
67 // bring the connection down 68 // bring the connection down
68 Down = 5 69 Down = 5
69} Action_t; 70} Action_t;
70 71
71class ANetNode : public QObject{ 72class ANetNode : public QObject{
72 73
73public: 74public:
74 75
75 typedef QArray<ANetNode *> NetNodeList; 76 typedef QArray<ANetNode *> NetNodeList;
76 77
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 //
82 83 // standard methods with sensible default
83 // description for this NetNode 84 //
84 virtual const QString nodeDescription() = 0; 85 //
85 86
86 // create a blank instance of a net node 87 inline int done( void )
87 virtual ANetNodeInstance * createInstance( void ) = 0; 88 { return Done; }
88 89 inline void setDone( int D )
89 // return feature this NetNode provides 90 { Done = D; }
90 virtual const char * provides( void ) = 0; 91
91 virtual const char ** needs( void ) = 0; 92 // does this Node provide a Connection
92 93 inline bool isToplevel( void )
93 // generate files specific for this node (if any) 94 { return strcmp( provides(), "fullsetup") == 0 ; }
94 virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; 95
95 // return TRUE if this node has data to be inserted in systemfile 96 // set the value of an attribute
96 // with name S 97 void setAttribute( QString & Attr, QString & Value ) ;
97 virtual bool hasDataFor( const QString & S ) = 0; 98 void saveAttributes( QTextStream & TS ) ;
98 // generate data specific for the device for the system file S 99
99 // called only IF data was needed 100 // compiled references to 'needed' NetNodes -> needs list
100 virtual bool generateDeviceDataForCommonFile( 101 inline void setAlternatives( NetNodeList * Alt )
101 SystemFile & SF, long DevNr ) = 0; 102 { Alternatives = Alt; }
102 103 inline NetNodeList & alternatives( void )
103 // does this Node provide a Connection 104 { return *Alternatives; }
104 bool isToplevel( void ) 105
105 { return strcmp( provides(), "fullsetup") == 0 ; } 106 //
106 107 //
107 // generate NIC name based on instance nr 108 // Virtual methods with sensible default
108 // only relevant if node instances are devices 109 //
109 virtual QString genNic( long ) 110 //
110 { return QString(""); } 111
111 112 // do instances of this noce class have data for this file
112 // max number of instances for this node type 113 virtual bool hasDataForFile( const QString & )
113 // only relevant if node instances are devices 114 { return 0; }
114 virtual long instanceCount( void ) 115
115 { return 1; } 116 // generate instance independent stuff
116 117 // 0 : data output, 1 no data, 2 error
117 // set the value of an attribute 118 virtual short generateFile( const QString & ,
118 void setAttribute( QString & Attr, QString & Value ) ; 119 const QString & ,
119 void saveAttributes( QTextStream & TS ) ; 120 QTextStream & ,
120 121 long )
121 // compiled references to 'needed' NetNodes -> needs list 122 { return 1; }
122 void setAlternatives( NetNodeList * Alt ) 123
123 { Alternatives = Alt; } 124 // generate instance dependent but profile common stuff
124 NetNodeList & alternatives( void ) 125 // 0 : data output, 1 no data, 2 error
125 { return *Alternatives; } 126 virtual short generateFile( const QString & ,
127 const QString & ,
128 QTextStream & ,
129 ANetNodeInstance * ,
130 long )
131 { return 1; }
132
133
134 // generate NIC name based on instance nr
135 // only relevant if node instances are devices
136 virtual QString genNic( long )
137 { return QString(""); }
138
139 // max number of instances for this node type
140 // only relevant if node instances are devices
141 virtual long instanceCount( void )
142 { return 1; }
143
144 // return list of files that are specific for this node class
145 virtual QStringList * properFiles( void )
146 { return 0; }
147
148 //
149 //
150 // pure virtual methods with sensible default
151 //
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
127protected : 167protected :
128 168
129 NetNodeList * Alternatives; 169 NetNodeList * Alternatives;
130 170
131private : 171private :
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
138class ANetNodeInstance : public QObject { 179class ANetNodeInstance : public QObject {
139 180
140public: 181public:
141 182
142 ANetNodeInstance( ANetNode * NN ) : QObject() 183 ANetNodeInstance( ANetNode * NN ) : QObject()
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 ) 191
151 { return Connection; } 192 // return data was modified
152 193 inline void setModified( bool M )
153 // create edit widget under parent 194 { IsModified = M; }
154 virtual QWidget * edit( QWidget * parent ) = 0; 195 inline bool isModified( void )
155 // is given data acceptable 196 { return IsModified; }
156 virtual QString acceptable( void ) = 0; 197
157 198 // get next node
158 // return data was modified 199 ANetNodeInstance * nextNode();
159 void setModified( bool M ) 200 // return NetNode this is an instance of
160 { IsModified = M; } 201 ANetNode * nodeClass( void )
161 bool isModified( void ) 202 { return NodeType; }
162 { return IsModified; } 203
163 204 // intialize am instance of a net node
164 // get data from GUI and store in node 205 void initialize( void );
165 virtual void commit( void ) = 0; 206
166 207 // set the value of an attribute
167 // get next node 208 void setAttribute( QString & Attr, QString & Value ) ;
168 ANetNodeInstance * nextNode(); 209 void saveAttributes( QTextStream & TS ) ;
169 // return NetNode this is an instance of 210
170 ANetNode * nodeClass( void ) 211 // return true if node isntance is NEW and not loaded
171 { return NodeType; } 212 inline void setNew( bool IsN )
172 213 { IsNew = IsN; }
173 // intialize am instance of a net node 214 inline bool isNew( void )
174 void initialize( void ); 215 { return IsNew; }
175 216
176 // set the value of an attribute 217 // return description for this instance
177 void setAttribute( QString & Attr, QString & Value ) ; 218 inline QString & description( void )
178 void saveAttributes( QTextStream & TS ) ; 219 { return Description; }
220 inline void setDescription( const QString & S )
221 { Description = S; }
222
223 // pixmap for this instance -> from NetNode
224 inline const QString pixmapName( void )
225 { return NodeType->pixmapName(); }
226
227 inline const char * provides( void )
228 { return NodeType->provides(); }
229
230 inline const char ** needs( void )
231 { return NodeType->needs(); }
232
233 inline void setConnection( NodeCollection * NC )
234 { Connection = NC; }
235 inline NodeCollection * connection( void )
236 { return Connection; }
237
238 //
239 //
240 // Virtual methods with sensible defaults
241 //
242 //
243
244
245
246 // open proper file identified by S
247 virtual QFile * openFile( const QString & )
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 }
179 264
180 // return true if node isntance is NEW and not loaded 265 // generate code specific for this node
181 void setNew( bool IsN ) 266 // (or find the first node that does)
182 { IsNew = IsN; } 267 virtual short generateFile( const QString & ID,
183 bool isNew( void ) 268 const QString & Path,
184 { return IsNew; } 269 QTextStream & TS,
270 long DevNr )
271 { ANetNodeInstance * NNI = nextNode();
272 return (NNI) ? NNI->generateFile( ID, Path, TS, DevNr ) : 1;
273 }
185 274
186 // return description for this instance 275 // return true if this node instance is triggered by this trigger
187 QString & description( void ) 276 // could be delegated to deeper instances
188 { return Description; } 277 virtual bool triggeredBy( const QString & )
189 void setDescription( const QString & S ) 278 { return 0; }
190 { Description = S; }
191 279
192 // pixmap for this instance -> from NetNode 280 //
193 const QString pixmapName( void ) 281 //
194 { return NodeType->pixmapName(); } 282 // Pure virtual functions
283 //
284 //
195 285
196 const char * provides( void ) 286 // return runtime information for this node
197 { return NodeType->provides(); } 287 virtual RuntimeInfo * runtime( void ) = 0;
198 288
199 const char ** needs( void ) 289 // create edit widget under parent
200 { return NodeType->needs(); } 290 virtual QWidget * edit( QWidget * parent ) = 0;
201 291
202 // returns node specific data -> only useful for 'buddy' 292 // is given data acceptable
203 virtual void * data( void ) = 0; 293 virtual QString acceptable( void ) = 0;
204 294
205 // return TRUE if this node has data to be inserted in systemfile 295 // get data from GUI and store in node
206 // with name S 296 virtual void commit( void ) = 0;
207 virtual bool hasDataFor( const QString & S ) = 0;
208 297
209 // generate data specific for a profile and for the system file S 298 // returns node specific data -> only useful for 'buddy'
210 // called only IF data was needed 299 virtual void * data( void ) = 0;
211 virtual bool generateDataForCommonFile(
212 SystemFile & SF, long DevNr ) = 0;
213 300
214protected : 301protected :
215 302
216 virtual void setSpecificAttribute( QString & , QString & ) = 0; 303 virtual void setSpecificAttribute( QString & , QString & ) = 0;
217 virtual void saveSpecificAttribute( QTextStream & ) = 0; 304 virtual void saveSpecificAttribute( QTextStream & ) = 0;
218 305
219 ANetNode * NodeType; 306 ANetNode * NodeType;
220 // connection to which this node belongs to 307 // connection to which this node belongs to
221 NodeCollection * Connection; 308 NodeCollection * Connection;
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};
228 316
229class RuntimeInfo : public QObject { 317class RuntimeInfo : public QObject {
230 318
231 Q_OBJECT 319 Q_OBJECT
232 320
@@ -279,40 +367,45 @@ class NodeCollection : public QList<ANetNodeInstance> {
279public : 367public :
280 368
281 NodeCollection( void ); 369 NodeCollection( void );
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 ) {
316 Log(( "TL %p TLR %p\n", 409 Log(( "TL %p TLR %p\n",
317 getToplevel(), 410 getToplevel(),
318 getToplevel()->runtime() )); 411 getToplevel()->runtime() ));
@@ -322,21 +415,21 @@ public :
322 return CurrentState; 415 return CurrentState;
323 } 416 }
324 417
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 );
340 433
341 void append( ANetNodeInstance * NNI ); 434 void append( ANetNodeInstance * NNI );
342 435
@@ -345,25 +438,41 @@ public :
345 void reassign( void ); 438 void reassign( void );
346 439
347 ANetNodeInstance * getToplevel( void ); 440 ANetNodeInstance * getToplevel( void );
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
364private : 473private :
365 474
366 int compareItems ( QCollection::Item item1, 475 int compareItems ( QCollection::Item item1,
367 QCollection::Item item2 ); 476 QCollection::Item item2 );
368 477
369 long Number; 478 long Number;
@@ -375,10 +484,11 @@ private :
375 // true if this collection was just created (and not 484 // true if this collection was just created (and not
376 // loaded from file 485 // loaded from file
377 bool IsNew; 486 bool IsNew;
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
384#endif 494#endif