6#include "../shared/collectionconfiguration.h"
8#include <QtCore/QDateTime>
9#include <QtCore/QFileInfo>
10#include <QtCore/QFileSystemWatcher>
11#include <QtCore/QTimer>
12#include <QtHelp/QHelpContentModel>
13#include <QtHelp/QHelpEngine>
14#include <QtHelp/QHelpFilterEngine>
15#include <QtHelp/QHelpIndexModel>
16#include <QtHelp/QHelpLink>
17#include <QtHelp/QHelpSearchEngine>
24using namespace Qt::StringLiterals;
27 const QString AppFontKey(
"appFont"_L1);
28 const QString AppWritingSystemKey(
"appWritingSystem"_L1);
29 const QString BookmarksKey(
"Bookmarks"_L1);
30 const QString BrowserFontKey(
"browserFont"_L1);
31 const QString BrowserWritingSystemKey(
"browserWritingSystem"_L1);
32 const QString HomePageKey(
"homepage"_L1);
33 const QString MainWindowKey(
"MainWindow"_L1);
34 const QString MainWindowGeometryKey(
"MainWindowGeometry"_L1);
35 const QString SearchWasAttachedKey(
"SearchWasAttached"_L1);
36 const QString StartOptionKey(
"StartOption"_L1);
37 const QString UseAppFontKey(
"useAppFont"_L1);
38 const QString UseBrowserFontKey(
"useBrowserFont"_L1);
39 const QString VersionKey(
"qtVersion%1$$$%2"_L1.arg(QLatin1StringView(QT_VERSION_STR)));
40 const QString ShowTabsKey(
"showTabs"_L1);
41 const QString TopicChooserGeometryKey(
"TopicChooserGeometry"_L1);
54 const QString m_fileName;
70 HelpEngineWrapperPrivate(
const QString &collectionFile);
72 void initFileSystemWatchers();
73 void checkDocFilesWatched();
74 void qchFileChanged(
const QString &fileName,
bool fromTimeout);
76 static const int UpdateGracePeriod = 2000;
78 QHelpEngine *
const m_helpEngine;
79 QFileSystemWatcher *
const m_qchWatcher;
82 std::unique_ptr<TimeoutForwarder> forwarder;
84 std::map<QString, RecentSignal> m_recentQchUpdates;
98
99
100
101 if (!helpEngineWrapper)
103 return *helpEngineWrapper;
109 delete helpEngineWrapper;
110 helpEngineWrapper =
nullptr;
119
120
121
122
123
124
125
127 disconnect(d->m_helpEngine, &QHelpEngineCore::setupFinished,
128 searchEngine(), &QHelpSearchEngine::scheduleIndexDocumentation);
130 connect(d, &HelpEngineWrapperPrivate::documentationRemoved,
131 this, &HelpEngineWrapper::documentationRemoved);
132 connect(d, &HelpEngineWrapperPrivate::documentationUpdated,
133 this, &HelpEngineWrapper::documentationUpdated);
134 connect(d->m_helpEngine, &QHelpEngineCore::setupFinished,
135 this, &HelpEngineWrapper::setupFinished);
141 const QStringList &namespaces = d->m_helpEngine->registeredDocumentations();
142 for (
const QString &nameSpace : namespaces) {
143 const QString &docFile
144 = d->m_helpEngine->documentationFileName(nameSpace);
145 d->m_qchWatcher->removePath(docFile);
155 connect(d->m_helpEngine, &QHelpEngineCore::setupFinished,
156 searchEngine(), &QHelpSearchEngine::scheduleIndexDocumentation);
163 return d->m_helpEngine->searchEngine();
169 return d->m_helpEngine->contentModel();
175 return d->m_helpEngine->indexModel();
181 return d->m_helpEngine->contentWidget();
187 return d->m_helpEngine->indexWidget();
193 return d->m_helpEngine->registeredDocumentations();
199 return d->m_helpEngine->documentationFileName(namespaceName);
205 return d->m_helpEngine->collectionFile();
211 d->checkDocFilesWatched();
212 if (!d->m_helpEngine->registerDocumentation(docFile))
214 d->m_qchWatcher->addPath(docFile);
215 d->checkDocFilesWatched();
222 d->checkDocFilesWatched();
223 const QString &file = d->m_helpEngine->documentationFileName(namespaceName);
224 if (!d->m_helpEngine->unregisterDocumentation(namespaceName))
226 d->m_qchWatcher->removePath(file);
227 d->checkDocFilesWatched();
234 return d->m_helpEngine->setupData();
240 return d->m_helpEngine->findFile(url);
246 return d->m_helpEngine->fileData(url);
252 return d->m_helpEngine->documentsForIdentifier(id);
258 return d->m_helpEngine->error();
263 return d->m_helpEngine->filterEngine();
269 return d->m_helpEngine->customValue(VersionKey.arg(component)).toString().
270 split(CollectionConfiguration::ListSeparator);
274 const QStringList &doc)
277 d->m_helpEngine->setCustomValue(VersionKey.arg(component),
278 doc.join(CollectionConfiguration::ListSeparator));
284 return CollectionConfiguration::lastShownPages(*d->m_helpEngine);
290 CollectionConfiguration::setLastShownPages(*d->m_helpEngine, lastShownPages);
296 return CollectionConfiguration::lastZoomFactors(*d->m_helpEngine);
302 CollectionConfiguration::setLastZoomFactors(*d->m_helpEngine, lastZoomFactors);
308 return CollectionConfiguration::cacheDir(*d->m_helpEngine);
318 bool relativeToCollection)
321 CollectionConfiguration::setCacheDir(*d->m_helpEngine, cacheDir,
322 relativeToCollection);
390 return CollectionConfiguration::aboutMenuTexts(*d->m_helpEngine);
396 CollectionConfiguration::setAboutMenuTexts(*d->m_helpEngine, texts);
402 return CollectionConfiguration::aboutIcon(*d->m_helpEngine);
408 CollectionConfiguration::setAboutIcon(*d->m_helpEngine, icon);
414 return CollectionConfiguration::aboutImages(*d->m_helpEngine);
420 CollectionConfiguration::setAboutImages(*d->m_helpEngine, images);
426 return CollectionConfiguration::aboutTexts(*d->m_helpEngine);
432 CollectionConfiguration::setAboutTexts(*d->m_helpEngine, texts);
438 return CollectionConfiguration::windowTitle(*d->m_helpEngine);
444 CollectionConfiguration::setWindowTitle(*d->m_helpEngine, windowTitle);
450 return CollectionConfiguration::applicationIcon(*d->m_helpEngine);
456 CollectionConfiguration::setApplicationIcon(*d->m_helpEngine, icon);
462 return d->m_helpEngine->customValue(MainWindowKey).toByteArray();
468 d->m_helpEngine->setCustomValue(MainWindowKey, mainWindow);
474 return d->m_helpEngine->customValue(MainWindowGeometryKey).toByteArray();
480 d->m_helpEngine->setCustomValue(MainWindowGeometryKey, geometry);
486 return d->m_helpEngine->customValue(BookmarksKey).toByteArray();
492 d->m_helpEngine->setCustomValue(BookmarksKey, bookmarks);
510 return d->m_helpEngine->customValue(StartOptionKey,
ShowLastPages).toInt();
516 d->m_helpEngine->setCustomValue(StartOptionKey, option);
522 const QString &homePage
523 = d->m_helpEngine->customValue(HomePageKey).toString();
524 if (!homePage.isEmpty())
526 return defaultHomePage();
532 d->m_helpEngine->setCustomValue(HomePageKey, page);
539 return CollectionConfiguration::defaultHomePage(*d->m_helpEngine);
545 CollectionConfiguration::setDefaultHomePage(*d->m_helpEngine, page);
551 return d->m_helpEngine->customValue(UseAppFontKey).isValid();
557 return d->m_helpEngine->customValue(UseAppFontKey).toBool();
563 d->m_helpEngine->setCustomValue(UseAppFontKey, useAppFont);
569 return d->m_helpEngine->customValue(UseBrowserFontKey,
false).toBool();
575 d->m_helpEngine->setCustomValue(UseBrowserFontKey, useBrowserFont);
581 return qvariant_cast<QFont>(d->m_helpEngine->customValue(AppFontKey));
587 d->m_helpEngine->setCustomValue(AppFontKey, font);
593 return static_cast<QFontDatabase::WritingSystem>(
594 d->m_helpEngine->customValue(AppWritingSystemKey).toInt());
600 d->m_helpEngine->setCustomValue(AppWritingSystemKey, system);
606 return qvariant_cast<QFont>(d->m_helpEngine->customValue(BrowserFontKey));
612 d->m_helpEngine->setCustomValue(BrowserFontKey, font);
618 return static_cast<QFontDatabase::WritingSystem>(
619 d->m_helpEngine->customValue(BrowserWritingSystemKey).toInt());
625 d->m_helpEngine->setCustomValue(BrowserWritingSystemKey, system);
631 return d->m_helpEngine->customValue(ShowTabsKey,
false).toBool();
637 d->m_helpEngine->setCustomValue(ShowTabsKey, show);
649 return d->m_helpEngine->customValue(TopicChooserGeometryKey).toByteArray();
655 d->m_helpEngine->setCustomValue(TopicChooserGeometryKey, geometry);
660 return d->m_helpEngine;
667 : m_fileName(fileName)
675 HelpEngineWrapper::instance().d->qchFileChanged(m_fileName,
true);
681 : m_helpEngine(
new QHelpEngine(collectionFile,
this)),
682 m_qchWatcher(
new QFileSystemWatcher(
this))
685 m_helpEngine->setReadOnly(
false);
686 m_helpEngine->setUsesFilterEngine(
true);
687 initFileSystemWatchers();
693 for (
const QString &ns : m_helpEngine->registeredDocumentations())
694 m_qchWatcher->addPath(m_helpEngine->documentationFileName(ns));
696 connect(m_qchWatcher, &QFileSystemWatcher::fileChanged,
this,
697 QOverload<
const QString &>::of(&HelpEngineWrapperPrivate::qchFileChanged));
698 checkDocFilesWatched();
704 qchFileChanged(fileName,
false);
710 const int watchedFilesCount = m_qchWatcher->files().size();
711 const int docFilesCount = m_helpEngine->registeredDocumentations().size();
712 if (watchedFilesCount != docFilesCount) {
713 qWarning(
"Strange: Have %d docs, but %d are being watched",
714 watchedFilesCount, docFilesCount);
724
725
726
728 for (
const QString &curNs : m_helpEngine->registeredDocumentations()) {
729 if (m_helpEngine->documentationFileName(curNs) == fileName) {
736
737
738
740 m_recentQchUpdates.erase(fileName);
745
746
747
748
750 const auto &it = m_recentQchUpdates.find(fileName);
751 const QDateTime now = QDateTime::currentDateTimeUtc();
754 if (it == m_recentQchUpdates.end()) {
756 QTimer::singleShot(UpdateGracePeriod, forwarder.get(),
757 &TimeoutForwarder::forward);
758 m_recentQchUpdates.emplace(fileName,
759 RecentSignal{std::move(now), std::move(forwarder)});
763 auto &[key, entry] = *it;
766 if (entry.timestamp > now.addMSecs(-UpdateGracePeriod)) {
768 entry.timestamp = now;
770 QTimer::singleShot(UpdateGracePeriod, entry.forwarder.get(),
771 &TimeoutForwarder::forward);
776 if (m_helpEngine->unregisterDocumentation(ns)) {
777 if (!QFileInfo(fileName).exists()
778 || !m_helpEngine->registerDocumentation(fileName)) {
779 m_qchWatcher->removePath(fileName);
780 emit documentationRemoved(ns);
782 emit documentationUpdated(ns);
784 m_helpEngine->setupData();
786 m_recentQchUpdates.erase(it);
791#include "helpenginewrapper.moc"
static bool filterFunctionalityEnabled(const QHelpEngineCore &helpEngine)
static void setLastTabPage(QHelpEngineCore &helpEngine, int lastPage)
static bool addressBarVisible(const QHelpEngineCore &helpEngine)
static bool addressBarEnabled(const QHelpEngineCore &helpEngine)
static void setAddressBarVisible(QHelpEngineCore &helpEngine, bool visible)
static void setDocumentationManagerEnabled(QHelpEngineCore &helpEngine, bool enabled)
static bool documentationManagerEnabled(const QHelpEngineCore &helpEngine)
static void setAddressBarEnabled(QHelpEngineCore &helpEngine, bool enabled)
static int lastTabPage(const QHelpEngineCore &helpEngine)
static bool cacheDirIsRelativeToCollection(const QHelpEngineCore &helpEngine)
static void setFilterToolbarVisible(QHelpEngineCore &helpEngine, bool visible)
static void setFilterFunctionalityEnabled(QHelpEngineCore &helpEngine, bool enabled)
static bool filterToolbarVisible(const QHelpEngineCore &helpEngine)
static bool fullTextSearchFallbackEnabled(const QHelpEngineCore &helpEngine)
void documentationUpdated(const QString &namespaceName)
void setHomePage(const QString &page)
QHelpEngineCore * helpEngine() const
QHelpFilterEngine * filterEngine() const
bool registerDocumentation(const QString &docFile)
const QString defaultHomePage() const
void setStartOption(int option)
QHelpSearchEngine * searchEngine() const
const QByteArray bookmarks() const
bool usesBrowserFont() const
const QStringList lastShownPages() const
void setDefaultHomePage(const QString &page)
static void removeInstance()
const QString homePage() const
bool fullTextSearchFallbackEnabled() const
void setAddressBarEnabled(bool enabled)
QHelpIndexWidget * indexWidget()
bool cacheDirIsRelativeToCollection() const
const QString windowTitle() const
void setLastZoomFactors(const QStringList &lastZoomFactors)
void setFilterFunctionalityEnabled(bool enabled)
void setShowTabs(bool show)
const QStringList qtDocInfo(const QString &component) const
void setBookmarks(const QByteArray &bookmarks)
const QByteArray mainWindow() const
static HelpEngineWrapper & instance()
const QByteArray mainWindowGeometry() const
void setBrowserFont(const QFont &font)
const QByteArray topicChooserGeometry() const
bool addressBarEnabled() const
const QFont browserFont() const
void setAboutMenuTexts(const QByteArray &texts)
void setFilterToolbarVisible(bool visible)
const QByteArray aboutMenuTexts() const
const QString collectionFile() const
void setAppWritingSystem(QFontDatabase::WritingSystem system)
QByteArray fileData(const QUrl &url) const
void setBrowserWritingSystem(QFontDatabase::WritingSystem system)
void setAppFont(const QFont &font)
bool unregisterDocumentation(const QString &namespaceName)
bool addressBarVisible() const
void setAboutIcon(const QByteArray &icon)
void setUseBrowserFont(bool useBrowserFont)
void setCacheDir(const QString &cacheDir, bool relativeToCollection)
bool documentationManagerEnabled() const
bool hasFontSettings() const
QFontDatabase::WritingSystem browserWritingSystem() const
void setApplicationIcon(const QByteArray &icon)
const QStringList registeredDocumentations() const
QHelpContentWidget * contentWidget()
const QByteArray aboutTexts() const
QHelpIndexModel * indexModel() const
void setAboutImages(const QByteArray &images)
void setTopicChooserGeometry(const QByteArray &geometry)
bool filterFunctionalityEnabled() const
void setMainWindowGeometry(const QByteArray &geometry)
void setAboutTexts(const QByteArray &texts)
void setAddressBarVisible(bool visible)
void setLastTabPage(int lastPage)
const QString cacheDir() const
QUrl findFile(const QUrl &url) const
const QStringList lastZoomFactors() const
const QByteArray applicationIcon() const
const QByteArray aboutImages() const
QList< QHelpLink > documentsForIdentifier(const QString &id) const
QFontDatabase::WritingSystem appWritingSystem() const
void setQtDocInfo(const QString &component, const QStringList &doc)
void initialDocSetupDone()
void setDocumentationManagerEnabled(bool enabled)
void setWindowTitle(const QString &windowTitle)
bool filterToolbarVisible() const
const QByteArray aboutIcon() const
void setUseAppFont(bool useAppFont)
QHelpContentModel * contentModel() const
void setLastShownPages(const QStringList &lastShownPages)
void setMainWindow(const QByteArray &mainWindow)
QString documentationFileName(const QString &namespaceName) const
const QFont appFont() const