summaryrefslogtreecommitdiffstats
path: root/src/imports/systeminfo/qdeclarativedeviceinfo.cpp
blob: ea8bbe6dbd8b8e7f74ce4aca2984372bf53f604d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtSystems module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativedeviceinfo_p.h"

QT_BEGIN_NAMESPACE

/*!
    \qmltype DeviceInfo
    \instantiates QDeclarativeDeviceInfo
    \inqmlmodule QtSystemInfo
    \ingroup qml-systeminfo
    \brief The DeviceInfo element provides various information about the device.
*/

/*!
    \internal
*/
QDeclarativeDeviceInfo::QDeclarativeDeviceInfo(QObject *parent)
    : QObject(parent)
    , deviceInfo(new QDeviceInfo(this))
    , isMonitorThermalState(false)
{
}

/*!
    \internal
 */
QDeclarativeDeviceInfo::~QDeclarativeDeviceInfo()
{
}

/*!
    \qmlproperty flag DeviceInfo::activatedLocks

    This property holds the activated locks. Available locks include:
    \list
    \li DeviceInfo.NoLock               - No lock.
    \li DeviceInfo.PinLock              - Device can be locked by PIN code or password.
    \li DeviceInfo.TouchOrKeyboardLock  - Device can be locked by touch or keyboard.
    \li DeviceInfo.UnknownLock          - Lock types requested but no result received yet.
    \endlist
*/
QDeclarativeDeviceInfo::LockTypeFlags QDeclarativeDeviceInfo::activatedLocks() const
{
    connect(deviceInfo, SIGNAL(activatedLocksChanged(QDeviceInfo::LockTypeFlags)),
            this, SIGNAL(activatedLocksChanged()), Qt::UniqueConnection);

    QDeviceInfo::LockTypeFlags locks(deviceInfo->activatedLocks());
    if (locks.testFlag(QDeviceInfo::UnknownLock))
       return QDeclarativeDeviceInfo::UnknownLock;
    LockTypeFlags declarativeLocks(NoLock);
    if (locks.testFlag(QDeviceInfo::PinLock))
        declarativeLocks |= PinLock;
    if (locks.testFlag(QDeviceInfo::TouchOrKeyboardLock))
        declarativeLocks |= TouchOrKeyboardLock;
    return declarativeLocks;
}

/*!
    \qmlproperty flag DeviceInfo::enabledLocks

    This property holds the enabled locks. Available locks include:
    \list
    \li DeviceInfo.NoLock               - No lock.
    \li DeviceInfo.PinLock              - Device can be locked by PIN code or password.
    \li DeviceInfo.TouchOrKeyboardLock  - Device can be locked by touch or keyboard.
    \li DeviceInfo.UnknownLock          - Lock types requested but no result received yet.
    \endlist
*/
QDeclarativeDeviceInfo::LockTypeFlags QDeclarativeDeviceInfo::enabledLocks() const
{
    connect(deviceInfo, SIGNAL(enabledLocksChanged(QDeviceInfo::LockTypeFlags)),
            this, SIGNAL(enabledLocksChanged()), Qt::UniqueConnection);

    QDeviceInfo::LockTypeFlags locks(deviceInfo->enabledLocks());
    if (locks.testFlag(QDeviceInfo::UnknownLock))
       return QDeclarativeDeviceInfo::UnknownLock;
    LockTypeFlags declarativeLocks(NoLock);
    if (locks.testFlag(QDeviceInfo::PinLock))
        declarativeLocks |= PinLock;
    if (locks.testFlag(QDeviceInfo::TouchOrKeyboardLock))
        declarativeLocks |= TouchOrKeyboardLock;
    return declarativeLocks;
}

/*!
    \qmlproperty bool DeviceInfo::monitorThermalState

    This property holds whether or not monitor the change of thermal state.
 */
bool QDeclarativeDeviceInfo::monitorThermalState() const
{
    return isMonitorThermalState;
}

void QDeclarativeDeviceInfo::setMonitorThermalState(bool monitor)
{
    if (monitor != isMonitorThermalState) {
        isMonitorThermalState = monitor;
        if (monitor) {
            connect(deviceInfo, SIGNAL(thermalStateChanged(QDeviceInfo::ThermalState)),
                    this, SIGNAL(thermalStateChanged()));
        } else {
            disconnect(deviceInfo, SIGNAL(thermalStateChanged(QDeviceInfo::ThermalState)),
                       this, SIGNAL(thermalStateChanged()));
        }
        emit monitorThermalStateChanged();
    }
}

