Re-design ListWindow.
[dorian] / bookmarksdialog.cpp
index fdfed5b..2186671 100644 (file)
@@ -3,7 +3,7 @@
 #include "bookmarksdialog.h"
 #include "book.h"
 #include "bookmarkinfodialog.h"
-#include "listview.h"
+#include "trace.h"
 
 BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
     ListWindow(parent), book(book_)
@@ -13,44 +13,42 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
         return;
     }
 
-    addAction(tr("Add bookmark"), this, SLOT(onAdd()), ":/icons/add.png");
-#ifndef Q_WS_MAEMO_5
-    addItemAction(tr("Go to"), this, SLOT(onGo()));
-    addItemAction(tr("Delete"), this, SLOT(onDelete()));
-#endif // ! Q_WS_MAEMO_5
+    addButton(tr("Add bookmark"), this, SLOT(onAdd()), "add");
 
-    // Build bookmark list
+    // 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 += "\nIn \"" + book_->content[chapterId].name + "\"";
+            label += "In \"" + book_->content[chapterId].name + "\"";
         }
         data.append(label);
     }
-
-    // Create bookmark list view
     QStringListModel *model = new QStringListModel(data, this);
-    list = new ListView;
-    list->setSelectionMode(QAbstractItemView::SingleSelection);
-    list->setModel(model);
-    addList(list);
-    connect(list, SIGNAL(activated(const QModelIndex &)),
-            this, SLOT(onItemActivated(const QModelIndex &)));
-    addList(list);
+    setModel(model);
+
+    // FIXME
+    // connect(list, SIGNAL(activated(const QModelIndex &)),
+    //         this, SLOT(onItemActivated(const QModelIndex &)));
 }
 
 void BookmarksDialog::onGo()
 {
-    QModelIndex current = list->currentIndex();
-    if (current.isValid()) {
-        emit goToBookmark(current.row());
-        close();
-    }
+    TRACE;
+    // FIXME
+    // QModelIndex current = list->currentIndex();
+    // if (current.isValid()) {
+    //     emit goToBookmark(current.row());
+    //     close();
+    // }
 }
 
 void BookmarksDialog::onItemActivated(const QModelIndex &index)
@@ -69,8 +67,13 @@ void BookmarksDialog::onItemActivated(const QModelIndex &index)
 
 void BookmarksDialog::onAdd()
 {
-    emit addBookmark();
-    close();
+    bool ok;
+    QString text = QInputDialog::getText(this, tr("Add bookmark"),
+        tr("Note (optional):"), QLineEdit::Normal, QString(), &ok);
+    if (ok) {
+        emit addBookmark(text);
+        close();
+    }
 }
 
 void BookmarksDialog::onDelete(bool really)