adding validation for files to make sure the underlying filesystem
hasn't deleted or moved files in the database
This commit is contained in:
parent
0d3e057734
commit
3b35424a0c
2 changed files with 52 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue