Merged ::DownloadInfo into DownloadState

This commit is contained in:
Veloman Yunkan 2024-02-11 15:10:27 +04:00
parent 8e3a783700
commit a6359af1ab
5 changed files with 14 additions and 29 deletions

View File

@ -163,7 +163,7 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
QAction menuOpenFolder(gt("open-folder"), this);
if (const auto download = bookNode->getDownloadState()) {
if (download->getDownloadInfo().paused) {
if (download->paused) {
contextMenu.addAction(&menuResumeBook);
} else {
contextMenu.addAction(&menuPauseBook);
@ -483,7 +483,7 @@ ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString bookId,
void ContentManager::updateDownload(QString bookId)
{
const auto downloadState = m_downloads.value(bookId);
if ( downloadState && !downloadState->getDownloadInfo().paused ) {
if ( downloadState && !downloadState->paused ) {
// This calls ContentManager::updateDownloadInfos() in a convoluted way
// and also has some other side-effects
managerModel->updateDownload(bookId);

View File

@ -20,7 +20,6 @@ public: // types
typedef ContentManagerModel::BookInfo BookInfo;
typedef ContentManagerModel::BookInfoList BookInfoList;
// XXX: potentional source of confusion with ::DownloadInfo from rownode.h
typedef QMap<QString, QVariant> DownloadInfo;
public: // functions

View File

@ -103,7 +103,7 @@ void createDownloadStats(QPainter *painter, QRect box, QString downloadSpeed, QS
painter->setFont(oldFont);
}
void showDownloadProgress(QPainter *painter, QRect box, DownloadInfo downloadInfo)
void showDownloadProgress(QPainter *painter, QRect box, const DownloadState& downloadInfo)
{
int x,y,w,h;
x = box.left();
@ -178,8 +178,7 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem
QStyleOptionViewItem eOpt = option;
if (index.column() == 5) {
if (const auto downloadState = node->getDownloadState()) {
auto downloadInfo = downloadState->getDownloadInfo();
showDownloadProgress(painter, r, downloadInfo);
showDownloadProgress(painter, r, *downloadState);
}
else {
baseButton->style()->drawControl( QStyle::CE_PushButton, &button, painter, baseButton.data());
@ -245,7 +244,7 @@ void ContentManagerDelegate::handleLastColumnClicked(const QModelIndex& index, Q
int w = r.width();
if (const auto downloadState = node->getDownloadState()) {
if (downloadState->getDownloadInfo().paused) {
if (downloadState->paused) {
if (clickX < (x + w/2)) {
KiwixApp::instance()->getContentManager()->cancelBook(id, index);
} else {

View File

@ -7,11 +7,6 @@
// DowloadState
////////////////////////////////////////////////////////////////////////////////
DownloadState::DownloadState()
: m_downloadInfo({0, "", "", false})
{
}
namespace
{
@ -35,7 +30,7 @@ bool DownloadState::update(QString id)
{
auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(id, {"status", "completedLength", "totalLength", "downloadSpeed"});
if (!downloadInfos["status"].isValid()) {
m_downloadInfo = {0, "", "", false};
*this = {0, "", "", false};
return false;
}
@ -44,18 +39,18 @@ bool DownloadState::update(QString id)
percent = QString::number(percent, 'g', 3).toDouble();
auto completedLength = convertToUnits(downloadInfos["completedLength"].toString());
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toString()) + "/s";
m_downloadInfo = {percent, completedLength, downloadSpeed, false};
*this = {percent, completedLength, downloadSpeed, false};
return true;
}
void DownloadState::pause()
{
m_downloadInfo.paused = true;
this->paused = true;
}
void DownloadState::resume()
{
m_downloadInfo.paused = false;
this->paused = false;
}

View File

@ -6,26 +6,18 @@
#include <QIcon>
#include "kiwix/book.h"
struct DownloadInfo
{
double progress;
QString completedLength;
QString downloadSpeed;
bool paused;
};
class DownloadState
{
public:
DownloadState();
double progress = 0;
QString completedLength;
QString downloadSpeed;
bool paused = false;
DownloadInfo getDownloadInfo() const { return m_downloadInfo; }
public:
void pause();
void resume();
bool update(QString id);
protected:
DownloadInfo m_downloadInfo;
};
class RowNode : public Node