fix gui error
This commit is contained in:
parent
86ffdd03d1
commit
dc3a65099d
1 changed files with 53 additions and 17 deletions
68
src/main.rs
68
src/main.rs
|
@ -49,15 +49,26 @@ 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) {
|
||||
|
||||
|
||||
println!("Lnk: {}", lnk);
|
||||
|
||||
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 {
|
||||
OutputFormat::FLAC => "flac",
|
||||
OutputFormat::MP3 => "mp3",
|
||||
|
@ -74,6 +85,8 @@ fn main() -> glib::ExitCode {
|
|||
.arg(output_format)
|
||||
.output();
|
||||
|
||||
println!("{:?} {}", res, lnk);
|
||||
|
||||
match res {
|
||||
Ok(_) => status_info_label.set_text(format!("\"{}\" downloaded!", &lnk).as_str()),
|
||||
Err(masg) => {
|
||||
|
@ -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;
|
||||
|
@ -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 link_vector = new_line_pattern.split(link_as_str).collect();
|
||||
let mut link_vector: Vec<&str> = vec!();
|
||||
|
||||
|
||||
if link_vector == [""]{
|
||||
let link_as_str = link_clone; //.as_str();
|
||||
|
||||
link_vector = new_line_pattern.split(&link_as_str).collect();
|
||||
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue