mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -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)
|
ContentManager::BookState ContentManager::getBookState(QString bookId)
|
||||||
{
|
{
|
||||||
if ( const auto downloadState = DownloadManager::getDownloadState(bookId) ) {
|
if ( const auto downloadState = DownloadManager::getDownloadState(bookId) ) {
|
||||||
return downloadState->paused
|
return downloadState->status == DownloadState::PAUSED
|
||||||
? BookState::DOWNLOAD_PAUSED
|
? BookState::DOWNLOAD_PAUSED
|
||||||
: BookState::DOWNLOADING;
|
: BookState::DOWNLOADING;
|
||||||
// TODO: a download may be in error state
|
// 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 completedLength = downloadInfo.completedLength;
|
||||||
auto downloadSpeed = downloadInfo.downloadSpeed;
|
auto downloadSpeed = downloadInfo.downloadSpeed;
|
||||||
|
|
||||||
if (downloadInfo.paused) {
|
if (downloadInfo.status == DownloadState::PAUSED) {
|
||||||
createResumeSymbol(painter, dcl.pauseResumeButtonRect);
|
createResumeSymbol(painter, dcl.pauseResumeButtonRect);
|
||||||
createCancelButton(painter, dcl.cancelButtonRect);
|
createCancelButton(painter, dcl.cancelButtonRect);
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,6 +26,15 @@ QString convertToUnits(double bytes)
|
|||||||
return preciseBytes + " " + units[unitIndex];
|
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
|
} // unnamed namespace
|
||||||
|
|
||||||
void DownloadState::update(const DownloadInfo& downloadInfos)
|
void DownloadState::update(const DownloadInfo& downloadInfos)
|
||||||
@ -35,8 +44,8 @@ void DownloadState::update(const DownloadInfo& downloadInfos)
|
|||||||
percent = QString::number(percent, 'g', 3).toDouble();
|
percent = QString::number(percent, 'g', 3).toDouble();
|
||||||
auto completedLength = convertToUnits(downloadInfos["completedLength"].toDouble());
|
auto completedLength = convertToUnits(downloadInfos["completedLength"].toDouble());
|
||||||
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toDouble()) + "/s";
|
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toDouble()) + "/s";
|
||||||
const bool paused = downloadInfos["status"] == "paused";
|
const auto status = getDownloadStatus(downloadInfos["status"].toString());
|
||||||
*this = {percent, completedLength, downloadSpeed, paused};
|
*this = {percent, completedLength, downloadSpeed, status};
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -85,7 +94,7 @@ void DownloadManager::restoreDownloads()
|
|||||||
const kiwix::Book& book = mp_library->getBookById(bookId);
|
const kiwix::Book& book = mp_library->getBookById(bookId);
|
||||||
if ( ! book.getDownloadId().empty() ) {
|
if ( ! book.getDownloadId().empty() ) {
|
||||||
const auto newDownload = std::make_shared<DownloadState>();
|
const auto newDownload = std::make_shared<DownloadState>();
|
||||||
newDownload->paused = true;
|
newDownload->status = DownloadState::UNKNOWN;
|
||||||
m_downloads.set(bookId, newDownload);
|
m_downloads.set(bookId, newDownload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,18 @@ typedef QMap<QString, QVariant> DownloadInfo;
|
|||||||
class DownloadState
|
class DownloadState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum Status {
|
||||||
|
UNKNOWN,
|
||||||
|
WAITING,
|
||||||
|
DOWNLOAD_ERROR,
|
||||||
|
DOWNLOADING,
|
||||||
|
PAUSED
|
||||||
|
};
|
||||||
|
|
||||||
double progress = 0;
|
double progress = 0;
|
||||||
QString completedLength;
|
QString completedLength;
|
||||||
QString downloadSpeed;
|
QString downloadSpeed;
|
||||||
bool paused = false;
|
Status status = UNKNOWN;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update(const DownloadInfo& info);
|
void update(const DownloadInfo& info);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user