1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtSystems module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 or version 3 as published by the Free |
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
22 | ** following information to ensure the GNU Lesser General Public License |
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
25 | ** |
26 | ** As a special exception, The Qt Company gives you certain additional |
27 | ** rights. These rights are described in The Qt Company LGPL Exception |
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
29 | ** |
30 | ** $QT_END_LICENSE$ |
31 | ** |
32 | ****************************************************************************/ |
33 | |
34 | #include "qdeclarativedeviceinfo_p.h" |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | /*! |
39 | \qmltype DeviceInfo |
40 | \instantiates QDeclarativeDeviceInfo |
41 | \inqmlmodule QtSystemInfo |
42 | \ingroup qml-systeminfo |
43 | \brief The DeviceInfo element provides various information about the device. |
44 | */ |
45 | |
46 | /*! |
47 | \internal |
48 | */ |
49 | QDeclarativeDeviceInfo::QDeclarativeDeviceInfo(QObject *parent) |
50 | : QObject(parent) |
51 | , deviceInfo(new QDeviceInfo(this)) |
52 | , isMonitorThermalState(false) |
53 | { |
54 | } |
55 | |
56 | /*! |
57 | \internal |
58 | */ |
59 | QDeclarativeDeviceInfo::~QDeclarativeDeviceInfo() |
60 | { |
61 | } |
62 | |
63 | /*! |
64 | \qmlproperty flag DeviceInfo::activatedLocks |
65 | |
66 | This property holds the activated locks. Available locks include: |
67 | \list |
68 | \li DeviceInfo.NoLock - No lock. |
69 | \li DeviceInfo.PinLock - Device can be locked by PIN code or password. |
70 | \li DeviceInfo.TouchOrKeyboardLock - Device can be locked by touch or keyboard. |
71 | \li DeviceInfo.UnknownLock - Lock types requested but no result received yet. |
72 | \endlist |
73 | */ |
74 | QDeclarativeDeviceInfo::LockTypeFlags QDeclarativeDeviceInfo::activatedLocks() const |
75 | { |
76 | connect(sender: deviceInfo, SIGNAL(activatedLocksChanged(QDeviceInfo::LockTypeFlags)), |
77 | receiver: this, SIGNAL(activatedLocksChanged()), Qt::UniqueConnection); |
78 | |
79 | QDeviceInfo::LockTypeFlags locks(deviceInfo->activatedLocks()); |
80 | if (locks.testFlag(flag: QDeviceInfo::UnknownLock)) |
81 | return QDeclarativeDeviceInfo::UnknownLock; |
82 | LockTypeFlags declarativeLocks(NoLock); |
83 | if (locks.testFlag(flag: QDeviceInfo::PinLock)) |
84 | declarativeLocks |= PinLock; |
85 | if (locks.testFlag(flag: QDeviceInfo::TouchOrKeyboardLock)) |
86 | declarativeLocks |= TouchOrKeyboardLock; |
87 | return declarativeLocks; |
88 | } |
89 | |
90 | /*! |
91 | \qmlproperty flag DeviceInfo::enabledLocks |
92 | |
93 | This property holds the enabled locks. Available locks include: |
94 | \list |
95 | \li DeviceInfo.NoLock - No lock. |
96 | \li DeviceInfo.PinLock - Device can be locked by PIN code or password. |
97 | \li DeviceInfo.TouchOrKeyboardLock - Device can be locked by touch or keyboard. |
98 | \li DeviceInfo.UnknownLock - Lock types requested but no result received yet. |
99 | \endlist |
100 | */ |
101 | QDeclarativeDeviceInfo::LockTypeFlags QDeclarativeDeviceInfo::enabledLocks() const |
102 | { |
103 | connect(sender: deviceInfo, SIGNAL(enabledLocksChanged(QDeviceInfo::LockTypeFlags)), |
104 | receiver: this, SIGNAL(enabledLocksChanged()), Qt::UniqueConnection); |
105 | |
106 | QDeviceInfo::LockTypeFlags locks(deviceInfo->enabledLocks()); |
107 | if (locks.testFlag(flag: QDeviceInfo::UnknownLock)) |
108 | return QDeclarativeDeviceInfo::UnknownLock; |
109 | LockTypeFlags declarativeLocks(NoLock); |
110 | if (locks.testFlag(flag: QDeviceInfo::PinLock)) |
111 | declarativeLocks |= PinLock; |
112 | if (locks.testFlag(flag: QDeviceInfo::TouchOrKeyboardLock)) |
113 | declarativeLocks |= TouchOrKeyboardLock; |
114 | return declarativeLocks; |
115 | } |
116 | |
117 | /*! |
118 | \qmlproperty bool DeviceInfo::monitorThermalState |
119 | |
120 | This property holds whether or not monitor the change of thermal state. |
121 | */ |
122 | bool QDeclarativeDeviceInfo::monitorThermalState() const |
123 | { |
124 | return isMonitorThermalState; |
125 | } |
126 | |
127 | void QDeclarativeDeviceInfo::setMonitorThermalState(bool monitor) |
128 | { |
129 | if (monitor != isMonitorThermalState) { |
130 | isMonitorThermalState = monitor; |
131 | if (monitor) { |
132 | connect(sender: deviceInfo, SIGNAL(thermalStateChanged(QDeviceInfo::ThermalState)), |
133 | receiver: this, SIGNAL(thermalStateChanged())); |
134 | } else { |
135 | disconnect(sender: deviceInfo, SIGNAL(thermalStateChanged(QDeviceInfo::ThermalState)), |
136 | receiver: this, SIGNAL(thermalStateChanged())); |
137 | } |
138 | emit monitorThermalStateChanged(); |
139 | } |
140 | } |
141 | |
142 | /*! |
143 | \qmlproperty enumeration DeviceInfo::thermalState |
144 | |
145 | This property holds the thermal state. Possible values are: |
146 | \list |
147 | \li DeviceInfo.UnknownThermal - The thermal state is unknown. |
148 | \li DeviceInfo.NormalThermal - The thermal state is normal. |
149 | \li DeviceInfo.WarningThermal - The thermal state is warning. |
150 | \li DeviceInfo.AlertThermal - The thermal state is alert. |
151 | \li DeviceInfo.ErrorThermal - The thermal state is error. |
152 | \endlist |
153 | */ |
154 | QDeclarativeDeviceInfo::ThermalState QDeclarativeDeviceInfo::thermalState() const |
155 | { |
156 | return static_cast<ThermalState>(deviceInfo->thermalState()); |
157 | } |
158 | |
159 | /*! |
160 | \qmlmethod bool DeviceInfo::hasFeature(Feature feature) |
161 | |
162 | Returns true if the \a feature is supported, otherwise false. The following features can be |
163 | queried: |
164 | \list |
165 | \li DeviceInfo.BluetoothFeature - Bluetooth feature. |
166 | \li DeviceInfo.CameraFeature - Camera feature. |
167 | \li DeviceInfo.FmRadioFeature - Frequency modulation (FM) radio feature. |
168 | \li DeviceInfo.FmTransmitterFeature - Frequency modulation (FM) radio transmitter feature. |
169 | \li DeviceInfo.InfraredFeature - Infrared communication feature. |
170 | \li DeviceInfo.LedFeature - Light-emitting diode (LED) feature. |
171 | \li DeviceInfo.MemoryCardFeature - Memory card feature. |
172 | \li DeviceInfo.UsbFeature - Universal system bus (USB) feature. |
173 | \li DeviceInfo.VibrationFeature - Vibration feature. |
174 | \li DeviceInfo.WlanFeature - Wireless local area network (WLAN) feature. |
175 | \li DeviceInfo.SimFeature - Subscriber identity module (SIM) feature. |
176 | \li DeviceInfo.PositioningFeature - Positioning feature, e.g. Global Positioning System (GPS). |
177 | \li DeviceInfo.VideoOutFeature - Video out feature. |
178 | \li DeviceInfo.HapticsFeature - Haptics feature, the platform can provide audio and/or visual and/or vibration feedback. |
179 | \li DeviceInfo.NfcFeature - Near Field Communication (NFC) feature |
180 | \endlist |
181 | */ |
182 | bool QDeclarativeDeviceInfo::hasFeature(QDeclarativeDeviceInfo::Feature feature) const |
183 | { |
184 | return deviceInfo->hasFeature(feature: static_cast<QDeviceInfo::Feature>(feature)); |
185 | } |
186 | |
187 | /*! |
188 | \qmlmethod int DeviceInfo::imeiCount() |
189 | |
190 | Returns the count of available International Mobile Equipment Identity (IMEI) of the device. In |
191 | case of error, or the information is not available, -1 is returned. |
192 | */ |
193 | int QDeclarativeDeviceInfo::imeiCount() const |
194 | { |
195 | return deviceInfo->imeiCount(); |
196 | } |
197 | |
198 | /*! |
199 | \qmlmethod string DeviceInfo::imei(int interface) |
200 | |
201 | Returns the International Mobile Equipment Identity (IMEI) of the given \a interface on the device. |
202 | In case of error, or the information is not available, an empty string is returned. |
203 | */ |
204 | QString QDeclarativeDeviceInfo::imei(int interface) const |
205 | { |
206 | return deviceInfo->imei(interfaceNumber: interface); |
207 | } |
208 | |
209 | /*! |
210 | \qmlmethod string DeviceInfo::manufacturer() |
211 | |
212 | Returns the name of the manufacturer of this device, or the name of the vendor of the motherboard |
213 | as a fallback. In case of error, or the information is not available, an empty string is returned. |
214 | */ |
215 | QString QDeclarativeDeviceInfo::manufacturer() const |
216 | { |
217 | return deviceInfo->manufacturer(); |
218 | } |
219 | |
220 | /*! |
221 | \qmlmethod string DeviceInfo::model() |
222 | |
223 | Returns the model information of the device, e.g. N8, or the CPU architect as a fallback. In case |
224 | of error, or the information is not available, an empty string is returned. |
225 | */ |
226 | QString QDeclarativeDeviceInfo::model() const |
227 | { |
228 | return deviceInfo->model(); |
229 | } |
230 | |
231 | /*! |
232 | \qmlmethod string DeviceInfo::productName() |
233 | |
234 | Returns the internal product name of the device, e.g. RM-774. In case of error, or the information |
235 | is not available, an empty string is returned. |
236 | |
237 | For Linux, it returns the codename of the distribution if any. |
238 | */ |
239 | QString QDeclarativeDeviceInfo::productName() const |
240 | { |
241 | return deviceInfo->productName(); |
242 | } |
243 | |
244 | /*! |
245 | \qmlmethod string DeviceInfo::uniqueDeviceID() |
246 | |
247 | Returns a unique identifier for the device, or an empty string if on error or not available. |
248 | */ |
249 | QString QDeclarativeDeviceInfo::uniqueDeviceID() const |
250 | { |
251 | return deviceInfo->uniqueDeviceID(); |
252 | } |
253 | |
254 | /*! |
255 | \qmlmethod string DeviceInfo::version(Version type) |
256 | |
257 | Returns the version of \a type. In case of error, or the version is unknown, an empty string |
258 | is returned. The following versions can be queried: |
259 | \list |
260 | \li DeviceInfo.Os - Operating system version. For Linux, it returns the version of the |
261 | distribution if any. |
262 | \li DeviceInfo.Firmware - Version of (flashable) system as a whole. For Linux, it's the version |
263 | of the kernel. |
264 | \endlist |
265 | */ |
266 | QString QDeclarativeDeviceInfo::version(QDeclarativeDeviceInfo::Version type) const |
267 | { |
268 | return deviceInfo->version(type: static_cast<QDeviceInfo::Version>(type)); |
269 | } |
270 | |
271 | QT_END_NAMESPACE |
272 | |