[niepce] npc-engine: FileType is part of the ffi



commit e8064c4f3733266938f72a63d373a74907f68b73
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Oct 15 22:13:23 2022 -0400

    npc-engine: FileType is part of the ffi

 crates/npc-engine/src/db/libfile.rs                | 23 +++-------------------
 crates/npc-engine/src/db/library.rs                |  2 +-
 crates/npc-engine/src/lib.rs                       | 11 ++---------
 niepce-main/src/niepce/ui/library_cell_renderer.rs |  1 +
 src/niepce/modules/darkroom/darkroommodule.cpp     |  4 ++--
 5 files changed, 9 insertions(+), 32 deletions(-)
---
diff --git a/crates/npc-engine/src/db/libfile.rs b/crates/npc-engine/src/db/libfile.rs
index e4b8a89e..0b3dfa2b 100644
--- a/crates/npc-engine/src/db/libfile.rs
+++ b/crates/npc-engine/src/db/libfile.rs
@@ -30,21 +30,7 @@ use super::LibraryId;
 use super::NiepceProperties as Np;
 use super::NiepcePropertyIdx;
 
-#[repr(i32)]
-#[derive(Debug, Copy, Clone, Eq, PartialEq)]
-/// A general type of the LibFile.
-pub enum FileType {
-    /// Don't know
-    Unknown = 0,
-    /// Camera Raw
-    Raw = 1,
-    /// Bundle of RAW + processed. Don't assume JPEG.
-    RawJpeg = 2,
-    /// Processed Image
-    Image = 3,
-    /// Video
-    Video = 4,
-}
+pub use crate::ffi::FileType;
 
 #[repr(i32)]
 #[derive(Debug, Clone, Copy, Eq, PartialEq)]
@@ -89,6 +75,7 @@ impl From<FileType> for &'static str {
             FileType::RawJpeg => "RAW + JPEG",
             FileType::Image => "Image",
             FileType::Video => "Video",
+            _ => unreachable!(),
         }
     }
 }
@@ -101,6 +88,7 @@ impl From<FileType> for i32 {
             FileType::RawJpeg => 2,
             FileType::Image => 3,
             FileType::Video => 4,
+            _ => unreachable!(),
         }
     }
 }
@@ -195,11 +183,6 @@ impl LibFile {
         self.file_type.to_owned()
     }
 
-    // for cxx
-    pub fn file_type_int(&self) -> i32 {
-        self.file_type.into()
-    }
-
     pub fn set_file_type(&mut self, ft: FileType) {
         self.file_type = ft;
     }
diff --git a/crates/npc-engine/src/db/library.rs b/crates/npc-engine/src/db/library.rs
index ca667419..35ca52d0 100644
--- a/crates/npc-engine/src/db/library.rs
+++ b/crates/npc-engine/src/db/library.rs
@@ -719,7 +719,7 @@ impl Library {
         }
 
         if let Some(ref conn) = self.dbconn {
-            let ifile_type = file_type as i32;
+            let ifile_type = i32::from(file_type);
             let time = Utc::now().timestamp();
             let c = conn.execute(
                 "INSERT INTO files (\
diff --git a/crates/npc-engine/src/lib.rs b/crates/npc-engine/src/lib.rs
index 37771c16..3e73af00 100644
--- a/crates/npc-engine/src/lib.rs
+++ b/crates/npc-engine/src/lib.rs
@@ -115,24 +115,18 @@ mod ffi {
         type RgbColour = npc_fwk::base::rgbcolour::RgbColour;
     }
 
-    // This enum is only here for the purpose of binding generation.
     #[repr(i32)]
-    /// A general type of the LibFile, cxx bindings version.
+    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
     pub enum FileType {
         /// Don't know
-        #[allow(dead_code)]
         Unknown = 0,
         /// Camera Raw
-        #[allow(dead_code)]
         Raw = 1,
         /// Bundle of RAW + processed. Don't assume JPEG.
-        #[allow(dead_code)]
         RawJpeg = 2,
         /// Processed Image
-        #[allow(dead_code)]
         Image = 3,
         /// Video
-        #[allow(dead_code)]
         Video = 4,
     }
 
@@ -162,9 +156,8 @@ mod ffi {
         fn id(&self) -> i64;
         fn folder_id(&self) -> i64;
         fn orientation(&self) -> i32;
-        #[cxx_name = "file_type"]
         // The type is `FileType`.
-        fn file_type_int(&self) -> i32;
+        fn file_type(&self) -> FileType;
     }
 
     impl Box<LibFile> {}
diff --git a/niepce-main/src/niepce/ui/library_cell_renderer.rs 
b/niepce-main/src/niepce/ui/library_cell_renderer.rs
index d9465c0c..7c9e217e 100644
--- a/niepce-main/src/niepce/ui/library_cell_renderer.rs
+++ b/niepce-main/src/niepce/ui/library_cell_renderer.rs
@@ -577,6 +577,7 @@ impl CellRendererImpl for LibraryCellRendererPriv {
                 FileType::Image => EMBLEMS.img.clone(),
                 FileType::Video => EMBLEMS.video.clone(),
                 FileType::Unknown => EMBLEMS.unknown.clone(),
+                _ => unreachable!(),
             };
             let left = Self::do_draw_format_emblem(snapshot, &emblem, &r);
 
diff --git a/src/niepce/modules/darkroom/darkroommodule.cpp b/src/niepce/modules/darkroom/darkroommodule.cpp
index c688af0b..0c1595b9 100644
--- a/src/niepce/modules/darkroom/darkroommodule.cpp
+++ b/src/niepce/modules/darkroom/darkroommodule.cpp
@@ -53,8 +53,8 @@ void DarkroomModule::reload_image()
         // currently we treat RAW + JPEG as RAW.
         // TODO: have a way to actually choose the JPEG.
         auto file_type = file->file_type();
-        bool isRaw = (file_type == (int32_t)eng::FileType::Raw)
-            || (file_type == (int32_t)eng::FileType::RawJpeg);
+        bool isRaw = (file_type == eng::FileType::Raw)
+            || (file_type == eng::FileType::RawJpeg);
         std::string path = std::string(file->path());
         m_image->reload(path, isRaw, file->orientation());
     }


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