[niepce] library: create folder command.
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] library: create folder command.
- Date: Fri, 17 Nov 2017 02:17:16 +0000 (UTC)
commit 3beac1ad256246f082f860a9a6acc7185ae459d3
Author: Hubert Figuière <hub figuiere net>
Date: Mon Nov 13 23:31:11 2017 -0500
library: create folder command.
src/engine/library/commands.rs | 9 +++++++++
src/libraryclient/clientimpl.rs | 12 ++++++++++++
src/libraryclient/clientinterface.rs | 5 ++++-
src/libraryclient/libraryclient.rs | 9 +++++++++
4 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/library/commands.rs b/src/engine/library/commands.rs
index 2ce9cb5..d349aa4 100644
--- a/src/engine/library/commands.rs
+++ b/src/engine/library/commands.rs
@@ -114,6 +114,15 @@ pub fn cmd_import_files(lib: &Library, folder: &str, files: &Vec<String>,
true
}
+pub fn cmd_create_folder(lib: &Library, path: &String) -> LibraryId {
+ if let Some(lf) = lib.add_folder(path) {
+ let id = lf.id();
+ lib.notify(Box::new(LibNotification::AddedFolder(lf)));
+ return id;
+ }
+ 0
+}
+
pub fn cmd_request_metadata(lib: &Library, file_id: LibraryId) -> bool {
if let Some(lm) = lib.get_metadata(file_id) {
lib.notify(Box::new(LibNotification::MetadataQueried(lm)));
diff --git a/src/libraryclient/clientimpl.rs b/src/libraryclient/clientimpl.rs
index 89ab2f1..f48a763 100644
--- a/src/libraryclient/clientimpl.rs
+++ b/src/libraryclient/clientimpl.rs
@@ -240,4 +240,16 @@ impl ClientInterfaceSync for ClientImpl {
rx.recv().unwrap()
}
+
+ fn create_folder_sync(&mut self, path: String) -> LibraryId {
+ // can't use futures::sync::oneshot
+ let (tx, rx) = mpsc::sync_channel::<LibraryId>(1);
+
+ self.schedule_op(move |lib| {
+ tx.send(commands::cmd_create_folder(&lib, &path)).unwrap();
+ true
+ });
+
+ rx.recv().unwrap()
+ }
}
diff --git a/src/libraryclient/clientinterface.rs b/src/libraryclient/clientinterface.rs
index 8a1ddbb..107a68e 100644
--- a/src/libraryclient/clientinterface.rs
+++ b/src/libraryclient/clientinterface.rs
@@ -68,6 +68,9 @@ pub trait ClientInterfaceSync {
/// If the keyword already exists, return its `LibraryId`.
fn create_keyword_sync(&mut self, keyword: String) -> LibraryId;
- /// Create a label. Return the id of the newly created labal.
+ /// Create a label. Return the id of the newly created label.
fn create_label_sync(&mut self, name: String, colour: String) -> LibraryId;
+
+ /// Create a folder. Return the id of the newly created folder.
+ fn create_folder_sync(&mut self, path: String) -> LibraryId;
}
diff --git a/src/libraryclient/libraryclient.rs b/src/libraryclient/libraryclient.rs
index 6390fa0..ad75808 100644
--- a/src/libraryclient/libraryclient.rs
+++ b/src/libraryclient/libraryclient.rs
@@ -30,6 +30,8 @@ use engine::db::library::Managed;
use root::fwk::FileList;
use root::eng::NiepceProperties as Np;
+/// Wrap the libclient Arc so that it can be passed around
+/// Used in the ffi for example.
pub struct LibraryClientWrapper {
client: Arc<LibraryClient>
}
@@ -39,6 +41,9 @@ impl LibraryClientWrapper {
LibraryClientWrapper { client: Arc::new(LibraryClient::new(dir, notif_id)) }
}
+ /// unwrap the mutable client Arc
+ /// XXX we need to unsure this is thread safe.
+ /// Don't hold this reference more than you need.
pub fn unwrap_mut(&mut self) -> &mut LibraryClient {
Arc::get_mut(&mut self.client).unwrap()
}
@@ -147,6 +152,10 @@ impl ClientInterfaceSync for LibraryClient {
fn create_label_sync(&mut self, name: String, colour: String) -> LibraryId {
self.pimpl.create_label_sync(name, colour)
}
+
+ fn create_folder_sync(&mut self, path: String) -> LibraryId {
+ self.pimpl.create_folder_sync(path)
+ }
}
#[no_mangle]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]