f57b0f4583e782a0f72c5266bbac623652fab3b6
[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
14 public:
15         explicit BluetoothDevicesModel(QObject *parent = 0);
16
17         enum Role
18         {
19                 name = Qt::UserRole + 1,
20                 address,
21                 path
22         };
23
24 public slots:
25
26         int columnCount(const QModelIndex &) const { return 1; }
27         int rowCount(const QModelIndex &parent = QModelIndex()) const;
28         QVariant data(const QModelIndex &index, int role) const;
29
30         QString devicePath(QString name);
31
32         QList<BluetoothDevice*> devices(){ return m_devices; }
33
34         BluetoothDevice* device(QString path);
35         void makeDiscoverable(bool isDiscoverable);
36         bool discoverable();
37
38 private slots:
39         void adapterAdded(QDBusObjectPath);
40         void adapterRemoved(QDBusObjectPath);
41         void deviceCreated(QDBusObjectPath);
42         void deviceRemoved(QDBusObjectPath);
43
44         void devicePropertyChanged(QString name, QVariant value);
45         void adapterPropertyChanged(QString name, QDBusVariant value);
46
47 signals:
48         void devicePaired(BluetoothDevice* device);
49         void discoverableChanged(bool discoverable);
50
51 private:
52         OrgBluezManagerInterface *manager;
53         OrgBluezAdapterInterface *adapter;
54         QList<BluetoothDevice*> m_devices;
55 };
56
57 #endif // BLUETOOTHDEVICEMODEL_H