mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-20 18:33:38 -04:00
{Content->Download}Manager::updateDownloads()
One subtlety of this refactoring is that ContentManager::downloadDisappeared() is now NOT called from updateDownloads() directly/synchronously but is invoked via a signal and is thus executed in the main thread.
This commit is contained in:
parent
300873a301
commit
1354363bfc
@ -143,9 +143,12 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader)
|
||||
setCategories();
|
||||
setLanguages();
|
||||
|
||||
connect(this, &ContentManager::downloadUpdated,
|
||||
connect(this, &DownloadManager::downloadUpdated,
|
||||
this, &ContentManager::updateDownload);
|
||||
|
||||
connect(this, &DownloadManager::downloadDisappeared,
|
||||
this, &ContentManager::downloadDisappeared);
|
||||
|
||||
if ( mp_downloader ) {
|
||||
startDownloadUpdaterThread();
|
||||
}
|
||||
@ -570,21 +573,6 @@ void ContentManager::updateDownload(QString bookId, const DownloadInfo& download
|
||||
}
|
||||
}
|
||||
|
||||
void ContentManager::updateDownloads()
|
||||
{
|
||||
DownloadInfo downloadInfo;
|
||||
for ( const auto& bookId : m_downloads.keys() ) {
|
||||
try {
|
||||
downloadInfo = getDownloadInfo(bookId);
|
||||
} catch ( ... ) {
|
||||
downloadDisappeared(bookId);
|
||||
continue;
|
||||
}
|
||||
|
||||
emit downloadUpdated(bookId, downloadInfo);
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "contentmanagermodel.h"
|
||||
#include "downloadmanagement.h"
|
||||
|
||||
class ContentManager : public QObject, private DownloadManager
|
||||
class ContentManager : public DownloadManager
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isLocal MEMBER m_local READ isLocal WRITE setLocal NOTIFY localChanged)
|
||||
@ -81,7 +81,6 @@ signals:
|
||||
void categoriesLoaded(QStringList);
|
||||
void languagesLoaded(LanguageList);
|
||||
void localChanged(const bool);
|
||||
void downloadUpdated(QString bookId, const DownloadInfo& );
|
||||
|
||||
public slots:
|
||||
QStringList getTranslations(const QStringList &keys);
|
||||
@ -105,7 +104,6 @@ public slots:
|
||||
void cancelBook(const QString& id);
|
||||
void onCustomContextMenu(const QPoint &point);
|
||||
void openBookWithIndex(const QModelIndex& index);
|
||||
void updateDownloads();
|
||||
void updateDownload(QString bookId, const DownloadInfo& downloadInfo);
|
||||
|
||||
private: // functions
|
||||
|
@ -56,6 +56,21 @@ void DownloadManager::restoreDownloads()
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadManager::updateDownloads()
|
||||
{
|
||||
DownloadInfo downloadInfo;
|
||||
for ( const auto& bookId : m_downloads.keys() ) {
|
||||
try {
|
||||
downloadInfo = getDownloadInfo(bookId);
|
||||
} catch ( ... ) {
|
||||
emit downloadDisappeared(bookId);
|
||||
continue;
|
||||
}
|
||||
|
||||
emit downloadUpdated(bookId, downloadInfo);
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef DOWNLOADMANAGEMENT_H
|
||||
#define DOWNLOADMANAGEMENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
@ -27,8 +28,10 @@ public:
|
||||
void update(const DownloadInfo& info);
|
||||
};
|
||||
|
||||
class DownloadManager
|
||||
class DownloadManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public: // types
|
||||
|
||||
// BookId -> DownloadState map
|
||||
@ -69,6 +72,11 @@ public: // functions
|
||||
|
||||
DownloadInfo getDownloadInfo(QString bookId) const;
|
||||
void restoreDownloads();
|
||||
void updateDownloads();
|
||||
|
||||
signals:
|
||||
void downloadUpdated(QString bookId, const DownloadInfo& );
|
||||
void downloadDisappeared(QString bookId);
|
||||
|
||||
protected: // data
|
||||
const Library* const mp_library;
|
||||
|
Loading…
x
Reference in New Issue
Block a user