From 5cb53cbe72c87f693d1eaeeb7357317e7c138444 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 25 Sep 2025 11:11:31 -0500 Subject: [PATCH] still trying to figure out video db stuff --- src/core/videos.rs | 13 +++-- src/main.rs | 2 +- src/ui/library.rs | 119 ++++++++++++++++------------------------- src/ui/song_editor.rs | 1 - src/ui/video_editor.rs | 23 +++----- 5 files changed, 63 insertions(+), 95 deletions(-) diff --git a/src/core/videos.rs b/src/core/videos.rs index 5304717..428a64a 100644 --- a/src/core/videos.rs +++ b/src/core/videos.rs @@ -245,7 +245,7 @@ pub async fn update_video_in_db( .to_str() .map(std::string::ToString::to_string) .unwrap_or_default(); - query!( + let result = query!( r#"UPDATE videos SET title = $2, file_path = $3, start_time = $4, end_time = $5, loop = $6 WHERE id = $1"#, video.id, video.title, @@ -255,10 +255,15 @@ pub async fn update_video_in_db( video.looping, ) .execute(&mut db.detach()) - .await - .into_diagnostic()?; + .await.into_diagnostic(); - Ok(()) + match result { + Ok(_) => Ok(()), + Err(e) => { + error! {?e}; + Err(e) + } + } } pub async fn get_video_from_db( diff --git a/src/main.rs b/src/main.rs index d8d9223..088eb1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,6 +141,7 @@ enum Message { Present(presenter::Message), Library(library::Message), SongEditor(song_editor::Message), + VideoEditor(video_editor::Message), File(PathBuf), OpenWindow, CloseWindow(Option), @@ -173,7 +174,6 @@ enum Message { Save(Option), SaveAs, OpenSettings, - VideoEditor(video_editor::Message), } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/src/ui/library.rs b/src/ui/library.rs index 1bcea18..5c589df 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -392,21 +392,28 @@ impl<'a> Library { return Action::None; } - match self + if self .song_library .update_item(song.clone(), index) + .is_err() { - Ok(()) => { - return Action::Task( - Task::future(self.db.acquire()).and_then( - move |conn| { - song_db_update(&song, conn) - }, - ), - ); - } - Err(_) => todo!(), - } + error!("Couldn't update song in model"); + return Action::None; + }; + + return Action::Task( + Task::future(self.db.acquire()).and_then( + move |conn| { + Task::perform( + update_song_in_db( + song.to_owned(), + conn, + ), + |_| Message::SongChanged, + ) + }, + ), + ); } Message::SongChanged => { // self.song_library.update_item(song, index); @@ -423,6 +430,15 @@ impl<'a> Library { return Action::None; } + if self + .image_library + .update_item(image.clone(), index) + .is_err() + { + error!("Couldn't update image in model"); + return Action::None; + }; + match self .image_library .update_item(image.clone(), index) @@ -457,21 +473,28 @@ impl<'a> Library { return Action::None; } - match self + if self .video_library .update_item(video.clone(), index) + .is_err() { - Ok(()) => { - return Action::Task( - Task::future(self.db.acquire()).and_then( - move |conn| { - video_db_update(&video, conn) - }, - ), - ); - } - Err(_) => todo!(), - } + error!("Couldn't update video in model"); + return Action::None; + }; + + return Action::Task( + Task::future(self.db.acquire()).and_then( + move |conn| { + Task::perform( + update_video_in_db( + video.to_owned(), + conn, + ), + |_| Message::VideoChanged, + ) + }, + ), + ); } Message::VideoChanged => debug!("vid shoulda changed"), Message::UpdatePresentation(presentation) => { @@ -967,54 +990,6 @@ async fn add_videos() -> Option> { ) } -fn video_db_update( - video: &Video, - conn: PoolConnection, -) -> Task { - let video_title = video.title.clone(); - warn!("Should have updated video: {:?}", video_title); - Task::perform( - update_video_in_db(video.to_owned(), conn).map(move |r| { - match r { - Ok(()) => { - warn!( - "Should have updated video: {:?}", - video_title - ); - } - Err(e) => { - error!(?e); - } - } - }), - |()| Message::VideoChanged, - ) -} - -fn song_db_update( - song: &Song, - conn: PoolConnection, -) -> Task { - let song_title = song.title.clone(); - warn!("Should have updated song: {:?}", song_title); - Task::perform( - update_song_in_db(song.to_owned(), conn).map( - move |r| match r { - Ok(()) => { - warn!( - "Should have updated song: {:?}", - song_title - ); - } - Err(e) => { - error!(?e); - } - }, - ), - |()| Message::SongChanged, - ) -} - async fn add_db() -> Result { let mut data = dirs::data_local_dir().unwrap(); data.push("lumina"); diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index e388adc..0d62812 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -9,7 +9,6 @@ use cosmic::{ widget::{ button, combo_box, container, horizontal_space, icon, progress_bar, scrollable, text, text_editor, text_input, - vertical_space, }, Element, Task, }; diff --git a/src/ui/video_editor.rs b/src/ui/video_editor.rs index 2f90795..add8092 100644 --- a/src/ui/video_editor.rs +++ b/src/ui/video_editor.rs @@ -1,32 +1,20 @@ -use std::{io, path::PathBuf, sync::Arc}; +use std::{io, path::PathBuf}; use cosmic::{ dialog::file_chooser::{open::Dialog, FileFilter}, iced::{alignment::Vertical, Length}, - iced_wgpu::graphics::text::cosmic_text::fontdb, iced_widget::{column, row}, theme, widget::{ - button, combo_box, container, horizontal_space, icon, - progress_bar, scrollable, text, text_editor, text_input, - vertical_space, Space, + button, container, horizontal_space, icon, progress_bar, + text, text_input, Space, }, Element, Task, }; -use dirs::font_dir; use iced_video_player::{Video, VideoPlayer}; -use rayon::iter::{IntoParallelIterator, ParallelIterator}; -use tracing::{debug, error}; +use tracing::{debug, error, warn}; use url::Url; -use crate::{ - core::{service_items::ServiceTrait, slide::Slide, songs::Song}, - ui::{ - presenter::slide_view, slide_editor::SlideEditor, text_svg, - }, - Background, BackgroundKind, -}; - #[derive(Debug)] pub struct VideoEditor { pub video: Option