154 lines
6.8 KiB
Rust
154 lines
6.8 KiB
Rust
use egui::{RichText, Sense, TextEdit, TopBottomPanel};
|
|
use xmpd_cache::DlStatus;
|
|
use xmpd_manifest::{song::Song, store::{BaseStore, StoreExtras}};
|
|
|
|
use crate::{components::{CompGetter, toast::{Toast, ToastType}}, windows::WindowId};
|
|
|
|
use super::Window;
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct AddSongW {
|
|
sid: uuid::Uuid,
|
|
pid: Option<uuid::Uuid>,
|
|
}
|
|
|
|
impl Window for AddSongW {
|
|
fn id() -> super::WindowId where Self: Sized {
|
|
super::WindowId::AddSongToPl
|
|
}
|
|
fn default_title() -> &'static str where Self: Sized {
|
|
"Add Song to Playlist"
|
|
}
|
|
fn draw(&mut self, ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
|
let mut save = false;
|
|
self.pid = crate::components::left_nav::LeftNav::get()?.selected_playlist_id.clone();
|
|
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
|
|
|
let songs: Vec<_> = state.manifest.store().get_songs_sorted();
|
|
if self.sid.is_nil() {
|
|
if let Some(sid) = songs.first() {
|
|
self.sid = sid.0.clone();
|
|
}
|
|
}
|
|
let avail = ui.available_size();
|
|
ui.horizontal(|ui| {
|
|
ui.vertical(|ui| {
|
|
ui.group(|ui| {
|
|
ui.set_height(avail.y);
|
|
let img = egui::Image::new(crate::data::NOTE_ICON)
|
|
.tint(theme.accent_color)
|
|
.fit_to_exact_size(egui::Vec2::new(64.0, 64.0));
|
|
ui.add(img);
|
|
let mut name = String::new();
|
|
let mut author = String::new();
|
|
if let Some(song) = state.manifest.store().get_song(&self.sid) {
|
|
name = song.name().to_string();
|
|
author = song.author().to_string();
|
|
}
|
|
ui.horizontal(|ui| {
|
|
ui.style_mut().spacing.text_edit_width = 150.0;
|
|
ui.label("Name: ");
|
|
ui.add_enabled(false, TextEdit::singleline(&mut name));
|
|
});
|
|
ui.horizontal(|ui| {
|
|
ui.style_mut().spacing.text_edit_width = 150.0;
|
|
ui.label("Author: ");
|
|
ui.add_enabled(false, TextEdit::singleline(&mut author));
|
|
});
|
|
});
|
|
});
|
|
ui.vertical(|ui| {
|
|
ui.group(|ui| {
|
|
egui::ScrollArea::vertical()
|
|
.id_source("song_list_song_add")
|
|
.drag_to_scroll(false)
|
|
.show(ui, |ui| {
|
|
ui.vertical(|ui| {
|
|
for (sid, song) in songs {
|
|
let resp = ui.group(|ui| {
|
|
let avail = ui.available_size();
|
|
ui.horizontal(|ui| {
|
|
ui.set_width(avail.x);
|
|
let img = egui::Image::new(crate::data::NOTE_ICON)
|
|
.tint(theme.accent_color)
|
|
.fit_to_exact_size(egui::Vec2::new(32.0, 32.0));
|
|
ui.add(img);
|
|
ui.vertical(|ui| {
|
|
let status = {
|
|
handle_error_ui!(xmpd_cache::Cache::get()).get_cached_song_status(&sid).clone()
|
|
};
|
|
let label = if self.sid == *sid {
|
|
RichText::new(song.name())
|
|
.color(theme.accent_color)
|
|
} else if matches!(status, Some(DlStatus::Done(_))) {
|
|
RichText::new(song.name())
|
|
.color(theme.text_color)
|
|
} else {
|
|
RichText::new(song.name())
|
|
.color(theme.dim_text_color)
|
|
};
|
|
ui.label(label);
|
|
});
|
|
});
|
|
});
|
|
if resp.response.interact(Sense::click()).clicked() {
|
|
self.sid = sid.clone();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
);
|
|
});
|
|
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
|
|
TopBottomPanel::bottom("bottom_bar")
|
|
.frame(
|
|
egui::Frame::none()
|
|
.fill(theme.primary_bg_color)
|
|
.stroke(egui::Stroke::new(
|
|
1.0,
|
|
theme.secondary_bg_color,
|
|
)),
|
|
)
|
|
.show(ui.ctx(), |ui| {
|
|
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
|
|
|
|
ui.add_space(3.0);
|
|
ui.horizontal(|ui| {
|
|
// ui.add_space(3.0);
|
|
|
|
|
|
if ui.button("Add").clicked() {
|
|
save = true;
|
|
}
|
|
|
|
if ui.button("Cancel").clicked() {
|
|
state.windows.toggle(&WindowId::AddSongToPl, false);
|
|
}
|
|
if ui.button("Close").clicked() {
|
|
state.windows.toggle(&WindowId::AddSongToPl, false);
|
|
}
|
|
});
|
|
});
|
|
|
|
})
|
|
});
|
|
if save {
|
|
match &self.pid {
|
|
Some(pid) => {
|
|
let pl = state.manifest.store_mut().get_playlist_mut(pid);
|
|
match pl {
|
|
Some(pl) => pl.add_song(&self.sid),
|
|
None => Toast::get().unwrap().show_toast("Not Allowed", "You cant add a song to the 'All Songs' playlist", ToastType::Error)
|
|
};
|
|
}
|
|
None => (),
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
|
|
|
}
|
|
}
|