added debug message for device removal
[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 public:
56         NearbyDevicesModel(QObject *parent = 0);
57
58         BluetoothDevice* pairingDevice() { if(agent) return agent->device();  else return NULL; }
59
60 public slots:
61
62         int columnCount(const QModelIndex &) const { return 1;}
63         int rowCount(const QModelIndex &parent = QModelIndex()) const;
64         QVariant data(const QModelIndex &index, int role) const;
65
66         QString hwAddress(int index) { return devices[index]->address(); }
67         QString alias(int index){ return devices[index]->name(); }
68         void pair(QString hwaddy);
69         void discover(bool start);
70         void removeAll(bool);
71
72         void replyRequestConfirmation(bool confirmed);
73         void replyPasskey(uint passkey);
74         void replyRequestPidCode(QString pidCode);
75
76         void setAdapterProperty(QString name, QVariant value);
77
78 private slots:
79         void adapterAdded(QDBusObjectPath);
80         void adapterRemoved(QDBusObjectPath);
81         void deviceCreated(QString hwaddy, QVariantMap properties);
82         void deviceRemoved(QString hwaddy);
83
84         void adapterPropertiesChangedSlot(QString n,QDBusVariant v);
85
86 signals:
87         void requestConfirmation(QString device, uint code);
88         void requestPasskey(QString device);
89         void requestPidCode(QString device);
90         void release();
91
92         void nearbyDeviceFound(int index);
93         void nearbyDeviceRemoved(int index);
94
95         void adapterPropertiesChanged(QString name, QVariant value);
96
97 private:
98         QList<NearbyItem*> devices;
99         OrgBluezManagerInterface *manager;
100         OrgBluezAdapterInterface *adapter;
101         AsyncAgent* agent;      
102 };
103
104 #endif // NEARBYDEVICESMODEL_H