From dc3a65099d1f83df0aecd7fe1b426fa6a01dea10 Mon Sep 17 00:00:00 2001 From: Tan Kian-ting Date: Sat, 16 Aug 2025 23:25:41 +0800 Subject: [PATCH] fix gui error --- src/main.rs | 70 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 913e9e5..8f4c0fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,16 +49,27 @@ fn main() -> glib::ExitCode { //let mut links = vec!(); - fn download_and_convert(mut links : &Vec<&'static str>, - output_path : &str, + fn download_and_convert(mut links : &Vec<&str>, + output_path : GString, format : OutputFormat, tmp_window_clone : &ApplicationWindow, status_info_label: >k4::Label){ let tmp_window_clone = tmp_window_clone.clone(); let tmp_window_clone2: ApplicationWindow = tmp_window_clone.clone(); + let output_path_clone = output_path.clone(); + let mut output_path_clone = Box::new(output_path.clone()); - fn real_download(output_path: &str, format: OutputFormat, tmp_window_clone: &ApplicationWindow, status_info_label: >k4::Label, lnk: String, is_processed: bool) { - let output_format = match format { + fn real_download(output_path: &str, + format: OutputFormat, + tmp_window_clone: &ApplicationWindow, + status_info_label: >k4::Label, + lnk: String, + is_processed: bool) { + + + println!("Lnk: {}", lnk); + + let output_format = match format { OutputFormat::FLAC => "flac", OutputFormat::MP3 => "mp3", OutputFormat::OGG => "vorbis", @@ -73,6 +84,8 @@ fn main() -> glib::ExitCode { .arg("--audio-format") .arg(output_format) .output(); + + println!("{:?} {}", res, lnk); match res { Ok(_) => status_info_label.set_text(format!("\"{}\" downloaded!", &lnk).as_str()), @@ -115,6 +128,11 @@ fn main() -> glib::ExitCode { } let mut links = links.clone(); + println!("{:?}", links); + + + + for lnk in links.iter_mut(){ let re = Regex::new(r"list=").unwrap(); @@ -123,9 +141,10 @@ fn main() -> glib::ExitCode { let mut is_processed = true; let format_clone = format.clone(); - let lnk_clone = lnk.clone(); + let lnk_clone = Box::leak(Box::new(lnk.clone())); + match capturing{ - None =>{is_processed = true; real_download(output_path.clone(), format_clone, &tmp_window_clone, status_info_label, lnk.to_string(), is_processed);}, + None =>{is_processed = true; real_download(&output_path.clone(), format_clone, &tmp_window_clone, status_info_label, lnk.to_string(), is_processed);}, Some(v) => { is_processed = false; let dialog = gtk::AlertDialog::builder() @@ -140,11 +159,18 @@ fn main() -> glib::ExitCode { + let tmp_window_clone3 = tmp_window_clone2.clone(); + let status_info_label = status_info_label.clone(); + let lnk_clone_s = lnk_clone.to_string().clone(); + let output_path_clone2 = output_path_clone.clone(); dialog.choose(Some(&tmp_window_clone), gio::Cancellable::NONE, move |result| { if result.is_err() || result.unwrap() != 1 { + let is_processed = true; println!("continue"); - let output_path = Box::new(output_path); - real_download(*output_path, format, &tmp_window_clone2, status_info_label, lnk_clone.to_string(), is_processed); + //let output_path = Box::new(output_path); + //let output_path_clone4 = value; + real_download(&output_path_clone2, format, &tmp_window_clone3, &status_info_label, lnk_clone_s, is_processed); + return; }else{ println!("cancel"); is_processed = false; @@ -154,7 +180,7 @@ fn main() -> glib::ExitCode { - } + } } } @@ -300,25 +326,34 @@ fn main() -> glib::ExitCode { let text_buffer2 = text_buffer.clone(); let tmp_window_clone: ApplicationWindow = window.clone(); - let start_iter = text_buffer2.start_iter(); - let end_iter = text_buffer2.end_iter(); + //let start_iter = text_buffer2.start_iter(); + //let end_iter = text_buffer2.end_iter(); //let mut links = text_buffer2.text(&start_iter, &end_iter, true); + let status_info_label_cloned = status_info_label.clone(); convert_button.connect_clicked(move|_|{ + let output_path = path_entry_cloned_for_converting.buffer().text(); + let output_path_cloned = output_path.clone(); + + let start_iter = text_buffer2.start_iter(); + let end_iter = text_buffer2.end_iter(); + let mut links = text_buffer2.text(&start_iter, &end_iter, true); + let mut link_clone = links.clone(); let new_line_pattern = Regex::new(r"(\r?\n)+").expect("invalid regex"); - let mut links = text_buffer2.text(&start_iter, &end_iter, true); - let link_as_str = links.as_str(); + let mut link_vector: Vec<&str> = vec!(); - let link_vector = new_line_pattern.split(link_as_str).collect(); + + let link_as_str = link_clone; //.as_str(); + + link_vector = new_line_pattern.split(&link_as_str).collect(); - if link_vector == [""]{ + if *link_vector == [""]{ show_empty_output_error(Some(&tmp_window_clone)); } - let output_path = path_entry_cloned_for_converting.buffer().text(); let format: OutputFormat; @@ -332,7 +367,8 @@ fn main() -> glib::ExitCode { format = OutputFormat::FLAC; } - download_and_convert(link_vector, output_path.as_str(), + let output_path_str = output_path_cloned; + download_and_convert(&link_vector, output_path_str, format, &tmp_window_clone, &status_info_label_cloned);