summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/resources.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp102
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
@@ -23,6 +23,8 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
23 23
24 _NSResources = this; 24 _NSResources = this;
25 25
26 detectCurrentUser();
27
26 // load available netnodes 28 // load available netnodes
27 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); 29 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR );
28 30
@@ -80,13 +82,23 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
80 // get access to the system 82 // get access to the system
81 TheSystem = new System(); 83 TheSystem = new System();
82 84
83 detectCurrentUser();
84} 85}
85 86
86TheNSResources::~TheNSResources( void ) { 87TheNSResources::~TheNSResources( void ) {
87 delete TheSystem; 88 delete TheSystem;
88} 89}
89 90
91void TheNSResources::busy( bool B ) {
92/*
93 if( B ) {
94 ShowWait->show();
95 qApp->process
96 } else {
97 ShowWait->hide();
98 }
99*/
100}
101
90/** 102/**
91 * Load all modules that are found in the path 103 * Load all modules that are found in the path
92 * @param path a directory that is scaned for any plugins that can be loaded 104 * @param path a directory that is scaned for any plugins that can be loaded
@@ -94,6 +106,7 @@ TheNSResources::~TheNSResources( void ) {
94 */ 106 */
95void TheNSResources::findAvailableNetNodes(const QString &path){ 107void TheNSResources::findAvailableNetNodes(const QString &path){
96 108
109 Log(("Locate plugins in %s\n", path.latin1() ));
97 QDir d(path); 110 QDir d(path);
98 if(!d.exists()) 111 if(!d.exists())
99 return; 112 return;
@@ -127,6 +140,27 @@ void TheNSResources::findAvailableNetNodes(const QString &path){
127 } 140 }
128} 141}
129 142
143// used to find unique connection number
144int TheNSResources::assignConnectionNumber( void ) {
145 bool found = 1;
146 for( int trial = 0; ; trial ++ ) {
147 found = 1;
148 for( QDictIterator<NodeCollection> it(ConnectionsMap);
149 it.current();
150 ++it ) {
151 if( it.current()->number() == trial ) {
152 found = 0;
153 break;
154 }
155 }
156
157 if( found ) {
158 Log(("Assign profile number %d\n", trial ));
159 return trial;
160 }
161 }
162}
163
130/** 164/**
131 * Attempt to load a function and resolve a function. 165 * Attempt to load a function and resolve a function.
132 * @param pluginFileName - the name of the file in which to attempt to load 166 * @param pluginFileName - the name of the file in which to attempt to load
@@ -167,7 +201,6 @@ bool TheNSResources::loadNetNode(
167 NN->NodeCountInLib = PNN.count(); 201 NN->NodeCountInLib = PNN.count();
168 202
169 // store mapping 203 // store mapping
170 printf( "Store %s\n", NN->NetNode->name() );
171 AllNodeTypes.insert( NN->NetNode->name(), NN ); 204 AllNodeTypes.insert( NN->NetNode->name(), NN );
172 } 205 }
173 206
@@ -175,10 +208,12 @@ bool TheNSResources::loadNetNode(
175} 208}
176 209
177QPixmap TheNSResources::getPixmap( const QString & QS ) { 210QPixmap TheNSResources::getPixmap( const QString & QS ) {
211 QPixmap P;
178 QString S("networksettings2/"); 212 QString S("networksettings2/");
179 S += QS; 213 S += QS;
180 fprintf( stderr, "%s\n", S.latin1() ); 214 Log(("%s\n", S.latin1() ));
181 return Resource::loadPixmap( S ); 215 P = Resource::loadPixmap( S );
216 return ( P.isNull() ) ? QPixmap() : P;
182} 217}
183 218
184QString TheNSResources::tr( const char * s ) { 219QString TheNSResources::tr( const char * s ) {
@@ -225,6 +260,7 @@ NodeCollection * TheNSResources::findConnection( const QString & S ) {
225 return ConnectionsMap[ S ]; 260 return ConnectionsMap[ S ];
226} 261}
227 262
263/*
228void TheNSResources::renumberConnections( void ) { 264void TheNSResources::renumberConnections( void ) {
229 Name2Connection_t & M = NSResources->connections(); 265 Name2Connection_t & M = NSResources->connections();
230 NodeCollection * NC; 266 NodeCollection * NC;
@@ -239,6 +275,7 @@ void TheNSResources::renumberConnections( void ) {
239 NC->setModified( 1 ); 275 NC->setModified( 1 );
240 } 276 }
241} 277}
278*/
242 279
243typedef struct EnvVars { 280typedef struct EnvVars {
244 char * Name; 281 char * Name;
@@ -263,10 +300,11 @@ void TheNSResources::detectCurrentUser( void ) {
263 // find current running qpe 300 // find current running qpe
264 QString QPEEnvFile = ""; 301 QString QPEEnvFile = "";
265 302
266 // open proc dir and find all dirs in it 303 if( getenv( "OPIEDIR" ) == 0 ) {
267 { QRegExp R("[0-9]+"); 304 // nothing known
305 { // open proc dir and find all dirs in it
306 QRegExp R("[0-9]+");
268 QDir ProcDir( "/proc" ); 307 QDir ProcDir( "/proc" );
269 QString QPELoc = QPEApplication::qpeDir() + "bin/qpe";
270 QFileInfo FI; 308 QFileInfo FI;
271 QStringList EL = ProcDir.entryList( QDir::Dirs ); 309 QStringList EL = ProcDir.entryList( QDir::Dirs );
272 310
@@ -278,9 +316,9 @@ void TheNSResources::detectCurrentUser( void ) {
278 QString S = ProcDir.path()+"/"+ (*it); 316 QString S = ProcDir.path()+"/"+ (*it);
279 S.append( "/exe" ); 317 S.append( "/exe" );
280 FI.setFile( S ); 318 FI.setFile( S );
281 // get the linke 319 // get the link
282 S = FI.readLink(); 320 S = FI.readLink();
283 if( S == QPELoc ) { 321 if( S.right( 8 ) == "/bin/qpe" ) {
284 // found running qpe 322 // found running qpe
285 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); 323 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" );
286 break; 324 break;
@@ -291,7 +329,7 @@ void TheNSResources::detectCurrentUser( void ) {
291 329
292 if( QPEEnvFile.isEmpty() ) { 330 if( QPEEnvFile.isEmpty() ) {
293 // could not find qpe 331 // could not find qpe
294 fprintf( stderr, "Could not find qpe\n" ); 332 Log(("Could not find qpe\n" ));
295 return; 333 return;
296 } 334 }
297 335
@@ -304,8 +342,8 @@ void TheNSResources::detectCurrentUser( void ) {
304 342
305 fd = open( QPEEnvFile.latin1(), O_RDONLY ); 343 fd = open( QPEEnvFile.latin1(), O_RDONLY );
306 if( fd < 0 ) { 344 if( fd < 0 ) {
307 fprintf( stderr, "Could not open %s : %d\n", 345 Log(("Could not open %s : %d\n",
308 QPEEnvFile.latin1(), errno ); 346 QPEEnvFile.latin1(), errno ));
309 return; 347 return;
310 } 348 }
311 349
@@ -337,6 +375,11 @@ void TheNSResources::detectCurrentUser( void ) {
337 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 375 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
338 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 376 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
339 strdup( Data ); 377 strdup( Data );
378 // put OPIEDIR in env
379 if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) {
380 putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] );
381
382 }
340 break; 383 break;
341 } 384 }
342 Run ++; 385 Run ++;
@@ -356,8 +399,8 @@ void TheNSResources::detectCurrentUser( void ) {
356 if( getpwnam_r( CurrentUser.UserName.latin1(), 399 if( getpwnam_r( CurrentUser.UserName.latin1(),
357 &pwd, TB, sizeof(TB), &pwdres ) || 400 &pwd, TB, sizeof(TB), &pwdres ) ||
358 pwdres == 0 ) { 401 pwdres == 0 ) {
359 fprintf( stderr, "Could not determine user %s : %d\n", 402 Log(("Could not determine user %s : %d\n",
360 CurrentUser.UserName.latin1(), errno ); 403 CurrentUser.UserName.latin1(), errno ));
361 return; 404 return;
362 } 405 }
363 CurrentUser.Uid = pwd.pw_uid; 406 CurrentUser.Uid = pwd.pw_uid;
@@ -367,4 +410,35 @@ void TheNSResources::detectCurrentUser( void ) {
367 CurrentUser.Gid = -1; 410 CurrentUser.Gid = -1;
368 } 411 }
369 } 412 }
413
414 } else {
415 CurrentUser.UserName = getenv( "LOGNAME" );
416 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
417 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
418 strdup( CurrentUser.UserName );
419
420 CurrentUser.HomeDir = getenv( "HOME" );
421 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
422 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
423 strdup( CurrentUser.HomeDir );
424
425 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
426 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER");
427 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
428 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH");
429
430 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
431 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH");
432
433 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
434 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR");
435
436 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
437 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR");
438 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
439 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL");
440
441 CurrentUser.Uid = getuid();
442 CurrentUser.Gid = getgid();
443 }
370} 444}