ContentManagerModel::Downloads became a class

... only one small step away from being thread-safe
This commit is contained in:
Veloman Yunkan 2024-03-01 19:36:03 +04:00
parent 728a8a44bb
commit c042532a8c
2 changed files with 28 additions and 2 deletions

View File

@ -543,7 +543,7 @@ void ContentManager::downloadBook(const QString &id, QModelIndex index)
downloadBook(id);
auto node = getSharedPointer(static_cast<RowNode*>(index.internalPointer()));
const auto newDownload = std::make_shared<DownloadState>();
m_downloads[id] = newDownload;
m_downloads.set(id, newDownload);
node->setDownloadState(newDownload);
}
catch ( const ContentManagerError& err )

View File

@ -22,7 +22,33 @@ public: // types
typedef QList<BookInfo> BookInfoList;
// BookId -> DownloadState map
typedef QMap<QString, std::shared_ptr<DownloadState>> Downloads;
class Downloads
{
private:
typedef std::shared_ptr<DownloadState> DownloadStatePtr;
typedef QMap<QString, DownloadStatePtr> ImplType;
public:
void set(const QString& id, DownloadStatePtr d) {
impl[id] = d;
}
DownloadStatePtr value(const QString& id) const {
return impl.value(id);
}
QList<QString> keys() const {
return impl.keys();
}
void remove(const QString& id) {
impl.remove(id);
}
private:
ImplType impl;
};
public: // functions
explicit ContentManagerModel(QObject *parent = nullptr);