mirror of
https://git.outfoxxed.me/quickshell/quickshell.git
synced 2026-04-10 06:11:54 +10:00
networking: add PSK, settings and connection status support
This commit is contained in:
parent
92b336c80c
commit
20c691cdf1
34 changed files with 2200 additions and 881 deletions
|
|
@ -14,9 +14,10 @@
|
|||
|
||||
#include "../../core/logcat.hpp"
|
||||
#include "../../dbus/properties.hpp"
|
||||
#include "../device.hpp"
|
||||
#include "connection.hpp"
|
||||
#include "active_connection.hpp"
|
||||
#include "dbus_nm_device.h"
|
||||
#include "enums.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
namespace qs::network {
|
||||
using namespace qs::dbus;
|
||||
|
|
@ -39,19 +40,29 @@ NMDevice::NMDevice(const QString& path, QObject* parent): QObject(parent) {
|
|||
}
|
||||
|
||||
// clang-format off
|
||||
QObject::connect(this, &NMDevice::availableConnectionPathsChanged, this, &NMDevice::onAvailableConnectionPathsChanged);
|
||||
QObject::connect(this, &NMDevice::availableSettingsPathsChanged, this, &NMDevice::onAvailableSettingsPathsChanged);
|
||||
QObject::connect(this, &NMDevice::activeConnectionPathChanged, this, &NMDevice::onActiveConnectionPathChanged);
|
||||
QObject::connect(this->deviceProxy, &DBusNMDeviceProxy::StateChanged, this, &NMDevice::onStateChanged);
|
||||
// clang-format on
|
||||
|
||||
this->deviceProperties.setInterface(this->deviceProxy);
|
||||
this->deviceProperties.updateAllViaGetAll();
|
||||
}
|
||||
|
||||
void NMDevice::onStateChanged(quint32 newState, quint32 /*oldState*/, quint32 reason) {
|
||||
auto enumReason = static_cast<NMDeviceStateReason::Enum>(reason);
|
||||
auto enumNewState = static_cast<NMDeviceState::Enum>(newState);
|
||||
if (enumNewState == NMDeviceState::Failed) this->bLastFailReason = enumReason;
|
||||
if (this->bStateReason == enumReason) return;
|
||||
this->bStateReason = enumReason;
|
||||
}
|
||||
|
||||
void NMDevice::onActiveConnectionPathChanged(const QDBusObjectPath& path) {
|
||||
const QString stringPath = path.path();
|
||||
|
||||
// Remove old active connection
|
||||
if (this->mActiveConnection) {
|
||||
qCDebug(logNetworkManager) << "Active connection removed:" << this->mActiveConnection->path();
|
||||
QObject::disconnect(this->mActiveConnection, nullptr, this, nullptr);
|
||||
delete this->mActiveConnection;
|
||||
this->mActiveConnection = nullptr;
|
||||
|
|
@ -64,6 +75,7 @@ void NMDevice::onActiveConnectionPathChanged(const QDBusObjectPath& path) {
|
|||
qCWarning(logNetworkManager) << "Ignoring invalid registration of" << stringPath;
|
||||
delete active;
|
||||
} else {
|
||||
qCDebug(logNetworkManager) << "Active connection added:" << stringPath;
|
||||
this->mActiveConnection = active;
|
||||
QObject::connect(
|
||||
active,
|
||||
|
|
@ -76,42 +88,44 @@ void NMDevice::onActiveConnectionPathChanged(const QDBusObjectPath& path) {
|
|||
}
|
||||
}
|
||||
|
||||
void NMDevice::onAvailableConnectionPathsChanged(const QList<QDBusObjectPath>& paths) {
|
||||
void NMDevice::onAvailableSettingsPathsChanged(const QList<QDBusObjectPath>& paths) {
|
||||
QSet<QString> newPathSet;
|
||||
for (const QDBusObjectPath& path: paths) {
|
||||
newPathSet.insert(path.path());
|
||||
}
|
||||
const auto existingPaths = this->mConnections.keys();
|
||||
const auto existingPaths = this->mSettings.keys();
|
||||
const QSet<QString> existingPathSet(existingPaths.begin(), existingPaths.end());
|
||||
|
||||
const auto addedConnections = newPathSet - existingPathSet;
|
||||
const auto removedConnections = existingPathSet - newPathSet;
|
||||
const auto addedSettings = newPathSet - existingPathSet;
|
||||
const auto removedSettings = existingPathSet - newPathSet;
|
||||
|
||||
for (const QString& path: addedConnections) {
|
||||
this->registerConnection(path);
|
||||
for (const QString& path: addedSettings) {
|
||||
this->registerSettings(path);
|
||||
}
|
||||
for (const QString& path: removedConnections) {
|
||||
auto* connection = this->mConnections.take(path);
|
||||
for (const QString& path: removedSettings) {
|
||||
auto* connection = this->mSettings.take(path);
|
||||
if (!connection) {
|
||||
qCDebug(logNetworkManager) << "Sent removal signal for" << path << "which is not registered.";
|
||||
} else {
|
||||
qCDebug(logNetworkManager) << "Connection settings removed:" << path;
|
||||
delete connection;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void NMDevice::registerConnection(const QString& path) {
|
||||
auto* connection = new NMConnectionSettings(path, this);
|
||||
if (!connection->isValid()) {
|
||||
void NMDevice::registerSettings(const QString& path) {
|
||||
auto* settings = new NMSettings(path, this);
|
||||
if (!settings->isValid()) {
|
||||
qCWarning(logNetworkManager) << "Ignoring invalid registration of" << path;
|
||||
delete connection;
|
||||
delete settings;
|
||||
} else {
|
||||
this->mConnections.insert(path, connection);
|
||||
qCDebug(logNetworkManager) << "Connection settings added:" << path;
|
||||
this->mSettings.insert(path, settings);
|
||||
QObject::connect(
|
||||
connection,
|
||||
&NMConnectionSettings::loaded,
|
||||
settings,
|
||||
&NMSettings::loaded,
|
||||
this,
|
||||
[this, connection]() { emit this->connectionLoaded(connection); },
|
||||
[this, settings]() { emit this->settingsLoaded(settings); },
|
||||
Qt::SingleShotConnection
|
||||
);
|
||||
}
|
||||
|
|
@ -125,6 +139,12 @@ void NMDevice::setAutoconnect(bool autoconnect) {
|
|||
this->pAutoconnect.write();
|
||||
}
|
||||
|
||||
void NMDevice::setManaged(bool managed) {
|
||||
if (managed == this->bManaged) return;
|
||||
this->bManaged = managed;
|
||||
this->pManaged.write();
|
||||
}
|
||||
|
||||
bool NMDevice::isValid() const { return this->deviceProxy && this->deviceProxy->isValid(); }
|
||||
QString NMDevice::address() const {
|
||||
return this->deviceProxy ? this->deviceProxy->service() : QString();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue