[FileTransferJob] Fix division by null and use elapsed timer
When sending multiple files from my phone to my PC, kdeconnectd usually received a SIGFPE. To get the transfer speed it divides the number of bytes received by the elapsed time which can be zero. Also, since we're only interested in the time that has elapsed, use QElapsedTimer, which is exactly for this. QTime::elapsed() also needs to take into account potentially ocurred timezone or DST changes. REVIEW: 128861
This commit is contained in:
parent
c19f26a95d
commit
77ad9336b6
2 changed files with 8 additions and 4 deletions
|
@ -80,7 +80,7 @@ void FileTransferJob::doStart()
|
|||
void FileTransferJob::startTransfer()
|
||||
{
|
||||
setProcessedAmount(Bytes, 0);
|
||||
mTime = QTime::currentTime();
|
||||
mTimer.start();
|
||||
description(this, i18n("Receiving file over KDE Connect"),
|
||||
{ i18nc("File transfer origin", "From"), mFrom },
|
||||
{ i18nc("File transfer destination", "To"), mDestination.toLocalFile() });
|
||||
|
@ -91,7 +91,11 @@ void FileTransferJob::startTransfer()
|
|||
|
||||
connect(mReply, &QNetworkReply::uploadProgress, this, [this](qint64 bytesSent, qint64 /*bytesTotal*/) {
|
||||
setProcessedAmount(Bytes, bytesSent);
|
||||
emitSpeed(bytesSent/mTime.elapsed());
|
||||
|
||||
const auto elapsed = mTimer.elapsed();
|
||||
if (elapsed > 0) {
|
||||
emitSpeed(bytesSent / elapsed);
|
||||
}
|
||||
});
|
||||
connect(mReply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
|
||||
this, &FileTransferJob::transferFailed);
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
#include <KJob>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QIODevice>
|
||||
#include <QTime>
|
||||
#include <QSharedPointer>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
|
@ -69,7 +69,7 @@ private:
|
|||
QNetworkReply* mReply;
|
||||
QString mFrom;
|
||||
QUrl mDestination;
|
||||
QTime mTime;
|
||||
QElapsedTimer mTimer;
|
||||
qulonglong mSpeedBytes;
|
||||
qint64 mWritten;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue