From 8cf2d48a16213749d80d2c1b39b025f696550d0b Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 1 May 2025 09:44:35 -0500 Subject: [PATCH] cargo fix --- src/core/images.rs | 10 +---- src/core/lisp.rs | 8 ++-- src/core/model.rs | 1 - src/core/presentations.rs | 10 +---- src/core/service_items.rs | 88 +++++++++++++++++++-------------------- src/core/slide.rs | 1 - src/core/songs.rs | 17 ++++---- src/core/videos.rs | 10 +---- src/lisp.rs | 4 +- src/main.rs | 15 ++++--- src/ui/library.rs | 6 +-- src/ui/presenter.rs | 21 ++++------ src/ui/song_editor.rs | 3 +- src/ui/text_svg.rs | 6 +-- 14 files changed, 85 insertions(+), 115 deletions(-) diff --git a/src/core/images.rs b/src/core/images.rs index 4eb16dd..beba760 100644 --- a/src/core/images.rs +++ b/src/core/images.rs @@ -3,7 +3,7 @@ use crate::{Background, Slide, SlideBuilder, TextAlignment}; use super::{ content::Content, kinds::ServiceItemKind, - model::{get_db, LibraryKind, Model}, + model::{LibraryKind, Model}, service_items::ServiceTrait, }; use crisp::types::{Keyword, Symbol, Value}; @@ -45,13 +45,7 @@ impl Content for Image { } fn background(&self) -> Option { - if let Ok(background) = - Background::try_from(self.path.clone()) - { - Some(background) - } else { - None - } + Background::try_from(self.path.clone()).ok() } fn subtext(&self) -> String { diff --git a/src/core/lisp.rs b/src/core/lisp.rs index ad795d2..af3c937 100644 --- a/src/core/lisp.rs +++ b/src/core/lisp.rs @@ -133,12 +133,12 @@ pub(crate) fn get_lists(exp: &Value) -> Vec { #[cfg(test)] mod test { - use std::fs::read_to_string; + - use lexpr::{parse::Options, Parser}; - use pretty_assertions::assert_eq; + + - use super::*; + // #[test] // fn test_list() { diff --git a/src/core/model.rs b/src/core/model.rs index 14ed67c..09d8663 100644 --- a/src/core/model.rs +++ b/src/core/model.rs @@ -4,7 +4,6 @@ use cosmic::iced::Executor; use miette::{miette, Result}; use sqlx::{Connection, SqliteConnection}; -use super::kinds::ServiceItemKind; #[derive(Debug, Clone)] pub struct Model { diff --git a/src/core/presentations.rs b/src/core/presentations.rs index 164a9dd..106f8c4 100644 --- a/src/core/presentations.rs +++ b/src/core/presentations.rs @@ -13,7 +13,7 @@ use crate::{Background, Slide, SlideBuilder, TextAlignment}; use super::{ content::Content, kinds::ServiceItemKind, - model::{get_db, LibraryKind, Model}, + model::{LibraryKind, Model}, service_items::ServiceTrait, }; @@ -57,13 +57,7 @@ impl Content for Presentation { } fn background(&self) -> Option { - if let Ok(background) = - Background::try_from(self.path.clone()) - { - Some(background) - } else { - None - } + Background::try_from(self.path.clone()).ok() } fn subtext(&self) -> String { diff --git a/src/core/service_items.rs b/src/core/service_items.rs index f84d231..f8d6655 100644 --- a/src/core/service_items.rs +++ b/src/core/service_items.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use cosmic::iced::clipboard::mime::{AllowedMimeTypes, AsMimeTypes}; use crisp::types::{Keyword, Symbol, Value}; -use miette::{miette, Result}; +use miette::Result; use tracing::{debug, error}; use crate::Slide; @@ -153,52 +153,50 @@ impl From<&Value> for ServiceItem { database_id: 0, kind: ServiceItemKind::Content(slide), } - } else { - if let Some(background) = - list.get(background_pos) - { - match background { - Value::List(item) => match &item[0] { - Value::Symbol(Symbol(s)) - if s == "image" => - { - Self::from(&Image::from( - background, - )) - } - Value::Symbol(Symbol(s)) - if s == "video" => - { - Self::from(&Video::from( - background, - )) - } - Value::Symbol(Symbol(s)) - if s == "presentation" => - { - Self::from( - &Presentation::from( - background, - ), - ) - } - _ => todo!(), - }, - _ => { - error!( - "There is no background here: {:?}", - background - ); - ServiceItem::default() + } else if let Some(background) = + list.get(background_pos) + { + match background { + Value::List(item) => match &item[0] { + Value::Symbol(Symbol(s)) + if s == "image" => + { + Self::from(&Image::from( + background, + )) } + Value::Symbol(Symbol(s)) + if s == "video" => + { + Self::from(&Video::from( + background, + )) + } + Value::Symbol(Symbol(s)) + if s == "presentation" => + { + Self::from( + &Presentation::from( + background, + ), + ) + } + _ => todo!(), + }, + _ => { + error!( + "There is no background here: {:?}", + background + ); + ServiceItem::default() } - } else { - error!( - "There is no background here: {:?}", - background_pos - ); - ServiceItem::default() } + } else { + error!( + "There is no background here: {:?}", + background_pos + ); + ServiceItem::default() } } Value::Symbol(Symbol(s)) if s == "song" => { @@ -342,7 +340,7 @@ mod test { use crate::core::presentations::PresKind; use super::*; - use pretty_assertions::{assert_eq, assert_ne}; + use pretty_assertions::assert_eq; fn test_song() -> Song { Song { diff --git a/src/core/slide.rs b/src/core/slide.rs index 662710a..ec267d6 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -1,6 +1,5 @@ // use cosmic::dialog::ashpd::url::Url; use crisp::types::{Keyword, Symbol, Value}; -use gstreamer::query::Uri; use iced_video_player::Video; use miette::{miette, Result}; use serde::{Deserialize, Serialize}; diff --git a/src/core/songs.rs b/src/core/songs.rs index 52f4b13..9b0d40a 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -8,14 +8,14 @@ use sqlx::{ pool::PoolConnection, query, sqlite::SqliteRow, FromRow, Row, Sqlite, SqliteConnection, SqlitePool, }; -use tracing::{debug, error}; +use tracing::error; use crate::{core::slide, Slide, SlideBuilder}; use super::{ content::Content, kinds::ServiceItemKind, - model::{get_db, LibraryKind, Model}, + model::{LibraryKind, Model}, service_items::ServiceTrait, slide::{Background, TextAlignment}, }; @@ -132,10 +132,7 @@ impl FromRow<'_, SqliteRow> for Song { }), background: { let string: String = row.try_get(7)?; - match Background::try_from(string) { - Ok(background) => Some(background), - Err(_) => None, - } + Background::try_from(string).ok() }, text_alignment: Some({ let horizontal_alignment: String = row.try_get(3)?; @@ -423,7 +420,7 @@ pub async fn update_song_in_db( if let Some(vo) = item.verse_order { vo.into_iter() .map(|mut s| { - s.push_str(" "); + s.push(' '); s }) .collect::() @@ -538,7 +535,7 @@ impl Song { lyric_list.push(lyric.to_string()); } else { // error!("NOT WORKING!"); - () + }; } // for lyric in lyric_list.iter() { @@ -556,7 +553,7 @@ mod test { use std::fs::read_to_string; use super::*; - use pretty_assertions::{assert_eq, assert_ne}; + use pretty_assertions::assert_eq; #[test] pub fn test_song_lyrics() { @@ -724,7 +721,7 @@ You saved my soul" let lisp = read_to_string("./test_song.lisp").expect("oops"); let lisp_value = crisp::reader::read(&lisp); match lisp_value { - Value::List(v) => v.get(0).unwrap().clone(), + Value::List(v) => v.first().unwrap().clone(), _ => Value::Nil, } } diff --git a/src/core/videos.rs b/src/core/videos.rs index c3fe4e0..c0c1dfb 100644 --- a/src/core/videos.rs +++ b/src/core/videos.rs @@ -3,7 +3,7 @@ use crate::{Background, SlideBuilder, TextAlignment}; use super::{ content::Content, kinds::ServiceItemKind, - model::{get_db, LibraryKind, Model}, + model::{LibraryKind, Model}, service_items::ServiceTrait, slide::Slide, }; @@ -50,13 +50,7 @@ impl Content for Video { } fn background(&self) -> Option { - if let Ok(background) = - Background::try_from(self.path.clone()) - { - Some(background) - } else { - None - } + Background::try_from(self.path.clone()).ok() } fn subtext(&self) -> String { diff --git a/src/lisp.rs b/src/lisp.rs index e5baa50..2406ea4 100644 --- a/src/lisp.rs +++ b/src/lisp.rs @@ -39,7 +39,7 @@ pub fn parse_lisp(value: Value) -> Vec { mod test { use std::{ fs::read_to_string, - path::{Path, PathBuf}, + path::PathBuf, }; use crate::{ @@ -47,7 +47,7 @@ mod test { images::Image, kinds::ServiceItemKind, service_items::ServiceTrait, songs::Song, videos::Video, }, - Background, Slide, SlideBuilder, TextAlignment, + Background, TextAlignment, }; use super::*; diff --git a/src/main.rs b/src/main.rs index 19d4f10..495b27e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ use clap::{command, Parser}; -use core::model::{get_db, LibraryKind}; use core::service_items::{ServiceItem, ServiceItemModel}; use core::slide::*; use core::songs::Song; @@ -16,11 +15,11 @@ use cosmic::widget::nav_bar::nav_bar_style; use cosmic::widget::segmented_button::Entity; use cosmic::widget::tooltip::Position as TPosition; use cosmic::widget::{ - button, horizontal_space, nav_bar, search_input, text_input, + button, horizontal_space, nav_bar, search_input, tooltip, Space, }; use cosmic::widget::{icon, slider}; -use cosmic::widget::{text, toggler}; +use cosmic::widget::text; use cosmic::{executor, Application, ApplicationExt, Element}; use cosmic::{prelude::*, theme}; use cosmic::{widget::Container, Theme}; @@ -332,7 +331,7 @@ impl cosmic::Application for App { ) .class(cosmic::theme::style::Button::HeaderBar) .on_press(Message::EditorToggle( - !self.editor_mode.is_some(), + self.editor_mode.is_none(), )), "Enter Edit Mode", TPosition::Bottom, @@ -721,7 +720,7 @@ impl cosmic::Application for App { let library = if self.library_open { Container::new(if let Some(library) = &self.library { - library.view().map(|m| Message::Library(m)) + library.view().map(Message::Library) } else { Space::new(0, 0).into() }) @@ -732,7 +731,7 @@ impl cosmic::Application for App { }; let song_editor = - self.song_editor.view().map(|m| Message::SongEditor(m)); + self.song_editor.view().map(Message::SongEditor); let row = row![ Container::new( @@ -880,8 +879,8 @@ where #[cfg(test)] mod test { - use super::*; - use pretty_assertions::assert_eq; + + fn test_slide() -> String { let slide = r#"(slide (image :source "./somehting.jpg" :fill cover diff --git a/src/ui/library.rs b/src/ui/library.rs index c89ed15..a239209 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -8,13 +8,13 @@ use cosmic::{ widget::{ button, container, horizontal_space, icon, mouse_area, responsive, row, scrollable, text, text_input, Container, - DndSource, Icon, Space, Widget, + DndSource, Space, Widget, }, Element, Task, }; -use miette::{miette, IntoDiagnostic, Result}; +use miette::{IntoDiagnostic, Result}; use sqlx::{ - pool::PoolConnection, Sqlite, SqliteConnection, SqlitePool, + pool::PoolConnection, Sqlite, SqlitePool, }; use tracing::{debug, error, warn}; diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index 8526c4e..ea33ea4 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -1,4 +1,4 @@ -use miette::{miette, IntoDiagnostic, Result}; +use miette::{IntoDiagnostic, Result}; use std::{fs::File, io::BufReader, path::PathBuf, sync::Arc}; use cosmic::{ @@ -13,7 +13,7 @@ use cosmic::{ scrollable::{ scroll_to, AbsoluteOffset, Direction, Scrollbar, }, - span, stack, text, + span, stack, }, prelude::*, widget::{ @@ -32,9 +32,6 @@ use crate::{ BackgroundKind, }; -use super::text_svg::{ - self, shadow, stroke, Font as SvgFont, TextSvg, -}; const REFERENCE_WIDTH: f32 = 1920.0; const REFERENCE_HEIGHT: f32 = 1080.0; @@ -528,21 +525,21 @@ async fn start_audio(sink: Arc, audio: PathBuf) { fn scale_font(font_size: f32, width: f32) -> f32 { let scale_factor = (REFERENCE_WIDTH / width).sqrt(); // debug!(scale_factor); - let font_size = if font_size > 0.0 { + + if font_size > 0.0 { font_size / scale_factor } else { 50.0 - }; - font_size + } } -pub(crate) fn slide_view<'a>( +pub(crate) fn slide_view( slide: Slide, - video: &'a Option