Skip to content

Commit

Permalink
Manager: Add initial bluetooth status icon
Browse files Browse the repository at this point in the history
Would have been nice to show the state of the killswitch and adapter
individually but the killswitch state is not easily accessible.
  • Loading branch information
infirit committed Feb 21, 2024
1 parent a33b8d4 commit d816e1d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions blueman/main/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ def do_activate(self) -> None:
margin_right = statusbar.get_margin_right()
statusbar.set_margin_right(margin_right + 10)

def update_bt_status(state: bool) -> None:
if state:
icon_name = "bluetooth"
tooltip_text = _("Bluetooth is enabled.")
else:
icon_name = "bluetooth-disabled"
tooltip_text = _("Bluetooth is disabled, enable in the Adapter menu.")

icon = self.builder.get_widget("bt_status_icon", Gtk.Image)
icon.set_from_icon_name(icon_name, Gtk.IconSize.MENU)
icon.set_tooltip_text(tooltip_text)

def on_applet_signal(_proxy: AppletService, _sender: str, signal_name: str, params: GLib.Variant) -> None:
if signal_name == 'BluetoothStatusChanged':
status = params.unpack()[0]
update_bt_status(status)

def on_dbus_name_vanished(_connection: Gio.DBusConnection, name: str) -> None:
logging.info(name)

Expand All @@ -108,6 +125,7 @@ def on_dbus_name_appeared(_connection: Gio.DBusConnection, name: str, owner: str

try:
self.Applet = AppletService()
self.Applet.connect('g-signal', on_applet_signal)
except DBusProxyFailed:
print("Blueman applet needs to be running")
bmexit()
Expand All @@ -134,6 +152,8 @@ def on_dbus_name_appeared(_connection: Gio.DBusConnection, name: str, owner: str
self.Config.bind("show-toolbar", toolbar, "visible", Gio.SettingsBindFlags.DEFAULT)
self.Config.bind("show-statusbar", statusbar, "visible", Gio.SettingsBindFlags.DEFAULT)

update_bt_status(self.Applet.GetBluetoothStatus())

Manager.watch_name_owner(on_dbus_name_appeared, on_dbus_name_vanished)

self.window.present_with_time(Gtk.get_current_event_time())
Expand Down
25 changes: 25 additions & 0 deletions data/ui/manager-main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,31 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkImage" id="bt_status_icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">bluetooth-disabled</property>
<property name="icon_size">1</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">0</property>
Expand Down

0 comments on commit d816e1d

Please sign in to comment.