summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/netnode.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/netnode.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.cpp222
1 files changed, 198 insertions, 24 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp
index 110786a..17653bd 100644
--- a/noncore/settings/networksettings2/networksettings2/netnode.cpp
+++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp
@@ -4,3 +4,2 @@
-
#include <qpainter.h>
@@ -13,6 +12,20 @@
-#include "asdevice.h"
-#include "asline.h"
-#include "asconnection.h"
-#include "asfullsetup.h"
+static char * ActionName[] = {
+ "Disable",
+ "Enable",
+ "Activate",
+ "Deactivate",
+ "Up",
+ "Down"
+};
+
+static char * StateName[] = {
+ "Unchecked",
+ "Unknown",
+ "Unavailable",
+ "Disabled",
+ "Off",
+ "Available",
+ "IsUp"
+};
@@ -67,2 +80,17 @@ void ANetNode::setAttribute( QString & Attr, QString & Value ){
+bool ANetNode::isToplevel( void ) {
+ const char ** P = provides();
+ while( *P ) {
+ if( strcmp( *P, "fullsetup") == 0 )
+ return 1;
+ P ++;
+ }
+ return 0;
+}
+
+bool ANetNode::openFile( SystemFile & SF,
+ ANetNodeInstance * NNI ) {
+ return (NNI ) ? NNI->openFile( SF ) : 0 ;
+}
+
//
@@ -86,3 +114,3 @@ void ANetNodeInstance::initialize( void ) {
void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){
- if( Attr == "name" ) {
+ if( Attr == "__name" ) {
setName( Value.latin1() );
@@ -94,3 +122,3 @@ void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){
void ANetNodeInstance::saveAttributes( QTextStream & TS ) {
- TS << "name=" << name() << endl;
+ TS << "__name=" << name() << endl;
saveSpecificAttribute( TS );
@@ -114,2 +142,3 @@ NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() {
CurrentState = Unchecked;
+ AssignedInterface = 0;
}
@@ -125,2 +154,3 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
IsNew = 0;
+ AssignedInterface = 0;
CurrentState = Unchecked;
@@ -149,3 +179,2 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
} else if( A == "number" ) {
- Log(( "Profile number %s\n", N.latin1() ));
setNumber( N.toLong() );
@@ -161,2 +190,5 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
} while( 1 );
+
+ Log(( "Profile number %s : %d nodes\n",
+ N.latin1(), count() ));
}
@@ -169,3 +201,3 @@ const QString & NodeCollection::description( void ) {
ANetNodeInstance * NNI = getToplevel();
- return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name;
+ return (NNI) ? NNI->runtime()->description() : Name;
}
@@ -256,3 +288,4 @@ QPixmap NodeCollection::devicePixmap( void ) {
- QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() );
+ QPixmap Mini = NSResources->getPixmap(
+ device()->netNode()->pixmapName() );
@@ -282,3 +315,3 @@ QString NodeCollection::stateName( State_t S) {
case Off :
- return qApp->translate( "networksettings2", "Off");
+ return qApp->translate( "networksettings2", "Inactive");
case Available :
@@ -286,3 +319,3 @@ QString NodeCollection::stateName( State_t S) {
case IsUp :
- return qApp->translate( "networksettings2", "IsUp");
+ return qApp->translate( "networksettings2", "Up");
case Unchecked : /* FT */
@@ -302,7 +335,7 @@ void NodeCollection::reassign( void ) {
-bool NodeCollection::triggersVPN() {
- return getToplevel()->runtime()->asFullSetup()->triggersVPN();
+const QStringList & NodeCollection::triggers() {
+ return getToplevel()->runtime()->triggers();
}
-bool NodeCollection::hasDataForFile( const QString & S ) {
+bool NodeCollection::hasDataForFile( SystemFile & S ) {
return ( firstWithDataForFile( S ) != 0 );
@@ -310,3 +343,3 @@ bool NodeCollection::hasDataForFile( const QString & S ) {
-ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) {
+ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) {
for( QListIterator<ANetNodeInstance> it(*this);
@@ -315,5 +348,2 @@ ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) {
if( it.current()->hasDataForFile( S ) ) {
- Log(( "Node %s has data for %s\n",
- it.current()->nodeClass()->name(),
- S.latin1() ));
return it.current();
@@ -324,5 +354,137 @@ ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) {
+State_t NodeCollection::state( bool Update ) {
+ State_t NodeState;
+
+ if( CurrentState == Unchecked || Update ) {
+ // collect states of all nodes until with get the 'higest'
+ // state possible
+
+ Log(( "Connection %s state %s\n",
+ Name.latin1(), StateName[CurrentState] ));
+
+ CurrentState = Unknown;
+ for( QListIterator<ANetNodeInstance> it(*this);
+ it.current();
+ ++it ) {
+ Log(( "-> Detect %s\n", it.current()->name() ));
+ NodeState = it.current()->runtime()->detectState();
+ Log(( " state %s\n", StateName[NodeState] ));
+
+ if( NodeState == Disabled ||
+ NodeState == IsUp ) {
+ // max
+ CurrentState = NodeState;
+ break;
+ }
+
+ if( NodeState > CurrentState ) {
+ // higher
+ CurrentState = NodeState;
+ }
+ }
+ }
+
+ return CurrentState;
+}
+
+QString NodeCollection::setState( Action_t A, bool Force ) {
+
+ QString msg;
+ Action_t Actions[10];
+ int NoOfActions = 0;
+
+ // get current state
+ state( Force );
+
+ switch( A ) {
+ case Disable :
+ if( CurrentState < Disabled ) {
+ // disabled
+ CurrentState = Disabled;
+ return QString();
+ }
+
+ if( CurrentState == IsUp ) {
+ Actions[NoOfActions++] = Down;
+ Actions[NoOfActions++] = Deactivate;
+ } else if( CurrentState == Available ) {
+ Actions[NoOfActions++] = Deactivate;
+ }
+ Actions[NoOfActions++] = Disable;
+ break;
+ case Enable :
+ // always possible -> detected state is new state
+ Actions[NoOfActions++] = Enable;
+ break;
+ case Activate :
+ if( ! Force ) {
+ if( CurrentState >= Available ) {
+ // already available
+ return QString();
+ }
+
+ if( CurrentState != Off ) {
+ return qApp->translate( "System",
+ "State should be off" );
+ }
+ }
+
+ Actions[NoOfActions++] = Activate;
+ break;
+ case Deactivate :
+ if( ! Force ) {
+ if( CurrentState < Off ) {
+ // already inactive
+ return QString();
+ }
+ }
+
+ if( CurrentState == IsUp ) {
+ Actions[NoOfActions++] = Down;
+ }
+ Actions[NoOfActions++] = Deactivate;
+ break;
+ case Up :
+ if( ! Force ) {
+ if( CurrentState == IsUp ) {
+ return QString();
+ }
+ if( CurrentState < Off ) {
+ return qApp->translate( "System",
+ "State should at least be off" );
+ }
+ }
+ if( CurrentState == Off ) {
+ Actions[NoOfActions++] = Activate;
+ }
+ Actions[NoOfActions++] = Up;
+ break;
+ case Down :
+ if( ! Force ) {
+ if( CurrentState < Available ) {
+ // OK
+ return QString();
+ }
+ }
+ Actions[NoOfActions++] = Down;
+ break;
+ }
+
+ // send actions to all nodes
+ Log(( "Action %s requires %d steps\n",
+ ActionName[A], NoOfActions ));
+
+ for( int i = 0 ; i < NoOfActions; i ++ ) {
+ // setState recurses through the tree depth first
+ msg = getToplevel()->runtime()->setState( this, Actions[i], Force );
+ if( ! msg.isEmpty() ) {
+ return msg;
+ }
+ }
+ return QString();
+}
+
//
//
-// RUNTIMEINFO
+// RuntimeInfo
//
@@ -330,8 +492,20 @@ ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) {
-InterfaceInfo * RuntimeInfo::assignedInterface( void ) {
- return netNode()->nextNode()->runtime()->assignedInterface();
+QString RuntimeInfo::setState( NodeCollection * NC,
+ Action_t A,
+ bool Force ) {
+ QString M;
+ RuntimeInfo * Deeper = nextNode();
+
+ if( Deeper ) {
+ // first go deeper
+ M = Deeper->setState( NC, A, Force );
+ if( ! M.isEmpty() )
+ return M;
}
-AsDevice * RuntimeInfo::device( void ) {
- return netNode()->nextNode()->runtime()->device();
+ // set my own state
+ Log (( "-> Act upon %s\n", netNode()->name() ));
+ M = setMyState( NC, A, Force );
+ Log (( " result %s\n", M.latin1() ));
+ return M;
}