mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
auto impl getters/setters on Entry
This commit is contained in:
parent
4619d0ea76
commit
44a2108585
3 changed files with 43 additions and 54 deletions
|
|
@ -18,10 +18,7 @@ impl Taggart {
|
||||||
{
|
{
|
||||||
let value = (column.getter)(&self.entries[self.cursor]);
|
let value = (column.getter)(&self.entries[self.cursor]);
|
||||||
let value = format!("{}", value.unwrap_or_default());
|
let value = format!("{}", value.unwrap_or_default());
|
||||||
self.mode = Some(Mode::Edit {
|
self.mode = Some(Mode::Edit { index: value.len(), value: value.into(), });
|
||||||
index: value.len(),
|
|
||||||
value: value.into(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn edit_cancel (&mut self) {
|
pub fn edit_cancel (&mut self) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use std::cmp::{Eq, PartialEq, Ord, PartialOrd, Ordering};
|
use std::cmp::{Eq, PartialEq, Ord, PartialOrd, Ordering};
|
||||||
use lofty::tag::TagItem;
|
|
||||||
|
|
||||||
pub struct Entry {
|
pub struct Entry {
|
||||||
/// How many levels deep is this from the working directory
|
/// How many levels deep is this from the working directory
|
||||||
|
|
@ -50,42 +49,6 @@ impl Entry {
|
||||||
pub fn is_image (&self) -> bool {
|
pub fn is_image (&self) -> bool {
|
||||||
matches!(&*self.info.read().unwrap(), Metadata::Image { .. })
|
matches!(&*self.info.read().unwrap(), Metadata::Image { .. })
|
||||||
}
|
}
|
||||||
pub fn hash (&self) -> Option<Arc<str>> {
|
|
||||||
self.info.read().unwrap().hash()
|
|
||||||
}
|
|
||||||
pub fn size (&self) -> Option<Arc<str>> {
|
|
||||||
self.info.read().unwrap().size()
|
|
||||||
}
|
|
||||||
pub fn artist (&self) -> Option<Arc<str>> {
|
|
||||||
self.info.read().unwrap().artist()
|
|
||||||
}
|
|
||||||
pub fn year (&self) -> Option<Arc<str>> {
|
|
||||||
self.info.read().unwrap().year()
|
|
||||||
}
|
|
||||||
pub fn album (&self) -> Option<Arc<str>> {
|
|
||||||
self.info.read().unwrap().album()
|
|
||||||
}
|
|
||||||
pub fn title (&self) -> Option<Arc<str>> {
|
|
||||||
self.info.read().unwrap().title()
|
|
||||||
}
|
|
||||||
pub fn track (&self) -> Option<Arc<str>> {
|
|
||||||
self.info.read().unwrap().track()
|
|
||||||
}
|
|
||||||
pub fn set_artist (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
|
||||||
self.info.write().unwrap().set_artist(value)
|
|
||||||
}
|
|
||||||
pub fn set_year (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
|
||||||
self.info.write().unwrap().set_year(value)
|
|
||||||
}
|
|
||||||
pub fn set_album (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
|
||||||
self.info.write().unwrap().set_album(value)
|
|
||||||
}
|
|
||||||
pub fn set_title (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
|
||||||
self.info.write().unwrap().set_title(value)
|
|
||||||
}
|
|
||||||
pub fn set_track (&self, value: &impl AsRef<str>) -> Option<TagItem> {
|
|
||||||
self.info.write().unwrap().set_track(value)
|
|
||||||
}
|
|
||||||
pub const ICON_DIRECTORY: &'static str = "";
|
pub const ICON_DIRECTORY: &'static str = "";
|
||||||
pub const ICON_IMAGE: &'static str = "";
|
pub const ICON_IMAGE: &'static str = "";
|
||||||
pub const ICON_MUSIC: &'static str = "";
|
pub const ICON_MUSIC: &'static str = "";
|
||||||
|
|
|
||||||
|
|
@ -104,26 +104,47 @@ impl Metadata {
|
||||||
hash: hex::encode(xxh3_64(&bytes).to_be_bytes()).into(),
|
hash: hex::encode(xxh3_64(&bytes).to_be_bytes()).into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn hash (&self) -> Option<Arc<str>> {
|
}
|
||||||
match self {
|
|
||||||
Metadata::Image { hash, .. } => Some(hash.clone()),
|
macro_rules! generated_field {
|
||||||
Metadata::Music { hash, .. } => Some(hash.clone()),
|
($get:ident = |$self:ident| $expr:expr) => {
|
||||||
Metadata::Unknown { hash, .. } => Some(hash.clone()),
|
impl Entry {
|
||||||
_ => None
|
pub fn $get (&$self) -> Option<Arc<str>> {
|
||||||
|
$self.info.read().unwrap().$get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn size (&self) -> Option<Arc<str>> {
|
impl Metadata {
|
||||||
match self {
|
pub fn $get (&$self) -> Option<Arc<str>> {
|
||||||
Metadata::Image { size, .. } => Some(size.clone()),
|
$expr
|
||||||
Metadata::Music { size, .. } => Some(size.clone()),
|
}
|
||||||
Metadata::Unknown { size, .. } => Some(size.clone()),
|
|
||||||
_ => None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generated_field!(hash = |self|match self {
|
||||||
|
Metadata::Image { hash, .. } => Some(hash.clone()),
|
||||||
|
Metadata::Music { hash, .. } => Some(hash.clone()),
|
||||||
|
Metadata::Unknown { hash, .. } => Some(hash.clone()),
|
||||||
|
_ => None
|
||||||
|
});
|
||||||
|
|
||||||
|
generated_field!(size = |self|match self {
|
||||||
|
Metadata::Image { size, .. } => Some(size.clone()),
|
||||||
|
Metadata::Music { size, .. } => Some(size.clone()),
|
||||||
|
Metadata::Unknown { size, .. } => Some(size.clone()),
|
||||||
|
_ => None
|
||||||
|
});
|
||||||
|
|
||||||
macro_rules! music_tag_field {
|
macro_rules! music_tag_field {
|
||||||
(string: $get:ident $set:ident $del:ident $key:expr) => {
|
(string: $get:ident $set:ident $del:ident $key:expr) => {
|
||||||
|
impl Entry {
|
||||||
|
pub fn $get (&self) -> Option<Arc<str>> {
|
||||||
|
self.info.read().unwrap().$get()
|
||||||
|
}
|
||||||
|
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
|
self.info.write().unwrap().$set(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub fn $get (&self) -> Option<Arc<str>> {
|
pub fn $get (&self) -> Option<Arc<str>> {
|
||||||
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
||||||
|
|
@ -169,6 +190,14 @@ macro_rules! music_tag_field {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(number: $get:ident $set:ident $del:ident $key:expr) => {
|
(number: $get:ident $set:ident $del:ident $key:expr) => {
|
||||||
|
impl Entry {
|
||||||
|
pub fn $get (&self) -> Option<Arc<str>> {
|
||||||
|
self.info.read().unwrap().$get()
|
||||||
|
}
|
||||||
|
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
|
self.info.write().unwrap().$set(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub fn $get (&self) -> Option<Arc<str>> {
|
pub fn $get (&self) -> Option<Arc<str>> {
|
||||||
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue