mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -04:00
Moved ownership of download state to ContentManager
ContentManagerModel depends on the current view settings (filters) much more than ContentManager does. Since the download state (the set of active and/or paused downloads and their progress info) is independent of the view settings it is more natural for ContentManager to own it.
This commit is contained in:
parent
b0b592dfd8
commit
a1c60d8dbe
@ -53,7 +53,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(this);
|
||||
managerModel = new ContentManagerModel(&m_downloads, this);
|
||||
const auto booksList = getBooksList();
|
||||
managerModel->setBooksData(booksList);
|
||||
auto treeView = mp_view->getView();
|
||||
|
@ -44,6 +44,7 @@ private:
|
||||
Library* mp_library;
|
||||
kiwix::LibraryPtr mp_remoteLibrary;
|
||||
kiwix::Downloader* mp_downloader;
|
||||
ContentManagerModel::Downloads m_downloads;
|
||||
OpdsRequestManager m_remoteLibraryManager;
|
||||
ContentManagerView* mp_view;
|
||||
bool m_local = true;
|
||||
@ -61,8 +62,10 @@ private:
|
||||
void reallyEraseBook(const QString& id, bool moveToTrash);
|
||||
void eraseBookFilesFromComputer(const QString dirPath, const QString filename, const bool moveToTrash);
|
||||
BookInfoList getBooksList();
|
||||
|
||||
ContentManagerModel *managerModel;
|
||||
QMutex remoteLibraryLocker;
|
||||
|
||||
void setCategories();
|
||||
void setLanguages();
|
||||
|
||||
|
@ -7,8 +7,9 @@
|
||||
#include "kiwixapp.h"
|
||||
#include <kiwix/tools.h>
|
||||
|
||||
ContentManagerModel::ContentManagerModel(QObject *parent)
|
||||
ContentManagerModel::ContentManagerModel(Downloads* downloads, QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, m_downloads(*downloads)
|
||||
{
|
||||
connect(&td, &ThumbnailDownloader::oneThumbnailDownloaded, this, &ContentManagerModel::updateImage);
|
||||
}
|
||||
|
@ -21,8 +21,11 @@ public: // types
|
||||
typedef QMap<QString, QVariant> BookInfo;
|
||||
typedef QList<BookInfo> BookInfoList;
|
||||
|
||||
// BookId -> DownloadState map
|
||||
typedef QMap<QString, std::shared_ptr<DownloadState>> Downloads;
|
||||
|
||||
public: // functions
|
||||
explicit ContentManagerModel(QObject *parent = nullptr);
|
||||
ContentManagerModel(Downloads* downloads, QObject *parent = nullptr);
|
||||
~ContentManagerModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
@ -63,7 +66,7 @@ private: // data
|
||||
ThumbnailDownloader td;
|
||||
QMap<QString, size_t> bookIdToRowMap;
|
||||
QMap<QString, QByteArray> iconMap;
|
||||
QMap<QString, std::shared_ptr<DownloadState>> m_downloads;
|
||||
Downloads& m_downloads;
|
||||
};
|
||||
|
||||
#endif // CONTENTMANAGERMODEL_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user