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