making presentation_editor only need one page at a time
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-30 05:51:33 -05:00
parent ee45a11a0f
commit 19e8fbcc35
2 changed files with 100 additions and 42 deletions

View file

@ -1182,10 +1182,43 @@ impl cosmic::Application for App {
Message::AddServiceItem(index, item) => { Message::AddServiceItem(index, item) => {
let item_index = item.0 .1; let item_index = item.0 .1;
let kind = item.0 .0; let kind = item.0 .0;
let mut item;
match kind { match kind {
core::model::LibraryKind::Song => todo!(), core::model::LibraryKind::Song => {
core::model::LibraryKind::Video => todo!(), let Some(library) = self.library.as_mut()
core::model::LibraryKind::Image => todo!(), else {
return Task::none();
};
let Some(song) = library.get_song(item_index)
else {
return Task::none();
};
item = song.to_service_item();
}
core::model::LibraryKind::Video => {
let Some(library) = self.library.as_mut()
else {
return Task::none();
};
let Some(video) =
library.get_video(item_index)
else {
return Task::none();
};
item = video.to_service_item();
}
core::model::LibraryKind::Image => {
let Some(library) = self.library.as_mut()
else {
return Task::none();
};
let Some(image) =
library.get_image(item_index)
else {
return Task::none();
};
item = image.to_service_item();
}
core::model::LibraryKind::Presentation => { core::model::LibraryKind::Presentation => {
let Some(library) = self.library.as_mut() let Some(library) = self.library.as_mut()
else { else {
@ -1196,7 +1229,9 @@ impl cosmic::Application for App {
else { else {
return Task::none(); return Task::none();
}; };
let mut item = presentation.to_service_item(); item = presentation.to_service_item();
}
}
item.slides = item item.slides = item
.slides .slides
.into_par_iter() .into_par_iter()
@ -1209,10 +1244,7 @@ impl cosmic::Application for App {
}) })
.collect(); .collect();
self.service.insert(index, item); self.service.insert(index, item);
self.presenter self.presenter.update_items(self.service.clone());
.update_items(self.service.clone());
}
}
Task::none() Task::none()
} }
Message::RemoveServiceItem(index) => { Message::RemoveServiceItem(index) => {

View file

@ -10,20 +10,25 @@ use cosmic::{
iced_widget::{column, row}, iced_widget::{column, row},
theme, theme,
widget::{ widget::{
button, container, horizontal_space, icon, image, text, self, button, container, horizontal_space, icon,
text_input, Space, image::{self, Handle},
text, text_input, Space,
}, },
Element, Task, Element, Task,
}; };
use miette::IntoDiagnostic;
use mupdf::{Colorspace, Document, Matrix};
use tracing::{debug, error, warn}; use tracing::{debug, error, warn};
#[derive(Debug)] #[derive(Debug)]
pub struct PresentationEditor { pub struct PresentationEditor {
pub presentation: Option<Presentation>, pub presentation: Option<Presentation>,
slides: Option<Vec<Slide>>, document: Option<Document>,
current_slide: Option<Handle>,
page_count: Option<i32>,
current_slide_index: Option<i32>,
title: String, title: String,
editing: bool, editing: bool,
current_slide: i16,
} }
pub enum Action { pub enum Action {
@ -46,10 +51,12 @@ impl PresentationEditor {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
presentation: None, presentation: None,
slides: None, document: None,
title: "Death was Arrested".to_string(), title: "Death was Arrested".to_string(),
editing: false, editing: false,
current_slide: 0, current_slide: None,
current_slide_index: None,
page_count: None,
} }
} }
pub fn update(&mut self, message: Message) -> Action { pub fn update(&mut self, message: Message) -> Action {
@ -57,12 +64,40 @@ impl PresentationEditor {
Message::ChangePresentation(presentation) => { Message::ChangePresentation(presentation) => {
self.presentation = Some(presentation.clone()); self.presentation = Some(presentation.clone());
self.title = presentation.title.clone(); self.title = presentation.title.clone();
self.document =
Document::open(&presentation.path.as_path()).ok();
self.page_count = self
.document
.as_ref()
.and_then(|doc| doc.page_count().ok());
warn!("changing presentation"); warn!("changing presentation");
let Ok(slides) = presentation.to_slides() else { self.current_slide =
return Action::None; self.document.as_ref().and_then(|doc| {
let page = doc.load_page(0).ok()?;
let matrix = Matrix::IDENTITY;
let colorspace = Colorspace::device_rgb();
let Ok(pixmap) = page
.to_pixmap(
&matrix,
&colorspace,
true,
true,
)
.into_diagnostic()
else {
error!(
"Can't turn this page into pixmap"
);
return None;
}; };
self.slides = Some(slides); debug!(?pixmap);
self.current_slide = 0; Some(Handle::from_rgba(
pixmap.width(),
pixmap.height(),
pixmap.samples().to_vec(),
))
});
self.current_slide_index = Some(0);
return self.update(Message::Update(presentation)); return self.update(Message::Update(presentation));
} }
Message::ChangeTitle(title) => { Message::ChangeTitle(title) => {
@ -110,21 +145,12 @@ impl PresentationEditor {
} }
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
let container = if let Some(slides) = &self.slides { let container = if let Some(slide) = &self.current_slide {
if let Some(slide) =
slides.get(self.current_slide as usize)
{
container( container(
image(slide.pdf_page().unwrap_or( widget::image(slide).content_fit(ContentFit::Cover),
image::Handle::from_path("res/chad.png"),
))
.content_fit(ContentFit::Cover),
) )
} else { } else {
container(Space::new(0, 0)) container(Space::new(0, 0))
}
} else {
container(Space::new(0, 0))
}; };
let column = column![ let column = column![
self.toolbar(), self.toolbar(),