diff --git a/core/compositefiletransferjob.cpp b/core/compositefiletransferjob.cpp index 9a921e1b0..489952e3a 100644 --- a/core/compositefiletransferjob.cpp +++ b/core/compositefiletransferjob.cpp @@ -17,11 +17,11 @@ CompositeFileTransferJob::CompositeFileTransferJob(const QString& deviceId) , m_running(false) , m_currentJobNum(1) , m_totalJobs(0) - , m_currentJobSendPayloadSize(0) - , m_totalSendPayloadSize(0) + , m_currentJobSentPayloadSize(0) + , m_totalSentPayloadSize(0) + , m_oldTotalSentPayloadSize(0) , m_totalPayloadSize(0) , m_currentJob(nullptr) - , m_prevElapsedTime(0) { setCapabilities(Killable); } @@ -40,7 +40,7 @@ void CompositeFileTransferJob::start() void CompositeFileTransferJob::startNextSubJob() { m_currentJob = qobject_cast(subjobs().at(0)); - m_currentJobSendPayloadSize = 0; + m_currentJobSentPayloadSize = 0; Q_EMIT description(this, i18ncp("@title job", "Receiving file", "Receiving files", m_totalJobs), {i18nc("The source of a file operation", "Source"), Daemon::instance()->getDevice(this->m_deviceId)->name()}, @@ -95,17 +95,25 @@ bool CompositeFileTransferJob::doKill() void CompositeFileTransferJob::slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount) { Q_UNUSED(job); - m_currentJobSendPayloadSize = amount; - quint64 uploaded = m_totalSendPayloadSize + m_currentJobSendPayloadSize; - if (uploaded == m_totalPayloadSize || m_prevElapsedTime == 0 || m_timer.elapsed() - m_prevElapsedTime >= 100) { - m_prevElapsedTime = m_timer.elapsed(); - setProcessedAmount(unit, uploaded); + m_currentJobSentPayloadSize = amount; + const auto totalSent = m_totalSentPayloadSize + m_currentJobSentPayloadSize; - const auto elapsed = m_timer.elapsed(); - if (elapsed > 0) { - emitSpeed((1000 * uploaded) / elapsed); - } + if (!m_reportTimer.isValid()) { + m_reportTimer.start(); + } + if (m_reportTimer.hasExpired(250)) { + setProcessedAmount(unit, totalSent); + m_reportTimer.restart(); + } + + if (!m_speedTimer.isValid()) { + m_speedTimer.start(); + } + if (m_speedTimer.hasExpired(1000)) { + emitSpeed(1000 * (totalSent - m_oldTotalSentPayloadSize) / m_speedTimer.elapsed()); + m_oldTotalSentPayloadSize = totalSent; + m_speedTimer.restart(); } } @@ -118,8 +126,9 @@ void CompositeFileTransferJob::slotResult(KJob *job) return; } - m_totalSendPayloadSize += m_currentJobSendPayloadSize; + m_totalSentPayloadSize += m_currentJobSentPayloadSize; + setProcessedAmount(Bytes, m_totalSentPayloadSize); setProcessedAmount(Files, m_currentJobNum); if (m_currentJobNum < m_totalJobs) { diff --git a/core/compositefiletransferjob.h b/core/compositefiletransferjob.h index 5e185b88b..93e960e1c 100644 --- a/core/compositefiletransferjob.h +++ b/core/compositefiletransferjob.h @@ -38,12 +38,13 @@ private: bool m_running; int m_currentJobNum; int m_totalJobs; - quint64 m_currentJobSendPayloadSize; - quint64 m_totalSendPayloadSize; + quint64 m_currentJobSentPayloadSize; + quint64 m_totalSentPayloadSize; + quint64 m_oldTotalSentPayloadSize; // for speed calculation quint64 m_totalPayloadSize; FileTransferJob *m_currentJob; - QElapsedTimer m_timer; - quint64 m_prevElapsedTime; + QElapsedTimer m_reportTimer; + QElapsedTimer m_speedTimer; };