Temporary commit

This commit is contained in:
RigoLigoRLC
2022-01-26 16:50:55 +08:00
parent 974d0032e3
commit 02530de7da
19 changed files with 409 additions and 91 deletions

View File

@@ -1,6 +1,8 @@

#include "spkdownloadentry.h"
#include "spklogging.h"
#include "spkutils.h"
#include <QDebug>
constexpr QSize SpkDownloadEntry::IconSize;
@@ -37,6 +39,8 @@ SpkDownloadEntry::SpkDownloadEntry(QWidget *parent)
mLayMain->addWidget(mBtnDelete);
setLayout(mLayMain);
mLastReportTime = QTime::currentTime();
}
@@ -45,13 +49,20 @@ SpkDownloadEntry::~SpkDownloadEntry()
// TODO
}
void SpkDownloadEntry::SetTotalBytes(qint64 total)
{
mTotalBytes = total;
mReadableTotalSize = SpkUtils::BytesToSize(total);
mLastReportTime = QTime::currentTime();
}
void SpkDownloadEntry::SetBasicInfo(QString name, QPixmap icon)
{
mAppName->setText(name);
mIcon->setPixmap(icon.scaled(IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
void SpkDownloadEntry::SetStatus(DownloadEntryStatus status)
void SpkDownloadEntry::SetStatus(DownloadEntryStatus status, QString msg)
{
switch(status)
{
@@ -73,7 +84,7 @@ void SpkDownloadEntry::SetStatus(DownloadEntryStatus status)
break;
case Failed:
mMessage->setText(tr("Download Failed"));
mMessage->setText(msg);
mProgress->setVisible(false);
break;
@@ -95,7 +106,7 @@ void SpkDownloadEntry::SetStatus(DownloadEntryStatus status)
break;
case InstallFailed:
mMessage->setText(tr("Install Failed"));
mMessage->setText(msg.isEmpty() ? tr("Install Failed") : msg);
mLoading->End();
mLoading->setVisible(false);
break;
@@ -105,7 +116,22 @@ void SpkDownloadEntry::SetStatus(DownloadEntryStatus status)
}
}
void SpkDownloadEntry::SetProgress(int p)
void SpkDownloadEntry::Progress(qint64 bytes)
{
mProgress->setValue(p);
auto now = QTime::currentTime();
auto msecDiff = mLastReportTime.msecsTo(now);
if(msecDiff != 0)
{
auto bytesPerSec = (bytes - mDownloadedBytes) / (msecDiff / 1000.0);
qDebug() << "Bytes" << bytes - mDownloadedBytes
<< "MsDiff" << msecDiff / 1000.0
<< "Bytes-Per-Seg" << bytesPerSec;
auto speedSize = SpkUtils::BytesToSize(static_cast<size_t>(bytesPerSec));
mMessage->setText(QString("%1/%2(%3/s)")
.arg(SpkUtils::BytesToSize(bytes), mReadableTotalSize, speedSize));
}
mDownloadedBytes = bytes;
mProgress->setValue(static_cast<int>(((double)bytes) / mTotalBytes * 1000));
mLastReportTime = now;
}