aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/helpmanager.cpp
blob: 465f86f82886db4cad75fe8da3e73a3efc47c437 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "helpmanager_implementation.h"

#include "coreplugin.h"

#include <extensionsystem/pluginspec.h>
#include <utils/qtcassert.h>

#include <QCoreApplication>
#include <QDir>
#include <QUrl>

namespace Core {
namespace HelpManager {

// makes sure that plugins can connect to HelpManager signals even if the Help plugin is not loaded
Q_GLOBAL_STATIC(Signals, m_signals)

static Implementation *m_instance = nullptr;

static bool checkInstance()
{
    auto plugin = Internal::CorePlugin::instance();
    // HelpManager API can only be used after the actual implementation has been created by the
    // Help plugin, so check that the plugins have all been created. That is the case
    // when the Core plugin is initialized.
    QTC_CHECK(plugin && plugin->pluginSpec()
              && plugin->pluginSpec()->state() >= ExtensionSystem::PluginSpec::Initialized);
    return m_instance != nullptr;
}

Signals *Signals::instance()
{
    return m_signals;
}

Implementation::Implementation()
{
    QTC_CHECK(!m_instance);
    m_instance = this;
}

Implementation::~Implementation()
{
    m_instance = nullptr;
}

QString documentationPath()
{
    return QDir::cleanPath(QCoreApplication::applicationDirPath() + '/' + RELATIVE_DOC_PATH);
}

void registerDocumentation(const QStringList &files)
{
    if (checkInstance())
        m_instance->registerDocumentation(files);
}

void unregisterDocumentation(const QStringList &fileNames)
{
    if (checkInstance())
        m_instance->unregisterDocumentation(fileNames);
}

QMultiMap<QString, QUrl> linksForIdentifier(const QString &id)
{
    return checkInstance() ? m_instance->linksForIdentifier(id) : QMultiMap<QString, QUrl>();
}

QMultiMap<QString, QUrl> linksForKeyword(const QString &keyword)
{
    return checkInstance() ? m_instance->linksForKeyword(keyword) : QMultiMap<QString, QUrl>();
}

QByteArray fileData(const QUrl &url)
{
    return checkInstance() ? m_instance->fileData(url) : QByteArray();
}

void showHelpUrl(const QUrl &url, HelpManager::HelpViewerLocation location)
{
    if (checkInstance())
        m_instance->showHelpUrl(url, location);
}

void showHelpUrl(const QString &url, HelpViewerLocation location)
{
    showHelpUrl(QUrl(url), location);
}

} // HelpManager
} // Core