1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Assistant of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QHELPCOLLECTIONHANDLER_H
41#define QHELPCOLLECTIONHANDLER_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of the help generator tools. This header file may change from version
49// to version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtCore/QList>
55#include <QtCore/QString>
56#include <QtCore/QObject>
57#include <QtCore/QVariant>
58#include <QtCore/QStringList>
59
60#include <QtSql/QSqlQuery>
61
62#include "qhelpdbreader_p.h"
63
64QT_BEGIN_NAMESPACE
65
66class QVersionNumber;
67class QHelpFilterData;
68struct QHelpLink;
69
70class QHelpCollectionHandler : public QObject
71{
72 Q_OBJECT
73
74public:
75 struct FileInfo
76 {
77 QString fileName;
78 QString folderName;
79 QString namespaceName;
80 };
81 typedef QList<FileInfo> FileInfoList;
82
83 struct TimeStamp
84 {
85 int namespaceId = -1;
86 int folderId = -1;
87 QString fileName;
88 int size = 0;
89 QString timeStamp;
90 };
91
92 struct ContentsData
93 {
94 QString namespaceName;
95 QString folderName;
96 QList<QByteArray> contentsList;
97 };
98
99 explicit QHelpCollectionHandler(const QString &collectionFile,
100 QObject *parent = nullptr);
101 ~QHelpCollectionHandler();
102
103 QString collectionFile() const;
104
105 bool openCollectionFile();
106 bool copyCollectionFile(const QString &fileName);
107
108 // *** Legacy block start ***
109 // legacy API since Qt 5.13
110
111 // use filters() instead
112 QStringList customFilters() const;
113
114 // use QHelpFilterEngine::removeFilter() instead
115 bool removeCustomFilter(const QString &filterName);
116
117 // use QHelpFilterEngine::setFilterData() instead
118 bool addCustomFilter(const QString &filterName,
119 const QStringList &attributes);
120
121 // use files(const QString &, const QString &, const QString &) instead
122 QStringList files(const QString &namespaceName,
123 const QStringList &filterAttributes,
124 const QString &extensionFilter) const;
125
126 // use namespaceForFile(const QUrl &, const QString &) instead
127 QString namespaceForFile(const QUrl &url,
128 const QStringList &filterAttributes) const;
129
130 // use findFile(const QUrl &, const QString &) instead
131 QUrl findFile(const QUrl &url,
132 const QStringList &filterAttributes) const;
133
134 // use indicesForFilter(const QString &) instead
135 QStringList indicesForFilter(const QStringList &filterAttributes) const;
136
137 // use contentsForFilter(const QString &) instead
138 QList<ContentsData> contentsForFilter(const QStringList &filterAttributes) const;
139
140 // use QHelpFilterEngine::activeFilter() and filterData(const QString &) instead;
141 QStringList filterAttributes() const;
142
143 // use filterData(const QString &) instead
144 QStringList filterAttributes(const QString &filterName) const;
145
146 // use filterData(const QString &) instead
147 QList<QStringList> filterAttributeSets(const QString &namespaceName) const;
148
149 // use linksForIdentifier(const QString &, const QString &) instead
150 QMap<QString, QUrl> linksForIdentifier(const QString &id,
151 const QStringList &filterAttributes) const;
152
153 // use linksForKeyword(const QString &, const QString &) instead
154 QMap<QString, QUrl> linksForKeyword(const QString &keyword,
155 const QStringList &filterAttributes) const;
156
157 // use documentsForIdentifier instead
158 QMap<QString, QUrl> linksForIdentifier(const QString &id,
159 const QString &filterName) const;
160
161 // use documentsForKeyword instead
162 QMap<QString, QUrl> linksForKeyword(const QString &keyword,
163 const QString &filterName) const;
164 // *** Legacy block end ***
165
166 QStringList filters() const;
167
168 QStringList availableComponents() const;
169 QList<QVersionNumber> availableVersions() const;
170 QMap<QString, QString> namespaceToComponent() const;
171 QMap<QString, QVersionNumber> namespaceToVersion() const;
172 QHelpFilterData filterData(const QString &filterName) const;
173 bool setFilterData(const QString &filterName, const QHelpFilterData &filterData);
174 bool removeFilter(const QString &filterName);
175
176
177 FileInfo registeredDocumentation(const QString &namespaceName) const;
178 FileInfoList registeredDocumentations() const;
179 bool registerDocumentation(const QString &fileName);
180 bool unregisterDocumentation(const QString &namespaceName);
181
182
183 bool fileExists(const QUrl &url) const;
184 QStringList files(const QString &namespaceName,
185 const QString &filterName,
186 const QString &extensionFilter) const;
187 QString namespaceForFile(const QUrl &url,
188 const QString &filterName) const;
189 QUrl findFile(const QUrl &url,
190 const QString &filterName) const;
191 QByteArray fileData(const QUrl &url) const;
192
193
194 QStringList indicesForFilter(const QString &filterName) const;
195 QList<ContentsData> contentsForFilter(const QString &filterName) const;
196
197 bool removeCustomValue(const QString &key);
198 QVariant customValue(const QString &key, const QVariant &defaultValue) const;
199 bool setCustomValue(const QString &key, const QVariant &value);
200
201
202 int registerNamespace(const QString &nspace, const QString &fileName);
203 int registerVirtualFolder(const QString &folderName, int namespaceId);
204 int registerComponent(const QString &componentName, int namespaceId);
205 bool registerVersion(const QString &version, int namespaceId);
206
207 QList<QHelpLink> documentsForIdentifier(const QString &id,
208 const QString &filterName) const;
209 QList<QHelpLink> documentsForKeyword(const QString &keyword,
210 const QString &filterName) const;
211 QList<QHelpLink> documentsForIdentifier(const QString &id,
212 const QStringList &filterAttributes) const;
213 QList<QHelpLink> documentsForKeyword(const QString &keyword,
214 const QStringList &filterAttributes) const;
215
216 QStringList namespacesForFilter(const QString &filterName) const;
217
218 void setReadOnly(bool readOnly);
219
220signals:
221 void error(const QString &msg) const;
222
223private:
224 // legacy stuff
225 QMap<QString, QUrl> linksForField(const QString &fieldName,
226 const QString &fieldValue,
227 const QStringList &filterAttributes) const;
228 QList<QHelpLink> documentsForField(const QString &fieldName,
229 const QString &fieldValue,
230 const QStringList &filterAttributes) const;
231
232 QString namespaceVersion(const QString &namespaceName) const;
233 QMap<QString, QUrl> linksForField(const QString &fieldName,
234 const QString &fieldValue,
235 const QString &filterName) const;
236 QList<QHelpLink> documentsForField(const QString &fieldName,
237 const QString &fieldValue,
238 const QString &filterName) const;
239
240 bool isDBOpened() const;
241 bool createTables(QSqlQuery *query);
242 void closeDB();
243 bool recreateIndexAndNamespaceFilterTables(QSqlQuery *query);
244 bool registerIndexAndNamespaceFilterTables(const QString &nameSpace,
245 bool createDefaultVersionFilter = false);
246 void createVersionFilter(const QString &version);
247 bool registerFilterAttributes(const QList<QStringList> &attributeSets, int nsId);
248 bool registerFileAttributeSets(const QList<QStringList> &attributeSets, int nsId);
249 bool registerIndexTable(const QHelpDBReader::IndexTable &indexTable,
250 int nsId, int vfId, const QString &fileName);
251 bool unregisterIndexTable(int nsId, int vfId);
252 QString absoluteDocPath(const QString &fileName) const;
253 bool isTimeStampCorrect(const TimeStamp &timeStamp) const;
254 bool hasTimeStampInfo(const QString &nameSpace) const;
255 void scheduleVacuum();
256 void execVacuum();
257
258 QString m_collectionFile;
259 QString m_connectionName;
260 QSqlQuery *m_query = nullptr;
261 bool m_vacuumScheduled = false;
262 bool m_readOnly = false;
263};
264
265QT_END_NAMESPACE
266
267#endif //QHELPCOLLECTIONHANDLER_H
268

source code of qttools/src/assistant/help/qhelpcollectionhandler_p.h