Merge lp:~xapantu/switchboard-plug-networking/rfkill into lp:~elementary-pantheon/switchboard-plug-networking/trunk

Proposed by xapantu
Status: Merged
Approved by: xapantu
Approved revision: 148
Merged at revision: 153
Proposed branch: lp:~xapantu/switchboard-plug-networking/rfkill
Merge into: lp:~elementary-pantheon/switchboard-plug-networking/trunk
Diff against target: 116 lines (+37/-19)
3 files modified
src/Widgets/WifiInterface.vala (+2/-5)
src/common/Widgets/AbstractWifiInterface.vala (+15/-10)
src/common/rfkill.vala (+20/-4)
To merge this branch: bzr merge lp:~xapantu/switchboard-plug-networking/rfkill
Reviewer Review Type Date Requested Status
elementary Pantheon team Pending
Review via email: mp+268159@code.launchpad.net

Commit message

Allow a per device deactivation on the rfkill side.

Description of the change

Allow a per device deactivation on the rfkill side. Does not work very well: NetworkManager disables every wifi connection or none apparently, but it will probably be fixed soon.

To post a comment you must log in.
Revision history for this message
Cody Garver (codygarver) wrote :

Conflicts with trunk

Revision history for this message
xapantu (xapantu) wrote :

Updated

148. By xapantu

rfkill devices: don't disable every one of them

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/WifiInterface.vala'
2--- src/Widgets/WifiInterface.vala 2015-08-14 11:30:28 +0000
3+++ src/Widgets/WifiInterface.vala 2015-08-16 10:50:45 +0000
4@@ -163,15 +163,12 @@
5 }
6
7 protected override void update_switch () {
8- control_switch.active = !software_locked;
9+ control_switch.active = !software_locked && nm_client.wireless_get_enabled ();
10 }
11
12 protected override void control_switch_activated () {
13 var active = control_switch.active;
14- if (active != !software_locked) {
15- rfkill.set_software_lock (RFKillDeviceType.WLAN, !active);
16- client.wireless_set_enabled (active);
17- }
18+ change_state (active);
19 }
20
21 protected override void wifi_activate_cb (WifiMenuItem row) {
22
23=== modified file 'src/common/Widgets/AbstractWifiInterface.vala'
24--- src/common/Widgets/AbstractWifiInterface.vala 2015-08-11 22:35:35 +0000
25+++ src/common/Widgets/AbstractWifiInterface.vala 2015-08-16 10:50:45 +0000
26@@ -163,6 +163,17 @@
27
28 }
29
30+ protected void change_state (bool enable) {
31+ if (enable != !software_locked) {
32+ RFKillDevice? rfkill_device = rfkill.get_device_for_nm_device (wifi_device);
33+ rfkill_device.software_lock = !enable;
34+ software_locked = !enable;
35+ }
36+ if (enable) {
37+ nm_client.wireless_set_enabled (enable);
38+ }
39+ }
40+
41 void update_active_ap () {
42 debug("Update active AP");
43
44@@ -282,19 +293,13 @@
45 break;
46 }
47
48- debug("New network state: %s", state.to_string ());
49-
50 /* Wifi */
51 software_locked = false;
52 hardware_locked = false;
53- foreach (var device in rfkill.get_devices ()) {
54- if (device.device_type != RFKillDeviceType.WLAN)
55- continue;
56-
57- if (device.software_lock)
58- software_locked = true;
59- if (device.hardware_lock)
60- hardware_locked = true;
61+ RFKillDevice? rfkill_device = rfkill.get_device_for_nm_device (wifi_device);
62+ if (rfkill_device != null) {
63+ software_locked = rfkill_device.software_lock;
64+ hardware_locked = rfkill_device.hardware_lock;
65 }
66 locked = hardware_locked || software_locked;
67
68
69=== modified file 'src/common/rfkill.vala'
70--- src/common/rfkill.vala 2015-08-01 20:32:38 +0000
71+++ src/common/rfkill.vala 2015-08-16 10:50:45 +0000
72@@ -46,6 +46,7 @@
73 internal RFKillDeviceType _device_type;
74 internal bool _software_lock;
75 internal bool _hardware_lock;
76+ internal string mac_address;
77
78 internal RFKillDevice (RFKillManager manager, uint32 idx, RFKillDeviceType device_type, bool software_lock, bool hardware_lock)
79 {
80@@ -54,6 +55,15 @@
81 _device_type = device_type;
82 _software_lock = software_lock;
83 _hardware_lock = hardware_lock;
84+
85+ /* MAC Address */
86+ try {
87+ if (!FileUtils.get_contents ("/sys/class/rfkill/rfkill%d/device/macaddress".printf((int)idx), out mac_address)) {
88+ mac_address = "";
89+ }
90+ } catch (Error e) {
91+ mac_address = "";
92+ }
93 }
94 }
95
96@@ -83,10 +93,16 @@
97
98 public List<RFKillDevice> get_devices ()
99 {
100- var devices = new List<RFKillDevice> ();
101- foreach (var device in _devices)
102- devices.append (device);
103- return devices;
104+ return _devices.copy ();
105+ }
106+
107+ public RFKillDevice? get_device_for_nm_device (NM.Device nm_device) {
108+ foreach (var device in _devices) {
109+ if (nm_device.get_hw_address ().up () == device.mac_address.strip ().up ()) {
110+ return device;
111+ }
112+ }
113+ return null;
114 }
115
116 public void set_software_lock (RFKillDeviceType type, bool lock_enabled)

Subscribers

People subscribed via source and target branches

to all changes: