File indexing completed on 2024-04-28 11:47:44

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 "device.h"
0008 #include "activeconnection.h"
0009 
0010 #include <QDBusConnection>
0011 #include <QDBusMetaType>
0012 
0013 Device::Device(QObject *parent)
0014     : QObject(parent)
0015     , m_activeConnection(QDBusObjectPath("/"))
0016     , m_autoconnect(true)
0017     , m_capabilities(0)
0018     , m_deviceType(0)
0019     , m_dhcp4Config(QDBusObjectPath("/"))
0020     , m_dhcp6Config(QDBusObjectPath("/"))
0021     , m_firmwareMissing(false)
0022     , m_ip4Address(0)
0023     , m_ip4Config(QDBusObjectPath("/"))
0024     , m_ip6Config(QDBusObjectPath("/"))
0025     , m_managed(true)
0026     , m_mtu(0)
0027     , m_state(30)
0028 {
0029     qDBusRegisterMetaType<DeviceDBusStateReason>();
0030 }
0031 
0032 Device::~Device()
0033 {
0034 }
0035 
0036 QDBusObjectPath Device::activeConnection() const
0037 {
0038     return m_activeConnection;
0039 }
0040 
0041 bool Device::autoconnect() const
0042 {
0043     return m_autoconnect;
0044 }
0045 
0046 void Device::setAutoconnect(bool autoconnect)
0047 {
0048     m_autoconnect = autoconnect;
0049 }
0050 
0051 QList<QDBusObjectPath> Device::availableConnections() const
0052 {
0053     return m_availableConnections;
0054 }
0055 
0056 uint Device::capabilities() const
0057 {
0058     return m_capabilities;
0059 }
0060 
0061 QString Device::deviceInterface() const
0062 {
0063     if (m_deviceType == NetworkManager::Device::Ethernet) {
0064         return QLatin1String("org.kde.fakenetwork.Device.Wired");
0065     } else if (m_deviceType == NetworkManager::Device::Wifi) {
0066         return QLatin1String("org.kde.fakenetwork.Device.Wireless");
0067     }
0068 
0069     return QLatin1String("org.kde.fakenetwork.Device.Wired");
0070 }
0071 
0072 QString Device::devicePath() const
0073 {
0074     return m_devicePath;
0075 }
0076 
0077 void Device::setDevicePath(const QString &devicePath)
0078 {
0079     m_devicePath = devicePath;
0080 }
0081 
0082 uint Device::deviceType() const
0083 {
0084     return m_deviceType;
0085 }
0086 
0087 QDBusObjectPath Device::dhcp4Config() const
0088 {
0089     return m_dhcp4Config;
0090 }
0091 
0092 QDBusObjectPath Device::dhcp6Config() const
0093 {
0094     return m_dhcp6Config;
0095 }
0096 
0097 QString Device::driver() const
0098 {
0099     return m_driver;
0100 }
0101 
0102 QString Device::driverVersion() const
0103 {
0104     return m_driverVersion;
0105 }
0106 
0107 bool Device::firmwareMissing() const
0108 {
0109     return m_firmwareMissing;
0110 }
0111 
0112 QString Device::firmwareVersion() const
0113 {
0114     return m_firmwareVersion;
0115 }
0116 
0117 QString Device::interface() const
0118 {
0119     return m_interface;
0120 }
0121 
0122 int Device::ip4Address() const
0123 {
0124     return m_ip4Address;
0125 }
0126 
0127 QDBusObjectPath Device::ip4Config() const
0128 {
0129     return m_ip4Config;
0130 }
0131 
0132 QDBusObjectPath Device::ip6Config() const
0133 {
0134     return m_ip6Config;
0135 }
0136 
0137 QString Device::ipInterface() const
0138 {
0139     return m_ipInterface;
0140 }
0141 
0142 bool Device::managed() const
0143 {
0144     return m_managed;
0145 }
0146 
0147 uint Device::mtu() const
0148 {
0149     return m_mtu;
0150 }
0151 
0152 uint Device::state() const
0153 {
0154     return m_state;
0155 }
0156 
0157 DeviceDBusStateReason Device::stateReason() const
0158 {
0159     return m_stateReason;
0160 }
0161 
0162 QString Device::udi() const
0163 {
0164     return m_udi;
0165 }
0166 
0167 void Device::addAvailableConnection(const QDBusObjectPath &availableConnection)
0168 {
0169     m_availableConnections << availableConnection;
0170 }
0171 
0172 void Device::removeAvailableConnection(const QDBusObjectPath &availableConnection)
0173 {
0174     m_availableConnections.removeAll(availableConnection);
0175 }
0176 
0177 void Device::setActiveConnection(const QString &activeConnection)
0178 {
0179     m_activeConnection = QDBusObjectPath(activeConnection);
0180 }
0181 
0182 void Device::setCapabilities(uint capabilities)
0183 {
0184     m_capabilities = capabilities;
0185 }
0186 
0187 void Device::setDeviceType(uint deviceType)
0188 {
0189     m_deviceType = deviceType;
0190 }
0191 
0192 void Device::setDhcp4Config(const QString &config)
0193 {
0194     m_dhcp4Config = QDBusObjectPath(config);
0195 }
0196 
0197 void Device::setDhcp6Config(const QString &config)
0198 {
0199     m_dhcp6Config = QDBusObjectPath(config);
0200 }
0201 
0202 void Device::setDriver(const QString &driver)
0203 {
0204     m_driver = driver;
0205 }
0206 
0207 void Device::setDriverVersion(const QString &driverVersion)
0208 {
0209     m_driverVersion = driverVersion;
0210 }
0211 
0212 void Device::setFirmwareMissing(bool firmwareMissing)
0213 {
0214     m_firmwareMissing = firmwareMissing;
0215 }
0216 
0217 void Device::setFirmwareVersion(const QString &firmwareVersion)
0218 {
0219     m_firmwareVersion = firmwareVersion;
0220 }
0221 
0222 void Device::setInterface(const QString &interface)
0223 {
0224     m_interface = interface;
0225 }
0226 
0227 void Device::setIp4Config(const QString &config)
0228 {
0229     m_ip4Config = QDBusObjectPath(config);
0230 }
0231 
0232 void Device::setIp6Config(const QString &config)
0233 {
0234     m_ip6Config = QDBusObjectPath(config);
0235 }
0236 
0237 void Device::setIpv4Address(int address)
0238 {
0239     m_ip4Address = address;
0240 }
0241 
0242 void Device::setIpInterface(const QString &interface)
0243 {
0244     m_ipInterface = interface;
0245 }
0246 
0247 void Device::setManaged(bool managed)
0248 {
0249     m_managed = managed;
0250 }
0251 
0252 void Device::setMtu(uint mtu)
0253 {
0254     m_mtu = mtu;
0255 }
0256 
0257 void Device::setState(uint state)
0258 {
0259     uint previousState = m_state;
0260     m_state = state;
0261     m_stateReason.state = state;
0262 
0263     QDBusMessage message = QDBusMessage::createSignal(m_devicePath, QLatin1String("org.kde.fakenetwork.Device"), QLatin1String("StateChanged"));
0264     message << previousState << state << m_stateReason.reason;
0265     QDBusConnection::sessionBus().send(message);
0266 }
0267 
0268 void Device::setStateReason(const DeviceDBusStateReason &reason)
0269 {
0270     m_stateReason = reason;
0271 }
0272 
0273 void Device::setUdi(const QString &udi)
0274 {
0275     m_udi = udi;
0276 }
0277 
0278 void Device::Disconnect()
0279 {
0280     // TODO
0281 }
0282 
0283 #include "moc_device.cpp"