1/****************************************************************************
2**
3** Copyright (C) 2018 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#include "collectionconfigreader.h"
41
42#include <QtGui/QGuiApplication>
43
44class QCG {
45 Q_DECLARE_TR_FUNCTIONS(QCollectionGenerator)
46};
47
48void CollectionConfigReader::raiseErrorWithLine()
49{
50 raiseError(message: QCG::tr(sourceText: "Unknown token at line %1.").arg(a: lineNumber()));
51}
52
53void CollectionConfigReader::readData(const QByteArray &contents)
54{
55 m_enableFilterFunctionality = true;
56 m_hideFilterFunctionality = true;
57 m_enableAddressBar = true;
58 m_hideAddressBar = true;
59 m_enableDocumentationManager = true;
60 m_enableFullTextSearchFallback = false;
61
62 addData(data: contents);
63 while (!atEnd()) {
64 readNext();
65 if (isStartElement()) {
66 if (name() == QLatin1String("QHelpCollectionProject")
67 && attributes().value(qualifiedName: QLatin1String("version")) == QLatin1String("1.0"))
68 readConfig();
69 else
70 raiseError(message: QCG::tr(sourceText: "Unknown token at line %1. "
71 "Expected \"QtHelpCollectionProject\".")
72 .arg(a: lineNumber()));
73 }
74 }
75}
76
77void CollectionConfigReader::readConfig()
78{
79 bool ok = false;
80 while (!atEnd()) {
81 readNext();
82 if (isStartElement()) {
83 if (name() == QLatin1String("assistant"))
84 readAssistantSettings();
85 else if (name() == QLatin1String("docFiles"))
86 readDocFiles();
87 else
88 raiseErrorWithLine();
89 } else if (isEndElement() && name() == QLatin1String("QHelpCollectionProject")) {
90 ok = true;
91 }
92 }
93 if (!ok && !hasError())
94 raiseError(message: QCG::tr(sourceText: "Missing end tags."));
95}
96
97void CollectionConfigReader::readAssistantSettings()
98{
99 while (!atEnd()) {
100 readNext();
101 if (isStartElement()) {
102 if (name() == QLatin1String("title")) {
103 m_title = readElementText();
104 } else if (name() == QLatin1String("homePage")) {
105 m_homePage = readElementText();
106 } else if (name() == QLatin1String("startPage")) {
107 m_startPage = readElementText();
108 } else if (name() == QLatin1String("currentFilter")) {
109 m_currentFilter = readElementText();
110 } else if (name() == QLatin1String("applicationIcon")) {
111 m_applicationIcon = readElementText();
112 } else if (name() == QLatin1String("enableFilterFunctionality")) {
113 if (attributes().value(qualifiedName: QLatin1String("visible")) == QLatin1String("true"))
114 m_hideFilterFunctionality = false;
115 if (readElementText() == QLatin1String("false"))
116 m_enableFilterFunctionality = false;
117 } else if (name() == QLatin1String("enableDocumentationManager")) {
118 if (readElementText() == QLatin1String("false"))
119 m_enableDocumentationManager = false;
120 } else if (name() == QLatin1String("enableAddressBar")) {
121 if (attributes().value(qualifiedName: QLatin1String("visible")) == QLatin1String("true"))
122 m_hideAddressBar = false;
123 if (readElementText() == QLatin1String("false"))
124 m_enableAddressBar = false;
125 } else if (name() == QLatin1String("aboutMenuText")) {
126 readMenuTexts();
127 } else if (name() == QLatin1String("aboutDialog")) {
128 readAboutDialog();
129 } else if (name() == "cacheDirectory") {
130 m_cacheDirRelativeToCollection =
131 attributes().value(qualifiedName: QLatin1String("base"))
132 == QLatin1String("collection");
133 m_cacheDirectory = readElementText();
134 } else if (name() == QLatin1String("enableFullTextSearchFallback")) {
135 if (readElementText() == QLatin1String("true"))
136 m_enableFullTextSearchFallback = true;
137 } else {
138 raiseErrorWithLine();
139 }
140 } else if (isEndElement() && name() == QLatin1String("assistant")) {
141 break;
142 }
143 }
144}
145
146void CollectionConfigReader::readMenuTexts()
147{
148 while (!atEnd()) {
149 readNext();
150 if (isStartElement()) {
151 if (name() == QLatin1String("text")) {
152 QString lang = attributes().value(qualifiedName: QLatin1String("language")).toString();
153 if (lang.isEmpty())
154 lang = QLatin1String("default");
155 m_aboutMenuTexts.insert(akey: lang, avalue: readElementText());
156 } else {
157 raiseErrorWithLine();
158 }
159 } else if (isEndElement() && name() == QLatin1String("aboutMenuText")) {
160 break;
161 }
162 }
163}
164
165void CollectionConfigReader::readAboutDialog()
166{
167 while (!atEnd()) {
168 readNext();
169 if (isStartElement()) {
170 if (name() == QLatin1String("file")) {
171 QString lang = attributes().value(qualifiedName: QLatin1String("language")).toString();
172 if (lang.isEmpty())
173 lang = QLatin1String("default");
174 m_aboutTextFiles.insert(akey: lang, avalue: readElementText());
175 } else if (name() == QLatin1String("icon")) {
176 m_aboutIcon = readElementText();
177 } else {
178 raiseErrorWithLine();
179 }
180 } else if (isEndElement() && name() == QLatin1String("aboutDialog")) {
181 break;
182 }
183 }
184}
185
186void CollectionConfigReader::readDocFiles()
187{
188 while (!atEnd()) {
189 readNext();
190 if (isStartElement()) {
191 if (name() == QLatin1String("generate")) {
192 readGenerate();
193 } else if (name() == QLatin1String("register")) {
194 readRegister();
195 } else {
196 raiseErrorWithLine();
197 }
198 } else if (isEndElement() && name() == QLatin1String("docFiles")) {
199 break;
200 }
201 }
202}
203
204void CollectionConfigReader::readGenerate()
205{
206 while (!atEnd()) {
207 readNext();
208 if (isStartElement()) {
209 if (name() == QLatin1String("file"))
210 readFiles();
211 else
212 raiseErrorWithLine();
213 } else if (isEndElement() && name() == QLatin1String("generate")) {
214 break;
215 }
216 }
217}
218
219void CollectionConfigReader::readFiles()
220{
221 QString input;
222 QString output;
223 while (!atEnd()) {
224 readNext();
225 if (isStartElement()) {
226 if (name() == QLatin1String("input"))
227 input = readElementText();
228 else if (name() == QLatin1String("output"))
229 output = readElementText();
230 else
231 raiseErrorWithLine();
232 } else if (isEndElement() && name() == QLatin1String("file")) {
233 break;
234 }
235 }
236 if (input.isEmpty() || output.isEmpty()) {
237 raiseError(message: QCG::tr(sourceText: "Missing input or output file for help file generation."));
238 return;
239 }
240 m_filesToGenerate.insert(akey: input, avalue: output);
241}
242
243void CollectionConfigReader::readRegister()
244{
245 while (!atEnd()) {
246 readNext();
247 if (isStartElement()) {
248 if (name() == QLatin1String("file"))
249 m_filesToRegister.append(t: readElementText());
250 else
251 raiseErrorWithLine();
252 } else if (isEndElement() && name() == QLatin1String("register")) {
253 break;
254 }
255 }
256}
257
258
259

source code of qttools/src/assistant/qhelpgenerator/collectionconfigreader.cpp