Diffstat (limited to 'noncore/settings/networksettings2/bluetooth') (more/less context) (ignore whitespace changes)
5 files changed, 359 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp new file mode 100644 index 0000000..ee3e92b --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.cpp @@ -0,0 +1,78 @@ +#include "bluetoothBNEP_NN.h" +#include "bluetoothBNEP_NNI.h" +#include "bluetoothRFCOMM_NNI.h" + +// +// +// BLUETOOTH PAN/NAP node +// +// + +static const char * BluetoothBNEPNeeds[] = + { 0 + }; + +static const char * BluetoothBNEPProvides[] = + { "device", + 0 + }; + +/** + * Constructor, find all of the possible interfaces + */ +BluetoothBNEPNetNode::BluetoothBNEPNetNode() : + ANetNode(tr("Bluetooth PAN/NAP")) { + InstanceCount = 7; // default +} + +/** + * Delete any interfaces that we own. + */ +BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ +} + +const QString BluetoothBNEPNetNode::nodeDescription(){ + return tr("\ +<p>Sets up a bluetooth link using the bluetooth Network profile.</p>\ +<p>Use this to connect two computing devices.</p>\ +" +); +} + +ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { + return new ABluetoothBNEP( this ); +} + +const char ** BluetoothBNEPNetNode::needs( void ) { + return BluetoothBNEPNeeds; +} + +const char ** BluetoothBNEPNetNode::provides( void ) { + return BluetoothBNEPProvides; +} + +QString BluetoothBNEPNetNode::genNic( long nr ) { + QString S; + return S.sprintf( "bnep%ld", nr ); +} + + +void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { + if( A == "interfacecount" ) { + InstanceCount = V.toLong(); + } +} + +void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) { + TS << "interfacecount=" + << InstanceCount + << endl; +} + +extern "C" { +// create plugin registers both BT functions +void create_plugin( QList<ANetNode> & PNN ) { + PNN.append( new BluetoothBNEPNetNode() ); + PNN.append( new BluetoothRFCOMMNetNode() ); +} +} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.h new file mode 100644 index 0000000..5057e6d --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NN.h @@ -0,0 +1,44 @@ +#ifndef BLUETOOTHBNEP_NETNODE_H +#define BLUETOOTHBNEP_NETNODE_H + +#include "netnode.h" +#include "bluetoothRFCOMM_NN.h" + +class ABluetoothBNEP; + +class BluetoothBNEPNetNode : public ANetNode { + + Q_OBJECT + +public: + + BluetoothBNEPNetNode(); + virtual ~BluetoothBNEPNetNode(); + + virtual QString genNic( long ); + virtual long instanceCount( void ) + { return InstanceCount; } + virtual const QString pixmapName() + { return "Devices/bluetooth"; } + + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** provides( void ); + virtual const char ** needs( void ); + +private: + + virtual void setSpecificAttribute( QString & Attr, QString & Value ); + virtual void saveSpecificAttribute( QTextStream & TS ); + + // number of interfaces for this device + long InstanceCount; + +}; + +extern "C" +{ + void create_plugin( QList<ANetNode> & PNN ); +}; + +#endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.cpp new file mode 100644 index 0000000..2b17ab5 --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.cpp @@ -0,0 +1,46 @@ +#include "bluetoothRFCOMM_NN.h" +#include "bluetoothRFCOMM_NNI.h" + +static const char * BluetoothRFCOMMNeeds[] = + { 0 + }; + +static const char * BluetoothRFCOMMProvides[] = + { "line", + "GPRS" + }; + +BluetoothRFCOMMNetNode::BluetoothRFCOMMNetNode() : + ANetNode( tr("Bluetooth serial link") ) { +} + +BluetoothRFCOMMNetNode::~BluetoothRFCOMMNetNode(){ +} + +const QString BluetoothRFCOMMNetNode::nodeDescription(){ + return tr("\ +<p>Sets up a bluetooth link using the bluetooth serial profile.</p>\ +<p>Use this to connect to a GSM.</p>\ +" +); +} + +ANetNodeInstance * BluetoothRFCOMMNetNode::createInstance( void ) { + return new ABluetoothRFCOMM( this ); +} + +const char ** BluetoothRFCOMMNetNode::needs( void ) { + return BluetoothRFCOMMNeeds; +} + +const char ** BluetoothRFCOMMNetNode::provides( void ) { + return BluetoothRFCOMMProvides; +} + +void BluetoothRFCOMMNetNode::setSpecificAttribute( QString &, QString & ) { +} + +void BluetoothRFCOMMNetNode::saveSpecificAttribute( QTextStream & ) { +} + +// create plugin -> see BNEP diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.h new file mode 100644 index 0000000..cc7037a --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NN.h @@ -0,0 +1,29 @@ +#ifndef BLUETOOTHRFCOMM_NETNODE_H +#define BLUETOOTHRFCOMM_NETNODE_H + +#include "netnode.h" + +class BluetoothRFCOMMNetNode : public ANetNode { + + Q_OBJECT + +public: + + BluetoothRFCOMMNetNode(); + virtual ~BluetoothRFCOMMNetNode(); + + virtual const QString pixmapName() + { return "Devices/bluetooth"; } + + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char ** provides( void ); + +private: + + virtual void setSpecificAttribute( QString & Attr, QString & Value ); + virtual void saveSpecificAttribute( QTextStream & TS ); +}; + +#endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp new file mode 100644 index 0000000..1e91ed1 --- a/dev/null +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp @@ -0,0 +1,162 @@ +#include <qapplication.h> +#include <resources.h> +#include <OTDevice.h> +#include <OTGateway.h> +#include "bluetoothRFCOMMrun.h" + +using namespace Opietooth2; + +BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) { + if( OT ) { + OTGateway::releaseOTGateway(); + } +} + +State_t BluetoothRFCOMMRun::detectState( void ) { + + if( ! OT ) { + OT = OTGateway::getOTGateway(); + } + + if( deviceNrOfConnection() >= 0 ) { + return Available; + } + + owarn << "Bluetooth " + << OT->isEnabled() + << oendl; + + return ( OT->isEnabled() ) ? Off : Unavailable; +} + +QString BluetoothRFCOMMRun::setMyState( NodeCollection *, + 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 ); + + 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 connection" ); + } + 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; + 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) ) { + owarn << "Selected " << Data->Devices[i]->Name << oendl; + Ch = Data->Devices[i]; + break; + } + } + } + + delete Dlg; + return Ch; +} + +QString BluetoothRFCOMMRun::deviceFile( void ) { + if( deviceNrOfConnection() >= 0 ) { + OTDevice * OTD = OT->getOTDevice(); + // there is a connection + return OTD->getRFCommDevicePattern().arg(DeviceNr); + } + return QString(); +} + +int BluetoothRFCOMMRun::deviceNrOfConnection( void ) { + + if( ! OT ) { + OT = OTGateway::getOTGateway(); + } + + DeviceNr = -1; + for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { + owarn << "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 ) { + owarn << "Up " + << oendl; + break; + } + } + return DeviceNr; +} |