From: Akos Polster Date: Sat, 25 Dec 2010 21:32:30 +0000 (+0100) Subject: Allow editing bookmarks. X-Git-Url: http://git.maemo.org/git/?p=dorian;a=commitdiff_plain;h=3edc0c67f1a1c8d683e1bd0068646902cafa281a Allow editing bookmarks. --- diff --git a/bookmarksdialog.cpp b/bookmarksdialog.cpp index 9f81259..ddeb88c 100644 --- a/bookmarksdialog.cpp +++ b/bookmarksdialog.cpp @@ -14,21 +14,8 @@ 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); @@ -111,5 +98,41 @@ void BookmarksDialog::reallyDelete() void BookmarksDialog::onEdit() { - // FIXME: Implement me + 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; } diff --git a/bookmarksdialog.h b/bookmarksdialog.h index d0812b4..f0b9342 100644 --- a/bookmarksdialog.h +++ b/bookmarksdialog.h @@ -4,9 +4,9 @@ #include #include "listwindow.h" +#include "book.h" class QCloseEvent; -class Book; /** Dialog box managing bookmarks. */ class BookmarksDialog: public ListWindow @@ -29,6 +29,7 @@ public slots: protected: void reallyDelete(); + QString bookmarkToText(const Book::Bookmark &bookmark); private: Book *book; diff --git a/model/book.cpp b/model/book.cpp index 87d0303..e15ac5a 100644 --- a/model/book.cpp +++ b/model/book.cpp @@ -359,6 +359,16 @@ void Book::addBookmark(int part, qreal position, const QString ¬e) save(); } +void Book::setBookmarkNote(int index, const QString ¬e) +{ + load(); + if (index >= 0 && index < mBookmarks.length()) { + mBookmarks[index].note = note; + } + save(); + +} + void Book::deleteBookmark(int index) { load(); diff --git a/model/book.h b/model/book.h index 3c00e3c..bfce66b 100644 --- a/model/book.h +++ b/model/book.h @@ -92,6 +92,9 @@ public: /** Add bookmark. */ void addBookmark(int part, qreal position, const QString ¬e); + /** Change a given bookmark's note text */ + void setBookmarkNote(int index, const QString ¬e); + /** Delete bookmark. */ void deleteBookmark(int index); diff --git a/pkg/changelog b/pkg/changelog index d0b2aed..78f4548 100644 --- a/pkg/changelog +++ b/pkg/changelog @@ -6,6 +6,7 @@ dorian (0.4.4-1) unstable; urgency=low * Improve identification of bookmark's chapter * Maintain date book added to the library and date book last read * Show presence of extra book parts + * Allow editing bookmark notes -- Akos Polster Sun, 5 Dec 2010 02:00:00 +0100