Got rid of ContentManagerModel::startDownload()

Inlined ContentManagerModel::startDownload() into
ContentManager::downloadBook().
This commit is contained in:
Veloman Yunkan 2024-02-09 18:54:14 +04:00
parent 6ba6ad0ee8
commit b53042edd5
3 changed files with 19 additions and 23 deletions

View File

@ -476,12 +476,29 @@ ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString bookId,
return result;
}
namespace
{
std::shared_ptr<RowNode> getSharedPointer(RowNode* ptr)
{
return std::static_pointer_cast<RowNode>(ptr->shared_from_this());
}
} // unnamed namespace
void ContentManager::downloadBook(const QString &id, QModelIndex index)
{
try
{
downloadBook(id);
emit managerModel->startDownload(index);
auto node = getSharedPointer(static_cast<RowNode*>(index.internalPointer()));
const auto newDownload = std::make_shared<DownloadState>();
m_downloads[id] = newDownload;
node->setDownloadState(newDownload);
QTimer *timer = newDownload->getDownloadUpdateTimer();
connect(timer, &QTimer::timeout, [=]() {
managerModel->updateDownload(id);
});
}
catch ( const ContentManagerError& err )
{

View File

@ -245,24 +245,6 @@ void ContentManagerModel::updateImage(QString bookId, QString url, QByteArray im
emit dataChanged(index, index);
}
std::shared_ptr<RowNode> getSharedPointer(RowNode* ptr)
{
return std::static_pointer_cast<RowNode>(ptr->shared_from_this());
}
void ContentManagerModel::startDownload(QModelIndex index)
{
auto node = getSharedPointer(static_cast<RowNode*>(index.internalPointer()));
const auto bookId = node->getBookId();
const auto newDownload = std::make_shared<DownloadState>();
m_downloads[bookId] = newDownload;
node->setDownloadState(newDownload);
QTimer *timer = newDownload->getDownloadUpdateTimer();
connect(timer, &QTimer::timeout, this, [=]() {
updateDownload(bookId);
});
}
void ContentManagerModel::updateDownload(QString bookId)
{
const auto download = m_downloads.value(bookId);

View File

@ -47,18 +47,15 @@ public: // functions
public slots:
void updateImage(QString bookId, QString url, QByteArray imageData);
void startDownload(QModelIndex index);
void pauseDownload(QModelIndex index);
void resumeDownload(QModelIndex index);
void cancelDownload(QModelIndex index);
void updateDownload(QString bookId);
protected: // functions
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
private: // functions
void updateDownload(QString bookId);
private: // data
BookInfoList m_data;
std::shared_ptr<RowNode> rootNode;