From 1342f81cab4cd8010ccdbce18d555592b8bc8979 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 24 Jul 2023 15:46:39 +0800 Subject: [PATCH] Add config option to stop synchronising existing folders when they grow beyond size Signed-off-by: Claudio Cambra --- src/gui/folder.cpp | 35 ++++++++++++++++++++++++----------- src/libsync/configfile.cpp | 13 +++++++++++++ src/libsync/configfile.h | 2 ++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index f8a60416f..5b5563d57 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -1257,6 +1257,7 @@ void Folder::slotExistingFolderNowBig(const QString &folderPath) { const auto trailSlashFolderPath = Utility::trailingSlashPath(folderPath); const auto journal = journalDb(); + const auto stopSyncing = ConfigFile().stopSyncingExistingFoldersOverLimit(); // Add the entry to the whitelist if it is neither in the blacklist or whitelist already bool ok1 = false; @@ -1264,8 +1265,13 @@ void Folder::slotExistingFolderNowBig(const QString &folderPath) auto blacklist = journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok1); auto whitelist = journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, &ok2); if (ok1 && ok2 && !blacklist.contains(trailSlashFolderPath) && !whitelist.contains(trailSlashFolderPath)) { - whitelist.append(trailSlashFolderPath); - journal->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, whitelist); + if (stopSyncing) { + blacklist.append(trailSlashFolderPath); + journal->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blacklist); + } else { + whitelist.append(trailSlashFolderPath); + journal->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, whitelist); + } } auto undecidedListQueryOk = false; @@ -1277,21 +1283,28 @@ void Folder::slotExistingFolderNowBig(const QString &folderPath) emit newBigFolderDiscovered(trailSlashFolderPath); } - const auto message = tr("A folder has surpassed the set folder size limit of %1MB: %2.\n" - "Please go into the settings and disable it if you wish to stop synchronising it.") - .arg(QString::number(ConfigFile().newBigFolderSizeLimit().second), folderPath); + const auto messageInstruction = + stopSyncing ? "Synchronisation of this folder has been disabled." : "Synchronisation of this folder can be disabled in the settings window."; + const auto message = tr("A folder has surpassed the set folder size limit of %1MB: %2.\n%3") + .arg(QString::number(ConfigFile().newBigFolderSizeLimit().second), folderPath, messageInstruction); Logger::instance()->postGuiLog(Theme::instance()->appNameGUI(), message); - auto blacklistActivityLink = ActivityLink(); - blacklistActivityLink._label = tr("Stop syncing"); - blacklistActivityLink._primary = true; - blacklistActivityLink._verb = "BLACKLIST_FOLDER"; - auto whitelistActivityLink = ActivityLink(); whitelistActivityLink._label = tr("Keep syncing"); whitelistActivityLink._primary = false; whitelistActivityLink._verb = "WHITELIST_FOLDER"; + QVector activityLinks = {whitelistActivityLink}; + + if (!stopSyncing) { + auto blacklistActivityLink = ActivityLink(); + blacklistActivityLink._label = tr("Stop syncing"); + blacklistActivityLink._primary = true; + blacklistActivityLink._verb = "BLACKLIST_FOLDER"; + + activityLinks.append(blacklistActivityLink); + } + auto existingFolderNowBigActivity = Activity(); existingFolderNowBigActivity._type = Activity::NotificationType; existingFolderNowBigActivity._dateTime = QDateTime::fromString(QDateTime::currentDateTime().toString(), Qt::ISODate); @@ -1301,7 +1314,7 @@ void Folder::slotExistingFolderNowBig(const QString &folderPath) existingFolderNowBigActivity._accName = _accountState->account()->displayName(); existingFolderNowBigActivity._folder = alias(); existingFolderNowBigActivity._file = cleanPath() + '/' + trailSlashFolderPath; - existingFolderNowBigActivity._links = {blacklistActivityLink, whitelistActivityLink}; + existingFolderNowBigActivity._links = activityLinks; existingFolderNowBigActivity._id = qHash(existingFolderNowBigActivity._file); const auto user = UserModel::instance()->findUserForAccount(_accountState.data()); diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 5bbcc817d..5931929d5 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -100,6 +100,7 @@ static constexpr char downloadLimitC[] = "BWLimit/downloadLimit"; static constexpr char newBigFolderSizeLimitC[] = "newBigFolderSizeLimit"; static constexpr char useNewBigFolderSizeLimitC[] = "useNewBigFolderSizeLimit"; static constexpr char notifyExistingFoldersOverLimitC[] = "notifyExistingFoldersOverLimit"; +static constexpr char stopSyncingExistingFoldersOverLimitC[] = "stopSyncingExistingFoldersOverLimit"; static constexpr char confirmExternalStorageC[] = "confirmExternalStorage"; static constexpr char moveToTrashC[] = "moveToTrash"; @@ -968,6 +969,18 @@ void ConfigFile::setNotifyExistingFoldersOverLimit(const bool notify) setValue(notifyExistingFoldersOverLimitC, notify); } +bool ConfigFile::stopSyncingExistingFoldersOverLimit() const +{ + const auto notifyExistingBigEnabled = notifyExistingFoldersOverLimit(); + const auto fallback = getValue(stopSyncingExistingFoldersOverLimitC, {}, notifyExistingBigEnabled); + return getPolicySetting(QString(stopSyncingExistingFoldersOverLimitC), fallback).toBool(); +} + +void ConfigFile::setStopSyncingExistingFoldersOverLimit(const bool stopSyncing) +{ + setValue(stopSyncingExistingFoldersOverLimitC, stopSyncing); +} + void ConfigFile::setConfirmExternalStorage(bool isChecked) { setValue(confirmExternalStorageC, isChecked); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index a947fec2b..6906c21b7 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -143,6 +143,8 @@ public: void setNewBigFolderSizeLimit(bool isChecked, qint64 mbytes); [[nodiscard]] bool notifyExistingFoldersOverLimit() const; void setNotifyExistingFoldersOverLimit(const bool notify); + [[nodiscard]] bool stopSyncingExistingFoldersOverLimit() const; + void setStopSyncingExistingFoldersOverLimit(const bool stopSyncing); [[nodiscard]] bool useNewBigFolderSizeLimit() const; [[nodiscard]] bool confirmExternalStorage() const; void setConfirmExternalStorage(bool); -- 2.30.2