adding the save function working and adding to service items better

This commit is contained in:
Chris Cochrun 2023-09-13 13:22:02 -05:00
parent 258949ae50
commit 8031c32a18
2 changed files with 44 additions and 14 deletions

View file

@ -72,7 +72,7 @@ Item {
onEntered: (drag) => {
if (drag.keys[0] === "library") {
dropHighlightLine.visible = true;
var lastItem = serviceItemList.itemAtIndex(ServiceItemModel.rowCount() - 1);
var lastItem = serviceItemList.itemAtIndex(ServiceItemModel.count() - 1);
dropHighlightLine.y = lastItem.y + lastItem.height;
}
}
@ -559,7 +559,7 @@ Item {
ServiceItemModel.insertItem(index, image.title,
type, image.filePath,
"image", "", "",
"", 0, 0, false);
"", 0, 0, false, 0.0, 0.0);
serviceItemList.forceLayout()
return;
}
@ -569,7 +569,7 @@ Item {
ServiceItemModel.insertItem(index, video.title,
type, video.filePath,
"video", "", "",
"", 0, 0, video.loop);
"", 0, 0, video.loop, video.startTime, video.endTime);
serviceItemList.forceLayout()
return;
}
@ -584,7 +584,7 @@ Item {
type, song.background,
song.backgroundType, lyrics,
song.audio, song.font, song.fontSize,
lyrics.length, true);
lyrics.length, true, 0.0, 0.0);
serviceItemList.forceLayout()
return;
}
@ -596,7 +596,7 @@ Item {
ServiceItemModel.insertItem(index, pres.title,
type, pres.filePath,
"image", "",
"", "", 0, pres.pageCount, false);
"", "", 0, pres.pageCount, false, 0.0, 0.0);
serviceItemList.forceLayout()
return;
}
@ -614,7 +614,7 @@ Item {
ServiceItemModel.addItem(image.title,
type, image.filePath,
"image", "", "",
"", 0, 0, false);
"", 0, 0, false, 0.0, 0.0);
serviceItemList.forceLayout()
return;
}
@ -624,7 +624,7 @@ Item {
ServiceItemModel.addItem(video.title,
type, video.filePath,
"video", "", "",
"", 0, 0, video.loop);
"", 0, 0, video.loop, video.startTime, video.endTime);
serviceItemList.forceLayout()
return;
}
@ -638,7 +638,7 @@ Item {
type, song.background,
song.backgroundType, lyrics,
song.audio, song.font, song.fontSize,
lyrics.length, true);
lyrics.length, true, 0.0, 0.0);
serviceItemList.forceLayout()
return;
}
@ -651,7 +651,7 @@ Item {
type, pres.filePath,
"image", "",
"", "", 0, pres.pageCount,
false);
false, 0.0, 0.0);
serviceItemList.forceLayout()
return;
}

View file

@ -487,9 +487,9 @@ mod service_item_model {
}
#[qinvokable]
pub fn save(mut self: Pin<&mut Self>, file: QUrl) -> bool {
println!("file is: {file}");
let lfr = fs::File::open(
file.to_local_file().unwrap_or_default().to_string(),
println!("rust-save-file: {file}");
let lfr = fs::File::create(
&file.to_local_file().unwrap_or_default().to_string(),
);
if let Ok(lf) = &lfr {
println!("archive: {:?}", lf);
@ -502,8 +502,36 @@ mod service_item_model {
let text_list = QList_QString::from(&item.text);
let mut text_vec = Vec::<String>::default();
let flat_background = item.background.to_string();
let flat_audio = item.audio.to_string();
let flat_background_path =
PathBuf::from(item.background.to_string());
let flat_background_name =
flat_background_path.file_name();
let flat_background;
match flat_background_name {
Some(name) => {
flat_background = name.to_str().unwrap()
}
_ => {
println!(
"save-background: no background"
);
flat_background = "";
}
}
let flat_audio_path =
PathBuf::from(item.audio.to_string());
let flat_audio_name = flat_audio_path.file_name();
let flat_audio;
match flat_audio_name {
Some(name) => {
flat_audio = name.to_str().unwrap()
}
_ => {
println!("save-audio: no audio");
flat_audio = "";
}
}
for (index, line) in text_list.iter().enumerate()
{
@ -522,9 +550,11 @@ mod service_item_model {
"loop".to_owned(): Value::from(item.looping),
"slideNumber".to_owned(): Value::from(item.slide_count),
"text".to_owned(): Value::from(text_vec)});
println!("{service_json}");
}
true
} else {
println!("rust-save-file-failed: {:?}", lfr);
false
}
}