clippy fix
This commit is contained in:
parent
f8e7eead5f
commit
0e949fae65
|
@ -2,7 +2,7 @@ use crate::{Background, Slide, SlideBuilder, TextAlignment};
|
|||
|
||||
use super::{model::Model, service_items::ServiceTrait};
|
||||
use crisp::types::{Keyword, Value};
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{query_as, SqliteConnection};
|
||||
use std::path::PathBuf;
|
||||
|
@ -114,7 +114,7 @@ pub async fn get_image_from_db(
|
|||
database_id: i32,
|
||||
db: &mut SqliteConnection,
|
||||
) -> Result<Image> {
|
||||
Ok(query_as!(Image, r#"SELECT title as "title!", file_path as "path!", id as "id: i32" from images where id = ?"#, database_id).fetch_one(db).await.into_diagnostic()?)
|
||||
query_as!(Image, r#"SELECT title as "title!", file_path as "path!", id as "id: i32" from images where id = ?"#, database_id).fetch_one(db).await.into_diagnostic()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::Slide;
|
|||
|
||||
use super::{
|
||||
images::Image,
|
||||
presentations::{PresKind, Presentation},
|
||||
presentations::Presentation,
|
||||
songs::Song,
|
||||
videos::Video,
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::mem::replace;
|
||||
|
||||
use cosmic::{executor, iced::Executor, Task};
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use cosmic::iced::Executor;
|
||||
use miette::{miette, Result};
|
||||
use sqlx::{Connection, SqliteConnection};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crisp::types::{Keyword, Value};
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{
|
||||
prelude::FromRow, query, sqlite::SqliteRow, Row, SqliteConnection,
|
||||
|
@ -164,7 +164,7 @@ pub async fn get_presentation_from_db(
|
|||
db: &mut SqliteConnection,
|
||||
) -> Result<Presentation> {
|
||||
let row = query(r#"SELECT id as "id: i32", title, file_path as "path", html from presentations where id = $1"#).bind(database_id).fetch_one(db).await.into_diagnostic()?;
|
||||
Ok(Presentation::from_row(&row).into_diagnostic()?)
|
||||
Presentation::from_row(&row).into_diagnostic()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
use crisp::types::{Keyword, Symbol, Value};
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use miette::{miette, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Display,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
};
|
||||
use tracing::error;
|
||||
|
||||
|
@ -381,7 +379,7 @@ pub fn lisp_to_background(lisp: &Value) -> Background {
|
|||
panic!("Should always be there");
|
||||
};
|
||||
let mut home = home.to_string();
|
||||
home.push_str("/");
|
||||
home.push('/');
|
||||
|
||||
let s = s.replace("./", &home);
|
||||
match Background::try_from(s.as_str()) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::{collections::HashMap, fmt::Display, path::PathBuf};
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use cosmic::{executor, iced::Executor};
|
||||
use cosmic::iced::Executor;
|
||||
use crisp::types::{Keyword, Symbol, Value};
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{
|
||||
query, query_as, sqlite::SqliteRow, FromRow, Row,
|
||||
query, sqlite::SqliteRow, FromRow, Row,
|
||||
SqliteConnection,
|
||||
};
|
||||
use tracing::{debug, error};
|
||||
|
@ -154,7 +154,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
.position(|v| v == &Value::Keyword(Keyword::from("id")))
|
||||
{
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos).map(|c| i32::from(c)).unwrap_or_default()
|
||||
list.get(pos).map(i32::from).unwrap_or_default()
|
||||
} else {
|
||||
DEFAULT_SONG_ID
|
||||
};
|
||||
|
@ -164,7 +164,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
v == &Value::Keyword(Keyword::from("background"))
|
||||
}) {
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos).map(|b| slide::lisp_to_background(b))
|
||||
list.get(pos).map(slide::lisp_to_background)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -174,7 +174,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
.position(|v| v == &Value::Keyword(Keyword::from("author")))
|
||||
{
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos).map(|a| String::from(a))
|
||||
list.get(pos).map(String::from)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -204,7 +204,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
.position(|v| v == &Value::Keyword(Keyword::from("font")))
|
||||
{
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos).map(|f| String::from(f))
|
||||
list.get(pos).map(String::from)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -213,7 +213,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
v == &Value::Keyword(Keyword::from("font-size"))
|
||||
}) {
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos).map(|f| i32::from(f))
|
||||
list.get(pos).map(i32::from)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -224,7 +224,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
{
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos)
|
||||
.map(|t| String::from(t))
|
||||
.map(String::from)
|
||||
.unwrap_or(String::from("song"))
|
||||
} else {
|
||||
String::from("song")
|
||||
|
@ -235,7 +235,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
v == &Value::Keyword(Keyword::from("text-alignment"))
|
||||
}) {
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos).map(|t| TextAlignment::from(t))
|
||||
list.get(pos).map(TextAlignment::from)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -247,7 +247,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
let pos = key_pos + 1;
|
||||
list.get(pos).map(|v| match v {
|
||||
Value::List(vals) => vals
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|v| String::from(v).to_uppercase())
|
||||
.collect::<Vec<String>>(),
|
||||
_ => vec![],
|
||||
|
@ -256,8 +256,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
None
|
||||
};
|
||||
|
||||
let first_text_postiion = if let Some(pos) =
|
||||
list.iter().position(|v| match v {
|
||||
let first_text_postiion = list.iter().position(|v| match v {
|
||||
Value::List(inner) => {
|
||||
(match &inner[0] {
|
||||
Value::Symbol(Symbol(text)) => {
|
||||
|
@ -273,11 +272,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
})
|
||||
}
|
||||
_ => false,
|
||||
}) {
|
||||
pos
|
||||
} else {
|
||||
1
|
||||
};
|
||||
}).unwrap_or(1);
|
||||
|
||||
let lyric_elements = &list[first_text_postiion..];
|
||||
|
||||
|
@ -347,7 +342,7 @@ pub async fn get_song_from_db(
|
|||
db: &mut SqliteConnection,
|
||||
) -> Result<Song> {
|
||||
let row = query(r#"SELECT verse_order as "verse_order!", font_size as "font_size!: i32", background_type as "background_type!", horizontal_text_alignment as "horizontal_text_alignment!", vertical_text_alignment as "vertical_text_alignment!", title as "title!", font as "font!", background as "background!", lyrics as "lyrics!", ccli as "ccli!", author as "author!", audio as "audio!", id as "id: i32" from songs where id = $1"#).bind(index).fetch_one(db).await.into_diagnostic()?;
|
||||
Ok(Song::from_row(&row).into_diagnostic()?)
|
||||
Song::from_row(&row).into_diagnostic()
|
||||
}
|
||||
|
||||
impl Model<Song> {
|
||||
|
|
|
@ -3,9 +3,9 @@ use crate::{Background, SlideBuilder, TextAlignment};
|
|||
use super::{
|
||||
model::Model, service_items::ServiceTrait, slide::Slide,
|
||||
};
|
||||
use cosmic::{executor, iced::Executor};
|
||||
use cosmic::iced::Executor;
|
||||
use crisp::types::{Keyword, Value};
|
||||
use miette::{miette, IntoDiagnostic, Result};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{query_as, SqliteConnection};
|
||||
use std::path::PathBuf;
|
||||
|
@ -83,7 +83,7 @@ impl From<&Value> for Video {
|
|||
let pos = loop_pos + 1;
|
||||
list.get(pos)
|
||||
.map(|l| {
|
||||
String::from(l) == "true".to_string()
|
||||
String::from(l) == *"true"
|
||||
})
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
|
@ -157,7 +157,7 @@ pub async fn get_video_from_db(
|
|||
database_id: i32,
|
||||
db: &mut SqliteConnection,
|
||||
) -> Result<Video> {
|
||||
Ok(query_as!(Video, r#"SELECT title as "title!", file_path as "path!", start_time as "start_time!: f32", end_time as "end_time!: f32", loop as "looping!", id as "id: i32" from videos where id = ?"#, database_id).fetch_one(db).await.into_diagnostic()?)
|
||||
query_as!(Video, r#"SELECT title as "title!", file_path as "path!", start_time as "start_time!: f32", end_time as "end_time!: f32", loop as "looping!", id as "id: i32" from videos where id = ?"#, database_id).fetch_one(db).await.into_diagnostic()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
use std::{fs::read_to_string, path::PathBuf};
|
||||
|
||||
use crisp::types::{Symbol, Value};
|
||||
use tracing::error;
|
||||
|
||||
use crate::{
|
||||
core::{service_items::ServiceItem, songs::lisp_to_song},
|
||||
Slide,
|
||||
};
|
||||
use crate::core::service_items::ServiceItem;
|
||||
|
||||
pub fn parse_lisp(value: Value) -> Vec<ServiceItem> {
|
||||
match &value {
|
||||
|
@ -28,7 +24,7 @@ pub fn parse_lisp(value: Value) -> Vec<ServiceItem> {
|
|||
match lisp_value {
|
||||
Value::List(value) => value
|
||||
.into_iter()
|
||||
.flat_map(|v| parse_lisp(v))
|
||||
.flat_map(parse_lisp)
|
||||
.collect(),
|
||||
_ => panic!("Should not be"),
|
||||
}
|
||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -5,18 +5,17 @@ use cosmic::app::{Core, Settings, Task};
|
|||
use cosmic::iced::keyboard::{Key, Modifiers};
|
||||
use cosmic::iced::window::{Mode, Position};
|
||||
use cosmic::iced::{
|
||||
self, event, window, Font, Length, Padding, Point,
|
||||
self, event, window, Length, Padding, Point,
|
||||
};
|
||||
use cosmic::iced_core::SmolStr;
|
||||
use cosmic::iced_futures::Subscription;
|
||||
use cosmic::iced_widget::{column, row, stack};
|
||||
use cosmic::iced_widget::{column, row};
|
||||
use cosmic::prelude::ElementExt;
|
||||
use cosmic::prelude::*;
|
||||
use cosmic::widget::nav_bar::nav_bar_style;
|
||||
use cosmic::widget::tooltip::Position as TPosition;
|
||||
use cosmic::widget::{
|
||||
button, context_drawer, image, nav_bar, text, tooltip, MouseArea,
|
||||
Responsive, Space,
|
||||
button, nav_bar, text, tooltip, Space,
|
||||
};
|
||||
use cosmic::widget::{icon, slider};
|
||||
use cosmic::{executor, Application, ApplicationExt, Element};
|
||||
|
@ -75,8 +74,8 @@ fn main() -> Result<()> {
|
|||
Settings::default().debug(false).no_main_window(true);
|
||||
}
|
||||
|
||||
Ok(cosmic::app::run::<App>(settings, args)
|
||||
.map_err(|e| miette!("Invalid things... {}", e))?)
|
||||
cosmic::app::run::<App>(settings, args)
|
||||
.map_err(|e| miette!("Invalid things... {}", e))
|
||||
}
|
||||
|
||||
fn theme(_state: &App) -> Theme {
|
||||
|
@ -159,11 +158,7 @@ impl cosmic::Application for App {
|
|||
|
||||
let items = ServiceItemModel::from(items);
|
||||
let presenter = Presenter::with_items(items.clone());
|
||||
let slides = if let Ok(slides) = items.to_slides() {
|
||||
slides
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
let slides = items.to_slides().unwrap_or_default();
|
||||
let current_slide = slides[0].clone();
|
||||
|
||||
for item in items.iter() {
|
||||
|
@ -239,7 +234,7 @@ impl cosmic::Application for App {
|
|||
.spacing(10);
|
||||
let padding = Padding::new(0.0).top(20);
|
||||
let container = Container::new(column)
|
||||
.style(|t| nav_bar_style(t))
|
||||
.style(nav_bar_style)
|
||||
.padding(padding);
|
||||
Some(container.into())
|
||||
}
|
||||
|
@ -288,7 +283,7 @@ impl cosmic::Application for App {
|
|||
.on_press({
|
||||
if self.presentation_open {
|
||||
Message::CloseWindow(
|
||||
presenter_window.map(|id| *id),
|
||||
presenter_window.copied(),
|
||||
)
|
||||
} else {
|
||||
Message::OpenWindow
|
||||
|
@ -351,14 +346,14 @@ impl cosmic::Application for App {
|
|||
) -> Option<
|
||||
cosmic::app::context_drawer::ContextDrawer<Self::Message>,
|
||||
> {
|
||||
Some(ContextDrawer {
|
||||
ContextDrawer {
|
||||
title: Some("Context".into()),
|
||||
header_actions: vec![],
|
||||
header: Some("hi".into()),
|
||||
content: "Sup".into(),
|
||||
footer: Some("foot".into()),
|
||||
on_close: Message::None,
|
||||
});
|
||||
};
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -390,23 +385,23 @@ impl cosmic::Application for App {
|
|||
presenter::Message::NextSlide,
|
||||
)),
|
||||
(Key::Character(k), _)
|
||||
if k == SmolStr::from("j")
|
||||
|| k == SmolStr::from("l") =>
|
||||
if k == *"j"
|
||||
|| k == *"l" =>
|
||||
{
|
||||
self.update(Message::Present(
|
||||
presenter::Message::NextSlide,
|
||||
))
|
||||
}
|
||||
(Key::Character(k), _)
|
||||
if k == SmolStr::from("k")
|
||||
|| k == SmolStr::from("h") =>
|
||||
if k == *"k"
|
||||
|| k == *"h" =>
|
||||
{
|
||||
self.update(Message::Present(
|
||||
presenter::Message::PrevSlide,
|
||||
))
|
||||
}
|
||||
(Key::Character(k), _)
|
||||
if k == SmolStr::from("q") =>
|
||||
if k == *"q" =>
|
||||
{
|
||||
self.update(Message::Quit)
|
||||
}
|
||||
|
@ -484,7 +479,7 @@ impl cosmic::Application for App {
|
|||
};
|
||||
self.windows.remove(window);
|
||||
// This closes the app if using the cli example
|
||||
if self.windows.len() == 0 {
|
||||
if self.windows.is_empty() {
|
||||
self.update(Message::Quit)
|
||||
} else {
|
||||
self.presentation_open = false;
|
||||
|
@ -542,7 +537,7 @@ impl cosmic::Application for App {
|
|||
Container::new(
|
||||
self.presenter
|
||||
.view_preview()
|
||||
.map(|m| Message::Present(m)),
|
||||
.map(Message::Present),
|
||||
)
|
||||
.align_bottom(Length::Fill),
|
||||
Container::new(if self.presenter.video.is_some() {
|
||||
|
@ -618,7 +613,7 @@ impl cosmic::Application for App {
|
|||
Container::new(
|
||||
self.presenter
|
||||
.preview_bar()
|
||||
.map(|m| Message::Present(m))
|
||||
.map(Message::Present)
|
||||
)
|
||||
.clip(true)
|
||||
.width(Length::Fill)
|
||||
|
@ -632,7 +627,7 @@ impl cosmic::Application for App {
|
|||
// View for presentation
|
||||
fn view_window(&self, _id: window::Id) -> Element<Message> {
|
||||
debug!("window");
|
||||
self.presenter.view().map(|m| Message::Present(m))
|
||||
self.presenter.view().map(Message::Present)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ use cosmic::{
|
|||
prelude::*,
|
||||
widget::{
|
||||
container, image, mouse_area, responsive, scrollable, text,
|
||||
Column, Container, Id, Responsive, Row, Space, Text,
|
||||
Column, Container, Id, Responsive, Row, Space,
|
||||
},
|
||||
Task,
|
||||
};
|
||||
|
@ -63,18 +63,14 @@ pub(crate) enum Message {
|
|||
|
||||
impl Presenter {
|
||||
pub fn with_items(items: ServiceItemModel) -> Self {
|
||||
let slides = if let Ok(slides) = items.to_slides() {
|
||||
slides
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
let slides = items.to_slides().unwrap_or_default();
|
||||
Self {
|
||||
slides: slides.clone(),
|
||||
items: items.into(),
|
||||
items: items,
|
||||
current_slide: slides[0].clone(),
|
||||
current_slide_index: 0,
|
||||
video: {
|
||||
if let Some(slide) = slides.get(0) {
|
||||
if let Some(slide) = slides.first() {
|
||||
let path = slide.background().path.clone();
|
||||
if path.exists() {
|
||||
let url = Url::from_file_path(path).unwrap();
|
||||
|
|
Loading…
Reference in a new issue