2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-06-11 13:11:37 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-06-11 13:11:37 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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>
|
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>
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QStringList>
|
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
|
|
|
|
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";
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
namespace Core {
|
|
|
|
|
|
2011-09-02 19:05:12 +02:00
|
|
|
struct HelpManagerPrivate
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
HelpManagerPrivate() :
|
2011-09-02 19:05:12 +02:00
|
|
|
m_needsSetup(true), m_helpEngine(0), m_collectionWatcher(0)
|
|
|
|
|
{}
|
2010-09-16 12:26:28 +02:00
|
|
|
|
2011-10-31 14:27:09 +01:00
|
|
|
QStringList documentationFromInstaller();
|
2014-12-02 17:51:14 +01:00
|
|
|
void readSettings();
|
|
|
|
|
void writeSettings();
|
|
|
|
|
void cleanUpDocumentation();
|
2011-10-31 14:27:09 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
bool m_needsSetup;
|
|
|
|
|
QHelpEngineCore *m_helpEngine;
|
2011-04-15 15:55:11 +02:00
|
|
|
Utils::FileSystemWatcher *m_collectionWatcher;
|
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;
|
2010-09-16 12:26:28 +02:00
|
|
|
};
|
|
|
|
|
|
2011-09-02 19:05:12 +02:00
|
|
|
static HelpManager *m_instance = 0;
|
2013-06-25 13:37:21 +02:00
|
|
|
static HelpManagerPrivate *d;
|
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()
|
|
|
|
|
{
|
2014-12-02 17:51:14 +01:00
|
|
|
d->writeSettings();
|
2010-09-16 12:26:28 +02:00
|
|
|
delete d->m_helpEngine;
|
|
|
|
|
d->m_helpEngine = 0;
|
2011-09-02 19:05:12 +02:00
|
|
|
m_instance = 0;
|
|
|
|
|
delete d;
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
QObject *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) {
|
2014-12-02 17:51:14 +01:00
|
|
|
foreach (const QString &filePath, files)
|
|
|
|
|
d->m_filesToRegister.insert(filePath);
|
2010-06-11 13:11:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool docsChanged = false;
|
|
|
|
|
foreach (const QString &file, files) {
|
2010-09-16 12:26:28 +02:00
|
|
|
const QString &nameSpace = d->m_helpEngine->namespaceName(file);
|
2010-06-11 13:11:37 +02:00
|
|
|
if (nameSpace.isEmpty())
|
|
|
|
|
continue;
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_helpEngine->registeredDocumentations().contains(nameSpace)) {
|
|
|
|
|
if (d->m_helpEngine->registerDocumentation(file)) {
|
2010-06-11 13:11:37 +02:00
|
|
|
docsChanged = true;
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Error registering namespace '" << nameSpace
|
2010-09-16 12:26:28 +02:00
|
|
|
<< "' from file '" << file << "':" << d->m_helpEngine->error();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
2010-07-30 13:48:24 +02:00
|
|
|
} else {
|
|
|
|
|
const QLatin1String key("CreationDate");
|
2010-09-16 12:26:28 +02:00
|
|
|
const QString &newDate = d->m_helpEngine->metaData(file, key).toString();
|
|
|
|
|
const QString &oldDate = d->m_helpEngine->metaData(
|
|
|
|
|
d->m_helpEngine->documentationFileName(nameSpace), key).toString();
|
2010-07-30 13:48:24 +02:00
|
|
|
if (QDateTime::fromString(newDate, Qt::ISODate)
|
|
|
|
|
> QDateTime::fromString(oldDate, Qt::ISODate)) {
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->unregisterDocumentation(nameSpace)) {
|
2010-07-30 13:48:24 +02:00
|
|
|
docsChanged = true;
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_helpEngine->registerDocumentation(file);
|
2010-07-30 13:48:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::unregisterDocumentation(const QStringList &nameSpaces)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup) {
|
2014-12-02 17:51:14 +01:00
|
|
|
foreach (const QString &name, nameSpaces)
|
|
|
|
|
d->m_nameSpacesToUnregister.insert(name);
|
2010-06-11 13:11:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool docsChanged = false;
|
|
|
|
|
foreach (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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
foreach (const QString &filePath, filePaths)
|
|
|
|
|
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();
|
2010-06-11 13:11:37 +02:00
|
|
|
foreach (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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This should go into Qt 4.8 once we start using it for Qt Creator
|
2013-08-01 10:14:10 +02:00
|
|
|
QStringList HelpManager::findKeywords(const QString &key, Qt::CaseSensitivity caseSensitivity,
|
2013-08-29 19:00:34 +02:00
|
|
|
int maxHits)
|
2010-06-11 13:11:37 +02:00
|
|
|
{
|
2014-12-01 17:07:03 +01:00
|
|
|
QTC_ASSERT(!d->m_needsSetup, return QStringList());
|
2010-06-11 13:11:37 +02:00
|
|
|
|
|
|
|
|
const QLatin1String sqlite("QSQLITE");
|
|
|
|
|
const QLatin1String name("HelpManager::findKeywords");
|
|
|
|
|
|
2012-06-01 14:44:44 +02:00
|
|
|
QSet<QString> keywords;
|
|
|
|
|
QSet<QString> keywordsToSort;
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
DbCleaner cleaner(name);
|
|
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
|
|
|
|
|
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
|
2011-03-16 15:20:02 +01:00
|
|
|
QHelpEngineCore core(collectionFilePath());
|
|
|
|
|
core.setAutoSaveFilter(false);
|
|
|
|
|
core.setCurrentFilter(tr("Unfiltered"));
|
|
|
|
|
core.setupData();
|
|
|
|
|
const QStringList ®isteredDocs = core.registeredDocumentations();
|
2010-06-11 13:11:37 +02:00
|
|
|
foreach (const QString &nameSpace, registeredDocs) {
|
2011-03-16 15:20:02 +01:00
|
|
|
db.setDatabaseName(core.documentationFileName(nameSpace));
|
2010-06-11 13:11:37 +02:00
|
|
|
if (db.open()) {
|
|
|
|
|
QSqlQuery query = QSqlQuery(db);
|
|
|
|
|
query.setForwardOnly(true);
|
2012-06-01 14:44:44 +02:00
|
|
|
query.exec(QString::fromLatin1("SELECT DISTINCT Name FROM IndexTable WHERE Name LIKE "
|
|
|
|
|
"'%%1%' LIMIT %2").arg(key, QString::number(maxHits)));
|
2010-06-11 13:11:37 +02:00
|
|
|
while (query.next()) {
|
2010-06-21 15:00:29 +10:00
|
|
|
const QString &keyValue = query.value(0).toString();
|
|
|
|
|
if (!keyValue.isEmpty()) {
|
2013-08-01 10:14:10 +02:00
|
|
|
if (keyValue.startsWith(key, caseSensitivity))
|
2012-06-01 14:44:44 +02:00
|
|
|
keywordsToSort.insert(keyValue);
|
|
|
|
|
else
|
|
|
|
|
keywords.insert(keyValue);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-01 14:44:44 +02:00
|
|
|
|
|
|
|
|
QStringList keywordsSorted = keywordsToSort.toList();
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(keywordsSorted);
|
2012-06-01 14:44:44 +02:00
|
|
|
return keywordsSorted + keywords.toList();
|
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();
|
2010-08-02 16:30:56 +02:00
|
|
|
foreach (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();
|
2010-08-02 16:30:56 +02:00
|
|
|
foreach (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
|
|
|
}
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
// -- private slots
|
|
|
|
|
|
|
|
|
|
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->setAutoSaveFilter(false);
|
|
|
|
|
d->m_helpEngine->setCurrentFilter(tr("Unfiltered"));
|
|
|
|
|
d->m_helpEngine->setupData();
|
2014-12-02 17:51:14 +01:00
|
|
|
|
|
|
|
|
foreach (const QString &filePath, d->documentationFromInstaller())
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- private
|
|
|
|
|
|
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();
|
2010-06-11 13:11:37 +02:00
|
|
|
foreach (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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-31 14:27:09 +01:00
|
|
|
QStringList HelpManagerPrivate::documentationFromInstaller()
|
|
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
QSettings *installSettings = ICore::settings();
|
2011-10-31 14:27:09 +01:00
|
|
|
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;
|
|
|
|
|
foreach (const QString &path, documentationPaths) {
|
|
|
|
|
QFileInfo pathInfo(path);
|
|
|
|
|
if (pathInfo.isFile() && pathInfo.isReadable()) {
|
|
|
|
|
documentationFiles << pathInfo.absoluteFilePath();
|
|
|
|
|
} else if (pathInfo.isDir()) {
|
|
|
|
|
QDir dir(path);
|
2011-12-22 14:44:14 +01:00
|
|
|
foreach (const QFileInfo &fileInfo, dir.entryInfoList(QStringList(QLatin1String("*.qch")),
|
2011-10-31 14:27:09 +01:00
|
|
|
QDir::Files | QDir::Readable)) {
|
|
|
|
|
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
|