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