[niepce] npc-fwk: Cargo format
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] npc-fwk: Cargo format
- Date: Wed, 11 Dec 2019 01:18:37 +0000 (UTC)
commit 9196aac47f4f87dd14a73f42f7686c1314d64cc8
Author: Hubert Figuière <hub figuiere net>
Date: Sun Oct 27 17:00:19 2019 -0400
npc-fwk: Cargo format
crates/npc-fwk/src/base/date.rs | 4 +-
crates/npc-fwk/src/base/debug.rs | 13 +-
crates/npc-fwk/src/base/fractions.rs | 10 +-
crates/npc-fwk/src/base/propertybag.rs | 40 +--
crates/npc-fwk/src/base/propertyvalue.rs | 50 ++--
crates/npc-fwk/src/base/rgbcolour.rs | 10 +-
crates/npc-fwk/src/lib.rs | 26 +-
crates/npc-fwk/src/toolkit/mimetype.rs | 13 +-
crates/npc-fwk/src/toolkit/mod.rs | 1 -
crates/npc-fwk/src/utils/exempi.rs | 173 +++++++++---
crates/npc-fwk/src/utils/exiv2.rs | 434 +++++++++++++++++++++++--------
crates/npc-fwk/src/utils/files.rs | 12 +-
12 files changed, 535 insertions(+), 251 deletions(-)
---
diff --git a/crates/npc-fwk/src/base/date.rs b/crates/npc-fwk/src/base/date.rs
index 10463bf..4dfb64b 100644
--- a/crates/npc-fwk/src/base/date.rs
+++ b/crates/npc-fwk/src/base/date.rs
@@ -43,5 +43,7 @@ pub unsafe extern "C" fn fwk_date_delete(date: *mut Date) {
#[no_mangle]
pub extern "C" fn fwk_date_to_string(date: &Date) -> *mut libc::c_char {
- CString::new(date.to_string().as_bytes()).unwrap().into_raw()
+ CString::new(date.to_string().as_bytes())
+ .unwrap()
+ .into_raw()
}
diff --git a/crates/npc-fwk/src/base/debug.rs b/crates/npc-fwk/src/base/debug.rs
index 7970ba6..7c13775 100644
--- a/crates/npc-fwk/src/base/debug.rs
+++ b/crates/npc-fwk/src/base/debug.rs
@@ -1,4 +1,3 @@
-
#[macro_export]
macro_rules! dbg_out {
( $( $x:expr ),* ) => {
@@ -33,14 +32,12 @@ macro_rules! err_out_line {
/// Does NOT abort of call assert!()
#[macro_export]
macro_rules! dbg_assert {
- ( $cond:expr, $msg:expr ) => {
- {
- if !$cond {
- print!("ASSERT: {}:{}: {}", file!(), line!(), stringify!($cond));
- println!( $msg );
- }
+ ( $cond:expr, $msg:expr ) => {{
+ if !$cond {
+ print!("ASSERT: {}:{}: {}", file!(), line!(), stringify!($cond));
+ println!($msg);
}
- };
+ }};
}
#[cfg(test)]
diff --git a/crates/npc-fwk/src/base/fractions.rs b/crates/npc-fwk/src/base/fractions.rs
index aa8e1bc..a6c692b 100644
--- a/crates/npc-fwk/src/base/fractions.rs
+++ b/crates/npc-fwk/src/base/fractions.rs
@@ -19,11 +19,10 @@
use std::f64;
-
-pub fn fraction_to_decimal(value: &str) -> Option<f64>
-{
- let numbers: Vec<i64> = value.split('/')
- .map(|s| { s.parse::<i64>().unwrap_or(0) })
+pub fn fraction_to_decimal(value: &str) -> Option<f64> {
+ let numbers: Vec<i64> = value
+ .split('/')
+ .map(|s| s.parse::<i64>().unwrap_or(0))
.collect();
if numbers.len() != 2 {
return None;
@@ -34,7 +33,6 @@ pub fn fraction_to_decimal(value: &str) -> Option<f64>
Some(numbers[0] as f64 / numbers[1] as f64)
}
-
#[cfg(test)]
mod tests {
#[test]
diff --git a/crates/npc-fwk/src/base/propertybag.rs b/crates/npc-fwk/src/base/propertybag.rs
index 99ed0ca..153809a 100644
--- a/crates/npc-fwk/src/base/propertybag.rs
+++ b/crates/npc-fwk/src/base/propertybag.rs
@@ -20,8 +20,8 @@
use std::collections::BTreeMap;
use std::ptr;
-use crate::base::PropertyIndex;
use crate::base::propertyvalue::PropertyValue;
+use crate::base::PropertyIndex;
#[derive(Default)]
pub struct PropertyBag {
@@ -30,7 +30,6 @@ pub struct PropertyBag {
}
impl PropertyBag {
-
pub fn new() -> Self {
PropertyBag::default()
}
@@ -67,7 +66,7 @@ pub unsafe extern "C" fn fwk_property_bag_delete(bag: *mut PropertyBag) {
pub unsafe extern "C" fn fwk_property_bag_is_empty(b: *const PropertyBag) -> bool {
match b.as_ref() {
Some(ref pb) => pb.is_empty(),
- None => true
+ None => true,
}
}
@@ -75,22 +74,26 @@ pub unsafe extern "C" fn fwk_property_bag_is_empty(b: *const PropertyBag) -> boo
pub unsafe extern "C" fn fwk_property_bag_len(b: *const PropertyBag) -> usize {
match b.as_ref() {
Some(ref pb) => pb.len(),
- None => unreachable!()
+ None => unreachable!(),
}
}
#[no_mangle]
-pub unsafe extern "C" fn fwk_property_bag_key_by_index(b: *const PropertyBag, idx: usize)
- -> PropertyIndex {
+pub unsafe extern "C" fn fwk_property_bag_key_by_index(
+ b: *const PropertyBag,
+ idx: usize,
+) -> PropertyIndex {
match b.as_ref() {
Some(ref pb) => pb.bag[idx],
- None => unreachable!()
+ None => unreachable!(),
}
}
#[no_mangle]
-pub unsafe extern "C" fn fwk_property_bag_value(b: *const PropertyBag, key: PropertyIndex)
- -> *mut PropertyValue {
+pub unsafe extern "C" fn fwk_property_bag_value(
+ b: *const PropertyBag,
+ key: PropertyIndex,
+) -> *mut PropertyValue {
match b.as_ref() {
Some(ref pb) => {
if pb.map.contains_key(&key) {
@@ -99,22 +102,23 @@ pub unsafe extern "C" fn fwk_property_bag_value(b: *const PropertyBag, key: Prop
} else {
ptr::null_mut()
}
- },
- None => unreachable!()
+ }
+ None => unreachable!(),
}
}
#[no_mangle]
-pub unsafe extern "C" fn fwk_property_bag_set_value(b: *mut PropertyBag, key: PropertyIndex,
- v: *const PropertyValue) -> bool {
+pub unsafe extern "C" fn fwk_property_bag_set_value(
+ b: *mut PropertyBag,
+ key: PropertyIndex,
+ v: *const PropertyValue,
+) -> bool {
let value = match v.as_ref() {
Some(value) => value.clone(),
- None => unreachable!()
+ None => unreachable!(),
};
match b.as_mut() {
- Some(ref mut pb) => {
- pb.set_value(key, value)
- },
- None => unreachable!()
+ Some(ref mut pb) => pb.set_value(key, value),
+ None => unreachable!(),
}
}
diff --git a/crates/npc-fwk/src/base/propertyvalue.rs b/crates/npc-fwk/src/base/propertyvalue.rs
index 2332648..c6fb754 100644
--- a/crates/npc-fwk/src/base/propertyvalue.rs
+++ b/crates/npc-fwk/src/base/propertyvalue.rs
@@ -18,21 +18,20 @@
*/
use libc::c_char;
-use std::ffi::{CStr,CString};
+use std::ffi::{CStr, CString};
use super::date::Date;
-#[derive(Clone,Debug)]
+#[derive(Clone, Debug)]
pub enum PropertyValue {
Empty,
Int(i32),
String(String),
StringArray(Vec<String>),
- Date(Date)
+ Date(Date),
}
-unsafe impl Send for PropertyValue {
-}
+unsafe impl Send for PropertyValue {}
#[no_mangle]
pub unsafe extern "C" fn fwk_property_value_new_str(v: *const c_char) -> *mut PropertyValue {
@@ -55,7 +54,7 @@ pub extern "C" fn fwk_property_value_new_date(v: &Date) -> *mut PropertyValue {
#[no_mangle]
pub extern "C" fn fwk_property_value_new_string_array() -> *mut PropertyValue {
- let value = Box::new(PropertyValue::StringArray(vec!()));
+ let value = Box::new(PropertyValue::StringArray(vec![]));
Box::into_raw(value)
}
@@ -70,7 +69,7 @@ pub unsafe extern "C" fn fwk_property_value_delete(v: *mut PropertyValue) {
pub unsafe extern "C" fn fwk_property_value_is_empty(v: *const PropertyValue) -> bool {
match v.as_ref() {
Some(&PropertyValue::Empty) => true,
- _ => false
+ _ => false,
}
}
@@ -78,7 +77,7 @@ pub unsafe extern "C" fn fwk_property_value_is_empty(v: *const PropertyValue) ->
pub unsafe extern "C" fn fwk_property_value_is_integer(v: *const PropertyValue) -> bool {
match v.as_ref() {
Some(&PropertyValue::Int(_)) => true,
- _ => false
+ _ => false,
}
}
@@ -86,7 +85,7 @@ pub unsafe extern "C" fn fwk_property_value_is_integer(v: *const PropertyValue)
pub unsafe extern "C" fn fwk_property_value_get_integer(v: *const PropertyValue) -> i32 {
match v.as_ref() {
Some(&PropertyValue::Int(i)) => i,
- _ => unreachable!()
+ _ => unreachable!(),
}
}
@@ -94,7 +93,7 @@ pub unsafe extern "C" fn fwk_property_value_get_integer(v: *const PropertyValue)
pub unsafe extern "C" fn fwk_property_value_is_date(v: *const PropertyValue) -> bool {
match v.as_ref() {
Some(&PropertyValue::Date(_)) => true,
- _ => false
+ _ => false,
}
}
@@ -102,7 +101,7 @@ pub unsafe extern "C" fn fwk_property_value_is_date(v: *const PropertyValue) ->
pub unsafe extern "C" fn fwk_property_value_get_date(v: *const PropertyValue) -> *const Date {
match v.as_ref() {
Some(&PropertyValue::Date(ref d)) => d,
- _ => unreachable!()
+ _ => unreachable!(),
}
}
@@ -110,17 +109,15 @@ pub unsafe extern "C" fn fwk_property_value_get_date(v: *const PropertyValue) ->
pub unsafe extern "C" fn fwk_property_value_is_string(v: *const PropertyValue) -> bool {
match v.as_ref() {
Some(&PropertyValue::String(_)) => true,
- _ => false
+ _ => false,
}
}
#[no_mangle]
pub unsafe extern "C" fn fwk_property_value_get_string(v: *const PropertyValue) -> *mut c_char {
match v.as_ref() {
- Some(&PropertyValue::String(ref s)) => {
- CString::new(s.as_bytes()).unwrap().into_raw()
- },
- _ => unreachable!()
+ Some(&PropertyValue::String(ref s)) => CString::new(s.as_bytes()).unwrap().into_raw(),
+ _ => unreachable!(),
}
}
@@ -129,29 +126,28 @@ pub unsafe extern "C" fn fwk_property_value_add_string(v: *mut PropertyValue, st
match v.as_mut() {
Some(&mut PropertyValue::StringArray(ref mut sa)) => {
sa.push(CStr::from_ptr(str).to_string_lossy().into_owned());
- },
- _ => unreachable!()
+ }
+ _ => unreachable!(),
}
-
}
#[no_mangle]
pub unsafe extern "C" fn fwk_property_value_count_string_array(v: *const PropertyValue) -> usize {
match v.as_ref() {
- Some(&PropertyValue::StringArray(ref sa)) => {
- sa.len()
- },
- _ => unreachable!()
+ Some(&PropertyValue::StringArray(ref sa)) => sa.len(),
+ _ => unreachable!(),
}
}
#[no_mangle]
-pub unsafe extern "C" fn fwk_property_value_get_string_at(v: *const PropertyValue, idx: usize)
- -> *mut c_char {
+pub unsafe extern "C" fn fwk_property_value_get_string_at(
+ v: *const PropertyValue,
+ idx: usize,
+) -> *mut c_char {
match v.as_ref() {
Some(&PropertyValue::StringArray(ref sa)) => {
CString::new(sa[idx].as_bytes()).unwrap().into_raw()
- },
- _ => unreachable!()
+ }
+ _ => unreachable!(),
}
}
diff --git a/crates/npc-fwk/src/base/rgbcolour.rs b/crates/npc-fwk/src/base/rgbcolour.rs
index 0bb11df..797fb0a 100644
--- a/crates/npc-fwk/src/base/rgbcolour.rs
+++ b/crates/npc-fwk/src/base/rgbcolour.rs
@@ -23,11 +23,11 @@ use std::num::ParseIntError;
use std::str::FromStr;
#[repr(C)]
-#[derive(Clone,Default)]
+#[derive(Clone, Default)]
pub struct RgbColour {
pub r: u16,
pub g: u16,
- pub b: u16
+ pub b: u16,
}
#[derive(Debug)]
@@ -47,14 +47,12 @@ impl From<ParseIntError> for ColourParseError {
}
impl RgbColour {
-
pub fn new(r: u16, g: u16, b: u16) -> RgbColour {
- RgbColour{r, g, b}
+ RgbColour { r, g, b }
}
}
impl FromStr for RgbColour {
-
type Err = ColourParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -91,7 +89,7 @@ pub extern "C" fn fwk_rgbcolour_component(c: &RgbColour, idx: i32) -> u16 {
0 => c.r,
1 => c.g,
2 => c.b,
- _ => unreachable!()
+ _ => unreachable!(),
}
}
diff --git a/crates/npc-fwk/src/lib.rs b/crates/npc-fwk/src/lib.rs
index 31e2367..9042c12 100644
--- a/crates/npc-fwk/src/lib.rs
+++ b/crates/npc-fwk/src/lib.rs
@@ -17,13 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
extern crate chrono;
extern crate exempi;
-extern crate gio_sys;
extern crate gio;
-extern crate glib_sys;
+extern crate gio_sys;
extern crate glib;
+extern crate glib_sys;
#[macro_use]
extern crate lazy_static;
extern crate libc;
@@ -34,31 +33,22 @@ extern crate try_opt;
#[macro_use]
pub mod base;
pub mod capi;
-pub mod utils;
pub mod toolkit;
+pub mod utils;
-pub use self::utils::exempi::{
- NsDef,
- ExempiManager,
- XmpMeta,
- gps_coord_from_xmp
-};
-pub use self::base::propertyvalue::PropertyValue;
+pub use self::base::fractions::fraction_to_decimal;
pub use self::base::propertybag::PropertyBag;
+pub use self::base::propertyvalue::PropertyValue;
pub use self::base::PropertySet;
-pub use self::base::fractions::{
- fraction_to_decimal
-};
+pub use self::utils::exempi::{gps_coord_from_xmp, ExempiManager, NsDef, XmpMeta};
pub use self::base::date::*;
-pub use self::toolkit::mimetype::{
- MimeType
-};
+pub use self::toolkit::mimetype::MimeType;
+use libc::c_char;
use std::f64;
use std::ffi::CStr;
-use libc::c_char;
#[no_mangle]
pub unsafe extern "C" fn fwk_gps_coord_from_xmp(cvalue: *const c_char) -> f64 {
diff --git a/crates/npc-fwk/src/toolkit/mimetype.rs b/crates/npc-fwk/src/toolkit/mimetype.rs
index 94daa99..aa68184 100644
--- a/crates/npc-fwk/src/toolkit/mimetype.rs
+++ b/crates/npc-fwk/src/toolkit/mimetype.rs
@@ -18,16 +18,16 @@
*/
use gio;
+use gio::prelude::*;
+use gio_sys;
use glib_sys;
use glib_sys::gboolean;
-use gio_sys;
-use gio::prelude::*;
use libc::c_void;
use std::ffi::CStr;
use std::ffi::CString;
-use std::ptr;
use std::path::Path;
+use std::ptr;
#[derive(PartialEq, Copy, Clone, Debug)]
pub enum IsRaw {
@@ -85,12 +85,7 @@ fn guess_type_for_file(filename: &str) -> MType {
let mut uncertainty: gboolean = 0;
let content_type = unsafe {
let cstr = CString::new(filename).unwrap();
- gio_sys::g_content_type_guess(
- cstr.as_ptr(),
- ptr::null_mut(),
- 0,
- &mut uncertainty,
- )
+ gio_sys::g_content_type_guess(cstr.as_ptr(), ptr::null_mut(), 0, &mut uncertainty)
};
let content_type_real = unsafe { CStr::from_ptr(content_type) };
let t = guess_type(&*content_type_real.to_string_lossy());
diff --git a/crates/npc-fwk/src/toolkit/mod.rs b/crates/npc-fwk/src/toolkit/mod.rs
index 45234c3..6ff5719 100644
--- a/crates/npc-fwk/src/toolkit/mod.rs
+++ b/crates/npc-fwk/src/toolkit/mod.rs
@@ -1,4 +1,3 @@
-
pub mod mimetype;
pub type Sender<T> = glib::Sender<T>;
diff --git a/crates/npc-fwk/src/utils/exempi.rs b/crates/npc-fwk/src/utils/exempi.rs
index 0f05edf..4fd4e26 100644
--- a/crates/npc-fwk/src/utils/exempi.rs
+++ b/crates/npc-fwk/src/utils/exempi.rs
@@ -70,18 +70,54 @@ impl From<i32> for Flash {
let mode = ((flash >> 3) & 0x3) as u8;
let function = ((flash >> 5) & 0x1) != 0;
let red_eye = ((flash >> 6) & 0x10) != 0;
- Flash { fired, rturn, mode, function, red_eye }
+ Flash {
+ fired,
+ rturn,
+ mode,
+ function,
+ red_eye,
+ }
}
}
impl Flash {
- pub fn set_as_xmp_property(&self, xmp: &mut Xmp, ns: &str, property: &str) -> exempi::Result<()> {
+ pub fn set_as_xmp_property(
+ &self,
+ xmp: &mut Xmp,
+ ns: &str,
+ property: &str,
+ ) -> exempi::Result<()> {
// XXX use set_struct_field() as soon as it is available
- xmp.set_property(ns, &format!("{}/exif:Fired", property), bool_to_propstring(self.fired),
exempi::PROP_NONE)?;
- xmp.set_property(ns, &format!("{}/exif:Return", property), &format!("{}", self.rturn),
exempi::PROP_NONE)?;
- xmp.set_property(ns, &format!("{}/exif:Mode", property), &format!("{}", self.mode),
exempi::PROP_NONE)?;
- xmp.set_property(ns, &format!("{}/exif:Function", property), bool_to_propstring(self.function),
exempi::PROP_NONE)?;
- xmp.set_property(ns, &format!("{}/exif:RedEyeMode", property), bool_to_propstring(self.red_eye),
exempi::PROP_NONE)?;
+ xmp.set_property(
+ ns,
+ &format!("{}/exif:Fired", property),
+ bool_to_propstring(self.fired),
+ exempi::PROP_NONE,
+ )?;
+ xmp.set_property(
+ ns,
+ &format!("{}/exif:Return", property),
+ &format!("{}", self.rturn),
+ exempi::PROP_NONE,
+ )?;
+ xmp.set_property(
+ ns,
+ &format!("{}/exif:Mode", property),
+ &format!("{}", self.mode),
+ exempi::PROP_NONE,
+ )?;
+ xmp.set_property(
+ ns,
+ &format!("{}/exif:Function", property),
+ bool_to_propstring(self.function),
+ exempi::PROP_NONE,
+ )?;
+ xmp.set_property(
+ ns,
+ &format!("{}/exif:RedEyeMode", property),
+ bool_to_propstring(self.red_eye),
+ exempi::PROP_NONE,
+ )?;
Ok(())
}
@@ -92,8 +128,7 @@ pub struct NsDef {
prefix: String,
}
-pub struct ExempiManager {
-}
+pub struct ExempiManager {}
impl ExempiManager {
pub fn new(namespaces: Option<Vec<NsDef>>) -> ExempiManager {
@@ -147,7 +182,7 @@ impl XmpMeta {
if let Ok(xmpfile) = exempi::XmpFile::open_new(file, exempi::OPEN_READ) {
meta = match xmpfile.get_new_xmp() {
Ok(xmp) => Some(Self::new_with_xmp(xmp)),
- _ => exiv2::xmp_from_exiv2(file)
+ _ => exiv2::xmp_from_exiv2(file),
}
}
}
@@ -172,7 +207,11 @@ impl XmpMeta {
sidecar_meta
} else {
let mut final_meta = sidecar_meta.unwrap();
- if !meta.as_ref().unwrap().merge_missing_into_xmp(&mut final_meta) {
+ if !meta
+ .as_ref()
+ .unwrap()
+ .merge_missing_into_xmp(&mut final_meta)
+ {
err_out!("xmp merge failed");
// XXX with the current heuristics, it is probably safe to just
// keep the source metadata.
@@ -193,8 +232,11 @@ impl XmpMeta {
let dest_date = dest.get_date_property(NS_XAP, "MetadataDate");
if source_date.is_none() || dest_date.is_none() {
- dbg_out!("missing metadata date {} {}", source_date.is_some(),
- dest_date.is_some());
+ dbg_out!(
+ "missing metadata date {} {}",
+ source_date.is_some(),
+ dest_date.is_some()
+ );
return false;
}
if source_date > dest_date {
@@ -215,15 +257,22 @@ impl XmpMeta {
continue;
}
if option.contains(exempi::PROP_VALUE_IS_ARRAY)
- || option.contains(exempi::PROP_VALUE_IS_STRUCT) {
+ || option.contains(exempi::PROP_VALUE_IS_STRUCT)
+ {
iter.skip(exempi::ITER_SKIP_SUBTREE);
continue;
}
- 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).is_err() {
- err_out!("Can set property {}", name);
+ 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,
+ ).is_err()
+ {
+ err_out!("Can set property {}", name);
}
}
}
@@ -234,7 +283,11 @@ impl XmpMeta {
pub fn serialize_inline(&self) -> String {
if let Ok(xmpstr) = self.xmp.serialize_and_format(
exempi::SERIAL_OMITPACKETWRAPPER | exempi::SERIAL_OMITALLFORMATTING,
- 0, "", "", 0) {
+ 0,
+ "",
+ "",
+ 0,
+ ) {
let buf = String::from(xmpstr.to_str());
return buf;
}
@@ -242,8 +295,10 @@ impl XmpMeta {
}
pub fn serialize(&self) -> String {
- if let Ok(xmpstr) = self.xmp.serialize_and_format(
- exempi::SERIAL_OMITPACKETWRAPPER, 0, "\n", "", 0) {
+ if let Ok(xmpstr) =
+ self.xmp
+ .serialize_and_format(exempi::SERIAL_OMITPACKETWRAPPER, 0, "\n", "", 0)
+ {
let buf = String::from(xmpstr.to_str());
return buf;
}
@@ -256,7 +311,9 @@ impl XmpMeta {
pub fn orientation(&self) -> Option<i32> {
let mut flags: exempi::PropFlags = exempi::PropFlags::empty();
- self.xmp.get_property_i32(NS_TIFF, "Orientation", &mut flags).ok()
+ self.xmp
+ .get_property_i32(NS_TIFF, "Orientation", &mut flags)
+ .ok()
}
pub fn label(&self) -> Option<String> {
@@ -272,12 +329,18 @@ impl XmpMeta {
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).ok()
+ 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).ok());
+ 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))
@@ -285,7 +348,11 @@ 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).ok());
+ let xmpstring = try_opt!(
+ self.xmp
+ .get_property(NS_EXIF, "DateTimeOriginal", &mut flags)
+ .ok()
+ );
Some(String::from(xmpstring.to_str()))
}
@@ -301,7 +368,11 @@ impl XmpMeta {
let xmpstring = property.unwrap();
let parsed = DateTime::parse_from_rfc3339(xmpstring.to_str());
if parsed.is_err() {
- err_out!("Error parsing property value '{}': {:?}", xmpstring, parsed.err());
+ err_out!(
+ "Error parsing property value '{}': {:?}",
+ xmpstring,
+ parsed.err()
+ );
return None;
}
let date = parsed.unwrap();
@@ -312,8 +383,8 @@ impl XmpMeta {
if !self.keywords_fetched {
use exempi::XmpString;
- let mut iter = exempi::XmpIterator::new(&self.xmp, NS_DC, "subject",
- exempi::ITER_JUST_LEAF_NODES);
+ let mut iter =
+ exempi::XmpIterator::new(&self.xmp, NS_DC, "subject", exempi::ITER_JUST_LEAF_NODES);
let mut schema = XmpString::new();
let mut name = XmpString::new();
let mut value = XmpString::new();
@@ -344,10 +415,8 @@ pub fn gps_coord_from_xmp(xmps: &str) -> Option<f64> {
// get rid of the comma
let (_, current) = current.split_at(1);
let orientation = match current.chars().last() {
- Some('N') | Some('E') =>
- 1.0f64,
- Some('S') | Some('W') =>
- -1.0f64,
+ Some('N') | Some('E') => 1.0f64,
+ Some('S') | Some('W') => -1.0f64,
_ => return None,
};
@@ -447,11 +516,11 @@ pub unsafe extern "C" fn fwk_exempi_manager_delete(em: *mut ExempiManager) {
#[cfg(test)]
mod tests {
- use std::path::PathBuf;
+ use super::xmp_date_from_exif;
use super::ExempiManager;
use super::XmpMeta;
- use super::xmp_date_from_exif;
use exempi;
+ use std::path::PathBuf;
fn get_xmp_sample_path() -> PathBuf {
use std::env;
@@ -470,7 +539,6 @@ mod tests {
#[test]
fn xmp_meta_works() {
-
let mut dir = get_xmp_sample_path();
dir.push("test.xmp");
let _xmp_manager = ExempiManager::new(None);
@@ -494,16 +562,20 @@ mod tests {
}
}
- fn test_property_value(meta: &XmpMeta, ns: &str,
- property: &str, expected_value: &str) {
+ fn test_property_value(meta: &XmpMeta, ns: &str, 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_ok());
assert_eq!(value.unwrap().to_str(), expected_value);
}
- fn test_property_array_value(meta: &XmpMeta, ns: &str,
- property: &str, idx: i32, expected_value: &str) {
+ fn test_property_array_value(
+ meta: &XmpMeta,
+ ns: &str,
+ 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_ok());
@@ -542,7 +614,13 @@ mod tests {
test_property_array_value(&dstmeta, super::NS_DC, "subject", 1, "night");
test_property_array_value(&dstmeta, super::NS_DC, "subject", 2, "ontario");
test_property_array_value(&dstmeta, super::NS_DC, "subject", 3, "ottawa");
- test_property_array_value(&dstmeta, super::NS_DC, "subject", 4, "parliament of canada");
+ test_property_array_value(
+ &dstmeta,
+ super::NS_DC,
+ "subject",
+ 4,
+ "parliament of canada",
+ );
assert!(!dstmeta.xmp.has_property(super::NS_DC, "dc:subject[5]"));
}
} else {
@@ -576,17 +654,26 @@ mod tests {
// well-formed 1
output = gps_coord_from_xmp("45,29.6681666667N");
assert!(output.is_some());
- assert_eq!(output.unwrap(), 45.494469444445002181964810006320476531982421875);
+ assert_eq!(
+ output.unwrap(),
+ 45.494469444445002181964810006320476531982421875
+ );
// well-formed 2
output = gps_coord_from_xmp("73,38.2871666667W");
assert!(output.is_some());
- assert_eq!(output.unwrap(), -73.6381194444449960201382054947316646575927734375);
+ assert_eq!(
+ output.unwrap(),
+ -73.6381194444449960201382054947316646575927734375
+ );
// well-formed 3
output = gps_coord_from_xmp("45,29,30.45N");
assert!(output.is_some());
- assert_eq!(output.unwrap(), 45.49179166666666418450404307805001735687255859375);
+ assert_eq!(
+ output.unwrap(),
+ 45.49179166666666418450404307805001735687255859375
+ );
}
#[test]
diff --git a/crates/npc-fwk/src/utils/exiv2.rs b/crates/npc-fwk/src/utils/exiv2.rs
index 898c850..941e26c 100644
--- a/crates/npc-fwk/src/utils/exiv2.rs
+++ b/crates/npc-fwk/src/utils/exiv2.rs
@@ -17,13 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use std::ffi::OsStr;
use multimap::MultiMap;
+use std::ffi::OsStr;
use exempi;
use rexiv2;
-use super::exempi::{Flash, XmpMeta, NS_TIFF, NS_EXIF, NS_EXIF_EX, NS_AUX, NS_XAP, xmp_date_from_exif};
+use super::exempi::{
+ xmp_date_from_exif, Flash, XmpMeta, NS_AUX, NS_EXIF, NS_EXIF_EX, NS_TIFF, NS_XAP,
+};
/// Property conversion rules
#[derive(Clone, Copy, Debug)]
@@ -54,60 +56,180 @@ enum Converted {
lazy_static! {
static ref EXIV2_TO_XMP: MultiMap<&'static str, (&'static str, &'static str, Conversion)> = {
[
- ("Exif.Image.DateTime", (NS_XAP, "ModifyDate", Conversion::ExifDate)),
- ("Exif.Image.ImageHeight", (NS_TIFF, "ImageHeight", Conversion::None)),
- ("Exif.Image.ImageWidth", (NS_TIFF, "ImageWidth", Conversion::None)),
+ (
+ "Exif.Image.DateTime",
+ (NS_XAP, "ModifyDate", Conversion::ExifDate),
+ ),
+ (
+ "Exif.Image.ImageHeight",
+ (NS_TIFF, "ImageHeight", Conversion::None),
+ ),
+ (
+ "Exif.Image.ImageWidth",
+ (NS_TIFF, "ImageWidth", Conversion::None),
+ ),
("Exif.Image.Make", (NS_TIFF, "Make", Conversion::None)),
("Exif.Image.Model", (NS_TIFF, "Model", Conversion::None)),
- ("Exif.Image.Orientation", (NS_TIFF, "Orientation", Conversion::None)),
- ("Exif.Image.Software", (NS_TIFF, "Software", Conversion::None)),
- ("Exif.Photo.ApertureValue", (NS_EXIF, "ApertureValue", Conversion::None)),
- ("Exif.Photo.BodySerialNumber", (NS_EXIF_EX, "BodySerialNumber", Conversion::None)),
- ("Exif.Photo.CameraOwnerName", (NS_EXIF_EX, "CameraOwnerName", Conversion::None)),
- ("Exif.Photo.ColorSpace", (NS_EXIF, "ColorSpace", Conversion::None)),
- ("Exif.Photo.DateTimeOriginal", (NS_EXIF, "DateTimeOriginal", Conversion::ExifDate)),
- ("Exif.Photo.DateTimeDigitized", (NS_XAP, "CreateDate", Conversion::ExifDate)),
- ("Exif.Photo.ExposureBiasValue", (NS_EXIF, "ExposureBiasValue", Conversion::None)),
- ("Exif.Photo.ExposureMode", (NS_EXIF, "ExposureMode", Conversion::None)),
- ("Exif.Photo.ExposureProgram", (NS_EXIF, "ExposureProgram", Conversion::None)),
- ("Exif.Photo.ExposureTime", (NS_EXIF, "ExposureTime", Conversion::None)),
+ (
+ "Exif.Image.Orientation",
+ (NS_TIFF, "Orientation", Conversion::None),
+ ),
+ (
+ "Exif.Image.Software",
+ (NS_TIFF, "Software", Conversion::None),
+ ),
+ (
+ "Exif.Photo.ApertureValue",
+ (NS_EXIF, "ApertureValue", Conversion::None),
+ ),
+ (
+ "Exif.Photo.BodySerialNumber",
+ (NS_EXIF_EX, "BodySerialNumber", Conversion::None),
+ ),
+ (
+ "Exif.Photo.CameraOwnerName",
+ (NS_EXIF_EX, "CameraOwnerName", Conversion::None),
+ ),
+ (
+ "Exif.Photo.ColorSpace",
+ (NS_EXIF, "ColorSpace", Conversion::None),
+ ),
+ (
+ "Exif.Photo.DateTimeOriginal",
+ (NS_EXIF, "DateTimeOriginal", Conversion::ExifDate),
+ ),
+ (
+ "Exif.Photo.DateTimeDigitized",
+ (NS_XAP, "CreateDate", Conversion::ExifDate),
+ ),
+ (
+ "Exif.Photo.ExposureBiasValue",
+ (NS_EXIF, "ExposureBiasValue", Conversion::None),
+ ),
+ (
+ "Exif.Photo.ExposureMode",
+ (NS_EXIF, "ExposureMode", Conversion::None),
+ ),
+ (
+ "Exif.Photo.ExposureProgram",
+ (NS_EXIF, "ExposureProgram", Conversion::None),
+ ),
+ (
+ "Exif.Photo.ExposureTime",
+ (NS_EXIF, "ExposureTime", Conversion::None),
+ ),
("Exif.Photo.FNumber", (NS_EXIF, "FNumber", Conversion::None)),
("Exif.Photo.Flash", (NS_EXIF, "Flash", Conversion::Flash)),
- ("Exif.Photo.FocalLength", (NS_EXIF, "FocalLength", Conversion::None)),
- ("Exif.Photo.FocalLengthIn35mmFilm", (NS_EXIF, "FocalLengthIn35mmFilm", Conversion::None)),
- ("Exif.Photo.ISOSpeedRatings", (NS_EXIF, "ISOSpeedRatings", Conversion::None)),
- ("Exif.Photo.LensMake", (NS_EXIF_EX, "LensMake", Conversion::None)),
+ (
+ "Exif.Photo.FocalLength",
+ (NS_EXIF, "FocalLength", Conversion::None),
+ ),
+ (
+ "Exif.Photo.FocalLengthIn35mmFilm",
+ (NS_EXIF, "FocalLengthIn35mmFilm", Conversion::None),
+ ),
+ (
+ "Exif.Photo.ISOSpeedRatings",
+ (NS_EXIF, "ISOSpeedRatings", Conversion::None),
+ ),
+ (
+ "Exif.Photo.LensMake",
+ (NS_EXIF_EX, "LensMake", Conversion::None),
+ ),
("Exif.Photo.LensModel", (NS_AUX, "Lens", Conversion::None)),
- ("Exif.Photo.LensModel", (NS_EXIF_EX, "LensModel", Conversion::None)),
- ("Exif.Photo.LensSerialNumber", (NS_EXIF_EX, "LensSerialNumber", Conversion::None)),
- ("Exif.Photo.LensSpecification", (NS_EXIF_EX, "LensSpecification", Conversion::None)),
- ("Exif.Photo.LightSource", (NS_EXIF, "LightSource", Conversion::None)),
- ("Exif.Photo.MeteringMode", (NS_EXIF, "MeteringMode", Conversion::None)),
- ("Exif.Photo.SceneCaptureType", (NS_EXIF, "SceneCaptureType", Conversion::None)),
- ("Exif.Photo.ShutterSpeedValue", (NS_EXIF, "ShutterSpeedValue", Conversion::None)),
- ("Exif.Photo.UserComment", (NS_EXIF, "UserComment", Conversion::None)),
- ("Exif.Photo.WhiteBalance", (NS_EXIF, "WhiteBalance", Conversion::None)),
-
+ (
+ "Exif.Photo.LensModel",
+ (NS_EXIF_EX, "LensModel", Conversion::None),
+ ),
+ (
+ "Exif.Photo.LensSerialNumber",
+ (NS_EXIF_EX, "LensSerialNumber", Conversion::None),
+ ),
+ (
+ "Exif.Photo.LensSpecification",
+ (NS_EXIF_EX, "LensSpecification", Conversion::None),
+ ),
+ (
+ "Exif.Photo.LightSource",
+ (NS_EXIF, "LightSource", Conversion::None),
+ ),
+ (
+ "Exif.Photo.MeteringMode",
+ (NS_EXIF, "MeteringMode", Conversion::None),
+ ),
+ (
+ "Exif.Photo.SceneCaptureType",
+ (NS_EXIF, "SceneCaptureType", Conversion::None),
+ ),
+ (
+ "Exif.Photo.ShutterSpeedValue",
+ (NS_EXIF, "ShutterSpeedValue", Conversion::None),
+ ),
+ (
+ "Exif.Photo.UserComment",
+ (NS_EXIF, "UserComment", Conversion::None),
+ ),
+ (
+ "Exif.Photo.WhiteBalance",
+ (NS_EXIF, "WhiteBalance", Conversion::None),
+ ),
("Exif.Canon.LensModel", (NS_AUX, "Lens", Conversion::None)),
- ("Exif.Canon.LensModel", (NS_EXIF_EX, "LensModel", Conversion::None)),
-
- ("Exif.Minolta.LensID", (NS_AUX, "Lens", Conversion::Interpreted)),
- ("Exif.Minolta.LensID", (NS_EXIF_EX, "LensModel", Conversion::Interpreted)),
-
- ("Exif.Nikon3.Lens", (NS_AUX, "Lens", Conversion::Interpreted)),
- ("Exif.Nikon3.Lens", (NS_EXIF_EX, "LensModel", Conversion::Interpreted)),
-
- ("Exif.OlympusEq.LensModel", (NS_AUX, "Lens", Conversion::None)),
- ("Exif.OlympusEq.LensModel", (NS_EXIF_EX, "LensModel", Conversion::None)),
- ("Exif.OlympusEq.LensSerialNumber", (NS_EXIF_EX, "LensSerialNumber", Conversion::None)),
-
- ("Exif.Panasonic.LensType", (NS_AUX, "Lens", Conversion::None)),
- ("Exif.Panasonic.LensType", (NS_EXIF_EX, "LensModel", Conversion::None)),
- ("Exif.Panasonic.LensSerialNumber", (NS_EXIF_EX, "LensSerialNumber", Conversion::None)),
-
- ("Exif.Pentax.LensType", (NS_AUX, "Lens", Conversion::Interpreted)),
- ("Exif.Pentax.LensType", (NS_EXIF_EX, "LensModel", Conversion::Interpreted))
- ].iter().cloned().collect()
+ (
+ "Exif.Canon.LensModel",
+ (NS_EXIF_EX, "LensModel", Conversion::None),
+ ),
+ (
+ "Exif.Minolta.LensID",
+ (NS_AUX, "Lens", Conversion::Interpreted),
+ ),
+ (
+ "Exif.Minolta.LensID",
+ (NS_EXIF_EX, "LensModel", Conversion::Interpreted),
+ ),
+ (
+ "Exif.Nikon3.Lens",
+ (NS_AUX, "Lens", Conversion::Interpreted),
+ ),
+ (
+ "Exif.Nikon3.Lens",
+ (NS_EXIF_EX, "LensModel", Conversion::Interpreted),
+ ),
+ (
+ "Exif.OlympusEq.LensModel",
+ (NS_AUX, "Lens", Conversion::None),
+ ),
+ (
+ "Exif.OlympusEq.LensModel",
+ (NS_EXIF_EX, "LensModel", Conversion::None),
+ ),
+ (
+ "Exif.OlympusEq.LensSerialNumber",
+ (NS_EXIF_EX, "LensSerialNumber", Conversion::None),
+ ),
+ (
+ "Exif.Panasonic.LensType",
+ (NS_AUX, "Lens", Conversion::None),
+ ),
+ (
+ "Exif.Panasonic.LensType",
+ (NS_EXIF_EX, "LensModel", Conversion::None),
+ ),
+ (
+ "Exif.Panasonic.LensSerialNumber",
+ (NS_EXIF_EX, "LensSerialNumber", Conversion::None),
+ ),
+ (
+ "Exif.Pentax.LensType",
+ (NS_AUX, "Lens", Conversion::Interpreted),
+ ),
+ (
+ "Exif.Pentax.LensType",
+ (NS_EXIF_EX, "LensModel", Conversion::Interpreted),
+ ),
+ ]
+ .iter()
+ .cloned()
+ .collect()
};
}
@@ -136,7 +258,7 @@ fn convert_int(conversion: Conversion, int: i32) -> Converted {
pub fn xmp_from_exiv2<S: AsRef<OsStr>>(file: S) -> Option<XmpMeta> {
if let Ok(meta) = rexiv2::Metadata::new_from_path(file) {
let mut xmp = exempi::Xmp::new();
- let mut all_tags : Vec<String> = vec!();
+ let mut all_tags: Vec<String> = vec![];
if let Ok(mut tags) = meta.get_exif_tags() {
all_tags.append(&mut tags);
}
@@ -156,111 +278,212 @@ pub fn xmp_from_exiv2<S: AsRef<OsStr>>(file: S) -> Option<XmpMeta> {
let converted = convert(xmp_prop.2, &value);
match converted {
Converted::Str(s) => {
- if let Err(err) = xmp.set_property(xmp_prop.0, xmp_prop.1, &s,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
+ if let Err(err) = xmp.set_property(
+ xmp_prop.0,
+ xmp_prop.1,
+ &s,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
- },
+ }
Converted::Date(d) => {
if let Some(d) = d {
- if let Err(err) = xmp.set_property_date(xmp_prop.0, xmp_prop.1,
&d, exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
+ if let Err(err) = xmp.set_property_date(
+ xmp_prop.0,
+ xmp_prop.1,
+ &d,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
} else {
err_out!("Couldn't convert Exif date {}", &value);
}
- },
+ }
_ => {
err_out!("Unknown conversion result {:?}", &converted);
}
}
}
- },
- Ok(rexiv2::TagType::UnsignedShort) |
- Ok(rexiv2::TagType::UnsignedLong) |
- Ok(rexiv2::TagType::SignedShort) |
- Ok(rexiv2::TagType::SignedLong) => {
+ }
+ Ok(rexiv2::TagType::UnsignedShort)
+ | Ok(rexiv2::TagType::UnsignedLong)
+ | Ok(rexiv2::TagType::SignedShort)
+ | Ok(rexiv2::TagType::SignedLong) => {
// XXX rexiv2 returns an i32, which is a problem for UnsignedLong
match xmp_prop.2 {
Conversion::Flash => {
- if let Converted::Flash(flash) = convert_int(xmp_prop.2,
meta.get_tag_numeric(&tag)) {
- if let Err(err) = flash.set_as_xmp_property(&mut xmp, NS_EXIF,
"Flash") {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
+ if let Converted::Flash(flash) =
+ convert_int(xmp_prop.2, meta.get_tag_numeric(&tag))
+ {
+ if let Err(err) =
+ flash.set_as_xmp_property(&mut xmp, NS_EXIF, "Flash")
+ {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
}
- },
+ }
Conversion::None => {
let value = meta.get_tag_numeric(&tag);
- if let Err(err) = xmp.set_property_i32(xmp_prop.0, xmp_prop.1, value,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
+ if let Err(err) = xmp.set_property_i32(
+ xmp_prop.0,
+ xmp_prop.1,
+ value,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
- },
+ }
Conversion::Interpreted => {
if let Ok(value) = meta.get_tag_interpreted_string(&tag) {
- if let Err(err) = xmp.set_property(xmp_prop.0, xmp_prop.1, &value,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
+ if let Err(err) = xmp.set_property(
+ xmp_prop.0,
+ xmp_prop.1,
+ &value,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
}
}
_ => {
- err_out!("Unknown conversion from {:?} to {:?}", tagtype, xmp_prop.2);
+ err_out!(
+ "Unknown conversion from {:?} to {:?}",
+ tagtype,
+ xmp_prop.2
+ );
let value = meta.get_tag_numeric(&tag);
- if let Err(err) = xmp.set_property_i32(xmp_prop.0, xmp_prop.1, value,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
+ if let Err(err) = xmp.set_property_i32(
+ xmp_prop.0,
+ xmp_prop.1,
+ value,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
}
}
- },
- Ok(rexiv2::TagType::UnsignedRational) |
- Ok(rexiv2::TagType::SignedRational) => {
- match xmp_prop.2 {
- Conversion::Interpreted => {
- if let Ok(value) = meta.get_tag_interpreted_string(&tag) {
- if let Err(err) = xmp.set_property(xmp_prop.0, xmp_prop.1, &value,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
- }
- }
- },
- _ => if let Some(value) = meta.get_tag_rational(&tag) {
- let value_str = format!("{}/{}", value.numer(), value.denom());
- if let Err(err) = xmp.set_property(xmp_prop.0, xmp_prop.1, &value_str,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
+ }
+ Ok(rexiv2::TagType::UnsignedRational)
+ | Ok(rexiv2::TagType::SignedRational) => match xmp_prop.2 {
+ Conversion::Interpreted => {
+ if let Ok(value) = meta.get_tag_interpreted_string(&tag) {
+ if let Err(err) = xmp.set_property(
+ xmp_prop.0,
+ xmp_prop.1,
+ &value,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
- },
+ }
}
+ _ => if let Some(value) = meta.get_tag_rational(&tag) {
+ let value_str = format!("{}/{}", value.numer(), value.denom());
+ if let Err(err) = xmp.set_property(
+ xmp_prop.0,
+ xmp_prop.1,
+ &value_str,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
+ }
+ },
},
Ok(rexiv2::TagType::Comment) => {
if let Ok(value) = meta.get_tag_string(&tag) {
- if let Err(err) = xmp.set_property(xmp_prop.0, xmp_prop.1, &value,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0, &xmp_prop.1,
&err);
+ if let Err(err) = xmp.set_property(
+ xmp_prop.0,
+ xmp_prop.1,
+ &value,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
}
- },
- Ok(rexiv2::TagType::UnsignedByte) => {
- match xmp_prop.2 {
- Conversion::Interpreted => {
- if let Ok(value) = meta.get_tag_interpreted_string(&tag) {
- if let Err(err) = xmp.set_property(xmp_prop.0, xmp_prop.1, &value,
exempi::PROP_NONE) {
- err_out!("Error setting property {} {}: {:?}", &xmp_prop.0,
&xmp_prop.1, &err);
- }
+ }
+ Ok(rexiv2::TagType::UnsignedByte) => match xmp_prop.2 {
+ Conversion::Interpreted => {
+ if let Ok(value) = meta.get_tag_interpreted_string(&tag) {
+ if let Err(err) = xmp.set_property(
+ xmp_prop.0,
+ xmp_prop.1,
+ &value,
+ exempi::PROP_NONE,
+ ) {
+ err_out!(
+ "Error setting property {} {}: {:?}",
+ &xmp_prop.0,
+ &xmp_prop.1,
+ &err
+ );
}
- },
- _ => err_out!("Unhandled type {:?} for {}", tagtype, &tag),
+ }
}
- }
+ _ => err_out!("Unhandled type {:?} for {}", tagtype, &tag),
+ },
_ => {
err_out!("Unhandled type {:?} for {}", tagtype, &tag);
}
}
}
} else {
-// err_out!("Unknown property {}", &tag);
+ // err_out!("Unknown property {}", &tag);
}
}
meta.get_gps_info();
let mut options = exempi::PROP_NONE;
if let Ok(date) = xmp.get_property_date(NS_XAP, "ModifyDate", &mut options) {
- if let Err(err) = xmp.set_property_date(NS_XAP, "MetadataDate", &date, exempi::PROP_NONE) {
+ if let Err(err) =
+ xmp.set_property_date(NS_XAP, "MetadataDate", &date, exempi::PROP_NONE)
+ {
err_out!("Error setting MetadataDate: {:?}", &err);
}
} else {
@@ -271,4 +494,3 @@ pub fn xmp_from_exiv2<S: AsRef<OsStr>>(file: S) -> Option<XmpMeta> {
None
}
}
-
diff --git a/crates/npc-fwk/src/utils/files.rs b/crates/npc-fwk/src/utils/files.rs
index 6f9b879..bf793ea 100644
--- a/crates/npc-fwk/src/utils/files.rs
+++ b/crates/npc-fwk/src/utils/files.rs
@@ -17,14 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use glib::translate::*;
use gio;
use gio_sys;
+use glib::translate::*;
-use crate::toolkit::mimetype::{
- guess_type,
- MType
-};
+use crate::toolkit::mimetype::{guess_type, MType};
#[no_mangle]
pub unsafe extern "C" fn file_is_media(finfo: *mut gio_sys::GFileInfo) -> bool {
@@ -32,9 +29,8 @@ pub unsafe extern "C" fn file_is_media(finfo: *mut gio_sys::GFileInfo) -> bool {
if let Some(gmtype) = fileinfo.get_content_type() {
let t = guess_type(&gmtype);
return match t {
- MType::Image(_) |
- MType::Movie => true,
- _ => false
+ MType::Image(_) | MType::Movie => true,
+ _ => false,
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]