From 3b35424a0c42cdb694e7836b6fda4c5873746557 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 17 Feb 2023 13:12:23 -0600 Subject: [PATCH] adding validation for files to make sure the underlying filesystem hasn't deleted or moved files in the database --- src/qml/presenter/Library.qml | 41 ++++++++++++++++++++++++++++------- src/rust/file_helper.rs | 19 ++++++++++++++++ 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index 51c9577..96c5653 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -485,16 +485,25 @@ Item { Item{ implicitWidth: ListView.view.width height: selectedLibrary == "videos" ? 50 : 0 + Kirigami.BasicListItem { id: videoListItem property bool rightMenu: false + property bool fileValidation: fileHelper.validate(filePath) implicitWidth: videoLibraryList.width height: selectedLibrary == "videos" ? 50 : 0 clip: true label: title - /* subtitle: author */ + icon: "folder-videos-symbolic" + iconSize: Kirigami.Units.gridUnit + subtitle: { + if (fileValidation) + filePath; + else + "file is missing" + } supportsMouseEvents: false backgroundColor: { if (parent.ListView.isCurrentItem) { @@ -506,10 +515,14 @@ Item { } } textColor: { - if (parent.ListView.isCurrentItem || videoDragHandler.containsMouse) - activeTextColor; + if (fileValidation) { + if (parent.ListView.isCurrentItem || videoDragHandler.containsMouse) + activeTextColor; + else + Kirigami.Theme.textColor; + } else - Kirigami.Theme.textColor; + "red" } Behavior on height { @@ -772,12 +785,20 @@ Item { id: imageListItem property bool rightMenu: false + property bool fileValidation: fileHelper.validate(filePath) implicitWidth: imageLibraryList.width height: selectedLibrary == "images" ? 50 : 0 clip: true label: title - /* subtitle: author */ + icon: "folder-pictures-symbolic" + iconSize: Kirigami.Units.gridUnit + subtitle: { + if (fileValidation) + filePath; + else + "file is missing" + } supportsMouseEvents: false backgroundColor: { if (parent.ListView.isCurrentItem) { @@ -789,10 +810,14 @@ Item { } } textColor: { - if (parent.ListView.isCurrentItem || imageDragHandler.containsMouse) - activeTextColor; + if (fileValidation) { + if (parent.ListView.isCurrentItem || imageDragHandler.containsMouse) + activeTextColor; + else + Kirigami.Theme.textColor; + } else - Kirigami.Theme.textColor; + "red" } Behavior on height { diff --git a/src/rust/file_helper.rs b/src/rust/file_helper.rs index 6538ebf..c46dcd2 100644 --- a/src/rust/file_helper.rs +++ b/src/rust/file_helper.rs @@ -1,6 +1,7 @@ #[cxx_qt::bridge] mod file_helper { use cxx_qt_lib::QVariantValue; + use std::path::Path; unsafe extern "C++" { include!("cxx-qt-lib/qstring.h"); @@ -47,5 +48,23 @@ mod file_helper { println!("{}", file); return vec!["hi".to_string()]; } + + #[qinvokable] + pub fn validate(self: Pin<&mut Self>, file: QUrl) -> bool { + let file_string = file.to_string(); + let _file_string = file_string.strip_prefix("file://"); + match _file_string { + None => { + let _exists = Path::new(&file.to_string()).exists(); + println!("{} does not exist", file.to_string()); + _exists + } + Some(file) => { + let _exists = Path::new(&file).exists(); + println!("{} exists? {_exists}", file); + _exists + } + } + } } }