File indexing completed on 2024-04-21 03:59:59
0001 /* 0002 SPDX-FileCopyrightText: 2014 Jan Grulich <jgrulich@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "wirelessdevice.h" 0008 0009 #include <QDBusConnection> 0010 0011 WirelessDevice::WirelessDevice(QObject *parent) 0012 : Device(parent) 0013 , m_activeAccessPoint(QDBusObjectPath("/")) 0014 , m_bitrate(0) 0015 , m_mode(2) 0016 , m_wirelessCapabilities(0) 0017 , m_accessPointCounter(0) 0018 { 0019 } 0020 0021 WirelessDevice::~WirelessDevice() 0022 { 0023 for (auto it = m_accessPoints.cbegin(); it != m_accessPoints.cend(); ++it) { 0024 const QDBusObjectPath &ap = it.key(); 0025 QDBusConnection::sessionBus().unregisterObject(ap.path()); 0026 Q_EMIT AccessPointRemoved(ap); 0027 } 0028 0029 qDeleteAll(m_accessPoints); 0030 0031 QVariantMap map; 0032 map.insert(QLatin1String("AvailableConnections"), QVariant::fromValue<QList<QDBusObjectPath>>(QList<QDBusObjectPath>())); 0033 Q_EMIT PropertiesChanged(map); 0034 } 0035 0036 QList<QDBusObjectPath> WirelessDevice::accessPoints() const 0037 { 0038 return m_accessPoints.keys(); 0039 } 0040 0041 QDBusObjectPath WirelessDevice::activeAccessPoint() const 0042 { 0043 return m_activeAccessPoint; 0044 } 0045 0046 uint WirelessDevice::bitrate() const 0047 { 0048 return m_bitrate; 0049 } 0050 0051 QString WirelessDevice::hwAddress() const 0052 { 0053 return m_hwAddress; 0054 } 0055 0056 uint WirelessDevice::mode() const 0057 { 0058 return m_mode; 0059 } 0060 0061 QString WirelessDevice::permHwAddress() const 0062 { 0063 return m_permHwAddress; 0064 } 0065 0066 uint WirelessDevice::wirelessCapabilities() const 0067 { 0068 return m_wirelessCapabilities; 0069 } 0070 0071 void WirelessDevice::addAccessPoint(AccessPoint *accessPoint) 0072 { 0073 QString newApPath = QString("/org/kde/fakenetwork/AccessPoints/") + QString::number(m_accessPointCounter++); 0074 accessPoint->setAccessPointPath(newApPath); 0075 m_accessPoints.insert(QDBusObjectPath(newApPath), accessPoint); 0076 QDBusConnection::sessionBus().registerObject(newApPath, accessPoint, QDBusConnection::ExportScriptableContents); 0077 0078 Q_EMIT AccessPointAdded(QDBusObjectPath(newApPath)); 0079 } 0080 0081 void WirelessDevice::removeAccessPoint(AccessPoint *accessPoint) 0082 { 0083 m_accessPoints.remove(QDBusObjectPath(accessPoint->accessPointPath())); 0084 0085 Q_EMIT AccessPointRemoved(QDBusObjectPath(accessPoint->accessPointPath())); 0086 } 0087 0088 void WirelessDevice::setActiveAccessPoint(const QString &activeAccessPoint) 0089 { 0090 m_activeAccessPoint = QDBusObjectPath(activeAccessPoint); 0091 } 0092 0093 void WirelessDevice::setBitrate(uint bitrate) 0094 { 0095 m_bitrate = bitrate; 0096 } 0097 0098 void WirelessDevice::setHwAddress(const QString &hwAddress) 0099 { 0100 m_hwAddress = hwAddress; 0101 } 0102 0103 void WirelessDevice::setMode(uint mode) 0104 { 0105 m_mode = mode; 0106 } 0107 0108 void WirelessDevice::setPermHwAddress(const QString &permHwAddress) 0109 { 0110 m_permHwAddress = permHwAddress; 0111 } 0112 0113 void WirelessDevice::setState(uint state) 0114 { 0115 Device::setState(state); 0116 0117 // TODO: set speed, etc. 0118 } 0119 0120 void WirelessDevice::setWirelessCapabilities(uint capabilities) 0121 { 0122 m_wirelessCapabilities = capabilities; 0123 } 0124 0125 QList<QDBusObjectPath> WirelessDevice::GetAccessPoints() 0126 { 0127 return m_accessPoints.keys(); 0128 } 0129 0130 QList<QDBusObjectPath> WirelessDevice::GetAllAccessPoints() 0131 { 0132 return m_accessPoints.keys(); 0133 } 0134 0135 void WirelessDevice::RequestScan(const QVariantMap &options) 0136 { 0137 Q_UNUSED(options); 0138 } 0139 0140 #include "moc_wirelessdevice.cpp"