-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 5c5f069..8b15c4f 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -1,93 +1,94 @@ | |||
1 | /* | 1 | /* |
2 | * bluebase.cpp * | 2 | * bluebase.cpp * |
3 | * --------------------- | 3 | * --------------------- |
4 | * | 4 | * |
5 | * copyright : (c) 2002 by Maximilian Reiß | 5 | * copyright : (c) 2002 by Maximilian Reiß |
6 | * email : max.reiss@gmx.de | 6 | * email : max.reiss@gmx.de |
7 | * | 7 | * |
8 | */ | 8 | */ |
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
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 | 23 | ||
24 | #include <remotedevice.h> | 24 | #include <remotedevice.h> |
25 | #include <services.h> | 25 | #include <services.h> |
26 | 26 | ||
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | 28 | ||
29 | #include <qframe.h> | 29 | #include <qframe.h> |
30 | #include <qlabel.h> | 30 | #include <qlabel.h> |
31 | #include <qpushbutton.h> | 31 | #include <qpushbutton.h> |
32 | #include <qlayout.h> | 32 | #include <qlayout.h> |
33 | #include <qvariant.h> | 33 | #include <qvariant.h> |
34 | #include <qimage.h> | 34 | #include <qimage.h> |
35 | #include <qpixmap.h> | 35 | #include <qpixmap.h> |
36 | #include <qtabwidget.h> | 36 | #include <qtabwidget.h> |
37 | #include <qscrollview.h> | 37 | #include <qscrollview.h> |
38 | #include <qvbox.h> | 38 | #include <qvbox.h> |
39 | #include <qmessagebox.h> | 39 | #include <qmessagebox.h> |
40 | #include <qcheckbox.h> | 40 | #include <qcheckbox.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qlistview.h> | 42 | #include <qlistview.h> |
43 | #include <qdir.h> | 43 | #include <qdir.h> |
44 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
45 | #include <qtimer.h> | 45 | #include <qtimer.h> |
46 | #include <qlist.h> | ||
46 | 47 | ||
47 | #include <qpe/qpeapplication.h> | 48 | #include <qpe/qpeapplication.h> |
48 | #include <qpe/resource.h> | 49 | #include <qpe/resource.h> |
49 | #include <qpe/config.h> | 50 | #include <qpe/config.h> |
50 | 51 | ||
51 | 52 | ||
52 | using namespace OpieTooth; | 53 | using namespace OpieTooth; |
53 | 54 | ||
54 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) | 55 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) |
55 | : BluetoothBase( parent, name, fl ) { | 56 | : BluetoothBase( parent, name, fl ) { |
56 | 57 | ||
57 | m_localDevice = new Manager( "hci0" ); | 58 | m_localDevice = new Manager( "hci0" ); |
58 | 59 | ||
59 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); | 60 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); |
60 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); | 61 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); |
61 | // not good since lib is async | 62 | // not good since lib is async |
62 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), | 63 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), |
63 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); | 64 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); |
64 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), | 65 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), |
65 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); | 66 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); |
66 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), | 67 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), |
67 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); | 68 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); |
68 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), | 69 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), |
69 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); | 70 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); |
70 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), | 71 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), |
71 | this, SLOT( deviceActive( const QString& , bool ) ) ); | 72 | this, SLOT( deviceActive( const QString& , bool ) ) ); |
72 | connect( m_localDevice, SIGNAL( connections( ConnectionState::ValueList ) ), | 73 | connect( m_localDevice, SIGNAL( connections( ConnectionState::ValueList ) ), |
73 | this, SLOT( addConnectedDevices( ConnectionState::ValueList ) ) ); | 74 | this, SLOT( addConnectedDevices( ConnectionState::ValueList ) ) ); |
74 | 75 | ||
75 | 76 | ||
76 | // let hold be rightButtonClicked() | 77 | // let hold be rightButtonClicked() |
77 | QPEApplication::setStylusOperation( ListView2->viewport(), QPEApplication::RightOnHold); | 78 | QPEApplication::setStylusOperation( ListView2->viewport(), QPEApplication::RightOnHold); |
78 | QPEApplication::setStylusOperation( ListView4->viewport(), QPEApplication::RightOnHold); | 79 | QPEApplication::setStylusOperation( ListView4->viewport(), QPEApplication::RightOnHold); |
79 | 80 | ||
80 | //Load all icons needed | 81 | //Load all icons needed |
81 | m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); | 82 | m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); |
82 | m_onPix = Resource::loadPixmap( "opietooth/connected" ); | 83 | m_onPix = Resource::loadPixmap( "opietooth/connected" ); |
83 | m_findPix = Resource::loadPixmap( "opietooth/find" ); | 84 | m_findPix = Resource::loadPixmap( "opietooth/find" ); |
84 | 85 | ||
85 | QPalette pal = this->palette(); | 86 | QPalette pal = this->palette(); |
86 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); | 87 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); |
87 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 88 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
88 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 89 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
89 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 90 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
90 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 91 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
91 | this->setPalette( pal ); | 92 | this->setPalette( pal ); |
92 | 93 | ||
93 | setCaption( tr( "Bluetooth Manager" ) ); | 94 | setCaption( tr( "Bluetooth Manager" ) ); |
@@ -340,158 +341,169 @@ void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & poin | |||
340 | popup = new QPopupMenu(); | 341 | popup = new QPopupMenu(); |
341 | } | 342 | } |
342 | int test1 = popup->insertItem( tr("Test1:"), 2); | 343 | int test1 = popup->insertItem( tr("Test1:"), 2); |
343 | 344 | ||
344 | ret = popup->exec( point ); | 345 | ret = popup->exec( point ); |
345 | qWarning("returned from exec() "); | 346 | qWarning("returned from exec() "); |
346 | if ( ret == -1 ) { | 347 | if ( ret == -1 ) { |
347 | ; | 348 | ; |
348 | } else if ( ret == test1 ) { | 349 | } else if ( ret == test1 ) { |
349 | ; | 350 | ; |
350 | } | 351 | } |
351 | delete popup; | 352 | delete popup; |
352 | } | 353 | } |
353 | delete menu; | 354 | delete menu; |
354 | } | 355 | } |
355 | 356 | ||
356 | 357 | ||
357 | /** | 358 | /** |
358 | * Search and display avail. services for a device (on expand from device listing) | 359 | * Search and display avail. services for a device (on expand from device listing) |
359 | * @param item the service item returned | 360 | * @param item the service item returned |
360 | */ | 361 | */ |
361 | void BlueBase::addServicesToDevice( BTDeviceItem * item ) { | 362 | void BlueBase::addServicesToDevice( BTDeviceItem * item ) { |
362 | qDebug("addServicesToDevice"); | 363 | qDebug("addServicesToDevice"); |
363 | // row of mac adress text(3) | 364 | // row of mac adress text(3) |
364 | RemoteDevice device = item->remoteDevice(); | 365 | RemoteDevice device = item->remoteDevice(); |
365 | m_deviceList.insert( item->mac() , item ); | 366 | m_deviceList.insert( item->mac() , item ); |
366 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back | 367 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back |
367 | m_localDevice->searchServices( device ); | 368 | m_localDevice->searchServices( device ); |
368 | } | 369 | } |
369 | 370 | ||
370 | 371 | ||
371 | /** | 372 | /** |
372 | * Overloaded. This one it the one that is connected to the foundServices signal | 373 | * Overloaded. This one it the one that is connected to the foundServices signal |
373 | * @param device the mac address of the remote device | 374 | * @param device the mac address of the remote device |
374 | * @param servicesList the list with the service the device has. | 375 | * @param servicesList the list with the service the device has. |
375 | */ | 376 | */ |
376 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { | 377 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { |
377 | qDebug("fill services list"); | 378 | qDebug("fill services list"); |
378 | 379 | ||
379 | QMap<QString,BTDeviceItem*>::Iterator it; | 380 | QMap<QString,BTDeviceItem*>::Iterator it; |
380 | BTDeviceItem* deviceItem = 0; | 381 | BTDeviceItem* deviceItem = 0; |
381 | 382 | ||
382 | // get the right devices which requested the search | 383 | // get the right devices which requested the search |
383 | it = m_deviceList.find( device ); | 384 | it = m_deviceList.find( device ); |
384 | if( it == m_deviceList.end() ) | 385 | if( it == m_deviceList.end() ) |
385 | return; | 386 | return; |
386 | deviceItem = it.data(); | 387 | deviceItem = it.data(); |
387 | 388 | ||
389 | // remove previous entries | ||
390 | QList<QListViewItem> tempList; | ||
391 | tempList.setAutoDelete( true ); | ||
392 | QListViewItem * child = deviceItem->firstChild(); | ||
393 | while( child ) { | ||
394 | tempList.append( child ); | ||
395 | child = child->nextSibling(); | ||
396 | } | ||
397 | tempList.clear(); | ||
398 | |||
388 | QValueList<OpieTooth::Services>::Iterator it2; | 399 | QValueList<OpieTooth::Services>::Iterator it2; |
389 | BTServiceItem * serviceItem; | 400 | BTServiceItem* serviceItem; |
401 | |||
390 | 402 | ||
391 | if (!servicesList.isEmpty() ) { | 403 | if (!servicesList.isEmpty() ) { |
392 | // add services | 404 | // add services |
393 | QMap<int, QString> list; | 405 | QMap<int, QString> list; |
394 | QMap<int, QString>::Iterator classIt; | 406 | QMap<int, QString>::Iterator classIt; |
395 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { | 407 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { |
396 | serviceItem = new BTServiceItem( deviceItem , (*it2) ); | 408 | serviceItem = new BTServiceItem( deviceItem, (*it2) ); |
397 | list = (*it2).classIdList(); | 409 | list = (*it2).classIdList(); |
398 | classIt = list.begin(); | 410 | classIt = list.begin(); |
399 | int classId=0; | 411 | int classId=0; |
400 | if ( classIt != list.end() ) { | 412 | if ( classIt != list.end() ) { |
401 | classId = classIt.key(); | 413 | classId = classIt.key(); |
402 | } | 414 | } |
403 | 415 | ||
404 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); | 416 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); |
405 | } | 417 | } |
406 | } else { | 418 | } else { |
407 | Services s1; | 419 | Services s1; |
408 | s1.setServiceName( tr("no serives found") ); | 420 | s1.setServiceName( tr("no services found") ); |
409 | serviceItem = new BTServiceItem( deviceItem, s1 ); | 421 | serviceItem = new BTServiceItem( deviceItem, s1 ); |
410 | } | 422 | } |
411 | // now remove them from the list | 423 | // now remove them from the list |
412 | m_deviceList.remove( it ); | 424 | m_deviceList.remove( it ); |
413 | } | 425 | } |
414 | 426 | ||
415 | 427 | ||
416 | /** | 428 | /** |
417 | * Add the existing connections (pairs) to the connections tab. | 429 | * Add the existing connections (pairs) to the connections tab. |
418 | * This one triggers the search | 430 | * This one triggers the search |
419 | */ | 431 | */ |
420 | void BlueBase::addConnectedDevices() { | 432 | void BlueBase::addConnectedDevices() { |
421 | m_localDevice->searchConnections(); | 433 | m_localDevice->searchConnections(); |
422 | } | 434 | } |
423 | 435 | ||
424 | 436 | ||
425 | /** | 437 | /** |
426 | * This adds the found connections to the connection tab. | 438 | * This adds the found connections to the connection tab. |
427 | * @param connectionList the ValueList with all current connections | 439 | * @param connectionList the ValueList with all current connections |
428 | */ | 440 | */ |
429 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) { | 441 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) { |
430 | 442 | ||
431 | // clear the ListView first | 443 | // clear the ListView first |
432 | ListView4->clear(); | 444 | ListView4->clear(); |
433 | 445 | ||
434 | QValueList<OpieTooth::ConnectionState>::Iterator it; | 446 | QValueList<OpieTooth::ConnectionState>::Iterator it; |
435 | BTConnectionItem * connectionItem; | 447 | BTConnectionItem * connectionItem; |
436 | 448 | ||
437 | if ( !connectionList.isEmpty() ) { | 449 | if ( !connectionList.isEmpty() ) { |
438 | 450 | ||
439 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { | 451 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { |
440 | connectionItem = new BTConnectionItem( ListView4 , (*it) ); | 452 | connectionItem = new BTConnectionItem( ListView4 , (*it) ); |
441 | } | 453 | } |
442 | } else { | 454 | } else { |
443 | ConnectionState con; | 455 | ConnectionState con; |
444 | con.setMac( tr("No connections found") ); | 456 | con.setMac( tr("No connections found") ); |
445 | connectionItem = new BTConnectionItem( ListView4 , con ); | 457 | connectionItem = new BTConnectionItem( ListView4 , con ); |
446 | } | 458 | } |
447 | 459 | ||
448 | // recall connection search after some time | 460 | // recall connection search after some time |
449 | QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); | 461 | QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); |
450 | } | 462 | } |
451 | 463 | ||
452 | 464 | ||
453 | /** | 465 | /** |
454 | * Find out if a device can currently be reached | 466 | * Find out if a device can currently be reached |
455 | * @param device | 467 | * @param device |
456 | */ | 468 | */ |
457 | void BlueBase::deviceActive( const RemoteDevice &device ) { | 469 | void BlueBase::deviceActive( const RemoteDevice &device ) { |
458 | // search by mac, async, gets a signal back | 470 | // search by mac, async, gets a signal back |
459 | // We should have a BTDeviceItem there or where does it get added to the map -zecke | 471 | // We should have a BTDeviceItem there or where does it get added to the map -zecke |
460 | m_localDevice->isAvailable( device.mac() ); | 472 | m_localDevice->isAvailable( device.mac() ); |
461 | } | 473 | } |
462 | 474 | ||
463 | 475 | ||
464 | /** | 476 | /** |
465 | * The signal catcher. Set the avail. status on device. | 477 | * The signal catcher. Set the avail. status on device. |
466 | * @param device - the mac address | 478 | * @param device - the mac address |
467 | * @param connected - if it is avail. or not | 479 | * @param connected - if it is avail. or not |
468 | */ | 480 | */ |
469 | void BlueBase::deviceActive( const QString& device, bool connected ) { | 481 | void BlueBase::deviceActive( const QString& device, bool connected ) { |
470 | qDebug("deviceActive slot"); | 482 | qDebug("deviceActive slot"); |
471 | 483 | ||
472 | QMap<QString,BTDeviceItem*>::Iterator it; | 484 | QMap<QString,BTDeviceItem*>::Iterator it; |
473 | 485 | ||
474 | it = m_deviceList.find( device ); | 486 | it = m_deviceList.find( device ); |
475 | if( it == m_deviceList.end() ) | 487 | if( it == m_deviceList.end() ) |
476 | return; | 488 | return; |
477 | 489 | ||
478 | BTDeviceItem* deviceItem = it.data(); | 490 | BTDeviceItem* deviceItem = it.data(); |
479 | 491 | ||
480 | 492 | ||
481 | if ( connected ) { | 493 | if ( connected ) { |
482 | deviceItem->setPixmap( 1, m_onPix ); | 494 | deviceItem->setPixmap( 1, m_onPix ); |
483 | } else { | 495 | } else { |
484 | deviceItem->setPixmap( 1, m_offPix ); | 496 | deviceItem->setPixmap( 1, m_offPix ); |
485 | } | 497 | } |
486 | m_deviceList.remove( it ); | 498 | m_deviceList.remove( it ); |
487 | } | 499 | } |
488 | 500 | ||
489 | 501 | ||
490 | /** | 502 | /** |
491 | * Open the "scan for devices" dialog | 503 | * Open the "scan for devices" dialog |
492 | */ | 504 | */ |
493 | void BlueBase::startScan() { | 505 | void BlueBase::startScan() { |
494 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", | 506 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", |
495 | true, WDestructiveClose ); | 507 | true, WDestructiveClose ); |
496 | QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ), | 508 | QObject::connect( scan, SIGNAL( selectedDevices( const QValueList<RemoteDevice>& ) ), |
497 | this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) ); | 509 | this, SLOT( addSearchedDevices( const QValueList<RemoteDevice>& ) ) ); |