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()), "add");
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 if (!bookmark.note.isEmpty()) {
29 label += ": " + bookmark.note;
32 int chapterIndex = book_->chapterFromPart(bookmark.part);
33 if (chapterIndex != -1) {
34 QString chapterId = book_->chapters[chapterIndex];
35 label += "In \"" + book_->content[chapterId].name + "\"";
40 // Create bookmark list view
41 QStringListModel *model = new QStringListModel(data, this);
43 list->setSelectionMode(QAbstractItemView::SingleSelection);
44 list->setModel(model);
46 connect(list, SIGNAL(activated(const QModelIndex &)),
47 this, SLOT(onItemActivated(const QModelIndex &)));
51 void BookmarksDialog::onGo()
53 QModelIndex current = list->currentIndex();
54 if (current.isValid()) {
55 emit goToBookmark(current.row());
60 void BookmarksDialog::onItemActivated(const QModelIndex &index)
62 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) {
63 case BookmarkInfoDialog::GoTo:
66 case BookmarkInfoDialog::Delete:
74 void BookmarksDialog::onAdd()
77 QString text = QInputDialog::getText(this, tr("Add bookmark"),
78 tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
80 emit addBookmark(text);
85 void BookmarksDialog::onDelete(bool really)
87 QModelIndex current = list->currentIndex();
88 if (!current.isValid()) {
92 if (QMessageBox::Yes !=
93 QMessageBox::question(this, tr("Delete bookmark"),
94 tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) {
98 int row = current.row();
99 list->model()->removeRow(row);
100 book->deleteBookmark(row);