summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.cpp42
1 files changed, 35 insertions, 7 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,21 +1,33 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <resources.h> 2#include <resources.h>
3
4#include <OTPeer.h>
3#include <OTDevice.h> 5#include <OTDevice.h>
4#include <OTGateway.h> 6#include <OTGateway.h>
7#include <Opietooth.h>
8
9#include <qlistbox.h>
10#include <qframe.h>
11#include <qlabel.h>
12#include <qlayout.h>
13#include <qdialog.h>
14
5#include "bluetoothRFCOMMrun.h" 15#include "bluetoothRFCOMMrun.h"
6 16
7using Opietooth2::OTGateway; 17using Opietooth2::OTGateway;
8using Opietooth2::OTDevice; 18using Opietooth2::OTDevice;
9using Opietooth2::OTDeviceAddress; 19using Opietooth2::OTDeviceAddress;
20using Opietooth2::OTScan;
21using Opietooth2::OTPeer;
10 22
11BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) { 23BluetoothRFCOMMRun::~BluetoothRFCOMMRun( void ) {
12 if( OT ) { 24 if( OT ) {
13 OTGateway::releaseOTGateway(); 25 OTGateway::releaseOTGateway();
14 } 26 }
15} 27}
16 28
17State_t BluetoothRFCOMMRun::detectState( void ) { 29State_t BluetoothRFCOMMRun::detectState( void ) {
18 30
19 if( ! OT ) { 31 if( ! OT ) {
20 OT = OTGateway::getOTGateway(); 32 OT = OTGateway::getOTGateway();
21 } 33 }
@@ -46,61 +58,74 @@ QString BluetoothRFCOMMRun::setMyState( NetworkSetup *,
46 58
47 if( Ch ) { 59 if( Ch ) {
48 // connect to this peer 60 // connect to this peer
49 DeviceNr = OT->getFreeRFCommDevice(); 61 DeviceNr = OT->getFreeRFCommDevice();
50 QStringList S; 62 QStringList S;
51 63
52 S << "rfcomm" 64 S << "rfcomm"
53 << "bind" 65 << "bind"
54 << QString().setNum( DeviceNr ) 66 << QString().setNum( DeviceNr )
55 << Ch->BDAddress 67 << Ch->BDAddress
56 << QString().setNum( Ch->Channel ); 68 << QString().setNum( Ch->Channel );
57 69
70 // no longer needed
71 delete Ch;
72
58 if( Sys.runAsRoot( S ) ) { 73 if( Sys.runAsRoot( S ) ) {
59 return QString( "Error starting %1").arg(S.join(" ")); 74 return QString( "Error starting %1").arg(S.join(" "));
60 } 75 }
61 76
62 // here rfcomm should be running -> we will detect state later 77 // here rfcomm should be running -> we will detect state later
63 return QString(); 78 return QString();
64 } else { 79 } else {
65 Log(( "No channel selected -> cancel\n" )); 80 Log(( "No channel selected -> cancel\n" ));
66 return QString( "No channel selected. Operation cancelled" ); 81 return QString( "No channel selected. Operation cancelled" );
67 } 82 }
68 } 83 }
69 84
70 if( A == Deactivate ) { 85 if( A == Deactivate ) {
71 if( DeviceNr >= 0 ) { 86 if( DeviceNr >= 0 ) {
72 if( OT->releaseRFCommDevice( DeviceNr ) ) { 87 if( OT->releaseRFCommDevice( DeviceNr ) ) {
73 return QString( "Cannot release RFCOMM NetworkSetup" ); 88 return QString( "Cannot release RFCOMM NetworkSetup" );
74 } 89 }
75 DeviceNr = -1; 90 DeviceNr = -1;
76 } 91 }
77 } 92 }
78 return QString(); 93 return QString();
79} 94}
80 95
81#include <qlistbox.h>
82#include <qframe.h>
83#include <qlabel.h>
84#include <qlayout.h>
85#include <qdialog.h>
86
87RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) { 96RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) {
88 97
89 if( Data->Devices.count() == 1 ) { 98 if( Data->Devices.count() == 1 ) {
90 // only one device -> return channel 99 // only one device -> return channel
91 return Data->Devices[0]; 100 return Data->Devices[0];
92 } 101 }
93 102
94 RFCOMMChannel * Ch = 0; 103 RFCOMMChannel * Ch = 0;
104
105 if( Data->Devices.count() == 0 ) {
106 OTPeer * Peer;
107 int Channel;
108
109 if( OTScan::getDevice( Peer, Channel, OT ) == QDialog::Accepted ) {
110 Ch = new RFCOMMChannel;
111 Ch->BDAddress = Peer->address().toString();
112 Ch->Name = Peer->name();
113 Ch->Channel = Channel;
114 return Ch;
115 }
116
117 return 0;
118 }
119
95 QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE ); 120 QDialog * Dlg = new QDialog( qApp->mainWidget(), 0, TRUE );
96 QVBoxLayout * V = new QVBoxLayout( Dlg ); 121 QVBoxLayout * V = new QVBoxLayout( Dlg );
97 122
98 QLabel * L = new QLabel( 123 QLabel * L = new QLabel(
99 qApp->translate( "BluetoothRFCOMMRun", 124 qApp->translate( "BluetoothRFCOMMRun",
100 "Select device to connect to"), 125 "Select device to connect to"),
101 Dlg ); 126 Dlg );
102 QListBox * LB = new QListBox( Dlg ); 127 QListBox * LB = new QListBox( Dlg );
103 128
104 for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) { 129 for( unsigned int i = 0; i < Data->Devices.count(); i ++ ) {
105 LB->insertItem( QString( "%1 (%2 Chnl %3)" ). 130 LB->insertItem( QString( "%1 (%2 Chnl %3)" ).
106 arg( Data->Devices[i]->Name ). 131 arg( Data->Devices[i]->Name ).
@@ -111,25 +136,28 @@ RFCOMMChannel * BluetoothRFCOMMRun::getChannel( void ) {
111 V->addWidget( L ); 136 V->addWidget( L );
112 V->addWidget( LB ); 137 V->addWidget( LB );
113 138
114 Dlg->resize( 100, 100 ); 139 Dlg->resize( 100, 100 );
115 Dlg->move( 20, 140 Dlg->move( 20,
116 (qApp->desktop()->height()-100)/2 ); 141 (qApp->desktop()->height()-100)/2 );
117 142
118 if( Dlg->exec() == QDialog::Accepted ) { 143 if( Dlg->exec() == QDialog::Accepted ) {
119 unsigned int i = 0; 144 unsigned int i = 0;
120 for( i = 0; i < Data->Devices.count(); i ++ ) { 145 for( i = 0; i < Data->Devices.count(); i ++ ) {
121 if( LB->isSelected(i) ) { 146 if( LB->isSelected(i) ) {
122 odebug << "Selected " << Data->Devices[i]->Name << oendl; 147 odebug << "Selected " << Data->Devices[i]->Name << oendl;
123 Ch = Data->Devices[i]; 148 Ch = new RFCOMMChannel;
149 Ch->BDAddress = Data->Devices[i]->BDAddress;
150 Ch->Name = Data->Devices[i]->Name;
151 Ch->Channel = Data->Devices[i]->Channel;
124 break; 152 break;
125 } 153 }
126 } 154 }
127 } 155 }
128 156
129 delete Dlg; 157 delete Dlg;
130 return Ch; 158 return Ch;
131} 159}
132 160
133QString BluetoothRFCOMMRun::deviceFile( void ) { 161QString BluetoothRFCOMMRun::deviceFile( void ) {
134 if( deviceNrOfNetworkSetup() >= 0 ) { 162 if( deviceNrOfNetworkSetup() >= 0 ) {
135 OTDevice * OTD = OT->getOTDevice(); 163 OTDevice * OTD = OT->getOTDevice();