[niepce: 10/29] engine+rust: implement LibFile in Rust



commit 38d6874756781b23f767d186c35fb7323369f820
Author: Hubert Figuière <hub figuiere net>
Date:   Thu Jun 8 21:43:43 2017 -0400

    engine+rust: implement LibFile in Rust
    
    -add rust bindgen

 Cargo.toml                                         |    4 +
 build.rs                                           |   34 +++
 src/engine/Makefile.am                             |    2 +-
 src/engine/db/filebundle.cpp                       |   10 +-
 src/engine/db/filebundle.hpp                       |    6 +-
 src/engine/db/fsfile.cpp                           |   44 ----
 src/engine/db/fsfile.hpp                           |   45 ----
 src/engine/db/fsfile.rs                            |   42 ++--
 src/engine/db/libfile.cpp                          |  101 ++-------
 src/engine/db/libfile.hpp                          |  116 +++-------
 src/engine/db/libfile.rs                           |  250 ++++++++++++++++++++
 src/engine/db/library.cpp                          |   30 ++--
 src/engine/db/library.hpp                          |    4 +-
 src/engine/db/mod.rs                               |    1 +
 src/engine/db/properties-enum.hpp                  |   22 ++
 src/engine/db/properties.hpp                       |   19 +--
 src/engine/db/test_library.cpp                     |    8 +-
 src/engine/library/commands.cpp                    |    4 +-
 src/engine/library/notification.hpp                |    2 +-
 src/engine/library/thumbnailcache.cpp              |   18 +-
 src/engine/library/thumbnailcache.hpp              |    8 +-
 src/fwk/base/mod.rs                                |   21 ++-
 src/lib.rs                                         |    1 +
 src/niepce/modules/darkroom/darkroommodule.cpp     |   16 +-
 src/niepce/modules/darkroom/darkroommodule.hpp     |    4 +-
 .../modules/interfaces/ipostimportprocessing.hpp   |    2 +-
 src/niepce/ui/filmstripcontroller.cpp              |    4 +-
 src/niepce/ui/gridviewmodule.cpp                   |    4 +-
 src/niepce/ui/imageliststore.cpp                   |   10 +-
 src/niepce/ui/imageliststore.hpp                   |    2 +-
 src/niepce/ui/librarycellrenderer.cpp              |   36 ++--
 src/niepce/ui/librarycellrenderer.hpp              |    6 +-
 src/niepce/ui/selectioncontroller.cpp              |   36 ++--
 src/niepce/ui/selectioncontroller.hpp              |    6 +-
 34 files changed, 511 insertions(+), 407 deletions(-)
---
diff --git a/Cargo.toml b/Cargo.toml
index 64d5fd6..dddc75e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,6 +9,10 @@ sqlite = "0.23.4"
 exempi = "2.4.1"
 #gphoto = "0.1.1"
 
+[build-dependencies]
+# We need git master as currently it the crate version fail on shared_ptr<>
+bindgen = { git = "https://github.com/servo/rust-bindgen.git"; }
+
 [lib]
 name = "niece_rust"
 crate-type = ["staticlib"]
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..c48b426
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,34 @@
+extern crate bindgen;
+
+use std::env;
+use std::path::PathBuf;
+
+fn main() {
+
+    // The bindgen::Builder is the main entry point
+    // to bindgen, and lets you build up options for
+    // the resulting bindings.
+    let builder = bindgen::Builder::default()
+        // Do not generate unstable Rust code that
+        // requires a nightly rustc and enabling
+        // unstable features.
+        .no_unstable_rust()
+        .enable_cxx_namespaces()
+        .generate_comments(false)
+        // The input header we would like to generate
+        // bindings for.
+        .whitelisted_type("eng::NiepceProperties")
+        .header("src/engine/db/properties-enum.hpp")
+        .clang_arg("-I./src");
+
+    // Finish the builder and generate the bindings.
+    let bindings = builder.generate()
+    // Unwrap the Result and panic on failure.
+        .expect("Unable to generate bindings");
+
+    // Write the bindings to the $OUT_DIR/bindings.rs file.
+    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
+    bindings
+        .write_to_file(out_path.join("bindings.rs"))
+        .expect("Couldn't write bindings!");
+}
diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am
index 09f94a6..8123f1c 100644
--- a/src/engine/Makefile.am
+++ b/src/engine/Makefile.am
@@ -41,7 +41,7 @@ libniepceengine_a_SOURCES = \
        db/libmetadata.hpp db/libmetadata.cpp \
        db/keyword.hpp db/keyword.cpp \
        db/storage.hpp \
-       db/fsfile.hpp db/fsfile.cpp \
+       db/fsfile.hpp \
        db/filebundle.hpp db/filebundle.cpp \
        db/metadata.hpp \
        db/properties.hpp db/properties.cpp \
diff --git a/src/engine/db/filebundle.cpp b/src/engine/db/filebundle.cpp
index 17eb195..9b2611e 100644
--- a/src/engine/db/filebundle.cpp
+++ b/src/engine/db/filebundle.cpp
@@ -38,21 +38,21 @@ FileBundle::add(const std::string & path)
         if(mime_type.isDigicamRaw()) {
             if(!m_main.empty() && m_jpeg.empty()) {
                 m_jpeg = m_main;
-                m_type = LibFile::FileType::RAW_JPEG;
+                m_type = LibFileType::RAW_JPEG;
             }
             else {
-                m_type = LibFile::FileType::RAW;
+                m_type = LibFileType::RAW;
             }
             m_main = path;
         }
         else {
             if(!m_main.empty()) {
                 m_jpeg = path;
-                m_type = LibFile::FileType::RAW_JPEG;
+                m_type = LibFileType::RAW_JPEG;
             }
             else {
                 m_main = path;
-                m_type = LibFile::FileType::IMAGE;
+                m_type = LibFileType::IMAGE;
             }
         }
     }
