model work
authorKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 14 Sep 2010 00:02:00 +0000 (17:02 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 14 Sep 2010 00:02:00 +0000 (17:02 -0700)
asyncagent.cpp
bluetoothdevice.h
bluetoothdevicemodel.cpp
bluetoothdevicemodel.h
nearbydevicesmodel.cpp
nearbydevicesmodel.h

index 1c2556e..12c9ecd 100644 (file)
@@ -8,6 +8,7 @@ AsyncAgent::AsyncAgent(QString path, QObject *parent) :
 
 void AsyncAgent::requestConfirmation(OrgBluezDeviceInterface &device, uint key)
 {
+       qDebug("requestConfirmation");
        setDelayedReply(true);
        pendingMessage = message();
        m_connection = connection();
@@ -40,6 +41,7 @@ uint AsyncAgent::requestPasskey(OrgBluezDeviceInterface &device)
 
 QString AsyncAgent::requestPidCode(OrgBluezDeviceInterface &device)
 {
+       qDebug("requestPidCode");
        setDelayedReply(true);
        pendingMessage = message();
        m_connection = connection();
index 03b9779..efce46d 100644 (file)
@@ -21,7 +21,7 @@ class BluetoothDevice : public QObject
        Q_PROPERTY(QString connectedProfile READ connectedProfile)*/
 
 public:
-       explicit BluetoothDevice(QDBusObjectPath path, QObject *parent = 0);
+       explicit BluetoothDevice(QDBusObjectPath path = QDBusObjectPath(), QObject *parent = 0);
 
 signals:
        void connetedChanged();
index ca786ed..a61d99c 100644 (file)
@@ -1,6 +1,6 @@
 #include "bluetoothdevicemodel.h"
 
-BluetoothDeviceModel::BluetoothDeviceModel(QObject *parent) :
+BluetoothDevicesModel::BluetoothDevicesModel(QObject *parent) :
        QAbstractListModel(parent), adapter(NULL)
 {
        manager = new OrgBluezManagerInterface(
@@ -19,12 +19,12 @@ BluetoothDeviceModel::BluetoothDeviceModel(QObject *parent) :
        setRoleNames(roles);
 }
 
-int BluetoothDeviceModel::rowCount(const QModelIndex &parent) const
+int BluetoothDevicesModel::rowCount(const QModelIndex &) const
 {
        return m_devices.size();
 }
 
-QVariant BluetoothDeviceModel::data(const QModelIndex &index, int role) const
+QVariant BluetoothDevicesModel::data(const QModelIndex &index, int role) const
 {
        if(role == name)
        {
@@ -56,7 +56,26 @@ QVariant BluetoothDeviceModel::data(const QModelIndex &index, int role) const
        return QVariant();
 }
 
-void BluetoothDeviceModel::adapterAdded(QDBusObjectPath path)
+QString BluetoothDevicesModel::devicePath(QString devicename)
+{
+       foreach(BluetoothDevice* device, m_devices)
+       {
+               if(device->name() == devicename)
+                       return device->path();
+       }
+       return "";
+}
+
+BluetoothDevice* BluetoothDevicesModel::device(QString path)
+{
+       foreach(BluetoothDevice* device, m_devices)
+       {
+               if(device->path() == path)
+                       return device;
+       }
+}
+
+void BluetoothDevicesModel::adapterAdded(QDBusObjectPath path)
 {
        if(adapter && adapter->path() == path.path()) return;
 
@@ -73,12 +92,12 @@ void BluetoothDeviceModel::adapterAdded(QDBusObjectPath path)
        connect(adapter,
                SIGNAL(DeviceRemoved(QDBusObjectPath)),
                this,
-               SIGNAL(deviceRemoved(QDBusObjectPath)));
+               SLOT(deviceRemoved(QDBusObjectPath)));
 
        connect(adapter,
                SIGNAL(DeviceCreated(QDBusObjectPath)),
                this,
-               SIGNAL(deviceCreated(QDBusObjectPath)));
+               SLOT(deviceCreated(QDBusObjectPath)));
 
        QList<QDBusObjectPath> list = adapter->ListDevices();
        foreach(QDBusObjectPath item, list)
@@ -87,7 +106,7 @@ void BluetoothDeviceModel::adapterAdded(QDBusObjectPath path)
        }
 }
 
-void BluetoothDeviceModel::adapterRemoved(QDBusObjectPath)
+void BluetoothDevicesModel::adapterRemoved(QDBusObjectPath)
 {
        QDBusObjectPath adapterpath = manager->DefaultAdapter();
 
@@ -106,7 +125,7 @@ void BluetoothDeviceModel::adapterRemoved(QDBusObjectPath)
        }
 }
 
-void BluetoothDeviceModel::deviceCreated(QDBusObjectPath devicepath)
+void BluetoothDevicesModel::deviceCreated(QDBusObjectPath devicepath)
 {
 
        beginInsertRows(QModelIndex(),m_devices.size()+1,m_devices.size()+1);
@@ -114,7 +133,7 @@ void BluetoothDeviceModel::deviceCreated(QDBusObjectPath devicepath)
        endInsertRows();
 }
 
-void BluetoothDeviceModel::deviceRemoved(QDBusObjectPath devicepath)
+void BluetoothDevicesModel::deviceRemoved(QDBusObjectPath devicepath)
 {
        for(int i=0; i<m_devices.size(); i++)
        {
index 6181871..fb2052f 100644 (file)
@@ -6,11 +6,11 @@
 #include "blueadapter.h"
 #include "bluetoothdevice.h"
 
-class BluetoothDeviceModel : public QAbstractListModel
+class BluetoothDevicesModel : public QAbstractListModel
 {
     Q_OBJECT
 public:
-    explicit BluetoothDeviceModel(QObject *parent = 0);
+       explicit BluetoothDevicesModel(QObject *parent = 0);
 
        enum Role
        {
@@ -25,12 +25,19 @@ public slots:
        int rowCount(const QModelIndex &parent = QModelIndex()) const;
        QVariant data(const QModelIndex &index, int role) const;
 
+       QString devicePath(QString name);
+
+       QList<BluetoothDevice*> devices(){ return m_devices; }
+
+       BluetoothDevice* device(QString path);
+
+private slots:
        void adapterAdded(QDBusObjectPath);
        void adapterRemoved(QDBusObjectPath);
        void deviceCreated(QDBusObjectPath);
        void deviceRemoved(QDBusObjectPath);
 
-       QList<BluetoothDevice*> devices(){ return m_devices; }
+
 
 private:
        OrgBluezManagerInterface *manager;
index db7acff..8643de8 100644 (file)
@@ -13,8 +13,8 @@ NearbyDevicesModel::NearbyDevicesModel(QObject *parent) :
        adapterAdded(QDBusObjectPath());
 
        QHash<int,QByteArray> roles;
-       roles[Qt::DisplayRole]="name";
-
+       roles[NearbyDevicesModelRoles::name]="name";
+       roles[NearbyDevicesModelRoles::address]="address";
        setRoleNames(roles);
 }
 
@@ -27,7 +27,7 @@ int NearbyDevicesModel::rowCount(const QModelIndex &parent) const
 
 QVariant NearbyDevicesModel::data(const QModelIndex &index, int role) const
 {
-       if (role == Qt::DisplayRole)
+       if (role == NearbyDevicesModelRoles::name)
        {
                QString rowData;
                if(index.row() < devicepathlist.size())
@@ -36,7 +36,15 @@ QVariant NearbyDevicesModel::data(const QModelIndex &index, int role) const
                }
                return QVariant(rowData);
        }
-
+       else if (role == NearbyDevicesModelRoles::address)
+       {
+               QString rowData;
+               if(index.row() < devicepathlist.size())
+               {
+                       rowData = devicepathlist[index.row()];
+               }
+               return QVariant(rowData);
+       }
        return QVariant();
 }
 
index 9312a9a..3a647d6 100644 (file)
@@ -9,6 +9,15 @@
 #include "blueadapter.h"
 #include "asyncagent.h"
 
+namespace NearbyDevicesModelRoles
+{
+       enum
+       {
+               name = Qt::UserRole + 1,
+               address
+       };
+}
+
 class NearbyDevicesModel : public QAbstractListModel
 {
        Q_OBJECT