some prelim enum stuff in service_item_model

This commit is contained in:
Chris Cochrun 2024-06-23 06:51:32 -05:00
parent eef6d6d15a
commit ee9c1e82f4

View file

@ -43,6 +43,15 @@ mod service_item_model {
Id,
}
#[qenum]
#[namespace = "Item"]
enum ItemType {
Song,
Video,
Image,
Presentation,
}
unsafe extern "RustQt" {
#[qobject]
#[base = "QAbstractListModel"]
@ -119,7 +128,7 @@ mod service_item_model {
fn add_item(
self: Pin<&mut ServiceItemModel>,
name: QString,
ty: QString,
ty: ItemType,
background: QString,
background_type: QString,
text: QStringList,
@ -139,7 +148,7 @@ mod service_item_model {
index: i32,
name: QString,
text: QStringList,
ty: QString,
ty: ItemType,
background: QString,
background_type: QString,
audio: QString,
@ -294,7 +303,7 @@ use crate::obs::Obs;
use crate::service_item_model::service_item_model::QList_QString;
use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{
QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant,
QByteArray, QModelIndex, QString, QStringList, QUrl, QVariant, QVariantValue,
};
use dirs;
use serde_json::{json, Value};
@ -308,18 +317,33 @@ use tar::{Archive, Builder};
use tracing::{debug, error};
use zstd::{Decoder, Encoder};
use self::service_item_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
ServiceRoles,
ItemType, QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, ServiceRoles
};
use super::service_item_model::service_item_model::ServiceItemModel;
#[derive(Clone, Debug)]
pub enum ItemType {
Song,
Video,
Image,
Presentation,
impl std::fmt::Debug for ItemType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
&ItemType::Song => write!(f, "Song"),
&ItemType::Image => write!(f, "Image"),
&ItemType::Video => write!(f, "Video"),
&ItemType::Presentation => write!(f, "Presentation"),
_ => write!(f, "Unknown"),
}
}
}
impl std::fmt::Display for ItemType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
&ItemType::Song => write!(f, "Song"),
&ItemType::Image => write!(f, "Image"),
&ItemType::Video => write!(f, "Video"),
&ItemType::Presentation => write!(f, "Presentation"),
_ => write!(f, "Unknown"),
}
}
}
#[derive(Clone, Debug)]
@ -449,7 +473,7 @@ impl service_item_model::ServiceItemModel {
pub fn add_item(
mut self: Pin<&mut Self>,
name: QString,
ty: QString,
ty: ItemType,
background: QString,
background_type: QString,
text: QStringList,
@ -509,7 +533,7 @@ impl service_item_model::ServiceItemModel {
index: i32,
name: QString,
text: QStringList,
ty: QString,
ty: ItemType,
background: QString,
background_type: QString,
audio: QString,
@ -1209,9 +1233,18 @@ impl service_item_model::ServiceItemModel {
let name = QString::from(
obj.get("name").unwrap().as_str().unwrap(),
);
let ty = QString::from(
obj.get("type").unwrap().as_str().unwrap(),
);
let ty =
obj.get("type").unwrap().as_str().unwrap();
let ty = match ty.to_lowercase().as_str() {
"image" => ItemType::Image,
"song" => ItemType::Song,
"video" => ItemType::Video,
"presentation" => ItemType::Presentation,
other => {
error!("ItemType doesn't match: {}", other);
ItemType::Image
},
};
// both audio and background will need to know if
// it exists on disk, if not use the flat version
let audio_string =
@ -1397,7 +1430,16 @@ impl service_item_model::ServiceItemModel {
QVariant::from(&service_item.name)
}
ServiceRoles::Type => {
QVariant::from(&service_item.ty)
match &service_item.ty {
&ItemType::Image => QVariant::from(&QString::from("Image")),
&ItemType::Song => QVariant::from(&QString::from("Song")),
&ItemType::Video => QVariant::from(&QString::from("Video")),
&ItemType::Presentation => QVariant::from(&QString::from("Presentation")),
other => {
error!("{:?} is not a proper variant.", other);
QVariant::from(&QString::from(""))
},
}
}
ServiceRoles::Audio => {
QVariant::from(&service_item.audio)