diff --git a/src/filewidgets/kurlnavigator.h b/src/filewidgets/kurlnavigator.h --- a/src/filewidgets/kurlnavigator.h +++ b/src/filewidgets/kurlnavigator.h @@ -289,6 +289,13 @@ */ QWidget *dropWidget() const; + /** + * @return Returns true if the given path is within an archive like a TAR + * or ZIP file. + * @since 5.54 + */ + bool isInsideCompressedPath(const QUrl &path) const; + #if !defined(KIOFILEWIDGETS_NO_DEPRECATED) && !defined(DOXYGEN_SHOULD_SKIP_THIS) /** * @return The current URL of the location. diff --git a/src/filewidgets/kurlnavigator.cpp b/src/filewidgets/kurlnavigator.cpp --- a/src/filewidgets/kurlnavigator.cpp +++ b/src/filewidgets/kurlnavigator.cpp @@ -1041,20 +1041,7 @@ // The URL represents a tar- or zip-file. Check whether // the URL is really part of the tar- or zip-file, otherwise // replace it by the local path again. - bool insideCompressedPath = d->isCompressedPath(url); - if (!insideCompressedPath) { - QUrl prevUrl = url; - QUrl parentUrl = KIO::upUrl(url); - while (parentUrl != prevUrl) { - if (d->isCompressedPath(parentUrl)) { - insideCompressedPath = true; - break; - } - prevUrl = parentUrl; - parentUrl = KIO::upUrl(parentUrl); - } - } - if (!insideCompressedPath) { + if (!isInsideCompressedPath(url)) { // drop the tar: or zip: protocol since we are not // inside the compressed path url.setScheme(QStringLiteral("file")); @@ -1257,6 +1244,24 @@ return d->m_dropWidget; } +bool KUrlNavigator::isInsideCompressedPath(const QUrl& path) const +{ + bool insideCompressedPath = d->isCompressedPath(path); + if (!insideCompressedPath) { + QUrl prevUrl = path; + QUrl parentUrl = KIO::upUrl(path); + while (parentUrl != prevUrl) { + if (d->isCompressedPath(parentUrl)) { + insideCompressedPath = true; + break; + } + prevUrl = parentUrl; + parentUrl = KIO::upUrl(parentUrl); + } + } + return insideCompressedPath; +} + #ifndef KIOFILEWIDGETS_NO_DEPRECATED const QUrl &KUrlNavigator::url() const { diff --git a/src/filewidgets/kurlnavigatorbutton.cpp b/src/filewidgets/kurlnavigatorbutton.cpp --- a/src/filewidgets/kurlnavigatorbutton.cpp +++ b/src/filewidgets/kurlnavigatorbutton.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -407,7 +408,20 @@ return; } - const QUrl url = m_replaceButton ? KIO::upUrl(m_url) : m_url; + QUrl url = m_url; + if (m_replaceButton) { + url = KIO::upUrl(m_url); + } else { + auto kurlnavigator = qobject_cast(parent()); + if (kurlnavigator->isInsideCompressedPath(kurlnavigator->locationUrl())) { + // We are in an archive, check whether the subdir we have to list is part of the archive + // or is a parent directory. + QDir testDir(url.path()); + if (testDir.exists()) { + url.setScheme(QStringLiteral("file")); + } + } + } m_subDirsJob = KIO::listDir(url, KIO::HideProgressInfo, false /*no hidden files*/); m_subDirs.clear(); // just to be ++safe