[niepce] libraryclient+rust: libraryclient is in Rust



commit 4d5203a2d5edd279ba871a17bc864bec03a9b5fc
Author: Hubert Figuière <hub figuiere net>
Date:   Wed Oct 25 00:18:24 2017 -0400

    libraryclient+rust: libraryclient is in Rust

 src/libraryclient/clientimpl.rs       |  129 ----------------
 src/libraryclient/libraryclient.cpp   |  109 +-------------
 src/libraryclient/libraryclient.hpp   |   64 +-------
 src/libraryclient/libraryclient.rs    |  260 +++++++++++++++++++++++++++++++++
 src/libraryclient/mod.rs              |    1 +
 src/niepce/ui/dialogs/editlabels.cpp  |   13 +-
 src/niepce/ui/gridviewmodule.cpp      |    2 +-
 src/niepce/ui/imageliststore.cpp      |    2 +-
 src/niepce/ui/imageliststore.hpp      |    1 +
 src/niepce/ui/moduleshell.cpp         |    2 +-
 src/niepce/ui/niepcewindow.cpp        |   19 +--
 src/niepce/ui/selectioncontroller.cpp |   27 ++--
 src/niepce/ui/selectioncontroller.hpp |    4 +-
 src/niepce/ui/workspacecontroller.cpp |   16 +-
 14 files changed, 321 insertions(+), 328 deletions(-)
---
diff --git a/src/libraryclient/clientimpl.rs b/src/libraryclient/clientimpl.rs
index ea013c1..770db97 100644
--- a/src/libraryclient/clientimpl.rs
+++ b/src/libraryclient/clientimpl.rs
@@ -17,9 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-use libc::c_char;
 use std::collections::VecDeque;
-use std::ffi::CStr;
 use std::path::PathBuf;
 use std::sync;
 use std::sync::atomic;
@@ -31,10 +29,8 @@ use engine::db::library::Managed;
 use engine::library::op::Op;
 use engine::library::commands;
 use super::clientinterface::ClientInterface;
-use root::fwk::FileList;
 use root::eng::NiepceProperties as Np;
 
