summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/lancard/lancardrun.cpp2
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.cpp2
-rw-r--r--noncore/settings/networksettings2/wlan/wlanrun.cpp2
3 files changed, 3 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp
index 470b797..8157dce 100644
--- a/noncore/settings/networksettings2/lancard/lancardrun.cpp
+++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp
@@ -1,130 +1,130 @@
#include <qfile.h>
#include <qtextstream.h>
#include <qstringlist.h>
#include <resources.h>
#include "lancardrun.h"
State_t LanCardRun::detectState( void ) {
// unavailable : no card found
// available : card found and assigned to us or free
// up : card found and assigned to us and up
NodeCollection * NC = nodeCollection();
QString S = QString( "/tmp/profile-%1.up" ).
arg( NC->number());
System & Sys = NSResources->system();
InterfaceInfo * Run;
QFile F( S );
if( F.open( IO_ReadOnly ) ) {
// could open file -> read interface and assign
QString X;
QTextStream TS(&F);
X = TS.readLine();
// find interface
if( handlesInterface( X ) ) {
for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
It.current();
++It ) {
Run = It.current();
if( X == Run->Name ) {
NC->assignInterface( Run );
- return IsUp;
+ return (Run->IsUp) ? IsUp : Available;
}
}
}
}
if( ( Run = NC->assignedInterface() ) ) {
// we already have an interface assigned -> still present ?
if( ! Run->IsUp ) {
// usb is still free -> keep assignment
return Available;
} // else interface is up but NOT us -> some other profile
}
// nothing (valid) assigned to us
NC->assignInterface( 0 );
// find possible interface
for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
It.current();
++It ) {
Run = It.current();
if( handlesInterface( *Run ) &&
( Run->CardType == ARPHRD_ETHER
#ifdef ARPHRD_IEEE1394
|| Run->CardType == ARPHRD_IEEE1394
#endif
) &&
! Run->IsUp
) {
// proper type, and Not UP -> free
return Off;
}
}
// no free found
return Unavailable;
}
QString LanCardRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
if( A == Activate ) {
InterfaceInfo * N = getInterface();
if( ! N ) {
// no interface available
NC->setCurrentState( Unavailable );
return tr("No interface found");
}
// because we were OFF the interface
// we get back is NOT assigned
NC->assignInterface( N );
NC->setCurrentState( Available );
return QString();
}
if( A == Deactivate ) {
NC->assignInterface( 0 );
NC->setCurrentState( Off );
}
return QString();
}
// get interface that is free or assigned to us
InterfaceInfo * LanCardRun::getInterface( void ) {
System & S = NSResources->system();
InterfaceInfo * best = 0, * Run;
for( QDictIterator<InterfaceInfo> It(S.interfaces());
It.current();
++It ) {
Run = It.current();
if( handlesInterface( *Run ) &&
( Run->CardType == ARPHRD_ETHER
#ifdef ARPHRD_IEEE1394
|| Run->CardType == ARPHRD_IEEE1394
#endif
)
) {
// this is a LAN card
if( Run->assignedConnection() == netNode()->connection() ) {
// assigned to us
return Run;
} else if( Run->assignedConnection() == 0 ) {
// free
best = Run;
}
}
}
return best; // can be 0
}
bool LanCardRun::handlesInterface( const QString & S ) {
InterfaceInfo * II;
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp
index de8c8a2..763644e 100644
--- a/noncore/settings/networksettings2/usb/usbrun.cpp
+++ b/noncore/settings/networksettings2/usb/usbrun.cpp
@@ -1,120 +1,120 @@
#include <qfile.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#include <resources.h>
#include "usbrun.h"
State_t USBRun::detectState( void ) {
// unavailable : no card found
// available : card found and assigned to us or free
// up : card found and assigned to us and up
NodeCollection * NC = nodeCollection();
QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
System & Sys = NSResources->system();
InterfaceInfo * Run;
QFile F( S );
Log(("Detecting for %s\n", NC->name().latin1() ));
if( F.open( IO_ReadOnly ) ) {
// could open file -> read interface and assign
QString X;
QTextStream TS(&F);
X = TS.readLine();
Log(("%s exists\n", S.latin1() ));
// find interface
if( handlesInterface( X ) ) {
for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
It.current();
++It ) {
Run = It.current();
if( X == Run->Name ) {
NC->assignInterface( Run );
- return IsUp;
+ return (Run->IsUp) ? IsUp : Available;
}
}
}
}
Log(("Assigned %p\n", NC->assignedInterface() ));
if( ( Run = NC->assignedInterface() ) ) {
// we already have an interface assigned -> still present ?
if( ! Run->IsUp ) {
// usb is still free -> keep assignment
return Available;
} // else interface is up but NOT us -> some other profile
}
// nothing (valid) assigned to us
NC->assignInterface( 0 );
// find possible interface
if( getInterface() ) {
// proper type, and Not UP -> free
// usb cables are currently always available when requested
// until we can detect if we are plugged in
return Available;
}
return Unavailable;
}
QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
InterfaceInfo * I = getInterface();
if( ! I ) {
return QString("No usb device available");
}
Log(( "Grabbed USB interface %s\n", I->Name.latin1() ));
// grab this interface
NC->assignInterface( I );
return QString();
}
// get interface that is free or assigned to us
InterfaceInfo * USBRun::getInterface( void ) {
System & S = NSResources->system();
InterfaceInfo * best = 0, * Run;
for( QDictIterator<InterfaceInfo> It(S.interfaces());
It.current();
++It ) {
Run = It.current();
Log(("%s %d %d=%d %d\n",
Run->Name.latin1(),
handlesInterface( Run->Name ),
Run->CardType, ARPHRD_ETHER,
! Run->IsUp ));
if( handlesInterface( Run->Name ) &&
Run->CardType == ARPHRD_ETHER
) {
// this is a USB card
if( Run->assignedConnection() == netNode()->connection() ) {
// assigned to us
return Run;
} else if( ! Run->IsUp &&
Run->assignedConnection() == 0 ) {
// free
best = Run;
} // UP or not assigned to us
}
}
return best; // can be 0
}
bool USBRun::handlesInterface( const QString & S ) {
return Pat.match( S ) >= 0;
}
bool USBRun::handlesInterface( InterfaceInfo * I ) {
return handlesInterface( I->Name );
}
diff --git a/noncore/settings/networksettings2/wlan/wlanrun.cpp b/noncore/settings/networksettings2/wlan/wlanrun.cpp
index fe49c4e..b15a560 100644
--- a/noncore/settings/networksettings2/wlan/wlanrun.cpp
+++ b/noncore/settings/networksettings2/wlan/wlanrun.cpp
@@ -1,120 +1,120 @@
#include <qfile.h>
#include <qtextstream.h>
#include <qstringlist.h>
#include <resources.h>
#include "wlanrun.h"
State_t WLanRun::detectState( void ) {
// unavailable : no card found
// available : card found and assigned to us or free
// up : card found and assigned to us and up
NodeCollection * NC = nodeCollection();
QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
System & Sys = NSResources->system();
InterfaceInfo * Run;
QFile F( S );
if( F.open( IO_ReadOnly ) ) {
// could open file -> read interface and assign
QString X;
QTextStream TS(&F);
X = TS.readLine();
// find interface
if( handlesInterface( X ) ) {
for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
It.current();
++It ) {
Run = It.current();
if( X == Run->Name ) {
NC->assignInterface( Run );
- return IsUp;
+ return (Run->IsUp) ? IsUp : Available;
}
}
}
}
if( ( Run = NC->assignedInterface() ) ) {
// we already have an interface assigned -> still present ?
if( ! Run->IsUp ) {
// usb is still free -> keep assignment
return Available;
} // else interface is up but NOT us -> some other profile
}
// nothing (valid) assigned to us
NC->assignInterface( 0 );
// find possible interface
for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
It.current();
++It ) {
Run = It.current();
if( handlesInterface( *Run ) &&
( Run->CardType == ARPHRD_ETHER
#ifdef ARPHRD_IEEE1394
|| Run->CardType == ARPHRD_IEEE1394
#endif
) &&
! Run->IsUp
) {
// proper type, and Not UP -> free
return Off;
}
}
return Unavailable;
}
QString WLanRun::setMyState( NodeCollection * , Action_t , bool ) {
// we only handle activate and deactivate
return QString();
}
// get interface that is free or assigned to us
InterfaceInfo * WLanRun::getInterface( void ) {
System & S = NSResources->system();
InterfaceInfo * best = 0, * Run;
for( QDictIterator<InterfaceInfo> It(S.interfaces());
It.current();
++It ) {
Run = It.current();
if( handlesInterface( *Run ) &&
( Run->CardType == ARPHRD_ETHER
#ifdef ARPHRD_IEEE1394
|| Run->CardType == ARPHRD_IEEE1394
#endif
)
) {
// this is a LAN card
if( Run->assignedConnection() == netNode()->connection() ) {
// assigned to us
return Run;
} else if( Run->assignedConnection() == 0 ) {
// free
best = Run;
}
}
}
return best; // can be 0
}
bool WLanRun::handlesInterface( const QString & S ) {
InterfaceInfo * II;
II = NSResources->system().interface( S );
if( ( II = NSResources->system().interface( S ) ) ) {
return handlesInterface( *II );
}
return Pat.match( S ) >= 0;
}
bool WLanRun::handlesInterface( const InterfaceInfo & II ) {
return ( Pat.match( II.Name ) < 0 );
}