mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
3way merge works!
This commit is contained in:
parent
e8a7c0682c
commit
8e6b74cec2
2 changed files with 94 additions and 73 deletions
|
|
@ -37,6 +37,7 @@ impl Perch {
|
|||
{
|
||||
setter(self, self.cursor, Some(value.as_ref()));
|
||||
self.mode = None;
|
||||
self.cursor_select(1);
|
||||
}
|
||||
}
|
||||
pub fn edit_clear (&mut self) {
|
||||
|
|
|
|||
|
|
@ -174,10 +174,8 @@ impl Metadata {
|
|||
})
|
||||
}
|
||||
// JPG
|
||||
if bytes.starts_with(MAGIC_JPG_1)
|
||||
|| bytes.starts_with(MAGIC_JPG_2)
|
||||
|| bytes.starts_with(MAGIC_JPG_3)
|
||||
|| (bytes.starts_with(MAGIC_JPG_4A) &&
|
||||
if bytes.starts_with(MAGIC_JPG_1) || bytes.starts_with(MAGIC_JPG_2)
|
||||
|| bytes.starts_with(MAGIC_JPG_3) || (bytes.starts_with(MAGIC_JPG_4A) &&
|
||||
bytes.get(6) == Some(&0x45) && bytes.get(7) == Some(&0x78) &&
|
||||
bytes.get(8) == Some(&0x69) && bytes.get(9) == Some(&0x66) &&
|
||||
bytes.get(10) == Some(&0x00) && bytes.get(11) == Some(&0x00))
|
||||
|
|
@ -230,10 +228,11 @@ macro_rules! music_tag_field {
|
|||
(
|
||||
key = $key:expr,
|
||||
get = $get:ident,
|
||||
format = $format:expr,
|
||||
parse = $parse:expr,
|
||||
read = $read:expr,
|
||||
set = $set:ident,
|
||||
del = $del:ident,
|
||||
write = $write:expr,
|
||||
parse = $parse:expr,
|
||||
) => {
|
||||
impl Entry {
|
||||
pub fn $get (&self) -> Option<Arc<str>> {
|
||||
|
|
@ -246,40 +245,44 @@ macro_rules! music_tag_field {
|
|||
impl Metadata {
|
||||
/// Get the metadata value if present.
|
||||
pub fn $get (&self) -> Option<Arc<str>> {
|
||||
let write = $write;
|
||||
let format = $format;
|
||||
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
||||
return modified_tag
|
||||
.as_ref()
|
||||
.map(|tag|tag.read().unwrap().$get().map(|x|write(x)))
|
||||
.map(|tag|tag.read().unwrap().$get().map(|x|format(x)))
|
||||
.flatten()
|
||||
.or_else(||original_tag
|
||||
.as_ref()
|
||||
.map(|tag|tag.$get().map(|x|write(x)))
|
||||
.flatten())
|
||||
//.or_else(||original_tag
|
||||
//.as_ref()
|
||||
//.map(|tag|tag.$get().map(|x|format(x)))
|
||||
//.flatten())
|
||||
}
|
||||
None
|
||||
}
|
||||
/// Set or delete the metadata value.
|
||||
/// Return whether the changes should be recounted.
|
||||
pub fn $set (&mut self, value: Option<&str>) -> bool {
|
||||
pub fn $set (&mut self, input_value: Option<&str>) -> bool {
|
||||
let parse = $parse;
|
||||
let read = $read;
|
||||
match self {
|
||||
|
||||
&mut Metadata::Music {
|
||||
original_tag: Some(ref original), modified_tag: Some(ref modified), ..
|
||||
} => if let Some(value) = value {
|
||||
} => if let Some(input_value) = input_value {
|
||||
if let Ok(input_value) = parse(input_value) {
|
||||
// set new value
|
||||
let value = parse(value).unwrap();
|
||||
let changed = original.$get() != Some(value);
|
||||
modified.write().unwrap().$set(value);
|
||||
let changed = original.$get().map(read) != Some(input_value.clone());
|
||||
modified.write().unwrap().$set(input_value);
|
||||
changed
|
||||
} else {
|
||||
let modified = modified.write().unwrap();
|
||||
false
|
||||
}
|
||||
} else {
|
||||
let mut modified = modified.write().unwrap();
|
||||
if let Some(value) = modified.$get() {
|
||||
// delete modified value
|
||||
modified.$del();
|
||||
true
|
||||
} else if let Some(value) = original.$get() {
|
||||
} else if let Some(value) = original.$get().map(read) {
|
||||
// set to original value
|
||||
modified.$set(value);
|
||||
true
|
||||
|
|
@ -290,13 +293,18 @@ macro_rules! music_tag_field {
|
|||
|
||||
&mut Metadata::Music {
|
||||
original_tag: Some(ref original), ref mut modified_tag, ..
|
||||
} => if let Some(input_value) = value {
|
||||
} => if let Some(input_value) = input_value {
|
||||
if let Ok(input_value) = parse(input_value) {
|
||||
let mut new_tag = Tag::new(TagType::Id3v2); // FIXME other types
|
||||
new_tag.$set(input_value);
|
||||
*modified_tag = Some(Arc::new(RwLock::new(new_tag)));
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else if let Some(original_value) = original.$get() {
|
||||
// set to original value
|
||||
let original_value = read(original_value);
|
||||
let mut new_tag = Tag::new(TagType::Id3v2); // FIXME other types
|
||||
new_tag.$set(original_value);
|
||||
*modified_tag = Some(Arc::new(RwLock::new(new_tag)));
|
||||
|
|
@ -307,19 +315,22 @@ macro_rules! music_tag_field {
|
|||
|
||||
&mut Metadata::Music {
|
||||
original_tag: None, modified_tag: Some(ref modified), ..
|
||||
} => if let Some(value) = value {
|
||||
} => if let Some(input_value) = input_value {
|
||||
// set new value
|
||||
let value = parse(value).unwrap();
|
||||
let modified = modified.write().unwrap();
|
||||
if modified.$get() != Some(value) {
|
||||
if let Ok(input_value) = parse(input_value) {
|
||||
let mut modified = modified.write().unwrap();
|
||||
if modified.$get().map(read) != Some(input_value.clone()) {
|
||||
// set modified value
|
||||
modified.$set(value);
|
||||
modified.$set(input_value);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
let modified = modified.write().unwrap();
|
||||
false
|
||||
}
|
||||
} else {
|
||||
let mut modified = modified.write().unwrap();
|
||||
if modified.$get().is_some() {
|
||||
// remove modified value
|
||||
modified.$del();
|
||||
|
|
@ -331,13 +342,17 @@ macro_rules! music_tag_field {
|
|||
|
||||
&mut Metadata::Music {
|
||||
original_tag: None, ref mut modified_tag, ..
|
||||
} => if let Some(value) = value {
|
||||
} => if let Some(input_value) = input_value {
|
||||
if let Ok(input_value) = parse(input_value) {
|
||||
let mut new_tag = Tag::new(TagType::Id3v2); // FIXME other types
|
||||
new_tag.$set(value);
|
||||
new_tag.$set(input_value);
|
||||
*modified_tag = Some(Arc::new(RwLock::new(new_tag)));
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
},
|
||||
|
||||
_ => {
|
||||
|
|
@ -352,44 +367,49 @@ macro_rules! music_tag_field {
|
|||
music_tag_field! {
|
||||
key = ItemKey::TrackArtist,
|
||||
get = artist,
|
||||
format = |value: Cow<str>|value.into(),
|
||||
parse = |value: &str|Ok::<String, ()>(value.trim().to_string()),
|
||||
read = |value: Cow<str>|value.to_string(),
|
||||
set = set_artist,
|
||||
del = remove_artist,
|
||||
write = |value: Cow<str>|value.into(),
|
||||
parse = |value: &str|Ok::<String, ()>(value.trim()),
|
||||
}
|
||||
|
||||
music_tag_field! {
|
||||
key = ItemKey::Year,
|
||||
get = year,
|
||||
format = |value: u32|format!("{value}").into(),
|
||||
parse = |value: &str|value.trim().parse::<u32>(),
|
||||
read = |value: u32|value,
|
||||
set = set_year,
|
||||
del = remove_year,
|
||||
write = |value: u32|format!("{value}").into(),
|
||||
parse = |value: &str|value.trim().parse::<u32>(),
|
||||
}
|
||||
|
||||
music_tag_field! {
|
||||
key = ItemKey::AlbumTitle,
|
||||
get = album,
|
||||
format = |value: Cow<str>|value.into(),
|
||||
parse = |value: &str|Ok::<String, ()>(value.trim().to_string()),
|
||||
read = |value: Cow<str>|value.to_string(),
|
||||
set = set_album,
|
||||
del = remove_album,
|
||||
write = |value: Cow<str>|value.into(),
|
||||
parse = |value: &str|Ok::<String, ()>(value.trim().into()),
|
||||
}
|
||||
|
||||
music_tag_field! {
|
||||
key = ItemKey::TrackNumber,
|
||||
get = track,
|
||||
format = |value: u32|format!("{value}").into(),
|
||||
parse = |value: &str|value.trim().parse::<u32>(),
|
||||
read = |value: u32|value,
|
||||
set = set_track,
|
||||
del = remove_track,
|
||||
write = |value: u32|format!("{value}").into(),
|
||||
parse = |value: &str|value.trim().parse::<u32>(),
|
||||
}
|
||||
|
||||
music_tag_field! {
|
||||
key = ItemKey::TrackTitle,
|
||||
get = title,
|
||||
format = |value: Cow<str>|value.into(),
|
||||
parse = |value: &str|Ok::<String, ()>(value.trim().to_string()),
|
||||
read = |value: Cow<str>|value.to_string(),
|
||||
set = set_title,
|
||||
del = remove_title,
|
||||
write = |value: Cow<str>|value.into(),
|
||||
parse = |value: &str|Ok::<String, ()>(value.trim().into()),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue