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#include "collectionconfiguration.h"
5
6#include <QtHelp/QHelpEngineCore>
7
8QT_BEGIN_NAMESPACE
9
10namespace {
11 const QString AboutIconKey(QLatin1String("AboutIcon"));
12 const QString AboutImagesKey(QLatin1String("AboutImages"));
13 const QString AboutMenuTextsKey(QLatin1String("AboutMenuTexts"));
14 const QString AboutTextsKey(QLatin1String("AboutTexts"));
15 const QString ApplicationIconKey(QLatin1String("ApplicationIcon"));
16 const QString CacheDirKey(QLatin1String("CacheDirectory"));
17 const QString CacheDirRelativeToCollectionKey(QLatin1String("CacheDirRelativeToCollection"));
18 const QString CreationTimeKey(QLatin1String("CreationTime"));
19 const QString DefaultHomePageKey(QLatin1String("defaultHomepage"));
20 const QString EnableAddressBarKey(QLatin1String("EnableAddressBar"));
21 const QString EnableDocManagerKey(QLatin1String("EnableDocumentationManager"));
22 const QString EnableFilterKey(QLatin1String("EnableFilterFunctionality"));
23 const QString HideAddressBarKey(QLatin1String("HideAddressBar"));
24 const QString FilterToolbarHiddenKey(QLatin1String("HideFilterFunctionality"));
25 const QString LastPageKey(QLatin1String("LastTabPage"));
26 const QString LastRegisterTime(QLatin1String("LastRegisterTime"));
27 const QString LastShownPagesKey(QLatin1String("LastShownPages"));
28 const QString LastZoomFactorsKey(QLatin1String(
29#if defined(BROWSER_QTWEBKIT)
30 "LastPagesZoomWebView"
31#else
32 "LastPagesZoomTextBrowser"
33#endif
34 ));
35 const QString WindowTitleKey(QLatin1String("WindowTitle"));
36 const QString FullTextSearchFallbackKey(QLatin1String("FullTextSearchFallback"));
37} // anonymous namespace
38
39const QString CollectionConfiguration::DefaultZoomFactor(QLatin1String("0.0"));
40const QString CollectionConfiguration::ListSeparator(QLatin1String("|"));
41
42uint CollectionConfiguration::creationTime(const QHelpEngineCore &helpEngine)
43{
44 return helpEngine.customValue(key: CreationTimeKey, defaultValue: 0).toUInt();
45}
46
47void CollectionConfiguration::setCreationTime(QHelpEngineCore &helpEngine, uint time)
48{
49 helpEngine.setCustomValue(key: CreationTimeKey, value: time);
50}
51
52const QString CollectionConfiguration::windowTitle(const QHelpEngineCore &helpEngine)
53{
54 return helpEngine.customValue(key: WindowTitleKey).toString();
55}
56
57void CollectionConfiguration::setWindowTitle(QHelpEngineCore &helpEngine,
58 const QString &windowTitle)
59{
60 helpEngine.setCustomValue(key: WindowTitleKey, value: windowTitle);
61}
62
63bool CollectionConfiguration::filterFunctionalityEnabled(const QHelpEngineCore &helpEngine)
64{
65 return helpEngine.customValue(key: EnableFilterKey, defaultValue: true).toBool();
66}
67
68void CollectionConfiguration::setFilterFunctionalityEnabled(QHelpEngineCore &helpEngine,
69 bool enabled)
70{
71 helpEngine.setCustomValue(key: EnableFilterKey, value: enabled);
72}
73
74bool CollectionConfiguration::filterToolbarVisible(const QHelpEngineCore &helpEngine)
75{
76 return !helpEngine.customValue(key: FilterToolbarHiddenKey, defaultValue: true).toBool();
77}
78
79void CollectionConfiguration::setFilterToolbarVisible(QHelpEngineCore &helpEngine,
80 bool visible)
81{
82 helpEngine.setCustomValue(key: FilterToolbarHiddenKey, value: !visible);
83}
84
85bool CollectionConfiguration::addressBarEnabled(const QHelpEngineCore &helpEngine)
86{
87 return helpEngine.customValue(key: EnableAddressBarKey, defaultValue: true).toBool();
88}
89
90void CollectionConfiguration::setAddressBarEnabled(QHelpEngineCore &helpEngine,
91 bool enabled)
92{
93 helpEngine.setCustomValue(key: EnableAddressBarKey, value: enabled);
94}
95
96bool CollectionConfiguration::addressBarVisible(const QHelpEngineCore &helpEngine)
97{
98 return !helpEngine.customValue(key: HideAddressBarKey, defaultValue: true).toBool();
99}
100
101void CollectionConfiguration::setAddressBarVisible(QHelpEngineCore &helpEngine,
102 bool visible)
103{
104 helpEngine.setCustomValue(key: HideAddressBarKey, value: !visible);
105}
106
107const QString CollectionConfiguration::cacheDir(const QHelpEngineCore &helpEngine)
108{
109 return helpEngine.customValue(key: CacheDirKey).toString();
110}
111
112bool CollectionConfiguration::cacheDirIsRelativeToCollection(const QHelpEngineCore &helpEngine)
113{
114 return helpEngine.customValue(key: CacheDirRelativeToCollectionKey).toBool();
115}
116
117void CollectionConfiguration::setCacheDir(QHelpEngineCore &helpEngine,
118 const QString &cacheDir, bool relativeToCollection)
119{
120 helpEngine.setCustomValue(key: CacheDirKey, value: cacheDir);
121 helpEngine.setCustomValue(key: CacheDirRelativeToCollectionKey,
122 value: relativeToCollection);
123}
124
125bool CollectionConfiguration::documentationManagerEnabled(const QHelpEngineCore &helpEngine)
126{
127 return helpEngine.customValue(key: EnableDocManagerKey, defaultValue: true).toBool();
128}
129
130void CollectionConfiguration::setDocumentationManagerEnabled(QHelpEngineCore &helpEngine,
131 bool enabled)
132{
133 helpEngine.setCustomValue(key: EnableDocManagerKey, value: enabled);
134}
135
136const QByteArray CollectionConfiguration::applicationIcon(const QHelpEngineCore &helpEngine)
137{
138 return helpEngine.customValue(key: ApplicationIconKey).toByteArray();
139}
140
141void CollectionConfiguration::setApplicationIcon(QHelpEngineCore &helpEngine,
142 const QByteArray &icon)
143{
144 helpEngine.setCustomValue(key: ApplicationIconKey, value: icon);
145}
146
147const QByteArray CollectionConfiguration::aboutMenuTexts(const QHelpEngineCore &helpEngine)
148{
149 return helpEngine.customValue(key: AboutMenuTextsKey).toByteArray();
150}
151
152void CollectionConfiguration::setAboutMenuTexts(QHelpEngineCore &helpEngine,
153 const QByteArray &texts)
154{
155 helpEngine.setCustomValue(key: AboutMenuTextsKey, value: texts);
156}
157
158const QByteArray CollectionConfiguration::aboutIcon(const QHelpEngineCore &helpEngine)
159{
160 return helpEngine.customValue(key: AboutIconKey).toByteArray();
161}
162
163void CollectionConfiguration::setAboutIcon(QHelpEngineCore &helpEngine,
164 const QByteArray &icon)
165{
166 helpEngine.setCustomValue(key: AboutIconKey, value: icon);
167}
168
169const QByteArray CollectionConfiguration::aboutTexts(const QHelpEngineCore &helpEngine)
170{
171 return helpEngine.customValue(key: AboutTextsKey).toByteArray();
172}
173
174void CollectionConfiguration::setAboutTexts(QHelpEngineCore &helpEngine,
175 const QByteArray &texts)
176{
177 helpEngine.setCustomValue(key: AboutTextsKey, value: texts);
178}
179
180const QByteArray CollectionConfiguration::aboutImages(const QHelpEngineCore &helpEngine)
181{
182 return helpEngine.customValue(key: AboutImagesKey).toByteArray();
183}
184
185void CollectionConfiguration::setAboutImages(QHelpEngineCore &helpEngine,
186 const QByteArray &images)
187{
188 helpEngine.setCustomValue(key: AboutImagesKey, value: images);
189}
190
191const QString CollectionConfiguration::defaultHomePage(const QHelpEngineCore &helpEngine)
192{
193 return helpEngine.customValue(key: DefaultHomePageKey, defaultValue: QLatin1String("help")).
194 toString();
195}
196
197void CollectionConfiguration::setDefaultHomePage(QHelpEngineCore &helpEngine,
198 const QString &page)
199{
200 helpEngine.setCustomValue(key: DefaultHomePageKey, value: page);
201}
202
203const QStringList CollectionConfiguration::lastShownPages(const QHelpEngineCore &helpEngine)
204{
205 return helpEngine.customValue(key: LastShownPagesKey).toString().
206 split(sep: ListSeparator, behavior: Qt::SkipEmptyParts);
207}
208
209void CollectionConfiguration::setLastShownPages(QHelpEngineCore &helpEngine,
210 const QStringList &lastShownPages)
211{
212 helpEngine.setCustomValue(key: LastShownPagesKey,
213 value: lastShownPages.join(sep: ListSeparator));
214}
215
216const QStringList CollectionConfiguration::lastZoomFactors(const QHelpEngineCore &helpEngine)
217{
218 return helpEngine.customValue(key: LastZoomFactorsKey).toString().
219 split(sep: ListSeparator, behavior: Qt::SkipEmptyParts);
220}
221
222void CollectionConfiguration::setLastZoomFactors(QHelpEngineCore &helpEngine,
223 const QStringList &lastZoomFactors)
224{
225 helpEngine.setCustomValue(key: LastZoomFactorsKey,
226 value: lastZoomFactors.join(sep: ListSeparator));
227}
228
229int CollectionConfiguration::lastTabPage(const QHelpEngineCore &helpEngine)
230{
231 return helpEngine.customValue(key: LastPageKey, defaultValue: 1).toInt();
232}
233
234void CollectionConfiguration::setLastTabPage(QHelpEngineCore &helpEngine,
235 int lastPage)
236{
237 helpEngine.setCustomValue(key: LastPageKey, value: lastPage);
238}
239
240const QDateTime CollectionConfiguration::lastRegisterTime(const QHelpEngineCore &helpEngine)
241{
242 return helpEngine.customValue(key: LastRegisterTime, defaultValue: QDateTime()).toDateTime();
243}
244
245void CollectionConfiguration::updateLastRegisterTime(QHelpEngineCore &helpEngine, QDateTime dt)
246{
247 helpEngine.setCustomValue(key: LastRegisterTime, value: dt);
248}
249
250void CollectionConfiguration::updateLastRegisterTime(QHelpEngineCore &helpEngine)
251{
252 updateLastRegisterTime(helpEngine, dt: QDateTime::currentDateTime());
253}
254
255bool CollectionConfiguration::isNewer(const QHelpEngineCore &newer,
256 const QHelpEngineCore &older)
257{
258 return creationTime(helpEngine: newer) > creationTime(helpEngine: older);
259}
260
261void CollectionConfiguration::copyConfiguration(const QHelpEngineCore &source,
262 QHelpEngineCore &target)
263{
264 setCreationTime(helpEngine&: target, time: creationTime(helpEngine: source));
265 setWindowTitle(helpEngine&: target, windowTitle: windowTitle(helpEngine: source));
266 target.setCurrentFilter(source.currentFilter());
267 setCacheDir(helpEngine&: target, cacheDir: cacheDir(helpEngine: source), relativeToCollection: cacheDirIsRelativeToCollection(helpEngine: source));
268 setFilterFunctionalityEnabled(helpEngine&: target, enabled: filterFunctionalityEnabled(helpEngine: source));
269 setFilterToolbarVisible(helpEngine&: target, visible: filterToolbarVisible(helpEngine: source));
270 setAddressBarEnabled(helpEngine&: target, enabled: addressBarEnabled(helpEngine: source));
271 setAddressBarVisible(helpEngine&: target, visible: addressBarVisible(helpEngine: source));
272 setDocumentationManagerEnabled(helpEngine&: target, enabled: documentationManagerEnabled(helpEngine: source));
273 setApplicationIcon(helpEngine&: target, icon: applicationIcon(helpEngine: source));
274 setAboutMenuTexts(helpEngine&: target, texts: aboutMenuTexts(helpEngine: source));
275 setAboutIcon(helpEngine&: target, icon: aboutIcon(helpEngine: source));
276 setAboutTexts(helpEngine&: target, texts: aboutTexts(helpEngine: source));
277 setAboutImages(helpEngine&: target, images: aboutImages(helpEngine: source));
278 setDefaultHomePage(helpEngine&: target, page: defaultHomePage(helpEngine: source));
279 setFullTextSearchFallbackEnabled(helpEngine&: target, on: fullTextSearchFallbackEnabled(helpEngine: source));
280}
281
282bool CollectionConfiguration:: fullTextSearchFallbackEnabled(
283 const QHelpEngineCore &helpEngine)
284{
285 return helpEngine.customValue(key: FullTextSearchFallbackKey, defaultValue: false).toBool();
286}
287
288void CollectionConfiguration::setFullTextSearchFallbackEnabled(
289 QHelpEngineCore &helpEngine, bool on)
290{
291 helpEngine.setCustomValue(key: FullTextSearchFallbackKey, value: on);
292}
293
294QT_END_NAMESPACE
295

source code of qttools/src/assistant/shared/collectionconfiguration.cpp