summaryrefslogtreecommitdiff
authorwimpie <wimpie>2005-01-04 04:13:29 (UTC)
committer wimpie <wimpie>2005-01-04 04:13:29 (UTC)
commit12e7c838d741d37c7a526e21ac43562ec5b64c6e (patch) (side-by-side diff)
tree3fe816a5dd68bc11a73dbb4b4144a41323041f21
parenta268c0ab03aed309a1a8f65350ef894c81142785 (diff)
downloadopie-12e7c838d741d37c7a526e21ac43562ec5b64c6e.zip
opie-12e7c838d741d37c7a526e21ac43562ec5b64c6e.tar.gz
opie-12e7c838d741d37c7a526e21ac43562ec5b64c6e.tar.bz2
Some more logging
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.cpp5
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp3
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.h3
3 files changed, 8 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp
index 17653bd..f8f2d1e 100644
--- a/noncore/settings/networksettings2/networksettings2/netnode.cpp
+++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp
@@ -87,203 +87,204 @@ bool ANetNode::isToplevel( void ) {
}
return 0;
}
bool ANetNode::openFile( SystemFile & SF,
ANetNodeInstance * NNI ) {
return (NNI ) ? NNI->openFile( SF ) : 0 ;
}
//
//
// ANETNODEINSTANCE
//
//
long ANetNodeInstance::InstanceCounter = -1;
void ANetNodeInstance::initialize( void ) {
if( InstanceCounter == -1 )
InstanceCounter = time(0);
// set name
QString N;
N.sprintf( "-%ld", InstanceCounter++ );
N.prepend( NodeType->name() );
setName( N.latin1() );
}
void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){
if( Attr == "__name" ) {
setName( Value.latin1() );
} else {
setSpecificAttribute( Attr, Value );
}
}
void ANetNodeInstance::saveAttributes( QTextStream & TS ) {
TS << "__name=" << name() << endl;
saveSpecificAttribute( TS );
}
ANetNodeInstance * ANetNodeInstance::nextNode( void ) {
return connection()->findNext( this );
}
//
//
// NODECOLLECTION
//
//
NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() {
IsModified = 0;
Index = -1;
Name="";
IsNew = 1;
CurrentState = Unchecked;
AssignedInterface = 0;
}
NodeCollection::NodeCollection( QTextStream & TS ) :
QList<ANetNodeInstance>() {
long idx;
bool InError = 0;
QString S, A, N;
IsModified = 0;
Index = -1;
Name="";
IsNew = 0;
AssignedInterface = 0;
CurrentState = Unchecked;
do {
S = TS.readLine();
if( S.isEmpty() ) {
if( InError ) {
// remove all nodes
clear();
}
// empty line
break;
}
idx = S.find('=');
S.stripWhiteSpace();
A = S.left( idx );
A.lower();
N = S.mid( idx+1, S.length() );
N.stripWhiteSpace();
N = deQuote( N );
if( A == "name" ) {
Name = N;
} else if( A == "number" ) {
setNumber( N.toLong() );
} else if( A == "node" ) {
ANetNodeInstance * NNI = NSResources->findNodeInstance( N );
+ Log(( "Find node %s : %p\n", N.latin1(), NNI ));
if( NNI && ! InError ) {
- append( NSResources->findNodeInstance( N ) );
+ append( NNI );
} else {
// could not find a node type -> collection invalid
InError = 1;
}
}
} while( 1 );
Log(( "Profile number %s : %d nodes\n",
- N.latin1(), count() ));
+ Name.latin1(), count() ));
}
NodeCollection::~NodeCollection( void ) {
}
const QString & NodeCollection::description( void ) {
ANetNodeInstance * NNI = getToplevel();
return (NNI) ? NNI->runtime()->description() : Name;
}
void NodeCollection::append( ANetNodeInstance * NNI ) {
NNI->setConnection( this );
QList<ANetNodeInstance>::append( NNI );
}
void NodeCollection::save( QTextStream & TS ) {
TS << "name=" << quote( Name ) << endl;
TS << "number=" << number() << endl;
ANetNodeInstance * NNI;
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNI = it.current();
TS << "node=" << NNI->name() << endl;
}
TS << endl;
IsNew = 0;
}
ANetNodeInstance * NodeCollection::getToplevel( void ) {
ANetNodeInstance * NNI = 0;
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNI = it.current();
if( NNI->nodeClass()->isToplevel() )
break;
}
return NNI;
}
ANetNodeInstance * NodeCollection::findByName( const QString & S ) {
ANetNodeInstance * NNI = 0;
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNI = it.current();
if( NNI->name() == S )
break;
}
return NNI;
}
ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) {
ANetNodeInstance * NNNI;
if( ! NNI )
getToplevel();
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNNI = it.current();
if( NNNI == NNI ) {
++it;
return it.current();
}
}
return 0; // no more next
}
int NodeCollection::compareItems( QCollection::Item I1,
QCollection::Item I2 ) {
ANetNodeInstance * NNI1, * NNI2;
NNI1 = (ANetNodeInstance *)I1;
NNI2 = (ANetNodeInstance *)I2;
return strcmp( NNI1->name(), NNI2->name() );
}
static char * State2PixmapTbl[] = {
"NULL", // Unchecked : no pixmap
"check", // Unknown
"delete", // unavailable
"disabled", // disabled
"off", // off
"disconnected", // available
"connected" // up
};
QPixmap NodeCollection::devicePixmap( void ) {
QPixmap pm = NSResources->getPixmap(
getToplevel()->nextNode()->pixmapName()+"-large");
QPixmap Mini = NSResources->getPixmap(
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp
index 8b3b4fe..50fb15a 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.cpp
+++ b/noncore/settings/networksettings2/networksettings2/resources.cpp
@@ -48,202 +48,205 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
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 );
}
}
// 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" ),
tr( "<p>Nodes that provide working IP connections</p>" ) );
addNodeType( "fullsetup", tr( "Connection Profile" ),
tr( "<p>Fully configured connection profile</p>" ) );
addNodeType( "GPRS", tr( "Connection to GPRS device" ),
tr( "<p>Connection to a GPRS capable device</p>" ) );
// get access to the system
TheSystem = new System();
}
TheNSResources::~TheNSResources( void ) {
delete TheSystem;
}
void TheNSResources::addNodeType( const QString & ID,
const QString & Name,
const QString & Descr ) {
if( NodeTypeNameMap[ID].isEmpty() ) {
NodeTypeNameMap.insert( ID, Name );
NodeTypeDescriptionMap.insert( ID, Descr );
}
}
void TheNSResources::addSystemFile( const QString & ID,
const QString & P,
bool KDI ) {
if( ! SystemFiles.find( ID ) ) {
// new system file
SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) );
} // else existed
}
void TheNSResources::busy( bool ) {
/*
if( B ) {
ShowWait->show();
qApp->process
} else {
ShowWait->hide();
}
*/
}
/**
* 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;
}
}
// 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;
}
}
}
/**
* 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;
}
QPixmap TheNSResources::getPixmap( const QString & QS ) {
QPixmap P;
QString S("networksettings2/");
S += QS;
P = Resource::loadPixmap( S );
if( P.isNull() ) {
Log(( "Cannot load %s\n", S.latin1() ));
}
return ( P.isNull() ) ? QPixmap() : P;
}
QString TheNSResources::tr( const char * s ) {
return qApp->translate( "resource", s );
}
const QString & TheNSResources::netNode2Name( const char * s ) {
return NodeTypeNameMap[s];
}
const QString & TheNSResources::netNode2Description( const char * s ) {
return NodeTypeDescriptionMap[s];
}
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h
index 634cd39..5d90286 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.h
+++ b/noncore/settings/networksettings2/networksettings2/resources.h
@@ -1,143 +1,144 @@
#ifndef __RESOURCES__H
#define __RESOURCES__H
#include <qstring.h>
#include <qdict.h>
#include <qmap.h>
#include <qlist.h>
#include "netnode.h"
#include "systemfile.h"
#include "system.h"
class QLibrary;
class QPixmap;
class ANetNode;
class ANetNodeInstance;
typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN );
typedef struct NetNode_S {
ANetNode * NetNode;
QLibrary * TheLibrary;
long NodeCountInLib;
} NetNode_t;
class CurrentQPEUser {
public :
CurrentQPEUser() : UserName(), HomeDir(), EnvList() {}
inline bool known( void )
{ return ! HomeDir.isEmpty() && ! UserName.isEmpty(); }
QString UserName;
QString HomeDir;
int Uid;
int Gid;
QArray<char *> EnvList;
};
typedef QDict<NetNode_t> Name2NetNode_t;
typedef QDict<ANetNodeInstance > Name2Instance_t;
typedef QDict<NodeCollection> Name2Connection_t;
typedef QDict<SystemFile> Name2SystemFile_t;
class TheNSResources {
public :
TheNSResources( void );
~TheNSResources( );
// give busy feedback
void busy( bool B );
System & system()
{ return *TheSystem; }
int assignConnectionNumber(void);
QPixmap getPixmap( const QString & Name );
Name2NetNode_t & netNodes( void )
{ return AllNodeTypes; }
bool netNodeExists( const QString & X )
{ return AllNodeTypes.find(X)!=0; }
ANetNode * findNetNode( const QString & N )
{ NetNode_t * NNT = AllNodeTypes.find(N);
return (NNT) ? NNT->NetNode : 0;
}
// define new plugin (=node)
void addNodeType( const QString & ID,
const QString & LongName,
const QString & Description );
Name2SystemFile_t & systemFiles( void )
{ return SystemFiles; }
void addSystemFile( const QString & ID,
const QString & P,
bool KDI );
ANetNodeInstance * createNodeInstance( const QString & S )
{ ANetNodeInstance * NNI = 0;
+ printf( "Find node type %s\n", S.latin1() );
NetNode_t * NNT = AllNodeTypes[S];
if( ! NNT ) {
return 0;
}
NNI = NNT->NetNode->createInstance();
NNI->initialize();
return NNI;
}
Name2Instance_t & netNodeInstances( void )
{ return AllNodes; }
void addNodeInstance( ANetNodeInstance * I )
{ AllNodes.insert( I->name(), I ); }
void removeNodeInstance( const QString & N )
{ AllNodes.remove( N );}
ANetNodeInstance * findNodeInstance( const QString & S )
- { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; }
+ { return AllNodes[S]; }
const QString & netNode2Name( const char * Type );
const QString & netNode2Description( const char * Type );
void addConnection( NodeCollection * NC );
void removeConnection( const QString & N );
NodeCollection * findConnection( const QString & N );
NodeCollection * getConnection( int nr );
Name2Connection_t & connections( void )
{ return ConnectionsMap; }
inline bool userKnown( void )
{ return CurrentUser.known(); }
CurrentQPEUser & currentUser( void )
{ return CurrentUser; }
private :
void detectCurrentUser( void );
QString tr( const char * path );
void findAvailableNetNodes( const QString &path );
bool loadNetNode(
const QString &pluginFileName,
const QString &resolveString = "create_plugin");
QMap< QString, QString> NodeTypeNameMap;
QMap< QString, QString> NodeTypeDescriptionMap;
Name2Connection_t ConnectionsMap;
System * TheSystem;
Name2SystemFile_t SystemFiles;
// all node type classes
Name2NetNode_t AllNodeTypes;
// all nodes
Name2Instance_t AllNodes;
CurrentQPEUser CurrentUser;
};
extern TheNSResources * _NSResources;
#define NSResources _NSResources
#endif