Merge lp:~donadigo/switchboard-plug-networking/page-cleanup into lp:~elementary-pantheon/switchboard-plug-networking/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 117
Merged at revision: 115
Proposed branch: lp:~donadigo/switchboard-plug-networking/page-cleanup
Merge into: lp:~elementary-pantheon/switchboard-plug-networking/trunk
Diff against target: 281 lines (+48/-67)
5 files modified
src/Plug.vala (+0/-4)
src/Widgets/Device/DeviceItem.vala (+2/-2)
src/Widgets/Device/DevicePage.vala (+2/-15)
src/Widgets/Page.vala (+32/-8)
src/Widgets/WiFi/WiFiPage.vala (+12/-38)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-networking/page-cleanup
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+265743@code.launchpad.net

Commit message

Page cleanup:
* Added init () method
* Renamed wifi states to: Enabled and Disabled
* Moved methods from DevicePage to Page class to make them more unified.

Description of the change

Page cleanup. Moved some methods from DevicePage to Page class to make them more unified. Renamed wifi states to: Enabled and Disabled.

* Fixed: control_switch does not switch when device state changed not from plug.

* Switch now reflects wireless state instead of the device state.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Enabling and disabling doesn't seem to work as expected.

Disabling always crashes the plug (I would consider this a regression since in trunk the switch does nothing. Nothing is probably better than a crash).

Enabling doesn't change the status in the sidebar (it should be "Disconnected" to match the status shown in the plug). However since the sidebar status doesn't seem to work correctly in trunk either, I don't think this is a blocker or necessarily needs to be fixed in this branch. Maybe in another branch the sidebar status should be changed so that it reads the same as the status in the plug. Its information seems to be accurate and reflect various network states.

The switch moves to the "disabled" state when merely disconnected. It sounds like you introduced this change intentionally, but it doesn't make design sense. There is already a disconnect button. This switch should reflect whether the device is on and capable of connecting to a network, not whether it is connected or not.

review: Needs Fixing (ux)
113. By Adam Bieńkowski

Clean code

114. By Adam Bieńkowski

Remove unneded debug line

115. By Adam Bieńkowski

Fixed: control switch goes crazy because of unrelated updating it in update () method

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Daniel, can you test this merge: https://code.launchpad.net/~donadigo/switchboard-plug-networking/page-use-client-singals/+merge/265846 ? This is new version of the old use-client-page. It solves not changing state in wifi item.

116. By Adam Bieńkowski

Scan for duplicates removed for now

117. By Adam Bieńkowski

Fixed: disabling control switch causes switchboard to crash in remove_access_point method

Revision history for this message
Danielle Foré (danrabbit) wrote :

Looks like the issues I encountered previously were fixed here with the exception of the sidebar stuff, which as I said probably can/should be addressed in another branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Plug.vala'
--- src/Plug.vala 2015-07-18 16:56:50 +0000
+++ src/Plug.vala 2015-07-24 17:43:15 +0000
@@ -120,10 +120,6 @@
120 content.add_named (wifi_page, string_id);120 content.add_named (wifi_page, string_id);
121121
122 switch_wifi_status (wifi_page); 122 switch_wifi_status (wifi_page);
123 wifi_page.switch_callback.connect (() => {
124 client.wireless_set_enabled (wifi_page.control_switch.get_active ());
125 switch_wifi_status (wifi_page);
126 });
127123
128 device_list.wifi.activate.connect (() => {124 device_list.wifi.activate.connect (() => {
129 if (content.get_visible_child_name () != string_id)125 if (content.get_visible_child_name () != string_id)
130126
=== modified file 'src/Widgets/Device/DeviceItem.vala'
--- src/Widgets/Device/DeviceItem.vala 2015-07-18 19:31:20 +0000
+++ src/Widgets/Device/DeviceItem.vala 2015-07-24 17:43:15 +0000
@@ -149,11 +149,11 @@
149 status_image.icon_name = "user-available";149 status_image.icon_name = "user-available";
150 break;150 break;
151 case "wifi-enabled":151 case "wifi-enabled":
152 row_description.label = Utils.state_to_string (NM.DeviceState.ACTIVATED);152 row_description.label = _("Enabled");
153 status_image.icon_name = "user-available";153 status_image.icon_name = "user-available";
154 break;154 break;
155 case "wifi-disabled":155 case "wifi-disabled":
156 row_description.label = Utils.state_to_string (NM.DeviceState.DISCONNECTED);156 row_description.label = _("Disabled");
157 status_image.icon_name = "user-busy";157 status_image.icon_name = "user-busy";
158 break;158 break;
159 }159 }
160160
=== modified file 'src/Widgets/Device/DevicePage.vala'
--- src/Widgets/Device/DevicePage.vala 2015-07-18 16:56:50 +0000
+++ src/Widgets/Device/DevicePage.vala 2015-07-24 17:43:15 +0000
@@ -23,35 +23,22 @@
23namespace Network.Widgets {23namespace Network.Widgets {
24 public class DevicePage : Page {24 public class DevicePage : Page {
25 public DeviceItem owner;25 public DeviceItem owner;
26 public InfoBox info_box;
2726
28 public DevicePage.from_owner (DeviceItem? _owner) {27 public DevicePage.from_owner (DeviceItem? _owner) {
29 this.owner = _owner;28 this.owner = _owner;
30 this.device = owner.get_item_device ();
31 this.icon_name = owner.get_item_icon_name ();29 this.icon_name = owner.get_item_icon_name ();
32 this.title = Utils.type_to_string (device.get_device_type ());30 this.title = Utils.type_to_string (device.get_device_type ());
33 this.margin_end = 12;
34
35 info_box = new info_box.from_owner (owner);31 info_box = new info_box.from_owner (owner);
36 info_box.margin_end = this.INFO_BOX_MARGIN;32 this.init (owner.get_item_device (), info_box);
37 info_box.info_changed.connect (update);
3833
39 var details_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);34 var details_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
40 details_box.pack_start (Utils.get_advanced_button_from_device (device), false, false, 0); 35 details_box.pack_start (Utils.get_advanced_button_from_device (device), false, false, 0);
4136
42 update ();37 update (info_box);
4338
44 this.add (info_box);39 this.add (info_box);
45 this.pack_end (details_box, false, false, 0);40 this.pack_end (details_box, false, false, 0);
46 this.show_all ();41 this.show_all ();
47 }42 }
48
49 private void update () {
50 string sent_bytes, received_bytes;
51 this.get_activity_information (device.get_iface (), out sent_bytes, out received_bytes);
52 info_box.update_activity (sent_bytes, received_bytes);
53
54 control_switch.active = (device.get_state () == NM.DeviceState.ACTIVATED);
55 }
56 }43 }
57}44}
5845
=== modified file 'src/Widgets/Page.vala'
--- src/Widgets/Page.vala 2015-07-18 16:11:54 +0000
+++ src/Widgets/Page.vala 2015-07-24 17:43:15 +0000
@@ -1,11 +1,9 @@
11
2namespace Network {2namespace Network.Widgets {
3 public class Page : Gtk.Box {3 public class Page : Gtk.Box {
4 public const int INFO_BOX_MARGIN = 16;
5
6 public NM.Device device;4 public NM.Device device;
5 public InfoBox info_box;
7 public Gtk.Switch control_switch;6 public Gtk.Switch control_switch;
8 public signal void switch_callback ();
9 public signal void show_error ();7 public signal void show_error ();
108
11 private string _icon_name; 9 private string _icon_name;
@@ -40,6 +38,15 @@
40 this.orientation = Gtk.Orientation.VERTICAL;38 this.orientation = Gtk.Orientation.VERTICAL;
41 this.margin = 12;39 this.margin = 12;
42 this.spacing = 24;40 this.spacing = 24;
41 }
42
43 public void init (NM.Device _device, Widgets.InfoBox _info_box) {
44 this.device = _device;
45 this.info_box = _info_box;
46 info_box.margin_end = 16;
47 info_box.info_changed.connect (() => {
48 update (info_box);
49 });
4350
44 device_img = new Gtk.Image.from_icon_name (_icon_name, Gtk.IconSize.DIALOG);51 device_img = new Gtk.Image.from_icon_name (_icon_name, Gtk.IconSize.DIALOG);
45 device_img.pixel_size = 48;52 device_img.pixel_size = 48;
@@ -48,7 +55,13 @@
48 device_label.get_style_context ().add_class ("h2");55 device_label.get_style_context ().add_class ("h2");
4956
50 control_switch = new Gtk.Switch ();57 control_switch = new Gtk.Switch ();
51 control_switch.activate.connect (control_switch_activated);58 if (device.get_device_type () == NM.DeviceType.WIFI) {
59 control_switch.active = (client.wireless_get_enabled ());
60 } else {
61 control_switch.active = (device.get_state () == NM.DeviceState.ACTIVATED);
62 }
63
64 control_switch.button_press_event.connect (control_switch_activated);
5265
53 control_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);66 control_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
54 control_box.pack_start (device_img, false, false, 0);67 control_box.pack_start (device_img, false, false, 0);
@@ -56,7 +69,13 @@
56 control_box.pack_end (control_switch, false, false, 0); 69 control_box.pack_end (control_switch, false, false, 0);
5770
58 this.add (control_box);71 this.add (control_box);
59 this.show_all (); 72 this.show_all ();
73 }
74
75 public void update (Widgets.InfoBox info_box) {
76 string sent_bytes, received_bytes;
77 this.get_activity_information (device.get_iface (), out sent_bytes, out received_bytes);
78 info_box.update_activity (sent_bytes, received_bytes);
60 }79 }
6180
62 public void add_switch_title (string title) {81 public void add_switch_title (string title) {
@@ -65,7 +84,12 @@
65 control_box.pack_end (label, false, false, 0);84 control_box.pack_end (label, false, false, 0);
66 }85 }
6786
68 private void control_switch_activated () {87 private bool control_switch_activated () {
88 if (device.get_device_type () == NM.DeviceType.WIFI) {
89 client.wireless_set_enabled (!client.wireless_get_enabled ());
90 return false;
91 }
92
69 if (device.get_state () == NM.DeviceState.ACTIVATED) {93 if (device.get_state () == NM.DeviceState.ACTIVATED) {
70 device.disconnect (null);94 device.disconnect (null);
71 } else {95 } else {
@@ -79,7 +103,7 @@
79 }103 }
80 }104 }
81105
82 this.switch_callback (); 106 return false;
83 }107 }
84108
85 public void get_activity_information (string iface, out string sent_bytes, out string received_bytes) {109 public void get_activity_information (string iface, out string sent_bytes, out string received_bytes) {
86110
=== modified file 'src/Widgets/WiFi/WiFiPage.vala'
--- src/Widgets/WiFi/WiFiPage.vala 2015-07-23 20:51:21 +0000
+++ src/Widgets/WiFi/WiFiPage.vala 2015-07-24 17:43:15 +0000
@@ -23,7 +23,6 @@
23namespace Network.Widgets {23namespace Network.Widgets {
24 public class WiFiPage : Page {24 public class WiFiPage : Page {
25 public new NM.DeviceWifi device;25 public new NM.DeviceWifi device;
26 private InfoBox info_box;
27 private Gtk.ListBox wifi_list;26 private Gtk.ListBox wifi_list;
28 private List<WiFiEntry> entries;27 private List<WiFiEntry> entries;
29 private const string[] BLACKLISTED = { "Free Public WiFi" };28 private const string[] BLACKLISTED = { "Free Public WiFi" };
@@ -37,6 +36,8 @@
37 this.device = wifidevice;36 this.device = wifidevice;
38 this.icon_name = "network-wireless";37 this.icon_name = "network-wireless";
39 this.title = _("Wi-Fi Network");38 this.title = _("Wi-Fi Network");
39 info_box = new InfoBox.from_device (device);
40 this.init (wifidevice, info_box);
4041
41 entries = new List<WiFiEntry> ();42 entries = new List<WiFiEntry> ();
4243
@@ -51,10 +52,6 @@
51 scrolled.vexpand = true;52 scrolled.vexpand = true;
52 scrolled.shadow_type = Gtk.ShadowType.OUT;53 scrolled.shadow_type = Gtk.ShadowType.OUT;
5354
54 info_box = new info_box.from_device (device);
55 info_box.margin_end = this.INFO_BOX_MARGIN;
56 info_box.info_changed.connect (update);
57
58 var disconnect_btn = new Gtk.Button.with_label (_("Disconnect"));55 var disconnect_btn = new Gtk.Button.with_label (_("Disconnect"));
59 disconnect_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);56 disconnect_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
60 disconnect_btn.get_style_context ().add_class ("destructive-action");57 disconnect_btn.get_style_context ().add_class ("destructive-action");
@@ -90,7 +87,7 @@
90 device.access_point_added.connect (add_access_point);87 device.access_point_added.connect (add_access_point);
91 device.access_point_removed.connect (remove_access_point);88 device.access_point_removed.connect (remove_access_point);
9289
93 update ();90 update (info_box);
9491
95 this.add_switch_title (_("Wireless:"));92 this.add_switch_title (_("Wireless:"));
96 this.add (scrolled);93 this.add (scrolled);
@@ -99,14 +96,6 @@
99 this.show_all (); 96 this.show_all ();
100 }97 }
10198
102 private void update () {
103 string sent_bytes, received_bytes;
104 this.get_activity_information (device.get_iface (), out sent_bytes, out received_bytes);
105 info_box.update_activity (sent_bytes, received_bytes);
106
107 control_switch.active = (client.wireless_get_enabled () && device.get_state () == NM.DeviceState.ACTIVATED);
108 }
109
110 private void on_row_activated (Gtk.ListBoxRow row) {99 private void on_row_activated (Gtk.ListBoxRow row) {
111 if (device != null) { 100 if (device != null) {
112 /* Do not activate connection if it is already activated */101 /* Do not activate connection if it is already activated */
@@ -154,8 +143,10 @@
154143
155 /* Check if we are successfully connected to the requested point */144 /* Check if we are successfully connected to the requested point */
156 if (device.get_active_access_point () == (row as WiFiEntry).ap) {145 if (device.get_active_access_point () == (row as WiFiEntry).ap) {
157 foreach (var entry in entries)146 entries.@foreach ((entry) => {
158 entry.set_status_point (false, false);147 entry.set_status_point (false, false);
148 });
149
159 (row as WiFiEntry).set_status_point (true, false);150 (row as WiFiEntry).set_status_point (true, false);
160 }151 }
161 }152 }
@@ -190,23 +181,9 @@
190 insert_on_top = true;181 insert_on_top = true;
191 });182 });
192183
193 scan_for_duplicates.begin ();
194 wifi_list.show_all ();184 wifi_list.show_all ();
195 }185 }
196 186
197 private async void scan_for_duplicates () {
198 var entries_dup = entries.copy ();
199 entries.@foreach ((entry) => {
200 var ssid = entry.ap.get_ssid ();
201
202 entries_dup.@foreach ((entry_dup) => {
203 if (entry_dup.ap.get_ssid () == ssid) {
204 this.remove_access_point (entry_dup.ap);
205 }
206 });
207 });
208 }
209
210 private void add_access_point (Object ap) {187 private void add_access_point (Object ap) {
211 var row = new WiFiEntry.from_access_point (ap as NM.AccessPoint);188 var row = new WiFiEntry.from_access_point (ap as NM.AccessPoint);
212 if (!(row.ssid in BLACKLISTED) && row.ap.get_ssid () != null) {189 if (!(row.ssid in BLACKLISTED) && row.ap.get_ssid () != null) {
@@ -219,21 +196,18 @@
219 entries.append (row as WiFiEntry);196 entries.append (row as WiFiEntry);
220 }197 }
221198
222 if ((ap as NM.AccessPoint) == device.get_active_access_point ())199 if ((ap as NM.AccessPoint) == device.get_active_access_point ()) {
223 row.set_status_point (true, false);200 row.set_status_point (true, false);
201 }
224 }202 }
225 203
226 private void remove_access_point (Object ap_removed) {204 private void remove_access_point (Object ap_removed) {
227 var new_entries = new List<WiFiEntry> ();205 entries.@foreach ((entry) => {
228 foreach (var entry in entries) {206 if (((WiFiEntry) entry).ap == ap_removed) {
229 if ((entry as WiFiEntry).ap == ap_removed) {207 entries.remove (entry);
230 entry.destroy ();208 entry.destroy ();
231 } else {
232 new_entries.append (entry);
233 }209 }
234 }210 });
235
236 entries = new_entries.copy ();
237 }211 }
238212
239 private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {213 private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {

Subscribers

People subscribed via source and target branches

to all changes: