#include "progressdialog.h"
#include "settings.h"
-LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(tr("(No books)"), parent)
+LibraryDialog::LibraryDialog(QWidget *parent):
+ ListWindow(tr("(No books)"), parent)
{
TRACE;
setWindowTitle(tr("Library"));
setAttribute(Qt::WA_DeleteOnClose, true);
// Add menu actions
- sortByTitle = addMenuAction(tr("Sort by title"), this, SLOT(onSortByTitle()));
+ sortByTitle =
+ addMenuAction(tr("Sort by title"), this, SLOT(onSortByTitle()));
sortByAuthor =
addMenuAction(tr("Sort by author"), this, SLOT(onSortByAuthor()));
// Add action buttons
addButton(tr("Add book"), this, SLOT(onAdd()), "add");
- addButton(tr("Add books from folder"), this, SLOT(onAddFolder()), "folder");
+ addButton(tr("Add books from folder"), this,
+ SLOT(onAddFolder()), "folder");
addButton(tr("Search the Web"), this, SLOT(onSearch()), "search");
+ addItemButton(tr("Delete"), this, SLOT(onDelete()), "delete");
// Set selected item
Library *library = Library::instance();
}
// Get book file name
- QString path = QFileDialog::getOpenFileName(this, tr("Add Book"),
+ QString path = QFileDialog::getOpenFileName(this, tr("Add book"),
lastDir, "Books (*.epub)");
if (path == "") {
return;
}
}
+void LibraryDialog::onDelete()
+{
+ QModelIndex current = currentItem();
+ if (!current.isValid()) {
+ return;
+ }
+ QModelIndex libraryIndex = sortedLibrary->mapToSource(current);
+ Book *book = Library::instance()->book(libraryIndex);
+ if (QMessageBox::Yes !=
+ QMessageBox::question(this, tr("Delete book"),
+ tr("Delete book \"%1\"?").arg(book->shortName()),
+ QMessageBox::Yes | QMessageBox::No)) {
+ return;
+ }
+ Library::instance()->remove(libraryIndex);
+}
+
QString LibraryDialog::createItemText(Book *book)
{
Q_ASSERT(book);