Skip to content

Commit

Permalink
Modernize FolderStatusModel::slotSetProgress.
Browse files Browse the repository at this point in the history
- Add const auto.
- Change variable names to be more clear.

Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan committed Apr 24, 2024
1 parent 658f3f7 commit 8d43b00
Showing 1 changed file with 39 additions and 41 deletions.
80 changes: 39 additions & 41 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,63 +979,62 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
return;
}

auto *pi = &_folders[folderIndex]._progress;
auto *subFolderProgress = &_folders[folderIndex]._progress;

if (progress.status() == ProgressInfo::Starting) {
_isSyncRunningForAwhile = false;
}

QVector<int> roles;
roles << FolderStatusDelegate::SyncProgressItemString
<< FolderStatusDelegate::WarningCount
<< Qt::ToolTipRole;
const QVector<int> roles{ FolderStatusDelegate::SyncProgressItemString, FolderStatusDelegate::WarningCount,
Qt::ToolTipRole };

if (progress.status() == ProgressInfo::Discovery) {
if (!progress._currentDiscoveredRemoteFolder.isEmpty()) {
pi->_overallSyncString = tr("Checking for changes in remote \"%1\"").arg(progress._currentDiscoveredRemoteFolder);
subFolderProgress->_overallSyncString = tr("Checking for changes in remote \"%1\"").arg(progress._currentDiscoveredRemoteFolder);
emit dataChanged(index(folderIndex), index(folderIndex), roles);
return;
} else if (!progress._currentDiscoveredLocalFolder.isEmpty()) {
pi->_overallSyncString = tr("Checking for changes in local \"%1\"").arg(progress._currentDiscoveredLocalFolder);
subFolderProgress->_overallSyncString = tr("Checking for changes in local \"%1\"").arg(progress._currentDiscoveredLocalFolder);
emit dataChanged(index(folderIndex), index(folderIndex), roles);
return;
}
}

if (progress.status() == ProgressInfo::Reconcile) {
pi->_overallSyncString = tr("Reconciling changes");
subFolderProgress->_overallSyncString = tr("Reconciling changes");
emit dataChanged(index(folderIndex), index(folderIndex), roles);
return;
}

// Status is Starting, Propagation or Done

if (!progress._lastCompletedItem.isEmpty()
&& Progress::isWarningKind(progress._lastCompletedItem._status)) {
pi->_warningCount++;
subFolderProgress->_warningCount++;
}

// find the single item to display: This is going to be the bigger item, or the last completed
// item if no items are in progress.
auto curItem = progress._lastCompletedItem;
qint64 curItemProgress = -1; // -1 means finished
qint64 biggerItemSize = 0;
quint64 estimatedUpBw = 0;
quint64 estimatedDownBw = 0;
auto curItemProgress = -1; // -1 means finished
auto biggerItemSize = 0;
auto estimatedUpBw = 0;
auto estimatedDownBw = 0;
QString allFilenames;
for (const auto &citm : progress._currentItems) {
if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(citm._item)
&& biggerItemSize < citm._item._size)) {
curItemProgress = citm._progress.completed();
curItem = citm._item;
biggerItemSize = citm._item._size;
for (const auto &syncFile : progress._currentItems) {
if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(syncFile._item)
&& biggerItemSize < syncFile._item._size)) {
curItemProgress = syncFile._progress.completed();
curItem = syncFile._item;
biggerItemSize = syncFile._item._size;
}
if (citm._item._direction != SyncFileItem::Up) {
estimatedDownBw += progress.fileProgress(citm._item).estimatedBandwidth;

if (syncFile._item._direction != SyncFileItem::Up) {
estimatedDownBw += progress.fileProgress(syncFile._item).estimatedBandwidth;
} else {
estimatedUpBw += progress.fileProgress(citm._item).estimatedBandwidth;
estimatedUpBw += progress.fileProgress(syncFile._item).estimatedBandwidth;
}
auto fileName = QFileInfo(citm._item._file).fileName();

auto fileName = QFileInfo(syncFile._item._file).fileName();
if (allFilenames.length() > 0) {
//: Build a list of file names
allFilenames.append(QStringLiteral(", \"%1\"").arg(fileName));
Expand All @@ -1053,8 +1052,6 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)

QString fileProgressString;
if (ProgressInfo::isSizeDependent(curItem)) {
const auto s1 = Utility::octetsToString(curItemProgress);
const auto s2 = Utility::octetsToString(curItem._size);
//quint64 estimatedBw = progress.fileProgress(curItem).estimatedBandwidth;
if (estimatedUpBw || estimatedDownBw) {
/*
Expand Down Expand Up @@ -1089,38 +1086,40 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
}
} else {
//: Example text: "uploading foobar.png (2MB of 2MB)"
fileProgressString = tr("%1 %2 (%3 of %4)").arg(kindString, itemFileName, s1, s2);
fileProgressString = tr("%1 %2 (%3 of %4)").arg(kindString, itemFileName,
Utility::octetsToString(curItemProgress),
Utility::octetsToString(curItem._size));
}
} else if (!kindString.isEmpty()) {
//: Example text: "uploading foobar.png"
fileProgressString = tr("%1 %2").arg(kindString, itemFileName);
}
pi->_progressString = fileProgressString;
subFolderProgress->_progressString = fileProgressString;

// overall progress
const auto completedSize = progress.completedSize();
const auto completedFile = progress.completedFiles();
const auto currentFile = progress.currentFile();
const auto totalSize = qMax(completedSize, progress.totalSize());
const auto totalFileCount = qMax(currentFile, progress.totalFiles());
const auto totalSize = qMax(completedSize, progress.totalSize());

QString overallSyncString;
if (totalSize > 0) {
const auto s1 = Utility::octetsToString(completedSize);
const auto s2 = Utility::octetsToString(totalSize);
const auto completedSizeString = Utility::octetsToString(completedSize);
const auto totalSizeString = Utility::octetsToString(totalSize);

const auto estimatedEta = progress.totalProgress().estimatedEta;
if (const auto estimatedEta = progress.totalProgress().estimatedEta;
progress.trustEta() && (estimatedEta > 0 || _isSyncRunningForAwhile)) {

if (progress.trustEta() && (estimatedEta > 0 || _isSyncRunningForAwhile)) {
_isSyncRunningForAwhile = true;
//: Example text: "5 minutes left, 12 MB of 345 MB, file 6 of 7"
if (estimatedEta == 0) {
overallSyncString = tr("A few seconds left, %1 of %2, file %3 of %4")
.arg(s1, s2)
.arg(completedSizeString, totalSizeString)
.arg(currentFile)
.arg(totalFileCount);
} else {
overallSyncString = tr("%5 left, %1 of %2, file %3 of %4")
.arg(s1, s2)
.arg(completedSizeString, totalSizeString)
.arg(currentFile)
.arg(totalFileCount)
.arg(Utility::durationToDescriptiveString1(estimatedEta));
Expand All @@ -1129,23 +1128,22 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
} else {
//: Example text: "12 MB of 345 MB, file 6 of 7"
overallSyncString = tr("%1 of %2, file %3 of %4")
.arg(s1, s2)
.arg(completedSizeString, totalSizeString)
.arg(currentFile)
.arg(totalFileCount);
}
} else if (totalFileCount > 0) {
// Don't attempt to estimate the time left if there is no kb to transfer.
overallSyncString = tr("file %1 of %2").arg(currentFile).arg(totalFileCount);
}

pi->_overallSyncString = overallSyncString;
subFolderProgress->_overallSyncString = overallSyncString;

auto overallPercent = 0;
if (totalFileCount > 0) {
if (const auto completedFile = progress.completedFiles();totalFileCount > 0) {
// Add one 'byte' for each file so the percentage is moving when deleting or renaming files
overallPercent = qRound(double(completedSize + completedFile) / double(totalSize + totalFileCount) * 100.0);
}
pi->_overallPercent = qBound(0, overallPercent, 100);
subFolderProgress->_overallPercent = qBound(0, overallPercent, 100);
emit dataChanged(index(folderIndex), index(folderIndex), roles);
}

Expand Down

0 comments on commit 8d43b00

Please sign in to comment.