[niepce] Fix clippy warnings:



commit 429f2f8d74d862e707d2d60af974e696a9583d94
Author: Hubert Figuière <hub figuiere net>
Date:   Fri Jul 2 23:19:15 2021 -0400

    Fix clippy warnings:
    
    - Remove Into()
    - Remove some unsafe
    - Add Default when recommended
    - Added Safety docs
    - Use range contains()

 crates/npc-engine/src/db/keyword.rs                |  9 +++--
 crates/npc-engine/src/db/label.rs                  |  3 +-
 crates/npc-engine/src/db/libfile.rs                | 18 +++++-----
 crates/npc-engine/src/db/libfolder.rs              |  1 -
 crates/npc-engine/src/db/libmetadata.rs            |  4 +--
 crates/npc-engine/src/db/library.rs                |  2 --
 crates/npc-engine/src/db/mod.rs                    |  2 --
 crates/npc-engine/src/db/props.rs                  | 12 ++++---
 crates/npc-engine/src/library/commands.rs          |  2 +-
 crates/npc-engine/src/library/notification.rs      | 23 ++++++------
 crates/npc-engine/src/library/thumbnail_cache.rs   | 14 ++++----
 crates/npc-fwk/src/base/propertyvalue.rs           | 23 +++---------
 crates/npc-fwk/src/base/rgbcolour.rs               | 13 ++++---
 crates/npc-fwk/src/toolkit/thumbnail.rs            | 31 ++++++----------
 crates/npc-fwk/src/toolkit/widgets/rating_label.rs |  1 -
 crates/npc-fwk/src/utils/exempi.rs                 | 10 +++---
 crates/npc-fwk/src/utils/files.rs                  |  5 +--
 niepce-main/src/libraryclient/mod.rs               |  2 +-
 niepce-main/src/niepce/ui/dialogs/confirm.rs       |  6 ++--
 .../src/niepce/ui/dialogs/requestnewfolder.rs      |  4 +--
 niepce-main/src/niepce/ui/image_grid_view.rs       |  3 +-
 niepce-main/src/niepce/ui/image_list_store.rs      | 41 +++++++++++++---------
 niepce-main/src/niepce/ui/imagetoolbar.rs          |  4 +--
 niepce-main/src/niepce/ui/library_cell_renderer.rs |  9 +++--
 niepce-main/src/niepce/ui/thumb_nav.rs             |  9 ++---
 niepce-main/src/niepce/ui/thumb_strip_view.rs      |  3 +-
 26 files changed, 117 insertions(+), 137 deletions(-)
---
diff --git a/crates/npc-engine/src/db/keyword.rs b/crates/npc-engine/src/db/keyword.rs
index cd9b158..af84df0 100644
--- a/crates/npc-engine/src/db/keyword.rs
+++ b/crates/npc-engine/src/db/keyword.rs
@@ -20,7 +20,6 @@
 use super::FromDb;
 use super::LibraryId;
 use libc::c_char;
-use rusqlite;
 use std::ffi::CStr;
 use std::ffi::CString;
 
@@ -42,7 +41,7 @@ impl Keyword {
         self.id
     }
 
-    pub fn keyword(&self) -> &String {
+    pub fn keyword(&self) -> &str {
         &self.keyword
     }
 }
@@ -66,6 +65,8 @@ impl FromDb for Keyword {
     }
 }
 
