File indexing completed on 2024-04-14 03:57:31

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 "activeconnection.h"
0008 #include "connection.h"
0009 
0010 #include <QDBusConnection>
0011 
0012 ActiveConnection::ActiveConnection(QObject *parent)
0013     : QObject(parent)
0014     , m_connection(QDBusObjectPath("/"))
0015     , m_default4(false)
0016     , m_default6(false)
0017     , m_dhcp4Config(QDBusObjectPath("/"))
0018     , m_dhcp6Config(QDBusObjectPath("/"))
0019     , m_ip4Config(QDBusObjectPath("/"))
0020     , m_ip6Config(QDBusObjectPath("/"))
0021     , m_master(QDBusObjectPath("/"))
0022     , m_specificObject(QDBusObjectPath("/"))
0023     , m_state(0)
0024     , m_vpn(false)
0025 {
0026 }
0027 
0028 ActiveConnection::~ActiveConnection()
0029 {
0030 }
0031 
0032 QDBusObjectPath ActiveConnection::connection() const
0033 {
0034     return m_connection;
0035 }
0036 
0037 bool ActiveConnection::default4() const
0038 {
0039     return m_default4;
0040 }
0041 
0042 bool ActiveConnection::default6() const
0043 {
0044     return m_default6;
0045 }
0046 
0047 QList<QDBusObjectPath> ActiveConnection::devices() const
0048 {
0049     return m_devices;
0050 }
0051 
0052 QDBusObjectPath ActiveConnection::dhcp4Config() const
0053 {
0054     return m_dhcp4Config;
0055 }
0056 
0057 QDBusObjectPath ActiveConnection::dhcp6Config() const
0058 {
0059     return m_dhcp6Config;
0060 }
0061 
0062 QString ActiveConnection::id() const
0063 {
0064     return m_id;
0065 }
0066 
0067 QDBusObjectPath ActiveConnection::ip4Config() const
0068 {
0069     return m_ip4Config;
0070 }
0071 
0072 QDBusObjectPath ActiveConnection::ip6Config() const
0073 {
0074     return m_ip6Config;
0075 }
0076 
0077 QDBusObjectPath ActiveConnection::master() const
0078 {
0079     return m_master;
0080 }
0081 
0082 QDBusObjectPath ActiveConnection::specificObject() const
0083 {
0084     return m_specificObject;
0085 }
0086 
0087 uint ActiveConnection::state() const
0088 {
0089     return m_state;
0090 }
0091 
0092 QString ActiveConnection::type() const
0093 {
0094     return m_type;
0095 }
0096 
0097 bool ActiveConnection::vpn() const
0098 {
0099     return m_vpn;
0100 }
0101 
0102 QString ActiveConnection::uuid() const
0103 {
0104     return m_uuid;
0105 }
0106 
0107 void ActiveConnection::addDevice(const QDBusObjectPath &device)
0108 {
0109     m_devices << device;
0110 }
0111 
0112 void ActiveConnection::removeDevice(const QDBusObjectPath &device)
0113 {
0114     m_devices.removeAll(device);
0115 }
0116 
0117 QString ActiveConnection::activeConnectionPath() const
0118 {
0119     return m_activeConnectionPath;
0120 }
0121 
0122 void ActiveConnection::setActiveConnectionPath(const QString &path)
0123 {
0124     m_activeConnectionPath = path;
0125 }
0126 
0127 void ActiveConnection::setConnection(const QDBusObjectPath &connection)
0128 {
0129     m_connection = connection;
0130 
0131     Connection *usedConnection = static_cast<Connection *>(QDBusConnection::sessionBus().objectRegisteredAt(connection.path()));
0132     if (usedConnection) {
0133         NMVariantMapMap settings = usedConnection->GetSettings();
0134         setId(settings.value(QLatin1String("connection")).value(QLatin1String("id")).toString());
0135         setUuid(settings.value(QLatin1String("connection")).value(QLatin1String("uuid")).toString());
0136         setType(settings.value(QLatin1String("connection")).value(QLatin1String("type")).toString());
0137     }
0138 }
0139 
0140 void ActiveConnection::setDefault4(bool default4)
0141 {
0142     m_default4 = default4;
0143 }
0144 
0145 void ActiveConnection::setDefault6(bool default6)
0146 {
0147     m_default6 = default6;
0148 }
0149 
0150 void ActiveConnection::setDhcp4Config(const QDBusObjectPath &dhcp4Config)
0151 {
0152     m_dhcp4Config = dhcp4Config;
0153 }
0154 
0155 void ActiveConnection::setDhcp6Config(const QDBusObjectPath &dhcp6Config)
0156 {
0157     m_dhcp6Config = dhcp6Config;
0158 }
0159 
0160 void ActiveConnection::setId(const QString &id)
0161 {
0162     m_id = id;
0163 }
0164 
0165 void ActiveConnection::setIpv4Config(const QDBusObjectPath &ipv4Config)
0166 {
0167     m_ip4Config = ipv4Config;
0168 }
0169 
0170 void ActiveConnection::setIpv6Config(const QDBusObjectPath &ipv6Config)
0171 {
0172     m_ip6Config = ipv6Config;
0173 }
0174 
0175 void ActiveConnection::setMaster(const QDBusObjectPath &master)
0176 {
0177     m_master = master;
0178 }
0179 
0180 void ActiveConnection::setSpecificObject(const QDBusObjectPath &specificObject)
0181 {
0182     m_specificObject = specificObject;
0183 }
0184 
0185 void ActiveConnection::setState(uint state)
0186 {
0187     m_state = state;
0188 }
0189 
0190 void ActiveConnection::setType(const QString &type)
0191 {
0192     m_type = type;
0193 
0194     if (type == QLatin1String("vpn")) {
0195         m_vpn = true;
0196     }
0197 }
0198 
0199 void ActiveConnection::setUuid(const QString &uuid)
0200 {
0201     m_uuid = uuid;
0202 }
0203 
0204 #include "moc_activeconnection.cpp"