added discoverable property to devicemodel
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 12 Jan 2011 00:07:35 +0000 (16:07 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 12 Jan 2011 00:07:35 +0000 (16:07 -0800)
bluetooth-qt.pro
bluetoothdevice.cpp
bluetoothdevice.h
bluetoothdevicemodel.cpp
bluetoothdevicemodel.h
btprofiles.h

index 2845194..ae2e89d 100644 (file)
@@ -34,7 +34,8 @@ HEADERS += agentadaptor.h \
        asyncagent.h \
        devicetypes.h \
     bluetoothdevice.h \
-    bluetoothdevicemodel.h
+       bluetoothdevicemodel.h \
+       audio.h
 SOURCES += agentadaptor.cpp \
        bluemanager.cpp \
        bluedevice.cpp \
@@ -46,7 +47,8 @@ SOURCES += agentadaptor.cpp \
        bluetoothbaseagent.cpp \
        asyncagent.cpp \
     bluetoothdevice.cpp \
-    bluetoothdevicemodel.cpp
+       bluetoothdevicemodel.cpp \
+       audio.cpp
 
 target.path = $$INSTALL_ROOT/usr/lib
 headers.path = $$INSTALL_ROOT/usr/include/bluetooth-qt/
index 269645f..0930763 100644 (file)
@@ -86,6 +86,13 @@ void BluetoothDevice::disconnect()
        m_device->Disconnect();
 }
 
+void BluetoothDevice::disconnectAudio()
+{
+       if(!audio) audio = new OrgBluezAudioInterface("org.bluez", m_device->path(), QDBusConnection::systemBus(), this);
+
+       audio->Disconnect();
+}
+
 QStringList BluetoothDevice::profiles()
 {
        QVariantMap props = m_device->GetProperties();
index 9855eb9..6f9efdf 100644 (file)
@@ -33,6 +33,7 @@ public slots:
        void connectAudioSrc();
        QString connectSerial();
        void disconnect();
+       void disconnectAudio();
 
        QStringList profiles();
        bool isProfileSupported(QString profile);
index 7b05953..d4e70bb 100644 (file)
@@ -92,9 +92,26 @@ BluetoothDevice* BluetoothDevicesModel::device(QString path)
                if(device->path() == path)
                        return device;
        }
+       qDebug()<<"Device not found for path: "<<path;
        return NULL;
 }
 
+void BluetoothDevicesModel::makeDiscoverable(bool discoverableValue)
+{
+       if(adapter) adapter->SetProperty("Discoverable", QDBusVariant(discoverableValue));
+}
+
+bool BluetoothDevicesModel::discoverable()
+{
+       if(adapter)
+       {
+               QVariantMap props = adapter->GetProperties();
+               return props["Discoverable"].toBool();
+       }
+
+       return false;
+}
+
 void BluetoothDevicesModel::adapterAdded(QDBusObjectPath path)
 {
        if(adapter && adapter->path() == path.path()) return;
@@ -110,6 +127,11 @@ void BluetoothDevicesModel::adapterAdded(QDBusObjectPath path)
                        QDBusConnection::systemBus(), this);
 
        connect(adapter,
+                       SIGNAL(PropertyChanged(QString,QDBusVariant)),
+                       this,
+                       SLOT(adapterPropertyChanged(QString,QDBusVariant)));
+
+       connect(adapter,
                SIGNAL(DeviceRemoved(QDBusObjectPath)),
                this,
                SLOT(deviceRemoved(QDBusObjectPath)));
@@ -187,3 +209,14 @@ void BluetoothDevicesModel::devicePropertyChanged(QString name, QVariant value)
 
        dataChanged(createIndex(row, 0),createIndex(row, 0));
 }
+
+
+void BluetoothDevicesModel::adapterPropertyChanged(QString name, QDBusVariant value)
+{
+       qDebug()<<"adapter property changed: "<<name<<" "<<value.variant();
+
+       if(name == "Discoverable")
+       {
+               discoverableChanged(value.variant().toBool());
+       }
+}
index f8f2daf..f57b0f4 100644 (file)
@@ -9,6 +9,8 @@
 class BluetoothDevicesModel : public QAbstractListModel
 {
     Q_OBJECT
+       Q_PROPERTY(bool discoverable READ discoverable WRITE makeDiscoverable NOTIFY discoverableChanged);
+
 public:
        explicit BluetoothDevicesModel(QObject *parent = 0);
 
@@ -30,6 +32,8 @@ public slots:
        QList<BluetoothDevice*> devices(){ return m_devices; }
 
        BluetoothDevice* device(QString path);
+       void makeDiscoverable(bool isDiscoverable);
+       bool discoverable();
 
 private slots:
        void adapterAdded(QDBusObjectPath);
@@ -38,9 +42,11 @@ private slots:
        void deviceRemoved(QDBusObjectPath);
 
        void devicePropertyChanged(QString name, QVariant value);
+       void adapterPropertyChanged(QString name, QDBusVariant value);
 
 signals:
        void devicePaired(BluetoothDevice* device);
+       void discoverableChanged(bool discoverable);
 
 private:
        OrgBluezManagerInterface *manager;
index b6a4ac7..9a551b0 100644 (file)
@@ -27,6 +27,7 @@ namespace BluetoothProfiles
        const char opush[] = "00001105-0000-1000-8000-00805f9b34fb";
        const char ftp[] = "00001106-0000-1000-8000-00805f9b34fb";
        const char panu[] = "00001115-0000-1000-8000-00805f9b34fb";
+       const char nap[] = "00001116-0000-1000-8000-00805f9b34fb";
        const char spp[] = "00001101-0000-1000-8000-00805f9b34fb";
 }
 #endif // BTPROFILES_H