thingks
This commit is contained in:
parent
cad786213c
commit
930430d5ec
4 changed files with 55 additions and 13 deletions
|
@ -46,7 +46,7 @@ template $AudreyUiPlaybar: Adw.Bin {
|
|||
|
||||
xalign: 0;
|
||||
halign: start;
|
||||
label: bind template.song as <$AudreyPlaybinSong>.title;
|
||||
label: bind $song_title(template.song) as <string>;
|
||||
ellipsize: end;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ template $AudreyUiPlaybar: Adw.Bin {
|
|||
]
|
||||
|
||||
xalign: 0;
|
||||
label: bind template.song as <$AudreyPlaybinSong>.artist;
|
||||
label: bind $song_artist(template.song) as <string>;
|
||||
ellipsize: end;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ template $AudreyUiPlaybar: Adw.Bin {
|
|||
]
|
||||
|
||||
xalign: 0;
|
||||
label: bind template.song as <$AudreyPlaybinSong>.album;
|
||||
label: bind $song_album(template.song) as <string>;
|
||||
ellipsize: end;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,9 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_row_activated(&self, position: u32) {
|
||||
self.obj().window().playlist_play_index(position as i64);
|
||||
self.obj()
|
||||
.window()
|
||||
.playlist_play_index(Some(position as i64));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ mod imp {
|
|||
#[property(get)]
|
||||
pulse_bar: TemplateChild<gtk::ProgressBar>,
|
||||
|
||||
#[property(get, set)]
|
||||
#[property(get, set, nullable)]
|
||||
song: RefCell<Option<PlaybinSong>>,
|
||||
#[property(get, set)]
|
||||
playing_cover_art: RefCell<Option<gdk::Paintable>>,
|
||||
|
@ -95,12 +95,20 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_skip_forward_clicked(&self) {
|
||||
if self.window().playlist_pos() + 1 < self.window().playlist_count() as i32 {
|
||||
self.window().playlist_next();
|
||||
} else {
|
||||
self.window().playlist_play_index(None);
|
||||
}
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn on_skip_backward_clicked(&self) {
|
||||
if self.window().playlist_pos() > 0 {
|
||||
self.window().playlist_prev();
|
||||
} else {
|
||||
self.window().playlist_play_index(None);
|
||||
}
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
|
@ -126,8 +134,13 @@ mod imp {
|
|||
|
||||
#[template_callback]
|
||||
fn on_play_pause_clicked(&self, _button: >k::Button) {
|
||||
if self.window().idle_active() {
|
||||
self.window().playlist_play_index(Some(0));
|
||||
self.window().set_pause(false);
|
||||
} else {
|
||||
self.window().set_pause(!self.window().pause());
|
||||
}
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn on_mute_toggle(&self) {
|
||||
|
@ -151,6 +164,23 @@ mod imp {
|
|||
fn window(&self) -> crate::ui::Window {
|
||||
self.obj().root().unwrap().dynamic_cast().unwrap()
|
||||
}
|
||||
|
||||
// these are nedeed because with regular bindings, if song becomes None, the labes are not
|
||||
// updated
|
||||
#[template_callback]
|
||||
fn song_title(&self, song: Option<&PlaybinSong>) -> String {
|
||||
song.map(PlaybinSong::title).unwrap_or("".to_string())
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn song_artist(&self, song: Option<&PlaybinSong>) -> String {
|
||||
song.map(PlaybinSong::artist).unwrap_or("".to_string())
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn song_album(&self, song: Option<&PlaybinSong>) -> String {
|
||||
song.map(PlaybinSong::album).unwrap_or("".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Playbar {
|
||||
|
|
|
@ -305,6 +305,8 @@ mod imp {
|
|||
|
||||
Event::EndFile(event) => {
|
||||
event!(Level::INFO, "end file event: {event:?}");
|
||||
window.notify("song");
|
||||
window.imp().buffering_end();
|
||||
|
||||
if let Err(err) = event.reason {
|
||||
event!(Level::ERROR, "end file error: {err}");
|
||||
|
@ -575,11 +577,19 @@ impl Window {
|
|||
todo!()
|
||||
}
|
||||
|
||||
pub fn playlist_play_index(&self, index: i64) {
|
||||
self.imp()
|
||||
pub fn playlist_play_index(&self, index: Option<i64>) {
|
||||
match index.as_ref() {
|
||||
Some(index) => self
|
||||
.imp()
|
||||
.mpv
|
||||
.command(["playlist-play-index", &index.to_string()])
|
||||
.unwrap();
|
||||
.unwrap(),
|
||||
None => self
|
||||
.imp()
|
||||
.mpv
|
||||
.command(["playlist-play-index", "none"])
|
||||
.unwrap(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn playlist_remove(&self, index: i64) {
|
||||
|
|
Loading…
Reference in a new issue