network: add NMSettings and NMConnectionContext#535
network: add NMSettings and NMConnectionContext#535cpwrs wants to merge 7 commits intoquickshell-mirror:masterfrom
Conversation
|
noticing you formatted it, is this ready now? |
Not yet, gotta add back some password stuff. I have time to work on it today |
e90eae3 to
db97686
Compare
dda9fcc to
d982e7f
Compare
| void NMConnectionContext::setNetwork(Network* network) { | ||
| if (this->bNetwork == network) return; | ||
| if (this->bNetwork) disconnect(this->bNetwork, nullptr, this, nullptr); | ||
| this->bNetwork = network; | ||
| if (!network) return; | ||
|
|
||
| QObject::connect(network, &Network::activeSettingsChanged, this, [network, this]() { | ||
| if (network->activeSettings()) { | ||
| if (this->bSettings) disconnect(this->bSettings, nullptr, this, nullptr); | ||
| this->bSettings = network->activeSettings(); | ||
| QObject::connect(this->bSettings, &NMSettings::destroyed, this, [this]() { | ||
| this->bSettings = nullptr; | ||
| }); | ||
| }; | ||
| }); | ||
| QObject::connect(network, &Network::stateChanged, this, [network, this]() { | ||
| if (network->state() == NetworkState::Connected) emit this->activated(); | ||
| if (network->state() == NetworkState::Connecting) emit this->activating(); | ||
| }); | ||
| QObject::connect(network, &Network::nmStateReasonChanged, this, [network, this]() { | ||
| // "Device disconnected" isn't useful, so we defer to the last device fail reason. | ||
| if (network->nmStateReason() == NMNetworkStateReason::DeviceDisconnected) { | ||
| auto failReason = network->nmDeviceFailReason(); | ||
| if (failReason == NMDeviceStateReason::NoSecrets) emit this->noSecrets(); | ||
| if (failReason == NMDeviceStateReason::SupplicantDisconnect) | ||
| emit this->supplicantDisconnect(); | ||
| if (failReason == NMDeviceStateReason::SupplicantFailed) emit this->supplicantFailed(); | ||
| if (failReason == NMDeviceStateReason::SupplicantTimeout) emit this->supplicantTimeout(); | ||
| }; | ||
| }); | ||
|
|
||
| connect(network, &Network::destroyed, this, [this]() { this->bNetwork = nullptr; }); | ||
| } |
There was a problem hiding this comment.
I included a really basic set, but it could include signals for anything from
https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMDeviceStateReason
or
https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMActiveConnectionStateReason
The latter unfortunately only emits for VPN connections, for wifi conns its always DeviceDisconnected.
Sadly there's no "auth failed", that falls under NoSecrets
| /// A network to provide connection context for or `null`. | ||
| Q_PROPERTY(Network* network READ network WRITE setNetwork NOTIFY networkChanged) | ||
| /// The last connection settings that context signals were emitted for or `null`. | ||
| Q_PROPERTY(NMSettings* settings READ default NOTIFY settingsChanged BINDABLE bindableSettings) |
There was a problem hiding this comment.
Is this what you were thinking for a "callback" to the specific settings?
|
I couldn't find a useful way to expose the settings as a big QMap (or multiple smaller maps), so it's empty besides the psk setter. Adding invokables for the popular eap methods is easy enough but I wasn't able to test them. As far as connection context, I was disappointed to learn that only VPN connections hit the more descriptive state reasons in https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMActiveConnectionStateReason. |
23cf03a to
8717373
Compare
3fe56a4 to
e20267d
Compare
|
Just checking in on this because it'd be nice to have in 0.3 which I want to cut this month. I should be around to review on more sane timelines than usual. |
ca90821 to
3cf65af
Compare
| struct NMIPv6Address { | ||
| QByteArray address; | ||
| quint32 prefix = 0; | ||
| QByteArray gateway; | ||
| }; | ||
|
|
||
| const QDBusArgument& operator>>(const QDBusArgument& argument, qs::network::NMIPv6Address& addr); | ||
| const QDBusArgument& operator<<(QDBusArgument& argument, const qs::network::NMIPv6Address& addr); | ||
|
|
||
| const QDBusArgument& | ||
| operator>>(const QDBusArgument& argument, QList<qs::network::NMIPv6Address>& list); | ||
| const QDBusArgument& | ||
| operator<<(QDBusArgument& argument, const QList<qs::network::NMIPv6Address>& list); | ||
|
|
||
| struct NMIPv6Route { | ||
| QByteArray destination; | ||
| quint32 prefix = 0; | ||
| QByteArray nexthop; | ||
| quint32 metric = 0; | ||
| }; | ||
|
|
||
| const QDBusArgument& operator>>(const QDBusArgument& argument, qs::network::NMIPv6Route& route); | ||
| const QDBusArgument& operator<<(QDBusArgument& argument, const qs::network::NMIPv6Route& route); | ||
|
|
||
| const QDBusArgument& | ||
| operator>>(const QDBusArgument& argument, QList<qs::network::NMIPv6Route>& list); | ||
| const QDBusArgument& | ||
| operator<<(QDBusArgument& argument, const QList<qs::network::NMIPv6Route>& list); |
There was a problem hiding this comment.
These struct settings are deprecated on stable but are still initialized by NM by default
| /// Update the connection with new settings and save the connection to disk. | ||
| /// Only changed fields need to be included. | ||
| /// | ||
| /// > [!NOTE] Secrets may be part of the update request, | ||
| /// > and will be either stored in persistent storage or sent to a Secret Agent for storage, | ||
| /// > depending on the flags associated with each secret. | ||
| Q_INVOKABLE void write(const QVariantMap& settings); | ||
| /// Get the settings map describing this network configuration. | ||
| /// | ||
| /// > [!NOTE] This will never include any secrets required for connection to the network, as those are often protected. | ||
| Q_INVOKABLE QVariantMap read(); |
There was a problem hiding this comment.
This can just be a Q_PROPERTY now if that's preferred. I can throw in read only props for id/uuid too for convenience.
write() is nice because you only have to give it the fields you want changed. Right now this provides setting = null to remove/unset a setting.
| const QDBusArgument& operator>>(const QDBusArgument& argument, QList<QVariantMap>& list); | ||
| const QDBusArgument& operator<<(QDBusArgument& argument, const QList<QVariantMap>& list); | ||
| const QDBusArgument& operator>>(const QDBusArgument& argument, QList<quint32>& list); | ||
| const QDBusArgument& operator<<(QDBusArgument& argument, const QList<quint32>& list); | ||
| const QDBusArgument& operator>>(const QDBusArgument& argument, QList<QList<quint32>>& list); | ||
| const QDBusArgument& operator<<(QDBusArgument& argument, const QList<QList<quint32>>& list); | ||
| const QDBusArgument& operator>>(const QDBusArgument& argument, QList<QByteArray>& list); | ||
| const QDBusArgument& operator<<(QDBusArgument& argument, const QList<QByteArray>& list); |
There was a problem hiding this comment.
Didn't type alias these because more than one setting uses these signatures and this would be the correct operator for them in any context.
I can give them some general aliases and bring them into network scope if you prefer
This exposes the connection settings from NetworkManager. It also exposes a creatable NMConnectionContext object that emits signals about connection attempts and tracks their respective connection settings.
Additions:
Fixes: