perf, pedantic, nursery, and unwrap_used clippy fixes
This commit is contained in:
parent
a186d3bec4
commit
3fe77c93e2
15 changed files with 195 additions and 207 deletions
|
@ -17,7 +17,7 @@ use std::path::PathBuf;
|
|||
use tracing::error;
|
||||
|
||||
#[derive(
|
||||
Clone, Debug, Default, PartialEq, Serialize, Deserialize,
|
||||
Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct Image {
|
||||
pub id: i32,
|
||||
|
@ -52,8 +52,7 @@ impl Content for Image {
|
|||
if self.path.exists() {
|
||||
self.path
|
||||
.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or("Missing image".into())
|
||||
.map_or("Missing image".into(), |f| f.to_string_lossy().to_string())
|
||||
} else {
|
||||
"Missing image".into()
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ impl From<&Value> for Image {
|
|||
let path =
|
||||
p.to_str().unwrap_or_default().to_string();
|
||||
let title =
|
||||
path.rsplit_once("/").unwrap_or_default().1;
|
||||
path.rsplit_once('/').unwrap_or_default().1;
|
||||
title.to_string()
|
||||
});
|
||||
Self {
|
||||
|
@ -154,14 +153,14 @@ impl Model<Image> {
|
|||
.await;
|
||||
match result {
|
||||
Ok(v) => {
|
||||
for image in v.into_iter() {
|
||||
for image in v {
|
||||
let _ = self.add_item(image);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("There was an error in converting images: {e}")
|
||||
error!("There was an error in converting images: {e}");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +171,7 @@ pub async fn update_image_in_db(
|
|||
let path = image
|
||||
.path
|
||||
.to_str()
|
||||
.map(|s| s.to_string())
|
||||
.map(std::string::ToString::to_string)
|
||||
.unwrap_or_default();
|
||||
query!(
|
||||
r#"UPDATE images SET title = $2, file_path = $3 WHERE id = $1"#,
|
||||
|
|
|
@ -50,7 +50,7 @@ impl std::fmt::Display for ServiceItemKind {
|
|||
// }
|
||||
|
||||
impl From<ServiceItemKind> for String {
|
||||
fn from(val: ServiceItemKind) -> String {
|
||||
fn from(val: ServiceItemKind) -> Self {
|
||||
match val {
|
||||
ServiceItemKind::Song(_) => "song".to_owned(),
|
||||
ServiceItemKind::Video(_) => "video".to_owned(),
|
||||
|
|
|
@ -10,7 +10,7 @@ pub struct Model<T> {
|
|||
pub kind: LibraryKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
|
||||
pub enum LibraryKind {
|
||||
Song,
|
||||
Video,
|
||||
|
@ -46,7 +46,7 @@ impl<T> Model<T> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_item(&self, index: i32) -> Option<&T> {
|
||||
#[must_use] pub fn get_item(&self, index: i32) -> Option<&T> {
|
||||
self.items.get(index as usize)
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,7 @@ impl Content for Presentation {
|
|||
if self.path.exists() {
|
||||
self.path
|
||||
.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or("Missing presentation".into())
|
||||
.map_or("Missing presentation".into(), |f| f.to_string_lossy().to_string())
|
||||
} else {
|
||||
"Missing presentation".into()
|
||||
}
|
||||
|
@ -190,14 +189,14 @@ impl ServiceTrait for Presentation {
|
|||
}
|
||||
|
||||
impl Presentation {
|
||||
pub fn new() -> Self {
|
||||
#[must_use] pub fn new() -> Self {
|
||||
Self {
|
||||
title: "".to_string(),
|
||||
title: String::new(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_kind(&self) -> &PresKind {
|
||||
#[must_use] pub const fn get_kind(&self) -> &PresKind {
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +239,7 @@ impl Model<Presentation> {
|
|||
.await;
|
||||
match result {
|
||||
Ok(v) => {
|
||||
for presentation in v.into_iter() {
|
||||
for presentation in v {
|
||||
let _ = self.add_item(Presentation {
|
||||
id: presentation.id,
|
||||
title: presentation.title,
|
||||
|
@ -267,7 +266,7 @@ pub async fn update_presentation_in_db(
|
|||
let path = presentation
|
||||
.path
|
||||
.to_str()
|
||||
.map(|s| s.to_string())
|
||||
.map(std::string::ToString::to_string)
|
||||
.unwrap_or_default();
|
||||
let html = presentation.kind == PresKind::Html;
|
||||
query!(
|
||||
|
|
|
@ -79,13 +79,13 @@ impl AsMimeTypes for ServiceItem {
|
|||
impl From<&ServiceItem> for Value {
|
||||
fn from(value: &ServiceItem) -> Self {
|
||||
match &value.kind {
|
||||
ServiceItemKind::Song(song) => Value::from(song),
|
||||
ServiceItemKind::Video(video) => Value::from(video),
|
||||
ServiceItemKind::Image(image) => Value::from(image),
|
||||
ServiceItemKind::Song(song) => Self::from(song),
|
||||
ServiceItemKind::Video(video) => Self::from(video),
|
||||
ServiceItemKind::Image(image) => Self::from(image),
|
||||
ServiceItemKind::Presentation(presentation) => {
|
||||
Value::from(presentation)
|
||||
Self::from(presentation)
|
||||
}
|
||||
ServiceItemKind::Content(slide) => Value::from(slide),
|
||||
ServiceItemKind::Content(slide) => Self::from(slide),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,54 +172,51 @@ impl From<&Value> for ServiceItem {
|
|||
} 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()
|
||||
if let Value::List(item) = background { 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!(),
|
||||
} } else {
|
||||
error!(
|
||||
"There is no background here: {:?}",
|
||||
background
|
||||
);
|
||||
Self::default()
|
||||
}
|
||||
} else {
|
||||
error!(
|
||||
"There is no background here: {:?}",
|
||||
background_pos
|
||||
);
|
||||
ServiceItem::default()
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
Value::Symbol(Symbol(s)) if s == "song" => {
|
||||
let song = lisp_to_song(list.clone());
|
||||
Self::from(&song)
|
||||
}
|
||||
_ => ServiceItem::default(),
|
||||
_ => Self::default(),
|
||||
},
|
||||
_ => ServiceItem::default(),
|
||||
_ => Self::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,9 +107,9 @@ impl TryFrom<&Background> for Video {
|
|||
fn try_from(
|
||||
value: &Background,
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
Video::new(
|
||||
Self::new(
|
||||
&url::Url::from_file_path(value.path.clone())
|
||||
.map_err(|_| ParseError::BackgroundNotVideo)?,
|
||||
.map_err(|()| ParseError::BackgroundNotVideo)?,
|
||||
)
|
||||
.map_err(|_| ParseError::BackgroundNotVideo)
|
||||
}
|
||||
|
@ -121,9 +121,9 @@ impl TryFrom<Background> for Video {
|
|||
fn try_from(
|
||||
value: Background,
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
Video::new(
|
||||
Self::new(
|
||||
&url::Url::from_file_path(value.path)
|
||||
.map_err(|_| ParseError::BackgroundNotVideo)?,
|
||||
.map_err(|()| ParseError::BackgroundNotVideo)?,
|
||||
)
|
||||
.map_err(|_| ParseError::BackgroundNotVideo)
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ impl TryFrom<Background> for Video {
|
|||
impl TryFrom<String> for Background {
|
||||
type Error = ParseError;
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
Background::try_from(value.as_str())
|
||||
Self::try_from(value.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ impl TryFrom<PathBuf> for Background {
|
|||
.to_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let path = path.replace("~", &home);
|
||||
let path = path.replace('~', &home);
|
||||
PathBuf::from(path)
|
||||
} else {
|
||||
path
|
||||
|
@ -192,10 +192,10 @@ impl TryFrom<&str> for Background {
|
|||
type Error = ParseError;
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let value = value.trim_start_matches("file://");
|
||||
if value.starts_with("~") {
|
||||
if value.starts_with('~') {
|
||||
if let Some(home) = dirs::home_dir() {
|
||||
if let Some(home) = home.to_str() {
|
||||
let value = value.replace("~", home);
|
||||
let value = value.replace('~', home);
|
||||
Self::try_from(PathBuf::from(value))
|
||||
} else {
|
||||
Self::try_from(PathBuf::from(value))
|
||||
|
@ -252,9 +252,9 @@ impl Display for ParseError {
|
|||
impl From<String> for BackgroundKind {
|
||||
fn from(value: String) -> Self {
|
||||
if value == "image" {
|
||||
BackgroundKind::Image
|
||||
Self::Image
|
||||
} else {
|
||||
BackgroundKind::Video
|
||||
Self::Video
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ impl Slide {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_font_size(mut self, font_size: i32) -> Self {
|
||||
pub const fn set_font_size(mut self, font_size: i32) -> Self {
|
||||
self.font_size = font_size;
|
||||
self
|
||||
}
|
||||
|
@ -291,12 +291,12 @@ impl Slide {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_pdf_index(mut self, pdf_index: u32) -> Self {
|
||||
pub const fn set_pdf_index(mut self, pdf_index: u32) -> Self {
|
||||
self.pdf_index = pdf_index;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn background(&self) -> &Background {
|
||||
pub const fn background(&self) -> &Background {
|
||||
&self.background
|
||||
}
|
||||
|
||||
|
@ -304,11 +304,11 @@ impl Slide {
|
|||
self.text.clone()
|
||||
}
|
||||
|
||||
pub fn text_alignment(&self) -> TextAlignment {
|
||||
pub const fn text_alignment(&self) -> TextAlignment {
|
||||
self.text_alignment
|
||||
}
|
||||
|
||||
pub fn font_size(&self) -> i32 {
|
||||
pub const fn font_size(&self) -> i32 {
|
||||
self.font_size
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ impl Slide {
|
|||
self.font.clone()
|
||||
}
|
||||
|
||||
pub fn video_loop(&self) -> bool {
|
||||
pub const fn video_loop(&self) -> bool {
|
||||
self.video_loop
|
||||
}
|
||||
|
||||
|
@ -328,13 +328,13 @@ impl Slide {
|
|||
self.pdf_page.clone()
|
||||
}
|
||||
|
||||
pub fn pdf_index(&self) -> u32 {
|
||||
pub const fn pdf_index(&self) -> u32 {
|
||||
self.pdf_index
|
||||
}
|
||||
|
||||
pub fn song_slides(song: &Song) -> Result<Vec<Self>> {
|
||||
let lyrics = song.get_lyrics()?;
|
||||
let slides: Vec<Slide> = lyrics
|
||||
let slides: Vec<Self> = lyrics
|
||||
.iter()
|
||||
.map(|l| {
|
||||
let song = song.clone();
|
||||
|
@ -358,7 +358,7 @@ impl Slide {
|
|||
Ok(slides)
|
||||
}
|
||||
|
||||
pub(crate) fn set_index(&mut self, index: i32) {
|
||||
pub(crate) const fn set_index(&mut self, index: i32) {
|
||||
self.id = index;
|
||||
}
|
||||
|
||||
|
@ -381,7 +381,7 @@ impl From<&Value> for Slide {
|
|||
fn from(value: &Value) -> Self {
|
||||
match value {
|
||||
Value::List(list) => lisp_to_slide(list),
|
||||
_ => Slide::default(),
|
||||
_ => Self::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -404,7 +404,7 @@ fn lisp_to_slide(lisp: &Vec<Value>) -> Slide {
|
|||
slide = slide.background(lisp_to_background(background));
|
||||
} else {
|
||||
slide = slide.background(Background::default());
|
||||
};
|
||||
}
|
||||
|
||||
let text_position = lisp.iter().position(|v| match v {
|
||||
Value::List(vec) => {
|
||||
|
@ -691,9 +691,7 @@ impl SlideBuilder {
|
|||
|
||||
impl Image {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
..Default::default()
|
||||
}
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ impl FromRow<'_, SqliteRow> for Song {
|
|||
})),
|
||||
verse_order: Some({
|
||||
let str: &str = row.try_get(0)?;
|
||||
str.split(' ').map(|s| s.to_string()).collect()
|
||||
str.split(' ').map(std::string::ToString::to_string).collect()
|
||||
}),
|
||||
background: {
|
||||
let string: String = row.try_get(7)?;
|
||||
|
@ -251,8 +251,7 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
{
|
||||
let pos = key_pos + 1;
|
||||
list.get(pos)
|
||||
.map(String::from)
|
||||
.unwrap_or(String::from("song"))
|
||||
.map_or(String::from("song"), String::from)
|
||||
} else {
|
||||
String::from("song")
|
||||
};
|
||||
|
@ -319,30 +318,30 @@ pub fn lisp_to_song(list: Vec<Value>) -> Song {
|
|||
let lyric = String::from(&lyric[1]);
|
||||
|
||||
let verse_title = match lyric_verse.as_str() {
|
||||
"i1" => r#"\n\nIntro 1\n"#,
|
||||
"i2" => r#"\n\nIntro 1\n"#,
|
||||
"v1" => r#"\n\nVerse 1\n"#,
|
||||
"v2" => r#"\n\nVerse 2\n"#,
|
||||
"v3" => r#"\n\nVerse 3\n"#,
|
||||
"v4" => r#"\n\nVerse 4\n"#,
|
||||
"v5" => r#"\n\nVerse 5\n"#,
|
||||
"c1" => r#"\n\nChorus 1\n"#,
|
||||
"c2" => r#"\n\nChorus 2\n"#,
|
||||
"c3" => r#"\n\nChorus 3\n"#,
|
||||
"c4" => r#"\n\nChorus 4\n"#,
|
||||
"b1" => r#"\n\nBridge 1\n"#,
|
||||
"b2" => r#"\n\nBridge 2\n"#,
|
||||
"e1" => r#"\n\nEnding 1\n"#,
|
||||
"e2" => r#"\n\nEnding 2\n"#,
|
||||
"o1" => r#"\n\nOther 1\n"#,
|
||||
"o2" => r#"\n\nOther 2\n"#,
|
||||
"i1" => r"\n\nIntro 1\n",
|
||||
"i2" => r"\n\nIntro 1\n",
|
||||
"v1" => r"\n\nVerse 1\n",
|
||||
"v2" => r"\n\nVerse 2\n",
|
||||
"v3" => r"\n\nVerse 3\n",
|
||||
"v4" => r"\n\nVerse 4\n",
|
||||
"v5" => r"\n\nVerse 5\n",
|
||||
"c1" => r"\n\nChorus 1\n",
|
||||
"c2" => r"\n\nChorus 2\n",
|
||||
"c3" => r"\n\nChorus 3\n",
|
||||
"c4" => r"\n\nChorus 4\n",
|
||||
"b1" => r"\n\nBridge 1\n",
|
||||
"b2" => r"\n\nBridge 2\n",
|
||||
"e1" => r"\n\nEnding 1\n",
|
||||
"e2" => r"\n\nEnding 2\n",
|
||||
"o1" => r"\n\nOther 1\n",
|
||||
"o2" => r"\n\nOther 2\n",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
let lyric = format!("{verse_title}{lyric}");
|
||||
let lyric = lyric.replace(
|
||||
"\\n", r#"
|
||||
"#,
|
||||
"\\n", r"
|
||||
",
|
||||
);
|
||||
lyrics.push(lyric);
|
||||
}
|
||||
|
@ -392,15 +391,15 @@ impl Model<Song> {
|
|||
let result = 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"#).fetch_all(db).await;
|
||||
match result {
|
||||
Ok(s) => {
|
||||
for song in s.into_iter() {
|
||||
for song in s {
|
||||
match Song::from_row(&song) {
|
||||
Ok(song) => {
|
||||
let _ = self.add_item(song);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Could not convert song: {e}")
|
||||
error!("Could not convert song: {e}");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
|
@ -425,7 +424,7 @@ pub async fn update_song_in_db(
|
|||
})
|
||||
.collect::<String>()
|
||||
} else {
|
||||
String::from("")
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -488,13 +487,13 @@ impl Song {
|
|||
let verse_order = self.verse_order.clone();
|
||||
|
||||
let mut lyric_map = HashMap::new();
|
||||
let mut verse_title = String::from("");
|
||||
let mut lyric = String::from("");
|
||||
let mut verse_title = String::new();
|
||||
let mut lyric = String::new();
|
||||
for (i, line) in raw_lyrics.split('\n').enumerate() {
|
||||
if VERSE_KEYWORDS.contains(&line) {
|
||||
if i != 0 {
|
||||
lyric_map.insert(verse_title, lyric);
|
||||
lyric = String::from("");
|
||||
lyric = String::new();
|
||||
verse_title = line.to_string();
|
||||
} else {
|
||||
verse_title = line.to_string();
|
||||
|
@ -535,7 +534,7 @@ impl Song {
|
|||
lyric_list.push(lyric.to_string());
|
||||
} else {
|
||||
// error!("NOT WORKING!");
|
||||
};
|
||||
}
|
||||
}
|
||||
// for lyric in lyric_list.iter() {
|
||||
// debug!(lyric = ?lyric)
|
||||
|
|
|
@ -11,7 +11,9 @@ pub fn bg_from_video(
|
|||
video: &Path,
|
||||
screenshot: &Path,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
if !screenshot.exists() {
|
||||
if screenshot.exists() {
|
||||
debug!("Screenshot already exists");
|
||||
} else {
|
||||
let output_duration = Command::new("ffprobe")
|
||||
.args(["-i", &video.to_string_lossy()])
|
||||
.output()
|
||||
|
@ -26,9 +28,9 @@ pub fn bg_from_video(
|
|||
let mut duration = log.split_off(duration_index + 10);
|
||||
duration.truncate(11);
|
||||
// debug!("rust-duration-is: {duration}");
|
||||
let mut hours = String::from("");
|
||||
let mut minutes = String::from("");
|
||||
let mut seconds = String::from("");
|
||||
let mut hours = String::new();
|
||||
let mut minutes = String::new();
|
||||
let mut seconds = String::new();
|
||||
for (i, c) in duration.chars().enumerate() {
|
||||
if i <= 1 {
|
||||
hours.push(c);
|
||||
|
@ -63,8 +65,6 @@ pub fn bg_from_video(
|
|||
.expect("failed to execute ffmpeg");
|
||||
// io::stdout().write_all(&output.stdout).unwrap();
|
||||
// io::stderr().write_all(&output.stderr).unwrap();
|
||||
} else {
|
||||
debug!("Screenshot already exists");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -57,8 +57,7 @@ impl Content for Video {
|
|||
if self.path.exists() {
|
||||
self.path
|
||||
.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or("Missing video".into())
|
||||
.map_or("Missing video".into(), |f| f.to_string_lossy().to_string())
|
||||
} else {
|
||||
"Missing video".into()
|
||||
}
|
||||
|
@ -90,7 +89,7 @@ impl From<&Value> for Video {
|
|||
let path =
|
||||
p.to_str().unwrap_or_default().to_string();
|
||||
let title =
|
||||
path.rsplit_once("/").unwrap_or_default().1;
|
||||
path.rsplit_once('/').unwrap_or_default().1;
|
||||
title.to_string()
|
||||
});
|
||||
|
||||
|
@ -124,8 +123,7 @@ impl From<&Value> for Video {
|
|||
}) {
|
||||
let pos = loop_pos + 1;
|
||||
list.get(pos)
|
||||
.map(|l| String::from(l) == *"true")
|
||||
.unwrap_or_default()
|
||||
.is_some_and(|l| String::from(l) == *"true")
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
@ -193,14 +191,14 @@ impl Model<Video> {
|
|||
let result = 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"#).fetch_all(db).await;
|
||||
match result {
|
||||
Ok(v) => {
|
||||
for video in v.into_iter() {
|
||||
for video in v {
|
||||
let _ = self.add_item(video);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("There was an error in converting videos: {e}")
|
||||
error!("There was an error in converting videos: {e}");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,7 +209,7 @@ pub async fn update_video_in_db(
|
|||
let path = video
|
||||
.path
|
||||
.to_str()
|
||||
.map(|s| s.to_string())
|
||||
.map(std::string::ToString::to_string)
|
||||
.unwrap_or_default();
|
||||
query!(
|
||||
r#"UPDATE videos SET title = $2, file_path = $3, start_time = $4, end_time = $5, loop = $6 WHERE id = $1"#,
|
||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use clap::{command, Parser};
|
||||
use core::service_items::ServiceItem;
|
||||
use core::slide::*;
|
||||
use core::slide::{Background, Slide, SlideBuilder, TextAlignment, BackgroundKind};
|
||||
use core::songs::Song;
|
||||
use cosmic::app::context_drawer::ContextDrawer;
|
||||
use cosmic::app::{Core, Settings, Task};
|
||||
|
@ -233,11 +233,11 @@ impl cosmic::Application for App {
|
|||
// }
|
||||
|
||||
// nav_model.activate_position(0);
|
||||
let mut app = App {
|
||||
let mut app = Self {
|
||||
presenter,
|
||||
core,
|
||||
nav_model,
|
||||
service: items.clone(),
|
||||
service: items,
|
||||
file: PathBuf::default(),
|
||||
windows,
|
||||
presentation_open: false,
|
||||
|
@ -248,7 +248,7 @@ impl cosmic::Application for App {
|
|||
song_editor,
|
||||
searching: false,
|
||||
search_results: vec![],
|
||||
search_query: "".into(),
|
||||
search_query: String::new(),
|
||||
search_id: cosmic::widget::Id::unique(),
|
||||
current_item: (0, 0),
|
||||
library_dragged_item: None,
|
||||
|
@ -259,11 +259,11 @@ impl cosmic::Application for App {
|
|||
|
||||
if input.ui {
|
||||
debug!("main view");
|
||||
batch.push(app.update_title())
|
||||
batch.push(app.update_title());
|
||||
} else {
|
||||
debug!("window view");
|
||||
batch.push(app.show_window())
|
||||
};
|
||||
batch.push(app.show_window());
|
||||
}
|
||||
|
||||
batch.push(app.add_library());
|
||||
// batch.push(app.add_service(items, Arc::clone(&fontdb)));
|
||||
|
@ -403,7 +403,7 @@ impl cosmic::Application for App {
|
|||
.fold(0, |a, item| a + item.slides.len());
|
||||
|
||||
let total_slides_text =
|
||||
format!("Total Slides: {}", total_slides);
|
||||
format!("Total Slides: {total_slides}");
|
||||
let row = row![
|
||||
text::body(total_items_text),
|
||||
text::body(total_slides_text)
|
||||
|
@ -635,7 +635,7 @@ impl cosmic::Application for App {
|
|||
cosmic::Action::App(
|
||||
Message::Present(m),
|
||||
)
|
||||
}))
|
||||
}));
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
|
@ -661,7 +661,7 @@ impl cosmic::Application for App {
|
|||
m,
|
||||
),
|
||||
)
|
||||
}))
|
||||
}));
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
|
@ -694,7 +694,7 @@ impl cosmic::Application for App {
|
|||
cosmic::Action::App(
|
||||
Message::Present(m),
|
||||
)
|
||||
}))
|
||||
}));
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
|
@ -735,7 +735,7 @@ impl cosmic::Application for App {
|
|||
m,
|
||||
),
|
||||
)
|
||||
}))
|
||||
}));
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
|
@ -817,7 +817,7 @@ impl cosmic::Application for App {
|
|||
|
||||
self.windows.push(id);
|
||||
_ = self.set_window_title(
|
||||
format!("window_{}", count),
|
||||
format!("window_{count}"),
|
||||
id,
|
||||
);
|
||||
|
||||
|
@ -992,7 +992,7 @@ impl cosmic::Application for App {
|
|||
Task::none()
|
||||
}
|
||||
Message::CloseSearch => {
|
||||
self.search_query = "".into();
|
||||
self.search_query = String::new();
|
||||
self.search_results = vec![];
|
||||
self.searching = false;
|
||||
Task::none()
|
||||
|
|
|
@ -133,13 +133,13 @@ impl<'a> Library {
|
|||
if kind != LibraryKind::Song {
|
||||
error!("Not editing a song item");
|
||||
return Action::None;
|
||||
};
|
||||
}
|
||||
|
||||
match self
|
||||
.song_library
|
||||
.update_item(song.clone(), index)
|
||||
{
|
||||
Ok(_) => {
|
||||
Ok(()) => {
|
||||
return Action::Task(
|
||||
Task::future(self.db.acquire()).and_then(
|
||||
move |conn| update_in_db(&song, conn),
|
||||
|
@ -162,13 +162,13 @@ impl<'a> Library {
|
|||
if kind != LibraryKind::Image {
|
||||
error!("Not editing a image item");
|
||||
return Action::None;
|
||||
};
|
||||
}
|
||||
|
||||
match self
|
||||
.image_library
|
||||
.update_item(image.clone(), index)
|
||||
{
|
||||
Ok(_) => {
|
||||
Ok(()) => {
|
||||
return Action::Task(
|
||||
Task::future(self.db.acquire()).and_then(
|
||||
move |conn| {
|
||||
|
@ -196,13 +196,13 @@ impl<'a> Library {
|
|||
if kind != LibraryKind::Video {
|
||||
error!("Not editing a video item");
|
||||
return Action::None;
|
||||
};
|
||||
}
|
||||
|
||||
match self
|
||||
.video_library
|
||||
.update_item(video.clone(), index)
|
||||
{
|
||||
Ok(_) => {
|
||||
Ok(()) => {
|
||||
return Action::Task(
|
||||
Task::future(self.db.acquire()).and_then(
|
||||
move |conn| {
|
||||
|
@ -230,13 +230,13 @@ impl<'a> Library {
|
|||
if kind != LibraryKind::Presentation {
|
||||
error!("Not editing a presentation item");
|
||||
return Action::None;
|
||||
};
|
||||
}
|
||||
|
||||
match self
|
||||
.presentation_library
|
||||
.update_item(presentation.clone(), index)
|
||||
{
|
||||
Ok(_) => return Action::Task(
|
||||
Ok(()) => return Action::Task(
|
||||
Task::future(self.db.acquire()).and_then(
|
||||
move |conn| {
|
||||
Task::perform(
|
||||
|
@ -254,7 +254,7 @@ impl<'a> Library {
|
|||
}
|
||||
Message::PresentationChanged => (),
|
||||
Message::Error(_) => (),
|
||||
};
|
||||
}
|
||||
Action::None
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ impl<'a> Library {
|
|||
textm!("Presentations").align_y(Vertical::Center),
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
let item_count = model.items.len();
|
||||
row = row.push(horizontal_space());
|
||||
row = row
|
||||
|
@ -373,7 +373,7 @@ impl<'a> Library {
|
|||
let service_item = item.to_service_item();
|
||||
let visual_item = self
|
||||
.single_item(index, item, model)
|
||||
.map(|_| Message::None);
|
||||
.map(|()| Message::None);
|
||||
DndSource::<Message, ServiceItem>::new(
|
||||
mouse_area(visual_item)
|
||||
.on_drag(Message::DragItem(service_item.clone()))
|
||||
|
@ -418,7 +418,7 @@ impl<'a> Library {
|
|||
)
|
||||
}})
|
||||
.drag_content(move || {
|
||||
service_item.to_owned()
|
||||
service_item.clone()
|
||||
})
|
||||
.into()
|
||||
},
|
||||
|
@ -573,14 +573,14 @@ impl<'a> Library {
|
|||
.items
|
||||
.iter()
|
||||
.filter(|song| song.title.to_lowercase().contains(&query))
|
||||
.map(|song| song.to_service_item())
|
||||
.map(super::super::core::content::Content::to_service_item)
|
||||
.collect();
|
||||
let videos: Vec<ServiceItem> = self
|
||||
.video_library
|
||||
.items
|
||||
.iter()
|
||||
.filter(|vid| vid.title.to_lowercase().contains(&query))
|
||||
.map(|vid| vid.to_service_item())
|
||||
.map(super::super::core::content::Content::to_service_item)
|
||||
.collect();
|
||||
let images: Vec<ServiceItem> = self
|
||||
.image_library
|
||||
|
@ -589,14 +589,14 @@ impl<'a> Library {
|
|||
.filter(|image| {
|
||||
image.title.to_lowercase().contains(&query)
|
||||
})
|
||||
.map(|image| image.to_service_item())
|
||||
.map(super::super::core::content::Content::to_service_item)
|
||||
.collect();
|
||||
let presentations: Vec<ServiceItem> = self
|
||||
.presentation_library
|
||||
.items
|
||||
.iter()
|
||||
.filter(|pres| pres.title.to_lowercase().contains(&query))
|
||||
.map(|pres| pres.to_service_item())
|
||||
.map(super::super::core::content::Content::to_service_item)
|
||||
.collect();
|
||||
items.extend(videos);
|
||||
items.extend(images);
|
||||
|
@ -656,7 +656,7 @@ fn update_in_db(
|
|||
Task::perform(
|
||||
update_song_in_db(song.to_owned(), conn).map(
|
||||
move |r| match r {
|
||||
Ok(_) => {
|
||||
Ok(()) => {
|
||||
warn!(
|
||||
"Should have updated song: {:?}",
|
||||
song_title
|
||||
|
@ -667,7 +667,7 @@ fn update_in_db(
|
|||
}
|
||||
},
|
||||
),
|
||||
|_| Message::SongChanged,
|
||||
|()| Message::SongChanged,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ impl Presenter {
|
|||
absolute_slide_index: 0,
|
||||
total_slides,
|
||||
video,
|
||||
audio: items[0].slides[0].audio().clone(),
|
||||
audio: items[0].slides[0].audio(),
|
||||
service: items,
|
||||
video_position: 0.0,
|
||||
hovered_slide: None,
|
||||
|
@ -221,8 +221,7 @@ impl Presenter {
|
|||
let offset = AbsoluteOffset {
|
||||
x: {
|
||||
if self.current_slide_index > 2 {
|
||||
self.current_slide_index as f32 * 187.5
|
||||
- 187.5
|
||||
(self.current_slide_index as f32).mul_add(187.5, -187.5)
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
|
@ -256,7 +255,7 @@ impl Presenter {
|
|||
?current_audio,
|
||||
"audio needs to change"
|
||||
);
|
||||
self.audio = Some(new_audio.clone());
|
||||
self.audio = Some(new_audio);
|
||||
tasks.push(self.start_audio());
|
||||
}
|
||||
Some(current_audio) => {
|
||||
|
@ -271,10 +270,10 @@ impl Presenter {
|
|||
?new_audio,
|
||||
"could not find audio, need to change"
|
||||
);
|
||||
self.audio = Some(new_audio.clone());
|
||||
self.audio = Some(new_audio);
|
||||
tasks.push(self.start_audio());
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
self.audio = None;
|
||||
self.update(Message::EndAudio);
|
||||
|
@ -326,7 +325,7 @@ impl Presenter {
|
|||
std::time::Duration::from_secs_f32(position),
|
||||
);
|
||||
match video.seek(position, false) {
|
||||
Ok(_) => debug!(
|
||||
Ok(()) => debug!(
|
||||
"Video position changed: {:?}",
|
||||
position
|
||||
),
|
||||
|
@ -355,7 +354,7 @@ impl Presenter {
|
|||
install_ctx
|
||||
.set_desktop_id(&format!("{}.desktop", "org.chriscochrun.lumina"));
|
||||
let install_detail = missing_plugin.installer_detail();
|
||||
println!("installing plugins: {}", install_detail);
|
||||
println!("installing plugins: {install_detail}");
|
||||
let status = gst_pbutils::missing_plugins::install_plugins_sync(
|
||||
&[&install_detail],
|
||||
Some(&install_ctx),
|
||||
|
@ -391,7 +390,7 @@ impl Presenter {
|
|||
Message::Error(error) => {
|
||||
error!(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
Action::None
|
||||
}
|
||||
|
||||
|
@ -641,7 +640,7 @@ impl Presenter {
|
|||
v.set_looping(
|
||||
self.current_slide.video_loop(),
|
||||
);
|
||||
self.video = Some(v)
|
||||
self.video = Some(v);
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
|
@ -664,7 +663,7 @@ impl Presenter {
|
|||
let audio = audio.clone();
|
||||
Task::perform(
|
||||
start_audio(Arc::clone(&self.sink.1), audio),
|
||||
|_| Message::None,
|
||||
|()| Message::None,
|
||||
)
|
||||
} else {
|
||||
debug!(?self.audio, "Apparently this doesn't exist");
|
||||
|
|
|
@ -54,10 +54,10 @@ struct EditorProgram {
|
|||
}
|
||||
|
||||
impl SlideEditor {
|
||||
pub fn view<'a>(
|
||||
&'a self,
|
||||
pub fn view(
|
||||
&self,
|
||||
font: Font,
|
||||
) -> cosmic::Element<'a, SlideWidget> {
|
||||
) -> cosmic::Element<'_, SlideWidget> {
|
||||
container(
|
||||
widget::canvas(&self.program)
|
||||
.height(Length::Fill)
|
||||
|
@ -122,10 +122,10 @@ impl<'a> Program<SlideWidget, cosmic::Theme, cosmic::Renderer>
|
|||
match event {
|
||||
canvas::Event::Mouse(event) => match event {
|
||||
cosmic::iced::mouse::Event::CursorEntered => {
|
||||
debug!("cursor entered")
|
||||
debug!("cursor entered");
|
||||
}
|
||||
cosmic::iced::mouse::Event::CursorLeft => {
|
||||
debug!("cursor left")
|
||||
debug!("cursor left");
|
||||
}
|
||||
cosmic::iced::mouse::Event::CursorMoved {
|
||||
position,
|
||||
|
@ -140,7 +140,7 @@ impl<'a> Program<SlideWidget, cosmic::Theme, cosmic::Renderer>
|
|||
}
|
||||
cosmic::iced::mouse::Event::ButtonPressed(button) => {
|
||||
// self.mouse_button_pressed = Some(button);
|
||||
debug!(?button, "mouse button pressed")
|
||||
debug!(?button, "mouse button pressed");
|
||||
}
|
||||
cosmic::iced::mouse::Event::ButtonReleased(
|
||||
button,
|
||||
|
|
|
@ -140,11 +140,11 @@ impl SongEditor {
|
|||
self.song = Some(song.clone());
|
||||
self.title = song.title;
|
||||
if let Some(font) = song.font {
|
||||
self.font = font
|
||||
};
|
||||
self.font = font;
|
||||
}
|
||||
if let Some(font_size) = song.font_size {
|
||||
self.font_size = font_size as usize
|
||||
};
|
||||
self.font_size = font_size as usize;
|
||||
}
|
||||
if let Some(verse_order) = song.verse_order {
|
||||
self.verse_order = verse_order
|
||||
.into_iter()
|
||||
|
@ -155,18 +155,18 @@ impl SongEditor {
|
|||
.collect();
|
||||
}
|
||||
if let Some(author) = song.author {
|
||||
self.author = author
|
||||
};
|
||||
self.author = author;
|
||||
}
|
||||
if let Some(audio) = song.audio {
|
||||
self.audio = audio
|
||||
};
|
||||
self.audio = audio;
|
||||
}
|
||||
if let Some(ccli) = song.ccli {
|
||||
self.ccli = ccli
|
||||
};
|
||||
self.ccli = ccli;
|
||||
}
|
||||
if let Some(lyrics) = song.lyrics {
|
||||
self.lyrics =
|
||||
text_editor::Content::with_text(&lyrics)
|
||||
};
|
||||
text_editor::Content::with_text(&lyrics);
|
||||
}
|
||||
self.background_video(&song.background);
|
||||
self.background = song.background;
|
||||
}
|
||||
|
@ -212,8 +212,8 @@ impl SongEditor {
|
|||
self.verse_order = verse_order.clone();
|
||||
if let Some(mut song) = self.song.clone() {
|
||||
let verse_order = verse_order
|
||||
.split(" ")
|
||||
.map(|s| s.to_owned())
|
||||
.split(' ')
|
||||
.map(std::borrow::ToOwned::to_owned)
|
||||
.collect();
|
||||
song.verse_order = Some(verse_order);
|
||||
return self.update_song(song);
|
||||
|
@ -245,7 +245,7 @@ impl SongEditor {
|
|||
debug!(?path);
|
||||
if let Some(mut song) = self.song.clone() {
|
||||
let background =
|
||||
Background::try_from(path.clone()).ok();
|
||||
Background::try_from(path).ok();
|
||||
self.background_video(&background);
|
||||
song.background = background;
|
||||
return self.update_song(song);
|
||||
|
@ -416,7 +416,7 @@ order",
|
|||
.into()
|
||||
}
|
||||
|
||||
pub fn editing(&self) -> bool {
|
||||
pub const fn editing(&self) -> bool {
|
||||
self.editing
|
||||
}
|
||||
|
||||
|
|
|
@ -121,15 +121,15 @@ impl From<&str> for Font {
|
|||
}
|
||||
|
||||
impl Font {
|
||||
pub fn get_name(&self) -> String {
|
||||
#[must_use] pub fn get_name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
pub fn get_weight(&self) -> Weight {
|
||||
#[must_use] pub const fn get_weight(&self) -> Weight {
|
||||
self.weight
|
||||
}
|
||||
|
||||
pub fn get_style(&self) -> Style {
|
||||
#[must_use] pub const fn get_style(&self) -> Style {
|
||||
self.style
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ impl Font {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn size(mut self, size: u8) -> Self {
|
||||
#[must_use] pub const fn size(mut self, size: u8) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
@ -161,12 +161,12 @@ impl Hash for Color {
|
|||
}
|
||||
|
||||
impl Color {
|
||||
pub fn from_hex_str(color: impl AsRef<str>) -> Color {
|
||||
pub fn from_hex_str(color: impl AsRef<str>) -> Self {
|
||||
match Rgb::from_hex_str(color.as_ref()) {
|
||||
Ok(rgb) => Color(rgb),
|
||||
Ok(rgb) => Self(rgb),
|
||||
Err(e) => {
|
||||
error!("error in making color from hex_str: {:?}", e);
|
||||
Color::default()
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ impl TextSvg {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn alignment(mut self, alignment: TextAlignment) -> Self {
|
||||
pub const fn alignment(mut self, alignment: TextAlignment) -> Self {
|
||||
self.alignment = alignment;
|
||||
self
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ impl TextSvg {
|
|||
shadow.spread,
|
||||
shadow.color)
|
||||
} else {
|
||||
"".into()
|
||||
String::new()
|
||||
};
|
||||
let stroke = if let Some(stroke) = &self.stroke {
|
||||
format!(
|
||||
|
@ -263,17 +263,17 @@ impl TextSvg {
|
|||
stroke.color, stroke.size
|
||||
)
|
||||
} else {
|
||||
"".into()
|
||||
String::new()
|
||||
};
|
||||
let size = Size::new(1920.0, 1080.0);
|
||||
let font_size = self.font.size as f32;
|
||||
let font_size = f32::from(self.font.size);
|
||||
let total_lines = self.text.lines().count();
|
||||
let half_lines = (total_lines / 2) as f32;
|
||||
let middle_position = size.height / 2.0;
|
||||
let line_spacing = 10.0;
|
||||
let text_and_line_spacing = font_size + line_spacing;
|
||||
let starting_y_position =
|
||||
middle_position - (half_lines * text_and_line_spacing);
|
||||
half_lines.mul_add(-text_and_line_spacing, middle_position);
|
||||
|
||||
let text_pieces: Vec<String> = self
|
||||
.text
|
||||
|
@ -282,8 +282,7 @@ impl TextSvg {
|
|||
.map(|(index, text)| {
|
||||
format!(
|
||||
"<tspan x=\"50%\" y=\"{}\">{}</tspan>",
|
||||
starting_y_position
|
||||
+ (index as f32 * text_and_line_spacing),
|
||||
(index as f32).mul_add(text_and_line_spacing, starting_y_position),
|
||||
text
|
||||
)
|
||||
})
|
||||
|
@ -350,7 +349,7 @@ impl TextSvg {
|
|||
self.text
|
||||
.lines()
|
||||
.enumerate()
|
||||
.map(|(i, t)| format!("<tspan x=\"50%\">{}</tspan>", t))
|
||||
.map(|(i, t)| format!("<tspan x=\"50%\">{t}</tspan>"))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
@ -391,7 +390,7 @@ pub fn text_svg_generator(
|
|||
.shadow(shadow(2, 2, 5, "#000000"))
|
||||
.stroke(stroke(3, "#000"))
|
||||
.font(
|
||||
Font::from(slide.font().clone())
|
||||
Font::from(slide.font())
|
||||
.size(slide.font_size().try_into().unwrap()),
|
||||
)
|
||||
.fontdb(Arc::clone(&fontdb))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue