Add Delete action to library dialog.
authorAkos Polster <polster@marzipan.local>
Sun, 26 Dec 2010 17:29:00 +0000 (18:29 +0100)
committerAkos Polster <polster@marzipan.local>
Sun, 26 Dec 2010 17:29:00 +0000 (18:29 +0100)
librarydialog.cpp
librarydialog.h

index b03d6e7..9e985b2 100644 (file)
@@ -38,6 +38,7 @@ LibraryDialog::LibraryDialog(QWidget *parent):
     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();
@@ -127,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);
index a29a093..91dec8d 100644 (file)
@@ -36,6 +36,7 @@ public slots:
     void showSearchResults();
     void onSortByAuthor();
     void onSortByTitle();
+    void onDelete();
 
 private:
     QString createItemText(Book *book);