Compare commits

...

2 commits

Author SHA1 Message Date
5d5ea1f78f update todo
Some checks are pending
/ test (push) Waiting to run
2025-10-20 14:09:38 -05:00
547a9b80f4 adding starting and ending indexes to pdfs
This will allow us to keep the library smart with the ability to split
our pdfs up into multiple presetations
2025-10-20 14:08:36 -05:00
3 changed files with 77 additions and 17 deletions

View file

@ -0,0 +1,6 @@
-- Add migration script here
ALTER TABLE presentations
ADD COLUMN starting_index INTEGER;
ALTER TABLE presentations
ADD COLUMN ending_index INTEGER;

View file

@ -24,8 +24,11 @@ use super::{
)] )]
pub enum PresKind { pub enum PresKind {
Html, Html,
Pdf {
starting_index: i32,
ending_index: i32,
},
#[default] #[default]
Pdf,
Generic, Generic,
} }
@ -50,22 +53,42 @@ impl PartialEq for Presentation {
impl From<PathBuf> for Presentation { impl From<PathBuf> for Presentation {
fn from(value: PathBuf) -> Self { fn from(value: PathBuf) -> Self {
let kind = match value
.extension()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
{
"pdf" => PresKind::Pdf,
"html" => PresKind::Html,
_ => PresKind::Generic,
};
let title = value let title = value
.file_name() .file_name()
.unwrap_or_default() .unwrap_or_default()
.to_str() .to_str()
.unwrap_or_default() .unwrap_or_default()
.to_string(); .to_string();
let kind = match value
.extension()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
{
"pdf" => {
if let Ok(document) = Document::open(&value.as_path())
{
if let Ok(count) = document.page_count() {
PresKind::Pdf {
starting_index: 0,
ending_index: count - 1,
}
} else {
PresKind::Pdf {
starting_index: 0,
ending_index: 0,
}
}
} else {
PresKind::Pdf {
starting_index: 0,
ending_index: 0,
}
}
}
"html" => PresKind::Html,
_ => PresKind::Generic,
};
Self { Self {
id: 0, id: 0,
title, title,
@ -250,7 +273,10 @@ impl FromRow<'_, SqliteRow> for Presentation {
kind: if row.try_get(3)? { kind: if row.try_get(3)? {
PresKind::Html PresKind::Html
} else { } else {
PresKind::Pdf PresKind::Pdf {
starting_index: row.try_get(4)?,
ending_index: row.try_get(5)?,
}
}, },
}) })
} }
@ -270,10 +296,11 @@ impl Model<Presentation> {
pub async fn load_from_db(&mut self, db: &mut SqliteConnection) { pub async fn load_from_db(&mut self, db: &mut SqliteConnection) {
let result = query!( let result = query!(
r#"SELECT id as "id: i32", title, file_path as "path", html from presentations"# r#"SELECT id as "id: i32", title, file_path as "path", html, starting_index, ending_index from presentations"#
) )
.fetch_all(db) .fetch_all(db)
.await; .await;
match result { match result {
Ok(v) => { Ok(v) => {
for presentation in v { for presentation in v {
@ -284,7 +311,21 @@ impl Model<Presentation> {
kind: if presentation.html { kind: if presentation.html {
PresKind::Html PresKind::Html
} else { } else {
PresKind::Pdf if let (
Some(starting_index),
Some(ending_index),
) = (
presentation.starting_index,
presentation.ending_index,
) {
PresKind::Pdf {
starting_index: starting_index
as i32,
ending_index: ending_index as i32,
}
} else {
PresKind::Generic
}
}, },
}); });
} }
@ -341,6 +382,16 @@ pub async fn update_presentation_in_db(
.unwrap_or_default(); .unwrap_or_default();
let html = presentation.kind == PresKind::Html; let html = presentation.kind == PresKind::Html;
let mut db = db.detach(); let mut db = db.detach();
let mut starting_index = 0;
let mut ending_index = 0;
if let PresKind::Pdf {
starting_index: s_index,
ending_index: e_index,
} = presentation.get_kind()
{
starting_index = *s_index;
ending_index = *e_index;
};
let id = presentation.id; let id = presentation.id;
if let Err(e) = if let Err(e) =
query!("SELECT id FROM presentations where id = $1", id) query!("SELECT id FROM presentations where id = $1", id)
@ -357,11 +408,13 @@ pub async fn update_presentation_in_db(
debug!(?e, "Presentation not found"); debug!(?e, "Presentation not found");
max += 1; max += 1;
let result = query!( let result = query!(
r#"INSERT into presentations VALUES($1, $2, $3, $4)"#, r#"INSERT into presentations VALUES($1, $2, $3, $4, $5, $6)"#,
max, max,
presentation.title, presentation.title,
path, path,
html, html,
starting_index,
ending_index,
) )
.execute(&mut db) .execute(&mut db)
.await .await

View file

@ -2,8 +2,7 @@
* TODO [#A] Need to fix tests now that the basic app is working * TODO [#A] Need to fix tests now that the basic app is working
* TODO [#A] Create a view of all slides in a PDF presenation and allow for a way to split the presentation up but a right click menu for the presentation. * TODO [#A] Allow for a way to split the presentation up but a right click menu for the presentation.
* TODO [#A] Text could be built by using SVG instead of the text element. Maybe I could construct my own text element even * TODO [#A] Text could be built by using SVG instead of the text element. Maybe I could construct my own text element even
This does almost work. There is a clear amount of lag or rather hang up since switching to the =text_svg= element. I think I may only keep it till I can figure out how to do strokes and shadows in iced's normal text element. This does almost work. There is a clear amount of lag or rather hang up since switching to the =text_svg= element. I think I may only keep it till I can figure out how to do strokes and shadows in iced's normal text element.
@ -34,6 +33,8 @@ This will need to be matched on for the =TextAlignment= from the user
* TODO [#C] Figure out why the Video element seems to have problems when moving the mouse around * TODO [#C] Figure out why the Video element seems to have problems when moving the mouse around
* DONE [#A] Create a view of all slides in a PDF presenation
* DONE [#A] Develop DnD for library items * DONE [#A] Develop DnD for library items
This is limited by the fact that I need to develop this in cosmic. I am honestly thinking that I'll need to build my own drag and drop system or at least work with system76 to fix their dnd system on other systems. This is limited by the fact that I need to develop this in cosmic. I am honestly thinking that I'll need to build my own drag and drop system or at least work with system76 to fix their dnd system on other systems.