mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -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
|
} // 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("");
|
bCopy.setDownloadId("");
|
||||||
mp_library->getKiwixLibrary()->addOrUpdateBook(bCopy);
|
mp_library->getKiwixLibrary()->addOrUpdateBook(bCopy);
|
||||||
mp_library->save();
|
mp_library->save();
|
||||||
emit(mp_library->booksChanged());
|
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.setPath(QDir::toNativeSeparators(path).toStdString());
|
||||||
bCopy.setDownloadId("");
|
bCopy.setDownloadId("");
|
||||||
bCopy.setPathValid(true);
|
bCopy.setPathValid(true);
|
||||||
@ -387,13 +387,13 @@ void ContentManager::downloadCompleted(const kiwix::Book& b, QString path)
|
|||||||
mp_library->save();
|
mp_library->save();
|
||||||
mp_library->bookmarksChanged();
|
mp_library->bookmarksChanged();
|
||||||
if (!m_local) {
|
if (!m_local) {
|
||||||
emit(oneBookChanged(QString::fromStdString(b.getId())));
|
emit(oneBookChanged(bookId));
|
||||||
} else {
|
} else {
|
||||||
emit(mp_library->booksChanged());
|
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;
|
DownloadInfo values;
|
||||||
if (!mp_downloader) {
|
if (!mp_downloader) {
|
||||||
@ -402,25 +402,40 @@ ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString id, con
|
|||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
auto& b = mp_library->getBookById(id);
|
|
||||||
|
auto& b = mp_library->getBookById(bookId);
|
||||||
std::shared_ptr<kiwix::Download> d;
|
std::shared_ptr<kiwix::Download> d;
|
||||||
try {
|
try {
|
||||||
d = mp_downloader->getDownload(b.getDownloadId());
|
d = mp_downloader->getDownload(b.getDownloadId());
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
downloadCancelled(b);
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->updateStatus(true);
|
d->updateStatus(true);
|
||||||
if (d->getStatus() == kiwix::Download::K_COMPLETE) {
|
|
||||||
downloadCompleted(b, QString::fromStdString(d->getPath()));
|
|
||||||
}
|
|
||||||
for(auto& key: keys){
|
for(auto& key: keys){
|
||||||
values.insert(key, getDownloadInfo(*d, key));
|
values.insert(key, ::getDownloadInfo(*d, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return values;
|
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 ContentManager::downloadBook(const QString &id, QModelIndex index)
|
||||||
{
|
{
|
||||||
QString downloadStatus = downloadBook(id);
|
QString downloadStatus = downloadBook(id);
|
||||||
|
@ -65,8 +65,9 @@ private:
|
|||||||
QMutex remoteLibraryLocker;
|
QMutex remoteLibraryLocker;
|
||||||
void setCategories();
|
void setCategories();
|
||||||
void setLanguages();
|
void setLanguages();
|
||||||
void downloadCancelled(const kiwix::Book& b);
|
void downloadCancelled(QString bookId);
|
||||||
void downloadCompleted(const kiwix::Book& book, QString path);
|
void downloadCompleted(QString bookId, QString path);
|
||||||
|
DownloadInfo getDownloadInfo(QString bookId, const QStringList& keys) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filterParamsChanged();
|
void filterParamsChanged();
|
||||||
@ -84,7 +85,7 @@ public slots:
|
|||||||
QStringList getTranslations(const QStringList &keys);
|
QStringList getTranslations(const QStringList &keys);
|
||||||
BookInfo getBookInfos(QString id, const QStringList &keys);
|
BookInfo getBookInfos(QString id, const QStringList &keys);
|
||||||
void openBook(const QString& id);
|
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);
|
||||||
QString downloadBook(const QString& id, QModelIndex index);
|
QString downloadBook(const QString& id, QModelIndex index);
|
||||||
void updateLibrary();
|
void updateLibrary();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user