X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=bookmarksdialog.cpp;h=ddeb88cba4567cea2387b0bbdf6e883bee8d779d;hb=9f73b19627aba7a802daa22df7b7683fd47ec809;hp=3f4bb8c41f11ee852069ed7e6c689229a7636363;hpb=4d3999dc36d1f07fd1a1b25ac932b2326d29de3d;p=dorian diff --git a/bookmarksdialog.cpp b/bookmarksdialog.cpp index 3f4bb8c..ddeb88c 100644 --- a/bookmarksdialog.cpp +++ b/bookmarksdialog.cpp @@ -14,27 +14,16 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent): } // Build and set bookmark model - // FIXME: Localize me foreach (Book::Bookmark bookmark, book_->bookmarks()) { - QString label("At "); - label += QString::number((int)(100 * book_-> - getProgress(bookmark.part, bookmark.pos))) + "%"; - if (!bookmark.note.isEmpty()) { - label += ": " + bookmark.note; - } - label += "\n"; - int chapterIndex = book_->chapterFromPart(bookmark.part); - if (chapterIndex != -1) { - QString chapterId = book_->chapters[chapterIndex]; - label += "In \"" + book_->content[chapterId].name + "\""; - } - data.append(label); + data.append(bookmarkToText(bookmark)); } QStringListModel *model = new QStringListModel(data, this); setModel(model); addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add"); - addItemButton(tr("Delete bookmark"), this, SLOT(onDelete()), "remove"); + addItemButton(tr("Go to bookmark"), this, SLOT(onGo()), "goto"); + addItemButton(tr("Edit bookmark"), this, SLOT(onEdit()), "edit"); + addItemButton(tr("Delete bookmark"), this, SLOT(onDelete()), "delete"); connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &))); @@ -52,20 +41,26 @@ void BookmarksDialog::onGo() void BookmarksDialog::onItemActivated(const QModelIndex &index) { + TRACE; +#ifdef Q_WS_MAEMO_5 switch ((new BookmarkInfoDialog(book, index.row(), this))->exec()) { case BookmarkInfoDialog::GoTo: onGo(); break; case BookmarkInfoDialog::Delete: - onDelete(true); + reallyDelete(); break; default: ; } +#else + Q_UNUSED(index); +#endif } void BookmarksDialog::onAdd() { + TRACE; bool ok; QString text = QInputDialog::getText(this, tr("Add bookmark"), tr("Note (optional):"), QLineEdit::Normal, QString(), &ok); @@ -75,20 +70,69 @@ void BookmarksDialog::onAdd() } } -void BookmarksDialog::onDelete(bool really) +void BookmarksDialog::onDelete() +{ + TRACE; + if (!currentItem().isValid()) { + return; + } + if (QMessageBox::Yes != + QMessageBox::question(this, tr("Delete bookmark"), + tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) { + return; + } + reallyDelete(); +} + +void BookmarksDialog::reallyDelete() { + TRACE; QModelIndex current = currentItem(); if (!current.isValid()) { return; } - if (!really) { - if (QMessageBox::Yes != - QMessageBox::question(this, tr("Delete bookmark"), - tr("Delete bookmark?"), QMessageBox::Yes | QMessageBox::No)) { - return; - } - } int row = current.row(); model()->removeRow(row); book->deleteBookmark(row); } + +void BookmarksDialog::onEdit() +{ + TRACE; + QModelIndex current = currentItem(); + if (!current.isValid()) { + return; + } + int row = current.row(); + Book::Bookmark b = book->bookmarks()[row]; + bool ok; + QString text = QInputDialog::getText(this, tr("Edit bookmark"), + tr("Note:"), QLineEdit::Normal, b.note, &ok); + if (!ok) { + return; + } + b.note = text; + book->setBookmarkNote(row, text); + QStringListModel *m = qobject_cast(model()); + if (m) { + m->setData(current, bookmarkToText(b), Qt::DisplayRole); + } +} + +QString BookmarksDialog::bookmarkToText(const Book::Bookmark &bookmark) +{ + // FIXME: Localize me + QString label("At "); + label += QString::number((int)(100 * book-> + getProgress(bookmark.part, bookmark.pos))) + "%"; + if (!bookmark.note.isEmpty()) { + label += ": " + bookmark.note; + } + label += "\n"; + int chapterIndex = book->chapterFromPart(bookmark.part); + if (chapterIndex != -1) { + QString chapterId = book->chapters[chapterIndex]; + label += "In \"" + book->content[chapterId].name + "\""; + } + return label; +}