diff --git a/resources/texts/_contentManager.html b/resources/texts/_contentManager.html index 7ae1bea..32df1bc 100644 --- a/resources/texts/_contentManager.html +++ b/resources/texts/_contentManager.html @@ -74,6 +74,9 @@ function init() { downloadUpdaters[book.id] = setInterval(function() { getDownloadInfo(book.id); }, 1000); }); }, + eraseBook : function(book) { + contentManager.eraseBook(book.id); + }, displayedBooks : function(books, nb) { var a = books.slice(0, nb); return a; @@ -215,6 +218,7 @@ details:hover {
+ icone poubelle File name Size @@ -225,6 +229,9 @@ details:hover {
+ + + diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index fc9dc41..dc3da5f 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -25,7 +25,6 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, connect(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary); } - void ContentManager::setLocal(bool local) { if (local == m_local) { return; @@ -185,10 +184,23 @@ QString ContentManager::downloadBook(const QString &id) mp_library->addBookToLibrary(book); mp_library->save(); emit(mp_library->booksChanged()); - emit(booksChanged()); return QString::fromStdString(download->getDid()); } +void ContentManager::eraseBook(const QString& id) +{ + kiwix::Book book = mp_library->getBookById(id); + QString dirName = QString::fromUtf8(getDataDirectory().c_str()); + QString fileSelection = QString::fromUtf8(getLastPathElement(book.getPath()).c_str()) + "*"; + QDir dir(dirName, fileSelection); + for(const QString& filename: dir.entryList()) { + dir.remove(filename); + } + mp_library->removeBookFromLibraryById(id); + mp_library->save(); + emit(mp_library->booksChanged()); +} + QStringList ContentManager::getDownloadIds() { QStringList list; diff --git a/src/contentmanager.h b/src/contentmanager.h index 4a7324c..64e1f26 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -51,6 +51,7 @@ public slots: QString downloadBook(const QString& id); void updateLibrary(); void setSearch(const QString& search); + void eraseBook(const QString& id); }; #endif // CONTENTMANAGER_H diff --git a/src/library.cpp b/src/library.cpp index 3eb47e9..9c0e989 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -113,6 +113,10 @@ void Library::addBookToLibrary(kiwix::Book &book) m_library.addBook(book); } +void Library::removeBookFromLibraryById(const QString& id) { + m_library.removeBookById(id.toStdString()); +} + void Library::addBookmark(kiwix::Bookmark &bookmark) { m_library.addBookmark(bookmark); diff --git a/src/library.h b/src/library.h index 47c33e9..b6705bb 100644 --- a/src/library.h +++ b/src/library.h @@ -32,6 +32,7 @@ public: QStringList listBookIds(const QString& query, const QString &categoryFilter); const std::vector& getBookmarks() { return m_library.getBookmarks(); } void addBookToLibrary(kiwix::Book& book); + void removeBookFromLibraryById(const QString& id); void addBookmark(kiwix::Bookmark& bookmark); void removeBookmark(const QString& zimId, const QString& url); void save();