mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Show current item in player bar
This commit is contained in:
parent
232faa6a2f
commit
2d4f3d73cf
6 changed files with 53 additions and 27 deletions
|
|
@ -183,11 +183,12 @@ impl MusicusHomePage {
|
|||
|
||||
if tracks.len() == 1 {
|
||||
items.push(PlaylistItem::new(
|
||||
true,
|
||||
&title,
|
||||
performances.as_ref().map(|x| x.as_str()),
|
||||
None,
|
||||
&tracks[0].path,
|
||||
))
|
||||
));
|
||||
} else {
|
||||
let work_parts = self.library().work_parts(&recording.work);
|
||||
let mut tracks = tracks.into_iter();
|
||||
|
|
@ -203,6 +204,7 @@ impl MusicusHomePage {
|
|||
};
|
||||
|
||||
items.push(PlaylistItem::new(
|
||||
true,
|
||||
&title,
|
||||
performances.as_ref().map(|x| x.as_str()),
|
||||
Some(&track_title(&first_track)),
|
||||
|
|
@ -210,7 +212,13 @@ impl MusicusHomePage {
|
|||
));
|
||||
|
||||
while let Some(track) = tracks.next() {
|
||||
items.push(PlaylistItem::new_part(&track_title(&track), &track.path));
|
||||
items.push(PlaylistItem::new(
|
||||
false,
|
||||
&title,
|
||||
performances.as_ref().map(|x| x.as_str()),
|
||||
Some(&track_title(&track)),
|
||||
&track.path,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,9 @@ mod imp {
|
|||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
self.player
|
||||
.borrow()
|
||||
let player = self.player.borrow();
|
||||
|
||||
player
|
||||
.bind_property("playing", &self.play_button.get(), "icon-name")
|
||||
.transform_to(|_, playing| {
|
||||
Some(if playing {
|
||||
|
|
@ -80,6 +81,28 @@ mod imp {
|
|||
})
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
let title_label = self.title_label.get();
|
||||
let subtitle_label = self.subtitle_label.get();
|
||||
player.connect_current_index_notify(move |player| {
|
||||
if let Some(item) = player.current_item() {
|
||||
let mut title = item.title();
|
||||
|
||||
if let Some(part_title) = item.part_title() {
|
||||
title.push_str(": ");
|
||||
title.push_str(&part_title);
|
||||
}
|
||||
|
||||
title_label.set_label(&title);
|
||||
|
||||
if let Some(performances) = item.performers() {
|
||||
subtitle_label.set_label(&performances);
|
||||
subtitle_label.set_visible(true);
|
||||
} else {
|
||||
subtitle_label.set_visible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +121,10 @@ impl PlayerBar {
|
|||
glib::Object::builder().property("player", player).build()
|
||||
}
|
||||
|
||||
pub fn connect_show_playlist<F: Fn(&Self, bool) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
pub fn connect_show_playlist<F: Fn(&Self, bool) + 'static>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> glib::SignalHandlerId {
|
||||
self.connect_local("show-playlist", true, move |values| {
|
||||
let obj = values[0].get::<Self>().unwrap();
|
||||
let show = values[1].get::<bool>().unwrap();
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ mod imp {
|
|||
#[property(get, construct_only)]
|
||||
pub is_title: OnceCell<bool>,
|
||||
|
||||
#[property(get, construct_only, nullable)]
|
||||
pub title: OnceCell<Option<String>>,
|
||||
#[property(get, construct_only)]
|
||||
pub title: OnceCell<String>,
|
||||
|
||||
#[property(get, construct_only, nullable)]
|
||||
pub performers: OnceCell<Option<String>>,
|
||||
|
|
@ -45,25 +45,18 @@ glib::wrapper! {
|
|||
|
||||
impl PlaylistItem {
|
||||
pub fn new(
|
||||
is_title: bool,
|
||||
title: &str,
|
||||
performers: Option<&str>,
|
||||
part_title: Option<&str>,
|
||||
path: impl AsRef<Path>,
|
||||
) -> Self {
|
||||
glib::Object::builder()
|
||||
.property("is-title", true)
|
||||
.property("is-title", is_title)
|
||||
.property("title", title)
|
||||
.property("performers", performers)
|
||||
.property("part-title", part_title)
|
||||
.property("path", path.as_ref())
|
||||
.build()
|
||||
}
|
||||
|
||||
pub fn new_part(part_title: &str, path: impl AsRef<Path>) -> Self {
|
||||
glib::Object::builder()
|
||||
.property("is-title", false)
|
||||
.property("part-title", part_title)
|
||||
.property("path", path.as_ref())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ impl PlaylistTile {
|
|||
}
|
||||
|
||||
if let Some(item) = item {
|
||||
if let Some(title) = item.title() {
|
||||
imp.title_label.set_label(&title);
|
||||
if item.is_title() {
|
||||
imp.title_label.set_label(&item.title());
|
||||
imp.title_label.set_visible(true);
|
||||
}
|
||||
|
||||
if let Some(performances) = item.performers() {
|
||||
imp.performances_label.set_label(&performances);
|
||||
imp.performances_label.set_visible(true);
|
||||
if let Some(performances) = item.performers() {
|
||||
imp.performances_label.set_label(&performances);
|
||||
imp.performances_label.set_visible(true);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(part_title) = item.part_title() {
|
||||
|
|
|
|||
|
|
@ -49,12 +49,13 @@ mod imp {
|
|||
let playlist_page = MusicusPlaylistPage::new(&self.player);
|
||||
self.stack.add_named(&playlist_page, Some("playlist"));
|
||||
|
||||
playlist_page.connect_close(clone!(@weak player_bar => move |_| {
|
||||
let stack = self.stack.get();
|
||||
playlist_page.connect_close(clone!(@weak player_bar, @weak stack => move |_| {
|
||||
stack.set_visible_child_name("navigation");
|
||||
player_bar.playlist_hidden();
|
||||
}));
|
||||
|
||||
let stack = self.stack.get();
|
||||
player_bar.connect_show_playlist(clone!(@weak playlist_page => move |_, show| {
|
||||
player_bar.connect_show_playlist(clone!(@weak playlist_page, @weak stack => move |_, show| {
|
||||
if show {
|
||||
playlist_page.scroll_to_current();
|
||||
stack.set_visible_child_name("playlist");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue