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
1=== modified file 'src/Plug.vala'
2--- src/Plug.vala 2015-07-18 16:56:50 +0000
3+++ src/Plug.vala 2015-07-24 17:43:15 +0000
4@@ -120,10 +120,6 @@
5 content.add_named (wifi_page, string_id);
6
7 switch_wifi_status (wifi_page);
8- wifi_page.switch_callback.connect (() => {
9- client.wireless_set_enabled (wifi_page.control_switch.get_active ());
10- switch_wifi_status (wifi_page);
11- });
12
13 device_list.wifi.activate.connect (() => {
14 if (content.get_visible_child_name () != string_id)
15
16=== modified file 'src/Widgets/Device/DeviceItem.vala'
17--- src/Widgets/Device/DeviceItem.vala 2015-07-18 19:31:20 +0000
18+++ src/Widgets/Device/DeviceItem.vala 2015-07-24 17:43:15 +0000
19@@ -149,11 +149,11 @@
20 status_image.icon_name = "user-available";
21 break;
22 case "wifi-enabled":
23- row_description.label = Utils.state_to_string (NM.DeviceState.ACTIVATED);
24+ row_description.label = _("Enabled");
25 status_image.icon_name = "user-available";
26 break;
27 case "wifi-disabled":
28- row_description.label = Utils.state_to_string (NM.DeviceState.DISCONNECTED);
29+ row_description.label = _("Disabled");
30 status_image.icon_name = "user-busy";
31 break;
32 }
33
34=== modified file 'src/Widgets/Device/DevicePage.vala'
35--- src/Widgets/Device/DevicePage.vala 2015-07-18 16:56:50 +0000
36+++ src/Widgets/Device/DevicePage.vala 2015-07-24 17:43:15 +0000
37@@ -23,35 +23,22 @@
38 namespace Network.Widgets {
39 public class DevicePage : Page {
40 public DeviceItem owner;
41- public InfoBox info_box;
42
43 public DevicePage.from_owner (DeviceItem? _owner) {
44 this.owner = _owner;
45- this.device = owner.get_item_device ();
46 this.icon_name = owner.get_item_icon_name ();
47 this.title = Utils.type_to_string (device.get_device_type ());
48- this.margin_end = 12;
49-
50 info_box = new info_box.from_owner (owner);
51- info_box.margin_end = this.INFO_BOX_MARGIN;
52- info_box.info_changed.connect (update);
53+ this.init (owner.get_item_device (), info_box);
54
55 var details_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
56 details_box.pack_start (Utils.get_advanced_button_from_device (device), false, false, 0);
57
58- update ();
59+ update (info_box);
60
61 this.add (info_box);
62 this.pack_end (details_box, false, false, 0);
63 this.show_all ();
64 }
65-
66- private void update () {
67- string sent_bytes, received_bytes;
68- this.get_activity_information (device.get_iface (), out sent_bytes, out received_bytes);
69- info_box.update_activity (sent_bytes, received_bytes);
70-
71- control_switch.active = (device.get_state () == NM.DeviceState.ACTIVATED);
72- }
73 }
74 }
75
76=== modified file 'src/Widgets/Page.vala'
77--- src/Widgets/Page.vala 2015-07-18 16:11:54 +0000
78+++ src/Widgets/Page.vala 2015-07-24 17:43:15 +0000
79@@ -1,11 +1,9 @@
80
81-namespace Network {
82+namespace Network.Widgets {
83 public class Page : Gtk.Box {
84- public const int INFO_BOX_MARGIN = 16;
85-
86 public NM.Device device;
87+ public InfoBox info_box;
88 public Gtk.Switch control_switch;
89- public signal void switch_callback ();
90 public signal void show_error ();
91
92 private string _icon_name;
93@@ -40,6 +38,15 @@
94 this.orientation = Gtk.Orientation.VERTICAL;
95 this.margin = 12;
96 this.spacing = 24;
97+ }
98+
99+ public void init (NM.Device _device, Widgets.InfoBox _info_box) {
100+ this.device = _device;
101+ this.info_box = _info_box;
102+ info_box.margin_end = 16;
103+ info_box.info_changed.connect (() => {
104+ update (info_box);
105+ });
106
107 device_img = new Gtk.Image.from_icon_name (_icon_name, Gtk.IconSize.DIALOG);
108 device_img.pixel_size = 48;
109@@ -48,7 +55,13 @@
110 device_label.get_style_context ().add_class ("h2");
111
112 control_switch = new Gtk.Switch ();
113- control_switch.activate.connect (control_switch_activated);
114+ if (device.get_device_type () == NM.DeviceType.WIFI) {
115+ control_switch.active = (client.wireless_get_enabled ());
116+ } else {
117+ control_switch.active = (device.get_state () == NM.DeviceState.ACTIVATED);
118+ }
119+
120+ control_switch.button_press_event.connect (control_switch_activated);
121
122 control_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
123 control_box.pack_start (device_img, false, false, 0);
124@@ -56,7 +69,13 @@
125 control_box.pack_end (control_switch, false, false, 0);
126
127 this.add (control_box);
128- this.show_all ();
129+ this.show_all ();
130+ }
131+
132+ public void update (Widgets.InfoBox info_box) {
133+ string sent_bytes, received_bytes;
134+ this.get_activity_information (device.get_iface (), out sent_bytes, out received_bytes);
135+ info_box.update_activity (sent_bytes, received_bytes);
136 }
137
138 public void add_switch_title (string title) {
139@@ -65,7 +84,12 @@
140 control_box.pack_end (label, false, false, 0);
141 }
142
143- private void control_switch_activated () {
144+ private bool control_switch_activated () {
145+ if (device.get_device_type () == NM.DeviceType.WIFI) {
146+ client.wireless_set_enabled (!client.wireless_get_enabled ());
147+ return false;
148+ }
149+
150 if (device.get_state () == NM.DeviceState.ACTIVATED) {
151 device.disconnect (null);
152 } else {
153@@ -79,7 +103,7 @@
154 }
155 }
156
157- this.switch_callback ();
158+ return false;
159 }
160
161 public void get_activity_information (string iface, out string sent_bytes, out string received_bytes) {
162
163=== modified file 'src/Widgets/WiFi/WiFiPage.vala'
164--- src/Widgets/WiFi/WiFiPage.vala 2015-07-23 20:51:21 +0000
165+++ src/Widgets/WiFi/WiFiPage.vala 2015-07-24 17:43:15 +0000
166@@ -23,7 +23,6 @@
167 namespace Network.Widgets {
168 public class WiFiPage : Page {
169 public new NM.DeviceWifi device;
170- private InfoBox info_box;
171 private Gtk.ListBox wifi_list;
172 private List<WiFiEntry> entries;
173 private const string[] BLACKLISTED = { "Free Public WiFi" };
174@@ -37,6 +36,8 @@
175 this.device = wifidevice;
176 this.icon_name = "network-wireless";
177 this.title = _("Wi-Fi Network");
178+ info_box = new InfoBox.from_device (device);
179+ this.init (wifidevice, info_box);
180
181 entries = new List<WiFiEntry> ();
182
183@@ -51,10 +52,6 @@
184 scrolled.vexpand = true;
185 scrolled.shadow_type = Gtk.ShadowType.OUT;
186
187- info_box = new info_box.from_device (device);
188- info_box.margin_end = this.INFO_BOX_MARGIN;
189- info_box.info_changed.connect (update);
190-
191 var disconnect_btn = new Gtk.Button.with_label (_("Disconnect"));
192 disconnect_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
193 disconnect_btn.get_style_context ().add_class ("destructive-action");
194@@ -90,7 +87,7 @@
195 device.access_point_added.connect (add_access_point);
196 device.access_point_removed.connect (remove_access_point);
197
198- update ();
199+ update (info_box);
200
201 this.add_switch_title (_("Wireless:"));
202 this.add (scrolled);
203@@ -99,14 +96,6 @@
204 this.show_all ();
205 }
206
207- private void update () {
208- string sent_bytes, received_bytes;
209- this.get_activity_information (device.get_iface (), out sent_bytes, out received_bytes);
210- info_box.update_activity (sent_bytes, received_bytes);
211-
212- control_switch.active = (client.wireless_get_enabled () && device.get_state () == NM.DeviceState.ACTIVATED);
213- }
214-
215 private void on_row_activated (Gtk.ListBoxRow row) {
216 if (device != null) {
217 /* Do not activate connection if it is already activated */
218@@ -154,8 +143,10 @@
219
220 /* Check if we are successfully connected to the requested point */
221 if (device.get_active_access_point () == (row as WiFiEntry).ap) {
222- foreach (var entry in entries)
223+ entries.@foreach ((entry) => {
224 entry.set_status_point (false, false);
225+ });
226+
227 (row as WiFiEntry).set_status_point (true, false);
228 }
229 }
230@@ -190,23 +181,9 @@
231 insert_on_top = true;
232 });
233
234- scan_for_duplicates.begin ();
235 wifi_list.show_all ();
236 }
237
238- private async void scan_for_duplicates () {
239- var entries_dup = entries.copy ();
240- entries.@foreach ((entry) => {
241- var ssid = entry.ap.get_ssid ();
242-
243- entries_dup.@foreach ((entry_dup) => {
244- if (entry_dup.ap.get_ssid () == ssid) {
245- this.remove_access_point (entry_dup.ap);
246- }
247- });
248- });
249- }
250-
251 private void add_access_point (Object ap) {
252 var row = new WiFiEntry.from_access_point (ap as NM.AccessPoint);
253 if (!(row.ssid in BLACKLISTED) && row.ap.get_ssid () != null) {
254@@ -219,21 +196,18 @@
255 entries.append (row as WiFiEntry);
256 }
257
258- if ((ap as NM.AccessPoint) == device.get_active_access_point ())
259+ if ((ap as NM.AccessPoint) == device.get_active_access_point ()) {
260 row.set_status_point (true, false);
261+ }
262 }
263
264 private void remove_access_point (Object ap_removed) {
265- var new_entries = new List<WiFiEntry> ();
266- foreach (var entry in entries) {
267- if ((entry as WiFiEntry).ap == ap_removed) {
268+ entries.@foreach ((entry) => {
269+ if (((WiFiEntry) entry).ap == ap_removed) {
270+ entries.remove (entry);
271 entry.destroy ();
272- } else {
273- new_entries.append (entry);
274 }
275- }
276-
277- entries = new_entries.copy ();
278+ });
279 }
280
281 private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {

Subscribers

People subscribed via source and target branches

to all changes: