From a8284ca62c3eb3b0f3b7d515766fd7aa5e0b0071 Mon Sep 17 00:00:00 2001 From: leixa Date: Fri, 26 Nov 2021 17:40:48 +0800 Subject: [PATCH 1/6] fix reconnecting while set switchbutton to unactive --- po/zh_CN.po | 1 - src/Views/EthernetPage.vala | 6 +----- src/Widgets/Page.vala | 40 ++++++++++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/po/zh_CN.po b/po/zh_CN.po index 2d4c1495..e3e86d4d 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -49,7 +49,6 @@ msgid "Requires more information" msgstr "需要更多信息" #: src/Utils.vala:106 -#, fuzzy #| msgid "Requesting adresses…" msgid "Requesting addresses…" msgstr "正在请求地址…" diff --git a/src/Views/EthernetPage.vala b/src/Views/EthernetPage.vala index 59268e82..b6c0ec78 100644 --- a/src/Views/EthernetPage.vala +++ b/src/Views/EthernetPage.vala @@ -57,7 +57,7 @@ namespace Network.Widgets { show_all (); status_switch.bind_property ("active", top_revealer, "reveal-child", GLib.BindingFlags.SYNC_CREATE); - update (); + // update ();//base will call this, no need call here } public override void update_name (int count) { @@ -82,12 +82,8 @@ namespace Network.Widgets { if (state == NM.DeviceState.UNAVAILABLE) { widgets_stack.visible_child = no_cable; - status_switch.active = false; - status_switch.sensitive = false; } else { widgets_stack.visible_child = top_revealer; - status_switch.active = true; - status_switch.sensitive = true; } } } diff --git a/src/Widgets/Page.vala b/src/Widgets/Page.vala index b5edaa1d..f99ee65e 100644 --- a/src/Widgets/Page.vala +++ b/src/Widgets/Page.vala @@ -25,6 +25,7 @@ namespace Network.Widgets { public NM.Device? device { get; construct; } protected InfoBox? info_box; + private bool switch_updating = false; construct { content_area.orientation = Gtk.Orientation.VERTICAL; @@ -37,7 +38,7 @@ namespace Network.Widgets { } if (activatable) { - update_switch (); + // update_switch (); // info_box.info_changed () will trigger update ,no need to call here status_switch.notify["active"].connect (control_switch_activated); } @@ -70,11 +71,44 @@ namespace Network.Widgets { if (!activatable) { return; } - - status_switch.active = device.get_state () != NM.DeviceState.DISCONNECTED && device.get_state () != NM.DeviceState.DEACTIVATING; + switch_updating = true; + switch (device.state) { + case NM.DeviceState.UNKNOWN: + case NM.DeviceState.UNMANAGED: + case NM.DeviceState.UNAVAILABLE: + case NM.DeviceState.FAILED: + status_switch.sensitive = false; + status_switch.active = false; + break; + case NM.DeviceState.DISCONNECTED: + case NM.DeviceState.DEACTIVATING: + status_switch.sensitive = true; + status_switch.active = false; + switch_updating = false; + break; + case NM.DeviceState.PREPARE: + case NM.DeviceState.CONFIG: + case NM.DeviceState.NEED_AUTH: + case NM.DeviceState.IP_CONFIG: + case NM.DeviceState.IP_CHECK: + case NM.DeviceState.SECONDARIES: + status_switch.sensitive = false; + status_switch.active = true; + break; + case NM.DeviceState.ACTIVATED: + status_switch.sensitive = true; + status_switch.active = true; + switch_updating = false; + break; + } + // warning ("update switch activated to ==============%s", Utils.state_to_string (device.state)); } protected virtual void control_switch_activated () { + if(switch_updating) + return; + // warning ("switch activated ==============%s, cur:%s", status_switch.active.to_string (), Utils.state_to_string (device.state)); + if (!status_switch.active && device.get_state () == NM.DeviceState.ACTIVATED) { try { device.disconnect (null); From b4fa3bf40b337bc705f4fbd8d0cc5adb43fc7cfc Mon Sep 17 00:00:00 2001 From: anzye <360845991@qq.com> Date: Tue, 14 Dec 2021 10:18:29 +0800 Subject: [PATCH 2/6] Update src/Widgets/Page.vala fix for elementary code style Co-authored-by: Jeremy Wootten --- src/Widgets/Page.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Widgets/Page.vala b/src/Widgets/Page.vala index f99ee65e..6f707ed7 100644 --- a/src/Widgets/Page.vala +++ b/src/Widgets/Page.vala @@ -105,8 +105,9 @@ namespace Network.Widgets { } protected virtual void control_switch_activated () { - if(switch_updating) + if (switch_updating) { return; + } // warning ("switch activated ==============%s, cur:%s", status_switch.active.to_string (), Utils.state_to_string (device.state)); if (!status_switch.active && device.get_state () == NM.DeviceState.ACTIVATED) { From a4bc5bb6c33906c8a8de2553c5bf029239a04c41 Mon Sep 17 00:00:00 2001 From: anzye <360845991@qq.com> Date: Tue, 14 Dec 2021 10:24:00 +0800 Subject: [PATCH 3/6] remove the commented out code --- src/Views/EthernetPage.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Views/EthernetPage.vala b/src/Views/EthernetPage.vala index b6c0ec78..4b299e2a 100644 --- a/src/Views/EthernetPage.vala +++ b/src/Views/EthernetPage.vala @@ -57,7 +57,6 @@ namespace Network.Widgets { show_all (); status_switch.bind_property ("active", top_revealer, "reveal-child", GLib.BindingFlags.SYNC_CREATE); - // update ();//base will call this, no need call here } public override void update_name (int count) { From 45474467732b8eec0e6e465209344df27fa171d7 Mon Sep 17 00:00:00 2001 From: anzye <360845991@qq.com> Date: Tue, 14 Dec 2021 10:26:44 +0800 Subject: [PATCH 4/6] remove the commented out code, add default case --- src/Widgets/Page.vala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Widgets/Page.vala b/src/Widgets/Page.vala index 6f707ed7..a7a31478 100644 --- a/src/Widgets/Page.vala +++ b/src/Widgets/Page.vala @@ -38,7 +38,6 @@ namespace Network.Widgets { } if (activatable) { - // update_switch (); // info_box.info_changed () will trigger update ,no need to call here status_switch.notify["active"].connect (control_switch_activated); } @@ -100,15 +99,15 @@ namespace Network.Widgets { status_switch.active = true; switch_updating = false; break; + default: + break; } - // warning ("update switch activated to ==============%s", Utils.state_to_string (device.state)); } protected virtual void control_switch_activated () { if (switch_updating) { return; } - // warning ("switch activated ==============%s, cur:%s", status_switch.active.to_string (), Utils.state_to_string (device.state)); if (!status_switch.active && device.get_state () == NM.DeviceState.ACTIVATED) { try { From 5603d6a2a7db1f95a5c3458b3b222e4a256c79dd Mon Sep 17 00:00:00 2001 From: leixa Date: Tue, 14 Dec 2021 10:46:57 +0800 Subject: [PATCH 5/6] fix reopen plug crash when a usb-network was removed --- src/Utils.vala | 9 ++++++++- src/Widgets/DeviceList.vala | 34 ++-------------------------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/Utils.vala b/src/Utils.vala index b2d03cd5..b9c07d17 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -85,7 +85,14 @@ namespace Network { public enum ItemType { DEVICE = 0, VIRTUAL, - INVALID + INVALID; + public string to_string () { + switch (this) { + case DEVICE: return _("Devices"); + case VIRTUAL: return _("Virtual"); + default: return _("Invalid"); + } + } } public static string state_to_string (NM.DeviceState state) { diff --git a/src/Widgets/DeviceList.vala b/src/Widgets/DeviceList.vala index c3793877..6ab44011 100644 --- a/src/Widgets/DeviceList.vala +++ b/src/Widgets/DeviceList.vala @@ -21,8 +21,6 @@ namespace Network.Widgets { public class DeviceList : Gtk.ListBox { public signal void show_no_devices (bool show); - private Gtk.Label virtual_l; - private Gtk.Label devices_l; private DeviceItem proxy; private DeviceItem vpn; @@ -30,16 +28,6 @@ namespace Network.Widgets { selection_mode = Gtk.SelectionMode.SINGLE; activate_on_single_click = true; - virtual_l = new Gtk.Label (_("Virtual")) { - halign = Gtk.Align.START - }; - virtual_l.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); - - devices_l = new Gtk.Label (_("Devices")) { - halign = Gtk.Align.START - }; - devices_l.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); - set_header_func (update_headers); set_sort_func (sort_items); @@ -140,28 +128,10 @@ namespace Network.Widgets { private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) { unowned DeviceItem row_item = (DeviceItem) row; unowned DeviceItem? before_item = (DeviceItem) before; - if (row_item.item_type == Utils.ItemType.VIRTUAL) { - if (before_item != null && before_item.item_type == Utils.ItemType.VIRTUAL) { - row.set_header (null); - return; - } - if (virtual_l.get_parent () != null) { - virtual_l.unparent (); - } - - row.set_header (virtual_l); - } else if (row_item.item_type == Utils.ItemType.DEVICE) { - if (before_item != null && before_item.item_type == Utils.ItemType.DEVICE) { - row.set_header (null); - return; - } - - if (devices_l.get_parent () != null) { - devices_l.unparent (); - } - row.set_header (devices_l); + if (before_item==null || row_item.item_type!=before_item.item_type) { + row.set_header (new Granite.HeaderLabel (row_item.item_type.to_string ())); } else { row.set_header (null); } From b4772af31d8b2a06d853b3c5883efe5dd5948af7 Mon Sep 17 00:00:00 2001 From: leixa Date: Tue, 14 Dec 2021 11:16:13 +0800 Subject: [PATCH 6/6] fix elementary code sytle --- src/Widgets/DeviceList.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/DeviceList.vala b/src/Widgets/DeviceList.vala index 6ab44011..1a3f6bc6 100644 --- a/src/Widgets/DeviceList.vala +++ b/src/Widgets/DeviceList.vala @@ -130,7 +130,7 @@ namespace Network.Widgets { unowned DeviceItem? before_item = (DeviceItem) before; - if (before_item==null || row_item.item_type!=before_item.item_type) { + if (before_item == null || row_item.item_type != before_item.item_type) { row.set_header (new Granite.HeaderLabel (row_item.item_type.to_string ())); } else { row.set_header (null);