~ubuntu-branches/ubuntu/karmic/qtcreator/karmic-security

« back to all changes in this revision

Viewing changes to src/plugins/help/helpplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-07-19 16:23:52 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090719162352-oni0h8hrrkdd3sil
Tags: 1.2.1-1ubuntu1
* Merge from debian unstable (LP: #399414), remaining changes:
  - Add qt-creator transitional package.
* debian/control: Conflicts on qt-creator (<< 1.2.1-1ubuntu1).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
**
5
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6
6
**
7
 
** Contact:  Qt Software Information (qt-info@nokia.com)
 
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8
8
**
9
9
** Commercial Usage
10
10
**
23
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
24
**
25
25
** If you are unsure which license is appropriate for your use, please
26
 
** contact the sales department at qt-sales@nokia.com.
 
26
** contact the sales department at http://www.qtsoftware.com/contact.
27
27
**
28
28
**************************************************************************/
29
29
 
58
58
#include <QtCore/QSettings>
59
59
#include <QtCore/QDir>
60
60
#include <QtCore/QResource>
 
61
#include <QtCore/QLibraryInfo>
 
62
#include <QtCore/QTranslator>
61
63
#include <QtGui/QAction>
62
64
#include <QtGui/QShortcut>
63
65
#include <QtGui/QSplitter>
64
66
#include <QtGui/QStyle>
65
67
#include <QtGui/QToolBar>
66
68
#include <QtGui/QComboBox>
 
69
#include <QtGui/QDesktopServices>
67
70
#include <QtHelp/QHelpEngine>
68
71
 
 
72
#ifndef QT_NO_WEBKIT
 
73
#include <QtGui/QApplication>
 
74
#include <QtWebKit/QWebSettings>
 
75
#endif
 
76
 
69
77
using namespace Help;
70
78
using namespace Help::Internal;
71
79
 
82
90
        if (!hc.setupData())
83
91
            qWarning() << "Could not initialize help engine:" << hc.error();
84
92
        foreach (const QString &fileName, fileNames) {
85
 
            if (!QFile::exists(fileName))
 
93
            if (!QFileInfo(fileName).exists())
86
94
                continue;
87
 
            QString fileNamespace = QHelpEngineCore::namespaceName(fileName);
88
 
            if (!fileNamespace.isEmpty() && !hc.registeredDocumentations().contains(fileNamespace)) {
 
95
            const QString &nameSpace = QHelpEngineCore::namespaceName(fileName);
 
96
            if (!nameSpace.isEmpty()
 
97
                && !hc.registeredDocumentations().contains(nameSpace)) {
89
98
                if (hc.registerDocumentation(fileName))
90
99
                    needsSetup = true;
91
100
                else
129
138
    QList<int> modecontext;
130
139
    modecontext << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_MODE_HELP);
131
140
 
 
141
    QString locale = qApp->property("qtc_locale").toString();
 
142
    if (!locale.isEmpty()) {
 
143
        QTranslator *qtr = new QTranslator(this);
 
144
        QTranslator *qhelptr = new QTranslator(this);
 
145
        const QString &creatorTrPath =
 
146
                Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
 
147
        const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
 
148
        const QString &trFile = QLatin1String("assistant_") + locale;
 
149
        const QString &helpTrFile = QLatin1String("qt_help_") + locale;
 
150
        if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
 
151
            qApp->installTranslator(qtr);
 
152
        if (qhelptr->load(helpTrFile, qtTrPath) || qhelptr->load(helpTrFile, creatorTrPath))
 
153
            qApp->installTranslator(qhelptr);
 
154
    }
 
155
 
 
156
#ifndef QT_NO_WEBKIT
 
157
    QWebSettings *webSettings = QWebSettings::globalSettings();
 
158
    const QFont applicationFont = QApplication::font();
 
159
    webSettings->setFontFamily(QWebSettings::StandardFont, applicationFont.family());
 
160
    //webSettings->setFontSize(QWebSettings::DefaultFontSize, applicationFont.pointSize());
 
161
#endif
 
162
 
132
163
    // FIXME shouldn't the help engine create the directory if it doesn't exist?
133
164
    QFileInfo fi(m_core->settings()->fileName());
134
165
    QDir directory(fi.absolutePath()+"/qtcreator");
135
166
    if (!directory.exists())
136
167
        directory.mkpath(directory.absolutePath());
137
 
    m_helpEngine = new QHelpEngine(directory.absolutePath()
138
 
                                   + QLatin1String("/helpcollection.qhc"), this);
139
 
    connect(m_helpEngine, SIGNAL(setupFinished()),
140
 
        this, SLOT(updateFilterComboBox()));
 
168
    m_helpEngine = new QHelpEngine(directory.absolutePath() +
 
169
        QLatin1String("/helpcollection.qhc"), this);
 
170
    connect(m_helpEngine, SIGNAL(setupFinished()), this,
 
171
        SLOT(updateFilterComboBox()));
141
172
 
142
173
    addAutoReleasedObject(new HelpManager(m_helpEngine));
143
174
 
148
179
    addAutoReleasedObject(m_filterSettingsPage);
149
180
    connect(m_docSettingsPage, SIGNAL(documentationAdded()),
150
181
        m_filterSettingsPage, SLOT(updateFilterPage()));
151
 
    connect(m_docSettingsPage, SIGNAL(dialogAccepted()),
152
 
        this, SLOT(checkForHelpChanges()));
 
182
    connect(m_docSettingsPage, SIGNAL(dialogAccepted()), this,
 
183
        SLOT(checkForHelpChanges()));
153
184
 
154
185
    m_contentWidget = new ContentWindow(m_helpEngine);
155
186
    m_contentWidget->setWindowTitle(tr("Contents"));
160
191
    m_bookmarkManager = new BookmarkManager(m_helpEngine);
161
192
    m_bookmarkWidget = new BookmarkWidget(m_bookmarkManager, 0, false);
162
193
    m_bookmarkWidget->setWindowTitle(tr("Bookmarks"));
163
 
    connect(m_bookmarkWidget, SIGNAL(addBookmark()),
164
 
        this, SLOT(addBookmark()));
 
194
    connect(m_bookmarkWidget, SIGNAL(addBookmark()), this, SLOT(addBookmark()));
165
195
 
166
196
    Core::ActionManager *am = m_core->actionManager();
167
197
    Core::Command *cmd;
168
198
 
169
199
    // Add Home, Previous and Next actions (used in the toolbar)
170
 
    QAction *homeAction = new QAction(QIcon(QLatin1String(":/help/images/home.png")), tr("Home"), this);
 
200
    QAction *homeAction =
 
201
        new QAction(QIcon(QLatin1String(":/help/images/home.png")), tr("Home"),
 
202
        this);
171
203
    cmd = am->registerAction(homeAction, QLatin1String("Help.Home"), globalcontext);
172
204
 
173
 
    QAction *previousAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
 
205
    QAction *previousAction =
 
206
        new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
174
207
        tr("Previous"), this);
175
 
    cmd = am->registerAction(previousAction, QLatin1String("Help.Previous"), modecontext);
176
 
    cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Backspace));
 
208
    cmd = am->registerAction(previousAction, QLatin1String("Help.Previous"),
 
209
        modecontext);
 
210
    cmd->setDefaultKeySequence(QKeySequence::Back);
177
211
 
178
 
    QAction *nextAction = new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"), this);
 
212
    QAction *nextAction =
 
213
        new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"),
 
214
        this);
179
215
    cmd = am->registerAction(nextAction, QLatin1String("Help.Next"), modecontext);
 
216
    cmd->setDefaultKeySequence(QKeySequence::Forward);
180
217
 
181
 
    QAction *addBookmarkAction = new QAction(QIcon(QLatin1String(":/help/images/bookmark.png")),
 
218
    QAction *addBookmarkAction =
 
219
        new QAction(QIcon(QLatin1String(":/help/images/bookmark.png")),
182
220
        tr("Add Bookmark"), this);
183
 
    cmd = am->registerAction(addBookmarkAction, QLatin1String("Help.AddBookmark"), modecontext);
 
221
    cmd = am->registerAction(addBookmarkAction, QLatin1String("Help.AddBookmark"),
 
222
        modecontext);
184
223
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_M));
185
224
 
186
225
    // Add Index, Contents, and Context menu items and a separator to the Help menu
187
226
    QAction *indexAction = new QAction(tr("Index"), this);
188
 
    cmd = am->registerAction(indexAction, QLatin1String("Help.Index"), globalcontext);
189
 
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
 
227
    cmd = am->registerAction(indexAction, QLatin1String("Help.Index"),
 
228
        globalcontext);
 
229
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
 
230
        Core::Constants::G_HELP_HELP);
190
231
 
191
232
    QAction *contentsAction = new QAction(tr("Contents"), this);
192
 
    cmd = am->registerAction(contentsAction, QLatin1String("Help.Contents"), globalcontext);
193
 
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
 
233
    cmd = am->registerAction(contentsAction, QLatin1String("Help.Contents"),
 
234
        globalcontext);
 
235
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
 
236
        Core::Constants::G_HELP_HELP);
194
237
 
195
238
    QAction *searchAction = new QAction(tr("Search"), this);
196
 
    cmd = am->registerAction(searchAction, QLatin1String("Help.Search"), globalcontext);
197
 
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
 
239
    cmd = am->registerAction(searchAction, QLatin1String("Help.Search"),
 
240
        globalcontext);
 
241
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
 
242
        Core::Constants::G_HELP_HELP);
198
243
 
199
244
    QAction *contextAction = new QAction(tr("Context Help"), this);
200
 
    cmd = am->registerAction(contextAction, QLatin1String("Help.Context"), globalcontext);
 
245
    cmd = am->registerAction(contextAction, QLatin1String("Help.Context"),
 
246
        globalcontext);
201
247
    cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1));
202
 
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
 
248
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
 
249
        Core::Constants::G_HELP_HELP);
203
250
 
204
 
#ifndef Q_OS_MAC
 
251
#ifndef Q_WS_MAC
205
252
    QAction *sep = new QAction(this);
206
253
    sep->setSeparator(true);
207
254
    cmd = am->registerAction(sep, QLatin1String("Help.Separator"), globalcontext);
208
 
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
 
255
    am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
 
256
        Core::Constants::G_HELP_HELP);
209
257
#endif
210
258
 
211
 
    m_centralWidget = new CentralWidget(m_helpEngine);
 
259
    m_centralWidget = new Help::Internal::CentralWidget(m_helpEngine);
212
260
    Aggregation::Aggregate *agg = new Aggregation::Aggregate;
213
261
    agg->add(m_centralWidget);
214
262
    agg->add(new HelpFindSupport(m_centralWidget));
252
300
    QMap<QString, Core::Command*> shortcutMap;
253
301
    QShortcut *shortcut = new QShortcut(splitter);
254
302
    shortcut->setWhatsThis(tr("Activate Index in Help mode"));
255
 
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.IndexShortcut"), modecontext);
 
303
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.IndexShortcut"),
 
304
        modecontext);
256
305
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_I));
257
306
    connect(shortcut, SIGNAL(activated()), this, SLOT(activateIndex()));
258
307
    shortcutMap.insert(m_indexWidget->windowTitle(), cmd);
259
308
 
260
309
    shortcut = new QShortcut(splitter);
261
310
    shortcut->setWhatsThis(tr("Activate Contents in Help mode"));
262
 
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.ContentsShortcut"), modecontext);
 
311
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.ContentsShortcut"),
 
312
        modecontext);
263
313
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_T));
264
314
    connect(shortcut, SIGNAL(activated()), this, SLOT(activateContents()));
265
315
    shortcutMap.insert(m_contentWidget->windowTitle(), cmd);
266
316
 
267
317
    shortcut = new QShortcut(splitter);
268
318
    shortcut->setWhatsThis(tr("Activate Search in Help mode"));
269
 
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.SearchShortcut"), modecontext);
 
319
    cmd = am->registerShortcut(shortcut, QLatin1String("Help.SearchShortcut"),
 
320
        modecontext);
270
321
    cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_S));
271
322
    connect(shortcut, SIGNAL(activated()), this, SLOT(activateSearch()));
272
323
    shortcutMap.insert(m_searchWidget->windowTitle(), cmd);
278
329
    connect(previousAction, SIGNAL(triggered()), m_centralWidget, SLOT(backward()));
279
330
    connect(nextAction, SIGNAL(triggered()), m_centralWidget, SLOT(forward()));
280
331
    connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(addBookmark()));
281
 
    connect(m_contentWidget, SIGNAL(linkActivated(const QUrl&)),
282
 
            m_centralWidget, SLOT(setSource(const QUrl&)));
283
 
    connect(m_indexWidget, SIGNAL(linkActivated(const QUrl&)),
284
 
            m_centralWidget, SLOT(setSource(const QUrl&)));
285
 
    connect(m_searchWidget, SIGNAL(requestShowLink(const QUrl&)),
286
 
        m_centralWidget, SLOT(setSource(const QUrl&)));
287
 
    connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(const QUrl&)),
288
 
        m_centralWidget, SLOT(setSourceInNewTab(const QUrl&)));
289
 
    connect(m_bookmarkWidget, SIGNAL(requestShowLink(const QUrl&)),
290
 
        m_centralWidget, SLOT(setSource(const QUrl&)));
 
332
    connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
 
333
        SLOT(setSource(QUrl)));
 
334
    connect(m_indexWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
 
335
        SLOT(setSource(QUrl)));
 
336
    connect(m_searchWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
 
337
        SLOT(setSource(QUrl)));
 
338
    connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)),
 
339
        m_centralWidget, SLOT(setSourceInNewTab(QUrl)));
 
340
    connect(m_bookmarkWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
 
341
        SLOT(setSource(const QUrl&)));
291
342
 
292
343
    connect(m_centralWidget, SIGNAL(backwardAvailable(bool)),
293
344
        previousAction, SLOT(setEnabled(bool)));
294
345
    connect(m_centralWidget, SIGNAL(forwardAvailable(bool)),
295
346
        nextAction, SLOT(setEnabled(bool)));
296
 
    connect(m_centralWidget, SIGNAL(addNewBookmark(const QString&, const QString&)),
297
 
        this, SLOT(addNewBookmark(const QString&, const QString&)));
 
347
    connect(m_centralWidget, SIGNAL(addNewBookmark(QString, QString)), this,
 
348
        SLOT(addNewBookmark(QString, QString)));
298
349
 
299
350
    QList<QAction*> actionList;
300
351
    actionList << previousAction
301
352
        << nextAction
302
353
        << homeAction
303
 
#ifndef Q_OS_MAC
 
354
#ifndef Q_WS_MAC
304
355
        << sep
305
356
#endif
306
357
        << copyAction;
314
365
    connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)),
315
366
        this, SLOT(modeChanged(Core::IMode*)));
316
367
 
317
 
    connect(m_contentWidget, SIGNAL(linkActivated(const QUrl&)),
318
 
        m_centralWidget, SLOT(setSource(const QUrl&)));
319
 
    connect(m_indexWidget, SIGNAL(linkActivated(const QUrl&)),
320
 
        m_centralWidget, SLOT(setSource(const QUrl&)));
321
 
    connect(m_indexWidget, SIGNAL(linksActivated(const QMap<QString, QUrl>&, const QString&)),
322
 
        m_centralWidget, SLOT(showTopicChooser(const QMap<QString, QUrl>&, const QString&)));
 
368
    connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
 
369
        SLOT(setSource(QUrl)));
 
370
    connect(m_indexWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
 
371
        SLOT(setSource(QUrl)));
 
372
    connect(m_indexWidget, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)),
 
373
        m_centralWidget, SLOT(showTopicChooser(QMap<QString, QUrl>, QString)));
323
374
 
324
375
    HelpIndexFilter *helpIndexFilter = new HelpIndexFilter(this, m_helpEngine);
325
376
    addAutoReleasedObject(helpIndexFilter);
326
 
    connect(helpIndexFilter, SIGNAL(linkActivated(QUrl)),
327
 
            this, SLOT(switchToHelpMode(QUrl)));
328
 
    connect(helpIndexFilter, SIGNAL(linksActivated(const QMap<QString, QUrl>&, const QString&)),
329
 
            this, SLOT(switchToHelpMode(const QMap<QString, QUrl>&, const QString&)));
 
377
    connect(helpIndexFilter, SIGNAL(linkActivated(QUrl)), this,
 
378
        SLOT(switchToHelpMode(QUrl)));
 
379
    connect(helpIndexFilter, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)),
 
380
        this, SLOT(switchToHelpMode(QMap<QString, QUrl>, QString)));
330
381
 
331
382
    previousAction->setEnabled(m_centralWidget->isBackwardAvailable());
332
383
    nextAction->setEnabled(m_centralWidget->isForwardAvailable());
333
384
 
334
385
    createRightPaneSideBar();
335
386
 
 
387
    QDesktopServices::setUrlHandler("qthelp", this, "openHelpPage");
 
388
 
336
389
    return true;
337
390
}
338
391
 
339
392
void HelpPlugin::createRightPaneSideBar()
340
393
{
341
394
    QAction *switchToHelpMode = new QAction("Go to Help Mode", this);
342
 
    m_rightPaneBackwardAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")), tr("Previous"), this);
343
 
    m_rightPaneForwardAction = new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"), this);
 
395
    m_rightPaneBackwardAction =
 
396
        new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
 
397
        tr("Previous"), this);
 
398
    m_rightPaneForwardAction =
 
399
        new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"),
 
400
        this);
344
401
 
345
402
    QToolBar *rightPaneToolBar = new QToolBar();
346
403
    rightPaneToolBar->addAction(switchToHelpMode);
348
405
    rightPaneToolBar->addAction(m_rightPaneForwardAction);
349
406
 
350
407
    connect(switchToHelpMode, SIGNAL(triggered()), this, SLOT(switchToHelpMode()));
351
 
    connect(m_rightPaneBackwardAction, SIGNAL(triggered()), this, SLOT(rightPaneBackward()));
352
 
    connect(m_rightPaneForwardAction, SIGNAL(triggered()), this, SLOT(rightPaneForward()));
 
408
    connect(m_rightPaneBackwardAction, SIGNAL(triggered()), this,
 
409
        SLOT(rightPaneBackward()));
 
410
    connect(m_rightPaneForwardAction, SIGNAL(triggered()), this,
 
411
        SLOT(rightPaneForward()));
353
412
 
354
413
    QToolButton *closeButton = new QToolButton();
355
414
    closeButton->setProperty("type", QLatin1String("dockbutton"));
380
439
    m_core->addContextObject(new Core::BaseContext(m_helpViewerForSideBar, QList<int>()
381
440
        << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_HELP_SIDEBAR),
382
441
        this));
 
442
    connect(m_centralWidget, SIGNAL(sourceChanged(QUrl)), this,
 
443
        SLOT(updateSideBarSource(QUrl)));
 
444
    connect(m_centralWidget, SIGNAL(currentViewerChanged()), this,
 
445
        SLOT(updateSideBarSource()));
383
446
 
384
447
    QAction *copyActionSideBar = new QAction(this);
385
448
    Core::Command *cmd = m_core->actionManager()->registerAction(copyActionSideBar,
418
481
void HelpPlugin::switchToHelpMode()
419
482
{
420
483
    switchToHelpMode(m_helpViewerForSideBar->source());
421
 
    Core::RightPaneWidget::instance()->setShown(false);
422
484
}
423
485
 
424
486
void HelpPlugin::switchToHelpMode(const QUrl &source)
428
490
    m_centralWidget->setFocus();
429
491
}
430
492
 
431
 
void HelpPlugin::switchToHelpMode(const QMap<QString, QUrl> &urls, const QString &keyword)
 
