3 #include "bookmarksdialog.h"
5 #include "bookmarkinfodialog.h"
8 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
9 ListWindow(parent), book(book_)
11 setWindowTitle(tr("Bookmarks"));
16 addAction(tr("Add bookmark"), this, SLOT(onAdd()), ":/icons/add.png");
18 addItemAction(tr("Go to"), this, SLOT(onGo()));
19 addItemAction(tr("Delete"), this, SLOT(onDelete()));
20 #endif // ! Q_WS_MAEMO_5
22 // Build bookmark list
24 foreach (Book::Bookmark bookmark, book_->bookmarks()) {
26 label += QString::number((int)(100 * book_->
27 getProgress(bookmark.part, bookmark.pos))) + "%";
28 int chapterIndex = book_->chapterFromPart(bookmark.part);
29 if (chapterIndex != -1) {
30 QString chapterId = book_->chapters[chapterIndex];
31 label += "\nIn \"" + book_->content[chapterId].name + "\"";
36 // Create bookmark list view
37 QStringListModel *model = new QStringListModel(data, this);
39 list->setSelectionMode(QAbstractItemView::SingleSelection);
40 list->setModel(model);
42 connect(list, SIGNAL(activated(const QModelIndex &)),
43 this, SLOT(onItemActivated(const QModelIndex &)));
47 void BookmarksDialog::onGo()
49 QModelIndex current = list->currentIndex();
50 if (current.isValid()) {
51 emit goToBookmark(current.row());
56 void BookmarksDialog::onItemActivated(const QModelIndex &index)
58 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
59 case BookmarkInfoDialog::GoTo:
62 case BookmarkInfoDialog::Delete:
70 void BookmarksDialog::onAdd()
76 void BookmarksDialog::onDelete(bool really)
78 QModelIndex current = list->currentIndex();
79 if (!current.isValid()) {
83 if (QMessageBox::Yes !=
84 QMessageBox::question(this, tr("Delete bookmark"),
85 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
89 int row = current.row();
90 list->model()->removeRow(row);
91 book->deleteBookmark(row);