| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
|
| 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(); |
| 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(); |
| 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 |
} |