Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/resources.cpp | 171 |
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 @@ -22,64 +22,20 @@ #define ICONDIR "/pics/networksettings2/" // single resources instance TheNSResources * _NSResources = 0; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), - ConnectionsMap() { + ConnectionsMap(), DanglingConnectionsMap() { _NSResources = this; detectCurrentUser(); // load available netnodes -#ifdef MYPLUGIN - - findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); - - // compile provides and needs lists - { const char ** NeedsRun; - QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); - bool Done; - - for ( ; OuterIt.current(); ++OuterIt ) { - // find needs list - ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; - ANetNode::NetNodeList & NNL = *(NNLP); - - // must iterate this way to avoid duplication pointers - for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); - InnerIt.current(); ++InnerIt ) { - if( InnerIt.current() == OuterIt.current() ) - // avoid recursive - continue; - - const char ** Provides = InnerIt.current()->NetNode->provides(); - NeedsRun = OuterIt.current()->NetNode->needs(); - - for( ; *NeedsRun; NeedsRun ++ ) { - const char ** PRun; - PRun = Provides; - for( ; *PRun; PRun ++ ) { - if( strcmp( *PRun, *NeedsRun ) == 0 ) { - // inner provides what outer needs - NNL.resize( NNL.size() + 1 ); - NNL[NNL.size()-1] = InnerIt.current()->NetNode; - Done = 1; // break from 2 loops - break; - } - } - } - } - OuterIt.current()->NetNode->setAlternatives( NNLP ); - } - } - -#else - Plugins = 0; findAvailableNetNodes(); // compile provides and needs lists { const char ** NeedsRun; QDictIterator<ANetNode> OuterIt( AllNodeTypes ); @@ -116,14 +72,12 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), } } OuterIt.current()->setAlternatives( NNLP ); } } -#endif - // define built in Node types to Description map addNodeType( "device", tr( "Network Device" ), tr( "<p>Devices that can handle IP packets</p>" ) ); addNodeType( "line", tr( "Character device" ), tr( "<p>Devices that can handle single bytes</p>" ) ); addNodeType( "connection", tr( "IP Connection" ), @@ -137,18 +91,16 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), TheSystem = new System(); } TheNSResources::~TheNSResources( void ) { -#ifndef MYPLUGINS if( Plugins ) { delete Plugins; delete PluginManager; } -#endif delete TheSystem; } void TheNSResources::addNodeType( const QString & ID, const QString & Name, @@ -176,105 +128,12 @@ void TheNSResources::busy( bool ) { } else { ShowWait->hide(); } */ } -#ifdef MYPLUGIN -/** - * Load all modules that are found in the path - * @param path a directory that is scaned for any plugins that can be loaded - * and attempts to load them - */ -void TheNSResources::findAvailableNetNodes(const QString &path){ - - Log(("Locate plugins in %s\n", path.latin1() )); - QDir d(path); - if(!d.exists()) - return; - - QString lang = ::getenv("LANG"); - - // Don't want sym links - d.setFilter( QDir::Files | QDir::NoSymLinks ); - const QFileInfoList *list = d.entryInfoList(); - QFileInfoListIterator it( *list ); - QFileInfo *fi; - - while ( (fi=it.current()) ) { - - if( fi->fileName().contains(".so")){ - /* if loaded install translation */ - if( loadNetNode(path + "/" + fi->fileName()) ) { - Log(( "Loading plugin %s\n", fi->fileName().latin1())); - QTranslator *trans = new QTranslator(qApp); - QString fn = QPEApplication::qpeDir()+ - "/i18n/"+lang+"/"+ - fi->fileName().left( fi->fileName().find(".") )+ - ".qm"; - - if( trans->load( fn ) ) - qApp->installTranslator( trans ); - else - delete trans; - } else { - Log(( "Error loading plugin %s\n", fi->fileName().latin1())); - } - } - ++it; - } -} - -/** - * Attempt to load a function and resolve a function. - * @param pluginFileName - the name of the file in which to attempt to load - * @param resolveString - function pointer to resolve - * @return true of loading is successful - */ -bool TheNSResources::loadNetNode( - const QString &pluginFileName, const QString &resolveString){ - - QLibrary *lib = new QLibrary(pluginFileName); - void * res = lib->resolve(resolveString); - if( ! res ){ - delete lib; - return 0; - } - - GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; - - // Try to get an object. - QList<ANetNode> PNN; - - getNetNodeList( PNN ); - if( PNN.isEmpty() ) { - delete lib; - return 0; - } - - ANetNode * NNP; - for( QListIterator<ANetNode> it(PNN); - it.current(); - ++it ) { - NetNode_t * NN; - - NNP = it.current(); - NN = new NetNode_t; - NN->NetNode = NNP; - NN->TheLibrary = lib; - NN->NodeCountInLib = PNN.count(); - - // store mapping - AllNodeTypes.insert( NN->NetNode->name(), NN ); - } - - return 1; -} - -#else - void TheNSResources::findAvailableNetNodes( void ){ Plugins = new OPluginLoader( "networksettings2" ); Plugins->setAutoDelete( true ); PluginManager = new OPluginManager( Plugins ); @@ -290,62 +149,61 @@ void TheNSResources::findAvailableNetNodes( void ){ " plugins.</qt>" ) .arg( PluginManager->crashedPlugin().name())); } // Get All Plugins OPluginLoader::List allplugins = Plugins->filtered(); + QString lang = ::getenv("LANG"); for( OPluginLoader::List::Iterator it = allplugins.begin(); it != allplugins.end(); ++it ) { // check if this plugin supports the proper interface NetNodeInterface * interface = Plugins->load<NetNodeInterface>( *it, IID_NetworkSettings2 ); if( ! interface ) { Log(( "Plugin %s from %s does not support proper interface\n", - it->name().latin1(), it->path().latin1() )); + (*it).name().latin1(), (*it).path().latin1() )); continue; } // add the nodes in this plugin to the dictionary { QList<ANetNode> PNN; interface->create_plugin( PNN ); if( PNN.isEmpty() ) { Log(( "Plugin %s from %s does offer any nodes\n", - it->name().latin1(), it->path().latin1() )); + (*it).name().latin1(), (*it).path().latin1() )); delete interface; continue; } // merge this node with global node for( QListIterator<ANetNode> it(PNN); it.current(); ++it ) { - AllNodeTypes.insert( it->current()->name(), it->current() ); + AllNodeTypes.insert( it.current()->name(), it.current() ); } } // load the translation QTranslator *trans = new QTranslator(qApp); QString fn = QPEApplication::qpeDir()+ - "/i18n/"+lang+"/"+ it->name() + ".qm"; + "/i18n/"+lang+"/"+ (*it).name() + ".qm"; if( trans->load( fn ) ) qApp->installTranslator( trans ); else delete trans; } } -#endif - // used to find unique connection number int TheNSResources::assignConnectionNumber( void ) { bool found = 1; for( int trial = 0; ; trial ++ ) { found = 1; for( QDictIterator<NodeCollection> it(ConnectionsMap); @@ -384,15 +242,20 @@ const QString & TheNSResources::netNode2Name( const char * s ) { } const QString & TheNSResources::netNode2Description( const char * s ) { return NodeTypeDescriptionMap[s]; } -void TheNSResources::addConnection( NodeCollection * NC ) { +void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) { ANetNodeInstance * NNI; - ConnectionsMap.insert( NC->name(), NC ); + if( Dangling ) { + DanglingConnectionsMap.insert( NC->name(), NC ); + } else { + ConnectionsMap.insert( NC->name(), NC ); + } + // add (new) nodes to NodeList for( QListIterator<ANetNodeInstance> it(*NC); it.current(); ++it ) { NNI = it.current(); if( findNodeInstance( NNI->name() ) == 0 ) { @@ -409,15 +272,21 @@ void TheNSResources::removeConnection( const QString & N ) { // delete netnodes in this connection ANetNodeInstance * NNI; for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { removeNodeInstance( NNI->name() ); } - ConnectionsMap.remove( N ); + if( ConnectionsMap.find( N ) ) { + ConnectionsMap.remove( N ); + } else { + DanglingConnectionsMap.remove( N ); + } + } +// dangling connections are filtered out NodeCollection * TheNSResources::findConnection( const QString & S ) { return ConnectionsMap[ S ]; } NodeCollection * TheNSResources::getConnection( int nr ) { for( QDictIterator<NodeCollection> it(ConnectionsMap); |