Major update
too lazy to describe
This commit is contained in:
@@ -33,3 +33,5 @@ uuid.workspace = true
|
||||
camino.workspace = true
|
||||
rfd.workspace = true
|
||||
dirs.workspace = true
|
||||
downcast-rs.workspace = true
|
||||
url.workspace = true
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use anyhow::anyhow;
|
||||
use egui::{Color32, CursorIcon, ImageSource, RichText, Sense, Vec2};
|
||||
use xmpd_cache::DlStatus;
|
||||
use xmpd_manifest::{query, song::Song, store::{BaseStore, StoreExtras}};
|
||||
use crate::utils::SearchType;
|
||||
|
||||
use crate::{components::toast::{Toast, ToastType}, utils::SearchType, windows::WindowId};
|
||||
use std::any::Any;
|
||||
use super::{CompGetter, CompUi};
|
||||
use downcast_rs::Downcast;
|
||||
|
||||
pub mod header;
|
||||
|
||||
@@ -93,7 +95,7 @@ impl SongList {
|
||||
fn display_song_tab(ui: &mut egui::Ui, state: &mut crate::GuiState, sid: &uuid::Uuid) -> crate::Result<()> {
|
||||
let mut clicked = false;
|
||||
ui.horizontal(|ui| {
|
||||
let song = handle_option!("(internal)", state.manifest.store().get_song(sid));
|
||||
let song = handle_option!("(internal)", state.manifest.store().get_song(sid)).clone();
|
||||
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
|
||||
// let icon_status = handle_error_ui!(xmpd_cache::Cache::get()).get_cached_icon_status(&sid).clone();
|
||||
let img = ui.add(
|
||||
@@ -151,7 +153,7 @@ impl SongList {
|
||||
}
|
||||
}
|
||||
|
||||
// label.context_menu(|ui| handle_error_ui!(Self::show_context_menu(ui, sid, song)));
|
||||
label.context_menu(|ui| handle_error_ui!(Self::show_context_menu(state, ui, sid, &song)));
|
||||
ui.monospace(
|
||||
RichText::new(format!("By {}", song.author()))
|
||||
.color(theme.dim_text_color)
|
||||
@@ -165,14 +167,14 @@ impl SongList {
|
||||
|
||||
match status {
|
||||
Some(DlStatus::Done(_)) => {
|
||||
//let img = egui::Image::new(crate::data::CHECK_ICON)
|
||||
// .tint(Color32::LIGHT_GREEN)
|
||||
// .sense(Sense::hover())
|
||||
// .fit_to_exact_size(Vec2::new(16.0, 16.0));
|
||||
let img = egui::Image::new(crate::data::CHECK_ICON)
|
||||
.tint(Color32::LIGHT_GREEN)
|
||||
.sense(Sense::hover())
|
||||
.fit_to_exact_size(Vec2::new(16.0, 16.0));
|
||||
|
||||
//ui.add(img).on_hover_ui(|ui| {
|
||||
// ui.label(format!("Path: {p}"));
|
||||
//});
|
||||
ui.add(img).on_hover_ui(|ui| {
|
||||
ui.label(format!("Id: {sid}"));
|
||||
});
|
||||
}
|
||||
Some(DlStatus::Downloading) => {
|
||||
let spinner = egui::Spinner::new()
|
||||
@@ -264,10 +266,36 @@ impl SongList {
|
||||
}
|
||||
Ok(playable_songs)
|
||||
}
|
||||
//fn show_context_menu(ui: &mut egui::Ui, sid: &uuid::Uuid, song: &Song) -> crate::Result<()> {
|
||||
// if ui.button("Download icon").clicked() {
|
||||
// xmpd_cache::Cache::get()?.download_icon_to_cache(sid.clone(), song.clone());
|
||||
// }
|
||||
// Ok(())
|
||||
//}
|
||||
fn show_context_menu(state: &mut crate::GuiState, ui: &mut egui::Ui, sid: &uuid::Uuid, song: &Song) -> crate::Result<()> {
|
||||
if ui.button("Edit").clicked() {
|
||||
// TODO: Implement song editing
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Song editing is not implemented", ToastType::Error);
|
||||
//state.windows.toggle(&crate::windows::WindowId::NewSong, status);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Add to playlist").clicked() {
|
||||
// TODO: Implement song editing
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Adding songs to another playlist is not implemented, go to that playlist and press add song", ToastType::Error);
|
||||
//state.windows.toggle(&WindowId::AddSongToPl, true);
|
||||
//let mut windows = crate::windows::WINDOWS.lock().map_err(|e| anyhow!("{e}"))?;
|
||||
//let mut w = windows.get_mut(&WindowId::AddSongToPl);
|
||||
//let w = w.as_any_mut();
|
||||
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Songs by artist").clicked() {
|
||||
crate::components::song_list::header::Header::get()?.search_text = format!("author:{}", song.author());
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button(RichText::new("Remove from playlist").color(Color32::RED)).clicked() {
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Removing songs from playlists is not implemented", ToastType::Error);
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button(RichText::new("Remove song globally").color(Color32::RED)).clicked() {
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Removing songs globally is not implemented", ToastType::Error);
|
||||
ui.close_menu();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ impl CompUi for TopNav {
|
||||
}
|
||||
});
|
||||
ui.menu_button("Manifest", |ui| {
|
||||
if ui.button("Add New Song").clicked() {
|
||||
state.windows.toggle(&WindowId::NewSong, true);
|
||||
}
|
||||
if ui.button("Save").clicked() {
|
||||
handle_error_ui!(state.manifest.save());
|
||||
ui.close_menu();
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::path::Path;
|
||||
use std::time::{Duration, Instant};
|
||||
use anyhow::anyhow;
|
||||
use xmpd_manifest::{store::JsonStore, Manifest};
|
||||
|
||||
#[macro_use]
|
||||
@@ -14,15 +16,20 @@ const W_NAME: &str = "xmpd v2.0.0a";
|
||||
type Result<T> = anyhow::Result<T>;
|
||||
|
||||
pub fn start() -> Result<()> {
|
||||
let cache_rx = xmpd_cache::Cache::get()?.init()?;
|
||||
let manifest_p = xmpd_settings::Settings::get()?.cache_settings.manifest_path.clone().into_std_path_buf();
|
||||
let cache_rx = xmpd_cache::Cache::get()
|
||||
.map_err(|e| anyhow!("Failed to get cache: {e}"))?
|
||||
.init()
|
||||
.map_err(|e| anyhow!("Failed to init cache: {e}"))?;
|
||||
|
||||
let options = eframe::NativeOptions::default();
|
||||
let mut state = GuiState::new()?;
|
||||
let mut state = GuiState::new(&manifest_p)?;
|
||||
let res = eframe::run_simple_native(W_NAME, options, move |ctx, _frame| {
|
||||
#[cfg(debug_assertions)]
|
||||
let f_start = Instant::now();
|
||||
|
||||
egui_extras::install_image_loaders(ctx);
|
||||
windows::Windows::draw_all(ctx, &mut state);
|
||||
windows::Windows::draw_all(ctx, &mut state);
|
||||
handle_error_ui!(main_window::draw(ctx, &mut state, &cache_rx));
|
||||
ctx.request_repaint_after(Duration::from_millis(500));
|
||||
|
||||
@@ -54,22 +61,22 @@ pub struct GuiState {
|
||||
|
||||
impl GuiState {
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(manifest_p: &Path) -> Result<Self> {
|
||||
Ok(Self {
|
||||
debug_info: DebugInfo {
|
||||
last_frame_time: Default::default()
|
||||
},
|
||||
player: xmpd_player::Player::new(),
|
||||
manifest: Manifest::new(&xmpd_cliargs::CLIARGS.manifest_path())?,
|
||||
manifest: Manifest::new(manifest_p)?,
|
||||
windows: windows::Windows::new(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(manifest_p: &Path) -> Result<Self> {
|
||||
Ok(Self {
|
||||
player: xmpd_player::Player::new(),
|
||||
manifest: Manifest::new(&xmpd_cliargs::CLIARGS.manifest_path())?,
|
||||
manifest: Manifest::new(manifest_p)?,
|
||||
windows: windows::Windows::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use egui::{RichText, TextEdit};
|
||||
use egui::{RichText, Sense, TextEdit, TopBottomPanel};
|
||||
use xmpd_cache::DlStatus;
|
||||
use xmpd_manifest::store::{BaseStore, StoreExtras};
|
||||
use xmpd_manifest::{song::Song, store::{BaseStore, StoreExtras}};
|
||||
|
||||
use crate::{components::{CompGetter, toast::{Toast, ToastType}}, windows::WindowId};
|
||||
|
||||
use super::Window;
|
||||
|
||||
@@ -8,6 +10,7 @@ use super::Window;
|
||||
#[derive(Debug, Default)]
|
||||
pub struct AddSongW {
|
||||
sid: uuid::Uuid,
|
||||
pid: Option<uuid::Uuid>,
|
||||
}
|
||||
|
||||
impl Window for AddSongW {
|
||||
@@ -18,6 +21,8 @@ impl Window for AddSongW {
|
||||
"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();
|
||||
@@ -61,7 +66,7 @@ impl Window for AddSongW {
|
||||
.show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
for (sid, song) in songs {
|
||||
ui.group(|ui| {
|
||||
let resp = ui.group(|ui| {
|
||||
let avail = ui.available_size();
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_width(avail.x);
|
||||
@@ -87,13 +92,62 @@ impl Window for AddSongW {
|
||||
});
|
||||
});
|
||||
});
|
||||
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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ impl Window for DebugW {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugW {
|
||||
|
||||
@@ -17,4 +17,7 @@ impl Window for ErrorW {
|
||||
ui.label("Hello from other window!");
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ use egui::{ViewportBuilder, ViewportId};
|
||||
use crate::GuiState;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
mod debug;
|
||||
mod error;
|
||||
mod settings;
|
||||
mod add_song;
|
||||
mod new_song;
|
||||
mod new_playlist;
|
||||
pub mod debug;
|
||||
pub mod error;
|
||||
pub mod settings;
|
||||
pub mod add_song;
|
||||
pub mod new_song;
|
||||
pub mod new_playlist;
|
||||
|
||||
lazy_static::lazy_static!(
|
||||
static ref WINDOWS: Arc<Mutex<HashMap<WindowId, Box<dyn Window>>>> = Arc::new(Mutex::new(HashMap::new()));
|
||||
pub static ref WINDOWS: Arc<Mutex<HashMap<WindowId, Box<dyn Window>>>> = Arc::new(Mutex::new(HashMap::new()));
|
||||
static ref OPEN_WINDOWS: Arc<Mutex<HashSet<WindowId>>> = Arc::new(Mutex::new(HashSet::new()));
|
||||
);
|
||||
|
||||
@@ -22,6 +22,7 @@ pub trait Window: std::fmt::Debug + Send {
|
||||
fn close(&self) where Self: Sized{
|
||||
OPEN_WINDOWS.lock().unwrap().remove(&Self::id());
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Ord, Eq)]
|
||||
@@ -104,4 +105,10 @@ impl Windows {
|
||||
pub fn is_open(&self, id: &WindowId) -> bool {
|
||||
OPEN_WINDOWS.lock().unwrap().contains(&id)
|
||||
}
|
||||
|
||||
pub fn set_value(&self, id: &WindowId, k: impl ToString, v: impl ToString) -> crate::Result<()> {
|
||||
// WINDOWS.lock().unwrap().get_mut(&win_id).unwrap().set_value();
|
||||
//
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,4 +99,7 @@ impl Window for NewPlaylistW {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use egui::{Sense, Vec2};
|
||||
use xmpd_manifest::{song::{Song, SourceType}, store::BaseStore};
|
||||
|
||||
use crate::{components::{CompGetter, toast::{Toast, ToastType}}, windows::WindowId};
|
||||
|
||||
use super::Window;
|
||||
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct NewSongW {
|
||||
|
||||
name: String,
|
||||
author: String,
|
||||
source_t: SourceType,
|
||||
source_url: String,
|
||||
source_url_old: String,
|
||||
}
|
||||
|
||||
impl Window for NewSongW {
|
||||
@@ -13,8 +24,113 @@ impl Window for NewSongW {
|
||||
fn default_title() -> &'static str where Self: Sized {
|
||||
"New Song"
|
||||
}
|
||||
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
|
||||
ui.label("Hello from other window!");
|
||||
fn draw(&mut self, ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
||||
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
||||
let img_size = 64.0;
|
||||
let img_spacing = 10.0;
|
||||
ui.vertical(|ui| {
|
||||
let mut rect = egui::Rect::ZERO;
|
||||
rect.set_width(img_size);
|
||||
rect.set_height(img_size);
|
||||
rect.set_top(img_spacing);
|
||||
rect.set_left(img_spacing);
|
||||
let rect_int = ui.interact(rect, "new_playlist_w".into(), Sense::click());
|
||||
if rect_int.hovered() {
|
||||
ui.allocate_ui_at_rect(rect, |ui| {
|
||||
ui.group(|ui| {
|
||||
let img = egui::Image::new(crate::data::PLUS_ICON)
|
||||
.tint(theme.accent_color)
|
||||
.fit_to_exact_size(Vec2::new(img_size, img_size));
|
||||
//.paint_at(ui, rect);
|
||||
ui.add(img);
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
ui.allocate_ui_at_rect(rect, |ui| {
|
||||
ui.group(|ui| {
|
||||
let img = egui::Image::new(crate::data::NOTE_ICON)
|
||||
.tint(theme.accent_color)
|
||||
.fit_to_exact_size(Vec2::new(img_size, img_size));
|
||||
//.paint_at(ui, rect);
|
||||
ui.add(img);
|
||||
});
|
||||
});
|
||||
}
|
||||
if rect_int.clicked() {
|
||||
// TODO: Add a way to add custom icons
|
||||
Toast::get().unwrap().show_toast("Not Implemented", "Adding icons to songs is not implemented", ToastType::Error);
|
||||
}
|
||||
ui.add_space(img_spacing);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Name: ");
|
||||
ui.text_edit_singleline(&mut self.name);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Author: ");
|
||||
ui.text_edit_singleline(&mut self.author);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Source Type: ");
|
||||
egui::ComboBox::new("new_song_song_t_sel", "")
|
||||
.selected_text(self.source_t.to_string())
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut self.source_t, SourceType::Youtube, SourceType::Youtube.to_string());
|
||||
ui.selectable_value(&mut self.source_t, SourceType::Spotify, SourceType::Spotify.to_string());
|
||||
ui.selectable_value(&mut self.source_t, SourceType::Soundcloud, SourceType::Soundcloud.to_string());
|
||||
//ui.selectable_value(&mut self.source_t, SourceType::HttpBare, SourceType::HttpBare.to_string());
|
||||
//ui.selectable_value(&mut self.source_t, SourceType::HttpZip, SourceType::HttpZip.to_string());
|
||||
//ui.selectable_value(&mut self.source_t, SourceType::Http7z, SourceType::Http7z.to_string());
|
||||
}
|
||||
);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Source URL: ");
|
||||
ui.text_edit_singleline(&mut self.source_url);
|
||||
if self.source_url != self.source_url_old {
|
||||
if let Some(t) = SourceType::from_url(&handle_error_ui!(url::Url::from_str(&self.source_url))) {
|
||||
self.source_t = t;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Max), |ui| {
|
||||
ui.add_space(3.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(3.0);
|
||||
if ui.button("Close").clicked() {
|
||||
self.author = String::from("New Song");
|
||||
self.name = String::from("Unknown");
|
||||
self.source_t = SourceType::Youtube;
|
||||
self.source_url = String::default();
|
||||
state.windows.toggle(&WindowId::NewSong, false);
|
||||
}
|
||||
|
||||
if ui.button("Add").clicked() {
|
||||
let mut s = handle_error_ui!(Song::new_from_str(&self.source_url, self.source_t));
|
||||
s.set_name(&self.name);
|
||||
s.set_author(&self.author);
|
||||
state.manifest.store_mut().get_songs_mut().insert(uuid::Uuid::new_v4(), s);
|
||||
|
||||
self.author = String::from("New Song");
|
||||
self.name = String::from("Unknown");
|
||||
self.source_t = SourceType::Youtube;
|
||||
self.source_url = String::default();
|
||||
}
|
||||
|
||||
if ui.button("Cancel").clicked() {
|
||||
self.author = String::from("New Song");
|
||||
self.name = String::from("Unknown");
|
||||
self.source_t = SourceType::Youtube;
|
||||
self.source_url = String::default();
|
||||
state.windows.toggle(&WindowId::NewSong, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, _: String, _: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,9 @@ impl Window for SettingsW {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl SettingsW {
|
||||
|
||||
Reference in New Issue
Block a user