mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -04:00
ContentManager::refreshIcons() works off RowNode data
This enables the following changes (to be done next): 1. move the thumbnail download initiation into the data access operation. 2. get rid of ContentManagerModel::refreshIcons() 3. get rid of ContentManagerModel::m_data
This commit is contained in:
parent
f68ae6d2f8
commit
6a1fc8a78e
@ -175,12 +175,12 @@ void ContentManagerModel::refreshIcons()
|
||||
return;
|
||||
td.clearQueue();
|
||||
for (auto i = 0; i < rowCount() && i < m_data.size(); i++) {
|
||||
const auto& bookItem = m_data[i];
|
||||
const QVariant favicon = bookItem["favicon"];
|
||||
auto& rowNode = *getRowNode(i);
|
||||
const QVariant favicon = rowNode.data(0);
|
||||
if ( favicon.type() == QVariant::String ) {
|
||||
const auto faviconUrl = favicon.toString();
|
||||
if (faviconUrl != "" && !m_iconMap.contains(faviconUrl)) {
|
||||
td.addDownload(faviconUrl, bookItem["id"].toString());
|
||||
td.addDownload(faviconUrl, rowNode.getBookId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -235,6 +235,11 @@ void ContentManagerModel::sort(int column, Qt::SortOrder order)
|
||||
KiwixApp::instance()->getContentManager()->setSortBy(sortBy, order == Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
RowNode* ContentManagerModel::getRowNode(size_t row)
|
||||
{
|
||||
return static_cast<RowNode*>(rootNode->child(row).get());
|
||||
}
|
||||
|
||||
void ContentManagerModel::updateImage(QString bookId, QString url, QByteArray imageData)
|
||||
{
|
||||
const auto it = bookIdToRowMap.constFind(bookId);
|
||||
@ -242,7 +247,7 @@ void ContentManagerModel::updateImage(QString bookId, QString url, QByteArray im
|
||||
return;
|
||||
|
||||
const size_t row = it.value();
|
||||
const auto item = static_cast<RowNode*>(rootNode->child(row).get());
|
||||
const auto item = getRowNode(row);
|
||||
item->setIconData(imageData);
|
||||
m_iconMap[url] = imageData;
|
||||
const QModelIndex index = this->index(row, 0);
|
||||
@ -278,8 +283,7 @@ void ContentManagerModel::removeDownload(QString bookId)
|
||||
return;
|
||||
|
||||
const size_t row = it.value();
|
||||
auto& node = static_cast<RowNode&>(*rootNode->child(row));
|
||||
node.setDownloadState(nullptr);
|
||||
getRowNode(row)->setDownloadState(nullptr);
|
||||
const QModelIndex index = this->index(row, 5);
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ private: // functions
|
||||
// Returns either data of the thumbnail (as a QByteArray) or a URL (as a
|
||||
// QString) from where the actual data can be obtained.
|
||||
QVariant getThumbnail(const BookInfo& bookItem) const;
|
||||
RowNode* getRowNode(size_t row);
|
||||
|
||||
private: // data
|
||||
BookInfoList m_data;
|
||||
|
Loading…
x
Reference in New Issue
Block a user