fixing lots of bugs
This commit is contained in:
parent
da735aa00b
commit
0ba3e7588b
24 changed files with 781 additions and 486 deletions
|
|
@ -19,9 +19,11 @@ pub mod slide_model {
|
|||
include!("cxx-qt-lib/qlist.h");
|
||||
type QList_QString = cxx_qt_lib::QList<QString>;
|
||||
include!("cxx-qt-gen/slide_object.cxxqt.h");
|
||||
type SlideObject = crate::slide_object::slide_object::SlideObject;
|
||||
type SlideObject =
|
||||
crate::slide_object::slide_object::SlideObject;
|
||||
include!("cxx-qt-gen/song_model.cxxqt.h");
|
||||
type SongModel = crate::songs::song_model::song_model::SongModel;
|
||||
type SongModel =
|
||||
crate::songs::song_model::song_model::SongModel;
|
||||
include!("cxx-qt-gen/video_model.cxxqt.h");
|
||||
type VideoModel = crate::video_model::video_model::VideoModel;
|
||||
include!("cxx-qt-gen/image_model.cxxqt.h");
|
||||
|
|
@ -229,26 +231,29 @@ pub mod slide_model {
|
|||
|
||||
use crate::image_model::image_model::ImageModel;
|
||||
use crate::image_model::{self, Image, ImageModelRust};
|
||||
use crate::obs::Obs;
|
||||
use crate::presentation_model::presentation_model::PresentationModel;
|
||||
use crate::presentation_model::{self, Presentation, PresentationModelRust};
|
||||
use crate::presentation_model::{
|
||||
self, Presentation, PresentationModelRust,
|
||||
};
|
||||
use crate::slide_model::slide_model::QList_QString;
|
||||
use crate::songs::song_model::song_model::{self, SongModel};
|
||||
use crate::songs::song_model::{get_song, Song, SongModelRust};
|
||||
use crate::video_model::video_model::VideoModel;
|
||||
use crate::video_model::{self, Video, VideoModelRust};
|
||||
use crate::{ffmpeg, slide_types::SlideType};
|
||||
use crate::obs::Obs;
|
||||
use crate::slide_model::slide_model::QList_QString;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::Section;
|
||||
use cxx_qt::{CxxQtType, Threading};
|
||||
use cxx_qt_lib::{
|
||||
CaseSensitivity, QByteArray, QList, QModelIndex, QString, QStringList, QVariant
|
||||
CaseSensitivity, QByteArray, QList, QModelIndex, QString,
|
||||
QStringList, QVariant,
|
||||
};
|
||||
use slide_model::SlideObject;
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display};
|
||||
use std::fmt::Display;
|
||||
use std::{path::PathBuf, pin::Pin};
|
||||
use tracing::{debug, error};
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
use self::slide_model::{
|
||||
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
||||
|
|
@ -336,45 +341,40 @@ impl Slide {
|
|||
fn slides_from_song(song: Song) -> Result<Vec<Self>> {
|
||||
let list = song.get_lyric_list();
|
||||
let total = list.len();
|
||||
let mut vector: Vec<Slide> = vec![];
|
||||
list.iter().map(|t| t.to_string()).enumerate()
|
||||
.for_each(|(i, s)| {
|
||||
if song.background_type == "image" {
|
||||
vector.push(
|
||||
Self {
|
||||
text: s,
|
||||
ty: SlideType::Song,
|
||||
audio: song.audio.clone(),
|
||||
image_background: song.background.clone(),
|
||||
video_background: "".to_owned(),
|
||||
htext_alignment: song.horizontal_text_alignment.clone(),
|
||||
vtext_alignment: song.vertical_text_alignment.clone(),
|
||||
font: song.font.clone(),
|
||||
font_size: song.font_size,
|
||||
slide_count: total as i32,
|
||||
slide_index: i as i32,
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
} else {
|
||||
vector.push(
|
||||
Self {
|
||||
text: s,
|
||||
ty: SlideType::Song,
|
||||
audio: song.audio.clone(),
|
||||
image_background: "".to_owned(),
|
||||
video_background: song.background.clone(),
|
||||
htext_alignment: song.horizontal_text_alignment.clone(),
|
||||
vtext_alignment: song.vertical_text_alignment.clone(),
|
||||
font: song.font.clone(),
|
||||
font_size: song.font_size,
|
||||
slide_count: total as i32,
|
||||
slide_index: i as i32,
|
||||
..Default::default()
|
||||
}
|
||||
)
|
||||
}
|
||||
});
|
||||
let vector = list
|
||||
.iter()
|
||||
.map(|t| {
|
||||
let s = t.to_string();
|
||||
warn!(s);
|
||||
s
|
||||
})
|
||||
.enumerate()
|
||||
.map(|(i, s)| Self {
|
||||
text: s,
|
||||
ty: SlideType::Song,
|
||||
audio: song.audio.clone(),
|
||||
image_background: if song.background_type == "image" {
|
||||
song.background.clone()
|
||||
} else {
|
||||
"".into()
|
||||
},
|
||||
video_background: if song.background_type == "video" {
|
||||
song.background.clone()
|
||||
} else {
|
||||
"".to_owned()
|
||||
},
|
||||
htext_alignment: song
|
||||
.horizontal_text_alignment
|
||||
.clone(),
|
||||
vtext_alignment: song.vertical_text_alignment.clone(),
|
||||
font: song.font.clone(),
|
||||
font_size: song.font_size,
|
||||
slide_count: total as i32,
|
||||
slide_index: i as i32,
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
warn!(?vector);
|
||||
Ok(vector)
|
||||
}
|
||||
|
||||
|
|
@ -395,7 +395,9 @@ impl Slide {
|
|||
})
|
||||
}
|
||||
|
||||
fn slides_from_presentation(presentation: Presentation) -> Result<Vec<Self>> {
|
||||
fn slides_from_presentation(
|
||||
presentation: Presentation,
|
||||
) -> Result<Vec<Self>> {
|
||||
let total = presentation.page_count;
|
||||
let mut slides: Vec<Slide> = vec![];
|
||||
for i in 0..total {
|
||||
|
|
@ -406,7 +408,7 @@ impl Slide {
|
|||
image_background: presentation.path.clone(),
|
||||
..Default::default()
|
||||
})
|
||||
};
|
||||
}
|
||||
Ok(slides)
|
||||
}
|
||||
}
|
||||
|
|
@ -456,9 +458,12 @@ impl slide_model::SlideModel {
|
|||
index: i32,
|
||||
) -> bool {
|
||||
let mut vector_roles = QVector_i32::default();
|
||||
vector_roles.append(self.get_role(SlideRoles::VideoThumbnail));
|
||||
vector_roles.append(self.get_role(SlideRoles::VideoBackground));
|
||||
vector_roles.append(self.get_role(SlideRoles::ImageBackground));
|
||||
vector_roles
|
||||
.append(self.get_role(SlideRoles::VideoThumbnail));
|
||||
vector_roles
|
||||
.append(self.get_role(SlideRoles::VideoBackground));
|
||||
vector_roles
|
||||
.append(self.get_role(SlideRoles::ImageBackground));
|
||||
let rc = self.as_ref().count() - 1;
|
||||
let tl = self.as_ref().index(0, 0, &QModelIndex::default());
|
||||
let br = self.as_ref().index(rc, 0, &QModelIndex::default());
|
||||
|
|
@ -470,7 +475,11 @@ impl slide_model::SlideModel {
|
|||
let path =
|
||||
PathBuf::from(slide.video_background.to_string());
|
||||
let screenshot = ffmpeg::bg_path_from_video(&path);
|
||||
let mut screenshot_string = screenshot.clone().into_os_string().into_string().unwrap_or_default();
|
||||
let mut screenshot_string = screenshot
|
||||
.clone()
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.unwrap_or_default();
|
||||
screenshot_string.insert_str(0, "file://");
|
||||
slide.video_thumbnail = screenshot_string;
|
||||
std::thread::spawn(move || {
|
||||
|
|
@ -483,7 +492,7 @@ impl slide_model::SlideModel {
|
|||
"Error making video background"
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
match thread.queue(move |mut slide_model| {
|
||||
slide_model.as_mut().data_changed(
|
||||
&tl,
|
||||
|
|
@ -616,37 +625,56 @@ impl slide_model::SlideModel {
|
|||
SlideType::Song => {
|
||||
let song = get_song(item_model_id)?;
|
||||
let slides = Slide::slides_from_song(song)?;
|
||||
slides.iter().for_each(|slide| self.as_mut().insert_slide(slide, index));
|
||||
slides.iter().enumerate().for_each(|(i, slide)| {
|
||||
self.as_mut()
|
||||
.insert_slide(slide, index + i as i32)
|
||||
});
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
SlideType::Video => {
|
||||
let video = video_model::get_video(item_model_id)?;
|
||||
self.insert_slide(&Slide::slide_from_video(video)?, index);
|
||||
self.insert_slide(
|
||||
&Slide::slide_from_video(video)?,
|
||||
index,
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
SlideType::Image => {
|
||||
let result = image_model::get_image(item_model_id);
|
||||
match result {
|
||||
Ok(image) => self.insert_slide(&Slide::slide_from_image(image)?, index),
|
||||
Ok(image) => self.insert_slide(
|
||||
&Slide::slide_from_image(image)?,
|
||||
index,
|
||||
),
|
||||
Err(e) => {
|
||||
e.with_note(|| {
|
||||
format!("This might fail if we are loading the items from a file")
|
||||
});
|
||||
let mut slide = Slide::default();
|
||||
slide.image_background = "qrc:/assets/black.jpg".to_owned();
|
||||
slide.image_background =
|
||||
"qrc:/assets/black.jpg".to_owned();
|
||||
self.insert_slide(&slide, index);
|
||||
},
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
SlideType::Content => {
|
||||
todo!();
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
SlideType::Presentation(_) => {
|
||||
let presentation = presentation_model::get_presentation(item_model_id)?;
|
||||
let slides = Slide::slides_from_presentation(presentation)?;
|
||||
slides.iter().for_each(|slide| self.as_mut().insert_slide(slide, slide.slide_index + index));
|
||||
let presentation =
|
||||
presentation_model::get_presentation(
|
||||
item_model_id,
|
||||
)?;
|
||||
let slides =
|
||||
Slide::slides_from_presentation(presentation)?;
|
||||
slides.iter().for_each(|slide| {
|
||||
self.as_mut().insert_slide(
|
||||
slide,
|
||||
slide.slide_index + index,
|
||||
)
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -656,7 +684,7 @@ impl slide_model::SlideModel {
|
|||
self: Pin<&mut Self>,
|
||||
item_model_id: i32,
|
||||
kind: &QString,
|
||||
) -> Result<()>{
|
||||
) -> Result<()> {
|
||||
let index = self.count;
|
||||
self.insert_item_from_service(index, item_model_id, kind)
|
||||
}
|
||||
|
|
@ -692,7 +720,8 @@ impl slide_model::SlideModel {
|
|||
|
||||
if let Some((i, slide)) = slides_iter
|
||||
.clone()
|
||||
.enumerate().find(|slide| slide.1.service_item_id == source_index)
|
||||
.enumerate()
|
||||
.find(|slide| slide.1.service_item_id == source_index)
|
||||
{
|
||||
debug!(index = i, ?slide);
|
||||
first_slide = i as i32;
|
||||
|
|
@ -705,11 +734,8 @@ impl slide_model::SlideModel {
|
|||
|
||||
// lets get the dest_slide and count
|
||||
if move_down {
|
||||
if let Some((i, slide)) = slides_iter
|
||||
.clone()
|
||||
.enumerate()
|
||||
.rev()
|
||||
.find(|slide| {
|
||||
if let Some((i, slide)) =
|
||||
slides_iter.clone().enumerate().rev().find(|slide| {
|
||||
slide.1.service_item_id == destination_index
|
||||
})
|
||||
{
|
||||
|
|
@ -724,9 +750,8 @@ impl slide_model::SlideModel {
|
|||
dest_slide, dest_count
|
||||
);
|
||||
}
|
||||
} else if let Some((i, slide)) = slides_iter
|
||||
.enumerate()
|
||||
.find(|slide| {
|
||||
} else if let Some((i, slide)) =
|
||||
slides_iter.enumerate().find(|slide| {
|
||||
slide.1.service_item_id == destination_index
|
||||
})
|
||||
{
|
||||
|
|
@ -1001,7 +1026,8 @@ impl slide_model::SlideModel {
|
|||
debug!(service_item = index, "Getting slide from this item");
|
||||
let mut id = 0;
|
||||
if let Some((i, slide)) = slides_iter
|
||||
.enumerate().find(|(_i, slide)| slide.service_item_id == index)
|
||||
.enumerate()
|
||||
.find(|(_i, slide)| slide.service_item_id == index)
|
||||
{
|
||||
debug!(slide_id = i, ?slide);
|
||||
id = i as i32;
|
||||
|
|
@ -1105,7 +1131,6 @@ impl slide_model::SlideModel {
|
|||
(0, QModelIndex::default(), vector_roles)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// QAbstractListModel implementation
|
||||
|
|
@ -1114,22 +1139,30 @@ 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.to_string())),
|
||||
SlideRoles::Text => QVariant::from(&QString::from(&slide.text)),
|
||||
SlideRoles::Audio => QVariant::from(&QString::from(&slide.audio)),
|
||||
SlideRoles::ImageBackground => {
|
||||
QVariant::from(&QString::from(&slide.image_background))
|
||||
SlideRoles::Ty => QVariant::from(&QString::from(
|
||||
&slide.ty.to_string(),
|
||||
)),
|
||||
SlideRoles::Text => {
|
||||
QVariant::from(&QString::from(&slide.text))
|
||||
}
|
||||
SlideRoles::VideoBackground => {
|
||||
QVariant::from(&QString::from(&slide.video_background))
|
||||
SlideRoles::Audio => {
|
||||
QVariant::from(&QString::from(&slide.audio))
|
||||
}
|
||||
SlideRoles::HTextAlignment => {
|
||||
QVariant::from(&QString::from(&slide.htext_alignment))
|
||||
SlideRoles::ImageBackground => QVariant::from(
|
||||
&QString::from(&slide.image_background),
|
||||
),
|
||||
SlideRoles::VideoBackground => QVariant::from(
|
||||
&QString::from(&slide.video_background),
|
||||
),
|
||||
SlideRoles::HTextAlignment => QVariant::from(
|
||||
&QString::from(&slide.htext_alignment),
|
||||
),
|
||||
SlideRoles::VTextAlignment => QVariant::from(
|
||||
&QString::from(&slide.vtext_alignment),
|
||||
),
|
||||
SlideRoles::Font => {
|
||||
QVariant::from(&QString::from(&slide.font))
|
||||
}
|
||||
SlideRoles::VTextAlignment => {
|
||||
QVariant::from(&QString::from(&slide.vtext_alignment))
|
||||
}
|
||||
SlideRoles::Font => QVariant::from(&QString::from(&slide.font)),
|
||||
SlideRoles::FontSize => {
|
||||
QVariant::from(&slide.font_size)
|
||||
}
|
||||
|
|
@ -1147,9 +1180,9 @@ impl slide_model::SlideModel {
|
|||
QVariant::from(&slide.selected)
|
||||
}
|
||||
SlideRoles::Looping => QVariant::from(&slide.looping),
|
||||
SlideRoles::VideoThumbnail => {
|
||||
QVariant::from(&QString::from(&slide.video_thumbnail))
|
||||
}
|
||||
SlideRoles::VideoThumbnail => QVariant::from(
|
||||
&QString::from(&slide.video_thumbnail),
|
||||
),
|
||||
SlideRoles::VideoStartTime => {
|
||||
QVariant::from(&slide.video_start_time)
|
||||
}
|
||||
|
|
@ -1256,7 +1289,8 @@ impl slide_model::SlideModel {
|
|||
fn extract_string(item: &QMap_QString_QVariant, key: &str) -> String {
|
||||
item.get(&QString::from(key))
|
||||
.unwrap_or(QVariant::from(&QString::default()))
|
||||
.value_or_default::<QString>().to_string()
|
||||
.value_or_default::<QString>()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn extract_value(item: &QMap_QString_QVariant, key: &str) -> i32 {
|
||||
|
|
@ -1277,12 +1311,11 @@ fn extract_bool(item: &QMap_QString_QVariant, key: &str) -> bool {
|
|||
.value_or_default::<bool>()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod test {
|
||||
|
||||
#[test]
|
||||
pub fn test_obs_setting_scene() {
|
||||
assert_eq!(true, true)
|
||||
}
|
||||
}
|
||||
// #[test]
|
||||
// pub fn test_obs_setting_scene() {
|
||||
// assert_eq!(true, true)
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue