2020-08-02 17:18:28 +02:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import gi
|
2024-05-26 18:29:10 +02:00
|
|
|
|
|
2023-01-08 18:20:30 +01:00
|
|
|
|
gi.require_version('Gtk', '4.0')
|
|
|
|
|
gi.require_version('Adw', '1')
|
|
|
|
|
from gi.repository import Gtk, Adw, GObject
|
2020-08-02 17:18:28 +02:00
|
|
|
|
|
|
|
|
|
|
2020-08-09 11:09:53 +02:00
|
|
|
|
@Gtk.Template(resource_path='/xyz/suruatoel/mcg/ui/server-panel.ui')
|
2023-01-08 18:20:30 +01:00
|
|
|
|
class ServerPanel(Adw.Bin):
|
2020-08-02 17:18:28 +02:00
|
|
|
|
__gtype_name__ = 'McgServerPanel'
|
|
|
|
|
__gsignals__ = {
|
2024-05-27 12:46:46 +02:00
|
|
|
|
'change-output-device': (GObject.SIGNAL_RUN_FIRST, None, (
|
|
|
|
|
GObject.TYPE_PYOBJECT,
|
|
|
|
|
bool,
|
|
|
|
|
)),
|
2020-08-02 17:18:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Widgets
|
2023-01-08 18:20:30 +01:00
|
|
|
|
toolbar = Gtk.Template.Child()
|
2020-08-02 17:18:28 +02:00
|
|
|
|
# Status widgets
|
|
|
|
|
status_file = Gtk.Template.Child()
|
|
|
|
|
status_audio = Gtk.Template.Child()
|
|
|
|
|
status_bitrate = Gtk.Template.Child()
|
|
|
|
|
status_error = Gtk.Template.Child()
|
|
|
|
|
# Stats widgets
|
|
|
|
|
stats_artists = Gtk.Template.Child()
|
|
|
|
|
stats_albums = Gtk.Template.Child()
|
|
|
|
|
stats_songs = Gtk.Template.Child()
|
|
|
|
|
stats_dbplaytime = Gtk.Template.Child()
|
|
|
|
|
stats_playtime = Gtk.Template.Child()
|
|
|
|
|
stats_uptime = Gtk.Template.Child()
|
2024-11-03 10:55:52 +01:00
|
|
|
|
# Audio output devices widgets
|
2020-08-02 17:18:28 +02:00
|
|
|
|
output_devices = Gtk.Template.Child()
|
|
|
|
|
|
2023-01-08 18:20:30 +01:00
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
|
super().__init__(**kwargs)
|
2020-08-02 17:18:28 +02:00
|
|
|
|
self._none_label = ""
|
|
|
|
|
self._output_buttons = {}
|
|
|
|
|
self._is_selected = False
|
|
|
|
|
|
|
|
|
|
# Widgets
|
|
|
|
|
self._none_label = self.status_file.get_label()
|
|
|
|
|
|
|
|
|
|
def set_selected(self, selected):
|
|
|
|
|
self._is_selected = selected
|
|
|
|
|
|
|
|
|
|
def get_toolbar(self):
|
2023-01-08 18:20:30 +01:00
|
|
|
|
return self.toolbar
|
2020-08-02 17:18:28 +02:00
|
|
|
|
|
|
|
|
|
def on_output_device_toggled(self, widget, device):
|
|
|
|
|
self.emit('change-output-device', device, widget.get_active())
|
|
|
|
|
|
|
|
|
|
def set_status(self, file, audio, bitrate, error):
|
|
|
|
|
if file:
|
|
|
|
|
file = GObject.markup_escape_text(file)
|
|
|
|
|
else:
|
|
|
|
|
file = self._none_label
|
|
|
|
|
self.status_file.set_markup(file)
|
|
|
|
|
# Audio information
|
2024-05-27 12:46:46 +02:00
|
|
|
|
if audio:
|
2020-08-02 17:18:28 +02:00
|
|
|
|
parts = audio.split(":")
|
|
|
|
|
if len(parts) == 3:
|
2024-05-27 12:46:46 +02:00
|
|
|
|
audio = "{} Hz, {} bit, {} channels".format(
|
|
|
|
|
parts[0], parts[1], parts[2])
|
2020-08-02 17:18:28 +02:00
|
|
|
|
else:
|
|
|
|
|
audio = self._none_label
|
|
|
|
|
self.status_audio.set_markup(audio)
|
|
|
|
|
# Bitrate
|
|
|
|
|
if bitrate:
|
|
|
|
|
bitrate = bitrate + " kb/s"
|
|
|
|
|
else:
|
|
|
|
|
bitrate = self._none_label
|
|
|
|
|
self.status_bitrate.set_markup(bitrate)
|
|
|
|
|
# Error
|
|
|
|
|
if error:
|
|
|
|
|
error = GObject.markup_escape_text(error)
|
|
|
|
|
else:
|
|
|
|
|
error = self._none_label
|
|
|
|
|
self.status_error.set_markup(error)
|
|
|
|
|
|
|
|
|
|
def set_stats(self, artists, albums, songs, dbplaytime, playtime, uptime):
|
|
|
|
|
self.stats_artists.set_text(str(artists))
|
|
|
|
|
self.stats_albums.set_text(str(albums))
|
|
|
|
|
self.stats_songs.set_text(str(songs))
|
|
|
|
|
self.stats_dbplaytime.set_text(str(dbplaytime))
|
|
|
|
|
self.stats_playtime.set_text(str(playtime))
|
|
|
|
|
self.stats_uptime.set_text(str(uptime))
|
|
|
|
|
|
|
|
|
|
def set_output_devices(self, devices):
|
|
|
|
|
device_ids = []
|
|
|
|
|
|
|
|
|
|
# Add devices
|
|
|
|
|
for device in devices:
|
|
|
|
|
device_ids.append(device.get_id())
|
|
|
|
|
if device.get_id() in self._output_buttons.keys():
|
|
|
|
|
self._output_buttons[device.get_id()].freeze_notify()
|
2024-05-27 12:46:46 +02:00
|
|
|
|
self._output_buttons[device.get_id()].set_active(
|
|
|
|
|
device.is_enabled())
|
2020-08-02 17:18:28 +02:00
|
|
|
|
self._output_buttons[device.get_id()].thaw_notify()
|
|
|
|
|
else:
|
2023-01-08 18:20:30 +01:00
|
|
|
|
button = Gtk.CheckButton.new_with_label(device.get_name())
|
2020-08-02 17:18:28 +02:00
|
|
|
|
if device.is_enabled():
|
|
|
|
|
button.set_active(True)
|
2024-11-03 10:44:11 +01:00
|
|
|
|
button.connect('toggled', self.on_output_device_toggled,
|
|
|
|
|
device)
|
2020-08-02 17:18:28 +02:00
|
|
|
|
self.output_devices.insert(button, -1)
|
|
|
|
|
self._output_buttons[device.get_id()] = button
|
|
|
|
|
|
|
|
|
|
# Remove devices
|
|
|
|
|
for id in self._output_buttons.keys():
|
|
|
|
|
if id not in device_ids:
|
2024-05-27 12:46:46 +02:00
|
|
|
|
self.output_devices.remove(
|
|
|
|
|
self._output_buttons[id].get_parent())
|