@@ -109,8 +109,7 @@ Folder::Folder(const FolderDefinition &definition,
109
109
if (definition.paused ) {
110
110
status = SyncResult::Paused;
111
111
}
112
- _syncResult.setStatus (status);
113
-
112
+ setSyncState (status);
114
113
// check if the local path exists
115
114
if (checkLocalPath ()) {
116
115
prepareFolder (path ());
@@ -261,7 +260,7 @@ bool Folder::checkLocalPath()
261
260
if (!error.isEmpty ()) {
262
261
qCWarning (lcFolder) << error;
263
262
_syncResult.appendErrorString (error);
264
- _syncResult. setStatus (SyncResult::SetupError);
263
+ setSyncState (SyncResult::SetupError);
265
264
return false ;
266
265
}
267
266
return true ;
@@ -454,19 +453,21 @@ void Folder::setSyncPaused(bool paused)
454
453
_definition.paused = paused;
455
454
saveToSettings ();
456
455
456
+ emit syncPausedChanged (this , paused);
457
457
if (!paused) {
458
458
setSyncState (SyncResult::NotYetStarted);
459
459
} else {
460
460
setSyncState (SyncResult::Paused);
461
461
}
462
- emit syncPausedChanged (this , paused);
463
- emit syncStateChange ();
464
462
emit canSyncChanged ();
465
463
}
466
464
467
465
void Folder::setSyncState (SyncResult::Status state)
468
466
{
469
- _syncResult.setStatus (state);
467
+ if (state != _syncResult.status ()) {
468
+ _syncResult.setStatus (state);
469
+ Q_EMIT syncStateChange ();
470
+ }
470
471
}
471
472
472
473
SyncResult Folder::syncResult () const
@@ -477,7 +478,7 @@ SyncResult Folder::syncResult() const
477
478
void Folder::prepareToSync ()
478
479
{
479
480
_syncResult.reset ();
480
- _syncResult. setStatus (SyncResult::NotYetStarted);
481
+ setSyncState (SyncResult::NotYetStarted);
481
482
}
482
483
483
484
void Folder::slotRunEtagJob ()
@@ -629,7 +630,7 @@ void Folder::startVfs()
629
630
const auto result = Vfs::checkAvailability (path (), _vfs->mode ());
630
631
if (!result) {
631
632
_syncResult.appendErrorString (result.error ());
632
- _syncResult. setStatus (SyncResult::SetupError);
633
+ setSyncState (SyncResult::SetupError);
633
634
return ;
634
635
}
635
636
@@ -658,7 +659,7 @@ void Folder::startVfs()
658
659
});
659
660
connect (_vfs.data (), &Vfs::error, this , [this ](const QString &error) {
660
661
_syncResult.appendErrorString (error);
661
- _syncResult. setStatus (SyncResult::SetupError);
662
+ setSyncState (SyncResult::SetupError);
662
663
_vfsIsReady = false ;
663
664
});
664
665
@@ -993,8 +994,7 @@ void Folder::startSync()
993
994
}
994
995
995
996
_timeSinceLastSyncStart.start ();
996
- _syncResult.setStatus (SyncResult::SyncPrepare);
997
- emit syncStateChange ();
997
+ setSyncState (SyncResult::SyncPrepare);
998
998
999
999
qCInfo (lcFolder) << " *** Start syncing " << remoteUrl ().toString () << " client version"
1000
1000
<< Theme::instance ()->aboutVersions (Theme::VersionFormat::OneLiner);
@@ -1074,8 +1074,7 @@ void Folder::slotSyncError(const QString &message, ErrorCategory category)
1074
1074
void Folder::slotSyncStarted ()
1075
1075
{
1076
1076
qCInfo (lcFolder) << " #### Propagation start ####################################################" ;
1077
- _syncResult.setStatus (SyncResult::SyncRunning);
1078
- emit syncStateChange ();
1077
+ setSyncState (SyncResult::SyncRunning);
1079
1078
}
1080
1079
1081
1080
void Folder::slotSyncFinished (bool success)
@@ -1097,49 +1096,44 @@ void Folder::slotSyncFinished(bool success)
1097
1096
1098
1097
auto anotherSyncNeeded = _engine->isAnotherSyncNeeded ();
1099
1098
1099
+ auto syncStatus = SyncResult::Status::Undefined;
1100
+
1100
1101
if (syncError) {
1101
- _syncResult. setStatus ( SyncResult::Error) ;
1102
+ syncStatus = SyncResult::Error;
1102
1103
} else if (_syncResult.foundFilesNotSynced ()) {
1103
- _syncResult. setStatus ( SyncResult::Problem) ;
1104
+ syncStatus = SyncResult::Problem;
1104
1105
} else if (_definition.paused ) {
1105
1106
// Maybe the sync was terminated because the user paused the folder
1106
- _syncResult. setStatus ( SyncResult::Paused) ;
1107
+ syncStatus = SyncResult::Paused;
1107
1108
} else {
1108
- _syncResult. setStatus ( SyncResult::Success) ;
1109
+ syncStatus = SyncResult::Success;
1109
1110
}
1110
1111
1111
1112
// Count the number of syncs that have failed in a row.
1112
- if (_syncResult.status () == SyncResult::Success
1113
- || _syncResult.status () == SyncResult::Problem) {
1113
+ if (syncStatus == SyncResult::Success || syncStatus == SyncResult::Problem) {
1114
1114
_consecutiveFailingSyncs = 0 ;
1115
1115
} else {
1116
1116
_consecutiveFailingSyncs++;
1117
1117
qCInfo (lcFolder) << " the last" << _consecutiveFailingSyncs << " syncs failed" ;
1118
1118
}
1119
1119
1120
- if (_syncResult. status () == SyncResult::Success && success) {
1120
+ if (syncStatus == SyncResult::Success && success) {
1121
1121
// Clear the white list as all the folders that should be on that list are sync-ed
1122
1122
journalDb ()->setSelectiveSyncList (SyncJournalDb::SelectiveSyncWhiteList, QStringList ());
1123
1123
}
1124
1124
1125
- if ((_syncResult.status () == SyncResult::Success
1126
- || _syncResult.status () == SyncResult::Problem)
1127
- && success) {
1125
+ if ((syncStatus == SyncResult::Success || syncStatus == SyncResult::Problem) && success) {
1128
1126
if (_engine->lastLocalDiscoveryStyle () == LocalDiscoveryStyle::FilesystemOnly) {
1129
1127
_timeSinceLastFullLocalDiscovery.start ();
1130
1128
}
1131
1129
}
1132
1130
1131
+ if (syncStatus != SyncResult::Undefined) {
1132
+ setSyncState (syncStatus);
1133
+ }
1133
1134
1134
- emit syncStateChange ();
1135
-
1136
- // The syncFinished result that is to be triggered here makes the folderman
1137
- // clear the current running sync folder marker.
1138
- // Lets wait a bit to do that because, as long as this marker is not cleared,
1139
- // file system change notifications are ignored for that folder. And it takes
1140
- // some time under certain conditions to make the file system notifications
1141
- // all come in.
1142
- QTimer::singleShot (200ms, this , &Folder::slotEmitFinishedDelayed);
1135
+ // syncStateChange from setSyncState needs to be emitted first
1136
+ QTimer::singleShot (0 , this , &Folder::slotEmitFinishedDelayed);
1143
1137
1144
1138
_lastSyncDuration = std::chrono::milliseconds (_timeSinceLastSyncStart.elapsed ());
1145
1139
_timeSinceLastSyncDone.start ();
0 commit comments