10 files changed, 651 insertions, 479 deletions
diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index bcef631..1e1270e 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp | |||
@@ -1,96 +1,119 @@ | |||
1 | #include "nsdata.h" | ||
2 | #include "activateprofile.h" | ||
1 | #include "networksettings.h" | 3 | #include "networksettings.h" |
2 | #include <qpe/qpeapplication.h> | 4 | #include <qpe/qpeapplication.h> |
3 | 5 | ||
4 | #include <opie/oapplicationfactory.h> | 6 | #include <opie/oapplicationfactory.h> |
5 | 7 | ||
6 | #ifdef GONE | 8 | #ifdef GONE |
7 | 9 | ||
8 | OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) | 10 | OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) |
9 | 11 | ||
10 | #else | 12 | #else |
11 | 13 | ||
14 | // just standard GUI | ||
12 | #define ACT_GUI 0 | 15 | #define ACT_GUI 0 |
16 | // used by interfaces to request for allow of up/down | ||
13 | #define ACT_REQUEST 1 | 17 | #define ACT_REQUEST 1 |
18 | // regenerate config files | ||
14 | #define ACT_REGEN 2 | 19 | #define ACT_REGEN 2 |
20 | // used by interfaces to request user prompt | ||
21 | #define ACT_PROMPT 3 | ||
15 | 22 | ||
16 | int main( int argc, char * argv[] ) { | 23 | int main( int argc, char * argv[] ) { |
17 | int rv = 0; | 24 | int rv = 0; |
18 | int Action = ACT_GUI; | 25 | int Action = ACT_GUI; |
19 | // could be overruled by -qws | 26 | // could be overruled by -qws |
20 | QApplication::Type GuiType = QApplication::GuiClient; | 27 | QApplication::Type GuiType = QApplication::GuiClient; |
21 | 28 | ||
22 | #ifdef _WS_QWS_ | 29 | #ifdef _WS_QWS_ |
23 | QPEApplication * TheApp; | 30 | QPEApplication * TheApp; |
24 | #else | 31 | #else |
25 | QApplication * TheApp; | 32 | QApplication * TheApp; |
26 | #endif | 33 | #endif |
27 | 34 | ||
28 | for ( int i = 1; i < argc; i ++ ) { | 35 | for ( int i = 1; i < argc; i ++ ) { |
29 | int rmv; | 36 | int rmv; |
30 | rmv = 0; | 37 | rmv = 0; |
31 | if( strcmp( argv[i], "--regen" ) == 0 ) { | 38 | if( strcmp( argv[i], "--regen" ) == 0 ) { |
32 | Action = ACT_REGEN; | 39 | Action = ACT_REGEN; |
33 | GuiType = QApplication::Tty; | 40 | GuiType = QApplication::Tty; |
34 | rmv = 1; | 41 | rmv = 1; |
42 | } else if( strcmp( argv[i], "--prompt" ) == 0 ) { | ||
43 | Action = ACT_PROMPT; | ||
44 | rmv = 1; | ||
35 | } | 45 | } |
36 | if( rmv ) { | 46 | if( rmv ) { |
37 | memmove( argv+i, argv+i+rmv, | 47 | memmove( argv+i, argv+i+rmv, |
38 | sizeof( char * ) * (argc-i-rmv) ); | 48 | sizeof( char * ) * (argc-i-rmv) ); |
39 | i --; | 49 | i --; |
40 | argc -= rmv; | 50 | argc -= rmv; |
41 | } | 51 | } |
42 | } | 52 | } |
43 | 53 | ||
44 | if( strstr( argv[0], "-request" ) ) { | 54 | if( strstr( argv[0], "-request" ) ) { |
45 | // called from system to request something | 55 | // called from system to request something |
46 | GuiType = QApplication::Tty; | 56 | GuiType = QApplication::Tty; |
47 | Action = ACT_REQUEST; | 57 | Action = ACT_REQUEST; |
48 | } | 58 | } |
49 | 59 | ||
50 | // Start Qt | 60 | // Start Qt |
51 | #ifdef _WS_QWS_ | 61 | #ifdef _WS_QWS_ |
52 | // because QPEApplication does not handle GuiType well | 62 | // because QPEApplication does not handle GuiType well |
53 | if( GuiType == QApplication::Tty ) { | 63 | if( GuiType == QApplication::Tty ) { |
54 | // this cast is NOT correct but we do not use | 64 | // this cast is NOT correct but we do not use |
55 | // TheApp anymore ... | 65 | // TheApp anymore ... |
56 | TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); | 66 | TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType ); |
57 | } else { | 67 | } else { |
58 | TheApp = new QPEApplication( argc, argv, GuiType ); | 68 | TheApp = new QPEApplication( argc, argv, GuiType ); |
59 | } | 69 | } |
60 | #else | 70 | #else |
61 | TheApp = new QApplication( argc, argv, GuiType ); | 71 | TheApp = new QApplication( argc, argv, GuiType ); |
62 | #endif | 72 | #endif |
63 | 73 | ||
64 | // init qt with app widget | 74 | // init qt with app widget |
65 | if( GuiType != QApplication::Tty ) { | 75 | |
66 | QWidget * W = 0; | 76 | switch( Action ) { |
67 | W = new NetworkSettings(0); | 77 | case ACT_REQUEST : |
68 | TheApp->setMainWidget( W ); | 78 | { NetworkSettingsData NS; |
69 | W->show(); | 79 | NS.canStart( argv[1] ); |
80 | } | ||
81 | break; | ||
82 | case ACT_REGEN : | ||
83 | { NetworkSettingsData NS; | ||
84 | // regen returns 0 if OK | ||
85 | rv = (NS.regenerate()) ? 1 : 0; | ||
86 | } | ||
87 | break; | ||
88 | case ACT_PROMPT : | ||
89 | { ActivateProfile AP(argv[1]); | ||
90 | if( AP.exec() == QDialog::Accepted ) { | ||
91 | printf( "%s-c%d-allowed", AP.selectedProfile() ); | ||
92 | } else { | ||
93 | printf( "%s-cNN-disallowed" ); | ||
94 | } | ||
95 | } | ||
96 | break; | ||
97 | case ACT_GUI : | ||
98 | { QWidget * W = new NetworkSettings(0); | ||
99 | TheApp->setMainWidget( W ); | ||
100 | W->show(); | ||
70 | #ifdef _WS_QWS_ | 101 | #ifdef _WS_QWS_ |
71 | W->showMaximized(); | 102 | W->showMaximized(); |
72 | #else | 103 | #else |
73 | W->resize( W->sizeHint() ); | 104 | W->resize( W->sizeHint() ); |
74 | #endif | 105 | #endif |
75 | rv = TheApp->exec(); | 106 | rv = TheApp->exec(); |
76 | delete W; | 107 | delete W; |
77 | } else { | 108 | } |
78 | switch( Action ) { | 109 | break; |
79 | case ACT_REQUEST : | ||
80 | NetworkSettings::canStart( argv[1] ); | ||
81 | break; | ||
82 | case ACT_REGEN : | ||
83 | // regen returns 0 if OK | ||
84 | rv = (NetworkSettings::regenerate()) ? 1 : 0; | ||
85 | break; | ||
86 | } | ||
87 | } | 110 | } |
88 | 111 | ||
89 | return rv; | 112 | return rv; |
90 | } | 113 | } |
91 | 114 | ||
92 | #endif | 115 | #endif |
93 | 116 | ||
94 | 117 | ||
95 | // main.cpp | 118 | // main.cpp |
96 | 119 | ||
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index ffe130c..f72fa8e 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp | |||
@@ -1,820 +1,414 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | 2 | ||
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <qiconset.h> | 4 | #include <qiconset.h> |
5 | #include <qgroupbox.h> | 5 | #include <qgroupbox.h> |
6 | #include <qtimer.h> | 6 | #include <qtimer.h> |
7 | #include <qlistbox.h> | 7 | #include <qlistbox.h> |
8 | #include <qmessagebox.h> | 8 | #include <qmessagebox.h> |
9 | #include <qlabel.h> | 9 | #include <qlabel.h> |
10 | #include <qiconview.h> | 10 | #include <qiconview.h> |
11 | #include <qtextstream.h> | ||
12 | #include <qdir.h> | ||
13 | #include <qfile.h> | ||
14 | #include <qfileinfo.h> | ||
15 | #include <qtimer.h> | 11 | #include <qtimer.h> |
16 | #include <qpe/qpeapplication.h> | 12 | #include <qpe/qpeapplication.h> |
17 | #include <qtoolbutton.h> | 13 | #include <qtoolbutton.h> |
18 | 14 | ||
19 | #include <asdevice.h> | 15 | #include <asdevice.h> |
20 | #include "networksettings.h" | 16 | #include "networksettings.h" |
21 | #include "netnode.h" | 17 | #include "netnode.h" |
22 | #include "editconnection.h" | 18 | #include "editconnection.h" |
23 | 19 | ||
24 | static QString CfgFile; | ||
25 | |||
26 | NetworkSettingsData::NetworkSettingsData( void ) { | ||
27 | // init global resources structure | ||
28 | new TheNSResources(); | ||
29 | |||
30 | CfgFile.sprintf( "%s/NETCONFIG", getenv("HOME") ); | ||
31 | |||
32 | // load settings | ||
33 | Force = 0; | ||
34 | loadSettings(); | ||
35 | } | ||
36 | |||
37 | // saving is done by caller | ||
38 | NetworkSettingsData::~NetworkSettingsData( void ) { | ||
39 | delete NSResources; | ||
40 | } | ||
41 | |||
42 | void NetworkSettingsData::loadSettings( void ) { | ||
43 | QString S; | ||
44 | ANetNodeInstance* NNI; | ||
45 | QString Attr, Value; | ||
46 | long idx; | ||
47 | |||
48 | QFile F( CfgFile ); | ||
49 | QTextStream TS( &F ); | ||
50 | |||
51 | do { | ||
52 | |||
53 | if( ! F.open(IO_ReadOnly) ) | ||
54 | break; | ||
55 | |||
56 | /* load the file -> | ||
57 | |||
58 | FORMAT : | ||
59 | |||
60 | [NETNODETYPE] | ||
61 | Entries ... | ||
62 | <EMPTYLINE> | ||
63 | [connection] | ||
64 | Name=Name | ||
65 | Node=Name | ||
66 | <EMPTYLINE> | ||
67 | */ | ||
68 | while( ! TS.atEnd() ) { | ||
69 | S = TS.readLine(); | ||
70 | |||
71 | if ( S.isEmpty() || S[0] != '[' ) | ||
72 | continue; | ||
73 | |||
74 | S = S.mid( 1, S.length()-2 ); | ||
75 | |||
76 | if( ! NSResources ) { | ||
77 | continue; | ||
78 | } | ||
79 | |||
80 | if( S == "connection" ) { | ||
81 | // load connections -> collections of nodes | ||
82 | NodeCollection * NC = new NodeCollection( TS ); | ||
83 | if ( NC->count() == 0 ) { | ||
84 | if( QMessageBox::warning( | ||
85 | 0, | ||
86 | qApp->translate( "NetworkSettings2", "Invalid connection" ), | ||
87 | qApp->translate( "NetworkSettings2", | ||
88 | "<p>Connection %1 contains unrecognized nodes and cannot be loaded</p>" ).arg(NC->name()), | ||
89 | qApp->translate( "NetworkSettings2", | ||
90 | "Remove node"), | ||
91 | qApp->translate( "NetworkSettings2", | ||
92 | "Exit program") ) == 1 ) { | ||
93 | exit( 0 ); | ||
94 | } | ||
95 | delete NC; | ||
96 | } else | ||
97 | NSResources->addConnection( NC ); | ||
98 | } else { | ||
99 | // load nodes | ||
100 | NNI = NSResources->createNodeInstance( S ); | ||
101 | if( ! NNI ) { | ||
102 | printf( "SKIPPING %s\n", S.latin1() ); | ||
103 | } | ||
104 | |||
105 | do { | ||
106 | S = TS.readLine(); | ||
107 | if( S.isEmpty() ) { | ||
108 | // empty line | ||
109 | break; | ||
110 | } | ||
111 | // node found ? | ||
112 | if( NNI ) { | ||
113 | idx = S.find( '=' ); | ||
114 | if( idx > 0 ) { | ||
115 | Attr = S.left( idx ); | ||
116 | Value = S.mid( idx+1, S.length() ); | ||
117 | } else { | ||
118 | Value=""; | ||
119 | Attr = S; | ||
120 | } | ||
121 | |||
122 | Value.stripWhiteSpace(); | ||
123 | Attr.stripWhiteSpace(); | ||
124 | Attr.lower(); | ||
125 | // dequote Attr | ||
126 | Value = deQuote(Value); | ||
127 | |||
128 | // set the attribute | ||
129 | NNI->setAttribute( Attr, Value ); | ||
130 | } | ||
131 | |||
132 | } while( 1 ); | ||
133 | if( NNI ) { | ||
134 | // loading from file -> exists | ||
135 | NNI->setNew( FALSE ); | ||
136 | NSResources->addNodeInstance( NNI ); | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | |||
141 | } while( 0 ); | ||
142 | |||
143 | } | ||
144 | |||
145 | QString NetworkSettingsData::saveSettings( void ) { | ||
146 | QString ErrS = ""; | ||
147 | |||
148 | if( ! isModified() ) | ||
149 | return ErrS; | ||
150 | |||
151 | QString S; | ||
152 | QFile F( CfgFile + ".bup" ); | ||
153 | |||
154 | printf( "Saving settings to %s\n", CfgFile.latin1() ); | ||
155 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { | ||
156 | ErrS = qApp->translate( "NetworkSettings", | ||
157 | "<p>Could not save setup to %1 !</p>" ). | ||
158 | arg(CfgFile); | ||
159 | // problem | ||
160 | return ErrS; | ||
161 | } | ||
162 | |||
163 | QTextStream TS( &F ); | ||
164 | { Name2Connection_t & M = NSResources->connections(); | ||
165 | ANetNodeInstance * NNI; | ||
166 | |||
167 | // for all connections | ||
168 | for( QDictIterator<NodeCollection> it(M); | ||
169 | it.current(); | ||
170 | ++it ) { | ||
171 | // all nodes in those connections | ||
172 | for( QListIterator<ANetNodeInstance> nit(*(it.current())); | ||
173 | nit.current(); | ||
174 | ++nit ) { | ||
175 | // header | ||
176 | NNI = nit.current(); | ||
177 | TS << '[' <<NNI->netNode()->nodeName() << ']' << endl; | ||
178 | NNI->saveAttributes( TS ); | ||
179 | TS << endl; | ||
180 | } | ||
181 | |||
182 | TS << "[connection]" << endl; | ||
183 | it.current()->save(TS); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | QDir D("."); | ||
188 | D.rename( CfgFile + ".bup", CfgFile ); | ||
189 | |||
190 | // | ||
191 | // proper files AND system files regenerated | ||
192 | // | ||
193 | |||
194 | setModified( 0 ); | ||
195 | return ErrS; | ||
196 | } | ||
197 | |||
198 | QString NetworkSettingsData::generateSettings( bool ForceReq ) { | ||
199 | bool ForceIt; | ||
200 | QString S = ""; | ||
201 | |||
202 | // include own force flag | ||
203 | ForceIt = (Force) ? 1 : ForceReq; | ||
204 | |||
205 | if( ! ForceIt && ! isModified() ) | ||
206 | return S; | ||
207 | |||
208 | // regenerate system files | ||
209 | printf( "Generating settings from %s\n", CfgFile.latin1() ); | ||
210 | |||
211 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); | ||
212 | Name2Connection_t & M = NSResources->connections(); | ||
213 | NodeCollection * NC; | ||
214 | ANetNodeInstance * NNI; | ||
215 | SystemFile * SF; | ||
216 | bool needToRegenerate = ForceIt; | ||
217 | |||
218 | // | ||
219 | // check if we need to generate at least one of the system files | ||
220 | // | ||
221 | if( ! ForceIt ) { | ||
222 | for( QDictIterator<SystemFile> sfit(SFM); | ||
223 | sfit.current(); | ||
224 | ++sfit ) { | ||
225 | SF = sfit.current(); | ||
226 | |||
227 | // check if there are nodes that are modified and require | ||
228 | // data for this system file | ||
229 | |||
230 | // for all connections | ||
231 | for( QDictIterator<NodeCollection> ncit(M); | ||
232 | ncit.current(); | ||
233 | ++ncit ) { | ||
234 | NC = ncit.current(); | ||
235 | |||
236 | if( NC->isModified() ) { | ||
237 | // does this connection 'touch' this system file ? | ||
238 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
239 | cncit.current(); | ||
240 | ++cncit ) { | ||
241 | NNI = cncit.current(); | ||
242 | if( NNI->netNode()->hasDataFor( SF->name() ) && | ||
243 | NNI->isModified() ) { | ||
244 | needToRegenerate = 1; | ||
245 | break; | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | if( needToRegenerate ) | ||
250 | break; | ||
251 | } | ||
252 | if( needToRegenerate ) | ||
253 | break; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | // we cannot renumber with a FORCE request since | ||
258 | // we probably are NOT going to save the config | ||
259 | // e.g. when using --regen option | ||
260 | if( ! ForceReq && needToRegenerate ) { | ||
261 | NSResources->renumberConnections(); | ||
262 | setModified(1); | ||
263 | } | ||
264 | |||
265 | // | ||
266 | // generate files proper to each netnodeinstance | ||
267 | // | ||
268 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); | ||
269 | ANetNodeInstance * NNI; | ||
270 | |||
271 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | ||
272 | NNIIt.current(); | ||
273 | ++NNIIt | ||
274 | ){ | ||
275 | // for all nodes find those that are modified | ||
276 | NNI = NNIIt.current(); | ||
277 | |||
278 | if( ForceIt || NNI->isModified() ) { | ||
279 | if( ! NNI->netNode()->generateProperFilesFor( NNI ) ) { | ||
280 | // problem generating | ||
281 | S = qApp->translate( "NetworkSettings", | ||
282 | "<p>Cannot generate files proper to %1</p>" ). | ||
283 | arg(NNI->netNode()->nodeName()) ; | ||
284 | return S; | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | |||
290 | // | ||
291 | // generate system files | ||
292 | // | ||
293 | for( QDictIterator<SystemFile> sfit(SFM); | ||
294 | sfit.current(); | ||
295 | ++sfit ) { | ||
296 | SF = sfit.current(); | ||
297 | |||
298 | // | ||
299 | // regenerate current file | ||
300 | // | ||
301 | printf( "Generating %s\n", SF->name().latin1() ); | ||
302 | SF->open(); | ||
303 | |||
304 | do { // so we can break; | ||
305 | |||
306 | if( SF->preSection() ) { | ||
307 | S = qApp->translate( "NetworkSettings", | ||
308 | "<p>Error in preSection for file %1</p>" ). | ||
309 | arg( SF->name() ); | ||
310 | return S; | ||
311 | } | ||
312 | |||
313 | for( QDictIterator<NodeCollection> ncit(M); | ||
314 | ncit.current(); | ||
315 | ++ncit ) { | ||
316 | NC = ncit.current(); | ||
317 | |||
318 | // get the netnode that serves as the device for this | ||
319 | // connection | ||
320 | AsDevice * Dev = NC->device(); | ||
321 | |||
322 | // generate 'entry' for every possible device this profile handles | ||
323 | |||
324 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
325 | cncit.current(); | ||
326 | ++cncit ) { | ||
327 | NNI = cncit.current(); | ||
328 | for( int i = 0; i < Dev->count(); i ++ ) { | ||
329 | if( NNI->netNode()->hasDataFor( SF->name() ) ) { | ||
330 | if( SF->preNodeSection( NNI, i ) ) { | ||
331 | S = qApp->translate( "NetworkSettings", | ||
332 | "<p>Error in preNodeSection for file %1 and node %2</p>" ). | ||
333 | arg( SF->name() ). | ||
334 | arg( NNI->netNode()->nodeName() ); | ||
335 | return S; | ||
336 | } | ||
337 | |||
338 | if( NNI->netNode()->generateDataForCommonFile(*SF,i,NNI) ) { | ||
339 | S = qApp->translate( "NetworkSettings", | ||
340 | "<p>Error in node part for file %1 and node %2</p>" ). | ||
341 | arg( SF->name() ). | ||
342 | arg( NNI->netNode()->nodeName() ); | ||
343 | return S; | ||
344 | } | ||
345 | |||
346 | if( SF->postNodeSection( NNI, i ) ) { | ||
347 | S = qApp->translate( "NetworkSettings", | ||
348 | "<p>Error in postNodeSection for file %1 and node %2</p>" ). | ||
349 | arg( SF->name() ). | ||
350 | arg( NNI->netNode()->nodeName() ); | ||
351 | return S; | ||
352 | } | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | *SF << endl; | ||
357 | } | ||
358 | |||
359 | if( SF->postSection() ) { | ||
360 | S = qApp->translate( "NetworkSettings", | ||
361 | "<p>Error in postSection for file %1</p>" ). | ||
362 | arg( SF->name() ); | ||
363 | return S; | ||
364 | } | ||
365 | } while( 0 ); | ||
366 | SF->close(); | ||
367 | } | ||
368 | } | ||
369 | Force = 0; | ||
370 | return S; | ||
371 | } | ||
372 | |||
373 | // | ||
374 | // GUI part | ||
375 | // | ||
376 | |||
377 | NetworkSettings::NetworkSettings( QWidget *parent, | 20 | NetworkSettings::NetworkSettings( QWidget *parent, |
378 | const char *name, | 21 | const char *name, |
379 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), | 22 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), |
380 | NSD() { | 23 | NSD() { |
381 | 24 | ||
382 | UpdateTimer = new QTimer( this ); | 25 | UpdateTimer = new QTimer( this ); |
383 | // set pixmaps | 26 | // set pixmaps |
384 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); | 27 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); |
385 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); | 28 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); |
386 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); | 29 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); |
387 | Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); | 30 | Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); |
388 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); | 31 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); |
389 | 32 | ||
390 | Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); | 33 | Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); |
391 | 34 | ||
392 | On_TB->setPixmap( NSResources->getPixmap( "off" ) ); | 35 | On_TB->setPixmap( NSResources->getPixmap( "off" ) ); |
393 | 36 | ||
394 | // populate main Listbox | 37 | // populate main Listbox |
395 | Profiles_IV->clear(); | 38 | Profiles_IV->clear(); |
396 | { Name2Connection_t & M = NSResources->connections(); | 39 | { Name2Connection_t & M = NSResources->connections(); |
397 | NodeCollection * NC; | 40 | NodeCollection * NC; |
398 | QIconViewItem * IVI; | 41 | QIconViewItem * IVI; |
399 | 42 | ||
400 | // for all connections | 43 | // for all connections |
401 | for( QDictIterator<NodeCollection> it(M); | 44 | for( QDictIterator<NodeCollection> it(M); |
402 | it.current(); | 45 | it.current(); |
403 | ++it ) { | 46 | ++it ) { |
404 | NC = it.current(); | 47 | NC = it.current(); |
405 | IVI = new QIconViewItem( Profiles_IV, | 48 | IVI = new QIconViewItem( Profiles_IV, |
406 | NC->name(), | 49 | NC->name(), |
407 | NC->devicePixmap() ); | 50 | NC->devicePixmap() ); |
408 | } | 51 | } |
409 | } | 52 | } |
410 | 53 | ||
411 | if( Profiles_IV->count() ) { | 54 | if( Profiles_IV->count() ) { |
412 | Profiles_IV->setSelected( Profiles_IV->firstItem(), TRUE ); | 55 | Profiles_IV->setSelected( Profiles_IV->firstItem(), TRUE ); |
413 | } | 56 | } |
414 | 57 | ||
415 | // if no profiles -> auto popup editing | 58 | // if no profiles -> auto popup editing |
416 | if( NSResources->connections().count() == 0 ) { | 59 | if( NSResources->connections().count() == 0 ) { |
417 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); | 60 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); |
418 | } | 61 | } |
419 | 62 | ||
420 | UpdateTimer->start( 5000 ); | 63 | UpdateTimer->start( 5000 ); |
421 | connect( UpdateTimer, SIGNAL( timeout() ), | 64 | connect( UpdateTimer, SIGNAL( timeout() ), |
422 | this, SLOT( SLOT_RefreshStates() ) ); | 65 | this, SLOT( SLOT_RefreshStates() ) ); |
66 | |||
67 | /* Add QCopChannel */ | ||
68 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | ||
69 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); | ||
423 | } | 70 | } |
424 | 71 | ||
425 | NetworkSettings::~NetworkSettings() { | 72 | NetworkSettings::~NetworkSettings() { |
426 | QString S; | 73 | QString S; |
427 | 74 | ||
428 | S = NSD.generateSettings(); | 75 | S = NSD.generateSettings(); |
429 | if( ! S.isEmpty() ) { | 76 | if( ! S.isEmpty() ) { |
430 | QMessageBox::warning( | 77 | QMessageBox::warning( |
431 | 0, | 78 | 0, |
432 | tr( "Generating system configuration" ), | 79 | tr( "Generating system configuration" ), |
433 | S | 80 | S |
434 | ); | 81 | ); |
435 | } | 82 | } |
436 | 83 | ||
437 | S = NSD.saveSettings(); | 84 | S = NSD.saveSettings(); |
438 | if( ! S.isEmpty() ) { | 85 | if( ! S.isEmpty() ) { |
439 | // problem saving | 86 | // problem saving |
440 | QMessageBox::warning( | 87 | QMessageBox::warning( |
441 | 0, | 88 | 0, |
442 | tr( "Saving setup" ), S ); | 89 | tr( "Saving setup" ), S ); |
443 | } | 90 | } |
444 | } | 91 | } |
445 | 92 | ||
446 | void NetworkSettings::SLOT_RefreshStates( void ) { | 93 | void NetworkSettings::SLOT_RefreshStates( void ) { |
447 | QIconViewItem * IVI = Profiles_IV->currentItem(); // remeber | 94 | QIconViewItem * IVI = Profiles_IV->currentItem(); // remeber |
448 | 95 | ||
449 | if( IVI ) { | 96 | if( IVI ) { |
450 | NodeCollection * NC; | 97 | NodeCollection * NC; |
451 | NSResources->system().probeInterfaces(); | 98 | NSResources->system().probeInterfaces(); |
452 | // update current selection only | 99 | // update current selection only |
453 | NC = NSResources->findConnection( IVI->text() ); | 100 | NC = NSResources->findConnection( IVI->text() ); |
454 | if( NC ) { | 101 | if( NC ) { |
455 | State_t OldS = NC->state(); | 102 | State_t OldS = NC->state(); |
456 | State_t NewS = NC->state(1); | 103 | State_t NewS = NC->state(1); |
457 | if( OldS != NewS ) { | 104 | if( OldS != NewS ) { |
458 | updateProfileState( IVI ); | 105 | updateProfileState( IVI ); |
459 | } | 106 | } |
460 | } | 107 | } |
461 | } | 108 | } |
462 | 109 | ||
463 | 110 | ||
464 | /* -> LATER !! | 111 | /* -> LATER !! |
465 | bool is; | 112 | bool is; |
466 | NodeCollection * NC; | 113 | NodeCollection * NC; |
467 | 114 | ||
468 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { | 115 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { |
469 | NC = NSResources->findConnection( Profiles_LB->text(i) ); | 116 | NC = NSResources->findConnection( Profiles_LB->text(i) ); |
470 | if( NC ) { | 117 | if( NC ) { |
471 | State_t OldS = NC->state(); | 118 | State_t OldS = NC->state(); |
472 | State_t NewS = NC->state(1); | 119 | State_t NewS = NC->state(1); |
473 | if( OldS != NewS ) { | 120 | if( OldS != NewS ) { |
474 | is = Profiles_LB->isSelected(i); | 121 | is = Profiles_LB->isSelected(i); |
475 | Profiles_LB->changeItem( NC->statePixmap(NewS), | 122 | Profiles_LB->changeItem( NC->statePixmap(NewS), |
476 | NC->name(), | 123 | NC->name(), |
477 | i ); | 124 | i ); |
478 | if( is ) { | 125 | if( is ) { |
479 | Profiles_LB->setSelected( i, TRUE ); | 126 | Profiles_LB->setSelected( i, TRUE ); |
480 | } | 127 | } |
481 | } | 128 | } |
482 | } | 129 | } |
483 | } | 130 | } |
484 | if( ci >= 0 ) | 131 | if( ci >= 0 ) |
485 | Profiles_LB->setCurrentItem( ci ); | 132 | Profiles_LB->setCurrentItem( ci ); |
486 | */ | 133 | */ |
487 | } | 134 | } |
488 | 135 | ||
489 | void NetworkSettings::SLOT_AddNode( void ) { | 136 | void NetworkSettings::SLOT_AddNode( void ) { |
490 | SLOT_EditNode( 0 ); | 137 | SLOT_EditNode( 0 ); |
491 | } | 138 | } |
492 | 139 | ||
493 | void NetworkSettings::SLOT_DeleteNode( void ) { | 140 | void NetworkSettings::SLOT_DeleteNode( void ) { |
494 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 141 | QIconViewItem * IVI = Profiles_IV->currentItem(); |
495 | 142 | ||
496 | if ( ! IVI ) | 143 | if ( ! IVI ) |
497 | return; | 144 | return; |
498 | 145 | ||
499 | if( QMessageBox::warning( | 146 | if( QMessageBox::warning( |
500 | 0, | 147 | 0, |
501 | tr( "Removing profile" ), | 148 | tr( "Removing profile" ), |
502 | tr( "Remove selected profile ?" ), | 149 | tr( "Remove selected profile ?" ), |
503 | 1, 0 ) == 1 ) { | 150 | 1, 0 ) == 1 ) { |
504 | NSResources->removeConnection( IVI->text() ); | 151 | NSResources->removeConnection( IVI->text() ); |
505 | delete IVI; | 152 | delete IVI; |
506 | setModified( 1 ); | 153 | setModified( 1 ); |
507 | NSD.forceGeneration(1); | 154 | NSD.forceGeneration(1); |
508 | } | 155 | } |
509 | } | 156 | } |
510 | 157 | ||
511 | void NetworkSettings::SLOT_EditNode( QIconViewItem * IVI ) { | 158 | void NetworkSettings::SLOT_EditNode( QIconViewItem * IVI ) { |
512 | QString OldName = ""; | 159 | QString OldName = ""; |
513 | EditConnection EC( this ); | 160 | EditConnection EC( this ); |
514 | 161 | ||
515 | if( IVI ) { | 162 | if( IVI ) { |
516 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); | 163 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); |
517 | if( ! NC ) { | 164 | if( ! NC ) { |
518 | return; | 165 | return; |
519 | } | 166 | } |
520 | OldName = NC->name(); | 167 | OldName = NC->name(); |
521 | EC.setConnection( NC ); | 168 | EC.setConnection( NC ); |
522 | } | 169 | } |
523 | 170 | ||
524 | EC.showMaximized(); | 171 | EC.showMaximized(); |
525 | // disable refresh timer | 172 | // disable refresh timer |
526 | UpdateTimer->stop(); | 173 | UpdateTimer->stop(); |
527 | if( EC.exec() == QDialog::Accepted ) { | 174 | if( EC.exec() == QDialog::Accepted ) { |
528 | // toplevel item -> store | 175 | // toplevel item -> store |
529 | NodeCollection * NC = EC.connection(); | 176 | NodeCollection * NC = EC.connection(); |
530 | if( NC->isModified() ) { | 177 | if( NC->isModified() ) { |
531 | setModified( 1 ); | 178 | setModified( 1 ); |
532 | if( IVI ) { | 179 | if( IVI ) { |
533 | // new name -> remove item | 180 | // new name -> remove item |
534 | NSResources->removeConnection( OldName ); | 181 | NSResources->removeConnection( OldName ); |
535 | // must add it here since change will trigger event | 182 | // must add it here since change will trigger event |
536 | NSResources->addConnection( NC ); | 183 | NSResources->addConnection( NC ); |
537 | IVI->setText( NC->name() ); | 184 | IVI->setText( NC->name() ); |
538 | IVI->setPixmap( NC->devicePixmap() ); | 185 | IVI->setPixmap( NC->devicePixmap() ); |
539 | } else { | 186 | } else { |
540 | // new item | 187 | // new item |
541 | NSResources->addConnection( NC ); | 188 | NSResources->addConnection( NC ); |
542 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 189 | NC->setNumber( NC->maxConnectionNumber()+1 ); |
543 | IVI = new QIconViewItem( Profiles_IV, | 190 | IVI = new QIconViewItem( Profiles_IV, |
544 | NC->name(), | 191 | NC->name(), |
545 | NC->devicePixmap() | 192 | NC->devicePixmap() |
546 | ); | 193 | ); |
547 | Profiles_IV->setSelected( IVI, TRUE ); | 194 | Profiles_IV->setSelected( IVI, TRUE ); |
548 | } | 195 | } |
549 | updateProfileState( IVI ); | 196 | updateProfileState( IVI ); |
550 | } | 197 | } |
551 | } else { | 198 | } else { |
552 | // cancelled : reset connection | 199 | // cancelled : reset connection |
553 | if( IVI ) { | 200 | if( IVI ) { |
554 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); | 201 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); |
555 | NC->reassign(); | 202 | NC->reassign(); |
556 | } | 203 | } |
557 | } | 204 | } |
558 | // reenable | 205 | // reenable |
559 | UpdateTimer->start( 5000 ); | 206 | UpdateTimer->start( 5000 ); |
560 | } | 207 | } |
561 | 208 | ||
562 | void NetworkSettings::SLOT_ShowNode( QIconViewItem * IVI ) { | 209 | void NetworkSettings::SLOT_ShowNode( QIconViewItem * IVI ) { |
563 | if( IVI == 0 ) | 210 | if( IVI == 0 ) |
564 | return; | 211 | return; |
565 | 212 | ||
566 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); | 213 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); |
567 | 214 | ||
568 | // is button possible | 215 | // is button possible |
569 | bool EnabledPossible, OnPossible, ConnectPossible; | 216 | bool EnabledPossible, OnPossible, ConnectPossible; |
570 | // is button On or Off | 217 | // is button On or Off |
571 | bool DisabledOn, OnOn, ConnectOn; | 218 | bool DisabledOn, OnOn, ConnectOn; |
572 | 219 | ||
573 | EnabledPossible = OnPossible = ConnectPossible = 1; | 220 | EnabledPossible = OnPossible = ConnectPossible = 1; |
574 | DisabledOn = 1; | 221 | DisabledOn = 1; |
575 | OnOn = ConnectOn = 0; | 222 | OnOn = ConnectOn = 0; |
576 | 223 | ||
577 | switch( NC->state() ) { | 224 | switch( NC->state() ) { |
578 | case Unknown : | 225 | case Unknown : |
579 | // cannot occur here | 226 | // cannot occur here |
580 | break; | 227 | break; |
581 | case Unchecked : | 228 | case Unchecked : |
582 | case Unavailable : | 229 | case Unavailable : |
583 | // cannot do anything but recheck | 230 | // cannot do anything but recheck |
584 | EnabledPossible = OnPossible = ConnectPossible = 0; | 231 | EnabledPossible = OnPossible = ConnectPossible = 0; |
585 | break; | 232 | break; |
586 | case Disabled : | 233 | case Disabled : |
587 | OnPossible = ConnectPossible = 0; | 234 | OnPossible = ConnectPossible = 0; |
588 | break; | 235 | break; |
589 | case Off : | 236 | case Off : |
590 | DisabledOn = 0; | 237 | DisabledOn = 0; |
591 | break; | 238 | break; |
592 | case Available : | 239 | case Available : |
593 | OnOn = 1; | 240 | OnOn = 1; |
594 | DisabledOn = 0; | 241 | DisabledOn = 0; |
595 | break; | 242 | break; |
596 | case IsUp : | 243 | case IsUp : |
597 | OnOn = ConnectOn = 1; | 244 | OnOn = ConnectOn = 1; |
598 | DisabledOn = 0; | 245 | DisabledOn = 0; |
599 | break; | 246 | break; |
600 | } | 247 | } |
601 | 248 | ||
602 | // set button state | 249 | // set button state |
603 | Enable_TB->setEnabled( EnabledPossible ); | 250 | Enable_TB->setEnabled( EnabledPossible ); |
604 | On_TB->setEnabled( OnPossible ); | 251 | On_TB->setEnabled( OnPossible ); |
605 | Connect_TB->setEnabled( ConnectPossible ); | 252 | Connect_TB->setEnabled( ConnectPossible ); |
606 | 253 | ||
607 | Enable_TB->setOn( DisabledOn ); | 254 | Enable_TB->setOn( DisabledOn ); |
608 | On_TB->setOn( OnOn ); | 255 | On_TB->setOn( OnOn ); |
609 | Connect_TB->setOn( ConnectOn ); | 256 | Connect_TB->setOn( ConnectOn ); |
610 | 257 | ||
611 | if( NC->description().isEmpty() ) { | 258 | if( NC->description().isEmpty() ) { |
612 | Description_LBL->setText( tr( "No description" ) ); | 259 | Description_LBL->setText( tr( "No description" ) ); |
613 | } else { | 260 | } else { |
614 | Description_LBL->setText( NC->description() ); | 261 | Description_LBL->setText( NC->description() ); |
615 | } | 262 | } |
616 | 263 | ||
617 | CurProfile_GB->setTitle( IVI->text() ); | 264 | CurProfile_GB->setTitle( IVI->text() ); |
618 | State_LBL->setText( NC->stateName() ); | 265 | State_LBL->setText( NC->stateName() ); |
619 | } | 266 | } |
620 | 267 | ||
621 | void NetworkSettings::SLOT_CheckState( void ) { | 268 | void NetworkSettings::SLOT_CheckState( void ) { |
622 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 269 | QIconViewItem * IVI = Profiles_IV->currentItem(); |
623 | if ( ! IVI ) | 270 | if ( ! IVI ) |
624 | return; | 271 | return; |
625 | updateProfileState( IVI ); | 272 | updateProfileState( IVI ); |
626 | } | 273 | } |
627 | 274 | ||
628 | void NetworkSettings::updateProfileState( QIconViewItem * IVI ) { | 275 | void NetworkSettings::updateProfileState( QIconViewItem * IVI ) { |
629 | if( IVI == Profiles_IV->currentItem() ) { | 276 | if( IVI == Profiles_IV->currentItem() ) { |
630 | SLOT_ShowNode( IVI ); | 277 | SLOT_ShowNode( IVI ); |
631 | } | 278 | } |
632 | } | 279 | } |
633 | 280 | ||
634 | void NetworkSettings::SLOT_GenerateConfig( void ) { | 281 | void NetworkSettings::SLOT_GenerateConfig( void ) { |
635 | QString S = NSD.generateSettings( TRUE ); | 282 | QString S = NSD.generateSettings( TRUE ); |
636 | 283 | ||
637 | if( ! S.isEmpty() ) { | 284 | if( ! S.isEmpty() ) { |
638 | QMessageBox::warning( | 285 | QMessageBox::warning( |
639 | 0, | 286 | 0, |
640 | tr( "Generating system configuration" ), | 287 | tr( "Generating system configuration" ), |
641 | S | 288 | S |
642 | ); | 289 | ); |
643 | } | 290 | } |
644 | } | 291 | } |
645 | 292 | ||
646 | void NetworkSettings::SLOT_Enable( void ) { | 293 | void NetworkSettings::SLOT_Enable( void ) { |
647 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 294 | QIconViewItem * IVI = Profiles_IV->currentItem(); |
648 | QString Msg; | 295 | QString Msg; |
649 | if ( ! IVI ) | 296 | if ( ! IVI ) |
650 | return; | 297 | return; |
651 | 298 | ||
652 | NodeCollection * NC = | 299 | NodeCollection * NC = |
653 | NSResources->findConnection( IVI->text() ); | 300 | NSResources->findConnection( IVI->text() ); |
654 | 301 | ||
655 | bool rv; | 302 | bool rv; |
656 | switch( NC->state() ) { | 303 | switch( NC->state() ) { |
657 | case Disabled : | 304 | case Disabled : |
658 | Msg = tr( "Cannot enable profile" ); | 305 | Msg = tr( "Cannot enable profile" ); |
659 | rv = NC->setState( Enable ); | 306 | rv = NC->setState( Enable ); |
660 | break; | 307 | break; |
661 | default : | 308 | default : |
662 | Msg = tr( "Cannot disable profile" ); | 309 | Msg = tr( "Cannot disable profile" ); |
663 | rv = NC->setState( Disable ); | 310 | rv = NC->setState( Disable ); |
664 | break; | 311 | break; |
665 | } | 312 | } |
666 | 313 | ||
667 | if( ! rv ) { | 314 | if( ! rv ) { |
668 | QMessageBox::warning( | 315 | QMessageBox::warning( |
669 | 0, | 316 | 0, |
670 | tr( "Activating profile" ), | 317 | tr( "Activating profile" ), |
671 | Msg ); | 318 | Msg ); |
672 | return; | 319 | return; |
673 | } | 320 | } |
674 | updateProfileState( IVI ); | 321 | updateProfileState( IVI ); |
675 | } | 322 | } |
676 | 323 | ||
677 | void NetworkSettings::SLOT_On( void ) { | 324 | void NetworkSettings::SLOT_On( void ) { |
678 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 325 | QIconViewItem * IVI = Profiles_IV->currentItem(); |
679 | 326 | ||
680 | if ( ! IVI ) | 327 | if ( ! IVI ) |
681 | return; | 328 | return; |
682 | 329 | ||
683 | NodeCollection * NC = | 330 | NodeCollection * NC = |
684 | NSResources->findConnection( IVI->text() ); | 331 | NSResources->findConnection( IVI->text() ); |
685 | 332 | ||
686 | bool rv; | 333 | bool rv; |
687 | switch( NC->state() ) { | 334 | switch( NC->state() ) { |
688 | case Off : | 335 | case Off : |
689 | // activate interface | 336 | // activate interface |
690 | rv = NC->setState( Activate ); | 337 | rv = NC->setState( Activate ); |
691 | break; | 338 | break; |
692 | case Available : | 339 | case Available : |
693 | // deactivate | 340 | // deactivate |
694 | rv = NC->setState( Deactivate ); | 341 | rv = NC->setState( Deactivate ); |
695 | break; | 342 | break; |
696 | case IsUp : | 343 | case IsUp : |
697 | // bring down and deactivate | 344 | // bring down and deactivate |
698 | rv = ( NC->setState( Down ) && | 345 | rv = ( NC->setState( Down ) && |
699 | NC->setState( Deactivate ) ); | 346 | NC->setState( Deactivate ) ); |
700 | break; | 347 | break; |
701 | default : | 348 | default : |
702 | // others no change | 349 | // others no change |
703 | return; | 350 | return; |
704 | } | 351 | } |
705 | 352 | ||
706 | if( ! rv ) { | 353 | if( ! rv ) { |
707 | QMessageBox::warning( | 354 | QMessageBox::warning( |
708 | 0, | 355 | 0, |
709 | tr( "Activating profile" ), | 356 | tr( "Activating profile" ), |
710 | tr( "Cannot enable profile" ) ); | 357 | tr( "Cannot enable profile" ) ); |
711 | return; | 358 | return; |
712 | } | 359 | } |
713 | updateProfileState( IVI ); | 360 | updateProfileState( IVI ); |
714 | } | 361 | } |
715 | 362 | ||
716 | void NetworkSettings::SLOT_Connect( void ) { | 363 | void NetworkSettings::SLOT_Connect( void ) { |
717 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 364 | QIconViewItem * IVI = Profiles_IV->currentItem(); |
718 | 365 | ||
719 | if ( ! IVI ) | 366 | if ( ! IVI ) |
720 | return; | 367 | return; |
721 | 368 | ||
722 | NodeCollection * NC = | 369 | NodeCollection * NC = |
723 | NSResources->findConnection( IVI->text() ); | 370 | NSResources->findConnection( IVI->text() ); |
724 | 371 | ||
725 | bool rv; | 372 | bool rv; |
726 | switch( NC->state() ) { | 373 | switch( NC->state() ) { |
727 | case IsUp : | 374 | case IsUp : |
728 | // down interface | 375 | // down interface |
729 | rv = NC->setState( Down ); | 376 | rv = NC->setState( Down ); |
730 | break; | 377 | break; |
731 | case Available : | 378 | case Available : |
732 | // up interface | 379 | // up interface |
733 | rv = NC->setState( Up ); | 380 | rv = NC->setState( Up ); |
734 | break; | 381 | break; |
735 | case Off : | 382 | case Off : |
736 | // activate and bring up | 383 | // activate and bring up |
737 | rv = ( NC->setState( Activate ) && | 384 | rv = ( NC->setState( Activate ) && |
738 | NC->setState( Up ) ); | 385 | NC->setState( Up ) ); |
739 | break; | 386 | break; |
740 | default : | 387 | default : |
741 | // others no change | 388 | // others no change |
742 | return; | 389 | return; |
743 | } | 390 | } |
744 | 391 | ||
745 | if( ! rv ) { | 392 | if( ! rv ) { |
746 | QMessageBox::warning( | 393 | QMessageBox::warning( |
747 | 0, | 394 | 0, |
748 | tr( "Activating profile" ), | 395 | tr( "Activating profile" ), |
749 | tr( "Cannot enable profile" ) ); | 396 | tr( "Cannot enable profile" ) ); |
750 | return; | 397 | return; |
751 | } | 398 | } |
752 | 399 | ||
753 | // we do not update the GUI but wait for the REAL upping of the device | 400 | // we do not update the GUI but wait for the REAL upping of the device |
754 | } | 401 | } |
755 | 402 | ||
756 | /* | 403 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { |
757 | Called by the system to see if interface can be brought UP | 404 | QDataStream stream( data, IO_ReadOnly ); |
758 | |||
759 | if allowed, echo Interface-allowed else Interface-disallowed | ||
760 | */ | ||
761 | |||
762 | void NetworkSettings::canStart( const char * Interface ) { | ||
763 | // load situation | ||
764 | NetworkSettingsData NSD; | ||
765 | |||
766 | { Name2Connection_t & M = NSResources->connections(); | ||
767 | NodeCollection * NC; | ||
768 | |||
769 | // for all connections | ||
770 | for( QDictIterator<NodeCollection> it(M); | ||
771 | it.current(); | ||
772 | ++it ) { | ||
773 | NC = it.current(); | ||
774 | // check if this profile handles the requested interface | ||
775 | if( NC->handlesInterface( Interface ) ) { | ||
776 | switch( NC->state() ) { | ||
777 | case Unchecked : | ||
778 | case Unknown : | ||
779 | case Unavailable : | ||
780 | case Disabled : | ||
781 | // this profile does not allow interface to be UP | ||
782 | // -> try others | ||
783 | break; | ||
784 | case Off : | ||
785 | // try to UP the device | ||
786 | if( ! NC->setState( Activate ) ) { | ||
787 | // cannot bring device Online -> try other alters | ||
788 | break; | ||
789 | } | ||
790 | // FT | ||
791 | case Available : | ||
792 | case IsUp : // also called for 'down' | ||
793 | // device is ready -> done | ||
794 | printf( "%s-c%d-allowed\n", | ||
795 | Interface, NC->number() ); | ||
796 | return; | ||
797 | } | ||
798 | } | ||
799 | } | ||
800 | } | ||
801 | // if we come here no alternatives are possible | ||
802 | printf( "%s-cnn-disallowed\n", Interface ); | ||
803 | } | ||
804 | |||
805 | /* | ||
806 | Called by the system to regenerate config files | ||
807 | */ | ||
808 | |||
809 | bool NetworkSettings::regenerate( void ) { | ||
810 | QString S; | ||
811 | // load situation | ||
812 | NetworkSettingsData NSD; | ||
813 | 405 | ||
814 | S = NSD.generateSettings( TRUE ); | 406 | if( msg == "raise" ) { |
815 | if( ! S.isEmpty() ) { | 407 | raise(); |
816 | fprintf( stdout, "%s\n", S.latin1() ); | 408 | return; |
817 | return 1; | 409 | } /* if ( msg == "someMessage(int,int,int)" ) { |
818 | } | 410 | int a,b,c; |
819 | return 0; | 411 | stream >> a >> b >> c; |
412 | ... | ||
413 | } */ | ||
820 | } | 414 | } |
diff --git a/noncore/settings/networksettings2/networksettings.h b/noncore/settings/networksettings2/networksettings.h index eb475a3..fadf81b 100644 --- a/noncore/settings/networksettings2/networksettings.h +++ b/noncore/settings/networksettings2/networksettings.h | |||
@@ -1,77 +1,49 @@ | |||
1 | #include "nsdata.h" | ||
1 | #include "networksettingsGUI.h" | 2 | #include "networksettingsGUI.h" |
2 | #include "resources.h" | 3 | #include "resources.h" |
3 | 4 | ||
4 | class ANetNode; | 5 | class ANetNode; |
5 | class ANetNodeInstance; | 6 | class ANetNodeInstance; |
6 | class QTimer; | 7 | class QTimer; |
7 | class QIconViewItem; | 8 | class QIconViewItem; |
8 | 9 | ||
9 | class NetworkSettingsData { | ||
10 | |||
11 | public : | ||
12 | |||
13 | NetworkSettingsData( void ); | ||
14 | ~NetworkSettingsData( void ); | ||
15 | |||
16 | void loadSettings( void ); | ||
17 | QString saveSettings( void ); | ||
18 | |||
19 | QString generateSettings( bool Force = FALSE ); | ||
20 | |||
21 | bool isModified( void ) | ||
22 | { return IsModified; } | ||
23 | void setModified( bool m ) | ||
24 | { IsModified = m; } | ||
25 | |||
26 | void forceGeneration( bool m ) | ||
27 | { Force = m; } | ||
28 | |||
29 | private : | ||
30 | |||
31 | bool IsModified; | ||
32 | bool Force; | ||
33 | |||
34 | }; | ||
35 | |||
36 | class NetworkSettings : public NetworkSettingsGUI { | 10 | class NetworkSettings : public NetworkSettingsGUI { |
37 | 11 | ||
38 | Q_OBJECT | 12 | Q_OBJECT |
39 | 13 | ||
40 | public : | 14 | public : |
41 | 15 | ||
42 | NetworkSettings( QWidget *parent=0, | 16 | NetworkSettings( QWidget *parent=0, |
43 | const char *name=0, | 17 | const char *name=0, |
44 | WFlags fl = 0 ); | 18 | WFlags fl = 0 ); |
45 | ~NetworkSettings( void ); | 19 | ~NetworkSettings( void ); |
46 | 20 | ||
47 | static QString appName( void ) | 21 | static QString appName( void ) |
48 | { return QString::fromLatin1("networksettings"); } | 22 | { return QString::fromLatin1("networksettings"); } |
49 | 23 | ||
50 | static void canStart( const char * Interface ); | ||
51 | static bool regenerate( void ); | ||
52 | |||
53 | bool isModified( void ) | 24 | bool isModified( void ) |
54 | { return NSD.isModified(); } | 25 | { return NSD.isModified(); } |
55 | void setModified( bool m ) | 26 | void setModified( bool m ) |
56 | { NSD.setModified( m ); } | 27 | { NSD.setModified( m ); } |
57 | 28 | ||
58 | public slots : | 29 | public slots : |
59 | 30 | ||
60 | void SLOT_AddNode( void ); | 31 | void SLOT_AddNode( void ); |
61 | void SLOT_DeleteNode( void ); | 32 | void SLOT_DeleteNode( void ); |
62 | void SLOT_ShowNode( QIconViewItem * ); | 33 | void SLOT_ShowNode( QIconViewItem * ); |
63 | void SLOT_EditNode( QIconViewItem * ); | 34 | void SLOT_EditNode( QIconViewItem * ); |
64 | void SLOT_CheckState( void ); | 35 | void SLOT_CheckState( void ); |
65 | void SLOT_Enable( void ); | 36 | void SLOT_Enable( void ); |
66 | void SLOT_On( void ); | 37 | void SLOT_On( void ); |
67 | void SLOT_Connect( void ); | 38 | void SLOT_Connect( void ); |
68 | void SLOT_GenerateConfig( void ); | 39 | void SLOT_GenerateConfig( void ); |
69 | void SLOT_RefreshStates( void ); | 40 | void SLOT_RefreshStates( void ); |
41 | void SLOT_QCopMessage( const QCString&,const QByteArray& ); | ||
70 | 42 | ||
71 | private : | 43 | private : |
72 | 44 | ||
73 | void updateProfileState( QIconViewItem * it ); | 45 | void updateProfileState( QIconViewItem * it ); |
74 | QTimer * UpdateTimer; | 46 | QTimer * UpdateTimer; |
75 | NetworkSettingsData NSD; | 47 | NetworkSettingsData NSD; |
76 | 48 | ||
77 | }; | 49 | }; |
diff --git a/noncore/settings/networksettings2/networksettings.pro b/noncore/settings/networksettings2/networksettings.pro index fb1f2cf..fe47971 100644 --- a/noncore/settings/networksettings2/networksettings.pro +++ b/noncore/settings/networksettings2/networksettings.pro | |||
@@ -1,16 +1,21 @@ | |||
1 | # | 1 | # |
2 | CONFIG = qt warn_on debug quick-app | 2 | CONFIG = qt warn_on debug quick-app |
3 | #CONFIG = qt warn_on release | 3 | #CONFIG = qt warn_on release |
4 | HEADERS = networksettings.h \ | 4 | HEADERS = networksettings.h \ |
5 | activateprofile.h \ | ||
5 | editconnection.h | 6 | editconnection.h |
6 | SOURCES = main.cpp \ | 7 | SOURCES = main.cpp \ |
7 | networksettings.cpp \ | 8 | networksettings.cpp \ |
9 | nsdata.cpp \ | ||
10 | activateprofile.cpp \ | ||
8 | editconnection.cpp | 11 | editconnection.cpp |
9 | INCLUDEPATH += $(OPIEDIR)/include networksettings2/ | 12 | INCLUDEPATH += $(OPIEDIR)/include networksettings2/ |
10 | DEPENDPATH += $(OPIEDIR)/include networksettings2/ | 13 | DEPENDPATH += $(OPIEDIR)/include networksettings2/ |
11 | LIBS += -lqpe -L$(OPIEDIR)/plugins/networksettings2 -lnetworksettings2 -lopie | 14 | LIBS += -lqpe -L$(OPIEDIR)/plugins/networksettings2 -lnetworksettings2 -lopie |
12 | INTERFACES = networksettingsGUI.ui editconnectionGUI.ui | 15 | INTERFACES = networksettingsGUI.ui \ |
16 | editconnectionGUI.ui \ | ||
17 | activateprofileGUI.ui | ||
13 | TARGET = networksettings2 | 18 | TARGET = networksettings2 |
14 | 19 | ||
15 | 20 | ||
16 | include ( $(OPIEDIR)/include.pro ) | 21 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index a5b572b..d36a1e5 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp | |||
@@ -1,278 +1,302 @@ | |||
1 | #include <qpe/qpeapplication.h> | 1 | #include <qpe/qpeapplication.h> |
2 | #include <time.h> | 2 | #include <time.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <qpixmap.h> | 4 | #include <qpixmap.h> |
5 | 5 | ||
6 | #include "resources.h" | 6 | #include "resources.h" |
7 | #include "netnode.h" | 7 | #include "netnode.h" |
8 | 8 | ||
9 | #include "asdevice.h" | 9 | #include "asdevice.h" |
10 | #include "asline.h" | 10 | #include "asline.h" |
11 | #include "asconnection.h" | 11 | #include "asconnection.h" |
12 | #include "asfullsetup.h" | 12 | #include "asfullsetup.h" |
13 | 13 | ||
14 | QString & deQuote( QString & X ) { | 14 | QString & deQuote( QString & X ) { |
15 | if( X[0] == '"' ) { | 15 | if( X[0] == '"' ) { |
16 | // remove end and trailing "" and \x -> x | 16 | // remove end and trailing "" and \x -> x |
17 | QChar R; | 17 | QChar R; |
18 | long idx; | 18 | long idx; |
19 | idx = X.length()-1; | 19 | idx = X.length()-1; |
20 | X = X.mid( 1, idx ); | 20 | X = X.mid( 1, idx ); |
21 | 21 | ||
22 | idx = 0; | 22 | idx = 0; |
23 | while( ( idx = X.find( '\\', idx ) ) >= 0 ) { | 23 | while( ( idx = X.find( '\\', idx ) ) >= 0 ) { |
24 | R = X[idx+1]; | 24 | R = X[idx+1]; |
25 | X.replace( idx, 2, &R, 1 ); | 25 | X.replace( idx, 2, &R, 1 ); |
26 | } | 26 | } |
27 | X = X.left( X.length()-1 ); | 27 | X = X.left( X.length()-1 ); |
28 | } | 28 | } |
29 | return X; | 29 | return X; |
30 | } | 30 | } |
31 | 31 | ||
32 | QString quote( QString X ) { | 32 | QString quote( QString X ) { |
33 | if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { | 33 | if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { |
34 | // need to quote this | 34 | // need to quote this |
35 | QString OutString = "\""; | 35 | QString OutString = "\""; |
36 | 36 | ||
37 | X.replace( QRegExp("\""), "\\\"" ); | 37 | X.replace( QRegExp("\""), "\\\"" ); |
38 | X.replace( QRegExp("\\"), "\\\\" ); | 38 | X.replace( QRegExp("\\"), "\\\\" ); |
39 | X.replace( QRegExp(" "), "\\ " ); | 39 | X.replace( QRegExp(" "), "\\ " ); |
40 | 40 | ||
41 | OutString += X; | 41 | OutString += X; |
42 | OutString += "\""; | 42 | OutString += "\""; |
43 | X = OutString; | 43 | X = OutString; |
44 | } | 44 | } |
45 | return X; | 45 | return X; |
46 | } | 46 | } |
47 | 47 | ||
48 | // | 48 | // |
49 | // | 49 | // |
50 | // | 50 | // |
51 | // | 51 | // |
52 | // | 52 | // |
53 | 53 | ||
54 | long ANetNodeInstance::InstanceCounter = -1; | 54 | long ANetNodeInstance::InstanceCounter = -1; |
55 | 55 | ||
56 | void ANetNodeInstance::initialize( void ) { | 56 | void ANetNodeInstance::initialize( void ) { |
57 | if( InstanceCounter == -1 ) | 57 | if( InstanceCounter == -1 ) |
58 | InstanceCounter = time(0); | 58 | InstanceCounter = time(0); |
59 | // set name | 59 | // set name |
60 | QString N; | 60 | QString N; |
61 | N.sprintf( "-%ld", InstanceCounter++ ); | 61 | N.sprintf( "-%ld", InstanceCounter++ ); |
62 | N.prepend( NodeType->nodeName() ); | 62 | N.prepend( NodeType->nodeName() ); |
63 | setNodeName( N ); | 63 | setNodeName( N ); |
64 | } | 64 | } |
65 | 65 | ||
66 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ | 66 | void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ |
67 | if( Attr == "name" ) { | 67 | if( Attr == "name" ) { |
68 | NodeName = Value; | 68 | NodeName = Value; |
69 | } else { | 69 | } else { |
70 | setSpecificAttribute( Attr, Value ); | 70 | setSpecificAttribute( Attr, Value ); |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { | 74 | void ANetNodeInstance::saveAttributes( QTextStream & TS ) { |
75 | TS << "name=" << quote( NodeName ) << endl; | 75 | TS << "name=" << quote( NodeName ) << endl; |
76 | saveSpecificAttribute( TS ); | 76 | saveSpecificAttribute( TS ); |
77 | } | 77 | } |
78 | 78 | ||
79 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { | 79 | ANetNodeInstance * ANetNodeInstance::nextNode( void ) { |
80 | return connection()->findNext( this ); | 80 | return connection()->findNext( this ); |
81 | } | 81 | } |
82 | 82 | ||
83 | // | 83 | // |
84 | // | 84 | // |
85 | // | 85 | // |
86 | // | 86 | // |
87 | // | 87 | // |
88 | 88 | ||
89 | long NodeCollection::MaxNr = -1; | 89 | long NodeCollection::MaxNr = -1; |
90 | 90 | ||
91 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { | 91 | NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { |
92 | IsModified = 0; | 92 | IsModified = 0; |
93 | Index = -1; | 93 | Index = -1; |
94 | Name=""; | 94 | Name=""; |
95 | IsNew = 1; | 95 | IsNew = 1; |
96 | CurrentState = Unchecked; | 96 | CurrentState = Unchecked; |
97 | } | 97 | } |
98 | 98 | ||
99 | NodeCollection::NodeCollection( QTextStream & TS ) : | 99 | NodeCollection::NodeCollection( QTextStream & TS ) : |
100 | QList<ANetNodeInstance>() { | 100 | QList<ANetNodeInstance>() { |
101 | long idx; | 101 | long idx; |
102 | bool InError = 0; | 102 | bool InError = 0; |
103 | QString S, A, N; | 103 | QString S, A, N; |
104 | IsModified = 0; | 104 | IsModified = 0; |
105 | Index = -1; | 105 | Index = -1; |
106 | Name=""; | 106 | Name=""; |
107 | IsNew = 0; | 107 | IsNew = 0; |
108 | CurrentState = Unchecked; | 108 | CurrentState = Unchecked; |
109 | 109 | ||
110 | do { | 110 | do { |
111 | S = TS.readLine(); | 111 | S = TS.readLine(); |
112 | if( S.isEmpty() ) { | 112 | if( S.isEmpty() ) { |
113 | if( InError ) { | 113 | if( InError ) { |
114 | // remove all nodes | 114 | // remove all nodes |
115 | clear(); | 115 | clear(); |
116 | } | 116 | } |
117 | // empty line | 117 | // empty line |
118 | break; | 118 | break; |
119 | } | 119 | } |
120 | 120 | ||
121 | idx = S.find('='); | 121 | idx = S.find('='); |
122 | S.stripWhiteSpace(); | 122 | S.stripWhiteSpace(); |
123 | A = S.left( idx ); | 123 | A = S.left( idx ); |
124 | A.lower(); | 124 | A.lower(); |
125 | N = S.mid( idx+1, S.length() ); | 125 | N = S.mid( idx+1, S.length() ); |
126 | N.stripWhiteSpace(); | 126 | N.stripWhiteSpace(); |
127 | N = deQuote( N ); | 127 | N = deQuote( N ); |
128 | 128 | ||
129 | if( A == "name" ) { | 129 | if( A == "name" ) { |
130 | Name = N; | 130 | Name = N; |
131 | } else if( A == "number" ) { | 131 | } else if( A == "number" ) { |
132 | setNumber( N.toLong() ); | 132 | setNumber( N.toLong() ); |
133 | } else if( A == "node" ) { | 133 | } else if( A == "node" ) { |
134 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); | 134 | ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); |
135 | if( NNI && ! InError ) { | 135 | if( NNI && ! InError ) { |
136 | append( NSResources->findNodeInstance( N ) ); | 136 | append( NSResources->findNodeInstance( N ) ); |
137 | } else { | 137 | } else { |
138 | // could not find a node type -> collection invalid | 138 | // could not find a node type -> collection invalid |
139 | InError = 1; | 139 | InError = 1; |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } while( 1 ); | 142 | } while( 1 ); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | NodeCollection::~NodeCollection( void ) { | 146 | NodeCollection::~NodeCollection( void ) { |
147 | } | 147 | } |
148 | 148 | ||
149 | const QString & NodeCollection::description( void ) { | 149 | const QString & NodeCollection::description( void ) { |
150 | ANetNodeInstance * NNI = getToplevel(); | 150 | ANetNodeInstance * NNI = getToplevel(); |
151 | return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; | 151 | return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; |
152 | } | 152 | } |
153 | 153 | ||
154 | void NodeCollection::append( ANetNodeInstance * NNI ) { | 154 | void NodeCollection::append( ANetNodeInstance * NNI ) { |
155 | NNI->setConnection( this ); | 155 | NNI->setConnection( this ); |
156 | QList<ANetNodeInstance>::append( NNI ); | 156 | QList<ANetNodeInstance>::append( NNI ); |
157 | } | 157 | } |
158 | 158 | ||
159 | void NodeCollection::save( QTextStream & TS ) { | 159 | void NodeCollection::save( QTextStream & TS ) { |
160 | 160 | ||
161 | TS << "name=" << quote( Name ) << endl; | 161 | TS << "name=" << quote( Name ) << endl; |
162 | TS << "number=" << number() << endl; | 162 | TS << "number=" << number() << endl; |
163 | ANetNodeInstance * NNI; | 163 | ANetNodeInstance * NNI; |
164 | for( QListIterator<ANetNodeInstance> it(*this); | 164 | for( QListIterator<ANetNodeInstance> it(*this); |
165 | it.current(); | 165 | it.current(); |
166 | ++it ) { | 166 | ++it ) { |
167 | NNI = it.current(); | 167 | NNI = it.current(); |
168 | TS << "node=" << quote( NNI->nodeName() ) << endl; | 168 | TS << "node=" << quote( NNI->nodeName() ) << endl; |
169 | } | 169 | } |
170 | TS << endl; | 170 | TS << endl; |
171 | IsNew = 0; | 171 | IsNew = 0; |
172 | } | 172 | } |
173 | 173 | ||
174 | ANetNodeInstance * NodeCollection::getToplevel( void ) { | 174 | ANetNodeInstance * NodeCollection::getToplevel( void ) { |
175 | ANetNodeInstance * NNI = 0; | 175 | ANetNodeInstance * NNI = 0; |
176 | for( QListIterator<ANetNodeInstance> it(*this); | 176 | for( QListIterator<ANetNodeInstance> it(*this); |
177 | it.current(); | 177 | it.current(); |
178 | ++it ) { | 178 | ++it ) { |
179 | NNI = it.current(); | 179 | NNI = it.current(); |
180 | if( NNI->netNode()->isToplevel() ) | 180 | if( NNI->netNode()->isToplevel() ) |
181 | break; | 181 | break; |
182 | } | 182 | } |
183 | return NNI; | 183 | return NNI; |
184 | } | 184 | } |
185 | 185 | ||
186 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { | 186 | ANetNodeInstance * NodeCollection::findByName( const QString & S ) { |
187 | ANetNodeInstance * NNI = 0; | 187 | ANetNodeInstance * NNI = 0; |
188 | for( QListIterator<ANetNodeInstance> it(*this); | 188 | for( QListIterator<ANetNodeInstance> it(*this); |
189 | it.current(); | 189 | it.current(); |
190 | ++it ) { | 190 | ++it ) { |
191 | NNI = it.current(); | 191 | NNI = it.current(); |
192 | if( NNI->name() == S ) | 192 | if( NNI->name() == S ) |
193 | break; | 193 | break; |
194 | } | 194 | } |
195 | return NNI; | 195 | return NNI; |
196 | } | 196 | } |
197 | 197 | ||
198 | ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { | 198 | ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { |
199 | ANetNodeInstance * NNNI; | 199 | ANetNodeInstance * NNNI; |
200 | 200 | ||
201 | if( ! NNI ) | 201 | if( ! NNI ) |
202 | getToplevel(); | 202 | getToplevel(); |
203 | 203 | ||
204 | for( QListIterator<ANetNodeInstance> it(*this); | 204 | for( QListIterator<ANetNodeInstance> it(*this); |
205 | it.current(); | 205 | it.current(); |
206 | ++it ) { | 206 | ++it ) { |
207 | NNNI = it.current(); | 207 | NNNI = it.current(); |
208 | if( NNNI == NNI ) { | 208 | if( NNNI == NNI ) { |
209 | ++it; | 209 | ++it; |
210 | return it.current(); | 210 | return it.current(); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | return 0; // no more next | 213 | return 0; // no more next |
214 | } | 214 | } |
215 | 215 | ||
216 | int NodeCollection::compareItems( QCollection::Item I1, | 216 | int NodeCollection::compareItems( QCollection::Item I1, |
217 | QCollection::Item I2 ) { | 217 | QCollection::Item I2 ) { |
218 | ANetNodeInstance * NNI1, * NNI2; | 218 | ANetNodeInstance * NNI1, * NNI2; |
219 | NNI1 = (ANetNodeInstance *)I1; | 219 | NNI1 = (ANetNodeInstance *)I1; |
220 | NNI2 = (ANetNodeInstance *)I2; | 220 | NNI2 = (ANetNodeInstance *)I2; |
221 | return NNI1->nodeName().compare( NNI2->nodeName() ); | 221 | return NNI1->nodeName().compare( NNI2->nodeName() ); |
222 | } | 222 | } |
223 | 223 | ||
224 | static char * State2PixmapTbl[] = { | 224 | static char * State2PixmapTbl[] = { |
225 | "NULL", // Unchecked : no pixmap | 225 | "NULL", // Unchecked : no pixmap |
226 | "check", // Unknown | 226 | "check", // Unknown |
227 | "delete", // unavailable | 227 | "delete", // unavailable |
228 | "disabled", // disabled | 228 | "disabled", // disabled |
229 | "off", // off | 229 | "off", // off |
230 | "disconnected", // available | 230 | "disconnected", // available |
231 | "connected" // up | 231 | "connected" // up |
232 | }; | 232 | }; |
233 | 233 | ||
234 | QPixmap NodeCollection::devicePixmap( void ) { | 234 | QPixmap NodeCollection::devicePixmap( void ) { |
235 | return NSResources->getPixmap( | 235 | return NSResources->getPixmap( |
236 | device()->netNode()->pixmapName()+"-large" ); | 236 | device()->netNode()->pixmapName()+"-large" ); |
237 | } | 237 | } |
238 | 238 | ||
239 | QPixmap NodeCollection::statePixmap( State_t S) { | 239 | QPixmap NodeCollection::statePixmap( State_t S) { |
240 | return NSResources->getPixmap( State2PixmapTbl[S] ); | 240 | return NSResources->getPixmap( State2PixmapTbl[S] ); |
241 | } | 241 | } |
242 | 242 | ||
243 | QString NodeCollection::stateName( State_t S) { | 243 | QString NodeCollection::stateName( State_t S) { |
244 | switch( S ) { | 244 | switch( S ) { |
245 | case Unknown : | 245 | case Unknown : |
246 | return qApp->translate( "networksettings2", "Unknown"); | 246 | return qApp->translate( "networksettings2", "Unknown"); |
247 | case Unavailable : | 247 | case Unavailable : |
248 | return qApp->translate( "networksettings2", "Unavailable"); | 248 | return qApp->translate( "networksettings2", "Unavailable"); |
249 | case Disabled : | 249 | case Disabled : |
250 | return qApp->translate( "networksettings2", "Disabled"); | 250 | return qApp->translate( "networksettings2", "Disabled"); |
251 | case Off : | 251 | case Off : |
252 | return qApp->translate( "networksettings2", "Off"); | 252 | return qApp->translate( "networksettings2", "Off"); |
253 | case Available : | 253 | case Available : |
254 | return qApp->translate( "networksettings2", "Available"); | 254 | return qApp->translate( "networksettings2", "Available"); |
255 | case IsUp : | 255 | case IsUp : |
256 | return qApp->translate( "networksettings2", "IsUp"); | 256 | return qApp->translate( "networksettings2", "IsUp"); |
257 | case Unchecked : /* FT */ | 257 | case Unchecked : /* FT */ |
258 | default : | 258 | default : |
259 | break; | 259 | break; |
260 | } | 260 | } |
261 | return QString(""); | 261 | return QString(""); |
262 | } | 262 | } |
263 | 263 | ||
264 | void NodeCollection::reassign( void ) { | 264 | void NodeCollection::reassign( void ) { |
265 | for( QListIterator<ANetNodeInstance> it(*this); | 265 | for( QListIterator<ANetNodeInstance> it(*this); |
266 | it.current(); | 266 | it.current(); |
267 | ++it ) { | 267 | ++it ) { |
268 | it.current()->setConnection( this ); | 268 | it.current()->setConnection( this ); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | 271 | ||
272 | InterfaceInfo * RuntimeInfo::assignedInterface( void ) { | 272 | InterfaceInfo * RuntimeInfo::assignedInterface( void ) { |
273 | return netNode()->nextNode()->runtime()->assignedInterface(); | 273 | return netNode()->nextNode()->runtime()->assignedInterface(); |
274 | } | 274 | } |
275 | 275 | ||
276 | AsDevice * RuntimeInfo::device( void ) { | 276 | AsDevice * RuntimeInfo::device( void ) { |
277 | return netNode()->nextNode()->runtime()->device(); | 277 | return netNode()->nextNode()->runtime()->device(); |
278 | } | 278 | } |
279 | |||
280 | ANetNodeInstance * FakeNetNode::createInstance( void ) { | ||
281 | return new FakeNetNodeInstance( this ); | ||
282 | } | ||
283 | |||
284 | void FakeNetNodeInstance::setSpecificAttribute( | ||
285 | QString & A, QString & V ) { | ||
286 | ValAttrPairs.insert( A, new QString(V) ); | ||
287 | } | ||
288 | |||
289 | void FakeNetNodeInstance::saveSpecificAttribute( QTextStream &TS ) { | ||
290 | for( QDictIterator<QString> it( ValAttrPairs ); | ||
291 | it.current(); | ||
292 | ++ it ) { | ||
293 | TS << it.currentKey().latin1() | ||
294 | << "=" | ||
295 | << quote( *(it.current())) | ||
296 | << endl ; | ||
297 | ++it; | ||
298 | } | ||
299 | } | ||
300 | |||
301 | // collects all info that no plugin acceps | ||
302 | FakeNetNode * FakeNode = 0; | ||
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 0ecd64e..56333c5 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h | |||
@@ -1,361 +1,440 @@ | |||
1 | #ifndef NETNODE_H | 1 | #ifndef NETNODE_H |
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 <qpixmap.h> | 7 | #include <qpixmap.h> |
7 | #include <qobject.h> | 8 | #include <qobject.h> |
8 | #include <time.h> | 9 | #include <time.h> |
9 | 10 | ||
10 | // difference feature interfaces | 11 | // difference feature interfaces |
11 | class AsDevice; | 12 | class AsDevice; |
12 | class AsLine; | 13 | class AsLine; |
13 | class AsConnection; | 14 | class AsConnection; |
14 | class AsFullSetup; | 15 | class AsFullSetup; |
15 | 16 | ||
16 | // needed for plugin creation function | 17 | // needed for plugin creation function |
17 | #include <qlist.h> | 18 | #include <qlist.h> |
18 | 19 | ||
19 | class ANetNode; | 20 | class ANetNode; |
20 | class ANetNodeInstance; | 21 | class ANetNodeInstance; |
21 | class NodeCollection; | 22 | class NodeCollection; |
22 | class QTextStream; | 23 | class QTextStream; |
23 | class RuntimeInfo; | 24 | class RuntimeInfo; |
24 | class InterfaceInfo; | 25 | class InterfaceInfo; |
25 | 26 | ||
26 | extern QString & deQuote( QString & X ); | 27 | extern QString & deQuote( QString & X ); |
27 | extern QString quote( QString X ); | 28 | extern QString quote( QString X ); |
28 | 29 | ||
29 | #include "systemfile.h" | 30 | #include "systemfile.h" |
30 | 31 | ||
31 | typedef enum State { | 32 | typedef enum State { |
32 | // if we have not yet detected the state of the device | 33 | // if we have not yet detected the state of the device |
33 | Unchecked = 0, | 34 | Unchecked = 0, |
34 | // if we cannot determine the state | 35 | // if we cannot determine the state |
35 | Unknown = 1, | 36 | Unknown = 1, |
36 | // if connection cannot be established e.g. because | 37 | // if connection cannot be established e.g. because |
37 | // the hardware is not available | 38 | // the hardware is not available |
38 | Unavailable = 2, | 39 | Unavailable = 2, |
39 | // if the connection cannot be establishec but NOT | 40 | // if the connection cannot be establishec but NOT |
40 | // because it is physically impossible but because | 41 | // because it is physically impossible but because |
41 | // it has been disabled for FUNCTIONAL reasons | 42 | // it has been disabled for FUNCTIONAL reasons |
42 | Disabled = 3, | 43 | Disabled = 3, |
43 | // if connection is available to is currently down | 44 | // if connection is available to is currently down |
44 | // i.e. the corresponding hardware is not activated | 45 | // i.e. the corresponding hardware is not activated |
45 | Off = 4, | 46 | Off = 4, |
46 | // if connection is available to be used (i.e. the | 47 | // if connection is available to be used (i.e. the |
47 | // devices if fully ready to be used | 48 | // devices if fully ready to be used |
48 | Available = 5, | 49 | Available = 5, |
49 | // if connection is being used | 50 | // if connection is being used |
50 | IsUp = 6 | 51 | IsUp = 6 |
51 | } State_t; | 52 | } State_t; |
52 | 53 | ||
53 | typedef enum Action { | 54 | typedef enum Action { |
54 | // to make the device unavailable functionally | 55 | // to make the device unavailable functionally |
55 | Disable = 0, | 56 | Disable = 0, |
56 | // to make the device available functionally | 57 | // to make the device available functionally |
57 | Enable = 1, | 58 | Enable = 1, |
58 | // bring the hardware up | 59 | // bring the hardware up |
59 | Activate = 2, | 60 | Activate = 2, |
60 | // bring the hardware down | 61 | // bring the hardware down |
61 | Deactivate = 3, | 62 | Deactivate = 3, |
62 | // bring the connection up | 63 | // bring the connection up |
63 | Up = 4, | 64 | Up = 4, |
64 | // bring the connection down | 65 | // bring the connection down |
65 | Down = 5 | 66 | Down = 5 |
66 | } Action_t; | 67 | } Action_t; |
67 | 68 | ||
68 | class ANetNode : public QObject{ | 69 | class ANetNode : public QObject{ |
69 | 70 | ||
70 | public: | 71 | public: |
71 | 72 | ||
72 | typedef QArray<ANetNode *> NetNodeList; | 73 | typedef QArray<ANetNode *> NetNodeList; |
73 | 74 | ||
74 | ANetNode(){}; | 75 | ANetNode(){}; |
75 | virtual ~ANetNode(){}; | 76 | virtual ~ANetNode(){}; |
76 | 77 | ||
77 | // pixmap needed for this NetNode | 78 | // pixmap needed for this NetNode |
78 | virtual const QString pixmapName() = 0; | 79 | virtual const QString pixmapName() = 0; |
79 | 80 | ||
80 | // name of this NetNode | 81 | // name of this NetNode |
81 | virtual const QString nodeName() = 0; | 82 | virtual const QString nodeName() = 0; |
82 | 83 | ||
83 | // description for this NetNode | 84 | // description for this NetNode |
84 | virtual const QString nodeDescription() = 0; | 85 | virtual const QString nodeDescription() = 0; |
85 | 86 | ||
86 | // create a blank instance of a net node | 87 | // create a blank instance of a net node |
87 | virtual ANetNodeInstance * createInstance( void ) = 0; | 88 | virtual ANetNodeInstance * createInstance( void ) = 0; |
88 | 89 | ||
89 | // return feature this NetNode provides | 90 | // return feature this NetNode provides |
90 | virtual const char * provides( void ) = 0; | 91 | virtual const char * provides( void ) = 0; |
91 | virtual const char ** needs( void ) = 0; | 92 | virtual const char ** needs( void ) = 0; |
92 | 93 | ||
93 | // generate files specific for this node (if any) | 94 | // generate files specific for this node (if any) |
94 | virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; | 95 | virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; |
95 | // return TRUE if this node has data to be inserted in systemfile | 96 | // return TRUE if this node has data to be inserted in systemfile |
96 | // with name S | 97 | // with name S |
97 | virtual bool hasDataFor( const QString & S ) = 0; | 98 | virtual bool hasDataFor( const QString & S ) = 0; |
98 | // generate data specific for the system file S | 99 | // generate data specific for the system file S |
99 | // called only IF data was needed | 100 | // called only IF data was needed |
100 | virtual bool generateDataForCommonFile( | 101 | virtual bool generateDataForCommonFile( |
101 | SystemFile & SF, long DevNr, ANetNodeInstance * NNI ) = 0; | 102 | SystemFile & SF, long DevNr, ANetNodeInstance * NNI ) = 0; |
102 | 103 | ||
103 | // does this Node provide a Connection | 104 | // does this Node provide a Connection |
104 | bool isToplevel( void ) | 105 | bool isToplevel( void ) |
105 | { return strcmp( provides(), "fullsetup") == 0 ; } | 106 | { return strcmp( provides(), "fullsetup") == 0 ; } |
106 | 107 | ||
107 | // compiled references to 'needed' NetNodes -> needs list | 108 | // compiled references to 'needed' NetNodes -> needs list |
108 | void setAlternatives( NetNodeList * Alt ) | 109 | void setAlternatives( NetNodeList * Alt ) |
109 | { Alternatives = Alt; } | 110 | { Alternatives = Alt; } |
110 | NetNodeList & alternatives( void ) | 111 | NetNodeList & alternatives( void ) |
111 | { return *Alternatives; } | 112 | { return *Alternatives; } |
112 | 113 | ||
113 | protected : | 114 | protected : |
114 | 115 | ||
115 | NetNodeList * Alternatives; | 116 | NetNodeList * Alternatives; |
116 | 117 | ||
117 | private : | 118 | private : |
118 | }; | 119 | }; |
119 | 120 | ||
120 | class ANetNodeInstance : public QObject { | 121 | class ANetNodeInstance : public QObject { |
121 | 122 | ||
122 | public: | 123 | public: |
123 | 124 | ||
124 | ANetNodeInstance( ANetNode * NN ) : QObject() | 125 | ANetNodeInstance( ANetNode * NN ) : QObject() |
125 | { IsModified=0; NodeType = NN; IsNew = TRUE; } | 126 | { IsModified=0; NodeType = NN; IsNew = TRUE; } |
126 | virtual ~ANetNodeInstance( void ) { } | 127 | virtual ~ANetNodeInstance( void ) { } |
127 | 128 | ||
128 | virtual RuntimeInfo * runtime( void ) = 0; | 129 | virtual RuntimeInfo * runtime( void ) = 0; |
129 | 130 | ||
130 | void setConnection( NodeCollection * NC ) | 131 | void setConnection( NodeCollection * NC ) |
131 | { Connection = NC; } | 132 | { Connection = NC; } |
132 | NodeCollection * connection( void ) | 133 | NodeCollection * connection( void ) |
133 | { return Connection; } | 134 | { return Connection; } |
134 | 135 | ||
135 | // create edit widget under parent | 136 | // create edit widget under parent |
136 | virtual QWidget * edit( QWidget * parent ) = 0; | 137 | virtual QWidget * edit( QWidget * parent ) = 0; |
137 | // is given data acceptable | 138 | // is given data acceptable |
138 | virtual QString acceptable( void ) = 0; | 139 | virtual QString acceptable( void ) = 0; |
139 | 140 | ||
140 | // return data was modified | 141 | // return data was modified |
141 | void setModified( bool M ) | 142 | void setModified( bool M ) |
142 | { IsModified = M; } | 143 | { IsModified = M; } |
143 | bool isModified( void ) | 144 | bool isModified( void ) |
144 | { return IsModified; } | 145 | { return IsModified; } |
145 | 146 | ||
146 | // get data from GUI and store in node | 147 | // get data from GUI and store in node |
147 | virtual void commit( void ) = 0; | 148 | virtual void commit( void ) = 0; |
148 | 149 | ||
149 | // get next node | 150 | // get next node |
150 | ANetNodeInstance * nextNode(); | 151 | ANetNodeInstance * nextNode(); |
151 | // return NetNode this is an instance of | 152 | // return NetNode this is an instance of |
152 | ANetNode * netNode( void ) | 153 | ANetNode * netNode( void ) |
153 | { return NodeType; } | 154 | { return NodeType; } |
154 | 155 | ||
155 | // intialize am instance of a net node | 156 | // intialize am instance of a net node |
156 | void initialize( void ); | 157 | void initialize( void ); |
157 | 158 | ||
158 | // set the value of an attribute | 159 | // set the value of an attribute |
159 | void setAttribute( QString & Attr, QString & Value ) ; | 160 | void setAttribute( QString & Attr, QString & Value ) ; |
160 | void saveAttributes( QTextStream & TS ) ; | 161 | void saveAttributes( QTextStream & TS ) ; |
161 | 162 | ||
162 | // return true if node isntance is NEW and not loaded | 163 | // return true if node isntance is NEW and not loaded |
163 | void setNew( bool IsN ) | 164 | void setNew( bool IsN ) |
164 | { IsNew = IsN; } | 165 | { IsNew = IsN; } |
165 | bool isNew( void ) | 166 | bool isNew( void ) |
166 | { return IsNew; } | 167 | { return IsNew; } |
167 | 168 | ||
168 | // return logical name of this instance | 169 | // return logical name of this instance |
169 | QString & nodeName( void ) | 170 | QString & nodeName( void ) |
170 | { return NodeName; } | 171 | { return NodeName; } |
171 | void setNodeName( const QString & S ) | 172 | void setNodeName( const QString & S ) |
172 | { NodeName = S; } | 173 | { NodeName = S; } |
173 | // return description for this instance | 174 | // return description for this instance |
174 | QString & description( void ) | 175 | QString & description( void ) |
175 | { return Description; } | 176 | { return Description; } |
176 | void setDescription( const QString & S ) | 177 | void setDescription( const QString & S ) |
177 | { Description = S; } | 178 | { Description = S; } |
178 | 179 | ||
179 | // pixmap for this instance -> from NetNode | 180 | // pixmap for this instance -> from NetNode |
180 | const QString pixmapName( void ) | 181 | const QString pixmapName( void ) |
181 | { return NodeType->pixmapName(); } | 182 | { return NodeType->pixmapName(); } |
182 | 183 | ||
183 | const char * provides( void ) | 184 | const char * provides( void ) |
184 | { return NodeType->provides(); } | 185 | { return NodeType->provides(); } |
185 | 186 | ||
186 | const char ** needs( void ) | 187 | const char ** needs( void ) |
187 | { return NodeType->needs(); } | 188 | { return NodeType->needs(); } |
188 | 189 | ||
189 | // returns node specific data -> only useful for 'buddy' | 190 | // returns node specific data -> only useful for 'buddy' |
190 | virtual void * data( void ) = 0; | 191 | virtual void * data( void ) = 0; |
191 | 192 | ||
192 | protected : | 193 | protected : |
193 | 194 | ||
194 | virtual void setSpecificAttribute( QString & , QString & ) = 0; | 195 | virtual void setSpecificAttribute( QString & , QString & ) = 0; |
195 | virtual void saveSpecificAttribute( QTextStream & ) = 0; | 196 | virtual void saveSpecificAttribute( QTextStream & ) = 0; |
196 | 197 | ||
197 | ANetNode * NodeType; | 198 | ANetNode * NodeType; |
198 | // connection to which this node belongs to | 199 | // connection to which this node belongs to |
199 | NodeCollection * Connection; | 200 | NodeCollection * Connection; |
200 | QString NodeName; | 201 | QString NodeName; |
201 | QString Description; | 202 | QString Description; |
202 | bool IsModified; | 203 | bool IsModified; |
203 | bool IsNew; | 204 | bool IsNew; |
204 | 205 | ||
205 | static long InstanceCounter; | 206 | static long InstanceCounter; |
206 | }; | 207 | }; |
207 | 208 | ||
208 | class RuntimeInfo : public QObject { | 209 | class RuntimeInfo : public QObject { |
209 | 210 | ||
210 | Q_OBJECT | 211 | Q_OBJECT |
211 | 212 | ||
212 | public : | 213 | public : |
213 | 214 | ||
214 | RuntimeInfo( ANetNodeInstance * TheNNI ) | 215 | RuntimeInfo( ANetNodeInstance * TheNNI ) |
215 | { NNI = TheNNI; } | 216 | { NNI = TheNNI; } |
216 | 217 | ||
217 | // downcast | 218 | // downcast |
218 | AsDevice * asDevice( void ) | 219 | AsDevice * asDevice( void ) |
219 | { return (AsDevice *)this; } | 220 | { return (AsDevice *)this; } |
220 | AsConnection * asConnection( void ) | 221 | AsConnection * asConnection( void ) |
221 | { return (AsConnection *)this; } | 222 | { return (AsConnection *)this; } |
222 | AsLine * asLine( void ) | 223 | AsLine * asLine( void ) |
223 | { return (AsLine *)this; } | 224 | { return (AsLine *)this; } |
224 | AsFullSetup * asFullSetup( void ) | 225 | AsFullSetup * asFullSetup( void ) |
225 | { return (AsFullSetup *)this; } | 226 | { return (AsFullSetup *)this; } |
226 | 227 | ||
227 | // does this node handles this interface e.g.eth0 | 228 | // does this node handles this interface e.g.eth0 |
228 | // recurse deeper if this node cannot answer that question | 229 | // recurse deeper if this node cannot answer that question |
229 | virtual bool handlesInterface( const QString & ) | 230 | virtual bool handlesInterface( const QString & ) |
230 | { return 0; } | 231 | { return 0; } |
231 | virtual InterfaceInfo * assignedInterface( void ); | 232 | virtual InterfaceInfo * assignedInterface( void ); |
232 | virtual AsDevice * device( void ); | 233 | virtual AsDevice * device( void ); |
233 | 234 | ||
234 | ANetNodeInstance * netNode() | 235 | ANetNodeInstance * netNode() |
235 | { return NNI; } | 236 | { return NNI; } |
236 | NodeCollection * connection() | 237 | NodeCollection * connection() |
237 | { return NNI->connection(); } | 238 | { return NNI->connection(); } |
238 | 239 | ||
239 | virtual void detectState( NodeCollection * NC ) = 0; | 240 | virtual void detectState( NodeCollection * NC ) = 0; |
240 | virtual bool setState( NodeCollection * NC, Action_t A ) = 0; | 241 | virtual bool setState( NodeCollection * NC, Action_t A ) = 0; |
241 | virtual bool canSetState( State_t Curr, Action_t A ) = 0; | 242 | virtual bool canSetState( State_t Curr, Action_t A ) = 0; |
242 | 243 | ||
243 | signals : | 244 | signals : |
244 | 245 | ||
245 | // sent by device if state changes | 246 | // sent by device if state changes |
246 | void stateChanged( State_t S, ANetNodeInstance * NNI ); | 247 | void stateChanged( State_t S, ANetNodeInstance * NNI ); |
247 | 248 | ||
248 | protected : | 249 | protected : |
249 | 250 | ||
250 | // connection this runtime info belongs to | 251 | // connection this runtime info belongs to |
251 | ANetNodeInstance * NNI; | 252 | ANetNodeInstance * NNI; |
252 | }; | 253 | }; |
253 | 254 | ||
254 | class NodeCollection : public QList<ANetNodeInstance> { | 255 | class NodeCollection : public QList<ANetNodeInstance> { |
255 | 256 | ||
256 | public : | 257 | public : |
257 | 258 | ||
258 | NodeCollection( void ); | 259 | NodeCollection( void ); |
259 | NodeCollection( QTextStream & TS ); | 260 | NodeCollection( QTextStream & TS ); |
260 | ~NodeCollection( void ); | 261 | ~NodeCollection( void ); |
261 | 262 | ||
262 | int number( void ) | 263 | int number( void ) |
263 | { return Number; } | 264 | { return Number; } |
264 | void setNumber( int i ) | 265 | void setNumber( int i ) |
265 | { Number = i; if( MaxNr < i ) MaxNr = i; } | 266 | { Number = i; if( MaxNr < i ) MaxNr = i; } |
266 | bool isNew( void ) | 267 | bool isNew( void ) |
267 | { return IsNew; } | 268 | { return IsNew; } |
268 | void setNew( bool N ) | 269 | void setNew( bool N ) |
269 | { IsNew = N ; } | 270 | { IsNew = N ; } |
270 | bool isModified( void ) | 271 | bool isModified( void ) |
271 | { return IsModified; } | 272 | { return IsModified; } |
272 | void setModified( bool N ) | 273 | void setModified( bool N ) |
273 | { IsModified = N ; } | 274 | { IsModified = N ; } |
274 | 275 | ||
275 | bool handlesInterface( const QString & S ) { | 276 | bool handlesInterface( const QString & S ) { |
276 | return getToplevel()->runtime()->handlesInterface( S ); | 277 | return getToplevel()->runtime()->handlesInterface( S ); |
277 | } | 278 | } |
278 | 279 | ||
279 | InterfaceInfo * assignedInterface( void ) { | 280 | InterfaceInfo * assignedInterface( void ) { |
280 | return getToplevel()->runtime()->assignedInterface(); | 281 | return getToplevel()->runtime()->assignedInterface(); |
281 | } | 282 | } |
282 | 283 | ||
283 | AsDevice * device() { | 284 | AsDevice * device() { |
284 | return getToplevel()->runtime()->device(); | 285 | return getToplevel()->runtime()->device(); |
285 | } | 286 | } |
286 | 287 | ||
287 | State_t state( bool Update = 0 ) | 288 | State_t state( bool Update = 0 ) |
288 | { if( CurrentState == Unchecked || Update ) { | 289 | { if( CurrentState == Unchecked || Update ) { |
289 | // need to get current state | 290 | // need to get current state |
290 | getToplevel()->runtime()->detectState( this ); | 291 | getToplevel()->runtime()->detectState( this ); |
291 | } | 292 | } |
292 | return CurrentState; | 293 | return CurrentState; |
293 | } | 294 | } |
294 | 295 | ||
295 | // get the ixmap for this device | 296 | // get the ixmap for this device |
296 | QPixmap devicePixmap( void ); | 297 | QPixmap devicePixmap( void ); |
297 | QPixmap statePixmap( State_t S ); | 298 | QPixmap statePixmap( State_t S ); |
298 | QPixmap statePixmap( bool Update = 0 ) | 299 | QPixmap statePixmap( bool Update = 0 ) |
299 | { return statePixmap( state(Update) ); } | 300 | { return statePixmap( state(Update) ); } |
300 | QString stateName( State_t ); | 301 | QString stateName( State_t ); |
301 | QString stateName( bool Update = 0 ) | 302 | QString stateName( bool Update = 0 ) |
302 | { return stateName( state(Update) ); } | 303 | { return stateName( state(Update) ); } |
303 | 304 | ||
304 | bool setState( Action_t A ) | 305 | bool setState( Action_t A ) |
305 | { return getToplevel()->runtime()->setState( this, A ); } | 306 | { return getToplevel()->runtime()->setState( this, A ); } |
306 | bool canSetState( Action_t A ) | 307 | bool canSetState( Action_t A ) |
307 | { return getToplevel()->runtime()->canSetState( CurrentState, A ); } | 308 | { return getToplevel()->runtime()->canSetState( CurrentState, A ); } |
308 | 309 | ||
309 | void save( QTextStream & TS ); | 310 | void save( QTextStream & TS ); |
310 | 311 | ||
311 | void append( ANetNodeInstance * NNI ); | 312 | void append( ANetNodeInstance * NNI ); |
312 | 313 | ||
313 | // makes sure that all items in the connection point to | 314 | // makes sure that all items in the connection point to |
314 | // that connectoin | 315 | // that connectoin |
315 | void reassign( void ); | 316 | void reassign( void ); |
316 | 317 | ||
317 | ANetNodeInstance * getToplevel( void ); | 318 | ANetNodeInstance * getToplevel( void ); |
318 | ANetNodeInstance * findNext( ANetNodeInstance * NNI ); | 319 | ANetNodeInstance * findNext( ANetNodeInstance * NNI ); |
319 | ANetNodeInstance * findByName( const QString & S ); | 320 | ANetNodeInstance * findByName( const QString & S ); |
320 | 321 | ||
321 | const QString & name() | 322 | const QString & name() |
322 | { return Name; } | 323 | { return Name; } |
323 | 324 | ||
324 | const QString & description( void ); | 325 | const QString & description( void ); |
325 | 326 | ||
326 | void setName( const QString & N) | 327 | void setName( const QString & N) |
327 | { Name = N; } | 328 | { Name = N; } |
328 | 329 | ||
329 | State_t currentState( void ) | 330 | State_t currentState( void ) |
330 | { return CurrentState; } | 331 | { return CurrentState; } |
331 | void setCurrentState( State_t S ) | 332 | void setCurrentState( State_t S ) |
332 | { CurrentState = S; } | 333 | { CurrentState = S; } |
333 | 334 | ||
334 | long maxConnectionNumber( void ) | 335 | long maxConnectionNumber( void ) |
335 | { return MaxNr; } | 336 | { return MaxNr; } |
336 | 337 | ||
337 | static void resetMaxNr( void ) | 338 | static void resetMaxNr( void ) |
338 | { MaxNr = -1; } | 339 | { MaxNr = -1; } |
339 | 340 | ||
340 | private : | 341 | private : |
341 | 342 | ||
342 | int compareItems ( QCollection::Item item1, | 343 | int compareItems ( QCollection::Item item1, |
343 | QCollection::Item item2 ); | 344 | QCollection::Item item2 ); |
344 | 345 | ||
345 | static long MaxNr; | 346 | static long MaxNr; |
346 | long Number; | 347 | long Number; |
347 | 348 | ||
348 | // state of this connection | 349 | // state of this connection |
349 | State_t CurrentState; | 350 | State_t CurrentState; |
350 | 351 | ||
351 | QString Name; | 352 | QString Name; |
352 | // true if this collection was just created (and not | 353 | // true if this collection was just created (and not |
353 | // loaded from file | 354 | // loaded from file |
354 | bool IsNew; | 355 | bool IsNew; |
355 | // index in listbox | 356 | // index in listbox |
356 | int Index; | 357 | int Index; |
357 | bool IsModified; | 358 | bool IsModified; |
358 | 359 | ||
359 | }; | 360 | }; |
360 | 361 | ||
362 | // | ||
363 | // special node that is used to remember entries for plugins | ||
364 | // that seem missing. This way we never loose data | ||
365 | // | ||
366 | |||
367 | class FakeNetNode : public ANetNode { | ||
368 | |||
369 | public: | ||
370 | |||
371 | FakeNetNode( ) { }; | ||
372 | virtual ~FakeNetNode(){}; | ||
373 | |||
374 | const QString pixmapName() | ||
375 | { return QString(""); } | ||
376 | const QString nodeName() | ||
377 | { return QString("Fake node" ); } | ||
378 | const QString nodeDescription() | ||
379 | { return QString("Fake node" ); } | ||
380 | ANetNodeInstance * createInstance( void ); | ||
381 | const char * provides( void ) | ||
382 | { return ""; } | ||
383 | virtual const char ** needs( void ) | ||
384 | { return 0; } | ||
385 | virtual bool generateProperFilesFor( ANetNodeInstance * ) | ||
386 | { return 0; } | ||
387 | virtual bool hasDataFor( const QString & ) | ||
388 | { return 0; } | ||
389 | virtual bool generateDataForCommonFile( | ||
390 | SystemFile & , long , ANetNodeInstance * ) | ||
391 | {return 1; } | ||
392 | |||
393 | private : | ||
394 | |||
395 | }; | ||
396 | |||
397 | class FakeNetNodeInstance : public ANetNodeInstance { | ||
398 | |||
399 | public: | ||
400 | |||
401 | FakeNetNodeInstance( ANetNode * NN ) : | ||
402 | ANetNodeInstance( NN ), ValAttrPairs() { } | ||
403 | virtual ~FakeNetNodeInstance( void ) { } | ||
404 | |||
405 | virtual RuntimeInfo * runtime( void ) | ||
406 | { return 0; } | ||
407 | |||
408 | // create edit widget under parent | ||
409 | virtual QWidget * edit( QWidget * ) | ||
410 | { return 0; } | ||
411 | // is given data acceptable | ||
412 | virtual QString acceptable( void ) | ||
413 | { return QString(""); } | ||
414 | |||
415 | // get data from GUI and store in node | ||
416 | virtual void commit( void ) {} | ||
417 | |||
418 | // get next node | ||
419 | ANetNodeInstance * nextNode() | ||
420 | { return 0; } | ||
421 | // return NetNode this is an instance of | ||
422 | |||
423 | // intialize am instance of a net node | ||
424 | void initialize( void ){} | ||
425 | |||
426 | // returns node specific data -> only useful for 'buddy' | ||
427 | virtual void * data( void ) | ||
428 | { return 0; } | ||
429 | |||
430 | protected : | ||
431 | |||
432 | virtual void setSpecificAttribute( QString & , QString & ); | ||
433 | virtual void saveSpecificAttribute( QTextStream & ); | ||
434 | |||
435 | QDict<QString> ValAttrPairs; | ||
436 | }; | ||
437 | |||
438 | extern FakeNetNode * FakeNode; | ||
439 | |||
361 | #endif | 440 | #endif |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index ff6e457..15e1b64 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp | |||
@@ -1,236 +1,231 @@ | |||
1 | #include <qpixmap.h> | 1 | #include <qpixmap.h> |
2 | #include <qpe/qlibrary.h> | 2 | #include <qpe/qlibrary.h> |
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <qdir.h> | 4 | #include <qdir.h> |
5 | #include <opie2/odebug.h> | ||
5 | #include <qtopia/resource.h> | 6 | #include <qtopia/resource.h> |
6 | 7 | ||
7 | #include "netnode.h" | 8 | #include "netnode.h" |
8 | #include "resources.h" | 9 | #include "resources.h" |
9 | 10 | ||
10 | #define PLUGINDIR "plugins/networksettings2" | 11 | #define PLUGINDIR "plugins/networksettings2" |
11 | #define ICONDIR "/pics/networksettings2/" | 12 | #define ICONDIR "/pics/networksettings2/" |
12 | 13 | ||
13 | // single resources instance | 14 | // single resources instance |
14 | TheNSResources * _NSResources = 0; | 15 | TheNSResources * _NSResources = 0; |
15 | 16 | ||
16 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), | 17 | TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), |
17 | ConnectionsMap() { | 18 | ConnectionsMap() { |
18 | 19 | ||
19 | _NSResources = this; | 20 | _NSResources = this; |
20 | 21 | ||
21 | // load available netnodes | 22 | // load available netnodes |
22 | findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); | 23 | findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); |
23 | 24 | ||
24 | // compile provides and needs lists | 25 | // compile provides and needs lists |
25 | { const char ** NeedsRun; | 26 | { const char ** NeedsRun; |
26 | QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); | 27 | QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); |
27 | bool Done; | 28 | bool Done; |
28 | 29 | ||
29 | for ( ; OuterIt.current(); ++OuterIt ) { | 30 | for ( ; OuterIt.current(); ++OuterIt ) { |
30 | // find needs list | 31 | // find needs list |
31 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; | 32 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; |
32 | ANetNode::NetNodeList & NNL = *(NNLP); | 33 | ANetNode::NetNodeList & NNL = *(NNLP); |
33 | 34 | ||
34 | // must iterate this way to avoid duplication pointers | 35 | // must iterate this way to avoid duplication pointers |
35 | for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); | 36 | for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); |
36 | InnerIt.current(); ++InnerIt ) { | 37 | InnerIt.current(); ++InnerIt ) { |
37 | if( InnerIt.current() == OuterIt.current() ) | 38 | if( InnerIt.current() == OuterIt.current() ) |
38 | // avoid recursive | 39 | // avoid recursive |
39 | continue; | 40 | continue; |
40 | 41 | ||
41 | const char * Provides = InnerIt.current()->NetNode->provides(); | 42 | const char * Provides = InnerIt.current()->NetNode->provides(); |
42 | NeedsRun = OuterIt.current()->NetNode->needs(); | 43 | NeedsRun = OuterIt.current()->NetNode->needs(); |
43 | for( ; *NeedsRun; NeedsRun ++ ) { | 44 | for( ; *NeedsRun; NeedsRun ++ ) { |
44 | if( strcmp( Provides, *NeedsRun ) == 0 ) { | 45 | if( strcmp( Provides, *NeedsRun ) == 0 ) { |
45 | // inner provides what outer needs | 46 | // inner provides what outer needs |
46 | NNL.resize( NNL.size() + 1 ); | 47 | NNL.resize( NNL.size() + 1 ); |
47 | NNL[NNL.size()-1] = InnerIt.current()->NetNode; | 48 | NNL[NNL.size()-1] = InnerIt.current()->NetNode; |
48 | Done = 1; // break from 2 loops | 49 | Done = 1; // break from 2 loops |
49 | break; | 50 | break; |
50 | } | 51 | } |
51 | } | 52 | } |
52 | } | 53 | } |
53 | OuterIt.current()->NetNode->setAlternatives( NNLP ); | 54 | OuterIt.current()->NetNode->setAlternatives( NNLP ); |
54 | } | 55 | } |
55 | } | 56 | } |
56 | 57 | ||
57 | // define Node types to Description map | 58 | // define Node types to Description map |
58 | NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); | 59 | NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); |
59 | NodeTypeNameMap.insert( "line", tr( "Character device" ) ); | 60 | NodeTypeNameMap.insert( "line", tr( "Character device" ) ); |
60 | NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); | 61 | NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); |
61 | NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); | 62 | NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); |
62 | 63 | ||
63 | NodeTypeDescriptionMap.insert( "device", | 64 | NodeTypeDescriptionMap.insert( "device", |
64 | tr( "<p>Devices that can handle IP packets</p>" ) ); | 65 | tr( "<p>Devices that can handle IP packets</p>" ) ); |
65 | NodeTypeDescriptionMap.insert( "line", | 66 | NodeTypeDescriptionMap.insert( "line", |
66 | tr( "<p>Devices that can handle single bytes</p>" ) ); | 67 | tr( "<p>Devices that can handle single bytes</p>" ) ); |
67 | NodeTypeDescriptionMap.insert( "connection", | 68 | NodeTypeDescriptionMap.insert( "connection", |
68 | tr( "<p>Nodes that provide working IP connections</p>" ) ); | 69 | tr( "<p>Nodes that provide working IP connections</p>" ) ); |
69 | NodeTypeDescriptionMap.insert( "fullsetup", | 70 | NodeTypeDescriptionMap.insert( "fullsetup", |
70 | tr( "<p>Fully configured connection profile</p>" ) ); | 71 | tr( "<p>Fully configured connection profile</p>" ) ); |
71 | 72 | ||
72 | // define system files | 73 | // define system files |
73 | addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); | 74 | addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); |
74 | 75 | ||
75 | // get access to the system | 76 | // get access to the system |
76 | TheSystem = new System(); | 77 | TheSystem = new System(); |
77 | } | 78 | } |
78 | 79 | ||
79 | TheNSResources::~TheNSResources( void ) { | 80 | TheNSResources::~TheNSResources( void ) { |
80 | delete TheSystem; | 81 | delete TheSystem; |
81 | } | 82 | } |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * Load all modules that are found in the path | 85 | * Load all modules that are found in the path |
85 | * @param path a directory that is scaned for any plugins that can be loaded | 86 | * @param path a directory that is scaned for any plugins that can be loaded |
86 | * and attempts to load them | 87 | * and attempts to load them |
87 | */ | 88 | */ |
88 | void TheNSResources::findAvailableNetNodes(const QString &path){ | 89 | void TheNSResources::findAvailableNetNodes(const QString &path){ |
89 | 90 | ||
90 | QDir d(path); | 91 | QDir d(path); |
91 | if(!d.exists()) | 92 | if(!d.exists()) |
92 | return; | 93 | return; |
93 | 94 | ||
94 | QString lang = ::getenv("LANG"); | 95 | QString lang = ::getenv("LANG"); |
95 | 96 | ||
96 | // Don't want sym links | 97 | // Don't want sym links |
97 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 98 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
98 | const QFileInfoList *list = d.entryInfoList(); | 99 | const QFileInfoList *list = d.entryInfoList(); |
99 | QFileInfoListIterator it( *list ); | 100 | QFileInfoListIterator it( *list ); |
100 | QFileInfo *fi; | 101 | QFileInfo *fi; |
101 | 102 | ||
102 | while ( (fi=it.current()) ) { | 103 | while ( (fi=it.current()) ) { |
103 | 104 | ||
104 | if( fi->fileName().contains(".so")){ | 105 | if( fi->fileName().contains(".so")){ |
105 | /* if loaded install translation */ | 106 | /* if loaded install translation */ |
106 | if( loadNetNode(path + "/" + fi->fileName()) ) { | 107 | if( loadNetNode(path + "/" + fi->fileName()) ) { |
107 | QTranslator *trans = new QTranslator(qApp); | 108 | QTranslator *trans = new QTranslator(qApp); |
108 | QString fn = QPEApplication::qpeDir()+ | 109 | QString fn = QPEApplication::qpeDir()+ |
109 | "/i18n/"+lang+"/"+ | 110 | "/i18n/"+lang+"/"+ |
110 | fi->fileName().left( fi->fileName().find(".") )+ | 111 | fi->fileName().left( fi->fileName().find(".") )+ |
111 | ".qm"; | 112 | ".qm"; |
112 | 113 | ||
113 | if( trans->load( fn ) ) | 114 | if( trans->load( fn ) ) |
114 | qApp->installTranslator( trans ); | 115 | qApp->installTranslator( trans ); |
115 | else | 116 | else |
116 | delete trans; | 117 | delete trans; |
117 | } | 118 | } |
118 | } | 119 | } |
119 | ++it; | 120 | ++it; |
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
123 | /** | 124 | /** |
124 | * Attempt to load a function and resolve a function. | 125 | * Attempt to load a function and resolve a function. |
125 | * @param pluginFileName - the name of the file in which to attempt to load | 126 | * @param pluginFileName - the name of the file in which to attempt to load |
126 | * @param resolveString - function pointer to resolve | 127 | * @param resolveString - function pointer to resolve |
127 | * @return true of loading is successful | 128 | * @return true of loading is successful |
128 | */ | 129 | */ |
129 | bool TheNSResources::loadNetNode( | 130 | bool TheNSResources::loadNetNode( |
130 | const QString &pluginFileName, const QString &resolveString){ | 131 | const QString &pluginFileName, const QString &resolveString){ |
131 | 132 | ||
132 | QLibrary *lib = new QLibrary(pluginFileName); | 133 | QLibrary *lib = new QLibrary(pluginFileName); |
133 | void * res = lib->resolve(resolveString); | 134 | void * res = lib->resolve(resolveString); |
134 | if( ! res ){ | 135 | if( ! res ){ |
135 | #ifdef DEBUG | ||
136 | qDebug("loadNetNode: Warning: %s is not a plugin", pluginFileName.latin1()); | ||
137 | #endif | ||
138 | delete lib; | 136 | delete lib; |
139 | return 0; | 137 | return 0; |
140 | } | 138 | } |
141 | 139 | ||
142 | GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; | 140 | GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; |
143 | 141 | ||
144 | // Try to get an object. | 142 | // Try to get an object. |
145 | QList<ANetNode> PNN; | 143 | QList<ANetNode> PNN; |
146 | 144 | ||
147 | getNetNodeList( PNN ); | 145 | getNetNodeList( PNN ); |
148 | if( PNN.isEmpty() ) { | 146 | if( PNN.isEmpty() ) { |
149 | #ifdef DEBUG | ||
150 | qDebug("loadNetNode: Couldn't get node list, but did load library!"); | ||
151 | #endif | ||
152 | delete lib; | 147 | delete lib; |
153 | return 0; | 148 | return 0; |
154 | } | 149 | } |
155 | 150 | ||
156 | ANetNode * NNP; | 151 | ANetNode * NNP; |
157 | for( QListIterator<ANetNode> it(PNN); | 152 | for( QListIterator<ANetNode> it(PNN); |
158 | it.current(); | 153 | it.current(); |
159 | ++it ) { | 154 | ++it ) { |
160 | NetNode_t * NN; | 155 | NetNode_t * NN; |
161 | 156 | ||
162 | NNP = it.current(); | 157 | NNP = it.current(); |
163 | NN = new NetNode_t; | 158 | NN = new NetNode_t; |
164 | NN->NetNode = NNP; | 159 | NN->NetNode = NNP; |
165 | NN->TheLibrary = lib; | 160 | NN->TheLibrary = lib; |
166 | NN->NodeCountInLib = PNN.count(); | 161 | NN->NodeCountInLib = PNN.count(); |
167 | 162 | ||
168 | // store mapping | 163 | // store mapping |
169 | AllNodeTypes.insert( NN->NetNode->nodeName(), NN ); | 164 | AllNodeTypes.insert( NN->NetNode->nodeName(), NN ); |
170 | } | 165 | } |
171 | 166 | ||
172 | return 1; | 167 | return 1; |
173 | } | 168 | } |
174 | 169 | ||
175 | QPixmap TheNSResources::getPixmap( const QString & QS ) { | 170 | QPixmap TheNSResources::getPixmap( const QString & QS ) { |
176 | return Resource::loadPixmap( QString("networksettings2")+QS ); | 171 | return Resource::loadPixmap( QString("networksettings2")+QS ); |
177 | } | 172 | } |
178 | 173 | ||
179 | QString TheNSResources::tr( const char * s ) { | 174 | QString TheNSResources::tr( const char * s ) { |
180 | return qApp->translate( "resource", s ); | 175 | return qApp->translate( "resource", s ); |
181 | } | 176 | } |
182 | 177 | ||
183 | const QString & TheNSResources::netNode2Name( const char * s ) { | 178 | const QString & TheNSResources::netNode2Name( const char * s ) { |
184 | return NodeTypeNameMap[s]; | 179 | return NodeTypeNameMap[s]; |
185 | } | 180 | } |
186 | 181 | ||
187 | const QString & TheNSResources::netNode2Description( const char * s ) { | 182 | const QString & TheNSResources::netNode2Description( const char * s ) { |
188 | return NodeTypeDescriptionMap[s]; | 183 | return NodeTypeDescriptionMap[s]; |
189 | } | 184 | } |
190 | 185 | ||
191 | void TheNSResources::addConnection( NodeCollection * NC ) { | 186 | void TheNSResources::addConnection( NodeCollection * NC ) { |
192 | ANetNodeInstance * NNI; | 187 | ANetNodeInstance * NNI; |
193 | ConnectionsMap.insert( NC->name(), NC ); | 188 | ConnectionsMap.insert( NC->name(), NC ); |
194 | // add (new) nodes to NodeList | 189 | // add (new) nodes to NodeList |
195 | for( QListIterator<ANetNodeInstance> it(*NC); | 190 | for( QListIterator<ANetNodeInstance> it(*NC); |
196 | it.current(); | 191 | it.current(); |
197 | ++it ) { | 192 | ++it ) { |
198 | NNI = it.current(); | 193 | NNI = it.current(); |
199 | if( findNodeInstance( NNI->nodeName() ) == 0 ) { | 194 | if( findNodeInstance( NNI->nodeName() ) == 0 ) { |
200 | // new item | 195 | // new item |
201 | addNodeInstance( NNI ); | 196 | addNodeInstance( NNI ); |
202 | } | 197 | } |
203 | } | 198 | } |
204 | } | 199 | } |
205 | 200 | ||
206 | void TheNSResources::removeConnection( const QString & N ) { | 201 | void TheNSResources::removeConnection( const QString & N ) { |
207 | NodeCollection * NC = findConnection( N ); | 202 | NodeCollection * NC = findConnection( N ); |
208 | if( ! NC ) | 203 | if( ! NC ) |
209 | return; | 204 | return; |
210 | 205 | ||
211 | // delete netnodes in this connection | 206 | // delete netnodes in this connection |
212 | ANetNodeInstance * NNI; | 207 | ANetNodeInstance * NNI; |
213 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { | 208 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { |
214 | removeNodeInstance( NNI->nodeName() ); | 209 | removeNodeInstance( NNI->nodeName() ); |
215 | } | 210 | } |
216 | ConnectionsMap.remove( N ); | 211 | ConnectionsMap.remove( N ); |
217 | } | 212 | } |
218 | 213 | ||
219 | NodeCollection * TheNSResources::findConnection( const QString & S ) { | 214 | NodeCollection * TheNSResources::findConnection( const QString & S ) { |
220 | return ConnectionsMap[ S ]; | 215 | return ConnectionsMap[ S ]; |
221 | } | 216 | } |
222 | 217 | ||
223 | void TheNSResources::renumberConnections( void ) { | 218 | void TheNSResources::renumberConnections( void ) { |
224 | Name2Connection_t & M = NSResources->connections(); | 219 | Name2Connection_t & M = NSResources->connections(); |
225 | NodeCollection * NC; | 220 | NodeCollection * NC; |
226 | 221 | ||
227 | // for all connections | 222 | // for all connections |
228 | NodeCollection::resetMaxNr(); | 223 | NodeCollection::resetMaxNr(); |
229 | for( QDictIterator<NodeCollection> it(M); | 224 | for( QDictIterator<NodeCollection> it(M); |
230 | it.current(); | 225 | it.current(); |
231 | ++it ) { | 226 | ++it ) { |
232 | NC = it.current(); | 227 | NC = it.current(); |
233 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 228 | NC->setNumber( NC->maxConnectionNumber()+1 ); |
234 | NC->setModified( 1 ); | 229 | NC->setModified( 1 ); |
235 | } | 230 | } |
236 | } | 231 | } |
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index cfa0b7a..4df3ce3 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h | |||
@@ -1,105 +1,110 @@ | |||
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 | typedef QDict<NetNode_t> Name2NetNode_t; | 25 | typedef QDict<NetNode_t> Name2NetNode_t; |
26 | typedef QDict<ANetNodeInstance > Name2Instance_t; | 26 | typedef QDict<ANetNodeInstance > Name2Instance_t; |
27 | typedef QDict<NodeCollection> Name2Connection_t; | 27 | typedef QDict<NodeCollection> Name2Connection_t; |
28 | typedef QDict<SystemFile> Name2SystemFile_t; | 28 | typedef QDict<SystemFile> Name2SystemFile_t; |
29 | 29 | ||
30 | class TheNSResources { | 30 | class TheNSResources { |
31 | 31 | ||
32 | public : | 32 | public : |
33 | 33 | ||
34 | TheNSResources( void ); | 34 | TheNSResources( void ); |
35 | ~TheNSResources( ); | 35 | ~TheNSResources( ); |
36 | 36 | ||
37 | System & system() | 37 | System & system() |
38 | { return *TheSystem; } | 38 | { return *TheSystem; } |
39 | 39 | ||
40 | QPixmap getPixmap( const QString & Name ); | 40 | QPixmap getPixmap( const QString & Name ); |
41 | 41 | ||
42 | Name2NetNode_t & netNodes( void ) | 42 | Name2NetNode_t & netNodes( void ) |
43 | { return AllNodeTypes; } | 43 | { return AllNodeTypes; } |
44 | bool netNodeExists( const QString & X ) | 44 | bool netNodeExists( const QString & X ) |
45 | { return AllNodeTypes.find(X)!=0; } | 45 | { return AllNodeTypes.find(X)!=0; } |
46 | 46 | ||
47 | Name2SystemFile_t & systemFiles( void ) | 47 | Name2SystemFile_t & systemFiles( void ) |
48 | { return SystemFiles; } | 48 | { return SystemFiles; } |
49 | void addSystemFile( SystemFile * SF ) | 49 | void addSystemFile( SystemFile * SF ) |
50 | { SystemFiles.insert( SF->name(), SF ); } | 50 | { SystemFiles.insert( SF->name(), SF ); } |
51 | 51 | ||
52 | ANetNodeInstance * createNodeInstance( const QString & S ) | 52 | ANetNodeInstance * createNodeInstance( const QString & S ) |
53 | { ANetNodeInstance * NNI = 0; | 53 | { ANetNodeInstance * NNI = 0; |
54 | NetNode_t * NNT = AllNodeTypes[S]; | 54 | NetNode_t * NNT = AllNodeTypes[S]; |
55 | if( NNT ) { | 55 | ANetNode * NN; |
56 | NNI = NNT->NetNode->createInstance(); | 56 | if( ! NNT ) { |
57 | NNI->initialize(); | 57 | NN = FakeNode = |
58 | ( FakeNode ) ? FakeNode : new FakeNetNode(); | ||
59 | } else { | ||
60 | NN = NNT->NetNode; | ||
58 | } | 61 | } |
62 | NNI = NN->createInstance(); | ||
63 | NNI->initialize(); | ||
59 | return NNI; | 64 | return NNI; |
60 | } | 65 | } |
61 | 66 | ||
62 | Name2Instance_t & netNodeInstances( void ) | 67 | Name2Instance_t & netNodeInstances( void ) |
63 | { return AllNodes; } | 68 | { return AllNodes; } |
64 | void addNodeInstance( ANetNodeInstance * I ) | 69 | void addNodeInstance( ANetNodeInstance * I ) |
65 | { AllNodes.insert( I->nodeName(), I ); } | 70 | { AllNodes.insert( I->nodeName(), I ); } |
66 | void removeNodeInstance( const QString & N ) | 71 | void removeNodeInstance( const QString & N ) |
67 | { AllNodes.remove( N );} | 72 | { AllNodes.remove( N );} |
68 | ANetNodeInstance * findNodeInstance( const QString & S ) | 73 | ANetNodeInstance * findNodeInstance( const QString & S ) |
69 | { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } | 74 | { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } |
70 | 75 | ||
71 | const QString & netNode2Name( const char * Type ); | 76 | const QString & netNode2Name( const char * Type ); |
72 | const QString & netNode2Description( const char * Type ); | 77 | const QString & netNode2Description( const char * Type ); |
73 | 78 | ||
74 | void renumberConnections( void ); | 79 | void renumberConnections( void ); |
75 | void addConnection( NodeCollection * NC ); | 80 | void addConnection( NodeCollection * NC ); |
76 | void removeConnection( const QString & N ); | 81 | void removeConnection( const QString & N ); |
77 | NodeCollection * findConnection( const QString & N ); | 82 | NodeCollection * findConnection( const QString & N ); |
78 | Name2Connection_t & connections( void ) | 83 | Name2Connection_t & connections( void ) |
79 | { return ConnectionsMap; } | 84 | { return ConnectionsMap; } |
80 | 85 | ||
81 | private : | 86 | private : |
82 | 87 | ||
83 | QString tr( const char * path ); | 88 | QString tr( const char * path ); |
84 | void findAvailableNetNodes( const QString &path ); | 89 | void findAvailableNetNodes( const QString &path ); |
85 | bool loadNetNode( | 90 | bool loadNetNode( |
86 | const QString &pluginFileName, | 91 | const QString &pluginFileName, |
87 | const QString &resolveString = "create_plugin"); | 92 | const QString &resolveString = "create_plugin"); |
88 | 93 | ||
89 | QMap< QString, QString> NodeTypeNameMap; | 94 | QMap< QString, QString> NodeTypeNameMap; |
90 | QMap< QString, QString> NodeTypeDescriptionMap; | 95 | QMap< QString, QString> NodeTypeDescriptionMap; |
91 | Name2Connection_t ConnectionsMap; | 96 | Name2Connection_t ConnectionsMap; |
92 | System * TheSystem; | 97 | System * TheSystem; |
93 | Name2SystemFile_t SystemFiles; | 98 | Name2SystemFile_t SystemFiles; |
94 | 99 | ||
95 | // all node type classes | 100 | // all node type classes |
96 | Name2NetNode_t AllNodeTypes; | 101 | Name2NetNode_t AllNodeTypes; |
97 | 102 | ||
98 | // all nodes | 103 | // all nodes |
99 | Name2Instance_t AllNodes; | 104 | Name2Instance_t AllNodes; |
100 | }; | 105 | }; |
101 | 106 | ||
102 | extern TheNSResources * _NSResources; | 107 | extern TheNSResources * _NSResources; |
103 | #define NSResources _NSResources | 108 | #define NSResources _NSResources |
104 | 109 | ||
105 | #endif | 110 | #endif |
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp new file mode 100644 index 0000000..9b2ad3a --- a/dev/null +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -0,0 +1,438 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <qpe/qpeapplication.h> | ||
3 | #include <qtextstream.h> | ||
4 | #include <qdir.h> | ||
5 | #include <qfile.h> | ||
6 | #include <qfileinfo.h> | ||
7 | |||
8 | #include "nsdata.h" | ||
9 | #include <asdevice.h> | ||
10 | #include <resources.h> | ||
11 | |||
12 | static QString CfgFile; | ||
13 | |||
14 | NetworkSettingsData::NetworkSettingsData( void ) { | ||
15 | // init global resources structure | ||
16 | new TheNSResources(); | ||
17 | |||
18 | CfgFile.sprintf( "%s/NETCONFIG", getenv("HOME") ); | ||
19 | |||
20 | // load settings | ||
21 | Force = 0; | ||
22 | loadSettings(); | ||
23 | } | ||
24 | |||
25 | // saving is done by caller | ||
26 | NetworkSettingsData::~NetworkSettingsData( void ) { | ||
27 | delete NSResources; | ||
28 | } | ||
29 | |||
30 | void NetworkSettingsData::loadSettings( void ) { | ||
31 | QString S; | ||
32 | ANetNodeInstance* NNI; | ||
33 | QString Attr, Value; | ||
34 | long idx; | ||
35 | |||
36 | QFile F( CfgFile ); | ||
37 | QTextStream TS( &F ); | ||
38 | |||
39 | do { | ||
40 | |||
41 | if( ! F.open(IO_ReadOnly) ) | ||
42 | break; | ||
43 | |||
44 | /* load the file -> | ||
45 | |||
46 | FORMAT : | ||
47 | |||
48 | [NETNODETYPE] | ||
49 | Entries ... | ||
50 | <EMPTYLINE> | ||
51 | [connection] | ||
52 | Name=Name | ||
53 | Node=Name | ||
54 | <EMPTYLINE> | ||
55 | */ | ||
56 | while( ! TS.atEnd() ) { | ||
57 | S = TS.readLine(); | ||
58 | |||
59 | if ( S.isEmpty() || S[0] != '[' ) | ||
60 | continue; | ||
61 | |||
62 | S = S.mid( 1, S.length()-2 ); | ||
63 | |||
64 | if( ! NSResources ) { | ||
65 | continue; | ||
66 | } | ||
67 | |||
68 | if( S == "connection" ) { | ||
69 | // load connections -> collections of nodes | ||
70 | NodeCollection * NC = new NodeCollection( TS ); | ||
71 | NSResources->addConnection( NC ); | ||
72 | } else { | ||
73 | // load nodes | ||
74 | NNI = NSResources->createNodeInstance( S ); | ||
75 | if( ! NNI ) { | ||
76 | printf( "SKIPPING %s\n", S.latin1() ); | ||
77 | } | ||
78 | |||
79 | do { | ||
80 | S = TS.readLine(); | ||
81 | if( S.isEmpty() ) { | ||
82 | // empty line | ||
83 | break; | ||
84 | } | ||
85 | // node found ? | ||
86 | if( NNI ) { | ||
87 | idx = S.find( '=' ); | ||
88 | if( idx > 0 ) { | ||
89 | Attr = S.left( idx ); | ||
90 | Value = S.mid( idx+1, S.length() ); | ||
91 | } else { | ||
92 | Value=""; | ||
93 | Attr = S; | ||
94 | } | ||
95 | |||
96 | Value.stripWhiteSpace(); | ||
97 | Attr.stripWhiteSpace(); | ||
98 | Attr.lower(); | ||
99 | // dequote Attr | ||
100 | Value = deQuote(Value); | ||
101 | |||
102 | // set the attribute | ||
103 | NNI->setAttribute( Attr, Value ); | ||
104 | } | ||
105 | |||
106 | } while( 1 ); | ||
107 | if( NNI ) { | ||
108 | // loading from file -> exists | ||
109 | NNI->setNew( FALSE ); | ||
110 | NSResources->addNodeInstance( NNI ); | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | |||
115 | } while( 0 ); | ||
116 | |||
117 | } | ||
118 | |||
119 | QString NetworkSettingsData::saveSettings( void ) { | ||
120 | QString ErrS = ""; | ||
121 | |||
122 | if( ! isModified() ) | ||
123 | return ErrS; | ||
124 | |||
125 | QString S; | ||
126 | QFile F( CfgFile + ".bup" ); | ||
127 | |||
128 | printf( "Saving settings to %s\n", CfgFile.latin1() ); | ||
129 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { | ||
130 | ErrS = qApp->translate( "NetworkSettings", | ||
131 | "<p>Could not save setup to %1 !</p>" ). | ||
132 | arg(CfgFile); | ||
133 | // problem | ||
134 | return ErrS; | ||
135 | } | ||
136 | |||
137 | QTextStream TS( &F ); | ||
138 | { Name2Connection_t & M = NSResources->connections(); | ||
139 | ANetNodeInstance * NNI; | ||
140 | |||
141 | // for all connections | ||
142 | for( QDictIterator<NodeCollection> it(M); | ||
143 | it.current(); | ||
144 | ++it ) { | ||
145 | // all nodes in those connections | ||
146 | for( QListIterator<ANetNodeInstance> nit(*(it.current())); | ||
147 | nit.current(); | ||
148 | ++nit ) { | ||
149 | // header | ||
150 | NNI = nit.current(); | ||
151 | TS << '[' <<NNI->netNode()->nodeName() << ']' << endl; | ||
152 | NNI->saveAttributes( TS ); | ||
153 | TS << endl; | ||
154 | } | ||
155 | |||
156 | TS << "[connection]" << endl; | ||
157 | it.current()->save(TS); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | QDir D("."); | ||
162 | D.rename( CfgFile + ".bup", CfgFile ); | ||
163 | |||
164 | // | ||
165 | // proper files AND system files regenerated | ||
166 | // | ||
167 | |||
168 | setModified( 0 ); | ||
169 | return ErrS; | ||
170 | } | ||
171 | |||
172 | QString NetworkSettingsData::generateSettings( bool ForceReq ) { | ||
173 | bool ForceIt; | ||
174 | QString S = ""; | ||
175 | |||
176 | // include own force flag | ||
177 | ForceIt = (Force) ? 1 : ForceReq; | ||
178 | |||
179 | if( ! ForceIt && ! isModified() ) | ||
180 | return S; | ||
181 | |||
182 | // regenerate system files | ||
183 | printf( "Generating settings from %s\n", CfgFile.latin1() ); | ||
184 | |||
185 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); | ||
186 | Name2Connection_t & M = NSResources->connections(); | ||
187 | NodeCollection * NC; | ||
188 | ANetNodeInstance * NNI; | ||
189 | SystemFile * SF; | ||
190 | bool needToRegenerate = ForceIt; | ||
191 | |||
192 | // | ||
193 | // check if we need to generate at least one of the system files | ||
194 | // | ||
195 | if( ! ForceIt ) { | ||
196 | for( QDictIterator<SystemFile> sfit(SFM); | ||
197 | sfit.current(); | ||
198 | ++sfit ) { | ||
199 | SF = sfit.current(); | ||
200 | |||
201 | // check if there are nodes that are modified and require | ||
202 | // data for this system file | ||
203 | |||
204 | // for all connections | ||
205 | for( QDictIterator<NodeCollection> ncit(M); | ||
206 | ncit.current(); | ||
207 | ++ncit ) { | ||
208 | NC = ncit.current(); | ||
209 | |||
210 | if( NC->isModified() ) { | ||
211 | // does this connection 'touch' this system file ? | ||
212 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
213 | cncit.current(); | ||
214 | ++cncit ) { | ||
215 | NNI = cncit.current(); | ||
216 | if( NNI->netNode()->hasDataFor( SF->name() ) && | ||
217 | NNI->isModified() ) { | ||
218 | needToRegenerate = 1; | ||
219 | break; | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | if( needToRegenerate ) | ||
224 | break; | ||
225 | } | ||
226 | if( needToRegenerate ) | ||
227 | break; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | // we cannot renumber with a FORCE request since | ||
232 | // we probably are NOT going to save the config | ||
233 | // e.g. when using --regen option | ||
234 | if( ! ForceReq && needToRegenerate ) { | ||
235 | NSResources->renumberConnections(); | ||
236 | setModified(1); | ||
237 | } | ||
238 | |||
239 | // | ||
240 | // generate files proper to each netnodeinstance | ||
241 | // | ||
242 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); | ||
243 | ANetNodeInstance * NNI; | ||
244 | |||
245 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | ||
246 | NNIIt.current(); | ||
247 | ++NNIIt | ||
248 | ){ | ||
249 | // for all nodes find those that are modified | ||
250 | NNI = NNIIt.current(); | ||
251 | |||
252 | if( ForceIt || NNI->isModified() ) { | ||
253 | if( ! NNI->netNode()->generateProperFilesFor( NNI ) ) { | ||
254 | // problem generating | ||
255 | S = qApp->translate( "NetworkSettings", | ||
256 | "<p>Cannot generate files proper to %1</p>" ). | ||
257 | arg(NNI->netNode()->nodeName()) ; | ||
258 | return S; | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | } | ||
263 | |||
264 | // | ||
265 | // generate system files | ||
266 | // | ||
267 | for( QDictIterator<SystemFile> sfit(SFM); | ||
268 | sfit.current(); | ||
269 | ++sfit ) { | ||
270 | SF = sfit.current(); | ||
271 | |||
272 | // | ||
273 | // regenerate current file | ||
274 | // | ||
275 | printf( "Generating %s\n", SF->name().latin1() ); | ||
276 | SF->open(); | ||
277 | |||
278 | do { // so we can break; | ||
279 | |||
280 | if( SF->preSection() ) { | ||
281 | S = qApp->translate( "NetworkSettings", | ||
282 | "<p>Error in preSection for file %1</p>" ). | ||
283 | arg( SF->name() ); | ||
284 | return S; | ||
285 | } | ||
286 | |||
287 | for( QDictIterator<NodeCollection> ncit(M); | ||
288 | ncit.current(); | ||
289 | ++ncit ) { | ||
290 | NC = ncit.current(); | ||
291 | |||
292 | // get the netnode that serves as the device for this | ||
293 | // connection | ||
294 | AsDevice * Dev = NC->device(); | ||
295 | |||
296 | // generate 'entry' for every possible device this profile handles | ||
297 | |||
298 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
299 | cncit.current(); | ||
300 | ++cncit ) { | ||
301 | NNI = cncit.current(); | ||
302 | for( int i = 0; i < Dev->count(); i ++ ) { | ||
303 | if( NNI->netNode()->hasDataFor( SF->name() ) ) { | ||
304 | if( SF->preNodeSection( NNI, i ) ) { | ||
305 | S = qApp->translate( "NetworkSettings", | ||
306 | "<p>Error in preNodeSection for file %1 and node %2</p>" ). | ||
307 | arg( SF->name() ). | ||
308 | arg( NNI->netNode()->nodeName() ); | ||
309 | return S; | ||
310 | } | ||
311 | |||
312 | if( NNI->netNode()->generateDataForCommonFile(*SF,i,NNI) ) { | ||
313 | S = qApp->translate( "NetworkSettings", | ||
314 | "<p>Error in node part for file %1 and node %2</p>" ). | ||
315 | arg( SF->name() ). | ||
316 | arg( NNI->netNode()->nodeName() ); | ||
317 | return S; | ||
318 | } | ||
319 | |||
320 | if( SF->postNodeSection( NNI, i ) ) { | ||
321 | S = qApp->translate( "NetworkSettings", | ||
322 | "<p>Error in postNodeSection for file %1 and node %2</p>" ). | ||
323 | arg( SF->name() ). | ||
324 | arg( NNI->netNode()->nodeName() ); | ||
325 | return S; | ||
326 | } | ||
327 | } | ||
328 | } | ||
329 | } | ||
330 | *SF << endl; | ||
331 | } | ||
332 | |||
333 | if( SF->postSection() ) { | ||
334 | S = qApp->translate( "NetworkSettings", | ||
335 | "<p>Error in postSection for file %1</p>" ). | ||
336 | arg( SF->name() ); | ||
337 | return S; | ||
338 | } | ||
339 | } while( 0 ); | ||
340 | SF->close(); | ||
341 | } | ||
342 | } | ||
343 | Force = 0; | ||
344 | return S; | ||
345 | } | ||
346 | |||
347 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { | ||
348 | // collect connections that can work on top of this interface | ||
349 | NodeCollection * NC; | ||
350 | QList<NodeCollection> PossibleConnections; | ||
351 | Name2Connection_t & M = NSResources->connections(); | ||
352 | |||
353 | // for all connections | ||
354 | for( QDictIterator<NodeCollection> it(M); | ||
355 | it.current(); | ||
356 | ++it ) { | ||
357 | NC = it.current(); | ||
358 | // check if this profile handles the requested interface | ||
359 | if( NC->handlesInterface( Interface ) && // if different Intf. | ||
360 | NC->state() != Disabled && // if not enabled | ||
361 | NC->state() != IsUp // if already used | ||
362 | ) { | ||
363 | PossibleConnections.append( NC ); | ||
364 | } | ||
365 | } | ||
366 | return PossibleConnections; | ||
367 | } | ||
368 | |||
369 | |||
370 | /* | ||
371 | Called by the system to see if interface can be brought UP | ||
372 | |||
373 | if allowed, echo Interface-allowed else Interface-disallowed | ||
374 | */ | ||
375 | |||
376 | void NetworkSettingsData::canStart( const char * Interface ) { | ||
377 | // load situation | ||
378 | NodeCollection * NC = 0; | ||
379 | QList<NodeCollection> PossibleConnections; | ||
380 | |||
381 | PossibleConnections = collectPossible( Interface ); | ||
382 | |||
383 | switch( PossibleConnections.count() ) { | ||
384 | case 0 : // no connections | ||
385 | break; | ||
386 | case 1 : // one connection | ||
387 | NC = PossibleConnections.first(); | ||
388 | break; | ||
389 | default : // need to ask user ? | ||
390 | // are we connected to a server | ||
391 | // system( "su %d networksettings2 --prompt %s\n", | ||
392 | // "", Interface ); | ||
393 | break; | ||
394 | } | ||
395 | |||
396 | if( NC ) { | ||
397 | switch( NC->state() ) { | ||
398 | case Unchecked : | ||
399 | case Unknown : | ||
400 | case Unavailable : | ||
401 | case Disabled : | ||
402 | // this profile does not allow interface to be UP | ||
403 | // -> try others | ||
404 | break; | ||
405 | case Off : | ||
406 | // try to UP the device | ||
407 | if( ! NC->setState( Activate ) ) { | ||
408 | // cannot bring device Online -> try other alters | ||
409 | break; | ||
410 | } | ||
411 | // FT | ||
412 | case Available : | ||
413 | case IsUp : // also called for 'ifdown' | ||
414 | // device is ready -> done | ||
415 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); | ||
416 | return; | ||
417 | } | ||
418 | } else { | ||
419 | // if we come here no alternatives are possible | ||
420 | printf( "%s-cnn-disallowed\n", Interface ); | ||
421 | } | ||
422 | } | ||
423 | |||
424 | /* | ||
425 | Called by the system to regenerate config files | ||
426 | */ | ||
427 | |||
428 | bool NetworkSettingsData::regenerate( void ) { | ||
429 | QString S; | ||
430 | // load situation | ||
431 | S = generateSettings( TRUE ); | ||
432 | if( ! S.isEmpty() ) { | ||
433 | fprintf( stdout, "%s\n", S.latin1() ); | ||
434 | return 1; | ||
435 | } | ||
436 | return 0; | ||
437 | } | ||
438 | |||
diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h new file mode 100644 index 0000000..55f8c71 --- a/dev/null +++ b/noncore/settings/networksettings2/nsdata.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #ifndef __NSDATA_H | ||
2 | #define __NSDATA_H | ||
3 | |||
4 | #include "netnode.h" | ||
5 | |||
6 | class NetworkSettingsData { | ||
7 | |||
8 | public : | ||
9 | |||
10 | NetworkSettingsData( void ); | ||
11 | ~NetworkSettingsData( void ); | ||
12 | |||
13 | void loadSettings( void ); | ||
14 | QString saveSettings( void ); | ||
15 | |||
16 | QString generateSettings( bool Force = FALSE ); | ||
17 | |||
18 | bool isModified( void ) | ||
19 | { return IsModified; } | ||
20 | void setModified( bool m ) | ||
21 | { IsModified = m; } | ||
22 | |||
23 | QList<NodeCollection> collectPossible( const char * Interface ); | ||
24 | void canStart( const char * Interface ); | ||
25 | bool regenerate( void ); | ||
26 | |||
27 | void forceGeneration( bool m ) | ||
28 | { Force = m; } | ||
29 | |||
30 | private : | ||
31 | |||
32 | bool IsModified; | ||
33 | bool Force; | ||
34 | |||
35 | }; | ||
36 | |||
37 | #endif | ||