Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/Opietooth.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/opietooth2/Opietooth.cpp | 1003 |
1 files changed, 1003 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp new file mode 100644 index 0000000..8d71f32 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp | |||
@@ -0,0 +1,1003 @@ | |||
1 | #include <opie2/odebug.h> | ||
2 | #include <opie2/oledbox.h> | ||
3 | |||
4 | #include <qpe/resource.h> | ||
5 | #include <qcheckbox.h> | ||
6 | #include <qgroupbox.h> | ||
7 | #include <qlabel.h> | ||
8 | #include <qprogressbar.h> | ||
9 | #include <qheader.h> | ||
10 | #include <qmessagebox.h> | ||
11 | #include <qapplication.h> | ||
12 | #include <qlistbox.h> | ||
13 | #include <qdialog.h> | ||
14 | #include <qlayout.h> | ||
15 | #include <qcombobox.h> | ||
16 | #include <qlabel.h> | ||
17 | #include <qlistview.h> | ||
18 | #include <qpushbutton.h> | ||
19 | |||
20 | #include <Opietooth.h> | ||
21 | #include <OTDriver.h> | ||
22 | #include <OTPeer.h> | ||
23 | #include <OTGateway.h> | ||
24 | #include <OTSDPAttribute.h> | ||
25 | #include <OTSDPService.h> | ||
26 | #include <OTInquiry.h> | ||
27 | |||
28 | using namespace Opietooth2; | ||
29 | |||
30 | namespace Opietooth2 { | ||
31 | |||
32 | class PeerLVI : public QListViewItem { | ||
33 | |||
34 | public : | ||
35 | |||
36 | PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) { | ||
37 | Peer = P; | ||
38 | } | ||
39 | ~PeerLVI( void ) { | ||
40 | } | ||
41 | |||
42 | inline OTPeer * peer( void ) | ||
43 | { return Peer; } | ||
44 | |||
45 | private : | ||
46 | |||
47 | OTPeer * Peer; | ||
48 | }; | ||
49 | |||
50 | class ChannelLVI : public QListViewItem { | ||
51 | |||
52 | public : | ||
53 | |||
54 | ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) { | ||
55 | Channel = Ch; | ||
56 | } | ||
57 | ~ChannelLVI( void ) { | ||
58 | } | ||
59 | |||
60 | inline int channel( void ) | ||
61 | { return Channel; } | ||
62 | |||
63 | private : | ||
64 | |||
65 | int Channel; | ||
66 | }; | ||
67 | |||
68 | class DriverLVI : public QListViewItem { | ||
69 | |||
70 | public : | ||
71 | |||
72 | DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) { | ||
73 | Driver = P; | ||
74 | } | ||
75 | ~DriverLVI( void ) { | ||
76 | } | ||
77 | |||
78 | inline OTDriver * driver( void ) | ||
79 | { return Driver; } | ||
80 | |||
81 | private : | ||
82 | |||
83 | OTDriver * Driver; | ||
84 | }; | ||
85 | |||
86 | class LinkKeyLVI : public QListViewItem { | ||
87 | |||
88 | public : | ||
89 | |||
90 | LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) { | ||
91 | LinkKey = Ch; | ||
92 | } | ||
93 | ~LinkKeyLVI( void ) { | ||
94 | } | ||
95 | |||
96 | inline int index( void ) | ||
97 | { return LinkKey; } | ||
98 | |||
99 | private : | ||
100 | |||
101 | int LinkKey; | ||
102 | }; | ||
103 | }; | ||
104 | |||
105 | // | ||
106 | // | ||
107 | // | ||
108 | // | ||
109 | // | ||
110 | |||
111 | OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) : | ||
112 | OTPairingGUI( parent ) { | ||
113 | |||
114 | OT = OTGateway::getOTGateway(); | ||
115 | Icons = (_IC ) ? _IC : new OTIcons(); | ||
116 | MyIcons = (_IC == 0 ); | ||
117 | |||
118 | // unpairing can only be done if bluetooth is disabled | ||
119 | Unpair_But->setEnabled( ! OT->isEnabled() ); | ||
120 | if( ! OT->isEnabled() ) { | ||
121 | Unpair_LBL->hide(); | ||
122 | } else { | ||
123 | Unpair_LBL->show(); | ||
124 | } | ||
125 | |||
126 | // open linkkey file and load pairs | ||
127 | LinkKeyArray Keys = OT->getLinkKeys(); | ||
128 | LinkKeyLVI * it; | ||
129 | OTPeer * P; | ||
130 | OTDriver * D; | ||
131 | |||
132 | for( unsigned int i = 0 ; | ||
133 | i < Keys.count(); | ||
134 | i ++ ) { | ||
135 | |||
136 | it = new LinkKeyLVI( i, Pairs_LV ); | ||
137 | |||
138 | P = 0; | ||
139 | D = OT->findDriver( Keys[i].from() ); | ||
140 | |||
141 | if( D ) { | ||
142 | it->setText( 0, D->devname() ); | ||
143 | |||
144 | // we are source | ||
145 | P = OT->findPeer( Keys[i].to() ); | ||
146 | |||
147 | if( P ) { | ||
148 | // put name | ||
149 | it->setText( 1, P->name() ); | ||
150 | } else { | ||
151 | // unknown | ||
152 | it->setText( 1, Keys[i].to().toString() ); | ||
153 | } | ||
154 | |||
155 | // and put address as sub | ||
156 | QListViewItem * Sub = new QListViewItem( it ); | ||
157 | Sub->setText( 0, D->address().toString() ); | ||
158 | Sub->setText( 1, Keys[i].to().toString() ); | ||
159 | } else { | ||
160 | // perhaps we are destination | ||
161 | D = OT->findDriver( Keys[i].to() ); | ||
162 | |||
163 | if( D ) { | ||
164 | it->setText( 1, D->devname() ); | ||
165 | |||
166 | // we are source | ||
167 | P = OT->findPeer( Keys[i].from() ); | ||
168 | |||
169 | if( P ) { | ||
170 | // put name | ||
171 | it->setText( 0, P->name() ); | ||
172 | } else { | ||
173 | // unknown | ||
174 | it->setText( 0, Keys[i].from().toString() ); | ||
175 | } | ||
176 | |||
177 | // and put address as sub | ||
178 | QListViewItem * Sub = new QListViewItem( it ); | ||
179 | Sub->setText( 0, Keys[i].from().toString() ); | ||
180 | Sub->setText( 1, D->address().toString() ); | ||
181 | } else { | ||
182 | // nor source nor destination -> unknown | ||
183 | it->setText( 0, Keys[i].from().toString() ); | ||
184 | it->setText( 1, Keys[i].to().toString() ); | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | |||
190 | |||
191 | OTPairing::~OTPairing() { | ||
192 | if( MyIcons ) | ||
193 | delete Icons; | ||
194 | OTGateway::releaseOTGateway(); | ||
195 | } | ||
196 | |||
197 | void OTPairing::SLOT_Unpair( ) { | ||
198 | // find selected pair | ||
199 | |||
200 | QListViewItem * it = Pairs_LV->firstChild(); | ||
201 | while( it ) { | ||
202 | if( it->isSelected() ) { | ||
203 | // confirm ? | ||
204 | if( QMessageBox::warning(0, | ||
205 | tr("Break pairing"), | ||
206 | tr("Sure ?"), | ||
207 | tr("Yes, break"), | ||
208 | tr("No, don't break") ) == 0 ) { | ||
209 | LinkKeyLVI * KPIt = (LinkKeyLVI *)it; | ||
210 | // break | ||
211 | OT->removeLinkKey( KPIt->index() ); | ||
212 | delete KPIt; | ||
213 | } | ||
214 | return; | ||
215 | } | ||
216 | it= it->nextSibling(); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | // | ||
221 | // | ||
222 | // | ||
223 | // | ||
224 | // | ||
225 | |||
226 | OTScan::OTScan( QWidget * parent, OTIcons * _IC ) : | ||
227 | OTScanGUI( parent ), Filter() { | ||
228 | |||
229 | OT = OTGateway::getOTGateway(); | ||
230 | Icons = (_IC ) ? _IC : new OTIcons(); | ||
231 | MyIcons = (_IC == 0 ); | ||
232 | DetectedPeers_LV->header()->hide(); | ||
233 | Current = 0; | ||
234 | SelectedPeer = 0; | ||
235 | SelectedChannel = 0; | ||
236 | |||
237 | StrengthTimer = new QTimer( this ); | ||
238 | connect( StrengthTimer, | ||
239 | SIGNAL( timeout()), | ||
240 | this, | ||
241 | SLOT( SLOT_UpdateStrength()) | ||
242 | ); | ||
243 | |||
244 | connect( OT, | ||
245 | SIGNAL( detectedPeer( OTPeer *, bool )), | ||
246 | this, | ||
247 | SLOT( SLOT_NewPeer( OTPeer *, bool )) | ||
248 | ); | ||
249 | connect( OT, | ||
250 | SIGNAL( finishedDetecting()), | ||
251 | this, | ||
252 | SLOT( SLOT_FinishedDetecting()) | ||
253 | ); | ||
254 | |||
255 | // populate with peers we already know about | ||
256 | const PeerVector & P = OT->peers(); | ||
257 | for( unsigned int i = 0; | ||
258 | i < P.count(); | ||
259 | i ++ ) { | ||
260 | SLOT_NewPeer( P[i], TRUE ); | ||
261 | } | ||
262 | |||
263 | // populate State fram | ||
264 | { QHBoxLayout * H =new QHBoxLayout( State_Frm ); | ||
265 | |||
266 | Paired_Led = new OLedBox( green, State_Frm ); | ||
267 | QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm ); | ||
268 | |||
269 | H->addWidget( Paired_Led ); | ||
270 | H->addWidget( L1 ); | ||
271 | H->addStretch( 1 ); | ||
272 | } | ||
273 | } | ||
274 | |||
275 | OTScan::~OTScan() { | ||
276 | if( MyIcons ) | ||
277 | delete Icons; | ||
278 | OTGateway::releaseOTGateway(); | ||
279 | |||
280 | // send all peers that we do not care about states | ||
281 | QListViewItem * Lit = DetectedPeers_LV->firstChild(); | ||
282 | while( Lit ) { | ||
283 | ((PeerLVI *)Lit)->peer()->stopFindingOutState( ); | ||
284 | Lit = Lit->nextSibling(); | ||
285 | } | ||
286 | } | ||
287 | |||
288 | // static scan dialog function | ||
289 | int OTScan::getDevice( OTPeer *& Peer, | ||
290 | int & Channel, | ||
291 | OTGateway * OT, | ||
292 | const UUIDVector & Filter, | ||
293 | QWidget* Parent ) { | ||
294 | bool IsUp = 0; | ||
295 | unsigned int i; | ||
296 | |||
297 | // check if bluetooth is up | ||
298 | OTDriverList & DL = OT->getDriverList(); | ||
299 | for( i = 0; | ||
300 | i < DL.count(); | ||
301 | i ++ ) { | ||
302 | if( DL[i]->isUp() ) { | ||
303 | // one device that is up found | ||
304 | IsUp = 1; | ||
305 | break; | ||
306 | } | ||
307 | } | ||
308 | |||
309 | // use this driver | ||
310 | OT->setScanWith( OT->driver(i) ); | ||
311 | |||
312 | // create dialog | ||
313 | QDialog * Dlg = new QDialog( Parent, 0, TRUE ); | ||
314 | QVBoxLayout * V = new QVBoxLayout( Dlg ); | ||
315 | OTScan * Scn = new OTScan( Dlg ); | ||
316 | |||
317 | connect( Scn, | ||
318 | SIGNAL( selected() ), | ||
319 | Dlg, | ||
320 | SLOT( accept() ) | ||
321 | ); | ||
322 | |||
323 | if( Filter ) { | ||
324 | Scn->setScanFilter( Filter ); | ||
325 | } | ||
326 | |||
327 | V->addWidget( Scn ); | ||
328 | Dlg->setCaption( tr("Scan Neighbourhood" ) ); | ||
329 | Dlg->showMaximized(); | ||
330 | int rv = Dlg->exec(); | ||
331 | |||
332 | if( rv == QDialog::Accepted ) { | ||
333 | // get peer | ||
334 | Peer = Scn->selectedPeer(); | ||
335 | if( Peer == 0 ) { | ||
336 | // no peer selected | ||
337 | rv = QDialog::Rejected; | ||
338 | } else { | ||
339 | Channel = Scn->selectedChannel(); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | delete Dlg; | ||
344 | |||
345 | return rv; | ||
346 | } | ||
347 | |||
348 | void OTScan::setScanFilter( const UUIDVector & V ) { | ||
349 | Filter = V; | ||
350 | } | ||
351 | |||
352 | void OTScan::resetScanFilter( void ) { | ||
353 | Filter.truncate(0); | ||
354 | } | ||
355 | |||
356 | void OTScan::SLOT_DoScan( bool DoIt ) { | ||
357 | if( DoIt ) { | ||
358 | OT->scanNeighbourhood(); | ||
359 | } else { | ||
360 | OT->stopScanOfNeighbourhood(); | ||
361 | } | ||
362 | |||
363 | scanMode( DoIt ); | ||
364 | } | ||
365 | |||
366 | // double clicked on a device | ||
367 | void OTScan::SLOT_Selected( QListViewItem * it ) { | ||
368 | if( ! it ) | ||
369 | return; | ||
370 | |||
371 | if( Filter.count() > 0 ) { | ||
372 | // filter on service | ||
373 | if( it->depth() == 0 ) { | ||
374 | // select a service and not a device | ||
375 | return; | ||
376 | } | ||
377 | |||
378 | // store result | ||
379 | SelectedPeer = ((PeerLVI *)it->parent())->peer(); | ||
380 | SelectedChannel = ((ChannelLVI *)it)->channel(); | ||
381 | } else { | ||
382 | // click on device | ||
383 | if( it->depth() != 0 ) { | ||
384 | return; | ||
385 | } | ||
386 | |||
387 | SelectedPeer = ((PeerLVI *)it)->peer(); | ||
388 | SelectedChannel = 0; | ||
389 | } | ||
390 | owarn << "Selected " << SelectedPeer->address().toString() << | ||
391 | " Channel " << SelectedChannel << oendl; | ||
392 | emit selected(); | ||
393 | } | ||
394 | |||
395 | void OTScan::SLOT_FinishedDetecting( ) { | ||
396 | scanMode( false ); | ||
397 | } | ||
398 | |||
399 | void OTScan::SLOT_CleanupOld( ) { | ||
400 | |||
401 | // iterate over all peers and find those that | ||
402 | // are down and have no pairing info | ||
403 | OTPeer * TheP; | ||
404 | const LinkKeyArray & Keys = OT->getLinkKeys(); | ||
405 | |||
406 | QListViewItem * Lit = DetectedPeers_LV->firstChild(); | ||
407 | while( Lit ) { | ||
408 | TheP = ((PeerLVI *)Lit)->peer(); | ||
409 | if( TheP->state() == OTPeer::Peer_Down ) { | ||
410 | unsigned int k; | ||
411 | |||
412 | // what about linkkeys ? | ||
413 | for( k = 0; k < Keys.count(); k ++ ) { | ||
414 | if( TheP->address() == Keys[k].to() || | ||
415 | TheP->address() == Keys[k].from() | ||
416 | ) { | ||
417 | // part of linkkey | ||
418 | owarn << "LINKKEY " << TheP->address().toString() << oendl; | ||
419 | break; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | if( k == Keys.count() ) { | ||
424 | owarn << "RM LINKKEY " << TheP->address().toString() << oendl; | ||
425 | // not found -> remember to remove this peer | ||
426 | QListViewItem * Nit; | ||
427 | OT->removePeer( TheP ); | ||
428 | Nit = Lit->nextSibling(); | ||
429 | delete Lit; | ||
430 | Lit = Nit; | ||
431 | continue; | ||
432 | } | ||
433 | } else { | ||
434 | owarn << "NODOWN " << TheP->address().toString() << oendl; | ||
435 | } | ||
436 | |||
437 | Lit = Lit->nextSibling(); | ||
438 | } | ||
439 | } | ||
440 | |||
441 | void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){ | ||
442 | PeerLVI * it = 0; | ||
443 | |||
444 | if( IsNew ) { | ||
445 | it = new PeerLVI( P, DetectedPeers_LV ); | ||
446 | } else { | ||
447 | // find peer in table | ||
448 | QListViewItem * Lit = DetectedPeers_LV->firstChild(); | ||
449 | while( Lit ) { | ||
450 | if( ((PeerLVI *)Lit)->peer() == P ) { | ||
451 | // this item | ||
452 | it = (PeerLVI *)Lit; | ||
453 | break; | ||
454 | } | ||
455 | Lit = Lit->nextSibling(); | ||
456 | } | ||
457 | |||
458 | if( ! it ) { | ||
459 | owarn << "Should not occur" << oendl; | ||
460 | return; | ||
461 | } | ||
462 | } | ||
463 | |||
464 | // update/show info | ||
465 | it->setText( 0, P->name() ); | ||
466 | it->setPixmap(0, Icons->deviceIcon( | ||
467 | OT->deviceTypeToName( P->deviceClass() ) ) ); | ||
468 | |||
469 | // tell peer to report its state async | ||
470 | connect( P, | ||
471 | SIGNAL( peerStateReport( OTPeer *)), | ||
472 | this, | ||
473 | SLOT( SLOT_PeerState( OTPeer *)) | ||
474 | ); | ||
475 | |||
476 | if( IsNew ) { | ||
477 | // find state | ||
478 | refreshState( (PeerLVI *)it, 1 ); | ||
479 | } else { | ||
480 | // update staet | ||
481 | SLOT_PeerState( P ); | ||
482 | } | ||
483 | } | ||
484 | |||
485 | void OTScan::SLOT_PeerState( OTPeer * P ) { | ||
486 | PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild(); | ||
487 | while( it ) { | ||
488 | if( it->peer() == P ) { | ||
489 | break; | ||
490 | } | ||
491 | it = (PeerLVI * )it->nextSibling(); | ||
492 | } | ||
493 | |||
494 | if( ! it ) | ||
495 | return; | ||
496 | |||
497 | switch( P->state() ) { | ||
498 | case OTPeer::Peer_Unknown : | ||
499 | case OTPeer::Peer_Down : | ||
500 | it->setPixmap( 1, 0 ); | ||
501 | break; | ||
502 | case OTPeer::Peer_Up : | ||
503 | it->setPixmap( 1, Icons->loadPixmap( | ||
504 | ( P->connectedTo() ) ? "connected" : "notconnected" ) ); | ||
505 | if( it == Current && ! StrengthTimer->isActive() ) { | ||
506 | // start showing strength | ||
507 | StrengthTimer->start( 1000, FALSE ); | ||
508 | SLOT_UpdateStrength(); | ||
509 | } | ||
510 | break; | ||
511 | } | ||
512 | } | ||
513 | |||
514 | void OTScan::SLOT_RefreshState( void ) { | ||
515 | |||
516 | QListViewItem * it = DetectedPeers_LV->firstChild(); | ||
517 | while( it ) { | ||
518 | if( it->isSelected() ) { | ||
519 | break; | ||
520 | } | ||
521 | it = it->nextSibling(); | ||
522 | } | ||
523 | |||
524 | if( ! it ) | ||
525 | return; | ||
526 | |||
527 | refreshState( (PeerLVI *)it, 1 ); | ||
528 | } | ||
529 | |||
530 | void OTScan::refreshState( PeerLVI * it, bool Force ) { | ||
531 | it->setPixmap( 1, Icons->loadPixmap( "find" ) ); | ||
532 | it->peer()->findOutState( 30, Force ); | ||
533 | } | ||
534 | |||
535 | void OTScan::SLOT_Show( QListViewItem * it ) { | ||
536 | |||
537 | if( ! it || it->depth() > 0 ) | ||
538 | return; | ||
539 | |||
540 | QString S; | ||
541 | |||
542 | Current = (PeerLVI *)it; | ||
543 | |||
544 | Strength_PB->setProgress( 0 ); // reset | ||
545 | Address_LBL->setText( Current->peer()->address().toString() ); | ||
546 | Peer_GB->setTitle( Current->peer()->name() ); | ||
547 | |||
548 | const LinkKeyArray & Keys = OT->getLinkKeys(); | ||
549 | |||
550 | Paired_Led->setOn( FALSE ); | ||
551 | for( unsigned int i = 0; | ||
552 | i < Keys.count(); | ||
553 | i ++ ) { | ||
554 | if( Current->peer()->address() == Keys[i].to() ) { | ||
555 | Paired_Led->setOn( TRUE ); | ||
556 | break; | ||
557 | } | ||
558 | } | ||
559 | |||
560 | if( Current->peer()->state() == OTPeer::Peer_Up ) { | ||
561 | RefreshServices_But->setEnabled( TRUE ); | ||
562 | StrengthTimer->start( 1000, FALSE ); | ||
563 | SLOT_UpdateStrength(); | ||
564 | } else { | ||
565 | RefreshServices_But->setEnabled( FALSE ); | ||
566 | } | ||
567 | |||
568 | } | ||
569 | |||
570 | void OTScan::SLOT_UpdateStrength( void ) { | ||
571 | OTDriver * D = Current->peer()->connectedTo(); | ||
572 | |||
573 | if( D ) { | ||
574 | long Q = D->getLinkQuality( Current->peer()->address() ); | ||
575 | Strength_PB->setProgress( Q ); | ||
576 | if( ! Q ) { | ||
577 | // no quality | ||
578 | Strength_PB->setEnabled( TRUE ); | ||
579 | StrengthTimer->stop(); | ||
580 | } | ||
581 | } else { | ||
582 | Strength_PB->setEnabled( FALSE ); | ||
583 | Strength_PB->setProgress( 0 ); | ||
584 | // no point in continuing | ||
585 | StrengthTimer->stop(); | ||
586 | } | ||
587 | } | ||
588 | |||
589 | void OTScan::SLOT_RefreshServices( void ) { | ||
590 | |||
591 | QListViewItem * it = DetectedPeers_LV->firstChild(); | ||
592 | while( it ) { | ||
593 | if( it->isSelected() ) { | ||
594 | break; | ||
595 | } | ||
596 | it = it->nextSibling(); | ||
597 | } | ||
598 | |||
599 | if( ! it ) | ||
600 | return; | ||
601 | |||
602 | QString S; | ||
603 | PeerLVI * PI = (PeerLVI *)it; | ||
604 | |||
605 | scanMode( true ); | ||
606 | qApp->processEvents(0); | ||
607 | |||
608 | ServiceVector & V = PI->peer()->services(); | ||
609 | |||
610 | while( PI->firstChild() ) { | ||
611 | // remove children | ||
612 | delete PI->firstChild(); | ||
613 | } | ||
614 | |||
615 | for( unsigned int i = 0 ; | ||
616 | i < V.count(); | ||
617 | i ++ ) { | ||
618 | QString S; | ||
619 | S = V[i]->name(); | ||
620 | |||
621 | if( S.isEmpty() ) { | ||
622 | continue; | ||
623 | } | ||
624 | |||
625 | { QListViewItem * SIt; | ||
626 | UUIDVector UIDV; | ||
627 | QPixmap Pm; | ||
628 | bool Done = 0; | ||
629 | bool R; | ||
630 | short ID; | ||
631 | |||
632 | SIt = 0; | ||
633 | |||
634 | UIDV = V[i]->classIDList(); | ||
635 | // first all UUID ! 1200 12ff (Genericprofiles) | ||
636 | for( unsigned int j = 0; | ||
637 | j < UIDV.count(); | ||
638 | j ++ ) { | ||
639 | |||
640 | if( Filter.count() ) { | ||
641 | bool FilterOut = 1; | ||
642 | // filter out if not in list | ||
643 | for( unsigned int ff = 0; | ||
644 | ff < Filter.count(); | ||
645 | ff ++ ) { | ||
646 | if( UIDV[j] == Filter[ff] ) { | ||
647 | FilterOut = 0; | ||
648 | break; | ||
649 | } | ||
650 | } | ||
651 | |||
652 | if( FilterOut ) { | ||
653 | // not in filter list | ||
654 | continue; | ||
655 | } | ||
656 | } // else show | ||
657 | |||
658 | ID = UIDV[j].toShort(); | ||
659 | if( ID < 0x1200 || ID > 0x12ff ) { | ||
660 | // use this profile | ||
661 | if( R ) { | ||
662 | unsigned int ch; | ||
663 | bool has; | ||
664 | has = V[i]->rfcommChannel( ch ); | ||
665 | SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); | ||
666 | SIt->setText(0, V[i]->name() ); | ||
667 | |||
668 | Pm = Icons->serviceIcon( ID, R ); | ||
669 | SIt->setPixmap(0, Pm ); | ||
670 | Done = 1; | ||
671 | break; | ||
672 | } | ||
673 | } | ||
674 | } | ||
675 | |||
676 | if( ! Done ) { | ||
677 | // check other range too | ||
678 | for( unsigned int j = 0; | ||
679 | j < UIDV.count(); | ||
680 | j ++ ) { | ||
681 | |||
682 | if( Filter.count() ) { | ||
683 | bool FilterOut = 1; | ||
684 | // filter out if not in list | ||
685 | for( unsigned int ff = 0; | ||
686 | ff < Filter.count(); | ||
687 | ff ++ ) { | ||
688 | if( UIDV[j] == Filter[ff] ) { | ||
689 | FilterOut = 0; | ||
690 | break; | ||
691 | } | ||
692 | } | ||
693 | |||
694 | if( FilterOut ) { | ||
695 | // not in filter list | ||
696 | continue; | ||
697 | } | ||
698 | } // else show | ||
699 | |||
700 | ID = UIDV[j].toShort(); | ||
701 | if( ID >= 0x1200 && ID <= 0x12ff ) { | ||
702 | // use this profile | ||
703 | unsigned int ch; | ||
704 | bool has; | ||
705 | has = V[i]->rfcommChannel( ch ); | ||
706 | SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI ); | ||
707 | SIt->setText(0, V[i]->name() ); | ||
708 | |||
709 | Pm = Icons->serviceIcon( ID, R ); | ||
710 | SIt->setPixmap(0, Pm ); | ||
711 | |||
712 | break; | ||
713 | } | ||
714 | } | ||
715 | } | ||
716 | |||
717 | } | ||
718 | } | ||
719 | |||
720 | scanMode( false ); | ||
721 | } | ||
722 | |||
723 | void OTScan::scanMode( bool M ) { | ||
724 | // avoid infinite loop because it triggers DoScan | ||
725 | Detect_But->blockSignals( TRUE ); | ||
726 | Detect_But->setOn( M ); | ||
727 | Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") ); | ||
728 | Detect_But->blockSignals( FALSE ); | ||
729 | } | ||
730 | |||
731 | // | ||
732 | // | ||
733 | // | ||
734 | // | ||
735 | // | ||
736 | |||
737 | OTManage::OTManage( QWidget * parent, OTIcons * _IC ) : | ||
738 | OTManageGUI( parent ) { | ||
739 | |||
740 | OT = OTGateway::getOTGateway(); | ||
741 | |||
742 | Icons = (_IC ) ? _IC : new OTIcons(); | ||
743 | MyIcons = (_IC == 0 ); | ||
744 | AllDrivers_LV->setSorting(-1); | ||
745 | |||
746 | connect( OT, | ||
747 | SIGNAL( driverListChanged() ), | ||
748 | this, | ||
749 | SLOT( SLOT_DriverListChanged() ) | ||
750 | ); | ||
751 | connect( OT, | ||
752 | SIGNAL( stateChange( OTDriver *, bool ) ), | ||
753 | this, | ||
754 | SLOT( SLOT_StateChange( OTDriver *, bool ) ) | ||
755 | ); | ||
756 | |||
757 | SLOT_DriverListChanged(); | ||
758 | |||
759 | AllDrivers_LV->header()->hide(); | ||
760 | } | ||
761 | |||
762 | OTManage::~OTManage() { | ||
763 | if( MyIcons ) | ||
764 | delete Icons; | ||
765 | OTGateway::releaseOTGateway(); | ||
766 | } | ||
767 | |||
768 | void OTManage::SLOT_ShowDriver( QListViewItem * It ) { | ||
769 | if( It == 0 || It->depth() > 0 ) | ||
770 | // not toplevel | ||
771 | return; | ||
772 | |||
773 | DriverLVI * it = (DriverLVI *) It; | ||
774 | DriverIsUp_CB->setChecked( it->driver()->isUp() ); | ||
775 | } | ||
776 | |||
777 | void OTManage::SLOT_UpDriver( bool Up ) { | ||
778 | QListViewItem * it = AllDrivers_LV->firstChild(); | ||
779 | while( it ) { | ||
780 | if( it->isSelected() ) { | ||
781 | OTDriver * D = ((DriverLVI *)it)->driver(); | ||
782 | owarn << "UP driver " << D->devname() << oendl; | ||
783 | // this | ||
784 | D->setUp( Up ); | ||
785 | return; | ||
786 | } | ||
787 | it = it->nextSibling(); | ||
788 | } | ||
789 | } | ||
790 | |||
791 | void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) { | ||
792 | QListViewItem * it = AllDrivers_LV->firstChild(); | ||
793 | while( it ) { | ||
794 | if( ((DriverLVI *)it)->driver() == D ) { | ||
795 | it->setPixmap( 0, | ||
796 | Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) ); | ||
797 | return; | ||
798 | } | ||
799 | it = it->nextSibling(); | ||
800 | } | ||
801 | } | ||
802 | |||
803 | void OTManage::SLOT_DriverListChanged( ) { | ||
804 | DriverLVI * It; | ||
805 | QListViewItem * Sub; | ||
806 | QListViewItem * First = 0; | ||
807 | OTDriver* D; | ||
808 | OTDriverList & DL = OT->getDriverList(); | ||
809 | |||
810 | AllDrivers_LV->clear(); | ||
811 | for( unsigned int i = 0; | ||
812 | i < DL.count(); | ||
813 | i ++ ) { | ||
814 | D = DL[i]; | ||
815 | It = new DriverLVI( D, AllDrivers_LV ); | ||
816 | |||
817 | if( ! First ) | ||
818 | First = It; | ||
819 | |||
820 | It->setText( 0, D->devname() ); | ||
821 | It->setPixmap( 0, | ||
822 | Icons->loadPixmap( (D->isUp()) ? | ||
823 | "bluezon" : "bluezoff" ) ); | ||
824 | |||
825 | Sub = new QListViewItem( It ); | ||
826 | Sub->setText( 0, tr( "Name" ) ); | ||
827 | Sub->setText( 1, D->name() ); | ||
828 | |||
829 | Sub = new QListViewItem( It ); | ||
830 | Sub->setText( 0, tr( "Address" ) ); | ||
831 | Sub->setText( 1, D->address().toString() ); | ||
832 | |||
833 | Sub = new QListViewItem( It ); | ||
834 | Sub->setText( 0, tr( "Revision" ) ); | ||
835 | Sub->setText( 1, D->revision() ); | ||
836 | |||
837 | Sub = new QListViewItem( It ); | ||
838 | Sub->setText( 0, tr( "Manufacturer" ) ); | ||
839 | Sub->setText( 1, D->manufacturer() ); | ||
840 | |||
841 | QString Service, Device; | ||
842 | D->getClass( Service, Device ); | ||
843 | |||
844 | Sub = new QListViewItem( It ); | ||
845 | Sub->setText( 0, tr( "Service classes" ) ); | ||
846 | Sub->setText( 1, Service ); | ||
847 | Sub = new QListViewItem( It ); | ||
848 | Sub->setText( 0, tr( "Device class" ) ); | ||
849 | Sub->setText( 1, Device ); | ||
850 | } | ||
851 | |||
852 | if( DL.count() ) { | ||
853 | AllDrivers_LV->setCurrentItem( First ); | ||
854 | DriverIsUp_CB->setEnabled( TRUE ); | ||
855 | } else { | ||
856 | DriverIsUp_CB->setChecked( FALSE ); | ||
857 | DriverIsUp_CB->setEnabled( FALSE ); | ||
858 | } | ||
859 | } | ||
860 | |||
861 | void OTManage::SLOT_SetRefreshTimer( int v ) { | ||
862 | OT->setRefreshTimer( v * 1000 ); | ||
863 | } | ||
864 | |||
865 | // | ||
866 | // | ||
867 | // | ||
868 | // | ||
869 | // | ||
870 | |||
871 | OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) { | ||
872 | |||
873 | Icons = new OTIcons(); | ||
874 | OT = OTGateway::getOTGateway(); | ||
875 | |||
876 | connect( OT, | ||
877 | SIGNAL( deviceEnabled( bool ) ), | ||
878 | this, | ||
879 | SLOT( SLOT_DeviceIsEnabled( bool ) ) | ||
880 | ); | ||
881 | connect( OT, | ||
882 | SIGNAL( driverListChanged() ), | ||
883 | this, | ||
884 | SLOT( SLOT_DriverListChanged() ) | ||
885 | ); | ||
886 | connect( OT, | ||
887 | SIGNAL( stateChange( OTDriver *, bool ) ), | ||
888 | this, | ||
889 | SLOT( SLOT_StateChange( OTDriver *, bool ) ) | ||
890 | ); | ||
891 | |||
892 | if( ! OT->needsEnabling() ) { | ||
893 | MustBeEnabled_CB->hide(); | ||
894 | } else { | ||
895 | // detect current state | ||
896 | MustBeEnabled_CB->setChecked( | ||
897 | OT->isEnabled() ); | ||
898 | } | ||
899 | |||
900 | SLOT_DriverListChanged(); | ||
901 | } | ||
902 | |||
903 | OTMain::~OTMain() { | ||
904 | OTGateway::releaseOTGateway(); | ||
905 | delete Icons; | ||
906 | } | ||
907 | |||
908 | void OTMain::SLOT_DriverListChanged() { | ||
909 | OTDriver * D; | ||
910 | OTDriverList & DL = OT->getDriverList(); | ||
911 | |||
912 | DeviceList_CB->clear(); | ||
913 | for( unsigned int i = 0; | ||
914 | i < DL.count(); | ||
915 | i ++ ) { | ||
916 | D = DL[i]; | ||
917 | DeviceList_CB->insertItem( | ||
918 | Icons->loadPixmap( (D->isUp()) ? | ||
919 | "bluezon" : "bluezoff" ), | ||
920 | D->devname() ); | ||
921 | if( D == OT->scanWith() ) { | ||
922 | DeviceList_CB->setCurrentItem( i ); | ||
923 | } | ||
924 | } | ||
925 | |||
926 | Scan_But->setEnabled( OT->getDriverList().count() > 0 ); | ||
927 | DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 ); | ||
928 | } | ||
929 | |||
930 | void OTMain::SLOT_EnableBluetooth( bool Up ) { | ||
931 | OT->SLOT_SetEnabled( Up ); | ||
932 | } | ||
933 | |||
934 | void OTMain::SLOT_DeviceIsEnabled( bool Up ) { | ||
935 | MustBeEnabled_CB->blockSignals( TRUE ); | ||
936 | MustBeEnabled_CB->setChecked( Up ); | ||
937 | MustBeEnabled_CB->blockSignals( FALSE ); | ||
938 | } | ||
939 | |||
940 | void OTMain::SLOT_Manage( void ) { | ||
941 | QDialog * Dlg = new QDialog( this, 0, TRUE ); | ||
942 | QVBoxLayout * V = new QVBoxLayout( Dlg ); | ||
943 | OTManage * Mng = new OTManage( Dlg, Icons ); | ||
944 | |||
945 | V->addWidget( Mng ); | ||
946 | |||
947 | Dlg->setCaption( tr("Manage local devices" ) ); | ||
948 | Dlg->showMaximized(); | ||
949 | Dlg->exec(); | ||
950 | delete Dlg; | ||
951 | } | ||
952 | |||
953 | void OTMain::SLOT_Scan( void ) { | ||
954 | OTDriverList & DL = OT->getDriverList(); | ||
955 | for( unsigned int i = 0; | ||
956 | i < DL.count(); | ||
957 | i ++ ) { | ||
958 | if( DL[i]->isUp() && | ||
959 | DL[i]->devname() == DeviceList_CB->currentText() | ||
960 | ) { | ||
961 | QDialog * Dlg = new QDialog( this, 0, TRUE ); | ||
962 | QVBoxLayout * V = new QVBoxLayout( Dlg ); | ||
963 | OTScan * Scn = new OTScan( Dlg, Icons ); | ||
964 | |||
965 | OT->setScanWith( OT->driver(i) ); | ||
966 | V->addWidget( Scn ); | ||
967 | Dlg->setCaption( tr("Scan Neighbourhood" ) ); | ||
968 | Dlg->showMaximized(); | ||
969 | Dlg->exec(); | ||
970 | |||
971 | delete Dlg; | ||
972 | return; | ||
973 | } | ||
974 | } | ||
975 | |||
976 | } | ||
977 | |||
978 | void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) { | ||
979 | for( int i = 0; | ||
980 | i < DeviceList_CB->count(); | ||
981 | i ++ ) { | ||
982 | if( DeviceList_CB->text(i) == D->devname() ) { | ||
983 | DeviceList_CB->changeItem( | ||
984 | Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ), | ||
985 | D->devname(), | ||
986 | i ); | ||
987 | return; | ||
988 | } | ||
989 | } | ||
990 | } | ||
991 | |||
992 | void OTMain::SLOT_Pairing( void ) { | ||
993 | QDialog * Dlg = new QDialog( this, 0, TRUE ); | ||
994 | QVBoxLayout * V = new QVBoxLayout( Dlg ); | ||
995 | OTPairing * Pair = new OTPairing( Dlg, Icons ); | ||
996 | |||
997 | V->addWidget( Pair ); | ||
998 | Dlg->showMaximized(); | ||
999 | Dlg->setCaption( tr("Manage pairing" ) ); | ||
1000 | Dlg->exec(); | ||
1001 | |||
1002 | delete Dlg; | ||
1003 | } | ||