Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/resources.cpp | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 2f17693..8b3b4fe 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp | |||
@@ -36,67 +36,75 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), | |||
36 | for ( ; OuterIt.current(); ++OuterIt ) { | 36 | for ( ; OuterIt.current(); ++OuterIt ) { |
37 | // find needs list | 37 | // find needs list |
38 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; | 38 | ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; |
39 | ANetNode::NetNodeList & NNL = *(NNLP); | 39 | ANetNode::NetNodeList & NNL = *(NNLP); |
40 | 40 | ||
41 | // must iterate this way to avoid duplication pointers | 41 | // must iterate this way to avoid duplication pointers |
42 | for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); | 42 | for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); |
43 | InnerIt.current(); ++InnerIt ) { | 43 | InnerIt.current(); ++InnerIt ) { |
44 | if( InnerIt.current() == OuterIt.current() ) | 44 | if( InnerIt.current() == OuterIt.current() ) |
45 | // avoid recursive | 45 | // avoid recursive |
46 | continue; | 46 | continue; |
47 | 47 | ||
48 | const char * Provides = InnerIt.current()->NetNode->provides(); | 48 | const char ** Provides = InnerIt.current()->NetNode->provides(); |
49 | NeedsRun = OuterIt.current()->NetNode->needs(); | 49 | NeedsRun = OuterIt.current()->NetNode->needs(); |
50 | |||
50 | for( ; *NeedsRun; NeedsRun ++ ) { | 51 | for( ; *NeedsRun; NeedsRun ++ ) { |
51 | if( strcmp( Provides, *NeedsRun ) == 0 ) { | 52 | const char ** PRun; |
53 | PRun = Provides; | ||
54 | for( ; *PRun; PRun ++ ) { | ||
55 | if( strcmp( *PRun, *NeedsRun ) == 0 ) { | ||
52 | // inner provides what outer needs | 56 | // inner provides what outer needs |
53 | NNL.resize( NNL.size() + 1 ); | 57 | NNL.resize( NNL.size() + 1 ); |
54 | NNL[NNL.size()-1] = InnerIt.current()->NetNode; | 58 | NNL[NNL.size()-1] = InnerIt.current()->NetNode; |
55 | Done = 1; // break from 2 loops | 59 | Done = 1; // break from 2 loops |
56 | break; | 60 | break; |
57 | } | 61 | } |
58 | } | 62 | } |
59 | } | 63 | } |
64 | } | ||
60 | OuterIt.current()->NetNode->setAlternatives( NNLP ); | 65 | OuterIt.current()->NetNode->setAlternatives( NNLP ); |
61 | } | 66 | } |
62 | } | 67 | } |
63 | 68 | ||
64 | // define Node types to Description map | 69 | // define built in Node types to Description map |
65 | NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); | 70 | addNodeType( "device", tr( "Network Device" ), |
66 | NodeTypeNameMap.insert( "line", tr( "Character device" ) ); | ||
67 | NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); | ||
68 | NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); | ||
69 | |||
70 | NodeTypeDescriptionMap.insert( "device", | ||
71 | tr( "<p>Devices that can handle IP packets</p>" ) ); | 71 | tr( "<p>Devices that can handle IP packets</p>" ) ); |
72 | NodeTypeDescriptionMap.insert( "line", | 72 | addNodeType( "line", tr( "Character device" ), |
73 | tr( "<p>Devices that can handle single bytes</p>" ) ); | 73 | tr( "<p>Devices that can handle single bytes</p>" ) ); |
74 | NodeTypeDescriptionMap.insert( "connection", | 74 | addNodeType( "connection", tr( "IP Connection" ), |
75 | tr( "<p>Nodes that provide working IP connections</p>" ) ); | 75 | tr( "<p>Nodes that provide working IP connections</p>" ) ); |
76 | NodeTypeDescriptionMap.insert( "fullsetup", | 76 | addNodeType( "fullsetup", tr( "Connection Profile" ), |
77 | tr( "<p>Fully configured connection profile</p>" ) ); | 77 | tr( "<p>Fully configured connection profile</p>" ) ); |
78 | 78 | addNodeType( "GPRS", tr( "Connection to GPRS device" ), | |
79 | // define system files | 79 | tr( "<p>Connection to a GPRS capable device</p>" ) ); |
80 | addSystemFile( "interfaces", "/tmp/interfaces", 1 ); | ||
81 | 80 | ||
82 | // get access to the system | 81 | // get access to the system |
83 | TheSystem = new System(); | 82 | TheSystem = new System(); |
84 | 83 | ||
85 | } | 84 | } |
86 | 85 | ||
87 | TheNSResources::~TheNSResources( void ) { | 86 | TheNSResources::~TheNSResources( void ) { |
88 | delete TheSystem; | 87 | delete TheSystem; |
89 | } | 88 | } |
90 | 89 | ||
90 | void TheNSResources::addNodeType( const QString & ID, | ||
91 | const QString & Name, | ||
92 | const QString & Descr ) { | ||
93 | if( NodeTypeNameMap[ID].isEmpty() ) { | ||
94 | NodeTypeNameMap.insert( ID, Name ); | ||
95 | NodeTypeDescriptionMap.insert( ID, Descr ); | ||
96 | } | ||
97 | } | ||
98 | |||
91 | void TheNSResources::addSystemFile( const QString & ID, | 99 | void TheNSResources::addSystemFile( const QString & ID, |
92 | const QString & P, | 100 | const QString & P, |
93 | bool KDI ) { | 101 | bool KDI ) { |
94 | if( ! SystemFiles.find( ID ) ) { | 102 | if( ! SystemFiles.find( ID ) ) { |
95 | // new system file | 103 | // new system file |
96 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); | 104 | SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); |
97 | } // else existed | 105 | } // else existed |
98 | } | 106 | } |
99 | 107 | ||
100 | void TheNSResources::busy( bool ) { | 108 | void TheNSResources::busy( bool ) { |
101 | /* | 109 | /* |
102 | if( B ) { | 110 | if( B ) { |
@@ -211,26 +219,28 @@ bool TheNSResources::loadNetNode( | |||
211 | 219 | ||
212 | // store mapping | 220 | // store mapping |
213 | AllNodeTypes.insert( NN->NetNode->name(), NN ); | 221 | AllNodeTypes.insert( NN->NetNode->name(), NN ); |
214 | } | 222 | } |
215 | 223 | ||
216 | return 1; | 224 | return 1; |
217 | } | 225 | } |
218 | 226 | ||
219 | QPixmap TheNSResources::getPixmap( const QString & QS ) { | 227 | QPixmap TheNSResources::getPixmap( const QString & QS ) { |
220 | QPixmap P; | 228 | QPixmap P; |
221 | QString S("networksettings2/"); | 229 | QString S("networksettings2/"); |
222 | S += QS; | 230 | S += QS; |
223 | Log(("%s\n", S.latin1() )); | ||
224 | P = Resource::loadPixmap( S ); | 231 | P = Resource::loadPixmap( S ); |
232 | if( P.isNull() ) { | ||
233 | Log(( "Cannot load %s\n", S.latin1() )); | ||
234 | } | ||
225 | return ( P.isNull() ) ? QPixmap() : P; | 235 | return ( P.isNull() ) ? QPixmap() : P; |
226 | } | 236 | } |
227 | 237 | ||
228 | QString TheNSResources::tr( const char * s ) { | 238 | QString TheNSResources::tr( const char * s ) { |
229 | return qApp->translate( "resource", s ); | 239 | return qApp->translate( "resource", s ); |
230 | } | 240 | } |
231 | 241 | ||
232 | const QString & TheNSResources::netNode2Name( const char * s ) { | 242 | const QString & TheNSResources::netNode2Name( const char * s ) { |
233 | return NodeTypeNameMap[s]; | 243 | return NodeTypeNameMap[s]; |
234 | } | 244 | } |
235 | 245 | ||
236 | const QString & TheNSResources::netNode2Description( const char * s ) { | 246 | const QString & TheNSResources::netNode2Description( const char * s ) { |
@@ -260,24 +270,34 @@ void TheNSResources::removeConnection( const QString & N ) { | |||
260 | // delete netnodes in this connection | 270 | // delete netnodes in this connection |
261 | ANetNodeInstance * NNI; | 271 | ANetNodeInstance * NNI; |
262 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { | 272 | for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { |
263 | removeNodeInstance( NNI->name() ); | 273 | removeNodeInstance( NNI->name() ); |
264 | } | 274 | } |
265 | ConnectionsMap.remove( N ); | 275 | ConnectionsMap.remove( N ); |
266 | } | 276 | } |
267 | 277 | ||
268 | NodeCollection * TheNSResources::findConnection( const QString & S ) { | 278 | NodeCollection * TheNSResources::findConnection( const QString & S ) { |
269 | return ConnectionsMap[ S ]; | 279 | return ConnectionsMap[ S ]; |
270 | } | 280 | } |
271 | 281 | ||
282 | NodeCollection * TheNSResources::getConnection( int nr ) { | ||
283 | for( QDictIterator<NodeCollection> it(ConnectionsMap); | ||
284 | it.current(); | ||
285 | ++it ) { | ||
286 | if( it.current()->number() == nr ) { | ||
287 | return it.current(); | ||
288 | } | ||
289 | } | ||
290 | return 0; | ||
291 | } | ||
272 | /* | 292 | /* |
273 | void TheNSResources::renumberConnections( void ) { | 293 | void TheNSResources::renumberConnections( void ) { |
274 | Name2Connection_t & M = NSResources->connections(); | 294 | Name2Connection_t & M = NSResources->connections(); |
275 | NodeCollection * NC; | 295 | NodeCollection * NC; |
276 | 296 | ||
277 | // for all connections | 297 | // for all connections |
278 | NodeCollection::resetMaxNr(); | 298 | NodeCollection::resetMaxNr(); |
279 | for( QDictIterator<NodeCollection> it(M); | 299 | for( QDictIterator<NodeCollection> it(M); |
280 | it.current(); | 300 | it.current(); |
281 | ++it ) { | 301 | ++it ) { |
282 | NC = it.current(); | 302 | NC = it.current(); |
283 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 303 | NC->setNumber( NC->maxConnectionNumber()+1 ); |