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/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/HotspotPage.vala b/src/Views/HotspotPage.vala index 6729c29b..bd3fe8a1 100644 --- a/src/Views/HotspotPage.vala +++ b/src/Views/HotspotPage.vala @@ -203,9 +203,13 @@ 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; + status_type = OFFLINE; } + + status = Utils.state_to_string (state); } protected override void update_switch () { diff --git a/src/Views/ProxyPage.vala b/src/Views/ProxyPage.vala index 0c3e13f0..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") ); } @@ -82,26 +80,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; - break; - default: - mode = Utils.CustomMode.INVALID; + status_type = SUCCESS; break; } - - owner.switch_status (mode); } } } 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 () { diff --git a/src/Widgets/DeviceItem.vala b/src/Widgets/DeviceItem.vala index d844ebe5..281129d2 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 = ""; } @@ -28,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, @@ -45,11 +60,8 @@ namespace Network.Widgets { page.bind_property ("title", this, "title", SYNC_CREATE); page.bind_property ("icon", this, "icon", SYNC_CREATE); - - switch_status (Utils.CustomMode.INVALID, page.state); - page.notify["state"].connect (() => { - switch_status (Utils.CustomMode.INVALID, page.state); - }); + page.bind_property ("status-type", this, "status-type", SYNC_CREATE); + page.bind_property ("status", this, "subtitle", SYNC_CREATE); } construct { @@ -70,8 +82,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 }; @@ -92,47 +105,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) { - 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 { - subtitle = Utils.state_to_string (state); - } - } else if (custom_mode != Utils.CustomMode.INVALID) { - 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; - } - } - - subtitle = "" + subtitle + ""; - } } } diff --git a/src/Widgets/Page.vala b/src/Widgets/Page.vala index cbcc8357..1d737939 100644 --- a/src/Widgets/Page.vala +++ b/src/Widgets/Page.vala @@ -49,13 +49,39 @@ 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; + } + + if (device is NM.DeviceWifi && state == UNAVAILABLE) { + status = _("Disabled"); + } else { + status = Utils.state_to_string (device.state); + } + } + public virtual void update () { if (info_box != null) { string sent_bytes, received_bytes;