/*!
    \qmlproperty enumeration DeviceInfo::thermalState

    This property holds the thermal state. Possible values are:
    \list
    \li DeviceInfo.UnknownThermal   - The thermal state is unknown.
    \li DeviceInfo.NormalThermal    - The thermal state is normal.
    \li DeviceInfo.WarningThermal   - The thermal state is warning.
    \li DeviceInfo.AlertThermal     - The thermal state is alert.
    \li DeviceInfo.ErrorThermal     - The thermal state is error.
    \endlist
*/
QDeclarativeDeviceInfo::ThermalState QDeclarativeDeviceInfo::thermalState() const
{
    return static_cast<ThermalState>(deviceInfo->thermalState());
}

/*!
    \qmlmethod bool DeviceInfo::hasFeature(Feature feature)

    Returns true if the \a feature is supported, otherwise false. The following features can be
    queried:
    \list
    \li DeviceInfo.BluetoothFeature      - Bluetooth feature.
    \li DeviceInfo.CameraFeature         - Camera feature.
    \li DeviceInfo.FmRadioFeature        - Frequency modulation (FM) radio feature.
    \li DeviceInfo.FmTransmitterFeature  - Frequency modulation (FM) radio transmitter feature.
    \li DeviceInfo.InfraredFeature       - Infrared communication feature.
    \li DeviceInfo.LedFeature            - Light-emitting diode (LED) feature.
    \li DeviceInfo.MemoryCardFeature     - Memory card feature.
    \li DeviceInfo.UsbFeature            - Universal system bus (USB) feature.
    \li DeviceInfo.VibrationFeature      - Vibration feature.
    \li DeviceInfo.WlanFeature           - Wireless local area network (WLAN) feature.
    \li DeviceInfo.SimFeature            - Subscriber identity module (SIM) feature.
    \li DeviceInfo.PositioningFeature    - Positioning feature, e.g. Global Positioning System (GPS).
    \li DeviceInfo.VideoOutFeature       - Video out feature.
    \li DeviceInfo.HapticsFeature        - Haptics feature, the platform can provide audio and/or visual and/or vibration feedback.
    \li DeviceInfo.NfcFeature            - Near Field Communication (NFC) feature
    \endlist
*/
bool QDeclarativeDeviceInfo::hasFeature(QDeclarativeDeviceInfo::Feature feature) const
{
    return deviceInfo->hasFeature(static_cast<QDeviceInfo::Feature>(feature));
}

/*!
    \qmlmethod int DeviceInfo::imeiCount()

    Returns the count of available International Mobile Equipment Identity (IMEI) of the device. In
    case of error, or the information is not available, -1 is returned.
*/
int QDeclarativeDeviceInfo::imeiCount() const
{
    return deviceInfo->imeiCount();
}

/*!
    \qmlmethod string DeviceInfo::imei(int interface)

    Returns the International Mobile Equipment Identity (IMEI) of the given \a interface on the device.
    In case of error, or the information is not available, an empty string is returned.
*/
QString QDeclarativeDeviceInfo::imei(int interface) const
{
    return deviceInfo->imei(interface);
}

/*!
    \qmlmethod string DeviceInfo::manufacturer()

    Returns the name of the manufacturer of this device, or the name of the vendor of the motherboard
    as a fallback. In case of error, or the information is not available, an empty string is returned.
*/
QString QDeclarativeDeviceInfo::manufacturer() const
{
    return deviceInfo->manufacturer();
}

/*!
    \qmlmethod string DeviceInfo::model()

    Returns the model information of the device, e.g. N8, or the CPU architect as a fallback. In case
    of error, or the information is not available, an empty string is returned.
*/
QString QDeclarativeDeviceInfo::model() const
{
    return deviceInfo->model();
}

/*!
    \qmlmethod string DeviceInfo::productName()

    Returns the internal product name of the device, e.g. RM-774. In case of error, or the information
    is not available, an empty string is returned.

    For Linux, it returns the codename of the distribution if any.
*/
QString QDeclarativeDeviceInfo::productName() const
{
    return deviceInfo->productName();
}

/*!
    \qmlmethod string DeviceInfo::uniqueDeviceID()

    Returns a unique identifier for the device, or an empty string if on error or not available.
*/
QString QDeclarativeDeviceInfo::uniqueDeviceID() const
{
    return deviceInfo->uniqueDeviceID();
}

/*!
    \qmlmethod string DeviceInfo::version(Version type)

    Returns the version of \a type. In case of error, or the version is unknown, an empty string
    is returned. The following versions can be queried:
    \list
    \li DeviceInfo.Os         - Operating system version. For Linux, it returns the version of the
                                distribution if any.
    \li DeviceInfo.Firmware   - Version of (flashable) system as a whole. For Linux, it's the version
                                of the kernel.
    \endlist
*/
QString QDeclarativeDeviceInfo::version(QDeclarativeDeviceInfo::Version type) const
{
    return deviceInfo->version(static_cast<QDeviceInfo::Version>(type));
}

QT_END_NAMESPACE