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 @@ | |||
1 | #include "bluetoothBNEP_NN.h" | ||
2 | #include "bluetoothBNEP_NNI.h" | ||
3 | #include "bluetoothRFCOMM_NNI.h" | ||
4 | |||
5 | // | ||
6 | // | ||
7 | // BLUETOOTH PAN/NAP node | ||
8 | // | ||
9 | // | ||
10 | |||
11 | static const char * BluetoothBNEPNeeds[] = | ||
12 | { 0 | ||
13 | }; | ||
14 | |||
15 | static const char * BluetoothBNEPProvides[] = | ||
16 | { "device", | ||
17 | 0 | ||
18 | }; | ||
19 | |||
20 | /** | ||
21 | * Constructor, find all of the possible interfaces | ||
22 | */ | ||
23 | BluetoothBNEPNetNode::BluetoothBNEPNetNode() : | ||
24 | ANetNode(tr("Bluetooth PAN/NAP")) { | ||
25 | InstanceCount = 7; // default | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * Delete any interfaces that we own. | ||
30 | */ | ||
31 | BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ | ||
32 | } | ||
33 | |||
34 | const QString BluetoothBNEPNetNode::nodeDescription(){ | ||
35 | return tr("\ | ||
36 | <p>Sets up a bluetooth link using the bluetooth Network profile.</p>\ | ||
37 | <p>Use this to connect two computing devices.</p>\ | ||
38 | " | ||
39 | ); | ||
40 | } | ||
41 | |||
42 | ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { | ||
43 | return new ABluetoothBNEP( this ); | ||
44 | } | ||
45 | |||
46 | const char ** BluetoothBNEPNetNode::needs( void ) { | ||
47 | return BluetoothBNEPNeeds; | ||
48 | } | ||
49 | |||
50 | const char ** BluetoothBNEPNetNode::provides( void ) { | ||
51 | return BluetoothBNEPProvides; | ||
52 | } | ||
53 | |||
54 | QString BluetoothBNEPNetNode::genNic( long nr ) { | ||
55 | QString S; | ||
56 | return S.sprintf( "bnep%ld", nr ); | ||
57 | } | ||
58 | |||
59 | |||
60 | void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { | ||
61 | if( A == "interfacecount" ) { | ||
62 | InstanceCount = V.toLong(); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) { | ||
67 | TS << "interfacecount=" | ||
68 | << InstanceCount | ||
69 | << endl; | ||
70 | } | ||
71 | |||
72 | extern "C" { | ||
73 | // create plugin registers both BT functions | ||
74 | void create_plugin( QList<ANetNode> & PNN ) { | ||
75 | PNN.append( new BluetoothBNEPNetNode() ); | ||
76 | PNN.append( new BluetoothRFCOMMNetNode() ); | ||
77 | } | ||
78 | } | ||
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 @@ | |||
1 | #ifndef BLUETOOTHBNEP_NETNODE_H | ||
2 | #define BLUETOOTHBNEP_NETNODE_H | ||
3 | |||
4 | #include "netnode.h" | ||
5 | #include "bluetoothRFCOMM_NN.h" | ||
6 | |||
7 | class ABluetoothBNEP; | ||
8 | |||
9 | class BluetoothBNEPNetNode : public ANetNode { | ||
10 | |||
11 | Q_OBJECT | ||
12 | |||
13 | public: | ||
14 | |||
15 | BluetoothBNEPNetNode(); | ||
16 | virtual ~BluetoothBNEPNetNode(); | ||
17 | |||
18 | virtual QString genNic( long ); | ||
19 | virtual long instanceCount( void ) | ||
20 | { return InstanceCount; } | ||
21 | virtual const QString pixmapName() | ||
22 | { return "Devices/bluetooth"; } | ||
23 | |||
24 | virtual const QString nodeDescription() ; | ||
25 | virtual ANetNodeInstance * createInstance( void ); | ||
26 | virtual const char ** provides( void ); | ||
27 | virtual const char ** needs( void ); | ||
28 | |||
29 | private: | ||
30 | |||
31 | virtual void setSpecificAttribute( QString & Attr, QString & Value ); | ||
32 | virtual void saveSpecificAttribute( QTextStream & TS ); | ||
33 | |||
34 | // number of interfaces for this device | ||
35 | long InstanceCount; | ||
36 | |||
37 | }; | ||
38 | |||
39 | extern "C" | ||
40 | { | ||
41 | void create_plugin( QList<ANetNode> & PNN ); | ||
42 | }; | ||
43 | |||
44 | #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 @@ | |||
1 | #include "bluetoothRFCOMM_NN.h" | ||
2 | #include "bluetoothRFCOMM_NNI.h" | ||
3 | |||
4 | static const char * BluetoothRFCOMMNeeds[] = | ||
5 | { 0 | ||
6 | }; | ||
7 | |||
8 | static const char * BluetoothRFCOMMProvides[] = | ||
9 | { "line", | ||
10 | "GPRS" | ||
11 | }; | ||
12 | |||
13 | BluetoothRFCOMMNetNode::BluetoothRFCOMMNetNode() : | ||
14 | ANetNode( tr("Bluetooth serial link") ) { | ||
15 | } | ||
16 | |||
17 | BluetoothRFCOMMNetNode::~BluetoothRFCOMMNetNode(){ | ||
18 | } | ||
19 | |||
20 | const QString BluetoothRFCOMMNetNode::nodeDescription(){ | ||
21 | return tr("\ | ||
22 | <p>Sets up a bluetooth link using the bluetooth serial profile.</p>\ | ||
23 | <p>Use this to connect to a GSM.</p>\ | ||
24 | " | ||
25 | ); | ||
26 | } | ||
27 | |||
28 | ANetNodeInstance * BluetoothRFCOMMNetNode::createInstance( void ) { | ||
29 | return new ABluetoothRFCOMM( this ); | ||
30 | } | ||
31 | |||
32 | const char ** BluetoothRFCOMMNetNode::needs( void ) { | ||
33 | return BluetoothRFCOMMNeeds; | ||
34 | } | ||
35 | |||
36 | const char ** BluetoothRFCOMMNetNode::provides( void ) { | ||
37 | return BluetoothRFCOMMProvides; | ||
38 | } | ||
39 | |||
40 | void BluetoothRFCOMMNetNode::setSpecificAttribute( QString &, QString & ) { | ||
41 | } | ||
42 | |||
43 | void BluetoothRFCOMMNetNode::saveSpecificAttribute( QTextStream & ) { | ||
44 | } | ||
45 | |||
46 | // 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 @@ | |||
1 | #ifndef BLUETOOTHRFCOMM_NETNODE_H | ||
2 | #define BLUETOOTHRFCOMM_NETNODE_H | ||
3 | |||
4 | #include "netnode.h" | ||
5 | |||
6 | class BluetoothRFCOMMNetNode : public ANetNode { | ||
7 | |||
8 | Q_OBJECT | ||
9 | |||
10 | public: | ||
11 | |||
12 | BluetoothRFCOMMNetNode(); | ||
13 | virtual ~BluetoothRFCOMMNetNode(); | ||
14 | |||
15 | virtual const QString pixmapName() | ||
16 | { return "Devices/bluetooth"; } | ||
17 | |||
18 | virtual const QString nodeDescription() ; | ||
19 | virtual ANetNodeInstance * createInstance( void ); | ||
20 | virtual const char ** needs( void ); | ||
21 | virtual const char ** provides( void ); | ||
22 | |||
23 | private: | ||
24 | |||
25 | virtual void setSpecificAttribute( QString & Attr, QString & Value ); | ||
26 | virtual void saveSpecificAttribute( QTextStream & TS ); | ||
27 | }; | ||
28 | |||
29 | #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 @@ | |||
1 | #include <qapplication.h> | ||
2 | #include <resources.h> | ||
3 | #include <OTDevice.h> | ||
4 | #include <OTGateway.h> | ||
5 | #include "bluetoothRFCOMMrun.h" | ||
6 | |||
7 | using namespace Opietooth2; | ||
8 | |||
9 | BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) { | ||
10 | if( OT ) { | ||
11 | OTGateway::releaseOTGateway(); | ||
12 | } | ||
13 | } | ||
14 | |||
15 | State_t BluetoothRFCOMMRun::detectState( void ) { | ||
16 | |||
17 | if( ! OT ) { | ||
18 | OT = OTGateway::getOTGateway(); | ||
19 | } | ||
20 | |||
21 | if( deviceNrOfConnection() >= 0 ) { | ||
22 | return Available; | ||
23 | } | ||
24 | |||
25 | owarn << "Bluetooth " | ||
26 | << OT->isEnabled() | ||
27 | << oendl; | ||
28 | |||
29 | return ( OT->isEnabled() ) ? Off : Unavailable; | ||
30 | } | ||
31 | |||
32 | QString BluetoothRFCOMMRun::setMyState( NodeCollection *, | ||
33 | Action_t A, | ||
34 | bool ) { | ||
35 | |||
36 | if( OT ) { | ||
37 | OTGateway::getOTGateway(); | ||
38 | } | ||
39 | |||
40 | if( A == Activate ) { | ||
41 | // from OFF to Available | ||
42 | RFCOMMChannel * Ch = getChannel( ); | ||
43 | System & Sys = NSResources->system(); | ||
44 | |||
45 | if( Ch ) { | ||
46 | // connect to this peer | ||
47 | DeviceNr = OT->getFreeRFCommDevice(); | ||
48 | QStringList S; | ||
49 | |||
50 | S << "rfcomm" | ||
51 | << "bind" | ||
52 | << QString().setNum( DeviceNr ) | ||
53 | << Ch->BDAddress | ||
54 | << QString().setNum( Ch->Channel ); | ||
55 | |||
56 | if( Sys.runAsRoot( S ) ) { | ||
57 | return QString( "Error starting %1").arg(S.join(" ")); | ||
58 | } | ||
59 | |||
60 | // here rfcomm should be running -> we will detect state later | ||
61 | return QString(); | ||
62 | } else { | ||
63 | Log(( "No channel selected -> cancel\n" )); | ||
64 | return QString( "No channel selected. Operation cancelled" ); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | if( A == Deactivate ) { | ||
69 | if( DeviceNr >= 0 ) { | ||
70 | if( OT->releaseRFCommDevice( DeviceNr ) ) { | ||
71 | return QString( "Cannot release RFCOMM connection" ); | ||
72 | } | ||
73 | DeviceNr = -1; | ||
74 | } | ||
75 | } | ||
76 | return QString(); | ||
77 | } | ||
78 | |||
79 | #include <qlistbox.h> | ||
80 | #include <qframe.h> | ||
81 | #include <qlabel.h> | ||
82 | #include <qlayout.h> | ||
83 | #include <qdialog.h> | ||
84 | |||
85 | RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) { | ||
86 | |||
87 | if( Data->Devices.count() == 1 ) { | ||
88 | // only one device -> return channel | ||
89 | return Data->Devices[0]; | ||
90 | } | ||
91 | |||
92 | RFCOMMChannel * Ch = 0; | ||
93 | QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE ); | ||
94 | QVBoxLayout * V = new QVBoxLayout( Dlg ); | ||
95 | |||
96 | QLabel * L = new QLabel( | ||
97 | qApp->translate( "BluetoothRFCOMMRun", | ||
98 | "Select device to connect to"), | ||
99 | Dlg ); | ||
100 | QListBox * LB = new QListBox( Dlg ); | ||
101 | |||
102 | for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { | ||
103 | LB->insertItem( QString( "%1 (%2 Chnl %3)" ). | ||
104 | arg( Data->Devices[i]->Name ). | ||
105 | arg( Data->Devices[i]->BDAddress ). | ||
106 | arg( Data->Devices[i]->Channel ) ); | ||
107 | } | ||
108 | |||
109 | V->addWidget( L ); | ||
110 | V->addWidget( LB ); | ||
111 | |||
112 | Dlg->resize( 100, 100 ); | ||
113 | Dlg->move( 20, | ||
114 | (qApp->desktop()->height()-100)/2 ); | ||
115 | |||
116 | if( Dlg->exec() == QDialog::Accepted ) { | ||
117 | unsigned int i = 0; | ||
118 | for( i = 0; i < Data->Devices.count(); i ++ ) { | ||
119 | if( LB->isSelected(i) ) { | ||
120 | owarn << "Selected " << Data->Devices[i]->Name << oendl; | ||
121 | Ch = Data->Devices[i]; | ||
122 | break; | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | |||
127 | delete Dlg; | ||
128 | return Ch; | ||
129 | } | ||
130 | |||
131 | QString BluetoothRFCOMMRun::deviceFile( void ) { | ||
132 | if( deviceNrOfConnection() >= 0 ) { | ||
133 | OTDevice * OTD = OT->getOTDevice(); | ||
134 | // there is a connection | ||
135 | return OTD->getRFCommDevicePattern().arg(DeviceNr); | ||
136 | } | ||
137 | return QString(); | ||
138 | } | ||
139 | |||
140 | int BluetoothRFCOMMRun::deviceNrOfConnection( void ) { | ||
141 | |||
142 | if( ! OT ) { | ||
143 | OT = OTGateway::getOTGateway(); | ||
144 | } | ||
145 | |||
146 | DeviceNr = -1; | ||
147 | for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { | ||
148 | owarn << "Check for rfcomm on " | ||
149 | << Data->Devices[i]->BDAddress | ||
150 | << " " | ||
151 | << Data->Devices[i]->Channel | ||
152 | << oendl; | ||
153 | if( ( DeviceNr = OT->connectedToRFCommChannel( | ||
154 | OTDeviceAddress( Data->Devices[i]->BDAddress ), | ||
155 | Data->Devices[i]->Channel ) ) >= 0 ) { | ||
156 | owarn << "Up " | ||
157 | << oendl; | ||
158 | break; | ||
159 | } | ||
160 | } | ||
161 | return DeviceNr; | ||
162 | } | ||