From 70eadeadb2bbb70f041831131ffc644c0bb43b7f Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 20 Sep 2023 06:15:48 -0500 Subject: [PATCH] update width --- src/rust/ffmpeg.rs | 9 +++-- src/rust/file_helper.rs | 5 ++- src/rust/lib.rs | 2 +- src/rust/models.rs | 7 +++- src/rust/reveal_js.rs | 6 ++- src/rust/schema.rs | 7 +++- src/rust/slide_obj.rs | 81 +++++++++++++++++++++++++++++------------ src/rust/ytdl.rs | 27 ++++++++++---- 8 files changed, 104 insertions(+), 40 deletions(-) diff --git a/src/rust/ffmpeg.rs b/src/rust/ffmpeg.rs index d0d71d8..8aaecac 100644 --- a/src/rust/ffmpeg.rs +++ b/src/rust/ffmpeg.rs @@ -13,7 +13,8 @@ pub fn bg_from_video(video: &Path) -> PathBuf { data_dir.push("librepresenter"); data_dir.push("thumbnails"); if !data_dir.exists() { - fs::create_dir(&data_dir).expect("Could not create thumbnails dir"); + fs::create_dir(&data_dir) + .expect("Could not create thumbnails dir"); } let mut screenshot = data_dir.clone(); screenshot.push(video.file_name().unwrap()); @@ -46,8 +47,10 @@ pub fn bg_from_video(video: &Path) -> PathBuf { } } let hours: i32 = hours.parse().unwrap_or_default(); - let mut minutes: i32 = minutes.parse().unwrap_or_default(); - let mut seconds: i32 = seconds.parse().unwrap_or_default(); + let mut minutes: i32 = + minutes.parse().unwrap_or_default(); + let mut seconds: i32 = + seconds.parse().unwrap_or_default(); minutes += hours * 60; seconds += minutes * 60; at_second = seconds / 5; diff --git a/src/rust/file_helper.rs b/src/rust/file_helper.rs index 574d8b7..d1ab84d 100644 --- a/src/rust/file_helper.rs +++ b/src/rust/file_helper.rs @@ -1,3 +1,5 @@ +// The purpose of this file is to provide validation +// of whether or not a file exists #[cxx_qt::bridge] mod file_helper { use cxx_qt_lib::QVariantValue; @@ -55,7 +57,8 @@ mod file_helper { let _file_string = file_string.strip_prefix("file://"); match _file_string { None => { - let _exists = Path::new(&file.to_string()).exists(); + let _exists = + Path::new(&file.to_string()).exists(); println!("{file} exists? {_exists}"); _exists } diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 6cf25ff..1a0d1a8 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -7,7 +7,7 @@ pub mod reveal_js; pub mod schema; mod service_item_model; mod service_thing; -mod settings; +pub mod settings; pub mod slide_model; mod slide_obj; pub mod song_model; diff --git a/src/rust/models.rs b/src/rust/models.rs index 21930f0..46e4586 100644 --- a/src/rust/models.rs +++ b/src/rust/models.rs @@ -1,8 +1,11 @@ use diesel::prelude::*; use diesel::sqlite::SqliteConnection; -use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; +use diesel_migrations::{ + embed_migrations, EmbeddedMigrations, MigrationHarness, +}; -pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("src/rust/migrations"); +pub const MIGRATIONS: EmbeddedMigrations = + embed_migrations!("src/rust/migrations"); pub fn run_migrations(conn: &mut SqliteConnection) -> bool { conn.run_pending_migrations(MIGRATIONS).unwrap(); diff --git a/src/rust/reveal_js.rs b/src/rust/reveal_js.rs index f368375..6479d15 100644 --- a/src/rust/reveal_js.rs +++ b/src/rust/reveal_js.rs @@ -3,11 +3,13 @@ use std::fs::read_to_string; pub fn count_slides_and_fragments(html_file_path: &str) -> i32 { // Read the HTML file - let html_content = read_to_string(html_file_path).expect("Failed to read HTML file"); + let html_content = read_to_string(html_file_path) + .expect("Failed to read HTML file"); // Split HTML content by slide delimiters let slide_delimiter = " = html_content.split(slide_delimiter).collect(); + let slide_content: Vec<&str> = + html_content.split(slide_delimiter).collect(); // Count slides and fragments let num_slides = slide_content.len() - 1; diff --git a/src/rust/schema.rs b/src/rust/schema.rs index 6da4465..9a25615 100644 --- a/src/rust/schema.rs +++ b/src/rust/schema.rs @@ -59,4 +59,9 @@ diesel::table! { } } -diesel::allow_tables_to_appear_in_same_query!(images, presentations, songs, videos,); +diesel::allow_tables_to_appear_in_same_query!( + images, + presentations, + songs, + videos, +); diff --git a/src/rust/slide_obj.rs b/src/rust/slide_obj.rs index b862bb3..4e84183 100644 --- a/src/rust/slide_obj.rs +++ b/src/rust/slide_obj.rs @@ -8,7 +8,8 @@ mod slide_obj { include!("cxx-qt-lib/qstring.h"); type QString = cxx_qt_lib::QString; include!("cxx-qt-lib/qmap.h"); - type QMap_QString_QVariant = cxx_qt_lib::QMap; + type QMap_QString_QVariant = + cxx_qt_lib::QMap; include!("cxx-qt-lib/qvariant.h"); type QVariant = cxx_qt_lib::QVariant; } @@ -87,7 +88,11 @@ mod slide_obj { impl qobject::SlideObj { #[qinvokable] - pub fn change_slide(mut self: Pin<&mut Self>, item: QMap_QString_QVariant, index: i32) { + pub fn change_slide( + mut self: Pin<&mut Self>, + item: QMap_QString_QVariant, + index: i32, + ) { println!("## Slide Details ##"); let text = item .get(&QString::from("text")) @@ -126,10 +131,15 @@ mod slide_obj { let image_background = item .get(&QString::from("imageBackground")) .unwrap_or(QVariant::from(&QString::from(""))); - if let Some(image_background) = image_background.value::() { - if &image_background != self.as_ref().image_background() { + if let Some(image_background) = + image_background.value::() + { + if &image_background + != self.as_ref().image_background() + { println!("image-bg: {image_background}"); - self.as_mut().set_image_background(image_background); + self.as_mut() + .set_image_background(image_background); } } else { println!("image-bg: empty"); @@ -137,17 +147,22 @@ mod slide_obj { let video_background = item .get(&QString::from("videoBackground")) .unwrap_or(QVariant::from(&QString::from(""))); - if let Some(video_background) = video_background.value::() { - if &video_background != self.as_ref().video_background() { + if let Some(video_background) = + video_background.value::() + { + if &video_background + != self.as_ref().video_background() + { println!("video-bg: {video_background}"); - self.as_mut().set_video_background(video_background); + self.as_mut() + .set_video_background(video_background); } } else { println!("video-bg: empty"); } - let font = item - .get(&QString::from("font")) - .unwrap_or(QVariant::from(&QString::from("Quicksand"))); + let font = item.get(&QString::from("font")).unwrap_or( + QVariant::from(&QString::from("Quicksand")), + ); if let Some(font) = font.value::() { if &font != self.as_ref().font() { println!("font: {font}"); @@ -159,10 +174,16 @@ mod slide_obj { let vtext_alignment = item .get(&QString::from("verticalTextAlignment")) .unwrap_or(QVariant::from(&QString::from("center"))); - if let Some(vtext_alignment) = vtext_alignment.value::() { - if &vtext_alignment != self.as_ref().vtext_alignment() { - println!("vertical-text-align: {vtext_alignment}"); - self.as_mut().set_vtext_alignment(vtext_alignment); + if let Some(vtext_alignment) = + vtext_alignment.value::() + { + if &vtext_alignment != self.as_ref().vtext_alignment() + { + println!( + "vertical-text-align: {vtext_alignment}" + ); + self.as_mut() + .set_vtext_alignment(vtext_alignment); } } else { println!("vertical-text-align: empty"); @@ -170,10 +191,16 @@ mod slide_obj { let htext_alignment = item .get(&QString::from("horizontalTextAlignment")) .unwrap_or(QVariant::from(&QString::from("center"))); - if let Some(htext_alignment) = htext_alignment.value::() { - if &htext_alignment != self.as_ref().htext_alignment() { - println!("horizontal-text-align: {htext_alignment}"); - self.as_mut().set_htext_alignment(htext_alignment); + if let Some(htext_alignment) = + htext_alignment.value::() + { + if &htext_alignment != self.as_ref().htext_alignment() + { + println!( + "horizontal-text-align: {htext_alignment}" + ); + self.as_mut() + .set_htext_alignment(htext_alignment); } } else { println!("horizontal-text-align: empty"); @@ -197,7 +224,8 @@ mod slide_obj { println!("looping: {looping}"); self.as_mut().set_looping(looping); let lp = looping; - self.as_mut().emit(Signals::LoopChanged { looping: &lp }); + self.as_mut() + .emit(Signals::LoopChanged { looping: &lp }); } } else { println!("looping: empty") @@ -230,18 +258,25 @@ mod slide_obj { println!("New slide index = {}", int); self.as_mut().set_slide_index(int); }; - self.as_mut().emit(Signals::SlideChanged { slide: &index }); + self.as_mut() + .emit(Signals::SlideChanged { slide: &index }); println!("## Slide End ##"); } #[qinvokable] - pub fn next(mut self: Pin<&mut Self>, next_item: QMap_QString_QVariant) -> bool { + pub fn next( + mut self: Pin<&mut Self>, + next_item: QMap_QString_QVariant, + ) -> bool { let new_id = self.as_ref().slide_index() + 1; self.as_mut().change_slide(next_item, new_id); true } #[qinvokable] - pub fn previous(mut self: Pin<&mut Self>, prev_item: QMap_QString_QVariant) -> bool { + pub fn previous( + mut self: Pin<&mut Self>, + prev_item: QMap_QString_QVariant, + ) -> bool { let new_id = self.as_ref().slide_index() - 1; self.as_mut().change_slide(prev_item, new_id); true diff --git a/src/rust/ytdl.rs b/src/rust/ytdl.rs index 13c4784..c7e3ef6 100644 --- a/src/rust/ytdl.rs +++ b/src/rust/ytdl.rs @@ -28,7 +28,10 @@ mod ytdl { impl qobject::Ytdl { #[qinvokable] - pub fn get_video(mut self: Pin<&mut Self>, url: QUrl) -> bool { + pub fn get_video( + mut self: Pin<&mut Self>, + url: QUrl, + ) -> bool { if !url.is_valid() { false } else { @@ -37,7 +40,8 @@ mod ytdl { data_dir.push("librepresenter"); data_dir.push("ytdl"); if !data_dir.exists() { - fs::create_dir(&data_dir).expect("Could not create ytdl dir"); + fs::create_dir(&data_dir) + .expect("Could not create ytdl dir"); } println!("{:?}", data_dir); self.as_mut().set_loading(true); @@ -53,25 +57,34 @@ mod ytdl { .download(true) .run() .unwrap(); - let output = ytdl.into_single_video().unwrap(); + let output = + ytdl.into_single_video().unwrap(); println!("{:?}", output.title); println!("{:?}", output.thumbnail); println!("{:?}", output.url); let title = QString::from(&output.title); - let thumbnail = QUrl::from(&output.thumbnail.unwrap_or_default()); + let thumbnail = QUrl::from( + &output.thumbnail.unwrap_or_default(), + ); let mut file = String::from(output_dirs); file.push_str("/"); file.push_str(&output.title); file.push_str("."); - file.push_str(&output.ext.unwrap_or_default()); + file.push_str( + &output.ext.unwrap_or_default(), + ); println!("{:?}", file); thread.queue(move |mut qobject_ytdl| { qobject_ytdl.as_mut().set_loaded(true); qobject_ytdl.as_mut().set_loading(false); qobject_ytdl.as_mut().set_title(title); - qobject_ytdl.as_mut().set_thumbnail(thumbnail); - qobject_ytdl.as_mut().set_file(QUrl::from(&file)); + qobject_ytdl + .as_mut() + .set_thumbnail(thumbnail); + qobject_ytdl + .as_mut() + .set_file(QUrl::from(&file)); }) }); true