|
| 1 | +// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 | + |
| 5 | +#include "networkdbusproxy.h" |
| 6 | + |
| 7 | +#include <QMetaObject> |
| 8 | +#include <QDBusConnection> |
| 9 | +#include <QDBusInterface> |
| 10 | +#include <QDBusPendingReply> |
| 11 | +#include <QDebug> |
| 12 | + |
| 13 | +#include <DDBusInterface> |
| 14 | + |
| 15 | +const QString NetworkService = QStringLiteral("org.deepin.dde.Network1"); |
| 16 | +const QString NetworkPath = QStringLiteral("/org/deepin/dde/Network1"); |
| 17 | +const QString NetworkInterface = QStringLiteral("org.deepin.dde.Network1"); |
| 18 | + |
| 19 | +const QString ProxyChainsService = QStringLiteral("org.deepin.dde.Network1"); |
| 20 | +const QString ProxyChainsPath = QStringLiteral("/org/deepin/dde/Network1/ProxyChains"); |
| 21 | +const QString ProxyChainsInterface = QStringLiteral("org.deepin.dde.Network1.ProxyChains"); |
| 22 | + |
| 23 | +const QString AirplaneModeService = QStringLiteral("org.deepin.dde.AirplaneMode1"); |
| 24 | +const QString AirplaneModePath = QStringLiteral("/org/deepin/dde/AirplaneMode1"); |
| 25 | +const QString AirplaneModeInterface = QStringLiteral("org.deepin.dde.AirplaneMode1"); |
| 26 | + |
| 27 | +const QString PropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); |
| 28 | +const QString PropertiesChanged = QStringLiteral("PropertiesChanged"); |
| 29 | +using namespace dde::network; |
| 30 | + |
| 31 | +NetworkDBusProxy::NetworkDBusProxy(QObject *parent) |
| 32 | + : QObject(parent) |
| 33 | + , m_networkInter(new Dtk::Core::DDBusInterface(NetworkService, NetworkPath, NetworkInterface, QDBusConnection::sessionBus(), this)) |
| 34 | + , m_proxyChainsInter(new Dtk::Core::DDBusInterface(ProxyChainsService, ProxyChainsPath, ProxyChainsInterface, QDBusConnection::sessionBus(), this)) |
| 35 | + , m_airplaneModeInter(new Dtk::Core::DDBusInterface(AirplaneModeService, AirplaneModePath, AirplaneModeInterface, QDBusConnection::systemBus(), this)) |
| 36 | +{ |
| 37 | +} |
| 38 | + |
| 39 | +// networkInter property |
| 40 | +QString NetworkDBusProxy::activeConnections() |
| 41 | +{ |
| 42 | + return qvariant_cast<QString>(m_networkInter->property("ActiveConnections")); |
| 43 | +} |
| 44 | + |
| 45 | +QString NetworkDBusProxy::connections() |
| 46 | +{ |
| 47 | + return qvariant_cast<QString>(m_networkInter->property("Connections")); |
| 48 | +} |
| 49 | + |
| 50 | +uint NetworkDBusProxy::connectivity() |
| 51 | +{ |
| 52 | + return qvariant_cast<uint>(m_networkInter->property("Connectivity")); |
| 53 | +} |
| 54 | + |
| 55 | +QString NetworkDBusProxy::devices() |
| 56 | +{ |
| 57 | + return qvariant_cast<QString>(m_networkInter->property("Devices")); |
| 58 | +} |
| 59 | + |
| 60 | +bool NetworkDBusProxy::networkingEnabled() |
| 61 | +{ |
| 62 | + return qvariant_cast<bool>(m_networkInter->property("NetworkingEnabled")); |
| 63 | +} |
| 64 | +void NetworkDBusProxy::setNetworkingEnabled(bool value) |
| 65 | +{ |
| 66 | + m_networkInter->setProperty("NetworkingEnabled", QVariant::fromValue(value)); |
| 67 | +} |
| 68 | + |
| 69 | +uint NetworkDBusProxy::state() |
| 70 | +{ |
| 71 | + return qvariant_cast<uint>(m_networkInter->property("State")); |
| 72 | +} |
| 73 | + |
| 74 | +bool NetworkDBusProxy::vpnEnabled() |
| 75 | +{ |
| 76 | + return qvariant_cast<bool>(m_networkInter->property("VpnEnabled")); |
| 77 | +} |
| 78 | +void NetworkDBusProxy::setVpnEnabled(bool value) |
| 79 | +{ |
| 80 | + m_networkInter->setProperty("VpnEnabled", QVariant::fromValue(value)); |
| 81 | +} |
| 82 | + |
| 83 | +QString NetworkDBusProxy::wirelessAccessPoints() |
| 84 | +{ |
| 85 | + return qvariant_cast<QString>(m_networkInter->property("WirelessAccessPoints")); |
| 86 | +} |
| 87 | +// proxyChains property |
| 88 | +QString NetworkDBusProxy::iP() |
| 89 | +{ |
| 90 | + return qvariant_cast<QString>(m_proxyChainsInter->property("IP")); |
| 91 | +} |
| 92 | + |
| 93 | +QString NetworkDBusProxy::password() |
| 94 | +{ |
| 95 | + return qvariant_cast<QString>(m_proxyChainsInter->property("Password")); |
| 96 | +} |
| 97 | + |
| 98 | +uint NetworkDBusProxy::port() |
| 99 | +{ |
| 100 | + return qvariant_cast<uint>(m_proxyChainsInter->property("Port")); |
| 101 | +} |
| 102 | + |
| 103 | +QString NetworkDBusProxy::type() |
| 104 | +{ |
| 105 | + return qvariant_cast<QString>(m_proxyChainsInter->property("Type")); |
| 106 | +} |
| 107 | + |
| 108 | +QString NetworkDBusProxy::user() |
| 109 | +{ |
| 110 | + return qvariant_cast<QString>(m_proxyChainsInter->property("User")); |
| 111 | +} |
| 112 | + |
| 113 | +bool NetworkDBusProxy::enabled() |
| 114 | +{ |
| 115 | + return qvariant_cast<bool>(m_airplaneModeInter->property("Enabled")); |
| 116 | +} |
| 117 | + |
| 118 | +void NetworkDBusProxy::ShowPage(const QString &url) |
| 119 | +{ |
| 120 | + QDBusMessage message = QDBusMessage::createMethodCall("org.deepin.dde.ControlCenter1", "/org/deepin/dde/ControlCenter1", "org.deepin.dde.ControlCenter1", "ShowPage"); |
| 121 | + message << QVariant::fromValue(url); |
| 122 | + QDBusConnection::sessionBus().asyncCall(message); |
| 123 | +} |
| 124 | +// networkInter property |
| 125 | +void NetworkDBusProxy::EnableDevice(const QDBusObjectPath &devPath, bool enabled) |
| 126 | +{ |
| 127 | + m_networkInter->asyncCall(QStringLiteral("EnableDevice"), QVariant::fromValue(devPath), QVariant::fromValue(enabled)); |
| 128 | +} |
| 129 | + |
| 130 | +QString NetworkDBusProxy::GetProxyMethod() |
| 131 | +{ |
| 132 | + return QDBusPendingReply<QString>(m_networkInter->asyncCall(QStringLiteral("GetProxyMethod"))); |
| 133 | +} |
| 134 | + |
| 135 | +void NetworkDBusProxy::SetProxyMethod(const QString &proxyMode) |
| 136 | +{ |
| 137 | + m_networkInter->asyncCall(QStringLiteral("SetProxyMethod"), QVariant::fromValue(proxyMode)); |
| 138 | +} |
| 139 | + |
| 140 | +void NetworkDBusProxy::SetProxyMethod(const QString &proxyMode, QObject *receiver, const char *member) |
| 141 | +{ |
| 142 | + QList<QVariant> argumentList; |
| 143 | + argumentList << QVariant::fromValue(proxyMode); |
| 144 | + m_networkInter->callWithCallback(QStringLiteral("SetProxyMethod"), argumentList, receiver, member); |
| 145 | +} |
| 146 | + |
| 147 | +QString NetworkDBusProxy::GetProxyIgnoreHosts() |
| 148 | +{ |
| 149 | + return QDBusPendingReply<QString>(m_networkInter->asyncCall(QStringLiteral("GetProxyIgnoreHosts"))); |
| 150 | +} |
| 151 | + |
| 152 | +void NetworkDBusProxy::SetProxyIgnoreHosts(const QString &ignoreHosts) |
| 153 | +{ |
| 154 | + m_networkInter->asyncCall(QStringLiteral("SetProxyIgnoreHosts"), QVariant::fromValue(ignoreHosts)); |
| 155 | +} |
| 156 | + |
| 157 | +void NetworkDBusProxy::SetProxyIgnoreHosts(const QString &ignoreHosts, QObject *receiver, const char *member) |
| 158 | +{ |
| 159 | + QList<QVariant> argumentList; |
| 160 | + argumentList << QVariant::fromValue(ignoreHosts); |
| 161 | + m_networkInter->callWithCallback(QStringLiteral("SetProxyIgnoreHosts"), argumentList, receiver, member); |
| 162 | +} |
| 163 | + |
| 164 | +QString NetworkDBusProxy::GetAutoProxy() |
| 165 | +{ |
| 166 | + return QDBusPendingReply<QString>(m_networkInter->asyncCall(QStringLiteral("GetAutoProxy"))); |
| 167 | +} |
| 168 | + |
| 169 | +void NetworkDBusProxy::SetAutoProxy(const QString &proxyAuto) |
| 170 | +{ |
| 171 | + m_networkInter->asyncCall(QStringLiteral("SetAutoProxy"), QVariant::fromValue(proxyAuto)); |
| 172 | +} |
| 173 | + |
| 174 | +void NetworkDBusProxy::SetAutoProxy(const QString &proxyAuto, QObject *receiver, const char *member) |
| 175 | +{ |
| 176 | + QList<QVariant> argumentList; |
| 177 | + argumentList << QVariant::fromValue(proxyAuto); |
| 178 | + m_networkInter->callWithCallback(QStringLiteral("SetAutoProxy"), argumentList, receiver, member); |
| 179 | +} |
| 180 | + |
| 181 | +QStringList NetworkDBusProxy::GetProxy(const QString &proxyType) |
| 182 | +{ |
| 183 | + QStringList out; |
| 184 | + QDBusMessage reply = m_networkInter->call(QDBus::Block, QStringLiteral("GetProxy"), QVariant::fromValue(proxyType)); |
| 185 | + if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 2) { |
| 186 | + out << qdbus_cast<QString>(reply.arguments().at(0)); |
| 187 | + out << qdbus_cast<QString>(reply.arguments().at(1)); |
| 188 | + } |
| 189 | + return out; |
| 190 | +} |
| 191 | + |
| 192 | +void NetworkDBusProxy::SetProxy(const QString &proxyType, const QString &host, const QString &port) |
| 193 | +{ |
| 194 | + m_networkInter->asyncCall(QStringLiteral("SetProxy"), QVariant::fromValue(proxyType), QVariant::fromValue(host), QVariant::fromValue(port)); |
| 195 | +} |
| 196 | + |
| 197 | +void NetworkDBusProxy::SetProxy(const QString &proxyType, const QString &host, const QString &port, QObject *receiver, const char *member) |
| 198 | +{ |
| 199 | + QList<QVariant> argumentList; |
| 200 | + argumentList << QVariant::fromValue(proxyType) << QVariant::fromValue(host) << QVariant::fromValue(port); |
| 201 | + m_networkInter->callWithCallback(QStringLiteral("SetProxy"), argumentList, receiver, member); |
| 202 | +} |
| 203 | + |
| 204 | +QString NetworkDBusProxy::GetActiveConnectionInfo() |
| 205 | +{ |
| 206 | + return QDBusPendingReply<QString>(m_networkInter->asyncCall(QStringLiteral("GetActiveConnectionInfo"))); |
| 207 | +} |
| 208 | + |
| 209 | +QDBusObjectPath NetworkDBusProxy::ActivateConnection(const QString &uuid, const QDBusObjectPath &devicePath) |
| 210 | +{ |
| 211 | + return QDBusPendingReply<QDBusObjectPath>(m_networkInter->asyncCall(QStringLiteral("ActivateConnection"), QVariant::fromValue(uuid), QVariant::fromValue(devicePath))); |
| 212 | +} |
| 213 | + |
| 214 | +QDBusObjectPath NetworkDBusProxy::ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath) |
| 215 | +{ |
| 216 | + return QDBusPendingReply<QDBusObjectPath>(m_networkInter->asyncCall(QStringLiteral("ActivateAccessPoint"), QVariant::fromValue(uuid), QVariant::fromValue(apPath), QVariant::fromValue(devPath))); |
| 217 | +} |
| 218 | + |
| 219 | +bool NetworkDBusProxy::ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath, QObject *receiver, const char *member, const char *errorSlot) |
| 220 | +{ |
| 221 | + QList<QVariant> argumentList; |
| 222 | + argumentList << QVariant::fromValue(uuid) << QVariant::fromValue(apPath) << QVariant::fromValue(devPath); |
| 223 | + return m_networkInter->callWithCallback(QStringLiteral("ActivateAccessPoint"), argumentList, receiver, member, errorSlot); |
| 224 | +} |
| 225 | + |
| 226 | +void NetworkDBusProxy::DisconnectDevice(const QDBusObjectPath &devPath) |
| 227 | +{ |
| 228 | + m_networkInter->asyncCall(QStringLiteral("DisconnectDevice"), QVariant::fromValue(devPath)); |
| 229 | +} |
| 230 | + |
| 231 | +void NetworkDBusProxy::RequestIPConflictCheck(const QString &ip, const QString &ifc) |
| 232 | +{ |
| 233 | + m_networkInter->asyncCall(QStringLiteral("RequestIPConflictCheck"), QVariant::fromValue(ip), QVariant::fromValue(ifc)); |
| 234 | +} |
| 235 | + |
| 236 | +bool NetworkDBusProxy::IsDeviceEnabled(const QDBusObjectPath &devPath) |
| 237 | +{ |
| 238 | + return QDBusPendingReply<bool>(m_networkInter->asyncCall(QStringLiteral("IsDeviceEnabled"), QVariant::fromValue(devPath))); |
| 239 | +} |
| 240 | + |
| 241 | +void NetworkDBusProxy::RequestWirelessScan() |
| 242 | +{ |
| 243 | + m_networkInter->asyncCall(QStringLiteral("RequestWirelessScan")); |
| 244 | +} |
| 245 | + |
| 246 | +void NetworkDBusProxy::Set(const QString &type0, const QString &ip, uint port, const QString &user, const QString &password) |
| 247 | +{ |
| 248 | + m_proxyChainsInter->asyncCall(QStringLiteral("Set"), QVariant::fromValue(type0), QVariant::fromValue(ip), QVariant::fromValue(port), QVariant::fromValue(user), QVariant::fromValue(password)); |
| 249 | +} |
| 250 | + |
| 251 | +uint NetworkDBusProxy::Notify(const QString &in0, uint in1, const QString &in2, const QString &in3, const QString &in4, const QStringList &in5, const QVariantMap &in6, int in7) |
| 252 | +{ |
| 253 | + QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify"); |
| 254 | + message << QVariant::fromValue(in0) << QVariant::fromValue(in1) << QVariant::fromValue(in2) << QVariant::fromValue(in3) << QVariant::fromValue(in4) << QVariant::fromValue(in5) << QVariant::fromValue(in6) << QVariant::fromValue(in7); |
| 255 | + return QDBusPendingReply<uint>(QDBusConnection::sessionBus().asyncCall(message)); |
| 256 | +} |
0 commit comments