Commit 8d118d3a authored by kh1's avatar kh1
Browse files

Add some more convinient functionality the help manager.

Add some more statics that can return the class instance,
implements a gui help engine and the bookmark manager for
easier sharing.
parent 42e01eaa
......@@ -28,44 +28,142 @@
**************************************************************************/
#include "helpmanager.h"
#include "helpplugin.h"
#include "bookmarkmanager.h"
#include <coreplugin/icore.h>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QMutexLocker>
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpEngineCore>
using namespace Help;
using namespace Help::Internal;
bool HelpManager::m_guiNeedsSetup = true;
bool HelpManager::m_needsCollectionFile = true;
QMutex HelpManager::m_guiMutex;
QHelpEngine* HelpManager::m_guiEngine = 0;
QMutex HelpManager::m_coreMutex;
QHelpEngineCore* HelpManager::m_coreEngine = 0;
HelpManager::HelpManager(HelpPlugin* plugin)
: m_plugin(plugin)
HelpManager* HelpManager::m_helpManager = 0;
BookmarkManager* HelpManager::m_bookmarkManager = 0;
HelpManager::HelpManager(QObject *parent)
: QObject(parent)
{
Q_ASSERT(!m_helpManager);
m_helpManager = this;
}
HelpManager::~HelpManager()
{
delete m_guiEngine;
m_guiEngine = 0;
delete m_coreEngine;
m_coreEngine = 0;
if (m_bookmarkManager) {
m_bookmarkManager->saveBookmarks();
delete m_bookmarkManager;
m_bookmarkManager = 0;
}
}
HelpManager& HelpManager::instance()
{
Q_ASSERT(m_helpManager);
return *m_helpManager;
}
void HelpManager::setupGuiHelpEngine()
{
if (m_needsCollectionFile) {
m_needsCollectionFile = false;
(&helpEngine())->setCollectionFile(collectionFilePath());
}
if (m_guiNeedsSetup) {
m_guiNeedsSetup = false;
(&helpEngine())->setupData();
}
}
bool HelpManager::guiEngineNeedsUpdate() const
{
return m_guiNeedsSetup;
}
void HelpManager::handleHelpRequest(const QString &url)
{
m_plugin->handleHelpRequest(url);
emit helpRequested(url);
}
void HelpManager::verifyDocumenation()
{
QStringList nameSpacesToUnregister;
QHelpEngineCore *engine = &helpEngineCore();
const QStringList &registeredDocs = engine->registeredDocumentations();
foreach (const QString &nameSpace, registeredDocs) {
const QString &file = engine->documentationFileName(nameSpace);
if (!QFileInfo(file).exists())
nameSpacesToUnregister.append(nameSpace);
}
if (!nameSpacesToUnregister.isEmpty())
unregisterDocumentation(nameSpacesToUnregister);
}
void HelpManager::registerDocumentation(const QStringList &files)
{
QHelpEngineCore *engine = &helpEngineCore();
foreach (const QString &file, files) {
const QString &nameSpace = engine->namespaceName(file);
if (nameSpace.isEmpty())
continue;
if (!engine->registeredDocumentations().contains(nameSpace)) {
if (engine->registerDocumentation(file)) {
m_guiNeedsSetup = true;
} else {
qWarning() << "Error registering namespace '" << nameSpace
<< "' from file '" << file << "':" << engine->error();
}
}
}
}
void HelpManager::unregisterDocumentation(const QStringList &nameSpaces)
{
QHelpEngineCore *engine = &helpEngineCore();
foreach (const QString &nameSpace, nameSpaces) {
const QString &file = engine->documentationFileName(nameSpace);
if (engine->unregisterDocumentation(nameSpace)) {
m_guiNeedsSetup = true;
} else {
qWarning() << "Error unregistering namespace '" << nameSpace
<< "' from file '" << file << "': " << engine->error();
}
}
}
void HelpManager::registerDocumentation(const QStringList &fileNames)
QHelpEngine &HelpManager::helpEngine()
{
if (m_plugin) {
m_plugin->setFilesToRegister(fileNames);
emit registerDocumentation();
if (!m_guiEngine) {
QMutexLocker _(&m_guiMutex);
if (!m_guiEngine) {
m_guiEngine = new QHelpEngine("");
m_guiEngine->setAutoSaveFilter(false);
}
}
return *m_guiEngine;
}
QString HelpManager::collectionFilePath()
......@@ -74,17 +172,19 @@ QString HelpManager::collectionFilePath()
const QDir directory(fi.absolutePath() + QLatin1String("/qtcreator"));
if (!directory.exists())
directory.mkpath(directory.absolutePath());
return directory.absolutePath() + QLatin1String("/helpcollection.qhc");
return QDir::cleanPath(directory.absolutePath() + QLatin1String("/helpcollection.qhc"));
}
QHelpEngineCore& HelpManager::helpEngineCore()
{
if (!m_coreEngine) {
m_coreEngine = new QHelpEngineCore(collectionFilePath());
m_coreEngine->setAutoSaveFilter(false);
m_coreEngine->setCurrentFilter(tr("Unfiltered"));
m_coreEngine->setupData();
QMutexLocker _(&m_coreMutex);
if (!m_coreEngine) {
m_coreEngine = new QHelpEngineCore(collectionFilePath());
m_coreEngine->setAutoSaveFilter(false);
m_coreEngine->setCurrentFilter(tr("Unfiltered"));
m_coreEngine->setupData();
}
}
return *m_coreEngine;
}
......@@ -31,37 +31,57 @@
#include "help_global.h"
#include <QtCore/QMutex>
#include <QtCore/QObject>
QT_FORWARD_DECLARE_CLASS(QHelpEngine)
QT_FORWARD_DECLARE_CLASS(QHelpEngineCore)
QT_FORWARD_DECLARE_CLASS(QString)
QT_FORWARD_DECLARE_CLASS(QStringList)
class BookmarkManager;
namespace Help {
namespace Internal {
class HelpPlugin;
} // Internal
class HELP_EXPORT HelpManager : public QObject
{
Q_OBJECT
public:
HelpManager(Internal::HelpPlugin *plugin);
HelpManager(QObject *parent = 0);
~HelpManager();
static HelpManager& instance();
void setupGuiHelpEngine();
bool guiEngineNeedsUpdate() const;
void handleHelpRequest(const QString &url);
void verifyDocumenation();
void registerDocumentation(const QStringList &fileNames);
void unregisterDocumentation(const QStringList &nameSpaces);
static QHelpEngine& helpEngine();
static QString collectionFilePath();
static QHelpEngineCore& helpEngineCore();
static BookmarkManager& bookmarkManager();
signals:
void registerDocumentation();
void helpRequested(const QString &Url);
private:
Internal::HelpPlugin *m_plugin;
static bool m_guiNeedsSetup;
static bool m_needsCollectionFile;
static QMutex m_guiMutex;
static QHelpEngine *m_guiEngine;
static QMutex m_coreMutex;
static QHelpEngineCore *m_coreEngine;
static QHelpEngineCore* m_coreEngine;
static HelpManager *m_helpManager;
static BookmarkManager *m_bookmarkManager;
};
} // Help
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment