diff options
author | Christian Kamm <mail@ckamm.de> | 2018-09-28 12:00:53 +0300 |
---|---|---|
committer | Christian Kamm <mail@ckamm.de> | 2018-11-26 14:47:31 +0300 |
commit | 96df14f897ebf4fb1f423149cba9f2972e5f280d (patch) | |
tree | c80bab947d1a774112f256c59ac52e2c94b088f4 /src | |
parent | 12c3b9e7188f55e7e641dc2a15ca89daff46e15e (diff) |
FolderMan: Remove assumption of unique running sync
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/accountsettings.cpp | 10 | ||||
-rw-r--r-- | src/gui/folder.cpp | 5 | ||||
-rw-r--r-- | src/gui/folder.h | 3 | ||||
-rw-r--r-- | src/gui/folderman.cpp | 83 | ||||
-rw-r--r-- | src/gui/folderman.h | 20 | ||||
-rw-r--r-- | src/gui/folderstatusmodel.cpp | 6 | ||||
-rw-r--r-- | src/gui/owncloudgui.cpp | 2 |
7 files changed, 81 insertions, 48 deletions
diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 14bd7a7d1..bca23fa37 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -307,7 +307,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) if (!folderPaused) { ac = menu->addAction(tr("Force sync now")); - if (folderMan->currentSyncFolder() == folder) { + if (folder && folder->isSyncRunning()) { ac->setText(tr("Restart sync")); } ac->setEnabled(folderConnected); @@ -617,9 +617,11 @@ void AccountSettings::slotForceSyncCurrentFolder() FolderMan *folderMan = FolderMan::instance(); if (auto selectedFolder = folderMan->folder(selectedFolderAlias())) { // Terminate and reschedule any running sync - if (Folder *current = folderMan->currentSyncFolder()) { - folderMan->terminateSyncProcess(); - folderMan->scheduleFolder(current); + for (auto f : folderMan->map()) { + if (f->isSyncRunning()) { + f->slotTerminateSync(); + folderMan->scheduleFolder(f); + } } selectedFolder->slotWipeErrorBlacklist(); // issue #6757 diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index ce5e5211d..fabd99805 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -221,6 +221,11 @@ bool Folder::isBusy() const return _engine->isSyncRunning(); } +bool Folder::isSyncRunning() const +{ + return _engine->isSyncRunning(); +} + QString Folder::remotePath() const { return _definition.targetPath; diff --git a/src/gui/folder.h b/src/gui/folder.h index 674d7c8b7..34e7a8bea 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -170,6 +170,9 @@ public: */ virtual bool isBusy() const; + /** True if the folder is currently synchronizing */ + bool isSyncRunning() const; + /** * return the last sync result with error message and status */ diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 753d83156..8ad3b8066 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -512,19 +512,6 @@ void FolderMan::slotFolderCanSyncChanged() } } -// this really terminates the current sync process -// ie. no questions, no prisoners -// csync still remains in a stable state, regardless of that. -void FolderMan::terminateSyncProcess() -{ - Folder *f = _currentSyncFolder; - if (f) { - // This will, indirectly and eventually, call slotFolderSyncFinished - // and thereby clear _currentSyncFolder. - f->slotTerminateSync(); - } -} - Folder *FolderMan::folder(const QString &alias) { if (!alias.isEmpty()) { @@ -636,7 +623,7 @@ void FolderMan::slotRunOneEtagJob() //qCDebug(lcFolderMan) << "No more remote ETag check jobs to schedule."; /* now it might be a good time to check for restarting... */ - if (_currentSyncFolder == NULL && _appRestartRequired) { + if (!isAnySyncRunning() && _appRestartRequired) { restartApplication(); } } else { @@ -668,9 +655,12 @@ void FolderMan::slotAccountStateChanged() qCInfo(lcFolderMan) << "Account" << accountName << "disconnected or paused, " "terminating or descheduling sync folders"; - if (_currentSyncFolder - && _currentSyncFolder->accountState() == accountState) { - _currentSyncFolder->slotTerminateSync(); + foreach (Folder *f, _folderMap.values()) { + if (f + && f->isSyncRunning() + && f->accountState() == accountState) { + f->slotTerminateSync(); + } } QMutableListIterator<Folder *> it(_scheduledFolders); @@ -705,7 +695,7 @@ void FolderMan::startScheduledSyncSoon() if (_scheduledFolders.empty()) { return; } - if (_currentSyncFolder) { + if (isAnySyncRunning()) { return; } @@ -743,8 +733,11 @@ void FolderMan::startScheduledSyncSoon() */ void FolderMan::slotStartScheduledFolderSync() { - if (_currentSyncFolder) { - qCInfo(lcFolderMan) << "Currently folder " << _currentSyncFolder->remoteUrl().toString() << " is running, wait for finish!"; + if (isAnySyncRunning()) { + for (auto f : _folderMap) { + if (f->isSyncRunning()) + qCInfo(lcFolderMan) << "Currently folder " << f->remoteUrl().toString() << " is running, wait for finish!"; + } return; } @@ -791,7 +784,7 @@ void FolderMan::slotEtagPollTimerTimeout() if (!f) { continue; } - if (_currentSyncFolder == f) { + if (f->isSyncRunning()) { continue; } if (_scheduledFolders.contains(f)) { @@ -901,12 +894,29 @@ void FolderMan::slotScheduleFolderByTime() } } +bool FolderMan::isAnySyncRunning() const +{ + if (_currentSyncFolder) + return true; + + for (auto f : _folderMap) { + if (f->isSyncRunning()) + return true; + } + return false; +} + void FolderMan::slotFolderSyncStarted() { + auto f = qobject_cast<Folder *>(sender()); + ASSERT(f); + if (!f) + return; + qCInfo(lcFolderMan, ">========== Sync started for folder [%s] of account [%s] with remote [%s]", - qPrintable(_currentSyncFolder->shortGuiLocalPath()), - qPrintable(_currentSyncFolder->accountState()->account()->displayName()), - qPrintable(_currentSyncFolder->remoteUrl().toString())); + qPrintable(f->shortGuiLocalPath()), + qPrintable(f->accountState()->account()->displayName()), + qPrintable(f->remoteUrl().toString())); } /* @@ -917,15 +927,22 @@ void FolderMan::slotFolderSyncStarted() */ void FolderMan::slotFolderSyncFinished(const SyncResult &) { - qCInfo(lcFolderMan, "<========== Sync finished for folder [%s] of account [%s] with remote [%s]", - qPrintable(_currentSyncFolder->shortGuiLocalPath()), - qPrintable(_currentSyncFolder->accountState()->account()->displayName()), - qPrintable(_currentSyncFolder->remoteUrl().toString())); + auto f = qobject_cast<Folder *>(sender()); + ASSERT(f); + if (!f) + return; - _lastSyncFolder = _currentSyncFolder; - _currentSyncFolder = 0; + qCInfo(lcFolderMan, "<========== Sync finished for folder [%s] of account [%s] with remote [%s]", + qPrintable(f->shortGuiLocalPath()), + qPrintable(f->accountState()->account()->displayName()), + qPrintable(f->remoteUrl().toString())); - startScheduledSyncSoon(); + if (f == _currentSyncFolder) { + _lastSyncFolder = _currentSyncFolder; + _currentSyncFolder = 0; + } + if (!isAnySyncRunning()) + startScheduledSyncSoon(); } Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition &folderDefinition) @@ -1049,10 +1066,10 @@ void FolderMan::removeFolder(Folder *f) qCInfo(lcFolderMan) << "Removing " << f->alias(); - const bool currentlyRunning = (_currentSyncFolder == f); + const bool currentlyRunning = f->isSyncRunning(); if (currentlyRunning) { // abort the sync now - terminateSyncProcess(); + f->slotTerminateSync(); } if (_scheduledFolders.removeAll(f) > 0) { diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 17656846b..2c100ed49 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -182,9 +182,22 @@ public: /** * Access to the currently syncing folder. + * + * Note: This is only the folder that's currently syncing *as-scheduled*. There + * may be externally-managed syncs such as from placeholder hydrations. + * + * See also isAnySyncRunning() */ Folder *currentSyncFolder() const; + /** + * Returns true if any folder is currently syncing. + * + * This might be a FolderMan-scheduled sync, or a externally + * managed sync like a placeholder hydration. + */ + bool isAnySyncRunning() const; + /** Removes all folders */ int unloadAndDeleteAllFolders(); @@ -206,13 +219,6 @@ public: void setDirtyProxy(); void setDirtyNetworkLimits(); - /** - * Terminates the current folder sync. - * - * It does not switch the folder to paused state. - */ - void terminateSyncProcess(); - signals: /** * signal to indicate a folder has changed its sync state. diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 69664efee..e7771cf08 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -1072,9 +1072,9 @@ void FolderStatusModel::slotFolderSyncStateChange(Folder *f) } else if (state == SyncResult::NotYetStarted) { FolderMan *folderMan = FolderMan::instance(); int pos = folderMan->scheduleQueue().indexOf(f); - if (folderMan->currentSyncFolder() - && folderMan->currentSyncFolder() != f) { - pos += 1; + for (auto other : folderMan->map()) { + if (other != f && other->isSyncRunning()) + pos += 1; } QString message; if (pos <= 0) { diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index cbd153000..e2aac12ca 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -211,7 +211,7 @@ void ownCloudGui::slotComputeOverallSyncStatus() QVector<AccountStatePtr> problemAccounts; auto setStatusText = [&](const QString &text) { // Don't overwrite the status if we're currently syncing - if (FolderMan::instance()->currentSyncFolder()) + if (FolderMan::instance()->isAnySyncRunning()) return; _actionStatus->setText(text); }; |