summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/resources.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp167
1 files changed, 18 insertions, 149 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp
index 79d41ea..3479abb 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.cpp
+++ b/noncore/settings/networksettings2/networksettings2/resources.cpp
@@ -25,7 +25,7 @@
25TheNSResources * _NSResources = 0; 25TheNSResources * _NSResources = 0;
26 26
27TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), 27TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
28 ConnectionsMap() { 28 ConnectionsMap(), DanglingConnectionsMap() {
29 29
30 _NSResources = this; 30 _NSResources = this;
31 31
@@ -33,50 +33,6 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
33 33
34 // load available netnodes 34 // load available netnodes
35 35
36#ifdef MYPLUGIN
37
38 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR );
39
40 // compile provides and needs lists
41 { const char ** NeedsRun;
42 QDictIterator<NetNode_t> OuterIt( AllNodeTypes );
43 bool Done;
44
45 for ( ; OuterIt.current(); ++OuterIt ) {
46 // find needs list
47 ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList;
48 ANetNode::NetNodeList & NNL = *(NNLP);
49
50 // must iterate this way to avoid duplication pointers
51 for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes );
52 InnerIt.current(); ++InnerIt ) {
53 if( InnerIt.current() == OuterIt.current() )
54 // avoid recursive
55 continue;
56
57 const char ** Provides = InnerIt.current()->NetNode->provides();
58 NeedsRun = OuterIt.current()->NetNode->needs();
59
60 for( ; *NeedsRun; NeedsRun ++ ) {
61 const char ** PRun;
62 PRun = Provides;
63 for( ; *PRun; PRun ++ ) {
64 if( strcmp( *PRun, *NeedsRun ) == 0 ) {
65 // inner provides what outer needs
66 NNL.resize( NNL.size() + 1 );
67 NNL[NNL.size()-1] = InnerIt.current()->NetNode;
68 Done = 1; // break from 2 loops
69 break;
70 }
71 }
72 }
73 }
74 OuterIt.current()->NetNode->setAlternatives( NNLP );
75 }
76 }
77
78#else
79
80 Plugins = 0; 36 Plugins = 0;
81 findAvailableNetNodes(); 37 findAvailableNetNodes();
82 38
@@ -119,8 +75,6 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
119 } 75 }
120 } 76 }
121 77
122#endif
123
124 // define built in Node types to Description map 78 // define built in Node types to Description map
125 addNodeType( "device", tr( "Network Device" ), 79 addNodeType( "device", tr( "Network Device" ),
126 tr( "<p>Devices that can handle IP packets</p>" ) ); 80 tr( "<p>Devices that can handle IP packets</p>" ) );
@@ -140,12 +94,10 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
140 94
141TheNSResources::~TheNSResources( void ) { 95TheNSResources::~TheNSResources( void ) {
142 96
143#ifndef MYPLUGINS
144 if( Plugins ) { 97 if( Plugins ) {
145 delete Plugins; 98 delete Plugins;
146 delete PluginManager; 99 delete PluginManager;
147 } 100 }
148#endif
149 delete TheSystem; 101 delete TheSystem;
150 102
151} 103}
@@ -179,99 +131,6 @@ void TheNSResources::busy( bool ) {
179*/ 131*/
180} 132}
181 133
182#ifdef MYPLUGIN
183/**
184 * Load all modules that are found in the path
185 * @param path a directory that is scaned for any plugins that can be loaded
186 * and attempts to load them
187 */
188void TheNSResources::findAvailableNetNodes(const QString &path){
189
190 Log(("Locate plugins in %s\n", path.latin1() ));
191 QDir d(path);
192 if(!d.exists())
193 return;
194
195 QString lang = ::getenv("LANG");
196
197 // Don't want sym links
198 d.setFilter( QDir::Files | QDir::NoSymLinks );
199 const QFileInfoList *list = d.entryInfoList();
200 QFileInfoListIterator it( *list );
201 QFileInfo *fi;
202
203 while ( (fi=it.current()) ) {
204
205 if( fi->fileName().contains(".so")){
206 /* if loaded install translation */
207 if( loadNetNode(path + "/" + fi->fileName()) ) {
208 Log(( "Loading plugin %s\n", fi->fileName().latin1()));
209 QTranslator *trans = new QTranslator(qApp);
210 QString fn = QPEApplication::qpeDir()+
211 "/i18n/"+lang+"/"+
212 fi->fileName().left( fi->fileName().find(".") )+
213 ".qm";
214
215 if( trans->load( fn ) )
216 qApp->installTranslator( trans );
217 else
218 delete trans;
219 } else {
220 Log(( "Error loading plugin %s\n", fi->fileName().latin1()));
221 }
222 }
223 ++it;
224 }
225}
226
227/**
228 * Attempt to load a function and resolve a function.
229 * @param pluginFileName - the name of the file in which to attempt to load
230 * @param resolveString - function pointer to resolve
231 * @return true of loading is successful
232 */
233bool TheNSResources::loadNetNode(
234 const QString &pluginFileName, const QString &resolveString){
235
236 QLibrary *lib = new QLibrary(pluginFileName);
237 void * res = lib->resolve(resolveString);
238 if( ! res ){
239 delete lib;
240 return 0;
241 }
242
243 GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res;
244
245 // Try to get an object.
246 QList<ANetNode> PNN;
247
248 getNetNodeList( PNN );
249 if( PNN.isEmpty() ) {
250 delete lib;
251 return 0;
252 }
253
254 ANetNode * NNP;
255 for( QListIterator<ANetNode> it(PNN);
256 it.current();
257 ++it ) {
258 NetNode_t * NN;
259
260 NNP = it.current();
261 NN = new NetNode_t;
262 NN->NetNode = NNP;
263 NN->TheLibrary = lib;
264 NN->NodeCountInLib = PNN.count();
265
266 // store mapping
267 AllNodeTypes.insert( NN->NetNode->name(), NN );
268 }
269
270 return 1;
271}
272
273#else
274
275void TheNSResources::findAvailableNetNodes( void ){ 134void TheNSResources::findAvailableNetNodes( void ){
276 135
277 Plugins = new OPluginLoader( "networksettings2" ); 136 Plugins = new OPluginLoader( "networksettings2" );
@@ -293,6 +152,7 @@ void TheNSResources::findAvailableNetNodes( void ){
293 152
294 // Get All Plugins 153 // Get All Plugins
295 OPluginLoader::List allplugins = Plugins->filtered(); 154 OPluginLoader::List allplugins = Plugins->filtered();
155 QString lang = ::getenv("LANG");
296 156
297 for( OPluginLoader::List::Iterator it = allplugins.begin(); 157 for( OPluginLoader::List::Iterator it = allplugins.begin();
298 it != allplugins.end(); 158 it != allplugins.end();
@@ -304,7 +164,7 @@ void TheNSResources::findAvailableNetNodes( void ){
304 164
305 if( ! interface ) { 165 if( ! interface ) {
306 Log(( "Plugin %s from %s does not support proper interface\n", 166 Log(( "Plugin %s from %s does not support proper interface\n",
307 it->name().latin1(), it->path().latin1() )); 167 (*it).name().latin1(), (*it).path().latin1() ));
308 continue; 168 continue;
309 } 169 }
310 170
@@ -315,7 +175,7 @@ void TheNSResources::findAvailableNetNodes( void ){
315 175
316 if( PNN.isEmpty() ) { 176 if( PNN.isEmpty() ) {
317 Log(( "Plugin %s from %s does offer any nodes\n", 177 Log(( "Plugin %s from %s does offer any nodes\n",
318 it->name().latin1(), it->path().latin1() )); 178 (*it).name().latin1(), (*it).path().latin1() ));
319 delete interface; 179 delete interface;
320 continue; 180 continue;
321 } 181 }
@@ -324,14 +184,14 @@ void TheNSResources::findAvailableNetNodes( void ){
324 for( QListIterator<ANetNode> it(PNN); 184 for( QListIterator<ANetNode> it(PNN);
325 it.current(); 185 it.current();
326 ++it ) { 186 ++it ) {
327 AllNodeTypes.insert( it->current()->name(), it->current() ); 187 AllNodeTypes.insert( it.current()->name(), it.current() );
328 } 188 }
329 } 189 }
330 190
331 // load the translation 191 // load the translation
332 QTranslator *trans = new QTranslator(qApp); 192 QTranslator *trans = new QTranslator(qApp);
333 QString fn = QPEApplication::qpeDir()+ 193 QString fn = QPEApplication::qpeDir()+
334 "/i18n/"+lang+"/"+ it->name() + ".qm"; 194 "/i18n/"+lang+"/"+ (*it).name() + ".qm";
335 195
336 if( trans->load( fn ) ) 196 if( trans->load( fn ) )
337 qApp->installTranslator( trans ); 197 qApp->installTranslator( trans );
@@ -341,8 +201,6 @@ void TheNSResources::findAvailableNetNodes( void ){
341 201
342} 202}
343 203
344#endif
345
346// used to find unique connection number 204// used to find unique connection number
347int TheNSResources::assignConnectionNumber( void ) { 205int TheNSResources::assignConnectionNumber( void ) {
348 bool found = 1; 206 bool found = 1;
@@ -387,9 +245,14 @@ const QString & TheNSResources::netNode2Description( const char * s ) {
387 return NodeTypeDescriptionMap[s]; 245 return NodeTypeDescriptionMap[s];
388} 246}
389 247
390void TheNSResources::addConnection( NodeCollection * NC ) { 248void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) {
391 ANetNodeInstance * NNI; 249 ANetNodeInstance * NNI;
250 if( Dangling ) {
251 DanglingConnectionsMap.insert( NC->name(), NC );
252 } else {
392 ConnectionsMap.insert( NC->name(), NC ); 253 ConnectionsMap.insert( NC->name(), NC );
254 }
255
393 // add (new) nodes to NodeList 256 // add (new) nodes to NodeList
394 for( QListIterator<ANetNodeInstance> it(*NC); 257 for( QListIterator<ANetNodeInstance> it(*NC);
395 it.current(); 258 it.current();
@@ -412,9 +275,15 @@ void TheNSResources::removeConnection( const QString & N ) {
412 for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { 275 for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) {
413 removeNodeInstance( NNI->name() ); 276 removeNodeInstance( NNI->name() );
414 } 277 }
278 if( ConnectionsMap.find( N ) ) {
415 ConnectionsMap.remove( N ); 279 ConnectionsMap.remove( N );
280 } else {
281 DanglingConnectionsMap.remove( N );
282 }
283
416} 284}
417 285
286// dangling connections are filtered out
418NodeCollection * TheNSResources::findConnection( const QString & S ) { 287NodeCollection * TheNSResources::findConnection( const QString & S ) {
419 return ConnectionsMap[ S ]; 288 return ConnectionsMap[ S ];
420} 289}