mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 03:26:05 -04:00
ContentManagerModel::Downloads became a class
... only one small step away from being thread-safe
This commit is contained in:
parent
728a8a44bb
commit
c042532a8c
@ -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 )
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user