2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-06-11 13:11:37 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 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
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/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
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** 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>
|
|
|
|
|
#include <utils/filesystemwatcher.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
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
QStringList m_filesToRegister;
|
|
|
|
|
QStringList m_nameSpacesToUnregister;
|
|
|
|
|
QHash<QString, QVariant> m_customValues;
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
{
|
2011-09-02 19:05:12 +02:00
|
|
|
Q_ASSERT(!m_instance);
|
|
|
|
|
m_instance = this;
|
2013-06-25 13:37:21 +02:00
|
|
|
d = new HelpManagerPrivate;
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpManager::~HelpManager()
|
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
2011-09-02 19:05:12 +02: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()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
return QDir::cleanPath(Core::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) {
|
|
|
|
|
d->m_filesToRegister.append(files);
|
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)
|
|
|
|
|
emit documentationChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::unregisterDocumentation(const QStringList &nameSpaces)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup) {
|
|
|
|
|
d->m_nameSpacesToUnregister.append(nameSpaces);
|
2010-06-11 13:11:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool docsChanged = false;
|
|
|
|
|
foreach (const QString &nameSpace, nameSpaces) {
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->unregisterDocumentation(nameSpace)) {
|
2010-06-11 13:11:37 +02:00
|
|
|
docsChanged = true;
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Error unregistering namespace '" << nameSpace
|
2010-09-16 12:26:28 +02:00
|
|
|
<< "' from file '" << d->m_helpEngine->documentationFileName(nameSpace)
|
|
|
|
|
<< "': " << d->m_helpEngine->error();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (docsChanged)
|
|
|
|
|
emit documentationChanged();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
QMap<QString, QUrl> HelpManager::linksForKeyword(const QString &key) const
|
|
|
|
|
{
|
|
|
|
|
QMap<QString, QUrl> links;
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-06-11 13:11:37 +02:00
|
|
|
return links;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id) const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-06-11 13:11:37 +02:00
|
|
|
return QMap<QString, QUrl>();
|
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
|
|
|
|
|
QStringList HelpManager::findKeywords(const QString &key, int maxHits) const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2012-06-01 14:44:44 +02:00
|
|
|
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()) {
|
2012-06-01 14:44:44 +02:00
|
|
|
if (keyValue.startsWith(key, Qt::CaseInsensitive))
|
|
|
|
|
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();
|
|
|
|
|
qSort(keywordsSorted.begin(), keywordsSorted.end());
|
|
|
|
|
return keywordsSorted + keywords.toList();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QUrl HelpManager::findFile(const QUrl &url) const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-06-11 13:11:37 +02:00
|
|
|
return QUrl();
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->findFile(url);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 13:24:45 +02:00
|
|
|
QByteArray HelpManager::fileData(const QUrl &url) const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-07-12 13:24:45 +02:00
|
|
|
return QByteArray();
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->fileData(url);
|
2010-07-12 13:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
void HelpManager::handleHelpRequest(const QString &url)
|
|
|
|
|
{
|
|
|
|
|
emit helpRequested(QUrl(url));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList HelpManager::registeredNamespaces() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-06-11 13:11:37 +02:00
|
|
|
return QStringList();
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->registeredDocumentations();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString HelpManager::namespaceFromFile(const QString &file) const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-06-11 13:11:37 +02:00
|
|
|
return QString();
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_helpEngine->namespaceName(file);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString HelpManager::fileFromNamespace(const QString &nameSpace) const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-06-11 13:11:37 +02:00
|
|
|
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))
|
2010-08-02 16:30:56 +02:00
|
|
|
emit collectionFileChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant HelpManager::customValue(const QString &key, const QVariant &value) const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-08-02 16:30:56 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpManager::Filters HelpManager::filters() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-08-02 16:30:56 +02:00
|
|
|
return Filters();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpManager::Filters HelpManager::fixedFilters() const
|
|
|
|
|
{
|
|
|
|
|
Filters fixedFilters;
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-08-02 16:30:56 +02:00
|
|
|
return fixedFilters;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelpManager::Filters HelpManager::userDefinedFilters() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-08-02 16:30:56 +02:00
|
|
|
return Filters();
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-08-02 16:30:56 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->removeCustomFilter(filter))
|
2010-08-02 16:30:56 +02:00
|
|
|
emit collectionFileChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpManager::addUserDefinedFilter(const QString &filter, const QStringList &attr)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_needsSetup)
|
2010-08-02 16:30:56 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_helpEngine->addCustomFilter(filter, attr))
|
2010-08-02 16:30:56 +02:00
|
|
|
emit collectionFileChanged();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_helpEngine = new QHelpEngineCore(collectionFilePath(), this);
|
|
|
|
|
d->m_helpEngine->setAutoSaveFilter(false);
|
|
|
|
|
d->m_helpEngine->setCurrentFilter(tr("Unfiltered"));
|
|
|
|
|
d->m_helpEngine->setupData();
|
2010-06-11 13:11:37 +02:00
|
|
|
verifyDocumenation();
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_nameSpacesToUnregister.isEmpty()) {
|
|
|
|
|
unregisterDocumentation(d->m_nameSpacesToUnregister);
|
|
|
|
|
d->m_nameSpacesToUnregister.clear();
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-31 14:27:09 +01:00
|
|
|
d->m_filesToRegister << d->documentationFromInstaller();
|
2010-06-11 13:11:37 +02:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_filesToRegister.isEmpty()) {
|
|
|
|
|
registerDocumentation(d->m_filesToRegister);
|
|
|
|
|
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());
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
emit setupFinished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- private
|
|
|
|
|
|
|
|
|
|
void HelpManager::verifyDocumenation()
|
|
|
|
|
{
|
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
|
|
|
if (!QFileInfo(d->m_helpEngine->documentationFileName(nameSpace)).exists())
|
|
|
|
|
d->m_nameSpacesToUnregister.append(nameSpace);
|
2010-06-11 13:11:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-31 14:27:09 +01:00
|
|
|
QStringList HelpManagerPrivate::documentationFromInstaller()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *installSettings = Core::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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
} // Core
|