From e76b005cdbeee236f526fc5bfc27e4dba46fc218 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 6 Dec 2020 12:26:27 +0100 Subject: [PATCH 01/11] Show an indicator icon for each active connection --- src/Utils.vala | 53 ++++++++++ src/Widgets/DisplayWidget.vala | 179 +++++++++++++++++++++++++++++---- 2 files changed, 211 insertions(+), 21 deletions(-) diff --git a/src/Utils.vala b/src/Utils.vala index a59466f8..7e5cccfc 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -74,4 +74,57 @@ public enum Network.State { return 8; } } + + public string to_string() { + switch (this) { + case Network.State.DISCONNECTED: + return "DISCONNECTED"; + case Network.State.WIRED_UNPLUGGED: + return "WIRED_UNPLUGGED"; + case Network.State.DISCONNECTED_WIRED: + return "DISCONNECTED_WIRED"; + case Network.State.DISCONNECTED_AIRPLANE_MODE: + return "DISCONNECTED_AIRPLANE_MODE"; + case Network.State.CONNECTED_WIRED: + return "CONNECTED_WIRED"; + case Network.State.CONNECTED_VPN: + return "CONNECTED_VPN"; + case Network.State.CONNECTED_WIFI: + return "CONNECTED_WIFI"; + case Network.State.CONNECTED_WIFI_WEAK: + return "CONNECTED_WIFI_WEAK"; + case Network.State.CONNECTED_WIFI_OK: + return "CONNECTED_WIFI_OK"; + case Network.State.CONNECTED_WIFI_GOOD: + return "CONNECTED_WIFI_GOOD"; + case Network.State.CONNECTED_WIFI_EXCELLENT: + return "CONNECTED_WIFI_EXCELLENT"; + case Network.State.CONNECTED_MOBILE_WEAK: + return "CONNECTED_MOBILE_WEAK"; + case Network.State.CONNECTED_MOBILE_OK: + return "CONNECTED_MOBILE_OK"; + case Network.State.CONNECTED_MOBILE_GOOD: + return "CONNECTED_MOBILE_GOOD"; + case Network.State.CONNECTED_MOBILE_EXCELLENT: + return "CONNECTED_MOBILE_EXCELLENT"; + case Network.State.CONNECTING_WIFI: + return "CONNECTING_WIFI"; + case Network.State.CONNECTING_MOBILE: + return "CONNECTING_MOBILE"; + case Network.State.CONNECTING_WIRED: + return "CONNECTING_WIRED"; + case Network.State.CONNECTING_VPN: + return "CONNECTING_VPN"; + case Network.State.FAILED_WIRED: + return "FAILED_WIRED"; + case Network.State.FAILED_WIFI: + return "FAILED_WIFI"; + case Network.State.FAILED_MOBILE: + return "FAILED_MOBILE"; + case Network.State.FAILED_VPN: + return "FAILED_VPN"; + } + + return "UNKNOWN"; + } } diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 2472682b..6eb4b5b9 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -17,7 +17,21 @@ */ public class Network.Widgets.DisplayWidget : Gtk.Grid { - private Gtk.Image image; + private Gtk.Image cellular_image; + private Gtk.Revealer cellular_revealer; + + private Gtk.Image vpn_image; + private Gtk.Revealer vpn_revealer; + + private Gtk.Image wifi_image; + private Gtk.Revealer wifi_revealer; + + private Gtk.Image wired_image; + private Gtk.Revealer wired_revealer; + + private Gtk.Image network_image; + private Gtk.Revealer network_revealer; + private Gtk.Label extra_info_label; private Gtk.Revealer extra_info_revealer; @@ -26,8 +40,52 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { private uint cellular_animation_timeout; private int cellular_animation_state = 0; + private enum ConnectionState { + DISCONNECTED = 0, + CONNECTING = 1, + CONNECTED = 2 + } + + private ConnectionState cellular_connected = ConnectionState.DISCONNECTED; + private ConnectionState wifi_connected = ConnectionState.DISCONNECTED; + private ConnectionState wired_connected = ConnectionState.DISCONNECTED; + construct { - image = new Gtk.Image.from_icon_name ("network-wired-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + cellular_image = new Gtk.Image.from_icon_name ("network-cellular-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + + cellular_revealer = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + }; + cellular_revealer.add (cellular_image); + + vpn_image = new Gtk.Image.from_icon_name ("network-vpn", Gtk.IconSize.LARGE_TOOLBAR); + + vpn_revealer = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + }; + vpn_revealer.add (vpn_image); + + wifi_image = new Gtk.Image.from_icon_name ("network-wireless-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + + wifi_revealer = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + }; + wifi_revealer.add (wifi_image); + + wired_image = new Gtk.Image.from_icon_name ("network-wired-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + + wired_revealer = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + }; + wired_revealer.add (wired_image); + + network_image = new Gtk.Image.from_icon_name ("network-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + + network_revealer = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT, + reveal_child = true + }; + network_revealer.add (network_image); extra_info_label = new Gtk.Label (null) { margin_start = 4, @@ -40,11 +98,19 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { }; extra_info_revealer.add (extra_info_label); - add (image); + add (cellular_revealer); + add (vpn_revealer); + add (wifi_revealer); + add (wired_revealer); + add (network_revealer); add (extra_info_revealer); + + update_icons (); } public void update_state (Network.State state, bool secure, string? extra_info = null) { + info ("Network state changed to \"%s\"\n", state.to_string ()); + extra_info_revealer.reveal_child = extra_info != null; extra_info_label.label = extra_info; @@ -60,28 +126,46 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { switch (state) { case Network.State.DISCONNECTED_AIRPLANE_MODE: - image.icon_name = "airplane-mode-symbolic"; + network_image.icon_name = "airplane-mode-symbolic"; + cellular_connected = ConnectionState.DISCONNECTED; + wifi_connected = ConnectionState.DISCONNECTED; + wired_connected = ConnectionState.DISCONNECTED; + update_icons (); break; case Network.State.CONNECTING_WIRED: - image.icon_name = "network-wired-acquiring-symbolic"; + wired_image.icon_name = "network-wired-acquiring-symbolic"; + wired_connected = ConnectionState.CONNECTING; + update_icons (); break; case Network.State.CONNECTED_WIRED: - image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); + wired_image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); + wired_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_WIFI: - image.icon_name = "network-wireless-connected-symbolic"; + wifi_image.icon_name = "network-wireless-connected-symbolic"; + wifi_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_WIFI_WEAK: - image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); + wifi_image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); + wifi_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_WIFI_OK: - image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); + wifi_image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); + wifi_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_WIFI_GOOD: - image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); + wifi_image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); + wifi_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_WIFI_EXCELLENT: - image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); + wifi_image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); + wifi_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTING_WIFI: wifi_animation_timeout = Timeout.add (300, () => { @@ -101,21 +185,31 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { strength = "excellent"; break; } - image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; + wifi_image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; + wifi_connected = ConnectionState.CONNECTING; + update_icons (); return true; }); break; case Network.State.CONNECTED_MOBILE_WEAK: - image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_MOBILE_OK: - image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_MOBILE_GOOD: - image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTED_MOBILE_EXCELLENT: - image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_connected = ConnectionState.CONNECTED; + update_icons (); break; case Network.State.CONNECTING_MOBILE: cellular_animation_timeout = Timeout.add (300, () => { @@ -136,24 +230,67 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { break; } - image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; + cellular_image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; + cellular_connected = ConnectionState.CONNECTING; + update_icons (); return true; }); break; case Network.State.FAILED_MOBILE: - image.icon_name = "network-cellular-offline-symbolic"; + cellular_image.icon_name = "network-cellular-offline-symbolic"; + cellular_connected = ConnectionState.DISCONNECTED; + update_icons (); break; case Network.State.FAILED_WIFI: case Network.State.DISCONNECTED: - image.icon_name = "network-wireless-offline-symbolic"; + wifi_image.icon_name = "network-wireless-offline-symbolic"; + wifi_connected = ConnectionState.DISCONNECTED; + update_icons (); break; case Network.State.WIRED_UNPLUGGED: - image.icon_name = "network-wired-offline-symbolic"; + wired_image.icon_name = "network-wired-offline-symbolic"; + wired_connected = ConnectionState.DISCONNECTED; + update_icons (); break; default: - image.icon_name = "network-offline-symbolic"; + network_image.icon_name = "network-offline-symbolic"; + cellular_connected = ConnectionState.DISCONNECTED; + wifi_connected = ConnectionState.DISCONNECTED; + wired_connected = ConnectionState.DISCONNECTED; + update_icons (); critical ("Unknown network state, cannot show the good icon: %s", state.to_string ()); break; } } + + private void update_icons () { + if ((cellular_connected + wifi_connected + wired_connected) > 0) { + network_revealer.reveal_child = false; + } else { + cellular_revealer.reveal_child = false; + wifi_revealer.reveal_child = false; + wired_revealer.reveal_child = false; + network_revealer.reveal_child = true; + + return; + } + + if (cellular_connected > 0) { + cellular_revealer.reveal_child = true; + } else { + cellular_revealer.reveal_child = false; + } + + if (wifi_connected > 0) { + wifi_revealer.reveal_child = true; + } else { + wifi_revealer.reveal_child = false; + } + + if (wired_connected > 0) { + wired_revealer.reveal_child = true; + } else { + wired_revealer.reveal_child = false; + } + } } From d01da45ddd659665f01681d1a22e3af0be328950 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 6 Dec 2020 12:28:36 +0100 Subject: [PATCH 02/11] Satisfy linter --- src/Utils.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils.vala b/src/Utils.vala index 7e5cccfc..9110aee9 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -75,7 +75,7 @@ public enum Network.State { } } - public string to_string() { + public string to_string () { switch (this) { case Network.State.DISCONNECTED: return "DISCONNECTED"; From b4e44b55ba013b24bb4623bb161b9928fb029d8d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 6 Dec 2020 12:35:30 +0100 Subject: [PATCH 03/11] Handle DISCONNECTED --- src/Widgets/DisplayWidget.vala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 6eb4b5b9..e128a76c 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -125,6 +125,13 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { } switch (state) { + case Network.State.DISCONNECTED: + network_image.icon_name = "network-offline-symbolic"; + cellular_connected = ConnectionState.DISCONNECTED; + wifi_connected = ConnectionState.DISCONNECTED; + wired_connected = ConnectionState.DISCONNECTED; + update_icons (); + break; case Network.State.DISCONNECTED_AIRPLANE_MODE: network_image.icon_name = "airplane-mode-symbolic"; cellular_connected = ConnectionState.DISCONNECTED; @@ -242,7 +249,6 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { update_icons (); break; case Network.State.FAILED_WIFI: - case Network.State.DISCONNECTED: wifi_image.icon_name = "network-wireless-offline-symbolic"; wifi_connected = ConnectionState.DISCONNECTED; update_icons (); From 010795239e7291fa6e72aec20b7a9d99feaedc9d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 6 Dec 2020 12:45:32 +0100 Subject: [PATCH 04/11] Change order of icons based on reliability --- src/Widgets/DisplayWidget.vala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index e128a76c..947bfb43 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -98,10 +98,10 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { }; extra_info_revealer.add (extra_info_label); - add (cellular_revealer); add (vpn_revealer); - add (wifi_revealer); add (wired_revealer); + add (wifi_revealer); + add (cellular_revealer); add (network_revealer); add (extra_info_revealer); @@ -253,6 +253,7 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { wifi_connected = ConnectionState.DISCONNECTED; update_icons (); break; + case Network.State.FAILED_WIRED: case Network.State.WIRED_UNPLUGGED: wired_image.icon_name = "network-wired-offline-symbolic"; wired_connected = ConnectionState.DISCONNECTED; From 85567bb3a06fae1474af0818174f0d01d49a4503 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 6 Dec 2020 12:49:26 +0100 Subject: [PATCH 05/11] Add icon for vpn --- src/Widgets/DisplayWidget.vala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 947bfb43..8557d1d3 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -139,6 +139,12 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { wired_connected = ConnectionState.DISCONNECTED; update_icons (); break; + case Network.State.CONNECTED_VPN: + vpn_revealer.reveal_child = true; + break; + case Network.State.FAILED_VPN: + vpn_revealer.reveal_child = false; + break; case Network.State.CONNECTING_WIRED: wired_image.icon_name = "network-wired-acquiring-symbolic"; wired_connected = ConnectionState.CONNECTING; From ebf3ea010a6be9af604b3c7a4b1e419114acefb6 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 10 Apr 2021 14:35:29 +0200 Subject: [PATCH 06/11] Rename connection state variables --- src/Widgets/DisplayWidget.vala | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 8557d1d3..34d1c3a8 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -46,9 +46,9 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { CONNECTED = 2 } - private ConnectionState cellular_connected = ConnectionState.DISCONNECTED; - private ConnectionState wifi_connected = ConnectionState.DISCONNECTED; - private ConnectionState wired_connected = ConnectionState.DISCONNECTED; + private ConnectionState cellular_connection_state = ConnectionState.DISCONNECTED; + private ConnectionState wifi_connection_state = ConnectionState.DISCONNECTED; + private ConnectionState wired_connection_state = ConnectionState.DISCONNECTED; construct { cellular_image = new Gtk.Image.from_icon_name ("network-cellular-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); @@ -127,16 +127,16 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { switch (state) { case Network.State.DISCONNECTED: network_image.icon_name = "network-offline-symbolic"; - cellular_connected = ConnectionState.DISCONNECTED; - wifi_connected = ConnectionState.DISCONNECTED; - wired_connected = ConnectionState.DISCONNECTED; + cellular_connection_state = ConnectionState.DISCONNECTED; + wifi_connection_state = ConnectionState.DISCONNECTED; + wired_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; case Network.State.DISCONNECTED_AIRPLANE_MODE: network_image.icon_name = "airplane-mode-symbolic"; - cellular_connected = ConnectionState.DISCONNECTED; - wifi_connected = ConnectionState.DISCONNECTED; - wired_connected = ConnectionState.DISCONNECTED; + cellular_connection_state = ConnectionState.DISCONNECTED; + wifi_connection_state = ConnectionState.DISCONNECTED; + wired_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; case Network.State.CONNECTED_VPN: @@ -147,37 +147,37 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { break; case Network.State.CONNECTING_WIRED: wired_image.icon_name = "network-wired-acquiring-symbolic"; - wired_connected = ConnectionState.CONNECTING; + wired_connection_state = ConnectionState.CONNECTING; update_icons (); break; case Network.State.CONNECTED_WIRED: wired_image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); - wired_connected = ConnectionState.CONNECTED; + wired_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI: wifi_image.icon_name = "network-wireless-connected-symbolic"; - wifi_connected = ConnectionState.CONNECTED; + wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_WEAK: wifi_image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); - wifi_connected = ConnectionState.CONNECTED; + wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_OK: wifi_image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); - wifi_connected = ConnectionState.CONNECTED; + wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_GOOD: wifi_image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); - wifi_connected = ConnectionState.CONNECTED; + wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_EXCELLENT: wifi_image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); - wifi_connected = ConnectionState.CONNECTED; + wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTING_WIFI: @@ -199,29 +199,29 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { break; } wifi_image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; - wifi_connected = ConnectionState.CONNECTING; + wifi_connection_state = ConnectionState.CONNECTING; update_icons (); return true; }); break; case Network.State.CONNECTED_MOBILE_WEAK: cellular_image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); - cellular_connected = ConnectionState.CONNECTED; + cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_MOBILE_OK: cellular_image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); - cellular_connected = ConnectionState.CONNECTED; + cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_MOBILE_GOOD: cellular_image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); - cellular_connected = ConnectionState.CONNECTED; + cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_MOBILE_EXCELLENT: cellular_image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); - cellular_connected = ConnectionState.CONNECTED; + cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTING_MOBILE: @@ -244,32 +244,32 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { } cellular_image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; - cellular_connected = ConnectionState.CONNECTING; + cellular_connection_state = ConnectionState.CONNECTING; update_icons (); return true; }); break; case Network.State.FAILED_MOBILE: cellular_image.icon_name = "network-cellular-offline-symbolic"; - cellular_connected = ConnectionState.DISCONNECTED; + cellular_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; case Network.State.FAILED_WIFI: wifi_image.icon_name = "network-wireless-offline-symbolic"; - wifi_connected = ConnectionState.DISCONNECTED; + wifi_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; case Network.State.FAILED_WIRED: case Network.State.WIRED_UNPLUGGED: wired_image.icon_name = "network-wired-offline-symbolic"; - wired_connected = ConnectionState.DISCONNECTED; + wired_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; default: network_image.icon_name = "network-offline-symbolic"; - cellular_connected = ConnectionState.DISCONNECTED; - wifi_connected = ConnectionState.DISCONNECTED; - wired_connected = ConnectionState.DISCONNECTED; + cellular_connection_state = ConnectionState.DISCONNECTED; + wifi_connection_state = ConnectionState.DISCONNECTED; + wired_connection_state = ConnectionState.DISCONNECTED; update_icons (); critical ("Unknown network state, cannot show the good icon: %s", state.to_string ()); break; @@ -277,7 +277,7 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { } private void update_icons () { - if ((cellular_connected + wifi_connected + wired_connected) > 0) { + if ((cellular_connection_state + wifi_connection_state + wired_connection_state) > 0) { network_revealer.reveal_child = false; } else { cellular_revealer.reveal_child = false; @@ -288,19 +288,19 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { return; } - if (cellular_connected > 0) { + if (cellular_connection_state > 0) { cellular_revealer.reveal_child = true; } else { cellular_revealer.reveal_child = false; } - if (wifi_connected > 0) { + if (wifi_connection_state > 0) { wifi_revealer.reveal_child = true; } else { wifi_revealer.reveal_child = false; } - if (wired_connected > 0) { + if (wired_connection_state > 0) { wired_revealer.reveal_child = true; } else { wired_revealer.reveal_child = false; From 68022274bb561aac03b03c1757ca567883cb4b8c Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 10 Apr 2021 14:57:55 +0200 Subject: [PATCH 07/11] Add connection revealer --- src/Widgets/DisplayWidget.vala | 108 ++++++++++++++------------------- 1 file changed, 44 insertions(+), 64 deletions(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 34d1c3a8..ce933b2b 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -17,20 +17,11 @@ */ public class Network.Widgets.DisplayWidget : Gtk.Grid { - private Gtk.Image cellular_image; - private Gtk.Revealer cellular_revealer; - - private Gtk.Image vpn_image; - private Gtk.Revealer vpn_revealer; - - private Gtk.Image wifi_image; - private Gtk.Revealer wifi_revealer; - - private Gtk.Image wired_image; - private Gtk.Revealer wired_revealer; - - private Gtk.Image network_image; - private Gtk.Revealer network_revealer; + private ConnectionRevealer cellular_revealer; + private ConnectionRevealer vpn_revealer; + private ConnectionRevealer wifi_revealer; + private ConnectionRevealer wired_revealer; + private ConnectionRevealer network_revealer; private Gtk.Label extra_info_label; private Gtk.Revealer extra_info_revealer; @@ -51,41 +42,15 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { private ConnectionState wired_connection_state = ConnectionState.DISCONNECTED; construct { - cellular_image = new Gtk.Image.from_icon_name ("network-cellular-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + cellular_revealer = new ConnectionRevealer.from_icon_name ("network-cellular-offline-symbolic"); - cellular_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT - }; - cellular_revealer.add (cellular_image); + vpn_revealer = new ConnectionRevealer.from_icon_name ("network-vpn-symbolic"); - vpn_image = new Gtk.Image.from_icon_name ("network-vpn", Gtk.IconSize.LARGE_TOOLBAR); + wifi_revealer = new ConnectionRevealer.from_icon_name ("network-wireless-offline-symbolic"); - vpn_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT - }; - vpn_revealer.add (vpn_image); - - wifi_image = new Gtk.Image.from_icon_name ("network-wireless-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); - - wifi_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT - }; - wifi_revealer.add (wifi_image); + wired_revealer = new ConnectionRevealer.from_icon_name ("network-wired-offline-symbolic"); - wired_image = new Gtk.Image.from_icon_name ("network-wired-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); - - wired_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT - }; - wired_revealer.add (wired_image); - - network_image = new Gtk.Image.from_icon_name ("network-offline-symbolic", Gtk.IconSize.LARGE_TOOLBAR); - - network_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT, - reveal_child = true - }; - network_revealer.add (network_image); + network_revealer = new ConnectionRevealer.from_icon_name ("network-offline-symbolic"); extra_info_label = new Gtk.Label (null) { margin_start = 4, @@ -126,14 +91,14 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { switch (state) { case Network.State.DISCONNECTED: - network_image.icon_name = "network-offline-symbolic"; + network_revealer.image.icon_name = "network-offline-symbolic"; cellular_connection_state = ConnectionState.DISCONNECTED; wifi_connection_state = ConnectionState.DISCONNECTED; wired_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; case Network.State.DISCONNECTED_AIRPLANE_MODE: - network_image.icon_name = "airplane-mode-symbolic"; + network_revealer.image.icon_name = "airplane-mode-symbolic"; cellular_connection_state = ConnectionState.DISCONNECTED; wifi_connection_state = ConnectionState.DISCONNECTED; wired_connection_state = ConnectionState.DISCONNECTED; @@ -146,37 +111,37 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { vpn_revealer.reveal_child = false; break; case Network.State.CONNECTING_WIRED: - wired_image.icon_name = "network-wired-acquiring-symbolic"; + wired_revealer.image.icon_name = "network-wired-acquiring-symbolic"; wired_connection_state = ConnectionState.CONNECTING; update_icons (); break; case Network.State.CONNECTED_WIRED: - wired_image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); + wired_revealer.image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); wired_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI: - wifi_image.icon_name = "network-wireless-connected-symbolic"; + wifi_revealer.image.icon_name = "network-wireless-connected-symbolic"; wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_WEAK: - wifi_image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); + wifi_revealer.image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_OK: - wifi_image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); + wifi_revealer.image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_GOOD: - wifi_image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); + wifi_revealer.image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_WIFI_EXCELLENT: - wifi_image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); + wifi_revealer.image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); wifi_connection_state = ConnectionState.CONNECTED; update_icons (); break; @@ -198,29 +163,29 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { strength = "excellent"; break; } - wifi_image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; + wifi_revealer.image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; wifi_connection_state = ConnectionState.CONNECTING; update_icons (); return true; }); break; case Network.State.CONNECTED_MOBILE_WEAK: - cellular_image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_revealer.image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_MOBILE_OK: - cellular_image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_revealer.image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_MOBILE_GOOD: - cellular_image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_revealer.image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; case Network.State.CONNECTED_MOBILE_EXCELLENT: - cellular_image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); + cellular_revealer.image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); cellular_connection_state = ConnectionState.CONNECTED; update_icons (); break; @@ -243,30 +208,30 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { break; } - cellular_image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; + cellular_revealer.image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; cellular_connection_state = ConnectionState.CONNECTING; update_icons (); return true; }); break; case Network.State.FAILED_MOBILE: - cellular_image.icon_name = "network-cellular-offline-symbolic"; + cellular_revealer.image.icon_name = "network-cellular-offline-symbolic"; cellular_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; case Network.State.FAILED_WIFI: - wifi_image.icon_name = "network-wireless-offline-symbolic"; + wifi_revealer.image.icon_name = "network-wireless-offline-symbolic"; wifi_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; case Network.State.FAILED_WIRED: case Network.State.WIRED_UNPLUGGED: - wired_image.icon_name = "network-wired-offline-symbolic"; + wired_revealer.image.icon_name = "network-wired-offline-symbolic"; wired_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; default: - network_image.icon_name = "network-offline-symbolic"; + network_revealer.image.icon_name = "network-offline-symbolic"; cellular_connection_state = ConnectionState.DISCONNECTED; wifi_connection_state = ConnectionState.DISCONNECTED; wired_connection_state = ConnectionState.DISCONNECTED; @@ -306,4 +271,19 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { wired_revealer.reveal_child = false; } } + + private class ConnectionRevealer : Gtk.Revealer { + public Gtk.Image image { get; construct set; } + + public ConnectionRevealer.from_icon_name (string icon_name) { + image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.LARGE_TOOLBAR); + } + + construct { + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT; + reveal_child = true; + + add (image); + } + } } From f20e6d6b8d563bb4d96502cfe48199cf2b2f0221 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 10 Apr 2021 14:58:25 +0200 Subject: [PATCH 08/11] Handle DISCONNECTED_WIRED --- src/Widgets/DisplayWidget.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index ce933b2b..443dc7a0 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -104,6 +104,11 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { wired_connection_state = ConnectionState.DISCONNECTED; update_icons (); break; + case Network.State.DISCONNECTED_WIRED: + wired_revealer.image.icon_name = "network-wired-disconnected"; + wired_connection_state = ConnectionState.DISCONNECTED; + update_icons (); + break; case Network.State.CONNECTED_VPN: vpn_revealer.reveal_child = true; break; From bd5242c54b903f600006b2fea5792f71e450b976 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 10 Apr 2021 15:00:07 +0200 Subject: [PATCH 09/11] Remove own implementation of to_string () --- src/Utils.vala | 53 -------------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/src/Utils.vala b/src/Utils.vala index 9110aee9..a59466f8 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -74,57 +74,4 @@ public enum Network.State { return 8; } } - - public string to_string () { - switch (this) { - case Network.State.DISCONNECTED: - return "DISCONNECTED"; - case Network.State.WIRED_UNPLUGGED: - return "WIRED_UNPLUGGED"; - case Network.State.DISCONNECTED_WIRED: - return "DISCONNECTED_WIRED"; - case Network.State.DISCONNECTED_AIRPLANE_MODE: - return "DISCONNECTED_AIRPLANE_MODE"; - case Network.State.CONNECTED_WIRED: - return "CONNECTED_WIRED"; - case Network.State.CONNECTED_VPN: - return "CONNECTED_VPN"; - case Network.State.CONNECTED_WIFI: - return "CONNECTED_WIFI"; - case Network.State.CONNECTED_WIFI_WEAK: - return "CONNECTED_WIFI_WEAK"; - case Network.State.CONNECTED_WIFI_OK: - return "CONNECTED_WIFI_OK"; - case Network.State.CONNECTED_WIFI_GOOD: - return "CONNECTED_WIFI_GOOD"; - case Network.State.CONNECTED_WIFI_EXCELLENT: - return "CONNECTED_WIFI_EXCELLENT"; - case Network.State.CONNECTED_MOBILE_WEAK: - return "CONNECTED_MOBILE_WEAK"; - case Network.State.CONNECTED_MOBILE_OK: - return "CONNECTED_MOBILE_OK"; - case Network.State.CONNECTED_MOBILE_GOOD: - return "CONNECTED_MOBILE_GOOD"; - case Network.State.CONNECTED_MOBILE_EXCELLENT: - return "CONNECTED_MOBILE_EXCELLENT"; - case Network.State.CONNECTING_WIFI: - return "CONNECTING_WIFI"; - case Network.State.CONNECTING_MOBILE: - return "CONNECTING_MOBILE"; - case Network.State.CONNECTING_WIRED: - return "CONNECTING_WIRED"; - case Network.State.CONNECTING_VPN: - return "CONNECTING_VPN"; - case Network.State.FAILED_WIRED: - return "FAILED_WIRED"; - case Network.State.FAILED_WIFI: - return "FAILED_WIFI"; - case Network.State.FAILED_MOBILE: - return "FAILED_MOBILE"; - case Network.State.FAILED_VPN: - return "FAILED_VPN"; - } - - return "UNKNOWN"; - } } From 7c41624459d0737f9a45be8f455e8357bab3b4ac Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 10 Apr 2021 15:15:24 +0200 Subject: [PATCH 10/11] Only reveal network by default --- src/Widgets/DisplayWidget.vala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 443dc7a0..552c4ef9 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -50,7 +50,9 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { wired_revealer = new ConnectionRevealer.from_icon_name ("network-wired-offline-symbolic"); - network_revealer = new ConnectionRevealer.from_icon_name ("network-offline-symbolic"); + network_revealer = new ConnectionRevealer.from_icon_name ("network-offline-symbolic") { + reveal_child = true + }; extra_info_label = new Gtk.Label (null) { margin_start = 4, @@ -286,7 +288,6 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { construct { transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT; - reveal_child = true; add (image); } From 5e9ea02e9e15ac0af7159f882a50a838af512fe8 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 10 Apr 2021 16:06:12 +0200 Subject: [PATCH 11/11] Add image in construct --- src/Widgets/DisplayWidget.vala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 552c4ef9..dae57e6e 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -281,12 +281,14 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { private class ConnectionRevealer : Gtk.Revealer { public Gtk.Image image { get; construct set; } + private string _icon_name; public ConnectionRevealer.from_icon_name (string icon_name) { - image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.LARGE_TOOLBAR); + _icon_name = icon_name; } construct { + image = new Gtk.Image.from_icon_name (_icon_name, Gtk.IconSize.LARGE_TOOLBAR); transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT; add (image);