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
=== modified file 'src/Widgets/WiFi/WiFiEntry.vala'
--- src/Widgets/WiFi/WiFiEntry.vala 2015-07-23 20:01:49 +0000
+++ src/Widgets/WiFi/WiFiEntry.vala 2015-08-01 18:42:17 +0000
@@ -22,65 +22,72 @@
2222
23namespace Network.Widgets {23namespace Network.Widgets {
24 public class WiFiEntry : Gtk.ListBoxRow {24 public class WiFiEntry : Gtk.ListBoxRow {
25 public NM.AccessPoint? ap;25 public NM.AccessPoint ap;
26 public string ssid;26 public Gtk.RadioButton radio_btn;
27 public string ssid_str;
27 public bool is_secured = false;28 public bool is_secured = false;
28 public uint strength;29 public uint strength;
2930
31 private Gtk.Box hbox;
32 private Gtk.Spinner spinner;
33
30 private string bssid;34 private string bssid;
3135
32 private Gtk.Label title;36 public WiFiEntry (NM.AccessPoint point, Gtk.RadioButton? previous_btn = null) {
33
34 public WiFiEntry.from_access_point (NM.AccessPoint? point) {
35 ap = point;37 ap = point;
3638
37 this.ssid = NM.Utils.ssid_to_utf8 (ap.get_ssid ());39 this.ssid_str = NM.Utils.ssid_to_utf8 (ap.get_ssid ());
38 this.bssid = ap.get_bssid ();40 this.bssid = ap.get_bssid ();
39 this.strength = ap.get_strength ();41 this.strength = ap.get_strength ();
4042
41 title = new Gtk.Label (ssid);43 radio_btn = new Gtk.RadioButton.with_label_from_widget (previous_btn, ssid_str);
42 title.halign = Gtk.Align.START;44 radio_btn.halign = Gtk.Align.START;
4345
44 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);46 hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
45 hbox.add (title);47 hbox.add (radio_btn);
4648
47 hbox.pack_end (get_strength_image (), false, false, 7);49 var strength_image = new Gtk.Image.from_icon_name (get_strength_icon (), Gtk.IconSize.SMALL_TOOLBAR);
48 if (ap.get_wpa_flags () != NM.@80211ApSecurityFlags.NONE) {50 ap.notify["strength"].connect (() => {
51 strength_image.icon_name = get_strength_icon ();
52 });
53
54 hbox.pack_end (strength_image, false, false, 7);
55 if (ap.get_wpa_flags () != NM.@80211ApSecurityFlags.NONE || ap.get_rsn_flags () != NM.@80211ApSecurityFlags.NONE) {
49 is_secured = true;56 is_secured = true;
5057
51 var lock_img = new Gtk.Image.from_icon_name ("channel-secure-symbolic", Gtk.IconSize.SMALL_TOOLBAR);58 var lock_img = new Gtk.Image.from_icon_name ("channel-secure-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
52 hbox.pack_end (lock_img, false, false, 0);59 hbox.pack_end (lock_img, false, false, 0);
53 }60 }
5461
62 spinner = new Gtk.Spinner ();
63 spinner.no_show_all = true;
64 spinner.start ();
65 hbox.pack_end (spinner, false, false, 0);
66
67 set_connection_in_progress (false);
68
55 this.add (hbox);69 this.add (hbox);
56 this.show_all ();70 this.show_all ();
57 }71 }
5872
59 public void set_status_point (bool connected, bool in_process) {73 public void set_active (bool connected) {
60 if (connected || in_process) {74 radio_btn.active = connected;
61 string status = Utils.state_to_string (NM.DeviceState.ACTIVATED);75 }
62 if (in_process)76
63 status = Utils.state_to_string (NM.DeviceState.CONFIG);77 public void set_connection_in_progress (bool progress) {
64 title.label = title.get_label () + SUFFIX + "(" + status + ")";78 spinner.visible = progress;
79 }
80
81 private string get_strength_icon () {
82 if (strength < 30) {
83 return "network-wireless-signal-weak-symbolic";
84 } else if (strength < 55) {
85 return "network-wireless-signal-ok-symbolic";
86 } else if (strength < 80) {
87 return "network-wireless-signal-good-symbolic";
65 } else {88 } else {
66 title.label = ssid;89 return "network-wireless-signal-excellent-symbolic";
67 }90 }
68 }
69
70 private Gtk.Image get_strength_image () {
71 var image = new Gtk.Image.from_icon_name ("network-wireless-offline-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
72
73 if (strength == 0 || strength <= 25) {
74 image.icon_name = "network-wireless-signal-weak-symbolic";
75 } else if (strength > 25 && strength <= 50) {
76 image.icon_name = "network-wireless-signal-ok-symbolic";
77 } else if (strength > 50 && strength <= 75) {
78 image.icon_name = "network-wireless-signal-good-symbolic";
79 } else if (strength > 75) {
80 image.icon_name = "network-wireless-signal-excellent-symbolic";
81 }
82
83 return image;
84 }91 }
85 }92 }
86}93}
8794
=== modified file 'src/Widgets/WiFi/WiFiPage.vala'
--- src/Widgets/WiFi/WiFiPage.vala 2015-07-24 17:42:48 +0000
+++ src/Widgets/WiFi/WiFiPage.vala 2015-08-01 18:42:17 +0000
@@ -25,6 +25,8 @@
25 public new NM.DeviceWifi device;25 public new NM.DeviceWifi device;
26 private Gtk.ListBox wifi_list;26 private Gtk.ListBox wifi_list;
27 private List<WiFiEntry> entries;27 private List<WiFiEntry> entries;
28 private Gtk.RadioButton dumb_btn;
29 private Gtk.RadioButton previous_btn;
28 private const string[] BLACKLISTED = { "Free Public WiFi" };30 private const string[] BLACKLISTED = { "Free Public WiFi" };
29 31
30 private WiFiEntry? current_connecting_entry = null;32 private WiFiEntry? current_connecting_entry = null;
@@ -40,6 +42,8 @@
40 this.init (wifidevice, info_box);42 this.init (wifidevice, info_box);
4143
42 entries = new List<WiFiEntry> ();44 entries = new List<WiFiEntry> ();
45 dumb_btn = new Gtk.RadioButton (null);
46 previous_btn = dumb_btn;
4347
44 wifi_list = new Gtk.ListBox ();48 wifi_list = new Gtk.ListBox ();
45 wifi_list.selection_mode = Gtk.SelectionMode.SINGLE;49 wifi_list.selection_mode = Gtk.SelectionMode.SINGLE;
@@ -56,7 +60,9 @@
56 disconnect_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);60 disconnect_btn.sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
57 disconnect_btn.get_style_context ().add_class ("destructive-action");61 disconnect_btn.get_style_context ().add_class ("destructive-action");
58 disconnect_btn.clicked.connect (() => {62 disconnect_btn.clicked.connect (() => {
59 device.disconnect (null);63 device.disconnect (((_device, _error) => {
64 update_points ();
65 }));
60 });66 });
6167
62 var advanced_btn = Utils.get_advanced_button_from_device (device);68 var advanced_btn = Utils.get_advanced_button_from_device (device);
@@ -65,6 +71,7 @@
65 bool sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);71 bool sensitive = (device.get_state () == NM.DeviceState.ACTIVATED);
66 disconnect_btn.sensitive = sensitive;72 disconnect_btn.sensitive = sensitive;
67 advanced_btn.sensitive = sensitive;73 advanced_btn.sensitive = sensitive;
74 update_points ();
68 });75 });
6976
70 var hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…"));77 var hidden_btn = new Gtk.Button.with_label (_("Connect to Hidden Network…"));
@@ -84,10 +91,12 @@
84 button_box.pack_start (hidden_btn, false, false, 0);91 button_box.pack_start (hidden_btn, false, false, 0);
85 button_box.pack_end (end_btn_box, false, false, 0);92 button_box.pack_end (end_btn_box, false, false, 0);
8693
94 device.notify["active-access-point"].connect (update_points);
87 device.access_point_added.connect (add_access_point);95 device.access_point_added.connect (add_access_point);
88 device.access_point_removed.connect (remove_access_point);96 device.access_point_removed.connect (remove_access_point);
8997
90 update (info_box);98 update (info_box);
99 update_points ();
91100
92 this.add_switch_title (_("Wireless:"));101 this.add_switch_title (_("Wireless:"));
93 this.add (scrolled);102 this.add (scrolled);
@@ -99,11 +108,11 @@
99 private void on_row_activated (Gtk.ListBoxRow row) {108 private void on_row_activated (Gtk.ListBoxRow row) {
100 if (device != null) { 109 if (device != null) {
101 /* Do not activate connection if it is already activated */110 /* Do not activate connection if it is already activated */
102 if (device.get_active_access_point () != (row as WiFiEntry).ap) {111 if (device.get_active_access_point () != ((WiFiEntry) row).ap) {
103 var setting_wireless = new NM.SettingWireless ();112 var setting_wireless = new NM.SettingWireless ();
104 if (setting_wireless.add_seen_bssid ((row as WiFiEntry).ap.get_bssid ())) {113 if (setting_wireless.add_seen_bssid (((WiFiEntry) row).ap.get_bssid ())) {
105 current_connecting_entry = row as WiFiEntry;114 current_connecting_entry = ((WiFiEntry) row);
106 if ((row as WiFiEntry).is_secured) {115 if (((WiFiEntry) row).is_secured) {
107 var remote_settings = new NM.RemoteSettings (null);116 var remote_settings = new NM.RemoteSettings (null);
108117
109 var connection = new NM.Connection ();118 var connection = new NM.Connection ();
@@ -112,62 +121,79 @@
112 connection.add_setting (s_con);121 connection.add_setting (s_con);
113122
114 var s_wifi = new NM.SettingWireless ();123 var s_wifi = new NM.SettingWireless ();
115 s_wifi.@set (NM.SettingWireless.SSID, (row as WiFiEntry).ap.get_ssid ());124 s_wifi.@set (NM.SettingWireless.SSID, ((WiFiEntry) row).ap.get_ssid ());
116 connection.add_setting (s_wifi);125 connection.add_setting (s_wifi);
117126
118 var s_wsec = new NM.SettingWirelessSecurity ();127 var s_wsec = new NM.SettingWirelessSecurity ();
119 s_wsec.@set (NM.SettingWirelessSecurity.KEY_MGMT, "wpa-eap");128 s_wsec.@set (NM.SettingWirelessSecurity.KEY_MGMT, "wpa-psk");
120 connection.add_setting (s_wsec);129 connection.add_setting (s_wsec);
121130
122 var s_8021x = new NM.Setting8021x ();131 var dialog = new NMAWifiDialog (client,
123 s_8021x.add_eap_method ("ttls");132 remote_settings,
124 s_8021x.@set (NM.Setting8021x.PHASE2_AUTH, "mschapv2");133 connection,
125 connection.add_setting (s_8021x);134 device,
126 135 ((WiFiEntry) row).ap,
127 var dialog = NMGtk.new_wifi_dialog (client,136 false);
128 remote_settings,137
129 connection,138 dialog.response.connect ((response) => {
130 device,139 if (response != Gtk.ResponseType.OK) {
131 (row as WiFiEntry).ap,140 return;
132 false);141 }
133 dialog.run ();142
143 NM.Device dialog_device;
144 NM.AccessPoint dialog_ap;
145 var dialog_connection = dialog.get_connection (out dialog_device, out dialog_ap);
146
147 if (get_connection_available (dialog_connection, dialog_device)) {
148 client.activate_connection (dialog_connection,
149 dialog_device,
150 dialog_ap.get_path (),
151 null);
152 } else {
153 client.add_and_activate_connection (dialog_connection,
154 dialog_device,
155 dialog_ap.get_path (),
156 finish_connection_callback);
157 }
158 });
159
160 dialog.run ();
161 dialog.destroy ();
134 } else {162 } else {
135 (row as WiFiEntry).set_status_point (false, true);
136 client.add_and_activate_connection (new NM.Connection (),163 client.add_and_activate_connection (new NM.Connection (),
137 device,164 device,
138 (row as WiFiEntry).ap.get_path (),165 ((WiFiEntry) row).ap.get_path (),
139 finish_connection_callback);166 finish_connection_callback);
140 }167 }
141 }168 }
142 }169 }
143170
144 /* Check if we are successfully connected to the requested point */171 update_points ();
145 if (device.get_active_access_point () == (row as WiFiEntry).ap) {
146 entries.@foreach ((entry) => {
147 entry.set_status_point (false, false);
148 });
149
150 (row as WiFiEntry).set_status_point (true, false);
151 }
152 }172 }
153 }173 }
154174
175 private bool get_connection_available (NM.Connection connection, NM.Device _device) {
176 bool retval = false;
177 _device.get_available_connections ().@foreach ((_connection) => {
178 if (_connection == connection) {
179 retval = true;
180 }
181 });
182
183 return retval;
184 }
185
155 private void finish_connection_callback (NM.Client _client,186 private void finish_connection_callback (NM.Client _client,
156 NM.ActiveConnection connection,187 NM.ActiveConnection connection,
157 string new_connection_path,188 string new_connection_path,
158 Error error) {189 Error error) {
159 bool success = false;190 bool success = false;
160 _client.get_active_connections ().@foreach ((c) => {191 _client.get_active_connections ().@foreach ((c) => {
161 if (c == connection)192 if (c == connection)
162 success = true;193 success = true;
163 });194 });
164195
165 if (success) {196 current_connecting_entry.set_active (success);
166 current_connecting_entry.set_status_point (true, false);
167 } else {
168 current_connecting_entry.set_status_point (false, false);
169 }
170
171 current_connecting_entry = null;197 current_connecting_entry = null;
172 }198 }
173199
@@ -185,20 +211,25 @@
185 }211 }
186 212
187 private void add_access_point (Object ap) {213 private void add_access_point (Object ap) {
188 var row = new WiFiEntry.from_access_point (ap as NM.AccessPoint);214 var row = new WiFiEntry (((NM.AccessPoint) ap), previous_btn);
189 if (!(row.ssid in BLACKLISTED) && row.ap.get_ssid () != null) {215 previous_btn = row.radio_btn;
216
217 if (!(row.ssid_str in BLACKLISTED) && row.ap.get_ssid () != null) {
190 if (insert_on_top) {218 if (insert_on_top) {
191 wifi_list.insert (row, 0);219 wifi_list.insert (row, 0);
192 } else {220 } else {
193 wifi_list.add (row);221 wifi_list.add (row);
194 }222 }
195223
196 entries.append (row as WiFiEntry);224 row.radio_btn.button_release_event.connect (() => {
197 }225 this.on_row_activated (row);
198226 return false;
199 if ((ap as NM.AccessPoint) == device.get_active_access_point ()) {227 });
200 row.set_status_point (true, false);228
201 }229 entries.append (row);
230 }
231
232 update_points ();
202 }233 }
203 234
204 private void remove_access_point (Object ap_removed) {235 private void remove_access_point (Object ap_removed) {
@@ -207,7 +238,9 @@
207 entries.remove (entry);238 entries.remove (entry);
208 entry.destroy ();239 entry.destroy ();
209 }240 }
210 }); 241 });
242
243 update_points ();
211 }244 }
212245
213 private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {246 private int sort_func (Gtk.ListBoxRow r1, Gtk.ListBoxRow r2) {
@@ -222,6 +255,36 @@
222 } else {255 } else {
223 return 0;256 return 0;
224 }257 }
225 } 258 }
259
260 private void update_points () {
261 var active_point = device.get_active_access_point ();
262 if (active_point == null) {
263 dumb_btn.active = true;
264 return;
265 }
266
267 bool in_progress = false;
268 switch (device.get_state ()) {
269 case NM.DeviceState.PREPARE:
270 case NM.DeviceState.CONFIG:
271 case NM.DeviceState.NEED_AUTH:
272 case NM.DeviceState.IP_CONFIG:
273 case NM.DeviceState.IP_CHECK:
274 case NM.DeviceState.SECONDARIES:
275 in_progress = true;
276 break;
277 default:
278 break;
279 }
280
281 entries.@foreach ((entry) => {
282 entry.set_connection_in_progress (false);
283 if (entry.ap == active_point) {
284 entry.set_connection_in_progress (in_progress);
285 entry.set_active (true);
286 }
287 });
288 }
226 }289 }
227}290}
228\ No newline at end of file291\ No newline at end of file
229292
=== modified file 'src/libnm-gtk.vapi'
--- src/libnm-gtk.vapi 2015-05-23 18:30:03 +0000
+++ src/libnm-gtk.vapi 2015-08-01 18:42:17 +0000
@@ -1,13 +1,12 @@
1[CCode (cheader_filename = "nm-wifi-dialog.h")]
2class NMAWifiDialog : Gtk.Dialog {
3 public NMAWifiDialog (NM.Client client, NM.RemoteSettings settings, NM.Connection connection, NM.Device device, NM.AccessPoint ap, bool secrets_only);
4 public NM.Connection get_connection (out NM.Device device, out NM.AccessPoint ap);
5}
6
7
1[CCode (cprefix = "NMGtk", gir_namespace = "NMGtk", gir_version = "1.0", lower_case_cprefix = "nmgtk_")]8[CCode (cprefix = "NMGtk", gir_namespace = "NMGtk", gir_version = "1.0", lower_case_cprefix = "nmgtk_")]
2namespace NMGtk {9namespace NMGtk {
3 [CCode (cheader_filename = "libnm-gtk/nm-wifi-dialog.h", cname = "nma_wifi_dialog_new")]
4 public Gtk.Dialog new_wifi_dialog (NM.Client client,
5 NM.RemoteSettings settings,
6 NM.Connection connection,
7 NM.Device device,
8 NM.AccessPoint ap,
9 bool secrets_only);
10
11 [CCode (cheader_filename = "libnm-gtk/nm-wifi-dialog.h", cname = "nma_wifi_dialog_new_for_other")] 10 [CCode (cheader_filename = "libnm-gtk/nm-wifi-dialog.h", cname = "nma_wifi_dialog_new_for_other")]
12 public Gtk.Dialog new_wifi_dialog_for_hidden (NM.Client client, NM.RemoteSettings settings); 11 public Gtk.Dialog new_wifi_dialog_for_hidden (NM.Client client, NM.RemoteSettings settings);
13}12}

Subscribers

People subscribed via source and target branches

to all changes: