31
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef BTDEVICEMODEL_H
|
|
19 |
#define BTDEVICEMODEL_H
|
|
20 |
|
|
21 |
#include <qglobal.h>
|
|
22 |
#include <QAbstractItemModel>
|
|
23 |
#include <QSharedPointer>
|
|
24 |
#include <btuimodeltypes.h>
|
|
25 |
|
|
26 |
class BtDeviceData;
|
|
27 |
|
|
28 |
/*!
|
|
29 |
\class BtDeviceModel
|
|
30 |
\brief The data model provided to Bluetooth UIs in QT
|
|
31 |
|
|
32 |
BtDeviceModel provides APIs for accessing the data of remote devices.
|
|
33 |
In addition, signals from this
|
|
34 |
model are provided for being informed of data update.
|
|
35 |
|
|
36 |
This model is in one dimension (n rows * 1 columns), i.e.,
|
|
37 |
|
|
38 |
row 0 ( a remote device)
|
|
39 |
row 1 ( another device)
|
|
40 |
...
|
|
41 |
|
|
42 |
The data in this model is non-modifiable from the user interface (except device
|
|
43 |
search may add a number of in-range devices temporarily) ,
|
|
44 |
determined by the characteristics of Bluetooth, the underline BT software
|
|
45 |
services and the BT application requirements.
|
|
46 |
|
|
47 |
Whenever feasible, the detailed description should contain a simple
|
|
48 |
example code example:
|
|
49 |
\code
|
|
50 |
// ...
|
|
51 |
\endcode
|
|
52 |
|
|
53 |
\sa \link model-view-programming.html Model/View Programming\endlink
|
|
54 |
*/
|
|
55 |
|
|
56 |
class BTUIMODEL_IMEXPORT BtDeviceModel : public QAbstractItemModel
|
|
57 |
{
|
|
58 |
Q_OBJECT
|
|
59 |
Q_ENUMS( DevDataRole DevMajorProperty AVDevMinorProperty PeripheralMinorProperty )
|
|
60 |
|
|
61 |
public:
|
|
62 |
|
|
63 |
// the roles for catogerizing Bluetooth device properties
|
|
64 |
enum DevDataRole {
|
|
65 |
NameAliasRole = Qt::DisplayRole, // QVariant::String, the name showing in UI
|
|
66 |
ReadableBdaddrRole = Qt::UserRole, // QString, the readable format of a BD_ADDR (BT Device address)
|
|
67 |
LastUsedTimeRole, // QDateTime
|
|
68 |
RssiRole, // QVariant::Int
|
|
69 |
MajorPropertyRole, // QVariant::Int, bits of DevMajorProperty
|
|
70 |
MinorPropertyRole, // QVariant::Int, bits according to an item from DevMajorProperty
|
|
71 |
CoDRole, // QVariant::Int, the value of Class of Device
|
|
72 |
};
|
|
73 |
|
|
74 |
/*
|
|
75 |
* Major device property values.
|
|
76 |
*/
|
|
77 |
enum DevMajorProperty {
|
|
78 |
NullProperty = 0x00000000, // device without any specific filter.
|
|
79 |
Bonded = 0x00000001, // device is in registry and bonded with phone
|
|
80 |
Blocked = 0x00000002, // device is in registry and blocked by user
|
|
81 |
RecentlyUsed = 0x00000004, // device is in registry and was used in last 30 days.
|
|
82 |
Trusted = 0x00000008, // device is in registry and authorized by user.
|
|
83 |
InRegistry = 0x00000010, // device exists in registry.
|
|
84 |
|
|
85 |
Connected = 0x00000020, // device is currently connected to one or more
|
|
86 |
// services managed by Bluetooth Engine.
|
|
87 |
Connectable = 0x00000040, // device is connectable to one or more
|
|
88 |
// services managed by Bluetooth Engine.
|
|
89 |
InRange = 0x00000100, // device is in range
|
|
90 |
|
|
91 |
// bits re-defined according to Class of Device:
|
|
92 |
Computer = 0x00010000, // a computer
|
|
93 |
Phone = 0x00020000, // a phone
|
|
94 |
LANAccessDev = 0x00040000, // a LAN access point
|
|
95 |
AVDev = 0x00080000, // an A/V device
|
|
96 |
Peripheral = 0x00100000, // a peripheral
|
|
97 |
ImagingDev = 0x00200000, // an imaging device
|
|
98 |
WearableDev = 0x00400000, // a wearable device
|
|
99 |
Toy = 0x00800000, // a toy
|
|
100 |
HealthDev = 0x01000000, // a health device
|
|
101 |
UncategorizedDev = 0x02000000, // a generic device that is uncategorized
|
|
102 |
|
|
103 |
// all properties derived from BT registry
|
|
104 |
RegistryProperties = Bonded |
|
|
105 |
Blocked | RecentlyUsed | Trusted | InRegistry,
|
|
106 |
|
|
107 |
// all properties derived from CoD
|
|
108 |
CodProperties = Computer | Phone | LANAccessDev |
|
|
109 |
AVDev | Peripheral | ImagingDev | WearableDev |
|
|
110 |
Toy | HealthDev | UncategorizedDev,
|
|
111 |
};
|
|
112 |
|
|
113 |
/*
|
|
114 |
* Minor device filters for major property \code AVDev \endcode
|
|
115 |
*/
|
|
116 |
enum AVDevMinorProperty {
|
|
117 |
Carkit = 0x00000001,
|
|
118 |
Headset = 0x00000002,
|
|
119 |
};
|
|
120 |
|
|
121 |
/*
|
|
122 |
* Minor device filters for major property \code Peripheral \endcode
|
|
123 |
*/
|
|
124 |
enum PeripheralMinorProperty {
|
|
125 |
Mouse = 0x00000001,
|
|
126 |
Keyboard = 0x00000002,
|
|
127 |
};
|
|
128 |
|
|
129 |
public:
|
|
130 |
|
|
131 |
explicit BtDeviceModel( QObject *parent = 0 );
|
|
132 |
|
|
133 |
explicit BtDeviceModel( const BtDeviceModel &model, QObject *parent = 0 );
|
|
134 |
|
|
135 |
virtual ~BtDeviceModel();
|
|
136 |
|
|
137 |
bool searchDevice();
|
|
138 |
|
|
139 |
void cancelSearchDevice();
|
|
140 |
|
|
141 |
void removeTransientDevices();
|
|
142 |
|
|
143 |
// from QAbstractItemModel
|
|
144 |
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
|
|
145 |
|
|
146 |
virtual QModelIndex parent( const QModelIndex &child ) const;
|
|
147 |
|
|
148 |
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
|
|
149 |
|
|
150 |
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
|
|
151 |
|
|
152 |
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
|
|
153 |
|
|
154 |
virtual QMap<int, QVariant> itemData( const QModelIndex & index ) const;
|
|
155 |
|
|
156 |
signals:
|
|
157 |
|
|
158 |
void deviceSearchCompleted(int error);
|
|
159 |
|
|
160 |
private:
|
|
161 |
|
|
162 |
void emitDataChanged(int row, int column, void *parent );
|
|
163 |
|
|
164 |
void emitDataChanged(const QModelIndex &top, const QModelIndex &bottom );
|
|
165 |
|
|
166 |
void emitdeviceSearchCompleted(int error);
|
|
167 |
|
|
168 |
private:
|
|
169 |
QSharedPointer<BtDeviceData> mDeviceData;
|
|
170 |
|
|
171 |
friend class BtDeviceData;
|
|
172 |
};
|
|
173 |
|
|
174 |
#endif // BTUIMODEL_H
|