-
Notifications
You must be signed in to change notification settings - Fork 2
/
zimfilewrapper.h
92 lines (75 loc) · 3.25 KB
/
zimfilewrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* WikiOnBoard
Copyright (C) 2011 Christian Puehringer
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.*/
#ifndef ZIMFILEWRAPPER_H
#define ZIMFILEWRAPPER_H
#include <QObject>
#include <zim/zim.h>
#include <zim/fileiterator.h>
#include <QPixmap>
#include <QFile>
#include <QDirIterator>
#include <QDebug>
#include <QMutex>
//TODO define implictly shared class?
class ZimFileWrapper : public QObject
{
Q_OBJECT
Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
Q_PROPERTY(int isTooLargeError READ isTooLargeError NOTIFY isTooLargeErrorChanged)
private:
zim::File* zimFile;
bool valid;
QString m_errorStr;
bool m_isTooLargeError;
QDirIterator* dirIterator;
QString byteArray2HexQString(const QByteArray &byteArray);
mutable QMutex mutex;
public:
explicit ZimFileWrapper(QObject *parent = 0);
~ZimFileWrapper();
bool isValid() {return valid;}
QString errorString() {return m_errorStr;}
bool isTooLargeError() {return m_isTooLargeError;}
Q_INVOKABLE bool openZimFile(QString zimFileName);
zim::File::const_iterator getArticleByUrl(QString articleUrl,QChar nameSpace='A', bool closestMatchIfNotFound=true);
QString getArticleTextByTitle(QString articleTitle);
QPair<QByteArray, QString> getDataByUrl(QString articleUrl);
Q_INVOKABLE QString getMetaDataString(QString key);
QString getArticleTitleByUrl(QString articleUrl);
std::pair<bool, QString> getMetaData(QString key);
QByteArray getUUID();
Q_INVOKABLE QString getUUIDString();
QString getFilename();
//TODO: should no expose the zim file iterators, but encapsulate them instead
zim::File::const_iterator end();
//In QML with QChar nameSpace not working, therefore
//QString variant added. Old QChar kept to reduce
// risk of problem with non-qml version
Q_INVOKABLE int getNamespaceCount(QString nameSpace);
int getNamespaceCount(QChar nameSpace);
zim::File::const_iterator findByTitle(QChar nameSpace, QString articleTitle);
std::pair<bool, zim::File::const_iterator> findxByTitle(QChar nameSpace, QString articleTitle);
zim::File::const_iterator begin();
zim::File::const_iterator beginByTitle();
QString fromUTF8EncodedStdString(std::string s) {
return QString::fromUtf8(s.data(), int(s.size()));
}
Q_INVOKABLE void zimFileIterator(QString path, bool recurseSubdirs);
Q_INVOKABLE QString nextZimFile();
protected:
signals:
void errorStringChanged(QString errorString);
void isTooLargeErrorChanged(bool isTooLargeError);
public slots:
};
#endif // ZIMFILEWRAPPER_H