Merge lp:~donadigo/switchboard-plug-networking/wifi-radiobuttons into lp:~elementary-pantheon/switchboard-plug-networking/trunk

Proposed by Adam Bieńkowski
Status: Rejected
Rejected by: Adam Bieńkowski
Proposed branch: lp:~donadigo/switchboard-plug-networking/wifi-radiobuttons
Merge into: lp:~elementary-pantheon/switchboard-plug-networking/trunk
Diff against target: 405 lines (+162/-93)
3 files modified
src/Widgets/WiFi/WiFiEntry.vala (+45/-38)
src/Widgets/WiFi/WiFiPage.vala (+110/-47)
src/libnm-gtk.vapi (+7/-8)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-networking/wifi-radiobuttons
Reviewer Review Type Date Requested Status
xapantu (community) Needs Fixing
Danielle Foré Needs Fixing
Review via email: mp+266475@code.launchpad.net

Commit message

* Add new radiobuttons to WiFi list instead of setting the text on the item.
* get_strenth_image replaced with get_strength_icon
* Strength boundaries are now taken from Indicator Network
* Update strength when it changes
* Add spinner that signals that the connection is in progress
* RSN flags now also for checking if the entry is secured.

Description of the change

* Add new radiobuttons to WiFi list instead of setting the text on the item.
* get_strenth_image replaced with get_strength_icon
* Strength boundaries are now taken from Indicator Network
* Update strength when it changes
* Add spinner that signals that the connection is in progress
* RSN flags now also for checking if the entry is secured.

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

Hm, it seems I'm now unable to connect to networks that require a password.

Also the spinner only shows while the password dialog is open, but then disappears and the connection never happens. Doesn't even seem like it tries to connect.

review: Needs Fixing
Revision history for this message
xapantu (xapantu) wrote :

There is definitively a problem with the spinner, it does not show as often as the spinner in the indicator.

I also have the problem with the password protected networks, a password is asked even if it is already registered.

review: Needs Fixing
Revision history for this message
xapantu (xapantu) wrote :

So, I wrote more inline comments. Some are maybe arguable. You don't need to fix every item marked as "not important", but that would be better if the other were :)

Other than that, it is great to see that this plug is quickly progressing :)

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

xapantu: Okay, I fixed some problems with this branch, there is only one dumb_btn created in the wifi page as you pointed out. I've also borrowed some of yours code to check if entry is connecting and showing a spinner :) I updated those casts, but I dunno about removing "private" stuff, is there anything about this in elementary code style or we are free with those? I will make separate branch for code style updates soon.

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

Ah, I forgot, I think the problem with connecting to secured entry is also gone now by these changes.

Revision history for this message
xapantu (xapantu) wrote :

About the "private" keyword thing, that is just an opinion, I don't really care :)

Revision history for this message
xapantu (xapantu) wrote :

The spinner is now shown too often: if my computer attempts to connect to a network, and then to another, two spinner are displayed. Connecting to a secured network is not fixed (however I did not check wether it worked before your branch or not).

Revision history for this message
xapantu (xapantu) wrote :

Okay, I just tested, this bug is not introduced by this branch, don't worry about then.

Revision history for this message
xapantu (xapantu) wrote :

After some discussions we decided to merge some code between the indicator and the plug, so I just merged this branch to lp:~elementary-apps/switchboard-plug-networking/merge-with-indicator where these radio buttons are going to be merged with the indicator ones.

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

