author | wimpie <wimpie> | 2005-01-07 15:23:23 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-07 15:23:23 (UTC) |
commit | b4eced64efad35beeb2004243ca26bf7eb20eaba (patch) (side-by-side diff) | |
tree | 14caf32705c787a8bffc917ecdf216ad40cfbdc0 | |
parent | 7af7203a51ddcf85f9f60e39157fcad21f7d9e34 (diff) | |
download | opie-b4eced64efad35beeb2004243ca26bf7eb20eaba.zip opie-b4eced64efad35beeb2004243ca26bf7eb20eaba.tar.gz opie-b4eced64efad35beeb2004243ca26bf7eb20eaba.tar.bz2 |
All NS2 libraries are now properly working plugins
21 files changed, 222 insertions, 518 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp index 5e4d951..5c2b8b2 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp @@ -1,94 +1,75 @@ #include "bluetoothBNEP_NN.h" #include "bluetoothBNEP_NNI.h" #include "bluetoothRFCOMM_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - // // // BLUETOOTH PAN/NAP node // // static const char * BluetoothBNEPNeeds[] = { 0 }; static const char * BluetoothBNEPProvides[] = { "device", 0 }; /** * Constructor, find all of the possible interfaces */ BluetoothBNEPNetNode::BluetoothBNEPNetNode() : ANetNode(tr("Bluetooth PAN/NAP")) { InstanceCount = 7; // default } /** * Delete any interfaces that we own. */ BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ } const QString BluetoothBNEPNetNode::nodeDescription(){ return tr("\ <p>Sets up a bluetooth link using the bluetooth Network profile.</p>\ <p>Use this to connect two computing devices.</p>\ " ); } ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { return new ABluetoothBNEP( this ); } const char ** BluetoothBNEPNetNode::needs( void ) { return BluetoothBNEPNeeds; } const char ** BluetoothBNEPNetNode::provides( void ) { return BluetoothBNEPProvides; } QString BluetoothBNEPNetNode::genNic( long nr ) { QString S; return S.sprintf( "bnep%ld", nr ); } void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); } } void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) { TS << "interfacecount=" << InstanceCount << endl; } -#ifndef MYPLUGIN - -extern "C" { -// create plugin registers both BT functions -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new BluetoothBNEPNetNode() ); - PNN.append( new BluetoothRFCOMMNetNode() ); -} - -#else - typedef Opie::Core::MakeTypelist<BluetoothBNEPNetNode, BluetoothRFCOMMNetNode>::Result BluetoothTypes; -OPIE_NS2_PLUGIN( NetNodeInterface<BluetoothTypes> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<BluetoothTypes> ) diff --git a/noncore/settings/networksettings2/cable/cable_NN.cpp b/noncore/settings/networksettings2/cable/cable_NN.cpp index 20299e4..58237a1 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.cpp +++ b/noncore/settings/networksettings2/cable/cable_NN.cpp @@ -1,69 +1,52 @@ #include "cable_NN.h" #include "cable_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * CableNeeds[] = { 0 }; static const char * CableProvides[] = { "line", 0 }; /** * Constructor, find all of the possible interfaces */ CableNetNode::CableNetNode() : ANetNode(tr("Cable Connection")) { } /** * Delete any interfaces that we own. */ CableNetNode::~CableNetNode(){ } const QString CableNetNode::nodeDescription(){ return tr("\ <p>Sets up a wired serial or parallel.</p>\ " ); } ANetNodeInstance * CableNetNode::createInstance( void ) { return new ACable( this ); } const char ** CableNetNode::needs( void ) { return CableNeeds; } const char ** CableNetNode::provides( void ) { return CableProvides; } void CableNetNode::setSpecificAttribute( QString & , QString & ) { } void CableNetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new CableNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<CableNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<CableNetNode> ) diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp index 3f8a53f..0c3ead6 100644 --- a/noncore/settings/networksettings2/editconnection.cpp +++ b/noncore/settings/networksettings2/editconnection.cpp @@ -1,631 +1,630 @@ #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 EditConnection::AutoCollapse = 1; EditConnection::EditConnection( QWidget* parent ) : EditConnectionGUI( 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(); } NodeCollection * EditConnection::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(); // 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 ) { owarn << "Radio not selected" << oendl; 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 connection NodeCollection to be edited void EditConnection::setConnection( NodeCollection * 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 Connection" ), tr( "<p>Old connection 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 Connection" ), tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). arg(NNI->nodeClass()->name()) ); } else { QMessageBox::warning( 0, tr( "Error presentig Connection" ), tr( "<p>Missing connection\"<i>%1</i>\"</p>" ). arg(it->text(0)) ); } return; } it = it->firstChild(); } } } // get result of editing (either new OR updated collection NodeCollection * EditConnection::connection( void ) { if( SelectedNodes == 0 ) { // new collection SelectedNodes = new NodeCollection; } // 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 EditConnection::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 Connection - for( QDictIterator<NetNode_t> Iter(NSResources->netNodes()); + for( QDictIterator<ANetNode> Iter(NSResources->netNodes()); Iter.current(); ++Iter ) { - - NN = Iter.current()->NetNode; + 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 EditConnection::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 EditConnection::accept( void ) { if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { QMessageBox::warning( 0, tr( "Closing Connection 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 EditConnection::SLOT_AutoCollapse( bool b ) { AutoCollapse = b; } // clicked on node in tree -> update GUI void EditConnection::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; } // item has really changed -> update TmpIsValid = 0; updateGUI( it, NN ); } // cliecked on TAB to go to setup void EditConnection::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 EditConnection::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 EditConnection::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 EditConnection::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 EditConnection::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/gprs/GPRS_NN.cpp b/noncore/settings/networksettings2/gprs/GPRS_NN.cpp index 4415739..e9553a6 100644 --- a/noncore/settings/networksettings2/gprs/GPRS_NN.cpp +++ b/noncore/settings/networksettings2/gprs/GPRS_NN.cpp @@ -1,95 +1,78 @@ #include <resources.h> #include <qpe/qpeapplication.h> #include <netnode.h> #include "GPRS_NN.h" #include "GPRS_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * GPRSNeeds[] = { "GPRS", 0 }; static const char * GPRSProvides[] = { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ GPRSNetNode::GPRSNetNode() : ANetNode(tr("GPRS capable device")) { NSResources->addSystemFile( "pap-secrets", "/etc/ppp/pap-secrets", 0 ); } /** * Delete any interfaces that we own. */ GPRSNetNode::~GPRSNetNode(){ } const QString GPRSNetNode::nodeDescription(){ return tr("\ <p>provides access to a GPRS capable device.</p>\ " ); } ANetNodeInstance * GPRSNetNode::createInstance( void ) { return new AGPRSDevice( this ); } bool GPRSNetNode::hasDataForFile( SystemFile & S ) { return S.name() == "pap-secrets"; } short GPRSNetNode::generateFile( SystemFile & , ANetNodeInstance * , long ) { return 0; } const char ** GPRSNetNode::needs( void ) { return GPRSNeeds; } const char ** GPRSNetNode::provides( void ) { return GPRSProvides; } void GPRSNetNode::setSpecificAttribute( QString & , QString & ) { } void GPRSNetNode::saveSpecificAttribute( QTextStream & ) { } QStringList GPRSNetNode::properFiles( void ) { QStringList SL; SL << "peers"; SL << "chatscripts"; SL << "extra"; return SL; } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new GPRSNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<GPRSNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<GPRSNetNode> ) diff --git a/noncore/settings/networksettings2/irda/irda_NN.cpp b/noncore/settings/networksettings2/irda/irda_NN.cpp index 6858157..a1ed686 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.cpp +++ b/noncore/settings/networksettings2/irda/irda_NN.cpp @@ -1,69 +1,52 @@ #include "irda_NN.h" #include "irda_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * IRDANeeds[] = { 0 }; static const char * IRDAProvides[] = { "line", 0 }; /** * Constructor, find all of the possible interfaces */ IRDANetNode::IRDANetNode() : ANetNode(tr("Infrared link")) { } /** * Delete any interfaces that we own. */ IRDANetNode::~IRDANetNode(){ } const QString IRDANetNode::nodeDescription(){ return tr("\ <p>Sets up a infra red serial link.</p>\ " ); } ANetNodeInstance * IRDANetNode::createInstance( void ) { return new AIRDA( this ); } const char ** IRDANetNode::needs( void ) { return IRDANeeds; } const char ** IRDANetNode::provides( void ) { return IRDAProvides; } void IRDANetNode::setSpecificAttribute( QString & , QString & ) { } void IRDANetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new IRDANetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<IRDANetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<IRDANetNode> ) diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp index fce3d29..520516c 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp @@ -1,92 +1,75 @@ #include "lancard_NN.h" #include "lancard_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * LanCardNeeds[] = { 0 }; static const char * LanCardProvides[] = { "device", 0 }; /** * Constructor, find all of the possible interfaces */ LanCardNetNode::LanCardNetNode() : ANetNode(tr("LAN card")), NICMACAddresses() { InstanceCount = 2; } /** * Delete any interfaces that we own. */ LanCardNetNode::~LanCardNetNode(){ } const QString LanCardNetNode::nodeDescription(){ return tr("\ <p>Sets up a wired regular LAN card.</p>\ <p>Use this to set up 10/100/1000 MBit LAN cards.</p>\ " ); } ANetNodeInstance * LanCardNetNode::createInstance( void ) { return new ALanCard( this ); } const char ** LanCardNetNode::needs( void ) { return LanCardNeeds; } const char ** LanCardNetNode::provides( void ) { return LanCardProvides; } QString LanCardNetNode::genNic( long nr ) { QString S; return S.sprintf( "eth%ld", nr ); } void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); } else if ( A == "macaddress" ) { NICMACAddresses.append( V ); } } void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) { TS << "interfacecount=" << InstanceCount << endl; for( QStringList::Iterator it = NICMACAddresses.begin(); it != NICMACAddresses.end(); ++it ) { TS << "macaddress=" << (*it) << endl; } } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new LanCardNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<LanCardNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<LanCardNetNode> ) diff --git a/noncore/settings/networksettings2/modem/modem_NN.cpp b/noncore/settings/networksettings2/modem/modem_NN.cpp index c7f6e78..e91b45a 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.cpp +++ b/noncore/settings/networksettings2/modem/modem_NN.cpp @@ -1,70 +1,53 @@ #include "modem_NN.h" #include "modem_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * ModemNeeds[] = { "line", 0 }; static const char * ModemProvides[] = { "modem", 0 }; /** * Constructor, find all of the possible interfaces */ ModemNetNode::ModemNetNode() : ANetNode(tr("Dialup modem")) { } /** * Delete any interfaces that we own. */ ModemNetNode::~ModemNetNode(){ } const QString ModemNetNode::nodeDescription(){ return tr("\ <p>Sets up a dialing procedures.</p>\ <p>Use this to dial up over modems, ISDN, GSM, ...</p>\ " ); } ANetNodeInstance * ModemNetNode::createInstance( void ) { return new AModem( this ); } const char ** ModemNetNode::needs( void ) { return ModemNeeds; } const char ** ModemNetNode::provides( void ) { return ModemProvides; } void ModemNetNode::setSpecificAttribute( QString & , QString & ) { } void ModemNetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new ModemNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<ModemNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<ModemNetNode> ) diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp index 82d0c29..2fa31bd 100644 --- a/noncore/settings/networksettings2/network/network_NN.cpp +++ b/noncore/settings/networksettings2/network/network_NN.cpp @@ -1,112 +1,95 @@ #include <qpe/qpeapplication.h> #include <resources.h> #include <netnode.h> #include "network_NN.h" #include "network_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * NetworkNeeds[] = { "device", 0 }; static const char * NetworkProvides[] = { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) { NSResources->addSystemFile( "interfaces", "/etc/network/interfaces", 1 ); } /** * Delete any interfaces that we own. */ NetworkNetNode::~NetworkNetNode(){ } const QString NetworkNetNode::nodeDescription(){ return tr("\ <p>Sets up TCP/IP options.</p>\ <p>Use this to configure the TCP/IP protocol</p>\ " ); } ANetNodeInstance * NetworkNetNode::createInstance( void ) { return new ANetwork( this ); } bool NetworkNetNode::hasDataForFile( SystemFile & S ) { return S.name() == "interfaces"; } short NetworkNetNode::generateFile( SystemFile & SF, ANetNodeInstance * NNI, long DevNr ) { if( DevNr < 0 ) { // generate device specific but common part return 1; } QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); if( SF.name() == "interfaces" ) { Log(("Generate entry for %s in %s\n", NIC.latin1(), SF.name().latin1() )); // generate mapping stanza for this interface SF << "# check if " << NIC << " can be brought UP" << endl; SF << "mapping " << NIC << endl; SF << " script " << QPEApplication::qpeDir() << "bin/networksettings2-request" << endl << endl; return 0; } return 1; } const char ** NetworkNetNode::needs( void ) { return NetworkNeeds; } const char ** NetworkNetNode::provides( void ) { return NetworkProvides; } void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { } void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new NetworkNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<NetworkNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<NetworkNetNode> ) diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index dca6631..9680a96 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -1,514 +1,514 @@ #include <stdio.h> #include <unistd.h> #include <errno.h> #include <opie2/odebug.h> #include <opie2/oledbox.h> #include <qpe/qpeapplication.h> #include <qlistbox.h> #include <qlayout.h> #include <qgroupbox.h> #include <qtimer.h> #include <qlistbox.h> #include <qmessagebox.h> #include <qlabel.h> #include <qiconview.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qtoolbutton.h> #include <qevent.h> #include "networksettings.h" #include "netnode.h" #include "editconnection.h" NetworkSettings::NetworkSettings( QWidget *parent, const char *name, WFlags fl ) : NetworkSettingsGUI(parent,name,fl), NSD() { UpdateTimer = new QTimer( this ); // set pixmaps Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); QVBoxLayout* V = new QVBoxLayout( LED_Frm ); QHBoxLayout * H = new QHBoxLayout( 0 ); V->addStretch(1); V->addLayout( H ); Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm ); H->addWidget( Leds[0], 0, Qt::AlignVCenter ); Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm ); H->addWidget( Leds[1], 0, Qt::AlignVCenter ); Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm ); H->addWidget( Leds[2], 0, Qt::AlignVCenter ); V->addStretch(1); SLOT_ToProfile(); // populate main Listbox Profiles_LB->clear(); QPEApplication::setStylusOperation( Profiles_LB->viewport(), QPEApplication::RightOnHold ); connect( Profiles_LB, SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), this, SLOT(SLOT_EditNode(QListBoxItem*)) ); { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); } } if( Profiles_LB->count() ) { Profiles_LB->setSelected( 0, TRUE ); } // if no profiles -> auto popup editing if( NSResources->connections().count() == 0 ) { QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); } connect( &(NSResources->system()), SIGNAL( stdoutLine(const QString &) ), this, SLOT( SLOT_CmdMessage(const QString &) ) ); connect( &(NSResources->system()), SIGNAL( stderrLine(const QString &) ), this, SLOT( SLOT_CmdMessage(const QString &) ) ); connect( &(NSResources->system()), SIGNAL( processEvent(const QString &) ), this, SLOT( SLOT_CmdMessage(const QString &) ) ); UpdateTimer->start( 5000 ); connect( UpdateTimer, SIGNAL( timeout() ), this, SLOT( SLOT_RefreshStates() ) ); /* Add QCopChannel */ connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); } NetworkSettings::~NetworkSettings() { QString S; owarn << "Dispose NS" << oendl; if( NSD.isModified() ) { owarn << "Modified" << oendl; S = NSD.saveSettings(); if( ! S.isEmpty() ) { S.insert( 0, "<p>" ); S.append( "</p>" ); // problem saving QMessageBox::warning( 0, tr( "Saving setup" ), S ); } SLOT_GenerateConfig(); NSD.setModified( 0 ); } } void NetworkSettings::SLOT_CmdMessage( const QString & S ) { Messages_LB->insertItem( S ); Messages_LB->setCurrentItem( Messages_LB->count()-1 ); Messages_LB->ensureCurrentVisible(); } void NetworkSettings::SLOT_RefreshStates( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember if( LBI ) { NodeCollection * NC; NSResources->system().probeInterfaces(); // update current selection only NC = NSResources->findConnection( LBI->text() ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { updateProfileState( LBI ); } } } /* -> LATER !! bool is; NodeCollection * NC; for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { NC = NSResources->findConnection( Profiles_LB->text(i) ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { is = Profiles_LB->isSelected(i); Profiles_LB->changeItem( NC->statePixmap(NewS), NC->name(), i ); if( is ) { Profiles_LB->setSelected( i, TRUE ); } } } } if( ci >= 0 ) Profiles_LB->setCurrentItem( ci ); */ } void NetworkSettings::SLOT_AddNode( void ) { SLOT_EditNode( 0 ); } void NetworkSettings::SLOT_DeleteNode( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; if( QMessageBox::warning( 0, tr( "Removing profile" ), tr( "Remove selected profile ?" ), 1, 0 ) == 1 ) { NSResources->removeConnection( LBI->text() ); delete LBI; NSD.setModified( 1 ); } } void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { QString OldName = ""; EditConnection EC( this ); if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); if( ! NC ) { return; } OldName = NC->name(); EC.setConnection( NC ); } EC.showMaximized(); // disable refresh timer UpdateTimer->stop(); // we need to retry while( 1 ) { if( EC.exec() == QDialog::Accepted ) { // toplevel item -> store NodeCollection * NC = EC.connection(); if( NC->isModified() ) { if( LBI ) { if( NC->name() != OldName ) { // find if new name is free NodeCollection * LCN = NSResources->findConnection( NC->name() ); if( LCN ) { QMessageBox::warning( 0, tr( "In System Config" ), tr( "Name %1 already exists" ).arg(NC->name()) ); continue; // restart exec } // else new name // new name -> remove item NSResources->removeConnection( OldName ); - NSResources->addConnection( NC ); + NSResources->addConnection( NC, 0 ); } // else not changed // must add it here since change will trigger event Profiles_LB->changeItem( NC->devicePixmap(), NC->name(), Profiles_LB->index( LBI ) ); } else { // new item int ci = Profiles_LB->count(); - NSResources->addConnection( NC ); + NSResources->addConnection( NC, 0 ); NC->setNumber( NSResources->assignConnectionNumber() ); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); Profiles_LB->setSelected( ci, TRUE ); } updateProfileState( LBI ); } } else { // cancelled : reset connection if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); NC->reassign(); } } break; } // reenable UpdateTimer->start( 5000 ); } void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { if( LBI == 0 ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); if( NC->description().isEmpty() ) { Description_LBL->setText( tr( "<<No description>>" ) ); } else { Description_LBL->setText( NC->description() ); } Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); bool FrmActive = 1; bool IsEnabled = 1; int leds = 0; owarn << "State " << NC->state() << oendl; switch( NC->state() ) { case Disabled : // no further work IsEnabled = 0; FrmActive = 0; owarn << "LEds " << leds << oendl; break; case Unknown : case Unchecked : case Unavailable : FrmActive = 0; break; case Off : leds = 1; break; case Available : leds = 2; break; case IsUp : leds = 3; break; } Disable_TB->setOn( ! IsEnabled ); LED_Frm->setEnabled( FrmActive ); for( int i = 0 ; i < leds; i ++ ) { Leds[i]->setColor( red ); Leds[i]->setOn( true ); } for( int i = leds ; i < 3; i ++ ) { Leds[i]->setColor( red ); Leds[i]->setOn( false ); } Up_TB->setEnabled( leds < 3 && leds != 0 ); Down_TB->setEnabled( leds > 0 ); } void NetworkSettings::SLOT_CheckState( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; updateProfileState( LBI ); } void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { SLOT_ShowNode( LBI ); } } void NetworkSettings::SLOT_GenerateConfig( void ) { QString S = NSD.generateSettings(); if( ! S.isEmpty() ) { S.insert( 0, "<p>" ); S.append( "</p>" ); QMessageBox::warning( 0, tr( "Generate config" ), S); } } void NetworkSettings::SLOT_Disable( bool T ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); QString Msg; if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); owarn << "Prepare to disable" << oendl; Msg = NC->setState( (T) ? Disable : Enable ); if( ! Msg.isEmpty() ) { Msg.insert( 0, "<p>" ); Msg.append( "</p>" ); QMessageBox::warning( 0, tr( "Activating profile" ), Msg ); return; } // reload new state NC->state( true ); updateProfileState( LBI ); } void NetworkSettings::SLOT_Up( void ) { // bring more up QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); QString Msg; int led = -1; if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); switch( NC->state() ) { case Disabled : // cannot modify this state case Unknown : // cannot modify this state case Unchecked : // cannot modify this state case Unavailable : // cannot modify this state case IsUp : // highest UP state return; case Off : // -> activate led = 1; Down_TB->setEnabled( true ); Log(( "Activate interface %s\n", NC->name().latin1() )); Msg = NC->setState( Activate ); break; case Available : // -> up led = 2; Log(( "Bring up interface %s\n", NC->name().latin1() )); Msg = NC->setState( Up ); if( Msg.isEmpty() ) { Up_TB->setEnabled( false ); } break; } if( ! Msg.isEmpty() ) { Msg.insert( 0, "<p>" ); Msg.append( "</p>" ); QMessageBox::warning( 0, tr( "Increase availability" ), Msg ); return; } updateProfileState( LBI ); // set color of led we should change if( led > 0 ) { Leds[led]->setColor( blue ); Leds[led]->setOn( true ); } } void NetworkSettings::SLOT_Down( void ) { // bring more down QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); int led = -1; QString Msg; if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); switch( NC->state() ) { case Disabled : // cannot modify this state case Unknown : // cannot modify this state case Unchecked : // cannot modify this state case Unavailable : // cannot modify this state case Off : // highest DOWN state break; case Available : // -> down led = 0; Log(( "Deactivate interface %s\n", NC->name().latin1() )); Msg = NC->setState( Deactivate ); Down_TB->setEnabled( false ); break; case IsUp : // highest UP state led = 1; Up_TB->setEnabled( true ); Log(( "Bring down interface %s\n", NC->name().latin1() )); Msg = NC->setState( Down, 1 ); if( Msg.isEmpty() ) { // remove 'up' file to make sure unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; } break; } if( ! Msg.isEmpty() ) { Msg.insert( 0, "<p>" ); Msg.append( "</p>" ); QMessageBox::warning( 0, tr( "Decrease availability" ), Msg ); return; } updateProfileState( LBI ); // set color of led we should change if( led >= 0 ) { Leds[led]->setColor( blue ); } } void NetworkSettings::SLOT_ToMessages( void ) { Profiles_LB->hide(); Profile_GB->hide(); Messages_GB->show(); } void NetworkSettings::SLOT_ToProfile( void ) { Profiles_LB->show(); Profile_GB->show(); Messages_GB->hide(); } void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { QDataStream stream( data, IO_ReadOnly ); if( msg == "raise" ) { raise(); return; } /* if ( msg == "someMessage(int,int,int)" ) { int a,b,c; stream >> a >> b >> c; ... } */ } diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index f8f2d1e..f00e0b3 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -1,512 +1,519 @@ #include <time.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpainter.h> #include <qbitmap.h> #include <qtextstream.h> #include <qpixmap.h> #include "resources.h" #include "netnode.h" static char * ActionName[] = { "Disable", "Enable", "Activate", "Deactivate", "Up", "Down" }; static char * StateName[] = { "Unchecked", "Unknown", "Unavailable", "Disabled", "Off", "Available", "IsUp" }; QString & deQuote( QString & X ) { if( X[0] == '"' ) { // remove end and trailing "" and \x -> x QChar R; long idx; idx = X.length()-1; X = X.mid( 1, idx ); idx = 0; while( ( idx = X.find( '\\', idx ) ) >= 0 ) { R = X.at( idx + 1 ); X.replace( idx, 2, &R, 1 ); } X = X.left( X.length()-1 ); } return X; } QString quote( QString X ) { if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { // need to quote this QString OutString = "\""; X.replace( QRegExp("\""), "\\\"" ); X.replace( QRegExp("\\"), "\\\\" ); X.replace( QRegExp(" "), "\\ " ); OutString += X; OutString += "\""; X = OutString; } return X; } // // // ANETNODE // // void ANetNode::saveAttributes( QTextStream & TS ) { saveSpecificAttribute( TS ); } void ANetNode::setAttribute( QString & Attr, QString & Value ){ setSpecificAttribute( Attr, 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 ; } // // // ANETNODEINSTANCE // // long ANetNodeInstance::InstanceCounter = -1; void ANetNodeInstance::initialize( void ) { if( InstanceCounter == -1 ) InstanceCounter = time(0); // set name QString N; N.sprintf( "-%ld", InstanceCounter++ ); N.prepend( NodeType->name() ); setName( N.latin1() ); } void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ if( Attr == "__name" ) { setName( Value.latin1() ); } else { setSpecificAttribute( Attr, Value ); } } void ANetNodeInstance::saveAttributes( QTextStream & TS ) { TS << "__name=" << name() << endl; saveSpecificAttribute( TS ); } ANetNodeInstance * ANetNodeInstance::nextNode( void ) { return connection()->findNext( this ); } // // // NODECOLLECTION // // NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { IsModified = 0; Index = -1; Name=""; IsNew = 1; CurrentState = Unchecked; AssignedInterface = 0; + Number = -1; + Done = 0; } -NodeCollection::NodeCollection( QTextStream & TS ) : +NodeCollection::NodeCollection( QTextStream & TS, bool & Dangling ) : QList<ANetNodeInstance>() { long idx; - bool InError = 0; QString S, A, N; + + Number = -1; + Done = 0; IsModified = 0; Index = -1; Name=""; IsNew = 0; AssignedInterface = 0; CurrentState = Unchecked; + Dangling = 0; // by default node collection is ok + do { S = TS.readLine(); if( S.isEmpty() ) { - if( InError ) { - // remove all nodes - clear(); - } // empty line break; } idx = S.find('='); S.stripWhiteSpace(); A = S.left( idx ); A.lower(); N = S.mid( idx+1, S.length() ); N.stripWhiteSpace(); N = deQuote( N ); if( A == "name" ) { Name = N; } else if( A == "number" ) { setNumber( N.toLong() ); } else if( A == "node" ) { ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); Log(( "Find node %s : %p\n", N.latin1(), NNI )); - if( NNI && ! InError ) { + if( NNI ) { append( NNI ); } else { // could not find a node type -> collection invalid - InError = 1; + Log(( "Node %s missing -> connection dangling\n", + N.latin1() )); + // create placeholder for this dangling NNI + NNI = new ErrorNNI( N ); + Dangling = 1; } } } while( 1 ); Log(( "Profile number %s : %d nodes\n", Name.latin1(), count() )); } - NodeCollection::~NodeCollection( void ) { } const QString & NodeCollection::description( void ) { ANetNodeInstance * NNI = getToplevel(); return (NNI) ? NNI->runtime()->description() : Name; } void NodeCollection::append( ANetNodeInstance * NNI ) { NNI->setConnection( this ); QList<ANetNodeInstance>::append( NNI ); } void NodeCollection::save( QTextStream & TS ) { TS << "name=" << quote( Name ) << endl; TS << "number=" << number() << endl; ANetNodeInstance * NNI; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); TS << "node=" << NNI->name() << endl; } TS << endl; IsNew = 0; } ANetNodeInstance * NodeCollection::getToplevel( void ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); - if( NNI->nodeClass()->isToplevel() ) - break; + if( NNI->nodeClass()->isToplevel() ) { + return NNI; + } } - return NNI; + return 0; } ANetNodeInstance * NodeCollection::findByName( const QString & S ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); - if( NNI->name() == S ) - break; + if( NNI->name() == S ) { + return NNI; + } } - return NNI; + return 0; } ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { ANetNodeInstance * NNNI; if( ! NNI ) getToplevel(); for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNNI = it.current(); if( NNNI == NNI ) { ++it; return it.current(); } } return 0; // no more next } int NodeCollection::compareItems( QCollection::Item I1, QCollection::Item I2 ) { ANetNodeInstance * NNI1, * NNI2; NNI1 = (ANetNodeInstance *)I1; NNI2 = (ANetNodeInstance *)I2; return strcmp( NNI1->name(), NNI2->name() ); } static char * State2PixmapTbl[] = { "NULL", // Unchecked : no pixmap "check", // Unknown "delete", // unavailable "disabled", // disabled "off", // off "disconnected", // available "connected" // up }; QPixmap NodeCollection::devicePixmap( void ) { QPixmap pm = NSResources->getPixmap( getToplevel()->nextNode()->pixmapName()+"-large"); QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() ); if( pm.isNull() || Mini.isNull() ) return Resource::loadPixmap("Unknown"); QPainter painter( &pm ); painter.drawPixmap( pm.width()-Mini.width(), pm.height()-Mini.height(), Mini ); pm.setMask( pm.createHeuristicMask( TRUE ) ); return pm; } QPixmap NodeCollection::statePixmap( State_t S) { return NSResources->getPixmap( State2PixmapTbl[S] ); } QString NodeCollection::stateName( State_t S) { switch( S ) { case Unknown : return qApp->translate( "networksettings2", "Unknown"); case Unavailable : return qApp->translate( "networksettings2", "Unavailable"); case Disabled : return qApp->translate( "networksettings2", "Disabled"); case Off : return qApp->translate( "networksettings2", "Inactive"); case Available : return qApp->translate( "networksettings2", "Available"); case IsUp : return qApp->translate( "networksettings2", "Up"); case Unchecked : /* FT */ default : break; } return QString(""); } void NodeCollection::reassign( void ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { it.current()->setConnection( this ); } } const QStringList & NodeCollection::triggers() { return getToplevel()->runtime()->triggers(); } bool NodeCollection::hasDataForFile( SystemFile & S ) { return ( firstWithDataForFile( S ) != 0 ); } ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { if( it.current()->hasDataForFile( S ) ) { return it.current(); } } return 0; } 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 // // 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; } // set my own state Log (( "-> Act upon %s\n", netNode()->name() )); M = setMyState( NC, A, Force ); Log (( " result %s\n", M.latin1() )); return M; } diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 4626381..151d546 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -1,596 +1,638 @@ #ifndef NETNODE_H #define NETNODE_H #include <qtextstream.h> #include <qlist.h> #include <qdict.h> #include <qpixmap.h> #include <qstringlist.h> #include <qobject.h> #include <time.h> #include <Utils.h> #include <system.h> // difference feature interfaces class AsDevice; class AsLine; class AsConnection; class AsFullSetup; // needed for plugin creation function #include <qlist.h> class ANetNode; class ANetNodeInstance; class NodeCollection; class QTextStream; class RuntimeInfo; class InterfaceInfo; class NSResources; extern QString & deQuote( QString & X ); extern QString quote( QString X ); #include "systemfile.h" typedef enum State { // if we have not yet detected the state of the device Unchecked = 0, // if we cannot determine the state Unknown = 1, // if connection cannot be established e.g. because // the hardware is not available Unavailable = 2, // if the connection cannot be establishec but NOT // because it is physically impossible but because // it has been disabled for FUNCTIONAL reasons Disabled = 3, // if connection is available to is currently down // i.e. the corresponding hardware is not activated Off = 4, // if connection is available to be used (i.e. the // devices if fully ready to be used Available = 5, // if connection is being used IsUp = 6 } State_t; typedef enum Action { // to make the device unavailable functionally -> to disabled Disable = 0, // to make the device available functionally -> to off Enable = 1, // bring the hardware up -> to Available Activate = 2, // bring the hardware down -> to off Deactivate = 3, // bring the connection up -> to IsUp Up = 4, // bring the connection down -> to Available Down = 5 } Action_t; class ANetNode : public QObject { public: typedef QArray<ANetNode *> NetNodeList; ANetNode( const char * Name ) : QObject( 0, Name ) {} virtual ~ANetNode(){}; // // // standard methods with sensible default // // inline int done( void ) { return Done; } inline void setDone( int D ) { Done = D; } // does this Node provide a Connection bool isToplevel( void ); // set the value of an attribute void setAttribute( QString & Attr, QString & Value ) ; void saveAttributes( QTextStream & TS ) ; // compiled references to 'needed' NetNodes -> needs list inline void setAlternatives( NetNodeList * Alt ) { Alternatives = Alt; } inline NetNodeList & alternatives( void ) { return *Alternatives; } // // // Virtual methods with sensible default // // // do instances of this noce class have data for this file virtual bool hasDataForFile( SystemFile & ) { return 0; } // open proper file SF identified by S // this method is called by NS2. // // overrule this ONLY if this proper file is a common file // for all NNI of this node class and the data generated // by each of the NNI needs to be put in one file // // if this is the case the file should be (re)opened in append // return 0 if file cannot be opened virtual bool openFile( SystemFile &SF, ANetNodeInstance * NNI ); // generate instance independent stuff // 0 : data output, 1 no data, 2 error virtual short generatePreamble( SystemFile & ) { return 1; } // generate instance independent stuff // 0 : data output, 1 no data, 2 error virtual short generatePostamble( SystemFile & ) { return 1; } // generate instance dependent but instance common stuff // 0 : data output, 1 no data, 2 error virtual short generateFile( SystemFile &, ANetNodeInstance * , long ) { return 1; } // generate NIC name based on instance nr // only relevant if node instances are devices virtual QString genNic( long ) { return QString(""); } // max number of instances for this node type // only relevant if node instances are devices virtual long instanceCount( void ) { return 1; } // return ID list for each file generated specially for // this node type virtual QStringList properFiles( void ) { return QStringList(); } // // // pure virtual methods with sensible default // // // pixmap needed for this NetNode virtual const QString pixmapName() = 0; // description for this NetNode virtual const QString nodeDescription() = 0; // create a blank instance of a net node virtual ANetNodeInstance * createInstance( void ) = 0; // return features this NetNode provides virtual const char ** provides( void ) = 0; // return features this NetNode needs virtual const char ** needs( void ) = 0; protected : NetNodeList * Alternatives; private : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; int Done; }; class ANetNodeInstance : public QObject { public: ANetNodeInstance( ANetNode * NN ) : QObject() { IsModified=0; NodeType = NN; IsNew = TRUE; } virtual ~ANetNodeInstance( void ) { } inline int done( void ) { return Done; } inline void setDone( int D ) { Done = D; } // return data was modified inline void setModified( bool M ) { IsModified = M; } inline bool isModified( void ) { return IsModified; } // get next node ANetNodeInstance * nextNode(); // return NetNode this is an instance of ANetNode * nodeClass( void ) { return NodeType; } // intialize am instance of a net node void initialize( void ); // set the value of an attribute void setAttribute( QString & Attr, QString & Value ) ; void saveAttributes( QTextStream & TS ) ; // return true if node isntance is NEW and not loaded inline void setNew( bool IsN ) { IsNew = IsN; } inline bool isNew( void ) { return IsNew; } // return description for this instance inline QString & description( void ) { return Description; } inline void setDescription( const QString & S ) { Description = S; } // pixmap for this instance -> from NetNode inline const QString pixmapName( void ) { return NodeType->pixmapName(); } inline const char ** provides( void ) { return NodeType->provides(); } inline const char ** needs( void ) { return NodeType->needs(); } inline void setConnection( NodeCollection * NC ) { Connection = NC; } inline NodeCollection * connection( void ) { return Connection; } // // // Virtual methods with sensible defaults // // // open proper file identified by S virtual bool openFile( SystemFile & ) { return 0; } // check if this node (or sub nodes) have data for this file virtual bool hasDataForFile( SystemFile & S ) { return nodeClass()->hasDataForFile( S ); } // generate code specific for this node but embedded // in the section of the parent // this is called within the code of the parent virtual short generateFileEmbedded( SystemFile & SF, long DevNr ) { ANetNodeInstance * NNI = nextNode(); return (NNI) ? NNI->generateFileEmbedded( SF, DevNr ) : 1; } // generate code specific for this node // (or find the first node that does) virtual short generateFile( SystemFile & SF, long DevNr ) { ANetNodeInstance * NNI = nextNode(); return (NNI) ? NNI->generateFile( SF, DevNr ) : 1; } // return true if this node instance is triggered by this trigger // could be delegated to deeper instances virtual bool triggeredBy( const QString & ) { return 0; } // // // Pure virtual functions // // // return runtime information for this node virtual RuntimeInfo * runtime( void ) = 0; // create edit widget under parent virtual QWidget * edit( QWidget * parent ) = 0; // is given data acceptable virtual QString acceptable( void ) = 0; // get data from GUI and store in node virtual void commit( void ) = 0; // returns node specific data -> only useful for 'buddy' virtual void * data( void ) = 0; protected : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; ANetNode * NodeType; // connection to which this node belongs to NodeCollection * Connection; QString Description; bool IsModified; + // true if this nodeinstance was just created (and not + // loaded from file bool IsNew; int Done; static long InstanceCounter; }; +class ErrorNNI: public ANetNodeInstance { + +public: + + ErrorNNI( const QString & _Name ) : ANetNodeInstance( 0 ) { + setName( _Name.latin1() ); + } + + RuntimeInfo * runtime( void ) { + return 0; + } + + // create edit widget under parent + QWidget * edit( QWidget * parent ) { + return 0; + } + + // is given data acceptable + QString acceptable( void ) { + return QString(); + } + + // get data from GUI and store in node + void commit( void ) { + } + + // returns node specific data -> only useful for 'buddy' + void * data( void ) { + return 0; + } + +protected : + + void setSpecificAttribute( QString & , QString & ) { + } + + void saveSpecificAttribute( QTextStream & ) { + } +}; + class RuntimeInfo : public QObject { Q_OBJECT public : RuntimeInfo( ANetNodeInstance * TheNNI ) { NNI = TheNNI; } // // // methods to be overloaded by connection capable // runtimes // // // // // methods to be overloaded by device capable // runtimes // // // does this node handles this interface e.g.eth0 // recurse deeper if this node cannot answer that question virtual bool handlesInterface( const QString & S ) { RuntimeInfo * RI = device(); if( RI ) { return RI->handlesInterface( S ); } return 0; } bool handlesInterface( const InterfaceInfo & I ) { RuntimeInfo * RI = device(); if( RI ) { return RI->handlesInterface( I ); } return 0; } // // // methods to be overloaded by full setup capable // runtimes // // // return description for this full setup virtual const QString & description( void ) { return fullSetup()->description( ); } // return triggers that should fire when this // setup is brought up virtual const QStringList & triggers( void ) { return fullSetup()->triggers( ); } // // // methods to be overloaded by line capable // runtimes // // // return the device file ('/dev/xxx') created // by this line capable runtime virtual QString deviceFile( void ) { RuntimeInfo * RI = line(); if( RI ) { return RI->deviceFile(); } return QString(); } // // // runtime interface // // // return the node that offers device capability virtual RuntimeInfo * device( void ) { RuntimeInfo * RI = nextNode(); return (RI) ? RI->device() : 0; } // return the node that offers connection capability virtual RuntimeInfo * connection( void ) { RuntimeInfo * RI = nextNode(); return (RI) ? RI->connection() : 0; } // return the node that offers line capability virtual RuntimeInfo * line( void ) { RuntimeInfo * RI = nextNode(); return (RI) ? RI->line() : 0; } // return the node that offers full setup capability virtual RuntimeInfo * fullSetup( void ) { RuntimeInfo * RI = nextNode(); return (RI) ? RI->fullSetup() : 0; } inline ANetNodeInstance * netNode() { return NNI; } inline NodeCollection * nodeCollection() { return NNI->connection(); } virtual State_t detectState( void ) = 0; // public API to set the state virtual QString setState( NodeCollection * NC, Action_t A, bool Force = 0 ); inline RuntimeInfo * nextNode( void ) { ANetNodeInstance * NNI = netNode()->nextNode(); return (NNI) ? NNI->runtime() : 0; } signals : // sent by device if state changes void stateChanged( State_t S, ANetNodeInstance * NNI ); protected : // set state of this node (private API) virtual QString setMyState( NodeCollection * NC, Action_t A, bool Force = 0 ) = 0; // connection this runtime info belongs to ANetNodeInstance * NNI; }; class NodeCollection : public QList<ANetNodeInstance> { public : NodeCollection( void ); - NodeCollection( QTextStream & TS ); + NodeCollection( QTextStream & TS, bool & Dangling ); ~NodeCollection( void ); inline int done( void ) { return Done; } inline void setDone( int D ) { Done = D; } inline int number( void ) { return Number; } inline void setNumber( int i ) { Number = i; } inline bool isNew( void ) { return IsNew; } inline void setNew( bool N ) { IsNew = N ; } inline bool isModified( void ) { return IsModified; } inline void setModified( bool N ) { IsModified = N ; } inline bool handlesInterface( const QString & S ) { return getToplevel()->runtime()->handlesInterface( S ); } // return the interface in the OS that is assigned to // this device inline InterfaceInfo * assignedInterface( void ) { return AssignedInterface; } // assign the interface to this device inline void assignInterface( InterfaceInfo * NI ) { if( NI == 0 ) { if( AssignedInterface ) { AssignedInterface->assignConnection( 0 ); } } AssignedInterface = NI; if( AssignedInterface ) { AssignedInterface->assignConnection( this ); } } inline RuntimeInfo * device() { return getToplevel()->runtime()->device(); } const QStringList & triggers(); State_t state( bool Update = 0 ); // get the ixmap for this device QPixmap devicePixmap( void ); QPixmap statePixmap( State_t S ); inline QPixmap statePixmap( bool Update = 0 ) { return statePixmap( state(Update) ); } QString stateName( State_t ); inline QString stateName( bool Update = 0 ) { return stateName( state(Update) ); } QString setState( Action_t A, bool Force = 0 ); void save( QTextStream & TS ); void append( ANetNodeInstance * NNI ); // makes sure that all items in the connection point to // that connectoin void reassign( void ); ANetNodeInstance * getToplevel( void ); ANetNodeInstance * findNext( ANetNodeInstance * NNI ); ANetNodeInstance * findByName( const QString & S ); inline const QString & name() { return Name; } const QString & description( void ); inline void setName( const QString & N) { Name = N; } inline State_t currentState( void ) { return CurrentState; } inline void setCurrentState( State_t S ) { CurrentState = S; } // return TRUE if this node can have data to be inserted in // file identified by S bool hasDataForFile( SystemFile & S ); ANetNodeInstance * firstWithDataForFile( SystemFile & ); // generate items for this file -> toplevel call short generateFile( SystemFile & SF, long DN // device number ) { return getToplevel()->generateFile( SF, DN ); } bool triggeredBy( const QString & Trigger ) { return getToplevel()->triggeredBy( Trigger ); } private : int compareItems ( QCollection::Item item1, QCollection::Item item2 ); long Number; // state of this connection State_t CurrentState; QString Name; // true if this collection was just created (and not // loaded from file bool IsNew; // index in listbox - int Index; + int Index; bool IsModified; - int Done; + int Done; InterfaceInfo * AssignedInterface; }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h index 34f3bb5..06d1548 100644 --- a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h +++ b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h @@ -1,139 +1,149 @@ /* This file is part of the Opie Project Copyright (C) 2005 Holger Hans Peter Freyther <freyther@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef ANET_NODE_INTERFACE_H #define ANET_NODE_INTERFACE_H #include <opie2/oapplicationfactory.h> #include <qpe/qcom.h> // {A215A785-FB73-4F74-84B0-053BCC77DB87} #ifndef IID_NetworkSettings2 #define IID_NetworkSettings2 QUuid( 0xa215a785, 0xfb73, 0x4f74, 0x84, 0xb0, 0x05, 0x3b, 0xcc, 0x77, 0xdb, 0x87) #endif /** * Multiple Types */ template <class Node > struct NS2PrivateFactory { inline static void createPlugins( QList<ANetNode> & PNN) { PNN.append( new Node()); } }; /* * Stop recursion here */ template <> struct NS2PrivateFactory<Opie::Core::NullType> { inline static void createPlugins( QList<ANetNode> &) { } }; template <class Node, class Tail> struct NS2PrivateFactory<Opie::Core::Typelist<Node, Tail> > { inline static void createPlugins( QList<ANetNode> & PNN ) { NS2PrivateFactory<Node>::createPlugins(PNN); NS2PrivateFactory<Tail>::createPlugins(PNN); } }; +class NetNodeInterface : public QUnknownInterface { + +public : + + virtual QRESULT queryInterface( const QUuid& uuid, + QUnknownInterface **iface ) = 0; + + virtual void create_plugin( QList<ANetNode> & PNN ) = 0; +}; + template<class Node> -struct NetNodeInterface : public QUnknownInterface { +struct NetNodeInterface_T : public NetNodeInterface { QRESULT queryInterface(const QUuid& uuid, QUnknownInterface **iface) { *iface = 0; if( uuid == IID_QUnknown ) *iface = this; else if( uuid == IID_NetworkSettings2 ) *iface = this; else return QS_FALSE; (*iface)->addRef(); return QS_OK; } void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new Node()); } Q_REFCOUNT }; template<class Node, class Tail> -struct NetNodeInterface<Opie::Core::Typelist<Node, Tail> > - : public QUnknownInterface { +struct NetNodeInterface_T<Opie::Core::Typelist<Node, Tail> > + : public NetNodeInterface { QRESULT queryInterface( const QUuid& uuid, QUnknownInterface **iface) { *iface = 0; if( uuid == IID_QUnknown ) *iface = this; else if( uuid == IID_NetworkSettings2 ) *iface = this; else return QS_FALSE; (*iface)->addRef(); return QS_OK; } void create_plugin( QList<ANetNode> & PNN ) { - NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugin( PNN ); + NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugins( PNN ); } Q_REFCOUNT }; #define OPIE_NS2_PLUGIN( factory ) \ Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( factory) } #endif diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 79d41ea..3479abb 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -1,610 +1,479 @@ #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <pwd.h> #include <qpixmap.h> #include <qdir.h> #include <qmessagebox.h> #include <qpe/qlibrary.h> #include <qpe/qpeapplication.h> #include <opie2/odebug.h> #include <opie2/opluginloader.h> #include <qtopia/resource.h> #include "netnode.h" #include "resources.h" #include "netnodeinterface.h" #define PLUGINDIR "plugins/networksettings2" #define ICONDIR "/pics/networksettings2/" // single resources instance TheNSResources * _NSResources = 0; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), - ConnectionsMap() { + ConnectionsMap(), DanglingConnectionsMap() { _NSResources = this; detectCurrentUser(); // load available netnodes -#ifdef MYPLUGIN - - findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); - - // compile provides and needs lists - { const char ** NeedsRun; - QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); - bool Done; - - for ( ; OuterIt.current(); ++OuterIt ) { - // find needs list - ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; - ANetNode::NetNodeList & NNL = *(NNLP); - - // must iterate this way to avoid duplication pointers - for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); - InnerIt.current(); ++InnerIt ) { - if( InnerIt.current() == OuterIt.current() ) - // avoid recursive - continue; - - const char ** Provides = InnerIt.current()->NetNode->provides(); - NeedsRun = OuterIt.current()->NetNode->needs(); - - for( ; *NeedsRun; NeedsRun ++ ) { - const char ** PRun; - PRun = Provides; - for( ; *PRun; PRun ++ ) { - if( strcmp( *PRun, *NeedsRun ) == 0 ) { - // inner provides what outer needs - NNL.resize( NNL.size() + 1 ); - NNL[NNL.size()-1] = InnerIt.current()->NetNode; - Done = 1; // break from 2 loops - break; - } - } - } - } - OuterIt.current()->NetNode->setAlternatives( NNLP ); - } - } - -#else - Plugins = 0; findAvailableNetNodes(); // compile provides and needs lists { const char ** NeedsRun; QDictIterator<ANetNode> OuterIt( AllNodeTypes ); bool Done; for ( ; OuterIt.current(); ++OuterIt ) { // find needs list ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; ANetNode::NetNodeList & NNL = *(NNLP); // must iterate this way to avoid duplication pointers for ( QDictIterator<ANetNode> InnerIt( AllNodeTypes ); InnerIt.current(); ++InnerIt ) { if( InnerIt.current() == OuterIt.current() ) // avoid recursive continue; const char ** Provides = InnerIt.current()->provides(); NeedsRun = OuterIt.current()->needs(); for( ; *NeedsRun; NeedsRun ++ ) { const char ** PRun; PRun = Provides; for( ; *PRun; PRun ++ ) { if( strcmp( *PRun, *NeedsRun ) == 0 ) { // inner provides what outer needs NNL.resize( NNL.size() + 1 ); NNL[NNL.size()-1] = InnerIt.current(); Done = 1; // break from 2 loops break; } } } } OuterIt.current()->setAlternatives( NNLP ); } } -#endif - // define built in Node types to Description map addNodeType( "device", tr( "Network Device" ), tr( "<p>Devices that can handle IP packets</p>" ) ); addNodeType( "line", tr( "Character device" ), tr( "<p>Devices that can handle single bytes</p>" ) ); addNodeType( "connection", tr( "IP Connection" ), tr( "<p>Nodes that provide working IP connections</p>" ) ); addNodeType( "fullsetup", tr( "Connection Profile" ), tr( "<p>Fully configured connection profile</p>" ) ); addNodeType( "GPRS", tr( "Connection to GPRS device" ), tr( "<p>Connection to a GPRS capable device</p>" ) ); // get access to the system TheSystem = new System(); } TheNSResources::~TheNSResources( void ) { -#ifndef MYPLUGINS if( Plugins ) { delete Plugins; delete PluginManager; } -#endif delete TheSystem; } void TheNSResources::addNodeType( const QString & ID, const QString & Name, const QString & Descr ) { if( NodeTypeNameMap[ID].isEmpty() ) { NodeTypeNameMap.insert( ID, Name ); NodeTypeDescriptionMap.insert( ID, Descr ); } } void TheNSResources::addSystemFile( const QString & ID, const QString & P, bool KDI ) { if( ! SystemFiles.find( ID ) ) { // new system file SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); } // else existed } void TheNSResources::busy( bool ) { /* if( B ) { ShowWait->show(); qApp->process } else { ShowWait->hide(); } */ } -#ifdef MYPLUGIN -/** - * Load all modules that are found in the path - * @param path a directory that is scaned for any plugins that can be loaded - * and attempts to load them - */ -void TheNSResources::findAvailableNetNodes(const QString &path){ - - Log(("Locate plugins in %s\n", path.latin1() )); - QDir d(path); - if(!d.exists()) - return; - - QString lang = ::getenv("LANG"); - - // Don't want sym links - d.setFilter( QDir::Files | QDir::NoSymLinks ); - const QFileInfoList *list = d.entryInfoList(); - QFileInfoListIterator it( *list ); - QFileInfo *fi; - - while ( (fi=it.current()) ) { - - if( fi->fileName().contains(".so")){ - /* if loaded install translation */ - if( loadNetNode(path + "/" + fi->fileName()) ) { - Log(( "Loading plugin %s\n", fi->fileName().latin1())); - QTranslator *trans = new QTranslator(qApp); - QString fn = QPEApplication::qpeDir()+ - "/i18n/"+lang+"/"+ - fi->fileName().left( fi->fileName().find(".") )+ - ".qm"; - - if( trans->load( fn ) ) - qApp->installTranslator( trans ); - else - delete trans; - } else { - Log(( "Error loading plugin %s\n", fi->fileName().latin1())); - } - } - ++it; - } -} - -/** - * Attempt to load a function and resolve a function. - * @param pluginFileName - the name of the file in which to attempt to load - * @param resolveString - function pointer to resolve - * @return true of loading is successful - */ -bool TheNSResources::loadNetNode( - const QString &pluginFileName, const QString &resolveString){ - - QLibrary *lib = new QLibrary(pluginFileName); - void * res = lib->resolve(resolveString); - if( ! res ){ - delete lib; - return 0; - } - - GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; - - // Try to get an object. - QList<ANetNode> PNN; - - getNetNodeList( PNN ); - if( PNN.isEmpty() ) { - delete lib; - return 0; - } - - ANetNode * NNP; - for( QListIterator<ANetNode> it(PNN); - it.current(); - ++it ) { - NetNode_t * NN; - - NNP = it.current(); - NN = new NetNode_t; - NN->NetNode = NNP; - NN->TheLibrary = lib; - NN->NodeCountInLib = PNN.count(); - - // store mapping - AllNodeTypes.insert( NN->NetNode->name(), NN ); - } - - return 1; -} - -#else - void TheNSResources::findAvailableNetNodes( void ){ Plugins = new OPluginLoader( "networksettings2" ); Plugins->setAutoDelete( true ); PluginManager = new OPluginManager( Plugins ); PluginManager->load(); if( Plugins->isInSafeMode() ) { QMessageBox::information( 0, tr( "Today Error"), tr( "<qt>The plugin '%1' caused Today to crash." " It could be that the plugin is not properly" " installed.<br>Today tries to continue loading" " plugins.</qt>" ) .arg( PluginManager->crashedPlugin().name())); } // Get All Plugins OPluginLoader::List allplugins = Plugins->filtered(); + QString lang = ::getenv("LANG"); for( OPluginLoader::List::Iterator it = allplugins.begin(); it != allplugins.end(); ++it ) { // check if this plugin supports the proper interface NetNodeInterface * interface = Plugins->load<NetNodeInterface>( *it, IID_NetworkSettings2 ); if( ! interface ) { Log(( "Plugin %s from %s does not support proper interface\n", - it->name().latin1(), it->path().latin1() )); + (*it).name().latin1(), (*it).path().latin1() )); continue; } // add the nodes in this plugin to the dictionary { QList<ANetNode> PNN; interface->create_plugin( PNN ); if( PNN.isEmpty() ) { Log(( "Plugin %s from %s does offer any nodes\n", - it->name().latin1(), it->path().latin1() )); + (*it).name().latin1(), (*it).path().latin1() )); delete interface; continue; } // merge this node with global node for( QListIterator<ANetNode> it(PNN); it.current(); ++it ) { - AllNodeTypes.insert( it->current()->name(), it->current() ); + AllNodeTypes.insert( it.current()->name(), it.current() ); } } // load the translation QTranslator *trans = new QTranslator(qApp); QString fn = QPEApplication::qpeDir()+ - "/i18n/"+lang+"/"+ it->name() + ".qm"; + "/i18n/"+lang+"/"+ (*it).name() + ".qm"; if( trans->load( fn ) ) qApp->installTranslator( trans ); else delete trans; } } -#endif - // used to find unique connection number int TheNSResources::assignConnectionNumber( void ) { bool found = 1; for( int trial = 0; ; trial ++ ) { found = 1; for( QDictIterator<NodeCollection> it(ConnectionsMap); it.current(); ++it ) { if( it.current()->number() == trial ) { found = 0; break; } } if( found ) { Log(("Assign profile number %d\n", trial )); return trial; } } } QPixmap TheNSResources::getPixmap( const QString & QS ) { QPixmap P; QString S("networksettings2/"); S += QS; P = Resource::loadPixmap( S ); if( P.isNull() ) { Log(( "Cannot load %s\n", S.latin1() )); } return ( P.isNull() ) ? QPixmap() : P; } QString TheNSResources::tr( const char * s ) { return qApp->translate( "resource", s ); } const QString & TheNSResources::netNode2Name( const char * s ) { return NodeTypeNameMap[s]; } const QString & TheNSResources::netNode2Description( const char * s ) { return NodeTypeDescriptionMap[s]; } -void TheNSResources::addConnection( NodeCollection * NC ) { +void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) { ANetNodeInstance * NNI; - ConnectionsMap.insert( NC->name(), NC ); + if( Dangling ) { + DanglingConnectionsMap.insert( NC->name(), NC ); + } else { + ConnectionsMap.insert( NC->name(), NC ); + } + // add (new) nodes to NodeList for( QListIterator<ANetNodeInstance> it(*NC); it.current(); ++it ) { NNI = it.current(); if( findNodeInstance( NNI->name() ) == 0 ) { // new item addNodeInstance( NNI ); } } } void TheNSResources::removeConnection( const QString & N ) { NodeCollection * NC = findConnection( N ); if( ! NC ) return; // delete netnodes in this connection ANetNodeInstance * NNI; for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { removeNodeInstance( NNI->name() ); } - ConnectionsMap.remove( N ); + if( ConnectionsMap.find( N ) ) { + ConnectionsMap.remove( N ); + } else { + DanglingConnectionsMap.remove( N ); + } + } +// dangling connections are filtered out NodeCollection * TheNSResources::findConnection( const QString & S ) { return ConnectionsMap[ S ]; } NodeCollection * TheNSResources::getConnection( int nr ) { for( QDictIterator<NodeCollection> it(ConnectionsMap); it.current(); ++it ) { if( it.current()->number() == nr ) { return it.current(); } } return 0; } /* void TheNSResources::renumberConnections( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections NodeCollection::resetMaxNr(); for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); NC->setNumber( NC->maxConnectionNumber()+1 ); NC->setModified( 1 ); } } */ typedef struct EnvVars { char * Name; int Len; } EnvVar_t; #define AnEV(x) x, sizeof(x)-1 static EnvVar_t EV[] = { AnEV( "HOME" ), AnEV( "LOGNAME" ), AnEV( "USER" ), AnEV( "LD_LIBRARY_PATH" ), AnEV( "PATH" ), AnEV( "QTDIR" ), AnEV( "OPIEDIR" ), AnEV( "SHELL" ), { NULL, 0 } }; void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; CurrentUser.UserName = ""; CurrentUser.HomeDir = ""; if( getenv( "OPIEDIR" ) == 0 ) { // nothing known { // open proc dir and find all dirs in it QRegExp R("[0-9]+"); QDir ProcDir( "/proc" ); QFileInfo FI; QStringList EL = ProcDir.entryList( QDir::Dirs ); // print it out for ( QStringList::Iterator it = EL.begin(); it != EL.end(); ++it ) { if( R.match( (*it) ) >= 0 ) { QString S = ProcDir.path()+"/"+ (*it); S.append( "/exe" ); FI.setFile( S ); // get the link S = FI.readLink(); if( S.right( 8 ) == "/bin/qpe" ) { // found running qpe QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); break; } } } } if( QPEEnvFile.isEmpty() ) { // could not find qpe Log(("Could not find qpe\n" )); return; } // FI now contains path ProcDir to the cmd dir { char * Buf = 0; char TB[1024]; long BufSize = 0; int fd; int rd; fd = open( QPEEnvFile.latin1(), O_RDONLY ); if( fd < 0 ) { Log(("Could not open %s : %d\n", QPEEnvFile.latin1(), errno )); return; } while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { Buf = (char *)realloc( Buf, BufSize+rd ); memcpy( Buf+BufSize, TB, rd ); BufSize += rd; } char * Data = Buf; char * DataEnd = Data+BufSize-1; // get env items out of list while( Data < DataEnd ) { EnvVar_t * Run = EV; while( Run->Name ) { if( strncmp( Data, Run->Name, Run->Len ) == 0 && Data[Run->Len] == '=' ) { CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( Data ); if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { // put OPIEDIR in env putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); } else if( strcmp( Run->Name, "HOME" ) == 0 ) { CurrentUser.HomeDir = Data+5; } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { CurrentUser.UserName = Data+8; } break; } Run ++; } Data += strlen( Data )+1; } free( Buf ); if( ! CurrentUser.UserName.isEmpty() ) { // find user info struct passwd pwd; struct passwd * pwdres; if( getpwnam_r( CurrentUser.UserName.latin1(), &pwd, TB, sizeof(TB), &pwdres ) || pwdres == 0 ) { Log(("Could not determine user %s : %d\n", CurrentUser.UserName.latin1(), errno )); return; } CurrentUser.Uid = pwd.pw_uid; CurrentUser.Gid = pwd.pw_gid; } else{ CurrentUser.Uid = CurrentUser.Gid = -1; } } } else { char * X; QString S; EnvVar_t * Run = EV; while( Run->Name ) { if( ( X = getenv( Run->Name ) ) ) { Log(( "Env : %s = %s\n", Run->Name, X )); S.sprintf( "%s=%s", Run->Name, X ); CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( S.latin1() ); if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { CurrentUser.UserName = X; } else if( strcmp( Run->Name, "HOME" ) == 0 ) { CurrentUser.HomeDir = X; } // regulare env var } else { Log(("Could not determine %s\n", Run->Name )); } Run ++; } CurrentUser.Uid = getuid(); CurrentUser.Gid = getgid(); } } diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 421a433..b27cda1 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -1,183 +1,153 @@ #ifndef __RESOURCES__H #define __RESOURCES__H #include <qstring.h> #include <qdict.h> #include <qmap.h> #include <qlist.h> #include "netnode.h" #include "systemfile.h" #include "system.h" class QLibrary; class QPixmap; class ANetNode; class ANetNodeInstance; namespace Opie { namespace Core { class OPluginLoader; class OPluginManager; } } typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); class CurrentQPEUser { public : CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} inline bool known( void ) { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } QString UserName; QString HomeDir; int Uid; int Gid; QArray<char *> EnvList; }; -#ifdef MYPLUGIN - -typedef struct NetNode_S { - ANetNode * NetNode; - QLibrary * TheLibrary; - long NodeCountInLib; -} NetNode_t; -typedef QDict<NetNode_t> Name2NetNode_t; - -#else - typedef QDict<ANetNode> Name2NetNode_t; - -#endif - typedef QDict<ANetNodeInstance > Name2Instance_t; typedef QDict<NodeCollection> Name2Connection_t; typedef QDict<SystemFile> Name2SystemFile_t; class TheNSResources { public : TheNSResources( void ); ~TheNSResources( ); // give busy feedback void busy( bool B ); System & system() { return *TheSystem; } int assignConnectionNumber(void); QPixmap getPixmap( const QString & Name ); Name2NetNode_t & netNodes( void ) { return AllNodeTypes; } bool netNodeExists( const QString & X ) { return AllNodeTypes.find(X)!=0; } -#ifdef MYPLUGIN - ANetNode * findNetNode( const QString & N ) - { NetNode_t * NNT = AllNodeTypes.find(N); - return (NNT) ? NNT->NetNode : 0; - } -#else ANetNode * findNetNode( const QString & N ) { return AllNodeTypes.find(N); } -#endif // define new plugin (=node) void addNodeType( const QString & ID, const QString & LongName, const QString & Description ); Name2SystemFile_t & systemFiles( void ) { return SystemFiles; } void addSystemFile( const QString & ID, const QString & P, bool KDI ); ANetNodeInstance * createNodeInstance( const QString & S ) - { ANetNodeInstance * NNI = 0; - printf( "Find node type %s\n", S.latin1() ); -#ifdef MYPLUGIN - NetNode_t * NNT = AllNodeTypes[S]; - if( ! NNT ) { - return 0; - } - NNI = NNT->NetNode->createInstance(); -#else - ANetNode * NNT = AllNodeTypes[S]; - if( ! NNT ) { + { ANetNode * NN = findNetNode( S ); + + Log(( "Find node type %s : %p\n", S.latin1(), NN )); + + if( NN == 0 ) + // type of this instance not found return 0; - } - NNI = NNT->createInstance(); -#endif + + ANetNodeInstance * NNI = NN->createInstance(); NNI->initialize(); return NNI; } Name2Instance_t & netNodeInstances( void ) { return AllNodes; } void addNodeInstance( ANetNodeInstance * I ) { AllNodes.insert( I->name(), I ); } void removeNodeInstance( const QString & N ) { AllNodes.remove( N );} ANetNodeInstance * findNodeInstance( const QString & S ) { return AllNodes[S]; } const QString & netNode2Name( const char * Type ); const QString & netNode2Description( const char * Type ); - void addConnection( NodeCollection * NC ); + void addConnection( NodeCollection * NC, bool Dangling ); void removeConnection( const QString & N ); NodeCollection * findConnection( const QString & N ); NodeCollection * getConnection( int nr ); Name2Connection_t & connections( void ) { return ConnectionsMap; } + Name2Connection_t & danglingConnections( void ) + { return ConnectionsMap; } inline bool userKnown( void ) { return CurrentUser.known(); } CurrentQPEUser & currentUser( void ) { return CurrentUser; } private : void detectCurrentUser( void ); QString tr( const char * path ); -#ifdef MYPLUGIN - void findAvailableNetNodes( const QString &path ); - bool loadNetNode( - const QString &pluginFileName, - const QString &resolveString = "create_plugin"); -#else void findAvailableNetNodes( void ); -#endif QMap< QString, QString> NodeTypeNameMap; QMap< QString, QString> NodeTypeDescriptionMap; + // list of connections that are valid Name2Connection_t ConnectionsMap; + // list of connection configurations that are not valid + // e.g. because plugins are missing + Name2Connection_t DanglingConnectionsMap; System * TheSystem; Name2SystemFile_t SystemFiles; // all node type classes Name2NetNode_t AllNodeTypes; // all nodes Name2Instance_t AllNodes; CurrentQPEUser CurrentUser; -#ifndef MYPLUGIN Opie::Core::OPluginLoader * Plugins; Opie::Core::OPluginManager * PluginManager; -#endif }; extern TheNSResources * _NSResources; #define NSResources _NSResources #endif diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 698a941..d76353a 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -1,725 +1,743 @@ #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 ) ) { NodeCollection * NC; interfacename = TS.readLine(); F->close(); Log(( "Assign interface %s to Profile nr %d\n", interfacename.latin1(), profilenr )); NC = NSResources->getConnection( profilenr ); if( NC ) { NC->assignInterface( NSResources->system().findInterface( interfacename ) ); } 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> [connection] 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 == "connection" ) { // load connections -> collections of nodes - NodeCollection * NC = new NodeCollection( TS ); - NSResources->addConnection( NC ); + bool Dangling; + NodeCollection * NC = new NodeCollection( TS, Dangling ); + NSResources->addConnection( 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( NN || NNI ) { - 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; - } + 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 ); - } + Value.stripWhiteSpace(); + Attr.stripWhiteSpace(); + Attr.lower(); + // dequote Attr + Value = deQuote(Value); + + if( NN ) { + // set the attribute + NN->setAttribute( Attr, Value ); } else { - LeftOvers.append( Line ); - // add empty line too as delimiter - if( S.isEmpty() ) { - // empty line - break; - } + // 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 leftovers - for ( QStringList::Iterator it = LeftOvers.begin(); - it != LeftOvers.end(); ++it ) { - TS << (*it) << endl; - } - // save global configs - for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); + for( QDictIterator<ANetNode> it( NSResources->netNodes() ); it.current(); ++it ) { TS << "[nodetype " - << quote( QString( it.current()->NetNode->name() ) ) + << quote( QString( it.current()->name() ) ) << "]" << endl; - it.current()->NetNode->saveAttributes( TS ); + 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 connections { Name2Connection_t & M = NSResources->connections(); - ANetNodeInstance * NNI; // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { - // all nodes in those connections - for( QListIterator<ANetNodeInstance> nit(*(it.current())); - nit.current(); - ++nit ) { - // header - NNI = nit.current(); - TS << '[' - << QString(NNI->nodeClass()->name()) - << ']' - << endl; - NNI->saveAttributes( TS ); - TS << endl; - } + TS << "[connection]" << endl; + it.current()->save(TS); + } + } + // save dangling connections + { Name2Connection_t & M = NSResources->danglingConnections(); + + // for all connections + for( QDictIterator<NodeCollection> it(M); + it.current(); + ++it ) { TS << "[connection]" << endl; it.current()->save(TS); } } QDir D("."); D.rename( CfgFile + ".bup", CfgFile ); // // proper files AND system files regenerated // for( QDictIterator<NodeCollection> it(NSResources->connections()); it.current(); ++it ) { it.current()->setModified( 0 ); } return ErrS; } QString NetworkSettingsData::generateSettings( void ) { QString S = ""; Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2Connection_t & M = NSResources->connections(); NodeCollection * 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<NetNode_t> nnit( NSResources->netNodes() ); + for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { - { QStringList SL; - bool FirstItem = 1; - bool Generated = 0; + bool FirstItem = 1; + bool Generated = 0; - CurDevNN = nnit.current()->NetNode; + 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<NetNode_t> nnit( NSResources->netNodes() ); + for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { - nnit.current()->NetNode->setDone(0); + nnit.current()->setDone(0); } for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); nniit.current(); ++nniit ) { nniit.current()->setDone(0); } for( QDictIterator<NodeCollection> 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<NetNode_t> nnit( NSResources->netNodes() ); + for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); ! needToGenerate && nnit.current(); ++nnit ) { - NN = nnit.current()->NetNode; + 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 connections that want to write to this file for( QDictIterator<NodeCollection> 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 connection %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 connection 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 nodeconnections that work on the same device for( QDictIterator<NodeCollection> ncit2(M); ncit2.current(); ++ncit2 ) { if( ncit2.current()->device() != CurDev ) { // different device continue; } Log(("Connection %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<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { // collect connections that can work on top of this interface NodeCollection * NC; QList<NodeCollection> PossibleConnections; Name2Connection_t & M = NSResources->connections(); // for all connections for( QDictIterator<NodeCollection> 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 not enabled NC->state() != IsUp // if already used ) { Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); PossibleConnections.append( NC ); } } return PossibleConnections; } /* Called by the system to see if interface can be brought UP if allowed, echo Interface-allowed else Interface-disallowed */ bool NetworkSettingsData::canStart( const char * Interface ) { // load situation NodeCollection * NC = 0; QList<NodeCollection> PossibleConnections; PossibleConnections = collectPossible( Interface ); Log( ( "for %s : Possiblilies %d\n", Interface, PossibleConnections.count() )); switch( PossibleConnections.count() ) { case 0 : // no connections break; case 1 : // one connection NC = PossibleConnections.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(( "%s-c%d-disallowed : %s\n", Interface, NC->number(), S.latin1() )); break; } // interface assigned } // FT case Available : case IsUp : // also called for 'ifdown' // device is ready -> done Log(( "%s-c%d-allowed\n", Interface, NC->number() )); printf( "%s-c%d-allowed\n", Interface, NC->number() ); return 0; } } // if we come here no alternatives are possible Log(( "%s-cnn-disallowed\n", Interface )); printf( "%s-cnn-disallowed\n", Interface ); return 0; } bool NetworkSettingsData::isModified( void ) { if( ForceModified ) return 1; for( QDictIterator<NodeCollection> it(NSResources->connections()); it.current(); ++it ) { if( it.current()->isModified() ) { return 1; } } return 0; } diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.cpp b/noncore/settings/networksettings2/ppp/ppp_NN.cpp index bd13ab9..8c15e9c 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NN.cpp @@ -1,100 +1,83 @@ #include <qfile.h> #include <resources.h> #include <qtextstream.h> #include "ppp_NN.h" #include "ppp_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - QStringList * PPPNetNode::ProperFiles = 0; static const char * PPPNeeds[] = { "modem", 0 }; static const char * PPPProvides[] = { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ PPPNetNode::PPPNetNode() : ANetNode(tr("PPP Connection")) { NSResources->addSystemFile( "pap-secrets", "/etc/ppp/pap-secrets", 0 ); NSResources->addSystemFile( "chap-secrets", "/etc/ppp/chap-secrets", 0 ); } /** * Delete any interfaces that we own. */ PPPNetNode::~PPPNetNode(){ } const QString PPPNetNode::nodeDescription(){ return tr("\ <p>Sets up IP using PPP.</p>\ <p>Use this for dialup devices or serial setups</p>\ " ); } ANetNodeInstance * PPPNetNode::createInstance( void ) { return new APPP( this ); } const char ** PPPNetNode::needs( void ) { return PPPNeeds; } const char ** PPPNetNode::provides( void ) { return PPPProvides; } QStringList PPPNetNode::properFiles( void ) { QStringList SL; SL << "peers" << "chatscripts"; return SL; } // need to generate : // /etc/ppp/pap-secrets // /etc/ppp/pap-secrets bool PPPNetNode::hasDataForFile( SystemFile & S ) { return S.name() == "pap-secrets" || S.name() == "chap-secrets" ; } QString PPPNetNode::genNic( long NicNr ) { QString S; return S.sprintf( "ppp%ld", NicNr ); } void PPPNetNode::setSpecificAttribute( QString & , QString & ) { } void PPPNetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new PPPNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<PPPNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<PPPNetNode> ) diff --git a/noncore/settings/networksettings2/profile/profile_NN.cpp b/noncore/settings/networksettings2/profile/profile_NN.cpp index 6028ea5..1e6912e 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.cpp +++ b/noncore/settings/networksettings2/profile/profile_NN.cpp @@ -1,75 +1,58 @@ #include <resources.h> #include "profile_NN.h" #include "profile_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * ProfileNeeds[] = { "connection", 0 }; static const char * ProfileProvides[] = { "fullsetup", 0 }; /** * Constructor, find all of the possible interfaces */ ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular connection profile")) { NSResources->addSystemFile( "interfaces", "/etc/network/interfaces", 1 ); } /** * Delete any interfaces that we own. */ ProfileNetNode::~ProfileNetNode(){ } const QString ProfileNetNode::nodeDescription(){ return tr("\ <p>Define use of an IP connection.</p>\ <p>Configure if and when this connection needs to be established</p>\ " ); } ANetNodeInstance * ProfileNetNode::createInstance( void ) { return new AProfile( this ); } const char ** ProfileNetNode::needs( void ) { return ProfileNeeds; } const char ** ProfileNetNode::provides( void ) { return ProfileProvides; } void ProfileNetNode::setSpecificAttribute( QString & , QString & ) { } void ProfileNetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new ProfileNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<ProfileNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<ProfileNetNode> ) diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index 9c07b82..6d90ae0 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -1,77 +1,60 @@ #include <resources.h> #include "usb_NN.h" #include "usb_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * USBNeeds[] = { 0 }; static const char * USBProvides[] = { "device", 0 }; /** * Constructor, find all of the possible interfaces */ USBNetNode::USBNetNode() : ANetNode(tr("USB Cable Connect")) { NSResources->addSystemFile( "interfaces", "/etc/network/interfaces", 1 ); } /** * Delete any interfaces that we own. */ USBNetNode::~USBNetNode(){ } const QString USBNetNode::nodeDescription(){ return tr("\ <p>Configure Ethernet over USB.</p>\ <p>Use this for a computer to computer USB cable connection</p>\ " ); } ANetNodeInstance * USBNetNode::createInstance( void ) { return new AUSB( this ); } const char ** USBNetNode::needs( void ) { return USBNeeds; } const char ** USBNetNode::provides( void ) { return USBProvides; } QString USBNetNode::genNic( long ) { return QString( "usbf" ); } void USBNetNode::setSpecificAttribute( QString & , QString & ) { } void USBNetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new USBNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<USBNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<USBNetNode> ) diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index 0a46642..eb439c1 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -1,124 +1,119 @@ #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; } } } } 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 for( QDictIterator<InterfaceInfo> It(Sys.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 && ! Run->IsUp ) { // proper type, and Not UP -> free - return Off; + // 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 ) { // nothing needs to be done to 'activate' or 'deactivate' // a cable - - // perhaps (later) we can figure out if the device is IN the - // cradle - if( A == Activate ) { - NC->setCurrentState( Available ); - } else if ( A == Deactivate ) { - NC->setCurrentState( Unavailable ); - } - return QString(); } // get interface that is free or assigned to us InterfaceInfo * USBRun::getInterface( void ) { System & S = NSResources->system(); InterfaceInfo * best = 0, * Run; QRegExp R( "usb[0-9abcdef]" ); for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); 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->assignedConnection() == 0 ) { // free best = Run; } } } 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/vpn/vpn_NN.cpp b/noncore/settings/networksettings2/vpn/vpn_NN.cpp index 6dd5332..96e9df2 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NN.cpp @@ -1,69 +1,52 @@ #include "vpn_NN.h" #include "vpn_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * VPNNeeds[] = { 0 }; static const char * VPNProvides[] = { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ VPNNetNode::VPNNetNode() : ANetNode(tr("VPN Connection")) { } /** * Delete any interfaces that we own. */ VPNNetNode::~VPNNetNode(){ } const QString VPNNetNode::nodeDescription(){ return tr("\ <p>Configure private IP connection.</p>\ <p>Defines Secure tunnels over non secure IP sessions</p>\ " ); } ANetNodeInstance * VPNNetNode::createInstance( void ) { return new AVPN( this ); } const char ** VPNNetNode::needs( void ) { return VPNNeeds; } const char ** VPNNetNode::provides( void ) { return VPNProvides; } void VPNNetNode::setSpecificAttribute( QString & , QString & ) { } void VPNNetNode::saveSpecificAttribute( QTextStream & ) { } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new VPNNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<VPNNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<VPNNetNode> ) diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.cpp b/noncore/settings/networksettings2/wlan/wlan_NN.cpp index c56da06..f7745be 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NN.cpp @@ -1,85 +1,68 @@ #include <resources.h> #include "wlan_NN.h" #include "wlan_NNI.h" -#ifndef MYPLUGIN - #include "netnodeinterface.h" -#endif - static const char * WLanNeeds[] = { 0 }; static const char * WLanProvides[] = { "device", 0 }; /** * Constructor, find all of the possible interfaces */ WLanNetNode::WLanNetNode() : ANetNode(tr("WLan Device")) { NSResources->addSystemFile( "interfaces", "/etc/network/interfaces", 1 ); InstanceCount = 2; } /** * Delete any interfaces that we own. */ WLanNetNode::~WLanNetNode(){ } const QString WLanNetNode::nodeDescription(){ return tr("\ <p>Configure Wi/Fi or WLan network cards.</p>\ <p>Defines Wireless options for those cards</p>\ " ); } ANetNodeInstance * WLanNetNode::createInstance( void ) { return new AWLan( this ); } const char ** WLanNetNode::needs( void ) { return WLanNeeds; } const char ** WLanNetNode::provides( void ) { return WLanProvides; } QString WLanNetNode::genNic( long nr ) { QString S; return S.sprintf( "wlan%ld", nr ); } void WLanNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); } } void WLanNetNode::saveSpecificAttribute( QTextStream & TS ) { TS << "interfacecount=" << InstanceCount << endl; } -#ifdef MYPLUGIN - -extern "C" { -void create_plugin( QList<ANetNode> & PNN ) { - PNN.append( new WLanNetNode() ); -} - -#else - -OPIE_NS2_PLUGIN( NetNodeInterface<WLanNetNode> ) - -#endif - -} +OPIE_NS2_PLUGIN( NetNodeInterface_T<WLanNetNode> ) |