void AsyncAgent::requestConfirmation(OrgBluezDeviceInterface &device, uint key)
{
+ qDebug("requestConfirmation");
setDelayedReply(true);
pendingMessage = message();
m_connection = connection();
QString AsyncAgent::requestPidCode(OrgBluezDeviceInterface &device)
{
+ qDebug("requestPidCode");
setDelayedReply(true);
pendingMessage = message();
m_connection = connection();
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();
#include "bluetoothdevicemodel.h"
-BluetoothDeviceModel::BluetoothDeviceModel(QObject *parent) :
+BluetoothDevicesModel::BluetoothDevicesModel(QObject *parent) :
QAbstractListModel(parent), adapter(NULL)
{
manager = new OrgBluezManagerInterface(
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)
{
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;
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)
}
}
-void BluetoothDeviceModel::adapterRemoved(QDBusObjectPath)
+void BluetoothDevicesModel::adapterRemoved(QDBusObjectPath)
{
QDBusObjectPath adapterpath = manager->DefaultAdapter();
}
}
-void BluetoothDeviceModel::deviceCreated(QDBusObjectPath devicepath)
+void BluetoothDevicesModel::deviceCreated(QDBusObjectPath devicepath)
{
beginInsertRows(QModelIndex(),m_devices.size()+1,m_devices.size()+1);
endInsertRows();
}
-void BluetoothDeviceModel::deviceRemoved(QDBusObjectPath devicepath)
+void BluetoothDevicesModel::deviceRemoved(QDBusObjectPath devicepath)
{
for(int i=0; i<m_devices.size(); i++)
{
#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
{
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;
adapterAdded(QDBusObjectPath());
QHash<int,QByteArray> roles;
- roles[Qt::DisplayRole]="name";
-
+ roles[NearbyDevicesModelRoles::name]="name";
+ roles[NearbyDevicesModelRoles::address]="address";
setRoleNames(roles);
}
QVariant NearbyDevicesModel::data(const QModelIndex &index, int role) const
{
- if (role == Qt::DisplayRole)
+ if (role == NearbyDevicesModelRoles::name)
{
QString rowData;
if(index.row() < devicepathlist.size())
}
return QVariant(rowData);
}
-
+ else if (role == NearbyDevicesModelRoles::address)
+ {
+ QString rowData;
+ if(index.row() < devicepathlist.size())
+ {
+ rowData = devicepathlist[index.row()];
+ }
+ return QVariant(rowData);
+ }
return QVariant();
}
#include "blueadapter.h"
#include "asyncagent.h"
+namespace NearbyDevicesModelRoles
+{
+ enum
+ {
+ name = Qt::UserRole + 1,
+ address
+ };
+}
+
class NearbyDevicesModel : public QAbstractListModel
{
Q_OBJECT