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 Feb 7, 2024
1 parent e4a274d commit ed4b52d
Showing 1 changed file with 54 additions and 55 deletions.
109 changes: 54 additions & 55 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,19 +955,19 @@ void FolderStatusModel::slotApplySelectiveSync()

void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
{
auto par = qobject_cast<QWidget *>(QObject::parent());
if (!par->isVisible()) {
auto parent = qobject_cast<QWidget *>(QObject::parent());
if (!parent->isVisible()) {
return; // for https://github.com/owncloud/client/issues/2648#issuecomment-71377909
}

auto *f = qobject_cast<Folder *>(sender());
if (!f) {
auto *folder = qobject_cast<Folder *>(sender());
if (!folder) {
return;
}

int folderIndex = -1;
for (int i = 0; i < _folders.count(); ++i) {
if (_folders.at(i)._folder == f) {
auto folderIndex = -1;
for (auto i = 0; i < _folders.count(); ++i) {
if (_folders.at(i)._folder == folder) {
folderIndex = i;
break;
}
Expand All @@ -976,63 +976,63 @@ 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.
SyncFileItem curItem = progress._lastCompletedItem;
qint64 curItemProgress = -1; // -1 means finished
qint64 biggerItemSize = 0;
quint64 estimatedUpBw = 0;
quint64 estimatedDownBw = 0;
auto curItem = progress._lastCompletedItem;
auto curItemProgress = -1; // -1 means finished
auto biggerItemSize = 0;
auto estimatedUpBw = 0;
auto estimatedDownBw = 0;

QString allFilenames;
foreach (const ProgressInfo::ProgressItem &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;
foreach (const ProgressInfo::ProgressItem &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 @@ -1045,13 +1045,11 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
curItemProgress = curItem._size;
}

QString itemFileName = curItem._file;
QString kindString = Progress::asActionString(curItem);
const auto itemFileName = curItem._file;
const auto kindString = Progress::asActionString(curItem);

QString fileProgressString;
if (ProgressInfo::isSizeDependent(curItem)) {
QString s1 = Utility::octetsToString(curItemProgress);
QString s2 = Utility::octetsToString(curItem._size);
//quint64 estimatedBw = progress.fileProgress(curItem).estimatedBandwidth;
if (estimatedUpBw || estimatedDownBw) {
/*
Expand Down Expand Up @@ -1086,38 +1084,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
qint64 completedSize = progress.completedSize();
qint64 completedFile = progress.completedFiles();
qint64 currentFile = progress.currentFile();
qint64 totalSize = qMax(completedSize, progress.totalSize());
qint64 totalFileCount = qMax(currentFile, progress.totalFiles());
const auto completedSize = progress.completedSize();
const auto currentFile = progress.currentFile();
const auto totalFileCount = qMax(currentFile, progress.totalFiles());
const auto totalSize = qMax(completedSize, progress.totalSize());

QString overallSyncString;
if (totalSize > 0) {
QString s1 = Utility::octetsToString(completedSize);
QString 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 @@ -1126,23 +1126,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);
}
subFolderProgress->_overallSyncString = overallSyncString;

pi->_overallSyncString = overallSyncString;

int overallPercent = 0;
if (totalFileCount > 0) {
auto overallPercent = 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 ed4b52d

Please sign in to comment.