From 6522245493e0b3757a8b4009fbb36a2dc5d89278 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 3 Aug 2023 15:34:39 +0800 Subject: [PATCH] Deduplicate whitelistFolderPath and blacklistFolderPath Signed-off-by: Claudio Cambra --- src/gui/folderman.cpp | 29 +++++++++++++++++++---------- src/gui/folderman.h | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index efbf46d906f51..cb757a2d6379f 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1259,7 +1259,7 @@ Folder *FolderMan::folderForPath(const QString &path) return it != folders.cend() ? *it : nullptr; } -void FolderMan::whitelistFolderPath(const QString &path) +void FolderMan::addFolderToSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType list) { const auto folder = folderForPath(path); if (!folder) { @@ -1268,19 +1268,28 @@ void FolderMan::whitelistFolderPath(const QString &path) const QString folderPath = folder->cleanPath() + QLatin1Char('/'); const auto relPath = path.mid(folderPath.length()); - folder->whitelistPath(relPath); + + switch (list) { + case SyncJournalDb::SelectiveSyncListType::SelectiveSyncWhiteList: + folder->whitelistPath(relPath); + break; + case SyncJournalDb::SelectiveSyncListType::SelectiveSyncBlackList: + folder->blacklistPath(relPath); + break; + default: + Q_UNREACHABLE(); + } } -void FolderMan::blacklistFolderPath(const QString &path) +void FolderMan::whitelistFolderPath(const QString &path) { - const auto folder = folderForPath(path); - if (!folder) { - return; - } + addFolderToSelectiveSyncList(path, SyncJournalDb::SelectiveSyncListType::SelectiveSyncWhiteList); +} - const QString folderPath = folder->cleanPath() + QLatin1Char('/'); - const auto relPath = path.mid(folderPath.length()); - folder->blacklistPath(relPath); +void FolderMan::blacklistFolderPath(const QString &path) +{ + addFolderToSelectiveSyncList(path, SyncJournalDb::SelectiveSyncListType::SelectiveSyncBlackList); +} } QStringList FolderMan::findFileInLocalFolders(const QString &relPath, const AccountPtr acc) diff --git a/src/gui/folderman.h b/src/gui/folderman.h index a79f1119355c2..684ba29829e41 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -358,6 +358,8 @@ private slots: [[nodiscard]] bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const; + void addFolderToSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType list); + QSet _disabledFolders; Folder::Map _folderMap; QString _folderConfigPath;