From 47a80e2b2a585b16c496414eddeee7a05f836c2c Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 8 Mar 2012 12:48:23 +0100 Subject: [PATCH] Fixed showing bad total + downloaded size when starting download. --- src/lib/downloads/downloadfilehelper.cpp | 7 ++++--- src/lib/downloads/downloadfilehelper.h | 1 + src/lib/downloads/downloaditem.cpp | 9 +++++++++ src/lib/downloads/downloaditem.h | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lib/downloads/downloadfilehelper.cpp b/src/lib/downloads/downloadfilehelper.cpp index 1858955f6..37bae7ded 100644 --- a/src/lib/downloads/downloadfilehelper.cpp +++ b/src/lib/downloads/downloadfilehelper.cpp @@ -72,9 +72,9 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool ask m_fileIcon = m_iconProvider->icon(tempInfo).pixmap(30, 30); QString mimeType = m_iconProvider->type(tempInfo); - qint64 size = m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(); - if (size > 0) { - mimeType.append(QString(" (%1)").arg(DownloadItem::fileSizeToString(size))); + m_fileSize = m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(); + if (m_fileSize > 0) { + mimeType.append(QString(" (%1)").arg(DownloadItem::fileSizeToString(m_fileSize))); } // Close Empty Tab @@ -226,6 +226,7 @@ void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoG QListWidgetItem* item = new QListWidgetItem(m_listWidget); DownloadItem* downItem = new DownloadItem(item, m_reply, m_path, m_fileName, m_fileIcon, m_timer, m_openFileChoosed, m_downloadPage, m_manager); + downItem->setTotalSize(m_fileSize); emit itemCreated(item, downItem); } diff --git a/src/lib/downloads/downloadfilehelper.h b/src/lib/downloads/downloadfilehelper.h index 38e503369..2b5cfb957 100644 --- a/src/lib/downloads/downloadfilehelper.h +++ b/src/lib/downloads/downloadfilehelper.h @@ -68,6 +68,7 @@ private: QNetworkReply* m_reply; QPixmap m_fileIcon; QUrl m_downloadPage; + qint64 m_fileSize; bool m_openFileChoosed; QListWidget* m_listWidget; diff --git a/src/lib/downloads/downloaditem.cpp b/src/lib/downloads/downloaditem.cpp index aa5edc4fa..3b552c92a 100644 --- a/src/lib/downloads/downloaditem.cpp +++ b/src/lib/downloads/downloaditem.cpp @@ -49,6 +49,8 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QS , m_downloading(false) , m_openAfterFinish(openAfterFinishedDownload) , m_downloadStopped(false) + , m_received(0) + , m_total(0) { #ifdef DOWNMANAGER_DEBUG qDebug() << __FUNCTION__ << item << reply << path << fileName; @@ -76,6 +78,13 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QS startDownloading(); } +void DownloadItem::setTotalSize(qint64 total) +{ + if (total > 0) { + m_total = total; + } +} + void DownloadItem::startDownloading() { QUrl locationHeader = m_reply->header(QNetworkRequest::LocationHeader).toUrl(); diff --git a/src/lib/downloads/downloaditem.h b/src/lib/downloads/downloaditem.h index e76877356..ed7e2f463 100644 --- a/src/lib/downloads/downloaditem.h +++ b/src/lib/downloads/downloaditem.h @@ -49,6 +49,8 @@ public: int progress(); ~DownloadItem(); + void setTotalSize(qint64 total); + static QString remaingTimeToString(QTime time); static QString currentSpeedToString(double speed); static QString fileSizeToString(qint64 size);