From 2f529defde1a41c2602769534fd3ae7490744e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 12:25:30 -0700 Subject: [PATCH 1/6] Page: set status_type --- src/Views/ProxyPage.vala | 3 +++ src/Widgets/DeviceItem.vala | 41 +++++++++++++++++++++---------------- src/Widgets/Page.vala | 20 ++++++++++++++++++ 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/Views/ProxyPage.vala b/src/Views/ProxyPage.vala index 0c3e13f0..d69cdf8d 100644 --- a/src/Views/ProxyPage.vala +++ b/src/Views/ProxyPage.vala @@ -87,14 +87,17 @@ namespace Network.Widgets { case "none": mode = Utils.CustomMode.PROXY_NONE; status_switch.active = false; + status_type = OFFLINE; break; case "manual": mode = Utils.CustomMode.PROXY_MANUAL; status_switch.active = true; + status_type = SUCCESS; break; case "auto": mode = Utils.CustomMode.PROXY_AUTO; status_switch.active = true; + status_type = SUCCESS; break; default: mode = Utils.CustomMode.INVALID; diff --git a/src/Widgets/DeviceItem.vala b/src/Widgets/DeviceItem.vala index d844ebe5..1de8e4ce 100644 --- a/src/Widgets/DeviceItem.vala +++ b/src/Widgets/DeviceItem.vala @@ -19,6 +19,28 @@ namespace Network.Widgets { public class DeviceItem : Gtk.ListBoxRow { + public Switchboard.SettingsPage.StatusType status_type { + set { + switch (value) { + case ERROR: + status_image.icon_name = "emblem-error"; + break; + case OFFLINE: + status_image.icon_name = "emblem-disabled"; + break; + case SUCCESS: + status_image.icon_name = "emblem-enabled"; + break; + case WARNING: + status_image.icon_name = "emblem-warning"; + break; + case NONE: + status_image.clear (); + break; + } + } + } + public NM.Device? device { get; construct; default = null; } public Widgets.Page? page { get; set; default = null; } public string title { get; set; default = ""; } @@ -45,6 +67,7 @@ namespace Network.Widgets { page.bind_property ("title", this, "title", SYNC_CREATE); page.bind_property ("icon", this, "icon", SYNC_CREATE); + page.bind_property ("status-type", this, "status-type", SYNC_CREATE); switch_status (Utils.CustomMode.INVALID, page.state); page.notify["state"].connect (() => { @@ -95,21 +118,6 @@ namespace Network.Widgets { public void switch_status (Utils.CustomMode custom_mode, NM.DeviceState? state = null) { if (state != null) { - switch (state) { - case NM.DeviceState.ACTIVATED: - status_image.icon_name = "user-available"; - break; - case NM.DeviceState.DISCONNECTED: - status_image.icon_name = "user-offline"; - break; - case NM.DeviceState.FAILED: - status_image.icon_name = "user-busy"; - break; - default: - status_image.icon_name = "user-away"; - break; - } - if (device is NM.DeviceWifi && state == NM.DeviceState.UNAVAILABLE) { subtitle = _("Disabled"); } else { @@ -119,15 +127,12 @@ namespace Network.Widgets { switch (custom_mode) { case Utils.CustomMode.PROXY_NONE: subtitle = _("Disabled"); - status_image.icon_name = "user-offline"; break; case Utils.CustomMode.PROXY_MANUAL: subtitle = _("Enabled (manual mode)"); - status_image.icon_name = "user-available"; break; case Utils.CustomMode.PROXY_AUTO: subtitle = _("Enabled (auto mode)"); - status_image.icon_name = "user-available"; break; } } diff --git a/src/Widgets/Page.vala b/src/Widgets/Page.vala index cbcc8357..714025a8 100644 --- a/src/Widgets/Page.vala +++ b/src/Widgets/Page.vala @@ -49,13 +49,33 @@ namespace Network.Widgets { get_uuid (); device.state_changed.connect_after (() => { + update_status (); get_uuid (); }); + + update_status (); } show_end_title_buttons = true; } + private void update_status () { + switch (device.state) { + case ACTIVATED: + status_type = SUCCESS; + break; + case DISCONNECTED: + status_type = OFFLINE; + break; + case FAILED: + status_type = ERROR; + break; + default: + status_type = WARNING; + break; + } + } + public virtual void update () { if (info_box != null) { string sent_bytes, received_bytes; From 1f2062b21e561eec58a286032dce77323297e2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 12:39:49 -0700 Subject: [PATCH 2/6] get status from page --- src/Utils.vala | 9 --------- src/Views/ProxyPage.vala | 12 +++--------- src/Widgets/DeviceItem.vala | 33 +++------------------------------ src/Widgets/Page.vala | 6 ++++++ 4 files changed, 12 insertions(+), 48 deletions(-) diff --git a/src/Utils.vala b/src/Utils.vala index c4d71eef..84fbf109 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -81,15 +81,6 @@ namespace Network { return true; } - public enum CustomMode { - PROXY_NONE = 0, - PROXY_MANUAL, - PROXY_AUTO, - HOTSPOT_ENABLED, - HOTSPOT_DISABLED, - INVALID - } - public enum ItemType { DEVICE = 0, VIRTUAL, diff --git a/src/Views/ProxyPage.vala b/src/Views/ProxyPage.vala index d69cdf8d..d0115529 100644 --- a/src/Views/ProxyPage.vala +++ b/src/Views/ProxyPage.vala @@ -82,29 +82,23 @@ namespace Network.Widgets { } private void update_mode () { - var mode = Utils.CustomMode.INVALID; switch (Network.Plug.proxy_settings.get_string ("mode")) { case "none": - mode = Utils.CustomMode.PROXY_NONE; + status = _("Disabled"); status_switch.active = false; status_type = OFFLINE; break; case "manual": - mode = Utils.CustomMode.PROXY_MANUAL; + status = _("Enabled (manual mode)"); status_switch.active = true; status_type = SUCCESS; break; case "auto": - mode = Utils.CustomMode.PROXY_AUTO; + status = _("Enabled (auto mode)"); status_switch.active = true; status_type = SUCCESS; break; - default: - mode = Utils.CustomMode.INVALID; - break; } - - owner.switch_status (mode); } } } diff --git a/src/Widgets/DeviceItem.vala b/src/Widgets/DeviceItem.vala index 1de8e4ce..cbe88cd3 100644 --- a/src/Widgets/DeviceItem.vala +++ b/src/Widgets/DeviceItem.vala @@ -68,11 +68,7 @@ namespace Network.Widgets { page.bind_property ("title", this, "title", SYNC_CREATE); page.bind_property ("icon", this, "icon", SYNC_CREATE); page.bind_property ("status-type", this, "status-type", SYNC_CREATE); - - switch_status (Utils.CustomMode.INVALID, page.state); - page.notify["state"].connect (() => { - switch_status (Utils.CustomMode.INVALID, page.state); - }); + page.bind_property ("status", this, "subtitle", SYNC_CREATE); } construct { @@ -93,8 +89,9 @@ namespace Network.Widgets { halign = Gtk.Align.START, valign = Gtk.Align.START }; + row_description.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL); - status_image = new Gtk.Image.from_icon_name ("user-available") { + status_image = new Gtk.Image () { halign = Gtk.Align.END, valign = Gtk.Align.END }; @@ -115,29 +112,5 @@ namespace Network.Widgets { bind_property ("subtitle", row_description, "label"); bind_property ("icon", row_image, "gicon"); } - - public void switch_status (Utils.CustomMode custom_mode, NM.DeviceState? state = null) { - if (state != null) { - if (device is NM.DeviceWifi && state == NM.DeviceState.UNAVAILABLE) { - subtitle = _("Disabled"); - } else { - subtitle = Utils.state_to_string (state); - } - } else if (custom_mode != Utils.CustomMode.INVALID) { - switch (custom_mode) { - case Utils.CustomMode.PROXY_NONE: - subtitle = _("Disabled"); - break; - case Utils.CustomMode.PROXY_MANUAL: - subtitle = _("Enabled (manual mode)"); - break; - case Utils.CustomMode.PROXY_AUTO: - subtitle = _("Enabled (auto mode)"); - break; - } - } - - subtitle = "" + subtitle + ""; - } } } diff --git a/src/Widgets/Page.vala b/src/Widgets/Page.vala index 714025a8..1d737939 100644 --- a/src/Widgets/Page.vala +++ b/src/Widgets/Page.vala @@ -74,6 +74,12 @@ namespace Network.Widgets { status_type = WARNING; break; } + + if (device is NM.DeviceWifi && state == UNAVAILABLE) { + status = _("Disabled"); + } else { + status = Utils.state_to_string (device.state); + } } public virtual void update () { From faa968b6dc1ac2f33529ec405754f5ef8b854fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 12:43:41 -0700 Subject: [PATCH 3/6] Deviceitems can only be constructed from page --- src/MainView.vala | 4 ++-- src/Views/ProxyPage.vala | 6 ++---- src/Widgets/DeviceItem.vala | 7 ------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/MainView.vala b/src/MainView.vala index 68c55f1a..0f9a351d 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -35,10 +35,10 @@ public class Network.MainView : Gtk.Box { virtual_header = new Granite.HeaderLabel (_("Virtual")); devices_header = new Granite.HeaderLabel (_("Devices")); - var proxy = new Widgets.DeviceItem (_("Proxy"), "preferences-system-network") { + var proxy_page = new Widgets.ProxyPage (); + var proxy = new Widgets.DeviceItem.from_page (proxy_page) { item_type = VIRTUAL }; - proxy.page = new Widgets.ProxyPage (proxy); vpn_page = new VPNPage (); var vpn = new Widgets.DeviceItem.from_page (vpn_page) { diff --git a/src/Views/ProxyPage.vala b/src/Views/ProxyPage.vala index d0115529..1e33022e 100644 --- a/src/Views/ProxyPage.vala +++ b/src/Views/ProxyPage.vala @@ -22,14 +22,12 @@ namespace Network.Widgets { public Gtk.Stack stack; public signal void update_status_label (string mode); - public DeviceItem owner { get; construct; } - public ProxyPage (DeviceItem _owner) { + public ProxyPage () { Object ( activatable: true, title: _("Proxy"), - icon: new ThemedIcon ("preferences-system-network"), - owner: _owner + icon: new ThemedIcon ("preferences-system-network") ); } diff --git a/src/Widgets/DeviceItem.vala b/src/Widgets/DeviceItem.vala index cbe88cd3..281129d2 100644 --- a/src/Widgets/DeviceItem.vala +++ b/src/Widgets/DeviceItem.vala @@ -50,13 +50,6 @@ namespace Network.Widgets { private Gtk.Image status_image; - public DeviceItem (string title, string icon_name) { - Object ( - title: title, - icon: new ThemedIcon (icon_name) - ); - } - public DeviceItem.from_page (Widgets.Page page, string icon_name = "network-wired") { Object ( device: page.device, From e80e320bc5ee900da42cf1b08f7242282fae8325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 12:51:26 -0700 Subject: [PATCH 4/6] fix VPN --- src/Views/VPNPage.vala | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Views/VPNPage.vala b/src/Views/VPNPage.vala index 21488d1e..c2f38784 100644 --- a/src/Views/VPNPage.vala +++ b/src/Views/VPNPage.vala @@ -164,7 +164,22 @@ public class Network.VPNPage : Network.Widgets.Page { } } - update_switch (); + switch (state) { + case ACTIVATED: + status_type = SUCCESS; + break; + case DISCONNECTED: + status_type = OFFLINE; + break; + case FAILED: + status_type = ERROR; + break; + default: + status_type = WARNING; + break; + } + + status = Utils.state_to_string (state); } protected override void update_switch () { From 2d46e17aa4bc6557a1809804cf2022e64d5ca802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 12:58:56 -0700 Subject: [PATCH 5/6] Fix hotspot --- src/Views/HotspotPage.vala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Views/HotspotPage.vala b/src/Views/HotspotPage.vala index 6729c29b..04206852 100644 --- a/src/Views/HotspotPage.vala +++ b/src/Views/HotspotPage.vala @@ -206,6 +206,23 @@ } else { state = NM.DeviceState.DISCONNECTED; } + + switch (state) { + case ACTIVATED: + status_type = SUCCESS; + break; + case DISCONNECTED: + status_type = OFFLINE; + break; + case FAILED: + status_type = ERROR; + break; + default: + status_type = WARNING; + break; + } + + status = Utils.state_to_string (state); } protected override void update_switch () { From a40373be3b2535441355df050233876f8da05c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 13:00:22 -0700 Subject: [PATCH 6/6] simpler --- src/Views/HotspotPage.vala | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Views/HotspotPage.vala b/src/Views/HotspotPage.vala index 04206852..bd3fe8a1 100644 --- a/src/Views/HotspotPage.vala +++ b/src/Views/HotspotPage.vala @@ -203,23 +203,10 @@ var root_iface_is_hotspot = Utils.get_device_is_hotspot (root_iface.wifi_device); if (root_iface_is_hotspot) { state = NM.DeviceState.ACTIVATED; + status_type = SUCCESS; } else { state = NM.DeviceState.DISCONNECTED; - } - - switch (state) { - case ACTIVATED: - status_type = SUCCESS; - break; - case DISCONNECTED: - status_type = OFFLINE; - break; - case FAILED: - status_type = ERROR; - break; - default: - status_type = WARNING; - break; + status_type = OFFLINE; } status = Utils.state_to_string (state);