mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Implement add to playlist
This commit is contained in:
parent
714722bd89
commit
4a33ed3fc5
5 changed files with 164 additions and 21 deletions
|
|
@ -2,6 +2,7 @@ use std::cell::OnceCell;
|
|||
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::{
|
||||
gio,
|
||||
glib::{self, Properties},
|
||||
prelude::*,
|
||||
};
|
||||
|
|
@ -57,6 +58,48 @@ mod imp {
|
|||
impl ObjectImpl for AlbumPage {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
let obj = self.obj().to_owned();
|
||||
let add_to_playlist_action = gio::ActionEntry::builder("add-to-playlist")
|
||||
.activate(move |_, _, _| {
|
||||
let playlist = obj
|
||||
.imp()
|
||||
.album
|
||||
.get()
|
||||
.unwrap()
|
||||
.recordings
|
||||
.iter()
|
||||
.map(|r| obj.player().recording_to_playlist(r))
|
||||
.flatten()
|
||||
.collect::<Vec<PlaylistItem>>();
|
||||
|
||||
if let Err(err) = obj.player().append(playlist) {
|
||||
log::warn!("Failed to add album to the playlits: {err}");
|
||||
};
|
||||
})
|
||||
.build();
|
||||
|
||||
let obj = self.obj().to_owned();
|
||||
let edit_action = gio::ActionEntry::builder("edit")
|
||||
.activate(move |_, _, _| {
|
||||
obj.navigation().push(&AlbumEditor::new(
|
||||
&obj.navigation(),
|
||||
&obj.library(),
|
||||
Some(&obj.imp().album.get().unwrap().clone()),
|
||||
));
|
||||
})
|
||||
.build();
|
||||
|
||||
// let obj = self.obj().to_owned();
|
||||
let delete_action = gio::ActionEntry::builder("delete")
|
||||
.activate(move |_, _, _| {
|
||||
log::error!("Delete not implemented");
|
||||
})
|
||||
.build();
|
||||
|
||||
let actions = gio::SimpleActionGroup::new();
|
||||
actions.add_action_entries([add_to_playlist_action, edit_action, delete_action]);
|
||||
self.obj().insert_action_group("album", Some(&actions));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,15 +142,6 @@ impl AlbumPage {
|
|||
obj
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn edit_button_clicked(&self) {
|
||||
self.navigation().push(&AlbumEditor::new(
|
||||
&self.navigation(),
|
||||
&self.library(),
|
||||
Some(&self.imp().album.get().unwrap().clone()),
|
||||
));
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn play_button_clicked(&self) {
|
||||
let playlist = self
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ mod imp {
|
|||
pub active: Cell<bool>,
|
||||
#[property(get, set)]
|
||||
pub playing: Cell<bool>,
|
||||
#[property(get, set)]
|
||||
#[property(get, set = Self::set_program)]
|
||||
pub program: RefCell<Option<Program>>,
|
||||
#[property(get, construct_only)]
|
||||
pub playlist: OnceCell<gio::ListStore>,
|
||||
|
|
@ -51,6 +51,25 @@ mod imp {
|
|||
}
|
||||
|
||||
impl Player {
|
||||
pub fn set_program(&self, program: Option<&Program>) {
|
||||
self.program.replace(program.cloned());
|
||||
|
||||
if let Some(program) = program {
|
||||
if !self.obj().active() {
|
||||
match self.obj().generate_items(program) {
|
||||
Ok(index) => {
|
||||
self.obj().set_active(true);
|
||||
self.obj().set_current_index(index);
|
||||
self.obj().pause();
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("Failed to play from program: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_current_index(&self, index: u32) {
|
||||
let playlist = self.playlist.get().unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -115,6 +115,32 @@ mod imp {
|
|||
obj.imp().scrolled_window.vadjustment().set_value(0.0);
|
||||
obj.search(&entry.text());
|
||||
});
|
||||
|
||||
let obj = self.obj().to_owned();
|
||||
let add_to_playlist_action = gio::ActionEntry::builder("add-to-playlist")
|
||||
.activate(move |_, _, _| {
|
||||
let program = Program::from_query(obj.imp().query.get().unwrap().clone());
|
||||
obj.player().set_program(program);
|
||||
})
|
||||
.build();
|
||||
|
||||
let obj = self.obj().to_owned();
|
||||
let edit_action = gio::ActionEntry::builder("edit")
|
||||
.activate(move |_, _, _| {
|
||||
obj.edit();
|
||||
})
|
||||
.build();
|
||||
|
||||
let obj = self.obj().to_owned();
|
||||
let delete_action = gio::ActionEntry::builder("delete")
|
||||
.activate(move |_, _, _| {
|
||||
obj.delete();
|
||||
})
|
||||
.build();
|
||||
|
||||
let actions = gio::SimpleActionGroup::new();
|
||||
actions.add_action_entries([add_to_playlist_action, edit_action, delete_action]);
|
||||
self.obj().insert_action_group("search", Some(&actions));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,8 +197,7 @@ impl SearchPage {
|
|||
obj
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn edit_button_clicked(&self) {
|
||||
fn edit(&self) {
|
||||
if let Some(highlight) = &*self.imp().highlight.borrow() {
|
||||
match highlight {
|
||||
Tag::Composer(person) | Tag::Performer(person) => {
|
||||
|
|
@ -204,6 +229,27 @@ impl SearchPage {
|
|||
}
|
||||
}
|
||||
|
||||
fn delete(&self) {
|
||||
log::warn!("Deletion not implemented");
|
||||
|
||||
// if let Some(highlight) = &*self.imp().highlight.borrow() {
|
||||
// match highlight {
|
||||
// Tag::Composer(person) | Tag::Performer(person) => {
|
||||
// // TODO
|
||||
// }
|
||||
// Tag::Ensemble(ensemble) => {
|
||||
// // TODO
|
||||
// }
|
||||
// Tag::Instrument(instrument) => {
|
||||
// // TODO
|
||||
// }
|
||||
// Tag::Work(work) => {
|
||||
// // TODO
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn play_button_clicked(&self) {
|
||||
let program = Program::from_query(self.imp().query.get().unwrap().clone());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue