Clean code for dealing with folder (scan) completion
This commit is contained in:
parent
eb527fd89a
commit
e6b97e1ecc
|
@ -1606,20 +1606,20 @@ void SyncthingConnection::readDirEvent(DateTime eventTime, const QString &eventT
|
|||
} else if (eventType == QLatin1String("FolderSummary")) {
|
||||
readDirSummary(eventTime, eventData.value(QStringLiteral("summary")).toObject(), *dirInfo, index);
|
||||
} else if (eventType == QLatin1String("FolderCompletion")) {
|
||||
//const QString device(eventData.value(QStringLiteral("device")).toString());
|
||||
int percentage = eventData.value(QStringLiteral("completion")).toInt();
|
||||
if (percentage > 0 && percentage < 100 && (dirInfo->progressPercentage <= 0 || percentage < dirInfo->progressPercentage)) {
|
||||
// Syncthing provides progress percentage for each device
|
||||
// just show the smallest percentage for now
|
||||
dirInfo->progressPercentage = percentage;
|
||||
const int percentage = static_cast<int>(eventData.value(QStringLiteral("completion")).toDouble());
|
||||
dirInfo->globalBytes = static_cast<uint64>(eventData.value(QStringLiteral("globalBytes")).toDouble(dirInfo->globalBytes));
|
||||
dirInfo->neededBytes = static_cast<uint64>(eventData.value(QStringLiteral("neededBytes")).toDouble(dirInfo->neededBytes));
|
||||
if (percentage > 0 && percentage < 100) {
|
||||
dirInfo->completionPercentage = percentage;
|
||||
emit dirStatusChanged(*dirInfo, index);
|
||||
}
|
||||
} else if (eventType == QLatin1String("FolderScanProgress")) {
|
||||
// FIXME: for some reason this is always 0
|
||||
const int current = eventData.value(QStringLiteral("current")).toInt(0), total = eventData.value(QStringLiteral("total")).toInt(0),
|
||||
rate = eventData.value(QStringLiteral("rate")).toInt(0);
|
||||
const double current = eventData.value(QStringLiteral("current")).toDouble(0);
|
||||
const double total = eventData.value(QStringLiteral("total")).toDouble(0);
|
||||
const double rate = eventData.value(QStringLiteral("rate")).toDouble(0);
|
||||
if (current > 0 && total > 0) {
|
||||
dirInfo->progressPercentage = current * 100 / total;
|
||||
dirInfo->progressRate = rate;
|
||||
dirInfo->scanningPercentage = static_cast<int>(current * 100 / total);
|
||||
dirInfo->scanningRate = rate;
|
||||
dirInfo->assignStatus(SyncthingDirStatus::Scanning, eventTime); // ensure state is scanning
|
||||
emit dirStatusChanged(*dirInfo, index);
|
||||
}
|
||||
|
@ -1876,7 +1876,7 @@ bool SyncthingConnection::readDirSummary(DateTime eventTime, const QJsonObject &
|
|||
dir.localDeleted = toUInt64(summary.value(QStringLiteral("localDeleted")));
|
||||
dir.localFiles = toUInt64(summary.value(QStringLiteral("localFiles")));
|
||||
dir.localDirs = toUInt64(summary.value(QStringLiteral("localDirectories")));
|
||||
dir.neededByted = toUInt64(summary.value(QStringLiteral("needByted")));
|
||||
dir.neededBytes = toUInt64(summary.value(QStringLiteral("needByted")));
|
||||
dir.neededFiles = toUInt64(summary.value(QStringLiteral("needFiles")));
|
||||
dir.ignorePatterns = summary.value(QStringLiteral("ignorePatterns")).toBool();
|
||||
dir.lastStatisticsUpdate = eventTime;
|
||||
|
|
|
@ -87,7 +87,7 @@ bool SyncthingDir::assignStatus(const QString &statusStr, ChronoUtilities::DateT
|
|||
// identify statusStr
|
||||
SyncthingDirStatus newStatus;
|
||||
if (statusStr == QLatin1String("idle")) {
|
||||
progressPercentage = 0;
|
||||
completionPercentage = 0;
|
||||
newStatus = SyncthingDirStatus::Idle;
|
||||
} else if (statusStr == QLatin1String("scanning")) {
|
||||
newStatus = SyncthingDirStatus::Scanning;
|
||||
|
@ -102,7 +102,7 @@ bool SyncthingDir::assignStatus(const QString &statusStr, ChronoUtilities::DateT
|
|||
previousItemErrors.swap(itemErrors);
|
||||
newStatus = SyncthingDirStatus::Synchronizing;
|
||||
} else if (statusStr == QLatin1String("error")) {
|
||||
progressPercentage = 0;
|
||||
completionPercentage = 0;
|
||||
newStatus = SyncthingDirStatus::OutOfSync;
|
||||
} else {
|
||||
newStatus = SyncthingDirStatus::Idle;
|
||||
|
|
|
@ -72,14 +72,15 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDir {
|
|||
int minDiskFreePercentage = 0;
|
||||
SyncthingDirStatus status = SyncthingDirStatus::Idle;
|
||||
ChronoUtilities::DateTime lastStatusUpdate;
|
||||
int progressPercentage = 0;
|
||||
int progressRate = 0;
|
||||
int completionPercentage = 0;
|
||||
int scanningPercentage = 0;
|
||||
double scanningRate = 0;
|
||||
QString globalError;
|
||||
std::vector<SyncthingItemError> itemErrors;
|
||||
std::vector<SyncthingItemError> previousItemErrors;
|
||||
quint64 globalBytes = 0, globalDeleted = 0, globalFiles = 0, globalDirs = 0;
|
||||
quint64 localBytes = 0, localDeleted = 0, localFiles = 0, localDirs = 0;
|
||||
quint64 neededByted = 0, neededFiles = 0, neededDirs = 0;
|
||||
quint64 neededBytes = 0, neededFiles = 0, neededDirs = 0;
|
||||
ChronoUtilities::DateTime lastStatisticsUpdate;
|
||||
ChronoUtilities::DateTime lastScanTime;
|
||||
ChronoUtilities::DateTime lastFileTime;
|
||||
|
|
|
@ -390,9 +390,15 @@ QString SyncthingDirectoryModel::dirStatusString(const SyncthingDir &dir)
|
|||
case SyncthingDirStatus::Idle:
|
||||
return tr("Idle");
|
||||
case SyncthingDirStatus::Scanning:
|
||||
return dir.progressPercentage > 0 ? tr("Scanning (%1 %)").arg(dir.progressPercentage) : tr("Scanning");
|
||||
if (dir.scanningPercentage > 0) {
|
||||
if (dir.scanningRate != 0.0) {
|
||||
return tr("Scanning (%1 %, %2)").arg(dir.scanningPercentage).arg(bitrateToString(dir.scanningRate * 0.008, true).data());
|
||||
}
|
||||
return tr("Scanning (%1 %)").arg(dir.scanningPercentage);
|
||||
}
|
||||
return tr("Scanning");
|
||||
case SyncthingDirStatus::Synchronizing:
|
||||
return dir.progressPercentage > 0 ? tr("Synchronizing (%1 %)").arg(dir.progressPercentage) : tr("Synchronizing");
|
||||
return dir.completionPercentage > 0 ? tr("Synchronizing (%1 %)").arg(dir.completionPercentage) : tr("Synchronizing");
|
||||
case SyncthingDirStatus::OutOfSync:
|
||||
return tr("Out of sync");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue