Diffstat (limited to 'noncore/net/opietooth/applet/bluezapplet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
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 @@ -54,33 +54,41 @@ using namespace Opie::Core; #include <device.h> namespace OpieTooth { BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { setFixedHeight( AppLnk::smallIconSize() ); setFixedWidth( AppLnk::smallIconSize() ); bluezOnPixmap = Resource::loadImage( "bluetoothapplet/bluezon" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); bluezOffPixmap = Resource::loadImage( "bluetoothapplet/bluezoff" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); //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() { return 6; } bool BluezApplet::checkBluezStatus() { if (btDevice) { if (btDevice->isLoaded() ) { return true; @@ -109,27 +117,70 @@ int BluezApplet::position() break; } } else { if ( btDevice ) { delete btDevice; btDevice = 0; } } return 0; } 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<QString, QString> btmap; + + RemoteDevice::ValueList::Iterator it; + for( it = deviceList.begin(); it != deviceList.end(); ++it ) + { + btmap[(*it).name()] = (*it).mac(); + } + + e << btmap; } void BluezApplet::mousePressEvent( QMouseEvent *) { QPopupMenu *menu = new QPopupMenu(); QPopupMenu *signal = new QPopupMenu(); int ret=0; /* Refresh active state */ timerEvent( 0 ); |