[niepce] engine+rust: FolderVirtualType is now defined in Rust
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] engine+rust: FolderVirtualType is now defined in Rust
- Date: Thu, 28 Sep 2017 13:41:23 +0000 (UTC)
commit dec3f847400708166f189177cf90777a8a1a99c6
Author: Hubert Figuière <hub figuiere net>
Date: Wed Sep 27 22:34:17 2017 -0400
engine+rust: FolderVirtualType is now defined in Rust
src/engine/db/libfile.cpp | 2 --
src/engine/db/libfolder.cpp | 8 ++------
src/engine/db/libfolder.hpp | 7 -------
src/engine/db/libfolder.rs | 28 ++++++++++++++--------------
src/engine/db/library.rs | 2 +-
src/niepce/ui/workspacecontroller.cpp | 2 +-
src/rust_bindings.hpp | 1 +
7 files changed, 19 insertions(+), 31 deletions(-)
---
diff --git a/src/engine/db/libfile.cpp b/src/engine/db/libfile.cpp
index 2d88b61..48224f3 100644
--- a/src/engine/db/libfile.cpp
+++ b/src/engine/db/libfile.cpp
@@ -19,8 +19,6 @@
#include "libfile.hpp"
#include "engine/library/notification.hpp"
-#include "fwk/base/debug.hpp"
-#include "properties.hpp"
namespace eng {
diff --git a/src/engine/db/libfolder.cpp b/src/engine/db/libfolder.cpp
index 76b3cbd..eca101e 100644
--- a/src/engine/db/libfolder.cpp
+++ b/src/engine/db/libfolder.cpp
@@ -19,16 +19,12 @@
#include "libfolder.hpp"
-extern "C" eng::LibFolder *engine_db_libfolder_new(eng::library_id_t id,
- const char *name);
-extern "C" void engine_db_libfolder_delete(eng::LibFolder *);
-
namespace eng {
LibFolderPtr libfolder_new(eng::library_id_t id, const char *name)
{
- return LibFolderPtr(engine_db_libfolder_new(id, name),
- &engine_db_libfolder_delete);
+ return LibFolderPtr(ffi::engine_db_libfolder_new(id, name),
+ &ffi::engine_db_libfolder_delete);
}
}
/*
diff --git a/src/engine/db/libfolder.hpp b/src/engine/db/libfolder.hpp
index 703b6df..5d24a66 100644
--- a/src/engine/db/libfolder.hpp
+++ b/src/engine/db/libfolder.hpp
@@ -37,13 +37,6 @@ typedef std::shared_ptr<LibFolder> LibFolderPtr;
typedef std::list<LibFolderPtr> LibFolderList;
typedef std::shared_ptr<LibFolderList> LibFolderListPtr;
-enum class LibFolderVirtualType {
- NONE = 0,
- TRASH = 1,
-
- _LAST
-};
-
LibFolderPtr libfolder_new(library_id_t id, const char *name);
}
diff --git a/src/engine/db/libfolder.rs b/src/engine/db/libfolder.rs
index 27c797c..2a478f6 100644
--- a/src/engine/db/libfolder.rs
+++ b/src/engine/db/libfolder.rs
@@ -27,17 +27,17 @@ use super::LibraryId;
#[repr(i32)]
#[derive(Clone)]
-pub enum VirtualType {
+pub enum FolderVirtualType {
NONE = 0,
TRASH = 1
}
-impl From<i32> for VirtualType {
+impl From<i32> for FolderVirtualType {
fn from(t: i32) -> Self {
match t {
- 0 => VirtualType::NONE,
- 1 => VirtualType::TRASH,
- _ => VirtualType::NONE,
+ 0 => FolderVirtualType::NONE,
+ 1 => FolderVirtualType::TRASH,
+ _ => FolderVirtualType::NONE,
}
}
}
@@ -48,7 +48,7 @@ pub struct LibFolder {
name: String,
locked: bool,
expanded: bool,
- virt: VirtualType,
+ virt: FolderVirtualType,
cstr: CString,
}
@@ -56,7 +56,7 @@ impl LibFolder {
pub fn new(id: LibraryId, name: &str) -> LibFolder {
LibFolder {
id: id, name: String::from(name), locked: false,
- expanded: false, virt: VirtualType::NONE,
+ expanded: false, virt: FolderVirtualType::NONE,
cstr: CString::new("").unwrap(),
}
}
@@ -85,11 +85,11 @@ impl LibFolder {
self.expanded = expanded;
}
- pub fn virtual_type(&self) -> VirtualType {
+ pub fn virtual_type(&self) -> FolderVirtualType {
self.virt.to_owned()
}
- pub fn set_virtual_type(&mut self, virt: VirtualType) {
+ pub fn set_virtual_type(&mut self, virt: FolderVirtualType) {
self.virt = virt;
}
@@ -113,7 +113,7 @@ impl FromDb for LibFolder {
let expanded = row.get(4);
let mut libfolder = LibFolder::new(id, &name);
- libfolder.set_virtual_type(VirtualType::from(virt_type));
+ libfolder.set_virtual_type(FolderVirtualType::from(virt_type));
libfolder.set_locked(locked);
libfolder.set_expanded(expanded);
@@ -144,8 +144,8 @@ pub extern "C" fn engine_db_libfolder_name(obj: &mut LibFolder) -> *const c_char
}
#[no_mangle]
-pub extern "C" fn engine_db_libfolder_virtual_type(obj: &LibFolder) -> i32 {
- obj.virtual_type() as i32
+pub extern "C" fn engine_db_libfolder_virtual_type(obj: &LibFolder) -> FolderVirtualType {
+ obj.virtual_type()
}
#[no_mangle]
@@ -164,6 +164,6 @@ pub extern fn engine_db_libfolder_set_expanded(obj: &mut LibFolder, expanded: bo
}
#[no_mangle]
-pub extern fn engine_db_libfolder_set_virtual_type(obj: &mut LibFolder, t: i32) {
- obj.set_virtual_type(VirtualType::from(t));
+pub extern fn engine_db_libfolder_set_virtual_type(obj: &mut LibFolder, t: FolderVirtualType) {
+ obj.set_virtual_type(t);
}
diff --git a/src/engine/db/library.rs b/src/engine/db/library.rs
index 5eb2fcd..498aba2 100644
--- a/src/engine/db/library.rs
+++ b/src/engine/db/library.rs
@@ -154,7 +154,7 @@ impl Library {
virtual INTEGER DEFAULT 0, \
expanded INTEGER DEFAULT 0, \
parent_id INTEGER)", &[]).unwrap();
- let trash_type = libfolder::VirtualType::TRASH as i32;
+ let trash_type = libfolder::FolderVirtualType::TRASH as i32;
conn.execute("insert into folders (name, locked, virtual, parent_id) \
values (:1, 1, :2, 0)",
&[&"Trash", &trash_type]).unwrap();
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index 00213e1..241c7b7 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -215,7 +215,7 @@ void WorkspaceController::add_keyword_item(const eng::Keyword* k)
void WorkspaceController::add_folder_item(const eng::LibFolder* f)
{
int icon_idx = ICON_ROLL;
- if(engine_db_libfolder_virtual_type(f) == (int32_t)eng::LibFolderVirtualType::TRASH) {
+ if(engine_db_libfolder_virtual_type(f) == eng::FolderVirtualType::TRASH) {
icon_idx = ICON_TRASH;
getLibraryClient()->set_trash_id(engine_db_libfolder_id(f));
}
diff --git a/src/rust_bindings.hpp b/src/rust_bindings.hpp
index 848f3bb..929ed0a 100644
--- a/src/rust_bindings.hpp
+++ b/src/rust_bindings.hpp
@@ -63,6 +63,7 @@ typedef ffi::Managed Managed;
typedef ffi::Notification LibNotification;
typedef ffi::NotificationType NotificationType;
typedef ffi::Np Np;
+typedef ffi::FolderVirtualType FolderVirtualType;
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]