From e6c6c77050870f602a8c690a5335c56cb0109454 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Wed, 7 Feb 2024 22:03:04 +0100 Subject: [PATCH] Modernize FolderStatusModel::slotSetProgress. Add const auto. Signed-off-by: Camila Ayres --- src/gui/folderstatusmodel.cpp | 114 ++++++++++++++++------------------ 1 file changed, 54 insertions(+), 60 deletions(-) diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 6540d76088f4e..30b75a27e5595 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -955,19 +955,19 @@ void FolderStatusModel::slotApplySelectiveSync() void FolderStatusModel::slotSetProgress(const ProgressInfo &progress) { - auto par = qobject_cast(QObject::parent()); - if (!par->isVisible()) { + auto parent = qobject_cast(QObject::parent()); + if (!parent->isVisible()) { return; // for https://github.com/owncloud/client/issues/2648#issuecomment-71377909 } - auto *f = qobject_cast(sender()); - if (!f) { + auto *folder = qobject_cast(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; } @@ -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 roles; - roles << FolderStatusDelegate::SyncProgressItemString - << FolderStatusDelegate::WarningCount - << Qt::ToolTipRole; + const QVector 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)); @@ -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) { /* @@ -1086,43 +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; - - qCDebug(lcFolderStatus) << "Progress for file: " << curItem._file; - qCDebug(lcFolderStatus) << "pi->_overallSyncString" << pi->_overallSyncString; - qCDebug(lcFolderStatus) << "pi->_progressString" << pi->_progressString; + 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)); @@ -1131,7 +1126,7 @@ 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); } @@ -1139,15 +1134,14 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress) // 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); }