Merge pull request #184 from kiwix/refresh-only-one-book

Refresh only one book instead of all the library
This commit is contained in:
Matthieu Gautier 2019-06-25 18:52:41 +02:00 committed by GitHub
commit 2508e0fc82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 4 deletions

View File

@ -7,6 +7,17 @@ function niceBytes(x){
return(n.toFixed(n >= 10 || unitIndex < 1 ? 0 : 2) + ' ' + units[unitIndex]);
}
function getIndexById(id) {
var index = 0;
for(var i = 0; i < app.books.length; i++) {
if (app.books[i]["id"] == id) {
index = i;
break;
}
}
return index;
}
function createDict(keys, values) {
var d = {}
for(var i=0; i<keys.length; i++) {
@ -34,6 +45,22 @@ function onBooksChanged () {
app.displayedBooksNb = 20;
}
function onOneBookChanged (id) {
var index = getIndexById(id);
contentManager.getBookInfos(id, BOOK_KEYS, function(values) {
var b = createDict(BOOK_KEYS, values);
if (b.downloadId && !downloadUpdaters.hasOwnProperty(b.id)) {
downloadUpdaters[b.id] = setInterval(function() { getDownloadInfo(b.id); }, 1000);
}
app.books.splice(index, 1, b);
});
}
function onBookRemoved (id) {
var index = getIndexById(id);
app.books.splice(index, 1);
}
downloadUpdaters = {}
const DOWNLOAD_KEYS = ["id", "status", "followedBy", "path", "totalLength", "completedLength", "downloadSpeed", "verifiedLength"];
function getDownloadInfo(id) {
@ -138,6 +165,8 @@ function init() {
}
});
contentManager.booksChanged.connect(onBooksChanged);
contentManager.oneBookChanged.connect(onOneBookChanged);
contentManager.bookRemoved.connect(onBookRemoved);
contentManager.pendingRequest.connect(displayLoadIcon);
onBooksChanged();
displayLoadIcon(false);

View File

@ -123,7 +123,11 @@ QStringList ContentManager::updateDownloadInfos(QString id, const QStringList &k
b.setPath(QDir::toNativeSeparators(tmp).toStdString());
b.setDownloadId("");
mp_library->save();
emit(mp_library->booksChanged());
if (!m_local) {
emit(oneBookChanged(id));
} else {
emit(mp_library->booksChanged());
}
}
for(auto& key: keys){
ADD_V("id", getDid);
@ -194,7 +198,7 @@ QString ContentManager::downloadBook(const QString &id)
book.setDownloadId(download->getDid());
mp_library->addBookToLibrary(book);
mp_library->save();
emit(mp_library->booksChanged());
emit(oneBookChanged(id));
return QString::fromStdString(download->getDid());
}
@ -214,7 +218,11 @@ void ContentManager::eraseBook(const QString& id)
eraseBookFilesFromComputer(fileToRemove);
mp_library->removeBookFromLibraryById(id);
mp_library->save();
emit(mp_library->booksChanged());
if (m_local) {
emit(bookRemoved(id));
} else {
emit(oneBookChanged(id));
}
}
void ContentManager::pauseBook(const QString& id)
@ -244,7 +252,7 @@ void ContentManager::cancelBook(const QString& id)
eraseBookFilesFromComputer(fileToRemove);
mp_library->removeBookFromLibraryById(id);
mp_library->save();
emit(mp_library->booksChanged());
emit(oneBookChanged(id));
}
QStringList ContentManager::getDownloadIds()

View File

@ -44,6 +44,8 @@ private:
signals:
void filterParamsChanged();
void booksChanged();
void oneBookChanged(const QString&);
void bookRemoved(const QString&);
void downloadsChanged();
void currentLangChanged();
void pendingRequest(const bool);