Allow editing bookmarks.
authorAkos Polster <polster@marzipan.local>
Sat, 25 Dec 2010 21:32:30 +0000 (22:32 +0100)
committerAkos Polster <polster@marzipan.local>
Sat, 25 Dec 2010 21:32:30 +0000 (22:32 +0100)
bookmarksdialog.cpp
bookmarksdialog.h
model/book.cpp
model/book.h
pkg/changelog

index 9f81259..ddeb88c 100644 (file)
@@ -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<QStringListModel *>(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;
 }
index d0812b4..f0b9342 100644 (file)
@@ -4,9 +4,9 @@
 #include <QStringList>
 
 #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;
index 87d0303..e15ac5a 100644 (file)
@@ -359,6 +359,16 @@ void Book::addBookmark(int part, qreal position, const QString &note)
     save();
 }
 
+void Book::setBookmarkNote(int index, const QString &note)
+{
+    load();
+    if (index >= 0 && index < mBookmarks.length()) {
+        mBookmarks[index].note = note;
+    }
+    save();
+
+}
+
 void Book::deleteBookmark(int index)
 {
     load();
index 3c00e3c..bfce66b 100644 (file)
@@ -92,6 +92,9 @@ public:
     /** Add bookmark. */
     void addBookmark(int part, qreal position, const QString &note);
 
+    /** Change a given bookmark's note text */
+    void setBookmarkNote(int index, const QString &note);
+
     /** Delete bookmark. */
     void deleteBookmark(int index);
 
index d0b2aed..78f4548 100644 (file)
@@ -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 <akos@pipacs.com>  Sun,  5 Dec 2010 02:00:00 +0100