@@ -61,7 +61,7 @@ FileBundle::add(const std::string & path)
     }
     else if(mime_type.isMovie()) {
         m_main = path;
-        m_type = LibFile::FileType::VIDEO;
+        m_type = LibFileType::VIDEO;
     }
     else {
         DBG_OUT("Unkown file %s of type %s\n", path.c_str(), 
diff --git a/src/engine/db/filebundle.hpp b/src/engine/db/filebundle.hpp
index 18470b2..d4300f4 100644
--- a/src/engine/db/filebundle.hpp
+++ b/src/engine/db/filebundle.hpp
@@ -38,9 +38,9 @@ public:
     typedef std::shared_ptr<List> ListPtr;
 
     FileBundle()
-        : m_type(LibFile::FileType::UNKNOWN)
+        : m_type(LibFileType::UNKNOWN)
         { }
-    LibFile::FileType type() const
+    LibFileType type() const
         { return m_type; }
 
     /** add a file to a bundle. Will determine what type it is. 
@@ -56,7 +56,7 @@ public:
     
     static ListPtr filter_bundles(const fwk::FileList::Ptr & files);
 private:
-    LibFile::FileType m_type;
+    LibFileType m_type;
     std::string m_main;
     std::string m_xmp_sidecar;
     std::string m_jpeg;
diff --git a/src/engine/db/fsfile.rs b/src/engine/db/fsfile.rs
index 5953f44..493706a 100644
--- a/src/engine/db/fsfile.rs
+++ b/src/engine/db/fsfile.rs
@@ -1,8 +1,22 @@
+/*
+ * niepce - engine/db/fsfile.rs
+ *
+ * Copyright (C) 2017 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
-
-use libc::c_char;
-use std::ffi::CStr;
-use std::ffi::CString;
 use std::path::{ Path, PathBuf };
 
 use super::LibraryId;
@@ -11,7 +25,6 @@ use super::LibraryId;
 pub struct FsFile {
     id: LibraryId,
     path: PathBuf,
-    pub cstr: CString,
 }
 
 impl FsFile {
@@ -19,7 +32,6 @@ impl FsFile {
     pub fn new(id: LibraryId, path: PathBuf) -> FsFile {
         FsFile {
             id: id, path: path,
-            cstr: CString::new("").unwrap(),
         }
     }
 
@@ -31,21 +43,3 @@ impl FsFile {
         self.path.as_path()
     }
 }
-
-#[no_mangle]
-pub extern fn engine_db_fsfile_new(id: i64, name: *const c_char) -> *mut FsFile {
-    let path = PathBuf::from(&*unsafe { CStr::from_ptr(name) }.to_string_lossy());
-    let lf = Box::new(FsFile::new(id, path));
-    Box::into_raw(lf)
-}
-
-#[no_mangle]
-pub extern fn engine_db_fsfile_delete(lf: *mut FsFile) {
-    unsafe { Box::from_raw(lf) };
-}
-
-#[no_mangle]
-pub extern fn engine_db_fsfile_path(this: &mut FsFile) -> *const c_char {
-    this.cstr = CString::new(&*this.path().to_string_lossy()).unwrap();
-    this.cstr.as_ptr()
-}
diff --git a/src/engine/db/libfile.cpp b/src/engine/db/libfile.cpp
index 193fdea..2c21cf5 100644
--- a/src/engine/db/libfile.cpp
+++ b/src/engine/db/libfile.cpp
@@ -23,88 +23,19 @@
 #include "properties.hpp"
 
 
-namespace eng {
-       
-LibFile::LibFile(library_id_t _id, library_id_t _folderId, library_id_t _fsfileid, const std::string & p,
-                 const std::string & _name )
-       : m_id(_id), m_folderId(_folderId),
-         m_name(_name),
-          m_main_file(fsfile_new(_fsfileid, p.c_str())),
-         m_orientation(0), m_rating(0), m_label(0),
-    m_flag(0),
-    m_file_type(FileType::UNKNOWN)
-{
-    
-}
-
-LibFile::~LibFile()
-{
-}
+extern "C" eng::LibFile* engine_db_libfile_new(eng::library_id_t id,
+                                               eng::library_id_t folder_id,
+                                               eng::library_id_t fs_file_id,
+                                               const char* path, const char* name);
+extern "C" void engine_db_libfile_delete(eng::LibFile*);
 
-void LibFile::setOrientation(int32_t v)
-{
-    m_orientation = v;
-}
-
-
-void LibFile::setRating(int32_t v)
-{
-    m_rating = v;
-}
-
-
-void LibFile::setLabel(int32_t v)
-{
-    m_label = v;
-}
-
-void LibFile::setFlag(int32_t v)
-{
-    m_flag = v;
-}
-
-void LibFile::setFileType(FileType v)
-{
-    m_file_type = v;
-}
-
-void LibFile::setProperty(fwk::PropertyIndex idx, int32_t v)
-{
-    switch(idx) {
-    case NpTiffOrientationProp:
-        setOrientation(v);
-        break;
-    case NpXmpRatingProp:
-        setRating(v);
-        break;
-    case NpXmpLabelProp:
-        setLabel(v);
-        break;
-    case NpNiepceFlagProp:
-        setFlag(v);
-        break;
-    default:
-        ERR_OUT("set property %u not handled", idx);
-        break;
-    }
-}
+namespace eng {
 
-int32_t LibFile::property(fwk::PropertyIndex idx) const
-{
-    switch(idx) {
-    case NpTiffOrientationProp:
-        return orientation();
-    case NpXmpRatingProp:
-        return rating();
-    case NpXmpLabelProp:
-        return label();
-    case NpNiepceFlagProp:
-        return flag();
-    default:
-        ERR_OUT("get property %u not handled", idx);
-        break;
-    }
-    return -1;
+LibFilePtr libfile_new(library_id_t id, library_id_t folder_id, library_id_t fs_file_id,
+                       const char* path, const char* name) {
+    return LibFilePtr(
+        engine_db_libfile_new(id, folder_id, fs_file_id, path, name),
+        &engine_db_libfile_delete);
 }
 
 /**
@@ -113,23 +44,23 @@ int32_t LibFile::property(fwk::PropertyIndex idx) const
  * @return the filetype
  * @todo: add the JPEG+RAW file types.
  */
-LibFile::FileType LibFile::mimetype_to_filetype(fwk::MimeType mime)
+LibFileType mimetype_to_filetype(fwk::MimeType mime)
 {
     if(mime.isDigicamRaw())
     {
-        return FileType::RAW;
+        return LibFileType::RAW;
     }
     else if(mime.isImage())
     {
-        return FileType::IMAGE;
+        return LibFileType::IMAGE;
     }
     else if(mime.isMovie())
     {
-        return FileType::VIDEO;
+        return LibFileType::VIDEO;
     }
     else
     {
-        return FileType::UNKNOWN;
+        return LibFileType::UNKNOWN;
     }
 }
 
diff --git a/src/engine/db/libfile.hpp b/src/engine/db/libfile.hpp
index e9948bc..00c45a6 100644
--- a/src/engine/db/libfile.hpp
+++ b/src/engine/db/libfile.hpp
@@ -1,5 +1,5 @@
 /*
- * niepce - eng/db/libfile.h
+ * niepce - eng/db/libfile.hpp
  *
  * Copyright (C) 2007-2013 Hubert Figuiere
  *
@@ -17,8 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __NIEPCE_DB_LIBFILE_H__
-#define __NIEPCE_DB_LIBFILE_H__
+#pragma once
 
 #include <string>
 #include <list>
@@ -28,96 +27,43 @@
 #include "fwk/base/propertybag.hpp"
 #include "engine/db/librarytypes.hpp"
 #include "engine/db/keyword.hpp"
-#include "engine/db/fsfile.hpp"
 
 namespace eng {
 
-
-class LibFile
-{
-public:
-    typedef std::shared_ptr< LibFile > Ptr;
-    typedef std::weak_ptr< LibFile> WeakPtr;
-    typedef std::list< Ptr > List;
-    typedef std::shared_ptr< List > ListPtr;
-
-    enum class FileType {
-        UNKNOWN = 0,
-        RAW = 1,
-        RAW_JPEG = 2,
-        IMAGE = 3,
-        VIDEO = 4
-    };
-
-    static FileType mimetype_to_filetype(fwk::MimeType mime);
-
-    LibFile(library_id_t id, library_id_t folderId, library_id_t fsfileid,
-            const std::string & p,
-            const std::string & name );
-    virtual ~LibFile();
-
-    library_id_t id() const
-        { return m_id; }
-    library_id_t folderId() const
-        { return m_folderId; }
-    const std::string & name() const
-        { return m_name; }
-    std::string path() const
-        { return engine_db_fsfile_path(m_main_file.get()); }
-
-    void setOrientation(int32_t v);
-    int32_t orientation() const
-        { return m_orientation; }
-    void setRating(int32_t v);
-    int32_t rating() const
-        { return m_rating; }
-    void setLabel(int32_t v);
-    int32_t label() const
-        { return m_label; }
-    void setFlag(int32_t v);
-    int32_t flag() const
-        { return m_flag; }
-    void setProperty(fwk::PropertyIndex idx, int32_t v);
-    int32_t property(fwk::PropertyIndex idx) const;
-
-    /** Setter for the filetype.
-     * @param v the FILETYPE of the file
-     */
-    void setFileType(FileType v);
-    /** Getter for the filetype enumeration. */
-    FileType fileType() const
-        { return m_file_type; }
-
-    /** return an URI of the real path
-     * because the Gtk stuff want that.
-     */
-    const std::string uri() const
-        { return std::string("file://") + engine_db_fsfile_path(m_main_file.get()); }
-    /** check is the library file is at uri
-     * @return true of the uri match
-     * @todo
-     */
-//             bool isUri(const char * _uri) const
-//                     { return uri() == _uri; }
-private:
-    library_id_t         m_id;           /**< file ID */
-    library_id_t         m_folderId;     /**< parent folder */
-    std::string m_name;         /**< name */
-    FsFilePtr      m_main_file;
-//    boost::filesystem::path  m_path;/**< path name relative to the folder */
-//             std::string m_type;
-    int32_t     m_orientation;  /**< Exif orientatoin */
-    int32_t     m_rating;       /**< rating */
-    int32_t     m_label;        /**< Label ID */
-    int32_t     m_flag;         /**< Flag */
-    FileType    m_file_type;    /**< File type */
+enum class LibFileType {
+    UNKNOWN = 0,
+    RAW = 1,
+    RAW_JPEG = 2,
+    IMAGE = 3,
+    VIDEO = 4
 };
 
-}
+LibFileType mimetype_to_filetype(fwk::MimeType mime);
 
+class LibFile;
+typedef std::shared_ptr<LibFile> LibFilePtr;
+typedef std::weak_ptr< LibFile> LibFileWeakPtr;
+typedef std::list<LibFilePtr> LibFileList;
+typedef std::shared_ptr<LibFileList> LibFileListPtr;
 
-#endif
+LibFilePtr libfile_new(library_id_t, library_id_t, library_id_t, const char*, const char*);
+}
 
