adding a SlideType enum that can parse from a string
This will start to allow us to have a much better data model for the slides and service items. They can have a type associated with them and parse which they are from this type.
This commit is contained in:
parent
0cac11cb89
commit
273dd76d23
4 changed files with 182 additions and 37 deletions
|
@ -14,4 +14,5 @@ pub mod songs;
|
|||
pub mod utils;
|
||||
pub mod video_model;
|
||||
pub mod ytdl;
|
||||
pub mod slide_types;
|
||||
// mod video_thumbnail;
|
||||
|
|
|
@ -310,13 +310,14 @@ use self::service_item_model::{
|
|||
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
||||
ServiceRoles,
|
||||
};
|
||||
use crate::slide_types::SlideType;
|
||||
|
||||
use super::service_item_model::service_item_model::ServiceItemModel;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ServiceItem {
|
||||
name: QString,
|
||||
ty: QString,
|
||||
ty: SlideType,
|
||||
audio: QString,
|
||||
background: QString,
|
||||
background_type: QString,
|
||||
|
@ -329,21 +330,14 @@ pub struct ServiceItem {
|
|||
looping: bool,
|
||||
video_start_time: f32,
|
||||
video_end_time: f32,
|
||||
obs_scene: QString,
|
||||
id: i32,
|
||||
}
|
||||
|
||||
impl ServiceItem {
|
||||
fn debug(self) {
|
||||
debug!(?self);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ServiceItem {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: QString::default(),
|
||||
ty: QString::default(),
|
||||
ty: SlideType::Image,
|
||||
audio: QString::default(),
|
||||
background: QString::default(),
|
||||
background_type: QString::default(),
|
||||
|
@ -356,7 +350,6 @@ impl Default for ServiceItem {
|
|||
looping: false,
|
||||
video_start_time: 0.0,
|
||||
video_end_time: 0.0,
|
||||
obs_scene: QString::default(),
|
||||
id: 0,
|
||||
}
|
||||
}
|
||||
|
@ -455,7 +448,7 @@ impl service_item_model::ServiceItemModel {
|
|||
) {
|
||||
let service_item = ServiceItem {
|
||||
name,
|
||||
ty,
|
||||
ty: ty.try_into().unwrap(),
|
||||
text,
|
||||
background,
|
||||
background_type,
|
||||
|
@ -515,7 +508,7 @@ impl service_item_model::ServiceItemModel {
|
|||
) {
|
||||
let service_item = ServiceItem {
|
||||
name,
|
||||
ty,
|
||||
ty: ty.try_into().unwrap(),
|
||||
text,
|
||||
background,
|
||||
background_type,
|
||||
|
@ -841,7 +834,8 @@ impl service_item_model::ServiceItemModel {
|
|||
debug!(activating_item = index,
|
||||
title = ?service_item.name,
|
||||
background = ?service_item.background,
|
||||
background_type = ?service_item.background_type);
|
||||
background_type = ?service_item.background_type,
|
||||
kind = ?service_item.ty);
|
||||
service_item.active = true;
|
||||
// if let Some(obs) = obs {
|
||||
// match obs
|
||||
|
@ -993,7 +987,7 @@ impl service_item_model::ServiceItemModel {
|
|||
}
|
||||
|
||||
let item_json = json!({"name".to_owned(): Value::from(item.name.to_string()),
|
||||
"type".to_owned(): Value::from(item.ty.to_string()),
|
||||
"type".to_owned(): Value::from(item.ty.clone().to_string()),
|
||||
"audio".to_owned(): Value::from(item.audio.to_string()),
|
||||
"background".to_owned(): Value::from(item.background.to_string()),
|
||||
"backgroundType".to_owned(): Value::from(item.background_type.to_string()),
|
||||
|
@ -1156,7 +1150,7 @@ impl service_item_model::ServiceItemModel {
|
|||
println!("size: {:?}", file.size());
|
||||
if !file_path.exists() {
|
||||
match file.unpack_in(&datadir) {
|
||||
Ok(t) => (),
|
||||
Ok(_t) => (),
|
||||
Err(e) => error!("Error unpacking archive: {}", e),
|
||||
}
|
||||
}
|
||||
|
@ -1326,6 +1320,7 @@ impl service_item_model::ServiceItemModel {
|
|||
.append(QString::from(txt.as_str().unwrap()));
|
||||
}
|
||||
let text = QStringList::from(&text_list);
|
||||
if let Ok(ty) = ty.try_into() {
|
||||
|
||||
let service_item = ServiceItem {
|
||||
name,
|
||||
|
@ -1345,6 +1340,26 @@ impl service_item_model::ServiceItemModel {
|
|||
self.as_mut().add_service_item(&service_item);
|
||||
println!("Loaded Service: {:?}", ds);
|
||||
// // files implement the Read trait
|
||||
} else {
|
||||
let service_item = ServiceItem {
|
||||
name,
|
||||
ty: SlideType::Content,
|
||||
text,
|
||||
background,
|
||||
background_type,
|
||||
audio,
|
||||
font,
|
||||
font_size,
|
||||
slide_count,
|
||||
looping,
|
||||
video_start_time,
|
||||
video_end_time,
|
||||
..Default::default()
|
||||
};
|
||||
self.as_mut().add_service_item(&service_item);
|
||||
error!("Loaded service item with generic type since it was an unknown type.");
|
||||
// // files implement the Read trait
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
|
@ -1393,7 +1408,7 @@ impl service_item_model::ServiceItemModel {
|
|||
QVariant::from(&service_item.name)
|
||||
}
|
||||
ServiceRoles::Type => {
|
||||
QVariant::from(&service_item.ty)
|
||||
QVariant::from(&QString::from(&service_item.ty.clone().to_string()))
|
||||
}
|
||||
ServiceRoles::Audio => {
|
||||
QVariant::from(&service_item.audio)
|
||||
|
|
|
@ -6,8 +6,8 @@ mod slide_object {
|
|||
include!("cxx-qt-lib/qmap.h");
|
||||
type QMap_QString_QVariant =
|
||||
cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
||||
include!("cxx-qt-lib/qvariant.h");
|
||||
type QVariant = cxx_qt_lib::QVariant;
|
||||
// include!("cxx-qt-lib/qvariant.h");
|
||||
// type QVariant = cxx_qt_lib::QVariant;
|
||||
// #[cxx_name = "SlideModel"]
|
||||
// type SlideModel = crate::slide_model::SlideModelRust;
|
||||
}
|
||||
|
@ -88,7 +88,12 @@ use std::pin::Pin;
|
|||
|
||||
use cxx_qt::CxxQtType;
|
||||
use cxx_qt_lib::{CaseSensitivity, QString, QVariant};
|
||||
use tracing::debug;
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::{
|
||||
slide_types::{PresType, SlideType},
|
||||
songs::song_model::{song_model::SongModel, SongModelRust},
|
||||
};
|
||||
|
||||
use self::slide_object::QMap_QString_QVariant;
|
||||
|
||||
|
@ -145,6 +150,38 @@ impl slide_object::SlideObject {
|
|||
item: QMap_QString_QVariant,
|
||||
slide_index: i32,
|
||||
) {
|
||||
// This function will grab the item from the relevant model
|
||||
// and load it into the slide_object
|
||||
let kind = item
|
||||
.get(&QString::from("type"))
|
||||
.unwrap_or(QVariant::from(&QString::default()))
|
||||
.value()
|
||||
.unwrap_or(QString::default());
|
||||
match SlideType::try_from(kind) {
|
||||
Ok(st) => {
|
||||
debug!(kind = ?st, "Changing slide");
|
||||
// let slide = match st {
|
||||
// SlideType::Song => {
|
||||
// SongModel::get_item(slide_index)
|
||||
// }
|
||||
// SlideType::Image => {
|
||||
// ImageModel::get_item(slide_index)
|
||||
// }
|
||||
// SlideType::Video => {
|
||||
// VideoModel::get_item(slide_index)
|
||||
// }
|
||||
// SlideType::Presentation(_) => {
|
||||
// PresentationModel::get_item(slide_index)
|
||||
// }
|
||||
// SlideType::Content => {
|
||||
// PresentationModel::get_item(slide_index)
|
||||
// }
|
||||
// };
|
||||
// debug!(slide);
|
||||
}
|
||||
Err(e) => error!(?e),
|
||||
}
|
||||
|
||||
let _current_index = self.as_ref().get_ref().slide_index();
|
||||
let icount_variant = item
|
||||
.get(&QString::from("imageCount"))
|
||||
|
|
92
src/rust/slide_types.rs
Normal file
92
src/rust/slide_types.rs
Normal file
|
@ -0,0 +1,92 @@
|
|||
use std::{error::Error, fmt::Display};
|
||||
|
||||
use cxx_qt_lib::QString;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PresType {
|
||||
Html,
|
||||
Pdf,
|
||||
Generic,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SlideType {
|
||||
Song,
|
||||
Video,
|
||||
Image,
|
||||
Presentation(PresType),
|
||||
Content,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SlideType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let s = match self {
|
||||
Self::Song => "song".to_owned(),
|
||||
Self::Image => "image".to_owned(),
|
||||
Self::Video => "video".to_owned(),
|
||||
Self::Presentation(PresType::Html) => "html".to_owned(),
|
||||
Self::Presentation(PresType::Pdf) => "pdf".to_owned(),
|
||||
Self::Presentation(PresType::Generic) => {
|
||||
"presentation".to_owned()
|
||||
}
|
||||
Self::Content => "content".to_owned(),
|
||||
};
|
||||
write!(f, "{s}")
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for SlideType {
|
||||
type Error = ParseError;
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
match value.as_str() {
|
||||
"song" => Ok(Self::Song),
|
||||
"image" => Ok(Self::Image),
|
||||
"video" => Ok(Self::Video),
|
||||
"presentation" => {
|
||||
Ok(Self::Presentation(PresType::Generic))
|
||||
}
|
||||
"html" => Ok(Self::Presentation(PresType::Html)),
|
||||
"pdf" => Ok(Self::Presentation(PresType::Pdf)),
|
||||
"content" => Ok(Self::Content),
|
||||
_ => Err(ParseError::UnknownType),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<QString> for SlideType {
|
||||
type Error = ParseError;
|
||||
fn try_from(value: QString) -> Result<Self, Self::Error> {
|
||||
value.to_string().try_into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SlideType> for String {
|
||||
fn from(val: SlideType) -> String {
|
||||
match val {
|
||||
SlideType::Song => "song".to_owned(),
|
||||
SlideType::Video => "video".to_owned(),
|
||||
SlideType::Image => "image".to_owned(),
|
||||
SlideType::Presentation(_) => "presentation".to_owned(),
|
||||
SlideType::Content => "content".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ParseError {
|
||||
UnknownType,
|
||||
}
|
||||
|
||||
impl Error for ParseError {}
|
||||
|
||||
impl Display for ParseError {
|
||||
fn fmt(
|
||||
&self,
|
||||
f: &mut std::fmt::Formatter<'_>,
|
||||
) -> std::fmt::Result {
|
||||
let message = match self {
|
||||
Self::UnknownType => "The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'",
|
||||
};
|
||||
write!(f, "Error: {message}")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue