mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Merged ::DownloadInfo into DownloadState
This commit is contained in:
parent
8e3a783700
commit
a6359af1ab
@ -163,7 +163,7 @@ void ContentManager::onCustomContextMenu(const QPoint &point)
|
|||||||
QAction menuOpenFolder(gt("open-folder"), this);
|
QAction menuOpenFolder(gt("open-folder"), this);
|
||||||
|
|
||||||
if (const auto download = bookNode->getDownloadState()) {
|
if (const auto download = bookNode->getDownloadState()) {
|
||||||
if (download->getDownloadInfo().paused) {
|
if (download->paused) {
|
||||||
contextMenu.addAction(&menuResumeBook);
|
contextMenu.addAction(&menuResumeBook);
|
||||||
} else {
|
} else {
|
||||||
contextMenu.addAction(&menuPauseBook);
|
contextMenu.addAction(&menuPauseBook);
|
||||||
@ -483,7 +483,7 @@ ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString bookId,
|
|||||||
void ContentManager::updateDownload(QString bookId)
|
void ContentManager::updateDownload(QString bookId)
|
||||||
{
|
{
|
||||||
const auto downloadState = m_downloads.value(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
|
// This calls ContentManager::updateDownloadInfos() in a convoluted way
|
||||||
// and also has some other side-effects
|
// and also has some other side-effects
|
||||||
managerModel->updateDownload(bookId);
|
managerModel->updateDownload(bookId);
|
||||||
|
@ -20,7 +20,6 @@ public: // types
|
|||||||
typedef ContentManagerModel::BookInfo BookInfo;
|
typedef ContentManagerModel::BookInfo BookInfo;
|
||||||
typedef ContentManagerModel::BookInfoList BookInfoList;
|
typedef ContentManagerModel::BookInfoList BookInfoList;
|
||||||
|
|
||||||
// XXX: potentional source of confusion with ::DownloadInfo from rownode.h
|
|
||||||
typedef QMap<QString, QVariant> DownloadInfo;
|
typedef QMap<QString, QVariant> DownloadInfo;
|
||||||
|
|
||||||
public: // functions
|
public: // functions
|
||||||
|
@ -103,7 +103,7 @@ void createDownloadStats(QPainter *painter, QRect box, QString downloadSpeed, QS
|
|||||||
painter->setFont(oldFont);
|
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;
|
int x,y,w,h;
|
||||||
x = box.left();
|
x = box.left();
|
||||||
@ -178,8 +178,7 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||||||
QStyleOptionViewItem eOpt = option;
|
QStyleOptionViewItem eOpt = option;
|
||||||
if (index.column() == 5) {
|
if (index.column() == 5) {
|
||||||
if (const auto downloadState = node->getDownloadState()) {
|
if (const auto downloadState = node->getDownloadState()) {
|
||||||
auto downloadInfo = downloadState->getDownloadInfo();
|
showDownloadProgress(painter, r, *downloadState);
|
||||||
showDownloadProgress(painter, r, downloadInfo);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
baseButton->style()->drawControl( QStyle::CE_PushButton, &button, painter, baseButton.data());
|
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();
|
int w = r.width();
|
||||||
|
|
||||||
if (const auto downloadState = node->getDownloadState()) {
|
if (const auto downloadState = node->getDownloadState()) {
|
||||||
if (downloadState->getDownloadInfo().paused) {
|
if (downloadState->paused) {
|
||||||
if (clickX < (x + w/2)) {
|
if (clickX < (x + w/2)) {
|
||||||
KiwixApp::instance()->getContentManager()->cancelBook(id, index);
|
KiwixApp::instance()->getContentManager()->cancelBook(id, index);
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,11 +7,6 @@
|
|||||||
// DowloadState
|
// DowloadState
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
DownloadState::DownloadState()
|
|
||||||
: m_downloadInfo({0, "", "", false})
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -35,7 +30,7 @@ bool DownloadState::update(QString id)
|
|||||||
{
|
{
|
||||||
auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(id, {"status", "completedLength", "totalLength", "downloadSpeed"});
|
auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(id, {"status", "completedLength", "totalLength", "downloadSpeed"});
|
||||||
if (!downloadInfos["status"].isValid()) {
|
if (!downloadInfos["status"].isValid()) {
|
||||||
m_downloadInfo = {0, "", "", false};
|
*this = {0, "", "", false};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,18 +39,18 @@ bool DownloadState::update(QString id)
|
|||||||
percent = QString::number(percent, 'g', 3).toDouble();
|
percent = QString::number(percent, 'g', 3).toDouble();
|
||||||
auto completedLength = convertToUnits(downloadInfos["completedLength"].toString());
|
auto completedLength = convertToUnits(downloadInfos["completedLength"].toString());
|
||||||
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toString()) + "/s";
|
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toString()) + "/s";
|
||||||
m_downloadInfo = {percent, completedLength, downloadSpeed, false};
|
*this = {percent, completedLength, downloadSpeed, false};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadState::pause()
|
void DownloadState::pause()
|
||||||
{
|
{
|
||||||
m_downloadInfo.paused = true;
|
this->paused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadState::resume()
|
void DownloadState::resume()
|
||||||
{
|
{
|
||||||
m_downloadInfo.paused = false;
|
this->paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,26 +6,18 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include "kiwix/book.h"
|
#include "kiwix/book.h"
|
||||||
|
|
||||||
struct DownloadInfo
|
|
||||||
{
|
|
||||||
double progress;
|
|
||||||
QString completedLength;
|
|
||||||
QString downloadSpeed;
|
|
||||||
bool paused;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DownloadState
|
class DownloadState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DownloadState();
|
double progress = 0;
|
||||||
|
QString completedLength;
|
||||||
|
QString downloadSpeed;
|
||||||
|
bool paused = false;
|
||||||
|
|
||||||
DownloadInfo getDownloadInfo() const { return m_downloadInfo; }
|
public:
|
||||||
void pause();
|
void pause();
|
||||||
void resume();
|
void resume();
|
||||||
bool update(QString id);
|
bool update(QString id);
|
||||||
|
|
||||||
protected:
|
|
||||||
DownloadInfo m_downloadInfo;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RowNode : public Node
|
class RowNode : public Node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user