From: Akos Polster Date: Sun, 26 Dec 2010 17:29:00 +0000 (+0100) Subject: Add Delete action to library dialog. X-Git-Url: http://vcs.maemo.org/git/?p=dorian;a=commitdiff_plain;h=373deac44975de2d91834727a2a779c490729270 Add Delete action to library dialog. --- diff --git a/librarydialog.cpp b/librarydialog.cpp index b03d6e7..9e985b2 100644 --- a/librarydialog.cpp +++ b/librarydialog.cpp @@ -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); diff --git a/librarydialog.h b/librarydialog.h index a29a093..91dec8d 100644 --- a/librarydialog.h +++ b/librarydialog.h @@ -36,6 +36,7 @@ public slots: void showSearchResults(); void onSortByAuthor(); void onSortByTitle(); + void onDelete(); private: QString createItemText(Book *book);