77#include < qtypes.h>
88
99#include " ../core/model.hpp"
10+ #include " connection.hpp"
1011#include " device.hpp"
1112
1213namespace qs ::network {
@@ -29,6 +30,35 @@ class NetworkState: public QObject {
2930 Q_INVOKABLE static QString toString (NetworkState::Enum state);
3031};
3132
33+ // /! The reason for the NMConnectionState of an NMConnection.
34+ // / In sync with https://networkmanager.dev/docs/api/latest/nm-dbus-types.html#NMActiveConnectionStateReason.
35+ class NMNetworkStateReason : public QObject {
36+ Q_OBJECT;
37+ QML_ELEMENT;
38+ QML_SINGLETON;
39+
40+ public:
41+ enum Enum : quint8 {
42+ Unknown = 0 ,
43+ None = 1 ,
44+ UserDisconnected = 2 ,
45+ DeviceDisconnected = 3 ,
46+ ServiceStopped = 4 ,
47+ IpConfigInvalid = 5 ,
48+ ConnectTimeout = 6 ,
49+ ServiceStartTimeout = 7 ,
50+ ServiceStartFailed = 8 ,
51+ NoSecrets = 9 ,
52+ LoginFailed = 10 ,
53+ ConnectionRemoved = 11 ,
54+ DependencyFailed = 12 ,
55+ DeviceRealizeFailed = 13 ,
56+ DeviceRemoved = 14
57+ };
58+ Q_ENUM (Enum);
59+ Q_INVOKABLE static QString toString (NMNetworkStateReason::Enum reason);
60+ };
61+
3262// /! The backend supplying the Network service.
3363class NetworkBackendType : public QObject {
3464 Q_OBJECT;
@@ -105,38 +135,81 @@ private slots:
105135class Network : public QObject {
106136 Q_OBJECT;
107137 QML_ELEMENT;
108- QML_UNCREATABLE (" BaseNetwork can only be aqcuired through network devices" );
138+ QML_UNCREATABLE (" Network can only be aqcuired through networking devices" );
109139
110140 // clang-format off
111141 // / The name of the network.
112142 Q_PROPERTY (QString name READ name CONSTANT);
143+ // / A list of connnection settings profiles for this network.
144+ // /
145+ // / > [!WARNING] Only valid for the NetworkManager backend.
146+ QSDOC_TYPE_OVERRIDE (ObjectModel<qs::network::NMConnection>*);
147+ Q_PROPERTY (UntypedObjectModel* nmConnections READ nmConnections CONSTANT);
148+ // / The default connection settings profile for this network. This is the connection settings used when connect() is invoked.
149+ // / Only available when the connection is known.
150+ // /
151+ // / > [!WARNING] Only valid for the NetworkManager backend.
152+ Q_PROPERTY (NMConnection* nmDefaultConnection READ nmDefaultConnection WRITE setNmDefaultConnection NOTIFY nmDefaultConnectionChanged BINDABLE bindableNmDefaultConnection);
113153 // / True if the network is connected.
114154 Q_PROPERTY (bool connected READ default NOTIFY connectedChanged BINDABLE bindableConnected);
155+ // / True if the wifi network has known connection settings saved.
156+ Q_PROPERTY (bool known READ default NOTIFY knownChanged BINDABLE bindableKnown);
115157 // / The connectivity state of the network.
116158 Q_PROPERTY (NetworkState::Enum state READ default NOTIFY stateChanged BINDABLE bindableState);
159+ // / A specific reason for the connection state. Only available for the NetworkManager backend.
160+ Q_PROPERTY (NMNetworkStateReason::Enum stateReason READ default NOTIFY stateReasonChanged BINDABLE bindableStateReason);
117161 // / If the network is currently connecting or disconnecting. Shorthand for checking @@state.
118162 Q_PROPERTY (bool stateChanging READ default NOTIFY stateChangingChanged BINDABLE bindableStateChanging);
119163 // clang-format on
120164
121165public:
122166 explicit Network (QString name, QObject* parent = nullptr );
123167
168+ // / Attempt to connect to the network.
169+ Q_INVOKABLE void connect ();
170+ // / Disconnect from the network.
171+ Q_INVOKABLE void disconnect ();
172+ // / Forget all connection settings for this network.
173+ Q_INVOKABLE void forget ();
174+
175+ void connectionAdded (NMConnection* conn);
176+ void connectionRemoved (NMConnection* conn);
177+
124178 [[nodiscard]] QString name () const { return this ->mName ; };
179+ [[nodiscard]] ObjectModel<NMConnection>* nmConnections () { return &this ->mNmConnections ; };
180+ [[nodiscard]] NMConnection* nmDefaultConnection () { return this ->bNmDefaultConnection ; };
181+ QBindable<NMConnection*> bindableNmDefaultConnection () { return &this ->bNmDefaultConnection ; };
182+ void setNmDefaultConnection (NMConnection* conn);
125183 QBindable<bool > bindableConnected () { return &this ->bConnected ; }
184+ QBindable<bool > bindableKnown () { return &this ->bKnown ; }
126185 QBindable<NetworkState::Enum> bindableState () { return &this ->bState ; }
186+ QBindable<NMNetworkStateReason::Enum> bindableStateReason () { return &this ->bStateReason ; }
127187 QBindable<bool > bindableStateChanging () { return &this ->bStateChanging ; }
128188
129189signals:
190+ void requestSetNmDefaultConnection (NMConnection* conn);
191+ void requestConnect ();
192+ void requestDisconnect ();
193+ void requestForget ();
194+ void nmDefaultConnectionChanged ();
130195 void connectedChanged ();
196+ void knownChanged ();
131197 void stateChanged ();
198+ void stateReasonChanged ();
132199 void stateChangingChanged ();
133200
134201protected:
135202 QString mName ;
203+ ObjectModel<NMConnection> mNmConnections {this };
136204
205+ // clang-format off
206+ Q_OBJECT_BINDABLE_PROPERTY (Network, NMConnection*, bNmDefaultConnection, &Network::nmDefaultConnectionChanged);
137207 Q_OBJECT_BINDABLE_PROPERTY (Network, bool , bConnected, &Network::connectedChanged);
208+ Q_OBJECT_BINDABLE_PROPERTY (Network, bool , bKnown, &Network::knownChanged);
138209 Q_OBJECT_BINDABLE_PROPERTY (Network, NetworkState::Enum, bState, &Network::stateChanged);
210+ Q_OBJECT_BINDABLE_PROPERTY (Network, NMNetworkStateReason::Enum, bStateReason, &Network::stateReasonChanged);
139211 Q_OBJECT_BINDABLE_PROPERTY (Network, bool , bStateChanging, &Network::stateChangingChanged);
212+ // clang-format on
140213};
141214
142215} // namespace qs::network
0 commit comments