Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
collectionconfigreader.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:insignificant reason:build-tool
4
6
7#include <QtGui/QGuiApplication>
8
9class QCG {
10 Q_DECLARE_TR_FUNCTIONS(QCollectionGenerator)
11};
12
13void CollectionConfigReader::raiseErrorWithLine()
14{
15 raiseError(QCG::tr("Unknown token at line %1.").arg(lineNumber()));
16}
17
18void CollectionConfigReader::readData(const QByteArray &contents)
19{
20 m_enableFilterFunctionality = true;
21 m_hideFilterFunctionality = true;
22 m_enableAddressBar = true;
23 m_hideAddressBar = true;
24 m_enableDocumentationManager = true;
25 m_enableFullTextSearchFallback = false;
26
27 addData(contents);
28 while (!atEnd()) {
29 readNext();
30 if (isStartElement()) {
31 if (name() == QLatin1String("QHelpCollectionProject")
32 && attributes().value(QLatin1String("version")) == QLatin1String("1.0"))
33 readConfig();
34 else
35 raiseError(QCG::tr("Unknown token at line %1. "
36 "Expected \"QtHelpCollectionProject\".")
37 .arg(lineNumber()));
38 }
39 }
40}
41
42void CollectionConfigReader::readConfig()
43{
44 bool ok = false;
45 while (!atEnd()) {
46 readNext();
47 if (isStartElement()) {
48 if (name() == QLatin1String("assistant"))
49 readAssistantSettings();
50 else if (name() == QLatin1String("docFiles"))
51 readDocFiles();
52 else
53 raiseErrorWithLine();
54 } else if (isEndElement() && name() == QLatin1String("QHelpCollectionProject")) {
55 ok = true;
56 }
57 }
58 if (!ok && !hasError())
59 raiseError(QCG::tr("Missing end tags."));
60}
61
62void CollectionConfigReader::readAssistantSettings()
63{
64 while (!atEnd()) {
65 readNext();
66 if (isStartElement()) {
67 if (name() == QLatin1String("title")) {
68 m_title = readElementText();
69 } else if (name() == QLatin1String("homePage")) {
70 m_homePage = readElementText();
71 } else if (name() == QLatin1String("startPage")) {
72 m_startPage = readElementText();
73 } else if (name() == QLatin1String("currentFilter")) {
74 m_currentFilter = readElementText();
75 } else if (name() == QLatin1String("applicationIcon")) {
76 m_applicationIcon = readElementText();
77 } else if (name() == QLatin1String("enableFilterFunctionality")) {
78 if (attributes().value(QLatin1String("visible")) == QLatin1String("true"))
79 m_hideFilterFunctionality = false;
80 if (readElementText() == QLatin1String("false"))
81 m_enableFilterFunctionality = false;
82 } else if (name() == QLatin1String("enableDocumentationManager")) {
83 if (readElementText() == QLatin1String("false"))
84 m_enableDocumentationManager = false;
85 } else if (name() == QLatin1String("enableAddressBar")) {
86 if (attributes().value(QLatin1String("visible")) == QLatin1String("true"))
87 m_hideAddressBar = false;
88 if (readElementText() == QLatin1String("false"))
89 m_enableAddressBar = false;
90 } else if (name() == QLatin1String("aboutMenuText")) {
91 readMenuTexts();
92 } else if (name() == QLatin1String("aboutDialog")) {
93 readAboutDialog();
94 } else if (name() == u"cacheDirectory") {
95 m_cacheDirRelativeToCollection =
96 attributes().value(QLatin1String("base"))
97 == QLatin1String("collection");
98 m_cacheDirectory = readElementText();
99 } else if (name() == QLatin1String("enableFullTextSearchFallback")) {
100 if (readElementText() == QLatin1String("true"))
101 m_enableFullTextSearchFallback = true;
102 } else {
103 raiseErrorWithLine();
104 }
105 } else if (isEndElement() && name() == QLatin1String("assistant")) {
106 break;
107 }
108 }
109}
110
111void CollectionConfigReader::readMenuTexts()
112{
113 while (!atEnd()) {
114 readNext();
115 if (isStartElement()) {
116 if (name() == QLatin1String("text")) {
117 QString lang = attributes().value(QLatin1String("language")).toString();
118 if (lang.isEmpty())
119 lang = QLatin1String("default");
120 m_aboutMenuTexts.insert(lang, readElementText());
121 } else {
122 raiseErrorWithLine();
123 }
124 } else if (isEndElement() && name() == QLatin1String("aboutMenuText")) {
125 break;
126 }
127 }
128}
129
130void CollectionConfigReader::readAboutDialog()
131{
132 while (!atEnd()) {
133 readNext();
134 if (isStartElement()) {
135 if (name() == QLatin1String("file")) {
136 QString lang = attributes().value(QLatin1String("language")).toString();
137 if (lang.isEmpty())
138 lang = QLatin1String("default");
139 m_aboutTextFiles.insert(lang, readElementText());
140 } else if (name() == QLatin1String("icon")) {
141 m_aboutIcon = readElementText();
142 } else {
143 raiseErrorWithLine();
144 }
145 } else if (isEndElement() && name() == QLatin1String("aboutDialog")) {
146 break;
147 }
148 }
149}
150
151void CollectionConfigReader::readDocFiles()
152{
153 while (!atEnd()) {
154 readNext();
155 if (isStartElement()) {
156 if (name() == QLatin1String("generate")) {
157 readGenerate();
158 } else if (name() == QLatin1String("register")) {
159 readRegister();
160 } else {
161 raiseErrorWithLine();
162 }
163 } else if (isEndElement() && name() == QLatin1String("docFiles")) {
164 break;
165 }
166 }
167}
168
169void CollectionConfigReader::readGenerate()
170{
171 while (!atEnd()) {
172 readNext();
173 if (isStartElement()) {
174 if (name() == QLatin1String("file"))
175 readFiles();
176 else
177 raiseErrorWithLine();
178 } else if (isEndElement() && name() == QLatin1String("generate")) {
179 break;
180 }
181 }
182}
183
184void CollectionConfigReader::readFiles()
185{
186 QString input;
187 QString output;
188 while (!atEnd()) {
189 readNext();
190 if (isStartElement()) {
191 if (name() == QLatin1String("input"))
192 input = readElementText();
193 else if (name() == QLatin1String("output"))
194 output = readElementText();
195 else
196 raiseErrorWithLine();
197 } else if (isEndElement() && name() == QLatin1String("file")) {
198 break;
199 }
200 }
201 if (input.isEmpty() || output.isEmpty()) {
202 raiseError(QCG::tr("Missing input or output file for help file generation."));
203 return;
204 }
205 m_filesToGenerate.insert(input, output);
206}
207
208void CollectionConfigReader::readRegister()
209{
210 while (!atEnd()) {
211 readNext();
212 if (isStartElement()) {
213 if (name() == QLatin1String("file"))
214 m_filesToRegister.append(readElementText());
215 else
216 raiseErrorWithLine();
217 } else if (isEndElement() && name() == QLatin1String("register")) {
218 break;
219 }
220 }
221}