azalea_shell/factory/media/
player.rs1use gtk::prelude::ButtonExt;
2use relm4::{
3 FactorySender,
4 prelude::{DynamicIndex, FactoryComponent},
5};
6use zbus_names::OwnedBusName;
7
8pub type PlayerName = OwnedBusName;
9
10#[derive(Debug)]
11pub struct Model {
12 name: PlayerName,
13}
14
15#[derive(Debug)]
16pub enum Input {
17 Click,
18}
19
20#[derive(Debug)]
21pub enum Output {
22 Select(PlayerName),
23}
24
25#[relm4::factory(pub)]
26impl FactoryComponent for Model {
27 type Init = PlayerName;
28 type Input = Input;
29 type Output = Output;
30 type CommandOutput = ();
31 type ParentWidget = gtk::Box;
32
33 view! {
34 #[root]
35 gtk::Button {
36 set_label: &self.name.strip_prefix("org.mpris.MediaPlayer2.").unwrap_or(&self.name),
37 connect_clicked => Input::Click
38 }
39 }
40
41 fn init_model(name: Self::Init, _index: &DynamicIndex, _sender: FactorySender<Self>) -> Self {
42 Self { name }
43 }
44
45 fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
46 match message {
47 Input::Click => drop(sender.output(Output::Select(self.name.clone()))),
48 }
49 }
50}