1 /*
2 This file is part of kde-thumbnailer-epub
3 Copyright (C) 2012-2017 Giacomo Barazzetti <giacomosrv@gmail.com>
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef EPUB_H
20 #define EPUB_H
21 
22 #include <kzip.h>
23 #include <QtXmlPatterns/QXmlQuery>
24 
25 class QImage;
26 
27 class Epub
28 {
29 public:
30     explicit Epub(const QString &path);
31     ~Epub();
32     bool open();
33     bool getCoverImage(QImage &coverImage);
34 
35 private:
36     KZip mZip;
37 
38     QStringList mFilesList;
39     QString mOpfUrl;
40     QString mOpf;
41     QXmlQuery mOpfQuery;
42 
43     void loadFilesList(const KArchiveDirectory *dir, const QString &subPath = "");
44     bool loadOpf();
45 
46     // searching strategies
47     QString getRefFromMetadata();
48     QString getRefFromGuide();
49     QString getRefFromSpine(); // search the first ~xhtm according to spine, it could contain the cover image
50     QString getRefByName() const; // search for cover by filename
51 
52     QString getRefById(const QString &coverId);
53     QString getAttrFromOpf(const QString &query, const QString &namesp = "");
54     QString getRefFromXhtm(const QString &xhtmUrl) const; // search for the first image in a xhtm
55 
56     bool isImage(const QString &ref) const;
57     QString getAbsoluteUrl(const QString &url) const;
58     QByteArray getFile(const QString &fileName) const;
59 };
60 
61 #endif // EPUB_H
62