2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-06-11 13:11:37 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-06-11 13:11:37 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-06-11 13:11:37 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-06-11 13:11:37 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-06-11 13:11:37 +02:00
|
|
|
|
|
|
|
|
#include "helpmanager.h"
|
|
|
|
|
|
2011-04-15 15:55:11 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2018-02-12 13:28:37 +01:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2011-04-15 15:55:11 +02:00
|
|
|
#include <utils/filesystemwatcher.h>
|
2014-12-01 17:07:03 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2018-02-12 13:28:37 +01:00
|
|
|
#include <utils/runextensions.h>
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
2018-02-12 13:28:37 +01:00
|
|
|
#include <QFutureWatcher>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStringList>
|
2017-02-08 10:57:10 +01:00
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
|
|
#ifdef QT_HELP_LIB
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHelpEngineCore>
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2018-02-12 13:28:37 +01:00
|
|
|
#include <QMutexLocker>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSqlDatabase>
|
|
|
|
|
#include <QSqlDriver>
|
|
|
|
|
#include <QSqlError>
|
|
|
|
|
#include <QSqlQuery>
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2014-12-02 17:51:14 +01:00
|
|
|
static const char kUserDocumentationKey[] = "Help/UserDocumentation";
|
2018-02-12 13:28:37 +01:00
|
|
|
static const char kUpdateDocumentationTask[] = "UpdateDocumentationTask";
|
2014-12-02 17:51:14 +01:00
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
namespace Core {
|
|
|
|
|
|
2011-09-02 19:05:12 +02:00
|
|
|
struct HelpManagerPrivate
|
|
|
|
|
{
|
2018-07-21 21:11:46 +02:00
|
|
|
HelpManagerPrivate() = default;
|
2018-01-24 10:20:59 +01:00
|
|
|
~HelpManagerPrivate();
|
|
|
|
|
|
|
|
|
|
const QStringList documentationFromInstaller();
|
2014-12-02 17:51:14 +01:00
|
|
|
void readSettings();
|
|
|
|
|
void writeSettings();
|
|
|
|
|
void cleanUpDocumentation();
|
2011-10-31 14:27:09 +01:00
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
bool m_needsSetup = true;
|
|
|
|
|
QHelpEngineCore *m_helpEngine = nullptr;
|
|
|
|
|
Utils::FileSystemWatcher *m_collectionWatcher = nullptr;
|
2010-09-16 12:26:28 +02:00
|
|
|
|
2014-12-02 17:51:14 +01:00
|
|
|
// data for delayed initialization
|
|
|
|
|
QSet<QString> m_filesToRegister;
|
|
|
|
|
QSet<QString> m_nameSpacesToUnregister;
|
2010-09-16 12:26:28 +02:00
|
|
|
QHash<QString, QVariant> m_customValues;
|
2014-12-02 17:51:14 +01:00
|
|
|
|
|
|
|
|
QSet<QString> m_userRegisteredFiles;
|
2018-02-12 13:28:37 +01:00
|
|
|
|
2018-02-21 08:41:36 +01:00
|
|
|
QMutex m_helpengineMutex;
|
|
|
|
|
QFuture<bool> m_registerFuture;
|
2010-09-16 12:26:28 +02:00
|
|
|
};
|
|
|
|
|
|
2018-01-24 10:20:59 +01:00
|
|
|
static HelpManager *m_instance = nullptr;
|
|
|
|
|
static HelpManagerPrivate *d = nullptr;
|
2010-06-11 13:11:37 +02:00
|
|
|
|
|
|
|
|
static const char linksForKeyQuery[] = "SELECT d.Title, f.Name, e.Name, "
|
|
|
|
|
"d.Name, a.Anchor FROM IndexTable a, FileNameTable d, FolderTable e, "
|
|
|
|
|
"NamespaceTable f WHERE a.FileId=d.FileId AND d.FolderId=e.Id AND "
|
|
|
|
|
"a.NamespaceId=f.Id AND a.Name='%1'";
|
|
|
|
|
|
|
|
|
|
// -- DbCleaner
|
|
|
|
|
|
2011-09-02 19:05:12 +02:00
|
|
|
struct DbCleaner
|
|
|
|
|
{
|
|
|
|
|
DbCleaner(const QString &dbName) : name(dbName) {}
|
|
|
|
|
~DbCleaner() { QSqlDatabase::removeDatabase(name); }
|
2010-06-11 13:11:37 +02:00
|
|
|
QString name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// -- HelpManager
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
HelpManager::HelpManager(QObject *parent) :
|
2013-06-25 13:37:21 +02:00
|
|
|
QObject(parent)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_CHECK(!m_instance);
|
2011-09-02 19:05:12 +02:00
|
|
|
m_instance = this;
|
2013-06-25 13:37:21 +02:00
|
|
|
d = new HelpManagerPrivate;
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpManager::~HelpManager()
|
|
|
|
|
{
|
2011-09-02 19:05:12 +02:00
|
|
|
delete d;
|
2018-01-24 10:20:59 +01:00
|
|
|
m_instance = nullptr;
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2014-12-11 18:10:25 +01:00
|
|
|
HelpManager *HelpManager::instance()
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2011-09-02 19:05:12 +02:00
|
|
|
Q_ASSERT(m_instance);
|
|
|
|
|
return m_instance;
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString HelpManager::collectionFilePath()
|
|
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
return QDir::cleanPath(ICore::userResourcePath()
|
2010-09-10 14:09:08 +02:00
|
|
|
+ QLatin1String("/helpcollection.qhc"));
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::registerDocumentation(const QStringList &files)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup) {
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &filePath : files)
|
2014-12-02 17:51:14 +01:00
|
|
|
d->m_filesToRegister.insert(filePath);
|
2010-06-11 13:11:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-12 13:28:37 +01:00
|
|
|
QFuture<bool> future = Utils::runAsync(&HelpManager::registerDocumentationNow, files);
|
|
|
|
|
Utils::onResultReady(future, m_instance, [](bool docsChanged){
|
|
|
|
|
if (docsChanged) {
|
|
|
|
|
d->m_helpEngine->setupData();
|
|
|
|
|
emit m_instance->documentationChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ProgressManager::addTask(future, tr("Update Documentation"),
|
|
|
|
|
kUpdateDocumentationTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::registerDocumentationNow(QFutureInterface<bool> &futureInterface,
|
|
|
|
|
const QStringList &files)
|
|
|
|
|
{
|
2018-02-21 08:41:36 +01:00
|
|
|
QMutexLocker locker(&d->m_helpengineMutex);
|
2018-02-12 13:28:37 +01:00
|
|
|
|
|
|
|
|
futureInterface.setProgressRange(0, files.count());
|
|
|
|
|
futureInterface.setProgressValue(0);
|
|
|
|
|
|
|
|
|
|
QHelpEngineCore helpEngine(collectionFilePath());
|
2018-02-27 13:34:03 +01:00
|
|
|
helpEngine.setupData();
|
2010-06-11 13:11:37 +02:00
|
|
|
bool docsChanged = false;
|
2018-03-01 10:12:45 +01:00
|
|
|
QStringList nameSpaces = helpEngine.registeredDocumentations();
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &file : files) {
|
2018-02-21 08:41:36 +01:00
|
|
|
if (futureInterface.isCanceled())
|
|
|
|
|
break;
|
2018-02-12 13:28:37 +01:00
|
|
|
futureInterface.setProgressValue(futureInterface.progressValue() + 1);
|
|
|
|
|
const QString &nameSpace = helpEngine.namespaceName(file);
|
2010-06-11 13:11:37 +02:00
|
|
|
if (nameSpace.isEmpty())
|
|
|
|
|
continue;
|
2018-02-15 13:26:41 +01:00
|
|
|
if (!nameSpaces.contains(nameSpace)) {
|
2018-02-12 13:28:37 +01:00
|
|
|
if (helpEngine.registerDocumentation(file)) {
|
2018-02-15 13:26:41 +01:00
|
|
|
nameSpaces.append(nameSpace);
|
2010-06-11 13:11:37 +02:00
|
|
|
docsChanged = true;
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Error registering namespace '" << nameSpace
|
2018-02-12 13:28:37 +01:00
|
|
|
<< "' from file '" << file << "':" << helpEngine.error();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
2010-07-30 13:48:24 +02:00
|
|
|
} else {
|
|
|
|
|
const QLatin1String key("CreationDate");
|
2018-02-12 13:28:37 +01:00
|
|
|
const QString &newDate = helpEngine.metaData(file, key).toString();
|
|
|
|
|
const QString &oldDate = helpEngine.metaData(
|
2018-03-01 10:12:45 +01:00
|
|
|
helpEngine.documentationFileName(nameSpace), key).toString();
|
2010-07-30 13:48:24 +02:00
|
|
|
if (QDateTime::fromString(newDate, Qt::ISODate)
|
|
|
|
|
> QDateTime::fromString(oldDate, Qt::ISODate)) {
|
2018-02-12 13:28:37 +01:00
|
|
|
if (helpEngine.unregisterDocumentation(nameSpace)) {
|
2010-07-30 13:48:24 +02:00
|
|
|
docsChanged = true;
|
2018-02-12 13:28:37 +01:00
|
|
|
helpEngine.registerDocumentation(file);
|
2010-07-30 13:48:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-12 13:28:37 +01:00
|
|
|
futureInterface.reportResult(docsChanged);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::unregisterDocumentation(const QStringList &nameSpaces)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup) {
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &name : nameSpaces)
|
2014-12-02 17:51:14 +01:00
|
|
|
d->m_nameSpacesToUnregister.insert(name);
|
2010-06-11 13:11:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 08:41:36 +01:00
|
|
|
QMutexLocker locker(&d->m_helpengineMutex);
|
2010-06-11 13:11:37 +02:00
|
|
|
bool docsChanged = false;
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &nameSpace : nameSpaces) {
|
2014-12-02 17:51:14 +01:00
|
|
|
const QString filePath = d->m_helpEngine->documentationFileName(nameSpace);
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->unregisterDocumentation(nameSpace)) {
|
2010-06-11 13:11:37 +02:00
|
|
|
docsChanged = true;
|
2014-12-02 17:51:14 +01:00
|
|
|
d->m_userRegisteredFiles.remove(filePath);
|
2010-06-11 13:11:37 +02:00
|
|
|
} else {
|
|
|
|
|
qWarning() << "Error unregistering namespace '" << nameSpace
|
2014-12-02 17:51:14 +01:00
|
|
|
<< "' from file '" << filePath
|
2010-09-16 12:26:28 +02:00
|
|
|
<< "': " << d->m_helpEngine->error();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-12 13:28:37 +01:00
|
|
|
locker.unlock();
|
2010-06-11 13:11:37 +02:00
|
|
|
if (docsChanged)
|
2013-08-29 19:00:34 +02:00
|
|
|
emit m_instance->documentationChanged();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2014-12-02 17:51:14 +01:00
|
|
|
void HelpManager::registerUserDocumentation(const QStringList &filePaths)
|
|
|
|
|
{
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &filePath : filePaths)
|
2014-12-02 17:51:14 +01:00
|
|
|
d->m_userRegisteredFiles.insert(filePath);
|
|
|
|
|
registerDocumentation(filePaths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSet<QString> HelpManager::userDocumentationPaths()
|
|
|
|
|
{
|
|
|
|
|
return d->m_userRegisteredFiles;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-26 12:58:06 +02:00
|
|
|
static QUrl buildQUrl(const QString &ns, const QString &folder,
|
2010-06-11 13:11:37 +02:00
|
|
|
const QString &relFileName, const QString &anchor)
|
|
|
|
|
{
|
|
|
|
|
QUrl url;
|
|
|
|
|
url.setScheme(QLatin1String("qthelp"));
|
2012-10-26 12:58:06 +02:00
|
|
|
url.setAuthority(ns);
|
|
|
|
|
url.setPath(QLatin1Char('/') + folder + QLatin1Char('/') + relFileName);
|
2010-06-11 13:11:37 +02:00
|
|
|
url.setFragment(anchor);
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This should go into Qt 4.8 once we start using it for Qt Creator
|
2013-08-29 19:00:34 +02:00
|
|
|
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
|
|
|
|
QMap<QString, QUrl> links;
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return links);
|
2010-06-11 13:11:37 +02:00
|
|
|
|
|
|
|
|
const QLatin1String sqlite("QSQLITE");
|
|
|
|
|
const QLatin1String name("HelpManager::linksForKeyword");
|
|
|
|
|
|
|
|
|
|
DbCleaner cleaner(name);
|
|
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
|
|
|
|
|
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
|
2010-09-16 12:26:28 +02:00
|
|
|
const QStringList ®isteredDocs = d->m_helpEngine->registeredDocumentations();
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &nameSpace : registeredDocs) {
|
2010-09-16 12:26:28 +02:00
|
|
|
db.setDatabaseName(d->m_helpEngine->documentationFileName(nameSpace));
|
2010-06-11 13:11:37 +02:00
|
|
|
if (db.open()) {
|
|
|
|
|
QSqlQuery query = QSqlQuery(db);
|
|
|
|
|
query.setForwardOnly(true);
|
|
|
|
|
query.exec(QString::fromLatin1(linksForKeyQuery).arg(key));
|
|
|
|
|
while (query.next()) {
|
|
|
|
|
QString title = query.value(0).toString();
|
|
|
|
|
if (title.isEmpty()) // generate a title + corresponding path
|
|
|
|
|
title = key + QLatin1String(" : ") + query.value(3).toString();
|
|
|
|
|
links.insertMulti(title, buildQUrl(query.value(1).toString(),
|
|
|
|
|
query.value(2).toString(), query.value(3).toString(),
|
|
|
|
|
query.value(4).toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return links;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QMap<QString, QUrl> empty;
|
|
|
|
|
QTC_ASSERT(!d->m_needsSetup, return empty);
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->linksForIdentifier(id);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QUrl HelpManager::findFile(const QUrl &url)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return QUrl());
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->findFile(url);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QByteArray HelpManager::fileData(const QUrl &url)
|
2010-07-12 13:24:45 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return QByteArray());
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->fileData(url);
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-20 17:24:18 +02:00
|
|
|
void HelpManager::handleHelpRequest(const QUrl &url, HelpManager::HelpViewerLocation location)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-06-20 17:24:18 +02:00
|
|
|
emit m_instance->helpRequested(url, location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::handleHelpRequest(const QString &url, HelpViewerLocation location)
|
|
|
|
|
{
|
|
|
|
|
handleHelpRequest(QUrl(url), location);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QStringList HelpManager::registeredNamespaces()
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return QStringList());
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->registeredDocumentations();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QString HelpManager::namespaceFromFile(const QString &file)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return QString());
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->namespaceName(file);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QString HelpManager::fileFromNamespace(const QString &nameSpace)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return QString());
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->documentationFileName(nameSpace);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-02 16:30:56 +02:00
|
|
|
void HelpManager::setCustomValue(const QString &key, const QVariant &value)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup) {
|
|
|
|
|
d->m_customValues.insert(key, value);
|
2010-08-02 16:30:56 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->setCustomValue(key, value))
|
2013-08-29 19:00:34 +02:00
|
|
|
emit m_instance->collectionFileChanged();
|
2010-08-02 16:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QVariant HelpManager::customValue(const QString &key, const QVariant &value)
|
2010-08-02 16:30:56 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return QVariant());
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->customValue(key, value);
|
2010-08-02 16:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
HelpManager::Filters HelpManager::filters()
|
2010-08-02 16:30:56 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return Filters());
|
2010-08-02 16:30:56 +02:00
|
|
|
|
|
|
|
|
Filters filters;
|
2010-09-16 12:26:28 +02:00
|
|
|
const QStringList &customFilters = d->m_helpEngine->customFilters();
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &filter : customFilters)
|
2010-09-16 12:26:28 +02:00
|
|
|
filters.insert(filter, d->m_helpEngine->filterAttributes(filter));
|
2010-08-02 16:30:56 +02:00
|
|
|
return filters;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
HelpManager::Filters HelpManager::fixedFilters()
|
2010-08-02 16:30:56 +02:00
|
|
|
{
|
|
|
|
|
Filters fixedFilters;
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return fixedFilters);
|
2010-08-02 16:30:56 +02:00
|
|
|
|
|
|
|
|
const QLatin1String sqlite("QSQLITE");
|
|
|
|
|
const QLatin1String name("HelpManager::fixedCustomFilters");
|
|
|
|
|
|
|
|
|
|
DbCleaner cleaner(name);
|
|
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
|
|
|
|
|
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
|
2010-09-16 12:26:28 +02:00
|
|
|
const QStringList ®isteredDocs = d->m_helpEngine->registeredDocumentations();
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &nameSpace : registeredDocs) {
|
2010-09-16 12:26:28 +02:00
|
|
|
db.setDatabaseName(d->m_helpEngine->documentationFileName(nameSpace));
|
2010-08-02 16:30:56 +02:00
|
|
|
if (db.open()) {
|
|
|
|
|
QSqlQuery query = QSqlQuery(db);
|
|
|
|
|
query.setForwardOnly(true);
|
|
|
|
|
query.exec(QLatin1String("SELECT Name FROM FilterNameTable"));
|
|
|
|
|
while (query.next()) {
|
|
|
|
|
const QString &filter = query.value(0).toString();
|
2010-09-16 12:26:28 +02:00
|
|
|
fixedFilters.insert(filter, d->m_helpEngine->filterAttributes(filter));
|
2010-08-02 16:30:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fixedFilters;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
HelpManager::Filters HelpManager::userDefinedFilters()
|
2010-08-02 16:30:56 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return Filters());
|
2010-08-02 16:30:56 +02:00
|
|
|
|
|
|
|
|
Filters all = filters();
|
|
|
|
|
const Filters &fixed = fixedFilters();
|
|
|
|
|
for (Filters::const_iterator it = fixed.constBegin(); it != fixed.constEnd(); ++it)
|
|
|
|
|
all.remove(it.key());
|
|
|
|
|
return all;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::removeUserDefinedFilter(const QString &filter)
|
|
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return);
|
2010-08-02 16:30:56 +02:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->removeCustomFilter(filter))
|
2013-08-29 19:00:34 +02:00
|
|
|
emit m_instance->collectionFileChanged();
|
2010-08-02 16:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList &attr)
|
|
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return);
|
2010-08-02 16:30:56 +02:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->addCustomFilter(filter, attr))
|
2013-08-29 19:00:34 +02:00
|
|
|
emit m_instance->collectionFileChanged();
|
2010-08-02 16:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-21 08:41:36 +01:00
|
|
|
void HelpManager::aboutToShutdown()
|
|
|
|
|
{
|
|
|
|
|
if (d && d->m_registerFuture.isRunning()) {
|
|
|
|
|
d->m_registerFuture.cancel();
|
|
|
|
|
d->m_registerFuture.waitForFinished();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
// -- private
|
2010-06-11 13:11:37 +02:00
|
|
|
|
|
|
|
|
void HelpManager::setupHelpManager()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_needsSetup)
|
2010-06-11 13:11:37 +02:00
|
|
|
return;
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_needsSetup = false;
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2014-12-02 17:51:14 +01:00
|
|
|
d->readSettings();
|
|
|
|
|
|
|
|
|
|
// create the help engine
|
2013-08-29 19:00:34 +02:00
|
|
|
d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), m_instance);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_helpEngine->setupData();
|
2014-12-02 17:51:14 +01:00
|
|
|
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &filePath : d->documentationFromInstaller())
|
2014-12-02 17:51:14 +01:00
|
|
|
d->m_filesToRegister.insert(filePath);
|
|
|
|
|
|
|
|
|
|
d->cleanUpDocumentation();
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_nameSpacesToUnregister.isEmpty()) {
|
2014-12-02 17:51:14 +01:00
|
|
|
unregisterDocumentation(d->m_nameSpacesToUnregister.toList());
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_nameSpacesToUnregister.clear();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_filesToRegister.isEmpty()) {
|
2014-12-02 17:51:14 +01:00
|
|
|
registerDocumentation(d->m_filesToRegister.toList());
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_filesToRegister.clear();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-02 16:30:56 +02:00
|
|
|
QHash<QString, QVariant>::const_iterator it;
|
2010-09-16 12:26:28 +02:00
|
|
|
for (it = d->m_customValues.constBegin(); it != d->m_customValues.constEnd(); ++it)
|
2010-08-02 16:30:56 +02:00
|
|
|
setCustomValue(it.key(), it.value());
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
emit m_instance->setupFinished();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2014-12-02 17:51:14 +01:00
|
|
|
void HelpManagerPrivate::cleanUpDocumentation()
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-02 17:51:14 +01:00
|
|
|
// mark documentation for removal for which there is no documentation file anymore
|
|
|
|
|
// mark documentation for removal that is neither user registered, nor marked for registration
|
|
|
|
|
const QStringList ®isteredDocs = m_helpEngine->registeredDocumentations();
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &nameSpace : registeredDocs) {
|
2014-12-02 17:51:14 +01:00
|
|
|
const QString filePath = m_helpEngine->documentationFileName(nameSpace);
|
|
|
|
|
if (!QFileInfo::exists(filePath)
|
|
|
|
|
|| (!m_filesToRegister.contains(filePath)
|
|
|
|
|
&& !m_userRegisteredFiles.contains(filePath))) {
|
|
|
|
|
m_nameSpacesToUnregister.insert(nameSpace);
|
|
|
|
|
}
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 10:20:59 +01:00
|
|
|
HelpManagerPrivate::~HelpManagerPrivate()
|
|
|
|
|
{
|
|
|
|
|
writeSettings();
|
|
|
|
|
delete m_helpEngine;
|
|
|
|
|
m_helpEngine = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList HelpManagerPrivate::documentationFromInstaller()
|
2011-10-31 14:27:09 +01:00
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
QSettings *installSettings = ICore::settings();
|
2018-01-24 10:20:59 +01:00
|
|
|
const QStringList documentationPaths = installSettings->value(QLatin1String("Help/InstalledDocumentation"))
|
2011-12-16 16:07:20 +01:00
|
|
|
.toStringList();
|
2011-10-31 14:27:09 +01:00
|
|
|
QStringList documentationFiles;
|
2018-01-24 10:20:59 +01:00
|
|
|
for (const QString &path : documentationPaths) {
|
2011-10-31 14:27:09 +01:00
|
|
|
QFileInfo pathInfo(path);
|
|
|
|
|
if (pathInfo.isFile() && pathInfo.isReadable()) {
|
|
|
|
|
documentationFiles << pathInfo.absoluteFilePath();
|
|
|
|
|
} else if (pathInfo.isDir()) {
|
2018-01-24 10:20:59 +01:00
|
|
|
const QFileInfoList files(QDir(path).entryInfoList(QStringList(QLatin1String("*.qch")),
|
|
|
|
|
QDir::Files | QDir::Readable));
|
|
|
|
|
for (const QFileInfo &fileInfo : files)
|
2011-10-31 14:27:09 +01:00
|
|
|
documentationFiles << fileInfo.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return documentationFiles;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-02 17:51:14 +01:00
|
|
|
void HelpManagerPrivate::readSettings()
|
|
|
|
|
{
|
|
|
|
|
m_userRegisteredFiles = ICore::settings()->value(QLatin1String(kUserDocumentationKey))
|
|
|
|
|
.toStringList().toSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManagerPrivate::writeSettings()
|
|
|
|
|
{
|
|
|
|
|
const QStringList list = m_userRegisteredFiles.toList();
|
|
|
|
|
ICore::settings()->setValue(QLatin1String(kUserDocumentationKey), list);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
} // Core
|
2017-02-08 10:57:10 +01:00
|
|
|
|
|
|
|
|
#else // QT_HELP_LIB
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
HelpManager *HelpManager::instance() { return nullptr; }
|
2017-02-08 10:57:10 +01:00
|
|
|
|
|
|
|
|
QString HelpManager::collectionFilePath() { return QString(); }
|
|
|
|
|
|
|
|
|
|
void HelpManager::registerDocumentation(const QStringList &) {}
|
2018-02-21 08:14:04 +01:00
|
|
|
void HelpManager::registerDocumentationNow(QFutureInterface<bool> &, const QStringList &) {}
|
2017-02-08 10:57:10 +01:00
|
|
|
void HelpManager::unregisterDocumentation(const QStringList &) {}
|
|
|
|
|
|
|
|
|
|
void HelpManager::registerUserDocumentation(const QStringList &) {}
|
|
|
|
|
QSet<QString> HelpManager::userDocumentationPaths() { return {}; }
|
|
|
|
|
|
|
|
|
|
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &) { return {}; }
|
|
|
|
|
QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &) { return {}; }
|
|
|
|
|
|
|
|
|
|
QUrl HelpManager::findFile(const QUrl &) { return QUrl();}
|
|
|
|
|
QByteArray HelpManager::fileData(const QUrl &) { return QByteArray();}
|
|
|
|
|
|
|
|
|
|
QStringList HelpManager::registeredNamespaces() { return {}; }
|
|
|
|
|
QString HelpManager::namespaceFromFile(const QString &) { return QString(); }
|
|
|
|
|
QString HelpManager::fileFromNamespace(const QString &) { return QString(); }
|
|
|
|
|
|
|
|
|
|
void HelpManager::setCustomValue(const QString &, const QVariant &) {}
|
|
|
|
|
QVariant HelpManager::customValue(const QString &, const QVariant &) { return QVariant(); }
|
|
|
|
|
|
|
|
|
|
HelpManager::Filters filters() { return {}; }
|
|
|
|
|
HelpManager::Filters fixedFilters() { return {}; }
|
|
|
|
|
|
|
|
|
|
HelpManager::Filters userDefinedFilters() { return {}; }
|
|
|
|
|
|
|
|
|
|
void HelpManager::removeUserDefinedFilter(const QString &) {}
|
|
|
|
|
void HelpManager::addUserDefinedFilter(const QString &, const QStringList &) {}
|
|
|
|
|
|
|
|
|
|
void HelpManager::handleHelpRequest(const QUrl &, HelpManager::HelpViewerLocation) {}
|
|
|
|
|
void HelpManager::handleHelpRequest(const QString &, HelpViewerLocation) {}
|
|
|
|
|
|
|
|
|
|
HelpManager::HelpManager(QObject *) {}
|
2018-07-21 21:11:46 +02:00
|
|
|
HelpManager::~HelpManager() = default;
|
2018-02-26 07:39:17 +01:00
|
|
|
void HelpManager::aboutToShutdown() {}
|
2017-02-08 10:57:10 +01:00
|
|
|
void HelpManager::setupHelpManager() {}
|
|
|
|
|
|
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
|
|
#endif // QT_HELP_LIB
|