From 035442b6da374cee4995e2ce2c4e377dd3d1f427 Mon Sep 17 00:00:00 2001 From: ckamm Date: Fri, 23 Sep 2016 13:47:57 +0200 Subject: [PATCH] Improve the "new big folder" UI #5202 (#5204) Instead of using the regular selective-sync UI (where it's unclear what the "Cancel" button would even mean in this context), provide a different set of buttons that allow the user to quickly synchronize all pending big folders, none of them, or perform manual changes as usual. --- src/gui/accountsettings.cpp | 11 ++- src/gui/accountsettings.ui | 127 +++++++++++++++++++++++++--------- src/gui/folderstatusmodel.cpp | 71 +++++++++++++++++++ src/gui/folderstatusmodel.h | 2 + 4 files changed, 175 insertions(+), 36 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 69028efc3..eb458079e 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -117,6 +117,10 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) : connect(ui->selectiveSyncApply, SIGNAL(clicked()), _model, SLOT(slotApplySelectiveSync())); connect(ui->selectiveSyncCancel, SIGNAL(clicked()), _model, SLOT(resetFolders())); + connect(ui->bigFolderApply, SIGNAL(clicked(bool)), _model, SLOT(slotApplySelectiveSync())); + connect(ui->bigFolderSyncAll, SIGNAL(clicked(bool)), _model, SLOT(slotSyncAllPendingBigFolders())); + connect(ui->bigFolderSyncNone, SIGNAL(clicked(bool)), _model, SLOT(slotSyncNoPendingBigFolders())); + connect(FolderMan::instance(), SIGNAL(folderListChanged(Folder::Map)), _model, SLOT(resetFolders())); connect(this, SIGNAL(folderChanged()), _model, SLOT(resetFolders())); @@ -635,12 +639,13 @@ void AccountSettings::refreshSelectiveSyncStatus() } if (msg.isEmpty()) { - ui->selectiveSyncNotification->setVisible(false); - ui->selectiveSyncNotification->setText(QString()); + ui->selectiveSyncButtons->setVisible(true); + ui->bigFolderUi->setVisible(false); } else { - ui->selectiveSyncNotification->setVisible(true); QString wholeMsg = tr("There are new folders that were not synchronized because they are too big: ") + msg; ui->selectiveSyncNotification->setText(wholeMsg); + ui->selectiveSyncButtons->setVisible(false); + ui->bigFolderUi->setVisible(true); shouldBeVisible = true; } diff --git a/src/gui/accountsettings.ui b/src/gui/accountsettings.ui index 8cc236cef..f100d3752 100644 --- a/src/gui/accountsettings.ui +++ b/src/gui/accountsettings.ui @@ -154,44 +154,105 @@ - - - color: red - - - - - - true - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + color: red + + + + + + true + + + + + + + + + Synchronize all + + + + + + + Synchronize none + + + + + + + Apply manual changes + + + + + + - - - - 0 - 0 - - - - Cancel - - - - - - - - 0 - 0 - - - - Apply - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Cancel + + + + + + + + 0 + 0 + + + + Apply + + + + diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index a850824d7..5b6ea1b2a 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -1046,6 +1046,77 @@ void FolderStatusModel::resetFolders() setAccountState(_accountState); } +void FolderStatusModel::slotSyncAllPendingBigFolders() +{ + for (int i = 0; i < _folders.count(); ++i) { + if (!_folders[i]._fetched) { + _folders[i]._folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, QStringList()); + continue; + } + auto folder = _folders.at(i)._folder; + + bool ok; + auto undecidedList = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, &ok); + if( !ok ) { + qDebug() << Q_FUNC_INFO << "Could not read selective sync list from db."; + return; + } + + // If this folder had no undecided entries, skip it. + if (undecidedList.isEmpty()) { + continue; + } + + // Remove all undecided folders from the blacklist + auto blackList = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok); + if( !ok ) { + qDebug() << Q_FUNC_INFO << "Could not read selective sync list from db."; + return; + } + foreach (const auto& undecidedFolder, undecidedList) { + blackList.removeAll(undecidedFolder); + } + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList); + + // Add all undecided folders to the white list + auto whiteList = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, &ok); + if( !ok ) { + qDebug() << Q_FUNC_INFO << "Could not read selective sync list from db."; + return; + } + whiteList += undecidedList; + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, whiteList); + + // Clear the undecided list + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, QStringList()); + + // Trigger a sync + if (folder->isBusy()) { + folder->slotTerminateSync(); + } + // The part that changed should not be read from the DB on next sync because there might be new folders + // (the ones that are no longer in the blacklist) + foreach (const auto &it, undecidedList) { + folder->journalDb()->avoidReadFromDbOnNextSync(it); + } + FolderMan::instance()->slotScheduleSync(folder); + } + + resetFolders(); +} + +void FolderStatusModel::slotSyncNoPendingBigFolders() +{ + for (int i = 0; i < _folders.count(); ++i) { + auto folder = _folders.at(i)._folder; + + // clear the undecided list + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, QStringList()); + } + + resetFolders(); +} + void FolderStatusModel::slotNewBigFolder() { auto f = qobject_cast(sender()); diff --git a/src/gui/folderstatusmodel.h b/src/gui/folderstatusmodel.h index 312e978ae..f1813ca1c 100644 --- a/src/gui/folderstatusmodel.h +++ b/src/gui/folderstatusmodel.h @@ -107,6 +107,8 @@ public slots: void slotUpdateFolderState(Folder *); void slotApplySelectiveSync(); void resetFolders(); + void slotSyncAllPendingBigFolders(); + void slotSyncNoPendingBigFolders(); void slotSetProgress(const ProgressInfo &progress); private slots: -- 2.39.5