00001 #include <opie2/odebug.h>
00002 #include <opie2/oledbox.h>
00003 #include <opie2/ofiledialog.h>
00004
00005 using namespace Opie::Core;
00006 using namespace Opie::Ui;
00007
00008 #include <qpe/resource.h>
00009 #include <qapplication.h>
00010 #include <qcheckbox.h>
00011 #include <qcombobox.h>
00012 #include <qdialog.h>
00013 #include <qdir.h>
00014 #include <qfile.h>
00015 #include <qgroupbox.h>
00016 #include <qheader.h>
00017 #include <qlabel.h>
00018 #include <qlayout.h>
00019 #include <qlistbox.h>
00020 #include <qlistview.h>
00021 #include <qmessagebox.h>
00022 #include <qprogressbar.h>
00023 #include <qpushbutton.h>
00024 #include <qscrollbar.h>
00025 #include <qtextstream.h>
00026 #include <qtextview.h>
00027
00028 #include <Opietooth.h>
00029 #include <OTDriver.h>
00030 #include <OTPeer.h>
00031 #include <OTGateway.h>
00032 #include <OTSDPAttribute.h>
00033 #include <OTSDPService.h>
00034 #include <OTInquiry.h>
00035
00036 #include <system.h>
00037
00038 using namespace Opietooth2;
00039
00040 namespace Opietooth2 {
00041
00042 class PeerLVI : public QListViewItem {
00043
00044 public :
00045
00046 PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) {
00047 Peer = P;
00048 }
00049 ~PeerLVI( void ) {
00050 }
00051
00052 inline OTPeer * peer( void )
00053 { return Peer; }
00054
00055 private :
00056
00057 OTPeer * Peer;
00058 };
00059
00060 class ChannelLVI : public QListViewItem {
00061
00062 public :
00063
00064 ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) {
00065 Channel = Ch;
00066 }
00067 ~ChannelLVI( void ) {
00068 }
00069
00070 inline int channel( void )
00071 { return Channel; }
00072
00073 private :
00074
00075 int Channel;
00076 };
00077
00078 class DriverLVI : public QListViewItem {
00079
00080 public :
00081
00082 DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) {
00083 Driver = P;
00084 }
00085 ~DriverLVI( void ) {
00086 }
00087
00088 inline OTDriver * driver( void )
00089 { return Driver; }
00090
00091 private :
00092
00093 OTDriver * Driver;
00094 };
00095
00096 class LinkKeyLVI : public QListViewItem {
00097
00098 public :
00099
00100 LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) {
00101 LinkKey = Ch;
00102 }
00103 ~LinkKeyLVI( void ) {
00104 }
00105
00106 inline int index( void )
00107 { return LinkKey; }
00108
00109 private :
00110
00111 int LinkKey;
00112 };
00113 };
00114
00115
00116
00117
00118
00119
00120
00121 OTSniffing::OTSniffing( QWidget * parent ) : OTSniffGUI( parent ) {
00122
00123 OT = OTGateway::getOTGateway();
00124 HciDump = 0;
00125 }
00126
00127 OTSniffing::~OTSniffing() {
00128 SLOT_Trace( 0 );
00129 }
00130
00131 void OTSniffing::SLOT_Trace( bool Run ) {
00132
00133 if( ! Run ) {
00134 if ( HciDump ) {
00135 HciDump->process().kill();
00136 delete HciDump;
00137 }
00138 HciDump = 0;
00139 return;
00140 }
00141
00142 HciDump = new MyProcess();
00143 QStringList SL;
00144
00145 SL << "/usr/sbin/hcidump";
00146 switch( DataFormat_CB->currentItem() ) {
00147 case 0 :
00148 SL << "-x";
00149 break;
00150 case 1 :
00151 SL << "-a";
00152 break;
00153 case 2 :
00154 SL << "-X";
00155 break;
00156 }
00157
00158 SL << "-i";
00159 SL << OT->scanWith()->devname();
00160
00161 connect( HciDump,
00162 SIGNAL( stdoutLine( const QString & ) ),
00163 this,
00164 SLOT( SLOT_Show( const QString & ) ) );
00165
00166 connect( HciDump,
00167 SIGNAL(processExited(MyProcess*) ),
00168 this,
00169 SLOT( SLOT_ProcessExited(MyProcess*) ) );
00170
00171 HciDump->process() << SL;
00172
00173 if( ! HciDump->process().start( OProcess::DontCare,
00174 OProcess::AllOutput )
00175 ) {
00176 QMessageBox::warning(0,
00177 tr("Run hcidump"),
00178 tr("Cannot start %1").arg(SL.join(" "))
00179 );
00180 delete HciDump;
00181 HciDump = 0;
00182 }
00183
00184 }
00185
00186 void OTSniffing::SLOT_Show( const QString & S ) {
00187 Output_TV->setText( Output_TV->text() + S + "\n" );
00188
00189 QScrollBar *scroll = Output_TV->verticalScrollBar();
00190 scroll->setValue(scroll->maxValue());
00191
00192
00193
00194 }
00195
00196 void OTSniffing::SLOT_ProcessExited( MyProcess * ) {
00197 printf( "Exited\n" );
00198 delete HciDump;
00199 HciDump = 0;
00200 }
00201
00202 void OTSniffing::SLOT_Save( void ) {
00203 QString S = OFileDialog::getSaveFileName(
00204 OFileSelector::Extended,
00205 QDir::home().path(),
00206 QString::null,
00207 MimeTypes(),
00208 this );
00209
00210 if( ! S.isEmpty() ) {
00211 QFile F( S );
00212 if( ! F.open( IO_WriteOnly ) ) {
00213 QMessageBox::warning(0,
00214 tr("Save log"),
00215 tr("Cannot open %1").arg(S)
00216 );
00217 return;
00218 }
00219 QTextStream TS( &F );
00220 TS << S << endl;
00221 }
00222 }
00223
00224 void OTSniffing::SLOT_Load( void ) {
00225 QString S = OFileDialog::getOpenFileName(
00226 OFileSelector::Extended,
00227 QDir::home().path(),
00228 QString::null,
00229 MimeTypes(),
00230 this );
00231
00232 if( ! S.isEmpty() ) {
00233 QFile F( S );
00234 if( ! F.open( IO_ReadOnly ) ) {
00235 QMessageBox::warning(0,
00236 tr("Save log"),
00237 tr("Cannot open %1").arg(S)
00238 );
00239 return;
00240 }
00241 QTextStream TS ( &F );
00242 SLOT_ClearLog();
00243 S = TS.read();
00244
00245 Output_TV->setText( S );
00246 }
00247 }
00248
00249 void OTSniffing::SLOT_ClearLog( void ) {
00250
00251 Output_TV->setText( "" );
00252 }
00253
00254
00255
00256
00257
00258
00259
00260 OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) :
00261 OTPairingGUI( parent ) {
00262
00263 OT = OTGateway::getOTGateway();
00264 Icons = (_IC ) ? _IC : new OTIcons();
00265 MyIcons = (_IC == 0 );
00266
00267
00268 Unpair_But->setEnabled( ! OT->isEnabled() );
00269 if( ! OT->isEnabled() ) {
00270 Unpair_LBL->hide();
00271 } else {
00272 Unpair_LBL->show();
00273 }
00274
00275
00276 LinkKeyArray Keys = OT->getLinkKeys();
00277 LinkKeyLVI * it;
00278 OTPeer * P;
00279 OTDriver * D;
00280
00281 for( unsigned int i = 0 ;
00282 i < Keys.count();
00283 i ++ ) {
00284
00285 it = new LinkKeyLVI( i, Pairs_LV );
00286
00287 P = 0;
00288 D = OT->findDriver( Keys[i].from() );
00289
00290 if( D ) {
00291 it->setText( 0, D->devname() );
00292
00293
00294 P = OT->findPeer( Keys[i].to() );
00295
00296 if( P ) {
00297
00298 it->setText( 1, P->name() );
00299 } else {
00300
00301 it->setText( 1, Keys[i].to().toString() );
00302 }
00303
00304
00305 QListViewItem * Sub = new QListViewItem( it );
00306 Sub->setText( 0, D->address().toString() );
00307 Sub->setText( 1, Keys[i].to().toString() );
00308 } else {
00309
00310 D = OT->findDriver( Keys[i].to() );
00311
00312 if( D ) {
00313 it->setText( 1, D->devname() );
00314
00315
00316 P = OT->findPeer( Keys[i].from() );
00317
00318 if( P ) {
00319
00320 it->setText( 0, P->name() );
00321 } else {
00322
00323 it->setText( 0, Keys[i].from().toString() );
00324 }
00325
00326
00327 QListViewItem * Sub = new QListViewItem( it );
00328 Sub->setText( 0, Keys[i].from().toString() );
00329 Sub->setText( 1, D->address().toString() );
00330 } else {
00331
00332 it->setText( 0, Keys[i].from().toString() );
00333 it->setText( 1, Keys[i].to().toString() );
00334 }
00335 }
00336 }
00337 }
00338
00339
00340 OTPairing::~OTPairing() {
00341 if( MyIcons )
00342 delete Icons;
00343 OTGateway::releaseOTGateway();
00344 }
00345
00346 void OTPairing::SLOT_Unpair( ) {
00347
00348
00349 QListViewItem * it = Pairs_LV->firstChild();
00350 while( it ) {
00351 if( it->isSelected() ) {
00352
00353 if( QMessageBox::warning(0,
00354 tr("Break pairing"),
00355 tr("Sure ?"),
00356 tr("Yes, break"),
00357 tr("No, don't break") ) == 0 ) {
00358 LinkKeyLVI * KPIt = (LinkKeyLVI *)it;
00359
00360 OT->removeLinkKey( KPIt->index() );
00361 delete KPIt;
00362 }
00363 return;
00364 }
00365 it= it->nextSibling();
00366 }
00367 }
00368
00369
00370
00371
00372
00373
00374
00375 OTScan::OTScan( QWidget * parent, OTIcons * _IC ) :
00376 OTScanGUI( parent ), Filter() {
00377
00378 OT = OTGateway::getOTGateway();
00379
00380 Icons = (_IC ) ? _IC : new OTIcons();
00381 MyIcons = (_IC == 0 );
00382 DetectedPeers_LV->header()->hide();
00383 Current = 0;
00384 SelectedPeer = 0;
00385 SelectedChannel = 0;
00386
00387 StrengthTimer = new QTimer( this );
00388 connect( StrengthTimer,
00389 SIGNAL( timeout()),
00390 this,
00391 SLOT( SLOT_UpdateStrength())
00392 );
00393
00394 connect( OT,
00395 SIGNAL( detectedPeer( OTPeer *, bool )),
00396 this,
00397 SLOT( SLOT_NewPeer( OTPeer *, bool ))
00398 );
00399 connect( OT,
00400 SIGNAL( finishedDetecting()),
00401 this,
00402 SLOT( SLOT_FinishedDetecting())
00403 );
00404
00405
00406 const PeerVector & P = OT->peers();
00407 for( unsigned int i = 0;
00408 i < P.count();
00409 i ++ ) {
00410 SLOT_NewPeer( P[i], TRUE );
00411 }
00412
00413
00414 { QHBoxLayout * H =new QHBoxLayout( State_Frm );
00415
00416 Paired_Led = new OLedBox( green, State_Frm );
00417 QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm );
00418
00419 H->addWidget( Paired_Led );
00420 H->addWidget( L1 );
00421 H->addStretch( 1 );
00422 }
00423 }
00424
00425 OTScan::~OTScan() {
00426 if( MyIcons )
00427 delete Icons;
00428 OTGateway::releaseOTGateway();
00429
00430
00431 QListViewItem * Lit = DetectedPeers_LV->firstChild();
00432 while( Lit ) {
00433 ((PeerLVI *)Lit)->peer()->stopFindingOutState( );
00434 Lit = Lit->nextSibling();
00435 }
00436 }
00437
00438
00439 int OTScan::getDevice( OTPeer *& Peer,
00440 int & Channel,
00441 OTGateway * OT,
00442 const UUIDVector & Filter,
00443 QWidget* Parent ) {
00444 bool IsUp = 0;
00445 unsigned int i;
00446
00447 if( ! OT->isEnabled() ) {
00448 QMessageBox::warning( 0,
00449 tr("Scanning problem"),
00450 tr("Bluetooth not enabled" )
00451 );
00452 return QDialog::Rejected;
00453 }
00454
00455
00456 OTDriverList & DL = OT->getDriverList();
00457 for( i = 0;
00458 i < DL.count();
00459 i ++ ) {
00460 if( DL[i]->isUp() ) {
00461
00462 IsUp = 1;
00463 break;
00464 }
00465 }
00466
00467
00468 OT->setScanWith( OT->driver(i) );
00469
00470
00471 QDialog * Dlg = new QDialog( Parent, 0, TRUE );
00472 QVBoxLayout * V = new QVBoxLayout( Dlg );
00473 OTScan * Scn = new OTScan( Dlg );
00474
00475 connect( Scn,
00476 SIGNAL( selected() ),
00477 Dlg,
00478 SLOT( accept() )
00479 );
00480
00481 if( Filter ) {
00482 Scn->setScanFilter( Filter );
00483 }
00484
00485 V->addWidget( Scn );
00486 Dlg->setCaption( tr("Scan Neighbourhood" ) );
00487 Dlg->showMaximized();
00488 int rv = Dlg->exec();
00489
00490 if( rv == QDialog::Accepted ) {
00491
00492 Peer = Scn->selectedPeer();
00493 if( Peer == 0 ) {
00494
00495 rv = QDialog::Rejected;
00496 } else {
00497 Channel = Scn->selectedChannel();
00498 }
00499 }
00500
00501 delete Dlg;
00502
00503 return rv;
00504 }
00505
00506 void OTScan::setScanFilter( const UUIDVector & V ) {
00507 Filter = V;
00508 }
00509
00510 void OTScan::resetScanFilter( void ) {
00511 Filter.truncate(0);
00512 }
00513
00514 void OTScan::SLOT_DoScan( bool DoIt ) {
00515 if( DoIt ) {
00516 OT->scanNeighbourhood();
00517 } else {
00518 OT->stopScanOfNeighbourhood();
00519 }
00520
00521 scanMode( DoIt );
00522 }
00523
00524
00525 void OTScan::SLOT_Selected( QListViewItem * it ) {
00526 if( ! it )
00527 return;
00528
00529 if( Filter.count() > 0 ) {
00530
00531 if( it->depth() == 0 ) {
00532
00533 return;
00534 }
00535
00536
00537 SelectedPeer = ((PeerLVI *)it->parent())->peer();
00538 SelectedChannel = ((ChannelLVI *)it)->channel();
00539 } else {
00540
00541 if( it->depth() != 0 ) {
00542 return;
00543 }
00544
00545 SelectedPeer = ((PeerLVI *)it)->peer();
00546 SelectedChannel = 0;
00547 }
00548 odebug << "Selected " << SelectedPeer->address().toString() <<
00549 " Channel " << SelectedChannel << oendl;
00550 emit selected();
00551 }
00552
00553 void OTScan::SLOT_FinishedDetecting( ) {
00554 scanMode( false );
00555 }
00556
00557 void OTScan::SLOT_CleanupOld( ) {
00558
00559
00560
00561 OTPeer * TheP;
00562 const LinkKeyArray & Keys = OT->getLinkKeys();
00563
00564 QListViewItem * Lit = DetectedPeers_LV->firstChild();
00565 while( Lit ) {
00566 TheP = ((PeerLVI *)Lit)->peer();
00567 if( TheP->state() == OTPeer::Peer_Down ) {
00568 unsigned int k;
00569
00570
00571 for( k = 0; k < Keys.count(); k ++ ) {
00572 if( TheP->address() == Keys[k].to() ||
00573 TheP->address() == Keys[k].from()
00574 ) {
00575
00576 odebug << "LINKKEY " << TheP->address().toString() << oendl;
00577 break;
00578 }
00579 }
00580
00581 if( k == Keys.count() ) {
00582 odebug << "RM LINKKEY " << TheP->address().toString() << oendl;
00583
00584 QListViewItem * Nit;
00585 OT->removePeer( TheP );
00586 Nit = Lit->nextSibling();
00587 delete Lit;
00588 Lit = Nit;
00589 continue;
00590 }
00591 } else {
00592 odebug << "NODOWN " << TheP->address().toString() << oendl;
00593 }
00594
00595 Lit = Lit->nextSibling();
00596 }
00597 }
00598
00599 void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){
00600 PeerLVI * it = 0;
00601
00602 if( IsNew ) {
00603 it = new PeerLVI( P, DetectedPeers_LV );
00604 } else {
00605
00606 QListViewItem * Lit = DetectedPeers_LV->firstChild();
00607 while( Lit ) {
00608 if( ((PeerLVI *)Lit)->peer() == P ) {
00609
00610 it = (PeerLVI *)Lit;
00611 break;
00612 }
00613 Lit = Lit->nextSibling();
00614 }
00615
00616 if( ! it ) {
00617 odebug << "Should not occur" << oendl;
00618 return;
00619 }
00620 }
00621
00622
00623 it->setText( 0, P->name() );
00624 it->setPixmap(0, Icons->deviceIcon(
00625 OT->deviceTypeToName( P->deviceClass() ) ) );
00626
00627
00628 connect( P,
00629 SIGNAL( peerStateReport( OTPeer *)),
00630 this,
00631 SLOT( SLOT_PeerState( OTPeer *))
00632 );
00633
00634 if( IsNew ) {
00635
00636 refreshState( (PeerLVI *)it, 1 );
00637 } else {
00638
00639 SLOT_PeerState( P );
00640 }
00641 }
00642
00643 void OTScan::SLOT_PeerState( OTPeer * P ) {
00644 PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild();
00645 while( it ) {
00646 if( it->peer() == P ) {
00647 break;
00648 }
00649 it = (PeerLVI * )it->nextSibling();
00650 }
00651
00652 if( ! it )
00653 return;
00654
00655 switch( P->state() ) {
00656 case OTPeer::Peer_Unknown :
00657 case OTPeer::Peer_Down :
00658 it->setPixmap( 1, 0 );
00659 break;
00660 case OTPeer::Peer_Up :
00661 it->setPixmap( 1, Icons->loadPixmap(
00662 ( P->connectedTo() ) ? "connected" : "notconnected" ) );
00663 if( it == Current && ! StrengthTimer->isActive() ) {
00664
00665 StrengthTimer->start( 1000, FALSE );
00666 SLOT_UpdateStrength();
00667 }
00668 break;
00669 }
00670 }
00671
00672 void OTScan::SLOT_RefreshState( void ) {
00673
00674 QListViewItem * it = DetectedPeers_LV->firstChild();
00675 while( it ) {
00676 if( it->isSelected() ) {
00677 break;
00678 }
00679 it = it->nextSibling();
00680 }
00681
00682 if( ! it )
00683 return;
00684
00685 refreshState( (PeerLVI *)it, 1 );
00686 }
00687
00688 void OTScan::refreshState( PeerLVI * it, bool Force ) {
00689 it->setPixmap( 1, Icons->loadPixmap( "find" ) );
00690 it->peer()->findOutState( 30, Force );
00691 }
00692
00693 void OTScan::SLOT_Show( QListViewItem * it ) {
00694
00695 if( ! it || it->depth() > 0 )
00696 return;
00697
00698 QString S;
00699
00700 Current = (PeerLVI *)it;
00701
00702 Strength_PB->setProgress( 0 );
00703 Address_LBL->setText( Current->peer()->address().toString() );
00704 Peer_GB->setTitle( Current->peer()->name() );
00705
00706 const LinkKeyArray & Keys = OT->getLinkKeys();
00707
00708 Paired_Led->setOn( FALSE );
00709 for( unsigned int i = 0;
00710 i < Keys.count();
00711 i ++ ) {
00712 if( Current->peer()->address() == Keys[i].to() ) {
00713 Paired_Led->setOn( TRUE );
00714 break;
00715 }
00716 }
00717
00718 if( Current->peer()->state() == OTPeer::Peer_Up ) {
00719 RefreshServices_But->setEnabled( TRUE );
00720 StrengthTimer->start( 1000, FALSE );
00721 SLOT_UpdateStrength();
00722 } else {
00723 RefreshServices_But->setEnabled( FALSE );
00724 }
00725
00726 }
00727
00728 void OTScan::SLOT_UpdateStrength( void ) {
00729 OTDriver * D = Current->peer()->connectedTo();
00730
00731 if( D ) {
00732 long Q = D->getLinkQuality( Current->peer()->address() );
00733 Strength_PB->setProgress( Q );
00734 if( ! Q ) {
00735
00736 Strength_PB->setEnabled( TRUE );
00737 StrengthTimer->stop();
00738 }
00739 } else {
00740 Strength_PB->setEnabled( FALSE );
00741 Strength_PB->setProgress( 0 );
00742
00743 StrengthTimer->stop();
00744 }
00745 }
00746
00747 void OTScan::SLOT_RefreshServices( void ) {
00748
00749 QListViewItem * it = DetectedPeers_LV->firstChild();
00750 while( it ) {
00751 if( it->isSelected() ) {
00752 break;
00753 }
00754 it = it->nextSibling();
00755 }
00756
00757 if( ! it )
00758 return;
00759
00760 QString S;
00761 PeerLVI * PI = (PeerLVI *)it;
00762
00763 scanMode( true );
00764 qApp->processEvents(0);
00765
00766 ServiceVector & V = PI->peer()->services();
00767
00768 while( PI->firstChild() ) {
00769
00770 delete PI->firstChild();
00771 }
00772
00773 for( unsigned int i = 0 ;
00774 i < V.count();
00775 i ++ ) {
00776 QString S;
00777 S = V[i]->name();
00778
00779 if( S.isEmpty() ) {
00780 continue;
00781 }
00782
00783 { QListViewItem * SIt;
00784 UUIDVector UIDV;
00785 QPixmap Pm;
00786 bool Done = 0;
00787 bool R;
00788 short ID;
00789
00790 SIt = 0;
00791
00792 UIDV = V[i]->classIDList();
00793
00794 for( unsigned int j = 0;
00795 j < UIDV.count();
00796 j ++ ) {
00797
00798 if( Filter.count() ) {
00799 bool FilterOut = 1;
00800
00801 for( unsigned int ff = 0;
00802 ff < Filter.count();
00803 ff ++ ) {
00804 if( UIDV[j] == Filter[ff] ) {
00805 FilterOut = 0;
00806 break;
00807 }
00808 }
00809
00810 if( FilterOut ) {
00811
00812 continue;
00813 }
00814 }
00815
00816 ID = UIDV[j].toShort();
00817 if( ID < 0x1200 || ID > 0x12ff ) {
00818
00819 if( R ) {
00820 unsigned int ch;
00821 bool has;
00822 has = V[i]->rfcommChannel( ch );
00823 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
00824 SIt->setText(0, V[i]->name() );
00825
00826 Pm = Icons->serviceIcon( ID, R );
00827 SIt->setPixmap(0, Pm );
00828 Done = 1;
00829 break;
00830 }
00831 }
00832 }
00833
00834 if( ! Done ) {
00835
00836 for( unsigned int j = 0;
00837 j < UIDV.count();
00838 j ++ ) {
00839
00840 if( Filter.count() ) {
00841 bool FilterOut = 1;
00842
00843 for( unsigned int ff = 0;
00844 ff < Filter.count();
00845 ff ++ ) {
00846 if( UIDV[j] == Filter[ff] ) {
00847 FilterOut = 0;
00848 break;
00849 }
00850 }
00851
00852 if( FilterOut ) {
00853
00854 continue;
00855 }
00856 }
00857
00858 ID = UIDV[j].toShort();
00859 if( ID >= 0x1200 && ID <= 0x12ff ) {
00860
00861 unsigned int ch;
00862 bool has;
00863 has = V[i]->rfcommChannel( ch );
00864 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
00865 SIt->setText(0, V[i]->name() );
00866
00867 Pm = Icons->serviceIcon( ID, R );
00868 SIt->setPixmap(0, Pm );
00869
00870 break;
00871 }
00872 }
00873 }
00874
00875 }
00876 }
00877
00878 scanMode( false );
00879 }
00880
00881 void OTScan::scanMode( bool M ) {
00882
00883 Detect_But->blockSignals( TRUE );
00884 Detect_But->setOn( M );
00885 Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") );
00886 Detect_But->blockSignals( FALSE );
00887 }
00888
00889
00890
00891
00892
00893
00894
00895 OTManage::OTManage( QWidget * parent, OTIcons * _IC ) :
00896 OTManageGUI( parent ) {
00897
00898 OT = OTGateway::getOTGateway();
00899
00900 Icons = (_IC ) ? _IC : new OTIcons();
00901 MyIcons = (_IC == 0 );
00902 AllDrivers_LV->setSorting(-1);
00903
00904 connect( OT,
00905 SIGNAL( driverListChanged() ),
00906 this,
00907 SLOT( SLOT_DriverListChanged() )
00908 );
00909 connect( OT,
00910 SIGNAL( stateChange( OTDriver *, bool ) ),
00911 this,
00912 SLOT( SLOT_StateChange( OTDriver *, bool ) )
00913 );
00914
00915 SLOT_DriverListChanged();
00916
00917 AllDrivers_LV->header()->hide();
00918 }
00919
00920 OTManage::~OTManage() {
00921 if( MyIcons )
00922 delete Icons;
00923 OTGateway::releaseOTGateway();
00924 }
00925
00926 void OTManage::SLOT_ShowDriver( QListViewItem * It ) {
00927 if( It == 0 || It->depth() > 0 )
00928
00929 return;
00930
00931 DriverLVI * it = (DriverLVI *) It;
00932 DriverIsUp_CB->setChecked( it->driver()->isUp() );
00933 }
00934
00935 void OTManage::SLOT_UpDriver( bool Up ) {
00936 QListViewItem * it = AllDrivers_LV->firstChild();
00937 while( it ) {
00938 if( it->isSelected() ) {
00939 OTDriver * D = ((DriverLVI *)it)->driver();
00940 odebug << "UP driver " << D->devname() << oendl;
00941
00942 D->setUp( Up );
00943 return;
00944 }
00945 it = it->nextSibling();
00946 }
00947 }
00948
00949 void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) {
00950 QListViewItem * it = AllDrivers_LV->firstChild();
00951 while( it ) {
00952 if( ((DriverLVI *)it)->driver() == D ) {
00953 it->setPixmap( 0,
00954 Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) );
00955 return;
00956 }
00957 it = it->nextSibling();
00958 }
00959 }
00960
00961 void OTManage::SLOT_DriverListChanged( ) {
00962 DriverLVI * It;
00963 QListViewItem * Sub;
00964 QListViewItem * First = 0;
00965 OTDriver* D;
00966 OTDriverList & DL = OT->getDriverList();
00967
00968 AllDrivers_LV->clear();
00969 for( unsigned int i = 0;
00970 i < DL.count();
00971 i ++ ) {
00972 D = DL[i];
00973 It = new DriverLVI( D, AllDrivers_LV );
00974
00975 if( ! First )
00976 First = It;
00977
00978 It->setText( 0, D->devname() );
00979 It->setPixmap( 0,
00980 Icons->loadPixmap( (D->isUp()) ?
00981 "bluezon" : "bluezoff" ) );
00982
00983 Sub = new QListViewItem( It );
00984 Sub->setText( 0, tr( "Name" ) );
00985 Sub->setText( 1, D->name() );
00986
00987 Sub = new QListViewItem( It );
00988 Sub->setText( 0, tr( "Address" ) );
00989 Sub->setText( 1, D->address().toString() );
00990
00991 Sub = new QListViewItem( It );
00992 Sub->setText( 0, tr( "Revision" ) );
00993 Sub->setText( 1, D->revision() );
00994
00995 Sub = new QListViewItem( It );
00996 Sub->setText( 0, tr( "Manufacturer" ) );
00997 Sub->setText( 1, D->manufacturer() );
00998
00999 QString Service, Device;
01000 D->getClass( Service, Device );
01001
01002 Sub = new QListViewItem( It );
01003 Sub->setText( 0, tr( "Service classes" ) );
01004 Sub->setText( 1, Service );
01005 Sub = new QListViewItem( It );
01006 Sub->setText( 0, tr( "Device class" ) );
01007 Sub->setText( 1, Device );
01008 }
01009
01010 if( DL.count() ) {
01011 AllDrivers_LV->setCurrentItem( First );
01012 DriverIsUp_CB->setEnabled( TRUE );
01013 } else {
01014 DriverIsUp_CB->setChecked( FALSE );
01015 DriverIsUp_CB->setEnabled( FALSE );
01016 }
01017 }
01018
01019 void OTManage::SLOT_SetRefreshTimer( int v ) {
01020 OT->setRefreshTimer( v * 1000 );
01021 }
01022
01023
01024
01025
01026
01027
01028
01029 OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) {
01030
01031 Icons = new OTIcons();
01032 SnifWindow = 0;
01033 OT = OTGateway::getOTGateway();
01034
01035 connect( OT,
01036 SIGNAL( deviceEnabled( bool ) ),
01037 this,
01038 SLOT( SLOT_DeviceIsEnabled( bool ) )
01039 );
01040 connect( OT,
01041 SIGNAL( driverListChanged() ),
01042 this,
01043 SLOT( SLOT_DriverListChanged() )
01044 );
01045 connect( OT,
01046 SIGNAL( stateChange( OTDriver *, bool ) ),
01047 this,
01048 SLOT( SLOT_StateChange( OTDriver *, bool ) )
01049 );
01050
01051 if( ! OT->needsEnabling() ) {
01052 MustBeEnabled_CB->hide();
01053 } else {
01054
01055 MustBeEnabled_CB->setChecked(
01056 OT->isEnabled() );
01057 }
01058
01059 SLOT_DriverListChanged();
01060 }
01061
01062 OTMain::~OTMain() {
01063 OTGateway::releaseOTGateway();
01064 delete Icons;
01065 }
01066
01067 void OTMain::SLOT_DriverListChanged() {
01068 OTDriver * D;
01069 OTDriverList & DL = OT->getDriverList();
01070
01071 DeviceList_CB->clear();
01072 for( unsigned int i = 0;
01073 i < DL.count();
01074 i ++ ) {
01075 D = DL[i];
01076 DeviceList_CB->insertItem(
01077 Icons->loadPixmap( (D->isUp()) ?
01078 "bluezon" : "bluezoff" ),
01079 D->devname() );
01080 if( D == OT->scanWith() ) {
01081 DeviceList_CB->setCurrentItem( i );
01082 }
01083 }
01084
01085 Scan_But->setEnabled( OT->getDriverList().count() > 0 );
01086 DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 );
01087 }
01088
01089 void OTMain::SLOT_EnableBluetooth( bool Up ) {
01090 OT->SLOT_SetEnabled( Up );
01091 }
01092
01093 void OTMain::SLOT_DeviceIsEnabled( bool Up ) {
01094 MustBeEnabled_CB->blockSignals( TRUE );
01095 MustBeEnabled_CB->setChecked( Up );
01096 MustBeEnabled_CB->blockSignals( FALSE );
01097 }
01098
01099 void OTMain::SLOT_Manage( void ) {
01100 QDialog * Dlg = new QDialog( this, 0, TRUE );
01101 QVBoxLayout * V = new QVBoxLayout( Dlg );
01102 OTManage * Mng = new OTManage( Dlg, Icons );
01103
01104 V->addWidget( Mng );
01105
01106 Dlg->setCaption( tr("Manage local devices" ) );
01107 Dlg->showMaximized();
01108 Dlg->exec();
01109 delete Dlg;
01110 }
01111
01112 void OTMain::SLOT_Scan( void ) {
01113 OTDriverList & DL = OT->getDriverList();
01114 for( unsigned int i = 0;
01115 i < DL.count();
01116 i ++ ) {
01117 if( DL[i]->isUp() &&
01118 DL[i]->devname() == DeviceList_CB->currentText()
01119 ) {
01120 QDialog * Dlg = new QDialog( this, 0, TRUE );
01121 QVBoxLayout * V = new QVBoxLayout( Dlg );
01122 OTScan * Scn = new OTScan( Dlg, Icons );
01123
01124 OT->setScanWith( OT->driver(i) );
01125 V->addWidget( Scn );
01126 Dlg->setCaption( tr("Scan Neighbourhood" ) );
01127 Dlg->showMaximized();
01128 Dlg->exec();
01129
01130 delete Dlg;
01131 return;
01132 }
01133 }
01134
01135 }
01136
01137 void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) {
01138 for( int i = 0;
01139 i < DeviceList_CB->count();
01140 i ++ ) {
01141 if( DeviceList_CB->text(i) == D->devname() ) {
01142 DeviceList_CB->changeItem(
01143 Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ),
01144 D->devname(),
01145 i );
01146 return;
01147 }
01148 }
01149 }
01150
01151 void OTMain::SLOT_Pairing( void ) {
01152 QDialog * Dlg = new QDialog( this, 0, TRUE );
01153 QVBoxLayout * V = new QVBoxLayout( Dlg );
01154 OTPairing * Pair = new OTPairing( Dlg, Icons );
01155
01156 V->addWidget( Pair );
01157 Dlg->showMaximized();
01158 Dlg->setCaption( tr("Manage pairing" ) );
01159 Dlg->exec();
01160
01161 delete Dlg;
01162 }
01163
01164 void OTMain::SLOT_Sniffing( void ) {
01165
01166 if( SnifWindow == 0 ) {
01167 SnifWindow = new QDialog( this, 0, FALSE );
01168 QVBoxLayout * V = new QVBoxLayout( SnifWindow );
01169 OTSniffing * SN = new OTSniffing( SnifWindow );
01170 V->addWidget( SN );
01171 }
01172
01173 SnifWindow->showMaximized();
01174 SnifWindow->show();
01175 }