28a8c056c63cd45282766cee71d8f29511913755
[profile/ivi/bluetooth-qt.git] / bluetoothdevicemodel.h
1 #ifndef BLUETOOTHDEVICEMODEL_H
2 #define BLUETOOTHDEVICEMODEL_H
3
4 #include <QAbstractListModel>
5 #include "bluemanager.h"
6 #include "blueadapter.h"
7 #include "bluetoothdevice.h"
8
9 class BluetoothDevicesModel : public QAbstractListModel
10 {
11     Q_OBJECT
12         Q_PROPERTY(bool discoverable READ discoverable WRITE makeDiscoverable NOTIFY discoverableChanged);
13         Q_PROPERTY(bool adapterPresent READ adapterPresent NOTIFY adapterChanged)
14 public:
15         explicit BluetoothDevicesModel(QObject *parent = 0);
16
17         bool adapterPresent() { return adapter != NULL; }
18
19 public slots:
20
21         int columnCount(const QModelIndex &) const { return 1; }
22         int rowCount(const QModelIndex &parent = QModelIndex()) const;
23         QVariant data(const QModelIndex &index, int role) const;
24
25         QString devicePath(QString name);
26
27         QList<BluetoothDevice*> devices(){ return m_devices; }
28
29         BluetoothDevice* device(QString path);
30         void makeDiscoverable(bool isDiscoverable);
31         bool discoverable();
32
33 private slots:
34         void adapterAdded(QDBusObjectPath);
35         void adapterRemoved(QDBusObjectPath);
36         void deviceCreated(QDBusObjectPath);
37         void deviceRemoved(QDBusObjectPath);
38
39         void devicePropertyChanged(QString name, QVariant value);
40         void adapterPropertyChanged(QString name, QDBusVariant value);
41
42 signals:
43         void devicePaired(BluetoothDevice* device);
44         void discoverableChanged(bool discoverable);
45         void adapterChanged(bool adapterPresent);
46
47 private:
48         OrgBluezManagerInterface *manager;
49         OrgBluezAdapterInterface *adapter;
50         QList<BluetoothDevice*> m_devices;
51 };
52
53 #endif // BLUETOOTHDEVICEMODEL_H