Debian Codegraph @

podcasts-gtk/src/widgets/sheet_player.rs

raw symbols SCIP
1 // chapters_page.rs
2 //
3 // Copyright 2025 nee <[email protected]>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // SPDX-License-Identifier: GPL-3.0-or-later
19
20 use adw::prelude::*;
21 use adw::subclass::prelude::*;
22 use glib::clone;
23 use glib::subclass::InitializingObject;
24 use gtk::CompositeTemplate;
25 use gtk::glib;
26 use std::cell::RefCell;
27 use std::rc::Rc;
28
29 use crate::download_covers::load_widget_texture;
30 use crate::widgets::player::PlayerExt;
31 use crate::widgets::player::{PlayerTimes, PlayerWidget};
32 use podcasts_data::Episode;
33 use podcasts_data::ShowCoverModel;
34
35 #[derive(Debug, CompositeTemplate, Default)]
36 #[template(resource = "/org/gnome/Podcasts/gtk/sheet_player.ui")]
37 pub(crate) struct SheetPlayerPriv {
38 #[template_child]
39 cover: TemplateChild<gtk::Image>,
40 #[template_child]
41 play_pause: TemplateChild<gtk::Stack>,
42 #[template_child]
43 play: TemplateChild<gtk::Button>,
44 #[template_child]
45 pause: TemplateChild<gtk::Button>,
46 #[template_child]
47 duration: TemplateChild<gtk::Label>,
48 #[template_child]
49 progressed: TemplateChild<gtk::Label>,
50 #[template_child]
51 slider: TemplateChild<gtk::Scale>,
52 #[template_child]
53 forward: TemplateChild<gtk::Button>,
54 #[template_child]
55 rewind: TemplateChild<gtk::Button>,
56 #[template_child]
57 show: TemplateChild<gtk::Label>,
58 #[template_child]
59 episode: TemplateChild<gtk::Label>,
60 }
61
62 #[glib::object_subclass]
63 impl ObjectSubclass for SheetPlayerPriv {
64 const NAME: &'static str = "PdSheetPlayer";
65 type Type = SheetPlayer;
66 type ParentType = adw::Bin;
67
68 fn class_init(klass: &mut Self::Class) {
69 klass.bind_template();
70 }
71
72 fn instance_init(obj: &InitializingObject<Self>) {
73 obj.init_template();
74 }
75 }
76
77 impl WidgetImpl for SheetPlayerPriv {}
78 impl ObjectImpl for SheetPlayerPriv {}
79 impl BinImpl for SheetPlayerPriv {}
80
81 glib::wrapper! {
82 pub(crate) struct SheetPlayer(ObjectSubclass<SheetPlayerPriv>)
83 @extends adw::Bin, gtk::Widget,
84 @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
85 }
86
87 impl SheetPlayer {
88 pub(crate) fn connect(&self, timer: &PlayerTimes) {
89 let imp = self.imp();
90 timer
91 .duration
92 .bind_property("label", &imp.duration.get(), "label")
93 .flags(glib::BindingFlags::SYNC_CREATE)
94 .build();
95 timer
96 .progressed
97 .bind_property("label", &imp.progressed.get(), "label")
98 .flags(glib::BindingFlags::SYNC_CREATE)
99 .build();
100 imp.slider.set_adjustment(&timer.slider.adjustment());
101 }
102
103 pub(crate) fn initialize_episode(&self, episode: &Episode, show: &ShowCoverModel) {
104 let imp = self.imp();
105 imp.episode.set_text(episode.title());
106 imp.show.set_text(show.title());
107 load_widget_texture(&imp.cover.get(), show.id(), crate::Thumb256, true);
108 }
109
110 pub(crate) fn on_play(&self) {
111 let imp = self.imp();
112 imp.play_pause.set_visible_child(&imp.pause.get());
113 }
114
115 pub(crate) fn on_pause(&self) {
116 let imp = self.imp();
117 imp.play_pause.set_visible_child(&imp.play.get());
118 }
119
120 pub(crate) fn on_stop(&self) {
121 let imp = self.imp();
122 let is_focus = imp.pause.is_focus();
123 imp.play_pause.set_visible_child(&imp.play.get());
124 if is_focus {
125 imp.play.grab_focus();
126 }
127 }
128
129 pub(crate) fn connect_control_buttons(&self, player: &Rc<RefCell<PlayerWidget>>) {
130 let imp = self.imp();
131 // Connect buttons to gst Player
132 imp.play.connect_clicked(clone!(
133 #[weak]
134 player,
135 #[weak(rename_to=this)]
136 self,
137 move |_| {
138 player.borrow().play();
139 this.imp().pause.grab_focus(); // keep focus for accessibility
140 }
141 ));
142
143 imp.pause.connect_clicked(clone!(
144 #[weak]
145 player,
146 #[weak(rename_to=this)]
147 self,
148 move |_| {
149 player.borrow_mut().pause();
150 this.imp().play.grab_focus(); // keep focus for accessibility
151 }
152 ));
153
154 imp.rewind.connect_clicked(clone!(
155 #[weak]
156 player,
157 move |_| {
158 player.borrow().rewind();
159 }
160 ));
161
162 imp.forward.connect_clicked(clone!(
163 #[weak]
164 player,
165 move |_| {
166 player.borrow().fast_forward();
167 }
168 ));
169 }
170 }