mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -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,
|
// mp_view will be passed to the tab who will take ownership,
|
||||||
// so, we don't need to delete it.
|
// so, we don't need to delete it.
|
||||||
mp_view = new ContentManagerView();
|
mp_view = new ContentManagerView();
|
||||||
managerModel = new ContentManagerModel(this);
|
managerModel = new ContentManagerModel(&m_downloads, this);
|
||||||
const auto booksList = getBooksList();
|
const auto booksList = getBooksList();
|
||||||
managerModel->setBooksData(booksList);
|
managerModel->setBooksData(booksList);
|
||||||
auto treeView = mp_view->getView();
|
auto treeView = mp_view->getView();
|
||||||
|
@ -44,6 +44,7 @@ private:
|
|||||||
Library* mp_library;
|
Library* mp_library;
|
||||||
kiwix::LibraryPtr mp_remoteLibrary;
|
kiwix::LibraryPtr mp_remoteLibrary;
|
||||||
kiwix::Downloader* mp_downloader;
|
kiwix::Downloader* mp_downloader;
|
||||||
|
ContentManagerModel::Downloads m_downloads;
|
||||||
OpdsRequestManager m_remoteLibraryManager;
|
OpdsRequestManager m_remoteLibraryManager;
|
||||||
ContentManagerView* mp_view;
|
ContentManagerView* mp_view;
|
||||||
bool m_local = true;
|
bool m_local = true;
|
||||||
@ -61,8 +62,10 @@ private:
|
|||||||
void reallyEraseBook(const QString& id, bool moveToTrash);
|
void reallyEraseBook(const QString& id, bool moveToTrash);
|
||||||
void eraseBookFilesFromComputer(const QString dirPath, const QString filename, const bool moveToTrash);
|
void eraseBookFilesFromComputer(const QString dirPath, const QString filename, const bool moveToTrash);
|
||||||
BookInfoList getBooksList();
|
BookInfoList getBooksList();
|
||||||
|
|
||||||
ContentManagerModel *managerModel;
|
ContentManagerModel *managerModel;
|
||||||
QMutex remoteLibraryLocker;
|
QMutex remoteLibraryLocker;
|
||||||
|
|
||||||
void setCategories();
|
void setCategories();
|
||||||
void setLanguages();
|
void setLanguages();
|
||||||
|
|
||||||
|
@ -7,8 +7,9 @@
|
|||||||
#include "kiwixapp.h"
|
#include "kiwixapp.h"
|
||||||
#include <kiwix/tools.h>
|
#include <kiwix/tools.h>
|
||||||
|
|
||||||
ContentManagerModel::ContentManagerModel(QObject *parent)
|
ContentManagerModel::ContentManagerModel(Downloads* downloads, QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
|
, m_downloads(*downloads)
|
||||||
{
|
{
|
||||||
connect(&td, &ThumbnailDownloader::oneThumbnailDownloaded, this, &ContentManagerModel::updateImage);
|
connect(&td, &ThumbnailDownloader::oneThumbnailDownloaded, this, &ContentManagerModel::updateImage);
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,11 @@ public: // types
|
|||||||
typedef QMap<QString, QVariant> BookInfo;
|
typedef QMap<QString, QVariant> BookInfo;
|
||||||
typedef QList<BookInfo> BookInfoList;
|
typedef QList<BookInfo> BookInfoList;
|
||||||
|
|
||||||
|
// BookId -> DownloadState map
|
||||||
|
typedef QMap<QString, std::shared_ptr<DownloadState>> Downloads;
|
||||||
|
|
||||||
public: // functions
|
public: // functions
|
||||||
explicit ContentManagerModel(QObject *parent = nullptr);
|
ContentManagerModel(Downloads* downloads, QObject *parent = nullptr);
|
||||||
~ContentManagerModel();
|
~ContentManagerModel();
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
@ -63,7 +66,7 @@ private: // data
|
|||||||
ThumbnailDownloader td;
|
ThumbnailDownloader td;
|
||||||
QMap<QString, size_t> bookIdToRowMap;
|
QMap<QString, size_t> bookIdToRowMap;
|
||||||
QMap<QString, QByteArray> iconMap;
|
QMap<QString, QByteArray> iconMap;
|
||||||
QMap<QString, std::shared_ptr<DownloadState>> m_downloads;
|
Downloads& m_downloads;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTENTMANAGERMODEL_H
|
#endif // CONTENTMANAGERMODEL_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user