}
}
-// 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()) {
//qCDebug(lcFolderMan) << "No more remote ETag check jobs to schedule.";
/* now it might be a good time to check for restarting... */
- if (!_currentSyncFolder && _appRestartRequired) {
+ if (!isAnySyncRunning() && _appRestartRequired) {
restartApplication();
}
} else {
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);
if (_scheduledFolders.empty()) {
return;
}
- if (_currentSyncFolder) {
+ if (isAnySyncRunning()) {
return;
}
*/
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;
}
if (!f) {
continue;
}
- if (_currentSyncFolder == f) {
+ if (f->isSyncRunning()) {
continue;
}
if (_scheduledFolders.contains(f)) {
}
}
+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()));
}
/*
*/
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 = nullptr;
+ 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 = nullptr;
+ }
+ if (!isAnySyncRunning())
+ startScheduledSyncSoon();
}
Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition &folderDefinition)
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) {
const bool currentlyRunning = (_currentSyncFolder == f);
if (currentlyRunning) {
// abort the sync now
- terminateSyncProcess();
+ _currentSyncFolder->slotTerminateSync();
}
if (_scheduledFolders.removeAll(f) > 0) {
/**
* 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();
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.