mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-21 02:51:26 -04:00
Enter DownloadState::Status
The binary flag DownloadState::paused was replaced with a richer DownloadState::status but the old logic of distinguishing only between active and paused downloads still remains.
This commit is contained in:
parent
e42a83dae6
commit
e86324d242
@ -379,7 +379,7 @@ ContentManager::BookInfo ContentManager::getBookInfos(QString id, const QStringL
|
||||
ContentManager::BookState ContentManager::getBookState(QString bookId)
|
||||
{
|
||||
if ( const auto downloadState = DownloadManager::getDownloadState(bookId) ) {
|
||||
return downloadState->paused
|
||||
return downloadState->status == DownloadState::PAUSED
|
||||
? BookState::DOWNLOAD_PAUSED
|
||||
: BookState::DOWNLOADING;
|
||||
// TODO: a download may be in error state
|
||||
|
@ -131,7 +131,7 @@ void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& dow
|
||||
auto completedLength = downloadInfo.completedLength;
|
||||
auto downloadSpeed = downloadInfo.downloadSpeed;
|
||||
|
||||
if (downloadInfo.paused) {
|
||||
if (downloadInfo.status == DownloadState::PAUSED) {
|
||||
createResumeSymbol(painter, dcl.pauseResumeButtonRect);
|
||||
createCancelButton(painter, dcl.cancelButtonRect);
|
||||
} else {
|
||||
|
@ -26,6 +26,15 @@ QString convertToUnits(double bytes)
|
||||
return preciseBytes + " " + units[unitIndex];
|
||||
}
|
||||
|
||||
DownloadState::Status getDownloadStatus(QString status)
|
||||
{
|
||||
if ( status == "active" ) return DownloadState::DOWNLOADING;
|
||||
if ( status == "paused" ) return DownloadState::PAUSED;
|
||||
if ( status == "waiting" ) return DownloadState::WAITING;
|
||||
if ( status == "error" ) return DownloadState::DOWNLOAD_ERROR;
|
||||
return DownloadState::UNKNOWN;
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
void DownloadState::update(const DownloadInfo& downloadInfos)
|
||||
@ -35,8 +44,8 @@ void DownloadState::update(const DownloadInfo& downloadInfos)
|
||||
percent = QString::number(percent, 'g', 3).toDouble();
|
||||
auto completedLength = convertToUnits(downloadInfos["completedLength"].toDouble());
|
||||
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toDouble()) + "/s";
|
||||
const bool paused = downloadInfos["status"] == "paused";
|
||||
*this = {percent, completedLength, downloadSpeed, paused};
|
||||
const auto status = getDownloadStatus(downloadInfos["status"].toString());
|
||||
*this = {percent, completedLength, downloadSpeed, status};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -85,7 +94,7 @@ void DownloadManager::restoreDownloads()
|
||||
const kiwix::Book& book = mp_library->getBookById(bookId);
|
||||
if ( ! book.getDownloadId().empty() ) {
|
||||
const auto newDownload = std::make_shared<DownloadState>();
|
||||
newDownload->paused = true;
|
||||
newDownload->status = DownloadState::UNKNOWN;
|
||||
m_downloads.set(bookId, newDownload);
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,18 @@ typedef QMap<QString, QVariant> DownloadInfo;
|
||||
class DownloadState
|
||||
{
|
||||
public:
|
||||
enum Status {
|
||||
UNKNOWN,
|
||||
WAITING,
|
||||
DOWNLOAD_ERROR,
|
||||
DOWNLOADING,
|
||||
PAUSED
|
||||
};
|
||||
|
||||
double progress = 0;
|
||||
QString completedLength;
|
||||
QString downloadSpeed;
|
||||
bool paused = false;
|
||||
Status status = UNKNOWN;
|
||||
|
||||
public:
|
||||
void update(const DownloadInfo& info);
|
||||
|
Loading…
x
Reference in New Issue
Block a user