adding validation for files to make sure the underlying filesystem

hasn't deleted or moved files in the database
This commit is contained in:
Chris Cochrun 2023-02-17 13:12:23 -06:00
parent 0d3e057734
commit 3b35424a0c
2 changed files with 52 additions and 8 deletions

View file

@ -485,16 +485,25 @@ Item {
Item{ Item{
implicitWidth: ListView.view.width implicitWidth: ListView.view.width
height: selectedLibrary == "videos" ? 50 : 0 height: selectedLibrary == "videos" ? 50 : 0
Kirigami.BasicListItem { Kirigami.BasicListItem {
id: videoListItem id: videoListItem
property bool rightMenu: false property bool rightMenu: false
property bool fileValidation: fileHelper.validate(filePath)
implicitWidth: videoLibraryList.width implicitWidth: videoLibraryList.width
height: selectedLibrary == "videos" ? 50 : 0 height: selectedLibrary == "videos" ? 50 : 0
clip: true clip: true
label: title label: title
/* subtitle: author */ icon: "folder-videos-symbolic"
iconSize: Kirigami.Units.gridUnit
subtitle: {
if (fileValidation)
filePath;
else
"file is missing"
}
supportsMouseEvents: false supportsMouseEvents: false
backgroundColor: { backgroundColor: {
if (parent.ListView.isCurrentItem) { if (parent.ListView.isCurrentItem) {
@ -506,10 +515,14 @@ Item {
} }
} }
textColor: { textColor: {
if (parent.ListView.isCurrentItem || videoDragHandler.containsMouse) if (fileValidation) {
activeTextColor; if (parent.ListView.isCurrentItem || videoDragHandler.containsMouse)
activeTextColor;
else
Kirigami.Theme.textColor;
}
else else
Kirigami.Theme.textColor; "red"
} }
Behavior on height { Behavior on height {
@ -772,12 +785,20 @@ Item {
id: imageListItem id: imageListItem
property bool rightMenu: false property bool rightMenu: false
property bool fileValidation: fileHelper.validate(filePath)
implicitWidth: imageLibraryList.width implicitWidth: imageLibraryList.width
height: selectedLibrary == "images" ? 50 : 0 height: selectedLibrary == "images" ? 50 : 0
clip: true clip: true
label: title label: title
/* subtitle: author */ icon: "folder-pictures-symbolic"
iconSize: Kirigami.Units.gridUnit
subtitle: {
if (fileValidation)
filePath;
else
"file is missing"
}
supportsMouseEvents: false supportsMouseEvents: false
backgroundColor: { backgroundColor: {
if (parent.ListView.isCurrentItem) { if (parent.ListView.isCurrentItem) {
@ -789,10 +810,14 @@ Item {
} }
} }
textColor: { textColor: {
if (parent.ListView.isCurrentItem || imageDragHandler.containsMouse) if (fileValidation) {
activeTextColor; if (parent.ListView.isCurrentItem || imageDragHandler.containsMouse)
activeTextColor;
else
Kirigami.Theme.textColor;
}
else else
Kirigami.Theme.textColor; "red"
} }
Behavior on height { Behavior on height {

View file

@ -1,6 +1,7 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod file_helper { mod file_helper {
use cxx_qt_lib::QVariantValue; use cxx_qt_lib::QVariantValue;
use std::path::Path;
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
@ -47,5 +48,23 @@ mod file_helper {
println!("{}", file); println!("{}", file);
return vec!["hi".to_string()]; 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
}
}
}
} }
} }