1c3f87ec803679f7e72337fb3245232b9e0a2d74
[profile/ivi/bluetooth-qt.git] / nearbydevicesmodel.h
1 #ifndef NEARBYDEVICESMODEL_H
2 #define NEARBYDEVICESMODEL_H
3
4 #include <QObject>
5 #include <QAbstractListModel>
6 #include <QDBusObjectPath>
7
8 #include "bluemanager.h"
9 #include "blueadapter.h"
10 #include "asyncagent.h"
11 #include "bluetoothdevice.h"
12
13 namespace NearbyDevicesModelRoles
14 {
15         enum
16         {
17                 name = Qt::UserRole + 1,
18                 address,
19                 icon
20         };
21 }
22
23 class NearbyItem: public QObject
24 {
25         Q_OBJECT
26         Q_PROPERTY(QString name READ name)
27         Q_PROPERTY(QString address READ address)
28         Q_PROPERTY(QString icon READ icon)
29         Q_PROPERTY(bool legacyPairing READ legacyPairing)
30 public:
31         NearbyItem(QString name="", QString address="", QString icon="", bool legacy=false, QObject* parent = 0)
32         :QObject(parent)
33         {
34             m_name=name;
35             m_addy=address;
36             m_icon=icon;
37             m_legacy = legacy;
38         }
39
40         QString name() { return m_name; }
41         QString address() { return m_addy; }
42         QString icon() { return m_icon; }
43         bool legacyPairing() { return m_legacy; }
44 private:
45         QString m_name;
46         QString m_addy;
47         QString m_icon;
48         bool m_legacy;
49 };
50
51 class NearbyDevicesModel : public QAbstractListModel
52 {
53         Q_OBJECT
54         Q_PROPERTY(BluetoothDevice* pairingDevice READ pairingDevice)
55
56 public:
57         NearbyDevicesModel(QObject *parent = 0);
58
59         BluetoothDevice* pairingDevice() { if(agent) return agent->device();  else return NULL; }
60
61 public slots:
62
63         int columnCount(const QModelIndex &) const { return 1;}
64         int rowCount(const QModelIndex &parent = QModelIndex()) const;
65         QVariant data(const QModelIndex &index, int role) const;
66
67         QString hwAddress(int index) { return devices[index]->address(); }
68         QString alias(int index){ return devices[index]->name(); }
69         void pair(QString hwaddy);
70         void discover(bool start);
71         void removeAll(bool);
72
73         void replyRequestConfirmation(bool confirmed);
74         void replyPasskey(uint passkey);
75         void replyRequestPidCode(QString pidCode);
76
77         void setAdapterProperty(QString name, QVariant value);
78
79 private slots:
80         void adapterAdded(QDBusObjectPath);
81         void adapterRemoved(QDBusObjectPath);
82         void deviceCreated(QString hwaddy, QVariantMap properties);
83         void deviceRemoved(QString hwaddy);
84
85         void adapterPropertiesChangedSlot(QString n,QDBusVariant v);
86
87 signals:
88         void requestConfirmation(QString device, uint code);
89         void requestPasskey(QString device);
90         void requestPidCode(QString device);
91         void release();
92
93         void nearbyDeviceFound(int index);
94         void nearbyDeviceRemoved(int index);
95
96         void adapterPropertiesChanged(QString name, QVariant value);
97
98 private:
99         QList<NearbyItem*> devices;
100         OrgBluezManagerInterface *manager;
101         OrgBluezAdapterInterface *adapter;
102         AsyncAgent* agent;      
103 };
104
105 #endif // NEARBYDEVICESMODEL_H