The branch will no longer be merged to the trunk as of the new branch that has merged this one.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/WiFi/WiFiEntry.vala'
2--- src/Widgets/WiFi/WiFiEntry.vala 2015-07-23 20:01:49 +0000
3+++ src/Widgets/WiFi/WiFiEntry.vala 2015-08-01 18:42:17 +0000
4@@ -22,65 +22,72 @@
5
6 namespace Network.Widgets {
7 public class WiFiEntry : Gtk.ListBoxRow {
8- public NM.AccessPoint? ap;
9- public string ssid;
10+ public NM.AccessPoint ap;
11+ public Gtk.RadioButton radio_btn;
12+ public string ssid_str;
13 public bool is_secured = false;
14 public uint strength;
15
16+ private Gtk.Box hbox;
17+ private Gtk.Spinner spinner;
18+
19 private string bssid;
20
21- private Gtk.Label title;
22-
23- public WiFiEntry.from_access_point (NM.AccessPoint? point) {
24+ public WiFiEntry (NM.AccessPoint point, Gtk.RadioButton? previous_btn = null) {
25 ap = point;
26
27- this.ssid = NM.Utils.ssid_to_utf8 (ap.get_ssid ());
28+ this.ssid_str = NM.Utils.ssid_to_utf8 (ap.get_ssid ());
29 this.bssid = ap.get_bssid ();
30 this.strength = ap.get_strength ();
31
32- title = new Gtk.Label (ssid);
33- title.halign = Gtk.Align.START;
34-
35- var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
36- hbox.add (title);
37-
38- hbox.pack_end (get_strength_image (), false, false, 7);
39- if (ap.get_wpa_flags () != NM.@80211ApSecurityFlags.NONE) {
40+ radio_btn = new Gtk.RadioButton.with_label_from_widget (previous_btn, ssid_str);
41+ radio_btn.halign = Gtk.Align.START;
42+
43+ hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
44+ hbox.add (radio_btn);
45+
46+ var strength_image = new Gtk.Image.from_icon_name (get_strength_icon (), Gtk.IconSize.SMALL_TOOLBAR);
47+ ap.notify["strength"].connect (() => {
48+ strength_image.icon_name = get_strength_icon ();
49+ });
50+
51+ hbox.pack_end (strength_image, false, false, 7);
52+ if (ap.get_wpa_flags () != NM.@80211ApSecurityFlags.NONE || ap.get_rsn_flags () != NM.@80211ApSecurityFlags.NONE) {
53 is_secured = true;
54
55 var lock_img = new Gtk.Image.from_icon_name ("channel-secure-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
56 hbox.pack_end (lock_img, false, false, 0);
57 }
58
59+ spinner = new Gtk.Spinner ();
60+ spinner.no_show_all = true;
61+ spinner.start ();
62+ hbox.pack_end (spinner, false, false, 0);
63+
64+ set_connection_in_progress (false);
65+
66 this.add (hbox);
67 this.show_all ();
68 }
69
70- public void set_status_point (bool connected, bool in_process) {
71- if (connected || in_process) {
72- string status = Utils.state_to_string (NM.DeviceState.ACTIVATED);
73- if (in_process)
74- status = Utils.state_to_string (NM.DeviceState.CONFIG);
75- title.label = title.get_label () + SUFFIX + "(" + status + ")";
76+ public void set_active (bool connected) {
77+ radio_btn.active = connected;
78+ }
79+
80+ public void set_connection_in_progress (bool progress) {
81+ spinner.visible = progress;
82+ }
83+
84+ private string get_strength_icon () {
85+ if (strength < 30) {
86+ return "network-wireless-signal-weak-symbolic";
87+ } else if (strength < 55) {
88+ return "network-wireless-signal-ok-symbolic";
89+ } else if (strength < 80) {
90+ return "network-wireless-signal-good-symbolic";
91 } else {
92- title.label = ssid;
93- }
94- }
95-
96- private Gtk.Image get_strength_image () {
97- var image = new Gtk.Image.from_icon_name ("network-wireless-offline-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
98-
99- if (strength == 0 || strength <= 25) {
100- image.icon_name = "network-wireless-signal-weak-symbolic";
101- } else if (strength > 25 && strength <= 50) {
102- image.icon_name = "network-wireless-signal-ok-symbolic";
103- } else if (strength > 50 && strength <= 75) {
104- image.icon_name = "network-wireless-signal-good-symbolic";
105- } else if (strength > 75) {
106- image.icon_name = "network-wireless-signal-excellent-symbolic";
107- }
108-
109- return image;
110+ return "network-wireless-signal-excellent-symbolic";
111+ }
112 }
113 }
114 }
115
116=== modified file 'src/Widgets/WiFi/WiFiPage.vala'
117--- src/Widgets/WiFi/WiFiPage.vala 2015-07-24 17:42:48 +0000
118+++ src/Widgets/WiFi/WiFiPage.vala 2015-08-01 18:42:17 +0000
119@@ -25,6 +25,8 @@
120 public new NM.DeviceWifi device;
121 private Gtk.ListBox wifi_list;
122 private List<WiFiEntry> entries;
123+ private Gtk.RadioButton dumb_btn;
124+ private Gtk.RadioButton previous_btn;
125 private const string[] BLACKLISTED = { "Free Public WiFi" };
126
127 private WiFiEntry? current_connecting_entry = null;
128@@ -40,6 +42,8 @@
129 this.init (wifidevice, info_box);
130
131 entries = new List<WiFiEntry> ();
132+ dumb_btn = new Gtk.RadioButton (null);
133+ previous_btn = dumb_btn;
134
135 wifi_list = new Gtk.ListBox ();
136 wifi_list.selection_mode = Gtk.SelectionMode.SINGLE;
137@@ -56,7 +60,9 @@
138 disconnect_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
139 disconnect_btn.get_style_context ().add_class ("destructive-action");
140 disconnect_btn.clicked.connect (() => {
141- device.disconnect (null);
142+ device.disconnect (((_device, _error) => {
143+ update_points ();
144+ }));
145 });
146
147 var advanced_btn = Utils.get_advanced_button_from_device (device);
148@@ -65,6 +71,7 @@
149 bool sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
150 disconnect_btn.sensitive = sensitive;
151 advanced_btn.sensitive = sensitive;
152+ update_points ();
153 });
154
155 var hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…"));
156@@ -84,10 +91,12 @@
157 button_box.pack_start (hidden_btn, false, false, 0);
158 button_box.pack_end (end_btn_box, false, false, 0);
159
160+ device.notify["active-access-point"].connect (update_points);
161 device.access_point_added.connect (add_access_point);
162 device.access_point_removed.connect (remove_access_point);
163
164 update (info_box);
165+ update_points ();
166
167 this.add_switch_title (_("Wireless:"));
168 this.add (scrolled);
169@@ -99,11 +108,11 @@
170 private void on_row_activated (Gtk.ListBoxRow row) {
171 if (device != null) {
172 /* Do not activate connection if it is already activated */
173- if (device.get_active_access_point () != (row as WiFiEntry).ap) {
174+ if (device.get_active_access_point () != ((WiFiEntry) row).ap) {
175 var setting_wireless = new NM.SettingWireless ();
176- if (setting_wireless.add_seen_bssid ((row as WiFiEntry).ap.get_bssid ())) {
177- current_connecting_entry = row as WiFiEntry;
178- if ((row as WiFiEntry).is_secured) {
179+ if (setting_wireless.add_seen_bssid (((WiFiEntry) row).ap.get_bssid ())) {
180+ current_connecting_entry = ((WiFiEntry) row);
181+ if (((WiFiEntry) row).is_secured) {
182 var remote_settings = new NM.RemoteSettings (null);
183
184 var connection = new NM.Connection ();
185@@ -112,62 +121,79 @@
186 connection.add_setting (s_con);
187
188 var s_wifi = new NM.SettingWireless ();
189- s_wifi.@set (NM.SettingWireless.SSID, (row as WiFiEntry).ap.get_ssid ());
190+ s_wifi.@set (NM.SettingWireless.SSID, ((WiFiEntry) row).ap.get_ssid ());
191 connection.add_setting (s_wifi);
192
193 var s_wsec = new NM.SettingWirelessSecurity ();
194- s_wsec.@set (NM.SettingWirelessSecurity.KEY_MGMT, "wpa-eap");
195+ s_wsec.@set (NM.SettingWirelessSecurity.KEY_MGMT, "wpa-psk");
196 connection.add_setting (s_wsec);
197
198- var s_8021x = new NM.Setting8021x ();
199- s_8021x.add_eap_method ("ttls");
200- s_8021x.@set (NM.Setting8021x.PHASE2_AUTH, "mschapv2");
201- connection.add_setting (s_8021x);
202-
203- var dialog = NMGtk.new_wifi_dialog (client,
204- remote_settings,
205- connection,
206- device,
207- (row as WiFiEntry).ap,
208- false);
209- dialog.run ();
210+ var dialog = new NMAWifiDialog (client,
211+ remote_settings,
212+ connection,
213+ device,
214+ ((WiFiEntry) row).ap,
215+ false);
216+
217+ dialog.response.connect ((response) => {
218+ if (response != Gtk.ResponseType.OK) {
219+ return;
220+ }
221+
222+ NM.Device dialog_device;
223+ NM.AccessPoint dialog_ap;
224+ var dialog_connection = dialog.get_connection (out dialog_device, out dialog_ap);
225+
226+ if (get_connection_available (dialog_connection, dialog_device)) {
227+ client.activate_connection (dialog_connection,
228+ dialog_device,
229+ dialog_ap.get_path (),
230+ null);
231+ } else {
232+ client.add_and_activate_connection (dialog_connection,
233+ dialog_device,
234+ dialog_ap.get_path (),
235+ finish_connection_callback);
236+ }
237+ });
238+
239+ dialog.run ();
240+ dialog.destroy ();
241 } else {
242- (row as WiFiEntry).set_status_point (false, true);
243 client.add_and_activate_connection (new NM.Connection (),
244 device,
245- (row as WiFiEntry).ap.get_path (),
246+ ((WiFiEntry) row).ap.get_path (),
247 finish_connection_callback);
248- }
249+ }
250 }
251 }
252
253- /* Check if we are successfully connected to the requested point */
254- if (device.get_active_access_point () == (row as WiFiEntry).ap) {
255- entries.@foreach ((entry) => {
256- entry.set_status_point (false, false);
257- });
258-
259- (row as WiFiEntry).set_status_point (true, false);
260- }
261+ update_points ();
262 }
263 }
264
265+ private bool get_connection_available (NM.Connection connection, NM.Device _device) {
266+ bool retval = false;
267+ _device.get_available_connections ().@foreach ((_connection) => {
268+ if (_connection == connection) {
269+ retval = true;
270+ }
271+ });
272+
273+ return retval;
274+ }
275+
276 private void finish_connection_callback (NM.Client _client,
277 NM.ActiveConnection connection,
278 string new_connection_path,
279 Error error) {
280 bool success = false;
281 _client.get_active_connections ().@foreach ((c) => {
282- if (c == connection)
283+ if (c == connection)
284 success = true;
285 });
286
287- if (success) {
288- current_connecting_entry.set_status_point (true, false);
289- } else {
290- current_connecting_entry.set_status_point (false, false);
291- }
292-
293+ current_connecting_entry.set_active (success);
294 current_connecting_entry = null;
295 }
296
297@@ -185,20 +211,25 @@
298 }
299
300 private void add_access_point (Object ap) {
301- var row = new WiFiEntry.from_access_point (ap as NM.AccessPoint);
302- if (!(row.ssid in BLACKLISTED) && row.ap.get_ssid () != null) {
303+ var row = new WiFiEntry (((NM.AccessPoint) ap), previous_btn);
304+ previous_btn = row.radio_btn;
305+
306+ if (!(row.ssid_str in BLACKLISTED) && row.ap.get_ssid () != null) {
307 if (insert_on_top) {
308 wifi_list.insert (row, 0);
309 } else {
310 wifi_list.add (row);
311 }
312
313- entries.append (row as WiFiEntry);
314- }
315-
316- if ((ap as NM.AccessPoint) == device.get_active_access_point ()) {
317- row.set_status_point (true, false);
318- }
319+ row.radio_btn.button_release_event.connect (() => {
320+ this.on_row_activated (row);
321+ return false;
322+ });
323+
324+ entries.append (row);
325+ }
326+
327+ update_points ();
328 }
329
330 private void remove_access_point (Object ap_removed) {
331@@ -207,7 +238,9 @@
332 entries.remove (entry);
333 entry.destroy ();
334 }
335- });
336+ });
337+
338+ update_points ();
339 }
340
341 private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {
342@@ -222,6 +255,36 @@
343 } else {
344 return 0;
345 }
346- }
347+ }
348+
349+ private void update_points () {
350+ var active_point = device.get_active_access_point ();
351+ if (active_point == null) {
352+ dumb_btn.active = true;
353+ return;
354+ }
355+
356+ bool in_progress = false;
357+ switch (device.get_state ()) {
358+ case NM.DeviceState.PREPARE:
359+ case NM.DeviceState.CONFIG:
360+ case NM.DeviceState.NEED_AUTH:
361+ case NM.DeviceState.IP_CONFIG:
362+ case NM.DeviceState.IP_CHECK:
363+ case NM.DeviceState.SECONDARIES:
364+ in_progress = true;
365+ break;
366+ default:
367+ break;
368+ }
369+
370+ entries.@foreach ((entry) => {
371+ entry.set_connection_in_progress (false);
372+ if (entry.ap == active_point) {
373+ entry.set_connection_in_progress (in_progress);
374+ entry.set_active (true);
375+ }
376+ });
377+ }
378 }
379 }
380\ No newline at end of file
381
382=== modified file 'src/libnm-gtk.vapi'
383--- src/libnm-gtk.vapi 2015-05-23 18:30:03 +0000
384+++ src/libnm-gtk.vapi 2015-08-01 18:42:17 +0000
385@@ -1,13 +1,12 @@
386+[CCode (cheader_filename = "nm-wifi-dialog.h")]
387+class NMAWifiDialog : Gtk.Dialog {
388+ public NMAWifiDialog (NM.Client client, NM.RemoteSettings settings, NM.Connection connection, NM.Device device, NM.AccessPoint ap, bool secrets_only);
389+ public NM.Connection get_connection (out NM.Device device, out NM.AccessPoint ap);
390+}
391+
392+
393 [CCode (cprefix = "NMGtk", gir_namespace = "NMGtk", gir_version = "1.0", lower_case_cprefix = "nmgtk_")]
394 namespace NMGtk {
395- [CCode (cheader_filename = "libnm-gtk/nm-wifi-dialog.h", cname = "nma_wifi_dialog_new")]
396- public Gtk.Dialog new_wifi_dialog (NM.Client client,
397- NM.RemoteSettings settings,
398- NM.Connection connection,
399- NM.Device device,
400- NM.AccessPoint ap,
401- bool secrets_only);
402-
403 [CCode (cheader_filename = "libnm-gtk/nm-wifi-dialog.h", cname = "nma_wifi_dialog_new_for_other")]
404 public Gtk.Dialog new_wifi_dialog_for_hidden (NM.Client client, NM.RemoteSettings settings);
405 }

Subscribers

People subscribed via source and target branches

to all changes: