helpplugin.cpp 36.8 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
con's avatar
con committed
29
#include "helpplugin.h"
30 31 32 33

#include "bookmarkmanager.h"
#include "centralwidget.h"
#include "contentwindow.h"
con's avatar
con committed
34 35
#include "docsettingspage.h"
#include "filtersettingspage.h"
36 37
#include "generalsettingspage.h"
#include "helpfindsupport.h"
con's avatar
con committed
38
#include "helpindexfilter.h"
kh1's avatar
kh1 committed
39
#include "helpmanager.h"
con's avatar
con committed
40 41 42 43 44
#include "helpmode.h"
#include "helpviewer.h"
#include "indexwindow.h"
#include "searchwidget.h"

45
#include <coreplugin/actionmanager/actionmanager.h>
46 47
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
48
#include <coreplugin/editormanager/ieditor.h>
49 50
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icore.h>
hjk's avatar
hjk committed
51 52
#include <coreplugin/minisplitter.h>
#include <coreplugin/modemanager.h>
53
#include <coreplugin/progressmanager/progressmanager.h>
hjk's avatar
hjk committed
54 55
#include <coreplugin/rightpane.h>
#include <coreplugin/sidebar.h>
56
#include <coreplugin/uniqueidmanager.h>
kh1's avatar
kh1 committed
57
#include <extensionsystem/pluginmanager.h>
58
#include <texteditor/texteditorconstants.h>
59
#include <utils/styledbar.h>
kh1's avatar
kh1 committed
60
#include <welcome/welcomemode.h>
61

con's avatar
con committed
62
#include <QtCore/QDir>
kh1's avatar
kh1 committed
63
#include <QtCore/QFileInfo>
64
#include <QtCore/QFuture>
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
65 66
#include <QtCore/QLibraryInfo>
#include <QtCore/QTranslator>
kh1's avatar
kh1 committed
67 68
#include <QtCore/qplugin.h>

con's avatar
con committed
69
#include <QtGui/QAction>
kh1's avatar
kh1 committed
70 71 72
#include <QtGui/QComboBox>
#include <QtGui/QMessageBox>
#include <QtGui/QDesktopServices>
con's avatar
con committed
73 74 75
#include <QtGui/QShortcut>
#include <QtGui/QSplitter>
#include <QtGui/QToolBar>
kh1's avatar
kh1 committed
76

con's avatar
con committed
77
#include <QtHelp/QHelpEngine>
78
#include <QtHelp/QHelpSearchEngine>
con's avatar
con committed
79

kh1's avatar
kh1 committed
80 81
#if defined(QT_NO_WEBKIT)
#   include <QtGui/QApplication>
kh's avatar
kh committed
82
#else
kh1's avatar
kh1 committed
83
#   include <QtWebKit/QWebSettings>
84 85
#endif

con's avatar
con committed
86 87 88
using namespace Help;
using namespace Help::Internal;

89 90 91
#if defined(Q_OS_MAC)
#   define DOCPATH "/../Resources/doc/"
#else
Tobias Hunger's avatar
Tobias Hunger committed
92
#   define DOCPATH "/../share/doc/qtcreator/"
93 94
#endif

kh1's avatar
kh1 committed
95 96
HelpPlugin::HelpPlugin()
    : m_core(0),
con's avatar
con committed
97 98 99 100 101 102 103 104 105 106
    m_helpEngine(0),
    m_contentWidget(0),
    m_indexWidget(0),
    m_centralWidget(0),
    m_helpViewerForSideBar(0),
    m_mode(0),
    m_contentItem(0),
    m_indexItem(0),
    m_searchItem(0),
    m_bookmarkItem(0),
107 108 109
    m_progress(0),
    isInitialised(false),
    firstModeChange(true)
con's avatar
con committed
110 111 112 113 114 115 116
{
}

HelpPlugin::~HelpPlugin()
{
}

117
bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
118
{
119 120
    Q_UNUSED(arguments)
    Q_UNUSED(error)
121
    m_core = Core::ICore::instance();
con's avatar
con committed
122 123 124 125 126
    QList<int> globalcontext;
    globalcontext << Core::Constants::C_GLOBAL_ID;
    QList<int> modecontext;
    modecontext << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_MODE_HELP);

127
    const QString &locale = qApp->property("qtc_locale").toString();
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
128 129
    if (!locale.isEmpty()) {
        QTranslator *qtr = new QTranslator(this);
130
        QTranslator *qhelptr = new QTranslator(this);
131 132
        const QString &creatorTrPath = Core::ICore::instance()->resourcePath()
            + QLatin1String("/translations");
133 134 135 136 137 138 139
        const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
        const QString &trFile = QLatin1String("assistant_") + locale;
        const QString &helpTrFile = QLatin1String("qt_help_") + locale;
        if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
            qApp->installTranslator(qtr);
        if (qhelptr->load(helpTrFile, qtTrPath) || qhelptr->load(helpTrFile, creatorTrPath))
            qApp->installTranslator(qhelptr);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
140 141
    }

142 143 144 145 146 147 148
#ifndef QT_NO_WEBKIT
    QWebSettings *webSettings = QWebSettings::globalSettings();
    const QFont applicationFont = QApplication::font();
    webSettings->setFontFamily(QWebSettings::StandardFont, applicationFont.family());
    //webSettings->setFontSize(QWebSettings::DefaultFontSize, applicationFont.pointSize());
#endif

con's avatar
con committed
149
    // FIXME shouldn't the help engine create the directory if it doesn't exist?
kh1's avatar
kh1 committed
150
    const QFileInfo &fi(m_core->settings()->fileName());
151
    const QDir directory(fi.absolutePath() + QLatin1String("/qtcreator"));
con's avatar
con committed
152 153
    if (!directory.exists())
        directory.mkpath(directory.absolutePath());
kh's avatar
kh committed
154 155
    m_helpEngine = new QHelpEngine(directory.absolutePath() +
        QLatin1String("/helpcollection.qhc"), this);
156
    m_helpEngine->setAutoSaveFilter(false);
con's avatar
con committed
157

158 159
    helpManager = new HelpManager(this);
    addAutoReleasedObject(helpManager);
con's avatar
con committed
160

161 162 163
    m_filterSettingsPage = new FilterSettingsPage(m_helpEngine);
    addAutoReleasedObject(m_filterSettingsPage);

con's avatar
con committed
164 165 166 167 168
    m_docSettingsPage = new DocSettingsPage(m_helpEngine);
    addAutoReleasedObject(m_docSettingsPage);

    connect(m_docSettingsPage, SIGNAL(documentationAdded()),
        m_filterSettingsPage, SLOT(updateFilterPage()));
kh's avatar
kh committed
169 170
    connect(m_docSettingsPage, SIGNAL(dialogAccepted()), this,
        SLOT(checkForHelpChanges()));
con's avatar
con committed
171 172 173 174 175 176 177 178 179 180

    m_contentWidget = new ContentWindow(m_helpEngine);
    m_contentWidget->setWindowTitle(tr("Contents"));
    m_indexWidget = new IndexWindow(m_helpEngine);
    m_indexWidget->setWindowTitle(tr("Index"));
    m_searchWidget = new SearchWidget(m_helpEngine->searchEngine());
    m_searchWidget->setWindowTitle(tr("Search"));
    m_bookmarkManager = new BookmarkManager(m_helpEngine);
    m_bookmarkWidget = new BookmarkWidget(m_bookmarkManager, 0, false);
    m_bookmarkWidget->setWindowTitle(tr("Bookmarks"));
kh's avatar
kh committed
181
    connect(m_bookmarkWidget, SIGNAL(addBookmark()), this, SLOT(addBookmark()));
con's avatar
con committed
182

183
    Core::ActionManager *am = m_core->actionManager();
con's avatar
con committed
184
    Core::Command *cmd;
con's avatar
con committed
185 186

    // Add Home, Previous and Next actions (used in the toolbar)
kh's avatar
kh committed
187 188 189
    QAction *homeAction =
        new QAction(QIcon(QLatin1String(":/help/images/home.png")), tr("Home"),
        this);
con's avatar
con committed
190 191
    cmd = am->registerAction(homeAction, QLatin1String("Help.Home"), globalcontext);

kh's avatar
kh committed
192 193
    QAction *previousAction =
        new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
194
        tr("Previous Page"), this);
kh's avatar
kh committed
195 196
    cmd = am->registerAction(previousAction, QLatin1String("Help.Previous"),
        modecontext);
197
    cmd->setDefaultKeySequence(QKeySequence::Back);
con's avatar
con committed
198

kh's avatar
kh committed
199
    QAction *nextAction =
200
        new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next Page"),
kh's avatar
kh committed
201
        this);
con's avatar
con committed
202
    cmd = am->registerAction(nextAction, QLatin1String("Help.Next"), modecontext);
203
    cmd->setDefaultKeySequence(QKeySequence::Forward);
con's avatar
con committed
204

kh's avatar
kh committed
205 206
    QAction *addBookmarkAction =
        new QAction(QIcon(QLatin1String(":/help/images/bookmark.png")),
con's avatar
con committed
207
        tr("Add Bookmark"), this);
kh's avatar
kh committed
208 209
    cmd = am->registerAction(addBookmarkAction, QLatin1String("Help.AddBookmark"),
        modecontext);
con's avatar
con committed
210 211 212 213
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_M));

    // Add Index, Contents, and Context menu items and a separator to the Help menu
    QAction *indexAction = new QAction(tr("Index"), this);
kh's avatar
kh committed
214 215 216 217
    cmd = am->registerAction(indexAction, QLatin1String("Help.Index"),
        globalcontext);
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
        Core::Constants::G_HELP_HELP);
con's avatar
con committed
218 219

    QAction *contentsAction = new QAction(tr("Contents"), this);
kh's avatar
kh committed
220 221 222 223
    cmd = am->registerAction(contentsAction, QLatin1String("Help.Contents"),
        globalcontext);
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
        Core::Constants::G_HELP_HELP);
con's avatar
con committed
224 225

    QAction *searchAction = new QAction(tr("Search"), this);
kh's avatar
kh committed
226 227 228 229
    cmd = am->registerAction(searchAction, QLatin1String("Help.Search"),
        globalcontext);
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
        Core::Constants::G_HELP_HELP);
con's avatar
con committed
230 231

    QAction *contextAction = new QAction(tr("Context Help"), this);
kh's avatar
kh committed
232 233
    cmd = am->registerAction(contextAction, QLatin1String("Help.Context"),
        globalcontext);
con's avatar
con committed
234
    cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1));
kh's avatar
kh committed
235 236
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
        Core::Constants::G_HELP_HELP);
con's avatar
con committed
237

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
238
#ifndef Q_WS_MAC
con's avatar
con committed
239 240 241
    QAction *sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("Help.Separator"), globalcontext);
kh's avatar
kh committed
242 243
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
        Core::Constants::G_HELP_HELP);
con's avatar
con committed
244 245
#endif

Friedemann Kleint's avatar
Friedemann Kleint committed
246
    m_centralWidget = new Help::Internal::CentralWidget(m_helpEngine);
con's avatar
con committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
    Aggregation::Aggregate *agg = new Aggregation::Aggregate;
    agg->add(m_centralWidget);
    agg->add(new HelpFindSupport(m_centralWidget));
    QWidget *mainWidget = new QWidget;
    QVBoxLayout *mainWidgetLayout = new QVBoxLayout(mainWidget);
    mainWidgetLayout->setMargin(0);
    mainWidgetLayout->setSpacing(0);
    mainWidgetLayout->addWidget(createToolBar());
    mainWidgetLayout->addWidget(m_centralWidget);

    m_contentItem = new Core::SideBarItem(m_contentWidget);
    m_indexItem = new Core::SideBarItem(m_indexWidget);
    m_searchItem = new Core::SideBarItem(m_searchWidget);
    m_bookmarkItem = new Core::SideBarItem(m_bookmarkWidget);
    QList<Core::SideBarItem*> itemList;
    itemList << m_contentItem << m_indexItem << m_searchItem << m_bookmarkItem;
    m_sideBar = new Core::SideBar(itemList, QList<Core::SideBarItem*>() << m_indexItem);

    QSplitter *splitter = new Core::MiniSplitter;
    splitter->setOpaqueResize(false);
    splitter->addWidget(m_sideBar);
    splitter->addWidget(mainWidget);
    splitter->setStretchFactor(0, 0);
    splitter->setStretchFactor(1, 1);
    splitter->setSizes(QList<int>() << 300 << 300);

    m_mode = new HelpMode(splitter, m_centralWidget);
    m_mode->setContext(QList<int>() << modecontext);
    addAutoReleasedObject(m_mode);

    QAction *printAction = new QAction(this);
    am->registerAction(printAction, Core::Constants::PRINT, modecontext);
    connect(printAction, SIGNAL(triggered()), m_centralWidget, SLOT(print()));

    QAction *copyAction = new QAction(this);
    cmd = am->registerAction(copyAction, Core::Constants::COPY, modecontext);
    connect(copyAction, SIGNAL(triggered()), m_centralWidget, SLOT(copy()));
    copyAction->setText(cmd->action()->text());
    copyAction->setIcon(cmd->action()->icon());

con's avatar
con committed
287
    QMap<QString, Core::Command*> shortcutMap;
con's avatar
con committed
288 289
    QShortcut *shortcut = new QShortcut(splitter);
    shortcut->setWhatsThis(tr("Activate Index in Help mode"));
kh's avatar
kh committed
290 291
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.IndexShortcut"),
        modecontext);
con's avatar
con committed
292 293 294 295 296 297
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_I));
    connect(shortcut, SIGNAL(activated()), this, SLOT(activateIndex()));
    shortcutMap.insert(m_indexWidget->windowTitle(), cmd);

    shortcut = new QShortcut(splitter);
    shortcut->setWhatsThis(tr("Activate Contents in Help mode"));
kh's avatar
kh committed
298 299
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.ContentsShortcut"),
        modecontext);
con's avatar
con committed
300 301 302 303 304 305
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_T));
    connect(shortcut, SIGNAL(activated()), this, SLOT(activateContents()));
    shortcutMap.insert(m_contentWidget->windowTitle(), cmd);

    shortcut = new QShortcut(splitter);
    shortcut->setWhatsThis(tr("Activate Search in Help mode"));
kh's avatar
kh committed
306 307
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.SearchShortcut"),
        modecontext);
con's avatar
con committed
308 309 310 311 312 313 314 315 316 317 318
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_S));
    connect(shortcut, SIGNAL(activated()), this, SLOT(activateSearch()));
    shortcutMap.insert(m_searchWidget->windowTitle(), cmd);
    shortcutMap.insert(m_bookmarkWidget->windowTitle(), 0);

    m_sideBar->setShortcutMap(shortcutMap);

    connect(homeAction, SIGNAL(triggered()), m_centralWidget, SLOT(home()));
    connect(previousAction, SIGNAL(triggered()), m_centralWidget, SLOT(backward()));
    connect(nextAction, SIGNAL(triggered()), m_centralWidget, SLOT(forward()));
    connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(addBookmark()));
kh's avatar
kh committed
319 320 321 322 323 324 325 326 327 328
    connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
        SLOT(setSource(QUrl)));
    connect(m_indexWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
        SLOT(setSource(QUrl)));
    connect(m_searchWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
        SLOT(setSource(QUrl)));
    connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)),
        m_centralWidget, SLOT(setSourceInNewTab(QUrl)));
    connect(m_bookmarkWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
        SLOT(setSource(const QUrl&)));
con's avatar
con committed
329 330 331 332 333

    connect(m_centralWidget, SIGNAL(backwardAvailable(bool)),
        previousAction, SLOT(setEnabled(bool)));
    connect(m_centralWidget, SIGNAL(forwardAvailable(bool)),
        nextAction, SLOT(setEnabled(bool)));
kh's avatar
kh committed
334 335
    connect(m_centralWidget, SIGNAL(addNewBookmark(QString, QString)), this,
        SLOT(addNewBookmark(QString, QString)));
con's avatar
con committed
336 337 338 339 340

    QList<QAction*> actionList;
    actionList << previousAction
        << nextAction
        << homeAction
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
341
#ifndef Q_WS_MAC
con's avatar
con committed
342 343 344 345 346 347 348 349 350 351 352 353 354
        << sep
#endif
        << copyAction;
    m_centralWidget->setGlobalActions(actionList);

    connect(contextAction, SIGNAL(triggered()), this, SLOT(activateContext()));
    connect(indexAction, SIGNAL(triggered()), this, SLOT(activateIndex()));
    connect(contentsAction, SIGNAL(triggered()), this, SLOT(activateContents()));
    connect(searchAction, SIGNAL(triggered()), this, SLOT(activateSearch()));

    connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)),
        this, SLOT(modeChanged(Core::IMode*)));

kh's avatar
kh committed
355 356 357 358 359 360
    connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
        SLOT(setSource(QUrl)));
    connect(m_indexWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
        SLOT(setSource(QUrl)));
    connect(m_indexWidget, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)),
        m_centralWidget, SLOT(showTopicChooser(QMap<QString, QUrl>, QString)));
