Allow editing bookmarks.
[dorian] / model / book.h
index dbc0b71..bfce66b 100644 (file)
@@ -4,10 +4,13 @@
 #include <QString>
 #include <QStringList>
 #include <QHash>
-#include <QIcon>
+#include <QImage>
 #include <QMetaType>
 #include <QObject>
 #include <QTemporaryFile>
+#include <QDateTime>
+
+class QPixmap;
 
 /** A book. */
 class Book: public QObject
@@ -27,44 +30,52 @@ public:
     /** Bookmark: a volume index and a relative position in volume. */
     struct Bookmark
     {
-        Bookmark(int part_, qreal pos_): part(part_), pos(pos_) {}
-        Bookmark() {part = pos = 0;}
+        Bookmark(int part_, qreal pos_, const QString &note_ = QString()):
+                part(part_), pos(pos_), note(note_) {}
+        Bookmark(): part(0), pos(0.0) {}
         int part;
         qreal pos;
-        bool operator<(const Bookmark&other) const {
-            return (part == other.part)? (pos < other.pos): (part < other.part);
+        QString note;
+        bool operator<(const Bookmark &other) const {
+            return (part == other.part)? (pos<other.pos): (part<other.part);
         }
     };
 
-    /** Construct a book from an EPUB file in path. */
-    Book(const QString &path, QObject *parent = 0);
+    /** Construct a book from an EPUB file. */
+    Book(const QString &fileName, QObject *parent = 0);
 
-    /** Default constructor. */
-    Book();
+    /** Destructor. */
+    ~Book();
 
-    /** Load book from persistent storage. */
+    /** Load book meta-data from persistent storage. */
     void load();
 
-    /** Save book to persistent storage. */
+    /** Save book meta-data to persistent storage. */
     void save();
 
+    /** Upgrade persistent storage of book meta-data. */
+    void upgrade();
+
+    /** Delete book meta-data from persistent storage. */
+    void remove();
+
     /** Extract and parse EPUB contents, fill in all members except mPath. */
     bool open();
 
-    /** Extract and parse EPUB metadata only, fill in all members except mPath. */
+    /** Extract and parse metadata only, fill in all members except mPath. */
     void peek();
 
     /** Clear toc and content members, remove extracted content files. */
     void close();
 
     /** Return path to EPUB. */
-    QString path() const;
+    QString path();
 
     /**
      * Return path to root directory of extracted EPUB.
      * Only valid after parsing Book::opsPath().
      */
-    QString rootPath() const;
+    QString rootPath();
 
     /** Return temporary directory path for extracting EPUB file. */
     QString tmpDir() const;
@@ -76,31 +87,37 @@ public:
     void setLastBookmark(int part, qreal position);
 
     /** Get last bookmark. */
-    Bookmark lastBookmark() const;
+    Bookmark lastBookmark();
 
     /** Add bookmark. */
-    void addBookmark(int part, qreal position);
+    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);
 
     /** List bookmarks. */
-    QList<Bookmark> bookmarks() const;
+    QList<Bookmark> bookmarks();
 
     /**
      * Get friendly name.
      * @return @see title or path name combined with author(s) name.
      */
-    QString name() const;
+    QString name();
+
+    /** Get cover image. */
+    QImage coverImage();
 
     /** Get short friendly name: title or file name. */
-    QString shortName() const;
+    QString shortName();
 
     /** Get chapter index from part index. */
     int chapterFromPart(int index);
 
-    /** Get part index from chapter index. */
-    int partFromChapter(int index);
+    /** Get part index and URL fragment from chapter index. */
+    int partFromChapter(int index, QString &fragment);
 
     /** Get progress (0..1) corresponding to part index and part position. */
     qreal getProgress(int part, qreal position);
@@ -118,8 +135,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. */
@@ -127,7 +146,7 @@ signals:
 
 protected:
     /** Extract EPUB as ZIP. */
-    bool extract();
+    bool extract(const QStringList &excludedExtensions);
 
     /** Extract metadata from EPUB. */
     bool extractMetaData();
@@ -141,11 +160,18 @@ protected:
     /** Get location of OPS file in EPUB archive. */
     QString opsPath();
 
+    /** Make a cover image from a file. */
+    QImage makeCover(const QString &fileName);
+
+    /** Make a cover image from an pixmap. */
+    QImage makeCover(const QPixmap &pixmap);
+
     QString mPath;                          //< Path to EPUB file.
     Bookmark mLastBookmark;                 //< Last position read.
     QList<Bookmark> mBookmarks;             //< List of bookmarks.
     QString mRootPath;                      //< Path to root item in EPUB dir.
     QTemporaryFile mTempFile;               //< Guards extracting books.
+    bool loaded;                            //< True, if loaded from database.
 };
 
 #endif // BOOK_H