+/// # Safety
+/// Dereference raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_db_keyword_new(id: i64, keyword: *const c_char) -> *mut Keyword {
     let kw = Box::new(Keyword::new(
@@ -82,10 +83,12 @@ pub extern "C" fn engine_db_keyword_id(obj: &Keyword) -> i64 {
 
 #[no_mangle]
 pub extern "C" fn engine_db_keyword_keyword(obj: &Keyword) -> *mut c_char {
-    let cstr = CString::new(obj.keyword().clone()).unwrap();
+    let cstr = CString::new(obj.keyword()).unwrap();
     cstr.into_raw()
 }
 
+/// # Safety
+/// Dereference raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_db_keyword_delete(kw: *mut Keyword) {
     Box::from_raw(kw);
diff --git a/crates/npc-engine/src/db/label.rs b/crates/npc-engine/src/db/label.rs
index 1e0feca..445277a 100644
--- a/crates/npc-engine/src/db/label.rs
+++ b/crates/npc-engine/src/db/label.rs
@@ -18,7 +18,6 @@
  */
 
 use libc::c_char;
-use rusqlite;
 use std::ffi::CString;
 use std::str::FromStr;
 
@@ -86,6 +85,8 @@ impl FromDb for Label {
     }
 }
 
+/// # Safety
+/// Dereference raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_db_label_delete(l: *mut Label) {
     Box::from_raw(l);
diff --git a/crates/npc-engine/src/db/libfile.rs b/crates/npc-engine/src/db/libfile.rs
index c4b0fa2..337f2aa 100644
--- a/crates/npc-engine/src/db/libfile.rs
+++ b/crates/npc-engine/src/db/libfile.rs
@@ -18,7 +18,6 @@
  */
 
 use libc::c_char;
-use rusqlite;
 use std::ffi::CStr;
 use std::ffi::CString;
 use std::path::{Path, PathBuf};
@@ -28,7 +27,6 @@ use super::FromDb;
 use super::LibraryId;
 use super::NiepceProperties as Np;
 use super::NiepcePropertyIdx;
-use npc_fwk;
 
 #[repr(i32)]
 #[derive(Debug, Copy, Clone, PartialEq)]
@@ -81,9 +79,9 @@ impl From<i32> for FileType {
     }
 }
 
-impl Into<&'static str> for FileType {
-    fn into(self) -> &'static str {
-        match self {
+impl From<FileType> for &'static str {
+    fn from(v: FileType) -> &'static str {
+        match v {
             FileType::Unknown => "Unknown",
             FileType::Raw => "RAW",
             FileType::RawJpeg => "RAW + JPEG",
@@ -93,9 +91,9 @@ impl Into<&'static str> for FileType {
     }
 }
 
-impl Into<i32> for FileType {
-    fn into(self) -> i32 {
-        match self {
+impl From<FileType> for i32 {
+    fn from(v: FileType) -> i32 {
+        match v {
             FileType::Unknown => 0,
             FileType::Raw => 1,
             FileType::RawJpeg => 2,
@@ -275,6 +273,8 @@ pub fn mimetype_to_filetype(mime: &npc_fwk::MimeType) -> FileType {
     }
 }
 
+/// # Safety
+/// Dereference raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_db_libfile_new(
     id: LibraryId,
@@ -293,6 +293,8 @@ pub unsafe extern "C" fn engine_db_libfile_new(
     Box::into_raw(lf)
 }
 
+/// # Safety
+/// Dereference raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_db_libfile_delete(lf: *mut LibFile) {
     Box::from_raw(lf);
diff --git a/crates/npc-engine/src/db/libfolder.rs b/crates/npc-engine/src/db/libfolder.rs
index 954da49..22a7a8e 100644
--- a/crates/npc-engine/src/db/libfolder.rs
+++ b/crates/npc-engine/src/db/libfolder.rs
@@ -18,7 +18,6 @@
  */
 
 use libc::c_char;
-use rusqlite;
 use std::ffi::CString;
 
 use super::FromDb;
diff --git a/crates/npc-engine/src/db/libmetadata.rs b/crates/npc-engine/src/db/libmetadata.rs
index 293da87..6870197 100644
--- a/crates/npc-engine/src/db/libmetadata.rs
+++ b/crates/npc-engine/src/db/libmetadata.rs
@@ -18,8 +18,6 @@
  */
 
 use chrono::Utc;
-use exempi;
-use rusqlite;
 
 use super::libfile::FileType;
 use super::props;
@@ -244,7 +242,7 @@ impl LibMetadata {
                     props.set_value(*prop_id, PropertyValue::StringArray(self.sidecars.clone()));
                 }
                 _ => {
-                    if let Some(propval) = self.get_metadata((*prop_id).into()) {
+                    if let Some(propval) = self.get_metadata(*prop_id) {
                         props.set_value(*prop_id, propval);
                     } else {
                         dbg_out!("missing prop {:?}", prop_id);
diff --git a/crates/npc-engine/src/db/library.rs b/crates/npc-engine/src/db/library.rs
index 48e93ad..6620254 100644
--- a/crates/npc-engine/src/db/library.rs
+++ b/crates/npc-engine/src/db/library.rs
@@ -24,7 +24,6 @@ use std::path::{Path, PathBuf};
 use std::result;
 
 use chrono::Utc;
-use rusqlite;
 use rusqlite::{functions::FunctionFlags, params};
 
 use super::props::NiepceProperties as Np;
@@ -39,7 +38,6 @@ use crate::db::libfolder;
 use crate::db::libfolder::LibFolder;
 use crate::db::libmetadata::LibMetadata;
 use crate::library::notification::LibNotification;
-use npc_fwk;
 use npc_fwk::toolkit;
 use npc_fwk::PropertyValue;
 
diff --git a/crates/npc-engine/src/db/mod.rs b/crates/npc-engine/src/db/mod.rs
index 6224837..faa2309 100644
--- a/crates/npc-engine/src/db/mod.rs
+++ b/crates/npc-engine/src/db/mod.rs
@@ -38,8 +38,6 @@ pub use self::library::Library;
 pub use self::props::NiepceProperties;
 pub use self::props::NiepcePropertyIdx;
 
-use rusqlite;
-
 pub trait FromDb: Sized {
     /// return the columns for reading from the DB.
     fn read_db_columns() -> &'static str;
diff --git a/crates/npc-engine/src/db/props.rs b/crates/npc-engine/src/db/props.rs
index e4716a3..180fff0 100644
--- a/crates/npc-engine/src/db/props.rs
+++ b/crates/npc-engine/src/db/props.rs
@@ -43,14 +43,16 @@ pub enum NiepceProperties {
     Index(NiepcePropertyIdx),
     Other(u32),
 }
-impl Into<u32> for NiepceProperties {
-    fn into(self) -> u32 {
-        match self {
-            Self::Index(i) => i as u32,
-            Self::Other(i) => i,
+
+impl From<NiepceProperties> for u32 {
+    fn from(v: NiepceProperties) -> u32 {
+        match v {
+            NiepceProperties::Index(i) => i as u32,
+            NiepceProperties::Other(i) => i,
         }
     }
 }
+
 impl From<u32> for NiepceProperties {
     fn from(v: u32) -> NiepceProperties {
         match v {
diff --git a/crates/npc-engine/src/library/commands.rs b/crates/npc-engine/src/library/commands.rs
index 2f3166c..28c87fc 100644
--- a/crates/npc-engine/src/library/commands.rs
+++ b/crates/npc-engine/src/library/commands.rs
@@ -215,7 +215,7 @@ pub fn cmd_set_metadata(lib: &Library, id: LibraryId, meta: Np, value: &Property
             if lib
                 .notify(LibNotification::MetadataChanged(MetadataChange::new(
                     id,
-                    meta.into(),
+                    meta,
                     value.clone(),
                 )))
                 .is_err()
diff --git a/crates/npc-engine/src/library/notification.rs b/crates/npc-engine/src/library/notification.rs
index c377685..30452c9 100644
--- a/crates/npc-engine/src/library/notification.rs
+++ b/crates/npc-engine/src/library/notification.rs
@@ -100,20 +100,18 @@ pub struct Thumbnail {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn metadatachange_get_id(meta: *const MetadataChange) -> LibraryId {
-    (*meta).id
+pub extern "C" fn metadatachange_get_id(meta: &MetadataChange) -> LibraryId {
+    meta.id
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn metadatachange_get_meta(meta: *const MetadataChange) -> PropertyIndex {
-    (*meta).meta.into()
+pub extern "C" fn metadatachange_get_meta(meta: &MetadataChange) -> PropertyIndex {
+    meta.meta.into()
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn metadatachange_get_value(
-    meta: *const MetadataChange,
-) -> *const PropertyValue {
-    &(*meta).value
+pub extern "C" fn metadatachange_get_value(meta: &MetadataChange) -> *const PropertyValue {
+    &meta.value
 }
 
 #[derive(Clone)]
@@ -144,12 +142,12 @@ pub enum LibNotification {
 /// Send a notification for the file status change.
 /// Return `false` if sending failed.
 #[no_mangle]
-pub unsafe extern "C" fn engine_library_notify_filestatus_changed(
-    channel: *const LcChannel,
+pub extern "C" fn engine_library_notify_filestatus_changed(
+    channel: &LcChannel,
     id: LibraryId,
     status: FileStatus,
 ) -> bool {
-    if let Err(err) = toolkit::thread_context().block_on((*channel).0.clone().send(
+    if let Err(err) = toolkit::thread_context().block_on(channel.0.clone().send(
         LibNotification::FileStatusChanged(FileStatusChange { id, status }),
     )) {
         err_out!("Error sending notification: {}", err);
@@ -159,6 +157,9 @@ pub unsafe extern "C" fn engine_library_notify_filestatus_changed(
 }
 
 /// Delete the Notification object.
+///
+/// # Safety
+/// Use raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_notification_delete(n: *mut LibNotification) {
     Box::from_raw(n);
diff --git a/crates/npc-engine/src/library/thumbnail_cache.rs 
b/crates/npc-engine/src/library/thumbnail_cache.rs
index 0badae2..04775f9 100644
--- a/crates/npc-engine/src/library/thumbnail_cache.rs
+++ b/crates/npc-engine/src/library/thumbnail_cache.rs
@@ -27,8 +27,6 @@ use std::sync;
 use std::sync::atomic;
 use std::thread;
 
-use gdk_pixbuf;
-
 use crate::db::libfile::{FileStatus, LibFile};
 use crate::db::LibraryId;
 use crate::library::notification;
@@ -79,7 +77,7 @@ fn get_thumbnail(f: &LibFile, w: i32, h: i32, cached: &Path) -> Thumbnail {
     } else {
         dbg_out!("couldn't get the thumbnail for {:?}", filename);
     }
-    return thumbnail;
+    thumbnail
 }
 
 type Tasks = sync::Arc<(sync::Mutex<VecDeque<ThumbnailTask>>, sync::Condvar)>;
@@ -188,7 +186,7 @@ impl ThumbnailCache {
         }
     }
 
-    pub fn request(&self, fl: &Vec<LibFile>) {
+    pub fn request(&self, fl: &[LibFile]) {
         for f in fl {
             self.schedule(ThumbnailTask::new(f.clone(), 160, 160));
         }
@@ -206,7 +204,7 @@ impl ThumbnailCache {
     ) -> PathBuf {
         let base_name = filename.file_name().and_then(|f| f.to_str()).unwrap(); // XXX fatal if fails.
         let thumb_name = format!("{}-{}.png", id, base_name);
-        let mut path = PathBuf::from(Self::dir_for_thumbnail(size, cache_dir));
+        let mut path = Self::dir_for_thumbnail(size, cache_dir);
         path.push(thumb_name);
         path
     }
@@ -223,6 +221,8 @@ impl ThumbnailCache {
     }
 }
 
+/// # Safety
+/// Dereference raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_thumbnail_cache_new(
     dir: *const c_char,
@@ -232,13 +232,15 @@ pub unsafe extern "C" fn engine_library_thumbnail_cache_new(
     Box::into_raw(Box::new(ThumbnailCache::new(&path, (*channel).0.clone())))
 }
 
+/// # Safety
+/// Dereference raw pointer.
 #[no_mangle]
 pub unsafe extern "C" fn engine_library_thumbnail_cache_delete(obj: *mut ThumbnailCache) {
     Box::from_raw(obj);
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn engine_library_thumbnail_cache_request(
+pub extern "C" fn engine_library_thumbnail_cache_request(
     self_: &mut ThumbnailCache,
     content: &QueriedContent,
 ) {
diff --git a/crates/npc-fwk/src/base/propertyvalue.rs b/crates/npc-fwk/src/base/propertyvalue.rs
index 186c5ba..513500f 100644
--- a/crates/npc-fwk/src/base/propertyvalue.rs
+++ b/crates/npc-fwk/src/base/propertyvalue.rs
@@ -75,21 +75,12 @@ pub unsafe extern "C" fn fwk_property_value_delete(v: *mut PropertyValue) {
 
 #[no_mangle]
 pub extern "C" fn fwk_property_value_is_empty(v: &PropertyValue) -> bool {
-    match *v {
-        PropertyValue::Empty => true,
-        _ => false,
-    }
+    matches!(*v, PropertyValue::Empty)
 }
 
 #[no_mangle]
 pub extern "C" fn fwk_property_value_is_integer(v: &PropertyValue) -> bool {
-    match *v {
-        PropertyValue::Int(_) => true,
-        _ => {
-            println!("PropertyValue is {:?}", &v);
-            false
-        }
-    }
+    matches!(*v, PropertyValue::Int(_))
 }
 
 #[no_mangle]
@@ -102,10 +93,7 @@ pub extern "C" fn fwk_property_value_get_integer(v: &PropertyValue) -> i32 {
 
 #[no_mangle]
 pub extern "C" fn fwk_property_value_is_date(v: &PropertyValue) -> bool {
-    match *v {
-        PropertyValue::Date(_) => true,
-        _ => false,
-    }
+    matches!(*v, PropertyValue::Date(_))
 }
 
 #[no_mangle]
@@ -118,10 +106,7 @@ pub extern "C" fn fwk_property_value_get_date(v: &PropertyValue) -> *const Date
 
 #[no_mangle]
 pub extern "C" fn fwk_property_value_is_string(v: &PropertyValue) -> bool {
-    match *v {
-        PropertyValue::String(_) => true,
-        _ => false,
-    }
+    matches!(*v, PropertyValue::String(_))
 }
 
 #[no_mangle]
diff --git a/crates/npc-fwk/src/base/rgbcolour.rs b/crates/npc-fwk/src/base/rgbcolour.rs
index 9425cd7..de86620 100644
--- a/crates/npc-fwk/src/base/rgbcolour.rs
+++ b/crates/npc-fwk/src/base/rgbcolour.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/base/rgbcolour.rs
  *
- * Copyright (C) 2017-2020 Hubert Figuière
+ * Copyright (C) 2017-2021 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
@@ -18,7 +18,6 @@
  */
 
 use libc::c_char;
-use std::convert::Into;
 use std::ffi::CString;
 use std::num::ParseIntError;
 use std::str::FromStr;
@@ -74,12 +73,12 @@ impl ToString for RgbColour {
     }
 }
 
-impl Into<gdk::RGBA> for RgbColour {
-    fn into(self) -> gdk::RGBA {
+impl From<RgbColour> for gdk::RGBA {
+    fn from(v: RgbColour) -> gdk::RGBA {
         gdk::RGBA {
-            red: self.r as f64 / 65535_f64,
-            green: self.g as f64 / 65535_f64,
-            blue: self.b as f64 / 65535_f64,
+            red: v.r as f64 / 65535_f64,
+            green: v.g as f64 / 65535_f64,
+            blue: v.b as f64 / 65535_f64,
             alpha: 1.0,
         }
     }
diff --git a/crates/npc-fwk/src/toolkit/thumbnail.rs b/crates/npc-fwk/src/toolkit/thumbnail.rs
index ea7123d..b07edbc 100644
--- a/crates/npc-fwk/src/toolkit/thumbnail.rs
+++ b/crates/npc-fwk/src/toolkit/thumbnail.rs
@@ -75,18 +75,7 @@ impl Thumbnail {
     /// Make a gdk_pixbuf::Pixbuf out of the Thumbnail
     pub fn make_pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
         if self.ok() {
-            // XXX figure out the allocation here.
-            // Ideally we should have this shared
-            // Also this is duplicated with Into()
-            Some(gdk_pixbuf::Pixbuf::from_bytes(
-                &glib::Bytes::from(&self.bytes),
-                self.colorspace,
-                self.has_alpha,
-                self.bits_per_sample,
-                self.width,
-                self.height,
-                self.stride,
-            ))
+            Some(self.into())
         } else {
             None
         }
@@ -174,16 +163,16 @@ impl From<Option<gdk_pixbuf::Pixbuf>> for Thumbnail {
     }
 }
 
-impl Into<gdk_pixbuf::Pixbuf> for Thumbnail {
-    fn into(self) -> gdk_pixbuf::Pixbuf {
+impl From<&Thumbnail> for gdk_pixbuf::Pixbuf {
+    fn from(v: &Thumbnail) -> gdk_pixbuf::Pixbuf {
         gdk_pixbuf::Pixbuf::from_bytes(
-            &glib::Bytes::from(&self.bytes),
-            self.colorspace,
-            self.has_alpha,
-            self.bits_per_sample,
-            self.width,
-            self.height,
-            self.stride,
+            &glib::Bytes::from(&v.bytes),
+            v.colorspace,
+            v.has_alpha,
+            v.bits_per_sample,
+            v.width,
+            v.height,
+            v.stride,
         )
     }
 }
diff --git a/crates/npc-fwk/src/toolkit/widgets/rating_label.rs 
b/crates/npc-fwk/src/toolkit/widgets/rating_label.rs
index 88b03ca..184020c 100644
--- a/crates/npc-fwk/src/toolkit/widgets/rating_label.rs
+++ b/crates/npc-fwk/src/toolkit/widgets/rating_label.rs
@@ -22,7 +22,6 @@ use std::cell::Cell;
 
 use gdk::prelude::*;
 use gdk_pixbuf::Pixbuf;
-use glib;
 use glib::subclass::prelude::*;
 use glib::subclass::Signal;
 use glib::translate::*;
diff --git a/crates/npc-fwk/src/utils/exempi.rs b/crates/npc-fwk/src/utils/exempi.rs
index 8d6a428..f8887c5 100644
--- a/crates/npc-fwk/src/utils/exempi.rs
+++ b/crates/npc-fwk/src/utils/exempi.rs
@@ -479,11 +479,11 @@ pub fn xmp_date_from_exif(d: &str) -> Option<exempi::DateTime> {
     }
     let year = try_opt!(i32::from_str_radix(ymd[0], 10).ok());
     let month = try_opt!(i32::from_str_radix(ymd[1], 10).ok());
-    if month < 1 || month > 12 {
+    if !(1..=12).contains(&month) {
         return None;
     }
     let day = try_opt!(i32::from_str_radix(ymd[2], 10).ok());
-    if day < 1 || day > 31 {
+    if !(1..=31).contains(&day) {
         return None;
     }
     let hms: Vec<&str> = v[1].split(':').collect();
@@ -492,15 +492,15 @@ pub fn xmp_date_from_exif(d: &str) -> Option<exempi::DateTime> {
         return None;
     }
     let hour = try_opt!(i32::from_str_radix(hms[0], 10).ok());
-    if hour < 0 || hour > 23 {
+    if !(0..=23).contains(&hour) {
         return None;
     }
     let min = try_opt!(i32::from_str_radix(hms[1], 10).ok());
-    if min < 0 || min > 59 {
+    if !(0..=59).contains(&min) {
         return None;
     }
     let sec = try_opt!(i32::from_str_radix(hms[2], 10).ok());
-    if sec < 0 || sec > 59 {
+    if !(0..=59).contains(&sec) {
         return None;
     }
 
diff --git a/crates/npc-fwk/src/utils/files.rs b/crates/npc-fwk/src/utils/files.rs
index 3bb84d6..a1ba27f 100644
--- a/crates/npc-fwk/src/utils/files.rs
+++ b/crates/npc-fwk/src/utils/files.rs
@@ -74,10 +74,7 @@ impl FileList {
     pub fn file_is_media(fileinfo: &gio::FileInfo) -> bool {
         if let Some(gmtype) = fileinfo.content_type() {
             let t = guess_type(&gmtype);
-            return match t {
-                MType::Image(_) | MType::Movie => true,
-                _ => false,
-            };
+            return matches!(t, MType::Image(_) | MType::Movie);
         }
 
         err_out!("Coudln't get file type");
diff --git a/niepce-main/src/libraryclient/mod.rs b/niepce-main/src/libraryclient/mod.rs
index 1016088..b0e28fe 100644
--- a/niepce-main/src/libraryclient/mod.rs
+++ b/niepce-main/src/libraryclient/mod.rs
@@ -172,7 +172,7 @@ impl ClientInterfaceSync for LibraryClient {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn lcchannel_new(
+pub extern "C" fn lcchannel_new(
     cb: extern "C" fn(n: *const LibNotification, data: *mut c_void) -> i32,
     data: *mut c_void,
 ) -> *mut LcChannel {
diff --git a/niepce-main/src/niepce/ui/dialogs/confirm.rs b/niepce-main/src/niepce/ui/dialogs/confirm.rs
index dc32aeb..9f981b9 100644
--- a/niepce-main/src/niepce/ui/dialogs/confirm.rs
+++ b/niepce-main/src/niepce/ui/dialogs/confirm.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - niepce/ui/dialogs/confirm.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2021 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
@@ -21,11 +21,11 @@ use libc::c_char;
 use std::ffi::CStr;
 
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
 use gtk::MessageDialog;
-use gtk_sys;
 
+/// # Safety
+/// Use raw pointers.
 #[no_mangle]
 pub unsafe extern "C" fn dialog_confirm(
     message: *const c_char,
diff --git a/niepce-main/src/niepce/ui/dialogs/requestnewfolder.rs 
b/niepce-main/src/niepce/ui/dialogs/requestnewfolder.rs
index 75e9cde..b4c4df4 100644
--- a/niepce-main/src/niepce/ui/dialogs/requestnewfolder.rs
+++ b/niepce-main/src/niepce/ui/dialogs/requestnewfolder.rs
@@ -19,13 +19,13 @@
 
 use gettextrs::gettext;
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
 use gtk::{Dialog, Entry, Label};
-use gtk_sys;
 
 use crate::libraryclient::{ClientInterface, LibraryClientWrapper};
 
+/// # Safety
+/// Use raw pointers.
 #[no_mangle]
 pub unsafe extern "C" fn dialog_request_new_folder(
     client: &mut LibraryClientWrapper,
diff --git a/niepce-main/src/niepce/ui/image_grid_view.rs b/niepce-main/src/niepce/ui/image_grid_view.rs
index 3cfa866..b7cfb3f 100644
--- a/niepce-main/src/niepce/ui/image_grid_view.rs
+++ b/niepce-main/src/niepce/ui/image_grid_view.rs
@@ -19,7 +19,6 @@
 
 use glib::subclass::prelude::*;
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
 use gtk::subclass::prelude::*;
 use gtk::subclass::widget::WidgetImplExt;
@@ -78,6 +77,8 @@ impl ContainerImpl for ImageGridViewPriv {}
 
 impl IconViewImpl for ImageGridViewPriv {}
 
+/// # Safety
+/// Use raw pointers.
 #[no_mangle]
 pub unsafe extern "C" fn npc_image_grid_view_new(
     store: *mut gtk_sys::GtkTreeModel,
diff --git a/niepce-main/src/niepce/ui/image_list_store.rs b/niepce-main/src/niepce/ui/image_list_store.rs
index fcdd816..7ec219d 100644
--- a/niepce-main/src/niepce/ui/image_list_store.rs
+++ b/niepce-main/src/niepce/ui/image_list_store.rs
@@ -20,12 +20,8 @@
 use std::collections::BTreeMap;
 use std::ptr;
 
-use gdk_pixbuf;
-use gdk_pixbuf_sys;
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
-use gtk_sys;
 
 use once_cell::unsync::OnceCell;
 
@@ -61,6 +57,12 @@ pub struct ImageListStore {
     image_loading_icon: OnceCell<Option<gdk_pixbuf::Pixbuf>>,
 }
 
+impl Default for ImageListStore {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl ImageListStore {
     pub fn new() -> Self {
         let col_types: [glib::Type; 4] = [
@@ -100,10 +102,10 @@ impl ImageListStore {
     }
 
     fn is_property_interesting(idx: Np) -> bool {
-        return (idx == Np::Index(NpXmpRatingProp))
+        (idx == Np::Index(NpXmpRatingProp))
             || (idx == Np::Index(NpXmpLabelProp))
             || (idx == Np::Index(NpTiffOrientationProp))
-            || (idx == Np::Index(NpNiepceFlagProp));
+            || (idx == Np::Index(NpNiepceFlagProp))
     }
 
     fn get_iter_from_id(&self, id: LibraryId) -> Option<&gtk::TreeIter> {
@@ -117,9 +119,9 @@ impl ImageListStore {
     }
 
     fn add_libfile(&mut self, f: &LibFile) {
-        let icon = self.get_loading_icon().map(|v| v.clone());
+        let icon = self.get_loading_icon().cloned();
         let iter = self.add_row(
-            icon.clone().as_ref(),
+            icon.as_ref(),
             f,
             gdk_utils::gdkpixbuf_scale_to_fit(icon.as_ref(), 100).as_ref(),
             FileStatus::Ok,
@@ -127,7 +129,7 @@ impl ImageListStore {
         self.idmap.insert(f.id(), iter);
     }
 
-    fn add_libfiles(&mut self, content: &Vec<LibFile>) {
+    fn add_libfiles(&mut self, content: &[LibFile]) {
         for f in content.iter() {
             self.add_libfile(f);
         }
@@ -299,11 +301,13 @@ impl ImageListStore {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_new() -> *mut ImageListStore {
+pub extern "C" fn npc_image_list_store_new() -> *mut ImageListStore {
     let box_ = Box::new(ImageListStore::new());
     Box::into_raw(box_)
 }
 
+/// # Safety
+/// Dereference pointer.
 #[no_mangle]
 pub unsafe extern "C" fn npc_image_list_store_delete(self_: *mut ImageListStore) {
     assert!(!self_.is_null());
@@ -312,13 +316,14 @@ pub unsafe extern "C" fn npc_image_list_store_delete(self_: *mut ImageListStore)
 
 /// Return the gobj for the GtkListStore. You must ref it to hold it.
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_gobj(
-    self_: &ImageListStore,
-) -> *mut gtk_sys::GtkListStore {
+pub extern "C" fn npc_image_list_store_gobj(self_: &ImageListStore) -> *mut gtk_sys::GtkListStore {
     self_.store.to_glib_none().0
 }
 
 /// Return the ID of the file at the given GtkTreePath
+///
+/// # Safety
+/// Use glib pointers.
 #[no_mangle]
 pub unsafe extern "C" fn npc_image_list_store_get_file_id_at_path(
     self_: &ImageListStore,
@@ -328,6 +333,8 @@ pub unsafe extern "C" fn npc_image_list_store_get_file_id_at_path(
     self_.get_file_id_at_path(&from_glib_borrow(path))
 }
 
+/// # Safety
+/// Dereference pointers.
 #[no_mangle]
 pub unsafe extern "C" fn npc_image_list_store_add_row(
     self_: &mut ImageListStore,
@@ -345,7 +352,7 @@ pub unsafe extern "C" fn npc_image_list_store_add_row(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_get_iter_from_id(
+pub extern "C" fn npc_image_list_store_get_iter_from_id(
     self_: &mut ImageListStore,
     id: LibraryId,
 ) -> *const gtk_sys::GtkTreeIter {
@@ -353,7 +360,7 @@ pub unsafe extern "C" fn npc_image_list_store_get_iter_from_id(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_get_file(
+pub extern "C" fn npc_image_list_store_get_file(
     self_: &mut ImageListStore,
     id: LibraryId,
 ) -> *mut LibFile {
@@ -365,7 +372,7 @@ pub unsafe extern "C" fn npc_image_list_store_get_file(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_on_lib_notification(
+pub extern "C" fn npc_image_list_store_on_lib_notification(
     self_: &mut ImageListStore,
     notification: &LibNotification,
     thumbnail_cache: &ThumbnailCache,
@@ -374,6 +381,6 @@ pub unsafe extern "C" fn npc_image_list_store_on_lib_notification(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn npc_image_list_store_clear_content(self_: &mut ImageListStore) {
+pub extern "C" fn npc_image_list_store_clear_content(self_: &mut ImageListStore) {
     self_.clear_content()
 }
diff --git a/niepce-main/src/niepce/ui/imagetoolbar.rs b/niepce-main/src/niepce/ui/imagetoolbar.rs
index 5b2caae..7bc7669 100644
--- a/niepce-main/src/niepce/ui/imagetoolbar.rs
+++ b/niepce-main/src/niepce/ui/imagetoolbar.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/imagetoolbar.rs
  *
- * Copyright (C) 2018 Hubert Figuiere
+ * Copyright (C) 2018-2021 Hubert Figuiere
  *
  * 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
@@ -18,9 +18,7 @@
  */
 
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
-use gtk_sys;
 
 #[no_mangle]
 pub extern "C" fn image_toolbar_new() -> *mut gtk_sys::GtkToolbar {
diff --git a/niepce-main/src/niepce/ui/library_cell_renderer.rs 
b/niepce-main/src/niepce/ui/library_cell_renderer.rs
index 74c4cd9..627262b 100644
--- a/niepce-main/src/niepce/ui/library_cell_renderer.rs
+++ b/niepce-main/src/niepce/ui/library_cell_renderer.rs
@@ -22,14 +22,11 @@ use once_cell::unsync::Lazy;
 use std::cell::{Cell, RefCell};
 use std::ptr;
 
-use cairo;
-use gdk;
 use gdk::prelude::*;
 use gdk_pixbuf::Pixbuf;
 use glib::subclass::prelude::*;
 use glib::subclass::Signal;
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
 use gtk::subclass::prelude::*;
 
@@ -440,7 +437,7 @@ impl CellRendererImpl for LibraryCellRendererPriv {
         let xpad = self_.xpad();
         let ypad = self_.ypad();
 
-        let mut r = cell_area.clone();
+        let mut r = *cell_area;
         r.x += xpad as i32;
         r.y += ypad as i32;
 
@@ -552,7 +549,7 @@ impl CellRendererImpl for LibraryCellRendererPriv {
             // hit test with the rating region
             let xpad = instance.xpad();
             let ypad = instance.ypad();
-            let mut r = cell_area.clone();
+            let mut r = *cell_area;
             r.x += xpad as i32;
             r.y += ypad as i32;
 
@@ -608,6 +605,8 @@ impl CellRendererImpl for LibraryCellRendererPriv {
 // allow subclassing this
 pub trait LibraryCellRendererImpl: CellRendererPixbufImpl + 'static {}
 
+/// # Safety
+/// Use raw pointers
 #[no_mangle]
 pub unsafe extern "C" fn npc_library_cell_renderer_new(
     get_colour: Option<unsafe extern "C" fn(i32, *mut RgbColour, *const c_void) -> bool>,
diff --git a/niepce-main/src/niepce/ui/thumb_nav.rs b/niepce-main/src/niepce/ui/thumb_nav.rs
index e467874..ad1ccb3 100644
--- a/niepce-main/src/niepce/ui/thumb_nav.rs
+++ b/niepce-main/src/niepce/ui/thumb_nav.rs
@@ -24,7 +24,6 @@ use once_cell::unsync::OnceCell;
 
 use glib::subclass::prelude::*;
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
 use gtk::subclass::prelude::*;
 
@@ -42,9 +41,9 @@ pub enum ThumbNavMode {
     Invalid,
 }
 
-impl Into<i32> for ThumbNavMode {
-    fn into(self) -> i32 {
-        match self {
+impl From<ThumbNavMode> for i32 {
+    fn from(v: ThumbNavMode) -> i32 {
+        match v {
             ThumbNavMode::OneRow => 0,
             ThumbNavMode::OneColumn => 1,
             ThumbNavMode::MultipleRows => 2,
@@ -447,6 +446,8 @@ impl ContainerImpl for ThumbNavPriv {}
 
 impl BoxImpl for ThumbNavPriv {}
 
+/// # Safety
+/// Use raw pointers
 #[no_mangle]
 pub unsafe extern "C" fn npc_thumb_nav_new(
     thumbview: *mut gtk_sys::GtkIconView,
diff --git a/niepce-main/src/niepce/ui/thumb_strip_view.rs b/niepce-main/src/niepce/ui/thumb_strip_view.rs
index c6c5546..be8557e 100644
--- a/niepce-main/src/niepce/ui/thumb_strip_view.rs
+++ b/niepce-main/src/niepce/ui/thumb_strip_view.rs
@@ -24,7 +24,6 @@ use once_cell::unsync::OnceCell;
 
 use glib::subclass::prelude::*;
 use glib::translate::*;
-use gtk;
 use gtk::prelude::*;
 use gtk::subclass::prelude::*;
 
@@ -280,6 +279,8 @@ impl ContainerImpl for ThumbStripViewPriv {}
 
 impl IconViewImpl for ThumbStripViewPriv {}
 
+/// # Safety
+/// Use raw pointers
 #[no_mangle]
 pub unsafe extern "C" fn npc_thumb_strip_view_new(
     store: *mut gtk_sys::GtkTreeModel,


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