con's avatar
con committed
361 362 363

    HelpIndexFilter *helpIndexFilter = new HelpIndexFilter(this, m_helpEngine);
    addAutoReleasedObject(helpIndexFilter);
kh's avatar
kh committed
364 365 366 367
    connect(helpIndexFilter, SIGNAL(linkActivated(QUrl)), this,
        SLOT(switchToHelpMode(QUrl)));
    connect(helpIndexFilter, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)),
        this, SLOT(switchToHelpMode(QMap<QString, QUrl>, QString)));
con's avatar
con committed
368 369 370 371

    previousAction->setEnabled(m_centralWidget->isBackwardAvailable());
    nextAction->setEnabled(m_centralWidget->isForwardAvailable());

372
    QDesktopServices::setUrlHandler("qthelp", this, "handleHelpRequest");
373

374 375 376 377 378 379 380 381 382
    if (Core::ActionContainer *advancedMenu =
        am->actionContainer(Core::Constants::M_EDIT_ADVANCED)) {
        // reuse TextEditor constants to avoid a second pair of menu actions
        QAction *a = new QAction(tr("Increase Font Size"), this);
        cmd = am->registerAction(a, TextEditor::Constants::INCREASE_FONT_SIZE,
            modecontext);
        cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl++")));
        connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomIn()));
        advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
383

384 385 386 387 388 389
        a = new QAction(tr("Decrease Font Size"), this);
        cmd = am->registerAction(a, TextEditor::Constants::DECREASE_FONT_SIZE,
            modecontext);
        cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-")));
        connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomOut()));
        advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
390 391

        a = new QAction(tr("Reset Font Size"), this);
mae's avatar
mae committed
392
        cmd = am->registerAction(a,  TextEditor::Constants::RESET_FONT_SIZE,
393 394 395 396
            modecontext);
        cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+0")));
        connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(resetZoom()));
        advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
397 398
    }

399 400 401 402 403
    generalSettingsPage = new GeneralSettingsPage(m_bookmarkManager);
    addAutoReleasedObject(generalSettingsPage);
    connect(generalSettingsPage, SIGNAL(fontChanged()), this, SLOT(fontChanged()));
    connect(generalSettingsPage, SIGNAL(dialogAccepted()), this,
        SLOT(checkForGeneralChanges()));
con's avatar
con committed
404 405 406
    return true;
}

407 408 409 410 411
QHelpEngine* HelpPlugin::helpEngine() const
{
    return m_helpEngine;
}

412 413 414 415 416 417 418
void HelpPlugin::setFilesToRegister(const QStringList &files)
{
    filesToRegister += files;
}

void HelpPlugin::pluginUpdateDocumentation()
{
419 420
    if (isInitialised)
        updateDocumentation();
421 422
}

kh1's avatar
kh1 committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
void HelpPlugin::resetFilter()
{
    const QLatin1String weAddedFilterKey("UnfilteredFilterInserted");
    const QLatin1String previousFilterNameKey("UnfilteredFilterName");
    if (m_helpEngine->customValue(weAddedFilterKey).toInt() == 1) {
        // we added a filter at some point, remove previously added filter
        const QString &previousFilter =
            m_helpEngine->customValue(previousFilterNameKey).toString();
        if (!previousFilter.isEmpty())
            m_helpEngine->removeCustomFilter(previousFilter);
    }

    // potentially remove a filter with new name
    const QString filterName = tr("Unfiltered");
    m_helpEngine->removeCustomFilter(filterName);
    m_helpEngine->addCustomFilter(filterName, QStringList());
    m_helpEngine->setCustomValue(weAddedFilterKey, 1);
    m_helpEngine->setCustomValue(previousFilterNameKey, filterName);
    m_helpEngine->setCurrentFilter(filterName);
}

444 445 446
bool HelpPlugin::updateDocumentation()
{
    bool needsSetup = false;
447 448 449 450 451 452 453 454 455 456 457 458 459 460
    const QStringList &registeredDocs = m_helpEngine->registeredDocumentations();
    foreach (const QString &nameSpace, registeredDocs) {
        const QString &file = m_helpEngine->documentationFileName(nameSpace);
        if (QFileInfo(file).exists())
            continue;

        if (!m_helpEngine->unregisterDocumentation(nameSpace)) {
            qWarning() << "Error unregistering namespace '"
                << nameSpace << "' from file '" << file << "': "
                << m_helpEngine->error();
        } else {
            needsSetup = true;
        }
    }
461

462 463 464 465 466 467 468 469 470
    foreach (const QString &file, filesToRegister) {
        const QString &nameSpace = m_helpEngine->namespaceName(file);
        if (nameSpace.isEmpty())
            continue;
        if (!m_helpEngine->registeredDocumentations().contains(nameSpace)) {
            if (m_helpEngine->registerDocumentation(file)) {
                needsSetup = true;
            } else {
                qWarning() << "error registering" << file << m_helpEngine->error();
471 472 473
            }
        }
    }
474 475
    filesToRegister.clear();

476 477 478 479 480
    if (needsSetup)
        m_helpEngine->setupData();
    return needsSetup;
}

con's avatar
con committed
481 482
void HelpPlugin::createRightPaneSideBar()
{
483 484
    if (m_helpViewerForSideBar)
        return;
con's avatar
con committed
485

486 487
    QAction *switchToHelp = new QAction(tr("Go to Help Mode"), this);
    connect(switchToHelp, SIGNAL(triggered()), this, SLOT(switchToHelpMode()));
con's avatar
con committed
488

489 490 491
    QAction *next = new QAction(QIcon(QLatin1String(":/help/images/next.png")),
        tr("Next"), this);
    connect(next, SIGNAL(triggered()), this, SLOT(rightPaneForward()));
con's avatar
con committed
492

493 494 495
    QAction *previous = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
        tr("Previous"), this);
    connect(previous, SIGNAL(triggered()), this, SLOT(rightPaneBackward()));
con's avatar
con committed
496 497 498 499 500

    // Dummy layout to align the close button to the right
    QHBoxLayout *hboxLayout = new QHBoxLayout();
    hboxLayout->setSpacing(0);
    hboxLayout->setMargin(0);
501 502 503 504 505 506 507

    // left side actions
    QToolBar *rightPaneToolBar = new QToolBar();
    rightPaneToolBar->addAction(switchToHelp);
    rightPaneToolBar->addAction(previous);
    rightPaneToolBar->addAction(next);

508
    hboxLayout->addWidget(rightPaneToolBar);
509 510 511 512
    hboxLayout->addStretch();

    QToolButton *closeButton = new QToolButton();
    closeButton->setIcon(QIcon(":/core/images/closebutton.png"));
con's avatar
con committed
513 514
    connect(closeButton, SIGNAL(clicked()), this, SLOT(slotHideRightPane()));

515 516 517
    // close button to the right
    hboxLayout->addWidget(closeButton);

con's avatar
con committed
518 519 520 521
    QVBoxLayout *rightPaneLayout = new QVBoxLayout;
    rightPaneLayout->setMargin(0);
    rightPaneLayout->setSpacing(0);

522 523 524 525 526 527 528 529 530 531 532 533 534
    QWidget *rightPaneSideBar = new QWidget;
    rightPaneSideBar->setLayout(rightPaneLayout);
    addAutoReleasedObject(new Core::BaseRightPaneWidget(rightPaneSideBar));

    Utils::StyledBar *rightPaneStyledBar = new Utils::StyledBar;
    rightPaneStyledBar->setLayout(hboxLayout);
    rightPaneLayout->addWidget(rightPaneStyledBar);

    m_helpViewerForSideBar = new HelpViewer(m_helpEngine, 0, rightPaneSideBar);
    rightPaneLayout->addWidget(m_helpViewerForSideBar);
    rightPaneLayout->addWidget(new Core::FindToolBarPlaceHolder(rightPaneSideBar));
    rightPaneSideBar->setFocusProxy(m_helpViewerForSideBar);

con's avatar
con committed
535 536 537
    Aggregation::Aggregate *agg = new Aggregation::Aggregate();
    agg->add(m_helpViewerForSideBar);
    agg->add(new HelpViewerFindSupport(m_helpViewerForSideBar));
538 539 540
    m_core->addContextObject(new Core::BaseContext(m_helpViewerForSideBar, QList<int>()
        << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_HELP_SIDEBAR), this));

541 542 543 544 545 546
#if defined(QT_NO_WEBKIT)
    QFont font = m_helpViewerForSideBar->font();
    font = qVariantValue<QFont>(m_helpEngine->customValue(QLatin1String("font"),
        font));
    m_helpViewerForSideBar->setFont(font);
#endif
547

548 549 550 551 552 553 554
    QAction *copyActionSideBar = new QAction(this);
    Core::Command *cmd = m_core->actionManager()->registerAction(copyActionSideBar,
        Core::Constants::COPY, QList<int>()
        << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_HELP_SIDEBAR));
    connect(copyActionSideBar, SIGNAL(triggered()), this, SLOT(copyFromSideBar()));
    copyActionSideBar->setText(cmd->action()->text());
    copyActionSideBar->setIcon(cmd->action()->icon());
555 556 557 558 559

    connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this,
        SLOT(updateSideBarSource(QUrl)));
    connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this,
        SLOT(updateSideBarSource()));
con's avatar
con committed
560 561
}

562 563 564 565 566
void HelpPlugin::copyFromSideBar()
{
    m_helpViewerForSideBar->copy();
}

con's avatar
con committed
567 568 569 570 571 572 573 574 575 576
void HelpPlugin::rightPaneBackward()
{
    m_helpViewerForSideBar->backward();
}

void HelpPlugin::rightPaneForward()
{
    m_helpViewerForSideBar->forward();
}

hjk's avatar
hjk committed
577 578 579 580 581
void HelpPlugin::activateHelpMode()
{
    m_core->modeManager()->activateMode(QLatin1String(Constants::ID_MODE_HELP));
}

con's avatar
con committed
582 583 584 585 586 587 588
void HelpPlugin::switchToHelpMode()
{
    switchToHelpMode(m_helpViewerForSideBar->source());
}

void HelpPlugin::switchToHelpMode(const QUrl &source)
{
hjk's avatar
hjk committed
589
    activateHelpMode();
con's avatar
con committed
590 591 592 593
    m_centralWidget->setSource(source);
    m_centralWidget->setFocus();
}

kh's avatar
kh committed
594 595
void HelpPlugin::switchToHelpMode(const QMap<QString, QUrl> &urls,
    const QString &keyword)
con's avatar
con committed
596
{
hjk's avatar
hjk committed
597
    activateHelpMode();
con's avatar
con committed
598 599 600 601 602 603 604 605 606 607
    m_centralWidget->showTopicChooser(urls, keyword);
}

void HelpPlugin::slotHideRightPane()
{
    Core::RightPaneWidget::instance()->setShown(false);
}

void HelpPlugin::extensionsInitialized()
{
608
    m_sideBar->readSettings(m_core->settings(), QLatin1String("HelpSideBar"));
609 610 611

    // force a block here to avoid the expensive indexing restart signal, etc...
    bool blocked = m_helpEngine->blockSignals(true);
con's avatar
con committed
612
    if (!m_helpEngine->setupData()) {
613
        m_helpEngine->blockSignals(blocked);
con's avatar
con committed
614 615 616 617
        qWarning() << "Could not initialize help engine: " << m_helpEngine->error();
        return;
    }

618
    const QString &docInternal = QString::fromLatin1("com.nokia.qtcreator.%1%2%3")
con's avatar
con committed
619
        .arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR).arg(IDE_VERSION_RELEASE);
620 621

    bool assistantInternalDocRegistered = false;
kh's avatar
kh committed
622 623 624
    const QStringList &docs = m_helpEngine->registeredDocumentations();
    foreach (const QString &ns, docs) {
        if (ns == docInternal) {
con's avatar
con committed
625
            assistantInternalDocRegistered = true;
626
        } else if (ns.startsWith(QLatin1String("com.nokia.qtcreator."))) {
627
            m_helpEngine->unregisterDocumentation(ns);
con's avatar
con committed
628 629
        }
    }
con's avatar
con committed
630

631 632
    const QString &filterInternal = QString::fromLatin1("Qt Creator %1.%2.%3")
        .arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR).arg(IDE_VERSION_RELEASE);
con's avatar
con committed
633

634 635 636 637 638 639 640
    const QRegExp filterRegExp(QLatin1String("Qt Creator \\d*\\.\\d*\\.\\d*"));
    const QStringList &filters = m_helpEngine->customFilters();
    foreach (const QString &filter, filters) {
        if (filterRegExp.exactMatch(filter) && filter != filterInternal)
            m_helpEngine->removeCustomFilter(filter);
    }

641

642
    m_helpEngine->blockSignals(blocked);
con's avatar
con committed
643

644 645
    connect(m_helpEngine, SIGNAL(setupFinished()), this,
        SLOT(updateFilterComboBox()));
646 647 648 649 650

    // explicit disconnect the full text search indexer, we connect and start
    // it later once we really need it, e.g. the full text search is opened...
    disconnect(m_helpEngine, SIGNAL(setupFinished()), m_helpEngine->searchEngine(),
        SLOT(indexDocumentation()));
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
    connect(m_helpEngine->searchEngine(), SIGNAL(indexingStarted()), this,
        SLOT(indexingStarted()));
    connect(m_helpEngine->searchEngine(), SIGNAL(indexingFinished()), this,
        SLOT(indexingFinished()));

    // Explicitly register qml.qch if located in creator directory. This is only
    // needed for the creator-qml package, were we want to ship the documentation
    // without a qt development version.
    const QString &appPath = QCoreApplication::applicationDirPath();
    filesToRegister.append(QDir::cleanPath(QDir::cleanPath(appPath
            + QLatin1String(DOCPATH "qml.qch"))));

    // we might need to register creators inbuild help
    if (!assistantInternalDocRegistered) {
        filesToRegister.append(QDir::cleanPath(appPath
            + QLatin1String(DOCPATH "qtcreator.qch")));
    }

    // this comes from the installer
670 671
    const QLatin1String key("AddedDocs");
    const QString &addedDocs = m_helpEngine->customValue(key).toString();
672
    if (!addedDocs.isEmpty()) {
673 674
        m_helpEngine->removeCustomValue(key);
        filesToRegister += addedDocs.split(QLatin1Char(';'));
675 676
    }

677 678 679 680 681
    if (!updateDocumentation()) {
        // if no documentation has been added, we need to force a setup data,
        // otherwise it has already been run in updateDocumentation
        m_helpEngine->setupData();
    }
con's avatar
con committed
682

683 684 685 686 687 688 689
#if !defined(QT_NO_WEBKIT)
    QWebSettings* webSettings = QWebSettings::globalSettings();
    QFont font(webSettings->fontFamily(QWebSettings::StandardFont),
        webSettings->fontSize(QWebSettings::DefaultFontSize));

    font = qVariantValue<QFont>(m_helpEngine->customValue(QLatin1String("font"),
        font));
690

691 692 693
    webSettings->setFontFamily(QWebSettings::StandardFont, font.family());
    webSettings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
#endif
694

695 696 697 698
    const QString &url = QString::fromLatin1("qthelp://com.nokia.qtcreator."
        "%1%2%3/doc/index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR)
        .arg(IDE_VERSION_RELEASE);
    m_helpEngine->setCustomValue(QLatin1String("DefaultHomePage"), url);
699 700 701 702 703 704 705

    connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this,
        SLOT(rebuildViewerComboBox()));
    connect(m_centralWidget, SIGNAL(currentViewerChanged(int)), this,
        SLOT(updateViewerComboBoxIndex(int)));
    connect(m_centralWidget, SIGNAL(viewerAboutToBeRemoved(int)), this,
        SLOT(removeViewerFromComboBox(int)));
706

Robert Loehning's avatar
Robert Loehning committed
707
    connect(helpManager, SIGNAL(registerDocumentation()), this,
708
        SLOT(pluginUpdateDocumentation()));
709 710

    isInitialised = true;
con's avatar
con committed
711 712 713 714
}

void HelpPlugin::shutdown()
{
715
    m_sideBar->saveSettings(m_core->settings(), QLatin1String("HelpSideBar"));
con's avatar
con committed
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
    m_bookmarkManager->saveBookmarks();
    delete m_bookmarkManager;
}

void HelpPlugin::setIndexFilter(const QString &filter)
{
    m_indexWidget->setSearchLineEditText(filter);
}

QString HelpPlugin::indexFilter() const
{
    return m_indexWidget->searchLineEditText();
}

void HelpPlugin::modeChanged(Core::IMode *mode)
{
732 733 734
    if (mode == m_mode && firstModeChange) {
        firstModeChange = false;

con's avatar
con committed
735 736
        qApp->processEvents();
        qApp->setOverrideCursor(Qt::WaitCursor);
737

kh1's avatar
kh1 committed
738
        resetFilter();
con's avatar
con committed
739
        m_centralWidget->setLastShownPages();
740 741 742
        connect(m_helpEngine, SIGNAL(setupFinished()), m_helpEngine->searchEngine(),
            SLOT(indexDocumentation()));
        QMetaObject::invokeMethod(m_helpEngine, "setupFinished", Qt::QueuedConnection);
con's avatar
con committed
743 744 745 746
        qApp->restoreOverrideCursor();
    }
}

747 748 749 750 751 752 753 754 755 756 757 758 759
void HelpPlugin::updateSideBarSource()
{
    const QUrl &url = m_centralWidget->currentSource();
    if (url.isValid())
        updateSideBarSource(url);
}

void HelpPlugin::updateSideBarSource(const QUrl &newUrl)
{
    if (m_helpViewerForSideBar)
        m_helpViewerForSideBar->setSource(newUrl);
}

760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
void HelpPlugin::fontChanged()
{
#if defined(QT_NO_WEBKIT)
    QFont font = qApp->font();
    font = qVariantValue<QFont>(m_helpEngine->customValue(QLatin1String("font"),
        font));

    if (m_helpViewerForSideBar)
        m_helpViewerForSideBar->setFont(font);

    if (m_centralWidget) {
        int i = 0;
        while (HelpViewer* viewer = m_centralWidget->helpViewerAtIndex(i++)) {
            if (viewer->font() != font)
                viewer->setFont(font);
        }
    }
#endif
}

780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
void HelpPlugin::rebuildViewerComboBox()
{
    m_documentsCombo->clear();

    int i = 0;
    while (HelpViewer *viewer = m_centralWidget->helpViewerAtIndex(i++))
        m_documentsCombo->addItem(viewer->documentTitle());

    int index = m_centralWidget->indexOf(m_centralWidget->currentHelpViewer());
    if (index >= 0)
        m_documentsCombo->setCurrentIndex(index);
}

void HelpPlugin::removeViewerFromComboBox(int index)
{
    if (index >= 0)
        m_documentsCombo->removeItem(index);
}

void HelpPlugin::updateViewerComboBoxIndex(int index)
{
    if (index >= 0)
        m_documentsCombo->setCurrentIndex(index);
}

805 806
void HelpPlugin::indexingStarted()
{
807 808 809
    Q_ASSERT(!m_progress);
    m_progress = new QFutureInterface<void>();
    Core::ICore::instance()->progressManager() ->addTask(m_progress->future(),
810
        tr("Indexing"), QLatin1String("Help.Indexer"));
811 812 813
    m_progress->setProgressRange(0, 2);
    m_progress->setProgressValueAndText(1, tr("Indexing Documentation..."));
    m_progress->reportStarted();
814

815
    m_watcher.setFuture(m_progress->future());
816 817 818 819 820 821
    connect(&m_watcher, SIGNAL(canceled()), m_helpEngine->searchEngine(),
        SLOT(cancelIndexing()));
}

void HelpPlugin::indexingFinished()
{
822 823 824 825
    m_progress->reportFinished();

    delete m_progress;
    m_progress = NULL;
826 827
}

828
HelpViewer* HelpPlugin::viewerForContextMode()
con's avatar
con committed
829
{
830
    using namespace Core;
831

832 833 834 835 836 837 838
    bool showSideBySide = false;
    RightPanePlaceHolder *placeHolder = RightPanePlaceHolder::current();
    switch (m_helpEngine->customValue(QLatin1String("ContextHelpOption"), 0).toInt()) {
        case 0: {
            // side by side if possible
            if (IEditor *editor = EditorManager::instance()->currentEditor()) {
                if (!placeHolder || !placeHolder->isVisible()) {
839 840 841 842 843
                    if (!editor->widget())
                        break;
                    if (!editor->widget()->isVisible())
                        break;
                    if (editor->widget()->width() < 800)
844 845
                        break;
                }
846
            }
847 848 849 850 851
        }   // fall through
        case 1: {
            // side by side
            showSideBySide = true;
        }   break;
852

853 854
        default: // help mode
            break;
855 856
    }

857
    HelpViewer *viewer = m_centralWidget->currentHelpViewer();
858
    if (placeHolder && showSideBySide) {
859
        RightPaneWidget::instance()->setShown(true);
kh's avatar
kh committed
860
        viewer = m_helpViewerForSideBar;
con's avatar
con committed
861
    } else {
862
        activateHelpMode();
863 864
        if (!viewer && m_centralWidget)
            viewer = m_centralWidget->newEmptyTab();
kh's avatar
kh committed
865
    }
866 867 868 869 870
    return viewer;
}

void HelpPlugin::activateContext()
{
871 872
    using namespace Core;

873 874 875
    if (!m_helpViewerForSideBar)
        createRightPaneSideBar();

876
    RightPanePlaceHolder* placeHolder = RightPanePlaceHolder::current();
877 878 879 880 881 882 883 884 885 886
    if (placeHolder && m_helpViewerForSideBar->hasFocus()) {
        switchToHelpMode();
        return;
    } else if (m_core->modeManager()->currentMode() == m_mode)
        return;

    QString id;
    QMap<QString, QUrl> links;

    // Find out what to show
887
    if (IContext *context = m_core->currentContextObject()) {
888
        id = context->contextHelpId();
889
        links = HelpManager::helpEngineCore().linksForIdentifier(id);
890 891
    }

892
    if (HelpViewer* viewer = viewerForContextMode()) {
kh's avatar
kh committed
893 894 895 896 897
        if (links.isEmpty()) {
            // No link found or no context object
            viewer->setHtml(tr("<html><head><title>No Documentation</title>"
                "</head><body><br/><center><b>%1</b><br/>No documentation "
                "available.</center></body></html>").arg(id));
con's avatar
con committed
898
            viewer->setSource(QUrl());
kh's avatar
kh committed
899
        } else {
900
            const QUrl &source = *links.begin();
kh's avatar
kh committed
901 902 903
            if (viewer->source() != source)
                viewer->setSource(source);
            viewer->setFocus();
con's avatar
con committed
904
        }
905 906
        if (viewer != m_helpViewerForSideBar)
            activateHelpMode();
con's avatar
con committed
907 908 909 910 911
    }
}

