forked from qt-creator/qt-creator
HelpManager: Hide registerDocumentationNow() in cpp
This avoid calling collectionFilePath() concurrently, which might be potentially problematic. Change-Id: Ic873b6429b933f2f3359623b1e9cb14409ef3c4b Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -94,45 +94,15 @@ QString HelpManager::collectionFilePath()
|
|||||||
return ICore::userResourcePath("helpcollection.qhc").toString();
|
return ICore::userResourcePath("helpcollection.qhc").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpManager::registerDocumentation(const QStringList &files)
|
static void registerDocumentationNow(QPromise<bool> &promise, const QString &collectionFilePath,
|
||||||
{
|
const QStringList &files)
|
||||||
if (d->m_needsSetup) {
|
|
||||||
for (const QString &filePath : files)
|
|
||||||
d->m_filesToRegister.insert(filePath);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<bool> future = Utils::asyncRun(&HelpManager::registerDocumentationNow, files);
|
|
||||||
Utils::onResultReady(future, this, [](bool docsChanged){
|
|
||||||
if (docsChanged) {
|
|
||||||
d->m_helpEngine->setupData();
|
|
||||||
emit Core::HelpManager::Signals::instance()->documentationChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ProgressManager::addTask(future, Tr::tr("Update Documentation"), kUpdateDocumentationTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelpManager::unregisterDocumentation(const QStringList &fileNames)
|
|
||||||
{
|
|
||||||
if (fileNames.isEmpty())
|
|
||||||
return;
|
|
||||||
const auto getNamespaces = [](const QStringList &fileNames) {
|
|
||||||
QMutexLocker locker(&d->m_helpengineMutex);
|
|
||||||
return Utils::transform(fileNames, [](const QString &filePath) {
|
|
||||||
return QHelpEngineCore::namespaceName(filePath);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
unregisterNamespaces(getNamespaces(fileNames));
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelpManager::registerDocumentationNow(QPromise<bool> &promise, const QStringList &files)
|
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&d->m_helpengineMutex);
|
QMutexLocker locker(&d->m_helpengineMutex);
|
||||||
|
|
||||||
promise.setProgressRange(0, files.count());
|
promise.setProgressRange(0, files.count());
|
||||||
promise.setProgressValue(0);
|
promise.setProgressValue(0);
|
||||||
|
|
||||||
QHelpEngineCore helpEngine(collectionFilePath());
|
QHelpEngineCore helpEngine(collectionFilePath);
|
||||||
helpEngine.setReadOnly(false);
|
helpEngine.setReadOnly(false);
|
||||||
helpEngine.setupData();
|
helpEngine.setupData();
|
||||||
bool docsChanged = false;
|
bool docsChanged = false;
|
||||||
@@ -157,6 +127,37 @@ void HelpManager::registerDocumentationNow(QPromise<bool> &promise, const QStrin
|
|||||||
promise.addResult(docsChanged);
|
promise.addResult(docsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HelpManager::registerDocumentation(const QStringList &files)
|
||||||
|
{
|
||||||
|
if (d->m_needsSetup) {
|
||||||
|
for (const QString &filePath : files)
|
||||||
|
d->m_filesToRegister.insert(filePath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFuture<bool> future = Utils::asyncRun(registerDocumentationNow, collectionFilePath(), files);
|
||||||
|
Utils::onResultReady(future, this, [](bool docsChanged){
|
||||||
|
if (docsChanged) {
|
||||||
|
d->m_helpEngine->setupData();
|
||||||
|
emit Core::HelpManager::Signals::instance()->documentationChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ProgressManager::addTask(future, Tr::tr("Update Documentation"), kUpdateDocumentationTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HelpManager::unregisterDocumentation(const QStringList &fileNames)
|
||||||
|
{
|
||||||
|
if (fileNames.isEmpty())
|
||||||
|
return;
|
||||||
|
const auto getNamespaces = [](const QStringList &fileNames) {
|
||||||
|
QMutexLocker locker(&d->m_helpengineMutex);
|
||||||
|
return Utils::transform(fileNames, [](const QString &filePath) {
|
||||||
|
return QHelpEngineCore::namespaceName(filePath);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
unregisterNamespaces(getNamespaces(fileNames));
|
||||||
|
}
|
||||||
|
|
||||||
void HelpManager::unregisterNamespaces(const QStringList &nameSpaces)
|
void HelpManager::unregisterNamespaces(const QStringList &nameSpaces)
|
||||||
{
|
{
|
||||||
if (d->m_needsSetup) {
|
if (d->m_needsSetup) {
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ public:
|
|||||||
Core::HelpManager::HelpViewerLocation location = Core::HelpManager::HelpModeAlways) override;
|
Core::HelpManager::HelpViewerLocation location = Core::HelpManager::HelpModeAlways) override;
|
||||||
|
|
||||||
static void setupHelpManager();
|
static void setupHelpManager();
|
||||||
static void registerDocumentationNow(QPromise<bool> &promise, const QStringList &fileNames);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void collectionFileChanged();
|
void collectionFileChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user