From 2022bb2acb9bb845cd171443d5edb8f66bbb0611 Mon Sep 17 00:00:00 2001 From: luddens Date: Thu, 20 Jun 2019 15:26:45 +0200 Subject: [PATCH] Refresh only one book instead of all the library These changes allow many improvements : - they fix the infinite refresh of the library due to the multiple "bookChanged" signal emitted when several operations on books were performed simultaneously (launch several downloads) - the scroll isn't reset to the top of the list when starting a download at the bottom of the list - (better optimization ?) Now methods that concern only one book emit the signal "oneBookChanged" with the id of the book, the JS slot search by id the correspondent book in its list and replace it with an updated one. --- resources/js/_contentManager.js | 29 +++++++++++++++++++++++++++++ src/contentmanager.cpp | 16 ++++++++++++---- src/contentmanager.h | 2 ++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/resources/js/_contentManager.js b/resources/js/_contentManager.js index bf1240b..183a00b 100644 --- a/resources/js/_contentManager.js +++ b/resources/js/_contentManager.js @@ -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; isave(); - 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() diff --git a/src/contentmanager.h b/src/contentmanager.h index 01bb802..b20b3db 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -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);