author | wimpie <wimpie> | 2005-01-12 01:40:53 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-12 01:40:53 (UTC) |
commit | f9a83585111afa08a47176097a150d9f468bfcdf (patch) (side-by-side diff) | |
tree | 6d5a3b5f9716f7c6ca6e7fae8b0e2bac8d6c57da | |
parent | b2e60aa0222b348f34aab501feb8bc854e94413c (diff) | |
download | opie-f9a83585111afa08a47176097a150d9f468bfcdf.zip opie-f9a83585111afa08a47176097a150d9f468bfcdf.tar.gz opie-f9a83585111afa08a47176097a150d9f468bfcdf.tar.bz2 |
*** empty log message ***
12 files changed, 121 insertions, 25 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp index cd7bb4a..63b214e 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp @@ -1,164 +1,192 @@ #include <qapplication.h> #include <resources.h> + +#include <OTPeer.h> #include <OTDevice.h> #include <OTGateway.h> +#include <Opietooth.h> + +#include <qlistbox.h> +#include <qframe.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qdialog.h> + #include "bluetoothRFCOMMrun.h" using Opietooth2::OTGateway; using Opietooth2::OTDevice; using Opietooth2::OTDeviceAddress; +using Opietooth2::OTScan; +using Opietooth2::OTPeer; BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) { if( OT ) { OTGateway::releaseOTGateway(); } } State_t BluetoothRFCOMMRun::detectState( void ) { if( ! OT ) { OT = OTGateway::getOTGateway(); } if( deviceNrOfNetworkSetup() >= 0 ) { return Available; } odebug << "Bluetooth " << OT->isEnabled() << oendl; return ( OT->isEnabled() ) ? Off : Unavailable; } QString BluetoothRFCOMMRun::setMyState( NetworkSetup *, Action_t A, bool ) { if( OT ) { OTGateway::getOTGateway(); } if( A == Activate ) { // from OFF to Available RFCOMMChannel * Ch = getChannel( ); System & Sys = NSResources->system(); if( Ch ) { // connect to this peer DeviceNr = OT->getFreeRFCommDevice(); QStringList S; S << "rfcomm" << "bind" << QString().setNum( DeviceNr ) << Ch->BDAddress << QString().setNum( Ch->Channel ); + // no longer needed + delete Ch; + if( Sys.runAsRoot( S ) ) { return QString( "Error starting %1").arg(S.join(" ")); } // here rfcomm should be running -> we will detect state later return QString(); } else { Log(( "No channel selected -> cancel\n" )); return QString( "No channel selected. Operation cancelled" ); } } if( A == Deactivate ) { if( DeviceNr >= 0 ) { if( OT->releaseRFCommDevice( DeviceNr ) ) { return QString( "Cannot release RFCOMM NetworkSetup" ); } DeviceNr = -1; } } return QString(); } -#include <qlistbox.h> -#include <qframe.h> -#include <qlabel.h> -#include <qlayout.h> -#include <qdialog.h> - RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) { if( Data->Devices.count() == 1 ) { // only one device -> return channel return Data->Devices[0]; } RFCOMMChannel * Ch = 0; + + if( Data->Devices.count() == 0 ) { + OTPeer * Peer; + int Channel; + + if( OTScan::getDevice( Peer, Channel, OT ) == QDialog::Accepted ) { + Ch = new RFCOMMChannel; + Ch->BDAddress = Peer->address().toString(); + Ch->Name = Peer->name(); + Ch->Channel = Channel; + return Ch; + } + + return 0; + } + QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE ); QVBoxLayout * V = new QVBoxLayout( Dlg ); QLabel * L = new QLabel( qApp->translate( "BluetoothRFCOMMRun", "Select device to connect to"), Dlg ); QListBox * LB = new QListBox( Dlg ); for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { LB->insertItem( QString( "%1 (%2 Chnl %3)" ). arg( Data->Devices[i]->Name ). arg( Data->Devices[i]->BDAddress ). arg( Data->Devices[i]->Channel ) ); } V->addWidget( L ); V->addWidget( LB ); Dlg->resize( 100, 100 ); Dlg->move( 20, (qApp->desktop()->height()-100)/2 ); if( Dlg->exec() == QDialog::Accepted ) { unsigned int i = 0; for( i = 0; i < Data->Devices.count(); i ++ ) { if( LB->isSelected(i) ) { odebug << "Selected " << Data->Devices[i]->Name << oendl; - Ch = Data->Devices[i]; + Ch = new RFCOMMChannel; + Ch->BDAddress = Data->Devices[i]->BDAddress; + Ch->Name = Data->Devices[i]->Name; + Ch->Channel = Data->Devices[i]->Channel; break; } } } delete Dlg; return Ch; } QString BluetoothRFCOMMRun::deviceFile( void ) { if( deviceNrOfNetworkSetup() >= 0 ) { OTDevice * OTD = OT->getOTDevice(); // there is a NetworkSetup return OTD->getRFCommDevicePattern().arg(DeviceNr); } return QString(); } int BluetoothRFCOMMRun::deviceNrOfNetworkSetup( void ) { if( ! OT ) { OT = OTGateway::getOTGateway(); } DeviceNr = -1; for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { odebug << "Check for rfcomm on " << Data->Devices[i]->BDAddress << " " << Data->Devices[i]->Channel << oendl; if( ( DeviceNr = OT->connectedToRFCommChannel( OTDeviceAddress( Data->Devices[i]->BDAddress ), Data->Devices[i]->Channel ) ) >= 0 ) { odebug << "Up " << oendl; break; } } return DeviceNr; } diff --git a/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp b/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp index bf8cc59..2dd54ff 100644 --- a/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp +++ b/noncore/settings/networksettings2/gprs/GPRS_NNI.cpp @@ -162,70 +162,73 @@ short AGPRSDevice::generateFile( SystemFile & SF, } else { Bits = ~ ((1 << ((32-Data.Routing[i]->Mask))) - 1); } SF << "route add -net " << Data.Routing[i]->Address << " netmask " << ((Bits&0xff000000)>>24) << "." << ((Bits&0x00ff0000)>>16) << "." << ((Bits&0x0000ff00)>>8) << "." << ((Bits&0x000000ff)) << " gw $PPP_REMOTE" << oendl; SF << "route del -net " << Data.Routing[i]->Address << " netmask " << ((Bits&0xff000000)>>24) << "." << ((Bits&0x00ff0000)>>16) << "." << ((Bits&0x0000ff00)>>8) << "." << ((Bits&0x000000ff)) << " gw $PPP_REMOTE" << oendl; } if( ! Data.DNS1.isEmpty() ) { SF << "nameserver " << Data.DNS1 << " # profile " << removeSpaces( networkSetup()->name() ) <<oendl; } if( ! Data.DNS2.isEmpty() ) { SF << "nameserver " << Data.DNS2 << " # profile " << removeSpaces( networkSetup()->name() ) <<oendl; } } return 1; } -bool AGPRSDevice::openFile( SystemFile & SF ) { +bool AGPRSDevice::openFile( SystemFile & SF, QStringList & SL ) { if( SF.name() == "peers" ) { + SL << "/etc" << "ppp" << "peers"; SF.setPath( QString( "/etc/ppp/peers/" ) + removeSpaces( networkSetup()->name() ) ); return 1; } else if ( SF.name() == "chatscripts" ) { + SL << "/etc" << "chatscripts"; SF.setPath( QString( "/etc/chatscripts/" ) + removeSpaces( networkSetup()->name() ) ); return 1; + SL << "/etc" << "ppp"; } else if ( SF.name() == "extra" ) { SF.setPath( QString( "/etc/ppp/" ) + removeSpaces( networkSetup()->name() ) + ".fixed" ); return 1; } return 0; } diff --git a/noncore/settings/networksettings2/gprs/GPRS_NNI.h b/noncore/settings/networksettings2/gprs/GPRS_NNI.h index 1060a6e..b5bf1b9 100644 --- a/noncore/settings/networksettings2/gprs/GPRS_NNI.h +++ b/noncore/settings/networksettings2/gprs/GPRS_NNI.h @@ -1,48 +1,49 @@ #ifndef GPRS_H #define GPRS_H #include <netnode.h> #include "GPRSdata.h" #include "GPRSrun.h" class GPRSNetNode; class GPRSEdit; class SystemFile; class AGPRSDevice : public ANetNodeInstance{ public : AGPRSDevice( GPRSNetNode * PNN ); RuntimeInfo * runtime( void ) { return ( RT ) ? RT : ( RT = new GPRSRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - virtual bool openFile( SystemFile & SF ); + virtual bool openFile( SystemFile & SF, + QStringList & SL ); virtual void * data( void ) { return (void *)&Data; } virtual bool hasDataForFile( SystemFile & S ); virtual short generateFile( SystemFile & SF, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : GPRSEdit * GUI; GPRSData Data; GPRSRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index 80dcb3d..2714dd5 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -206,97 +206,97 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { if( ! NC ) { return; } OldName = NC->name(); EC.setNetworkSetup( NC ); } EC.showMaximized(); // disable refresh timer UpdateTimer->stop(); // we need to retry while( 1 ) { if( EC.exec() == QDialog::Accepted ) { // toplevel item -> store NetworkSetup * NC = EC.networkSetup(); if( NC->isModified() ) { if( LBI ) { if( NC->name() != OldName ) { // find if new name is free NetworkSetup * LCN = NSResources->findNetworkSetup( 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->removeNetworkSetup( OldName ); NSResources->addNetworkSetup( 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->addNetworkSetup( NC, 0 ); NC->setNumber( NSResources->assignNetworkSetupNumber() ); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); Profiles_LB->setSelected( ci, TRUE ); } - updateProfileState( LBI ); + SLOT_RefreshStates(); } } else { // cancelled : reset NetworkSetup if( LBI ) { NetworkSetup * NC = NSResources->findNetworkSetup( LBI->text() ); NC->reassign(); } } break; } // reenable UpdateTimer->start( 5000 ); } void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { if( LBI == 0 ) return; NetworkSetup * NC = NSResources->findNetworkSetup( 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; switch( NC->state() ) { case Disabled : // no further work IsEnabled = 0; FrmActive = 0; break; case Unknown : case Unchecked : case Unavailable : FrmActive = 0; break; case Off : leds = 1; break; case Available : leds = 2; break; diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index 0ab0e5b..1bcd95c 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -44,98 +44,99 @@ QString & deQuote( QString & X ) { } 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 * NNI, + QStringList & SL ) { + return (NNI ) ? NNI->openFile( SF, SL ) : 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 networkSetup()->findNext( this ); } // // // NODECOLLECTION // // NetworkSetup::NetworkSetup( void ) : QList<ANetNodeInstance>() { IsModified = 0; Index = -1; Name=""; IsNew = 1; @@ -361,101 +362,103 @@ ANetNodeInstance * NetworkSetup::firstWithDataForFile( SystemFile & S ) { } State_t NetworkSetup::state( bool Update ) { State_t NodeState; if( CurrentState == Unchecked || Update ) { // collect states of all nodes until with get the 'higest' // state possible Log(( "NetworkSetup %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 NetworkSetup::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", diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 8aebdc0..fa4ab70 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -76,100 +76,105 @@ 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 NetworkSetup 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 // + // the function can return a set of folders that should + // be created (or perhaps already exist) prior to opening + // the 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 ); + ANetNodeInstance * NNI, + QStringList & PathToCreate ); // 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; @@ -214,97 +219,98 @@ public: 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 setNetworkSetup( NetworkSetup * NC ) { TheNetworkSetup = NC; } inline NetworkSetup * networkSetup( void ) { return TheNetworkSetup; } // // // Virtual methods with sensible defaults // // // open proper file identified by S - virtual bool openFile( SystemFile & ) + virtual bool openFile( SystemFile &, + QStringList & ) { 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; diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 835c7c3..6b87399 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -291,148 +291,170 @@ QString NetworkSettingsData::saveSettings( void ) { return ErrS; } QString NetworkSettingsData::generateSettings( void ) { QString S = ""; Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2NetworkSetup_t & M = NSResources->networkSetups(); NetworkSetup * NC; ANetNodeInstance * NNI; ANetNodeInstance * FirstWithData; RuntimeInfo * CurDev; ANetNode * NN, * CurDevNN = 0; long NoOfDevs; long DevCtStart; bool needToGenerate; // regenerate system files Log( ( "Generating settings from %s\n", CfgFile.latin1() )); for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { bool FirstItem = 1; bool Generated = 0; CurDevNN = nnit.current(); { QStringList SL; SL = CurDevNN->properFiles(); for ( QStringList::Iterator it = SL.begin(); it != SL.end(); ++it ) { Generated = 0; FirstItem = 1; // iterate over NNI's of this class for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); nniit.current(); ++nniit ) { if( nniit.current()->nodeClass() != CurDevNN ) // different class continue; // open proper file { SystemFile SF( (*it) ); + QStringList SL; - if( ! CurDevNN->openFile( SF, nniit.current()) ) { + if( ! CurDevNN->openFile( SF, nniit.current(), SL) ) { // cannot open S = qApp->translate( "NetworkSettings", - "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). - arg( (*it) ).arg( CurDevNN->name() ); + "<p>Cannot build proper file \"%1\" for node \"%2\"</p>" ). + arg( (*it) ). + arg( CurDevNN->name() ); + return S; + } + + if( ! createPath( SL ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot create path \"%1\" for proper file \"%2\" for node \"%3\"</p>" ). + arg( SL.join("/") ). + 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) ); + QStringList SL; - if( CurDevNN->openFile( SF, 0 ) && + if( CurDevNN->openFile( SF, 0, SL ) && ! SF.path().isEmpty() ) { + if( ! createPath( SL ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot create path \"%1\" for proper file \"%2\" for node \"%3\"</p>" ). + arg( SL.join("/") ). + 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() ); + arg( (*it) ). + arg( CurDevNN->name() ); return S; } if( CurDevNN->generatePostamble( SF ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). arg( (*it) ). arg( CurDevNN->name() ); return S; } } // no postamble } } } } // // generate all registered files // for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { SystemFile * SF; SF = sfit.current(); // reset all for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { nnit.current()->setDone(0); } for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); nniit.current(); ++nniit ) { nniit.current()->setDone(0); } for( QDictIterator<NetworkSetup> ncit(M); ncit.current(); ++ncit ) { ncit.current()->setDone(0); } Log( ( "Generating system file %s\n", SF->name().latin1() )); @@ -740,48 +762,71 @@ bool NetworkSettingsData::isModified( void ) { it.current(); ++it ) { if( it.current()->isModified() ) { return 1; } } return 0; } bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) { // load situation QList<NetworkSetup> PossibleTriggered; PossibleTriggered = collectTriggered( Interface ); Log( ( "for %s : Possiblilies %d\n", Interface.latin1(), PossibleTriggered.count() )); return ( PossibleTriggered.count() ) ? 1 : 0; } QList<NetworkSetup> NetworkSettingsData::collectTriggered( const QString & Interface ) { // collect NetworkSetups that could be triggered by this interface NetworkSetup * NC; QList<NetworkSetup> PossibleTriggered; // for all NetworkSetups Name2NetworkSetup_t & M = NSResources->networkSetups(); for( QDictIterator<NetworkSetup> it(M); it.current(); ++it ) { NC = it.current(); // check if this profile handles the requested interface if( NC->triggeredBy( Interface ) && // if different Intf. NC->state() != Disabled && // if enabled NC->state() != IsUp // if already used ) { Log( ( "Append %s for %s\n", NC->name().latin1(), Interface.latin1() )); PossibleTriggered.append( NC ); } } return PossibleTriggered; } +bool NetworkSettingsData::createPath( const QStringList & SL ) { + + QDir D( SL[0] ); + + for ( QStringList::ConstIterator it = SL.begin(); + it != SL.end(); + ++it ) { + + printf( "Create %s\n", (*it).latin1() ); + if( it == SL.begin() ) + continue; + + if( ! D.exists( *it ) ) { + if( ! D.mkdir( *it ) ) { + printf( "Failed %s %s\n", D.path().latin1(), (*it).latin1() ); + return 0; + } + } + + D.cd( *it ); + } + return 1; +} diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h index b9c216d..65b61a3 100644 --- a/noncore/settings/networksettings2/nsdata.h +++ b/noncore/settings/networksettings2/nsdata.h @@ -1,38 +1,39 @@ #ifndef __NSDATA_H #define __NSDATA_H #include <netnode.h> class NetworkSettingsData { public : NetworkSettingsData( void ); ~NetworkSettingsData( void ); void loadSettings( void ); QString saveSettings( void ); QString generateSettings( void ); bool isModified( void ); inline void setModified( bool M ) { ForceModified = M; } QList<NetworkSetup> collectPossible( const QString & Interface ); // return TRUE if we need gui to decide bool canStart( const QString & Interface ); // return TRUE if there are vpns that could be triggered // by this interface bool couldBeTriggered( const QString & Interface ); private : QList<NetworkSetup> collectTriggered( const QString &Interface ); + bool createPath( const QStringList & SL ); bool ForceModified; // collect strings in config file nobody wants QStringList LeftOvers; }; #endif diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp index 8323549..fc30bf8 100644 --- a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp @@ -139,97 +139,96 @@ void OTSniffing::SLOT_Trace( bool Run ) { return; } HciDump = new MyProcess(); QStringList SL; SL << "/usr/sbin/hcidump"; switch( DataFormat_CB->currentItem() ) { case 0 : // Hex SL << "-x"; break; case 1 : // Ascii SL << "-a"; break; case 2 : // both SL << "-X"; break; } SL << "-i"; SL << OT->scanWith()->devname(); connect( HciDump, SIGNAL( stdoutLine( const QString & ) ), this, SLOT( SLOT_Show( const QString & ) ) ); connect( HciDump, SIGNAL(processExited(MyProcess*) ), this, SLOT( SLOT_ProcessExited(MyProcess*) ) ); HciDump->process() << SL; if( ! HciDump->process().start( OProcess::DontCare, OProcess::AllOutput ) ) { QMessageBox::warning(0, tr("Run hcidump"), tr("Cannot start %1").arg(SL.join(" ")) ); delete HciDump; HciDump = 0; } } void OTSniffing::SLOT_Show( const QString & S ) { - printf( "%s\n", S.latin1() ); Output_TV->setText( Output_TV->text() + S + "\n" ); QScrollBar *scroll = Output_TV->verticalScrollBar(); scroll->setValue(scroll->maxValue()); //Output_LB->insertItem( S ); //Output_LB->setCurrentItem( Output_LB->count()-1 ); //Output_LB->ensureCurrentVisible(); } void OTSniffing::SLOT_ProcessExited( MyProcess * ) { printf( "Exited\n" ); delete HciDump; HciDump = 0; } void OTSniffing::SLOT_Save( void ) { QString S = OFileDialog::getSaveFileName( OFileSelector::Extended, QDir::home().path(), QString::null, MimeTypes(), this ); if( ! S.isEmpty() ) { QFile F( S ); if( ! F.open( IO_WriteOnly ) ) { QMessageBox::warning(0, tr("Save log"), tr("Cannot open %1").arg(S) ); return; } QTextStream TS( &F ); TS << S << endl; } } void OTSniffing::SLOT_Load( void ) { QString S = OFileDialog::getOpenFileName( OFileSelector::Extended, QDir::home().path(), QString::null, MimeTypes(), this ); if( ! S.isEmpty() ) { QFile F( S ); if( ! F.open( IO_ReadOnly ) ) { @@ -332,163 +331,172 @@ OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) : // nor source nor destination -> unknown it->setText( 0, Keys[i].from().toString() ); it->setText( 1, Keys[i].to().toString() ); } } } } OTPairing::~OTPairing() { if( MyIcons ) delete Icons; OTGateway::releaseOTGateway(); } void OTPairing::SLOT_Unpair( ) { // find selected pair QListViewItem * it = Pairs_LV->firstChild(); while( it ) { if( it->isSelected() ) { // confirm ? if( QMessageBox::warning(0, tr("Break pairing"), tr("Sure ?"), tr("Yes, break"), tr("No, don't break") ) == 0 ) { LinkKeyLVI * KPIt = (LinkKeyLVI *)it; // break OT->removeLinkKey( KPIt->index() ); delete KPIt; } return; } it= it->nextSibling(); } } // // // // // OTScan::OTScan( QWidget * parent, OTIcons * _IC ) : OTScanGUI( parent ), Filter() { OT = OTGateway::getOTGateway(); + Icons = (_IC ) ? _IC : new OTIcons(); MyIcons = (_IC == 0 ); DetectedPeers_LV->header()->hide(); Current = 0; SelectedPeer = 0; SelectedChannel = 0; StrengthTimer = new QTimer( this ); connect( StrengthTimer, SIGNAL( timeout()), this, SLOT( SLOT_UpdateStrength()) ); connect( OT, SIGNAL( detectedPeer( OTPeer *, bool )), this, SLOT( SLOT_NewPeer( OTPeer *, bool )) ); connect( OT, SIGNAL( finishedDetecting()), this, SLOT( SLOT_FinishedDetecting()) ); // populate with peers we already know about const PeerVector & P = OT->peers(); for( unsigned int i = 0; i < P.count(); i ++ ) { SLOT_NewPeer( P[i], TRUE ); } // populate State fram { QHBoxLayout * H =new QHBoxLayout( State_Frm ); Paired_Led = new OLedBox( green, State_Frm ); QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm ); H->addWidget( Paired_Led ); H->addWidget( L1 ); H->addStretch( 1 ); } } OTScan::~OTScan() { if( MyIcons ) delete Icons; OTGateway::releaseOTGateway(); // send all peers that we do not care about states QListViewItem * Lit = DetectedPeers_LV->firstChild(); while( Lit ) { ((PeerLVI *)Lit)->peer()->stopFindingOutState( ); Lit = Lit->nextSibling(); } } // static scan dialog function int OTScan::getDevice( OTPeer *& Peer, int & Channel, OTGateway * OT, const UUIDVector & Filter, QWidget* Parent ) { bool IsUp = 0; unsigned int i; + if( ! OT->isEnabled() ) { + QMessageBox::warning( 0, + tr("Scanning problem"), + tr("Bluetooth not enabled" ) + ); + return QDialog::Rejected; + } + // check if bluetooth is up OTDriverList & DL = OT->getDriverList(); for( i = 0; i < DL.count(); i ++ ) { if( DL[i]->isUp() ) { // one device that is up found IsUp = 1; break; } } // use this driver OT->setScanWith( OT->driver(i) ); // create dialog QDialog * Dlg = new QDialog( Parent, 0, TRUE ); QVBoxLayout * V = new QVBoxLayout( Dlg ); OTScan * Scn = new OTScan( Dlg ); connect( Scn, SIGNAL( selected() ), Dlg, SLOT( accept() ) ); if( Filter ) { Scn->setScanFilter( Filter ); } V->addWidget( Scn ); Dlg->setCaption( tr("Scan Neighbourhood" ) ); Dlg->showMaximized(); int rv = Dlg->exec(); if( rv == QDialog::Accepted ) { // get peer Peer = Scn->selectedPeer(); if( Peer == 0 ) { // no peer selected rv = QDialog::Rejected; } else { Channel = Scn->selectedChannel(); } } delete Dlg; diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp index 7286d96..9cdd51e 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp @@ -101,102 +101,104 @@ void APPP::setSpecificAttribute( QString & A, QString & V ) { void APPP::saveSpecificAttribute( QTextStream & TS ) { TS << "dnsserverassigned=" << ( ( Data.DNS.ServerAssigned ) ? "yes" : "no" ) << endl; TS << "dnsdomainname=" << Data.DNS.DomainName << endl; for( unsigned int i = 0; i < Data.DNS.Servers.size(); i ++ ) { TS << "dnsserver=" << *(Data.DNS.Servers[i]) << endl; } TS << "authmode=" << Data.Auth.Mode << endl; TS << "authloginexpect=" << quote( Data.Auth.Login.Expect ) << endl; TS << "authloginsend=" << quote( Data.Auth.Login.Send ) << endl; TS << "authpasswordexpect=" << quote( Data.Auth.Password.Expect ) << endl; TS << "authpasswordsend=" << quote( Data.Auth.Password.Send ) << endl; TS << "authpcemode=" << Data.Auth.PCEMode << endl; TS << "authclient=" << Data.Auth.Client << endl; TS << "authserver=" << Data.Auth.Server << endl; TS << "authsecret=" << quote( Data.Auth.Secret ) << endl; TS << "ipgwautomatic=" << ( ( Data.IP.GWAutomatic ) ? "yes" : "no" ) << endl; TS << "ipgwisdefault=" << ( ( Data.IP.GWIsDefault ) ? "yes" : "no" ) << endl; TS << "ipgwifnotset=" << ( ( Data.IP.GWIfNotSet ) ? "yes" : "no" ) << endl; TS << "iplocaloverrule=" << ( ( Data.IP.LocalOverrule ) ? "yes" : "no" ) << endl; TS << "ipremoteoverrule=" << ( ( Data.IP.RemoteOverrule ) ? "yes" : "no" ) << endl; TS << "iplocaladdress=" << Data.IP.LocalAddress << endl; TS << "ipremoteaddress=" << Data.IP.RemoteAddress << endl; TS << "ipgwaddress=" << Data.IP.GWAddress << endl; TS << "runpreconnect=" << Data.Run.PreConnect << endl; TS << "runpostconnect=" << Data.Run.PostConnect << endl; TS << "runpredisconnect=" << Data.Run.PreDisconnect << endl; TS << "runpostdisconnect=" << Data.Run.PostDisconnect << endl; } QWidget * APPP::edit( QWidget * parent ) { GUI = new PPPEdit( parent ); GUI->showData( Data ); return GUI; } QString APPP::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void APPP::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -bool APPP::openFile( SystemFile & SF ) { +bool APPP::openFile( SystemFile & SF, QStringList & SL ) { if( SF.name() == "peers" ) { + SL << "/tmp/ppp" << "peers" ; SF.setPath( removeSpaces( QString( "/tmp/ppp/peers/" ) + networkSetup()->name() ) ); return 1; } else if ( SF.name() == "chatscripts" ) { + SL << "/tmp/chatscripts"; SF.setPath( removeSpaces( QString( "/tmp/chatscripts/" ) + networkSetup()->name() ) ); return 1; } return 0; } short APPP::generateFile( SystemFile & SF, long DevNr ) { short rvl, rvd; rvl = 1; rvd = 1; if( SF.name() == "pap-secrets" ) { Log(("Generate PPP for %s\n", SF.name().latin1() )); if( Data.Auth.Mode == 1 && Data.Auth.PCEMode == 0 ) { SF << "# secrets for " << networkSetup()->name().latin1() << endl; SF << Data.Auth.Client << " " << Data.Auth.Server << " " << Data.Auth.Secret << endl; rvl = 0; rvd = networkSetup()->getToplevel()->generateFileEmbedded( SF, DevNr ); } } else if( SF.name() == "chap-secrets" ) { Log(("Generate PPP for %s\n", SF.name().latin1() )); if( Data.Auth.Mode == 1 && Data.Auth.PCEMode != 0 ) { // used for both EAP and Chap SF << "# secrets for " << networkSetup()->name().latin1() << endl; SF << Data.Auth.Client << " " << Data.Auth.Server << " " << Data.Auth.Secret << endl; rvl = 0; rvd = networkSetup()->getToplevel()->generateFileEmbedded( SF, DevNr ); } diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.h b/noncore/settings/networksettings2/ppp/ppp_NNI.h index 76afb21..7830a4a 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.h +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.h @@ -1,45 +1,45 @@ #ifndef PPP_H #define PPP_H #include <netnode.h> #include "pppdata.h" #include "ppprun.h" class PPPNetNode; class PPPEdit; class QTextStream; class APPP : public ANetNodeInstance { public : APPP( PPPNetNode * PNN ); RuntimeInfo * runtime( void ) { return (RT) ? RT : (RT = new PPPRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - virtual bool openFile( SystemFile & Sf ); + virtual bool openFile( SystemFile & Sf, QStringList &SL ); short generateFile( SystemFile & TS, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : PPPEdit * GUI; PPPData Data; PPPRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/profile/profilerun.cpp b/noncore/settings/networksettings2/profile/profilerun.cpp index 48011ea..77bf9ac 100644 --- a/noncore/settings/networksettings2/profile/profilerun.cpp +++ b/noncore/settings/networksettings2/profile/profilerun.cpp @@ -1,31 +1,30 @@ #include <resources.h> #include "profilerun.h" State_t ProfileRun::detectState( void ) { - InterfaceInfo * II = networkSetup()->assignedInterface(); - Log(( "Interface %p %p %p: %d\n", II, - netNode(), netNode()->networkSetup(), (II) ? II->IsUp : 0 )); + Log(( "Profile %sabled\n", (Data->Disabled) ? "dis" : "en" )); + if( Data->Disabled ) { return Disabled; } return Unknown; } QString ProfileRun::setMyState( NetworkSetup * NC, Action_t A, bool ) { odebug << "Profile " << Data->Disabled << oendl; if( A == Disable ) { if( ! Data->Disabled ) { Data->Disabled = 1; NC->setModified( 1 ); } } else if( A == Enable ) { if( Data->Disabled ) { Data->Disabled = 0; NC->setModified( 1 ); } } return QString(); } |