Skip to content

Commit

Permalink
Respect adapter power state in manager toolbar
Browse files Browse the repository at this point in the history
Disable search and send buttons if the adapter is not powered (unpaired devices should not be present anyway).
  • Loading branch information
cschramm committed Nov 4, 2023
1 parent 40449c0 commit 0ed27ea
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions blueman/gui/manager/ManagerToolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,52 +56,39 @@ def on_action(self, _button: Gtk.ToolButton, func: Callable[[Device], None]) ->
if device is not None:
func(device)

def on_adapter_property_changed(self, _lst: ManagerDeviceList, _adapter: Adapter,
def on_adapter_property_changed(self, _lst: ManagerDeviceList, adapter: Adapter,
key_value: Tuple[str, object]) -> None:
key, value = key_value
if key == "Discovering":
if value:
self.b_search.props.sensitive = False
else:
self.b_search.props.sensitive = True
if key == "Discovering" or key == "Powered":
self._update_buttons(adapter)

def on_adapter_changed(self, _lst: ManagerDeviceList, adapter_path: Optional[str]) -> None:
logging.debug(f"toolbar adapter {adapter_path}")
if adapter_path is None:
self.b_search.props.sensitive = False
self.b_send.props.sensitive = False
else:
self.b_search.props.sensitive = True
self._update_buttons(None if adapter_path is None else Adapter(obj_path=adapter_path))

def on_device_selected(self, dev_list: ManagerDeviceList, device: Device, _tree_iter: Gtk.TreeIter) -> None:
self._update_buttons(Adapter(obj_path=device["Adapter"]))

def _update_buttons(self, adapter: Optional[Adapter]) -> None:
powered = adapter is not None and adapter["Powered"]
self.b_search.props.sensitive = powered and not (adapter and adapter["Discovering"])

def on_device_selected(self, dev_list: ManagerDeviceList, device: Device, tree_iter: Gtk.TreeIter) -> None:
if device is None or tree_iter is None:
tree_iter = self.blueman.List.selected()
if tree_iter is None:
self.b_bond.props.sensitive = False
self.b_remove.props.sensitive = False
self.b_trust.props.sensitive = False
self.b_remove.props.sensitive = False
self.b_send.props.sensitive = False
else:
row = dev_list.get(tree_iter, "paired", "trusted", "objpush")
row = self.blueman.List.get(tree_iter, "paired", "trusted", "objpush")
self.b_bond.props.sensitive = powered and not row["paired"]
self.b_trust.props.sensitive = True
self.b_remove.props.sensitive = True
if row["paired"]:
self.b_bond.props.sensitive = False
else:
self.b_bond.props.sensitive = True

if row["trusted"]:
image = Gtk.Image(icon_name="blueman-untrust-symbolic", pixel_size=24, visible=True)
self.b_trust.props.icon_widget = image
self.b_trust.props.sensitive = True
self.b_trust.props.label = _("Untrust")

else:
image = Gtk.Image(icon_name="blueman-trust-symbolic", pixel_size=24, visible=True)
self.b_trust.props.icon_widget = image
self.b_trust.props.sensitive = True
self.b_trust.props.label = _("Trust")

if row["objpush"]:
self.b_send.props.sensitive = True
else:
self.b_send.props.sensitive = False
self.b_send.props.sensitive = powered and row["objpush"]

icon_name = "blueman-untrust-symbolic" if row["trusted"] else "blueman-trust-symbolic"
self.b_trust.props.icon_widget = Gtk.Image(icon_name=icon_name, pixel_size=24, visible=True)
self.b_trust.props.label = _("Untrust") if row["trusted"] else _("Trust")

def on_device_propery_changed(self, dev_list: ManagerDeviceList, device: Device, tree_iter: Gtk.TreeIter,
key_value: Tuple[str, object]) -> None:
Expand Down

0 comments on commit 0ed27ea

Please sign in to comment.