From 9e7011cbed503d41130fe702928e0ec4458c9982 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 24 Dec 2018 13:55:46 +0100 Subject: [PATCH] DownloadManager: Start download timer when download is created Since we block in download options / file dialogs and QtWebEngine download is already running, it will report invalid (faster) download speed. BUG: 401661 FIXED-IN: 3.1.0 --- src/lib/downloads/downloaditem.cpp | 6 +++--- src/lib/downloads/downloaditem.h | 6 +++--- src/lib/downloads/downloadmanager.cpp | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/downloads/downloaditem.cpp b/src/lib/downloads/downloaditem.cpp index 61784e709..48400300b 100644 --- a/src/lib/downloads/downloaditem.cpp +++ b/src/lib/downloads/downloaditem.cpp @@ -74,8 +74,6 @@ DownloadItem::DownloadItem(QListWidgetItem *item, QWebEngineDownloadItem* downlo connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint))); connect(ui->button, SIGNAL(clicked(QPoint)), this, SLOT(stop())); connect(manager, SIGNAL(resized(QSize)), this, SLOT(parentResized(QSize))); - - startDownloading(); } void DownloadItem::startDownloading() @@ -84,7 +82,9 @@ void DownloadItem::startDownloading() connect(m_download, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItem::downloadProgress); m_downloading = true; - m_downTimer.start(); + if (m_downTimer.elapsed() < 1) { + m_downTimer.start(); + } updateDownloadInfo(0, m_download->receivedBytes(), m_download->totalBytes()); diff --git a/src/lib/downloads/downloaditem.h b/src/lib/downloads/downloaditem.h index 0fe2a7414..e59761dea 100644 --- a/src/lib/downloads/downloaditem.h +++ b/src/lib/downloads/downloaditem.h @@ -49,6 +49,9 @@ public: double currentSpeed() { return m_currSpeed; } int progress(); ~DownloadItem(); + void setDownTimer(const QTime &timer) { m_downTimer = timer; } + + void startDownloading(); static QString remaingTimeToString(QTime time); static QString currentSpeedToString(double speed); @@ -70,8 +73,6 @@ private Q_SLOTS: void copyDownloadLink(); private: - void startDownloading(); - void updateDownloadInfo(double currSpeed, qint64 received, qint64 total); void mouseDoubleClickEvent(QMouseEvent* e); @@ -83,7 +84,6 @@ private: QString m_fileName; QTime m_downTimer; QTime m_remTime; - QBasicTimer m_timer; QUrl m_downUrl; bool m_openFile; diff --git a/src/lib/downloads/downloadmanager.cpp b/src/lib/downloads/downloadmanager.cpp index b610b9e2d..7e108a33d 100644 --- a/src/lib/downloads/downloadmanager.cpp +++ b/src/lib/downloads/downloadmanager.cpp @@ -269,6 +269,9 @@ void DownloadManager::clearList() void DownloadManager::download(QWebEngineDownloadItem *downloadItem) { + QTime downloadTimer; + downloadTimer.start(); + closeDownloadTab(downloadItem->url()); QString downloadPath; @@ -373,6 +376,8 @@ void DownloadManager::download(QWebEngineDownloadItem *downloadItem) // Create download item QListWidgetItem* listItem = new QListWidgetItem(ui->list); DownloadItem* downItem = new DownloadItem(listItem, downloadItem, QFileInfo(downloadPath).absolutePath(), QFileInfo(downloadPath).fileName(), openFile, this); + downItem->setDownTimer(downloadTimer); + downItem->startDownloading(); connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*))); connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool))); ui->list->setItemWidget(listItem, downItem);