-
Notifications
You must be signed in to change notification settings - Fork 49
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
44
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.
Open
Changes from 38 commits
Commits
Show all changes
44 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 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,96 @@ | ||
# NetworkManager DBus | ||
set_source_files_properties(nm/org.freedesktop.NetworkManager.xml PROPERTIES | ||
CLASSNAME DBusNetworkManagerProxy | ||
NO_NAMESPACE TRUE | ||
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/nm/dbus_types.hpp | ||
) | ||
|
||
qt_add_dbus_interface(NM_DBUS_INTERFACES | ||
nm/org.freedesktop.NetworkManager.xml | ||
nm/dbus_nm_backend | ||
) | ||
|
||
set_source_files_properties(nm/org.freedesktop.NetworkManager.Device.xml PROPERTIES | ||
CLASSNAME DBusNMDeviceProxy | ||
NO_NAMESPACE TRUE | ||
) | ||
|
||
qt_add_dbus_interface(NM_DBUS_INTERFACES | ||
nm/org.freedesktop.NetworkManager.Device.xml | ||
nm/dbus_nm_device | ||
) | ||
|
||
set_source_files_properties(nm/org.freedesktop.NetworkManager.Device.Wireless.xml PROPERTIES | ||
CLASSNAME DBusNMWirelessProxy | ||
NO_NAMESPACE TRUE | ||
) | ||
|
||
qt_add_dbus_interface(NM_DBUS_INTERFACES | ||
nm/org.freedesktop.NetworkManager.Device.Wireless.xml | ||
nm/dbus_nm_wireless | ||
) | ||
|
||
set_source_files_properties(nm/org.freedesktop.NetworkManager.AccessPoint.xml PROPERTIES | ||
CLASSNAME DBusNMAccessPointProxy | ||
NO_NAMESPACE TRUE | ||
) | ||
|
||
qt_add_dbus_interface(NM_DBUS_INTERFACES | ||
nm/org.freedesktop.NetworkManager.AccessPoint.xml | ||
nm/dbus_nm_accesspoint | ||
) | ||
|
||
set_source_files_properties(nm/org.freedesktop.NetworkManager.Settings.Connection.xml PROPERTIES | ||
CLASSNAME DBusNMConnectionSettingsProxy | ||
NO_NAMESPACE TRUE | ||
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/nm/dbus_types.hpp | ||
) | ||
|
||
qt_add_dbus_interface(NM_DBUS_INTERFACES | ||
nm/org.freedesktop.NetworkManager.Settings.Connection.xml | ||
nm/dbus_nm_connection_settings | ||
) | ||
|
||
set_source_files_properties(nm/org.freedesktop.NetworkManager.Connection.Active.xml PROPERTIES | ||
CLASSNAME DBusNMActiveConnectionProxy | ||
NO_NAMESPACE TRUE | ||
) | ||
|
||
qt_add_dbus_interface(NM_DBUS_INTERFACES | ||
nm/org.freedesktop.NetworkManager.Connection.Active.xml | ||
nm/dbus_nm_active_connection | ||
) | ||
|
||
qt_add_library(quickshell-network STATIC | ||
network.cpp | ||
device.cpp | ||
wifi.cpp | ||
nm/backend.cpp | ||
nm/device.cpp | ||
nm/connection.cpp | ||
nm/accesspoint.cpp | ||
nm/wireless.cpp | ||
nm/utils.cpp | ||
nm/enums.hpp | ||
${NM_DBUS_INTERFACES} | ||
) | ||
|
||
# dbus headers | ||
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 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,67 @@ | ||
#include "device.hpp" | ||
|
||
#include <qdbusconnection.h> | ||
#include <qdbusconnectioninterface.h> | ||
#include <qdbusextratypes.h> | ||
#include <qdbuspendingcall.h> | ||
#include <qdbuspendingreply.h> | ||
#include <qdbusservicewatcher.h> | ||
#include <qlogging.h> | ||
|
||
namespace qs::network { | ||
|
||
namespace { | ||
Q_LOGGING_CATEGORY(logNetworkDevice, "quickshell.network.device", QtWarningMsg); | ||
} // namespace | ||
|
||
NetworkDevice::NetworkDevice(QObject* parent): QObject(parent) {}; | ||
|
||
void NetworkDevice::setName(const QString& name) { | ||
if (name == this->mName) return; | ||
this->mName = name; | ||
emit this->nameChanged(); | ||
} | ||
|
||
void NetworkDevice::setAddress(const QString& address) { | ||
if (address == this->mAddress) return; | ||
this->mAddress = address; | ||
emit this->addressChanged(); | ||
} | ||
|
||
void NetworkDevice::setState(NetworkConnectionState::Enum state) { | ||
if (state == this->mState) return; | ||
this->mState = state; | ||
emit this->stateChanged(); | ||
} | ||
|
||
void NetworkDevice::setNmState(NMDeviceState::Enum nmState) { | ||
if (nmState == this->mNmState) return; | ||
this->mNmState = nmState; | ||
emit this->nmStateChanged(); | ||
} | ||
|
||
void NetworkDevice::disconnect() { | ||
if (this->mState == NetworkConnectionState::Disconnected) { | ||
qCCritical(logNetworkDevice) << "Device" << this << "is already disconnected"; | ||
return; | ||
} | ||
if (this->mState == NetworkConnectionState::Disconnecting) { | ||
qCCritical(logNetworkDevice) << "Device" << this << "is already disconnecting"; | ||
return; | ||
} | ||
qCDebug(logNetworkDevice) << "Disconnecting from device" << this; | ||
this->requestDisconnect(); | ||
} | ||
|
||
QString NetworkConnectionState::toString(NetworkConnectionState::Enum state) { | ||
switch (state) { | ||
case Unknown: return "Unknown"; | ||
case Connecting: return "Connecting"; | ||
case Connected: return "Connected"; | ||
case Disconnecting: return "Disconnecting"; | ||
case Disconnected: return "Disconnected"; | ||
} | ||
return {}; | ||
} | ||
|
||
} // 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,81 @@ | ||
#pragma once | ||
|
||
#include <qcontainerfwd.h> | ||
#include <qdbusextratypes.h> | ||
#include <qdbusservicewatcher.h> | ||
#include <qhash.h> | ||
#include <qobject.h> | ||
#include <qqmlintegration.h> | ||
#include <qqmllist.h> | ||
#include <qtmetamacros.h> | ||
#include <qtypes.h> | ||
|
||
#include "nm/enums.hpp" | ||
|
||
namespace qs::network { | ||
|
||
///! Connection state. | ||
class NetworkConnectionState: 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(NetworkConnectionState::Enum state); | ||
}; | ||
|
||
///! A Network device. | ||
class NetworkDevice: public QObject { | ||
Q_OBJECT; | ||
QML_ELEMENT; | ||
QML_UNCREATABLE("Devices can only be acquired through Network"); | ||
|
||
/// The name of the device's interface. | ||
Q_PROPERTY(QString name READ name NOTIFY nameChanged); | ||
/// The hardware address of the device's interface in the XX:XX:XX:XX:XX:XX format. | ||
Q_PROPERTY(QString address READ address NOTIFY addressChanged); | ||
/// Connection state of the device. | ||
Q_PROPERTY(NetworkConnectionState::Enum state READ state NOTIFY stateChanged); | ||
/// A more specific device state when the backend is NetworkManager. | ||
Q_PROPERTY(NMDeviceState::Enum nmState READ nmState NOTIFY nmStateChanged); | ||
|
||
signals: | ||
void nameChanged(); | ||
void addressChanged(); | ||
void stateChanged(); | ||
void nmStateChanged(); | ||
void requestDisconnect(); | ||
|
||
public slots: | ||
void setName(const QString& name); | ||
void setAddress(const QString& address); | ||
void setState(NetworkConnectionState::Enum state); | ||
void setNmState(NMDeviceState::Enum state); | ||
|
||
public: | ||
explicit NetworkDevice(QObject* parent = nullptr); | ||
|
||
[[nodiscard]] QString name() const { return this->mName; }; | ||
[[nodiscard]] QString address() const { return this->mAddress; }; | ||
[[nodiscard]] NetworkConnectionState::Enum state() const { return this->mState; }; | ||
[[nodiscard]] NMDeviceState::Enum nmState() const { return this->mNmState; }; | ||
|
||
/// Disconnects the device and prevents it from automatically activating further connections. | ||
Q_INVOKABLE void disconnect(); | ||
|
||
private: | ||
QString mName; | ||
QString mAddress; | ||
NetworkConnectionState::Enum mState = NetworkConnectionState::Unknown; | ||
NMDeviceState::Enum mNmState = NMDeviceState::Unknown; | ||
}; | ||
|
||
} // 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,40 @@ | ||
#include "network.hpp" | ||
|
||
#include <qdbusconnection.h> | ||
#include <qdbusconnectioninterface.h> | ||
#include <qdbusextratypes.h> | ||
#include <qdbuspendingcall.h> | ||
#include <qdbuspendingreply.h> | ||
#include <qdbusservicewatcher.h> | ||
#include <qlogging.h> | ||
|
||
#include "nm/backend.hpp" | ||
|
||
namespace qs::network { | ||
|
||
namespace { | ||
Q_LOGGING_CATEGORY(logNetwork, "quickshell.network", QtWarningMsg); | ||
} // namespace | ||
|
||
Network::Network(QObject* parent): QObject(parent), mWifi(new Wifi(this)) { | ||
// NetworkManager | ||
auto* nm = new NetworkManager(this); | ||
if (nm->isAvailable()) { | ||
// clang-format off | ||
QObject::connect(nm, &NetworkManager::wifiDeviceAdded, this->wifi(), &Wifi::onDeviceAdded); | ||
QObject::connect(nm, &NetworkManager::wifiDeviceRemoved, this->wifi(), &Wifi::onDeviceRemoved); | ||
QObject::connect(nm, &NetworkManager::wifiEnabledChanged, this->wifi(), &Wifi::onEnabledSet); | ||
QObject::connect(nm, &NetworkManager::wifiHardwareEnabledChanged, this->wifi(), &Wifi::onHardwareEnabledSet); | ||
QObject::connect(this->wifi(), &Wifi::requestSetEnabled, nm, &NetworkManager::setWifiEnabled); | ||
// clang-format on | ||
this->mBackend = nm; | ||
this->mBackendType = NetworkBackendType::NetworkManager; | ||
return; | ||
} else { | ||
delete nm; | ||
} | ||
|
||
qCCritical(logNetwork) << "Network will not work. Could not find an available backend."; | ||
} | ||
|
||
} // 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,68 @@ | ||
#pragma once | ||
|
||
#include <qcontainerfwd.h> | ||
#include <qdbusextratypes.h> | ||
#include <qdbusservicewatcher.h> | ||
#include <qhash.h> | ||
#include <qobject.h> | ||
#include <qqmlintegration.h> | ||
#include <qqmllist.h> | ||
#include <qtmetamacros.h> | ||
#include <qtypes.h> | ||
|
||
#include "wifi.hpp" | ||
|
||
namespace qs::network { | ||
|
||
///! The backend supplying the Network service. | ||
class NetworkBackendType: public QObject { | ||
Q_OBJECT; | ||
QML_ELEMENT; | ||
QML_SINGLETON; | ||
|
||
public: | ||
enum Enum : quint8 { | ||
/// There is no available Network backend. | ||
None = 0, | ||
/// The backend is NetworkManager. | ||
NetworkManager = 1, | ||
}; | ||
Q_ENUM(Enum); | ||
}; | ||
|
||
class NetworkBackend: public QObject { | ||
Q_OBJECT; | ||
|
||
public: | ||
[[nodiscard]] virtual bool isAvailable() const = 0; | ||
|
||
protected: | ||
explicit NetworkBackend(QObject* parent = nullptr): QObject(parent) {}; | ||
}; | ||
|
||
///! The Network service. | ||
/// An interface to a network backend (currently only NetworkManager), | ||
/// which can be used to view, configure, and connect to various networks. | ||
class Network: public QObject { | ||
Q_OBJECT; | ||
QML_NAMED_ELEMENT(Network); | ||
QML_SINGLETON; | ||
|
||
/// The wifi device service. | ||
Q_PROPERTY(Wifi* wifi READ wifi CONSTANT); | ||
/// The backend being used to power the Network service. | ||
Q_PROPERTY(NetworkBackendType::Enum backend READ backend); | ||
cpwrs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
public: | ||
explicit Network(QObject* parent = nullptr); | ||
|
||
[[nodiscard]] Wifi* wifi() { return this->mWifi; }; | ||
[[nodiscard]] NetworkBackendType::Enum backend() { return this->mBackendType; }; | ||
|
||
private: | ||
Wifi* mWifi; | ||
NetworkBackend* mBackend = nullptr; | ||
NetworkBackendType::Enum mBackendType = NetworkBackendType::None; | ||
}; | ||
|
||
} // 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.