summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/resources.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/resources.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp256
1 files changed, 165 insertions, 91 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
@@ -25,2 +25,4 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
25 25
26 detectCurrentUser();
27
26 // load available netnodes 28 // load available netnodes
@@ -82,3 +84,2 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
82 84
83 detectCurrentUser();
84} 85}
@@ -89,2 +90,13 @@ TheNSResources::~TheNSResources( void ) {
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/**
@@ -96,2 +108,3 @@ void TheNSResources::findAvailableNetNodes(const QString &path){
96 108
109 Log(("Locate plugins in %s\n", path.latin1() ));
97 QDir d(path); 110 QDir d(path);
@@ -129,2 +142,23 @@ void TheNSResources::findAvailableNetNodes(const QString &path){
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/**
@@ -169,3 +203,2 @@ bool TheNSResources::loadNetNode(
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 );
@@ -177,6 +210,8 @@ bool TheNSResources::loadNetNode(
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}
@@ -227,2 +262,3 @@ NodeCollection * TheNSResources::findConnection( const QString & S ) {
227 262
263/*
228void TheNSResources::renumberConnections( void ) { 264void TheNSResources::renumberConnections( void ) {
@@ -241,2 +277,3 @@ void TheNSResources::renumberConnections( void ) {
241} 277}
278*/
242 279
@@ -265,23 +302,25 @@ void TheNSResources::detectCurrentUser( void ) {
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
268 QDir ProcDir( "/proc" ); 305 { // open proc dir and find all dirs in it
269 QString QPELoc = QPEApplication::qpeDir() + "bin/qpe"; 306 QRegExp R("[0-9]+");
270 QFileInfo FI; 307 QDir ProcDir( "/proc" );
271 QStringList EL = ProcDir.entryList( QDir::Dirs ); 308 QFileInfo FI;
272 309 QStringList EL = ProcDir.entryList( QDir::Dirs );
273 // print it out 310
274 for ( QStringList::Iterator it = EL.begin(); 311 // print it out
275 it != EL.end(); 312 for ( QStringList::Iterator it = EL.begin();
276 ++it ) { 313 it != EL.end();
277 if( R.match( (*it) ) >= 0 ) { 314 ++it ) {
278 QString S = ProcDir.path()+"/"+ (*it); 315 if( R.match( (*it) ) >= 0 ) {
279 S.append( "/exe" ); 316 QString S = ProcDir.path()+"/"+ (*it);
280 FI.setFile( S ); 317 S.append( "/exe" );
281 // get the linke 318 FI.setFile( S );
282 S = FI.readLink(); 319 // get the link
283 if( S == QPELoc ) { 320 S = FI.readLink();
284 // found running qpe 321 if( S.right( 8 ) == "/bin/qpe" ) {
285 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); 322 // found running qpe
286 break; 323 QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" );
324 break;
325 }
287 } 326 }
@@ -289,21 +328,6 @@ void TheNSResources::detectCurrentUser( void ) {
289 } 328 }
290 }
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;
296 }
297
298 // FI now contains path ProcDir to the cmd dir
299 { char * Buf = 0;
300 char TB[1024];
301 long BufSize = 0;
302 int fd;
303 int rd;
304
305 fd = open( QPEEnvFile.latin1(), O_RDONLY );
306 if( fd < 0 ) {
307 fprintf( stderr, "Could not open %s : %d\n",
308 QPEEnvFile.latin1(), errno );
309 return; 333 return;
@@ -311,59 +335,109 @@ void TheNSResources::detectCurrentUser( void ) {
311 335
312 while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { 336 // FI now contains path ProcDir to the cmd dir
313 Buf = (char *)realloc( Buf, BufSize+rd ); 337 { char * Buf = 0;
314 memcpy( Buf+BufSize, TB, rd ); 338 char TB[1024];
315 BufSize += rd; 339 long BufSize = 0;
316 } 340 int fd;
341 int rd;
342
343 fd = open( QPEEnvFile.latin1(), O_RDONLY );
344 if( fd < 0 ) {
345 Log(("Could not open %s : %d\n",
346 QPEEnvFile.latin1(), errno ));
347 return;
348 }
317 349
318 char * Data = Buf; 350 while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) {
319 char * DataEnd = Data+BufSize-1; 351 Buf = (char *)realloc( Buf, BufSize+rd );
320 352 memcpy( Buf+BufSize, TB, rd );
321 // get env items out of list 353 BufSize += rd;
322 while( Data < DataEnd ) { 354 }
323 if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) { 355
324 CurrentUser.UserName = Data+8; 356 char * Data = Buf;
325 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 357 char * DataEnd = Data+BufSize-1;
326 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 358
327 strdup( Data ); 359 // get env items out of list
328 } else if( strncmp( Data, "HOME=", 5 ) == 0 ) { 360 while( Data < DataEnd ) {
329 CurrentUser.HomeDir = Data+5; 361 if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) {
330 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 362 CurrentUser.UserName = Data+8;
331 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 363 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
332 strdup( Data ); 364 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
333 } else { 365 strdup( Data );
334 EnvVar_t * Run = EV; 366 } else if( strncmp( Data, "HOME=", 5 ) == 0 ) {
335 while( Run->Name ) { 367 CurrentUser.HomeDir = Data+5;
336 if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { 368 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
337 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); 369 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
338 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = 370 strdup( Data );
339 strdup( Data ); 371 } else {
340 break; 372 EnvVar_t * Run = EV;
373 while( Run->Name ) {
374 if( strncmp( Data, Run->Name, Run->Len ) == 0 ) {
375 CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
376 CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
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 }
383 break;
384 }
385 Run ++;
341 } 386 }
342 Run ++;
343 } 387 }
344 }
345 388
346 Data += strlen( Data )+1; 389 Data += strlen( Data )+1;
347 } 390 }
348 391
349 free( Buf ); 392 free( Buf );
350 393
351 if( ! CurrentUser.UserName.isEmpty() ) { 394 if( ! CurrentUser.UserName.isEmpty() ) {
352 // find user info 395 // find user info
353 struct passwd pwd; 396 struct passwd pwd;
354 struct passwd * pwdres; 397 struct passwd * pwdres;
355 398
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;
405 }
406 CurrentUser.Uid = pwd.pw_uid;
407 CurrentUser.Gid = pwd.pw_gid;
408 } else{
409 CurrentUser.Uid =
410 CurrentUser.Gid = -1;
362 } 411 }
363 CurrentUser.Uid = pwd.pw_uid;
364 CurrentUser.Gid = pwd.pw_gid;
365 } else{
366 CurrentUser.Uid =
367 CurrentUser.Gid = -1;
368 } 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();
369 } 443 }