diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 15a2b16..297da37 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -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); diff --git a/src/contentmanager.h b/src/contentmanager.h index edce662..c441a6e 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -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 DownloadInfo; public: // functions diff --git a/src/contentmanagerdelegate.cpp b/src/contentmanagerdelegate.cpp index 8944026..7a9eddb 100644 --- a/src/contentmanagerdelegate.cpp +++ b/src/contentmanagerdelegate.cpp @@ -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 { diff --git a/src/rownode.cpp b/src/rownode.cpp index b2ad611..cea54b2 100644 --- a/src/rownode.cpp +++ b/src/rownode.cpp @@ -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; } diff --git a/src/rownode.h b/src/rownode.h index 62d9150..cea055f 100644 --- a/src/rownode.h +++ b/src/rownode.h @@ -6,26 +6,18 @@ #include #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