update name and alias on device create signal
[profile/ivi/bluetooth-qt.git] / bluetooth-qt / 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 NOTIFY nameChanged)
27         Q_PROPERTY(QString alias READ alias NOTIFY aliasChanged)
28         Q_PROPERTY(QString address READ address)
29         Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
30         Q_PROPERTY(bool legacyPairing READ legacyPairing)
31 public:
32         NearbyItem(QString name="", QString address="", QString icon="", bool legacy=false, QObject* parent = 0)
33         :QObject(parent)
34         {
35             m_name=name;
36             m_addy=address;
37             m_icon=icon;
38             m_legacy = legacy;
39         }
40
41         QString name() { return m_name; }
42         QString alias() { return m_alias; }
43         QString address() { return m_addy; }
44         QString icon() { return m_icon; }
45         bool legacyPairing() { return m_legacy; }
46
47         void setName(QString n) { m_name = n; nameChanged(); }
48         void setIcon(QString i) { m_icon = i; iconChanged(); }
49         void setAlias(QString a) { m_alias = a; aliasChanged(); }
50
51 signals:
52         void nameChanged();
53         void aliasChanged();
54         void iconChanged();
55
56 private:
57         QString m_name;
58         QString m_alias;
59         QString m_addy;
60         QString m_icon;
61         bool m_legacy;
62 };
63
64 class NearbyDevicesModel : public QAbstractListModel
65 {
66         Q_OBJECT
67         Q_PROPERTY(BluetoothDevice* pairingDevice READ pairingDevice)
68 public:
69         NearbyDevicesModel(QObject *parent = 0);
70
71         BluetoothDevice* pairingDevice() { if(agent) return agent->device();  else return NULL; }
72
73 public slots:
74
75         int columnCount(const QModelIndex &) const { return 1;}
76         int rowCount(const QModelIndex &parent = QModelIndex()) const;
77         QVariant data(const QModelIndex &index, int role) const;
78
79         QString hwAddress(int index) { return devices[index]->address(); }
80         QString alias(int index){ return devices[index]->name(); }
81         void pair(QString hwaddy);
82         void discover(bool start);
83         void removeAll(bool);
84
85         void replyRequestConfirmation(bool confirmed);
86         void replyPasskey(uint passkey);
87         void replyRequestPidCode(QString pidCode);
88
89         void setAdapterProperty(QString name, QVariant value);
90
91 private slots:
92         void adapterAdded(QDBusObjectPath);
93         void adapterRemoved(QDBusObjectPath);
94         void deviceCreated(QString hwaddy, QVariantMap properties);
95         void deviceRemoved(QString hwaddy);
96
97         void adapterPropertiesChangedSlot(QString n,QDBusVariant v);
98
99 signals:
100         void requestConfirmation(QString device, uint code);
101         void requestPasskey(QString device);
102         void requestPidCode(QString device);
103         void release();
104
105         void nearbyDeviceFound(int index);
106         void nearbyDeviceRemoved(int index);
107
108         void adapterPropertiesChanged(QString name, QVariant value);
109
110 private:
111         QList<NearbyItem*> devices;
112         OrgBluezManagerInterface *manager;
113         OrgBluezAdapterInterface *adapter;
114         AsyncAgent* agent;      
115 };
116
117 #endif // NEARBYDEVICESMODEL_H