From 836c997e974cdac125685696032a869fcf5dea5e Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 27 Sep 2024 06:12:41 -0500 Subject: [PATCH] adding SlideType to slide_model --- src/rust/slide_model.rs | 33 ++++++++++++++++----------------- src/rust/slide_object.rs | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/rust/slide_model.rs b/src/rust/slide_model.rs index 26c45b6..38416d0 100644 --- a/src/rust/slide_model.rs +++ b/src/rust/slide_model.rs @@ -214,7 +214,7 @@ pub mod slide_model { } } -use crate::ffmpeg; +use crate::{ffmpeg, slide_types::SlideType}; use crate::obs::Obs; use crate::slide_model::slide_model::QList_QString; use cxx_qt::{CxxQtType, Threading}; @@ -222,7 +222,6 @@ use cxx_qt_lib::{ CaseSensitivity, QByteArray, QModelIndex, QString, QStringList, QVariant }; use slide_model::SlideObject; -use std::thread; use std::{path::PathBuf, pin::Pin}; use tracing::{debug, error}; @@ -234,7 +233,7 @@ use self::slide_model::{ #[derive(Clone, Debug)] pub struct Slide { pub text: String, - pub ty: String, + pub ty: SlideType, pub audio: String, pub image_background: String, pub video_background: String, @@ -259,7 +258,7 @@ impl Default for Slide { fn default() -> Self { Self { text: String::default(), - ty: String::default(), + ty: SlideType::Image, audio: String::default(), image_background: String::default(), video_background: String::default(), @@ -508,7 +507,7 @@ impl slide_model::SlideModel { // let vec_slize: &[usize] = &text_vec; 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"), image_background: extract_string(service_item, "imageBackground"), video_background: extract_string(service_item, "videoBackground"), @@ -566,7 +565,7 @@ impl slide_model::SlideModel { match ty { 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.video_background = String::from(""); slide.slide_index = 0; @@ -580,7 +579,7 @@ impl slide_model::SlideModel { "rust: add song of {:?} length at index {:?}", &count, &slide_index ); - slide.ty = ty.clone().to_string(); + slide.ty = ty.clone().try_into().unwrap(); // debug!("{:?}", text_vec[i].clone()); slide.text = text.clone().to_string(); slide.slide_count = count as i32; @@ -597,7 +596,7 @@ impl slide_model::SlideModel { } } Some(ty) if ty == QString::from("video") => { - slide.ty = ty.to_string(); + slide.ty = ty.try_into().unwrap(); slide.image_background = String::from(""); slide.video_background = background.to_string(); slide.slide_index = 0; @@ -609,7 +608,7 @@ impl slide_model::SlideModel { &QString::from(".html"), CaseSensitivity::CaseInsensitive, ) { - slide.ty = ty.clone().to_string(); + slide.ty = ty.clone().try_into().unwrap(); slide.html = true; slide.image_background = background.clone().to_string(); slide.video_background = String::from(""); @@ -617,7 +616,7 @@ impl slide_model::SlideModel { self.as_mut().insert_slide(&slide, slide_index); } else { 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.video_background = String::from(""); slide.slide_index = i; @@ -696,7 +695,7 @@ impl slide_model::SlideModel { .get(&QString::from("type")) .unwrap_or(QVariant::from(&QString::from(""))) .value() - .unwrap_or(QString::from("")).to_string(); + .unwrap_or(QString::from("")).try_into().unwrap_or(SlideType::Image); slide.text = service_item .get(&QString::from("text")) .unwrap_or(QVariant::from(&QString::from(""))) @@ -767,7 +766,7 @@ impl slide_model::SlideModel { match ty { 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.video_background = String::from(""); slide.slide_index = 0; @@ -775,7 +774,7 @@ impl slide_model::SlideModel { } Some(ty) if ty == QString::from("song") => { 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()); slide.text = text.clone().to_string(); slide.slide_count = text_vec.len() as i32; @@ -791,7 +790,7 @@ impl slide_model::SlideModel { } } 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.video_background = background.to_string(); slide.slide_index = 0; @@ -803,7 +802,7 @@ impl slide_model::SlideModel { &QString::from(".html"), CaseSensitivity::CaseInsensitive, ) { - slide.ty = ty.clone().to_string(); + slide.ty = ty.clone().try_into().unwrap_or(SlideType::Image); slide.html = true; slide.image_background = background.clone().to_string(); slide.video_background = String::from(""); @@ -811,7 +810,7 @@ impl slide_model::SlideModel { self.as_mut().add_slide(&slide); } else { 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.video_background = String::from(""); slide.slide_index = i; @@ -1278,7 +1277,7 @@ impl slide_model::SlideModel { let role = SlideRoles { repr: role }; if let Some(slide) = self.slides.get(index.row() as usize) { 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::Audio => QVariant::from(&QString::from(&slide.audio)), SlideRoles::ImageBackground => { diff --git a/src/rust/slide_object.rs b/src/rust/slide_object.rs index 9c9fc9d..b4ec9b9 100644 --- a/src/rust/slide_object.rs +++ b/src/rust/slide_object.rs @@ -482,7 +482,7 @@ impl slide_object::SlideObject { self.as_mut().set_slide_size(slide.slide_count); self.as_mut().set_looping(slide.looping); 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_image_background(QString::from(&slide.image_background)); self.as_mut().set_video_background(QString::from(&slide.video_background));