summaryrefslogtreecommitdiff
path: root/lib/network/wired.vala
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-09-01 14:17:36 +0200
committerAylur <[email protected]>2024-09-01 14:17:36 +0200
commit3e3f045d650a839d21f7b649da7aa5c19bd2e38b (patch)
tree9a974eb0d38932d474940288c662bd1f01ea3088 /lib/network/wired.vala
parent408faee16911ccfaa3e7dad69f9938fd4a696704 (diff)
monorepo structuring
Diffstat (limited to 'lib/network/wired.vala')
-rw-r--r--lib/network/wired.vala73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/network/wired.vala b/lib/network/wired.vala
new file mode 100644
index 0000000..68cf460
--- /dev/null
+++ b/lib/network/wired.vala
@@ -0,0 +1,73 @@
+public class AstalNetwork.Wired : Object {
+ private const string ICON_CONNECTED = "network-wired-symbolic";
+ private const string ICON_DISCONNECTED = "network-wired-disconnected-symbolic";
+ private const string ICON_ACQUIRING = "network-wired-acquiring-symbolic";
+ private const string ICON_NO_ROUTE = "network-wired-no-route-symbolic";
+
+ public NM.DeviceEthernet device { get; construct set; }
+
+ public NM.ActiveConnection connection;
+ private ulong connection_handler = 0;
+
+ internal Wired(NM.DeviceEthernet device) {
+ this.device = device;
+
+ speed = device.speed;
+ state = (DeviceState)device.state;
+ icon_name = _icon();
+
+ device.notify.connect((pspec) => {
+ if (pspec.name == "speed") {
+ speed = device.speed;
+ }
+ if (pspec.name == "state") {
+ state = (DeviceState)device.state;
+ }
+ if (pspec.name == "active-connection") {
+ on_active_connection();
+ }
+ icon_name = _icon();
+ });
+
+ device.client.notify.connect(() => { icon_name = _icon(); });
+
+ on_active_connection();
+ icon_name = _icon();
+ }
+
+ private void on_active_connection() {
+ if (connection_handler > 0 && connection != null) {
+ connection.disconnect(connection_handler);
+ connection_handler = 0;
+ connection = null;
+ }
+
+ connection = device.active_connection;
+ if (connection != null) {
+ connection_handler = connection.notify["state"].connect(() => {
+ internet = Internet.from_device(device);
+ });
+ }
+ }
+
+ public uint speed { get; private set; }
+ public Internet internet { get; private set; }
+ public DeviceState state { get; private set; }
+ public string icon_name { get; private set; }
+
+ private string _icon() {
+ var full = device.client.connectivity == NM.ConnectivityState.FULL;
+
+ if (internet == Internet.CONNECTING) {
+ return ICON_ACQUIRING;
+ }
+
+ if (internet == Internet.CONNECTED) {
+ if (!full) return ICON_NO_ROUTE;
+
+ return ICON_CONNECTED;
+ }
+
+ return ICON_DISCONNECTED;
+ }
+}