Added highlighting, right click menu, other fixes

This commit is contained in:
Gvidas Juknevičius 2024-09-17 00:06:53 +03:00
parent 776a88c4cf
commit 7d6d560d2b
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
9 changed files with 1021 additions and 603 deletions

371
Cargo.lock generated
View File

@ -63,7 +63,7 @@ dependencies = [
"futures-lite 1.13.0",
"once_cell",
"serde",
"zbus",
"zbus 3.15.2",
]
[[package]]
@ -297,6 +297,18 @@ dependencies = [
"futures-core",
]
[[package]]
name = "async-broadcast"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20cd0e2e25ea8e5f7e9df04578dc6cf5c83577fd09b1a46aaf5c85e1c33f2a7e"
dependencies = [
"event-listener 5.3.1",
"event-listener-strategy",
"futures-core",
"pin-project-lite",
]
[[package]]
name = "async-channel"
version = "2.3.1"
@ -334,6 +346,17 @@ dependencies = [
"futures-lite 1.13.0",
]
[[package]]
name = "async-fs"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebcd09b382f40fcd159c2d695175b2ae620ffa5f3bd6f664131efff4e8b9e04a"
dependencies = [
"async-lock 3.4.0",
"blocking",
"futures-lite 2.3.0",
]
[[package]]
name = "async-io"
version = "1.13.0"
@ -416,6 +439,25 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "async-process"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63255f1dc2381611000436537bbedfe83183faa303a5a0edaf191edef06526bb"
dependencies = [
"async-channel",
"async-io 2.3.4",
"async-lock 3.4.0",
"async-signal",
"async-task",
"blocking",
"cfg-if",
"event-listener 5.3.1",
"futures-lite 2.3.0",
"rustix 0.38.37",
"tracing",
]
[[package]]
name = "async-recursion"
version = "1.1.1"
@ -488,9 +530,9 @@ dependencies = [
"enumflags2",
"serde",
"static_assertions",
"zbus",
"zbus_names",
"zvariant",
"zbus 3.15.2",
"zbus_names 2.6.1",
"zvariant 3.15.2",
]
[[package]]
@ -502,7 +544,7 @@ dependencies = [
"atspi-common",
"atspi-proxies",
"futures-lite 1.13.0",
"zbus",
"zbus 3.15.2",
]
[[package]]
@ -513,7 +555,7 @@ checksum = "6495661273703e7a229356dcbe8c8f38223d697aacfaf0e13590a9ac9977bb52"
dependencies = [
"atspi-common",
"serde",
"zbus",
"zbus 3.15.2",
]
[[package]]
@ -797,6 +839,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "cgl"
version = "0.3.2"
@ -1084,6 +1132,27 @@ dependencies = [
"subtle",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "dispatch"
version = "0.2.0"
@ -1255,6 +1324,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "endi"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
[[package]]
name = "enum-map"
version = "2.7.3"
@ -1683,7 +1758,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fcd4ae4e86d991ad1300b8f57166e5be0c95ef1f63f3f5b827f8a164548746"
dependencies = [
"bitflags 2.6.0",
"cfg_aliases",
"cfg_aliases 0.1.1",
"cgl",
"core-foundation",
"dispatch",
@ -1706,7 +1781,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebcdfba24f73b8412c5181e56f092b5eff16671c514ce896b258a0a64bd7735"
dependencies = [
"cfg_aliases",
"cfg_aliases 0.1.1",
"glutin",
"raw-window-handle 0.5.2",
"winit",
@ -2083,6 +2158,25 @@ version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4"
[[package]]
name = "is-docker"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
dependencies = [
"once_cell",
]
[[package]]
name = "is-wsl"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
dependencies = [
"is-docker",
"once_cell",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
@ -2195,6 +2289,16 @@ dependencies = [
"redox_syscall 0.4.1",
]
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.6.0",
"libc",
]
[[package]]
name = "linux-raw-sys"
version = "0.3.8"
@ -2229,6 +2333,19 @@ version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "mac-notification-sys"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dce8f34f3717aa37177e723df6c1fc5fb02b2a1087374ea3fe0ea42316dc8f91"
dependencies = [
"cc",
"dirs-next",
"objc-foundation",
"objc_id",
"time",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -2254,6 +2371,8 @@ dependencies = [
"lazy_static",
"libc",
"log",
"notify-rust",
"open",
"reqwest",
"serde",
"serde_json",
@ -2438,12 +2557,38 @@ dependencies = [
"memoffset 0.7.1",
]
[[package]]
name = "nix"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
dependencies = [
"bitflags 2.6.0",
"cfg-if",
"cfg_aliases 0.2.1",
"libc",
"memoffset 0.9.1",
]
[[package]]
name = "nohash-hasher"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "notify-rust"
version = "4.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5134a72dc570b178bff81b01e81ab14a6fcc015391ed4b3b14853090658cd3a3"
dependencies = [
"log",
"mac-notification-sys",
"serde",
"tauri-winrt-notification",
"zbus 4.4.0",
]
[[package]]
name = "num-conv"
version = "0.1.0"
@ -2490,6 +2635,17 @@ dependencies = [
"objc_exception",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc-sys"
version = "0.2.0-beta.2"
@ -2640,6 +2796,15 @@ dependencies = [
"cc",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.36.4"
@ -2655,6 +2820,17 @@ version = "1.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe"
[[package]]
name = "open"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a877bf6abd716642a53ef1b89fb498923a4afca5c754f9050b4d081c05c4b3"
dependencies = [
"is-wsl",
"libc",
"pathdiff",
]
[[package]]
name = "openssl"
version = "0.10.66"
@ -2705,7 +2881,7 @@ version = "0.3.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52f0d54bde9774d3a51dcf281a5def240c71996bc6ca05d2c847ec8b2b216166"
dependencies = [
"libredox",
"libredox 0.0.2",
]
[[package]]
@ -2773,6 +2949,12 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "pbkdf2"
version = "0.11.0"
@ -2939,6 +3121,15 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d84d1d7a6ac92673717f9f6d1518374ef257669c24ebc5ac25d5033828be58"
[[package]]
name = "quick-xml"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
dependencies = [
"memchr",
]
[[package]]
name = "quick-xml"
version = "0.36.1"
@ -3026,6 +3217,17 @@ dependencies = [
"bitflags 2.6.0",
]
[[package]]
name = "redox_users"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom",
"libredox 0.1.3",
"thiserror",
]
[[package]]
name = "regex"
version = "1.10.6"
@ -3573,6 +3775,17 @@ dependencies = [
"libc",
]
[[package]]
name = "tauri-winrt-notification"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f89f5fb70d6f62381f5d9b2ba9008196150b40b75f3068eb24faeddf1c686871"
dependencies = [
"quick-xml 0.31.0",
"windows 0.56.0",
"windows-version",
]
[[package]]
name = "tempfile"
version = "3.12.0"
@ -4159,7 +4372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597f2001b2e5fc1121e3d5b9791d3e78f05ba6bfa4641053846248e3a13661c3"
dependencies = [
"proc-macro2",
"quick-xml",
"quick-xml 0.36.1",
"quote",
]
@ -4220,7 +4433,7 @@ checksum = "cbd7311dbd2abcfebaabf1841a2824ed7c8be443a0f29166e5d3c6a53a762c01"
dependencies = [
"arrayvec",
"cfg-if",
"cfg_aliases",
"cfg_aliases 0.1.1",
"js-sys",
"log",
"parking_lot",
@ -4245,7 +4458,7 @@ dependencies = [
"arrayvec",
"bit-vec",
"bitflags 2.6.0",
"cfg_aliases",
"cfg_aliases 0.1.1",
"codespan-reporting",
"indexmap",
"log",
@ -4272,7 +4485,7 @@ dependencies = [
"arrayvec",
"ash",
"bitflags 2.6.0",
"cfg_aliases",
"cfg_aliases 0.1.1",
"core-graphics-types",
"glow",
"glutin_wgl_sys",
@ -4568,6 +4781,15 @@ dependencies = [
"windows_x86_64_msvc 0.52.6",
]
[[package]]
name = "windows-version"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6998aa457c9ba8ff2fb9f13e9d2a930dabcea28f1d0ab94d687d8b3654844515"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
@ -4712,7 +4934,7 @@ dependencies = [
"bitflags 2.6.0",
"bytemuck",
"calloop 0.12.4",
"cfg_aliases",
"cfg_aliases 0.1.1",
"core-foundation",
"core-graphics",
"cursor-icon",
@ -4846,12 +5068,12 @@ version = "3.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "675d170b632a6ad49804c8cf2105d7c31eddd3312555cffd4b740e08e97c25e6"
dependencies = [
"async-broadcast",
"async-broadcast 0.5.1",
"async-executor",
"async-fs",
"async-fs 1.6.0",
"async-io 1.13.0",
"async-lock 2.8.0",
"async-process",
"async-process 1.8.1",
"async-recursion",
"async-task",
"async-trait",
@ -4864,7 +5086,7 @@ dependencies = [
"futures-sink",
"futures-util",
"hex",
"nix",
"nix 0.26.4",
"once_cell",
"ordered-stream",
"rand",
@ -4876,9 +5098,47 @@ dependencies = [
"uds_windows",
"winapi",
"xdg-home",
"zbus_macros",
"zbus_names",
"zvariant",
"zbus_macros 3.15.2",
"zbus_names 2.6.1",
"zvariant 3.15.2",
]
[[package]]
name = "zbus"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb97012beadd29e654708a0fdb4c84bc046f537aecfde2c3ee0a9e4b4d48c725"
dependencies = [
"async-broadcast 0.7.1",
"async-executor",
"async-fs 2.1.2",
"async-io 2.3.4",
"async-lock 3.4.0",
"async-process 2.3.0",
"async-recursion",
"async-task",
"async-trait",
"blocking",
"enumflags2",
"event-listener 5.3.1",
"futures-core",
"futures-sink",
"futures-util",
"hex",
"nix 0.29.0",
"ordered-stream",
"rand",
"serde",
"serde_repr",
"sha1",
"static_assertions",
"tracing",
"uds_windows",
"windows-sys 0.52.0",
"xdg-home",
"zbus_macros 4.4.0",
"zbus_names 3.0.0",
"zvariant 4.2.0",
]
[[package]]
@ -4892,7 +5152,20 @@ dependencies = [
"quote",
"regex",
"syn 1.0.109",
"zvariant_utils",
"zvariant_utils 1.0.1",
]
[[package]]
name = "zbus_macros"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "267db9407081e90bbfa46d841d3cbc60f59c0351838c4bc65199ecd79ab1983e"
dependencies = [
"proc-macro-crate 3.2.0",
"proc-macro2",
"quote",
"syn 2.0.77",
"zvariant_utils 2.1.0",
]
[[package]]
@ -4903,7 +5176,18 @@ checksum = "437d738d3750bed6ca9b8d423ccc7a8eb284f6b1d6d4e225a0e4e6258d864c8d"
dependencies = [
"serde",
"static_assertions",
"zvariant",
"zvariant 3.15.2",
]
[[package]]
name = "zbus_names"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c"
dependencies = [
"serde",
"static_assertions",
"zvariant 4.2.0",
]
[[package]]
@ -5002,7 +5286,20 @@ dependencies = [
"libc",
"serde",
"static_assertions",
"zvariant_derive",
"zvariant_derive 3.15.2",
]
[[package]]
name = "zvariant"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe"
dependencies = [
"endi",
"enumflags2",
"serde",
"static_assertions",
"zvariant_derive 4.2.0",
]
[[package]]
@ -5015,7 +5312,20 @@ dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
"zvariant_utils",
"zvariant_utils 1.0.1",
]
[[package]]
name = "zvariant_derive"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73e2ba546bda683a90652bac4a279bc146adad1386f25379cf73200d2002c449"
dependencies = [
"proc-macro-crate 3.2.0",
"proc-macro2",
"quote",
"syn 2.0.77",
"zvariant_utils 2.1.0",
]
[[package]]
@ -5028,3 +5338,14 @@ dependencies = [
"quote",
"syn 1.0.109",
]
[[package]]
name = "zvariant_utils"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
]

View File

@ -18,6 +18,8 @@ futures = "0.3.30"
lazy_static = "1.4.0"
libc = "0.2.153"
log = "0.4.21"
notify-rust = "4.11.3"
open = "5.3.0"
reqwest = "0.12.3"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"

File diff suppressed because it is too large Load Diff

View File

@ -2,15 +2,16 @@ mod nav_bar;
mod song_edit_window;
use egui::{Color32, Label, Sense};
use std::collections::HashSet;
use egui::{Button, Color32, Label, RichText, Sense};
use egui_extras::{Column, TableBuilder};
use song_edit_window::{GuiError, GuiImportPlaylist, GuiNewSong};
use crate::{config::{Config, ConfigWrapper}, downloader::Downloader, manifest::{song::SongType, Manifest}};
use crate::{config::{Config, ConfigWrapper}, downloader::Downloader, manifest::{song::{Song, SongType}, Manifest}};
use self::song_edit_window::GuiSongEditor;
#[derive(Debug, Default)]
pub struct Gui {
manifest: Manifest,
@ -20,14 +21,14 @@ pub struct Gui {
error_w: GuiError,
filter: String,
downloader: Downloader,
cfg: ConfigWrapper
cfg: ConfigWrapper,
downloading: bool,
}
impl Gui {
fn new(_: &eframe::CreationContext<'_>, manifest: Manifest, downloader: Downloader, cfg: ConfigWrapper) -> Self {
Self {
manifest,
filter: String::new(),
downloader,
cfg,
..Default::default()
@ -93,7 +94,7 @@ impl eframe::App for Gui {
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.colored_label(Color32::BLUE, "Filter: ");
ui.colored_label(Color32::from_hex("#4444aa").unwrap(), "Filter: ");
ui.text_edit_singleline(&mut self.filter);
});
});
@ -104,7 +105,7 @@ impl eframe::App for Gui {
.striped(true)
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
.resizable(true)
.column(Column::auto())
//.column(Column::auto())
.column(Column::auto())
//.column(
// Column::remainder()
@ -132,7 +133,7 @@ impl eframe::App for Gui {
};
table.header(20.0, |mut header| {
header.col(|_|{});
// header.col(|_|{});
header.col(|ui| {
ui.strong("Playlist");
});
@ -161,31 +162,83 @@ impl eframe::App for Gui {
continue;
}
}
body.row(18.0, |mut row| {
row.col(|ui| {
if ui.add(Label::new("[edit]").sense(Sense::click())).clicked() {
self.song_edit_w.song = (
ui.label(pname.clone())
.context_menu(|ui| context_menu(self, ui, &pname, &sname, &s));
});
row.col(|ui| {
let color =
match s.get_type() {
SongType::Youtube => Color32::from_hex("#FF0000").unwrap(),
SongType::Spotify => Color32::from_hex("#1db954").unwrap(),
SongType::Soundcloud => Color32::from_hex("#F26F23").unwrap()
};
ui.colored_label(color, s.get_type().to_string())
.context_menu(|ui| context_menu(self, ui, &pname, &sname, &s));
});
row.col(|ui| {
ui.hyperlink_to(sname.clone(), s.get_url_str())
.context_menu(|ui| context_menu(self, ui, &pname, &sname, &s));
});
row.response()
.context_menu(|ui| context_menu(self, ui, &pname, &sname, &s));
fn context_menu(this: &mut Gui, ui: &mut egui::Ui, pname: &String, sname: &String, song: &Song) {
if ui.button("Edit").clicked() {
this.song_edit_w.song = (
pname.clone(),
sname.clone(),
);
log::debug!("Label pressed");
self.song_edit_w.is_open = true;
self.song_edit_w.ed_name = sname.clone();
self.song_edit_w.ed_url = s.get_url_str().clone();
this.song_edit_w.is_open = true;
this.song_edit_w.ed_name = sname.clone();
this.song_edit_w.ed_url = song.get_url_str().clone();
ui.close_menu()
}
});
row.col(|ui| {
ui.label(pname.clone());
});
row.col(|ui| {
ui.label(s.get_type().to_string());
});
row.col(|ui| {
ui.hyperlink_to(sname.clone(), s.get_url_str());
});
if ui.button("Download").clicked() {
if let Err(e) = this.downloader.download_song_nb(&this.cfg, pname, sname, song, this.manifest.get_format()) {
log::error!("{e}");
this.throw_error(format!("Failed to download song {sname}: {e}"));
}
ui.close_menu()
}
if ui.button("Open Source").clicked() {
if let Err(e) = open::that(song.get_url_str()) {
log::error!("{e}");
this.throw_error(format!("Failed to open song source: {e}"));
}
ui.close_menu()
}
if ui.button("Play").clicked() {
let p = crate::util::get_song_path(pname, sname, this.manifest.get_format());
if !p.exists() {
this.throw_error(format!("Song does not exist on disk"));
} else if let Err(e) = open::that(p) {
log::error!("{e}");
this.throw_error(format!("Failed to play song: {e}"));
}
ui.close_menu()
}
if ui.button("Delete from disk").clicked() {
let p = crate::util::get_song_path(pname, sname, this.manifest.get_format());
if p.exists() {
if let Err(e) = std::fs::remove_file(p) {
this.throw_error(format!("Failed to delete file: {e}"));
}
}
ui.close_menu();
}
if ui.button(RichText::new("Delete").color(Color32::RED)).clicked() {
this.throw_error("TODO");
ui.close_menu()
}
}
})
}
});

View File

@ -46,7 +46,14 @@ impl Gui {
ui.with_layout(egui::Layout::bottom_up(egui::Align::RIGHT), |ui| {
ui.horizontal(|ui| {
if self.downloader.get_songs_left_nb() > 0 {
self.downloading = true;
ui.label(format!("Downloading: {}/{}", self.downloader.get_songs_left_nb(), self.downloader.get_initial_song_count_nb()));
} else if self.downloading {
let _ = notify_rust::Notification::new()
.summary("Done downloading")
.body("Your music has been downloaded")
.show();
self.downloading = false;
}
let _ = self.downloader.download_all_nb_poll(&self.cfg);
egui::widgets::global_dark_light_mode_buttons(ui);

View File

@ -1,5 +1,7 @@
use egui::{Color32, RichText, TextBuffer};
use std::sync::Arc;
use egui::{text::{LayoutJob, TextWrapping}, Color32, Label, RichText, Style, TextBuffer, TextFormat, TextStyle};
use crate::manifest::{playlist::Playlist, song::{Song, SongType}};
@ -97,6 +99,7 @@ impl Gui {
playlist.remove_song(&song_name);
playlist.add_song(self.song_edit_w.ed_name.clone(), song);
self.song_edit_w.is_open = false;
let _ = self.manifest.save(None);
}
}
@ -125,7 +128,7 @@ impl Gui {
ui.horizontal(|ui| {
ui.label("Playlist: ");
egui::ComboBox::from_id_source("new_song_window_playlist")
.selected_text(format!("{}", self.new_song_w.ed_playlist.clone().unwrap()))
.selected_text(format!("{}", self.new_song_w.ed_playlist.clone().unwrap_or("".to_string())))
.show_ui(ui, |ui| {
for p in self.manifest.get_playlists().keys() {
ui.selectable_value(&mut self.new_song_w.ed_playlist, Option::Some(p.clone()), p.as_str());
@ -212,8 +215,7 @@ impl Gui {
ui.vertical(|ui| {
ui.label(RichText::new("Error:").size(30.0).color(Color32::RED));
ui.horizontal(|ui| {
ui.label("Mcmg had an error:");
ui.label(self.error_w.text.clone());
ui.add(Label::new(self.error_w.text.clone()).wrap(true));
})
})
});

View File

@ -37,7 +37,14 @@ impl Downloader {
}
pub fn get_songs_left_nb(&self) -> usize {
self.nb_cache.len()
self.nb_cache.len() + crate::process_manager::proc_count()
}
pub fn download_song_nb(&mut self, cfg: &ConfigWrapper, pname: &String, sname: &String, song: &Song, format: &Format) -> anyhow::Result<()> {
self.nb_cache.push((pname.clone(), sname.clone(), song.clone(), format.clone()));
self.nb_initial_song_count += 1;
self.download_all_nb_poll(cfg)?;
Ok(())
}
pub fn download_all_nb(&mut self, manifest: &Manifest, cfg: &ConfigWrapper) -> anyhow::Result<Option<usize>> {
@ -57,7 +64,7 @@ impl Downloader {
self.download_song(cfg, &sname, &song, &pname, &format)?;
}
}
if self.nb_cache.is_empty() {
if self.get_songs_left_nb() == 0 {
self.nb_initial_song_count = 0;
}
if crate::process_manager::proc_count() == 0 && self.nb_cache.is_empty() {
@ -81,7 +88,8 @@ impl Downloader {
self.count += crate::process_manager::wait_for_procs_untill(0)?;
Ok(self.count)
}
#[allow(dead_code)]
pub fn download_playlist(&mut self, cfg: &ConfigWrapper, url: &String, pname: &String, format: &Format) -> anyhow::Result<usize> {
self.download_playlist_nb(cfg, url, pname, format)?;
let mut count = 0;
@ -126,7 +134,7 @@ impl Downloader {
pub fn download_song(&mut self, cfg: &ConfigWrapper, name: &String, song: &Song, playlist: &String, format: &Format) -> anyhow::Result<()> {
let dl_dir = format!("{}/{playlist}", cfg.cli.output);
let dl_file = format!("{dl_dir}/{}.{}", name, &format);
log::debug!("Checking: {dl_file}");
if PathBuf::from(&dl_file).exists() {
log::debug!("File {dl_file} exists, skipping");
return Ok(())

View File

@ -64,6 +64,7 @@ impl Song {
impl TryFrom<url::Url> for SongType {
type Error = anyhow::Error;

View File

@ -1,6 +1,6 @@
use std::path::PathBuf;
use std::{any::Any, path::PathBuf};
use crate::constants;
use crate::{constants, manifest::Format};
pub(crate) fn is_supported_host(url: url::Url) -> bool {
let host = url.host_str();
@ -52,6 +52,11 @@ pub(crate) fn isatty() -> bool {
}
}
pub fn as_any_mut<T: Any>(val: &mut T) -> &mut dyn Any {
val as &mut dyn Any
}
// pub async fn dl_to_file(url: &str, p: PathBuf) -> anyhow::Result<()> {
// log::info!("Downloading {} -> {:?}", url, p);
// let ytdlp_req = reqwest::get(url).await?.bytes().await?;
@ -60,4 +65,23 @@ pub(crate) fn isatty() -> bool {
// fd.write(&ytdlp_req)?;
// log::debug!("Finished writing {:?}", p);
// Ok(())
// }
// }
pub fn get_song_path/*<P: TryInto<PathBuf>>*/(/*basepath: Option<P>,*/ pname: &String, sname: &String, format: &Format) -> PathBuf {
// let mut path: PathBuf;
/*if let Some(bp) = basepath {
if let Ok(bp) = bp.try_into() {
path = bp;
} else {
path = std::env::current_dir().unwrap_or(PathBuf::new());
}
} else {*/
let mut path = std::env::current_dir().unwrap_or(PathBuf::new());
//}
// TODO: Get this from cfg
path.push("out");
path.push(pname);
path.push(sname);
path.set_extension(format.to_string());
path
}