From 8e64982b8df29e450edac6c6bbe081d7a82d161b Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Fri, 24 Dec 2010 21:33:01 +0100 Subject: [PATCH] Maintain date added and date last opened. --- infodialog.cpp | 12 ++++++++++++ librarydialog.cpp | 5 +++-- model/book.cpp | 9 +++++++-- model/book.h | 7 +++++-- model/library.cpp | 1 + 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/infodialog.cpp b/infodialog.cpp index 621eaaa..4a92fe4 100644 --- a/infodialog.cpp +++ b/infodialog.cpp @@ -46,6 +46,18 @@ InfoDialog::InfoDialog(Book *b, QWidget *parent, bool showButtons): rights->setWordWrap(true); addWidget(rights); } + if (book->dateAdded.isValid()) { + QLabel *added = new QLabel("Added to library: " + + book->dateAdded.toString(Qt::SystemLocaleShortDate), this); + added->setWordWrap(true); + addWidget(added); + } + if (book->dateOpened.isValid()) { + QLabel *opened = new QLabel("Last read: " + + book->dateOpened.toString(Qt::SystemLocaleShortDate), this); + opened->setWordWrap(true); + addWidget(opened); + } addStretch(); } diff --git a/librarydialog.cpp b/librarydialog.cpp index cf48c48..b03d6e7 100644 --- a/librarydialog.cpp +++ b/librarydialog.cpp @@ -35,7 +35,8 @@ LibraryDialog::LibraryDialog(QWidget *parent): // Add action buttons addButton(tr("Add book"), this, SLOT(onAdd()), "add"); - addButton(tr("Add books from folder"), this, SLOT(onAddFolder()), "folder"); + addButton(tr("Add books from folder"), this, + SLOT(onAddFolder()), "folder"); addButton(tr("Search the Web"), this, SLOT(onSearch()), "search"); // Set selected item @@ -77,7 +78,7 @@ void LibraryDialog::onAdd() } // Get book file name - QString path = QFileDialog::getOpenFileName(this, tr("Add Book"), + QString path = QFileDialog::getOpenFileName(this, tr("Add book"), lastDir, "Books (*.epub)"); if (path == "") { return; diff --git a/model/book.cpp b/model/book.cpp index d209816..87d0303 100644 --- a/model/book.cpp +++ b/model/book.cpp @@ -53,6 +53,7 @@ bool Book::open() if (!parse()) { return false; } + dateOpened = QDateTime::currentDateTimeUtc(); save(); emit opened(path()); return true; @@ -190,8 +191,8 @@ bool Book::parse() cover = makeCover(coverPath); } - // If there is an "ncx" item in content, parse it: That's the real table of - // contents + // If there is an "ncx" item in content, parse it: That's the real table + // of contents QString ncxFileName; if (content.contains("ncx")) { ncxFileName = content["ncx"].href; @@ -303,6 +304,8 @@ void Book::load() QString note = data[QString("bookmark%1note").arg(i)].toString(); mBookmarks.append(Bookmark(part, pos, note)); } + dateAdded = data["dateadded"].toDateTime(); + dateOpened = data["dateopened"].toDateTime(); } void Book::save() @@ -328,6 +331,8 @@ void Book::save() data[QString("bookmark%1pos").arg(i)] = mBookmarks[i].pos; data[QString("bookmark%1note").arg(i)] = mBookmarks[i].note; } + data["dateadded"] = dateAdded; + data["dateopened"] = dateOpened; BookDb::instance()->save(path(), data); } diff --git a/model/book.h b/model/book.h index 1da4209..3c00e3c 100644 --- a/model/book.h +++ b/model/book.h @@ -8,6 +8,7 @@ #include #include #include +#include class QPixmap; @@ -36,7 +37,7 @@ public: qreal pos; QString note; bool operator<(const Bookmark &other) const { - return (part == other.part)? (pos < other.pos): (part < other.part); + return (part == other.part)? (pospeek(); + book->dateAdded = QDateTime::currentDateTimeUtc(); mBooks.append(book); save(); endInsertRows(); -- 1.7.9.5