File indexing completed on 2024-04-14 14:30:35

0001 /*
0002     SPDX-FileCopyrightText: 2011 Lamarque Souza <lamarque@kde.org>
0003     SPDX-FileCopyrightText: 2011 Will Stephenson <wstephenson@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "bluetoothdevice.h"
0009 #include "bluetoothdevice_p.h"
0010 #include "manager_p.h"
0011 
0012 #include "nmdebug.h"
0013 
0014 NetworkManager::BluetoothDevicePrivate::BluetoothDevicePrivate(const QString &path, BluetoothDevice *q)
0015     : ModemDevicePrivate(path, q)
0016 #ifdef NMQT_STATIC
0017     , btIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
0018 #else
0019     , btIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
0020 #endif
0021 {
0022 }
0023 
0024 NetworkManager::BluetoothDevice::BluetoothDevice(const QString &path, QObject *parent)
0025     : ModemDevice(*new BluetoothDevicePrivate(path, this), parent)
0026 {
0027     Q_D(BluetoothDevice);
0028 
0029     QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->btIface.staticInterfaceName(), path);
0030     if (!initialProperties.isEmpty()) {
0031         d->propertiesChanged(initialProperties);
0032     }
0033 
0034 }
0035 
0036 NetworkManager::BluetoothDevice::~BluetoothDevice()
0037 {
0038 }
0039 
0040 NetworkManager::Device::Type NetworkManager::BluetoothDevice::type() const
0041 {
0042     return NetworkManager::Device::Bluetooth;
0043 }
0044 
0045 void NetworkManager::BluetoothDevicePrivate::propertyChanged(const QString &property, const QVariant &value)
0046 {
0047     Q_Q(BluetoothDevice);
0048 
0049     if (property == QLatin1String("Name")) {
0050         name = value.toString();
0051         Q_EMIT q->nameChanged(name);
0052     } else if (property == QLatin1String("HwAddress")) {
0053         hardwareAddress = value.toString();
0054     } else if (property == QLatin1String("BtCapabilities")) {
0055         btCapabilities = static_cast<NetworkManager::BluetoothDevice::Capabilities>(value.toUInt());
0056     } else {
0057         DevicePrivate::propertyChanged(property, value);
0058     }
0059 }
0060 
0061 NetworkManager::BluetoothDevice::Capabilities NetworkManager::BluetoothDevice::bluetoothCapabilities() const
0062 {
0063     Q_D(const BluetoothDevice);
0064     return d->btCapabilities;
0065 }
0066 
0067 QString NetworkManager::BluetoothDevice::hardwareAddress() const
0068 {
0069     Q_D(const BluetoothDevice);
0070     return d->hardwareAddress;
0071 }
0072 
0073 QString NetworkManager::BluetoothDevice::name() const
0074 {
0075     Q_D(const BluetoothDevice);
0076     return d->name;
0077 }
0078 
0079 #include "moc_bluetoothdevice.cpp"
0080 #include "moc_bluetoothdevice_p.cpp"