making the text in the library smarter
This commit is contained in:
parent
40065d2c5a
commit
9b9c337c1b
8 changed files with 65 additions and 22 deletions
|
@ -7,4 +7,5 @@ pub trait Content {
|
|||
fn kind(&self) -> ServiceItemKind;
|
||||
fn to_service_item(&self) -> ServiceItem;
|
||||
fn background(&self) -> Option<Background>;
|
||||
fn subtext(&self) -> String;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,17 @@ impl Content for Image {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn subtext(&self) -> String {
|
||||
if self.path.exists() {
|
||||
self.path
|
||||
.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or("Missing image".into())
|
||||
} else {
|
||||
"Missing image".into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value> for Image {
|
||||
|
|
|
@ -65,6 +65,17 @@ impl Content for Presentation {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn subtext(&self) -> String {
|
||||
if self.path.exists() {
|
||||
self.path
|
||||
.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or("Missing presentation".into())
|
||||
} else {
|
||||
"Missing presentation".into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value> for Presentation {
|
||||
|
|
|
@ -59,6 +59,10 @@ impl Content for Song {
|
|||
fn background(&self) -> Option<Background> {
|
||||
self.background.clone()
|
||||
}
|
||||
|
||||
fn subtext(&self) -> String {
|
||||
self.author.clone().unwrap_or("Author missing".into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ServiceTrait for Song {
|
||||
|
|
|
@ -58,6 +58,17 @@ impl Content for Video {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn subtext(&self) -> String {
|
||||
if self.path.exists() {
|
||||
self.path
|
||||
.file_name()
|
||||
.map(|f| f.to_string_lossy().to_string())
|
||||
.unwrap_or("Missing video".into())
|
||||
} else {
|
||||
"Missing video".into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value> for Video {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue