summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/resources.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp179
1 files changed, 158 insertions, 21 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp
index 50fb15a..79d41ea 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.cpp
+++ b/noncore/settings/networksettings2/networksettings2/resources.cpp
@@ -6,5 +6,10 @@
#include <qdir.h>
+#include <qmessagebox.h>
+
#include <qpe/qlibrary.h>
#include <qpe/qpeapplication.h>
+
#include <opie2/odebug.h>
+#include <opie2/opluginloader.h>
+
#include <qtopia/resource.h>
@@ -13,2 +18,3 @@
#include "resources.h"
+#include "netnodeinterface.h"
@@ -28,2 +34,5 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
// load available netnodes
+
+#ifdef MYPLUGIN
+
findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR );
@@ -68,2 +77,48 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
+#else
+
+ Plugins = 0;
+ findAvailableNetNodes();
+
+ // compile provides and needs lists
+ { const char ** NeedsRun;
+ QDictIterator<ANetNode> 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<ANetNode> InnerIt( AllNodeTypes );
+ InnerIt.current(); ++InnerIt ) {
+
+ if( InnerIt.current() == OuterIt.current() )
+ // avoid recursive
+ continue;
+
+ const char ** Provides = InnerIt.current()->provides();
+ NeedsRun = OuterIt.current()->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();
+ Done = 1; // break from 2 loops
+ break;
+ }
+ }
+ }
+ }
+ OuterIt.current()->setAlternatives( NNLP );
+ }
+ }
+
+#endif
+
// define built in Node types to Description map
@@ -86,3 +141,11 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
TheNSResources::~TheNSResources( void ) {
+
+#ifndef MYPLUGINS
+ if( Plugins ) {
+ delete Plugins;
+ delete PluginManager;
+ }
+#endif
delete TheSystem;
+
}
@@ -118,2 +181,3 @@ void TheNSResources::busy( bool ) {
+#ifdef MYPLUGIN
/**
@@ -162,23 +226,2 @@ void TheNSResources::findAvailableNetNodes(const QString &path){
-// 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);
- it.current();
- ++it ) {
- if( it.current()->number() == trial ) {
- found = 0;
- break;
- }
- }
-
- if( found ) {
- Log(("Assign profile number %d\n", trial ));
- return trial;
- }
- }
-}
-
/**
@@ -229,2 +272,96 @@ bool TheNSResources::loadNetNode(
+#else
+
+void TheNSResources::findAvailableNetNodes( void ){
+
+ Plugins = new OPluginLoader( "networksettings2" );
+ Plugins->setAutoDelete( true );
+
+ PluginManager = new OPluginManager( Plugins );
+ PluginManager->load();
+
+ if( Plugins->isInSafeMode() ) {
+ QMessageBox::information(
+ 0,
+ tr( "Today Error"),
+ tr( "<qt>The plugin '%1' caused Today to crash."
+ " It could be that the plugin is not properly"
+ " installed.<br>Today tries to continue loading"
+ " plugins.</qt>" )
+ .arg( PluginManager->crashedPlugin().name()));
+ }
+
+ // Get All Plugins
+ OPluginLoader::List allplugins = Plugins->filtered();
+
+ 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() ));
+ 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() ));
+ delete interface;
+ continue;
+ }
+
+ // merge this node with global node
+ for( QListIterator<ANetNode> it(PNN);
+ it.current();
+ ++it ) {
+ AllNodeTypes.insert( it->current()->name(), it->current() );
+ }
+ }
+
+ // load the translation
+ QTranslator *trans = new QTranslator(qApp);
+ QString fn = QPEApplication::qpeDir()+
+ "/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);
+ it.current();
+ ++it ) {
+ if( it.current()->number() == trial ) {
+ found = 0;
+ break;
+ }
+ }
+
+ if( found ) {
+ Log(("Assign profile number %d\n", trial ));
+ return trial;
+ }
+ }
+}
+
QPixmap TheNSResources::getPixmap( const QString & QS ) {