Skip to content

Commit b1f12d3

Browse files
committed
EthernetDevice
1 parent fb10ab2 commit b1f12d3

25 files changed

Lines changed: 725 additions & 237 deletions

src/network/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_subdirectory(nm)
33
qt_add_library(quickshell-network STATIC
44
network.cpp
55
device.cpp
6+
ethernet.cpp
67
wifi.cpp
78
enums.cpp
89
)

src/network/device.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
namespace qs::network {
1313

1414
///! A network device.
15-
/// The @@type property may be used to determine if this device is a @@WifiDevice.
15+
/// The @@type property may be used to determine if this device is a @@WifiDevice or @@EthernetDevice.
1616
class NetworkDevice: public QObject {
1717
Q_OBJECT;
1818
QML_ELEMENT;
1919
QML_UNCREATABLE("Devices can only be acquired through Network");
2020
// clang-format off
2121
/// The device type.
2222
///
23-
/// When the device type is `Wifi`, the device object is a @@WifiDevice which exposes wifi network
23+
/// When the device type is `Wifi`, the device object is a @@WifiDevice which exposes wifi networks.
24+
/// When the device type is `Ethernet`, the device object is a @@EthernetDevice.
2425
/// connection and scanning.
2526
Q_PROPERTY(DeviceType::Enum type READ type CONSTANT);
2627
/// The name of the device's control interface.

src/network/enums.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ QString DeviceType::toString(DeviceType::Enum type) {
5050
switch (type) {
5151
case None: return QStringLiteral("None");
5252
case Wifi: return QStringLiteral("Wifi");
53+
case Ethernet: return QStringLiteral("Ethernet");
5354
default: return QStringLiteral("Unknown");
5455
}
5556
}

src/network/enums.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class DeviceType: public QObject {
9898
enum Enum : quint8 {
9999
None = 0,
100100
Wifi = 1,
101+
Ethernet = 2,
101102
};
102103
Q_ENUM(Enum);
103104
Q_INVOKABLE static QString toString(DeviceType::Enum type);

src/network/ethernet.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "ethernet.hpp"
2+
3+
#include <qobject.h>
4+
5+
#include "device.hpp"
6+
#include "enums.hpp"
7+
#include "network.hpp"
8+
9+
namespace qs::network {
10+
11+
EthernetDevice::EthernetDevice(Network* net, QObject* parent)
12+
: NetworkDevice(DeviceType::Ethernet, parent)
13+
, mNetwork(net) {}
14+
15+
} // namespace qs::network

src/network/ethernet.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#pragma once
2+
3+
#include <qobject.h>
4+
#include <qproperty.h>
5+
#include <qqmlintegration.h>
6+
#include <qtmetamacros.h>
7+
#include <qtypes.h>
8+
9+
#include "device.hpp"
10+
#include "network.hpp"
11+
12+
namespace qs::network {
13+
14+
///! Ethernet variant of a @@NetworkDevice.
15+
class EthernetDevice: public NetworkDevice {
16+
Q_OBJECT;
17+
QML_ELEMENT;
18+
QML_UNCREATABLE("");
19+
20+
/// The available wired network for this device.
21+
Q_PROPERTY(Network* network READ network CONSTANT)
22+
/// The maximum speed of the physical device link, in megabits per second.
23+
Q_PROPERTY(quint32 linkSpeed READ default NOTIFY linkSpeedChanged BINDABLE bindableLinkSpeed)
24+
/// True if the ethernet device has a physical link (cable plugged in).
25+
Q_PROPERTY(bool hasLink READ default NOTIFY hasLinkChanged BINDABLE bindableHasLink)
26+
27+
public:
28+
explicit EthernetDevice(Network* net, QObject* parent = nullptr);
29+
30+
[[nodiscard]] Network* network() { return this->mNetwork; };
31+
QBindable<quint32> bindableLinkSpeed() { return &this->bLinkSpeed; }
32+
QBindable<bool> bindableHasLink() { return &this->bHasLink; }
33+
34+
signals:
35+
void linkSpeedChanged();
36+
void hasLinkChanged();
37+
38+
private:
39+
Network* mNetwork;
40+
Q_OBJECT_BINDABLE_PROPERTY(
41+
EthernetDevice,
42+
quint32,
43+
bLinkSpeed,
44+
&EthernetDevice::linkSpeedChanged
45+
);
46+
Q_OBJECT_BINDABLE_PROPERTY(EthernetDevice, bool, bHasLink, &EthernetDevice::hasLinkChanged);
47+
};
48+
49+
} // namespace qs::network

src/network/module.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ headers = [
44
"network.hpp",
55
"device.hpp",
66
"wifi.hpp",
7+
"ethernet.hpp",
78
"enums.hpp",
89
"nm/settings.hpp",
910
]

src/network/network.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "network.hpp"
2-
#include <utility>
32

43
#include <qdebug.h>
54
#include <qlogging.h>
@@ -81,7 +80,7 @@ NetworkingQml::NetworkingQml(QObject* parent): QObject(parent) {
8180

8281
void NetworkingQml::checkConnectivity() { Networking::instance()->checkConnectivity(); }
8382

84-
Network::Network(QString name, QObject* parent): QObject(parent), mName(std::move(name)) {
83+
Network::Network(QObject* parent): QObject(parent) {
8584
this->bStateChanging.setBinding([this] {
8685
auto state = this->bState.value();
8786
return state == ConnectionState::Connecting || state == ConnectionState::Disconnecting;

src/network/network.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ class Network: public QObject {
157157
QML_UNCREATABLE("Network can only be aqcuired through networking devices");
158158

159159
// clang-format off
160-
/// The name of the network.
161-
Q_PROPERTY(QString name READ name CONSTANT);
162160
/// A list of NetworkManager connnection settings profiles for this network.
163161
///
164162
/// > [!WARNING] Only valid for the NetworkManager backend.
@@ -174,7 +172,7 @@ class Network: public QObject {
174172
// clang-format on
175173

176174
public:
177-
explicit Network(QString name, QObject* parent = nullptr);
175+
explicit Network(QObject* parent = nullptr);
178176
/// Attempt to connect to the network.
179177
///
180178
/// > [!NOTE] If the network is a @@WifiNetwork and requires secrets, a @@connectionFailed(s)
@@ -194,7 +192,6 @@ class Network: public QObject {
194192
void settingsRemoved(NMSettings* settings);
195193

196194
// clang-format off
197-
[[nodiscard]] QString name() const { return this->mName; }
198195
[[nodiscard]] const QList<NMSettings*>& nmSettings() const { return this->bNmSettings; }
199196
QBindable<QList<NMSettings*>> bindableNmSettings() const { return &this->bNmSettings; }
200197
QBindable<bool> bindableConnected() { return &this->bConnected; }
@@ -219,8 +216,6 @@ class Network: public QObject {
219216
QSDOC_HIDE void requestForget();
220217

221218
protected:
222-
QString mName;
223-
224219
// clang-format off
225220
Q_OBJECT_BINDABLE_PROPERTY(Network, bool, bConnected, &Network::connectedChanged);
226221
Q_OBJECT_BINDABLE_PROPERTY(Network, bool, bKnown, &Network::knownChanged);

src/network/nm/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ qt_add_dbus_interface(NM_DBUS_INTERFACES
2929
dbus_nm_wireless
3030
)
3131

32+
set_source_files_properties(org.freedesktop.NetworkManager.Device.Wired.xml PROPERTIES
33+
CLASSNAME DBusNMWiredProxy
34+
NO_NAMESPACE TRUE
35+
)
36+
37+
qt_add_dbus_interface(NM_DBUS_INTERFACES
38+
org.freedesktop.NetworkManager.Device.Wired.xml
39+
dbus_nm_wired
40+
)
41+
3242
set_source_files_properties(org.freedesktop.NetworkManager.AccessPoint.xml PROPERTIES
3343
CLASSNAME DBusNMAccessPointProxy
3444
NO_NAMESPACE TRUE
@@ -67,6 +77,7 @@ qt_add_library(quickshell-network-nm STATIC
6777
settings.cpp
6878
accesspoint.cpp
6979
wireless.cpp
80+
wired.cpp
7081
utils.cpp
7182
dbus_types.cpp
7283
network.cpp
@@ -80,3 +91,4 @@ target_include_directories(quickshell-network-nm PUBLIC
8091

8192
target_link_libraries(quickshell-network-nm PRIVATE Qt::Qml Qt::DBus)
8293
qs_add_link_dependencies(quickshell-network-nm quickshell-dbus)
94+
qs_add_link_dependencies(quickshell-network-nm quickshell-network)

0 commit comments

Comments
 (0)