Maintain date added and date last opened.
authorAkos Polster <polster@marzipan.local>
Fri, 24 Dec 2010 20:33:01 +0000 (21:33 +0100)
committerAkos Polster <polster@marzipan.local>
Fri, 24 Dec 2010 20:33:01 +0000 (21:33 +0100)
infodialog.cpp
librarydialog.cpp
model/book.cpp
model/book.h
model/library.cpp

index 621eaaa..4a92fe4 100644 (file)
@@ -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();
     }
 
index cf48c48..b03d6e7 100644 (file)
@@ -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;
index d209816..87d0303 100644 (file)
@@ -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);
 }
 
index 1da4209..3c00e3c 100644 (file)
@@ -8,6 +8,7 @@
 #include <QMetaType>
 #include <QObject>
 #include <QTemporaryFile>
+#include <QDateTime>
 
 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)? (pos<other.pos): (part<other.part);
         }
     };
 
@@ -131,8 +132,10 @@ public:
     QString rights;                         //< Rights.
     QString tocPath;                        //< Path to toc NCX file.
     QString coverPath;                      //< Path to cover HTML file.
-    QStringList chapters;                   //< Main navigation items from EPUB.
+    QStringList chapters;                   //< Main navigation items.
     qint64 size;                            //< Size of all parts.
+    QDateTime dateAdded;                    //< Date book added to library.
+    QDateTime dateOpened;                   //< Date book was last read.
 
 signals:
     /** Emitted if @see open() succeeds. */
index 1a66639..a8c0db4 100644 (file)
@@ -121,6 +121,7 @@ bool Library::add(const QString &path)
     beginInsertRows(QModelIndex(), size, size);
     Book *book = new Book(path);
     book->peek();
+    book->dateAdded = QDateTime::currentDateTimeUtc();
     mBooks.append(book);
     save();
     endInsertRows();