This commit is contained in:
parent
8068b57e71
commit
09654aef94
4 changed files with 153 additions and 104 deletions
|
|
@ -15,7 +15,7 @@ use sqlx::{
|
|||
SqlitePool,
|
||||
};
|
||||
use std::path::{Path, PathBuf};
|
||||
use tracing::error;
|
||||
use tracing::{debug, error};
|
||||
|
||||
#[derive(
|
||||
Clone, Debug, Default, PartialEq, Serialize, Deserialize,
|
||||
|
|
|
|||
74
src/main.rs
74
src/main.rs
|
|
@ -50,6 +50,7 @@ use ui::EditorMode;
|
|||
|
||||
use crate::core::kinds::ServiceItemKind;
|
||||
use crate::ui::text_svg::{self};
|
||||
use crate::ui::video_editor::{self, VideoEditor};
|
||||
use crate::ui::widgets::draggable;
|
||||
|
||||
pub mod core;
|
||||
|
|
@ -124,6 +125,7 @@ struct App {
|
|||
library_open: bool,
|
||||
editor_mode: Option<EditorMode>,
|
||||
song_editor: SongEditor,
|
||||
video_editor: VideoEditor,
|
||||
searching: bool,
|
||||
search_query: String,
|
||||
search_results: Vec<ServiceItem>,
|
||||
|
|
@ -171,6 +173,7 @@ enum Message {
|
|||
Save(Option<PathBuf>),
|
||||
SaveAs,
|
||||
OpenSettings,
|
||||
VideoEditor(video_editor::Message),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
|
@ -324,6 +327,7 @@ impl cosmic::Application for App {
|
|||
library_open: true,
|
||||
editor_mode: None,
|
||||
song_editor,
|
||||
video_editor: VideoEditor::new(),
|
||||
searching: false,
|
||||
search_results: vec![],
|
||||
search_query: String::new(),
|
||||
|
|
@ -763,6 +767,27 @@ impl cosmic::Application for App {
|
|||
song_editor::Action::None => Task::none(),
|
||||
}
|
||||
}
|
||||
Message::VideoEditor(message) => {
|
||||
match self.video_editor.update(message) {
|
||||
video_editor::Action::Task(task) => {
|
||||
task.map(|m| {
|
||||
cosmic::Action::App(Message::VideoEditor(
|
||||
m,
|
||||
))
|
||||
})
|
||||
}
|
||||
video_editor::Action::UpdateVideo(video) => {
|
||||
if let Some(_) = &mut self.library {
|
||||
self.update(Message::Library(
|
||||
library::Message::UpdateVideo(video),
|
||||
))
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
video_editor::Action::None => Task::none(),
|
||||
}
|
||||
}
|
||||
Message::Present(message) => {
|
||||
// debug!(?message);
|
||||
if self.presentation_open
|
||||
|
|
@ -932,6 +957,8 @@ impl cosmic::Application for App {
|
|||
kind,
|
||||
index,
|
||||
))) => {
|
||||
match kind {
|
||||
core::model::LibraryKind::Song => {
|
||||
debug!(
|
||||
"Should get song at index: {:?}",
|
||||
index
|
||||
|
|
@ -947,6 +974,22 @@ impl cosmic::Application for App {
|
|||
"Should change songs to: {:?}",
|
||||
song
|
||||
);
|
||||
|
||||
return self.update(Message::SongEditor(
|
||||
song_editor::Message::ChangeSong(song),
|
||||
));
|
||||
},
|
||||
core::model::LibraryKind::Video => {
|
||||
let Some(lib_video) = library.get_video(index) else {
|
||||
return Task::none();
|
||||
};
|
||||
self.editor_mode = Some(kind.into());
|
||||
let video = lib_video.to_owned();
|
||||
return self.update(Message::VideoEditor(video_editor::Message::ChangeVideo(video)));
|
||||
},
|
||||
core::model::LibraryKind::Image => todo!(),
|
||||
core::model::LibraryKind::Presentation => todo!(),
|
||||
}
|
||||
}
|
||||
library::Action::DraggedItem(
|
||||
service_item,
|
||||
|
|
@ -961,9 +1004,7 @@ impl cosmic::Application for App {
|
|||
}
|
||||
}
|
||||
}
|
||||
self.update(Message::SongEditor(
|
||||
song_editor::Message::ChangeSong(song),
|
||||
))
|
||||
Task::none()
|
||||
}
|
||||
Message::File(file) => {
|
||||
self.file = file;
|
||||
|
|
@ -1283,8 +1324,20 @@ impl cosmic::Application for App {
|
|||
Container::new(horizontal_space().width(0))
|
||||
};
|
||||
|
||||
let song_editor =
|
||||
self.song_editor.view().map(Message::SongEditor);
|
||||
let editor = self.editor_mode.as_ref().map_or_else(
|
||||
|| Element::from(Space::new(0, 0)),
|
||||
|mode| match mode {
|
||||
EditorMode::Song => {
|
||||
self.song_editor.view().map(Message::SongEditor)
|
||||
}
|
||||
EditorMode::Image => todo!(),
|
||||
EditorMode::Video => {
|
||||
self.video_editor.view().map(Message::VideoEditor)
|
||||
}
|
||||
EditorMode::Presentation => todo!(),
|
||||
EditorMode::Slide => todo!(),
|
||||
},
|
||||
);
|
||||
|
||||
let service_row = row![
|
||||
service_list,
|
||||
|
|
@ -1331,12 +1384,13 @@ impl cosmic::Application for App {
|
|||
Container::new(horizontal_space())
|
||||
};
|
||||
|
||||
let main_area = if let Some(editor) = &self.editor_mode {
|
||||
container(song_editor)
|
||||
let main_area = self.editor_mode.as_ref().map_or_else(
|
||||
|| Container::new(service_row).center_y(Length::Fill),
|
||||
|_| {
|
||||
container(editor)
|
||||
.padding(cosmic::theme::spacing().space_xxl)
|
||||
} else {
|
||||
Container::new(service_row).center_y(Length::Fill)
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
let column = column![
|
||||
row![
|
||||
|
|
|
|||
|
|
@ -399,7 +399,9 @@ impl<'a> Library {
|
|||
Ok(()) => {
|
||||
return Action::Task(
|
||||
Task::future(self.db.acquire()).and_then(
|
||||
move |conn| update_in_db(&song, conn),
|
||||
move |conn| {
|
||||
song_db_update(&song, conn)
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -463,13 +465,7 @@ impl<'a> Library {
|
|||
return Action::Task(
|
||||
Task::future(self.db.acquire()).and_then(
|
||||
move |conn| {
|
||||
Task::perform(
|
||||
update_video_in_db(
|
||||
video.clone(),
|
||||
conn,
|
||||
),
|
||||
|_| Message::VideoChanged,
|
||||
)
|
||||
video_db_update(&video, conn)
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
@ -477,7 +473,7 @@ impl<'a> Library {
|
|||
Err(_) => todo!(),
|
||||
}
|
||||
}
|
||||
Message::VideoChanged => (),
|
||||
Message::VideoChanged => debug!("vid shoulda changed"),
|
||||
Message::UpdatePresentation(presentation) => {
|
||||
let Some((kind, index)) = self.editing_item else {
|
||||
error!("Not editing an item");
|
||||
|
|
@ -938,37 +934,12 @@ impl<'a> Library {
|
|||
items.into_iter().map(|item| item.1).collect()
|
||||
}
|
||||
|
||||
// fn update_item<C: Content>(self, item: C) -> Task<Message> {
|
||||
// let Some((kind, index)) = self.editing_item else {
|
||||
// error!("Not editing an item");
|
||||
// return Task::none();
|
||||
// };
|
||||
|
||||
// match kind {
|
||||
// LibraryKind::Song => todo!(),
|
||||
// LibraryKind::Video => todo!(),
|
||||
// LibraryKind::Image => {
|
||||
// match self
|
||||
// .image_library
|
||||
// .update_item(item as Image, index)
|
||||
// {
|
||||
// Ok(_) => Task::future(self.db.acquire())
|
||||
// .and_then(|conn| {
|
||||
// Task::perform(
|
||||
// update_image_in_db(item, conn),
|
||||
// |_| Message::ImageChanged,
|
||||
// )
|
||||
// }),
|
||||
// Err(_) => todo!(),
|
||||
// }
|
||||
// }
|
||||
// LibraryKind::Presentation => todo!(),
|
||||
// }
|
||||
// }
|
||||
pub fn get_video(&self, index: i32) -> Option<&Video> {
|
||||
self.video_library.get_item(index)
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_images() -> Option<Vec<Image>> {
|
||||
debug!("here man");
|
||||
let paths =
|
||||
Dialog::new().title("pick image").open_files().await.ok()?;
|
||||
Some(
|
||||
|
|
@ -983,7 +954,6 @@ async fn add_images() -> Option<Vec<Image>> {
|
|||
}
|
||||
|
||||
async fn add_videos() -> Option<Vec<Video>> {
|
||||
debug!("here man");
|
||||
let paths =
|
||||
Dialog::new().title("pick video").open_files().await.ok()?;
|
||||
Some(
|
||||
|
|
@ -997,7 +967,31 @@ async fn add_videos() -> Option<Vec<Video>> {
|
|||
)
|
||||
}
|
||||
|
||||
fn update_in_db(
|
||||
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> {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ pub mod slide_editor;
|
|||
pub mod song_editor;
|
||||
pub mod text_svg;
|
||||
pub mod video;
|
||||
pub mod video_editor;
|
||||
pub mod widgets;
|
||||
|
||||
pub enum EditorMode {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue