summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/downloadlistwidget.cpp4
-rw-r--r--src/downloadlistwidgetcompact.cpp3
-rw-r--r--src/downloadmanager.cpp30
-rw-r--r--src/downloadmanager.h4
4 files changed, 30 insertions, 11 deletions
diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp
index cb7a49c3..2af74cc2 100644
--- a/src/downloadlistwidget.cpp
+++ b/src/downloadlistwidget.cpp
@@ -53,6 +53,7 @@ DownloadListWidgetDelegate::DownloadListWidgetDelegate(DownloadManager *manager,
m_InstallLabel = m_ItemWidget->findChild<QLabel*>("installLabel");
m_InstallLabel->setVisible(false);
+ m_Progress->setTextVisible(true);
connect(manager, SIGNAL(stateChanged(int,DownloadManager::DownloadState)), this, SLOT(stateChanged(int,DownloadManager::DownloadState)));
connect(manager, SIGNAL(downloadRemoved(int)), this, SLOT(resetCache(int)));
@@ -159,7 +160,8 @@ void DownloadListWidgetDelegate::paintRegularDownload(int downloadIndex) const
} else {
m_InstallLabel->setVisible(false);
m_Progress->setVisible(true);
- m_Progress->setValue(m_Manager->getProgress(downloadIndex));
+ m_Progress->setValue(m_Manager->getProgress(downloadIndex).first);
+ m_Progress->setFormat(m_Manager->getProgress(downloadIndex).second);
}
}
diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp
index b390bff4..898d400a 100644
--- a/src/downloadlistwidgetcompact.cpp
+++ b/src/downloadlistwidgetcompact.cpp
@@ -138,7 +138,8 @@ void DownloadListWidgetCompactDelegate::paintRegularDownload(int downloadIndex)
} else {
m_DoneLabel->setVisible(false);
m_Progress->setVisible(true);
- m_Progress->setValue(m_Manager->getProgress(downloadIndex));
+ m_Progress->setValue(m_Manager->getProgress(downloadIndex).first);
+ m_Progress->setFormat(m_Manager->getProgress(downloadIndex).second);
}
}
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 77a4cf98..097a1168 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -62,7 +62,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const Mo
info->m_DownloadID = s_NextDownloadID++;
info->m_StartTime.start();
info->m_PreResumeSize = 0LL;
- info->m_Progress = 0;
+ info->m_Progress = std::make_pair<int, QString>(0, "0 bytes/sec");
info->m_ResumePos = 0;
info->m_FileInfo = new ModRepositoryFileInfo(*fileInfo);
info->m_Urls = URLs;
@@ -852,7 +852,7 @@ qint64 DownloadManager::getFileSize(int index) const
}
-int DownloadManager::getProgress(int index) const
+std::pair<int, QString> DownloadManager::getProgress(int index) const
{
if ((index < 0) || (index >= m_ActiveDownloads.size())) {
throw MyException(tr("progress: invalid download index %1").arg(index));
@@ -1076,12 +1076,28 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
if (bytesTotal > info->m_TotalSize) {
info->m_TotalSize = bytesTotal;
}
- int oldProgress = info->m_Progress;
- info->m_Progress = ((info->m_ResumePos + bytesReceived) * 100) / (info->m_ResumePos + bytesTotal);
- TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal);
- if (oldProgress != info->m_Progress) {
- emit update(index);
+ int oldProgress = info->m_Progress.first;
+ info->m_Progress.first = ((info->m_ResumePos + bytesReceived) * 100) / (info->m_ResumePos + bytesTotal);
+
+ // calculate the download speed
+ double speed = bytesReceived * 1000.0 / info->m_StartTime.elapsed();
+ QString unit;
+ if (speed < 1024) {
+ unit = "bytes/sec";
+ }
+ else if (speed < 1024 * 1024) {
+ speed /= 1024;
+ unit = "kB/s";
+ }
+ else {
+ speed /= 1024 * 1024;
+ unit = "MB/s";
}
+
+ info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(speed, 3, 'f', 1).arg(unit);
+
+ TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal);
+ emit update(index);
}
}
} catch (const std::bad_alloc&) {
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 308d365b..0ff77011 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -75,7 +75,7 @@ private:
QNetworkReply *m_Reply;
QTime m_StartTime;
qint64 m_PreResumeSize;
- int m_Progress;
+ std::pair<int, QString> m_Progress;
DownloadState m_State;
int m_CurrentUrl;
QStringList m_Urls;
@@ -259,7 +259,7 @@ public:
* @param index index of the file to look up
* @return progress of the download in percent (integer)
**/
- int getProgress(int index) const;
+ std::pair<int, QString> getProgress(int index) const;
/**
* @brief retrieve the current state of the download