-
 pub struct ClientImpl {
     terminate: sync::Arc<atomic::AtomicBool>,
     tasks: sync::Arc<(sync::Mutex<VecDeque<Op>>, sync::Condvar)>,
@@ -216,128 +212,3 @@ impl ClientInterface for ClientImpl {
         });
     }
 }
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_new(path: *const c_char, notif_id: u64) -> *mut ClientImpl {
-    let dir = PathBuf::from(&*unsafe { CStr::from_ptr(path) }.to_string_lossy());
-    Box::into_raw(Box::new(ClientImpl::new(dir, notif_id)))
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_delete(obj: *mut ClientImpl) {
-    unsafe { Box::from_raw(obj); }
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_get_all_keywords(client: &mut ClientImpl) {
-    client.get_all_keywords();
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_get_all_folders(client: &mut ClientImpl) {
-    client.get_all_folders();
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_query_folder_content(client: &mut ClientImpl,
-                                                                folder_id: LibraryId) {
-    client.query_folder_content(folder_id);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_count_folder(client: &mut ClientImpl,
-                                                        folder_id: LibraryId) {
-    client.count_folder(folder_id)
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_query_keyword_content(client: &mut ClientImpl,
-                                                                 keyword_id: LibraryId) {
-    client.query_keyword_content(keyword_id);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_request_metadata(client: &mut ClientImpl,
-                                                            file_id: LibraryId) {
-    client.request_metadata(file_id);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_set_metadata(client: &mut ClientImpl,
-                                                        file_id: LibraryId,
-                                                        meta: Np, value: &PropertyValue) {
-    client.set_metadata(file_id, meta, value);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_write_metadata(client: &mut ClientImpl,
-                                                          file_id: LibraryId) {
-    client.write_metadata(file_id);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_move_file_to_folder(client: &mut ClientImpl,
-                                                               file_id: LibraryId,
-                                                               from: LibraryId,
-                                                               to: LibraryId) {
-    client.move_file_to_folder(file_id, from, to);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_get_all_labels(client: &mut ClientImpl) {
-    client.get_all_labels();
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_create_label(client: &mut ClientImpl,
-                                                        s: *const c_char, c: *const c_char) {
-    let name = unsafe { CStr::from_ptr(s) }.to_string_lossy();
-    let colour = unsafe { CStr::from_ptr(c) }.to_string_lossy();
-    client.create_label(String::from(name), String::from(colour));
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_delete_label(client: &mut ClientImpl,
-                                                        label_id: LibraryId) {
-    client.delete_label(label_id);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_update_label(client: &mut ClientImpl,
-                                                        label_id: LibraryId,
-                                                        s: *const c_char, c: *const c_char) {
-    let name = unsafe { CStr::from_ptr(s) }.to_string_lossy();
-    let colour = unsafe { CStr::from_ptr(c) }.to_string_lossy();
-    client.update_label(label_id, String::from(name), String::from(colour));
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_process_xmp_update_queue(client: &mut ClientImpl,
-                                                                    write_xmp: bool) {
-    client.process_xmp_update_queue(write_xmp);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_import_file(client: &mut ClientImpl,
-                                                       file_path: *const c_char,
-                                                       manage: Managed) {
-    let path = String::from(unsafe { CStr::from_ptr(file_path) }.to_string_lossy());
-    client.import_file(path, manage);
-}
-
-#[no_mangle]
-pub extern "C" fn libraryclient_clientimpl_import_files(client: &mut ClientImpl,
-                                                        dir: *const c_char, cfiles: &mut FileList,
-                                                        manage: Managed) {
-    let folder = unsafe { CStr::from_ptr(dir) }.to_string_lossy();
-    let mut files: Vec<String> = vec!();
-    {
-        let len = unsafe { cfiles.size() };
-        for i in 0..len {
-            let f = unsafe { cfiles.at_cstr(i) };
-            let cstr = unsafe { CStr::from_ptr(f) }.to_string_lossy();
-            files.push(String::from(cstr));
-        }
-    }
-    client.import_from_directory(String::from(folder), files, manage);
-}
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index 3f4ec9e..b5134dd 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -34,108 +34,16 @@ const char * s_thumbcacheDirname = "thumbcache";
 
 LibraryClient::LibraryClient(const fwk::Moniker & moniker,
                              uint64_t notif_id)
-    : m_impl(ffi::libraryclient_clientimpl_new(moniker.path().c_str(), notif_id))
+    : m_client(
+        ffi::libraryclient_new(moniker.path().c_str(), notif_id),
+        ffi::libraryclient_delete)
     , m_thumbnailCache(moniker.path() + "/" + s_thumbcacheDirname, notif_id)
     , m_uidataprovider(new UIDataProvider())
-    , m_trash_id(0)
 {
 }
 
 LibraryClient::~LibraryClient()
 {
-    ffi::libraryclient_clientimpl_delete(m_impl);
-}
-
-bool LibraryClient::ok() const
-{
-    return m_impl;
-}
-
-void LibraryClient::getAllKeywords()
-{
-    ffi::libraryclient_clientimpl_get_all_keywords(m_impl);
-}
-
-
-void LibraryClient::getAllFolders()
-{
-    ffi::libraryclient_clientimpl_get_all_folders(m_impl);
-}
-
-void LibraryClient::queryFolderContent(eng::library_id_t folder_id)
-{
-    ffi::libraryclient_clientimpl_query_folder_content(m_impl, folder_id);
-}
-
-void LibraryClient::queryKeywordContent(eng::library_id_t keyword_id)
-{
-    ffi::libraryclient_clientimpl_query_keyword_content(m_impl, keyword_id);
-}
-
-void LibraryClient::countFolder(library_id_t folder_id)
-{
-    ffi::libraryclient_clientimpl_count_folder(m_impl, folder_id);
-}
-
-void LibraryClient::requestMetadata(eng::library_id_t file_id)
-{
-    ffi::libraryclient_clientimpl_request_metadata(m_impl, file_id);
-}
-
-/** set the metadata */
-void LibraryClient::setMetadata(library_id_t file_id, fwk::PropertyIndex meta,
-                                      const fwk::PropertyValuePtr & value)
-{
-    ffi::libraryclient_clientimpl_set_metadata(m_impl, file_id, static_cast<eng::Np>(meta),
-                                               value.get());
-}
-
-void LibraryClient::write_metadata(eng::library_id_t file_id)
-{
-    ffi::libraryclient_clientimpl_write_metadata(m_impl, file_id);
-}
-
-
-void LibraryClient::moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder_id,
-                                           eng::library_id_t to_folder_id)
-{
-    ffi::libraryclient_clientimpl_move_file_to_folder(m_impl, file_id, from_folder_id,
-                                                      to_folder_id);
-}
-
-void LibraryClient::getAllLabels()
-{
-    ffi::libraryclient_clientimpl_get_all_labels(m_impl);
-}
-
-
-void LibraryClient::createLabel(const std::string& s, const std::string& colour)
-{
-    ffi::libraryclient_clientimpl_create_label(m_impl, s.c_str(), colour.c_str());
-}
-
-
-void LibraryClient::deleteLabel(int label_id)
-{
-    ffi::libraryclient_clientimpl_delete_label(m_impl, label_id);
-}
-
-
-void LibraryClient::updateLabel(library_id_t label_id, const std::string& new_name,
-                                          const std::string& new_colour)
-{
-    ffi::libraryclient_clientimpl_update_label(m_impl, label_id,
-                                               new_name.c_str(), new_colour.c_str());
-}
-
-void LibraryClient::processXmpUpdateQueue(bool write_xmp)
-{
-    ffi::libraryclient_clientimpl_process_xmp_update_queue(m_impl, write_xmp);
-}
-
-void LibraryClient::importFile(const std::string& path, eng::Managed manage)
-{
-    ffi::libraryclient_clientimpl_import_file(m_impl, path.c_str(), manage);
 }
 
 void LibraryClient::importFromDirectory(const std::string& dir, eng::Managed manage)
@@ -143,17 +51,8 @@ void LibraryClient::importFromDirectory(const std::string& dir, eng::Managed man
     fwk::FileListPtr files;
     files = fwk::FileList::getFilesFromDirectory(dir, &fwk::filter_none);
 
-    ffi::libraryclient_clientimpl_import_files(m_impl, dir.c_str(), files.get(), manage);
-}
-
-#if 0
-bool LibraryClient::fetchKeywordsForFile(int /*file*/,
-                                         eng::Keyword::IdList & /*keywords*/)
-{
-    // TODO
-    return false;
+    ffi::libraryclient_import_files(m_client.get(), dir.c_str(), files.get(), manage);
 }
-#endif
 
 }
 /*
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index a76519f..b12264b 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -23,65 +23,26 @@
 #include <string>
 #include <memory>
 
-#include "fwk/base/propertybag.hpp"
-#include "fwk/base/util.hpp"
 #include "engine/library/thumbnailcache.hpp"
 
+#include "rust_bindings.hpp"
+
 namespace fwk {
 class Moniker;
-class NotificationCenter;
 }
 
 namespace libraryclient {
 
 class UIDataProvider;
 
-class ClientImpl;
-
 class LibraryClient
 {
 public:
-    NON_COPYABLE(LibraryClient);
+    LibraryClient() = delete;
+    LibraryClient& operator=(const LibraryClient&) = delete;
+
     LibraryClient(const fwk::Moniker & moniker, uint64_t notif_id);
     virtual ~LibraryClient();
-    // @return false in case of error.
-    bool ok() const;
-
-    /** get all the keywords
-     */
-    void getAllKeywords();
-    /** get all the folder
-     */
-    void getAllFolders();
-
-    void queryFolderContent(eng::library_id_t id);
-    void queryKeywordContent(eng::library_id_t id);
-    void countFolder(eng::library_id_t id);
-    void requestMetadata(eng::library_id_t id);
-
-    /** set the metadata */
-    void setMetadata(eng::library_id_t id, fwk::PropertyIndex meta,
-                           const fwk::PropertyValuePtr & value);
-    void moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder,
-                                eng::library_id_t to_folder);
-    void write_metadata(eng::library_id_t file_id);
-
-    /** get all the labels */
-    void getAllLabels();
-    void createLabel(const std::string & s, const std::string & color);
-    void deleteLabel(int id);
-    /** update a label */
-    void updateLabel(eng::library_id_t id, const std::string & new_name,
-                           const std::string & new_color);
-
-    /** tell to process the Xmp update Queue */
-    void processXmpUpdateQueue(bool write_xmp);
-
-    /** Import file
-     * @param path the file path
-     * @param manage true if imported file have to be managed
-     */
-    void importFile(const std::string & path, eng::Managed manage);
 
     /** Import files from a directory
      * @param dir the directory
@@ -95,21 +56,14 @@ public:
     const std::unique_ptr<UIDataProvider>& getDataProvider() const
         { return m_uidataprovider; }
 
-    // state
-    eng::library_id_t trash_id() const
-        {
-           return m_trash_id;
-        }
-    void set_trash_id(eng::library_id_t id)
-        {
-           m_trash_id = id;
-        }
+    ffi::LibraryClient* client() const {
+        return m_client.get();
+    }
 private:
-    ffi::ClientImpl* m_impl;
+    std::shared_ptr<ffi::LibraryClient> m_client;
 
     eng::ThumbnailCache m_thumbnailCache;
     std::unique_ptr<UIDataProvider> m_uidataprovider;
-    eng::library_id_t m_trash_id;
 };
 
 typedef std::shared_ptr<LibraryClient> LibraryClientPtr;
diff --git a/src/libraryclient/libraryclient.rs b/src/libraryclient/libraryclient.rs
new file mode 100644
index 0000000..e250f7a
--- /dev/null
+++ b/src/libraryclient/libraryclient.rs
@@ -0,0 +1,260 @@
+/*
+ * niepce - libraryclient/libraryclient.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::path::PathBuf;
+
+use fwk::base::PropertyValue;
+use super::clientimpl::ClientImpl;
+use super::clientinterface::ClientInterface;
+use engine::db::LibraryId;
+use engine::db::library::Managed;
+use root::fwk::FileList;
+use root::eng::NiepceProperties as Np;
+
+pub struct LibraryClient {
+    pimpl: ClientImpl,
+
+    trash_id: LibraryId
+}
+
+impl LibraryClient {
+
+    pub fn new(dir: PathBuf, notif_id: u64) -> LibraryClient {
+        LibraryClient {
+            pimpl: ClientImpl::new(dir, notif_id),
+            trash_id: 0
+        }
+    }
+
+    pub fn get_trash_id(&self) -> LibraryId {
+        self.trash_id
+    }
+
+    pub fn set_trash_id(&mut self, id: LibraryId) {
+        self.trash_id = id;
+    }
+
+}
+
+impl ClientInterface for LibraryClient {
+    /// get all the keywords
+    fn get_all_keywords(&mut self) {
+        self.pimpl.get_all_keywords();
+    }
+    fn query_keyword_content(&mut self, id: LibraryId) {
+        self.pimpl.query_keyword_content(id);
+    }
+
+    /// get all the folder
+    fn get_all_folders(&mut self) {
+        self.pimpl.get_all_folders();
+    }
+    fn query_folder_content(&mut self, id: LibraryId) {
+        self.pimpl.query_folder_content(id);
+    }
+    fn count_folder(&mut self, id: LibraryId) {
+        self.pimpl.count_folder(id);
+    }
+
+    fn request_metadata(&mut self, id: LibraryId) {
+        self.pimpl.request_metadata(id);
+    }
+    /// set the metadata
+    fn set_metadata(&mut self, id: LibraryId, meta: Np, value: &PropertyValue) {
+        self.pimpl.set_metadata(id, meta, value);
+    }
+    fn write_metadata(&mut self, id: LibraryId) {
+        self.pimpl.write_metadata(id);
+    }
+
+    fn move_file_to_folder(&mut self, file_id: LibraryId, from: LibraryId,
+                           to: LibraryId) {
+        self.pimpl.move_file_to_folder(file_id, from, to);
+    }
+    /// get all the labels
+    fn get_all_labels(&mut self) {
+        self.pimpl.get_all_labels();
+    }
+    fn create_label(&mut self, label: String, colour: String) {
+        self.pimpl.create_label(label, colour);
+    }
+    fn delete_label(&mut self, id: LibraryId) {
+        self.pimpl.delete_label(id);
+    }
+    /// update a label
+    fn update_label(&mut self, id: LibraryId, new_name: String, new_colour: String) {
+        self.pimpl.update_label(id, new_name, new_colour);
+    }
+
+    /// tell to process the Xmp update Queue
+    fn process_xmp_update_queue(&mut self, write_xmp: bool) {
+        self.pimpl.process_xmp_update_queue(write_xmp);
+    }
+
+    /// Import file
+    /// @param path the file path
+    /// @param manage true if imported file have to be managed
+    fn import_file(&mut self, path: String, manage: Managed) {
+        self.pimpl.import_file(path, manage);
+    }
+    /// Import files from a directory
+    /// @param dir the directory
+    /// @param manage true if imports have to be managed
+    fn import_from_directory(&mut self, dir: String, files: Vec<String>, manage: Managed) {
+        self.pimpl.import_from_directory(dir, files, manage);
+    }
+
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_new(path: *const c_char, notif_id: u64) -> *mut LibraryClient {
+    let dir = PathBuf::from(&*unsafe { CStr::from_ptr(path) }.to_string_lossy());
+    Box::into_raw(Box::new(LibraryClient::new(dir, notif_id)))
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_delete(obj: *mut LibraryClient) {
+    unsafe { Box::from_raw(obj); }
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_set_trash_id(client: &mut LibraryClient, id: LibraryId) {
+    client.set_trash_id(id);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_get_trash_id(client: &mut LibraryClient) -> LibraryId {
+    client.get_trash_id()
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_get_all_keywords(client: &mut LibraryClient) {
+    client.get_all_keywords();
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_get_all_folders(client: &mut LibraryClient) {
+    client.get_all_folders();
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_query_folder_content(client: &mut LibraryClient,
+                                                     folder_id: LibraryId) {
+    client.query_folder_content(folder_id);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_count_folder(client: &mut LibraryClient,
+                                             folder_id: LibraryId) {
+    client.count_folder(folder_id)
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_query_keyword_content(client: &mut LibraryClient,
+                                                      keyword_id: LibraryId) {
+    client.query_keyword_content(keyword_id);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_request_metadata(client: &mut LibraryClient,
+                                                 file_id: LibraryId) {
+    client.request_metadata(file_id);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_set_metadata(client: &mut LibraryClient,
+                                             file_id: LibraryId,
+                                             meta: Np, value: &PropertyValue) {
+    client.set_metadata(file_id, meta, value);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_write_metadata(client: &mut LibraryClient,
+                                               file_id: LibraryId) {
+    client.write_metadata(file_id);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_move_file_to_folder(client: &mut LibraryClient,
+                                                    file_id: LibraryId,
+                                                    from: LibraryId,
+                                                    to: LibraryId) {
+    client.move_file_to_folder(file_id, from, to);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_get_all_labels(client: &mut LibraryClient) {
+    client.get_all_labels();
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_create_label(client: &mut LibraryClient,
+                                             s: *const c_char, c: *const c_char) {
+    let name = unsafe { CStr::from_ptr(s) }.to_string_lossy();
+    let colour = unsafe { CStr::from_ptr(c) }.to_string_lossy();
+    client.create_label(String::from(name), String::from(colour));
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_delete_label(client: &mut LibraryClient,
+                                             label_id: LibraryId) {
+    client.delete_label(label_id);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_update_label(client: &mut LibraryClient,
+                                             label_id: LibraryId,
+                                             s: *const c_char, c: *const c_char) {
+    let name = unsafe { CStr::from_ptr(s) }.to_string_lossy();
+    let colour = unsafe { CStr::from_ptr(c) }.to_string_lossy();
+    client.update_label(label_id, String::from(name), String::from(colour));
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_process_xmp_update_queue(client: &mut LibraryClient,
+                                                         write_xmp: bool) {
+    client.process_xmp_update_queue(write_xmp);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_import_file(client: &mut LibraryClient,
+                                            file_path: *const c_char,
+                                            manage: Managed) {
+    let path = String::from(unsafe { CStr::from_ptr(file_path) }.to_string_lossy());
+    client.import_file(path, manage);
+}
+
+#[no_mangle]
+pub extern "C" fn libraryclient_import_files(client: &mut LibraryClient,
+                                             dir: *const c_char, cfiles: &mut FileList,
+                                             manage: Managed) {
+    let folder = unsafe { CStr::from_ptr(dir) }.to_string_lossy();
+    let mut files: Vec<String> = vec!();
+    {
+        let len = unsafe { cfiles.size() };
+        for i in 0..len {
+            let f = unsafe { cfiles.at_cstr(i) };
+            let cstr = unsafe { CStr::from_ptr(f) }.to_string_lossy();
+            files.push(String::from(cstr));
+        }
+    }
+    client.import_from_directory(String::from(folder), files, manage);
+}
diff --git a/src/libraryclient/mod.rs b/src/libraryclient/mod.rs
index 428ae2d..fbe3dd2 100644
--- a/src/libraryclient/mod.rs
+++ b/src/libraryclient/mod.rs
@@ -19,3 +19,4 @@
 
 pub mod clientimpl;
 pub mod clientinterface;
+pub mod libraryclient;
diff --git a/src/niepce/ui/dialogs/editlabels.cpp b/src/niepce/ui/dialogs/editlabels.cpp
index bb786f4..b1e57a1 100644
--- a/src/niepce/ui/dialogs/editlabels.cpp
+++ b/src/niepce/ui/dialogs/editlabels.cpp
@@ -123,22 +123,25 @@ void EditLabels::update_labels(int /*response*/)
 
                 undo->new_command<void>(
                     [libclient, new_name, new_colour, label_id] () {
-                        libclient->updateLabel(label_id, new_name, new_colour);
+                        ffi::libraryclient_update_label(
+                            libclient->client(), label_id, new_name.c_str(), new_colour.c_str());
                     },
                     [libclient, current_name, current_colour, label_id] () {
-                        libclient->updateLabel(label_id, current_name,
-                                current_colour);
+                        ffi::libraryclient_update_label(
+                            libclient->client(), label_id, current_name.c_str(),
+                            current_colour.c_str());
                     });
             } else {
                 undo->new_command<int>(
                     [libclient, new_name, new_colour] () {
-                        libclient->createLabel(new_name, new_colour);
+                        ffi::libraryclient_create_label(
+                            libclient->client(), new_name.c_str(), new_colour.c_str());
                         return 0; // XXX this is wrong. This was wrong before/
                         // We need to figure out how to get he new label id to be able
                         // To cancel it.
                     },
                     [libclient] (int label) {
-                        libclient->deleteLabel(label);
+                        ffi::libraryclient_delete_label(libclient->client(), label);
                     });
             }
         }
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index 6bf9e56..5ddff44 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -72,7 +72,7 @@ GridViewModule::on_lib_notification(const eng::LibNotification &ln)
         auto id = engine_library_notification_get_id(&ln);
         if(id && id == m_metapanecontroller->displayed_file()) {
             // FIXME: actually just update the metadata
-          m_shell.getLibraryClient()->requestMetadata(id);
+            ffi::libraryclient_request_metadata(m_shell.getLibraryClient()->client(), id);
         }
         break;
     }
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index 7ab0b42..fd23fd9 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -178,7 +178,7 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
             ERR_OUT("couldn't cast %s: %s", xmp_pref.c_str(),
                     e.what());
         }
-        getLibraryClient()->processXmpUpdateQueue(write_xmp);
+        ffi::libraryclient_process_xmp_update_queue(getLibraryClient()->client(), write_xmp);
         break;
     }
     default:
diff --git a/src/niepce/ui/imageliststore.hpp b/src/niepce/ui/imageliststore.hpp
index ad4a399..7ce67b5 100644
--- a/src/niepce/ui/imageliststore.hpp
+++ b/src/niepce/ui/imageliststore.hpp
@@ -26,6 +26,7 @@
 #include <gdkmm/pixbuf.h>
 #include <gtkmm/liststore.h>
 
+#include "fwk/base/propertybag.hpp"
 #include "fwk/toolkit/controller.hpp"
 #include "engine/db/libfile.hpp"
 #include "engine/library/notification.hpp"
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index 3d37cc4..7d50b78 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -246,7 +246,7 @@ void ModuleShell::on_selected(eng::library_id_t id)
 {
     DBG_OUT("selected callback %Ld", (long long)id);
     if(id > 0) {
-        m_libraryclient->requestMetadata(id);
+        ffi::libraryclient_request_metadata(m_libraryclient->client(), id);
     }
     else  {
         m_gridview->display_none();
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index e7fe0a9..1d5e54b 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -278,7 +278,7 @@ void NiepceWindow::on_action_file_import()
                 source, dest_dir,
                 [this] (const std::string & path, IImporter::Import type, Managed manage) {
                     if (type == IImporter::Import::SINGLE) {
-                        m_libClient->importFile(path, manage);
+                        ffi::libraryclient_import_file(m_libClient->client(), path.c_str(), manage);
                     } else {
                         m_libClient->importFromDirectory(path, manage);
                     }
@@ -327,11 +327,11 @@ void NiepceWindow::on_open_library()
 void NiepceWindow::create_initial_labels()
 {
     // TODO make this parametric from resources
-    m_libClient->createLabel(_("Label 1"), fwk::rgbcolour_to_string(55769, 9509, 4369)); /* 217, 37, 17 */
-    m_libClient->createLabel(_("Label 2"), fwk::rgbcolour_to_string(24929, 55769, 4369)); /* 97, 217, 17 */
-    m_libClient->createLabel(_("Label 3"), fwk::rgbcolour_to_string(4369, 50629, 55769)); /* 17, 197, 217 */
-    m_libClient->createLabel(_("Label 4"), fwk::rgbcolour_to_string(35209, 4369, 55769)); /* 137, 17, 217 */
-    m_libClient->createLabel(_("Label 5"), fwk::rgbcolour_to_string(55769, 35209, 4369)); /* 217, 137, 17 */
+    ffi::libraryclient_create_label(m_libClient->client(), _("Label 1"), fwk::rgbcolour_to_string(55769, 
9509, 4369).c_str()); /* 217, 37, 17 */
+    ffi::libraryclient_create_label(m_libClient->client(), _("Label 2"), fwk::rgbcolour_to_string(24929, 
55769, 4369).c_str()); /* 97, 217, 17 */
+    ffi::libraryclient_create_label(m_libClient->client(), _("Label 3"), fwk::rgbcolour_to_string(4369, 
50629, 55769).c_str()); /* 17, 197, 217 */
+    ffi::libraryclient_create_label(m_libClient->client(), _("Label 4"), fwk::rgbcolour_to_string(35209, 
4369, 55769).c_str()); /* 137, 17, 217 */
+    ffi::libraryclient_create_label(m_libClient->client(), _("Label 5"), fwk::rgbcolour_to_string(55769, 
35209, 4369).c_str()); /* 217, 137, 17 */
 }
 
 
@@ -409,16 +409,13 @@ bool NiepceWindow::open_library(const std::string & libMoniker)
     fwk::Moniker mon = fwk::Moniker(libMoniker);
     m_libClient = LibraryClientPtr(new LibraryClient(mon,
                                                      m_notifcenter->id()));
-    if(!m_libClient->ok()) {
-        m_libClient = nullptr;
-        return false;
-    }
+    // XXX ensure the library is open.
     set_title(libMoniker);
     m_library_cfg
         = fwk::Configuration::Ptr(
             new fwk::Configuration(
                 Glib::build_filename(mon.path(), "config.ini")));
-    m_libClient->getAllLabels();
+    ffi::libraryclient_get_all_labels(m_libClient->client());
     if(!m_moduleshell) {
         _createModuleShell();
     }
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index 2243fb9..d6d8dc7 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -193,7 +193,7 @@ void SelectionController::rotate(int angle)
 
 bool SelectionController::_set_metadata(const std::string & undo_label,
                                         const eng::LibFilePtr & file,
-                                        fwk::PropertyIndex meta,
+                                        ffi::Np meta,
                                         int old_value, int new_value)
 {
     std::shared_ptr<fwk::UndoTransaction> undo =
@@ -203,10 +203,12 @@ bool SelectionController::_set_metadata(const std::string & undo_label,
     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::property_value_new(new_value));
+            ffi::libraryclient_set_metadata(
+                libclient->client(), file_id, meta, fwk::property_value_new(new_value).get());
         },
         [libclient, file_id, meta, old_value] () {
-            libclient->setMetadata(file_id, meta, fwk::property_value_new(old_value));
+            ffi::libraryclient_set_metadata(
+                libclient->client(), file_id, meta, fwk::property_value_new(old_value).get());
         });
     undo->execute();
     return true;
@@ -238,10 +240,12 @@ bool SelectionController::_set_metadata(const std::string & undo_label,
         auto new_value = fwk::property_bag_value(props, key);
         undo->new_command<void>(
             [libclient, file_id, key, new_value] () {
-                libclient->setMetadata(file_id, key, new_value);
+                ffi::libraryclient_set_metadata(
+                    libclient->client(), file_id, static_cast<ffi::Np>(key), new_value.get());
             },
             [libclient, file_id, key, value] () {
-                libclient->setMetadata(file_id, key, value);
+                ffi::libraryclient_set_metadata(
+                    libclient->client(), file_id, static_cast<ffi::Np>(key), value.get());
             });
     }
     undo->execute();
@@ -264,7 +268,7 @@ void SelectionController::set_flag(int flag)
     set_property(eng::NpNiepceFlagProp, flag);
 }
 
-void SelectionController::set_property(fwk::PropertyIndex idx, int value)
+void SelectionController::set_property(ffi::Np idx, int value)
 {
     DBG_OUT("property %u = %d", idx, value);
     eng::library_id_t selection = get_selection();
@@ -314,13 +318,14 @@ void SelectionController::write_metadata()
 {
     eng::library_id_t selection = get_selection();
     if(selection >= 0) {
-         getLibraryClient()->write_metadata(selection);
+        ffi::libraryclient_write_metadata(getLibraryClient()->client(), selection);
     }
 }
 
 void SelectionController::move_to_trash()
 {
-    eng::library_id_t trash_folder = getLibraryClient()->trash_id();
+    eng::library_id_t trash_folder =
+        ffi::libraryclient_get_trash_id(getLibraryClient()->client());
     eng::library_id_t selection = get_selection();
     if(selection >= 0) {
         Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
@@ -333,10 +338,12 @@ void SelectionController::move_to_trash()
             auto libclient = getLibraryClient();
             undo->new_command<void>(
                 [libclient, selection, from_folder, trash_folder] () {
-                    libclient->moveFileToFolder(selection, from_folder, trash_folder);
+                    ffi::libraryclient_move_file_to_folder(
+                        libclient->client(), selection, from_folder, trash_folder);
                 },
                 [libclient, selection, from_folder, trash_folder] () {
-                    libclient->moveFileToFolder(selection, trash_folder, from_folder);
+                    ffi::libraryclient_move_file_to_folder(
+                        libclient->client(), selection, trash_folder, from_folder);
                 });
             undo->execute();
         }
diff --git a/src/niepce/ui/selectioncontroller.hpp b/src/niepce/ui/selectioncontroller.hpp
index a2960f0..cdb849f 100644
--- a/src/niepce/ui/selectioncontroller.hpp
+++ b/src/niepce/ui/selectioncontroller.hpp
@@ -95,7 +95,7 @@ public:
     /** set flag */
     void set_flag(int flag);
 
-    void set_property(fwk::PropertyIndex idx, int value);
+    void set_property(ffi::Np idx, int value);
 
     void set_properties(const fwk::PropertyBagPtr & props,
                         const fwk::PropertyBagPtr & old);
@@ -116,7 +116,7 @@ private:
 
     bool _set_metadata(const std::string & undo_label,
                        const eng::LibFilePtr& file,
-                       fwk::PropertyIndex meta,
+                       ffi::Np meta,
                        int old_value, int new_value);
     bool _set_metadata(const std::string & undo_label,
                        const eng::LibFilePtr& file,
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index f0e9dad..bc4221c 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -147,11 +147,11 @@ void WorkspaceController::on_libtree_selection()
     switch(type) {
 
     case FOLDER_ITEM:
-        getLibraryClient()->queryFolderContent(id);
+        ffi::libraryclient_query_folder_content(getLibraryClient()->client(), id);
         break;
 
     case KEYWORD_ITEM:
-        getLibraryClient()->queryKeywordContent(id);
+        ffi::libraryclient_query_keyword_content(getLibraryClient()->client(), id);
         break;
 
     default:
@@ -216,7 +216,7 @@ void WorkspaceController::add_folder_item(const eng::LibFolder* f)
     int icon_idx = ICON_ROLL;
     if(engine_db_libfolder_virtual_type(f) == eng::FolderVirtualType::TRASH) {
         icon_idx = ICON_TRASH;
-        getLibraryClient()->set_trash_id(engine_db_libfolder_id(f));
+        ffi::libraryclient_set_trash_id(getLibraryClient()->client(), engine_db_libfolder_id(f));
     }
     auto children = m_folderNode->children();
     bool was_empty = children.empty();
@@ -227,10 +227,10 @@ void WorkspaceController::add_folder_item(const eng::LibFolder* f)
     if(engine_db_libfolder_expanded(f)) {
         m_librarytree.expand_row(m_treestore->get_path(iter), false);
     }
-    getLibraryClient()->countFolder(engine_db_libfolder_id(f));
+    ffi::libraryclient_count_folder(getLibraryClient()->client(), engine_db_libfolder_id(f));
     m_folderidmap[engine_db_libfolder_id(f)] = iter;
-    // expand if needed. Because Gtk is stupid and doesn't expand empty
-    if(was_empty) {
+    // expand if needed. Because Gtk doesn't expand empty
+    if (was_empty) {
         expand_from_cfg("workspace_folders_expanded", m_folderNode);
     }
 }
@@ -325,8 +325,8 @@ void WorkspaceController::on_ready()
 {
     libraryclient::LibraryClientPtr libraryClient = getLibraryClient();
     if (libraryClient) {
-        libraryClient->getAllFolders();
-        libraryClient->getAllKeywords();
+        ffi::libraryclient_get_all_folders(libraryClient->client());
+        ffi::libraryclient_get_all_keywords(libraryClient->client());
     }
 }
 



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