[niepce] xmp: adapt to new Exempi API
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] xmp: adapt to new Exempi API
- Date: Mon, 26 Nov 2018 04:14:54 +0000 (UTC)
commit 389ccde4f7005baeb797461c52ecf298b36a1f23
Author: Hubert Figuière <hub figuiere net>
Date: Sat Nov 17 23:20:31 2018 -0500
xmp: adapt to new Exempi API
Cargo.lock | 12 ++++++------
Cargo.toml | 2 +-
src/engine/db/libmetadata.rs | 38 ++++++++++++++++++++------------------
src/fwk/utils/exempi.rs | 39 ++++++++++++++++++++-------------------
4 files changed, 47 insertions(+), 44 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 24b9ca1..abf4f92 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -175,17 +175,17 @@ dependencies = [
[[package]]
name = "exempi"
version = "2.5.0"
-source = "git+https://github.com/hfiguiere/exempi-rs.git#3c42c300a36414bf24e52c935f9c7a005657bdf2"
+source =
"git+https://github.com/hfiguiere/exempi-rs.git?rev=065721c4#065721c48de36cf8f3e3d89691e3891a3d3230cc"
dependencies = [
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "exempi-sys 2.4.1 (git+https://github.com/hfiguiere/exempi-rs.git)",
+ "exempi-sys 2.4.1 (git+https://github.com/hfiguiere/exempi-rs.git?rev=065721c4)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "exempi-sys"
version = "2.4.1"
-source = "git+https://github.com/hfiguiere/exempi-rs.git#3c42c300a36414bf24e52c935f9c7a005657bdf2"
+source =
"git+https://github.com/hfiguiere/exempi-rs.git?rev=065721c4#065721c48de36cf8f3e3d89691e3891a3d3230cc"
dependencies = [
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -480,7 +480,7 @@ dependencies = [
"bindgen 0.37.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cbindgen 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "exempi 2.5.0 (git+https://github.com/hfiguiere/exempi-rs.git)",
+ "exempi 2.5.0 (git+https://github.com/hfiguiere/exempi-rs.git?rev=065721c4)",
"gettext-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -944,8 +944,8 @@ dependencies = [
"checksum clap 2.31.1 (registry+https://github.com/rust-lang/crates.io-index)" =
"5dc18f6f4005132120d9711636b32c46a233fad94df6217fa1d81c5e97a9f200"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" =
"09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" =
"0e6e40ebb0e66918a37b38c7acab4e10d299e0463fe2af5d29b9cc86710cfd2a"
-"checksum exempi 2.5.0 (git+https://github.com/hfiguiere/exempi-rs.git)" = "<none>"
-"checksum exempi-sys 2.4.1 (git+https://github.com/hfiguiere/exempi-rs.git)" = "<none>"
+"checksum exempi 2.5.0 (git+https://github.com/hfiguiere/exempi-rs.git?rev=065721c4)" = "<none>"
+"checksum exempi-sys 2.4.1 (git+https://github.com/hfiguiere/exempi-rs.git?rev=065721c4)" = "<none>"
"checksum fragile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" =
"05f8140122fa0d5dcb9fc8627cfce2b37cc1500f752636d46ea28bc26785c2f9"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" =
"2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" =
"3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
diff --git a/Cargo.toml b/Cargo.toml
index 1fdccb8..f4f4838 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ build = "build.rs"
[dependencies]
chrono = "0.4.0"
-exempi = { version = "2.5.0", git = "https://github.com/hfiguiere/exempi-rs.git" }
+exempi = { version = "2.5.0", git = "https://github.com/hfiguiere/exempi-rs.git", rev="065721c4" }
gettext-rs = "0.3.0"
glib-sys = "0.7.0"
glib = "0.6.0"
diff --git a/src/engine/db/libmetadata.rs b/src/engine/db/libmetadata.rs
index 611fb03..d78f09a 100644
--- a/src/engine/db/libmetadata.rs
+++ b/src/engine/db/libmetadata.rs
@@ -89,41 +89,37 @@ impl LibMetadata {
self.xmp
.xmp
.get_property(&index_to_xmp.ns, &index_to_xmp.property, &mut prop_flags);
- if xmp_result.is_some() && prop_flags.contains(exempi::ARRAY_IS_ALTTEXT) {
- let mut value = exempi::XmpString::new();
- let mut actual_lang = exempi::XmpString::new();
- if self.xmp.xmp.get_localized_text(
+ if xmp_result.is_ok() && prop_flags.contains(exempi::ARRAY_IS_ALTTEXT) {
+ if let Ok((_, value)) = self.xmp.xmp.get_localized_text(
&index_to_xmp.ns,
&index_to_xmp.property,
"",
"x-default",
- &mut actual_lang,
- &mut value,
&mut prop_flags,
) {
- xmp_result = Some(value);
+ xmp_result = Ok(value);
}
}
Some(PropertyValue::String(String::from(
- try_opt!(xmp_result).to_str(),
+ try_opt!(xmp_result.ok()).to_str(),
)))
}
pub fn set_metadata(&mut self, meta: Np, value: &PropertyValue) -> bool {
if let Some(ix) = property_index_to_xmp(meta) {
match *value {
- PropertyValue::Empty => return self.xmp.xmp.delete_property(&ix.ns, &ix.property),
+ PropertyValue::Empty => return self.xmp.xmp.delete_property(&ix.ns, &ix.property).is_ok(),
PropertyValue::Int(i) => {
return self.xmp
.xmp
- .set_property_i32(&ix.ns, &ix.property, i, exempi::PROP_NONE)
+ .set_property_i32(&ix.ns, &ix.property, i, exempi::PROP_NONE).is_ok()
}
PropertyValue::String(ref s) => {
if s.is_empty() {
- return self.xmp.xmp.delete_property(&ix.ns, &ix.property);
+ return self.xmp.xmp.delete_property(&ix.ns, &ix.property).is_ok();
} else if !self.xmp
.xmp
- .set_property(&ix.ns, &ix.property, s, exempi::PROP_NONE)
+ .set_property(&ix.ns, &ix.property, s, exempi::PROP_NONE).is_ok()
{
if exempi::get_error() == exempi::Error::BadXPath {
return self.xmp.xmp.set_localized_text(
@@ -133,22 +129,28 @@ impl LibMetadata {
"x-default",
s,
exempi::PROP_NONE,
- );
+ ).is_ok();
}
} else {
return true;
}
}
PropertyValue::StringArray(ref sa) => {
- self.xmp.xmp.delete_property(&ix.ns, &ix.property);
+ if self.xmp.xmp.delete_property(&ix.ns, &ix.property).is_err() {
+ err_out!("Error deleting property {}", &ix.property);
+ return false;
+ }
for s in sa {
- self.xmp.xmp.append_array_item(
+ if self.xmp.xmp.append_array_item(
&ix.ns,
&ix.property,
exempi::PROP_VALUE_IS_ARRAY,
s,
exempi::PROP_NONE,
- );
+ ).is_err() {
+ err_out!("Error appending array item {} in property {}", &s, &ix.ns);
+ return false;
+ }
}
return true;
}
@@ -159,7 +161,7 @@ impl LibMetadata {
&ix.property,
&xmp_date,
exempi::PROP_NONE,
- );
+ ).is_ok();
}
}
err_out!(
@@ -245,7 +247,7 @@ impl LibMetadata {
let xmpdate = xmp_date_from(&Utc::now());
self.xmp
.xmp
- .set_property_date(NS_XAP, "MetadataDate", &xmpdate, exempi::PROP_NONE)
+ .set_property_date(NS_XAP, "MetadataDate", &xmpdate, exempi::PROP_NONE).is_ok()
}
}
diff --git a/src/fwk/utils/exempi.rs b/src/fwk/utils/exempi.rs
index eee3828..7ec415d 100644
--- a/src/fwk/utils/exempi.rs
+++ b/src/fwk/utils/exempi.rs
@@ -85,8 +85,8 @@ impl XmpMeta {
pub fn new_from_file(file: &str, sidecar_only: bool) -> Option<XmpMeta> {
let mut meta: Option<XmpMeta> = None;
if !sidecar_only {
- if let Some(xmpfile) = exempi::XmpFile::open_new(file, exempi::OPEN_READ) {
- if let Some(xmp) = xmpfile.get_new_xmp() {
+ if let Ok(xmpfile) = exempi::XmpFile::open_new(file, exempi::OPEN_READ) {
+ if let Ok(xmp) = xmpfile.get_new_xmp() {
meta = Some(XmpMeta {
xmp,
keywords: Vec::new(),
@@ -102,10 +102,9 @@ impl XmpMeta {
let sidecaropen = File::open(sidecar);
if let Ok(mut sidecarfile) = sidecaropen {
let mut sidecarcontent = String::new();
- let result = sidecarfile.read_to_string(&mut sidecarcontent);
- if result.ok().is_some() {
+ if sidecarfile.read_to_string(&mut sidecarcontent).is_ok() {
let mut xmp = exempi::Xmp::new();
- if xmp.parse(sidecarcontent.into_bytes().as_slice()) {
+ if let Ok(_) = xmp.parse(sidecarcontent.into_bytes().as_slice()) {
sidecar_meta = Some(XmpMeta {
xmp,
keywords: Vec::new(),
@@ -171,8 +170,10 @@ impl XmpMeta {
}
if !dest.xmp.has_property(schema.to_str(), name.to_str()) {
- dest.xmp.set_property(schema.to_str(), name.to_str(),
- value.to_str(), exempi::PROP_NONE);
+ if dest.xmp.set_property(schema.to_str(), name.to_str(),
+ value.to_str(), exempi::PROP_NONE).is_err() {
+ err_out!("Can set property {}", name);
+ }
}
}
}
@@ -181,7 +182,7 @@ impl XmpMeta {
}
pub fn serialize_inline(&self) -> String {
- if let Some(xmpstr) = self.xmp.serialize_and_format(
+ if let Ok(xmpstr) = self.xmp.serialize_and_format(
exempi::SERIAL_OMITPACKETWRAPPER | exempi::SERIAL_OMITALLFORMATTING,
0, "", "", 0) {
let buf = String::from(xmpstr.to_str());
@@ -191,7 +192,7 @@ impl XmpMeta {
}
pub fn serialize(&self) -> String {
- if let Some(xmpstr) = self.xmp.serialize_and_format(
+ if let Ok(xmpstr) = self.xmp.serialize_and_format(
exempi::SERIAL_OMITPACKETWRAPPER, 0, "\n", "", 0) {
let buf = String::from(xmpstr.to_str());
return buf;
@@ -200,33 +201,33 @@ impl XmpMeta {
}
pub fn unserialize(&mut self, buf: &str) -> bool {
- self.xmp.parse(buf.as_bytes())
+ self.xmp.parse(buf.as_bytes()).is_ok() // XXX actually report the error.
}
pub fn orientation(&self) -> Option<i32> {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
- self.xmp.get_property_i32(NS_TIFF, "Orientation", &mut flags)
+ self.xmp.get_property_i32(NS_TIFF, "Orientation", &mut flags).ok()
}
pub fn label(&self) -> Option<String> {
let mut flags: exempi::PropFlags = exempi::PROP_NONE;
- let xmpstring = try_opt!(self.xmp.get_property(NS_XAP, "Label", &mut flags));
+ let xmpstring = try_opt!(self.xmp.get_property(NS_XAP, "Label", &mut flags).ok());
Some(String::from(xmpstring.to_str()))
}
pub fn rating(&self) -> Option<i32> {
let mut flags: exempi::PropFlags = exempi::PROP_NONE;
- self.xmp.get_property_i32(NS_XAP, "Rating", &mut flags)
+ self.xmp.get_property_i32(NS_XAP, "Rating", &mut flags).ok()
}
pub fn flag(&self) -> Option<i32> {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
- self.xmp.get_property_i32(NIEPCE_XMP_NAMESPACE, "Flag", &mut flags)
+ self.xmp.get_property_i32(NIEPCE_XMP_NAMESPACE, "Flag", &mut flags).ok()
}
pub fn creation_date(&self) -> Option<DateTime<Utc>> {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
- let xmpstring = try_opt!(self.xmp.get_property(NS_EXIF, "DateTimeOriginal", &mut flags));
+ let xmpstring = try_opt!(self.xmp.get_property(NS_EXIF, "DateTimeOriginal", &mut flags).ok());
let date = try_opt!(DateTime::parse_from_rfc3339(xmpstring.to_str()).ok());
Some(date.with_timezone(&Utc))
@@ -234,7 +235,7 @@ impl XmpMeta {
pub fn creation_date_str(&self) -> Option<String> {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
- let xmpstring = try_opt!(self.xmp.get_property(NS_EXIF, "DateTimeOriginal", &mut flags));
+ let xmpstring = try_opt!(self.xmp.get_property(NS_EXIF, "DateTimeOriginal", &mut flags).ok());
Some(String::from(xmpstring.to_str()))
}
@@ -242,7 +243,7 @@ impl XmpMeta {
/// from the string value.
pub fn get_date_property(&self, ns: &str, property: &str) -> Option<DateTime<Utc>> {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
- let xmpstring = try_opt!(self.xmp.get_property(ns, property, &mut flags));
+ let xmpstring = try_opt!(self.xmp.get_property(ns, property, &mut flags).ok());
let date = try_opt!(DateTime::parse_from_rfc3339(xmpstring.to_str()).ok());
Some(date.with_timezone(&Utc))
}
@@ -385,7 +386,7 @@ mod tests {
property: &str, expected_value: &str) {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
let value = meta.xmp.get_property(ns, property, &mut flags);
- assert!(value.is_some());
+ assert!(value.is_ok());
assert_eq!(value.unwrap().to_str(), expected_value);
}
@@ -393,7 +394,7 @@ mod tests {
property: &str, idx: i32, expected_value: &str) {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
let value = meta.xmp.get_array_item(ns, property, idx, &mut flags);
- assert!(value.is_some());
+ assert!(value.is_ok());
assert_eq!(value.unwrap().to_str(), expected_value);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]