delete books with simple ui

add a column at the book's list's table with "delete" button. This ui
is temporary.

On click, this button sends the id of the selected book at the
ContentManager class which gets book by this id, and erases all files
in relationship with this book on the computer.
This commit is contained in:
luddens 2019-04-19 17:48:09 +02:00
parent 3a425980ef
commit 2848fc1e43
5 changed files with 27 additions and 2 deletions

View File

@ -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 {
</div>
<div id="bookTable">
<div class="header">
<span class="tablecell cell0">icone poubelle</span>
<span class="tablecell cell0"></span>
<span class="tablecell cell1">File name</span>
<span class="tablecell cell2">Size</span>
@ -225,6 +229,9 @@ details:hover {
<div id="bookList" onscroll=scrolled(this)>
<details v-for="book in displayedBooks(books, displayedBooksNb)" class="book">
<summary class="tablerow">
<span class="tablecell cell0">
<button v-if="book.path" v-on:click="eraseBook(book)">Delete</button>
</span>
<span class="tablecell cell0">
<img v-if="book.faviconUrl" v-bind:src="'http://' + book.faviconUrl" />
<img v-else-if="book.faviconMimeType" v-bind:src="'zim://' + book.id + '.favicon.meta'" />

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -32,6 +32,7 @@ public:
QStringList listBookIds(const QString& query, const QString &categoryFilter);
const std::vector<kiwix::Bookmark>& 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();