From e8b042df5437378908fe98321ce6610d8bf75d75 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 27 Apr 2023 14:17:59 -0500 Subject: [PATCH] Preparing to add html as a presentation option --- src/qml/presenter/Presentation.qml | 1 + src/qml/presenter/PresentationWindow.qml | 1 + src/qml/presenter/Slide.qml | 8 + src/rust/models.rs | 1 + src/rust/presentation_model.rs | 25 +- src/rust/schema.rs | 1 + src/rust/slide_obj.rs | 3 + src/rust/song_model.rs | 313 ++--------------------- 8 files changed, 52 insertions(+), 301 deletions(-) diff --git a/src/qml/presenter/Presentation.qml b/src/qml/presenter/Presentation.qml index c263d40..c0bdc0a 100644 --- a/src/qml/presenter/Presentation.qml +++ b/src/qml/presenter/Presentation.qml @@ -121,6 +121,7 @@ FocusScope { anchors.centerIn: parent itemType: SlideObject.ty imageSource: SlideObject.imageBackground + webSource: SlideObject.html videoSource: SlideObject.videoBackground audioSource: SlideObject.audio chosenFont: SlideObject.font diff --git a/src/qml/presenter/PresentationWindow.qml b/src/qml/presenter/PresentationWindow.qml index a154f3b..e77d9c4 100644 --- a/src/qml/presenter/PresentationWindow.qml +++ b/src/qml/presenter/PresentationWindow.qml @@ -35,6 +35,7 @@ Window { id: presentationSlide anchors.fill: parent imageSource: SlideObject.imageBackground + webSource: SlideObject.html videoSource: presentationWindow.visible ? SlideObject.videoBackground : "" audioSource: SlideObject.audio text: SlideObject.text diff --git a/src/qml/presenter/Slide.qml b/src/qml/presenter/Slide.qml index 0cfc615..a15fa46 100644 --- a/src/qml/presenter/Slide.qml +++ b/src/qml/presenter/Slide.qml @@ -3,6 +3,7 @@ import QtQuick.Controls 2.15 as Controls import QtQuick.Layouts 1.15 import QtMultimedia 5.15 /* import QtAudioEngine 1.15 */ +import QtWebEngine 1.10 import QtGraphicalEffects 1.15 import org.kde.kirigami 2.13 as Kirigami import "./" as Presenter @@ -18,6 +19,7 @@ Item { property real textSize: 50 property bool dropShadow: false property url imageSource + property url webSource property url videoSource property url audioSource property bool vidLoop @@ -165,6 +167,12 @@ Item { } } } + + WebEngine { + id: web + anchors.fill: parent + source: webSource + } } function changeText(text) { diff --git a/src/rust/models.rs b/src/rust/models.rs index e387b14..d605302 100644 --- a/src/rust/models.rs +++ b/src/rust/models.rs @@ -23,6 +23,7 @@ pub struct Presentation { pub title: String, pub path: String, pub page_count: Option, + pub html: bool, } #[derive(Queryable)] diff --git a/src/rust/presentation_model.rs b/src/rust/presentation_model.rs index 399fd12..65e4548 100644 --- a/src/rust/presentation_model.rs +++ b/src/rust/presentation_model.rs @@ -5,6 +5,7 @@ mod presentation_model { use crate::schema::presentations::dsl::*; use diesel::sqlite::SqliteConnection; use diesel::{delete, insert_into, prelude::*}; + // use sqlx::Connection; use std::path::{Path, PathBuf}; unsafe extern "C++" { @@ -33,6 +34,7 @@ mod presentation_model { pub struct Presentation { id: i32, title: QString, + html: bool, path: QString, } @@ -57,6 +59,7 @@ mod presentation_model { IdRole, PathRole, TitleRole, + HtmlRole, } // use crate::entities::{presentations, prelude::Presentations}; @@ -74,6 +77,8 @@ mod presentation_model { #[qinvokable] pub fn setup(mut self: Pin<&mut Self>) { let db = &mut self.as_mut().get_db(); + // let table_info = diesel::sql_query("PRAGMA table_info(presentations)").load(db); + // println!("{:?}", table_info); let results = presentations .load::(db) .expect("Error loading presentations"); @@ -85,6 +90,7 @@ mod presentation_model { println!("{}", presentation.title); println!("{}", presentation.id); println!("{}", presentation.path); + println!("{}", presentation.html); println!("--------------"); if self.as_mut().highest_id() < &presentation.id { self.as_mut().set_highest_id(presentation.id); @@ -93,6 +99,7 @@ mod presentation_model { let img = self::Presentation { id: presentation.id, title: QString::from(&presentation.title), + html: false, path: QString::from(&presentation.path), }; @@ -149,11 +156,15 @@ mod presentation_model { let presentation_id = self.rust().highest_id + 1; let presentation_title = QString::from(name); let presentation_path = url.to_qstring(); + println!("{:?}", file_path.extension().unwrap()); + let presentation_html = file_path.extension().unwrap() == std::ffi::OsStr::new(".html"); - if self - .as_mut() - .add_item(presentation_id, presentation_title, presentation_path) - { + if self.as_mut().add_item( + presentation_id, + presentation_title, + presentation_path, + presentation_html, + ) { println!("filename: {:?}", name); self.as_mut().set_highest_id(presentation_id); } else { @@ -167,12 +178,14 @@ mod presentation_model { presentation_id: i32, presentation_title: QString, presentation_path: QString, + presentation_html: bool, ) -> bool { let db = &mut self.as_mut().get_db(); // println!("{:?}", db); let presentation = self::Presentation { id: presentation_id, title: presentation_title.clone(), + html: false, path: presentation_path.clone(), }; println!("{:?}", presentation); @@ -182,6 +195,7 @@ mod presentation_model { id.eq(&presentation_id), title.eq(&presentation_title.to_string()), path.eq(&presentation_path.to_string()), + html.eq(&presentation_html), )) .execute(db); println!("{:?}", result); @@ -236,6 +250,7 @@ mod presentation_model { Role::IdRole => 0, Role::TitleRole => 1, Role::PathRole => 2, + Role::HtmlRole => 3, _ => 0, } } @@ -286,6 +301,7 @@ mod presentation_model { 0 => QVariant::from(&presentation.id), 1 => QVariant::from(&presentation.title), 2 => QVariant::from(&presentation.path), + 3 => QVariant::from(&presentation.html), _ => QVariant::default(), }; } @@ -305,6 +321,7 @@ mod presentation_model { roles.insert(0, cxx_qt_lib::QByteArray::from("id")); roles.insert(1, cxx_qt_lib::QByteArray::from("title")); roles.insert(2, cxx_qt_lib::QByteArray::from("filePath")); + roles.insert(3, cxx_qt_lib::QByteArray::from("html")); roles } diff --git a/src/rust/schema.rs b/src/rust/schema.rs index d957587..316fb04 100644 --- a/src/rust/schema.rs +++ b/src/rust/schema.rs @@ -17,6 +17,7 @@ diesel::table! { path -> Text, #[sql_name = "pageCount"] page_count -> Nullable, + html -> Bool, } } diff --git a/src/rust/slide_obj.rs b/src/rust/slide_obj.rs index 8fe6c73..6137d20 100644 --- a/src/rust/slide_obj.rs +++ b/src/rust/slide_obj.rs @@ -46,6 +46,8 @@ mod slide_obj { #[qproperty] video_background: QString, #[qproperty] + html: QString, + #[qproperty] vtext_alignment: QString, #[qproperty] htext_alignment: QString, @@ -70,6 +72,7 @@ mod slide_obj { ty: QString::from(""), audio: QString::from(""), image_background: QString::from(""), + html: QString::from(""), video_background: QString::from(""), vtext_alignment: QString::from(""), htext_alignment: QString::from(""), diff --git a/src/rust/song_model.rs b/src/rust/song_model.rs index 4e26ee8..b641ea0 100644 --- a/src/rust/song_model.rs +++ b/src/rust/song_model.rs @@ -33,16 +33,17 @@ mod song_model { pub struct Song { id: i32, title: QString, - lyrics: QString, - author: QString, - ccli: QString, - audio: QString, - verse_order: QString, - background: QString, - background_type: QString, - horizontal_text_alignment: QString, - vertical_text_alignment: QString, - font: QString, + title: String, + lyrics: String, + author: String, + ccli: String, + audio: String, + verse_order: String, + background: String, + background_type: String, + horizontal_text_alignment: String, + vertical_text_alignment: String, + font: String, font_size: i32, } @@ -92,7 +93,7 @@ mod song_model { } #[qinvokable] - pub fn setup(mut self: Pin<&mut Self>) { + pub fn test_database(mut self: Pin<&mut Self>) { let db = &mut self.as_mut().get_db(); let results = songs .load::(db) @@ -124,12 +125,14 @@ mod song_model { } #[qinvokable] - pub fn delete_song(mut self: Pin<&mut Self>, index: i32) -> bool { + pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool { if index < 0 || (index as usize) >= self.songs().len() { return false; } let db = &mut self.as_mut().get_db(); + let song_id = self.songs().get(index as usize).unwrap().id; + let result = delete(songs.filter(id.eq(song_id))).execute(db); match result { @@ -159,11 +162,6 @@ mod song_model { // self.rust().db = db; } - #[qinvokable] - pub fn new_song(mut self: Pin<&mut Self>) { - todo!(); - } - #[qinvokable] pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) { println!("LETS INSERT THIS SUCKER!"); @@ -251,102 +249,6 @@ mod song_model { } } - #[qinvokable] - pub fn update_lyrics( - mut self: Pin<&mut Self>, - index: i32, - updated_lyrics: QString, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::LyricsRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(lyrics.eq(updated_lyrics.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.lyrics = updated_lyrics; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_audio(mut self: Pin<&mut Self>, index: i32, updated_audio: QString) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::AudioRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(audio.eq(updated_audio.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.audio = updated_audio; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_author( - mut self: Pin<&mut Self>, - index: i32, - updated_author: QString, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::AuthorRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(author.eq(updated_author.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.author = updated_author; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_ccli(mut self: Pin<&mut Self>, index: i32, updated_ccli: QString) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::CcliRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(ccli.eq(updated_ccli.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.ccli = updated_ccli; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - #[qinvokable] pub fn update_file_path( mut self: Pin<&mut Self>, @@ -374,190 +276,7 @@ mod song_model { } #[qinvokable] - pub fn update_verse_order( - mut self: Pin<&mut Self>, - index: i32, - updated_verse_order: QString, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::VerseOrderRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(verse_order.eq(updated_verse_order.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.verse_order = updated_verse_order; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_background( - mut self: Pin<&mut Self>, - index: i32, - updated_background: QString, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::BackgroundRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(background.eq(updated_background.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.background = updated_background; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_background_type( - mut self: Pin<&mut Self>, - index: i32, - updated_background_type: QString, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::BackgroundTypeRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(background_type.eq(updated_background_type.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.background_type = updated_background_type; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_horizontal_text_alignment( - mut self: Pin<&mut Self>, - index: i32, - updated_horizontal_text_alignment: QString, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::HorizontalTextAlignmentRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(horizontal_text_alignment.eq(updated_horizontal_text_alignment.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.horizontal_text_alignment = updated_horizontal_text_alignment; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_vertical_text_alignment( - mut self: Pin<&mut Self>, - index: i32, - updated_vertical_text_alignment: QString, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::VerticalTextAlignmentRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(vertical_text_alignment.eq(updated_vertical_text_alignment.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.vertical_text_alignment = updated_vertical_text_alignment; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_font(mut self: Pin<&mut Self>, index: i32, updated_font: QString) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::FontRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(font.eq(updated_font.to_string())) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.font = updated_font; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn update_font_size( - mut self: Pin<&mut Self>, - index: i32, - updated_font_size: i32, - ) -> bool { - let mut vector_roles = QVector_i32::default(); - vector_roles.append(self.as_ref().get_role(Role::FontSizeRole)); - let model_index = &self.as_ref().index(index, 0, &QModelIndex::default()); - - let db = &mut self.as_mut().get_db(); - let result = update(songs.filter(id.eq(index))) - .set(font_size.eq(updated_font_size)) - .execute(db); - match result { - Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.font_size = updated_font_size; - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true - } - Err(_e) => false, - } - } - - #[qinvokable] - pub fn get_lyric_list(mut self: Pin<&mut Self>, index: i32) -> QList_QString { - todo!(); - } - - #[qinvokable] - pub fn get_song(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant { + pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant { println!("{index}"); let mut qvariantmap = QMap_QString_QVariant::default(); let idx = self.index(index, 0, &QModelIndex::default());