+extern "C" const char* engine_db_libfile_path(const eng::LibFile*);
+extern "C" eng::library_id_t engine_db_libfile_id(const eng::LibFile*);
+extern "C" eng::library_id_t engine_db_libfile_folderid(const eng::LibFile*);
+extern "C" int32_t engine_db_libfile_orientation(const eng::LibFile*);
+extern "C" int32_t engine_db_libfile_rating(const eng::LibFile*);
+extern "C" int32_t engine_db_libfile_label(const eng::LibFile*);
+extern "C" int32_t engine_db_libfile_flag(const eng::LibFile*);
+extern "C" int32_t engine_db_libfile_property(const eng::LibFile*, fwk::PropertyIndex);
+extern "C" eng::LibFileType engine_db_libfile_file_type(const eng::LibFile*);
+extern "C" void engine_db_libfile_set_orientation(eng::LibFile*, int32_t);
+extern "C" void engine_db_libfile_set_rating(eng::LibFile*, int32_t);
+extern "C" void engine_db_libfile_set_label(eng::LibFile*, int32_t);
+extern "C" void engine_db_libfile_set_flag(eng::LibFile*, int32_t);
+extern "C" void engine_db_libfile_set_property(const eng::LibFile*, fwk::PropertyIndex, int32_t);
+extern "C" void engine_db_libfile_set_file_type(eng::LibFile*, eng::LibFileType);
 
 /*
   Local Variables:
diff --git a/src/engine/db/libfile.rs b/src/engine/db/libfile.rs
new file mode 100644
index 0000000..0bf968f
--- /dev/null
+++ b/src/engine/db/libfile.rs
@@ -0,0 +1,250 @@
+/*
+ * niepce - eng/db/libfile.rs
+ *
+ * Copyright (C) 2017 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+use libc::c_char;
+use std::ffi::CStr;
+use std::ffi::CString;
+use std::mem::transmute;
+use std::path::{Path, PathBuf};
+
+use super::LibraryId;
+use super::fsfile::FsFile;
+use fwk::base::PropertyIndex;
+use root::eng::NiepceProperties as Np;
+
+#[repr(i32)]
+#[allow(non_camel_case_types)]
+#[derive(Clone)]
+pub enum FileType {
+    UNKNOWN = 0,
+    RAW = 1,
+    RAW_JPEG = 2,
+    IMAGE = 3,
+    VIDEO = 4
+}
+
+pub struct LibFile {
+    id: LibraryId,
+    folder_id: LibraryId,
+    name: String,
+    pub cstr: CString,
+    main_file: FsFile,
+    orientation: i32,
+    rating: i32,
+    label: i32,
+    flag: i32,
+    file_type: FileType,
+}
+
+impl LibFile {
+
+    pub fn new(id: LibraryId, folder_id: LibraryId, fs_file_id: LibraryId,
+               path: PathBuf, name: &str) -> LibFile {
+        let main_file = FsFile::new(fs_file_id, path);
+        LibFile {
+            id: id, folder_id: folder_id,
+            name: String::from(name),
+            cstr: CString::new("").unwrap(),
+            main_file: main_file, orientation: 0,
+            rating: 0, label: 0, flag: 0,
+            file_type: FileType::UNKNOWN,
+        }
+    }
+
+    pub fn id(&self) -> LibraryId {
+        self.id
+    }
+
+    pub fn folder_id(&self) -> LibraryId {
+        self.folder_id
+    }
+
+    pub fn name(&self) -> &str {
+        &self.name
+    }
+
+    pub fn path(&self) -> &Path {
+        self.main_file.path()
+    }
+
+    pub fn orientation(&self) -> i32 {
+        self.orientation
+    }
+    pub fn set_orientation(&mut self, o: i32) {
+        self.orientation = o;
+    }
+
+    pub fn rating(&self) -> i32 {
+        self.rating
+    }
+    pub fn set_rating(&mut self, r: i32) {
+        self.rating = r;
+    }
+
+    pub fn label(&self) -> i32 {
+        self.label
+    }
+    pub fn set_label(&mut self, l: i32) {
+        self.label = l;
+    }
+
+    pub fn flag(&self) -> i32 {
+        self.flag
+    }
+    pub fn set_flag(&mut self, f: i32) {
+        self.flag = f;
+    }
+
+    pub fn file_type(&self) -> FileType {
+        self.file_type.to_owned()
+    }
+    pub fn set_file_type(&mut self, ft: FileType) {
+        self.file_type = ft;
+    }
+
+    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(),
+            _ =>
+                -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),
+            _ =>
+                (),
+        };
+    }
+
+    /// return an URI of the real path as Glib want this, oftern
+    pub fn uri(&self) -> String {
+        let mut s = String::from("file://");
+        s.push_str(&*self.main_file.path().to_string_lossy());
+        s
+    }
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_new(id: LibraryId, folder_id: LibraryId,
+                                    fs_file_id: LibraryId, path: *const c_char,
+                                    name: *const c_char) -> *mut LibFile {
+    let lf = Box::new(
+        LibFile::new(id, folder_id, fs_file_id,
+                     PathBuf::from(&*unsafe { CStr::from_ptr(path) }.to_string_lossy()),
+                     &*unsafe { CStr::from_ptr(name) }.to_string_lossy())
+            );
+    Box::into_raw(lf)
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_delete(lf: *mut LibFile) {
+    unsafe { Box::from_raw(lf) };
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_path(this: &mut LibFile) -> *const c_char {
+    this.cstr = CString::new(this.path().to_str().unwrap_or("")).unwrap();
+    this.cstr.as_ptr()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_id(this: &LibFile) -> LibraryId {
+    this.id()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_folderid(this: &LibFile) -> LibraryId {
+    this.folder_id()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_orientation(this: &LibFile) -> i32 {
+    this.orientation()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_rating(this: &LibFile) -> i32 {
+    this.rating()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_label(this: &LibFile) -> i32 {
+    this.label()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_flag(this: &LibFile) -> i32 {
+    this.flag()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_property(this: &LibFile, idx: PropertyIndex) -> i32 {
+    this.property(unsafe { transmute(idx) })
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_file_type(this: &LibFile) -> FileType {
+    this.file_type()
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_set_orientation(this: &mut LibFile, o: i32) {
+    this.set_orientation(o);
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_set_rating(this: &mut LibFile, r: i32) {
+    this.set_rating(r);
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_set_label(this: &mut LibFile, l: i32) {
+    this.set_label(l);
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_set_flag(this: &mut LibFile, f: i32) {
+    this.set_flag(f);
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_set_property(this: &mut LibFile, idx: PropertyIndex, v: i32) {
+    this.set_property(unsafe { transmute(idx) }, v);
+}
+
+#[no_mangle]
+pub extern fn engine_db_libfile_set_file_type(this: &mut LibFile, t: FileType) {
+    this.set_file_type(t);
+}
diff --git a/src/engine/db/library.cpp b/src/engine/db/library.cpp
index 5eefd97..32014ae 100644
--- a/src/engine/db/library.cpp
+++ b/src/engine/db/library.cpp
@@ -278,8 +278,8 @@ library_id_t Library::addFile(library_id_t folder_id, const std::string & file,
         library_id_t label_id;
         std::string label;
         fwk::MimeType mime = fwk::MimeType(file);
-        eng::LibFile::FileType file_type = eng::LibFile::mimetype_to_filetype(mime);
-        fwk::XmpMeta meta(file, file_type == eng::LibFile::FileType::RAW);
+        eng::LibFileType file_type = eng::mimetype_to_filetype(mime);
+        fwk::XmpMeta meta(file, file_type == eng::LibFileType::RAW);
         label_id = 0;
         orientation = meta.orientation();
         rating = meta.rating();
@@ -400,7 +400,7 @@ bool Library::addJpegFileToBundle(library_id_t file_id, library_id_t fsfile_id)
                                    " file_type='%3%' "
                                    " WHERE id='%1%';")
                      % file_id % fsfile_id
-                     % static_cast<int>(LibFile::FileType::RAW_JPEG));
+                     % static_cast<int>(LibFileType::RAW_JPEG));
     try {
         return m_dbdrv->execute_statement(sql);
     }
@@ -474,7 +474,7 @@ void Library::getAllFolders(const LibFolderListPtr & l)
     }
 }
 
-static LibFile::Ptr getFileFromDbRow(const db::IConnectionDriver::Ptr & dbdrv)
+static LibFilePtr getFileFromDbRow(const db::IConnectionDriver::Ptr & dbdrv)
 {
     library_id_t id;
     library_id_t fid;
@@ -488,27 +488,27 @@ static LibFile::Ptr getFileFromDbRow(const db::IConnectionDriver::Ptr & dbdrv)
     dbdrv->get_column_content(3, name);
     dbdrv->get_column_content(8, fsfid);
     DBG_OUT("found %s", pathname.c_str());
-    LibFile::Ptr f(new LibFile(id, fid, fsfid,
-                               pathname, name));
+    LibFilePtr f(libfile_new(id, fid, fsfid,
+                             pathname.c_str(), name.c_str()));
     int32_t val;
     dbdrv->get_column_content(4, val);
-    f->setOrientation(val);
+    engine_db_libfile_set_orientation(f.get(), val);
     dbdrv->get_column_content(5, val);
-    f->setRating(val);
+    engine_db_libfile_set_rating(f.get(), val);
     dbdrv->get_column_content(6, val);
-    f->setLabel(val);
+    engine_db_libfile_set_label(f.get(), val);
     dbdrv->get_column_content(9, val);
-    f->setFlag(val);
+    engine_db_libfile_set_flag(f.get(), val);
 
     /* Casting needed. Remember that a simple enum like this is just a couple
      * of #define for integers.
      */
     dbdrv->get_column_content(7, val);
