summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-03-07 23:58:45 (UTC)
committer harlekin <harlekin>2003-03-07 23:58:45 (UTC)
commit3e92beca986b9fecd8193f55513ea1ecd2cd0866 (patch) (unidiff)
tree651a9a6fe0f35c18baea5d793425e03d12e70104
parente2f480bc22863bf803259e98b1c62933af20b48f (diff)
downloadopie-3e92beca986b9fecd8193f55513ea1ecd2cd0866.zip
opie-3e92beca986b9fecd8193f55513ea1ecd2cd0866.tar.gz
opie-3e92beca986b9fecd8193f55513ea1ecd2cd0866.tar.bz2
nicer refresh handling for connections
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index 9663b52..b5a09e5 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -374,209 +374,235 @@ void BlueBase::addServicesToDevice( BTDeviceItem * item ) {
374 374
375 375
376/** 376/**
377 * Overloaded. This one it the one that is 377 * Overloaded. This one it the one that is
378 ted to the foundServices signal 378 ted to the foundServices signal
379 * @param device the mac address of the remote device 379 * @param device the mac address of the remote device
380 * @param servicesList the list with the service the device has. 380 * @param servicesList the list with the service the device has.
381 */ 381 */
382void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { 382void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) {
383 qDebug("fill services list"); 383 qDebug("fill services list");
384 384
385 QMap<QString,BTDeviceItem*>::Iterator it; 385 QMap<QString,BTDeviceItem*>::Iterator it;
386 BTDeviceItem* deviceItem = 0; 386 BTDeviceItem* deviceItem = 0;
387 387
388 // get the right devices which requested the search 388 // get the right devices which requested the search
389 it = m_deviceList.find( device ); 389 it = m_deviceList.find( device );
390 if( it == m_deviceList.end() ) 390 if( it == m_deviceList.end() )
391 return; 391 return;
392 deviceItem = it.data(); 392 deviceItem = it.data();
393 393
394 // remove previous entries 394 // remove previous entries
395 QList<QListViewItem> tempList; 395 QList<QListViewItem> tempList;
396 tempList.setAutoDelete( true ); 396 tempList.setAutoDelete( true );
397 QListViewItem * child = deviceItem->firstChild(); 397 QListViewItem * child = deviceItem->firstChild();
398 while( child ) { 398 while( child ) {
399 tempList.append( child ); 399 tempList.append( child );
400 child = child->nextSibling(); 400 child = child->nextSibling();
401 } 401 }
402 tempList.clear(); 402 tempList.clear();
403 403
404 QValueList<OpieTooth::Services>::Iterator it2; 404 QValueList<OpieTooth::Services>::Iterator it2;
405 BTServiceItem* serviceItem; 405 BTServiceItem* serviceItem;
406 406
407 407
408 if (!servicesList.isEmpty() ) { 408 if (!servicesList.isEmpty() ) {
409 // add services 409 // add services
410 QMap<int, QString> list; 410 QMap<int, QString> list;
411 QMap<int, QString>::Iterator classIt; 411 QMap<int, QString>::Iterator classIt;
412 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { 412 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) {
413 serviceItem = new BTServiceItem( deviceItem, (*it2) ); 413 serviceItem = new BTServiceItem( deviceItem, (*it2) );
414 list = (*it2).classIdList(); 414 list = (*it2).classIdList();
415 classIt = list.begin(); 415 classIt = list.begin();
416 int classId=0; 416 int classId=0;
417 if ( classIt != list.end() ) { 417 if ( classIt != list.end() ) {
418 classId = classIt.key(); 418 classId = classIt.key();
419 } 419 }
420 420
421 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); 421 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) );
422 } 422 }
423 } else { 423 } else {
424 Services s1; 424 Services s1;
425 s1.setServiceName( tr("no services found") ); 425 s1.setServiceName( tr("no services found") );
426 serviceItem = new BTServiceItem( deviceItem, s1 ); 426 serviceItem = new BTServiceItem( deviceItem, s1 );
427 } 427 }
428 // now remove them from the list 428 // now remove them from the list
429 m_deviceList.remove( it ); 429 m_deviceList.remove( it );
430} 430}
431 431
432 432
433 433
434 434
435 435
436void BlueBase::addSignalStrength() { 436void BlueBase::addSignalStrength() {
437 437
438 QListViewItemIterator it( ListView4 ); 438 QListViewItemIterator it( ListView4 );
439 for ( ; it.current(); ++it ) { 439 for ( ; it.current(); ++it ) {
440 m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() ); 440 m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() );
441 } 441 }
442 442
443 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); 443 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) );
444} 444}
445 445
446void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) { 446void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) {
447 447
448 QListViewItemIterator it( ListView4 ); 448 QListViewItemIterator it( ListView4 );
449 for ( ; it.current(); ++it ) { 449 for ( ; it.current(); ++it ) {
450 if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) { 450 if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) {
451 ((BTConnectionItem*)it.current() )->setSignalStrength( strength ); 451 ((BTConnectionItem*)it.current() )->setSignalStrength( strength );
452 } 452 }
453 } 453 }
454} 454}
455 455
456/** 456/**
457 * Add the existing connections (pairs) to the connections tab. 457 * Add the existing connections (pairs) to the connections tab.
458 * This one triggers the search 458 * This one triggers the search
459 */ 459 */
460void BlueBase::addConnectedDevices() { 460void BlueBase::addConnectedDevices() {
461 m_localDevice->searchConnections(); 461 m_localDevice->searchConnections();
462} 462}
463 463
464/** 464/**
465 * This adds the found connections to the connection tab. 465 * This adds the found connections to the connection tab.
466 * @param connectionList the ValueList with all current connections 466 * @param connectionList the ValueList with all current connections
467 */ 467 */
468void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) { 468void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) {
469 469
470 // clear the ListView first
471 ListView4->clear();
472
473 QValueList<OpieTooth::ConnectionState>::Iterator it; 470 QValueList<OpieTooth::ConnectionState>::Iterator it;
474 BTConnectionItem * connectionItem; 471 BTConnectionItem * connectionItem;
475 472
476 if ( !connectionList.isEmpty() ) { 473 if ( !connectionList.isEmpty() ) {
477 474
478 for (it = connectionList.begin(); it != connectionList.end(); ++it) { 475 for (it = connectionList.begin(); it != connectionList.end(); ++it) {
479 connectionItem = new BTConnectionItem( ListView4, (*it) );
480 476
481 if( m_deviceList.find((*it).mac()).data() ) { 477 QListViewItemIterator it2( ListView4 );
478 bool found = false;
479 for ( ; it2.current(); ++it2 ) {
480 if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() ) {
481 found = true;
482 }
483 }
484
485 if ( found == false ) {
486 connectionItem = new BTConnectionItem( ListView4, (*it) );
487
488 if( m_deviceList.find((*it).mac()).data() ) {
489 connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() );
490 }
491 }
482 492
483 connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() );
484 }
485 } 493 }
494
495 QListViewItemIterator it2( ListView4 );
496 for ( ; it2.current(); ++it2 ) {
497 bool found = false;
498 for (it = connectionList.begin(); it != connectionList.end(); ++it) {
499 if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() ) {
500 found = true;
501 }
502 }
503
504 if ( !found ) {
505 delete it2.current();
506 }
507
508 }
509
510
486 } else { 511 } else {
512 ListView4->clear();
487 ConnectionState con; 513 ConnectionState con;
488 con.setMac( tr("No connections found") ); 514 con.setMac( tr("No connections found") );
489 connectionItem = new BTConnectionItem( ListView4 , con ); 515 connectionItem = new BTConnectionItem( ListView4 , con );
490 } 516 }
491 517
492 // recall connection search after some time 518 // recall connection search after some time
493 QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); 519 QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) );
494} 520}
495 521
496 522
497/** 523/**
498 * Find out if a device can currently be reached 524 * Find out if a device can currently be reached
499 * @param device 525 * @param device
500 */ 526 */
501void BlueBase::deviceActive( const RemoteDevice &device ) { 527void BlueBase::deviceActive( const RemoteDevice &device ) {
502 // search by mac, async, gets a signal back 528 // search by mac, async, gets a signal back
503 // We should have a BTDeviceItem there or where does it get added to the map -zecke 529 // We should have a BTDeviceItem there or where does it get added to the map -zecke
504 m_localDevice->isAvailable( device.mac() ); 530 m_localDevice->isAvailable( device.mac() );
505} 531}
506 532
507 533
508/** 534/**
509 * The signal catcher. Set the avail. status on device. 535 * The signal catcher. Set the avail. status on device.
510 * @param device - the mac address 536 * @param device - the mac address
511 * @param connected - if it is avail. or not 537 * @param connected - if it is avail. or not
512 */ 538 */
513void BlueBase::deviceActive( const QString& device, bool connected ) { 539void BlueBase::deviceActive( const QString& device, bool connected ) {
514 qDebug("deviceActive slot"); 540 qDebug("deviceActive slot");
515 541
516 QMap<QString,BTDeviceItem*>::Iterator it; 542 QMap<QString,BTDeviceItem*>::Iterator it;
517 543
518 it = m_deviceList.find( device ); 544 it = m_deviceList.find( device );
519 if( it == m_deviceList.end() ) 545 if( it == m_deviceList.end() )
520 return; 546 return;
521 547
522 BTDeviceItem* deviceItem = it.data(); 548 BTDeviceItem* deviceItem = it.data();
523 549
524 550
525 if ( connected ) { 551 if ( connected ) {
526 deviceItem->setPixmap( 1, m_onPix ); 552 deviceItem->setPixmap( 1, m_onPix );
527 } else { 553 } else {
528 deviceItem->setPixmap( 1, m_offPix ); 554 deviceItem->setPixmap( 1, m_offPix );
529 } 555 }
530 m_deviceList.remove( it ); 556 m_deviceList.remove( it );
531} 557}
532 558
533 559
534/** 560/**
535 * Open the "scan for devices" dialog 561 * Open the "scan for devices" dialog
536 */ 562 */
537void BlueBase::startScan() { 563void BlueBase::startScan() {
538 ScanDialog *scan = new ScanDialog( this, "ScanDialog", 564 ScanDialog *scan = new ScanDialog( this, "ScanDialog",
539 true, WDestructiveClose ); 565 true, WDestructiveClose );
540 QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ), 566 QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ),
541 this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) ); 567 this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) );
542 568
543 scan->showMaximized(); 569 scan->showMaximized();
544} 570}
545 571
546 572
547/** 573/**
548 * Set the informations about the local device in information Tab 574 * Set the informations about the local device in information Tab
549 */ 575 */
550void BlueBase::setInfo() { 576void BlueBase::setInfo() {
551 StatusLabel->setText( status() ); 577 StatusLabel->setText( status() );
552} 578}
553 579
554 580
555/** 581/**
556 * Decontructor 582 * Decontructor
557 */ 583 */
558BlueBase::~BlueBase() { 584BlueBase::~BlueBase() {
559 writeSavedDevices(); 585 writeSavedDevices();
560 delete m_iconLoader; 586 delete m_iconLoader;
561} 587}
562 588
563 589
564/** 590/**
565 * find searches the ListView for a BTDeviceItem containig 591 * find searches the ListView for a BTDeviceItem containig
566 * the same Device if found return true else false 592 * the same Device if found return true else false
567 * @param dev RemoteDevice to find 593 * @param dev RemoteDevice to find
568 * @return returns true if found 594 * @return returns true if found
569 */ 595 */
570bool BlueBase::find( const RemoteDevice& rem ) { 596bool BlueBase::find( const RemoteDevice& rem ) {
571 QListViewItemIterator it( ListView2 ); 597 QListViewItemIterator it( ListView2 );
572 BTListItem* item; 598 BTListItem* item;
573 BTDeviceItem* device; 599 BTDeviceItem* device;
574 for (; it.current(); ++it ) { 600 for (; it.current(); ++it ) {
575 item = (BTListItem*) it.current(); 601 item = (BTListItem*) it.current();
576 if ( item->typeId() != BTListItem::Device ) 602 if ( item->typeId() != BTListItem::Device )
577 continue; 603 continue;
578 604
579 device = (BTDeviceItem*)item; 605 device = (BTDeviceItem*)item;
580 if ( rem.equals( device->remoteDevice() ) ) 606 if ( rem.equals( device->remoteDevice() ) )
581 return true; 607 return true;
582 } 608 }