Skip to content

Commit

Permalink
ManagerToolbar: Use Gio Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
infirit committed Dec 10, 2022
1 parent 89d007b commit 09f85be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
32 changes: 19 additions & 13 deletions blueman/gui/manager/ManagerToolbar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from gettext import gettext as _
import logging
from typing import TYPE_CHECKING, Callable, Tuple, Optional
from typing import TYPE_CHECKING, Callable, Tuple, Optional, Any

import gi

Expand All @@ -10,6 +10,7 @@

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import Gio

if TYPE_CHECKING:
from blueman.main.Manager import Blueman
Expand All @@ -25,13 +26,18 @@ def __init__(self, blueman: "Blueman") -> None:
self.blueman.List.connect("adapter-property-changed", self.on_adapter_property_changed)

self.b_search = blueman.builder.get_widget("b_search", Gtk.ToolButton)

self.b_bond = blueman.builder.get_widget("b_bond", Gtk.ToolButton)
self.b_bond.connect("clicked", self.on_action, self.blueman.bond)

self.b_trust = blueman.builder.get_widget("b_trust", Gtk.ToolButton)
self.b_trust.connect("clicked", self.on_action, self.blueman.toggle_trust)
self.b_trust.set_homogeneous(False)
self.b_remove = blueman.builder.get_widget("b_remove", Gtk.ToolButton)
self.b_send = blueman.builder.get_widget("b_send", Gtk.ToolButton)

bond_action = Gio.SimpleAction.new("bond", None)
self.blueman.add_action(bond_action)
bond_action.connect("activate", self.on_action, self.blueman.bond)

trust_action = Gio.SimpleAction.new("trust", None)
self.blueman.add_action(trust_action)
trust_action.connect("activate", self.on_action, self.blueman.toggle_trust)

self.b_trust.props.label = _("Untrust")
(size, nsize) = Gtk.Widget.get_preferred_size(self.b_trust)
Expand All @@ -40,17 +46,17 @@ def __init__(self, blueman: "Blueman") -> None:

self.b_trust.props.width_request = max(size.width, size2.width)

self.b_remove = blueman.builder.get_widget("b_remove", Gtk.ToolButton)
self.b_remove.connect("clicked", self.on_action, self.blueman.remove)
remove_action = Gio.SimpleAction.new("remove", None)
self.blueman.add_action(remove_action)
remove_action.connect("activate", self.on_action, self.blueman.remove)

self.b_send = blueman.builder.get_widget("b_send", Gtk.ToolButton)
self.b_send.props.sensitive = False
self.b_send.connect("clicked", self.on_action, self.blueman.send)
self.b_send.set_homogeneous(False)
send_file_action = Gio.SimpleAction.new("sendfile", None)
self.blueman.add_action(send_file_action)
send_file_action.connect("activate", self.on_action, self.blueman.send)

self.on_adapter_changed(blueman.List, blueman.List.get_adapter_path())

def on_action(self, _button: Gtk.ToolButton, func: Callable[[Device], None]) -> None:
def on_action(self, _action: Gio.Action, _val: Optional[Any], func: Callable[[Device], None]) -> None:
device = self.blueman.List.get_selected_device()
if device is not None:
func(device)
Expand Down
9 changes: 7 additions & 2 deletions data/ui/manager-main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
<property name="sensitive">False</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Create pairing with the device</property>
<property name="action-name">app.bond</property>
<property name="label" translatable="yes" comments="translators: toolbar item: keep it as short as possible">Pair</property>
<property name="icon-name">blueman-pair-symbolic</property>
</object>
Expand All @@ -332,12 +333,13 @@
<property name="sensitive">False</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Mark/Unmark this device as trusted</property>
<property name="action-name">app.trust</property>
<property name="label" translatable="yes" comments="translators: toolbar item: keep it as short as possible">Trust</property>
<property name="icon-name">blueman-trust-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
<property name="homogeneous">False</property>
</packing>
</child>
<child>
Expand All @@ -346,6 +348,7 @@
<property name="sensitive">False</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Remove this device from the known devices list</property>
<property name="action-name">app.remove</property>
<property name="label" translatable="yes" comments="translators: toolbar item: keep it as short as possible">Remove</property>
<property name="icon-name">list-remove-symbolic</property>
</object>
Expand All @@ -367,15 +370,17 @@
<child>
<object class="GtkToolButton" id="b_send">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Send file(s) to the device</property>
<property name="is-important">True</property>
<property name="action-name">app.sendfile</property>
<property name="label" translatable="yes" comments="translators: toolbar item: keep it as short as possible">Send File</property>
<property name="icon-name">blueman-send-symbolic</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
<property name="homogeneous">False</property>
</packing>
</child>
<style>
Expand Down

0 comments on commit 09f85be

Please sign in to comment.