2022-01-28 15:56:11 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-02-05 11:45:17 +01:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2022-01-28 15:56:11 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-25 19:58:52 +02:00
|
|
|
#include "helpdialog.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
|
2020-08-29 21:26:49 +02:00
|
|
|
#include "common.h"
|
2020-08-25 19:58:52 +02:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
#include "ui_helpdialog.h"
|
|
|
|
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QApplication>
|
2020-08-25 19:58:52 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QHelpEngine>
|
|
|
|
#include <QHelpContentWidget>
|
|
|
|
#include <QHelpIndexWidget>
|
|
|
|
#include <QMessageBox>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QStringList>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QVBoxLayout>
|
2020-08-25 19:58:52 +02:00
|
|
|
|
2022-04-13 12:24:00 +02:00
|
|
|
class QWidget;
|
|
|
|
|
2020-08-25 19:58:52 +02:00
|
|
|
void HelpBrowser::setHelpEngine(QHelpEngine *helpEngine)
|
|
|
|
{
|
|
|
|
mHelpEngine = helpEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant HelpBrowser::loadResource(int type, const QUrl &name)
|
|
|
|
{
|
|
|
|
if (name.scheme() == "qthelp") {
|
|
|
|
QString url(name.toString());
|
|
|
|
while (url.indexOf("/./") > 0)
|
|
|
|
url.remove(url.indexOf("/./"), 2);
|
|
|
|
return QVariant(mHelpEngine->fileData(QUrl(url)));
|
|
|
|
}
|
|
|
|
return QTextBrowser::loadResource(type, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString getHelpFile()
|
|
|
|
{
|
2020-08-29 21:26:49 +02:00
|
|
|
const QString datadir = getDataDir();
|
2020-08-25 19:58:52 +02:00
|
|
|
|
|
|
|
QStringList paths;
|
|
|
|
paths << (datadir + "/help")
|
|
|
|
<< datadir
|
|
|
|
<< (QApplication::applicationDirPath() + "/help")
|
|
|
|
<< QApplication::applicationDirPath();
|
2020-10-11 03:49:27 +02:00
|
|
|
#ifdef FILESDIR
|
|
|
|
const QString filesdir = FILESDIR;
|
|
|
|
paths << (filesdir + "/help")
|
|
|
|
<< filesdir;
|
|
|
|
#endif
|
2022-02-12 08:20:45 +01:00
|
|
|
for (const QString &p: paths) {
|
2020-08-25 19:58:52 +02:00
|
|
|
QString filename = p + "/online-help.qhc";
|
|
|
|
if (QFileInfo(filename).exists())
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
HelpDialog::HelpDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
mUi(new Ui::HelpDialog)
|
|
|
|
{
|
|
|
|
mUi->setupUi(this);
|
|
|
|
|
|
|
|
QString helpFile = getHelpFile();
|
|
|
|
if (helpFile.isEmpty()) {
|
|
|
|
const QString msg = tr("Helpfile '%1' was not found").arg("online-help.qhc");
|
|
|
|
QMessageBox msgBox(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
msg,
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
msgBox.exec();
|
|
|
|
mHelpEngine = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mHelpEngine = new QHelpEngine(helpFile);
|
2020-11-08 15:06:14 +01:00
|
|
|
// Disable the timestamp check of online-help.qhc by setting _q_readonly
|
|
|
|
mHelpEngine->setProperty("_q_readonly", QVariant::fromValue<bool>(true));
|
2020-08-25 19:58:52 +02:00
|
|
|
mHelpEngine->setupData();
|
|
|
|
|
|
|
|
mUi->contents->addWidget(mHelpEngine->contentWidget());
|
|
|
|
mUi->index->addWidget(mHelpEngine->indexWidget());
|
|
|
|
|
|
|
|
mUi->textBrowser->setHelpEngine(mHelpEngine);
|
|
|
|
|
2021-08-28 12:46:54 +02:00
|
|
|
mUi->textBrowser->setSource(QUrl("qthelp://cppcheck.sourceforge.io/doc/index.html"));
|
2020-08-25 19:58:52 +02:00
|
|
|
connect(mHelpEngine->contentWidget(),
|
|
|
|
SIGNAL(linkActivated(QUrl)),
|
|
|
|
mUi->textBrowser,
|
|
|
|
SLOT(setSource(QUrl)));
|
|
|
|
|
|
|
|
connect(mHelpEngine->indexWidget(),
|
2021-08-07 20:51:18 +02:00
|
|
|
SIGNAL(linkActivated(QUrl,QString)),
|
2020-08-25 19:58:52 +02:00
|
|
|
mUi->textBrowser,
|
|
|
|
SLOT(setSource(QUrl)));
|
|
|
|
}
|
|
|
|
|
|
|
|
HelpDialog::~HelpDialog()
|
|
|
|
{
|
|
|
|
delete mUi;
|
2022-07-13 21:09:53 +02:00
|
|
|
delete mHelpEngine;
|
2020-08-25 19:58:52 +02:00
|
|
|
}
|