mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -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();
|
setCategories();
|
||||||
setLanguages();
|
setLanguages();
|
||||||
|
|
||||||
connect(this, &ContentManager::downloadUpdated,
|
connect(this, &DownloadManager::downloadUpdated,
|
||||||
this, &ContentManager::updateDownload);
|
this, &ContentManager::updateDownload);
|
||||||
|
|
||||||
|
connect(this, &DownloadManager::downloadDisappeared,
|
||||||
|
this, &ContentManager::downloadDisappeared);
|
||||||
|
|
||||||
if ( mp_downloader ) {
|
if ( mp_downloader ) {
|
||||||
startDownloadUpdaterThread();
|
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
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "contentmanagermodel.h"
|
#include "contentmanagermodel.h"
|
||||||
#include "downloadmanagement.h"
|
#include "downloadmanagement.h"
|
||||||
|
|
||||||
class ContentManager : public QObject, private DownloadManager
|
class ContentManager : public DownloadManager
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool isLocal MEMBER m_local READ isLocal WRITE setLocal NOTIFY localChanged)
|
Q_PROPERTY(bool isLocal MEMBER m_local READ isLocal WRITE setLocal NOTIFY localChanged)
|
||||||
@ -81,7 +81,6 @@ signals:
|
|||||||
void categoriesLoaded(QStringList);
|
void categoriesLoaded(QStringList);
|
||||||
void languagesLoaded(LanguageList);
|
void languagesLoaded(LanguageList);
|
||||||
void localChanged(const bool);
|
void localChanged(const bool);
|
||||||
void downloadUpdated(QString bookId, const DownloadInfo& );
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QStringList getTranslations(const QStringList &keys);
|
QStringList getTranslations(const QStringList &keys);
|
||||||
@ -105,7 +104,6 @@ public slots:
|
|||||||
void cancelBook(const QString& id);
|
void cancelBook(const QString& id);
|
||||||
void onCustomContextMenu(const QPoint &point);
|
void onCustomContextMenu(const QPoint &point);
|
||||||
void openBookWithIndex(const QModelIndex& index);
|
void openBookWithIndex(const QModelIndex& index);
|
||||||
void updateDownloads();
|
|
||||||
void updateDownload(QString bookId, const DownloadInfo& downloadInfo);
|
void updateDownload(QString bookId, const DownloadInfo& downloadInfo);
|
||||||
|
|
||||||
private: // functions
|
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
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef DOWNLOADMANAGEMENT_H
|
#ifndef DOWNLOADMANAGEMENT_H
|
||||||
#define DOWNLOADMANAGEMENT_H
|
#define DOWNLOADMANAGEMENT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
@ -27,8 +28,10 @@ public:
|
|||||||
void update(const DownloadInfo& info);
|
void update(const DownloadInfo& info);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DownloadManager
|
class DownloadManager : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public: // types
|
public: // types
|
||||||
|
|
||||||
// BookId -> DownloadState map
|
// BookId -> DownloadState map
|
||||||
@ -69,6 +72,11 @@ public: // functions
|
|||||||
|
|
||||||
DownloadInfo getDownloadInfo(QString bookId) const;
|
DownloadInfo getDownloadInfo(QString bookId) const;
|
||||||
void restoreDownloads();
|
void restoreDownloads();
|
||||||
|
void updateDownloads();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void downloadUpdated(QString bookId, const DownloadInfo& );
|
||||||
|
void downloadDisappeared(QString bookId);
|
||||||
|
|
||||||
protected: // data
|
protected: // data
|
||||||
const Library* const mp_library;
|
const Library* const mp_library;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user