[niepce] npc-engine: Np values are now consts of u32 type
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] npc-engine: Np values are now consts of u32 type
- Date: Mon, 27 Jan 2020 05:43:02 +0000 (UTC)
commit 530c15cefed32a19b2215abcec1adeb1957e7c2c
Author: Hubert Figuière <hub figuiere net>
Date: Sun Jan 19 16:22:15 2020 -0500
npc-engine: Np values are now consts of u32 type
crates/npc-engine/build.rs | 3 ++-
crates/npc-engine/src/db/libfile.rs | 17 +++++++++--------
crates/npc-engine/src/db/libmetadata.rs | 29 ++++++++++++++---------------
crates/npc-engine/src/db/library.rs | 21 +++++++++++----------
4 files changed, 36 insertions(+), 34 deletions(-)
---
diff --git a/crates/npc-engine/build.rs b/crates/npc-engine/build.rs
index 7051f65..ac02cc8 100644
--- a/crates/npc-engine/build.rs
+++ b/crates/npc-engine/build.rs
@@ -19,7 +19,8 @@ fn main() {
// The input header we would like to generate
// bindings for.
.whitelist_type("eng::NiepceProperties")
- .rustified_enum("eng::NiepceProperties")
+ .constified_enum("eng::NiepceProperties")
+ .prepend_enum_name(false)
.opaque_type("std::.*")
.whitelist_type("fwk::FileList")
.whitelist_type("eng::IndexToXmp")
diff --git a/crates/npc-engine/src/db/libfile.rs b/crates/npc-engine/src/db/libfile.rs
index 04d94b6..2776421 100644
--- a/crates/npc-engine/src/db/libfile.rs
+++ b/crates/npc-engine/src/db/libfile.rs
@@ -27,6 +27,7 @@ use std::path::{Path, PathBuf};
use super::fsfile::FsFile;
use super::FromDb;
use super::LibraryId;
+use crate::root::eng;
use crate::root::eng::NiepceProperties as Np;
use npc_fwk;
use npc_fwk::base::PropertyIndex;
@@ -167,20 +168,20 @@ impl LibFile {
pub fn property(&self, idx: Np) -> i32 {
match idx {
- Np::NpTiffOrientationProp => self.orientation(),
- Np::NpXmpRatingProp => self.rating(),
- Np::NpXmpLabelProp => self.label(),
- Np::NpNiepceFlagProp => self.flag(),
+ eng::NpTiffOrientationProp => self.orientation(),
+ eng::NpXmpRatingProp => self.rating(),
+ eng::NpXmpLabelProp => self.label(),
+ eng::NpNiepceFlagProp => self.flag(),
_ => -1,
}
}
pub fn set_property(&mut self, idx: Np, value: i32) {
match idx {
- Np::NpTiffOrientationProp => self.set_orientation(value),
- Np::NpXmpRatingProp => self.set_rating(value),
- Np::NpXmpLabelProp => self.set_label(value),
- Np::NpNiepceFlagProp => self.set_flag(value),
+ eng::NpTiffOrientationProp => self.set_orientation(value),
+ eng::NpXmpRatingProp => self.set_rating(value),
+ eng::NpXmpLabelProp => self.set_label(value),
+ eng::NpNiepceFlagProp => self.set_flag(value),
_ => err_out!("invalid property {:?} - noop", idx),
};
}
diff --git a/crates/npc-engine/src/db/libmetadata.rs b/crates/npc-engine/src/db/libmetadata.rs
index e2a43fc..d881dfa 100644
--- a/crates/npc-engine/src/db/libmetadata.rs
+++ b/crates/npc-engine/src/db/libmetadata.rs
@@ -1,7 +1,7 @@
/*
* niepce - eng/db/libmetadata.rs
*
- * Copyright (C) 2017-2019 Hubert Figuière
+ * Copyright (C) 2017-2020 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,10 +21,10 @@ use chrono::Utc;
use exempi;
use rusqlite;
use std::ffi::CStr;
-use std::mem::transmute;
use super::{FromDb, LibraryId};
use crate::db::libfile::FileType;
+use crate::root::eng;
use crate::root::eng::NiepceProperties as Np;
use npc_fwk::utils::exempi::{NS_DC, NS_XAP};
use npc_fwk::{xmp_date_from, PropertyBag, PropertySet, PropertyValue, XmpMeta};
@@ -195,29 +195,28 @@ impl LibMetadata {
pub fn to_properties(&self, propset: &PropertySet) -> PropertyBag {
let mut props = PropertyBag::new();
for prop_id in propset {
- let prop_id_np: Np = unsafe { transmute(*prop_id) };
- match prop_id_np {
- Np::NpXmpRatingProp => {
+ match *prop_id {
+ eng::NpXmpRatingProp => {
if let Some(rating) = self.xmp.rating() {
props.set_value(*prop_id, PropertyValue::Int(rating));
}
}
- Np::NpXmpLabelProp => {
+ eng::NpXmpLabelProp => {
if let Some(label) = self.xmp.label() {
props.set_value(*prop_id, PropertyValue::String(label));
}
}
- Np::NpTiffOrientationProp => {
+ eng::NpTiffOrientationProp => {
if let Some(orientation) = self.xmp.orientation() {
props.set_value(*prop_id, PropertyValue::Int(orientation));
}
}
- Np::NpExifDateTimeOriginalProp => {
+ eng::NpExifDateTimeOriginalProp => {
if let Some(date) = self.xmp.creation_date() {
props.set_value(*prop_id, PropertyValue::Date(date));
}
}
- Np::NpIptcKeywordsProp => {
+ eng::NpIptcKeywordsProp => {
let mut iter = exempi::XmpIterator::new(
&self.xmp.xmp,
NS_DC,
@@ -234,10 +233,10 @@ impl LibMetadata {
}
props.set_value(*prop_id, PropertyValue::StringArray(keywords));
}
- Np::NpFileNameProp => {
+ eng::NpFileNameProp => {
props.set_value(*prop_id, PropertyValue::String(self.name.clone()));
}
- Np::NpFileTypeProp => {
+ eng::NpFileTypeProp => {
// XXX this to string convert should be elsewhere
let file_type = match self.file_type {
FileType::UNKNOWN => "Unknown",
@@ -248,15 +247,15 @@ impl LibMetadata {
};
props.set_value(*prop_id, PropertyValue::String(String::from(file_type)));
}
- Np::NpFileSizeProp => {}
- Np::NpFolderProp => {
+ eng::NpFileSizeProp => {}
+ eng::NpFolderProp => {
props.set_value(*prop_id, PropertyValue::String(self.folder.clone()));
}
- Np::NpSidecarsProp => {
+ eng::NpSidecarsProp => {
props.set_value(*prop_id, PropertyValue::StringArray(self.sidecars.clone()));
}
_ => {
- if let Some(propval) = self.get_metadata(prop_id_np) {
+ if let Some(propval) = self.get_metadata(*prop_id) {
props.set_value(*prop_id, propval);
} else {
dbg_out!("missing prop {}", prop_id);
diff --git a/crates/npc-engine/src/db/library.rs b/crates/npc-engine/src/db/library.rs
index fe85189..89856a4 100644
--- a/crates/npc-engine/src/db/library.rs
+++ b/crates/npc-engine/src/db/library.rs
@@ -1,7 +1,7 @@
/*
* niepce - engine/db/library.rs
*
- * Copyright (C) 2017-2019 Hubert Figuière
+ * Copyright (C) 2017-2020 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -36,6 +36,7 @@ use crate::db::libfolder;
use crate::db::libfolder::LibFolder;
use crate::db::libmetadata::LibMetadata;
use crate::library::notification::LibNotification;
+use crate::root::eng;
use crate::root::eng::NiepceProperties as Np;
use npc_fwk;
use npc_fwk::PropertyValue;
@@ -876,19 +877,19 @@ impl Library {
pub fn set_metadata(&self, file_id: LibraryId, meta: Np, value: &PropertyValue) -> Result<()> {
match meta {
- Np::NpXmpRatingProp
- | Np::NpXmpLabelProp
- | Np::NpTiffOrientationProp
- | Np::NpNiepceFlagProp => {
+ eng::NpXmpRatingProp
+ | eng::NpXmpLabelProp
+ | eng::NpTiffOrientationProp
+ | eng::NpNiepceFlagProp => {
match *value {
PropertyValue::Int(i) => {
// internal
// make the column mapping more generic.
let column = match meta {
- Np::NpXmpRatingProp => "rating",
- Np::NpXmpLabelProp => "orientation",
- Np::NpTiffOrientationProp => "label",
- Np::NpNiepceFlagProp => "flag",
+ eng::NpXmpRatingProp => "rating",
+ eng::NpXmpLabelProp => "orientation",
+ eng::NpTiffOrientationProp => "label",
+ eng::NpNiepceFlagProp => "flag",
_ => unreachable!(),
};
if !column.is_empty() {
@@ -898,7 +899,7 @@ impl Library {
_ => err_out!("improper value type for {:?}", meta),
}
}
- Np::NpIptcKeywordsProp => {
+ eng::NpIptcKeywordsProp => {
self.unassign_all_keywords_for_file(file_id)?;
match *value {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]