diff --git a/krusader/FileSystem/defaultfilesystem.h b/krusader/FileSystem/defaultfilesystem.h --- a/krusader/FileSystem/defaultfilesystem.h +++ b/krusader/FileSystem/defaultfilesystem.h @@ -67,6 +67,14 @@ protected: bool refreshInternal(const QUrl &origin, bool onlyScan) override; + /** + * Get the file list from the .hidden file. + * + * @param dir the directory containing the .hidden file + * @return a list containing all files that must be hidden or an empty set + * if the file cannot be read. + */ + QSet filesInDotHidden(const QString &dir); protected slots: /// Handle result after dir listing job is finished diff --git a/krusader/FileSystem/defaultfilesystem.cpp b/krusader/FileSystem/defaultfilesystem.cpp --- a/krusader/FileSystem/defaultfilesystem.cpp +++ b/krusader/FileSystem/defaultfilesystem.cpp @@ -362,11 +362,14 @@ QT_DIRENT* dirEnt; QString name; const bool showHidden = showHiddenFiles(); + QSet hiddenFiles = filesInDotHidden(path); while ((dirEnt = QT_READDIR(dir)) != nullptr) { name = QString::fromLocal8Bit(dirEnt->d_name); // show hidden files? if (!showHidden && name.left(1) == ".") continue; + // show file in .hidden file? + if (!showHidden && hiddenFiles.contains(name)) continue; // we don't need the "." and ".." entries if (name == "." || name == "..") continue; @@ -393,6 +396,29 @@ return true; } +QSet DefaultFileSystem::filesInDotHidden(const QString &dir) +{ + // code "borrowed" from KIO, Copyright (C) by Bruno Nova + const QString path = dir + QLatin1String("/.hidden"); + QFile dotHiddenFile(path); + + if (dotHiddenFile.exists()) { + if (dotHiddenFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QSet filesToHide; + QTextStream stream(&dotHiddenFile); + while (!stream.atEnd()) { + QString name = stream.readLine(); + if (!name.isEmpty()) { + filesToHide.insert(name); + } + } + return filesToHide; + } + } + + return QSet(); +} + FileItem *DefaultFileSystem::createLocalFileItem(const QString &name) { return FileSystem::createLocalFileItem(name, _currentDirectory.path());