| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 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:LGPL$ |
| 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 https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://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 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qdeviceinfo.h" |
| 41 | |
| 42 | #if defined(Q_OS_LINUX) |
| 43 | # include "linux/qdeviceinfo_linux_p.h" |
| 44 | #elif defined(Q_OS_WIN) |
| 45 | # include "windows/qdeviceinfo_win_p.h" |
| 46 | #elif defined(Q_OS_MAC) |
| 47 | # include "mac/qdeviceinfo_mac_p.h" |
| 48 | #else |
| 49 | QT_BEGIN_NAMESPACE |
| 50 | class QDeviceInfoPrivate |
| 51 | { |
| 52 | public: |
| 53 | QDeviceInfoPrivate(QDeviceInfo *) {} |
| 54 | |
| 55 | bool hasFeature(QDeviceInfo::Feature) { return false; } |
| 56 | int imeiCount() { return -1; } |
| 57 | QDeviceInfo::LockTypeFlags activatedLocks() { return QDeviceInfo::NoLock; } |
| 58 | QDeviceInfo::LockTypeFlags enabledLocks() { return QDeviceInfo::NoLock; } |
| 59 | QDeviceInfo::ThermalState thermalState() { return QDeviceInfo::UnknownThermal; } |
| 60 | QString imei(int) { return QString(); } |
| 61 | QString manufacturer() { return QString(); } |
| 62 | QString model() { return QString(); } |
| 63 | QString productName() { return QString(); } |
| 64 | QString uniqueDeviceID() { return QString(); } |
| 65 | QString version(QDeviceInfo::Version) { return QString(); } |
| 66 | QString operatingSystemName() { return QString(); } |
| 67 | bool currentBluetoothPowerState() { return false; } |
| 68 | QString boardName() { return QString(); } |
| 69 | }; |
| 70 | QT_END_NAMESPACE |
| 71 | #endif |
| 72 | |
| 73 | #include <QtCore/qmetaobject.h> |
| 74 | |
| 75 | QT_BEGIN_NAMESPACE |
| 76 | |
| 77 | /*! |
| 78 | \class QDeviceInfo |
| 79 | \inmodule QtSystemInfo |
| 80 | \brief The QDeviceInfo class provides various information of the system. |
| 81 | \ingroup systeminfo |
| 82 | */ |
| 83 | |
| 84 | /*! |
| 85 | \enum QDeviceInfo::Feature |
| 86 | This enum describes the features of the device. |
| 87 | |
| 88 | \value BluetoothFeature Bluetooth feature. |
| 89 | \value CameraFeature Camera feature. |
| 90 | \value FmRadioFeature Frequency modulation (FM) radio feature. |
| 91 | \value FmTransmitterFeature Frequency modulation (FM) radio transmitter feature. |
| 92 | \value InfraredFeature Infrared communication feature. |
| 93 | \value LedFeature Light-emitting diode (LED) feature. |
| 94 | \value MemoryCardFeature Memory card feature. |
| 95 | \value UsbFeature Universal system bus (USB) feature. |
| 96 | \value VibrationFeature Vibration feature. |
| 97 | \value WlanFeature Wireless local area network (WLAN) feature. |
| 98 | \value SimFeature Subscriber identity module (SIM) feature. |
| 99 | \value PositioningFeature Positioning feature, e.g. Global Positioning System (GPS). |
| 100 | \value VideoOutFeature Video out feature. |
| 101 | \value HapticsFeature Haptics feature, the platform can provide audio and/or visual and/or vibration feedback. |
| 102 | \value NfcFeature Near Field Communication (NFC) feature. |
| 103 | */ |
| 104 | |
| 105 | /*! |
| 106 | \enum QDeviceInfo::LockType |
| 107 | This enum describes lock type on the device. |
| 108 | |
| 109 | \value NoLock No lock. |
| 110 | \value PinLock Device can be locked by PIN code or password. |
| 111 | \value TouchOrKeyboardLock Device can be locked by touch or keyboard. |
| 112 | \value UnknownLock lock types requested but no result received yet. |
| 113 | */ |
| 114 | |
| 115 | /*! |
| 116 | \enum QDeviceInfo::ThermalState |
| 117 | This enum describes the thermal state: |
| 118 | |
| 119 | \value UnknownThermal The thermal state is unknown. |
| 120 | \value NormalThermal The thermal state is normal. |
| 121 | \value WarningThermal The thermal state is warning. |
| 122 | \value AlertThermal The thermal state is alert. |
| 123 | \value ErrorThermal The thermal state is error. |
| 124 | */ |
| 125 | |
| 126 | /*! |
| 127 | \enum QDeviceInfo::Version |
| 128 | This enum describes the version component. |
| 129 | |
| 130 | \value Os Operating system version. For Linux, it returns the version of the |
| 131 | distribution if any. |
| 132 | \value Firmware Version of (flashable) system as a whole. For Linux, it's the version |
| 133 | of the kernel. |
| 134 | */ |
| 135 | |
| 136 | /*! |
| 137 | \fn void QDeviceInfo::activatedLocksChanged(QDeviceInfo::LockTypeFlags types) |
| 138 | |
| 139 | This signal is emitted when the activated locks have changed to \a types. |
| 140 | */ |
| 141 | |
| 142 | /*! |
| 143 | \fn void QDeviceInfo::enabledLocksChanged(QDeviceInfo::LockTypeFlags types) |
| 144 | |
| 145 | This signal is emitted when the enabled locks have changed to \a types. |
| 146 | */ |
| 147 | |
| 148 | /*! |
| 149 | \fn void QDeviceInfo::thermalStateChanged(QDeviceInfo::ThermalState state) |
| 150 | |
| 151 | This signal is emitted when the thermal state has changed to \a state. |
| 152 | */ |
| 153 | |
| 154 | /*! |
| 155 | Constructs a QDeviceInfo object with the given \a parent. |
| 156 | */ |
| 157 | QDeviceInfo::QDeviceInfo(QObject *parent) |
| 158 | : QObject(parent) |
| 159 | , d_ptr(new QDeviceInfoPrivate(this)) |
| 160 | { |
| 161 | } |
| 162 | |
| 163 | /*! |
| 164 | Destroys the object |
| 165 | */ |
| 166 | QDeviceInfo::~QDeviceInfo() |
| 167 | { |
| 168 | delete d_ptr; |
| 169 | } |
| 170 | |
| 171 | /*! |
| 172 | \property QDeviceInfo::activatedLocks |
| 173 | \brief The activated lock types. |
| 174 | |
| 175 | The current activated lock types of the device. It suggests that these lock types are also |
| 176 | enabled. |
| 177 | */ |
| 178 | QDeviceInfo::LockTypeFlags QDeviceInfo::activatedLocks() const |
| 179 | { |
| 180 | return d_ptr->activatedLocks(); |
| 181 | } |
| 182 | |
| 183 | /*! |
| 184 | \property QDeviceInfo::enabledLocks |
| 185 | \brief The enabled lock types. |
| 186 | |
| 187 | The current lock types that are enabled on the device. Note that it doesn't mean the device is |
| 188 | currently locked. |
| 189 | */ |
| 190 | QDeviceInfo::LockTypeFlags QDeviceInfo::enabledLocks() const |
| 191 | { |
| 192 | return d_ptr->enabledLocks(); |
| 193 | } |
| 194 | |
| 195 | /*! |
| 196 | \property QDeviceInfo::thermalState |
| 197 | \brief The thermal state. |
| 198 | |
| 199 | The current thermal state of the device. If there are more than one thermal zone devices available, |
| 200 | the state of the most critical one is reported. |
| 201 | */ |
| 202 | QDeviceInfo::ThermalState QDeviceInfo::thermalState() const |
| 203 | { |
| 204 | return d_ptr->thermalState(); |
| 205 | } |
| 206 | |
| 207 | /*! |
| 208 | Returns true if the \a feature is supported, otherwise false. |
| 209 | */ |
| 210 | bool QDeviceInfo::hasFeature(QDeviceInfo::Feature feature) const |
| 211 | { |
| 212 | return d_ptr->hasFeature(feature); |
| 213 | } |
| 214 | |
| 215 | /*! |
| 216 | Returns the count of available International Mobile Equipment Identity (IMEI) of the device. In |
| 217 | case of error, or the information is not available, -1 is returned. |
| 218 | */ |
| 219 | int QDeviceInfo::imeiCount() const |
| 220 | { |
| 221 | return d_ptr->imeiCount(); |
| 222 | } |
| 223 | |
| 224 | /*! |
| 225 | Returns the International Mobile Equipment Identity (IMEI) of the given \a interfaceNumber on the device. |
| 226 | In case of error, or the information is not available, an empty string is returned. |
| 227 | */ |
| 228 | QString QDeviceInfo::imei(int interfaceNumber) const |
| 229 | { |
| 230 | return d_ptr->imei(interfaceNumber); |
| 231 | } |
| 232 | |
| 233 | /*! |
| 234 | Returns the name of the manufacturer of this device, or the name of the vendor of the motherboard |
| 235 | as a fallback. In case of error, or the information is not available, an empty string is returned. |
| 236 | */ |
| 237 | QString QDeviceInfo::manufacturer() const |
| 238 | { |
| 239 | return d_ptr->manufacturer(); |
| 240 | } |
| 241 | |
| 242 | /*! |
| 243 | Returns the model information of the device, e.g. N8, or the CPU architect as a fallback. In case |
| 244 | of error, or the information is not available, an empty string is returned. |
| 245 | */ |
| 246 | QString QDeviceInfo::model() const |
| 247 | { |
| 248 | return d_ptr->model(); |
| 249 | } |
| 250 | |
| 251 | /*! |
| 252 | Returns the internal product name of the device, e.g. RM-774. In case of error, or the information |
| 253 | is not available, an empty string is returned. |
| 254 | |
| 255 | For Linux, it returns the codename of the distribution if any. |
| 256 | */ |
| 257 | QString QDeviceInfo::productName() const |
| 258 | { |
| 259 | return d_ptr->productName(); |
| 260 | } |
| 261 | |
| 262 | /*! |
| 263 | Returns a unique identifier for the device, or an empty string if on error or not available. |
| 264 | */ |
| 265 | QString QDeviceInfo::uniqueDeviceID() const |
| 266 | { |
| 267 | return d_ptr->uniqueDeviceID(); |
| 268 | } |
| 269 | |
| 270 | /*! |
| 271 | Returns the version of \a type. In case of error, or the version is unknown, an empty string |
| 272 | is returned. |
| 273 | */ |
| 274 | QString QDeviceInfo::version(QDeviceInfo::Version type) const |
| 275 | { |
| 276 | return d_ptr->version(type); |
| 277 | } |
| 278 | |
| 279 | /*! |
| 280 | Returns the current bluetooth power state. |
| 281 | */ |
| 282 | bool QDeviceInfo::currentBluetoothPowerState() |
| 283 | { |
| 284 | return d_ptr->currentBluetoothPowerState(); |
| 285 | } |
| 286 | |
| 287 | /*! |
| 288 | Returns the name for the operating system for the device, or an empty string if an error or not available. |
| 289 | */ |
| 290 | QString QDeviceInfo::operatingSystemName() const |
| 291 | { |
| 292 | return d_ptr->operatingSystemName(); |
| 293 | } |
| 294 | |
| 295 | /*! |
| 296 | Returns the board name for the device, or an empty string if an error or not available. |
| 297 | */ |
| 298 | QString QDeviceInfo::boardName() const |
| 299 | { |
| 300 | return d_ptr->boardName(); |
| 301 | } |
| 302 | |
| 303 | extern QMetaMethod proxyToSourceSignal(const QMetaMethod &, QObject *); |
| 304 | |
| 305 | /*! |
| 306 | \internal |
| 307 | */ |
| 308 | void QDeviceInfo::connectNotify(const QMetaMethod &signalSig) |
| 309 | { |
| 310 | #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(Q_OS_MAC) |
| 311 | QMetaMethod sourceSignal = proxyToSourceSignal(signalSig, reinterpret_cast<QObject *>(d_ptr)); |
| 312 | connect(reinterpret_cast<QObject *>(d_ptr), sourceSignal, this, signalSig, Qt::UniqueConnection); |
| 313 | #else |
| 314 | Q_UNUSED(signalSig) |
| 315 | #endif |
| 316 | } |
| 317 | |
| 318 | /*! |
| 319 | \internal |
| 320 | */ |
| 321 | void QDeviceInfo::disconnectNotify(const QMetaMethod &signalSig) |
| 322 | { |
| 323 | #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(Q_OS_MAC) |
| 324 | // We can only disconnect with the private implementation, when there is no receivers for the signal. |
| 325 | if (isSignalConnected(signalSig)) |
| 326 | return; |
| 327 | |
| 328 | QMetaMethod sourceSignal = proxyToSourceSignal(signalSig, reinterpret_cast<QObject *>(d_ptr)); |
| 329 | disconnect(reinterpret_cast<QObject *>(d_ptr), sourceSignal, this, signalSig); |
| 330 | #else |
| 331 | Q_UNUSED(signalSig) |
| 332 | #endif |
| 333 | } |
| 334 | |
| 335 | QT_END_NAMESPACE |