More naming fixes.
[dorian] / model / book.h
1 #ifndef BOOK_H
2 #define BOOK_H
3
4 #include <QString>
5 #include <QStringList>
6 #include <QHash>
7 #include <QIcon>
8 #include <QMetaType>
9 #include <QObject>
10
11 /** A book. */
12 class Book: public QObject
13 {
14     Q_OBJECT
15
16 public:
17
18     /** Content item in the table of contents. */
19     struct ContentItem
20     {
21         QString href;
22         QString name;
23         qint64 size;
24     };
25
26     /** Bookmark: a volume index and a relative position in volume. */
27     struct Bookmark
28     {
29         Bookmark(int part_, qreal pos_): part(part_), pos(pos_) {}
30         Bookmark() {part = pos = 0;}
31         int part;
32         qreal pos;
33         bool operator<(const Bookmark&other) const {
34             return (part == other.part)? (pos < other.pos): (part < other.part);
35         }
36     };
37
38     /** Construct a book from an EPUB file in path. */
39     Book(const QString &path, QObject *parent = 0);
40
41     /** Default constructor. */
42     Book();
43
44     /** Load book from persistent storage. */
45     void load();
46
47     /** Save book to persistent storage. */
48     void save();
49
50     /** Extract and parse EPUB contents, fill in all members except mPath. */
51     bool open();
52
53     /** Clear toc and content members, remove extracted content files. */
54     void close();
55
56     /** Return path to EPUB. */
57     QString path() const;
58
59     /**
60      * Return path to root directory of extracted EPUB.
61      * Only valid after parsing Book::opsPath().
62      */
63     QString rootPath() const;
64
65     /** Return temporary directory path for extracting EPUB file. */
66     QString tmpDir() const;
67
68     /** Clear directory. */
69     bool clearDir(const QString &directory);
70
71     /** Set last bookmark. */
72     void setLastBookmark(int part, qreal position);
73
74     /** Get last bookmark. */
75     Bookmark lastBookmark() const;
76
77     /** Add bookmark. */
78     void addBookmark(int part, qreal position);
79
80     /** Delete bookmark. */
81     void deleteBookmark(int index);
82
83     /** List bookmarks. */
84     QList<Bookmark> bookmarks() const;
85
86     /**
87      * Get friendly name.
88      * @return @see title or path name combined with author(s) name.
89      */
90     QString name() const;
91
92     /** Get short friendly name: title or file name. */
93     QString shortName() const;
94
95     /** Get chapter index from part index. */
96     int chapterFromPart(int index);
97
98     /** Get part index from chapter index. */
99     int partFromChapter(int index);
100
101     QString title;                          //< Book title from EPUB.
102     QStringList parts;                      //< EPUB part list.
103     QHash<QString, ContentItem> content;    //< Content items from EPUB.
104     QImage cover;                           //< Cover image.
105     QStringList creators;                   //< Creators.
106     QString date;                           //< Date of creation.
107     QString publisher;                      //< Publisher.
108     QString datePublished;                  //< Date of publishing.
109     QString subject;                        //< Subject.
110     QString source;                         //< Source.
111     QString rights;                         //< Rights.
112     QString tocPath;                        //< Path to toc ncx.
113     QString coverPath;                      //< Path to cover html.
114     QStringList chapters;                   //< Main navigation items from EPUB.
115
116 signals:
117     /** Emitted if @see open() succeeds. */
118     void opened(const QString &bookPath);
119
120 protected:
121     /** Extract EPUB as ZIP. */
122     bool extract();
123
124     /** Parse extracted EPUB. */
125     bool parse();
126
127     /** Clear all book fields except path. */
128     void clear();
129
130     /** Get location of OPS file in EPUB archive. */
131     QString opsPath();
132
133     QString mPath;                          //< Path to EPUB file.
134     Bookmark mLastBookmark;                 //< Last position read.
135     QList<Bookmark> mBookmarks;             //< List of bookmarks.
136     QString mRootPath;                      //< Path to root item in EPUB dir.
137 };
138
139 #endif // BOOK_H