Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/resources.cpp | 102 |
1 files changed, 88 insertions, 14 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index c95ac7f..71e84cd 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -20,12 +20,14 @@ TheNSResources * _NSResources = 0; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), ConnectionsMap() { _NSResources = this; + detectCurrentUser(); + // load available netnodes findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); // compile provides and needs lists { const char ** NeedsRun; QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); @@ -77,26 +79,37 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), // define system files addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); // get access to the system TheSystem = new System(); - detectCurrentUser(); } TheNSResources::~TheNSResources( void ) { delete TheSystem; } +void TheNSResources::busy( bool B ) { +/* + 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"); @@ -124,12 +137,33 @@ void TheNSResources::findAvailableNetNodes(const QString &path){ } } ++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 */ @@ -164,24 +198,25 @@ bool TheNSResources::loadNetNode( NN = new NetNode_t; NN->NetNode = NNP; NN->TheLibrary = lib; NN->NodeCountInLib = PNN.count(); // store mapping - printf( "Store %s\n", NN->NetNode->name() ); AllNodeTypes.insert( NN->NetNode->name(), NN ); } return 1; } QPixmap TheNSResources::getPixmap( const QString & QS ) { + QPixmap P; QString S("networksettings2/"); S += QS; - fprintf( stderr, "%s\n", S.latin1() ); - return Resource::loadPixmap( S ); + Log(("%s\n", S.latin1() )); + P = Resource::loadPixmap( S ); + return ( P.isNull() ) ? QPixmap() : P; } QString TheNSResources::tr( const char * s ) { return qApp->translate( "resource", s ); } @@ -222,12 +257,13 @@ void TheNSResources::removeConnection( const QString & N ) { } NodeCollection * TheNSResources::findConnection( const QString & S ) { return ConnectionsMap[ S ]; } +/* void TheNSResources::renumberConnections( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections NodeCollection::resetMaxNr(); @@ -236,12 +272,13 @@ void TheNSResources::renumberConnections( void ) { ++it ) { NC = it.current(); NC->setNumber( NC->maxConnectionNumber()+1 ); NC->setModified( 1 ); } } +*/ typedef struct EnvVars { char * Name; int Len; } EnvVar_t; @@ -260,55 +297,56 @@ static EnvVar_t EV[] = { }; void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; - // open proc dir and find all dirs in it - { QRegExp R("[0-9]+"); + if( getenv( "OPIEDIR" ) == 0 ) { + // nothing known + { // open proc dir and find all dirs in it + QRegExp R("[0-9]+"); QDir ProcDir( "/proc" ); - QString QPELoc = QPEApplication::qpeDir() + "bin/qpe"; QFileInfo FI; QStringList EL = ProcDir.entryList( QDir::Dirs ); // print it out for ( QStringList::Iterator it = EL.begin(); it != EL.end(); ++it ) { if( R.match( (*it) ) >= 0 ) { QString S = ProcDir.path()+"/"+ (*it); S.append( "/exe" ); FI.setFile( S ); - // get the linke + // get the link S = FI.readLink(); - if( S == QPELoc ) { + if( S.right( 8 ) == "/bin/qpe" ) { // found running qpe QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); break; } } } } if( QPEEnvFile.isEmpty() ) { // could not find qpe - fprintf( stderr, "Could not find qpe\n" ); + Log(("Could not find qpe\n" )); return; } // FI now contains path ProcDir to the cmd dir { char * Buf = 0; char TB[1024]; long BufSize = 0; int fd; int rd; fd = open( QPEEnvFile.latin1(), O_RDONLY ); if( fd < 0 ) { - fprintf( stderr, "Could not open %s : %d\n", - QPEEnvFile.latin1(), errno ); + Log(("Could not open %s : %d\n", + QPEEnvFile.latin1(), errno )); return; } while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { Buf = (char *)realloc( Buf, BufSize+rd ); memcpy( Buf+BufSize, TB, rd ); @@ -334,12 +372,17 @@ void TheNSResources::detectCurrentUser( void ) { EnvVar_t * Run = EV; while( Run->Name ) { if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( Data ); + // put OPIEDIR in env + if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) { + putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); + + } break; } Run ++; } } @@ -353,18 +396,49 @@ void TheNSResources::detectCurrentUser( void ) { struct passwd pwd; struct passwd * pwdres; if( getpwnam_r( CurrentUser.UserName.latin1(), &pwd, TB, sizeof(TB), &pwdres ) || pwdres == 0 ) { - fprintf( stderr, "Could not determine user %s : %d\n", - CurrentUser.UserName.latin1(), errno ); + Log(("Could not determine user %s : %d\n", + CurrentUser.UserName.latin1(), errno )); return; } CurrentUser.Uid = pwd.pw_uid; CurrentUser.Gid = pwd.pw_gid; } else{ CurrentUser.Uid = CurrentUser.Gid = -1; } } + + } else { + CurrentUser.UserName = getenv( "LOGNAME" ); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( CurrentUser.UserName ); + + CurrentUser.HomeDir = getenv( "HOME" ); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( CurrentUser.HomeDir ); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER"); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH"); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH"); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR"); + + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR"); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL"); + + CurrentUser.Uid = getuid(); + CurrentUser.Gid = getgid(); + } } |