diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 51bbe4f748406..d03cead137def 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -998,8 +998,6 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress) SyncFileItem curItem = progress._lastCompletedItem; qint64 curItemProgress = -1; // -1 means finished qint64 biggerItemSize = 0; - quint64 estimatedUpBw = 0; - quint64 estimatedDownBw = 0; QString allFilenames; foreach (const ProgressInfo::ProgressItem &citm, progress._currentItems) { if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(citm._item) @@ -1008,11 +1006,6 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress) curItem = citm._item; biggerItemSize = citm._item._size; } - if (citm._item._direction != SyncFileItem::Up) { - estimatedDownBw += progress.fileProgress(citm._item).estimatedBandwidth; - } else { - estimatedUpBw += progress.fileProgress(citm._item).estimatedBandwidth; - } auto fileName = QFileInfo(citm._item._file).fileName(); if (allFilenames.length() > 0) { //: Build a list of file names @@ -1034,7 +1027,7 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress) QString s1 = Utility::octetsToString(curItemProgress); QString s2 = Utility::octetsToString(curItem._size); //quint64 estimatedBw = progress.fileProgress(curItem).estimatedBandwidth; - if (estimatedUpBw || estimatedDownBw) { + if (progress.estimatedUpBw() || progress.estimatedDownBw()) { /* //: Example text: "uploading foobar.png (1MB of 2MB) time left 2 minutes at a rate of 24Kb/s" fileProgressString = tr("%1 %2 (%3 of %4) %5 left at a rate of %6/s") @@ -1043,28 +1036,8 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress) Utility::octetsToString(estimatedBw) ); */ //: Example text: "Syncing 'foo.txt', 'bar.txt'" - fileProgressString = tr("Syncing %1").arg(allFilenames); - if (estimatedDownBw > 0) { - fileProgressString.append(tr(", ")); -// ifdefs: https://github.com/owncloud/client/issues/3095#issuecomment-128409294 -#ifdef Q_OS_WIN - //: Example text: "download 24Kb/s" (%1 is replaced by 24Kb (translated)) - fileProgressString.append(tr("download %1/s").arg(Utility::octetsToString(estimatedDownBw))); -#else - fileProgressString.append(tr("\u2193 %1/s") - .arg(Utility::octetsToString(estimatedDownBw))); -#endif - } - if (estimatedUpBw > 0) { - fileProgressString.append(tr(", ")); -#ifdef Q_OS_WIN - //: Example text: "upload 24Kb/s" (%1 is replaced by 24Kb (translated)) - fileProgressString.append(tr("upload %1/s").arg(Utility::octetsToString(estimatedUpBw))); -#else - fileProgressString.append(tr("\u2191 %1/s") - .arg(Utility::octetsToString(estimatedUpBw))); -#endif - } + fileProgressString = tr("Syncing %1 %2").arg(allFilenames, + progress.estimatedBwString()); } else { //: Example text: "uploading foobar.png (2MB of 2MB)" fileProgressString = tr("%1 %2 (%3 of %4)").arg(kindString, itemFileName, s1, s2); @@ -1088,12 +1061,12 @@ void FolderStatusModel::slotSetProgress(const ProgressInfo &progress) if (progress.trustEta()) { //: Example text: "5 minutes left, 12 MB of 345 MB, file 6 of 7" - overallSyncString = tr("%5 left, %1 of %2, file %3 of %4") + overallSyncString = tr("%5 left, %1 of %2, file %3 of %4 %6") .arg(s1, s2) .arg(currentFile) .arg(totalFileCount) - .arg(Utility::durationToDescriptiveString1(progress.totalProgress().estimatedEta)); - + .arg(Utility::durationToDescriptiveString1(progress.totalProgress().estimatedEta)) + .arg(progress.estimatedBwString()); } else { //: Example text: "12 MB of 345 MB, file 6 of 7" overallSyncString = tr("%1 of %2, file %3 of %4") diff --git a/src/gui/tray/syncstatussummary.cpp b/src/gui/tray/syncstatussummary.cpp index 8f74985c8e6d3..348390e1d278c 100644 --- a/src/gui/tray/syncstatussummary.cpp +++ b/src/gui/tray/syncstatussummary.cpp @@ -215,9 +215,12 @@ void SyncStatusSummary::onFolderProgressInfo(const ProgressInfo &progress) if (progress.trustEta()) { setSyncStatusDetailString( - tr("%1 of %2 · %3 left") - .arg(completedSizeString, totalSizeString) - .arg(Utility::durationToDescriptiveString1(progress.totalProgress().estimatedEta))); + tr("%1 of %2 · %3 left %4") + .arg(completedSizeString, + totalSizeString, + Utility::durationToDescriptiveString1(progress.totalProgress().estimatedEta), + progress.estimatedBwString()) + ); } else { setSyncStatusDetailString(tr("%1 of %2").arg(completedSizeString, totalSizeString)); } diff --git a/src/libsync/progressdispatcher.cpp b/src/libsync/progressdispatcher.cpp index 45c5beac4f01e..493ba783b1083 100644 --- a/src/libsync/progressdispatcher.cpp +++ b/src/libsync/progressdispatcher.cpp @@ -156,6 +156,9 @@ void ProgressInfo::reset() _updateEstimatesTimer.stop(); _lastCompletedItem = SyncFileItem(); + + _estimatedDownBw = 0; + _estimatedUpBw = 0; } ProgressInfo::Status ProgressInfo::status() const @@ -335,6 +338,53 @@ ProgressInfo::Estimates ProgressInfo::fileProgress(const SyncFileItem &item) con return _currentItems[item._file]._progress.estimates(); } +void ProgressInfo::setEstimatedBandwidth(const SyncFileItem &item) +{ + if (item._direction != SyncFileItem::Up) { + _estimatedDownBw = fileProgress(item).estimatedBandwidth; + } else { + _estimatedUpBw = fileProgress(item).estimatedBandwidth; + } +} + +quint64 ProgressInfo::estimatedUpBw() const +{ + return _estimatedUpBw; +} + +quint64 ProgressInfo::estimatedDownBw() const +{ + return _estimatedDownBw; +} + +QString ProgressInfo::estimatedBwString() const +{ + QString estimatedBwString; + if (_estimatedDownBw > 0) { + estimatedBwString.append(tr(", ")); +// ifdefs: https://github.com/owncloud/client/issues/3095#issuecomment-128409294 +#ifdef Q_OS_WIN + //: Example text: "download 24Kb/s" (%1 is replaced by 24Kb (translated)) + estimatedBwString.append(tr("download %1/s").arg(Utility::octetsToString(_estimatedDownBw))); +#else + estimatedBwString.append(tr("\u2193 %1/s") + .arg(Utility::octetsToString(_estimatedDownBw))); +#endif + } + if (_estimatedUpBw > 0) { + estimatedBwString.append(tr(", ")); +#ifdef Q_OS_WIN + //: Example text: "upload 24Kb/s" (%1 is replaced by 24Kb (translated)) + estimatedBwString.append(tr("upload %1/s").arg(Utility::octetsToString(_estimatedUpBw))); +#else + estimatedBwString.append(tr("\u2191 %1/s") + .arg(Utility::octetsToString(_estimatedUpBw))); +#endif + } + + return estimatedBwString; +} + void ProgressInfo::updateEstimates() { _sizeProgress.update(); diff --git a/src/libsync/progressdispatcher.h b/src/libsync/progressdispatcher.h index 3e34fdd8f4efa..e7227838e5ab0 100644 --- a/src/libsync/progressdispatcher.h +++ b/src/libsync/progressdispatcher.h @@ -23,6 +23,7 @@ #include #include +#include "common/utility.h" #include "syncfileitem.h" namespace OCC { @@ -208,6 +209,12 @@ class OWNCLOUDSYNC_EXPORT ProgressInfo : public QObject */ Estimates fileProgress(const SyncFileItem &item) const; + void setEstimatedBandwidth(const SyncFileItem &item); + + quint64 estimatedUpBw() const; + quint64 estimatedDownBw() const; + QString estimatedBwString() const; + private slots: /** * Called every second once started, this function updates the @@ -232,6 +239,9 @@ private slots: // The fastest observed rate of files per second in this sync. double _maxFilesPerSecond; double _maxBytesPerSecond; + + quint64 _estimatedUpBw{0}; + quint64 _estimatedDownBw{0}; }; namespace Progress { diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index ac19cd40cbb55..247b5912ada10 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -859,10 +859,10 @@ void SyncEngine::finalize(bool success) void SyncEngine::slotProgress(const SyncFileItem &item, qint64 current) { _progressInfo->setProgressItem(item, current); + _progressInfo->setEstimatedBandwidth(item); emit transmissionProgress(*_progressInfo); } - void SyncEngine::restoreOldFiles(SyncFileItemVector &syncItems) { /* When the server is trying to send us lots of file in the past, this means that a backup