107 lines
4.1 KiB
Rust
107 lines
4.1 KiB
Rust
use std::str::FromStr;
|
|
|
|
use super::Window;
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct SettingsW {
|
|
ytdlp_p: String,
|
|
spotdl_p: String,
|
|
ffmpeg_p: String,
|
|
song_fmt: String,
|
|
}
|
|
|
|
impl Default for SettingsW {
|
|
fn default() -> Self {
|
|
let tooling = xmpd_settings::Settings::get().unwrap().tooling.clone();
|
|
Self {
|
|
ytdlp_p: tooling.ytdlp_path.to_string(),
|
|
spotdl_p: tooling.spotdl_path.to_string(),
|
|
ffmpeg_p: tooling.ffmpeg_path.to_string(),
|
|
song_fmt: tooling.song_format
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl Window for SettingsW {
|
|
fn id() -> super::WindowId where Self: Sized {
|
|
super::WindowId::Settings
|
|
}
|
|
fn default_title() -> &'static str where Self: Sized {
|
|
"Settings"
|
|
}
|
|
#[allow(irrefutable_let_patterns)]
|
|
fn draw(&mut self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
|
|
ui.group(|ui| {
|
|
ui.vertical(|ui| {
|
|
ui.horizontal(|ui| {
|
|
{
|
|
let theme = &mut handle_error_ui!(xmpd_settings::Settings::get()).theme;
|
|
ui.group(|ui| {
|
|
ui.vertical(|ui| {
|
|
ui.heading("Theme");
|
|
Self::add_theme_button(&mut theme.accent_color, ui, "Accent");
|
|
Self::add_theme_button(&mut theme.primary_bg_color, ui, "Primary BG");
|
|
Self::add_theme_button(&mut theme.secondary_bg_color, ui, "Secondary BG");
|
|
Self::add_theme_button(&mut theme.text_color, ui, "Text");
|
|
Self::add_theme_button(&mut theme.dim_text_color, ui, "Dim Text");
|
|
if ui.button("Reset").clicked() {
|
|
*theme = xmpd_settings::theme::Theme::default();
|
|
}
|
|
});
|
|
});
|
|
|
|
}
|
|
{
|
|
ui.group(|ui| {
|
|
ui.vertical(|ui| {
|
|
ui.heading("Tooling paths");
|
|
Self::add_tooling_input(&mut self.ytdlp_p, ui, "stdlp");
|
|
Self::add_tooling_input(&mut self.spotdl_p, ui, "spotdl");
|
|
Self::add_tooling_input(&mut self.ffmpeg_p, ui, "ffmpeg");
|
|
Self::add_tooling_input(&mut self.song_fmt, ui, "Format");
|
|
});
|
|
});
|
|
}
|
|
});
|
|
ui.with_layout(egui::Layout::bottom_up(egui::Align::RIGHT), |ui| {
|
|
if ui.button("Save").clicked() {
|
|
let mut settings = handle_error_ui!(xmpd_settings::Settings::get());
|
|
if let Ok(p) = camino::Utf8PathBuf::from_str(&self.ytdlp_p) {
|
|
settings.tooling.ytdlp_path = p;
|
|
}
|
|
if let Ok(p) = camino::Utf8PathBuf::from_str(&self.spotdl_p) {
|
|
settings.tooling.spotdl_path = p;
|
|
}
|
|
if let Ok(p) = camino::Utf8PathBuf::from_str(&self.ffmpeg_p) {
|
|
settings.tooling.ffmpeg_path = p;
|
|
}
|
|
settings.tooling.song_format.clone_from(&self.song_fmt);
|
|
handle_error_ui!(settings.save(None));
|
|
}
|
|
});
|
|
});
|
|
});
|
|
Ok(())
|
|
}
|
|
fn set_value<V>(&mut self, k: String, v: Box<V>) where Self: Sized {
|
|
|
|
}
|
|
}
|
|
|
|
impl SettingsW {
|
|
fn add_theme_button(rf: &mut egui::Color32, ui: &mut egui::Ui, name: &str) {
|
|
ui.horizontal(|ui| {
|
|
ui.label(format!("{name}: "));
|
|
ui.color_edit_button_srgba(rf);
|
|
});
|
|
}
|
|
fn add_tooling_input(inp: &mut String, ui: &mut egui::Ui, name: &str) {
|
|
ui.horizontal(|ui|{
|
|
ui.label(format!("{name}: "));
|
|
ui.text_edit_singleline(inp);
|
|
});
|
|
}
|
|
}
|