saving some updates

This commit is contained in:
Chris Cochrun 2024-09-17 15:32:34 -05:00
parent bb3a5d9b7b
commit 9b75c366de
4 changed files with 70 additions and 39 deletions

View file

@ -556,7 +556,7 @@ Item {
function addItem(index, type, itemIndex) { function addItem(index, type, itemIndex) {
switch (type) { switch (type) {
case 'image': { case 'image': {
const image = imageProxyModel.getImage(itemIndex); const image = imageModel.getItem(itemIndex);
console.log("adding: " + image.title + " of type " + type); console.log("adding: " + image.title + " of type " + type);
ServiceItemModel.insertItem(index, image.title, ServiceItemModel.insertItem(index, image.title,
"", type, image.filePath, "", type, image.filePath,
@ -566,7 +566,7 @@ Item {
return; return;
} }
case 'video': { case 'video': {
const video = videoProxyModel.getVideo(itemIndex); const video = videoModel.getItem(itemIndex);
console.log("adding: " + video.title + " of type " + type); console.log("adding: " + video.title + " of type " + type);
ServiceItemModel.insertItem(index, video.title, ServiceItemModel.insertItem(index, video.title,
"", type, video.filePath, "", type, video.filePath,
@ -576,8 +576,8 @@ Item {
return; return;
} }
case 'song': { case 'song': {
const lyrics = songProxyModel.getLyricList(itemIndex); const lyrics = songModel.getLyricList(itemIndex);
const song = songProxyModel.getSong(itemIndex); const song = songModel.getItem(itemIndex);
/* showPassiveNotification(song.title); */ /* showPassiveNotification(song.title); */
console.log("adding: " + song.title + console.log("adding: " + song.title +
" of type " + type + " of type " + type +
@ -591,7 +591,7 @@ Item {
return; return;
} }
case 'presentation': { case 'presentation': {
const pres = presProxyModel.presentationModel.getItem(itemIndex); const pres = presentationModel.getItem(itemIndex);
console.log("adding: " + pres.title + console.log("adding: " + pres.title +
" of type " + type + " of type " + type +
" with " + pres.pageCount + " slides"); " with " + pres.pageCount + " slides");
@ -611,7 +611,7 @@ Item {
function appendItem(type, itemIndex) { function appendItem(type, itemIndex) {
switch (type) { switch (type) {
case 'image': { case 'image': {
const image = imageProxyModel.getImage(itemIndex); const image = imageModel.getItem(itemIndex);
console.log("adding: " + image.title + " of type " + type); console.log("adding: " + image.title + " of type " + type);
ServiceItemModel.addItem(image.title, ServiceItemModel.addItem(image.title,
type, image.filePath, type, image.filePath,
@ -621,7 +621,7 @@ Item {
return; return;
} }
case 'video': { case 'video': {
const video = videoProxyModel.getVideo(itemIndex); const video = videoModel.getItem(itemIndex);
console.log("adding: " + video.title + " of type " + type); console.log("adding: " + video.title + " of type " + type);
ServiceItemModel.addItem(video.title, ServiceItemModel.addItem(video.title,
type, video.filePath, type, video.filePath,
@ -631,8 +631,8 @@ Item {
return; return;
} }
case 'song': { case 'song': {
const lyrics = songProxyModel.getLyricList(itemIndex); const lyrics = songModel.getLyricList(itemIndex);
const song = songProxyModel.getSong(itemIndex); const song = songModel.getItem(itemIndex);
console.log("adding: " + song.title + console.log("adding: " + song.title +
" of type " + type + " of type " + type +
" with " + lyrics.length + " slides"); " with " + lyrics.length + " slides");
@ -645,7 +645,7 @@ Item {
return; return;
} }
case 'presentation': { case 'presentation': {
const pres = presProxyModel.presentationModel.getItem(itemIndex); const pres = presentationModel.getItem(itemIndex);
console.log("adding: " + pres.title + console.log("adding: " + pres.title +
" of type " + type + " of type " + type +
" with " + pres.pageCount + " slides"); " with " + pres.pageCount + " slides");

View file

@ -156,6 +156,7 @@ mod image_model {
} }
} }
use crate::models::run_migrations;
use crate::schema::images::dsl::*; use crate::schema::images::dsl::*;
use cxx_qt::CxxQtType; use cxx_qt::CxxQtType;
use cxx_qt_lib::{QModelIndex, QString, QUrl, QVariant}; use cxx_qt_lib::{QModelIndex, QString, QUrl, QVariant};
@ -197,6 +198,7 @@ impl image_model::ImageModel {
pub fn setup(mut self: Pin<&mut Self>) { pub fn setup(mut self: Pin<&mut Self>) {
let db = &mut self.as_mut().get_db(); let db = &mut self.as_mut().get_db();
run_migrations(db);
let results = images let results = images
.load::<crate::models::Image>(db) .load::<crate::models::Image>(db)
.expect("Error loading images"); .expect("Error loading images");

View file

@ -1356,6 +1356,29 @@ impl service_item_model::ServiceItemModel {
} }
} }
fn get_indices(
self: Pin<&mut Self>,
item_id: i32,
role: ServiceRoles,
) -> (usize, QModelIndex, QVector_i32) {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(role));
if let Some(index) =
self.as_ref().service_items.iter().position(|x| x.id == item_id)
{
let model_index = self.as_ref().index(
index as i32,
0,
&QModelIndex::default(),
);
(index, model_index, vector_roles)
} else {
error!(item_id, "This item appears to be missing");
(0, QModelIndex::default(), vector_roles)
}
}
pub fn load_last_saved(self: Pin<&mut Self>) -> bool { pub fn load_last_saved(self: Pin<&mut Self>) -> bool {
todo!(); todo!();
// Don't actually need // Don't actually need

View file

@ -315,17 +315,10 @@ impl slide_model::SlideModel {
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
index: i32, index: i32,
) -> bool { ) -> bool {
let mut vector_roles = QVector_i32::default(); let (id, index, roles) = self.as_mut().get_indices(index, SlideRoles::VideoThumbnail);
vector_roles
.append(self.get_role(SlideRoles::VideoThumbnail));
let thread = self.qt_thread(); let thread = self.qt_thread();
let model_index = self
.as_ref()
.index(index, 0, &QModelIndex::default())
.clone();
if let Some(slide) = if let Some(slide) =
self.as_mut().rust_mut().slides.get_mut(index as usize) self.as_mut().rust_mut().slides.get_mut(id)
{ {
if !slide.video_background.is_empty() { if !slide.video_background.is_empty() {
let path = let path =
@ -335,9 +328,7 @@ impl slide_model::SlideModel {
screenshot_string.insert_str(0, "file://"); screenshot_string.insert_str(0, "file://");
slide.video_thumbnail = screenshot_string; slide.video_thumbnail = screenshot_string;
std::thread::spawn(move || { std::thread::spawn(move || {
let result = match ffmpeg::bg_from_video(&path, &screenshot) {
ffmpeg::bg_from_video(&path, &screenshot);
match result {
Ok(_o) => { Ok(_o) => {
debug!("Success making video background!") debug!("Success making video background!")
} }
@ -346,15 +337,14 @@ impl slide_model::SlideModel {
"Error making video background" "Error making video background"
), ),
}; };
let result =
thread.queue(move |mut slide_model| { match thread.queue(move |mut slide_model| {
slide_model.as_mut().data_changed( slide_model.as_mut().data_changed(
&model_index, &index,
&model_index, &index,
&vector_roles, &roles,
) )
}); }) {
match result {
Ok(_o) => { Ok(_o) => {
debug!("Success in creating qt_thread") debug!("Success in creating qt_thread")
} }
@ -466,14 +456,7 @@ impl slide_model::SlideModel {
} }
let count = self.as_ref().count; let count = self.as_ref().count;
self.as_mut().set_count(count + 1); self.as_mut().set_count(count + 1);
let thread = self.qt_thread(); self.as_mut().add_video_thumbnail(index);
thread::spawn(move || {
thread
.queue(move |slidemodel| {
slidemodel.add_video_thumbnail(index);
})
.unwrap();
});
} }
pub fn insert_item_from_service( pub fn insert_item_from_service(
@ -1232,6 +1215,29 @@ impl slide_model::SlideModel {
_ => 0, _ => 0,
} }
} }
fn get_indices(
self: Pin<&mut Self>,
item_id: i32,
role: SlideRoles,
) -> (usize, QModelIndex, QVector_i32) {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(role));
if let Some(index) =
self.as_ref().slides.iter().enumerate().nth(item_id)
{
let model_index = self.as_ref().index(
index as i32,
0,
&QModelIndex::default(),
);
(index, model_index, vector_roles)
} else {
error!(item_id, "This item appears to be missing");
(0, QModelIndex::default(), vector_roles)
}
}
} }
// QAbstractListModel implementation // QAbstractListModel implementation