Utils: Fake root info

When trying to open a FileDialog all roots were tested for existence.
This is slow and might show ask-pass.

Since "/" can be considered always valid, we create a fake entry for it
and only test existence of remote paths if they are not a root path.

In the future FilePath should get a "isRoot()" function so we don't just
test for == "/".

Remove the fileAccess from WebAssembly devices.

Change-Id: I7a1a6e7d2025e9fd4428e4bd1d07cdbdb5680c8e
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-01-19 08:05:43 +01:00
parent d36ecb23df
commit 598ffc3b1c
4 changed files with 26 additions and 5 deletions

View File

@@ -415,26 +415,30 @@ FilePath qUrlToFilePath(const QUrl &url)
QUrl filePathToQUrl(const FilePath &filePath)
{
return QUrl::fromLocalFile(filePath.toFSPathString());
return QUrl::fromLocalFile(filePath.toFSPathString());
}
void prepareNonNativeDialog(QFileDialog &dialog)
{
const auto isValidSideBarPath = [](const FilePath &fp) {
return !fp.needsDevice() || fp.hasFileAccess();
};
// Checking QFileDialog::itemDelegate() seems to be the only way to determine
// whether the dialog is native or not.
if (dialog.itemDelegate()) {
FilePaths sideBarPaths;
// Check existing urls, remove paths that need a device and no longer exist.
// Check existing urls, remove paths that need a device and are no longer valid.
for (const QUrl &url : dialog.sidebarUrls()) {
FilePath path = qUrlToFilePath(url);
if (!path.needsDevice() || path.exists())
if (isValidSideBarPath(path))
sideBarPaths.append(path);
}
// Add all device roots that are not already in the sidebar and exist.
// Add all device roots that are not already in the sidebar and valid.
for (const FilePath &path : FSEngine::registeredDeviceRoots()) {
if (!sideBarPaths.contains(path) && path.exists())
if (!sideBarPaths.contains(path) && isValidSideBarPath(path))
sideBarPaths.append(path);
}