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

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