Skip to content

Commit c49e825

Browse files
committed
feat: NMWirelessNetwork holds all wifi network objects
Removes the NMWirelessManager and moves its functionality to the NMWirelessDevice, which now extends NMDevice. NMWirelessNetworks hold all of the state of the APs and connections and signals the best settings for connection.
1 parent c936fb9 commit c49e825

24 files changed

+1339
-1152
lines changed

src/network/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set_source_files_properties(nm/org.freedesktop.NetworkManager.xml PROPERTIES
33
CLASSNAME DBusNetworkManagerProxy
44
NO_NAMESPACE TRUE
5+
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/nm/dbus_types.hpp
56
)
67

78
qt_add_dbus_interface(NM_DBUS_INTERFACES
@@ -41,6 +42,7 @@ qt_add_dbus_interface(NM_DBUS_INTERFACES
4142

4243
set_source_files_properties(nm/org.freedesktop.NetworkManager.Settings.Connection.xml PROPERTIES
4344
CLASSNAME DBusNMConnectionSettingsProxy
45+
NO_NAMESPACE TRUE
4446
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/nm/dbus_types.hpp
4547
)
4648

@@ -60,7 +62,9 @@ qt_add_dbus_interface(NM_DBUS_INTERFACES
6062
)
6163

6264
qt_add_library(quickshell-network STATIC
63-
frontend.cpp
65+
network.cpp
66+
device.cpp
67+
wifi.cpp
6468
nm/backend.cpp
6569
nm/device.cpp
6670
nm/connection.cpp

src/network/device.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "device.hpp"
2+
3+
#include <qdbusconnection.h>
4+
#include <qdbusconnectioninterface.h>
5+
#include <qdbusextratypes.h>
6+
#include <qdbuspendingcall.h>
7+
#include <qdbuspendingreply.h>
8+
#include <qdbusservicewatcher.h>
9+
#include <qlogging.h>
10+
11+
namespace qs::network {
12+
13+
namespace {
14+
Q_LOGGING_CATEGORY(logNetworkDevice, "quickshell.network.device", QtWarningMsg);
15+
} // namespace
16+
17+
NetworkDevice::NetworkDevice(QObject* parent): QObject(parent) {};
18+
19+
void NetworkDevice::setName(const QString& name) {
20+
if (name == this->mName) return;
21+
this->mName = name;
22+
emit this->nameChanged();
23+
}
24+
25+
void NetworkDevice::setAddress(const QString& address) {
26+
if (address == this->mAddress) return;
27+
this->mAddress = address;
28+
emit this->addressChanged();
29+
}
30+
31+
void NetworkDevice::setState(NetworkConnectionState::Enum state) {
32+
if (state == this->mState) return;
33+
this->mState = state;
34+
emit this->stateChanged();
35+
}
36+
37+
void NetworkDevice::setNmState(NMDeviceState::Enum nmState) {
38+
if (nmState == this->mNmState) return;
39+
this->mNmState = nmState;
40+
emit this->nmStateChanged();
41+
}
42+
43+
void NetworkDevice::disconnect() {
44+
if (this->mState == NetworkConnectionState::Disconnected) {
45+
qCCritical(logNetworkDevice) << "Device" << this << "is already disconnected";
46+
return;
47+
}
48+
if (this->mState == NetworkConnectionState::Disconnecting) {
49+
qCCritical(logNetworkDevice) << "Device" << this << "is already disconnecting";
50+
return;
51+
}
52+
qCDebug(logNetworkDevice) << "Disconnecting from device" << this;
53+
this->requestDisconnect();
54+
}
55+
56+
QString NetworkConnectionState::toString(NetworkConnectionState::Enum state) {
57+
switch (state) {
58+
case Unknown: return "Unknown";
59+
case Connecting: return "Connecting";
60+
case Connected: return "Connected";
61+
case Disconnecting: return "Disconnecting";
62+
case Disconnected: return "Disconnected";
63+
}
64+
return {};
65+
}
66+
67+
} // namespace qs::network

src/network/device.hpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#pragma once
2+
3+
#include <qcontainerfwd.h>
4+
#include <qdbusextratypes.h>
5+
#include <qdbusservicewatcher.h>
6+
#include <qhash.h>
7+
#include <qobject.h>
8+
#include <qqmlintegration.h>
9+
#include <qqmllist.h>
10+
#include <qtmetamacros.h>
11+
#include <qtypes.h>
12+
13+
#include "nm/enums.hpp"
14+
15+
namespace qs::network {
16+
17+
///! Connection state.
18+
class NetworkConnectionState: public QObject {
19+
Q_OBJECT;
20+
QML_ELEMENT;
21+
QML_SINGLETON;
22+
23+
public:
24+
enum Enum : quint8 {
25+
Unknown = 0,
26+
Connecting = 1,
27+
Connected = 2,
28+
Disconnecting = 3,
29+
Disconnected = 4,
30+
};
31+
Q_ENUM(Enum);
32+
Q_INVOKABLE static QString toString(NetworkConnectionState::Enum state);
33+
};
34+
35+
///! A Network device.
36+
class NetworkDevice: public QObject {
37+
Q_OBJECT;
38+
QML_ELEMENT;
39+
QML_UNCREATABLE("Devices can only be acquired through Network");
40+
41+
/// The name of the device's interface.
42+
Q_PROPERTY(QString name READ name NOTIFY nameChanged);
43+
/// The hardware address of the device's interface in the XX:XX:XX:XX:XX:XX format.
44+
Q_PROPERTY(QString address READ address NOTIFY addressChanged);
45+
/// Connection state of the device.
46+
Q_PROPERTY(NetworkConnectionState::Enum state READ state NOTIFY stateChanged);
47+
/// A more specific device state when the backend is NetworkManager.
48+
Q_PROPERTY(NMDeviceState::Enum nmState READ nmState NOTIFY nmStateChanged);
49+
50+
signals:
51+
void nameChanged();
52+
void addressChanged();
53+
void stateChanged();
54+
void nmStateChanged();
55+
void requestDisconnect();
56+
57+
public slots:
58+
void setName(const QString& name);
59+
void setAddress(const QString& address);
60+
void setState(NetworkConnectionState::Enum state);
61+
void setNmState(NMDeviceState::Enum state);
62+
63+
public:
64+
explicit NetworkDevice(QObject* parent = nullptr);
65+
66+
[[nodiscard]] QString name() const { return this->mName; };
67+
[[nodiscard]] QString address() const { return this->mAddress; };
68+
[[nodiscard]] NetworkConnectionState::Enum state() const { return this->mState; };
69+
[[nodiscard]] NMDeviceState::Enum nmState() const { return this->mNmState; };
70+
71+
/// Disconnects the device and prevents it from automatically activating further connections.
72+
Q_INVOKABLE void disconnect();
73+
74+
private:
75+
QString mName;
76+
QString mAddress;
77+
NetworkConnectionState::Enum mState = NetworkConnectionState::Unknown;
78+
NMDeviceState::Enum mNmState = NMDeviceState::Unknown;
79+
};
80+
81+
} // namespace qs::network

src/network/frontend.cpp

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)