mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 18:27:23 +02:00
Merge pull request #2625 from alicevision/fix/validateSavePermissions
[ui] Add Validation for Save file path accessibility
This commit is contained in:
commit
faff99f963
2 changed files with 50 additions and 9 deletions
|
@ -57,6 +57,13 @@ class FilepathHelper(QObject):
|
||||||
""" Returns the pathname without its extension (.ext)"""
|
""" Returns the pathname without its extension (.ext)"""
|
||||||
return os.path.splitext(self.asStr(path))[0]
|
return os.path.splitext(self.asStr(path))[0]
|
||||||
|
|
||||||
|
@Slot(str, result=bool)
|
||||||
|
@Slot(QUrl, result=bool)
|
||||||
|
def accessible(self, path):
|
||||||
|
""" Returns whether a path is accessible for the user """
|
||||||
|
path = self.asStr(path)
|
||||||
|
return os.path.isdir(self.asStr(path)) and os.access(path, os.R_OK) and os.access(path, os.W_OK)
|
||||||
|
|
||||||
@Slot(str, result=bool)
|
@Slot(str, result=bool)
|
||||||
@Slot(QUrl, result=bool)
|
@Slot(QUrl, result=bool)
|
||||||
def isFile(self, path):
|
def isFile(self, path):
|
||||||
|
|
|
@ -62,6 +62,24 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: permissionsDialog
|
||||||
|
|
||||||
|
MessageDialog {
|
||||||
|
title: "Permission Denied"
|
||||||
|
|
||||||
|
required property string filepath
|
||||||
|
|
||||||
|
preset: "Warning"
|
||||||
|
text: "The location does not exist or you do not have necessary permissions to save to the provided filepath."
|
||||||
|
detailedText: "Filepath: " + filepath
|
||||||
|
helperText: "Please check the location or permissions and try again or choose a different location."
|
||||||
|
|
||||||
|
standardButtons: Dialog.Ok
|
||||||
|
onClosed: destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function validateFilepathForSave(filepath: string, sourceSaveDialog: Dialog): bool {
|
function validateFilepathForSave(filepath: string, sourceSaveDialog: Dialog): bool {
|
||||||
/**
|
/**
|
||||||
* Return true if `filepath` is valid for saving a file to disk.
|
* Return true if `filepath` is valid for saving a file to disk.
|
||||||
|
@ -70,11 +88,8 @@ Page {
|
||||||
*/
|
*/
|
||||||
const emptyFilename = Filepath.basename(filepath).trim() === ".mg";
|
const emptyFilename = Filepath.basename(filepath).trim() === ".mg";
|
||||||
|
|
||||||
// Provided filename is valid
|
// Provided filename is not valid
|
||||||
if (!emptyFilename) {
|
if (emptyFilename) {
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instantiate the Warning Dialog with the provided filepath
|
// Instantiate the Warning Dialog with the provided filepath
|
||||||
const warningDialog = invalidFilepathDialog.createObject(root, {"filepath": Filepath.urlToString(filepath)});
|
const warningDialog = invalidFilepathDialog.createObject(root, {"filepath": Filepath.urlToString(filepath)});
|
||||||
|
|
||||||
|
@ -82,7 +97,26 @@ Page {
|
||||||
warningDialog.closed.connect(sourceSaveDialog.open);
|
warningDialog.closed.connect(sourceSaveDialog.open);
|
||||||
warningDialog.open();
|
warningDialog.open();
|
||||||
|
|
||||||
return false
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the user has access to the directory where the file is to be saved
|
||||||
|
const hasPermission = Filepath.accessible(Filepath.dirname(filepath));
|
||||||
|
|
||||||
|
// Either the directory does not exist or is inaccessible for the user
|
||||||
|
if (!hasPermission) {
|
||||||
|
// Intantiate the permissions dialog with the provided filepath
|
||||||
|
const warningDialog = permissionsDialog.createObject(root, {"filepath": Filepath.urlToString(filepath)});
|
||||||
|
|
||||||
|
// Connect and show the dialog
|
||||||
|
warningDialog.closed.connect(sourceSaveDialog.open);
|
||||||
|
warningDialog.open();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything is valid
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// File dialogs
|
// File dialogs
|
||||||
|
|
Loading…
Add table
Reference in a new issue