From 4def5629dc68465b1dc8bb23c115e2f5f7513804 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Sun, 21 Aug 2005 22:29:07 +0000 Subject: Add some simple interfaces for device scanning (scanning for discoverable receivers) to support OBEX Send, and requests for taking BT up or down. Patch courtesy Michael Haynie - thanks! --- (limited to 'noncore') diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index 8925803..48698b6 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp @@ -63,15 +63,23 @@ namespace OpieTooth { //bluezDiscoveryOnPixmap = Resource::loadImage( "bluetoothapplet/magglass" )smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize()); startTimer(4000); btDevice = 0; + btManager = 0; bluezactive = false; bluezDiscoveryActive = false; + // TODO: determine whether this channel has to be closed at destruction time. + QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); + connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), + this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); } BluezApplet::~BluezApplet() { if ( btDevice ) { delete btDevice; } + if ( btManager ) { + delete btManager; + } } int BluezApplet::position() @@ -118,9 +126,52 @@ int BluezApplet::position() } int BluezApplet::checkBluezDiscoveryStatus() { + return bluezDiscoveryActive; } int BluezApplet::setBluezDiscoveryStatus(int d) { + return bluezDiscoveryActive=d; + } + + // FIXME mbhaynie + // receiver for QCopChannel("QPE/Bluetooth") messages. + void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) + { + if ( str == "enableBluetooth()") { + if (!checkBluezStatus()) { + setBluezStatus(1); + } + } else if ( str == "disableBluetooth()") { + if (checkBluezStatus()) { + // setBluezStatus(0); + } + } else if ( str == "listDevices()") { + if (!btManager) + { + btManager = new Manager("hci0"); + connect( btManager, SIGNAL( foundDevices(const QString&,RemoteDevice::ValueList) ), + this, SLOT( fillList(const QString&,RemoteDevice::ValueList) ) ) ; + } + + btManager->searchDevices(); + } + } + + // Once the hcitool scan is complete, report back. + void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) + { + QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); + + QStringList list; + QMap btmap; + + RemoteDevice::ValueList::Iterator it; + for( it = deviceList.begin(); it != deviceList.end(); ++it ) + { + btmap[(*it).name()] = (*it).mac(); + } + + e << btmap; } void BluezApplet::mousePressEvent( QMouseEvent *) { diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index a394e38..3b99c0f 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace OpieTooth { class Device; @@ -46,6 +47,8 @@ namespace OpieTooth { void timerEvent(QTimerEvent *te ); public slots: + void fillList( const QString& device, RemoteDevice::ValueList list ); + private: void mousePressEvent( QMouseEvent * ); void paintEvent( QPaintEvent* ); @@ -57,6 +60,7 @@ public slots: private: Device* btDevice; + Manager *btManager; QPixmap bluezOnPixmap; QPixmap bluezOffPixmap; QPixmap bluezDiscoveryOnPixmap; @@ -64,6 +68,7 @@ public slots: bool bluezDiscoveryActive; private slots: + void slotMessage( const QCString& , const QByteArray& ); }; -- cgit v0.9.0.2