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 "qhelpdbreader_p.h" |
19 | #include "qhelplink.h" |
20 | |
21 | #include <QtCore/qdatetime.h> |
22 | #include <QtCore/qobject.h> |
23 | #include <QtCore/qstringlist.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class QHelpFilterData; |
28 | class QSqlQuery; |
29 | class QVariant; |
30 | class QVersionNumber; |
31 | |
32 | class QHelpCollectionHandler : public QObject |
33 | { |
34 | Q_OBJECT |
35 | |
36 | public: |
37 | struct FileInfo |
38 | { |
39 | QString fileName; |
40 | QString folderName; |
41 | QString namespaceName; |
42 | }; |
43 | typedef QList<FileInfo> FileInfoList; |
44 | |
45 | struct TimeStamp |
46 | { |
47 | int namespaceId = -1; |
48 | int folderId = -1; |
49 | QString fileName; |
50 | int size = 0; |
51 | QDateTime timeStamp; |
52 | }; |
53 | |
54 | struct ContentsData |
55 | { |
56 | QString namespaceName; |
57 | QString folderName; |
58 | QList<QByteArray> contentsList; |
59 | }; |
60 | |
61 | explicit QHelpCollectionHandler(const QString &collectionFile, QObject *parent = nullptr); |
62 | ~QHelpCollectionHandler(); |
63 | |
64 | QString collectionFile() const { return m_collectionFile; } |
65 | |
66 | bool openCollectionFile(); |
67 | bool copyCollectionFile(const QString &fileName); |
68 | |
69 | // *** Legacy block start *** |
70 | // legacy API since Qt 5.13 |
71 | |
72 | // use filters() instead |
73 | QStringList customFilters() const; |
74 | |
75 | // use QHelpFilterEngine::removeFilter() instead |
76 | bool removeCustomFilter(const QString &filterName); |
77 | |
78 | // use QHelpFilterEngine::setFilterData() instead |
79 | bool addCustomFilter(const QString &filterName, const QStringList &attributes); |
80 | |
81 | // use files(const QString &, const QString &, const QString &) instead |
82 | QStringList files(const QString &namespaceName, |
83 | const QStringList &filterAttributes, |
84 | const QString &extensionFilter) const; |
85 | |
86 | // use namespaceForFile(const QUrl &, const QString &) instead |
87 | QString namespaceForFile(const QUrl &url, const QStringList &filterAttributes) const; |
88 | |
89 | // use findFile(const QUrl &, const QString &) instead |
90 | QUrl findFile(const QUrl &url, const QStringList &filterAttributes) const; |
91 | |
92 | // use indicesForFilter(const QString &) instead |
93 | QStringList indicesForFilter(const QStringList &filterAttributes) const; |
94 | |
95 | // use contentsForFilter(const QString &) instead |
96 | QList<ContentsData> contentsForFilter(const QStringList &filterAttributes) const; |
97 | |
98 | // use QHelpFilterEngine::activeFilter() and filterData(const QString &) instead; |
99 | QStringList filterAttributes() const; |
100 | |
101 | // use filterData(const QString &) instead |
102 | QStringList filterAttributes(const QString &filterName) const; |
103 | |
104 | // use filterData(const QString &) instead |
105 | QList<QStringList> filterAttributeSets(const QString &namespaceName) const; |
106 | |
107 | // *** Legacy block end *** |
108 | |
109 | QStringList filters() const; |
110 | |
111 | QStringList availableComponents() const; |
112 | QList<QVersionNumber> availableVersions() const; |
113 | QMap<QString, QString> namespaceToComponent() const; |
114 | QMap<QString, QVersionNumber> namespaceToVersion() const; |
115 | QHelpFilterData filterData(const QString &filterName) const; |
116 | bool setFilterData(const QString &filterName, const QHelpFilterData &filterData); |
117 | bool removeFilter(const QString &filterName); |
118 | |
119 | FileInfo registeredDocumentation(const QString &namespaceName) const; |
120 | FileInfoList registeredDocumentations() const; |
121 | bool registerDocumentation(const QString &fileName); |
122 | bool unregisterDocumentation(const QString &namespaceName); |
123 | |
124 | bool fileExists(const QUrl &url) const; |
125 | QStringList files(const QString &namespaceName, |
126 | const QString &filterName, |
127 | const QString &extensionFilter) const; |
128 | QString namespaceForFile(const QUrl &url, const QString &filterName) const; |
129 | QUrl findFile(const QUrl &url, const QString &filterName) const; |
130 | QByteArray fileData(const QUrl &url) const; |
131 | |
132 | QStringList indicesForFilter(const QString &filterName) const; |
133 | QList<ContentsData> contentsForFilter(const QString &filterName) const; |
134 | |
135 | bool removeCustomValue(const QString &key); |
136 | QVariant customValue(const QString &key, const QVariant &defaultValue) const; |
137 | bool setCustomValue(const QString &key, const QVariant &value); |
138 | |
139 | int registerNamespace(const QString &nspace, const QString &fileName); |
140 | int registerVirtualFolder(const QString &folderName, int namespaceId); |
141 | int registerComponent(const QString &componentName, int namespaceId); |
142 | bool registerVersion(const QString &version, int namespaceId); |
143 | |
144 | QList<QHelpLink> documentsForIdentifier(const QString &id, const QString &filterName) const; |
145 | QList<QHelpLink> documentsForKeyword(const QString &keyword, const QString &filterName) const; |
146 | QList<QHelpLink> documentsForIdentifier(const QString &id, |
147 | const QStringList &filterAttributes) const; |
148 | QList<QHelpLink> documentsForKeyword(const QString &keyword, |
149 | const QStringList &filterAttributes) const; |
150 | |
151 | QStringList namespacesForFilter(const QString &filterName) const; |
152 | |
153 | void setReadOnly(bool readOnly) { m_readOnly = readOnly; } |
154 | |
155 | static QUrl buildQUrl(const QString &ns, const QString &folder, |
156 | const QString &relFileName, const QString &anchor); |
157 | |
158 | signals: |
159 | void error(const QString &msg); |
160 | |
161 | private: |
162 | // legacy stuff |
163 | QList<QHelpLink> documentsForField(const QString &fieldName, |
164 | const QString &fieldValue, |
165 | const QStringList &filterAttributes) const; |
166 | |
167 | QString namespaceVersion(const QString &namespaceName) const; |
168 | QMultiMap<QString, QUrl> linksForField(const QString &fieldName, const QString &fieldValue, |
169 | const QString &filterName) const; |
170 | QList<QHelpLink> documentsForField(const QString &fieldName, |
171 | const QString &fieldValue, |
172 | const QString &filterName) const; |
173 | |
174 | bool isDBOpened() const; |
175 | bool createTables(QSqlQuery *query); |
176 | void closeDB(); |
177 | bool recreateIndexAndNamespaceFilterTables(QSqlQuery *query); |
178 | bool registerIndexAndNamespaceFilterTables(const QString &nameSpace, |
179 | bool createDefaultVersionFilter = false); |
180 | void createVersionFilter(const QString &version); |
181 | bool registerFilterAttributes(const QList<QStringList> &attributeSets, int nsId); |
182 | bool registerFileAttributeSets(const QList<QStringList> &attributeSets, int nsId); |
183 | bool registerIndexTable(const QHelpDBReader::IndexTable &indexTable, |
184 | int nsId, int vfId, const QString &fileName); |
185 | bool unregisterIndexTable(int nsId, int vfId); |
186 | QString absoluteDocPath(const QString &fileName) const; |
187 | bool isTimeStampCorrect(const TimeStamp &timeStamp) const; |
188 | bool hasTimeStampInfo(const QString &nameSpace) const; |
189 | void scheduleVacuum(); |
190 | void execVacuum(); |
191 | |
192 | QString m_collectionFile; |
193 | QString m_connectionName; |
194 | std::unique_ptr<QSqlQuery> m_query; |
195 | bool m_vacuumScheduled = false; |
196 | bool m_readOnly = true; |
197 | }; |
198 | |
199 | QT_END_NAMESPACE |
200 | |
201 | #endif // QHELPCOLLECTIONHANDLER_H |
202 | |