refactor to remove code duplication

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2025-01-16 17:04:53 +02:00
parent 9d25680587
commit 797cacf804
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
6 changed files with 33 additions and 62 deletions

View file

@ -273,3 +273,28 @@ bool FileIgnoreProxy::filterFile(const QString& fileName) const
{
return m_blocked.covers(fileName) || ignoreFile(QFileInfo(QDir(m_root), fileName));
}
void FileIgnoreProxy::loadBlockedPathsFromFile(const QString& fileName)
{
QFile ignoreFile(fileName);
if (!ignoreFile.open(QIODevice::ReadOnly)) {
return;
}
auto ignoreData = ignoreFile.readAll();
auto string = QString::fromUtf8(ignoreData);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
setBlockedPaths(string.split('\n', Qt::SkipEmptyParts));
#else
setBlockedPaths(string.split('\n', QString::SkipEmptyParts));
#endif
}
void FileIgnoreProxy::saveBlockedPathsToFile(const QString& fileName)
{
auto ignoreData = blockedPaths().toStringList().join('\n').toUtf8();
try {
FS::write(fileName, ignoreData);
} catch (const Exception& e) {
qWarning() << e.cause();
}
}