summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/manager.cc58
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp44
-rw-r--r--noncore/net/opietooth/manager/bluebase.h9
3 files changed, 54 insertions, 57 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc
index 53122c1..83100f1 100644
--- a/noncore/net/opietooth/lib/manager.cc
+++ b/noncore/net/opietooth/lib/manager.cc
@@ -1,336 +1,336 @@
1 1
2#include "parser.h" 2#include "parser.h"
3#include "manager.h" 3#include "manager.h"
4 4
5#include <opie2/oprocess.h> 5#include <opie2/oprocess.h>
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7using namespace Opie::Core; 7using namespace Opie::Core;
8 8
9 9
10using namespace OpieTooth; 10using namespace OpieTooth;
11 11
12using Opie::Core::OProcess; 12using Opie::Core::OProcess;
13Manager::Manager( const QString& dev ) 13Manager::Manager( const QString& dev )
14 : QObject() 14 : QObject()
15{ 15{
16 owarn << "created" << oendl; 16 odebug << "Manager: created" << oendl;
17 m_device = dev; 17 m_device = dev;
18 m_hcitool = 0; 18 m_hcitool = 0;
19 m_sdp = 0; 19 m_sdp = 0;
20} 20}
21Manager::Manager( Device* /*dev*/ ) 21Manager::Manager( Device* /*dev*/ )
22 : QObject() 22 : QObject()
23{ 23{
24 m_hcitool = 0; 24 m_hcitool = 0;
25 m_sdp = 0; 25 m_sdp = 0;
26} 26}
27Manager::Manager() 27Manager::Manager()
28 : QObject() 28 : QObject()
29{ 29{
30 m_hcitool = 0; 30 m_hcitool = 0;
31 m_sdp = 0; 31 m_sdp = 0;
32} 32}
33Manager::~Manager(){ 33Manager::~Manager(){
34 delete m_hcitool; 34 delete m_hcitool;
35 delete m_sdp; 35 delete m_sdp;
36} 36}
37void Manager::setDevice( const QString& dev ){ 37void Manager::setDevice( const QString& dev ){
38 m_device = dev; 38 m_device = dev;
39} 39}
40void Manager::setDevice( Device* /*dev*/ ){ 40void Manager::setDevice( Device* /*dev*/ ){
41 41
42} 42}
43void Manager::isAvailable( const QString& device ){ 43void Manager::isAvailable( const QString& device ){
44 OProcess* l2ping = new OProcess(); 44 OProcess* l2ping = new OProcess();
45 l2ping->setName( device.latin1() ); 45 l2ping->setName( device.latin1() );
46 *l2ping << "l2ping" << "-c1" << device; 46 *l2ping << "l2ping" << "-c1" << device;
47 connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ), 47 connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ),
48 this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) ); 48 this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) );
49 if (!l2ping->start() ) { 49 if (!l2ping->start() ) {
50 emit available( device, false ); 50 emit available( device, false );
51 delete l2ping; 51 delete l2ping;
52 } 52 }
53 53
54} 54}
55 55
56void Manager::isAvailable( Device* /*dev*/ ){ 56void Manager::isAvailable( Device* /*dev*/ ){
57 57
58 58
59} 59}
60void Manager::searchDevices( const QString& device ){ 60void Manager::searchDevices( const QString& device ){
61 owarn << "search devices" << oendl; 61 odebug << "Manager: search devices" << oendl;
62 OProcess* hcitool = new OProcess(); 62 OProcess* hcitool = new OProcess();
63 hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); 63 hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() );
64 *hcitool << "hcitool" << "scan"; 64 *hcitool << "hcitool" << "scan";
65 connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , 65 connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) ,
66 this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) ); 66 this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) );
67 connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 67 connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
68 this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) ); 68 this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) );
69 if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 69 if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
70 owarn << "could not start" << oendl; 70 odebug << "Manager: could not start" << oendl;
71 RemoteDevice::ValueList list; 71 RemoteDevice::ValueList list;
72 emit foundDevices( device, list ); 72 emit foundDevices( device, list );
73 delete hcitool; 73 delete hcitool;
74 } 74 }
75} 75}
76 76
77void Manager::searchDevices(Device* /*d*/ ){ 77void Manager::searchDevices(Device* /*d*/ ){
78 78
79 79
80} 80}
81void Manager::addService(const QString& name ){ 81void Manager::addService(const QString& name ){
82 OProcess proc; 82 OProcess proc;
83 proc << "sdptool" << "add" << name; 83 proc << "sdptool" << "add" << name;
84 bool bo = true; 84 bool bo = true;
85 if (!proc.start(OProcess::DontCare ) ) 85 if (!proc.start(OProcess::DontCare ) )
86 bo = false; 86 bo = false;
87 emit addedService( name, bo ); 87 emit addedService( name, bo );
88} 88}
89void Manager::addServices(const QStringList& list){ 89void Manager::addServices(const QStringList& list){
90 QStringList::ConstIterator it; 90 QStringList::ConstIterator it;
91 for (it = list.begin(); it != list.end(); ++it ) 91 for (it = list.begin(); it != list.end(); ++it )
92 addService( (*it) ); 92 addService( (*it) );
93} 93}
94void Manager::removeService( const QString& name ){ 94void Manager::removeService( const QString& name ){
95 OProcess prc; 95 OProcess prc;
96 prc << "sdptool" << "del" << name; 96 prc << "sdptool" << "del" << name;
97 bool bo = true; 97 bool bo = true;
98 if (!prc.start(OProcess::DontCare ) ) 98 if (!prc.start(OProcess::DontCare ) )
99 bo = false; 99 bo = false;
100 emit removedService( name, bo ); 100 emit removedService( name, bo );
101} 101}
102void Manager::removeServices( const QStringList& list){ 102void Manager::removeServices( const QStringList& list){
103 QStringList::ConstIterator it; 103 QStringList::ConstIterator it;
104 for (it = list.begin(); it != list.end(); ++it ) 104 for (it = list.begin(); it != list.end(); ++it )
105 removeService( (*it) ); 105 removeService( (*it) );
106} 106}
107void Manager::searchServices( const QString& remDevice ){ 107void Manager::searchServices( const QString& remDevice ){
108 OProcess *m_sdp =new OProcess(); 108 OProcess *m_sdp =new OProcess();
109 *m_sdp << "sdptool" << "browse" << remDevice; 109 *m_sdp << "sdptool" << "browse" << remDevice;
110 m_sdp->setName( remDevice.latin1() ); 110 m_sdp->setName( remDevice.latin1() );
111 owarn << "search Services for " << remDevice.latin1() << oendl; 111 odebug << "Manager: search Services for " << remDevice.latin1() << oendl;
112 connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), 112 connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ),
113 this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) ); 113 this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) );
114 connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 114 connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
115 this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) ); 115 this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) );
116 if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 116 if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
117 owarn << "could not start sdptool" << oendl; 117 odebug << "Manager: could not start sdptool" << oendl;
118 delete m_sdp; 118 delete m_sdp;
119 Services::ValueList list; 119 Services::ValueList list;
120 emit foundServices( remDevice, list ); 120 emit foundServices( remDevice, list );
121 } 121 }
122} 122}
123void Manager::searchServices( const RemoteDevice& dev){ 123void Manager::searchServices( const RemoteDevice& dev){
124 searchServices( dev.mac() ); 124 searchServices( dev.mac() );
125} 125}
126QString Manager::toDevice( const QString& /*mac*/ ){ 126QString Manager::toDevice( const QString& /*mac*/ ){
127 return QString::null; 127 return QString::null;
128} 128}
129QString Manager::toMac( const QString &/*device*/ ){ 129QString Manager::toMac( const QString &/*device*/ ){
130 return QString::null; 130 return QString::null;
131} 131}
132void Manager::slotProcessExited(OProcess* proc ) { 132void Manager::slotProcessExited(OProcess* proc ) {
133 bool conn= false; 133 bool conn= false;
134 if (proc->normalExit() && proc->exitStatus() == 0 ) 134 if (proc->normalExit() && proc->exitStatus() == 0 )
135 conn = true; 135 conn = true;
136 136
137 QString name = QString::fromLatin1(proc->name() ); 137 QString name = QString::fromLatin1(proc->name() );
138 emit available( name, conn ); 138 emit available( name, conn );
139 delete proc; 139 delete proc;
140} 140}
141void Manager::slotSDPOut(OProcess* proc, char* ch, int len) 141void Manager::slotSDPOut(OProcess* proc, char* ch, int len)
142{ 142{
143 QCString str(ch, len+1 ); 143 QCString str(ch, len+1 );
144 owarn << "SDP:" << str.data() << oendl; 144 odebug << "Manager: SDP:" << str.data() << oendl;
145 QMap<QString, QString>::Iterator it; 145 QMap<QString, QString>::Iterator it;
146 it = m_out.find(proc->name() ); 146 it = m_out.find(proc->name() );
147 QString string; 147 QString string;
148 if ( it != m_out.end() ) { 148 if ( it != m_out.end() ) {
149 string = it.data(); 149 string = it.data();
150 } 150 }
151 string.append( str ); 151 string.append( str );
152 m_out.replace( proc->name(), string ); 152 m_out.replace( proc->name(), string );
153 153
154} 154}
155void Manager::slotSDPExited( OProcess* proc) 155void Manager::slotSDPExited( OProcess* proc)
156{ 156{
157 owarn << "proc name " << proc->name() << oendl; 157 odebug << "Manager: proc name " << proc->name() << oendl;
158 Services::ValueList list; 158 Services::ValueList list;
159 if (proc->normalExit() ) { 159 if (proc->normalExit() ) {
160 QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); 160 QMap<QString, QString>::Iterator it = m_out.find( proc->name() );
161 if ( it != m_out.end() ) { 161 if ( it != m_out.end() ) {
162 owarn << "found process" << oendl; 162 odebug << "Manager: found process" << oendl;
163 list = parseSDPOutput( it.data() ); 163 list = parseSDPOutput( it.data() );
164 m_out.remove( it ); 164 m_out.remove( it );
165 } 165 }
166 } 166 }
167 emit foundServices( proc->name(), list ); 167 emit foundServices( proc->name(), list );
168 delete proc; 168 delete proc;
169} 169}
170Services::ValueList Manager::parseSDPOutput( const QString& out ) { 170Services::ValueList Manager::parseSDPOutput( const QString& out ) {
171 Services::ValueList list; 171 Services::ValueList list;
172 owarn << "parsing output" << oendl; 172 odebug << "Manager: parsing output" << oendl;
173 Parser parser( out ); 173 Parser parser( out );
174 list = parser.services(); 174 list = parser.services();
175 return list; 175 return list;
176} 176}
177 177
178void Manager::slotHCIExited(OProcess* proc ) { 178void Manager::slotHCIExited(OProcess* proc ) {
179 owarn << "process exited" << oendl; 179 odebug << "Manager: process exited" << oendl;
180 RemoteDevice::ValueList list; 180 RemoteDevice::ValueList list;
181 if (proc->normalExit() ) { 181 if (proc->normalExit() ) {
182 owarn << "normalExit " << proc->name() << oendl; 182 odebug << "Manager: normalExit " << proc->name() << oendl;
183 QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); 183 QMap<QString, QString>::Iterator it = m_devices.find(proc->name() );
184 if (it != m_devices.end() ) { 184 if (it != m_devices.end() ) {
185 owarn << "!= end ;)" << oendl; 185 odebug << "Manager: != end ;)" << oendl;
186 list = parseHCIOutput( it.data() ); 186 list = parseHCIOutput( it.data() );
187 m_devices.remove( it ); 187 m_devices.remove( it );
188 } 188 }
189 } 189 }
190 emit foundDevices( proc->name(), list ); 190 emit foundDevices( proc->name(), list );
191 delete proc; 191 delete proc;
192} 192}
193void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { 193void Manager::slotHCIOut(OProcess* proc, char* ch, int len) {
194 QCString str( ch, len+1 ); 194 QCString str( ch, len+1 );
195 owarn << "hci: " << str.data() << oendl; 195 odebug << "Manager: hci: " << str.data() << oendl;
196 QMap<QString, QString>::Iterator it; 196 QMap<QString, QString>::Iterator it;
197 it = m_devices.find( proc->name() ); 197 it = m_devices.find( proc->name() );
198 owarn << "proc->name " << proc->name() << oendl; 198 odebug << "Manager: proc->name " << proc->name() << oendl;
199 QString string; 199 QString string;
200 if (it != m_devices.end() ) { 200 if (it != m_devices.end() ) {
201 owarn << "slotHCIOut " << oendl; 201 odebug << "Manager: slotHCIOut " << oendl;
202 string = it.data(); 202 string = it.data();
203 } 203 }
204 string.append( str ); 204 string.append( str );
205 205
206 m_devices.replace( proc->name(), string ); 206 m_devices.replace( proc->name(), string );
207} 207}
208RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { 208RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) {
209 owarn << "parseHCI " << output.latin1() << oendl; 209 odebug << "Manager: parseHCI " << output.latin1() << oendl;
210 RemoteDevice::ValueList list; 210 RemoteDevice::ValueList list;
211 QStringList strList = QStringList::split('\n', output ); 211 QStringList strList = QStringList::split('\n', output );
212 QStringList::Iterator it; 212 QStringList::Iterator it;
213 QString str; 213 QString str;
214 for ( it = strList.begin(); it != strList.end(); ++it ) { 214 for ( it = strList.begin(); it != strList.end(); ++it ) {
215 str = (*it).stripWhiteSpace(); 215 str = (*it).stripWhiteSpace();
216 owarn << "OpieTooth " << str.latin1() << oendl; 216 odebug << "Manager: OpieTooth " << str.latin1() << oendl;
217 int pos = str.findRev(':' ); 217 int pos = str.findRev(':' );
218 if ( pos > 0 ) { 218 if ( pos > 0 ) {
219 QString mac = str.left(17 ); 219 QString mac = str.left(17 );
220 str.remove( 0, 17 ); 220 str.remove( 0, 17 );
221 owarn << "mac " << mac.latin1() << oendl; 221 odebug << "Manager: mac " << mac.latin1() << oendl;
222 owarn << "rest: " << str.latin1() << oendl; 222 odebug << "Manager: rest: " << str.latin1() << oendl;
223 RemoteDevice rem( mac , str.stripWhiteSpace() ); 223 RemoteDevice rem( mac , str.stripWhiteSpace() );
224 list.append( rem ); 224 list.append( rem );
225 } 225 }
226 } 226 }
227 return list; 227 return list;
228} 228}
229 229
230////// hcitool cc and hcitool con 230////// hcitool cc and hcitool con
231 231
232/** 232/**
233 * Create it on the stack as don't care 233 * Create it on the stack as don't care
234 * so we don't need to care for it 234 * so we don't need to care for it
235 * cause hcitool gets reparented 235 * cause hcitool gets reparented
236 */ 236 */
237void Manager::connectTo( const QString& mac) { 237void Manager::connectTo( const QString& mac) {
238 OProcess proc; 238 OProcess proc;
239 proc << "hcitool"; 239 proc << "hcitool";
240 proc << "cc"; 240 proc << "cc";
241 proc << mac; 241 proc << mac;
242 proc.start(OProcess::DontCare); // the lib does not care at this point 242 proc.start(OProcess::DontCare); // the lib does not care at this point
243} 243}
244 244
245 245
246void Manager::searchConnections() { 246void Manager::searchConnections() {
247 owarn << "searching connections?" << oendl; 247 odebug << "Manager: searchConnections()" << oendl;
248 OProcess* proc = new OProcess(); 248 OProcess* proc = new OProcess();
249 m_hcitoolCon = QString::null; 249 m_hcitoolCon = QString::null;
250 250
251 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ), 251 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ),
252 this, SLOT(slotConnectionExited( Opie::Core::OProcess*) ) ); 252 this, SLOT(slotConnectionExited( Opie::Core::OProcess*) ) );
253 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), 253 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ),
254 this, SLOT(slotConnectionOutput(Opie::Core::OProcess*, char*, int) ) ); 254 this, SLOT(slotConnectionOutput(Opie::Core::OProcess*, char*, int) ) );
255 *proc << "hcitool"; 255 *proc << "hcitool";
256 *proc << "con"; 256 *proc << "con";
257 257
258 if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 258 if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
259 ConnectionState::ValueList list; 259 ConnectionState::ValueList list;
260 emit connections( list ); 260 emit connections( list );
261 delete proc; 261 delete proc;
262 } 262 }
263} 263}
264void Manager::slotConnectionExited( OProcess* proc ) { 264void Manager::slotConnectionExited( OProcess* proc ) {
265 ConnectionState::ValueList list; 265 ConnectionState::ValueList list;
266 list = parseConnections( m_hcitoolCon ); 266 list = parseConnections( m_hcitoolCon );
267 emit connections(list ); 267 emit connections(list );
268 delete proc; 268 delete proc;
269} 269}
270void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) { 270void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) {
271 QCString str(cha, len ); 271 QCString str(cha, len );
272 m_hcitoolCon.append( str ); 272 m_hcitoolCon.append( str );
273 //delete proc; 273 //delete proc;
274} 274}
275ConnectionState::ValueList Manager::parseConnections( const QString& out ) { 275ConnectionState::ValueList Manager::parseConnections( const QString& out ) {
276 ConnectionState::ValueList list2; 276 ConnectionState::ValueList list2;
277 QStringList list = QStringList::split('\n', out ); 277 QStringList list = QStringList::split('\n', out );
278 QStringList::Iterator it; 278 QStringList::Iterator it;
279 // remove the first line ( "Connections:") 279 // remove the first line ( "Connections:")
280 it = list.begin(); 280 it = list.begin();
281 it = list.remove( it ); 281 it = list.remove( it );
282 for (; it != list.end(); ++it ) { 282 for (; it != list.end(); ++it ) {
283 QString row = (*it).stripWhiteSpace(); 283 QString row = (*it).stripWhiteSpace();
284 QStringList value = QStringList::split(' ', row ); 284 QStringList value = QStringList::split(' ', row );
285 owarn << "0: %s" << value[0].latin1() << oendl; 285 odebug << "Manager: 0: " << value[0].latin1() << oendl;
286 owarn << "1: %s" << value[1].latin1() << oendl; 286 odebug << "Manager: 1: " << value[1].latin1() << oendl;
287 owarn << "2: %s" << value[2].latin1() << oendl; 287 odebug << "Manager: 2: " << value[2].latin1() << oendl;
288 owarn << "3: %s" << value[3].latin1() << oendl; 288 odebug << "Manager: 3: " << value[3].latin1() << oendl;
289 owarn << "4: %s" << value[4].latin1() << oendl; 289 odebug << "Manager: 4: " << value[4].latin1() << oendl;
290 owarn << "5: %s" << value[5].latin1() << oendl; 290 odebug << "Manager: 5: " << value[5].latin1() << oendl;
291 owarn << "6: %s" << value[6].latin1() << oendl; 291 odebug << "Manager: 6: " << value[6].latin1() << oendl;
292 owarn << "7: %s" << value[7].latin1() << oendl; 292 odebug << "Manager: 7: " << value[7].latin1() << oendl;
293 owarn << "8: %s" << value[8].latin1() << oendl; 293 odebug << "Manager: 8: " << value[8].latin1() << oendl;
294 ConnectionState con; 294 ConnectionState con;
295 con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming ); 295 con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming );
296 con.setConnectionMode( value[1] ); 296 con.setConnectionMode( value[1] );
297 con.setMac( value[2] ); 297 con.setMac( value[2] );
298 con.setHandle( value[4].toInt() ); 298 con.setHandle( value[4].toInt() );
299 con.setState( value[6].toInt() ); 299 con.setState( value[6].toInt() );
300 con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client ); 300 con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client );
301 list2.append( con ); 301 list2.append( con );
302 } 302 }
303 return list2; 303 return list2;
304} 304}
305 305
306void Manager::signalStrength( const QString &mac ) { 306void Manager::signalStrength( const QString &mac ) {
307 307
308 OProcess* sig_proc = new OProcess(); 308 OProcess* sig_proc = new OProcess();
309 309
310 connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ), 310 connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ),
311 this, SLOT(slotSignalStrengthExited( Opie::Core::OProcess*) ) ); 311 this, SLOT(slotSignalStrengthExited( Opie::Core::OProcess*) ) );
312 connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), 312 connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ),
313 this, SLOT(slotSignalStrengthOutput(Opie::Core::OProcess*, char*, int) ) ); 313 this, SLOT(slotSignalStrengthOutput(Opie::Core::OProcess*, char*, int) ) );
314 *sig_proc << "hcitool"; 314 *sig_proc << "hcitool";
315 *sig_proc << "lq"; 315 *sig_proc << "lq";
316 *sig_proc << mac; 316 *sig_proc << mac;
317 317
318 sig_proc->setName( mac.latin1() ); 318 sig_proc->setName( mac.latin1() );
319 319
320 if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 320 if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
321 emit signalStrength( mac, "-1" ); 321 emit signalStrength( mac, "-1" );
322 delete sig_proc; 322 delete sig_proc;
323 } 323 }
324} 324}
325 325
326void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) { 326void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) {
327 QCString str(cha, len ); 327 QCString str(cha, len );
328 QString temp = QString(str).stripWhiteSpace(); 328 QString temp = QString(str).stripWhiteSpace();
329 QStringList value = QStringList::split(' ', temp ); 329 QStringList value = QStringList::split(' ', temp );
330 emit signalStrength( proc->name(), value[2].latin1() ); 330 emit signalStrength( proc->name(), value[2].latin1() );
331} 331}
332 332
333 333
334void Manager::slotSignalStrengthExited( OProcess* proc ) { 334void Manager::slotSignalStrengthExited( OProcess* proc ) {
335 delete proc; 335 delete proc;
336} 336}
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index af1cd23..0649514 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -14,223 +14,217 @@
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include "bluebase.h" 18#include "bluebase.h"
19#include "scandialog.h" 19#include "scandialog.h"
20#include "hciconfwrapper.h" 20#include "hciconfwrapper.h"
21#include "devicehandler.h" 21#include "devicehandler.h"
22#include "btconnectionitem.h" 22#include "btconnectionitem.h"
23#include "rfcommassigndialogimpl.h" 23#include "rfcommassigndialogimpl.h"
24 24
25/* OPIE */ 25/* OPIE */
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/resource.h> 27#include <qpe/resource.h>
28#include <qpe/config.h> 28#include <qpe/config.h>
29#include <opie2/odebug.h> 29#include <opie2/odebug.h>
30using namespace Opie::Core; 30using namespace Opie::Core;
31 31
32/* QT */ 32/* QT */
33#include <qframe.h> 33#include <qframe.h>
34#include <qlabel.h> 34#include <qlabel.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qvariant.h> 37#include <qvariant.h>
38#include <qimage.h> 38#include <qimage.h>
39#include <qpixmap.h> 39#include <qpixmap.h>
40#include <qtabwidget.h> 40#include <qtabwidget.h>
41#include <qscrollview.h> 41#include <qscrollview.h>
42#include <qvbox.h> 42#include <qvbox.h>
43#include <qmessagebox.h> 43#include <qmessagebox.h>
44#include <qcheckbox.h> 44#include <qcheckbox.h>
45#include <qlineedit.h> 45#include <qlineedit.h>
46#include <qlistview.h> 46#include <qlistview.h>
47#include <qdir.h> 47#include <qdir.h>
48#include <qpopupmenu.h> 48#include <qpopupmenu.h>
49#include <qtimer.h> 49#include <qtimer.h>
50#include <qlist.h> 50#include <qlist.h>
51 51
52/* STD */ 52/* STD */
53#include <remotedevice.h> 53#include <remotedevice.h>
54#include <services.h> 54#include <services.h>
55#include <stdlib.h> 55#include <stdlib.h>
56 56
57using namespace OpieTooth; 57using namespace OpieTooth;
58 58
59BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) 59BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
60 : BluetoothBase( parent, name, fl ) 60 : BluetoothBase( parent, name, fl )
61{ 61{
62
63 m_localDevice = new Manager( "hci0" ); 62 m_localDevice = new Manager( "hci0" );
64 63
65 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); 64 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) );
66 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); 65 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) );
67 66
68 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); 67 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) );
69 // not good since lib is async 68
70 // connect( devicesView, SIGNAL( expanded(QListViewItem*) ),
71 // this, SLOT( addServicesToDevice(QListViewItem*) ) );
72 connect( devicesView, SIGNAL( clicked(QListViewItem*)), 69 connect( devicesView, SIGNAL( clicked(QListViewItem*)),
73 this, SLOT( startServiceActionClicked(QListViewItem*) ) ); 70 this, SLOT( startServiceActionClicked(QListViewItem*) ) );
74 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), 71 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ),
75 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) ); 72 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) );
76 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ), 73 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ),
77 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) ); 74 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) );
78 connect( m_localDevice, SIGNAL( available(const QString&,bool) ), 75 connect( m_localDevice, SIGNAL( available(const QString&,bool) ),
79 this, SLOT( deviceActive(const QString&,bool) ) ); 76 this, SLOT( deviceActive(const QString&,bool) ) );
80 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), 77 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ),
81 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); 78 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) );
82 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), 79 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ),
83 this, SLOT( addSignalStrength(const QString&,const QString&) ) ); 80 this, SLOT( addSignalStrength(const QString&,const QString&) ) );
84 81
85
86 // let hold be rightButtonClicked() 82 // let hold be rightButtonClicked()
87 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); 83 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold);
88 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold); 84 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold);
89 85
90 //Load all icons needed 86 //Load all icons needed
91 m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); 87 m_offPix = Resource::loadPixmap( "opietooth/notconnected" );
92 m_onPix = Resource::loadPixmap( "opietooth/connected" ); 88 m_onPix = Resource::loadPixmap( "opietooth/connected" );
93 m_findPix = Resource::loadPixmap( "opietooth/find" ); 89 m_findPix = Resource::loadPixmap( "opietooth/find" );
94 90
95 QPalette pal = this->palette(); 91 QPalette pal = this->palette();
96 QColor col = pal.color( QPalette::Active, QColorGroup::Background ); 92 QColor col = pal.color( QPalette::Active, QColorGroup::Background );
97 pal.setColor( QPalette::Active, QColorGroup::Button, col ); 93 pal.setColor( QPalette::Active, QColorGroup::Button, col );
98 pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); 94 pal.setColor( QPalette::Inactive, QColorGroup::Button, col );
99 pal.setColor( QPalette::Normal, QColorGroup::Button, col ); 95 pal.setColor( QPalette::Normal, QColorGroup::Button, col );
100 pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); 96 pal.setColor( QPalette::Disabled, QColorGroup::Button, col );
101 this->setPalette( pal ); 97 this->setPalette( pal );
102 98
103 setCaption( tr( "Bluetooth Manager" ) ); 99 setCaption( tr( "Bluetooth Manager" ) );
104 100
105 readConfig(); 101 readConfig();
106 initGui(); 102 initGui();
107 103
108 devicesView->setRootIsDecorated(true); 104 devicesView->setRootIsDecorated(true);
109 105 m_iconLoader = new BTIconLoader();
110
111 writeToHciConfig(); 106 writeToHciConfig();
112 // search conncetions
113 addConnectedDevices(); 107 addConnectedDevices();
114 addSignalStrength();
115 m_iconLoader = new BTIconLoader();
116 readSavedDevices(); 108 readSavedDevices();
109 addServicesToDevices();
110 QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) );
117} 111}
118 112
119/** 113/**
120 * Reads all options from the config file 114 * Reads all options from the config file
121 */ 115 */
122void BlueBase::readConfig() 116void BlueBase::readConfig()
123{ 117{
124 118
125 Config cfg( "bluetoothmanager" ); 119 Config cfg( "bluetoothmanager" );
126 cfg.setGroup( "bluezsettings" ); 120 cfg.setGroup( "bluezsettings" );
127 121
128 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with 122 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with
129 m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak 123 m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak
130 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); 124 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE );
131 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); 125 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE );
132 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); 126 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE );
133 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); 127 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE );
134} 128}
135 129
136/** 130/**
137 * Writes all options to the config file 131 * Writes all options to the config file
138 */ 132 */
139void BlueBase::writeConfig() 133void BlueBase::writeConfig()
140{ 134{
141 135
142 Config cfg( "bluetoothmanager" ); 136 Config cfg( "bluetoothmanager" );
143 cfg.setGroup( "bluezsettings" ); 137 cfg.setGroup( "bluezsettings" );
144 138
145 cfg.writeEntry( "name" , m_deviceName ); 139 cfg.writeEntry( "name" , m_deviceName );
146 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); 140 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey );
147 cfg.writeEntry( "useEncryption" , m_useEncryption ); 141 cfg.writeEntry( "useEncryption" , m_useEncryption );
148 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); 142 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification );
149 cfg.writeEntry( "enablePagescan" , m_enablePagescan ); 143 cfg.writeEntry( "enablePagescan" , m_enablePagescan );
150 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); 144 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan );
151 145
152 writeToHciConfig(); 146 writeToHciConfig();
153} 147}
154 148
155/** 149/**
156 * Modify the hcid.conf file to our needs 150 * Modify the hcid.conf file to our needs
157 */ 151 */
158void BlueBase::writeToHciConfig() 152void BlueBase::writeToHciConfig()
159{ 153{
160 owarn << "writeToHciConfig" << oendl; 154 owarn << "writeToHciConfig" << oendl;
161 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); 155 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" );
162 hciconf.load(); 156 hciconf.load();
163 hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" ); 157 hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" );
164 hciconf.setName( m_deviceName ); 158 hciconf.setName( m_deviceName );
165 hciconf.setEncrypt( m_useEncryption ); 159 hciconf.setEncrypt( m_useEncryption );
166 hciconf.setAuth( m_enableAuthentification ); 160 hciconf.setAuth( m_enableAuthentification );
167 hciconf.setPscan( m_enablePagescan ); 161 hciconf.setPscan( m_enablePagescan );
168 hciconf.setIscan( m_enableInquiryscan ); 162 hciconf.setIscan( m_enableInquiryscan );
169 hciconf.save(); 163 hciconf.save();
170} 164}
171 165
172 166
173/** 167/**
174 * Read the list of allready known devices 168 * Read the list of already known devices
175 */ 169 */
176void BlueBase::readSavedDevices() 170void BlueBase::readSavedDevices()
177{ 171{
178 172
179 QValueList<RemoteDevice> loadedDevices; 173 QValueList<RemoteDevice> loadedDevices;
180 DeviceHandler handler; 174 DeviceHandler handler;
181 loadedDevices = handler.load(); 175 loadedDevices = handler.load();
182 176
183 addSearchedDevices( loadedDevices ); 177 addSearchedDevices( loadedDevices );
184} 178}
185 179
186 180
187/** 181/**
188 * Write the list of allready known devices 182 * Write the list of already known devices
189 */ 183 */
190void BlueBase::writeSavedDevices() 184void BlueBase::writeSavedDevices()
191{ 185{
192 QListViewItemIterator it( devicesView ); 186 QListViewItemIterator it( devicesView );
193 BTListItem* item; 187 BTListItem* item;
194 BTDeviceItem* device; 188 BTDeviceItem* device;
195 RemoteDevice::ValueList list; 189 RemoteDevice::ValueList list;
196 for ( ; it.current(); ++it ) 190 for ( ; it.current(); ++it )
197 { 191 {
198 item = (BTListItem*)it.current(); 192 item = (BTListItem*)it.current();
199 if(item->typeId() != BTListItem::Device ) 193 if(item->typeId() != BTListItem::Device )
200 continue; 194 continue;
201 device = (BTDeviceItem*)item; 195 device = (BTDeviceItem*)item;
202 196
203 list.append( device->remoteDevice() ); 197 list.append( device->remoteDevice() );
204 } 198 }
205 /* 199 /*
206 * if not empty save the List through DeviceHandler 200 * if not empty save the List through DeviceHandler
207 */ 201 */
208 if ( list.isEmpty() ) 202 if ( list.isEmpty() )
209 return; 203 return;
210 DeviceHandler handler; 204 DeviceHandler handler;
211 handler.save( list ); 205 handler.save( list );
212} 206}
213 207
214 208
215/** 209/**
216 * Set up the gui 210 * Set up the gui
217 */ 211 */
218void BlueBase::initGui() 212void BlueBase::initGui()
219{ 213{
220 StatusLabel->setText( status() ); // maybe move it to getStatus() 214 StatusLabel->setText( status() ); // maybe move it to getStatus()
221 cryptCheckBox->setChecked( m_useEncryption ); 215 cryptCheckBox->setChecked( m_useEncryption );
222 authCheckBox->setChecked( m_enableAuthentification ); 216 authCheckBox->setChecked( m_enableAuthentification );
223 pagescanCheckBox->setChecked( m_enablePagescan ); 217 pagescanCheckBox->setChecked( m_enablePagescan );
224 inquiryscanCheckBox->setChecked( m_enableInquiryscan ); 218 inquiryscanCheckBox->setChecked( m_enableInquiryscan );
225 deviceNameLine->setText( m_deviceName ); 219 deviceNameLine->setText( m_deviceName );
226 passkeyLine->setText( m_defaultPasskey ); 220 passkeyLine->setText( m_defaultPasskey );
227 // set info tab 221 // set info tab
228 setInfo(); 222 setInfo();
229} 223}
230 224
231 225
232/** 226/**
233 * Get the status informations and returns it 227 * Get the status informations and returns it
234 * @return QString the status informations gathered 228 * @return QString the status informations gathered
235 */ 229 */
236QString BlueBase::status()const 230QString BlueBase::status()const
@@ -250,99 +244,96 @@ void BlueBase::applyConfigChanges()
250{ 244{
251 m_deviceName = deviceNameLine->text(); 245 m_deviceName = deviceNameLine->text();
252 m_defaultPasskey = passkeyLine->text(); 246 m_defaultPasskey = passkeyLine->text();
253 m_useEncryption = cryptCheckBox->isChecked(); 247 m_useEncryption = cryptCheckBox->isChecked();
254 m_enableAuthentification = authCheckBox->isChecked(); 248 m_enableAuthentification = authCheckBox->isChecked();
255 m_enablePagescan = pagescanCheckBox->isChecked(); 249 m_enablePagescan = pagescanCheckBox->isChecked();
256 m_enableInquiryscan = inquiryscanCheckBox->isChecked(); 250 m_enableInquiryscan = inquiryscanCheckBox->isChecked();
257 251
258 writeConfig(); 252 writeConfig();
259 253
260 QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); 254 QMessageBox::information( this, tr("Test") , tr("Changes were applied.") );
261} 255}
262 256
263/** 257/**
264 * Launch Rfcomm Bind dialog 258 * Launch Rfcomm Bind dialog
265 * 259 *
266 */ 260 */
267void BlueBase::rfcommDialog() 261void BlueBase::rfcommDialog()
268{ 262{
269 RfcommAssignDialog rfcommAssign ( this, "RfcommAssignDialog", true, WStyle_ContextHelp ); 263 RfcommAssignDialog rfcommAssign ( this, "RfcommAssignDialog", true, WStyle_ContextHelp );
270 264
271 if ( QPEApplication::execDialog( &rfcommAssign ) == QDialog::Accepted ) 265 if ( QPEApplication::execDialog( &rfcommAssign ) == QDialog::Accepted )
272 { 266 {
273 rfcommAssign.saveConfig(); 267 rfcommAssign.saveConfig();
274 } 268 }
275} 269}
276 270
277/** 271/**
278 * Add fresh found devices from scan dialog to the listing 272 * Add fresh found devices from scan dialog to the listing
279 * 273 *
280 */ 274 */
281void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) 275void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices )
282{ 276{
283 BTDeviceItem * deviceItem; 277 BTDeviceItem * deviceItem;
284 QValueList<RemoteDevice>::ConstIterator it; 278 QValueList<RemoteDevice>::ConstIterator it;
285 279
286 for( it = newDevices.begin(); it != newDevices.end() ; ++it ) 280 for( it = newDevices.begin(); it != newDevices.end() ; ++it )
287 { 281 {
288 282
289 if (find( (*it) )) // is already inserted 283 if (find( (*it) )) // is already inserted
290 continue; 284 continue;
291 285
292 deviceItem = new BTDeviceItem( devicesView , (*it) ); 286 deviceItem = new BTDeviceItem( devicesView , (*it) );
293 deviceItem->setPixmap( 1, m_findPix ); 287 deviceItem->setPixmap( 1, m_findPix );
294 deviceItem->setExpandable ( true ); 288 deviceItem->setExpandable ( true );
295 289
296 // look if device is avail. atm, async 290 // look if device is avail. atm, async
297 deviceActive( (*it) ); 291 deviceActive( (*it) );
298
299 // ggf auch hier?
300 addServicesToDevice( deviceItem );
301 } 292 }
302} 293}
303 294
304 295
305/** 296/**
306 * Action that is toggled on entrys on click 297 * Action that is toggled on entrys on click
307 */ 298 */
308void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) 299void BlueBase::startServiceActionClicked( QListViewItem */*item*/ )
309{} 300{}
310 301
311 302
312/** 303/**
313 * Action that are toggled on hold (mostly QPopups i guess) 304 * Action that are toggled on hold (mostly QPopups i guess)
314 */ 305 */
315void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) 306void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ )
316{ 307{
317 if (!item ) 308 if (!item )
318 return; 309 return;
319 310
320 QPopupMenu *menu = new QPopupMenu(); 311 QPopupMenu *menu = new QPopupMenu();
321 312
322 if ( static_cast<BTListItem*>( item )->type() == "device") 313 if ( static_cast<BTListItem*>( item )->type() == "device")
323 { 314 {
324 QPopupMenu *groups = new QPopupMenu(); 315 QPopupMenu *groups = new QPopupMenu();
325 316
326 menu->insertItem( static_cast<BTDeviceItem*>( item )->name(), 0 ); 317 menu->insertItem( static_cast<BTDeviceItem*>( item )->name(), 0 );
327 menu->insertSeparator( 1 ); 318 menu->insertSeparator( 1 );
328 menu->insertItem( tr( "&Rescan services" ), 2); 319 menu->insertItem( tr( "&Rescan services" ), 2);
329 // menu->insertItem( tr( "&Add to group" ), groups, 3); 320 // menu->insertItem( tr( "&Add to group" ), groups, 3);
330 menu->insertItem( tr( "&Delete"), 4); 321 menu->insertItem( tr( "&Delete"), 4);
331 int ret = menu->exec( point, 0); 322 int ret = menu->exec( point, 0);
332 323
333 switch(ret) 324 switch(ret)
334 { 325 {
335 case -1: 326 case -1:
336 break; 327 break;
337 case 2: 328 case 2:
338 addServicesToDevice( static_cast<BTDeviceItem*>( item ) ); 329 addServicesToDevice( static_cast<BTDeviceItem*>( item ) );
339 break; 330 break;
340 331
341 case 4: 332 case 4:
342 // deletes childs too 333 // deletes childs too
343 delete item; 334 delete item;
344 break; 335 break;
345 } 336 }
346 // delete groups; 337 // delete groups;
347 } 338 }
348 339
@@ -353,210 +344,216 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin
353 * one if the factory returns 0 344 * one if the factory returns 0
354 * PopupMenu deletion is kind of weird. 345 * PopupMenu deletion is kind of weird.
355 * If escaped( -1 ) or any of our items were chosen we'll 346 * If escaped( -1 ) or any of our items were chosen we'll
356 * delete the PopupMenu otherwise it's the responsibility of 347 * delete the PopupMenu otherwise it's the responsibility of
357 * the PopupMenu to delete itself 348 * the PopupMenu to delete itself
358 * 349 *
359 */ 350 */
360 else if ( ((BTListItem*)item)->type() == "service") 351 else if ( ((BTListItem*)item)->type() == "service")
361 { 352 {
362 BTServiceItem* service = (BTServiceItem*)item; 353 BTServiceItem* service = (BTServiceItem*)item;
363 QMap<int, QString> list = service->services().classIdList(); 354 QMap<int, QString> list = service->services().classIdList();
364 QMap<int, QString>::Iterator it = list.begin(); 355 QMap<int, QString>::Iterator it = list.begin();
365 QPopupMenu *popup =0l; 356 QPopupMenu *popup =0l;
366 if ( it != list.end() ) 357 if ( it != list.end() )
367 { 358 {
368 owarn << "Searching id " << it.key() << " " << it.data().latin1() << "" << oendl; 359 owarn << "Searching id " << it.key() << " " << it.data().latin1() << "" << oendl;
369 popup = m_popHelper.find( it.key(), 360 popup = m_popHelper.find( it.key(),
370 service->services(), 361 service->services(),
371 (BTDeviceItem*)service->parent() ); 362 (BTDeviceItem*)service->parent() );
372 } 363 }
373 else 364 else
374 { 365 {
375 owarn << "Empty" << oendl; 366 owarn << "Empty" << oendl;
376 } 367 }
377 368
378 if ( popup == 0l ) 369 if ( popup == 0l )
379 { 370 {
380 owarn << "factory returned 0l" << oendl; 371 owarn << "factory returned 0l" << oendl;
381 popup = new QPopupMenu(); 372 popup = new QPopupMenu();
382 } 373 }
383 int test1 = popup->insertItem( tr("Test1:"), 2); 374 int test1 = popup->insertItem( tr("Test1:"), 2);
384 375
385 int ret = popup->exec( point ); 376 int ret = popup->exec( point );
386 owarn << "returned from exec() " << oendl; 377 owarn << "returned from exec() " << oendl;
387 if ( ret == -1 ) 378 if ( ret == -1 )
388 { 379 {
389 ; 380 ;
390 } 381 }
391 else if ( ret == test1 ) 382 else if ( ret == test1 )
392 { 383 {
393 ; 384 ;
394 } 385 }
395 delete popup; 386 delete popup;
396 } 387 }
397 delete menu; 388 delete menu;
398} 389}
399 390
400 391
392void BlueBase::addServicesToDevices()
393{
394 odebug << "BlueBase::addServicesToDevices()" << oendl;
395 BTDeviceItem* item = (BTDeviceItem*) devicesView->firstChild();
396 while ( item )
397 {
398 addServicesToDevice( item );
399 item = (BTDeviceItem*) static_cast<QListViewItem*>( item )->nextSibling();
400 }
401}
402
401/** 403/**
402 * Search and display avail. services for a device (on expand from device listing) 404 * Search and display avail. services for a device (on expand from device listing)
403 * @param item the service item returned 405 * @param item the service item returned
404 */ 406 */
405void BlueBase::addServicesToDevice( BTDeviceItem * item ) 407void BlueBase::addServicesToDevice( BTDeviceItem * item )
406{ 408{
407 odebug << "addServicesToDevice" << oendl; 409 odebug << "BlueBase::addServicesToDevice" << oendl;
408 // row of mac adress text(3) 410 // row of mac adress text(3)
409 RemoteDevice device = item->remoteDevice(); 411 RemoteDevice device = item->remoteDevice();
410 m_deviceList.insert( item->mac() , item ); 412 m_deviceList.insert( item->mac() , item );
411 // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back 413 // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back
412 m_localDevice->searchServices( device ); 414 m_localDevice->searchServices( device );
413} 415}
414 416
415 417
416/** 418/**
417 * Overloaded. This one it the one that is
418 ted to the foundServices signal
419 * @param device the mac address of the remote device 419 * @param device the mac address of the remote device
420 * @param servicesList the list with the service the device has. 420 * @param servicesList the list with the service the device has.
421 */ 421 */
422void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) 422void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList )
423{ 423{
424 odebug << "fill services list" << oendl; 424 odebug << "BlueBase::fill services list" << oendl;
425 425
426 QMap<QString,BTDeviceItem*>::Iterator it; 426 QMap<QString,BTDeviceItem*>::Iterator it;
427 BTDeviceItem* deviceItem = 0; 427 BTDeviceItem* deviceItem = 0;
428 428
429 // get the right devices which requested the search 429 // get the right devices which requested the search
430 it = m_deviceList.find( device ); 430 it = m_deviceList.find( device );
431 if( it == m_deviceList.end() ) 431 if( it == m_deviceList.end() )
432 return; 432 return;
433 deviceItem = it.data(); 433 deviceItem = it.data();
434 434
435 // remove previous entries 435 // remove previous entries
436 QList<QListViewItem> tempList; 436 QList<QListViewItem> tempList;
437 tempList.setAutoDelete( true ); 437 tempList.setAutoDelete( true );
438 QListViewItem * child = deviceItem->firstChild(); 438 QListViewItem * child = deviceItem->firstChild();
439 while( child ) 439 while( child )
440 { 440 {
441 tempList.append( child ); 441 tempList.append( child );
442 child = child->nextSibling(); 442 child = child->nextSibling();
443 } 443 }
444 tempList.clear(); 444 tempList.clear();
445 445
446 QValueList<OpieTooth::Services>::Iterator it2; 446 QValueList<OpieTooth::Services>::Iterator it2;
447 BTServiceItem* serviceItem; 447 BTServiceItem* serviceItem;
448 448
449 449
450 if (!servicesList.isEmpty() ) 450 if (!servicesList.isEmpty() )
451 { 451 {
452 // add services 452 // add services
453 QMap<int, QString> list; 453 QMap<int, QString> list;
454 QMap<int, QString>::Iterator classIt; 454 QMap<int, QString>::Iterator classIt;
455 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) 455 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 )
456 { 456 {
457 serviceItem = new BTServiceItem( deviceItem, (*it2) ); 457 serviceItem = new BTServiceItem( deviceItem, (*it2) );
458 list = (*it2).classIdList(); 458 list = (*it2).classIdList();
459 classIt = list.begin(); 459 classIt = list.begin();
460 int classId=0; 460 int classId=0;
461 if ( classIt != list.end() ) 461 if ( classIt != list.end() )
462 { 462 {
463 classId = classIt.key(); 463 classId = classIt.key();
464 } 464 }
465 465
466 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); 466 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) );
467 } 467 }
468 } 468 }
469 else 469 else
470 { 470 {
471 Services s1; 471 Services s1;
472 s1.setServiceName( tr("no services found") ); 472 s1.setServiceName( tr("no services found") );
473 serviceItem = new BTServiceItem( deviceItem, s1 ); 473 serviceItem = new BTServiceItem( deviceItem, s1 );
474 } 474 }
475 // now remove them from the list 475 // now remove them from the list
476 m_deviceList.remove( it ); 476 m_deviceList.remove( it );
477} 477}
478 478
479
480
481
482
483void BlueBase::addSignalStrength() 479void BlueBase::addSignalStrength()
484{ 480{
485 481
486 QListViewItemIterator it( connectionsView ); 482 QListViewItemIterator it( connectionsView );
487 for ( ; it.current(); ++it ) 483 for ( ; it.current(); ++it )
488 { 484 {
489 m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() ); 485 m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() );
490 } 486 }
491 487
492 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); 488 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) );
493} 489}
494 490
495void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) 491void BlueBase::addSignalStrength( const QString& mac, const QString& strength )
496{ 492{
497 493
498 QListViewItemIterator it( connectionsView ); 494 QListViewItemIterator it( connectionsView );
499 for ( ; it.current(); ++it ) 495 for ( ; it.current(); ++it )
500 { 496 {
501 if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) 497 if( ((BTConnectionItem*)it.current())->connection().mac() == mac )
502 { 498 {
503 ((BTConnectionItem*)it.current() )->setSignalStrength( strength ); 499 ((BTConnectionItem*)it.current() )->setSignalStrength( strength );
504 } 500 }
505 } 501 }
506} 502}
507 503
508/** 504/**
509 * Add the existing connections (pairs) to the connections tab. 505 * Add the existing connections (pairs) to the connections tab.
510 * This one triggers the search 506 * This one triggers the search
511 */ 507 */
512void BlueBase::addConnectedDevices() 508void BlueBase::addConnectedDevices()
513{ 509{
514 m_localDevice->searchConnections(); 510 m_localDevice->searchConnections();
511 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) );
515} 512}
516 513
517/** 514/**
518 * This adds the found connections to the connection tab. 515 * This adds the found connections to the connection tab.
519 * @param connectionList the ValueList with all current connections 516 * @param connectionList the ValueList with all current connections
520 */ 517 */
521void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) 518void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList )
522{ 519{
523 520
524 QValueList<OpieTooth::ConnectionState>::Iterator it; 521 QValueList<OpieTooth::ConnectionState>::Iterator it;
525 BTConnectionItem * connectionItem; 522 BTConnectionItem * connectionItem;
526 523
527 if ( !connectionList.isEmpty() ) 524 if ( !connectionList.isEmpty() )
528 { 525 {
529 526
530 for (it = connectionList.begin(); it != connectionList.end(); ++it) 527 for (it = connectionList.begin(); it != connectionList.end(); ++it)
531 { 528 {
532 529
533 QListViewItemIterator it2( connectionsView ); 530 QListViewItemIterator it2( connectionsView );
534 bool found = false; 531 bool found = false;
535 for ( ; it2.current(); ++it2 ) 532 for ( ; it2.current(); ++it2 )
536 { 533 {
537 if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() ) 534 if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() )
538 { 535 {
539 found = true; 536 found = true;
540 } 537 }
541 } 538 }
542 539
543 if ( found == false ) 540 if ( found == false )
544 { 541 {
545 connectionItem = new BTConnectionItem( connectionsView, (*it) ); 542 connectionItem = new BTConnectionItem( connectionsView, (*it) );
546 543
547 if( m_deviceList.find((*it).mac()).data() ) 544 if( m_deviceList.find((*it).mac()).data() )
548 { 545 {
549 connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() ); 546 connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() );
550 } 547 }
551 } 548 }
552 549
553 } 550 }
554 551
555 QListViewItemIterator it2( connectionsView ); 552 QListViewItemIterator it2( connectionsView );
556 for ( ; it2.current(); ++it2 ) 553 for ( ; it2.current(); ++it2 )
557 { 554 {
558 bool found = false; 555 bool found = false;
559 for (it = connectionList.begin(); it != connectionList.end(); ++it) 556 for (it = connectionList.begin(); it != connectionList.end(); ++it)
560 { 557 {
561 if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() ) 558 if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() )
562 { 559 {
@@ -570,97 +567,96 @@ void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList )
570 } 567 }
571 568
572 } 569 }
573 570
574 571
575 } 572 }
576 else 573 else
577 { 574 {
578 connectionsView->clear(); 575 connectionsView->clear();
579 ConnectionState con; 576 ConnectionState con;
580 con.setMac( tr("No connections found") ); 577 con.setMac( tr("No connections found") );
581 connectionItem = new BTConnectionItem( connectionsView , con ); 578 connectionItem = new BTConnectionItem( connectionsView , con );
582 } 579 }
583 580
584 // recall connection search after some time 581 // recall connection search after some time
585 QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); 582 QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) );
586} 583}
587 584
588 585
589/** 586/**
590 * Find out if a device can currently be reached 587 * Find out if a device can currently be reached
591 * @param device 588 * @param device
592 */ 589 */
593void BlueBase::deviceActive( const RemoteDevice &device ) 590void BlueBase::deviceActive( const RemoteDevice &device )
594{ 591{
595 // search by mac, async, gets a signal back 592 // search by mac, async, gets a signal back
596 // We should have a BTDeviceItem there or where does it get added to the map -zecke 593 // We should have a BTDeviceItem there or where does it get added to the map -zecke
597 m_localDevice->isAvailable( device.mac() ); 594 m_localDevice->isAvailable( device.mac() );
598} 595}
599 596
600 597
601/** 598/**
602 * The signal catcher. Set the avail. status on device. 599 * The signal catcher. Set the avail. status on device.
603 * @param device - the mac address 600 * @param device - the mac address
604 * @param connected - if it is avail. or not 601 * @param connected - if it is avail. or not
605 */ 602 */
606void BlueBase::deviceActive( const QString& device, bool connected ) 603void BlueBase::deviceActive( const QString& device, bool connected )
607{ 604{
608 odebug << "deviceActive slot" << oendl; 605 odebug << "deviceActive slot" << oendl;
609 606
610 QMap<QString,BTDeviceItem*>::Iterator it; 607 QMap<QString,BTDeviceItem*>::Iterator it;
611 608
612 it = m_deviceList.find( device ); 609 it = m_deviceList.find( device );
613 if( it == m_deviceList.end() ) 610 if( it == m_deviceList.end() )
614 return; 611 return;
615 612
616 BTDeviceItem* deviceItem = it.data(); 613 BTDeviceItem* deviceItem = it.data();
617 614
618
619 if ( connected ) 615 if ( connected )
620 { 616 {
621 deviceItem->setPixmap( 1, m_onPix ); 617 deviceItem->setPixmap( 1, m_onPix );
622 } 618 }
623 else 619 else
624 { 620 {
625 deviceItem->setPixmap( 1, m_offPix ); 621 deviceItem->setPixmap( 1, m_offPix );
626 } 622 }
627 m_deviceList.remove( it ); 623 m_deviceList.remove( it );
628} 624}
629 625
630 626
631/** 627/**
632 * Open the "scan for devices" dialog 628 * Open the "scan for devices" dialog
633 */ 629 */
634void BlueBase::startScan() 630void BlueBase::startScan()
635{ 631{
636 ScanDialog *scan = new ScanDialog( this, "ScanDialog", 632 ScanDialog *scan = new ScanDialog( this, "ScanDialog",
637 true, WDestructiveClose ); 633 true, WDestructiveClose );
638 QObject::connect( scan, SIGNAL( selectedDevices(const QValueList<RemoteDevice>&) ), 634 QObject::connect( scan, SIGNAL( selectedDevices(const QValueList<RemoteDevice>&) ),
639 this, SLOT( addSearchedDevices(const QValueList<RemoteDevice>&) ) ); 635 this, SLOT( addSearchedDevices(const QValueList<RemoteDevice>&) ) );
640 636
641 QPEApplication::showDialog( scan ); 637 QPEApplication::showDialog( scan );
642} 638}
643 639
644 640
645/** 641/**
646 * Set the informations about the local device in information Tab 642 * Set the informations about the local device in information Tab
647 */ 643 */
648void BlueBase::setInfo() 644void BlueBase::setInfo()
649{ 645{
650 StatusLabel->setText( status() ); 646 StatusLabel->setText( status() );
651} 647}
652 648
653 649
654/** 650/**
655 * Decontructor 651 * Decontructor
656 */ 652 */
657BlueBase::~BlueBase() 653BlueBase::~BlueBase()
658{ 654{
659 writeSavedDevices(); 655 writeSavedDevices();
660 delete m_iconLoader; 656 delete m_iconLoader;
661} 657}
662 658
663 659
664/** 660/**
665 * find searches the ListView for a BTDeviceItem containig 661 * find searches the ListView for a BTDeviceItem containig
666 * the same Device if found return true else false 662 * the same Device if found return true else false
diff --git a/noncore/net/opietooth/manager/bluebase.h b/noncore/net/opietooth/manager/bluebase.h
index a8ab3db..48883d2 100644
--- a/noncore/net/opietooth/manager/bluebase.h
+++ b/noncore/net/opietooth/manager/bluebase.h
@@ -1,101 +1,102 @@
1 1
2#ifndef BLUEBASE_H 2#ifndef BLUEBASE_H
3#define BLUEBASE_H 3#define BLUEBASE_H
4 4
5#include <qvariant.h> 5#include <qvariant.h>
6#include <qwidget.h> 6#include <qwidget.h>
7#include <qscrollview.h> 7#include <qscrollview.h>
8#include <qsplitter.h> 8#include <qsplitter.h>
9#include <qlist.h> 9#include <qlist.h>
10#include <qpixmap.h> 10#include <qpixmap.h>
11 11
12#include "bluetoothbase.h" 12#include "bluetoothbase.h"
13 13
14#include "btserviceitem.h" 14#include "btserviceitem.h"
15#include "btdeviceitem.h" 15#include "btdeviceitem.h"
16 16
17#include "popuphelper.h" 17#include "popuphelper.h"
18 18
19#include "bticonloader.h" 19#include "bticonloader.h"
20 20
21#include <remotedevice.h> 21#include <remotedevice.h>
22#include <manager.h> 22#include <manager.h>
23 23
24class QVBox; 24class QVBox;
25class QHBoxLayout; 25class QHBoxLayout;
26class QGridLayout; 26class QGridLayout;
27class QFrame; 27class QFrame;
28class QLabel; 28class QLabel;
29class QPushButton; 29class QPushButton;
30class QTabWidget; 30class QTabWidget;
31class QCheckBox; 31class QCheckBox;
32class BTConnectionItem; 32class BTConnectionItem;
33 33
34 34
35namespace OpieTooth { 35namespace OpieTooth {
36 36
37 class BlueBase : public BluetoothBase { 37 class BlueBase : public BluetoothBase {
38 Q_OBJECT 38 Q_OBJECT
39 39
40 public: 40 public:
41 BlueBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 41 BlueBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
42 ~BlueBase(); 42 ~BlueBase();
43 43
44 static QString appName() { return QString::fromLatin1("bluetooth-manager"); } 44 static QString appName() { return QString::fromLatin1("bluetooth-manager"); }
45 45
46 protected: 46 protected:
47 47
48 48
49 private slots: 49 private slots:
50 void startScan(); 50 void startScan();
51 51
52 52
53 private: 53 private:
54 bool find( const RemoteDevice& device ); 54 bool find( const RemoteDevice& device );
55 void readConfig(); 55 void readConfig();
56 void writeConfig(); 56 void writeConfig();
57 void readSavedDevices(); 57 void readSavedDevices();
58 void writeSavedDevices(); 58 void writeSavedDevices();
59 void writeToHciConfig(); 59 void writeToHciConfig();
60 QString status()const; 60 QString status()const;
61 void initGui(); 61 void initGui();
62 void setInfo(); 62 void setInfo();
63 63
64 PopupHelper m_popHelper; 64 PopupHelper m_popHelper;
65 Manager *m_localDevice; 65 Manager *m_localDevice;
66 QMap<QString,BTDeviceItem*> m_deviceList; 66 QMap<QString,BTDeviceItem*> m_deviceList;
67 67
68 void deviceActive( const RemoteDevice &device ); 68 void deviceActive( const RemoteDevice &device );
69 69
70 QString m_deviceName; 70 QString m_deviceName;
71 QString m_defaultPasskey; 71 QString m_defaultPasskey;
72 bool m_useEncryption; 72 bool m_useEncryption;
73 bool m_enableAuthentification; 73 bool m_enableAuthentification;
74 bool m_enablePagescan; 74 bool m_enablePagescan;
75 bool m_enableInquiryscan; 75 bool m_enableInquiryscan;
76 76
77 QPixmap m_offPix; 77 QPixmap m_offPix;
78 QPixmap m_onPix; 78 QPixmap m_onPix;
79 QPixmap m_findPix; 79 QPixmap m_findPix;
80 80
81 BTIconLoader *m_iconLoader; 81 BTIconLoader *m_iconLoader;
82 82
83 private slots: 83 private slots:
84 void addSearchedDevices( const QValueList<RemoteDevice> &newDevices ); 84 void addSearchedDevices( const QValueList<RemoteDevice> &newDevices );
85 void addServicesToDevices();
85 void addServicesToDevice( BTDeviceItem *item ); 86 void addServicesToDevice( BTDeviceItem *item );
86 void addServicesToDevice( const QString& device, Services::ValueList ); 87 void addServicesToDevice( const QString& device, Services::ValueList );
87 void addConnectedDevices(); 88 void addConnectedDevices();
88 void addConnectedDevices( ConnectionState::ValueList ); 89 void addConnectedDevices( ConnectionState::ValueList );
89 void startServiceActionClicked( QListViewItem *item ); 90 void startServiceActionClicked( QListViewItem *item );
90 void startServiceActionHold( QListViewItem *, const QPoint &, int ); 91 void startServiceActionHold( QListViewItem *, const QPoint &, int );
91 void deviceActive( const QString& mac, bool connected ); 92 void deviceActive( const QString& mac, bool connected );
92 void applyConfigChanges(); 93 void applyConfigChanges();
93 void addSignalStrength(); 94 void addSignalStrength();
94 void addSignalStrength( const QString& mac, const QString& strengh ); 95 void addSignalStrength( const QString& mac, const QString& strengh );
95 void rfcommDialog(); 96 void rfcommDialog();
96 97
97 }; 98 };
98 99
99} 100}
100 101
101#endif 102#endif