mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-21 02:51:26 -04:00
Extracted ContentManager::getDownloadInfo()
This commit is contained in:
parent
dd69a9d2bd
commit
2fbfe40c11
@ -366,18 +366,18 @@ QString getDownloadInfo(const kiwix::Download& d, const QString& k)
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
void ContentManager::downloadCancelled(const kiwix::Book& b)
|
||||
void ContentManager::downloadCancelled(QString bookId)
|
||||
{
|
||||
kiwix::Book bCopy(b);
|
||||
kiwix::Book bCopy(mp_library->getBookById(bookId));
|
||||
bCopy.setDownloadId("");
|
||||
mp_library->getKiwixLibrary()->addOrUpdateBook(bCopy);
|
||||
mp_library->save();
|
||||
emit(mp_library->booksChanged());
|
||||
}
|
||||
|
||||
void ContentManager::downloadCompleted(const kiwix::Book& b, QString path)
|
||||
void ContentManager::downloadCompleted(QString bookId, QString path)
|
||||
{
|
||||
kiwix::Book bCopy(b);
|
||||
kiwix::Book bCopy(mp_library->getBookById(bookId));
|
||||
bCopy.setPath(QDir::toNativeSeparators(path).toStdString());
|
||||
bCopy.setDownloadId("");
|
||||
bCopy.setPathValid(true);
|
||||
@ -387,13 +387,13 @@ void ContentManager::downloadCompleted(const kiwix::Book& b, QString path)
|
||||
mp_library->save();
|
||||
mp_library->bookmarksChanged();
|
||||
if (!m_local) {
|
||||
emit(oneBookChanged(QString::fromStdString(b.getId())));
|
||||
emit(oneBookChanged(bookId));
|
||||
} else {
|
||||
emit(mp_library->booksChanged());
|
||||
}
|
||||
}
|
||||
|
||||
ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString id, const QStringList &keys)
|
||||
ContentManager::DownloadInfo ContentManager::getDownloadInfo(QString bookId, const QStringList &keys) const
|
||||
{
|
||||
DownloadInfo values;
|
||||
if (!mp_downloader) {
|
||||
@ -402,25 +402,40 @@ ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString id, con
|
||||
}
|
||||
return values;
|
||||
}
|
||||
auto& b = mp_library->getBookById(id);
|
||||
|
||||
auto& b = mp_library->getBookById(bookId);
|
||||
std::shared_ptr<kiwix::Download> d;
|
||||
try {
|
||||
d = mp_downloader->getDownload(b.getDownloadId());
|
||||
} catch(...) {
|
||||
downloadCancelled(b);
|
||||
return values;
|
||||
}
|
||||
|
||||
d->updateStatus(true);
|
||||
if (d->getStatus() == kiwix::Download::K_COMPLETE) {
|
||||
downloadCompleted(b, QString::fromStdString(d->getPath()));
|
||||
}
|
||||
|
||||
for(auto& key: keys){
|
||||
values.insert(key, getDownloadInfo(*d, key));
|
||||
values.insert(key, ::getDownloadInfo(*d, key));
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString bookId, QStringList keys)
|
||||
{
|
||||
if ( !keys.contains("status") ) keys.append("status");
|
||||
if ( !keys.contains("path") ) keys.append("path");
|
||||
|
||||
const DownloadInfo result = getDownloadInfo(bookId, keys);
|
||||
|
||||
if ( result.isEmpty() ) {
|
||||
downloadCancelled(bookId);
|
||||
} else if ( result["status"] == "completed" ) {
|
||||
downloadCompleted(bookId, result["path"].toString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString ContentManager::downloadBook(const QString &id, QModelIndex index)
|
||||
{
|
||||
QString downloadStatus = downloadBook(id);
|
||||
|
@ -65,8 +65,9 @@ private:
|
||||
QMutex remoteLibraryLocker;
|
||||
void setCategories();
|
||||
void setLanguages();
|
||||
void downloadCancelled(const kiwix::Book& b);
|
||||
void downloadCompleted(const kiwix::Book& book, QString path);
|
||||
void downloadCancelled(QString bookId);
|
||||
void downloadCompleted(QString bookId, QString path);
|
||||
DownloadInfo getDownloadInfo(QString bookId, const QStringList& keys) const;
|
||||
|
||||
signals:
|
||||
void filterParamsChanged();
|
||||
@ -84,7 +85,7 @@ public slots:
|
||||
QStringList getTranslations(const QStringList &keys);
|
||||
BookInfo getBookInfos(QString id, const QStringList &keys);
|
||||
void openBook(const QString& id);
|
||||
DownloadInfo updateDownloadInfos(QString id, const QStringList& keys);
|
||||
DownloadInfo updateDownloadInfos(QString bookId, QStringList keys);
|
||||
QString downloadBook(const QString& id);
|
||||
QString downloadBook(const QString& id, QModelIndex index);
|
||||
void updateLibrary();
|
||||
|
Loading…
x
Reference in New Issue
Block a user