mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-20 18:33:38 -04:00
Dropped ContentManagerModel::m_downloads
ContentManagerModel is explicitly given access to the list of active downloads during calls to ContentManagerModel::setBooksData(). This limits by design the time when the list of downloads can be accessed and facilitates making it thread-safe.
This commit is contained in:
parent
ef1b36fd28
commit
90603190fe
@ -90,7 +90,7 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
||||
// mp_view will be passed to the tab who will take ownership,
|
||||
// so, we don't need to delete it.
|
||||
mp_view = new ContentManagerView();
|
||||
managerModel = new ContentManagerModel(&m_downloads, this);
|
||||
managerModel = new ContentManagerModel(this);
|
||||
updateModel();
|
||||
auto treeView = mp_view->getView();
|
||||
treeView->setModel(managerModel);
|
||||
@ -145,7 +145,7 @@ void ContentManager::updateModel()
|
||||
auto mp = getBookInfos(bookId, keys);
|
||||
bookList.append(mp);
|
||||
}
|
||||
managerModel->setBooksData(bookList);
|
||||
managerModel->setBooksData(bookList, m_downloads);
|
||||
}
|
||||
|
||||
void ContentManager::onCustomContextMenu(const QPoint &point)
|
||||
|
@ -7,9 +7,8 @@
|
||||
#include "kiwixapp.h"
|
||||
#include <kiwix/tools.h>
|
||||
|
||||
ContentManagerModel::ContentManagerModel(const Downloads* downloads, QObject *parent)
|
||||
ContentManagerModel::ContentManagerModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, m_downloads(*downloads)
|
||||
{
|
||||
connect(&td, &ThumbnailDownloader::oneThumbnailDownloaded, this, &ContentManagerModel::updateImage);
|
||||
}
|
||||
@ -112,11 +111,11 @@ QVariant ContentManagerModel::headerData(int section, Qt::Orientation orientatio
|
||||
}
|
||||
}
|
||||
|
||||
void ContentManagerModel::setBooksData(const BookInfoList& data)
|
||||
void ContentManagerModel::setBooksData(const BookInfoList& data, const Downloads& downloads)
|
||||
{
|
||||
m_data = data;
|
||||
rootNode = std::shared_ptr<RowNode>(new RowNode({tr("Icon"), tr("Name"), tr("Date"), tr("Size"), tr("Content Type"), tr("Download")}, "", std::weak_ptr<RowNode>()));
|
||||
setupNodes();
|
||||
setupNodes(downloads);
|
||||
emit dataChanged(QModelIndex(), QModelIndex());
|
||||
}
|
||||
|
||||
@ -151,7 +150,7 @@ std::shared_ptr<RowNode> ContentManagerModel::createNode(BookInfo bookItem) cons
|
||||
return rowNodePtr;
|
||||
}
|
||||
|
||||
void ContentManagerModel::setupNodes()
|
||||
void ContentManagerModel::setupNodes(const Downloads& downloads)
|
||||
{
|
||||
beginResetModel();
|
||||
bookIdToRowMap.clear();
|
||||
@ -159,8 +158,8 @@ void ContentManagerModel::setupNodes()
|
||||
const auto rowNode = createNode(bookItem);
|
||||
|
||||
// Restore download state during model updates (filtering, etc)
|
||||
const auto downloadIter = m_downloads.constFind(rowNode->getBookId());
|
||||
if ( downloadIter != m_downloads.constEnd() ) {
|
||||
const auto downloadIter = downloads.constFind(rowNode->getBookId());
|
||||
if ( downloadIter != downloads.constEnd() ) {
|
||||
rowNode->setDownloadState(downloadIter.value());
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public: // types
|
||||
typedef QMap<QString, std::shared_ptr<DownloadState>> Downloads;
|
||||
|
||||
public: // functions
|
||||
ContentManagerModel(const Downloads* downloads, QObject *parent = nullptr);
|
||||
explicit ContentManagerModel(QObject *parent = nullptr);
|
||||
~ContentManagerModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
@ -37,8 +37,8 @@ public: // functions
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
void setBooksData(const BookInfoList& data);
|
||||
void setupNodes();
|
||||
void setBooksData(const BookInfoList& data, const Downloads& downloads);
|
||||
void setupNodes(const Downloads& downloads);
|
||||
bool hasChildren(const QModelIndex &parent) const override;
|
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
|
||||
@ -63,7 +63,6 @@ private: // data
|
||||
mutable ThumbnailDownloader td;
|
||||
QMap<QString, size_t> bookIdToRowMap;
|
||||
QMap<QString, QByteArray> m_iconMap;
|
||||
const Downloads& m_downloads;
|
||||
};
|
||||
|
||||
#endif // CONTENTMANAGERMODEL_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user