author | wimpie <wimpie> | 2004-04-03 21:33:30 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-04-03 21:33:30 (UTC) |
commit | d82581fff0a7fa02b5c391a5b0bcfbfd1e5a6843 (patch) (unidiff) | |
tree | 32ccf2da6464c498c4c43c750e1391a06a1ad431 | |
parent | 41ba1a87a850785caf94d0b50675281fb6561168 (diff) | |
download | opie-d82581fff0a7fa02b5c391a5b0bcfbfd1e5a6843.zip opie-d82581fff0a7fa02b5c391a5b0bcfbfd1e5a6843.tar.gz opie-d82581fff0a7fa02b5c391a5b0bcfbfd1e5a6843.tar.bz2 |
Factored out non-gui data class
Added support for prompting
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,454 +1,101 @@ | |||
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 ) { |
@@ -724,97 +371,44 @@ void NetworkSettings::SLOT_Connect( void ) { | |||
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 | |||
@@ -247,32 +247,56 @@ QString NodeCollection::stateName( State_t S) { | |||
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,37 +1,38 @@ | |||
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 |
@@ -329,33 +330,111 @@ public : | |||
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,36 +1,37 @@ | |||
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 ) { |
@@ -103,81 +104,75 @@ void TheNSResources::findAvailableNetNodes(const QString &path){ | |||
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 ) { |
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 | |||
@@ -23,68 +23,73 @@ typedef struct NetNode_S { | |||
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; |
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 | ||