Add config option to stop synchronising existing folders when they grow beyond size
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 24 Jul 2023 07:46:39 +0000 (15:46 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 4 Aug 2023 09:44:15 +0000 (17:44 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folder.cpp
src/libsync/configfile.cpp
src/libsync/configfile.h

index f8a60416f1bcda461b86b3734fcbb1ca0b7753fc..5b5563d5794b8bb6bc7d15635772155a756c5978 100644 (file)
@@ -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<ActivityLink> 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());
index 5bbcc817d345126e0980ce32bda9e820824f6b45..5931929d559d508721f695eae4d3fdda200096ea 100644 (file)
@@ -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);
index a947fec2bd6e71985fa532d3e9d77ab77d7906d0..6906c21b7600a97d33cb1e390e986a65ffb37758 100644 (file)
@@ -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);