Facelift bookmarks dialog. Add Maemo-friendly dialog box class.
[dorian] / 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
10 /** A book. */
11 class Book
12 {
13 public:
14
15     /** Content item in the table of contents. */
16     struct ContentItem
17     {
18         QString href;
19         QString name;
20     };
21
22     /** Bookmark: a volume index and a relative position in volume. */
23     struct Bookmark
24     {
25         Bookmark(int chapter_, qreal pos_): chapter(chapter_), pos(pos_) {}
26         Bookmark() {chapter = pos = 0;}
27         int chapter;
28         qreal pos;
29         bool operator<(const Bookmark&other) const {
30             if (chapter != other.chapter) {
31                 return chapter < other.chapter;
32             } else {
33                 return pos < other.pos;
34             }
35         }
36     };
37
38     /** Construct a book from an EPUB file in path. */
39     Book(const QString &path);
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     void 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 chapter, qreal position);
73
74     /** Get last bookmark. */
75     Bookmark lastBookmark() const;
76
77     /** Add bookmark. */
78     void addBookmark(int chapter, 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 if title is not available yet.
89      */
90     QString name() const;
91
92     QString title;                          //< Book title from EPUB.
93     QStringList toc;                        //< Table of contents from EPUB.
94     QHash<QString, ContentItem> content;    //< Content items from EPUB.
95     QIcon cover;                            //< Cover image.
96     QStringList creators;                   //< Creators.
97     QString date;                           //< Date of creation.
98     QString publisher;                      //< Publisher.
99     QString datePublished;                  //< Date of publishing.
100     QString subject;                        //< Subject.
101     QString source;                         //< Source.
102     QString rights;                         //< Rights.
103     QString tocPath;                        //< Path to toc ncx.
104     QString coverPath;                      //< Path to cover html.
105     QString coverImagePath;                 //< Path to cover image.
106
107 protected:
108     /** Indicate failure by creating a single "error" content item. */
109     void fail(const QString &details,
110               const QString &error = QString("Could not open book"));
111
112     /** Extract EPUB as ZIP. */
113     bool extract();
114
115     /** Parse exteacted EPUB. */
116     bool parse();
117
118     /** Clear all book fields except path. */
119     void clear();
120
121     /** Get location of OPS file in EPUB archive. */
122     QString opsPath();
123
124     QString mPath;                          //< Path to EPUB file.
125     Bookmark mLastBookmark;                 //< Last position read.
126     QList<Bookmark> mBookmarks;             //< List of bookmarks.
127     QString mRootPath;                      //< Path to root item in EPUB dir.
128 };
129
130 Q_DECLARE_METATYPE(Book)
131
132 #endif // BOOK_H