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
|
|
@ -22,14 +22,12 @@ template $MusicusPlayerBar : Gtk.Box {
|
||||||
Gtk.Label title_label {
|
Gtk.Label title_label {
|
||||||
styles ["title"]
|
styles ["title"]
|
||||||
halign: start;
|
halign: start;
|
||||||
label: _("Title");
|
|
||||||
ellipsize: end;
|
ellipsize: end;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gtk.Label subtitle_label {
|
Gtk.Label subtitle_label {
|
||||||
styles ["subtitle", "dim-label"]
|
styles ["subtitle", "dim-label"]
|
||||||
halign: start;
|
halign: start;
|
||||||
label: _("Subtitle");
|
|
||||||
ellipsize: end;
|
ellipsize: end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,11 +183,12 @@ impl MusicusHomePage {
|
||||||
|
|
||||||
if tracks.len() == 1 {
|
if tracks.len() == 1 {
|
||||||
items.push(PlaylistItem::new(
|
items.push(PlaylistItem::new(
|
||||||
|
true,
|
||||||
&title,
|
&title,
|
||||||
performances.as_ref().map(|x| x.as_str()),
|
performances.as_ref().map(|x| x.as_str()),
|
||||||
None,
|
None,
|
||||||
&tracks[0].path,
|
&tracks[0].path,
|
||||||
))
|
));
|
||||||
} else {
|
} else {
|
||||||
let work_parts = self.library().work_parts(&recording.work);
|
let work_parts = self.library().work_parts(&recording.work);
|
||||||
let mut tracks = tracks.into_iter();
|
let mut tracks = tracks.into_iter();
|
||||||
|
|
@ -203,6 +204,7 @@ impl MusicusHomePage {
|
||||||
};
|
};
|
||||||
|
|
||||||
items.push(PlaylistItem::new(
|
items.push(PlaylistItem::new(
|
||||||
|
true,
|
||||||
&title,
|
&title,
|
||||||
performances.as_ref().map(|x| x.as_str()),
|
performances.as_ref().map(|x| x.as_str()),
|
||||||
Some(&track_title(&first_track)),
|
Some(&track_title(&first_track)),
|
||||||
|
|
@ -210,7 +212,13 @@ impl MusicusHomePage {
|
||||||
));
|
));
|
||||||
|
|
||||||
while let Some(track) = tracks.next() {
|
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) {
|
fn constructed(&self) {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
self.player
|
let player = self.player.borrow();
|
||||||
.borrow()
|
|
||||||
|
player
|
||||||
.bind_property("playing", &self.play_button.get(), "icon-name")
|
.bind_property("playing", &self.play_button.get(), "icon-name")
|
||||||
.transform_to(|_, playing| {
|
.transform_to(|_, playing| {
|
||||||
Some(if playing {
|
Some(if playing {
|
||||||
|
|
@ -80,6 +81,28 @@ mod imp {
|
||||||
})
|
})
|
||||||
.sync_create()
|
.sync_create()
|
||||||
.build();
|
.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()
|
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| {
|
self.connect_local("show-playlist", true, move |values| {
|
||||||
let obj = values[0].get::<Self>().unwrap();
|
let obj = values[0].get::<Self>().unwrap();
|
||||||
let show = values[1].get::<bool>().unwrap();
|
let show = values[1].get::<bool>().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ mod imp {
|
||||||
#[property(get, construct_only)]
|
#[property(get, construct_only)]
|
||||||
pub is_title: OnceCell<bool>,
|
pub is_title: OnceCell<bool>,
|
||||||
|
|
||||||
#[property(get, construct_only, nullable)]
|
#[property(get, construct_only)]
|
||||||
pub title: OnceCell<Option<String>>,
|
pub title: OnceCell<String>,
|
||||||
|
|
||||||
#[property(get, construct_only, nullable)]
|
#[property(get, construct_only, nullable)]
|
||||||
pub performers: OnceCell<Option<String>>,
|
pub performers: OnceCell<Option<String>>,
|
||||||
|
|
@ -45,25 +45,18 @@ glib::wrapper! {
|
||||||
|
|
||||||
impl PlaylistItem {
|
impl PlaylistItem {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
is_title: bool,
|
||||||
title: &str,
|
title: &str,
|
||||||
performers: Option<&str>,
|
performers: Option<&str>,
|
||||||
part_title: Option<&str>,
|
part_title: Option<&str>,
|
||||||
path: impl AsRef<Path>,
|
path: impl AsRef<Path>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
glib::Object::builder()
|
glib::Object::builder()
|
||||||
.property("is-title", true)
|
.property("is-title", is_title)
|
||||||
.property("title", title)
|
.property("title", title)
|
||||||
.property("performers", performers)
|
.property("performers", performers)
|
||||||
.property("part-title", part_title)
|
.property("part-title", part_title)
|
||||||
.property("path", path.as_ref())
|
.property("path", path.as_ref())
|
||||||
.build()
|
.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(item) = item {
|
||||||
if let Some(title) = item.title() {
|
if item.is_title() {
|
||||||
imp.title_label.set_label(&title);
|
imp.title_label.set_label(&item.title());
|
||||||
imp.title_label.set_visible(true);
|
imp.title_label.set_visible(true);
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(performances) = item.performers() {
|
if let Some(performances) = item.performers() {
|
||||||
imp.performances_label.set_label(&performances);
|
imp.performances_label.set_label(&performances);
|
||||||
imp.performances_label.set_visible(true);
|
imp.performances_label.set_visible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(part_title) = item.part_title() {
|
if let Some(part_title) = item.part_title() {
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,13 @@ mod imp {
|
||||||
let playlist_page = MusicusPlaylistPage::new(&self.player);
|
let playlist_page = MusicusPlaylistPage::new(&self.player);
|
||||||
self.stack.add_named(&playlist_page, Some("playlist"));
|
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();
|
player_bar.playlist_hidden();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let stack = self.stack.get();
|
player_bar.connect_show_playlist(clone!(@weak playlist_page, @weak stack => move |_, show| {
|
||||||
player_bar.connect_show_playlist(clone!(@weak playlist_page => move |_, show| {
|
|
||||||
if show {
|
if show {
|
||||||
playlist_page.scroll_to_current();
|
playlist_page.scroll_to_current();
|
||||||
stack.set_visible_child_name("playlist");
|
stack.set_visible_child_name("playlist");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue