1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QHELPCOLLECTIONHANDLER_H |
5 | #define QHELPCOLLECTIONHANDLER_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of the help generator tools. This header file may change from version |
13 | // to version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/QList> |
19 | #include <QtCore/QString> |
20 | #include <QtCore/QObject> |
21 | #include <QtCore/QVariant> |
22 | #include <QtCore/QStringList> |
23 | |
24 | #include <QtSql/QSqlQuery> |
25 | |
26 | #include "qhelpdbreader_p.h" |
27 | #include "qhelplink.h" |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QVersionNumber; |
32 | class QHelpFilterData; |
33 | |
34 | class QHelpCollectionHandler : public QObject |
35 | { |
36 | Q_OBJECT |
37 | |
38 | public: |
39 | struct FileInfo |
40 | { |
41 | QString fileName; |
42 | QString folderName; |
43 | QString namespaceName; |
44 | }; |
45 | typedef QList<FileInfo> FileInfoList; |
46 | |
47 | struct TimeStamp |
48 | { |
49 | int namespaceId = -1; |
50 | int folderId = -1; |
51 | QString fileName; |
52 | int size = 0; |
53 | QString timeStamp; |
54 | }; |
55 | |
56 | struct ContentsData |
57 | { |
58 | QString namespaceName; |
59 | QString folderName; |
60 | QList<QByteArray> contentsList; |
61 | }; |
62 | |
63 | explicit QHelpCollectionHandler(const QString &collectionFile, |
64 | QObject *parent = nullptr); |
65 | ~QHelpCollectionHandler(); |
66 | |
67 | QString collectionFile() const; |
68 | |
69 | bool openCollectionFile(); |
70 | bool copyCollectionFile(const QString &fileName); |
71 | |
72 | // *** Legacy block start *** |
73 | // legacy API since Qt 5.13 |
74 | |
75 | // use filters() instead |
76 | QStringList customFilters() const; |
77 | |
78 | // use QHelpFilterEngine::removeFilter() instead |
79 | bool removeCustomFilter(const QString &filterName); |
80 | |
81 | // use QHelpFilterEngine::setFilterData() instead |
82 | bool addCustomFilter(const QString &filterName, |
83 | const QStringList &attributes); |
84 | |
85 | // use files(const QString &, const QString &, const QString &) instead |
86 | QStringList files(const QString &namespaceName, |
87 | const QStringList &filterAttributes, |
88 | const QString &extensionFilter) const; |
89 | |
90 | // use namespaceForFile(const QUrl &, const QString &) instead |
91 | QString namespaceForFile(const QUrl &url, |
92 | const QStringList &filterAttributes) const; |
93 | |
94 | // use findFile(const QUrl &, const QString &) instead |
95 | QUrl findFile(const QUrl &url, |
96 | const QStringList &filterAttributes) const; |
97 | |
98 | // use indicesForFilter(const QString &) instead |
99 | QStringList indicesForFilter(const QStringList &filterAttributes) const; |
100 | |
101 | // use contentsForFilter(const QString &) instead |
102 | QList<ContentsData> contentsForFilter(const QStringList &filterAttributes) const; |
103 | |
104 | // use QHelpFilterEngine::activeFilter() and filterData(const QString &) instead; |
105 | QStringList filterAttributes() const; |
106 | |
107 | // use filterData(const QString &) instead |
108 | QStringList filterAttributes(const QString &filterName) const; |
109 | |
110 | // use filterData(const QString &) instead |
111 | QList<QStringList> filterAttributeSets(const QString &namespaceName) const; |
112 | |
113 | // use linksForIdentifier(const QString &, const QString &) instead |
114 | QMultiMap<QString, QUrl> linksForIdentifier(const QString &id, |
115 | const QStringList &filterAttributes) const; |
116 | |
117 | // use linksForKeyword(const QString &, const QString &) instead |
118 | QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword, |
119 | const QStringList &filterAttributes) const; |
120 | |
121 | // use documentsForIdentifier instead |
122 | QMultiMap<QString, QUrl> linksForIdentifier(const QString &id, const QString &filterName) const; |
123 | |
124 | // use documentsForKeyword instead |
125 | QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword, |
126 | const QString &filterName) const; |
127 | // *** Legacy block end *** |
128 | |
129 | QStringList filters() const; |
130 | |
131 | QStringList availableComponents() const; |
132 | QList<QVersionNumber> availableVersions() const; |
133 | QMap<QString, QString> namespaceToComponent() const; |
134 | QMap<QString, QVersionNumber> namespaceToVersion() const; |
135 | QHelpFilterData filterData(const QString &filterName) const; |
136 | bool setFilterData(const QString &filterName, const QHelpFilterData &filterData); |
137 | bool removeFilter(const QString &filterName); |
138 | |
139 | |
140 | FileInfo registeredDocumentation(const QString &namespaceName) const; |
141 | FileInfoList registeredDocumentations() const; |
142 | bool registerDocumentation(const QString &fileName); |
143 | bool unregisterDocumentation(const QString &namespaceName); |
144 | |
145 | |
146 | bool fileExists(const QUrl &url) const; |
147 | QStringList files(const QString &namespaceName, |
148 | const QString &filterName, |
149 | const QString &extensionFilter) const; |
150 | QString namespaceForFile(const QUrl &url, |
151 | const QString &filterName) const; |
152 | QUrl findFile(const QUrl &url, |
153 | const QString &filterName) const; |
154 | QByteArray fileData(const QUrl &url) const; |
155 | |
156 | |
157 | QStringList indicesForFilter(const QString &filterName) const; |
158 | QList<ContentsData> contentsForFilter(const QString &filterName) const; |
159 | |
160 | bool removeCustomValue(const QString &key); |
161 | QVariant customValue(const QString &key, const QVariant &defaultValue) const; |
162 | bool setCustomValue(const QString &key, const QVariant &value); |
163 | |
164 | |
165 | int registerNamespace(const QString &nspace, const QString &fileName); |
166 | int registerVirtualFolder(const QString &folderName, int namespaceId); |
167 | int registerComponent(const QString &componentName, int namespaceId); |
168 | bool registerVersion(const QString &version, int namespaceId); |
169 | |
170 | QList<QHelpLink> documentsForIdentifier(const QString &id, |
171 | const QString &filterName) const; |
172 | QList<QHelpLink> documentsForKeyword(const QString &keyword, |
173 | const QString &filterName) const; |
174 | QList<QHelpLink> documentsForIdentifier(const QString &id, |
175 | const QStringList &filterAttributes) const; |
176 | QList<QHelpLink> documentsForKeyword(const QString &keyword, |
177 | const QStringList &filterAttributes) const; |
178 | |
179 | QStringList namespacesForFilter(const QString &filterName) const; |
180 | |
181 | void setReadOnly(bool readOnly); |
182 | |
183 | static QUrl buildQUrl(const QString &ns, const QString &folder, |
184 | const QString &relFileName, const QString &anchor); |
185 | |
186 | signals: |
187 | void error(const QString &msg); |
188 | |
189 | private: |
190 | // legacy stuff |
191 | QMultiMap<QString, QUrl> linksForField(const QString &fieldName, |
192 | const QString &fieldValue, |
193 | const QStringList &filterAttributes) const; |
194 | QList<QHelpLink> documentsForField(const QString &fieldName, |
195 | const QString &fieldValue, |
196 | const QStringList &filterAttributes) const; |
197 | |
198 | QString namespaceVersion(const QString &namespaceName) const; |
199 | QMultiMap<QString, QUrl> linksForField(const QString &fieldName, const QString &fieldValue, |
200 | const QString &filterName) const; |
201 | QList<QHelpLink> documentsForField(const QString &fieldName, |
202 | const QString &fieldValue, |
203 | const QString &filterName) const; |
204 | |
205 | bool isDBOpened() const; |
206 | bool createTables(QSqlQuery *query); |
207 | void closeDB(); |
208 | bool recreateIndexAndNamespaceFilterTables(QSqlQuery *query); |
209 | bool registerIndexAndNamespaceFilterTables(const QString &nameSpace, |
210 | bool createDefaultVersionFilter = false); |
211 | void createVersionFilter(const QString &version); |
212 | bool registerFilterAttributes(const QList<QStringList> &attributeSets, int nsId); |
213 | bool registerFileAttributeSets(const QList<QStringList> &attributeSets, int nsId); |
214 | bool registerIndexTable(const QHelpDBReader::IndexTable &indexTable, |
215 | int nsId, int vfId, const QString &fileName); |
216 | bool unregisterIndexTable(int nsId, int vfId); |
217 | QString absoluteDocPath(const QString &fileName) const; |
218 | bool isTimeStampCorrect(const TimeStamp &timeStamp) const; |
219 | bool hasTimeStampInfo(const QString &nameSpace) const; |
220 | void scheduleVacuum(); |
221 | void execVacuum(); |
222 | |
223 | QString m_collectionFile; |
224 | QString m_connectionName; |
225 | QSqlQuery *m_query = nullptr; |
226 | bool m_vacuumScheduled = false; |
227 | bool m_readOnly = true; |
228 | }; |
229 | |
230 | QT_END_NAMESPACE |
231 | |
232 | #endif //QHELPCOLLECTIONHANDLER_H |
233 | |