-    f->setFileType((eng::LibFile::FileType)val);
+    engine_db_libfile_set_file_type(f.get(),(eng::LibFileType)val);
     return f;
 }
 
-void Library::getFolderContent(library_id_t folder_id, const LibFile::ListPtr & fl)
+void Library::getFolderContent(library_id_t folder_id, const LibFileListPtr & fl)
 {
     SQLStatement sql(boost::format("SELECT files.id,parent_id,fsfiles.path,"
                                    "name,"
@@ -521,7 +521,7 @@ void Library::getFolderContent(library_id_t folder_id, const LibFile::ListPtr &
     try {
         if(m_dbdrv->execute_statement(sql)) {
             while(m_dbdrv->read_next_row()) {
-                LibFile::Ptr f(getFileFromDbRow(m_dbdrv));
+                LibFilePtr f(getFileFromDbRow(m_dbdrv));
                 fl->push_back(f);
             }
         }
@@ -645,7 +645,7 @@ bool Library::assignKeyword(library_id_t kw_id, library_id_t file_id)
 }
 
 
-void Library::getKeywordContent(library_id_t keyword_id, const LibFile::ListPtr & fl)
+void Library::getKeywordContent(library_id_t keyword_id, const LibFileListPtr & fl)
 {
     SQLStatement sql(boost::format("SELECT files.id,parent_id,fsfiles.path,"
                                    "name,orientation,rating,label,file_type,"
@@ -659,7 +659,7 @@ void Library::getKeywordContent(library_id_t keyword_id, const LibFile::ListPtr
     try {
         if(m_dbdrv->execute_statement(sql)) {
             while(m_dbdrv->read_next_row()) {
-                LibFile::Ptr f(getFileFromDbRow(m_dbdrv));
+                LibFilePtr f(getFileFromDbRow(m_dbdrv));
                 fl->push_back(f);
             }
         }
diff --git a/src/engine/db/library.hpp b/src/engine/db/library.hpp
index 001dd02..5d91341 100644
--- a/src/engine/db/library.hpp
+++ b/src/engine/db/library.hpp
@@ -144,10 +144,10 @@ public:
      * @param folder_id id of the folder
      * @param fl the resulting file list
      */
-    void getFolderContent(library_id_t folder_id, const LibFile::ListPtr & fl);
+    void getFolderContent(library_id_t folder_id, const LibFileListPtr & fl);
     int countFolder(library_id_t folder_id);
     void getAllKeywords(const KeywordListPtr & l);
-    void getKeywordContent(library_id_t keyword_id, const LibFile::ListPtr & fl);
+    void getKeywordContent(library_id_t keyword_id, const LibFileListPtr & fl);
     /** get the metadata block (XMP) */
     void getMetaData(library_id_t file_id, const LibMetadata::Ptr & );
     /** set the metadata block (XMP) */
diff --git a/src/engine/db/mod.rs b/src/engine/db/mod.rs
index dfea170..775b144 100644
--- a/src/engine/db/mod.rs
+++ b/src/engine/db/mod.rs
@@ -19,6 +19,7 @@
 
 pub mod fsfile;
 pub mod keyword;
+pub mod libfile;
 pub mod libfolder;
 
 pub type LibraryId = i64;
diff --git a/src/engine/db/properties-enum.hpp b/src/engine/db/properties-enum.hpp
new file mode 100644
index 0000000..3fd5c1b
--- /dev/null
+++ b/src/engine/db/properties-enum.hpp
@@ -0,0 +1,22 @@
+
+#pragma once
+
+#include "engine/db/metadata.hpp"
+
+namespace eng {
+
+  // prefix Np is for Niepce Property
+
+#define DEFINE_PROPERTY(a,b,c,d,e)               \
+    a = b,
+
+enum NiepceProperties {
+
+    #include "engine/db/properties-def.hpp"
+
+    _NpLastProp
+};
+
+#undef DEFINE_PROPERTY
+
+}
diff --git a/src/engine/db/properties.hpp b/src/engine/db/properties.hpp
index da032c5..fe2244e 100644
--- a/src/engine/db/properties.hpp
+++ b/src/engine/db/properties.hpp
@@ -18,29 +18,17 @@
  */
 
 
-#ifndef __ENG_PROPERTIES_HPP__
-#define __ENG_PROPERTIES_HPP__
+#pragma once
 
 #include <typeinfo>
 
 #include "fwk/base/propertybag.hpp"
 #include "engine/db/metadata.hpp"
 
-namespace eng {
-
-  // prefix Np is for Niepce Property
-
-#define DEFINE_PROPERTY(a,b,c,d,e)               \
-    a = b,
-
-enum {
+#include "engine/db/properties-enum.hpp"
 
-    #include "engine/db/properties-def.hpp"
-
-    _NpLastProp
-};
+namespace eng {
 
-#undef DEFINE_PROPERTY
 
 struct property_desc_t {
     fwk::PropertyIndex prop;
@@ -70,4 +58,3 @@ const char * _propertyName(fwk::PropertyIndex idx);
   fill-column:80
   End:
 */
-#endif
diff --git a/src/engine/db/test_library.cpp b/src/engine/db/test_library.cpp
index 45be8bd..9c2e423 100644
--- a/src/engine/db/test_library.cpp
+++ b/src/engine/db/test_library.cpp
@@ -67,10 +67,10 @@ int test_main(int, char *[])
     int count = lib.countFolder(engine_db_libfolder_id(folder_added.get()));
     BOOST_CHECK(count == 1);
 
-    const eng::LibFile::ListPtr fl(new eng::LibFile::List);
+    const eng::LibFileListPtr fl(new eng::LibFileList);
     lib.getFolderContent(engine_db_libfolder_id(folder_added.get()), fl);
     BOOST_CHECK(fl->size() == (size_t)count);
-    BOOST_CHECK(fl->front()->id() == file_id);
+    BOOST_CHECK(engine_db_libfile_id(fl->front().get()) == file_id);
 
     int kwid1 = lib.makeKeyword("foo");
     BOOST_CHECK(kwid1 > 0);
@@ -85,10 +85,10 @@ int test_main(int, char *[])
     BOOST_CHECK(lib.assignKeyword(kwid1, file_id));
     BOOST_CHECK(lib.assignKeyword(kwid2, file_id));
 
-    eng::LibFile::ListPtr fl2(new eng::LibFile::List);
+    eng::LibFileListPtr fl2(new eng::LibFileList);
     lib.getKeywordContent(kwid1, fl2);
     BOOST_CHECK(fl2->size() == 1);
-    BOOST_CHECK(fl2->front()->id() == file_id);
+    BOOST_CHECK(engine_db_libfile_id(fl2->front().get()) == file_id);
 
     eng::KeywordListPtr kl(new eng::KeywordList);
     lib.getAllKeywords(kl);
diff --git a/src/engine/library/commands.cpp b/src/engine/library/commands.cpp
index 64c43c0..45bfb32 100644
--- a/src/engine/library/commands.cpp
+++ b/src/engine/library/commands.cpp
@@ -105,7 +105,7 @@ void Commands::cmdImportFiles(const Library::Ptr & lib,
 void Commands::cmdQueryFolderContent(const Library::Ptr & lib,
                                      library_id_t folder_id)
 {
-    LibFile::ListPtr fl(new LibFile::List);
+    LibFileListPtr fl(new LibFileList);
     lib->getFolderContent(folder_id, fl);
     lib->notify(LibNotification::make<LibNotification::Type::FOLDER_CONTENT_QUERIED>(
                     {folder_id, fl}));
@@ -122,7 +122,7 @@ void Commands::cmdCountFolder(const Library::Ptr & lib,
 void Commands::cmdQueryKeywordContent(const Library::Ptr & lib,
                                       library_id_t keyword_id)
 {
-    LibFile::ListPtr fl(new LibFile::List());
+    LibFileListPtr fl(new LibFileList);
     lib->getKeywordContent(keyword_id, fl);
     lib->notify(LibNotification::make<LibNotification::Type::KEYWORD_CONTENT_QUERIED>(
                     {keyword_id, fl}));
diff --git a/src/engine/library/notification.hpp b/src/engine/library/notification.hpp
index 85fa8fa..e187c23 100644
--- a/src/engine/library/notification.hpp
+++ b/src/engine/library/notification.hpp
@@ -80,7 +80,7 @@ public:
 
     struct QueriedContent {
         library_id_t container;
-        LibFile::ListPtr files;
+        LibFileListPtr files;
     };
 
     struct MetadataContent {
diff --git a/src/engine/library/thumbnailcache.cpp b/src/engine/library/thumbnailcache.cpp
index 9c73a96..1b728f8 100644
--- a/src/engine/library/thumbnailcache.cpp
+++ b/src/engine/library/thumbnailcache.cpp
@@ -44,7 +44,7 @@ ThumbnailCache::~ThumbnailCache()
 {
 }
 
-void ThumbnailCache::request(const LibFile::ListPtr & fl)
+void ThumbnailCache::request(const LibFileListPtr & fl)
 {
     clear();
     std::for_each(fl->begin(), fl->end(),
@@ -56,11 +56,11 @@ void ThumbnailCache::request(const LibFile::ListPtr & fl)
 
 namespace {
 
-fwk::Thumbnail getThumbnail(const LibFile::Ptr & f, int w, int h, const std::string & cached)
+fwk::Thumbnail getThumbnail(const LibFilePtr & f, int w, int h, const std::string & cached)
 {
-    const std::string & filename = f->path();
+    std::string filename = engine_db_libfile_path(f.get());
 
-    if(ThumbnailCache::is_thumbnail_cached(f->path(), cached)) {
+    if (ThumbnailCache::is_thumbnail_cached(filename, cached)) {
         DBG_OUT("thumbnail for %s is cached!", filename.c_str());
         return Gdk::Pixbuf::create_from_file(cached);
     }
@@ -71,7 +71,8 @@ fwk::Thumbnail getThumbnail(const LibFile::Ptr & f, int w, int h, const std::str
         ERR_OUT("coudln't create directories for %s", cached.c_str());
     }
 
-    auto thumbnail = fwk::Thumbnail::thumbnail_file(filename, w, h, f->orientation());
+    auto thumbnail = fwk::Thumbnail::thumbnail_file(filename, w, h,
+                                                    engine_db_libfile_orientation(f.get()));
     if (thumbnail.ok()) {
         thumbnail.save(cached, "png");
     } else {
@@ -88,7 +89,9 @@ void ThumbnailCache::execute(const ptr_t & task)
     w = task->width();
     h = task->height();
 
-    std::string dest = path_for_thumbnail(task->file()->path(), task->file()->id(), std::max(w,h));
+    std::string dest = path_for_thumbnail(
+        engine_db_libfile_path(task->file().get()),
+        engine_db_libfile_id(task->file().get()), std::max(w,h));
     DBG_OUT("cached thumbnail %s", dest.c_str());
 
     fwk::Thumbnail pix = getThumbnail(task->file(), w, h, dest);
@@ -99,7 +102,8 @@ void ThumbnailCache::execute(const ptr_t & task)
     if(nc) {
         // pass the notification
         fwk::Notification::Ptr n(new fwk::Notification(niepce::NOTIFICATION_THUMBNAIL));
-        ThumbnailNotification tn{task->file()->id(), pix.get_width(), pix.get_height(), pix};
+        ThumbnailNotification tn{ engine_db_libfile_id(task->file().get()),
+                pix.get_width(), pix.get_height(), pix };
         n->setData(boost::any(tn));
         DBG_OUT("notify thumbnail for id=%Ld", (long long)tn.id);
         nc->post(std::move(n));
diff --git a/src/engine/library/thumbnailcache.hpp b/src/engine/library/thumbnailcache.hpp
index 022f1b1..c405101 100644
--- a/src/engine/library/thumbnailcache.hpp
+++ b/src/engine/library/thumbnailcache.hpp
@@ -35,18 +35,18 @@ class ThumbnailTask
 public:
     typedef std::unique_ptr<ThumbnailTask> Ptr;
 
-    ThumbnailTask(const LibFile::Ptr & f, int w, int h)
+    ThumbnailTask(const LibFilePtr & f, int w, int h)
         : m_file(f), m_width(w), m_height(h)
         { }
 
-    const LibFile::Ptr & file()
+    const LibFilePtr & file()
         { return m_file; }
     int width() const
         { return m_width; }
     int height() const
         { return m_height; }
 private:
-    const LibFile::Ptr m_file;
+    const LibFilePtr m_file;
     int m_width;
     int m_height;
 };
@@ -60,7 +60,7 @@ public:
                    const fwk::NotificationCenter::Ptr & nc);
     ~ThumbnailCache();
 
-    void request(const LibFile::ListPtr & fl);
+    void request(const LibFileListPtr & fl);
 
     static bool is_thumbnail_cached(const std::string & file, const std::string & thumb);
 
diff --git a/src/fwk/base/mod.rs b/src/fwk/base/mod.rs
index 40444b7..c59bd7b 100644
--- a/src/fwk/base/mod.rs
+++ b/src/fwk/base/mod.rs
@@ -1,3 +1,22 @@
-
+/*
+ * niepce - fwk/base/mod.rs
+ *
+ * Copyright (C) 2017 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
 pub mod fractions;
+
+pub type PropertyIndex = u32;
diff --git a/src/lib.rs b/src/lib.rs
index 5385367..f511f12 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,3 +23,4 @@ extern crate libc;
 pub mod fwk;
 pub mod engine;
 
+include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
diff --git a/src/niepce/modules/darkroom/darkroommodule.cpp b/src/niepce/modules/darkroom/darkroommodule.cpp
index 5abbda0..f7a832e 100644
--- a/src/niepce/modules/darkroom/darkroommodule.cpp
+++ b/src/niepce/modules/darkroom/darkroommodule.cpp
@@ -46,15 +46,15 @@ void DarkroomModule::reload_image()
     if(!m_need_reload) {
         return;
     }
-    eng::LibFile::Ptr file = m_imagefile.lock();
+    eng::LibFilePtr file = m_imagefile.lock();
     if(file) {
         // currently we treat RAW + JPEG as RAW.
         // TODO: have a way to actually choose the JPEG.
-        bool isRaw = (file->fileType() == eng::LibFile::FileType::RAW)
-            || (file->fileType() == eng::LibFile::FileType::RAW_JPEG);
-        const std::string& path = file->path();
-        m_image->reload(path, isRaw,
-                        file->orientation());
+        auto file_type = engine_db_libfile_file_type(file.get());
+        bool isRaw = (file_type == eng::LibFileType::RAW)
+            || (file_type == eng::LibFileType::RAW_JPEG);
+        std::string path = engine_db_libfile_path(file.get());
+        m_image->reload(path, isRaw, engine_db_libfile_orientation(file.get()));
     }
     else {
         // reset
@@ -65,10 +65,10 @@ void DarkroomModule::reload_image()
     m_need_reload = false;
 }
 
-void DarkroomModule::set_image(const eng::LibFile::Ptr & file)
+void DarkroomModule::set_image(const eng::LibFilePtr & file)
 {
     if(m_imagefile.expired() || (file != m_imagefile.lock())) {
-        m_imagefile = eng::LibFile::WeakPtr(file);
+        m_imagefile = eng::LibFileWeakPtr(file);
         m_need_reload = true;
     }
     else if(!static_cast<bool>(file)) {
diff --git a/src/niepce/modules/darkroom/darkroommodule.hpp b/src/niepce/modules/darkroom/darkroommodule.hpp
index 7b4ab59..8605b7e 100644
--- a/src/niepce/modules/darkroom/darkroommodule.hpp
+++ b/src/niepce/modules/darkroom/darkroommodule.hpp
@@ -50,7 +50,7 @@ public:
 
     DarkroomModule(const ui::IModuleShell & shell);
 
-    void set_image(const eng::LibFile::Ptr & file);
+    void set_image(const eng::LibFilePtr & file);
 
     virtual void dispatch_action(const std::string & action_name) override;
 
@@ -75,7 +75,7 @@ private:
     Gtk::ScrolledWindow          m_canvas_scroll;
     ToolboxController::Ptr       m_toolbox_ctrl;
     Glib::RefPtr<Gio::ActionGroup> m_actionGroup;
-    eng::LibFile::WeakPtr        m_imagefile;
+    eng::LibFileWeakPtr        m_imagefile;
     ncr::Image::Ptr              m_image;
     fwk::Dock                   *m_dock;
 
diff --git a/src/niepce/modules/interfaces/ipostimportprocessing.hpp 
b/src/niepce/modules/interfaces/ipostimportprocessing.hpp
index 58625f3..b90f243 100644
--- a/src/niepce/modules/interfaces/ipostimportprocessing.hpp
+++ b/src/niepce/modules/interfaces/ipostimportprocessing.hpp
@@ -17,7 +17,7 @@ class IPostImportProcessing
 public:
   static const char * IFACE_NAME;
 
-  virtual void post_process_image(const eng::LibFile::Ptr & file) = 0;
+  virtual void post_process_image(const eng::LibFilePtr & file) = 0;
 };
 
 }
diff --git a/src/niepce/ui/filmstripcontroller.cpp b/src/niepce/ui/filmstripcontroller.cpp
index 8e3b19c..9173caa 100644
--- a/src/niepce/ui/filmstripcontroller.cpp
+++ b/src/niepce/ui/filmstripcontroller.cpp
@@ -73,9 +73,9 @@ eng::library_id_t FilmStripController::get_selected()
     Gtk::TreeRow row = *(m_store->get_iter(path));
     if(row) {
         DBG_OUT("found row");
-        eng::LibFile::Ptr libfile = row[m_store->columns().m_libfile];
+        eng::LibFilePtr libfile = row[m_store->columns().m_libfile];
         if(libfile) {
-            id = libfile->id();
+            id = engine_db_libfile_id(libfile.get());
         }
     }
 
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index 009284d..ac299a0 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -157,9 +157,9 @@ eng::library_id_t GridViewModule::get_selected()
         Gtk::TreeRow row = *(m_model->get_iter(path));
         if(row) {
             DBG_OUT("found row");
-            eng::LibFile::Ptr libfile = row[m_model->columns().m_libfile];
+            eng::LibFilePtr libfile = row[m_model->columns().m_libfile];
             if(libfile) {
-                id = libfile->id();
+                id = engine_db_libfile_id(libfile.get());
             }
         }
     }
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index c5c1c28..d4a82b2 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -107,9 +107,9 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
         // clear the map before the list.
         m_idmap.clear();
         clear();
-        eng::LibFile::List::const_iterator iter = l->begin();
+        eng::LibFileList::const_iterator iter = l->begin();
         for_each(l->begin(), l->end(),
-                 [this](const eng::LibFile::Ptr & f) {
+                 [this] (const eng::LibFilePtr & f) {
                      Gtk::TreeModel::iterator riter = append();
                      Gtk::TreeRow row = *riter;
                      Glib::RefPtr<Gdk::Pixbuf> icon = get_loading_icon();
@@ -117,7 +117,7 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
                      row[m_columns.m_libfile] = f;
                      row[m_columns.m_strip_thumb]
                          = fwk::gdkpixbuf_scale_to_fit(icon, 100);
-                     m_idmap[f->id()] = riter;
+                     m_idmap[engine_db_libfile_id(f.get())] = riter;
                  });
         // at that point clear the cache because the icon view is populated.
         getLibraryClient()->thumbnailCache().request(l);
@@ -152,8 +152,8 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
             if(iter != m_idmap.end()) {
                 Gtk::TreeRow row = *(iter->second);
                 //
-                eng::LibFile::Ptr file = row[m_columns.m_libfile];
-                file->setProperty(prop, boost::get<int>(m.value));
+                eng::LibFilePtr file = row[m_columns.m_libfile];
+                engine_db_libfile_set_property(file.get(), prop, boost::get<int32_t>(m.value));
                 row[m_columns.m_libfile] = file;
             }
         }
diff --git a/src/niepce/ui/imageliststore.hpp b/src/niepce/ui/imageliststore.hpp
index 45c8984..a3d889f 100644
--- a/src/niepce/ui/imageliststore.hpp
+++ b/src/niepce/ui/imageliststore.hpp
@@ -55,7 +55,7 @@ public:
                 add(m_strip_thumb);
             }
         Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_pix;
-        Gtk::TreeModelColumn<eng::LibFile::Ptr> m_libfile;
+        Gtk::TreeModelColumn<eng::LibFilePtr> m_libfile;
         Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_strip_thumb;
     };
 
diff --git a/src/niepce/ui/librarycellrenderer.cpp b/src/niepce/ui/librarycellrenderer.cpp
index df4a171..11f41ee 100644
--- a/src/niepce/ui/librarycellrenderer.cpp
+++ b/src/niepce/ui/librarycellrenderer.cpp
@@ -213,7 +213,7 @@ LibraryCellRenderer::render_vfunc(const Cairo::RefPtr<Cairo::Context>& cr,
     r.x += xpad;
     r.y += ypad;
 
-    eng::LibFile::Ptr file = m_libfileproperty.get_value();
+    eng::LibFilePtr file = m_libfileproperty.get_value();
 
     Glib::RefPtr<Gtk::StyleContext> style_context = widget.get_style_context();
 
@@ -237,31 +237,31 @@ LibraryCellRenderer::render_vfunc(const Cairo::RefPtr<Cairo::Context>& cr,
         double x, y;
         x = r.x + CELL_PADDING;
         y = r.y + r.height - CELL_PADDING;
-        fwk::RatingLabel::draw_rating(cr, file->rating(), 
-                                      fwk::RatingLabel::get_star(), 
+        fwk::RatingLabel::draw_rating(cr, engine_db_libfile_rating(file.get()),
+                                      fwk::RatingLabel::get_star(),
                                       fwk::RatingLabel::get_unstar(), x, y);
     }
     if(m_drawflag) {
         double x, y;
         x = r.x + r.width - CELL_PADDING;
         y = r.y + CELL_PADDING;
-        _drawFlag(cr, file->flag(), x, y);
+        _drawFlag(cr, engine_db_libfile_flag(file.get()), x, y);
     }
-    
+
     if(m_drawemblem) {
         Cairo::RefPtr<Cairo::ImageSurface> emblem;
-        
-        switch(file->fileType()) {
-        case eng::LibFile::FileType::RAW:
+
+        switch(engine_db_libfile_file_type(file.get())) {
+        case eng::LibFileType::RAW:
             emblem = m_raw_format_emblem;
             break;
-        case eng::LibFile::FileType::RAW_JPEG:
+        case eng::LibFileType::RAW_JPEG:
             emblem = m_rawjpeg_format_emblem;
             break;
-        case eng::LibFile::FileType::IMAGE:
+        case eng::LibFileType::IMAGE:
             emblem = m_img_format_emblem;
             break;
-        case eng::LibFile::FileType::VIDEO:
+        case eng::LibFileType::VIDEO:
             emblem = m_video_format_emblem;
             break;
         default:
@@ -271,7 +271,7 @@ LibraryCellRenderer::render_vfunc(const Cairo::RefPtr<Cairo::Context>& cr,
 
         int left = drawFormatEmblem(cr, emblem, r);
         if(m_drawlabel) {
-            uint32_t label_id = file->label();
+            uint32_t label_id = engine_db_libfile_label(file.get());
             if(label_id != 0) {
                 auto result = m_shell.get_ui_data_provider()->colourForLabel(label_id);
                 DBG_ASSERT(!result.empty(), "colour not found");
@@ -322,24 +322,24 @@ LibraryCellRenderer::activate_vfunc(GdkEvent * /*event*/, Gtk::Widget & ,
         // hit test for the rating value
         int new_rating = fwk::RatingLabel::rating_value_from_hit_x(x - rect.x);
         DBG_OUT("new_rating %d", new_rating);
-        eng::LibFile::Ptr file = m_libfileproperty.get_value();
-        if(file->rating() != new_rating) {
+        eng::LibFilePtr file = m_libfileproperty.get_value();
+        if (engine_db_libfile_rating(file.get()) != new_rating) {
             // emit if changed
-            signal_rating_changed.emit(file->id(), new_rating);
+            signal_rating_changed.emit(engine_db_libfile_id(file.get()), new_rating);
         }
         return true;
     }
     return false;
 }
 
-Glib::PropertyProxy_ReadOnly<eng::LibFile::Ptr>
+Glib::PropertyProxy_ReadOnly<eng::LibFilePtr>
 LibraryCellRenderer::property_libfile() const
 {
-    return Glib::PropertyProxy_ReadOnly<eng::LibFile::Ptr>(this, "libfile");
+    return Glib::PropertyProxy_ReadOnly<eng::LibFilePtr>(this, "libfile");
 }
 
 
-Glib::PropertyProxy<eng::LibFile::Ptr>
+Glib::PropertyProxy<eng::LibFilePtr>
 LibraryCellRenderer::property_libfile()
 {
     return m_libfileproperty.get_proxy();
diff --git a/src/niepce/ui/librarycellrenderer.hpp b/src/niepce/ui/librarycellrenderer.hpp
index 0d52555..841f217 100644
--- a/src/niepce/ui/librarycellrenderer.hpp
+++ b/src/niepce/ui/librarycellrenderer.hpp
@@ -73,8 +73,8 @@ public:
     void set_drawflag(bool val)
         { m_drawflag = val; }
 
-    Glib::PropertyProxy_ReadOnly<eng::LibFile::Ptr> property_libfile() const;
-    Glib::PropertyProxy<eng::LibFile::Ptr>          property_libfile();
+    Glib::PropertyProxy_ReadOnly<eng::LibFilePtr> property_libfile() const;
+    Glib::PropertyProxy<eng::LibFilePtr>          property_libfile();
     sigc::signal<void, int, int> signal_rating_changed;
 protected:
     /* drawing implementations */
@@ -92,7 +92,7 @@ private:
     bool                                m_drawrating;
     bool                                m_drawlabel;
     bool                                m_drawflag;
-    Glib::Property<eng::LibFile::Ptr>   m_libfileproperty;
+    Glib::Property<eng::LibFilePtr>   m_libfileproperty;
 
     Cairo::RefPtr<Cairo::ImageSurface>  m_raw_format_emblem;
     Cairo::RefPtr<Cairo::ImageSurface>  m_rawjpeg_format_emblem;
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index 336b0ef..98ebc2c 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -68,9 +68,9 @@ void SelectionController::activated(const Gtk::TreeModel::Path & path,
     fwk::AutoFlag f(m_in_handler);
     auto iter = m_imageliststore->get_iter(path);
     if(iter) {
-        eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
+        eng::LibFilePtr file = (*iter)[m_imageliststore->columns().m_libfile];
         if(file) {
-            eng::library_id_t selection = file->id();
+            eng::library_id_t selection = engine_db_libfile_id(file.get());
             DBG_OUT("item activated %Ld", (long long)selection);
             signal_activated(selection);
         }
@@ -121,13 +121,13 @@ eng::library_id_t SelectionController::get_selection() const
     return selectable->get_selected();
 }
 
-eng::LibFile::Ptr SelectionController::get_file(eng::library_id_t id) const
+eng::LibFilePtr SelectionController::get_file(eng::library_id_t id) const
 {
     auto iter = m_imageliststore->get_iter_from_id(id);
     if(iter) {
         return (*iter)[m_imageliststore->columns().m_libfile];
     }
-    return eng::LibFile::Ptr();
+    return eng::LibFilePtr();
 }
 
 void SelectionController::_selection_move(bool backwards)
@@ -148,9 +148,9 @@ void SelectionController::_selection_move(bool backwards)
     }
     if(iter) {
         // make sure the iterator is valid...
-        eng::LibFile::Ptr libfile
+        eng::LibFilePtr libfile
             = (*iter)[m_imageliststore->columns().m_libfile];
-        selection = libfile->id();
+        selection = engine_db_libfile_id(libfile.get());
 
         fwk::AutoFlag f(m_in_handler);
 
@@ -192,7 +192,7 @@ void SelectionController::rotate(int angle)
 
 
 bool SelectionController::_set_metadata(const std::string & undo_label,
-                                        const eng::LibFile::Ptr & file,
+                                        const eng::LibFilePtr & file,
                                         fwk::PropertyIndex meta,
                                         int old_value, int new_value)
 {
@@ -200,7 +200,7 @@ bool SelectionController::_set_metadata(const std::string & undo_label,
         fwk::Application::app()->begin_undo(undo_label);
 
     auto libclient = getLibraryClient();
-    auto file_id = file->id();
+    auto file_id = engine_db_libfile_id(file.get());
     undo->new_command<void>(
         [libclient, file_id, meta, new_value] () {
             libclient->setMetadata(file_id, meta, fwk::PropertyValue(new_value));
@@ -213,7 +213,7 @@ bool SelectionController::_set_metadata(const std::string & undo_label,
 }
 
 bool SelectionController::_set_metadata(const std::string & undo_label,
-                                        const eng::LibFile::Ptr & file,
+                                        const eng::LibFilePtr& file,
                                         const fwk::PropertyBag & props,
                                         const fwk::PropertyBag & old)
 {
@@ -231,7 +231,7 @@ bool SelectionController::_set_metadata(const std::string & undo_label,
         }
 
         auto libclient = getLibraryClient();
-        auto file_id = file->id();
+        auto file_id = engine_db_libfile_id(file.get());
         auto key = iter.first;
         auto new_value = iter.second;
         undo->new_command<void>(
@@ -269,9 +269,9 @@ void SelectionController::set_property(fwk::PropertyIndex idx, int value)
     if(selection >= 0) {
         Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
         if(iter) {
-            eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
-            DBG_OUT("old property is %d", file->property(idx));
-            int old_value = file->property(idx);
+            eng::LibFilePtr file = (*iter)[m_imageliststore->columns().m_libfile];
+            DBG_OUT("old property is %d", engine_db_libfile_property(file.get(), idx));
+            int32_t old_value = engine_db_libfile_property(file.get(), idx);
             const char *action = nullptr;
             switch(idx) {
             case eng::NpNiepceFlagProp:
@@ -290,9 +290,9 @@ void SelectionController::set_property(fwk::PropertyIndex idx, int value)
             _set_metadata(action, file, idx, old_value, value);
             // we need to set the property here so that undo/redo works
             // consistently.
-            file->setProperty(idx, value);
+            engine_db_libfile_set_property(file.get(), idx, value);
         }
-    }    
+    }
 }
 
 void SelectionController::set_properties(const fwk::PropertyBag & props,
@@ -302,7 +302,7 @@ void SelectionController::set_properties(const fwk::PropertyBag & props,
     if(selection >= 0) {
         Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
         if(iter) {
-            eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
+            eng::LibFilePtr file = (*iter)[m_imageliststore->columns().m_libfile];
             _set_metadata(_("Set Properties"), file, props, old);
         }
     }
@@ -323,8 +323,8 @@ void SelectionController::move_to_trash()
     if(selection >= 0) {
         Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
         if(iter) {
-            eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
-            eng::library_id_t from_folder = file->folderId();
+            eng::LibFilePtr file = (*iter)[m_imageliststore->columns().m_libfile];
+            eng::library_id_t from_folder = engine_db_libfile_folderid(file.get());
             std::shared_ptr<fwk::UndoTransaction> undo =
                 fwk::Application::app()->begin_undo(_("Move to Trash"));
 
diff --git a/src/niepce/ui/selectioncontroller.hpp b/src/niepce/ui/selectioncontroller.hpp
index dca999d..4fa8977 100644
--- a/src/niepce/ui/selectioncontroller.hpp
+++ b/src/niepce/ui/selectioncontroller.hpp
@@ -109,18 +109,18 @@ public:
      *  todo: change it to support multiple
      */
     eng::library_id_t get_selection() const;
-    eng::LibFile::Ptr get_file(eng::library_id_t id) const;
+    eng::LibFilePtr get_file(eng::library_id_t id) const;
 protected:
     virtual void _added() override;
 private:
     libraryclient::LibraryClientPtr getLibraryClient();
 
     bool _set_metadata(const std::string & undo_label,
-                       const eng::LibFile::Ptr & file,
+                       const eng::LibFilePtr& file,
                        fwk::PropertyIndex meta,
                        int old_value, int new_value);
     bool _set_metadata(const std::string & undo_label,
-                       const eng::LibFile::Ptr & file,
+                       const eng::LibFilePtr& file,
                        const fwk::PropertyBag & props,
                        const fwk::PropertyBag & old);
     /** move the selection and emit the signal


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]