493
void HelpPlugin::switchToHelpMode(const QMap<QString, QUrl> &urls,
 
494
    const QString &keyword)
432
495
{
433
496
    activateHelpMode();
434
497
    m_centralWidget->showTopicChooser(urls, keyword);
450
513
    bool needsSetup = false;
451
514
    bool assistantInternalDocRegistered = false;
452
515
 
453
 
    foreach (QString ns, m_helpEngine->registeredDocumentations()) {
454
 
        if (ns == QString("com.nokia.qtcreator.%1%2")
455
 
            .arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR)) {
 
516
    const QString &docInternal = QString("com.nokia.qtcreator.%1%2")
 
517
        .arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR);
 
518
    const QStringList &docs = m_helpEngine->registeredDocumentations();
 
519
    foreach (const QString &ns, docs) {
 
520
        if (ns == docInternal) {
456
521
            assistantInternalDocRegistered = true;
457
522
            break;
458
523
        }
465
530
        QHelpEngineCore hc(fi.absoluteFilePath());
466
531
        hc.setupData();
467
532
        QString fileNamespace = QHelpEngineCore::namespaceName(qchFileName);
468
 
        if (!fileNamespace.isEmpty() && !hc.registeredDocumentations().contains(fileNamespace)) {
469
 
            if (!hc.registerDocumentation(qchFileName))
470
 
                qDebug() << hc.error();
471
 
            needsSetup = true;
 
533
        if (!fileNamespace.isEmpty()
 
534
            && !hc.registeredDocumentations().contains(fileNamespace)) {
 
535
                if (!hc.registerDocumentation(qchFileName))
 
536
                    qDebug() << hc.error();
 
537
                needsSetup = true;
472
538
        }
473
539
    }
474
540
 
475
 
    int i = m_helpEngine->customValue(
476
 
        QLatin1String("UnfilteredFilterInserted")).toInt();
 
541
    QLatin1String key("UnfilteredFilterInserted");
 
542
    int i = m_helpEngine->customValue(key).toInt();
477
543
    if (i != 1) {
478
544
        {
479
545
            QHelpEngineCore hc(m_helpEngine->collectionFile());
480
546
            hc.setupData();
481
547
            hc.addCustomFilter(tr("Unfiltered"), QStringList());
482
 
            hc.setCustomValue(QLatin1String("UnfilteredFilterInserted"), 1);
 
548
            hc.setCustomValue(key, 1);
483
549
        }
484
550
        m_helpEngine->blockSignals(true);
485
551
        m_helpEngine->setCurrentFilter(tr("Unfiltered"));
493
559
    updateFilterComboBox();
494
560
    m_bookmarkManager->setupBookmarkModels();
495
561
 
496
 
    if (Core::Internal::WelcomeMode *welcomeMode = qobject_cast<Core::Internal::WelcomeMode*>(m_core->modeManager()->mode(Core::Constants::MODE_WELCOME))) {
497
 
        connect(welcomeMode, SIGNAL(requestHelp(QString)), this, SLOT(openGettingStarted()));
 
562
    using namespace Core::Internal;
 
563
    using namespace Core::Constants;
 
564
    WelcomeMode *welcomeMode =
 
565
        qobject_cast<WelcomeMode*>(m_core->modeManager()->mode(MODE_WELCOME));
 
566
    if (welcomeMode) {
 
567
        connect(welcomeMode, SIGNAL(openHelpPage(QString)), this,
 
568
            SLOT(openHelpPage(QString)));
 
569
        connect(welcomeMode, SIGNAL(openContextHelpPage(QString)), this,
 
570
            SLOT(openContextHelpPage(QString)));
498
571
    }
499
572
}
500
573
 
526
599
    }
527
600
}
528
601
 
 
602
void HelpPlugin::openContextHelpPage(const QString &url)
 
603
{
 
604
    Core::RightPaneWidget::instance()->setShown(true);
 
605
    m_helpViewerForSideBar->setSource(QUrl(url));
 
606
}
 
607
 
 
608
void HelpPlugin::updateSideBarSource()
 
609
{
 
610
    const QUrl &url = m_centralWidget->currentSource();
 
611
    if (url.isValid())
 
612
        updateSideBarSource(url);
 
613
}
 
614
 
 
615
void HelpPlugin::updateSideBarSource(const QUrl &newUrl)
 
616
{
 
617
    if (m_helpViewerForSideBar)
 
618
        m_helpViewerForSideBar->setSource(newUrl);
 
619
}
 
620
 
529
621
void HelpPlugin::activateContext()
530
622
{
531
 
    using namespace Core;
532
 
    // case 1 sidebar shown and has focus, we show whatever we have in the
533
 
    // sidebar in big
534
 
    RightPanePlaceHolder* placeHolder = RightPanePlaceHolder::current();
 
623
    Core::RightPanePlaceHolder* placeHolder = Core::RightPanePlaceHolder::current();
535
624
    if (placeHolder && Core::RightPaneWidget::instance()->hasFocus()) {
536
625
        switchToHelpMode();
537
626
        return;
538
 
    }
 
627
    } else if (m_core->modeManager()->currentMode() == m_mode)
 
628
        return;
539
629
 
540
 
    bool useSideBar = false;
541
 
    if (placeHolder && !Core::RightPaneWidget::instance()->hasFocus())
542
 
        useSideBar = true;
 
630
    QString id;
 
631
    QMap<QString, QUrl> links;
543
632
 
544
633
    // Find out what to show
545
 
    HelpViewer *viewer = 0;
546
 
    if (IContext *context = m_core->currentContextObject()) {
 
634
    if (Core::IContext *context = m_core->currentContextObject()) {
547
635
        if (!m_contextHelpEngine) {
548
 
            m_contextHelpEngine = new QHelpEngineCore(m_helpEngine->collectionFile(), this);
549
 
            //m_contextHelpEngine->setAutoSaveFilter(false);
 
636
            m_contextHelpEngine =
 
637
                new QHelpEngineCore(m_helpEngine->collectionFile(), this);
550
638
            m_contextHelpEngine->setupData();
551
639
            m_contextHelpEngine->setCurrentFilter(tr("Unfiltered"));
552
640
        }
553
641
 
554
 
        const QString &id = context->contextHelpId();
555
 
        QMap<QString, QUrl> links = m_contextHelpEngine->linksForIdentifier(id);
556
 
        if (!links.isEmpty()) {
557
 
            if (useSideBar) {
558
 
                Core::RightPaneWidget::instance()->setShown(true);
559
 
                viewer = m_helpViewerForSideBar;
560
 
            } else {
561
 
                viewer = m_centralWidget->currentHelpViewer();
562
 
                m_core->modeManager()->activateMode(QLatin1String(Constants::ID_MODE_HELP));
563
 
            }
 
642
        id = context->contextHelpId();
 
643
        links = m_contextHelpEngine->linksForIdentifier(id);
 
644
    }
564
645
 
565
 
            if (viewer) {
566
 
                QUrl source = *links.begin();
567
 
                if (viewer->source() != source)
568
 
                    viewer->setSource(source);
569
 
                viewer->setFocus();
570
 
            }
571
 
        } else {
572
 
            // No link found
573
 
            if (useSideBar) {
574
 
                Core::RightPaneWidget::instance()->setShown(true);
575
 
                viewer = m_helpViewerForSideBar;
576
 
            } else {
577
 
                viewer = m_centralWidget->currentHelpViewer();
578
 
                activateHelpMode();
579
 
            }
580
 
            
581
 
            if (viewer) {
582
 
                viewer->setHtml(tr("<html><head><title>No Documentation</title></head><body><br/>"
583
 
                    "<center><b>%1</b><br/>No documentation available.</center></body></html>").
584
 
                    arg(id));
585
 
                viewer->setSource(QUrl());
586
 
                //activateIndex();
587
 
            }
588
 
        }
 
646
    HelpViewer *viewer = 0;
 
647
    if (placeHolder && !Core::RightPaneWidget::instance()->hasFocus()) {
 
648
        Core::RightPaneWidget::instance()->setShown(true);
 
649
        viewer = m_helpViewerForSideBar;
589
650
    } else {
590
 
        // No context object
591
 
        if (useSideBar) {
592
 
            Core::RightPaneWidget::instance()->setShown(true);
593
 
            viewer = m_helpViewerForSideBar;
594
 
        } else {
595
 
            viewer = m_centralWidget->currentHelpViewer();
596
 
            activateHelpMode();
597
 
        }
 
651
        viewer = m_centralWidget->currentHelpViewer();
 
652
        activateHelpMode();
 
653
    }
598
654
 
599
 
        if (viewer) {
 
655
    if (viewer) {
 
656
        if (links.isEmpty()) {
 
657
            // No link found or no context object
 
658
            viewer->setHtml(tr("<html><head><title>No Documentation</title>"
 
659
                "</head><body><br/><center><b>%1</b><br/>No documentation "
 
660
                "available.</center></body></html>").arg(id));
600
661
            viewer->setSource(QUrl());
601
 
            viewer->setHtml("<html><head><title>No Documentation</title></head><body><br/><br/><center>No"
602
 
                " documentation available.</center></body></html>");
603
 
            //activateIndex();
 
662
        } else {
 
663
            QUrl source = *links.begin();
 
664
            if (viewer->source() != source)
 
665
                viewer->setSource(source);
 
666
            viewer->setFocus();
604
667
        }
605
668
    }
606
669
}
645
708
    layout->addWidget(new QLabel(tr("Filtered by:")));
646
709
    m_filterComboBox = new QComboBox;
647
710
    m_filterComboBox->setMinimumContentsLength(20);
648
 
    connect(m_filterComboBox, SIGNAL(activated(const QString&)),
649
 
        this, SLOT(filterDocumentation(const QString&)));
 
711
    connect(m_filterComboBox, SIGNAL(activated(QString)), this,
 
712
        SLOT(filterDocumentation(QString)));
650
713
    layout->addWidget(m_filterComboBox);
651
714
    toolWidget->addWidget(w);
652
715
 
681
744
 
682
745
void HelpPlugin::addBookmark()
683
746
{
684
 
    addNewBookmark(m_centralWidget->currentTitle(), m_centralWidget->currentSource().toString());
 
747
    addNewBookmark(m_centralWidget->currentTitle(),
 
748
        m_centralWidget->currentSource().toString());
685
749
}
686
750
 
687
751
void HelpPlugin::addNewBookmark(const QString &title, const QString &url)
688
752
{
689
 
    if (url.isEmpty())
 
753
    if (url.isEmpty() || url == QLatin1String("about:blank"))
690
754
        return;
691
755
 
692
756
    m_bookmarkManager->showBookmarkDialog(m_centralWidget, title, url);
693
757
}
694
758
 
695
 
void HelpPlugin::openGettingStarted()
 
759
void HelpPlugin::openHelpPage(const QUrl& url)
696
760
{
697
 
    activateHelpMode();
698
 
    m_centralWidget->setSource(
699
 
        QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html")
700
 
        .arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
 
761
    openHelpPage(url.toString());
701
762
}
702
763
 
 
764
void HelpPlugin::openHelpPage(const QString& url)
 
765
{
 
766
    if (m_helpEngine->findFile(url).isValid()) {
 
767
        activateHelpMode();
 
768
        m_centralWidget->setSource(url);
 
769
    } else {
 
770
        // local help not installed, resort to external web help
 
771
        QString urlPrefix;
 
772
        if (url.startsWith("qthelp://com.nokia.qtcreator")) {
 
773
            urlPrefix = QString::fromLatin1("http://doc.trolltech.com/qtcreator-%1.%2/")
 
774
                        .arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR);
 
775
        } else {
 
776
            urlPrefix = QLatin1String("http://doc.trolltech.com/latest/");
 
777
        }
 
778
        QDesktopServices::openUrl(urlPrefix + url.mid(url.lastIndexOf('/') + 1));
 
779
    }
 
780
}
703
781
 
704
782
Q_EXPORT_PLUGIN(HelpPlugin)