Diffstat (limited to 'noncore/settings/networksettings2/bluetooth') (more/less context) (show whitespace changes)
15 files changed, 594 insertions, 289 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth.pro b/noncore/settings/networksettings2/bluetooth/bluetooth.pro index 8170d46..2e3b5bb 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth.pro +++ b/noncore/settings/networksettings2/bluetooth/bluetooth.pro @@ -1,22 +1,26 @@ TEMPLATE = lib CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/plugins/networksettings2 -HEADERS = bluetooth_NN.h \ +HEADERS = bluetoothBNEP_NN.h \ bluetoothBNEP_NNI.h \ + bluetoothRFCOMM_NN.h \ bluetoothRFCOMM_NNI.h \ bluetoothBNEPedit.h \ + bluetoothRFCOMMrun.h \ bluetoothRFCOMMedit.h -SOURCES = bluetooth_NN.cpp \ +SOURCES = bluetoothBNEP_NN.cpp \ bluetoothBNEP_NNI.cpp \ + bluetoothRFCOMM_NN.cpp \ bluetoothRFCOMM_NNI.cpp \ bluetoothBNEPedit.cpp \ bluetoothBNEPrun.cpp \ + bluetoothRFCOMMrun.cpp \ bluetoothRFCOMMedit.cpp -INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 -DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 -LIBS += -lqpe +INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 ../opietooth2 +DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 ../opietooth2 +LIBS += -lqpe -lopietooth2 INTERFACES = bluetoothBNEPGUI.ui bluetoothRFCOMMGUI.ui TARGET = bluetooth VERSION = 1.0.0 include( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp index 398dcdc..42b2515 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp @@ -1,11 +1,11 @@ #include "bluetoothBNEPedit.h" #include "bluetoothBNEP_NNI.h" -#include "bluetooth_NN.h" +#include "bluetoothBNEP_NN.h" ABluetoothBNEP::ABluetoothBNEP( BluetoothBNEPNetNode * PNN ) : ANetNodeInstance( PNN ), Data() { GUI = 0; RT = 0; Data.AllowAll = 1; } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h index 03c6903..f52a2c5 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPdata.h @@ -1,11 +1,14 @@ #ifndef BLUETOOTHBNEP_DATA_H #define BLUETOOTHBNEP_DATA_H #include <qstringlist.h> -typedef struct BluetoothBNEPData { +class BluetoothBNEPData { + +public : + bool AllowAll; QStringList BDAddress; -} BluetoothBNEPData_t; +}; #endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp index 24e4b7b..9d4ae97 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.cpp @@ -1,249 +1,161 @@ #include <qfile.h> #include <qfileinfo.h> #include <qtextstream.h> #include <resources.h> #include "bluetoothBNEPrun.h" -QDict<QString> * BluetoothBNEPRun::PANConnections = 0; - -void BluetoothBNEPRun::detectState( NodeCollection * NC ) { - // unavailable : no card found - // available : card found and assigned to us or free - // up : card found and assigned to us and up - QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); - System & Sys = NSResources->system(); - InterfaceInfo * Run; - QFile F( S ); - - Log(("Detecting for %s\n", NC->name().latin1() )); - - if( F.open( IO_ReadOnly ) ) { - // could open file -> read interface and assign - QString X; - bool accepted = 0; - QTextStream TS(&F); - X = TS.readLine(); - Log(("%s exists : %s\n", S.latin1(), X.latin1() )); - // find interface - if( handlesInterface( X ) ) { - - Log(("Handles interface %s, PANC %p\n", X.latin1(), PANConnections )); - if( PANConnections == 0 ) { - // load connections that are active - // format : bnep0 00:60:57:02:71:A2 PANU - FILE * OutputOfCmd = popen( "pand --show", "r" ) ; - - PANConnections = new QDict<QString>; - - if( OutputOfCmd ) { - char ch; - // could fork - // read all data - QString Line = ""; - while( 1 ) { - if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) { - // eof - break; - } - if( ch == '\n' || ch == '\r' ) { - if( ! Line.isEmpty() ) { - if( Line.startsWith( "bnep" ) ) { - QStringList SL = QStringList::split( " ", Line ); - Log(("Detected PAN %s %s\n", - SL[0].latin1(), SL[1].latin1() )); - PANConnections->insert( SL[0], new QString(SL[1])); - } - Line=""; - } - } else { - Line += ch; +BluetoothBNEPRun::BluetoothBNEPRun( ANetNodeInstance * NNI, + BluetoothBNEPData & D ) : + RuntimeInfo( NNI ), + Data( D), + Pat( "bnep[0-6]" ) { + OT = 0; } + +BluetoothBNEPRun::~BluetoothBNEPRun( void ) { + if( OT ) { + OTGateway::releaseOTGateway(); } } - pclose( OutputOfCmd ); - } +State_t BluetoothBNEPRun::detectState( void ) { - // check if this runtime allows connection to node - if( ! Data.AllowAll ) { - // has addresses - for ( QStringList::Iterator it = Data.BDAddress.begin(); - ! accepted && it != Data.BDAddress.end(); - ++ it ) { - for( QDictIterator<QString> it2( *(PANConnections) ); - it2.current(); - ++ it2 ) { - if( X == it2.currentKey() && - (*it) == *(it2.current()) - ) { - // found - Log(("%s accepts connections to %s\n", - NC->name().latin1(), - it2.current()->latin1() )); - accepted = 1; - break; - } - } - } - } else { - Log(("%s accepts any connection\n", NC->name().latin1() )); - // accept any - accepted = 1; - } + /* - if( accepted ) { - // matches and is allowed for this node - for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); - It.current(); - ++It ) { - Run = It.current(); - if( X == Run->Name ) { - Log(("%s Assigned %p\n", NC->name().latin1(), Run )); - Run->assignNode( netNode() ); - assignInterface( Run ); - NC->setCurrentState( IsUp ); - return; - } - } - } - } - } + need to detect - Log(("Assigned %p\n", assignedInterface() )); - if( ( Run = assignedInterface() ) ) { - // we already have an interface assigned -> still present ? - if( ! Run->IsUp ) { - // usb is still free -> keep assignment - NC->setCurrentState( Available ); - return; - } // else interface is up but NOT us -> some other profile - } - - // nothing (valid) assigned to us - assignInterface( 0 ); - - // find possible interface - for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); - It.current(); - ++It ) { - Run = It.current(); - - Log(("%s %d %d=%d %d\n", - Run->Name.latin1(), - handlesInterface( Run->Name ), - Run->CardType, ARPHRD_ETHER, - ! Run->IsUp )); - - if( handlesInterface( Run->Name ) && - Run->CardType == ARPHRD_ETHER && - ! Run->IsUp - ) { - Log(("Released(OFF)\n" )); - // proper type, and Not UP -> free - NC->setCurrentState( Off ); - return; + 1. for any PAN connection that is found if that + PAN is connected. + + if it is connected it is not available (since we do + not manage IP settings and we are called to detect + the state we knwo that we do not have an UP connection) + + 2. if it not connected and we allow any connection we + are available or if that PAN connection is to a device + with a correct address + + 3. if it is not connected and the address do not match or + we do not accept any address, we are Unavailable but + not DOWN. I.e a new connection could perhaps be created + + */ + + if( ! OT ) { + OT = OTGateway::getOTGateway(); } + + if( ! OT->isEnabled() ) { + return Unavailable; } - // no free found - Log(("None available\n" )); - NC->setCurrentState( Unavailable ); + // if there is a PAN connection that is UP but not + // yet configured (no ifup) the we are available + return ( hasFreePANConnection() ) ? Available : Unknown; } -bool BluetoothBNEPRun::setState( NodeCollection * NC, Action_t A, bool ) { +QString BluetoothBNEPRun::setMyState( NodeCollection * NC, Action_t A, bool ) { - // we only handle activate and deactivate - switch( A ) { - case Activate : - { - if( NC->currentState() != Off ) { - return 0; - } - InterfaceInfo * N = getInterface(); - if( ! N ) { - // no interface available - NC->setCurrentState( Unavailable ); - return 0; + if( A == Activate ) { + if( hasFreePANConnection( 1 ) ) { + // we have now an assignedinterface + } else { + return QString("TODO : Start PAND"); } - // because we were OFF the interface - // we get back is NOT assigned - N->assignNode( netNode() ); - assignInterface( N ); - Log(("Assing %p\n", N )); + + Log(( "Assigned interface" )); NC->setCurrentState( Available ); - return 1; - } - case Deactivate : - if( NC->currentState() == IsUp ) { - // bring down first - if( ! connection()->setState( Down ) ) - // could not ... - return 0; - } else if( NC->currentState() != Available ) { - return 1; + + return QString(); } - assignedInterface()->assignNode( 0 ); // release - assignInterface( 0 ); + + if( A == Deactivate ) { + // nothing to do NC->setCurrentState( Off ); - return 1; - default : - // FT - break; + return QString(); } - return 0; + return QString(); } -bool BluetoothBNEPRun::canSetState( State_t Curr , Action_t A ) { - // we only handle up down activate and deactivate - switch( A ) { - case Activate : - { // at least available - if( Curr == Available ) { - return 1; +bool BluetoothBNEPRun::handlesInterface( const QString & S ) { + return Pat.match( S ) >= 0; } - // or we can make one available - InterfaceInfo * N = getInterface(); - if( ! N || N->assignedNode() != 0 ) { - // non available or assigned - return 0; + +bool BluetoothBNEPRun::handlesInterface( InterfaceInfo * I ) { + return handlesInterface( I->Name ); } - return 1; + +bool BluetoothBNEPRun::hasFreePANConnection( bool Grab ) { + + if( ! OT ) { + OT = OTGateway::getOTGateway(); } - case Deactivate : - return ( Curr >= Available ); - default : - // FT + + // load PAN connections + OTPANConnection * C; + InterfaceInfo * Run; + InterfaceInfo * Candidate = 0; // reuse this interface + PANConnectionVector Conns = OT->getPANConnections(); + System & Sys = NSResources->system(); + bool IsValid; + + for( unsigned int i = 0; + i < Conns.count(); + i ++ ) { + C = Conns[i]; + + if( Data.AllowAll ) { + // we allow all + IsValid = 1; + } else { + // is this PAN connection connecting to a Peer + // we allow ? + IsValid = 0; + for ( QStringList::Iterator it = Data.BDAddress.begin(); + it != Data.BDAddress.end(); + ++ it ) { + if( C->ConnectedTo == (*it) ) { + // this is a connection we could accept + IsValid = 1; break; } - return 0; + } } -// get interface that is free or assigned to us -InterfaceInfo * BluetoothBNEPRun::getInterface( void ) { + if( ! IsValid ) { + Log(("%s to %s not acceptable\n", + C->Device.latin1(), + C->ConnectedTo.latin1() )); + // don't bother checking this address + // it is not acceptable + continue; + } - System & S = NSResources->system(); - InterfaceInfo * best = 0, * Run; + // is this PAN connection available to us ? + Run = Sys.findInterface( C->Device ); - for( QDictIterator<InterfaceInfo> It(S.interfaces()); - It.current(); - ++It ) { - Run = It.current(); - if( handlesInterface( Run->Name ) && - Run->CardType == ARPHRD_ETHER - ) { - // this is a bluetooth card - if( Run->assignedNode() == netNode() ) { - // assigned to us - return Run; - } else if( Run->assignedNode() == 0 ) { - // free - best = Run; + if( Run && Run->IsUp ) { + // this PAN connection is up + Log(("%s acceptable but unavailable\n", + C->Device.latin1() )); + // find others + continue; } + + // we at least have a possible interface + if( ! Candidate ) { + Candidate = Run; } } - return best; // can be 0 + + if( Candidate ) { + if ( Grab ) { + netNode()->connection()->assignInterface( Candidate ); + } + return 1; } -bool BluetoothBNEPRun::handlesInterface( const QString & S ) { - return Pat.match( S ) >= 0; + // no free PAN + return 0; } + diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h index ce03cbb..a05a7a2 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h @@ -1,34 +1,35 @@ -#include <asdevice.h> +#include <netnode.h> #include "bluetoothBNEPdata.h" -class BluetoothBNEPRun : public AsDevice { +#include <OTGateway.h> +using namespace Opietooth2; + +class BluetoothBNEPRun : public RuntimeInfo { public : BluetoothBNEPRun( ANetNodeInstance * NNI, - BluetoothBNEPData & D ) : - AsDevice( NNI ), - Data( D), - Pat( "bnep[0-6]" ) - { } + BluetoothBNEPData & D ); + virtual ~BluetoothBNEPRun( void ); + + // i am a device + virtual RuntimeInfo * device( void ) + { return this; } - virtual AsDevice * asDevice( void ) - { return (AsDevice *)this; } + bool handlesInterface( const QString & ); + bool handlesInterface( InterfaceInfo * ); - virtual AsDevice * device( void ) - { return asDevice(); } + State_t detectState( void ); protected : - void detectState( NodeCollection * ); - bool setState( NodeCollection * , Action_t, bool ); - bool canSetState( State_t , Action_t ); - bool handlesInterface( const QString & ); + QString setMyState( NodeCollection * , Action_t, bool ); private : - InterfaceInfo * getInterface( void ); + bool hasFreePANConnection( bool Grab = 0 ); + BluetoothBNEPData & Data; - static QDict<QString> * PANConnections; + OTGateway * OT; QRegExp Pat; }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui index 2754a70..7f6565a 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMGUI.ui @@ -6,126 +6,326 @@ <name>name</name> <cstring>BluetoothRFCOMM_FRM</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>283</width> - <height>199</height> + <width>488</width> + <height>604</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Bluetooth-rfcomm</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> - <number>2</number> + <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>2</number> + <number>3</number> </property> <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel5_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Selected devices with gprs capability</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>WordBreak|AlignVCenter|AlignLeft</set> + </property> + <property> + <name>wordwrap</name> + </property> + </widget> + <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout4</cstring> + <cstring>Layout8</cstring> + </property> + <property> + <name>layoutSpacing</name> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>3</number> </property> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel4</cstring> + <cstring>TextLabel5</cstring> </property> <property stdset="1"> <name>text</name> - <string>Name</string> + <string>Address</string> </property> </widget> <widget> <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>Name_LE</cstring> + <cstring>Address_LE</cstring> + </property> + </widget> + <widget> + <class>QToolButton</class> + <property stdset="1"> + <name>name</name> + <cstring>FindDevice_TB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>...</string> </property> </widget> </hbox> </widget> <widget> + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout7</cstring> + </property> + <property> + <name>layoutSpacing</name> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>3</number> + </property> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Channel</string> + </property> + </widget> + <widget> + <class>QSpinBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Channel_SB</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>minValue</name> + <number>1</number> + </property> + </widget> + <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel3</cstring> + <cstring>TextLabel2_2</cstring> </property> <property stdset="1"> <name>text</name> - <string>Description</string> + <string>Name</string> </property> </widget> <widget> - <class>QMultiLineEdit</class> + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>Description_LE</cstring> + <cstring>Name_LBL</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Box</enum> </property> + <property stdset="1"> + <name>indent</name> + <number>0</number> + </property> + </widget> + </hbox> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout5</cstring> </property> + <property> + <name>layoutSpacing</name> + </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>3</number> </property> <widget> - <class>QCheckBox</class> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel7</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>text</name> + <string>Addresses</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignVCenter|AlignLeft</set> + </property> + <property> + <name>vAlign</name> + </property> + </widget> + <widget> + <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>Automatic_CB</cstring> + <cstring>Add_TB</cstring> </property> <property stdset="1"> <name>text</name> - <string>Start automatically</string> + <string>...</string> </property> </widget> <widget> - <class>QCheckBox</class> + <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>Confirm_CB</cstring> + <cstring>Remove_TB</cstring> </property> <property stdset="1"> <name>text</name> - <string>Confirm before start</string> + <string>...</string> </property> </widget> </hbox> </widget> + <widget> + <class>QListView</class> + <column> + <property> + <name>text</name> + <string>Name</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Channel</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Address</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <property stdset="1"> + <name>name</name> + <cstring>Addresses_LV</cstring> + </property> + <property stdset="1"> + <name>allColumnsShowFocus</name> + <bool>true</bool> + </property> + </widget> </vbox> </widget> +<connections> + <connection> + <sender>Add_TB</sender> + <signal>clicked()</signal> + <receiver>BluetoothRFCOMM_FRM</receiver> + <slot>SLOT_AddServer()</slot> + </connection> + <connection> + <sender>Remove_TB</sender> + <signal>clicked()</signal> + <receiver>BluetoothRFCOMM_FRM</receiver> + <slot>SLOT_RemoveServer()</slot> + </connection> + <connection> + <sender>FindDevice_TB</sender> + <signal>clicked()</signal> + <receiver>BluetoothRFCOMM_FRM</receiver> + <slot>SLOT_FindDevice()</slot> + </connection> + <slot access="public">SLOT_AddServer()</slot> + <slot access="public">SLOT_RemoveServer()</slot> + <slot access="public">SLOT_FindDevice()</slot> +</connections> </UI> diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp index 7ec8288..d19386e 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp @@ -1,21 +1,40 @@ #include "bluetoothRFCOMMedit.h" #include "bluetoothRFCOMM_NNI.h" -#include "bluetooth_NN.h" +#include "bluetoothRFCOMM_NN.h" -ABluetoothRFCOMM::ABluetoothRFCOMM( BluetoothRFCOMMNetNode * PNN ) : ANetNodeInstance( PNN ) { +ABluetoothRFCOMM::ABluetoothRFCOMM( BluetoothRFCOMMNetNode * PNN ) : + ANetNodeInstance( PNN ), Data() { + Data.Devices.setAutoDelete( TRUE ); GUI = 0; RT = 0; } -void ABluetoothRFCOMM::setSpecificAttribute( QString & , QString & ) { +void ABluetoothRFCOMM::setSpecificAttribute( QString & A, QString & V) { + + if( A == "bdaddress" ) { + Data.Devices.resize( Data.Devices.size() + 1 ); + Data.Devices.insert( Data.Devices.size() - 1, new RFCOMMChannel); + Data.Devices[ Data.Devices.size() - 1 ]->BDAddress = V; + } else if ( A == "channel" ) { + Data.Devices[ Data.Devices.size() - 1 ]->Channel = V.toLong(); + } else if ( A == "name" ) { + Data.Devices[ Data.Devices.size() - 1 ]->Name = V; + } } -void ABluetoothRFCOMM::saveSpecificAttribute( QTextStream & ) { +void ABluetoothRFCOMM::saveSpecificAttribute( QTextStream & TS ) { + for( unsigned int i = 0 ; + i < Data.Devices.count(); + i ++ ) { + TS << "bdaddress=" << Data.Devices[i]->BDAddress << endl; + TS << "name=" << quote( Data.Devices[i]->Name ) << endl; + TS << "channel=" << Data.Devices[i]->Channel << endl; + } } QWidget * ABluetoothRFCOMM::edit( QWidget * parent ) { GUI = new BluetoothRFCOMMEdit( parent ); GUI->showData( Data ); return GUI; } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h index 18f0d38..14cfeb0 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMdata.h @@ -1,18 +1,22 @@ #ifndef BLUETOOTHRFCOMM_DATA_H #define BLUETOOTHRFCOMM_DATA_H #include <qstring.h> +#include <qvector.h> -typedef struct BluetoothRFCOMMData { - QString Device; - QString LockFile; - long Speed; - short Parity; - short DataBits; - short StopBits; - bool HardwareControl; - bool SoftwareControl; +class RFCOMMChannel { -} BluetoothRFCOMMData_t; +public : + QString BDAddress; + QString Name; + int Channel; +}; + +class BluetoothRFCOMMData { + +public : + + QVector<RFCOMMChannel> Devices; +}; #endif diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp index d3ddab4..7cac13f 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.cpp @@ -1,18 +1,156 @@ +#include <qlistview.h> +#include <qdialog.h> +#include <qlabel.h> +#include <qlineedit.h> +#include <qtoolbutton.h> +#include <qcheckbox.h> +#include <qspinbox.h> +#include <OTPeer.h> +#include <OTGateway.h> +#include <Opietooth.h> +#include <resources.h> #include <GUIUtils.h> #include "bluetoothRFCOMMedit.h" +using namespace Opietooth2; + +class PeerLBI : public QListViewItem { + +public : + + PeerLBI( OTPeer * P, int Ch, QListView * LV ) : QListViewItem( LV ) { + Peer = P; + Channel = Ch; + + setText( 0, (P->name().isEmpty()) ? + P->address().toString() : + P->name() ); + QString S; + S.setNum( Ch ); + setText( 1, S ); + setText( 2, P->address().toString() ); + } + ~PeerLBI( ) { + } + + inline int channel( void ) const + { return Channel; } + inline OTPeer * peer( void ) const + { return Peer; } + + int Channel; + OTPeer * Peer; +}; + BluetoothRFCOMMEdit::BluetoothRFCOMMEdit( QWidget * Parent ) : BluetoothRFCOMMGUI( Parent ){ + Modified = 0; + OT = OTGateway::getOTGateway(); + + Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); + Remove_TB->setPixmap( NSResources->getPixmap( "remove" ) ); + FindDevice_TB->setPixmap( NSResources->getPixmap( "Devices/bluetooth" ) ); + Addresses_LV->setColumnAlignment( 1, Qt::AlignRight ); +} +BluetoothRFCOMMEdit::~BluetoothRFCOMMEdit( void ) { + OTGateway::releaseOTGateway(); } QString BluetoothRFCOMMEdit::acceptable( void ) { return QString(); } +bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) { + int ct = 0; + PeerLBI * I; + + if( Modified ) { + QListViewItem * it = Addresses_LV->firstChild(); + + Data.Devices.resize( 0 ); + while( it ) { + + ct ++; + Data.Devices.resize( ct ); + I = (PeerLBI * )it; + + Data.Devices.insert( ct-1, new RFCOMMChannel ); + + Data.Devices[ct-1]->BDAddress = I->peer()->address().toString(); + Data.Devices[ct-1]->Name = I->peer()->name(); + Data.Devices[ct-1]->Channel = I->channel(); + + it = it->nextSibling(); + } + } + + return Modified; +} + void BluetoothRFCOMMEdit::showData( BluetoothRFCOMMData & Data ) { + + OTPeer * P; + + for( unsigned int i = 0; + i < Data.Devices.count(); + i ++ ) { + P = new OTPeer( OT ); + P->setAddress( OTDeviceAddress( Data.Devices[i]->BDAddress ) ); + P->setName( Data.Devices[i]->Name ); + + new PeerLBI( P, Data.Devices[i]->Channel, Addresses_LV ); + } + Modified = 0; } -bool BluetoothRFCOMMEdit::commit( BluetoothRFCOMMData & Data ) { - return 0; +void BluetoothRFCOMMEdit::SLOT_AddServer( void ) { + QListViewItem * it = Addresses_LV->firstChild(); + + while( it ) { + // check address + if( it->text(2) == Address_LE->text() ) { + // already in table + return; + } + it = it->nextSibling(); + } + + // new server + Modified = 1; + OTPeer * P = new OTPeer( OT ); + P->setAddress( OTDeviceAddress( Address_LE->text() ) ); + P->setName( Name_LBL->text() ); + new PeerLBI( P, Channel_SB->value(), Addresses_LV ); + + Address_LE->setText(""); + Name_LBL->setText(""); + Channel_SB->setValue(1); +} + +void BluetoothRFCOMMEdit::SLOT_RemoveServer( void ) { + + QListViewItem * it = Addresses_LV->firstChild(); + + while( it ) { + // check address + if( it->isSelected() ) { + delete it; + Modified = 1; + return; + } + it = it->nextSibling(); + } +} + +void BluetoothRFCOMMEdit::SLOT_FindDevice( void ) { + OTPeer * Peer; + int Channel; + + // find device in Opietooth + if( OTScan::getDevice( Peer, Channel, OT ) == QDialog::Accepted ) { + Address_LE->setText( Peer->address().toString() ); + Name_LBL->setText( Peer->name() ); + Channel_SB->setValue( Channel ); + } } diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h index 14a6d64..9ad8f2a 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMedit.h @@ -1,13 +1,27 @@ #include "bluetoothRFCOMMdata.h" #include "bluetoothRFCOMMGUI.h" +#include <Opietooth.h> +using namespace Opietooth2; + class BluetoothRFCOMMEdit : public BluetoothRFCOMMGUI { public : BluetoothRFCOMMEdit( QWidget * parent ); + virtual ~BluetoothRFCOMMEdit( void ); QString acceptable( void ); void showData( BluetoothRFCOMMData & Data ); bool commit( BluetoothRFCOMMData & Data ); + + bool Modified; + OTGateway * OT; + +public slots : + + void SLOT_AddServer( void ); + void SLOT_RemoveServer( void ); + void SLOT_FindDevice( void ); + }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h index 65fd686..24e3dae 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h @@ -1,28 +1,33 @@ -#include <asline.h> +#include <netnode.h> #include "bluetoothRFCOMMdata.h" -class BluetoothRFCOMMRun : public AsLine { +#include <OTGateway.h> +using namespace Opietooth2; + +class BluetoothRFCOMMRun : public RuntimeInfo { public : BluetoothRFCOMMRun( ANetNodeInstance * NNI, - BluetoothRFCOMMData & Data ) : AsLine( NNI ) - { } + BluetoothRFCOMMData & D ) : RuntimeInfo( NNI ) + { DeviceNr = -1; Data = &D; OT = 0; } + virtual ~BluetoothRFCOMMRun( void ); - virtual AsLine * asLine( void ) - { return (AsLine *)this; } + virtual RuntimeInfo * line( void ) + { return this; } + virtual QString deviceFile( void ); - virtual QString deviceFile( void ) - { return QString( "/dev/rfcomm..." ); } + State_t detectState( void ); protected : - void detectState( NodeCollection * ) - { } + QString setMyState( NodeCollection * , Action_t, bool ); - bool setState( NodeCollection * , Action_t, bool ) - { return 0; } +private : - bool canSetState( State_t , Action_t ) - { return 0; } + int deviceNrOfConnection( void ); + RFCOMMChannel * getChannel( void ); + BluetoothRFCOMMData * Data; + Opietooth2::OTGateway * OT; + int DeviceNr; // cached from detection }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp index 443a627..9be6b16 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp @@ -7,16 +7,21 @@ // 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 } @@ -37,18 +42,18 @@ const QString BluetoothBNEPNetNode::nodeDescription(){ ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { return new ABluetoothBNEP( this ); } const char ** BluetoothBNEPNetNode::needs( void ) { return BluetoothBNEPNeeds; } -const char * BluetoothBNEPNetNode::provides( void ) { - return "device"; +const char ** BluetoothBNEPNetNode::provides( void ) { + return BluetoothBNEPProvides; } QString BluetoothBNEPNetNode::genNic( long nr ) { QString S; return S.sprintf( "bnep%ld", nr ); } diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h index 4d6a3c1..b93342e 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h @@ -17,17 +17,17 @@ public: 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 ** 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 diff --git a/noncore/settings/networksettings2/bluetooth/config.in b/noncore/settings/networksettings2/bluetooth/config.in index 6968ac8..398cff1 100644 --- a/noncore/settings/networksettings2/bluetooth/config.in +++ b/noncore/settings/networksettings2/bluetooth/config.in @@ -1,4 +1,4 @@ config NS2BT boolean "opie-networksettings2plugin-bluetooth (set up BLUETOOTH)" default "n" if NS2 - depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && NS2CORE && NS2OPIETOOTH diff --git a/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control b/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control index ea77bd7..c4d29f2 100644 --- a/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control +++ b/noncore/settings/networksettings2/bluetooth/opie-networksettings2plugin-bluetooth.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-bluetooth +Package: opie-networksettings2plugin-bluetooth Files: plugins/networksettings2/libbluetooth.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm -Depends: opie-networksettings2, libopiecore2, libopienet2 +Depends: opie-networksettings2, libopietooth2, libopiecore2, libopienet2 Description: Network settings bluetooth plugin. Version: $QPE_VERSION$EXTRAVERSION |