summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/resources.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp171
1 files changed, 20 insertions, 151 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
@@ -27,3 +27,3 @@ TheNSResources * _NSResources = 0;
27TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), 27TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
28 ConnectionsMap() { 28 ConnectionsMap(), DanglingConnectionsMap() {
29 29
@@ -35,46 +35,2 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
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;
@@ -121,4 +77,2 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
121 77
122#endif
123
124 // define built in Node types to Description map 78 // define built in Node types to Description map
@@ -142,3 +96,2 @@ TheNSResources::~TheNSResources( void ) {
142 96
143#ifndef MYPLUGINS
144 if( Plugins ) { 97 if( Plugins ) {
@@ -147,3 +100,2 @@ TheNSResources::~TheNSResources( void ) {
147 } 100 }
148#endif
149 delete TheSystem; 101 delete TheSystem;
@@ -181,95 +133,2 @@ void TheNSResources::busy( bool ) {
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 ){
@@ -295,2 +154,3 @@ void TheNSResources::findAvailableNetNodes( void ){
295 OPluginLoader::List allplugins = Plugins->filtered(); 154 OPluginLoader::List allplugins = Plugins->filtered();
155 QString lang = ::getenv("LANG");
296 156
@@ -306,3 +166,3 @@ void TheNSResources::findAvailableNetNodes( void ){
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;
@@ -317,3 +177,3 @@ void TheNSResources::findAvailableNetNodes( void ){
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;
@@ -326,3 +186,3 @@ void TheNSResources::findAvailableNetNodes( void ){
326 ++it ) { 186 ++it ) {
327 AllNodeTypes.insert( it->current()->name(), it->current() ); 187 AllNodeTypes.insert( it.current()->name(), it.current() );
328 } 188 }
@@ -333,3 +193,3 @@ void TheNSResources::findAvailableNetNodes( void ){
333 QString fn = QPEApplication::qpeDir()+ 193 QString fn = QPEApplication::qpeDir()+
334 "/i18n/"+lang+"/"+ it->name() + ".qm"; 194 "/i18n/"+lang+"/"+ (*it).name() + ".qm";
335 195
@@ -343,4 +203,2 @@ void TheNSResources::findAvailableNetNodes( void ){
343 203
344#endif
345
346// used to find unique connection number 204// used to find unique connection number
@@ -389,5 +247,10 @@ const QString & TheNSResources::netNode2Description( const char * s ) {
389 247
390void TheNSResources::addConnection( NodeCollection * NC ) { 248void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) {
391 ANetNodeInstance * NNI; 249 ANetNodeInstance * NNI;
392 ConnectionsMap.insert( NC->name(), NC ); 250 if( Dangling ) {
251 DanglingConnectionsMap.insert( NC->name(), NC );
252 } else {
253 ConnectionsMap.insert( NC->name(), NC );
254 }
255
393 // add (new) nodes to NodeList 256 // add (new) nodes to NodeList
@@ -414,5 +277,11 @@ void TheNSResources::removeConnection( const QString & N ) {
414 } 277 }
415 ConnectionsMap.remove( N ); 278 if( ConnectionsMap.find( 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 ) {