Skip to content

Commit

Permalink
Add Upload & download speed rate on nextcloud window
Browse files Browse the repository at this point in the history
Signed-off-by: tokun-mobica <[email protected]>
  • Loading branch information
tokun-mobica authored and mgallien committed May 30, 2022
1 parent e57ba87 commit 0873f57
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 37 deletions.
39 changes: 6 additions & 33 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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);
Expand All @@ -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")
Expand Down
9 changes: 6 additions & 3 deletions src/gui/tray/syncstatussummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
50 changes: 50 additions & 0 deletions src/libsync/progressdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ void ProgressInfo::reset()

_updateEstimatesTimer.stop();
_lastCompletedItem = SyncFileItem();

_estimatedDownBw = 0;
_estimatedUpBw = 0;
}

ProgressInfo::Status ProgressInfo::status() const
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions src/libsync/progressdispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QElapsedTimer>
#include <QTimer>

#include "common/utility.h"
#include "syncfileitem.h"

namespace OCC {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0873f57

Please sign in to comment.