feat: load gallery for wsl$ location

This commit is contained in:
Gary Wang 2020-08-31 20:02:49 +08:00
parent 7245a4e212
commit e2fb1813f1
2 changed files with 14 additions and 7 deletions

View File

@ -35,10 +35,6 @@ void GraphicsView::showFileFromUrl(const QUrl &url, bool doRequestGallery)
// TODO: remove this workaround when M$ change the "wsl$" hostname.
if (Q_UNLIKELY(url.scheme() == QStringLiteral("qtbug-86277"))) {
filePath = url.path();
// Qt's QUrl won't work with such hostname anyway so the urls will
// still be the wrong one when requesting gallery. So we just don't
// request gallery here...
doRequestGallery = false;
}
#endif // Q_OS_WIN

View File

@ -238,9 +238,20 @@ void MainWindow::loadGalleryBySingleLocalFile(const QString &path)
clearGallery();
for (int i = 0; i < entryList.count(); i++) {
const QString & oneEntry = entryList.at(i);
m_files.append(QUrl::fromLocalFile(dir.absoluteFilePath(oneEntry)));
if (oneEntry == currentFileName) {
const QString & fileName = entryList.at(i);
const QString & oneEntry = dir.absoluteFilePath(fileName);
QUrl url = QUrl::fromLocalFile(oneEntry);
#ifdef Q_OS_WIN
// TODO: remove this workaround when M$ change the "wsl$" hostname.
// Qt will convert path "\\wsl$\" to "//wsl$/"...
if (Q_UNLIKELY(oneEntry.startsWith(R"(//wsl$/)"))) {
url.clear();
url.setScheme(QStringLiteral("qtbug-86277"));
url.setPath(oneEntry);
}
#endif // Q_OS_WIN
m_files.append(url);
if (fileName == currentFileName) {
m_currentFileIndex = i;
}
}