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 @@ -1,231 +1,234 @@ #include <system.h> #include <netnode.h> #include "GPRSedit.h" #include "GPRS_NNI.h" #include "GPRS_NN.h" AGPRSDevice::AGPRSDevice( GPRSNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.APN = ""; Data.User = ""; Data.Password = ""; Data.DefaultGateway = 1; Data.SetIfSet = 0; Data.Debug = 0; Data.Routing.setAutoDelete( TRUE ); GUI = 0; RT = 0; } void AGPRSDevice::setSpecificAttribute( QString & A, QString & V ) { if( A == "apn" ) { Data.APN = V; } else if( A == "user" ) { Data.User = V; } else if( A == "password" ) { Data.Password = V; } else if( A == "dns2" ) { Data.DNS2 = V; } else if( A == "dns1" ) { Data.DNS1 = V; } else if( A == "defaultgateway" ) { Data.DefaultGateway = (V=="yes"); } else if( A == "setifset" ) { Data.SetIfSet = (V == "yes"); } else if( A == "routes" ) { Data.Routing.resize( V.toULong() ); } else if( A.startsWith( "route" ) ) { QStringList SL = QStringList::split( "/", V ); GPRSRoutingEntry * E = new GPRSRoutingEntry; E->Address = SL[0]; E->Mask = SL[1].toULong(); Data.Routing.insert( A.mid(5).toULong(), E ); } else if( A == "debug" ) { Data.Debug = V.toShort(); } } void AGPRSDevice::saveSpecificAttribute( QTextStream & TS ) { TS << "apn=" << Data.APN << endl; TS << "user=" << Data.User << endl; TS << "password=" << Data.Password << endl; TS << "dns1=" << Data.DNS1 << endl; TS << "dns2=" << Data.DNS2 << endl; TS << "defaultgateway=" << ( (Data.DefaultGateway) ? "yes" : "no" ) << endl; TS << "setifset=" << ((Data.SetIfSet) ? "yes" : "no") << endl; TS << "debug=" << Data.Debug << endl; TS << "routes=" << Data.Routing.count() << oendl; for( unsigned int i = 0; i < Data.Routing.count(); i ++ ) { TS << "route" << i << "=" << Data.Routing[i]->Address << "/" << Data.Routing[i]->Mask << oendl; } } QWidget * AGPRSDevice::edit( QWidget * parent ) { GUI = new GPRSEdit( parent ); GUI->showData( Data ); return GUI; } QString AGPRSDevice::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AGPRSDevice::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } bool AGPRSDevice::hasDataForFile( SystemFile & S ) { return S.name() == "pap-secrets" || S.name() == "peers" || S.name() == "extra" || S.name() == "chatscripts" ; } short AGPRSDevice::generateFile( SystemFile & SF, long ) { if( SF.name() == "pap-secrets" ) { SF << Data.User << " * " << Data.Password << " *" << endl; return 0; } else if( SF.name() == "chatscripts" ) { SF << "SAY \"Starting\\n\"" << oendl; SF << "ECHO OFF" << oendl; SF << "ABORT BUSY" << oendl; SF << "ABORT ERROR" << oendl; SF << "ABORT VOICE" << oendl; SF << "ABORT \"NO CARRIER\"" << oendl; SF << "ABORT \"NO DIALTONE\"" << oendl; SF << "\"\" AT" << oendl; SF << "OK AT+CGATT=1" << oendl; SF << "OK AT+CGDCONT=1,\"IP\",\"" << Data.APN << "\"" << oendl; SF << "OK ATD*99***1#\\n" << oendl; SF << "TIMEOUT 10" << oendl; SF << "CONNECT \"\"" << oendl; SF << "SAY \"READY\\n\"" << oendl; return 0; } else if( SF.name() == "peers" ) { SF << "noauth" << oendl; SF << "user " << Data.User << oendl; SF << "connect \"/usr/sbin/chat -s -v -f /etc/chatscripts/" << removeSpaces( networkSetup()->name() ) << "\"" << oendl; SF << "ipcp-accept-local" << oendl; SF << "ipcp-accept-remote" << oendl; if( Data.DefaultGateway ) { SF << "defaultroute" << oendl; if( Data.SetIfSet ) { SF << "replacedefaultroute" << oendl; } } if( Data.Debug ) { SF << "logfile /tmp/" << removeSpaces( networkSetup()->name() ) << oendl; for( int i = 0; i < Data.Debug; i ++ ) { SF << "debug" << oendl; } } SF << "nocrtscts" << oendl; SF << "local" << oendl; SF << "lcp-echo-interval 0" << oendl; SF << "lcp-echo-failure 0" << oendl; SF << "usepeerdns" << oendl; SF << "linkname " << removeSpaces( networkSetup()->name() ) << oendl; SF << "nopersist" << oendl; SF << "ipparam " << removeSpaces( networkSetup()->name() ) <<oendl; SF << "maxfail 1" << oendl; return 0; } else if( SF.name() == "extra" ) { unsigned long Bits; // generate 'fixed' settings for( unsigned int i = 0 ; i < Data.Routing.count(); i ++ ) { if( Data.Routing[i]->Mask == 32 ) { Bits = 0xffffffff; } 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 @@ -1,510 +1,510 @@ #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*)) ); { Name2NetworkSetup_t & M = NSResources->networkSetups(); NetworkSetup * NC; // for all NetworkSetups for( QDictIterator<NetworkSetup> 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->networkSetups().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; if( NSD.isModified() ) { 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 ) { NetworkSetup * NC; NSResources->system().probeInterfaces(); // update current selection only NC = NSResources->findNetworkSetup( LBI->text() ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { updateProfileState( LBI ); } } } /* -> LATER !! bool is; NetworkSetup * NC; for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { NC = NSResources->findNetworkSetup( 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->removeNetworkSetup( LBI->text() ); delete LBI; NSD.setModified( 1 ); } } void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { QString OldName = ""; EditNetworkSetup EC( this ); if( LBI ) { NetworkSetup * NC = NSResources->findNetworkSetup( LBI->text() ); 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; 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; NetworkSetup * NC = NSResources->findNetworkSetup( LBI->text() ); Log(( "Prepare to %sable\n", (T) ? "en" : "dis" )); 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; NetworkSetup * NC = NSResources->findNetworkSetup( 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; NetworkSetup * NC = NSResources->findNetworkSetup( 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 0ab0e5b..1bcd95c 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -1,528 +1,531 @@ #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 * 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; CurrentState = Unchecked; AssignedInterface = 0; Number = -1; Done = 0; } NetworkSetup::NetworkSetup( QTextStream & TS, bool & Dangling ) : QList<ANetNodeInstance>() { long idx; 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() ) { // 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 ) { append( NNI ); } else { // could not find a node type -> collection invalid Log(( "Node %s missing -> NetworkSetup 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() )); } NetworkSetup::~NetworkSetup( void ) { } const QString & NetworkSetup::description( void ) { ANetNodeInstance * NNI = getToplevel(); return (NNI) ? NNI->runtime()->description() : Name; } void NetworkSetup::append( ANetNodeInstance * NNI ) { NNI->setNetworkSetup( this ); QList<ANetNodeInstance>::append( NNI ); } void NetworkSetup::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 * NetworkSetup::getToplevel( void ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->nodeClass()->isToplevel() ) { return NNI; } } return 0; } ANetNodeInstance * NetworkSetup::findByName( const QString & S ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->name() == S ) { return NNI; } } return 0; } ANetNodeInstance * NetworkSetup::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 NetworkSetup::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 NetworkSetup::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 NetworkSetup::statePixmap( State_t S) { return NSResources->getPixmap( State2PixmapTbl[S] ); } QString NetworkSetup::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 NetworkSetup::reassign( void ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { it.current()->setNetworkSetup( this ); } } const QStringList & NetworkSetup::triggers() { return getToplevel()->runtime()->triggers(); } bool NetworkSetup::hasDataForFile( SystemFile & S ) { return ( firstWithDataForFile( S ) != 0 ); } ANetNodeInstance * NetworkSetup::firstWithDataForFile( SystemFile & S ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { if( it.current()->hasDataForFile( S ) ) { return it.current(); } } return 0; } 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", "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(); } void NetworkSetup::copyFrom( const NetworkSetup & N ) { Number = N.Number; CurrentState = N.CurrentState; Name = N.Name; IsNew = N.IsNew; Index = N.Index; AssignedInterface = N.AssignedInterface; } // // // RuntimeInfo // // QString RuntimeInfo::setState( NetworkSetup * 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 8aebdc0..fa4ab70 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -1,641 +1,647 @@ #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 AsNetworkSetup; class AsFullSetup; // needed for plugin creation function #include <qlist.h> class ANetNode; class ANetNodeInstance; class NetworkSetup; 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 networkSetup cannot be established e.g. because // the hardware is not available Unavailable = 2, // if the networkSetup cannot be establishec but NOT // because it is physically impossible but because // it has been disabled for FUNCTIONAL reasons Disabled = 3, // if networkSetup is available to is currently down // i.e. the corresponding hardware is not activated Off = 4, // if networkSetup is available to be used (i.e. the // devices if fully ready to be used Available = 5, // if networkSetup 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 networkSetup up -> to IsUp Up = 4, // bring the networkSetup 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 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; // 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 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; protected : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; ANetNode * NodeType; // networkSetup to which this node belongs to NetworkSetup * TheNetworkSetup; 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 networkSetup 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 NetworkSetup * networkSetup() { return NNI->networkSetup(); } virtual State_t detectState( void ) = 0; // public API to set the state virtual QString setState( NetworkSetup * 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( NetworkSetup * NC, Action_t A, bool Force = 0 ) = 0; // networkSetup this runtime info belongs to ANetNodeInstance * NNI; }; class NetworkSetup : public QList<ANetNodeInstance> { public : NetworkSetup( void ); NetworkSetup( QTextStream & TS, bool & Dangling ); ~NetworkSetup( void ); // copy settings from NC to this void copyFrom( const NetworkSetup & NC ); 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 ) { // cleanup previous if( AssignedInterface ) { AssignedInterface->assignToNetworkSetup( 0 ); } if( NI ) { // assign new NI->assignToNetworkSetup( this ); } AssignedInterface = NI; } 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 networkSetup 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 networkSetup State_t CurrentState; QString Name; // true if this collection was just created (and not // loaded from file bool IsNew; // index in listbox int Index; bool IsModified; int Done; InterfaceInfo * AssignedInterface; }; #endif 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 @@ -1,787 +1,832 @@ #include <stdlib.h> #include <opie2/odebug.h> #include <qpe/qpeapplication.h> #include <qtextstream.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include "nsdata.h" #include <netnode.h> #include <resources.h> static QString CfgFile; NetworkSettingsData::NetworkSettingsData( void ) { // init global resources structure new TheNSResources(); if( ! NSResources->userKnown() ) { Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", NSResources->currentUser().HomeDir.latin1(), NSResources->currentUser().UserName.latin1() )); return; } CfgFile.sprintf( "%s/Settings/NS2.conf", NSResources->currentUser().HomeDir.latin1() ); Log(( "Cfg from %s\n", CfgFile.latin1() )); // load settings loadSettings(); // assign interfaces by scanning /tmp/profile-%s.Up files { QDir D( "/tmp" ); QFile * F = new QFile; int profilenr; QString interfacename; QTextStream TS ( F ); QStringList SL = D.entryList( "profile-*.up"); Log(( "System reports %d interfaces. Found %d up\n", NSResources->system().interfaces().count(), SL.count() )); for ( QStringList::Iterator it = SL.begin(); it != SL.end(); ++it ) { profilenr = atol( (*it).mid( 8 ).latin1() ); // read the interface store int 'up' F->setName( D.path() + "/" + (*it) ); if( F->open( IO_ReadOnly ) ) { NetworkSetup * NC; interfacename = TS.readLine(); F->close(); Log(( "Assign interface %s to Profile nr %d\n", interfacename.latin1(), profilenr )); NC = NSResources->getNetworkSetup( profilenr ); if( NC ) { NC->assignInterface( NSResources->system().findInterface( interfacename ) ); Log(( "Assign interface %p\n", NC->assignedInterface() )); } else { Log(( "Profile nr %d no longer defined\n", profilenr )); } } } } } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { delete NSResources; } void NetworkSettingsData::loadSettings( void ) { QString Line, S; QString Attr, Value; long idx; QFile F( CfgFile ); QTextStream TS( &F ); ForceModified = 0; do { if( ! F.open(IO_ReadOnly) ) break; /* load the file -> FORMAT : [NETNODETYPE] Entries ... <EMPTYLINE> [NetworkSetup] Name=Name Node=Name <EMPTYLINE> */ while( ! TS.atEnd() ) { S = Line = TS.readLine(); if ( S.isEmpty() || S[0] != '[' ) continue; S = S.mid( 1, S.length()-2 ); if( ! NSResources ) { continue; } if( S == "NetworkSetup" ) { // load NetworkSetups -> collections of nodes bool Dangling; NetworkSetup * NC = new NetworkSetup( TS, Dangling ); NSResources->addNetworkSetup( NC, Dangling ); } else { ANetNode * NN = 0; ANetNodeInstance* NNI = 0; if( S.startsWith( "nodetype " ) ) { S = S.mid( 9, S.length()-9 ); S = deQuote(S); // try to find netnode NN = NSResources->findNetNode( S ); } else { // try to find instance NNI = NSResources->createNodeInstance( S ); } if( NN == 0 && NNI == 0 ) { LeftOvers.append( Line ); do { Line = TS.readLine(); // store even delimiter LeftOvers.append( Line ); } while ( ! Line.isEmpty() ); //next section continue; } // read entries of this section do { S = Line = TS.readLine(); if( S.isEmpty() ) { // empty line break; } idx = S.find( '=' ); if( idx > 0 ) { Attr = S.left( idx ); Value = S.mid( idx+1, S.length() ); } else { Value=""; Attr = S; } Value.stripWhiteSpace(); Attr.stripWhiteSpace(); Attr.lower(); // dequote Attr Value = deQuote(Value); if( NN ) { // set the attribute NN->setAttribute( Attr, Value ); } else { // set the attribute NNI->setAttribute( Attr, Value ); } } while( 1 ); if( NNI ) { // loading from file -> exists Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); NNI->setNew( FALSE ); NSResources->addNodeInstance( NNI ); } if( NN ) { Log( ( "Node %s : %p\n", NN->name(), NN ) ); } } } } while( 0 ); } QString NetworkSettingsData::saveSettings( void ) { QString ErrS = ""; if( ! isModified() ) return ErrS; QString S; QFile F( CfgFile + ".bup" ); Log( ( "Saving settings to %s\n", CfgFile.latin1() )); if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { ErrS = qApp->translate( "NetworkSettings", "<p>Could not save setup to \"%1\" !</p>" ). arg(CfgFile); // problem return ErrS; } QTextStream TS( &F ); // save global configs for( QDictIterator<ANetNode> it( NSResources->netNodes() ); it.current(); ++it ) { TS << "[nodetype " << quote( QString( it.current()->name() ) ) << "]" << endl; it.current()->saveAttributes( TS ); TS << endl; } // save leftovers for ( QStringList::Iterator it = LeftOvers.begin(); it != LeftOvers.end(); ++it ) { TS << (*it) << endl; } // save all netnode instances { ANetNodeInstance * NNI; for( QDictIterator<ANetNodeInstance> nit( NSResources->netNodeInstances()); nit.current(); ++nit ) { // header NNI = nit.current(); TS << '[' << QString(NNI->nodeClass()->name()) << ']' << endl; NNI->saveAttributes( TS ); TS << endl; } } // good NetworkSetups { Name2NetworkSetup_t & M = NSResources->networkSetups(); // for all NetworkSetups for( QDictIterator<NetworkSetup> it(M); it.current(); ++it ) { TS << "[NetworkSetup]" << endl; it.current()->save(TS); } } // save dangling NetworkSetups { Name2NetworkSetup_t & M = NSResources->danglingNetworkSetups(); // for all NetworkSetups for( QDictIterator<NetworkSetup> it(M); it.current(); ++it ) { TS << "[NetworkSetup]" << endl; it.current()->save(TS); } } QDir D("."); D.rename( CfgFile + ".bup", CfgFile ); // // proper files AND system files regenerated // for( QDictIterator<NetworkSetup> it(NSResources->networkSetups()); it.current(); ++it ) { it.current()->setModified( 0 ); } return ErrS; } QString NetworkSettingsData::generateSettings( void ) { QString S = ""; Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2NetworkSetup_t & M = NSResources->networkSetups(); NetworkSetup * NC; ANetNodeInstance * NNI; ANetNodeInstance * FirstWithData; RuntimeInfo * CurDev; ANetNode * NN, * CurDevNN = 0; long NoOfDevs; long DevCtStart; bool needToGenerate; // regenerate system files Log( ( "Generating settings from %s\n", CfgFile.latin1() )); for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { bool FirstItem = 1; bool Generated = 0; CurDevNN = nnit.current(); { QStringList SL; SL = CurDevNN->properFiles(); for ( QStringList::Iterator it = SL.begin(); it != SL.end(); ++it ) { Generated = 0; FirstItem = 1; // iterate over NNI's of this class for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); nniit.current(); ++nniit ) { if( nniit.current()->nodeClass() != CurDevNN ) // different class continue; // open proper file { SystemFile SF( (*it) ); + 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() )); needToGenerate = 0; // are there netnodes that have instances and need // to write data in this system file ? for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); ! needToGenerate && nnit.current(); ++nnit ) { NN = nnit.current(); if( NN->hasDataForFile( *SF ) ) { // netnode can have data // are there instances of this node ? for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); ! needToGenerate && nniit.current(); ++nniit ) { if( nniit.current()->nodeClass() == NN ) { // yes Log(("Node %s has data\n", nniit.current()->name() )); needToGenerate = 1; break; } } } } if( ! needToGenerate ) { // no instances found that might need to write data // in this systemfile Log(("No nodes for systemfile %s\n", SF->name().latin1() )); continue; } // ok generate this system file if( ! SF->open() ) { S = qApp->translate( "NetworkSettings", "<p>Cannot open system file \"%1\"</p>" ). arg( SF->name() ); return S; } // global presection for this system file if( ! SF->preSection() ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } // find NetworkSetups that want to write to this file for( QDictIterator<NetworkSetup> ncit(M); ncit.current(); ++ncit ) { NC = ncit.current(); if( NC->done() ) { // already done continue; } if( ! NC->hasDataForFile( *SF ) ) { // no data continue; } Log(("Generating %s for NetworkSetup %s\n", SF->name().latin1(), NC->name().latin1() )); // find highest item that wants to write data to this file FirstWithData = NC->firstWithDataForFile( *SF ); // find device on which this NetworkSetup works CurDev = NC->device(); // class of that node CurDevNN = CurDev->netNode()->nodeClass(); if( ! FirstWithData->nodeClass()->done() ) { // generate fixed part if( ! SF->preDeviceSection( CurDevNN ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } if( FirstWithData->nodeClass()->generateFile( *SF, FirstWithData, -2 ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } FirstWithData->nodeClass()->setDone( 1 ); Log(( "Systemfile %s for node instance %s is done\n", SF->name().latin1(), FirstWithData->name() )); } NoOfDevs = 0; DevCtStart = -1; if( SF->knowsDeviceInstances() ) { DevCtStart = 0; NoOfDevs = CurDevNN->instanceCount(); } if( ! CurDev->netNode()->nodeClass()->done() ) { // first time this device is handled // generate common device specific part for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { if( FirstWithData->nodeClass()->generateFile( *SF, CurDev->netNode(), i ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } } CurDev->netNode()->nodeClass()->setDone( 1 ); Log(( "Systemfile %s for Nodeclass %s is done\n", SF->name().latin1(), CurDev->netNode()->nodeClass()->name() )); } // generate profile specific info // for all nodeNetworkSetups that work on the same device for( QDictIterator<NetworkSetup> ncit2(M); ncit2.current(); ++ncit2 ) { if( ncit2.current()->device() != CurDev ) { // different device continue; } Log(("NetworkSetup %s of family %s\n", ncit2.current()->name().latin1(), CurDev->name() )); // generate NNI = ncit2.current()->firstWithDataForFile( *SF ); for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { if( ! SF->preNodeSection( NNI, i ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } switch( NNI->generateFile( *SF, i ) ) { case 0 : (*SF) << endl; break; case 1 : break; case 2 : S = qApp->translate( "NetworkSettings", "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } if( ! SF->postNodeSection( NNI, i ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } } ncit2.current()->setDone( 1 ); } } if( ! SF->postDeviceSection( CurDevNN ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } if( ! SF->postSection() ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Closure\" for file \"%1\"</p>" ). arg( SF->name() ); return S; } // end of file SF->close(); } return S; } QList<NetworkSetup> NetworkSettingsData::collectPossible( const QString & Interface ) { // collect NetworkSetups that can work on top of this interface NetworkSetup * NC; QList<NetworkSetup> PossibleNetworkSetups; Name2NetworkSetup_t & M = NSResources->networkSetups(); // for all NetworkSetups for( QDictIterator<NetworkSetup> it(M); it.current(); ++it ) { NC = it.current(); // check if this profile handles the requested interface if( NC->handlesInterface( Interface ) && // if different Intf. NC->state() != Disabled && // if enabled NC->state() != IsUp // if already used ) { Log( ( "Append %s for %s\n", NC->name().latin1(), Interface.latin1() )); PossibleNetworkSetups.append( NC ); } } return PossibleNetworkSetups; } /* Called by the system to see if interface can be brought UP if allowed, echo Interface-allowed else Interface-disallowed */ bool NetworkSettingsData::canStart( const QString & Interface ) { // load situation NetworkSetup * NC = 0; QList<NetworkSetup> PossibleNetworkSetups; PossibleNetworkSetups = collectPossible( Interface ); Log( ( "for %s : Possiblilies %d\n", Interface.latin1(), PossibleNetworkSetups.count() )); switch( PossibleNetworkSetups.count() ) { case 0 : // no NetworkSetups break; case 1 : // one NetworkSetup NC = PossibleNetworkSetups.first(); break; default : // need to ask user ? return 1; } if( NC ) { switch( NC->state() ) { case Unchecked : case Unknown : case Unavailable : case Disabled : // this profile does not allow interface to be UP // -> try others break; case Off : // try to UP the device { QString S= NC->setState( Activate ); if( ! S.isEmpty() ) { // could not bring device Online -> try other alters Log(( "disallow %ld for %s : %s\n", NC->number(), Interface.latin1(), S.latin1() )); break; } // interface assigned } // FT case Available : case IsUp : // also called for 'ifdown' // device is ready -> done Log(( "allow %ld for %s\n", NC->number(), Interface.latin1())); printf( "A%d%s\n", NC->number(), Interface.latin1() ); return 0; } } // if we come here no alternatives are possible Log(( "disallow %s\n", Interface.latin1())); printf( "D-%s\n", Interface.latin1() ); return 0; } bool NetworkSettingsData::isModified( void ) { if( ForceModified ) return 1; for( QDictIterator<NetworkSetup> it(NSResources->networkSetups()); it.current(); ++it ) { if( it.current()->isModified() ) { return 1; } } return 0; } bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) { // load situation QList<NetworkSetup> PossibleTriggered; PossibleTriggered = collectTriggered( Interface ); Log( ( "for %s : Possiblilies %d\n", Interface.latin1(), PossibleTriggered.count() )); return ( PossibleTriggered.count() ) ? 1 : 0; } QList<NetworkSetup> NetworkSettingsData::collectTriggered( const QString & Interface ) { // collect NetworkSetups that could be triggered by this interface NetworkSetup * NC; QList<NetworkSetup> PossibleTriggered; // for all NetworkSetups Name2NetworkSetup_t & M = NSResources->networkSetups(); for( QDictIterator<NetworkSetup> it(M); it.current(); ++it ) { NC = it.current(); // check if this profile handles the requested interface if( NC->triggeredBy( Interface ) && // if different Intf. NC->state() != Disabled && // if enabled NC->state() != IsUp // if already used ) { Log( ( "Append %s for %s\n", NC->name().latin1(), Interface.latin1() )); PossibleTriggered.append( NC ); } } return PossibleTriggered; } +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 @@ -1,958 +1,966 @@ #include <opie2/odebug.h> #include <opie2/oledbox.h> #include <opie2/ofiledialog.h> using namespace Opie::Core; using namespace Opie::Ui; #include <qpe/resource.h> #include <qapplication.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qdialog.h> #include <qdir.h> #include <qfile.h> #include <qgroupbox.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qlistbox.h> #include <qlistview.h> #include <qmessagebox.h> #include <qprogressbar.h> #include <qpushbutton.h> #include <qscrollbar.h> #include <qtextstream.h> #include <qtextview.h> #include <Opietooth.h> #include <OTDriver.h> #include <OTPeer.h> #include <OTGateway.h> #include <OTSDPAttribute.h> #include <OTSDPService.h> #include <OTInquiry.h> #include <system.h> using namespace Opietooth2; namespace Opietooth2 { class PeerLVI : public QListViewItem { public : PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) { Peer = P; } ~PeerLVI( void ) { } inline OTPeer * peer( void ) { return Peer; } private : OTPeer * Peer; }; class ChannelLVI : public QListViewItem { public : ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) { Channel = Ch; } ~ChannelLVI( void ) { } inline int channel( void ) { return Channel; } private : int Channel; }; class DriverLVI : public QListViewItem { public : DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) { Driver = P; } ~DriverLVI( void ) { } inline OTDriver * driver( void ) { return Driver; } private : OTDriver * Driver; }; class LinkKeyLVI : public QListViewItem { public : LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) { LinkKey = Ch; } ~LinkKeyLVI( void ) { } inline int index( void ) { return LinkKey; } private : int LinkKey; }; }; // // // // // OTSniffing::OTSniffing( QWidget * parent ) : OTSniffGUI( parent ) { OT = OTGateway::getOTGateway(); HciDump = 0; } OTSniffing::~OTSniffing() { SLOT_Trace( 0 ); } void OTSniffing::SLOT_Trace( bool Run ) { if( ! Run ) { if ( HciDump ) { HciDump->process().kill(); delete HciDump; } HciDump = 0; 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 ) ) { QMessageBox::warning(0, tr("Save log"), tr("Cannot open %1").arg(S) ); return; } QTextStream TS ( &F ); SLOT_ClearLog(); S = TS.read(); // Output_LB->insertStringList( QStringList::split( "\n", S ) ); Output_TV->setText( S ); } } void OTSniffing::SLOT_ClearLog( void ) { // Output_LB->clear(); Output_TV->setText( "" ); } // // // // // OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) : OTPairingGUI( parent ) { OT = OTGateway::getOTGateway(); Icons = (_IC ) ? _IC : new OTIcons(); MyIcons = (_IC == 0 ); // unpairing can only be done if bluetooth is disabled Unpair_But->setEnabled( ! OT->isEnabled() ); if( ! OT->isEnabled() ) { Unpair_LBL->hide(); } else { Unpair_LBL->show(); } // open linkkey file and load pairs LinkKeyArray Keys = OT->getLinkKeys(); LinkKeyLVI * it; OTPeer * P; OTDriver * D; for( unsigned int i = 0 ; i < Keys.count(); i ++ ) { it = new LinkKeyLVI( i, Pairs_LV ); P = 0; D = OT->findDriver( Keys[i].from() ); if( D ) { it->setText( 0, D->devname() ); // we are source P = OT->findPeer( Keys[i].to() ); if( P ) { // put name it->setText( 1, P->name() ); } else { // unknown it->setText( 1, Keys[i].to().toString() ); } // and put address as sub QListViewItem * Sub = new QListViewItem( it ); Sub->setText( 0, D->address().toString() ); Sub->setText( 1, Keys[i].to().toString() ); } else { // perhaps we are destination D = OT->findDriver( Keys[i].to() ); if( D ) { it->setText( 1, D->devname() ); // we are source P = OT->findPeer( Keys[i].from() ); if( P ) { // put name it->setText( 0, P->name() ); } else { // unknown it->setText( 0, Keys[i].from().toString() ); } // and put address as sub QListViewItem * Sub = new QListViewItem( it ); Sub->setText( 0, Keys[i].from().toString() ); Sub->setText( 1, D->address().toString() ); } else { // 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; return rv; } void OTScan::setScanFilter( const UUIDVector & V ) { Filter = V; } void OTScan::resetScanFilter( void ) { Filter.truncate(0); } void OTScan::SLOT_DoScan( bool DoIt ) { if( DoIt ) { OT->scanNeighbourhood(); } else { OT->stopScanOfNeighbourhood(); } scanMode( DoIt ); } // double clicked on a device void OTScan::SLOT_Selected( QListViewItem * it ) { if( ! it ) return; if( Filter.count() > 0 ) { // filter on service if( it->depth() == 0 ) { // select a service and not a device return; } // store result SelectedPeer = ((PeerLVI *)it->parent())->peer(); SelectedChannel = ((ChannelLVI *)it)->channel(); } else { // click on device if( it->depth() != 0 ) { return; } SelectedPeer = ((PeerLVI *)it)->peer(); SelectedChannel = 0; } odebug << "Selected " << SelectedPeer->address().toString() << " Channel " << SelectedChannel << oendl; emit selected(); } void OTScan::SLOT_FinishedDetecting( ) { scanMode( false ); } void OTScan::SLOT_CleanupOld( ) { // iterate over all peers and find those that // are down and have no pairing info OTPeer * TheP; const LinkKeyArray & Keys = OT->getLinkKeys(); QListViewItem * Lit = DetectedPeers_LV->firstChild(); while( Lit ) { TheP = ((PeerLVI *)Lit)->peer(); if( TheP->state() == OTPeer::Peer_Down ) { unsigned int k; // what about linkkeys ? for( k = 0; k < Keys.count(); k ++ ) { if( TheP->address() == Keys[k].to() || TheP->address() == Keys[k].from() ) { // part of linkkey odebug << "LINKKEY " << TheP->address().toString() << oendl; break; } } if( k == Keys.count() ) { odebug << "RM LINKKEY " << TheP->address().toString() << oendl; // not found -> remember to remove this peer QListViewItem * Nit; OT->removePeer( TheP ); Nit = Lit->nextSibling(); delete Lit; Lit = Nit; continue; } } else { odebug << "NODOWN " << TheP->address().toString() << oendl; } Lit = Lit->nextSibling(); } } void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){ PeerLVI * it = 0; if( IsNew ) { it = new PeerLVI( P, DetectedPeers_LV ); } else { // find peer in table QListViewItem * Lit = DetectedPeers_LV->firstChild(); while( Lit ) { if( ((PeerLVI *)Lit)->peer() == P ) { // this item it = (PeerLVI *)Lit; break; } Lit = Lit->nextSibling(); } if( ! it ) { odebug << "Should not occur" << oendl; return; } } // update/show info it->setText( 0, P->name() ); it->setPixmap(0, Icons->deviceIcon( OT->deviceTypeToName( P->deviceClass() ) ) ); // tell peer to report its state async connect( P, SIGNAL( peerStateReport( OTPeer *)), this, SLOT( SLOT_PeerState( OTPeer *)) ); if( IsNew ) { // find state refreshState( (PeerLVI *)it, 1 ); } else { // update staet SLOT_PeerState( P ); } } void OTScan::SLOT_PeerState( OTPeer * P ) { PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild(); while( it ) { if( it->peer() == P ) { break; } it = (PeerLVI * )it->nextSibling(); } if( ! it ) return; switch( P->state() ) { case OTPeer::Peer_Unknown : case OTPeer::Peer_Down : it->setPixmap( 1, 0 ); break; case OTPeer::Peer_Up : it->setPixmap( 1, Icons->loadPixmap( ( P->connectedTo() ) ? "connected" : "notconnected" ) ); if( it == Current && ! StrengthTimer->isActive() ) { // start showing strength StrengthTimer->start( 1000, FALSE ); SLOT_UpdateStrength(); } break; } } void OTScan::SLOT_RefreshState( void ) { QListViewItem * it = DetectedPeers_LV->firstChild(); while( it ) { if( it->isSelected() ) { break; } it = it->nextSibling(); } if( ! it ) return; refreshState( (PeerLVI *)it, 1 ); } void OTScan::refreshState( PeerLVI * it, bool Force ) { it->setPixmap( 1, Icons->loadPixmap( "find" ) ); it->peer()->findOutState( 30, Force ); } void OTScan::SLOT_Show( QListViewItem * it ) { if( ! it || it->depth() > 0 ) return; QString S; Current = (PeerLVI *)it; Strength_PB->setProgress( 0 ); // reset Address_LBL->setText( Current->peer()->address().toString() ); Peer_GB->setTitle( Current->peer()->name() ); const LinkKeyArray & Keys = OT->getLinkKeys(); Paired_Led->setOn( FALSE ); for( unsigned int i = 0; i < Keys.count(); i ++ ) { if( Current->peer()->address() == Keys[i].to() ) { Paired_Led->setOn( TRUE ); break; } } if( Current->peer()->state() == OTPeer::Peer_Up ) { RefreshServices_But->setEnabled( TRUE ); StrengthTimer->start( 1000, FALSE ); SLOT_UpdateStrength(); } else { RefreshServices_But->setEnabled( FALSE ); } } void OTScan::SLOT_UpdateStrength( void ) { OTDriver * D = Current->peer()->connectedTo(); if( D ) { long Q = D->getLinkQuality( Current->peer()->address() ); Strength_PB->setProgress( Q ); if( ! Q ) { // no quality Strength_PB->setEnabled( TRUE ); StrengthTimer->stop(); } } else { Strength_PB->setEnabled( FALSE ); Strength_PB->setProgress( 0 ); // no point in continuing StrengthTimer->stop(); } } void OTScan::SLOT_RefreshServices( void ) { QListViewItem * it = DetectedPeers_LV->firstChild(); while( it ) { if( it->isSelected() ) { break; } it = it->nextSibling(); } if( ! it ) return; QString S; PeerLVI * PI = (PeerLVI *)it; scanMode( true ); qApp->processEvents(0); ServiceVector & V = PI->peer()->services(); while( PI->firstChild() ) { // remove children delete PI->firstChild(); } for( unsigned int i = 0 ; i < V.count(); i ++ ) { QString S; S = V[i]->name(); if( S.isEmpty() ) { continue; } { QListViewItem * SIt; UUIDVector UIDV; QPixmap Pm; bool Done = 0; bool R; short ID; SIt = 0; UIDV = V[i]->classIDList(); // first all UUID ! 1200 12ff (Genericprofiles) for( unsigned int j = 0; j < UIDV.count(); j ++ ) { if( Filter.count() ) { bool FilterOut = 1; // filter out if not in list for( unsigned int ff = 0; ff < Filter.count(); ff ++ ) { if( UIDV[j] == Filter[ff] ) { FilterOut = 0; break; } } if( FilterOut ) { // not in filter list continue; } } // else show ID = UIDV[j].toShort(); if( ID < 0x1200 || ID > 0x12ff ) { // use this profile if( R ) { unsigned int ch; bool has; has = V[i]->rfcommChannel( ch ); SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); SIt->setText(0, V[i]->name() ); Pm = Icons->serviceIcon( ID, R ); SIt->setPixmap(0, Pm ); Done = 1; break; } } } if( ! Done ) { // check other range too for( unsigned int j = 0; j < UIDV.count(); j ++ ) { if( Filter.count() ) { bool FilterOut = 1; // filter out if not in list for( unsigned int ff = 0; ff < Filter.count(); ff ++ ) { if( UIDV[j] == Filter[ff] ) { FilterOut = 0; break; } } if( FilterOut ) { // not in filter list continue; } } // else show ID = UIDV[j].toShort(); if( ID >= 0x1200 && ID <= 0x12ff ) { // use this profile unsigned int ch; bool has; has = V[i]->rfcommChannel( ch ); SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); SIt->setText(0, V[i]->name() ); Pm = Icons->serviceIcon( ID, R ); SIt->setPixmap(0, Pm ); break; } } } } } scanMode( false ); } void OTScan::scanMode( bool M ) { // avoid infinite loop because it triggers DoScan Detect_But->blockSignals( TRUE ); Detect_But->setOn( M ); Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") ); Detect_But->blockSignals( FALSE ); } // // // // // OTManage::OTManage( QWidget * parent, OTIcons * _IC ) : OTManageGUI( parent ) { OT = OTGateway::getOTGateway(); Icons = (_IC ) ? _IC : new OTIcons(); MyIcons = (_IC == 0 ); AllDrivers_LV->setSorting(-1); connect( OT, SIGNAL( driverListChanged() ), this, SLOT( SLOT_DriverListChanged() ) ); connect( OT, SIGNAL( stateChange( OTDriver *, bool ) ), this, SLOT( SLOT_StateChange( OTDriver *, bool ) ) ); SLOT_DriverListChanged(); AllDrivers_LV->header()->hide(); } OTManage::~OTManage() { if( MyIcons ) delete Icons; OTGateway::releaseOTGateway(); } void OTManage::SLOT_ShowDriver( QListViewItem * It ) { if( It == 0 || It->depth() > 0 ) // not toplevel return; DriverLVI * it = (DriverLVI *) It; DriverIsUp_CB->setChecked( it->driver()->isUp() ); } void OTManage::SLOT_UpDriver( bool Up ) { QListViewItem * it = AllDrivers_LV->firstChild(); while( it ) { if( it->isSelected() ) { OTDriver * D = ((DriverLVI *)it)->driver(); odebug << "UP driver " << D->devname() << oendl; // this D->setUp( Up ); return; } it = it->nextSibling(); } } void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) { QListViewItem * it = AllDrivers_LV->firstChild(); while( it ) { if( ((DriverLVI *)it)->driver() == D ) { it->setPixmap( 0, Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) ); return; } it = it->nextSibling(); } } void OTManage::SLOT_DriverListChanged( ) { DriverLVI * It; QListViewItem * Sub; QListViewItem * First = 0; OTDriver* D; OTDriverList & DL = OT->getDriverList(); 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 @@ -1,235 +1,237 @@ #include <qfile.h> #include <qfileinfo.h> #include "PPPedit.h" #include "ppp_NNI.h" #include "ppp_NN.h" APPP::APPP( PPPNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.DNS.ServerAssigned = 1; Data.DNS.DomainName = ""; Data.Auth.Mode = 0; Data.Auth.Login.Expect = "ogin:"; Data.Auth.Password.Expect = "assword:"; Data.Auth.PCEMode = 0; Data.Auth.Client = "*"; Data.Auth.Server = "*"; Data.Auth.Secret = ""; Data.IP.LocalAddress = "10.0.0.1"; Data.IP.RemoteAddress = "10.0.0.2"; Data.IP.LocalOverrule = 1; Data.IP.RemoteOverrule = 1; Data.IP.GWAutomatic = 1; Data.IP.GWAddress = ""; Data.IP.GWIsDefault = 1; Data.IP.GWIfNotSet = 1; Data.Run.PreConnect = ""; Data.Run.PostConnect = ""; Data.Run.PreDisconnect = ""; Data.Run.PostDisconnect = ""; GUI = 0; RT = 0; } void APPP::setSpecificAttribute( QString & A, QString & V ) { if( A.startsWith( "dns" ) ) { if( A == "dnsserverassigned" ) { Data.DNS.ServerAssigned = (V == "yes"); } else if( A == "dnsdomainname" ) { Data.DNS.DomainName = V; } else if( A == "dnsserver" ) { Data.DNS.Servers.resize( Data.DNS.Servers.size()+1 ); Data.DNS.Servers[Data.DNS.Servers.size()-1] = new QString( V ); } } else if( A.startsWith( "auth" ) ) { if( A == "authmode" ) { Data.Auth.Mode = V.toShort(); } else if( A == "authloginexpect" ) { Data.Auth.Login.Expect = V; } else if( A == "authloginsend" ) { Data.Auth.Login.Send = V; } else if( A == "authpasswordexpect" ) { Data.Auth.Password.Expect = V; } else if( A == "authpasswordsend" ) { Data.Auth.Password.Send = V; } else if( A == "authpcemode" ) { Data.Auth.PCEMode = V.toShort(); } else if( A == "authclient" ) { Data.Auth.Client = V; } else if( A == "authserver" ) { Data.Auth.Server = V; } else if( A == "authsecret" ) { Data.Auth.Secret = V; } } else if( A.startsWith( "ip" ) ) { if( A == "iplocaloverrule" ) { Data.IP.LocalOverrule = (V == "yes"); } else if( A == "ipremoteoverrule" ) { Data.IP.RemoteOverrule = (V == "yes"); } else if( A == "ipgwautomatic" ) { Data.IP.GWAutomatic = (V == "yes"); } else if( A == "ipgwisdefault" ) { Data.IP.GWIsDefault = (V == "yes"); } else if( A == "ipgwifnotset" ) { Data.IP.GWIfNotSet = (V == "yes"); } else if( A == "iplocaladdress" ) { Data.IP.LocalAddress = V; } else if( A == "ipremoteaddress" ) { Data.IP.RemoteAddress = V; } else if( A == "ipgwaddress" ) { Data.IP.GWAddress = V; } } else if( A.startsWith( "run" ) ) { if( A == "runpreconnect" ) { Data.Run.PreConnect = V; } else if( A == "runpostconnect" ) { Data.Run.PostConnect = V; } else if( A == "runpredisconnect" ) { Data.Run.PreDisconnect = V; } else if( A == "runpostdisconnect" ) { Data.Run.PostDisconnect = 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 ); } } else if ( SF.name() == "peers" ) { QFileInfo FI(SF.path()); Log(("Generate PPP for %s\n", SF.name().latin1() )); SF << "connect \"/usr/sbin/chat -v -f /etc/chatscripts/" << FI.baseName() << "\"" << endl; if( Data.IP.GWIsDefault ) { SF << "defaultroute" << endl; } SF << "linkname " << removeSpaces( SF.name().latin1() ) << endl; // insert other data here rvl = 0; rvd = networkSetup()->getToplevel()->generateFileEmbedded( SF, DevNr ); } else if ( SF.name() == "chatscripts" ) { Log(("Generate PPP for %s\n", SF.name().latin1() )); rvl = 0; rvd = networkSetup()->getToplevel()->generateFileEmbedded( SF, DevNr ); } return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } 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(); } |