Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Network.Indicator : Wingpanel.Indicator {

NetworkMonitor network_monitor;

private RFKillManager rfkill;
private Gtk.GestureMultiPress gesture_click;
private SimpleAction airplane_action;

Expand Down Expand Up @@ -65,19 +66,16 @@ public class Network.Indicator : Wingpanel.Indicator {
});
}

airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (popover_widget.nm_client.networking_get_enabled ()));
rfkill = new RFKillManager ();
rfkill.open ();

airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (rfkill.airplane_mode));
airplane_action.activate.connect (() => {
popover_widget.nm_client.dbus_call.begin (
NM.DBUS_PATH, NM.DBUS_INTERFACE,
"Enable", new Variant.tuple ({new Variant.boolean (!popover_widget.nm_client.networking_get_enabled ())}),
null, -1, null, (obj, res) => {
try {
((NM.Client) obj).dbus_set_property.end (res);
} catch (Error e) {
warning ("Error setting airplane mode: %s", e.message);
}
}
);
rfkill.airplane_mode = !rfkill.airplane_mode;
});

rfkill.device_changed.connect (() => {
airplane_action.set_state (new Variant.boolean (rfkill.airplane_mode));
});

var action_group = (SimpleActionGroup) popover_widget.get_action_group ("network");
Expand All @@ -102,8 +100,6 @@ public class Network.Indicator : Wingpanel.Indicator {

display_widget.update_state (popover_widget.state, popover_widget.secure, popover_widget.extra_info);

airplane_action.set_state (new Variant.boolean (!popover_widget.nm_client.networking_get_enabled ()));

update_tooltip ();
}

Expand Down
1 change: 0 additions & 1 deletion src/Widgets/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class Network.Widgets.PopoverWidget : Gtk.Box {

var action_group = new SimpleActionGroup ();
action_group.action_state_changed.connect ((action_name, state) => {
critical ("got a state change");
if (action_name == "airplane-mode") {
if (state.get_boolean ()) {
airplane_toggle.icon_name = "airplane-mode-symbolic";
Expand Down
44 changes: 44 additions & 0 deletions src/rfkill.vala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,50 @@ public class RFKillManager : Object {
return devices;
}

/*
* Toggle Airplane Mode
*
* Modern mobile platforms don't disable Bluetooth, we skip it too
*
* Setting airplane mode from here does all software lock, whereas setting
* from a key press does all hardware lock. We need one of these two things—
* all devices to be locked somehow—to consider it Airplane Mode
*/
public bool airplane_mode {
get {
var all_hardware_locked = true;
var all_software_locked = true;

foreach (unowned var device in get_devices ()) {
if (device.device_type == BLUETOOTH) {
continue;
}

if (!device.software_lock) {
all_software_locked = false;
}

if (!device.hardware_lock) {
all_hardware_locked = false;
}
}

return all_hardware_locked || all_software_locked;
}

set {
set_software_lock (WLAN, value);
set_software_lock (UWB, value);
set_software_lock (WIMAX, value);
set_software_lock (WMAN, value);

// Some hardware keys still turn off bluetooth
if (!value) {
set_software_lock (BLUETOOTH, false);
}
}
}

public void set_software_lock (RFKillDeviceType type, bool lock_enabled) {
var event = RFKillEvent ();
event.type = type;
Expand Down