Diffstat (limited to 'noncore/settings/networksettings2/networksettings2') (more/less context) (ignore whitespace changes)
5 files changed, 116 insertions, 218 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index f8f2d1e..f00e0b3 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -143,9 +143,13 @@ NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { AssignedInterface = 0; + Number = -1; + Done = 0; } -NodeCollection::NodeCollection( QTextStream & TS ) : +NodeCollection::NodeCollection( QTextStream & TS, bool & Dangling ) : QList<ANetNodeInstance>() { long idx; - bool InError = 0; QString S, A, N; + + Number = -1; + Done = 0; IsModified = 0; @@ -157,2 +161,4 @@ NodeCollection::NodeCollection( QTextStream & TS ) : + Dangling = 0; // by default node collection is ok + do { @@ -160,6 +166,2 @@ NodeCollection::NodeCollection( QTextStream & TS ) : if( S.isEmpty() ) { - if( InError ) { - // remove all nodes - clear(); - } // empty line @@ -183,3 +185,3 @@ NodeCollection::NodeCollection( QTextStream & TS ) : Log(( "Find node %s : %p\n", N.latin1(), NNI )); - if( NNI && ! InError ) { + if( NNI ) { append( NNI ); @@ -187,3 +189,7 @@ NodeCollection::NodeCollection( QTextStream & TS ) : // could not find a node type -> collection invalid - InError = 1; + Log(( "Node %s missing -> connection dangling\n", + N.latin1() )); + // create placeholder for this dangling NNI + NNI = new ErrorNNI( N ); + Dangling = 1; } @@ -196,3 +202,2 @@ NodeCollection::NodeCollection( QTextStream & TS ) : - NodeCollection::~NodeCollection( void ) { @@ -231,6 +236,7 @@ ANetNodeInstance * NodeCollection::getToplevel( void ) { NNI = it.current(); - if( NNI->nodeClass()->isToplevel() ) - break; + if( NNI->nodeClass()->isToplevel() ) { + return NNI; + } } - return NNI; + return 0; } @@ -243,6 +249,7 @@ ANetNodeInstance * NodeCollection::findByName( const QString & S ) { NNI = it.current(); - if( NNI->name() == S ) - break; + if( NNI->name() == S ) { + return NNI; + } } - return NNI; + return 0; } diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 4626381..151d546 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -321,2 +321,4 @@ protected : bool IsModified; + // true if this nodeinstance was just created (and not + // loaded from file bool IsNew; @@ -327,2 +329,42 @@ protected : +class ErrorNNI: public ANetNodeInstance { + +public: + + ErrorNNI( const QString & _Name ) : ANetNodeInstance( 0 ) { + setName( _Name.latin1() ); + } + + RuntimeInfo * runtime( void ) { + return 0; + } + + // create edit widget under parent + QWidget * edit( QWidget * parent ) { + return 0; + } + + // is given data acceptable + QString acceptable( void ) { + return QString(); + } + + // get data from GUI and store in node + void commit( void ) { + } + + // returns node specific data -> only useful for 'buddy' + void * data( void ) { + return 0; + } + +protected : + + void setSpecificAttribute( QString & , QString & ) { + } + + void saveSpecificAttribute( QTextStream & ) { + } +}; + class RuntimeInfo : public QObject { @@ -470,3 +512,3 @@ public : NodeCollection( void ); - NodeCollection( QTextStream & TS ); + NodeCollection( QTextStream & TS, bool & Dangling ); ~NodeCollection( void ); @@ -587,5 +629,5 @@ private : // index in listbox - int Index; + int Index; bool IsModified; - int Done; + int Done; diff --git a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h index 34f3bb5..06d1548 100644 --- a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h +++ b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h @@ -80,4 +80,14 @@ struct NS2PrivateFactory<Opie::Core::Typelist<Node, Tail> > { +class NetNodeInterface : public QUnknownInterface { + +public : + + virtual QRESULT queryInterface( const QUuid& uuid, + QUnknownInterface **iface ) = 0; + + virtual void create_plugin( QList<ANetNode> & PNN ) = 0; +}; + template<class Node> -struct NetNodeInterface : public QUnknownInterface { +struct NetNodeInterface_T : public NetNodeInterface { @@ -109,4 +119,4 @@ struct NetNodeInterface : public QUnknownInterface { template<class Node, class Tail> -struct NetNodeInterface<Opie::Core::Typelist<Node, Tail> > - : public QUnknownInterface { +struct NetNodeInterface_T<Opie::Core::Typelist<Node, Tail> > + : public NetNodeInterface { @@ -127,3 +137,3 @@ struct NetNodeInterface<Opie::Core::Typelist<Node, Tail> > void create_plugin( QList<ANetNode> & PNN ) { - NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugin( PNN ); + NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugins( PNN ); } 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; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), - ConnectionsMap() { + ConnectionsMap(), DanglingConnectionsMap() { @@ -35,46 +35,2 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), -#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; @@ -121,4 +77,2 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), -#endif - // define built in Node types to Description map @@ -142,3 +96,2 @@ TheNSResources::~TheNSResources( void ) { -#ifndef MYPLUGINS if( Plugins ) { @@ -147,3 +100,2 @@ TheNSResources::~TheNSResources( void ) { } -#endif delete TheSystem; @@ -181,95 +133,2 @@ void TheNSResources::busy( bool ) { -#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 ){ @@ -295,2 +154,3 @@ void TheNSResources::findAvailableNetNodes( void ){ OPluginLoader::List allplugins = Plugins->filtered(); + QString lang = ::getenv("LANG"); @@ -306,3 +166,3 @@ void TheNSResources::findAvailableNetNodes( void ){ Log(( "Plugin %s from %s does not support proper interface\n", - it->name().latin1(), it->path().latin1() )); + (*it).name().latin1(), (*it).path().latin1() )); continue; @@ -317,3 +177,3 @@ void TheNSResources::findAvailableNetNodes( void ){ Log(( "Plugin %s from %s does offer any nodes\n", - it->name().latin1(), it->path().latin1() )); + (*it).name().latin1(), (*it).path().latin1() )); delete interface; @@ -326,3 +186,3 @@ void TheNSResources::findAvailableNetNodes( void ){ ++it ) { - AllNodeTypes.insert( it->current()->name(), it->current() ); + AllNodeTypes.insert( it.current()->name(), it.current() ); } @@ -333,3 +193,3 @@ void TheNSResources::findAvailableNetNodes( void ){ QString fn = QPEApplication::qpeDir()+ - "/i18n/"+lang+"/"+ it->name() + ".qm"; + "/i18n/"+lang+"/"+ (*it).name() + ".qm"; @@ -343,4 +203,2 @@ void TheNSResources::findAvailableNetNodes( void ){ -#endif - // used to find unique connection number @@ -389,5 +247,10 @@ const QString & TheNSResources::netNode2Description( const char * 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 @@ -414,5 +277,11 @@ void TheNSResources::removeConnection( const QString & N ) { } - 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 ) { diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 421a433..b27cda1 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -40,17 +40,3 @@ public : -#ifdef MYPLUGIN - -typedef struct NetNode_S { - ANetNode * NetNode; - QLibrary * TheLibrary; - long NodeCountInLib; -} NetNode_t; -typedef QDict<NetNode_t> Name2NetNode_t; - -#else - typedef QDict<ANetNode> Name2NetNode_t; - -#endif - typedef QDict<ANetNodeInstance > Name2Instance_t; @@ -79,8 +65,2 @@ public : { return AllNodeTypes.find(X)!=0; } -#ifdef MYPLUGIN - ANetNode * findNetNode( const QString & N ) - { NetNode_t * NNT = AllNodeTypes.find(N); - return (NNT) ? NNT->NetNode : 0; - } -#else ANetNode * findNetNode( const QString & N ) @@ -88,3 +68,2 @@ public : } -#endif // define new plugin (=node) @@ -101,17 +80,11 @@ public : ANetNodeInstance * createNodeInstance( const QString & S ) - { ANetNodeInstance * NNI = 0; - printf( "Find node type %s\n", S.latin1() ); -#ifdef MYPLUGIN - NetNode_t * NNT = AllNodeTypes[S]; - if( ! NNT ) { - return 0; - } - NNI = NNT->NetNode->createInstance(); -#else - ANetNode * NNT = AllNodeTypes[S]; - if( ! NNT ) { + { ANetNode * NN = findNetNode( S ); + + Log(( "Find node type %s : %p\n", S.latin1(), NN )); + + if( NN == 0 ) + // type of this instance not found return 0; - } - NNI = NNT->createInstance(); -#endif + + ANetNodeInstance * NNI = NN->createInstance(); NNI->initialize(); @@ -132,3 +105,3 @@ public : - void addConnection( NodeCollection * NC ); + void addConnection( NodeCollection * NC, bool Dangling ); void removeConnection( const QString & N ); @@ -138,2 +111,4 @@ public : { return ConnectionsMap; } + Name2Connection_t & danglingConnections( void ) + { return ConnectionsMap; } @@ -149,10 +124,3 @@ private : -#ifdef MYPLUGIN - void findAvailableNetNodes( const QString &path ); - bool loadNetNode( - const QString &pluginFileName, - const QString &resolveString = "create_plugin"); -#else void findAvailableNetNodes( void ); -#endif @@ -160,3 +128,7 @@ private : QMap< QString, QString> NodeTypeDescriptionMap; + // list of connections that are valid Name2Connection_t ConnectionsMap; + // list of connection configurations that are not valid + // e.g. because plugins are missing + Name2Connection_t DanglingConnectionsMap; System * TheSystem; @@ -172,6 +144,4 @@ private : -#ifndef MYPLUGIN Opie::Core::OPluginLoader * Plugins; Opie::Core::OPluginManager * PluginManager; -#endif |