still trying to figure out video db stuff
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-25 11:11:31 -05:00
parent a019dc235d
commit 5cb53cbe72
5 changed files with 63 additions and 95 deletions

View file

@ -245,7 +245,7 @@ pub async fn update_video_in_db(
.to_str() .to_str()
.map(std::string::ToString::to_string) .map(std::string::ToString::to_string)
.unwrap_or_default(); .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"#, r#"UPDATE videos SET title = $2, file_path = $3, start_time = $4, end_time = $5, loop = $6 WHERE id = $1"#,
video.id, video.id,
video.title, video.title,
@ -255,10 +255,15 @@ pub async fn update_video_in_db(
video.looping, video.looping,
) )
.execute(&mut db.detach()) .execute(&mut db.detach())
.await .await.into_diagnostic();
.into_diagnostic()?;
Ok(()) match result {
Ok(_) => Ok(()),
Err(e) => {
error! {?e};
Err(e)
}
}
} }
pub async fn get_video_from_db( pub async fn get_video_from_db(

View file

@ -141,6 +141,7 @@ enum Message {
Present(presenter::Message), Present(presenter::Message),
Library(library::Message), Library(library::Message),
SongEditor(song_editor::Message), SongEditor(song_editor::Message),
VideoEditor(video_editor::Message),
File(PathBuf), File(PathBuf),
OpenWindow, OpenWindow,
CloseWindow(Option<window::Id>), CloseWindow(Option<window::Id>),
@ -173,7 +174,6 @@ enum Message {
Save(Option<PathBuf>), Save(Option<PathBuf>),
SaveAs, SaveAs,
OpenSettings, OpenSettings,
VideoEditor(video_editor::Message),
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]

View file

@ -392,21 +392,28 @@ impl<'a> Library {
return Action::None; return Action::None;
} }
match self if self
.song_library .song_library
.update_item(song.clone(), index) .update_item(song.clone(), index)
.is_err()
{ {
Ok(()) => { error!("Couldn't update song in model");
return Action::Task( return Action::None;
Task::future(self.db.acquire()).and_then( };
move |conn| {
song_db_update(&song, conn) return Action::Task(
}, Task::future(self.db.acquire()).and_then(
), move |conn| {
); Task::perform(
} update_song_in_db(
Err(_) => todo!(), song.to_owned(),
} conn,
),
|_| Message::SongChanged,
)
},
),
);
} }
Message::SongChanged => { Message::SongChanged => {
// self.song_library.update_item(song, index); // self.song_library.update_item(song, index);
@ -423,6 +430,15 @@ impl<'a> Library {
return Action::None; 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 match self
.image_library .image_library
.update_item(image.clone(), index) .update_item(image.clone(), index)
@ -457,21 +473,28 @@ impl<'a> Library {
return Action::None; return Action::None;
} }
match self if self
.video_library .video_library
.update_item(video.clone(), index) .update_item(video.clone(), index)
.is_err()
{ {
Ok(()) => { error!("Couldn't update video in model");
return Action::Task( return Action::None;
Task::future(self.db.acquire()).and_then( };
move |conn| {
video_db_update(&video, conn) return Action::Task(
}, Task::future(self.db.acquire()).and_then(
), move |conn| {
); Task::perform(
} update_video_in_db(
Err(_) => todo!(), video.to_owned(),
} conn,
),
|_| Message::VideoChanged,
)
},
),
);
} }
Message::VideoChanged => debug!("vid shoulda changed"), Message::VideoChanged => debug!("vid shoulda changed"),
Message::UpdatePresentation(presentation) => { Message::UpdatePresentation(presentation) => {
@ -967,54 +990,6 @@ async fn add_videos() -> Option<Vec<Video>> {
) )
} }
fn video_db_update(
video: &Video,
conn: PoolConnection<Sqlite>,
) -> Task<Message> {
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<Sqlite>,
) -> Task<Message> {
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<SqlitePool> { async fn add_db() -> Result<SqlitePool> {
let mut data = dirs::data_local_dir().unwrap(); let mut data = dirs::data_local_dir().unwrap();
data.push("lumina"); data.push("lumina");

View file

@ -9,7 +9,6 @@ use cosmic::{
widget::{ widget::{
button, combo_box, container, horizontal_space, icon, button, combo_box, container, horizontal_space, icon,
progress_bar, scrollable, text, text_editor, text_input, progress_bar, scrollable, text, text_editor, text_input,
vertical_space,
}, },
Element, Task, Element, Task,
}; };

View file

@ -1,32 +1,20 @@
use std::{io, path::PathBuf, sync::Arc}; use std::{io, path::PathBuf};
use cosmic::{ use cosmic::{
dialog::file_chooser::{open::Dialog, FileFilter}, dialog::file_chooser::{open::Dialog, FileFilter},
iced::{alignment::Vertical, Length}, iced::{alignment::Vertical, Length},
iced_wgpu::graphics::text::cosmic_text::fontdb,
iced_widget::{column, row}, iced_widget::{column, row},
theme, theme,
widget::{ widget::{
button, combo_box, container, horizontal_space, icon, button, container, horizontal_space, icon, progress_bar,
progress_bar, scrollable, text, text_editor, text_input, text, text_input, Space,
vertical_space, Space,
}, },
Element, Task, Element, Task,
}; };
use dirs::font_dir;
use iced_video_player::{Video, VideoPlayer}; use iced_video_player::{Video, VideoPlayer};
use rayon::iter::{IntoParallelIterator, ParallelIterator}; use tracing::{debug, error, warn};
use tracing::{debug, error};
use url::Url; 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)] #[derive(Debug)]
pub struct VideoEditor { pub struct VideoEditor {
pub video: Option<Video>, pub video: Option<Video>,
@ -98,6 +86,7 @@ impl VideoEditor {
}; };
} }
Message::Update(video) => { Message::Update(video) => {
warn!(?video);
return Action::UpdateVideo(video); return Action::UpdateVideo(video);
} }
Message::PickVideo => { Message::PickVideo => {
@ -115,7 +104,7 @@ impl VideoEditor {
}); });
return Action::Task(task); return Action::Task(task);
} }
_ => (), Message::None => (),
} }
Action::None Action::None
} }