-
Notifications
You must be signed in to change notification settings - Fork 65
network: add network integration with NetworkManager backend #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cpwrs
wants to merge
48
commits into
quickshell-mirror:master
Choose a base branch
from
cpwrs:nm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,085
−1
Open
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
a7ff484
init: NetworkManager service
cpwrs e92a9ec
fix: CMake typo
cpwrs 66fa5dc
feat: NetworkManager.state
cpwrs c3e1280
feat: devices, wifiDevice, device properties
cpwrs 6ee3cb5
hotfix: revert unintended change to upower
cpwrs 8679f79
feat(nix): nm buildInput
cpwrs 3c32d88
test: device basics
cpwrs 0391e02
test: nm state
cpwrs fdbdf1d
fix: devicetype enum matches NMDeviceType in spec
cpwrs 208cfd0
style: shorten to NM
cpwrs 2504210
Revert "feat(nix): nm buildInput"
cpwrs d323881
feat: AP, Wireless xml
cpwrs 4705796
fix test
cpwrs a1515c1
feat: begin wireless
cpwrs 19ac6db
Merge branch 'quickshell-mirror:master' into nm
cpwrs e445c9b
Quickshell.Network
cpwrs c4d8fc2
clean
cpwrs 28bf2d7
refactor: nm dir
cpwrs 1d02e1c
fix: log names
cpwrs 112eb66
feat: Wireless
cpwrs 87787dc
feat: frontend slots
cpwrs bdaaa5f
feat: state, working subdevices
cpwrs c9ece29
disconnect
cpwrs 997f45b
feat: scan, lastScan, NetworkDeviceType
cpwrs 560232c
feat: accessPoints
cpwrs 7090633
fix: annotate RequestScan a{sv} for qdbusxml2cpp
cpwrs 6429991
feat: AccessPoints -> WifiNetworks
cpwrs 61f8c8f
feat: connected
cpwrs 8b21137
feat: remove lastScan
cpwrs c955811
refactor: move nm_* to nm/ and seperate adapter classes
cpwrs e5e0544
feat: backend connections
cpwrs be80d20
feat: ap flags, device connections
cpwrs 840e6ec
feat: merge backend connections + networks -> WifiNetwork.
cpwrs c936fb9
feat: add NMActiveConnectionAdapter
cpwrs c49e825
feat: NMWirelessNetwork holds all wifi network objects
cpwrs 6282af4
fix: show signal of active AP
cpwrs b12ad1b
refactor: active AP is handled by NMWirelessNetwork
cpwrs c23b068
chore: cleanup and lint
cpwrs 434f9ee
fix: style, includes, best network Security
cpwrs c9f70e0
feat: move synced properties to bindables
cpwrs c4656a7
fix: scanning is bindable on backend
cpwrs fc69097
fix: setEnabled is WRITE
cpwrs 8fee842
style: whitespace
cpwrs 62ab321
network: fmt, lint, style
cpwrs 6e227a7
network: update API
cpwrs b031b02
network: add WifiScanner
cpwrs 14068b8
network: add WifiDeviceMode, update NM wireless logic
cpwrs b0b3d8a
network: fix segfault, split backend CMakeLists
cpwrs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| add_subdirectory(nm) | ||
|
|
||
| qt_add_library(quickshell-network STATIC | ||
| network.cpp | ||
| device.cpp | ||
| wifi.cpp | ||
| ) | ||
|
|
||
| target_include_directories(quickshell-network PRIVATE | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| ) | ||
|
|
||
| qt_add_qml_module(quickshell-network | ||
| URI Quickshell.Network | ||
| VERSION 0.1 | ||
| DEPENDENCIES QtQml | ||
| ) | ||
|
|
||
| qs_add_module_deps_light(quickshell-network Quickshell) | ||
| install_qml_module(quickshell-network) | ||
| target_link_libraries(quickshell-network PRIVATE quickshell-network-nm Qt::Qml Qt::DBus) | ||
| qs_add_link_dependencies(quickshell-network quickshell-dbus) | ||
| target_link_libraries(quickshell PRIVATE quickshell-networkplugin) | ||
| qs_module_pch(quickshell-network SET dbus) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #include "device.hpp" | ||
|
|
||
| #include <qdebug.h> | ||
| #include <qlogging.h> | ||
| #include <qloggingcategory.h> | ||
| #include <qobject.h> | ||
| #include <qstringliteral.h> | ||
| #include <qtmetamacros.h> | ||
|
|
||
| #include "../core/logcat.hpp" | ||
|
|
||
| namespace qs::network { | ||
|
|
||
| namespace { | ||
| QS_LOGGING_CATEGORY(logNetworkDevice, "quickshell.network.device", QtWarningMsg); | ||
| } // namespace | ||
|
|
||
| QString DeviceConnectionState::toString(DeviceConnectionState::Enum state) { | ||
| switch (state) { | ||
| case Unknown: return QStringLiteral("Unknown"); | ||
| case Connecting: return QStringLiteral("Connecting"); | ||
| case Connected: return QStringLiteral("Connected"); | ||
| case Disconnecting: return QStringLiteral("Disconnecting"); | ||
| case Disconnected: return QStringLiteral("Disconnected"); | ||
| default: return QStringLiteral("Unknown"); | ||
| } | ||
| } | ||
|
|
||
| QString DeviceType::toString(DeviceType::Enum type) { | ||
| switch (type) { | ||
| case None: return QStringLiteral("None"); | ||
| case Wifi: return QStringLiteral("Wifi"); | ||
| default: return QStringLiteral("Unknown"); | ||
| } | ||
| } | ||
|
|
||
| QString NMDeviceState::toString(NMDeviceState::Enum state) { | ||
| switch (state) { | ||
| case Unknown: return QStringLiteral("Unknown"); | ||
| case Unmanaged: return QStringLiteral("Not managed by NetworkManager"); | ||
| case Unavailable: return QStringLiteral("Unavailable"); | ||
| case Disconnected: return QStringLiteral("Disconnected"); | ||
| case Prepare: return QStringLiteral("Preparing to connect"); | ||
| case Config: return QStringLiteral("Connecting to a network"); | ||
| case NeedAuth: return QStringLiteral("Waiting for authentication"); | ||
| case IPConfig: return QStringLiteral("Requesting IPv4 and/or IPv6 addresses from the network"); | ||
| case IPCheck: | ||
| return QStringLiteral("Checking if further action is required for the requested connection"); | ||
| case Secondaries: | ||
| return QStringLiteral("Waiting for a required secondary connection to activate"); | ||
| case Activated: return QStringLiteral("Connected"); | ||
| case Deactivating: return QStringLiteral("Disconnecting"); | ||
| case Failed: return QStringLiteral("Failed to connect"); | ||
| default: return QStringLiteral("Unknown"); | ||
| }; | ||
| } | ||
|
|
||
| NetworkDevice::NetworkDevice(DeviceType::Enum type, QObject* parent): QObject(parent), mType(type) { | ||
| this->bindableConnected().setBinding([this]() { | ||
| return this->bState == DeviceConnectionState::Connected; | ||
| }); | ||
| }; | ||
|
|
||
| void NetworkDevice::setAutoconnect(bool autoconnect) { | ||
| if (this->bAutoconnect == autoconnect) return; | ||
| emit this->requestSetAutoconnect(autoconnect); | ||
| } | ||
|
|
||
| void NetworkDevice::disconnect() { | ||
| if (this->bState == DeviceConnectionState::Disconnected) { | ||
| qCCritical(logNetworkDevice) << "Device" << this << "is already disconnected"; | ||
| return; | ||
| } | ||
| if (this->bState == DeviceConnectionState::Disconnecting) { | ||
| qCCritical(logNetworkDevice) << "Device" << this << "is already disconnecting"; | ||
| return; | ||
| } | ||
| qCDebug(logNetworkDevice) << "Disconnecting from device" << this; | ||
| this->requestDisconnect(); | ||
| } | ||
|
|
||
| } // namespace qs::network |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| #pragma once | ||
|
|
||
| #include <qobject.h> | ||
| #include <qproperty.h> | ||
| #include <qqmlintegration.h> | ||
| #include <qtmetamacros.h> | ||
| #include <qtypes.h> | ||
|
|
||
| namespace qs::network { | ||
|
|
||
| ///! Connection state of a NetworkDevice. | ||
| class DeviceConnectionState: public QObject { | ||
| Q_OBJECT; | ||
| QML_ELEMENT; | ||
| QML_SINGLETON; | ||
|
|
||
| public: | ||
| enum Enum : quint8 { | ||
| Unknown = 0, | ||
| Connecting = 1, | ||
| Connected = 2, | ||
| Disconnecting = 3, | ||
| Disconnected = 4, | ||
| }; | ||
| Q_ENUM(Enum); | ||
| Q_INVOKABLE static QString toString(DeviceConnectionState::Enum state); | ||
| }; | ||
|
|
||
| ///! Type of network device. | ||
| class DeviceType: public QObject { | ||
| Q_OBJECT; | ||
| QML_ELEMENT; | ||
| QML_SINGLETON; | ||
|
|
||
| public: | ||
| enum Enum : quint8 { | ||
| None = 0, | ||
| Wifi = 1, | ||
| }; | ||
| Q_ENUM(Enum); | ||
| Q_INVOKABLE static QString toString(DeviceType::Enum type); | ||
| }; | ||
|
|
||
| ///! NetworkManager-specific device state. | ||
| /// In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMDeviceState. | ||
| class NMDeviceState: public QObject { | ||
| Q_OBJECT; | ||
| QML_ELEMENT; | ||
| QML_SINGLETON; | ||
|
|
||
| public: | ||
| enum Enum : quint8 { | ||
| Unknown = 0, | ||
| Unmanaged = 10, | ||
| Unavailable = 20, | ||
| Disconnected = 30, | ||
| Prepare = 40, | ||
| Config = 50, | ||
| NeedAuth = 60, | ||
| IPConfig = 70, | ||
| IPCheck = 80, | ||
| Secondaries = 90, | ||
| Activated = 100, | ||
| Deactivating = 110, | ||
| Failed = 120, | ||
| }; | ||
| Q_ENUM(Enum); | ||
| Q_INVOKABLE static QString toString(NMDeviceState::Enum state); | ||
| }; | ||
|
|
||
| ///! A network device. | ||
| class NetworkDevice: public QObject { | ||
| Q_OBJECT; | ||
| QML_ELEMENT; | ||
| QML_UNCREATABLE("Devices can only be acquired through Network"); | ||
| // clang-format off | ||
| /// The device type. | ||
| Q_PROPERTY(DeviceType::Enum type READ type CONSTANT); | ||
| /// The name of the device's control interface. | ||
| Q_PROPERTY(QString name READ name NOTIFY nameChanged BINDABLE bindableName); | ||
| /// The hardware address of the device in the XX:XX:XX:XX:XX:XX format. | ||
| Q_PROPERTY(QString address READ default NOTIFY addressChanged BINDABLE bindableAddress); | ||
| /// True if the device is connected. | ||
| Q_PROPERTY(bool connected READ default NOTIFY connectedChanged BINDABLE bindableConnected); | ||
| /// Connection state of the device. | ||
| Q_PROPERTY(qs::network::DeviceConnectionState::Enum state READ default NOTIFY stateChanged BINDABLE bindableState); | ||
| /// A more specific device state when the backend is NetworkManager. | ||
| Q_PROPERTY(qs::network::NMDeviceState::Enum nmState READ default NOTIFY nmStateChanged BINDABLE bindableNmState); | ||
| /// True if the device is allowed to autoconnect. | ||
| Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect NOTIFY autoconnectChanged); | ||
| // clang-format on | ||
|
|
||
| public: | ||
| explicit NetworkDevice(DeviceType::Enum type, QObject* parent = nullptr); | ||
|
|
||
| /// Disconnects the device and prevents it from automatically activating further connections. | ||
| Q_INVOKABLE void disconnect(); | ||
|
|
||
| [[nodiscard]] DeviceType::Enum type() const { return this->mType; }; | ||
| QBindable<QString> bindableName() { return &this->bName; }; | ||
| [[nodiscard]] QString name() const { return this->bName; }; | ||
| QBindable<QString> bindableAddress() { return &this->bAddress; }; | ||
| QBindable<bool> bindableConnected() { return &this->bConnected; }; | ||
| QBindable<DeviceConnectionState::Enum> bindableState() { return &this->bState; }; | ||
| QBindable<NMDeviceState::Enum> bindableNmState() { return &this->bNmState; }; | ||
| [[nodiscard]] bool autoconnect() const { return this->bAutoconnect; }; | ||
| QBindable<bool> bindableAutoconnect() { return &this->bAutoconnect; }; | ||
| void setAutoconnect(bool autoconnect); | ||
|
|
||
| signals: | ||
| void requestDisconnect(); | ||
| void requestSetAutoconnect(bool autoconnect); | ||
| void nameChanged(); | ||
| void addressChanged(); | ||
| void connectedChanged(); | ||
| void stateChanged(); | ||
| void nmStateChanged(); | ||
| void autoconnectChanged(); | ||
|
|
||
| private: | ||
| DeviceType::Enum mType; | ||
| // clang-format off | ||
| Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, QString, bName, &NetworkDevice::nameChanged); | ||
| Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, QString, bAddress, &NetworkDevice::addressChanged); | ||
| Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, bool, bConnected, &NetworkDevice::connectedChanged); | ||
| Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, DeviceConnectionState::Enum, bState, &NetworkDevice::stateChanged); | ||
| Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, NMDeviceState::Enum, bNmState, &NetworkDevice::nmStateChanged); | ||
| Q_OBJECT_BINDABLE_PROPERTY(NetworkDevice, bool, bAutoconnect, &NetworkDevice::autoconnectChanged); | ||
| // clang-format on | ||
| }; | ||
|
|
||
| } // namespace qs::network |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| name = "Quickshell.Network" | ||
| description = "Network API" | ||
| headers = [ | ||
| "network.hpp", | ||
| "device.hpp", | ||
| "wifi.hpp", | ||
| ] | ||
| ----- | ||
| This module exposes Network management APIs provided by a supported network backend. | ||
| For now, the only backend available is the NetworkManager DBus interface. | ||
| Both DBus and NetworkManager must be running to use it. | ||
|
|
||
| See the @@Quickshell.Network.Network singleton. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include "network.hpp" | ||
| #include <utility> | ||
|
|
||
| #include <qlogging.h> | ||
| #include <qloggingcategory.h> | ||
| #include <qobject.h> | ||
| #include <qtmetamacros.h> | ||
|
|
||
| #include "../core/logcat.hpp" | ||
| #include "device.hpp" | ||
| #include "nm/backend.hpp" | ||
|
|
||
| namespace qs::network { | ||
|
|
||
| namespace { | ||
| QS_LOGGING_CATEGORY(logNetwork, "quickshell.network", QtWarningMsg); | ||
| } // namespace | ||
|
|
||
| Network::Network(QObject* parent): QObject(parent) { | ||
| // Try to create the NetworkManager backend and bind to it. | ||
| auto* nm = new NetworkManager(this); | ||
| if (nm->isAvailable()) { | ||
| QObject::connect(nm, &NetworkManager::deviceAdded, this, &Network::deviceAdded); | ||
| QObject::connect(nm, &NetworkManager::deviceRemoved, this, &Network::deviceRemoved); | ||
| QObject::connect(this, &Network::requestSetWifiEnabled, nm, &NetworkManager::setWifiEnabled); | ||
| this->bindableWifiEnabled().setBinding([nm]() { return nm->wifiEnabled(); }); | ||
| this->bindableWifiHardwareEnabled().setBinding([nm]() { return nm->wifiHardwareEnabled(); }); | ||
|
|
||
| this->mBackend = nm; | ||
| this->mBackendType = NetworkBackendType::NetworkManager; | ||
| return; | ||
| } else { | ||
| delete nm; | ||
| } | ||
|
|
||
| qCCritical(logNetwork) << "Network will not work. Could not find an available backend."; | ||
| } | ||
|
|
||
| void Network::deviceAdded(NetworkDevice* dev) { this->mDevices.insertObject(dev); } | ||
| void Network::deviceRemoved(NetworkDevice* dev) { this->mDevices.removeObject(dev); } | ||
|
|
||
| void Network::setWifiEnabled(bool enabled) { | ||
| if (this->bWifiEnabled == enabled) return; | ||
| emit this->requestSetWifiEnabled(enabled); | ||
| } | ||
|
|
||
| BaseNetwork::BaseNetwork(QString name, QObject* parent): QObject(parent), mName(std::move(name)) {}; | ||
|
|
||
| } // namespace qs::network |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.