diff options
author | ck <qt-info@nokia.com> | 2009-12-21 08:50:59 (GMT) |
---|---|---|
committer | ck <qt-info@nokia.com> | 2009-12-21 08:50:59 (GMT) |
commit | f0c5c37ad8c2497511564d8c52dd53b2503c97c4 (patch) | |
tree | b32b7132a7189e58b6a94f184a543b7f55fe9e51 /tools | |
parent | d4005e273d4285d0b6a9c60f712cfd12c311c3a3 (diff) | |
download | Qt-f0c5c37ad8c2497511564d8c52dd53b2503c97c4.zip Qt-f0c5c37ad8c2497511564d8c52dd53b2503c97c4.tar.gz Qt-f0c5c37ad8c2497511564d8c52dd53b2503c97c4.tar.bz2 |
Assistant: Refactor help engine wrapper.
This class had a lot of implementation details in the header,
which were moved to an internal private class.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/assistant/tools/assistant/helpenginewrapper.cpp | 292 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpenginewrapper.h | 37 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/main.cpp | 2 |
3 files changed, 187 insertions, 144 deletions
diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp index 79a25ec..72ba30d 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.cpp +++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp @@ -43,8 +43,11 @@ #include "helpenginewrapper.h" #include "../shared/collectionconfiguration.h" +#include <QtCore/QDateTime> #include <QtCore/QFileInfo> #include <QtCore/QFileSystemWatcher> +#include <QtCore/QPair> +#include <QtCore/QSharedPointer> #include <QtCore/QTimer> #include <QtHelp/QHelpContentModel> #include <QtHelp/QHelpEngine> @@ -71,6 +74,49 @@ namespace { arg(QLatin1String(QT_VERSION_STR))); } // anonymous namespace +class TimeoutForwarder : public QObject +{ + Q_OBJECT +public: + TimeoutForwarder(const QString &fileName); +private slots: + void forward(); +private: + friend class HelpEngineWrapperPrivate; + + const QString m_fileName; +}; + +class HelpEngineWrapperPrivate : public QObject +{ + Q_OBJECT + friend class HelpEngineWrapper; + friend class TimeoutForwarder; +private slots: + void qchFileChanged(const QString &fileName); + +signals: + void documentationRemoved(const QString &namespaceName); + void documentationUpdated(const QString &namespaceName); + +private: + HelpEngineWrapperPrivate(const QString &collectionFile); + + friend class TimeoutForwarder; + + void initFileSystemWatchers(); + void assertDocFilesWatched(); + void qchFileChanged(const QString &fileName, bool fromTimeout); + + static const int UpdateGracePeriod = 2000; + + QHelpEngine * const m_helpEngine; + QFileSystemWatcher * const m_qchWatcher; + typedef QPair<QDateTime, QSharedPointer<TimeoutForwarder> > RecentSignal; + QMap<QString, RecentSignal> m_recentQchUpdates; + +}; + HelpEngineWrapper *HelpEngineWrapper::helpEngineWrapper = 0; HelpEngineWrapper &HelpEngineWrapper::instance(const QString &collectionFile) @@ -93,183 +139,179 @@ void HelpEngineWrapper::removeInstance() } HelpEngineWrapper::HelpEngineWrapper(const QString &collectionFile) - : m_helpEngine(new QHelpEngine(collectionFile, this)), - m_qchWatcher(new QFileSystemWatcher(this)) + : d(new HelpEngineWrapperPrivate(collectionFile)) { TRACE_OBJ - connect(m_helpEngine, SIGNAL(currentFilterChanged(QString)), + connect(d, SIGNAL(documentationRemoved(QString)), + this, SIGNAL(documentationRemoved(QString))); + connect(d, SIGNAL(documentationUpdated(QString)), + this, SIGNAL(documentationUpdated(QString))); + connect(d->m_helpEngine, SIGNAL(currentFilterChanged(QString)), this, SIGNAL(currentFilterChanged(QString))); - connect(m_helpEngine, SIGNAL(setupFinished()), + connect(d->m_helpEngine, SIGNAL(setupFinished()), this, SIGNAL(setupFinished())); - initFileSystemWatchers(); } -void HelpEngineWrapper::initFileSystemWatchers() +HelpEngineWrapper::~HelpEngineWrapper() { TRACE_OBJ - foreach(const QString &ns, m_helpEngine->registeredDocumentations()) { - const QString &docFile = m_helpEngine->documentationFileName(ns); - m_qchWatcher->addPath(docFile); - connect(m_qchWatcher, SIGNAL(fileChanged(QString)), - this, SLOT(qchFileChanged(QString))); - } - assertDocFilesWatched(); + delete d; } QHelpSearchEngine *HelpEngineWrapper::searchEngine() const { TRACE_OBJ - return m_helpEngine->searchEngine(); + return d->m_helpEngine->searchEngine(); } QHelpContentModel *HelpEngineWrapper::contentModel() const { TRACE_OBJ - return m_helpEngine->contentModel(); + return d->m_helpEngine->contentModel(); } QHelpIndexModel *HelpEngineWrapper::indexModel() const { TRACE_OBJ - return m_helpEngine->indexModel(); + return d->m_helpEngine->indexModel(); } QHelpContentWidget *HelpEngineWrapper::contentWidget() { TRACE_OBJ - return m_helpEngine->contentWidget(); + return d->m_helpEngine->contentWidget(); } QHelpIndexWidget *HelpEngineWrapper::indexWidget() { TRACE_OBJ - return m_helpEngine->indexWidget(); + return d->m_helpEngine->indexWidget(); } const QStringList HelpEngineWrapper::registeredDocumentations() const { TRACE_OBJ - return m_helpEngine->registeredDocumentations(); + return d->m_helpEngine->registeredDocumentations(); } const QString HelpEngineWrapper::collectionFile() const { TRACE_OBJ - return m_helpEngine->collectionFile(); + return d->m_helpEngine->collectionFile(); } bool HelpEngineWrapper::registerDocumentation(const QString &docFile) { TRACE_OBJ - assertDocFilesWatched(); - if (!m_helpEngine->registerDocumentation(docFile)) + d->assertDocFilesWatched(); + if (!d->m_helpEngine->registerDocumentation(docFile)) return false; - m_qchWatcher->addPath(docFile); - assertDocFilesWatched(); + d->m_qchWatcher->addPath(docFile); + d->assertDocFilesWatched(); return true; } bool HelpEngineWrapper::unregisterDocumentation(const QString &namespaceName) { TRACE_OBJ - assertDocFilesWatched(); - const QString &file = m_helpEngine->documentationFileName(namespaceName); - if (!m_helpEngine->unregisterDocumentation(namespaceName)) + d->assertDocFilesWatched(); + const QString &file = d->m_helpEngine->documentationFileName(namespaceName); + if (!d->m_helpEngine->unregisterDocumentation(namespaceName)) return false; - m_qchWatcher->removePath(file); - assertDocFilesWatched(); + d->m_qchWatcher->removePath(file); + d->assertDocFilesWatched(); return true; } bool HelpEngineWrapper::setupData() { TRACE_OBJ - return m_helpEngine->setupData(); + return d->m_helpEngine->setupData(); } bool HelpEngineWrapper::addCustomFilter(const QString &filterName, const QStringList &attributes) { TRACE_OBJ - return m_helpEngine->addCustomFilter(filterName, attributes); + return d->m_helpEngine->addCustomFilter(filterName, attributes); } bool HelpEngineWrapper::removeCustomFilter(const QString &filterName) { TRACE_OBJ - return m_helpEngine->removeCustomFilter(filterName); + return d->m_helpEngine->removeCustomFilter(filterName); } void HelpEngineWrapper::setCurrentFilter(const QString ¤tFilter) { TRACE_OBJ - m_helpEngine->setCurrentFilter(currentFilter); + d->m_helpEngine->setCurrentFilter(currentFilter); } const QString HelpEngineWrapper::currentFilter() const { TRACE_OBJ - return m_helpEngine->currentFilter(); + return d->m_helpEngine->currentFilter(); } const QStringList HelpEngineWrapper::customFilters() const { TRACE_OBJ - return m_helpEngine->customFilters(); + return d->m_helpEngine->customFilters(); } QUrl HelpEngineWrapper::findFile(const QUrl &url) const { TRACE_OBJ - return m_helpEngine->findFile(url); + return d->m_helpEngine->findFile(url); } QByteArray HelpEngineWrapper::fileData(const QUrl &url) const { TRACE_OBJ - return m_helpEngine->fileData(url); + return d->m_helpEngine->fileData(url); } QMap<QString, QUrl> HelpEngineWrapper::linksForIdentifier(const QString &id) const { TRACE_OBJ - return m_helpEngine->linksForIdentifier(id); + return d->m_helpEngine->linksForIdentifier(id); } const QStringList HelpEngineWrapper::filterAttributes() const { TRACE_OBJ - return m_helpEngine->filterAttributes(); + return d->m_helpEngine->filterAttributes(); } const QStringList HelpEngineWrapper::filterAttributes(const QString &filterName) const { TRACE_OBJ - return m_helpEngine->filterAttributes(filterName); + return d->m_helpEngine->filterAttributes(filterName); } QString HelpEngineWrapper::error() const { TRACE_OBJ - return m_helpEngine->error(); + return d->m_helpEngine->error(); } bool HelpEngineWrapper::unfilteredInserted() const { TRACE_OBJ - return m_helpEngine->customValue(UnfilteredInsertedKey).toInt() == 1; + return d->m_helpEngine->customValue(UnfilteredInsertedKey).toInt() == 1; } void HelpEngineWrapper::setUnfilteredInserted() { TRACE_OBJ - m_helpEngine->setCustomValue(UnfilteredInsertedKey, 1); + d->m_helpEngine->setCustomValue(UnfilteredInsertedKey, 1); } const QStringList HelpEngineWrapper::qtDocInfo(const QString &component) const { TRACE_OBJ - return m_helpEngine->customValue(VersionKey.arg(component)).toString(). + return d->m_helpEngine->customValue(VersionKey.arg(component)).toString(). split(CollectionConfiguration::ListSeparator); } @@ -277,264 +319,265 @@ void HelpEngineWrapper::setQtDocInfo(const QString &component, const QStringList &doc) { TRACE_OBJ - m_helpEngine->setCustomValue(VersionKey.arg(component), + d->m_helpEngine->setCustomValue(VersionKey.arg(component), doc.join(CollectionConfiguration::ListSeparator)); } const QStringList HelpEngineWrapper::lastShownPages() const { TRACE_OBJ - return CollectionConfiguration::lastShownPages(*m_helpEngine); + return CollectionConfiguration::lastShownPages(*d->m_helpEngine); } void HelpEngineWrapper::setLastShownPages(const QStringList &lastShownPages) { TRACE_OBJ - CollectionConfiguration::setLastShownPages(*m_helpEngine, lastShownPages); + CollectionConfiguration::setLastShownPages(*d->m_helpEngine, lastShownPages); } const QStringList HelpEngineWrapper::lastZoomFactors() const { TRACE_OBJ - return CollectionConfiguration::lastZoomFactors(*m_helpEngine); + return CollectionConfiguration::lastZoomFactors(*d->m_helpEngine); } void HelpEngineWrapper::setLastZoomFactors(const QStringList &lastZoomFactors) { TRACE_OBJ - CollectionConfiguration::setLastZoomFactors(*m_helpEngine, lastZoomFactors); + CollectionConfiguration::setLastZoomFactors(*d->m_helpEngine, lastZoomFactors); } const QString HelpEngineWrapper::cacheDir() const { TRACE_OBJ - return CollectionConfiguration::cacheDir(*m_helpEngine); + return CollectionConfiguration::cacheDir(*d->m_helpEngine); } bool HelpEngineWrapper::cacheDirIsRelativeToCollection() const { TRACE_OBJ - return CollectionConfiguration::cacheDirIsRelativeToCollection(*m_helpEngine); + return CollectionConfiguration::cacheDirIsRelativeToCollection(*d->m_helpEngine); } void HelpEngineWrapper::setCacheDir(const QString &cacheDir, bool relativeToCollection) { TRACE_OBJ - CollectionConfiguration::setCacheDir(*m_helpEngine, cacheDir, + CollectionConfiguration::setCacheDir(*d->m_helpEngine, cacheDir, relativeToCollection); } bool HelpEngineWrapper::filterFunctionalityEnabled() const { TRACE_OBJ - return CollectionConfiguration::filterFunctionalityEnabled(*m_helpEngine); + return CollectionConfiguration::filterFunctionalityEnabled(*d->m_helpEngine); } void HelpEngineWrapper::setFilterFunctionalityEnabled(bool enabled) { TRACE_OBJ - CollectionConfiguration::setFilterFunctionalityEnabled(*m_helpEngine, + CollectionConfiguration::setFilterFunctionalityEnabled(*d->m_helpEngine, enabled); } bool HelpEngineWrapper::filterToolbarVisible() const { TRACE_OBJ - return CollectionConfiguration::filterToolbarVisible(*m_helpEngine); + return CollectionConfiguration::filterToolbarVisible(*d->m_helpEngine); } void HelpEngineWrapper::setFilterToolbarVisible(bool visible) { TRACE_OBJ - CollectionConfiguration::setFilterToolbarVisible(*m_helpEngine, visible); + CollectionConfiguration::setFilterToolbarVisible(*d->m_helpEngine, visible); } bool HelpEngineWrapper::addressBarEnabled() const { TRACE_OBJ - return CollectionConfiguration::addressBarEnabled(*m_helpEngine); + return CollectionConfiguration::addressBarEnabled(*d->m_helpEngine); } void HelpEngineWrapper::setAddressBarEnabled(bool enabled) { TRACE_OBJ - CollectionConfiguration::setAddressBarEnabled(*m_helpEngine, enabled); + CollectionConfiguration::setAddressBarEnabled(*d->m_helpEngine, enabled); } bool HelpEngineWrapper::addressBarVisible() const { TRACE_OBJ - return CollectionConfiguration::addressBarVisible(*m_helpEngine); + return CollectionConfiguration::addressBarVisible(*d->m_helpEngine); } void HelpEngineWrapper::setAddressBarVisible(bool visible) { TRACE_OBJ - CollectionConfiguration::setAddressBarVisible(*m_helpEngine, visible); + CollectionConfiguration::setAddressBarVisible(*d->m_helpEngine, visible); } bool HelpEngineWrapper::documentationManagerEnabled() const { TRACE_OBJ - return CollectionConfiguration::documentationManagerEnabled(*m_helpEngine); + return CollectionConfiguration::documentationManagerEnabled(*d->m_helpEngine); } void HelpEngineWrapper::setDocumentationManagerEnabled(bool enabled) { TRACE_OBJ - CollectionConfiguration::setDocumentationManagerEnabled(*m_helpEngine, + CollectionConfiguration::setDocumentationManagerEnabled(*d->m_helpEngine, enabled); } const QByteArray HelpEngineWrapper::aboutMenuTexts() const { TRACE_OBJ - return CollectionConfiguration::aboutMenuTexts(*m_helpEngine); + return CollectionConfiguration::aboutMenuTexts(*d->m_helpEngine); } void HelpEngineWrapper::setAboutMenuTexts(const QByteArray &texts) { TRACE_OBJ - CollectionConfiguration::setAboutMenuTexts(*m_helpEngine, texts); + CollectionConfiguration::setAboutMenuTexts(*d->m_helpEngine, texts); } const QByteArray HelpEngineWrapper::aboutIcon() const { TRACE_OBJ - return CollectionConfiguration::aboutIcon(*m_helpEngine); + return CollectionConfiguration::aboutIcon(*d->m_helpEngine); } void HelpEngineWrapper::setAboutIcon(const QByteArray &icon) { TRACE_OBJ - CollectionConfiguration::setAboutIcon(*m_helpEngine, icon); + CollectionConfiguration::setAboutIcon(*d->m_helpEngine, icon); } const QByteArray HelpEngineWrapper::aboutImages() const { TRACE_OBJ - return CollectionConfiguration::aboutImages(*m_helpEngine); + return CollectionConfiguration::aboutImages(*d->m_helpEngine); } void HelpEngineWrapper::setAboutImages(const QByteArray &images) { TRACE_OBJ - CollectionConfiguration::setAboutImages(*m_helpEngine, images); + CollectionConfiguration::setAboutImages(*d->m_helpEngine, images); } const QByteArray HelpEngineWrapper::aboutTexts() const { TRACE_OBJ - return CollectionConfiguration::aboutTexts(*m_helpEngine); + return CollectionConfiguration::aboutTexts(*d->m_helpEngine); } void HelpEngineWrapper::setAboutTexts(const QByteArray &texts) { TRACE_OBJ - CollectionConfiguration::setAboutTexts(*m_helpEngine, texts); + CollectionConfiguration::setAboutTexts(*d->m_helpEngine, texts); } const QString HelpEngineWrapper::windowTitle() const { TRACE_OBJ - return CollectionConfiguration::windowTitle(*m_helpEngine); + return CollectionConfiguration::windowTitle(*d->m_helpEngine); } void HelpEngineWrapper::setWindowTitle(const QString &windowTitle) { TRACE_OBJ - CollectionConfiguration::setWindowTitle(*m_helpEngine, windowTitle); + CollectionConfiguration::setWindowTitle(*d->m_helpEngine, windowTitle); } const QByteArray HelpEngineWrapper::applicationIcon() const { TRACE_OBJ - return CollectionConfiguration::applicationIcon(*m_helpEngine); + return CollectionConfiguration::applicationIcon(*d->m_helpEngine); } void HelpEngineWrapper::setApplicationIcon(const QByteArray &icon) { TRACE_OBJ - CollectionConfiguration::setApplicationIcon(*m_helpEngine, icon); + CollectionConfiguration::setApplicationIcon(*d->m_helpEngine, icon); } const QByteArray HelpEngineWrapper::mainWindow() const { TRACE_OBJ - return m_helpEngine->customValue(MainWindowKey).toByteArray(); + return d->m_helpEngine->customValue(MainWindowKey).toByteArray(); } void HelpEngineWrapper::setMainWindow(const QByteArray &mainWindow) { TRACE_OBJ - m_helpEngine->setCustomValue(MainWindowKey, mainWindow); + d->m_helpEngine->setCustomValue(MainWindowKey, mainWindow); } const QByteArray HelpEngineWrapper::mainWindowGeometry() const { TRACE_OBJ - return m_helpEngine->customValue(MainWindowGeometryKey).toByteArray(); + return d->m_helpEngine->customValue(MainWindowGeometryKey).toByteArray(); } void HelpEngineWrapper::setMainWindowGeometry(const QByteArray &geometry) { TRACE_OBJ - m_helpEngine->setCustomValue(MainWindowGeometryKey, geometry); + d->m_helpEngine->setCustomValue(MainWindowGeometryKey, geometry); } const QByteArray HelpEngineWrapper::bookmarks() const { TRACE_OBJ - return m_helpEngine->customValue(BookmarksKey).toByteArray(); + return d->m_helpEngine->customValue(BookmarksKey).toByteArray(); } void HelpEngineWrapper::setBookmarks(const QByteArray &bookmarks) { TRACE_OBJ - m_helpEngine->setCustomValue(BookmarksKey, bookmarks); + d->m_helpEngine->setCustomValue(BookmarksKey, bookmarks); } int HelpEngineWrapper::lastTabPage() const { TRACE_OBJ - return CollectionConfiguration::lastTabPage(*m_helpEngine); + return CollectionConfiguration::lastTabPage(*d->m_helpEngine); } void HelpEngineWrapper::setLastTabPage(int lastPage) { TRACE_OBJ - CollectionConfiguration::setLastTabPage(*m_helpEngine, lastPage); + CollectionConfiguration::setLastTabPage(*d->m_helpEngine, lastPage); } bool HelpEngineWrapper::searchWasAttached() const { TRACE_OBJ - return m_helpEngine->customValue(SearchWasAttachedKey).toBool(); + return d->m_helpEngine->customValue(SearchWasAttachedKey).toBool(); } void HelpEngineWrapper::setSearchWasAttached(bool attached) { TRACE_OBJ - m_helpEngine->setCustomValue(SearchWasAttachedKey, attached); + d->m_helpEngine->setCustomValue(SearchWasAttachedKey, attached); } int HelpEngineWrapper::startOption() const { TRACE_OBJ - return m_helpEngine->customValue(StartOptionKey, ShowLastPages).toInt(); + return d->m_helpEngine->customValue(StartOptionKey, ShowLastPages).toInt(); } void HelpEngineWrapper::setStartOption(int option) { TRACE_OBJ - m_helpEngine->setCustomValue(StartOptionKey, option); + d->m_helpEngine->setCustomValue(StartOptionKey, option); } const QString HelpEngineWrapper::homePage() const { TRACE_OBJ - const QString &homePage = m_helpEngine->customValue(HomePageKey).toString(); + const QString &homePage + = d->m_helpEngine->customValue(HomePageKey).toString(); if (!homePage.isEmpty()) return homePage; return defaultHomePage(); @@ -543,129 +586,151 @@ const QString HelpEngineWrapper::homePage() const void HelpEngineWrapper::setHomePage(const QString &page) { TRACE_OBJ - m_helpEngine->setCustomValue(HomePageKey, page); + d->m_helpEngine->setCustomValue(HomePageKey, page); } const QString HelpEngineWrapper::defaultHomePage() const { TRACE_OBJ - return CollectionConfiguration::defaultHomePage(*m_helpEngine); + return CollectionConfiguration::defaultHomePage(*d->m_helpEngine); } void HelpEngineWrapper::setDefaultHomePage(const QString &page) { TRACE_OBJ - CollectionConfiguration::setDefaultHomePage(*m_helpEngine, page); + CollectionConfiguration::setDefaultHomePage(*d->m_helpEngine, page); } bool HelpEngineWrapper::hasFontSettings() const { TRACE_OBJ - return m_helpEngine->customValue(UseAppFontKey).isValid(); + return d->m_helpEngine->customValue(UseAppFontKey).isValid(); } bool HelpEngineWrapper::usesAppFont() const { TRACE_OBJ - return m_helpEngine->customValue(UseAppFontKey).toBool(); + return d->m_helpEngine->customValue(UseAppFontKey).toBool(); } void HelpEngineWrapper::setUseAppFont(bool useAppFont) { TRACE_OBJ - m_helpEngine->setCustomValue(UseAppFontKey, useAppFont); + d->m_helpEngine->setCustomValue(UseAppFontKey, useAppFont); } bool HelpEngineWrapper::usesBrowserFont() const { TRACE_OBJ - return m_helpEngine->customValue(UseBrowserFontKey, false).toBool(); + return d->m_helpEngine->customValue(UseBrowserFontKey, false).toBool(); } void HelpEngineWrapper::setUseBrowserFont(bool useBrowserFont) { TRACE_OBJ - m_helpEngine->setCustomValue(UseBrowserFontKey, useBrowserFont); + d->m_helpEngine->setCustomValue(UseBrowserFontKey, useBrowserFont); } const QFont HelpEngineWrapper::appFont() const { TRACE_OBJ - return qVariantValue<QFont>(m_helpEngine->customValue(AppFontKey)); + return qVariantValue<QFont>(d->m_helpEngine->customValue(AppFontKey)); } void HelpEngineWrapper::setAppFont(const QFont &font) { TRACE_OBJ - m_helpEngine->setCustomValue(AppFontKey, font); + d->m_helpEngine->setCustomValue(AppFontKey, font); } QFontDatabase::WritingSystem HelpEngineWrapper::appWritingSystem() const { TRACE_OBJ return static_cast<QFontDatabase::WritingSystem>( - m_helpEngine->customValue(AppWritingSystemKey).toInt()); + d->m_helpEngine->customValue(AppWritingSystemKey).toInt()); } void HelpEngineWrapper::setAppWritingSystem(QFontDatabase::WritingSystem system) { TRACE_OBJ - m_helpEngine->setCustomValue(AppWritingSystemKey, system); + d->m_helpEngine->setCustomValue(AppWritingSystemKey, system); } const QFont HelpEngineWrapper::browserFont() const { TRACE_OBJ - return qVariantValue<QFont>(m_helpEngine->customValue(BrowserFontKey)); + return qVariantValue<QFont>(d->m_helpEngine->customValue(BrowserFontKey)); } void HelpEngineWrapper::setBrowserFont(const QFont &font) { TRACE_OBJ - m_helpEngine->setCustomValue(BrowserFontKey, font); + d->m_helpEngine->setCustomValue(BrowserFontKey, font); } QFontDatabase::WritingSystem HelpEngineWrapper::browserWritingSystem() const { TRACE_OBJ return static_cast<QFontDatabase::WritingSystem>( - m_helpEngine->customValue(BrowserWritingSystemKey).toInt()); + d->m_helpEngine->customValue(BrowserWritingSystemKey).toInt()); } void HelpEngineWrapper::setBrowserWritingSystem(QFontDatabase::WritingSystem system) { TRACE_OBJ - m_helpEngine->setCustomValue(BrowserWritingSystemKey, system); + d->m_helpEngine->setCustomValue(BrowserWritingSystemKey, system); } -void HelpEngineWrapper::assertDocFilesWatched() +TimeoutForwarder::TimeoutForwarder(const QString &fileName) + : m_fileName(fileName) { TRACE_OBJ - Q_ASSERT(m_qchWatcher->files().count() - == m_helpEngine->registeredDocumentations().count()); } -TimeoutForwarder::TimeoutForwarder(const QString &fileName) - : m_fileName(fileName) +void TimeoutForwarder::forward() { TRACE_OBJ + HelpEngineWrapper::instance().d->qchFileChanged(m_fileName, true); } -void TimeoutForwarder::forward() + +HelpEngineWrapperPrivate::HelpEngineWrapperPrivate(const QString &collectionFile) + : m_helpEngine(new QHelpEngine(collectionFile, this)), + m_qchWatcher(new QFileSystemWatcher(this)) { TRACE_OBJ - HelpEngineWrapper::instance().qchFileChanged(m_fileName, true); + initFileSystemWatchers(); +} + +void HelpEngineWrapperPrivate::initFileSystemWatchers() +{ + TRACE_OBJ + foreach(const QString &ns, m_helpEngine->registeredDocumentations()) { + const QString &docFile = m_helpEngine->documentationFileName(ns); + m_qchWatcher->addPath(docFile); + connect(m_qchWatcher, SIGNAL(fileChanged(QString)), + this, SLOT(qchFileChanged(QString))); + } + assertDocFilesWatched(); } -void HelpEngineWrapper::qchFileChanged(const QString &fileName) +void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName) { TRACE_OBJ qchFileChanged(fileName, false); } -void HelpEngineWrapper::qchFileChanged(const QString &fileName, bool fromTimeout) +void HelpEngineWrapperPrivate::assertDocFilesWatched() +{ + TRACE_OBJ + Q_ASSERT(m_qchWatcher->files().count() + == m_helpEngine->registeredDocumentations().count()); +} + +void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName, + bool fromTimeout) { TRACE_OBJ @@ -731,4 +796,7 @@ void HelpEngineWrapper::qchFileChanged(const QString &fileName, bool fromTimeout m_recentQchUpdates.erase(it); } + QT_END_NAMESPACE + +#include "helpenginewrapper.moc" diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h index 348479e..ea7b762 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.h +++ b/tools/assistant/tools/assistant/helpenginewrapper.h @@ -42,11 +42,8 @@ #ifndef HELPENGINEWRAPPER_H #define HELPENGINEWRAPPER_H -#include <QtCore/QDateTime> #include <QtCore/QMap> #include <QtCore/QObject> -#include <QtCore/QPair> -#include <QtCore/QSharedPointer> #include <QtCore/QString> #include <QtCore/QStringList> #include <QtCore/QUrl> @@ -58,8 +55,6 @@ QT_BEGIN_NAMESPACE class QFileSystemWatcher; class QHelpContentModel; class QHelpContentWidget; -class QHelpEngine; -class QHelpEngineCore; class QHelpIndexModel; class QHelpIndexWidget; class QHelpSearchEngine; @@ -70,24 +65,14 @@ enum { ShowLastPages = 2 }; - -class TimeoutForwarder : public QObject -{ - Q_OBJECT -public: - TimeoutForwarder(const QString &fileName); -private slots: - void forward(); -private: - friend class HelpEngineWrapper; - - const QString m_fileName; -}; +class HelpEngineWrapperPrivate; +class TimeoutForwarder; class HelpEngineWrapper : public QObject { Q_OBJECT Q_DISABLE_COPY(HelpEngineWrapper) + friend class TimeoutForwarder; public: static HelpEngineWrapper &instance(const QString &collectionFile = QString()); static void removeInstance(); @@ -210,23 +195,13 @@ signals: void currentFilterChanged(const QString ¤tFilter); void setupFinished(); -private slots: - void qchFileChanged(const QString &fileName); - private: - friend class TimeoutForwarder; - HelpEngineWrapper(const QString &collectionFile); - void initFileSystemWatchers(); - void assertDocFilesWatched(); - void qchFileChanged(const QString &fileName, bool fromTimeout); + ~HelpEngineWrapper(); - static const int UpdateGracePeriod = 2000; static HelpEngineWrapper *helpEngineWrapper; - QHelpEngine * const m_helpEngine; - QFileSystemWatcher * const m_qchWatcher; - typedef QPair<QDateTime, QSharedPointer<TimeoutForwarder> > RecentSignal; - QMap<QString, RecentSignal> m_recentQchUpdates; + + HelpEngineWrapperPrivate *d; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/main.cpp b/tools/assistant/tools/assistant/main.cpp index ce85854..dfee0fb 100644 --- a/tools/assistant/tools/assistant/main.cpp +++ b/tools/assistant/tools/assistant/main.cpp @@ -427,6 +427,6 @@ int main(int argc, char *argv[]) a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); const int retval = a.exec(); delete w; - delete &HelpEngineWrapper::instance(); + HelpEngineWrapper::removeInstance(); return retval; } |