Fix forward navigation control on Linux.
[dorian] / librarydialog.cpp
index cf48c48..9e985b2 100644 (file)
@@ -35,8 +35,10 @@ LibraryDialog::LibraryDialog(QWidget *parent):
 
     // 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();
@@ -77,7 +79,7 @@ void LibraryDialog::onAdd()
     }
 
     // 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;
@@ -126,6 +128,23 @@ void LibraryDialog::onItemActivated(const QModelIndex &index)
     }
 }
 
+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);