adding SlideType to slide_model

This commit is contained in:
Chris Cochrun 2024-09-27 06:12:41 -05:00
parent faae0f0186
commit 836c997e97
2 changed files with 17 additions and 18 deletions

View file

@ -214,7 +214,7 @@ pub mod slide_model {
} }
} }
use crate::ffmpeg; use crate::{ffmpeg, slide_types::SlideType};
use crate::obs::Obs; use crate::obs::Obs;
use crate::slide_model::slide_model::QList_QString; use crate::slide_model::slide_model::QList_QString;
use cxx_qt::{CxxQtType, Threading}; use cxx_qt::{CxxQtType, Threading};
@ -222,7 +222,6 @@ use cxx_qt_lib::{
CaseSensitivity, QByteArray, QModelIndex, QString, QStringList, QVariant CaseSensitivity, QByteArray, QModelIndex, QString, QStringList, QVariant
}; };
use slide_model::SlideObject; use slide_model::SlideObject;
use std::thread;
use std::{path::PathBuf, pin::Pin}; use std::{path::PathBuf, pin::Pin};
use tracing::{debug, error}; use tracing::{debug, error};
@ -234,7 +233,7 @@ use self::slide_model::{
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Slide { pub struct Slide {
pub text: String, pub text: String,
pub ty: String, pub ty: SlideType,
pub audio: String, pub audio: String,
pub image_background: String, pub image_background: String,
pub video_background: String, pub video_background: String,
@ -259,7 +258,7 @@ impl Default for Slide {
fn default() -> Self { fn default() -> Self {
Self { Self {
text: String::default(), text: String::default(),
ty: String::default(), ty: SlideType::Image,
audio: String::default(), audio: String::default(),
image_background: String::default(), image_background: String::default(),
video_background: String::default(), video_background: String::default(),
@ -508,7 +507,7 @@ impl slide_model::SlideModel {
// let vec_slize: &[usize] = &text_vec; // let vec_slize: &[usize] = &text_vec;
let mut slide = Slide { let mut slide = Slide {
ty: extract_string(service_item, "type"), ty: SlideType::try_from(extract_string(service_item, "type")).unwrap(),
text: extract_string(service_item, "text"), text: extract_string(service_item, "text"),
image_background: extract_string(service_item, "imageBackground"), image_background: extract_string(service_item, "imageBackground"),
video_background: extract_string(service_item, "videoBackground"), video_background: extract_string(service_item, "videoBackground"),
@ -566,7 +565,7 @@ impl slide_model::SlideModel {
match ty { match ty {
Some(ty) if ty == QString::from("image") => { Some(ty) if ty == QString::from("image") => {
slide.ty = ty.to_string(); slide.ty = ty.try_into().unwrap();
slide.image_background = background.to_string(); slide.image_background = background.to_string();
slide.video_background = String::from(""); slide.video_background = String::from("");
slide.slide_index = 0; slide.slide_index = 0;
@ -580,7 +579,7 @@ impl slide_model::SlideModel {
"rust: add song of {:?} length at index {:?}", "rust: add song of {:?} length at index {:?}",
&count, &slide_index &count, &slide_index
); );
slide.ty = ty.clone().to_string(); slide.ty = ty.clone().try_into().unwrap();
// debug!("{:?}", text_vec[i].clone()); // debug!("{:?}", text_vec[i].clone());
slide.text = text.clone().to_string(); slide.text = text.clone().to_string();
slide.slide_count = count as i32; slide.slide_count = count as i32;
@ -597,7 +596,7 @@ impl slide_model::SlideModel {
} }
} }
Some(ty) if ty == QString::from("video") => { Some(ty) if ty == QString::from("video") => {
slide.ty = ty.to_string(); slide.ty = ty.try_into().unwrap();
slide.image_background = String::from(""); slide.image_background = String::from("");
slide.video_background = background.to_string(); slide.video_background = background.to_string();
slide.slide_index = 0; slide.slide_index = 0;
@ -609,7 +608,7 @@ impl slide_model::SlideModel {
&QString::from(".html"), &QString::from(".html"),
CaseSensitivity::CaseInsensitive, CaseSensitivity::CaseInsensitive,
) { ) {
slide.ty = ty.clone().to_string(); slide.ty = ty.clone().try_into().unwrap();
slide.html = true; slide.html = true;
slide.image_background = background.clone().to_string(); slide.image_background = background.clone().to_string();
slide.video_background = String::from(""); slide.video_background = String::from("");
@ -617,7 +616,7 @@ impl slide_model::SlideModel {
self.as_mut().insert_slide(&slide, slide_index); self.as_mut().insert_slide(&slide, slide_index);
} else { } else {
for i in 0..slide.slide_count { for i in 0..slide.slide_count {
slide.ty = ty.clone().to_string(); slide.ty = ty.clone().try_into().unwrap();
slide.image_background = background.clone().to_string(); slide.image_background = background.clone().to_string();
slide.video_background = String::from(""); slide.video_background = String::from("");
slide.slide_index = i; slide.slide_index = i;
@ -696,7 +695,7 @@ impl slide_model::SlideModel {
.get(&QString::from("type")) .get(&QString::from("type"))
.unwrap_or(QVariant::from(&QString::from(""))) .unwrap_or(QVariant::from(&QString::from("")))
.value() .value()
.unwrap_or(QString::from("")).to_string(); .unwrap_or(QString::from("")).try_into().unwrap_or(SlideType::Image);
slide.text = service_item slide.text = service_item
.get(&QString::from("text")) .get(&QString::from("text"))
.unwrap_or(QVariant::from(&QString::from(""))) .unwrap_or(QVariant::from(&QString::from("")))
@ -767,7 +766,7 @@ impl slide_model::SlideModel {
match ty { match ty {
Some(ty) if ty == QString::from("image") => { Some(ty) if ty == QString::from("image") => {
slide.ty = ty.to_string(); slide.ty = ty.try_into().unwrap_or(SlideType::Image);
slide.image_background = background.to_string(); slide.image_background = background.to_string();
slide.video_background = String::from(""); slide.video_background = String::from("");
slide.slide_index = 0; slide.slide_index = 0;
@ -775,7 +774,7 @@ impl slide_model::SlideModel {
} }
Some(ty) if ty == QString::from("song") => { Some(ty) if ty == QString::from("song") => {
for (i, text) in text_vec.iter().enumerate() { for (i, text) in text_vec.iter().enumerate() {
slide.ty = ty.clone().to_string(); slide.ty = ty.clone().try_into().unwrap_or(SlideType::Image);
// debug!("{:?}", text_vec[i].clone()); // debug!("{:?}", text_vec[i].clone());
slide.text = text.clone().to_string(); slide.text = text.clone().to_string();
slide.slide_count = text_vec.len() as i32; slide.slide_count = text_vec.len() as i32;
@ -791,7 +790,7 @@ impl slide_model::SlideModel {
} }
} }
Some(ty) if ty == QString::from("video") => { Some(ty) if ty == QString::from("video") => {
slide.ty = ty.to_string(); slide.ty = ty.try_into().unwrap_or(SlideType::Image);
slide.image_background = String::from(""); slide.image_background = String::from("");
slide.video_background = background.to_string(); slide.video_background = background.to_string();
slide.slide_index = 0; slide.slide_index = 0;
@ -803,7 +802,7 @@ impl slide_model::SlideModel {
&QString::from(".html"), &QString::from(".html"),
CaseSensitivity::CaseInsensitive, CaseSensitivity::CaseInsensitive,
) { ) {
slide.ty = ty.clone().to_string(); slide.ty = ty.clone().try_into().unwrap_or(SlideType::Image);
slide.html = true; slide.html = true;
slide.image_background = background.clone().to_string(); slide.image_background = background.clone().to_string();
slide.video_background = String::from(""); slide.video_background = String::from("");
@ -811,7 +810,7 @@ impl slide_model::SlideModel {
self.as_mut().add_slide(&slide); self.as_mut().add_slide(&slide);
} else { } else {
for i in 0..slide.slide_count { for i in 0..slide.slide_count {
slide.ty = ty.clone().to_string(); slide.ty = ty.clone().try_into().unwrap_or(SlideType::Image);
slide.image_background = background.clone().to_string(); slide.image_background = background.clone().to_string();
slide.video_background = String::from(""); slide.video_background = String::from("");
slide.slide_index = i; slide.slide_index = i;
@ -1278,7 +1277,7 @@ impl slide_model::SlideModel {
let role = SlideRoles { repr: role }; let role = SlideRoles { repr: role };
if let Some(slide) = self.slides.get(index.row() as usize) { if let Some(slide) = self.slides.get(index.row() as usize) {
return match role { return match role {
SlideRoles::Ty => QVariant::from(&QString::from(&slide.ty)), SlideRoles::Ty => QVariant::from(&QString::from(&slide.ty.to_string())),
SlideRoles::Text => QVariant::from(&QString::from(&slide.text)), SlideRoles::Text => QVariant::from(&QString::from(&slide.text)),
SlideRoles::Audio => QVariant::from(&QString::from(&slide.audio)), SlideRoles::Audio => QVariant::from(&QString::from(&slide.audio)),
SlideRoles::ImageBackground => { SlideRoles::ImageBackground => {

View file

@ -482,7 +482,7 @@ impl slide_object::SlideObject {
self.as_mut().set_slide_size(slide.slide_count); self.as_mut().set_slide_size(slide.slide_count);
self.as_mut().set_looping(slide.looping); self.as_mut().set_looping(slide.looping);
self.as_mut().set_text(QString::from(&slide.text)); self.as_mut().set_text(QString::from(&slide.text));
self.as_mut().set_ty(QString::from(&slide.ty)); self.as_mut().set_ty(QString::from(&slide.ty.to_string()));
self.as_mut().set_audio(QString::from(&slide.audio)); self.as_mut().set_audio(QString::from(&slide.audio));
self.as_mut().set_image_background(QString::from(&slide.image_background)); self.as_mut().set_image_background(QString::from(&slide.image_background));
self.as_mut().set_video_background(QString::from(&slide.video_background)); self.as_mut().set_video_background(QString::from(&slide.video_background));