void HelpPlugin::activateIndex()
{
hjk's avatar
hjk committed
912
    activateHelpMode();
con's avatar
con committed
913 914 915 916 917
    m_sideBar->activateItem(m_indexItem);
}

void HelpPlugin::activateContents()
{
hjk's avatar
hjk committed
918
    activateHelpMode();
con's avatar
con committed
919 920 921 922 923
    m_sideBar->activateItem(m_contentItem);
}

void HelpPlugin::activateSearch()
{
hjk's avatar
hjk committed
924
    activateHelpMode();
con's avatar
con committed
925 926 927 928 929 930
    m_sideBar->activateItem(m_searchItem);
}

QToolBar *HelpPlugin::createToolBar()
{
    QToolBar *toolWidget = new QToolBar;
931
    Core::ActionManager *am = m_core->actionManager();
con's avatar
con committed
932 933 934 935 936 937 938 939 940 941 942 943
    toolWidget->addAction(am->command(QLatin1String("Help.Home"))->action());
    toolWidget->addAction(am->command(QLatin1String("Help.Previous"))->action());
    toolWidget->addAction(am->command(QLatin1String("Help.Next"))->action());
    toolWidget->addSeparator();
    toolWidget->addAction(am->command(QLatin1String("Help.AddBookmark"))->action());
    //int size = toolWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
    //toolWidget->setIconSize(QSize(size, size));
    toolWidget->setMovable(false);

    toolWidget->addSeparator();

    QWidget *w = new QWidget;
944 945
    toolWidget->addWidget(w);

con's avatar
con committed
946 947 948
    QHBoxLayout *layout = new QHBoxLayout(w);
    layout->setMargin(0);
    layout->addSpacing(10);
949 950 951 952 953 954 955
    m_documentsCombo = new QComboBox;
    m_documentsCombo->setMinimumContentsLength(40);
    layout->addWidget(m_documentsCombo);

    connect(m_documentsCombo, SIGNAL(activated(int)), m_centralWidget,
        SLOT(activateTab(int)));

con's avatar
con committed
956 957 958
    layout->addWidget(new QLabel(tr("Filtered by:")));
    m_filterComboBox = new QComboBox;
    m_filterComboBox->setMinimumContentsLength(20);
959 960
    layout->addWidget(m_filterComboBox);

kh's avatar
kh committed
961 962
    connect(m_filterComboBox, SIGNAL(activated(QString)), this,
        SLOT(filterDocumentation(QString)));
con's avatar
con committed
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987

    return toolWidget;
}

void HelpPlugin::updateFilterComboBox()
{
    QString curFilter = m_filterComboBox->currentText();
    if (curFilter.isEmpty())
        curFilter = m_helpEngine->currentFilter();
    m_filterComboBox->clear();
    m_filterComboBox->addItems(m_helpEngine->customFilters());
    int idx = m_filterComboBox->findText(curFilter);
    if (idx < 0)
        idx = 0;
    m_filterComboBox->setCurrentIndex(idx);
}

void HelpPlugin::checkForHelpChanges()
{
    bool changed = m_docSettingsPage->applyChanges();
    changed |= m_filterSettingsPage->applyChanges();
    if (changed)
        m_helpEngine->setupData();
}

988 989 990 991 992 993
void HelpPlugin::checkForGeneralChanges()
{
    if (generalSettingsPage->applyChanges())
        m_helpEngine->setupData();
}

con's avatar
con committed
994 995 996 997 998 999 1000
void HelpPlugin::filterDocumentation(const QString &customFilter)
{
    m_helpEngine->setCurrentFilter(customFilter);
}

void HelpPlugin::addBookmark()
{
1001 1002
    addNewBookmark(m_centralWidget->currentTitle(),
        m_centralWidget->currentSource().toString());
con's avatar
con committed
1003 1004 1005 1006
}

void HelpPlugin::addNewBookmark(const QString &title, const QString &url)
{
1007
    if (url.isEmpty() || url == QLatin1String("about:blank"))
con's avatar
con committed
1008 1009 1010 1011 1012
        return;

    m_bookmarkManager->showBookmarkDialog(m_centralWidget, title, url);
}

1013
void HelpPlugin::handleHelpRequest(const QString &address)
con's avatar
con committed
1014
{
1015 1016 1017 1018 1019 1020 1021 1022 1023
    if (m_helpEngine->findFile(address).isValid()) {
        const QUrl url(address);
        if (url.queryItemValue(QLatin1String("view")) == QLatin1String("split")) {
            if (HelpViewer* viewer = viewerForContextMode())
                viewer->setSource(url);
        } else {
            activateHelpMode();
            m_centralWidget->setSource(url);
        }
1024 1025 1026
    } else {
        // local help not installed, resort to external web help
        QString urlPrefix;
1027
        if (address.startsWith(QLatin1String("qthelp://com.nokia.qtcreator"))) {
1028 1029
            urlPrefix = QString::fromLatin1("http://doc.trolltech.com/qtcreator"
                "-%1.%2/").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR);
1030 1031 1032
        } else {
            urlPrefix = QLatin1String("http://doc.trolltech.com/latest/");
        }
1033
        QDesktopServices::openUrl(QUrl(urlPrefix + address.mid(address
1034
            .lastIndexOf(QLatin1Char('/')) + 1)));
1035 1036
    }
}
con's avatar
con committed
1037 1038

Q_EXPORT_PLUGIN(HelpPlugin)