summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/editconnection.cpp17
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp2
2 files changed, 14 insertions, 5 deletions
diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp
index 6ab2dd6..bda9d7e 100644
--- a/noncore/settings/networksettings2/editconnection.cpp
+++ b/noncore/settings/networksettings2/editconnection.cpp
@@ -1,631 +1,640 @@
#include <opie2/odebug.h>
#include <qlistview.h>
#include <qwidgetstack.h>
#include <qframe.h>
#include <qcombobox.h>
#include <qtabwidget.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qheader.h>
#include <qpainter.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include "editconnection.h"
#include "resources.h"
#include "netnode.h"
//
//
// THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS
//
//
class MyQCheckListItem : public QCheckListItem
{
public:
MyQCheckListItem( QListView *parent, const QString & S, Type T ) :
QCheckListItem( parent, S, T ) { }
MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) :
QCheckListItem( parent, S, T ) { }
MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) :
QCheckListItem( parent, S, T ) { }
MyQCheckListItem( QListView *parent, const QString & S ) :
QCheckListItem( parent, S, QCheckListItem::Controller ) { }
MyQCheckListItem( QCheckListItem *parent, const QString & S ) :
QCheckListItem( parent, S, QCheckListItem::Controller ) { }
MyQCheckListItem( QListViewItem *parent, const QString & S ) :
QCheckListItem( parent, S, QCheckListItem::Controller ) { }
virtual void paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment );
};
void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment )
{
QColorGroup _cg( cg );
QColor c = _cg.text();
if ( ! isSelectable() )
_cg.setColor( QColorGroup::Text, Qt::lightGray );
QCheckListItem::paintCell( p, _cg, column, width, alignment );
_cg.setColor( QColorGroup::Text, c );
}
class MyQListViewItem : public QListViewItem
{
public:
MyQListViewItem( QListView *parent, const QString & S ) :
QListViewItem( parent, S ) { }
MyQListViewItem( QListViewItem *parent, const QString & S ) :
QListViewItem( parent, S ) { }
virtual void paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment );
};
void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment )
{
QColorGroup _cg( cg );
QColor c = _cg.text();
if ( ! isSelectable() )
_cg.setColor( QColorGroup::Text, Qt::lightGray );
QListViewItem::paintCell( p, _cg, column, width, alignment );
_cg.setColor( QColorGroup::Text, c );
}
//
//
// REAL GUI
//
//
bool EditNetworkSetup::AutoCollapse = 1;
EditNetworkSetup::EditNetworkSetup( QWidget* parent ) :
EditNetworkSetupGUI( parent, 0, TRUE ), TmpCollection() {
Tab_TB->setTabEnabled( Setup_FRM, FALSE );
Setup_FRM->setEnabled( FALSE );
TmpIsValid = 0;
SelectedNodes = 0;
AutoCollapse_CB->setChecked( AutoCollapse );
Mapping = new QPtrDict<ANetNode>;
Mapping->setAutoDelete( FALSE );
Nodes_LV->header()->hide();
// popluate tree with all NetNodes
buildFullTree();
}
NetworkSetup * EditNetworkSetup::getTmpCollection( void ) {
if( TmpIsValid )
// content is stil OK
return &(TmpCollection);
// reset collection -> delete all NEW NetNodes
for( QListIterator<ANetNodeInstance> it(TmpCollection);
it.current();
++it ) {
if( it.current()->isNew() ) {
delete it.current();
}
}
TmpCollection.clear();
- TmpCollection.copyFrom( *SelectedNodes );
+ if( SelectedNodes ) {
+ // initialize like original
+ TmpCollection.copyFrom( *SelectedNodes );
+ }
// update content
QListViewItem * it = Nodes_LV->firstChild();
ANetNode * NN;
// start iter (if there is a collection)
/*
a node collection is sorted from the toplevel
node to the deepest node
*/
ANetNodeInstance * NNI =
(SelectedNodes) ? SelectedNodes->first() : 0 ;
TmpCollection.setModified( 0 );
// the listview always starts with the toplevel
// hierarchy. This is always a controller item
while ( it ) {
NN = (*Mapping)[it];
if( NN == 0 ) {
// this item is a controller ->
// has radio items as children ->
// find selected one
it = it->firstChild();
while( it ) {
if( ((QCheckListItem *)it)->isOn() ) {
// this radio is selected -> go deeper
break;
}
it = it->nextSibling();
}
if( ! it ) {
TmpIsValid = 0;
return 0;
}
// it now contains selected radio
NN = (*Mapping)[it];
}
// NN here contains the netnode of the
// current item -> this node needs to
// be stored in the collection
if( NNI == 0 ||
it->text(0) != NNI->nodeClass()->name() ) {
// new item not in previous collection
ANetNodeInstance * NNI = NN->createInstance();
NNI->initialize();
// this node type not in collection
TmpCollection.append( NNI );
// master collection changed because new item in it
TmpCollection.setModified( 1 );
// no more valid items in old list
NNI = 0;
} else {
// already in list -> copy pointer
TmpCollection.append( NNI );
NNI = SelectedNodes->next();
}
// go deeper to next level
// this level is can be a new controller
// or an item
it = it->firstChild();
}
TmpIsValid = 1;
return &(TmpCollection);
}
// pass a NetworkSetup NetworkSetup to be edited
void EditNetworkSetup::setNetworkSetup( NetworkSetup * NC ) {
ANetNodeInstance * NNI;
ANetNode * NN;
SelectedNodes = NC;
Name_LE->setText( NC->name() );
NNI = NC->first();
// show configure tabl
Tab_TB->setCurrentPage( 1 );
// valid colledction
Tab_TB->setTabEnabled( Setup_FRM, FALSE );
Setup_FRM->setEnabled( FALSE );
// select items in collection
QListViewItem * it = Nodes_LV->firstChild();
bool Found;
TmpIsValid = 0;
while ( it ) {
NN = (*Mapping)[it];
if( NN == 0 ) {
// this item is a controller ->
// has radio items as children ->
// find selected one
it = it->firstChild();
Found = 0;
while( it ) {
if( NNI && it->text(0) == NNI->nodeClass()->name() ) {
// this radio is part of the collection
((QCheckListItem *)it)->setOn( 1 );
updateGUI( it, NNI->nodeClass() );
// check its children
Found = 1;
it = it->firstChild();
NNI = SelectedNodes->next();
// do not bother to check other items
break;
}
it = it->nextSibling();
}
if( ! Found ) {
// this means that this level is NOT present in collection
// probably INCOMPATIBEL collection OR Missing plugin
QMessageBox::warning(
0,
tr( "Error presentig NetworkSetup" ),
tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ).
arg(NNI->nodeClass()->name()) );
return;
}
// it now contains selected radio
NN = (*Mapping)[it];
} else {
// automatic selection
if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) {
// should exist and be the same
if( NNI ) {
QMessageBox::warning(
0,
tr( "Error presentig NetworkSetup" ),
tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ).
arg(NNI->nodeClass()->name()) );
} else {
QMessageBox::warning(
0,
tr( "Error presentig NetworkSetup" ),
tr( "<p>Missing NetworkSetup\"<i>%1</i>\"</p>" ).
arg(it->text(0)) );
}
return;
}
it = it->firstChild();
}
}
}
// get result of editing (either new OR updated collection
NetworkSetup * EditNetworkSetup::networkSetup( void ) {
if( SelectedNodes == 0 ) {
// new collection
SelectedNodes = new NetworkSetup;
}
// clean out old entries
SelectedNodes->clear();
// transfer
for( QListIterator<ANetNodeInstance> it(TmpCollection);
it.current();
++it ) {
SelectedNodes->append( it.current() );
}
if( TmpCollection.isModified() )
SelectedNodes->setModified( 1 );
if( SelectedNodes->name() != Name_LE->text() ) {
SelectedNodes->setName( Name_LE->text() );
SelectedNodes->setModified( 1 );
}
return SelectedNodes;
}
// Build device tree -> start
void EditNetworkSetup::buildFullTree( void ) {
ANetNode * NN;
// toplevel item
MyQCheckListItem * TheTop = new MyQCheckListItem(
Nodes_LV,
NSResources->netNode2Name("fullsetup"),
QCheckListItem::Controller );
TheTop->setOpen( TRUE );
Description_LBL->setText(
NSResources->netNode2Description( "fullsetup" ) );
Nodes_LV->setSelected( TheTop, TRUE );
// find all Nodes that are toplevel nodes -> ie provide
// TCP/IP NetworkSetup
for( QDictIterator<ANetNode> Iter(NSResources->netNodes());
Iter.current();
++Iter ) {
NN = Iter.current();
if( ! NN->isToplevel() ) {
continue;
}
MyQCheckListItem * it = new MyQCheckListItem( TheTop,
NN->name(),
QCheckListItem::RadioButton );
it->setPixmap( 0,
NSResources->getPixmap( NN->pixmapName() )
);
// remember that this node maps to this listitem
Mapping->insert( it, NN );
buildSubTree( it, NN );
}
}
// Build device tree -> help function
void EditNetworkSetup::buildSubTree( QListViewItem * it, ANetNode *NN ) {
ANetNode::NetNodeList & NNL = NN->alternatives();
if( NNL.size() > 1 ) {
// this node has alternatives -> needs radio buttons
it = new MyQCheckListItem(
it,
NSResources->netNode2Name(NN->needs()[0]),
QCheckListItem::Controller );
it->setSelectable( FALSE );
}
for ( unsigned int i=0; i < NNL.size(); i++ ) {
QListViewItem * CI;
if( NNL.size() > 1 ) {
// generate radio buttons
CI = new MyQCheckListItem(
(QCheckListItem *)it,
NNL[i]->name(), QCheckListItem::RadioButton );
// remember that this node maps to this listitem
CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) );
Mapping->insert( CI, NNL[i] );
CI->setSelectable( FALSE );
} else {
// Single item
CI = new MyQListViewItem( it, NNL[i]->name() );
// remember that this node maps to this listitem
Mapping->insert( CI, NNL[i] );
CI->setSelectable( FALSE );
CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) );
}
buildSubTree( CI, NNL[i] );
}
}
// Clicked ok OK button
void EditNetworkSetup::accept( void ) {
if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) {
QMessageBox::warning(
0,
tr( "Closing NetworkSetup Setup" ),
tr( "Definition not complete or no name" ) );
return;
}
// check if all devices have acceptable input
getTmpCollection();
{ ANetNodeInstance * NNI;
QString S;
for( QListIterator<ANetNodeInstance> it(TmpCollection);
it.current();
++it ) {
NNI = it.current();
// widget must show its own problems
S = NNI->acceptable();
if( ! S.isEmpty() ) {
QMessageBox::warning(
0,
tr( "Cannot save" ),
S );
return;
}
NNI->commit();
if( NNI->isModified() ) {
TmpCollection.setModified( 1 );
// commit the data
}
}
}
QDialog::accept();
}
// triggered by CB
void EditNetworkSetup::SLOT_AutoCollapse( bool b ) {
AutoCollapse = b;
}
// clicked on node in tree -> update GUI
void EditNetworkSetup::SLOT_SelectNode( QListViewItem * it ) {
ANetNode * NN;
if( it == 0 || it->depth() == 0 ) {
Description_LBL->setText(
NSResources->netNode2Description( "fullsetup" ) );
// topevel or no selection
return;
}
// store conversion from lvitem to node
NN = (*Mapping)[ it ];
if( ! NN ) {
// intermediate node
NN = (*Mapping)[ it->parent() ];
if( NN ) {
// figure out type of this node -> produce mesage
Description_LBL->setText( NSResources->netNode2Description(
NN->needs()[0]) );
} else {
Description_LBL->setText( "" );
}
return;
}
Description_LBL->setText( NN->nodeDescription() );
if( ! it->isSelectable() ) {
return;
}
- if( ! ((QCheckListItem *)it)->isOn() ) {
- // clicked on line but NOT on Check or Radio item
- return;
+ ANetNode::NetNodeList & NNL = NN->alternatives();
+
+ if( NNL.size() != 1 ) {
+ if( NNL.size() == 0 ||
+ ! ((MyQCheckListItem *)it)->isOn()
+ ) {
+ // not clicked on Check or Radio item
+ return;
+ }
}
// item has really changed -> update
TmpIsValid = 0;
updateGUI( it, NN );
}
// cliecked on TAB to go to setup
void EditNetworkSetup::SLOT_AlterTab( const QString & S ) {
if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) {
// switched to setup -> update CB and populate ws with
// forms for devices
if( ! TmpIsValid ) {
getTmpCollection();
// clear CB and Ws
{ QWidget * W;
int i = 0;
Devices_CB->clear();
while( ( W = Setup_WS->widget( i ) ) ) {
Setup_WS->removeWidget( W );
i ++;
}
}
// update CB
// and populate WidgetStack
{ ANetNodeInstance * NNI;
QListIterator<ANetNodeInstance> it(TmpCollection);
int i = 0;
QWidget * W;
for ( ; it.current(); ++it ) {
NNI = it.current();
Devices_CB->insertItem(
NSResources->getPixmap( NNI->nodeClass()->pixmapName() ),
NNI->nodeClass()->name()
);
// add edit widget
W = NNI->edit( Setup_WS );
if( ! W) {
W = new QLabel( Setup_WS,
tr("No configuration required"));
}
Setup_WS->addWidget( W , i );
i ++;
}
}
Setup_WS->raiseWidget( 0 );
} // still valid
}
}
// update visual feedback of selection state
void EditNetworkSetup::updateGUI( QListViewItem * it, ANetNode * NN ) {
bool HCC = haveCompleteConfig( it );
Tab_TB->setTabEnabled( Setup_FRM, HCC );
Setup_FRM->setEnabled( HCC );
// disable children of all siblings at same level
QListViewItem * Sbl = it->parent()->firstChild();
while( Sbl ) {
if ( Sbl != it ) {
disableTree( Sbl->firstChild(), FALSE );
Sbl->setSelectable( TRUE );
if( AutoCollapse )
Sbl->setOpen( FALSE );
}
Sbl = Sbl->nextSibling();
}
// enable selected path (as deep as it goes
it->setOpen( TRUE );
enablePath( it->firstChild(),
(it->depth()==1) ?
1 : // toplevel always alternatives
(NN->alternatives().size() > 1) );
}
void EditNetworkSetup::disableTree( QListViewItem * it, bool Mode ) {
while( it ) {
// disable sbl's chidren
it->setSelectable( Mode );
if( AutoCollapse )
it->setOpen( Mode );
disableTree( it->firstChild(), Mode );
it = it->nextSibling();
}
}
// pah : ParentHasAlternatives
void EditNetworkSetup::enablePath( QListViewItem * it, bool pha ) {
while( it ) {
ANetNode * NN;
NN = (*Mapping)[it];
if( NN ) {
if( pha ) {
bool doOn = ((QCheckListItem *)it)->isOn();
// we are a checklistitem for sure
it->setSelectable( TRUE );
if( AutoCollapse && ! doOn )
it->setOpen( doOn );
if( doOn ) {
// selected alternative
enablePath( it->firstChild(),
NN->alternatives().size() > 1);
} else {
// non-selected alternative
disableTree( it->firstChild(), FALSE);
}
} else {
// we are single subitem
it->setSelectable( TRUE );
it->setOpen( TRUE );
enablePath( it->firstChild(),
NN->alternatives().size() > 1);
}
} else {
// controller node
it->setSelectable( TRUE );
it->setOpen( TRUE );
enablePath( it->firstChild(), pha );
}
it = it->nextSibling();
}
}
// do we have a complete configuration (all needs are provided for ?)
bool EditNetworkSetup::haveCompleteConfig( QListViewItem * it ) {
// check if all below this level is selected
it = ( it ) ?it : Nodes_LV->firstChild();
ANetNode *NN;
bool Found;
while ( it ) {
NN = (*Mapping)[it];
if( NN == 0 ) {
// this item is a controller ->
// has radio items as children ->
// find selected one
it = it->firstChild();
Found = 0;
while( it ) {
if( ((QCheckListItem *)it)->isOn() ) {
Found = 1;
// go deeper
it = it->firstChild();
break;
}
it = it->nextSibling();
}
if( ! Found ) {
return 0; // no not complete -> a radio should have been chkd
}
// it now contains selected radio
NN = (*Mapping)[it];
} else {
// automatic selection
it = it->firstChild();
}
}
return 1;
}
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index b4622fc..835c7c3 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -1,787 +1,787 @@
#include <stdlib.h>
#include <opie2/odebug.h>
#include <qpe/qpeapplication.h>
#include <qtextstream.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include "nsdata.h"
#include <netnode.h>
#include <resources.h>
static QString CfgFile;
NetworkSettingsData::NetworkSettingsData( void ) {
// init global resources structure
new TheNSResources();
if( ! NSResources->userKnown() ) {
Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n",
NSResources->currentUser().HomeDir.latin1(),
NSResources->currentUser().UserName.latin1() ));
return;
}
CfgFile.sprintf( "%s/Settings/NS2.conf",
NSResources->currentUser().HomeDir.latin1() );
Log(( "Cfg from %s\n", CfgFile.latin1() ));
// load settings
loadSettings();
// assign interfaces by scanning /tmp/profile-%s.Up files
{ QDir D( "/tmp" );
QFile * F = new QFile;
int profilenr;
QString interfacename;
QTextStream TS ( F );
QStringList SL = D.entryList( "profile-*.up");
Log(( "System reports %d interfaces. Found %d up\n",
NSResources->system().interfaces().count(),
SL.count() ));
for ( QStringList::Iterator it = SL.begin();
it != SL.end();
++it ) {
profilenr = atol( (*it).mid( 8 ).latin1() );
// read the interface store int 'up'
F->setName( D.path() + "/" + (*it) );
if( F->open( IO_ReadOnly ) ) {
NetworkSetup * NC;
interfacename = TS.readLine();
F->close();
Log(( "Assign interface %s to Profile nr %d\n",
interfacename.latin1(), profilenr ));
NC = NSResources->getNetworkSetup( profilenr );
if( NC ) {
NC->assignInterface(
NSResources->system().findInterface( interfacename ) );
Log(( "Assign interface %p\n",
NC->assignedInterface() ));
} else {
Log(( "Profile nr %d no longer defined\n",
profilenr ));
}
}
}
}
}
// saving is done by caller
NetworkSettingsData::~NetworkSettingsData( void ) {
delete NSResources;
}
void NetworkSettingsData::loadSettings( void ) {
QString Line, S;
QString Attr, Value;
long idx;
QFile F( CfgFile );
QTextStream TS( &F );
ForceModified = 0;
do {
if( ! F.open(IO_ReadOnly) )
break;
/* load the file ->
FORMAT :
[NETNODETYPE]
Entries ...
<EMPTYLINE>
[NetworkSetup]
Name=Name
Node=Name
<EMPTYLINE>
*/
while( ! TS.atEnd() ) {
S = Line = TS.readLine();
if ( S.isEmpty() || S[0] != '[' )
continue;
S = S.mid( 1, S.length()-2 );
if( ! NSResources ) {
continue;
}
if( S == "NetworkSetup" ) {
// load NetworkSetups -> collections of nodes
bool Dangling;
NetworkSetup * NC = new NetworkSetup( TS, Dangling );
NSResources->addNetworkSetup( NC, Dangling );
} else {
ANetNode * NN = 0;
ANetNodeInstance* NNI = 0;
if( S.startsWith( "nodetype " ) ) {
S = S.mid( 9, S.length()-9 );
S = deQuote(S);
// try to find netnode
NN = NSResources->findNetNode( S );
} else {
// try to find instance
NNI = NSResources->createNodeInstance( S );
}
if( NN == 0 && NNI == 0 ) {
LeftOvers.append( Line );
do {
Line = TS.readLine();
// store even delimiter
LeftOvers.append( Line );
} while ( ! Line.isEmpty() );
//next section
continue;
}
// read entries of this section
do {
S = Line = TS.readLine();
if( S.isEmpty() ) {
// empty line
break;
}
idx = S.find( '=' );
if( idx > 0 ) {
Attr = S.left( idx );
Value = S.mid( idx+1, S.length() );
} else {
Value="";
Attr = S;
}
Value.stripWhiteSpace();
Attr.stripWhiteSpace();
Attr.lower();
// dequote Attr
Value = deQuote(Value);
if( NN ) {
// set the attribute
NN->setAttribute( Attr, Value );
} else {
// set the attribute
NNI->setAttribute( Attr, Value );
}
} while( 1 );
if( NNI ) {
// loading from file -> exists
Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI ));
NNI->setNew( FALSE );
NSResources->addNodeInstance( NNI );
}
if( NN ) {
Log( ( "Node %s : %p\n", NN->name(), NN ) );
}
}
}
} while( 0 );
}
QString NetworkSettingsData::saveSettings( void ) {
QString ErrS = "";
if( ! isModified() )
return ErrS;
QString S;
QFile F( CfgFile + ".bup" );
Log( ( "Saving settings to %s\n", CfgFile.latin1() ));
if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
ErrS = qApp->translate( "NetworkSettings",
"<p>Could not save setup to \"%1\" !</p>" ).
arg(CfgFile);
// problem
return ErrS;
}
QTextStream TS( &F );
// save global configs
for( QDictIterator<ANetNode> it( NSResources->netNodes() );
it.current();
++it ) {
TS << "[nodetype "
<< quote( QString( it.current()->name() ) )
<< "]"
<< endl;
it.current()->saveAttributes( TS );
TS << endl;
}
// save leftovers
for ( QStringList::Iterator it = LeftOvers.begin();
it != LeftOvers.end(); ++it ) {
TS << (*it) << endl;
}
// save all netnode instances
{ ANetNodeInstance * NNI;
for( QDictIterator<ANetNodeInstance> nit(
NSResources->netNodeInstances());
nit.current();
++nit ) {
// header
NNI = nit.current();
TS << '['
<< QString(NNI->nodeClass()->name())
<< ']'
<< endl;
NNI->saveAttributes( TS );
TS << endl;
}
}
// good NetworkSetups
{ Name2NetworkSetup_t & M = NSResources->networkSetups();
// for all NetworkSetups
for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
TS << "[NetworkSetup]" << endl;
it.current()->save(TS);
}
}
// save dangling NetworkSetups
{ Name2NetworkSetup_t & M = NSResources->danglingNetworkSetups();
// for all NetworkSetups
for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
TS << "[NetworkSetup]" << endl;
it.current()->save(TS);
}
}
QDir D(".");
D.rename( CfgFile + ".bup", CfgFile );
//
// proper files AND system files regenerated
//
for( QDictIterator<NetworkSetup> it(NSResources->networkSetups());
it.current();
++it ) {
it.current()->setModified( 0 );
}
return ErrS;
}
QString NetworkSettingsData::generateSettings( void ) {
QString S = "";
Name2SystemFile_t & SFM = NSResources->systemFiles();
Name2NetworkSetup_t & M = NSResources->networkSetups();
NetworkSetup * NC;
ANetNodeInstance * NNI;
ANetNodeInstance * FirstWithData;
RuntimeInfo * CurDev;
ANetNode * NN, * CurDevNN = 0;
long NoOfDevs;
long DevCtStart;
bool needToGenerate;
// regenerate system files
Log( ( "Generating settings from %s\n", CfgFile.latin1() ));
for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
nnit.current();
++nnit ) {
bool FirstItem = 1;
bool Generated = 0;
CurDevNN = nnit.current();
{ QStringList SL;
SL = CurDevNN->properFiles();
for ( QStringList::Iterator it = SL.begin();
it != SL.end();
++it ) {
Generated = 0;
FirstItem = 1;
// iterate over NNI's of this class
for( QDictIterator<ANetNodeInstance> nniit(
NSResources->netNodeInstances() );
nniit.current();
++nniit ) {
if( nniit.current()->nodeClass() != CurDevNN )
// different class
continue;
// open proper file
{ SystemFile SF( (*it) );
if( ! CurDevNN->openFile( SF, nniit.current()) ) {
// cannot open
S = qApp->translate( "NetworkSettings",
"<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ).
arg( (*it) ).arg( CurDevNN->name() );
return S;
}
if( ! SF.open() ) {
S = qApp->translate( "NetworkSettings",
"<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ).
arg( (*it) ).arg( CurDevNN->name() );
return S;
}
// preamble on first
if( FirstItem ) {
if( CurDevNN->generatePreamble( SF ) == 2 ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ).
arg( (*it) ).
arg( CurDevNN->name() );
return S;
}
}
FirstItem = 0;
Generated = 1;
// item specific
if( nniit.current()->generateFile( SF, -1 ) == 2 ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ).
arg( nniit.current()->name() ).
arg( (*it) ).
arg( CurDevNN->name() );
return S;
}
}
}
if( Generated ) {
SystemFile SF( (*it) );
if( CurDevNN->openFile( SF, 0 ) &&
! SF.path().isEmpty()
) {
if( ! SF.open() ) {
S = qApp->translate( "NetworkSettings",
"<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ).
arg( (*it) ).arg( CurDevNN->name() );
return S;
}
if( CurDevNN->generatePostamble( SF ) == 2 ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ).
arg( (*it) ).
arg( CurDevNN->name() );
return S;
}
} // no postamble
}
}
}
}
//
// generate all registered files
//
for( QDictIterator<SystemFile> sfit(SFM);
sfit.current();
++sfit ) {
SystemFile * SF;
SF = sfit.current();
// reset all
for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
nnit.current();
++nnit ) {
nnit.current()->setDone(0);
}
for( QDictIterator<ANetNodeInstance> nniit(
NSResources->netNodeInstances() );
nniit.current();
++nniit ) {
nniit.current()->setDone(0);
}
for( QDictIterator<NetworkSetup> ncit(M);
ncit.current();
++ncit ) {
ncit.current()->setDone(0);
}
Log( ( "Generating system file %s\n", SF->name().latin1() ));
needToGenerate = 0;
// are there netnodes that have instances and need
// to write data in this system file ?
for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
! needToGenerate && nnit.current();
++nnit ) {
NN = nnit.current();
if( NN->hasDataForFile( *SF ) ) {
// netnode can have data
// are there instances of this node ?
for( QDictIterator<ANetNodeInstance> nniit(
NSResources->netNodeInstances() );
! needToGenerate && nniit.current();
++nniit ) {
if( nniit.current()->nodeClass() == NN ) {
// yes
Log(("Node %s has data\n",
nniit.current()->name() ));
needToGenerate = 1;
break;
}
}
}
}
if( ! needToGenerate ) {
// no instances found that might need to write data
// in this systemfile
Log(("No nodes for systemfile %s\n", SF->name().latin1() ));
continue;
}
// ok generate this system file
if( ! SF->open() ) {
S = qApp->translate( "NetworkSettings",
"<p>Cannot open system file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
// global presection for this system file
if( ! SF->preSection() ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Preamble\" for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
// find NetworkSetups that want to write to this file
for( QDictIterator<NetworkSetup> ncit(M);
ncit.current();
++ncit ) {
NC = ncit.current();
if( NC->done() ) {
// already done
continue;
}
if( ! NC->hasDataForFile( *SF ) ) {
// no data
continue;
}
Log(("Generating %s for NetworkSetup %s\n",
SF->name().latin1(), NC->name().latin1() ));
// find highest item that wants to write data to this file
FirstWithData = NC->firstWithDataForFile( *SF );
// find device on which this NetworkSetup works
CurDev = NC->device();
// class of that node
CurDevNN = CurDev->netNode()->nodeClass();
if( ! FirstWithData->nodeClass()->done() ) {
// generate fixed part
if( ! SF->preDeviceSection( CurDevNN ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
if( FirstWithData->nodeClass()->generateFile(
*SF,
FirstWithData,
-2 ) == 2 ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
FirstWithData->nodeClass()->setDone( 1 );
Log(( "Systemfile %s for node instance %s is done\n",
SF->name().latin1(),
FirstWithData->name() ));
}
NoOfDevs = 0;
DevCtStart = -1;
if( SF->knowsDeviceInstances() ) {
DevCtStart = 0;
NoOfDevs = CurDevNN->instanceCount();
}
if( ! CurDev->netNode()->nodeClass()->done() ) {
// first time this device is handled
// generate common device specific part
for( int i = DevCtStart; i < NoOfDevs ; i ++ ) {
if( FirstWithData->nodeClass()->generateFile(
*SF, CurDev->netNode(), i ) == 2 ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
}
CurDev->netNode()->nodeClass()->setDone( 1 );
Log(( "Systemfile %s for Nodeclass %s is done\n",
SF->name().latin1(),
CurDev->netNode()->nodeClass()->name()
));
}
// generate profile specific info
// for all nodeNetworkSetups that work on the same device
for( QDictIterator<NetworkSetup> ncit2(M);
ncit2.current();
++ncit2 ) {
if( ncit2.current()->device() != CurDev ) {
// different device
continue;
}
Log(("NetworkSetup %s of family %s\n",
ncit2.current()->name().latin1(),
CurDev->name() ));
// generate
NNI = ncit2.current()->firstWithDataForFile( *SF );
for( int i = DevCtStart; i < NoOfDevs ; i ++ ) {
if( ! SF->preNodeSection( NNI, i ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
switch( NNI->generateFile( *SF, i ) ) {
case 0 :
(*SF) << endl;
break;
case 1 :
break;
case 2 :
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
if( ! SF->postNodeSection( NNI, i ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
}
ncit2.current()->setDone( 1 );
}
}
if( ! SF->postDeviceSection( CurDevNN ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
if( ! SF->postSection() ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Closure\" for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
// end of file
SF->close();
}
return S;
}
QList<NetworkSetup> NetworkSettingsData::collectPossible(
const QString & Interface ) {
// collect NetworkSetups that can work on top of this interface
NetworkSetup * NC;
QList<NetworkSetup> PossibleNetworkSetups;
Name2NetworkSetup_t & M = NSResources->networkSetups();
// for all NetworkSetups
for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
NC = it.current();
// check if this profile handles the requested interface
if( NC->handlesInterface( Interface ) && // if different Intf.
NC->state() != Disabled && // if enabled
NC->state() != IsUp // if already used
) {
Log( ( "Append %s for %s\n",
NC->name().latin1(), Interface.latin1() ));
PossibleNetworkSetups.append( NC );
}
}
return PossibleNetworkSetups;
}
/*
Called by the system to see if interface can be brought UP
if allowed, echo Interface-allowed else Interface-disallowed
*/
bool NetworkSettingsData::canStart( const QString & Interface ) {
// load situation
NetworkSetup * NC = 0;
QList<NetworkSetup> PossibleNetworkSetups;
PossibleNetworkSetups = collectPossible( Interface );
Log( ( "for %s : Possiblilies %d\n",
Interface.latin1(), PossibleNetworkSetups.count() ));
switch( PossibleNetworkSetups.count() ) {
case 0 : // no NetworkSetups
break;
case 1 : // one NetworkSetup
NC = PossibleNetworkSetups.first();
break;
default : // need to ask user ?
return 1;
}
if( NC ) {
switch( NC->state() ) {
case Unchecked :
case Unknown :
case Unavailable :
case Disabled :
// this profile does not allow interface to be UP
// -> try others
break;
case Off :
// try to UP the device
{ QString S= NC->setState( Activate );
if( ! S.isEmpty() ) {
// could not bring device Online -> try other alters
Log(( "disallow %ld for %s : %s\n",
NC->number(), Interface.latin1(), S.latin1() ));
break;
}
// interface assigned
}
// FT
case Available :
case IsUp : // also called for 'ifdown'
// device is ready -> done
Log(( "allow %ld for %s\n", NC->number(), Interface.latin1()));
- printf( "A%ld%s\n", NC->number(), Interface.latin1() );
+ printf( "A%d%s\n", NC->number(), Interface.latin1() );
return 0;
}
}
// if we come here no alternatives are possible
Log(( "disallow %s\n", Interface.latin1()));
printf( "D-%s\n", Interface.latin1() );
return 0;
}
bool NetworkSettingsData::isModified( void ) {
if( ForceModified )
return 1;
for( QDictIterator<NetworkSetup> it(NSResources->networkSetups());
it.current();
++it ) {
if( it.current()->isModified() ) {
return 1;
}
}
return 0;
}
bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) {
// load situation
QList<NetworkSetup> PossibleTriggered;
PossibleTriggered = collectTriggered( Interface );
Log( ( "for %s : Possiblilies %d\n",
Interface.latin1(), PossibleTriggered.count() ));
return ( PossibleTriggered.count() ) ? 1 : 0;
}
QList<NetworkSetup> NetworkSettingsData::collectTriggered(
const QString & Interface ) {
// collect NetworkSetups that could be triggered by this interface
NetworkSetup * NC;
QList<NetworkSetup> PossibleTriggered;
// for all NetworkSetups
Name2NetworkSetup_t & M = NSResources->networkSetups();
for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
NC = it.current();
// check if this profile handles the requested interface
if( NC->triggeredBy( Interface ) && // if different Intf.
NC->state() != Disabled && // if enabled
NC->state() != IsUp // if already used
) {
Log( ( "Append %s for %s\n",
NC->name().latin1(), Interface.latin1() ));
PossibleTriggered.append( NC );
}
}
return PossibleTriggered;
}