mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 19:46:12 -04:00
Got rid of ContentManagerModel::startDownload()
Inlined ContentManagerModel::startDownload() into ContentManager::downloadBook().
This commit is contained in:
parent
6ba6ad0ee8
commit
b53042edd5
@ -476,12 +476,29 @@ ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString bookId,
|
|||||||
return result;
|
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)
|
void ContentManager::downloadBook(const QString &id, QModelIndex index)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
downloadBook(id);
|
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 )
|
catch ( const ContentManagerError& err )
|
||||||
{
|
{
|
||||||
|
@ -245,24 +245,6 @@ void ContentManagerModel::updateImage(QString bookId, QString url, QByteArray im
|
|||||||
emit dataChanged(index, index);
|
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)
|
void ContentManagerModel::updateDownload(QString bookId)
|
||||||
{
|
{
|
||||||
const auto download = m_downloads.value(bookId);
|
const auto download = m_downloads.value(bookId);
|
||||||
|
@ -47,18 +47,15 @@ public: // functions
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateImage(QString bookId, QString url, QByteArray imageData);
|
void updateImage(QString bookId, QString url, QByteArray imageData);
|
||||||
void startDownload(QModelIndex index);
|
|
||||||
void pauseDownload(QModelIndex index);
|
void pauseDownload(QModelIndex index);
|
||||||
void resumeDownload(QModelIndex index);
|
void resumeDownload(QModelIndex index);
|
||||||
void cancelDownload(QModelIndex index);
|
void cancelDownload(QModelIndex index);
|
||||||
|
void updateDownload(QString bookId);
|
||||||
|
|
||||||
protected: // functions
|
protected: // functions
|
||||||
bool canFetchMore(const QModelIndex &parent) const override;
|
bool canFetchMore(const QModelIndex &parent) const override;
|
||||||
void fetchMore(const QModelIndex &parent) override;
|
void fetchMore(const QModelIndex &parent) override;
|
||||||
|
|
||||||
private: // functions
|
|
||||||
void updateDownload(QString bookId);
|
|
||||||
|
|
||||||
private: // data
|
private: // data
|
||||||
BookInfoList m_data;
|
BookInfoList m_data;
|
||||||
std::shared_ptr<RowNode> rootNode;
|
std::shared_ptr<RowNode> rootNode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user