From 14dfa035c179e613a83d52a7ed27cf6c98bbd719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 1 Aug 2020 18:56:37 +0200 Subject: [PATCH] GUI: Try to reuse Qt Assistant to show help --- gui/assistant.cpp | 62 +++++++++++++++++++++++++++++++++++ gui/assistant.h | 23 +++++++++++++ gui/gui.pro | 5 ++- gui/help/online-help.qhcp | 16 +++++++++ gui/helpdialog.cpp | 53 ------------------------------ gui/helpdialog.h | 34 ------------------- gui/helpdialog.ui | 67 -------------------------------------- gui/mainwindow.cpp | 8 +++-- gui/mainwindow.h | 3 ++ man/build-html.sh | 0 man/build-pdf.sh | 0 win_installer/cppcheck.wxs | 2 ++ 12 files changed, 113 insertions(+), 160 deletions(-) create mode 100644 gui/assistant.cpp create mode 100644 gui/assistant.h delete mode 100644 gui/helpdialog.cpp delete mode 100644 gui/helpdialog.h delete mode 100644 gui/helpdialog.ui mode change 100644 => 100755 man/build-html.sh mode change 100644 => 100755 man/build-pdf.sh diff --git a/gui/assistant.cpp b/gui/assistant.cpp new file mode 100644 index 000000000..d97c917cc --- /dev/null +++ b/gui/assistant.cpp @@ -0,0 +1,62 @@ +#include "assistant.h" + +#include +#include +#include +#include +#include + +Assistant::Assistant() + : mProc(nullptr) +{ +} + +Assistant::~Assistant() +{ + if (mProc && mProc->state() == QProcess::Running) { + mProc->terminate(); + mProc->waitForFinished(3000); + } + delete mProc; +} + +void Assistant::showDocumentation(const QString &page) +{ + if (!startAssistant()) + return; + + QByteArray ba("SetSource "); + ba.append("qthelp://cppcheck.sourceforge.net/doc/"); + + mProc->write(ba + page.toLocal8Bit() + '\n'); +} + +bool Assistant::startAssistant() +{ + if (!mProc) + mProc = new QProcess(); + + if (mProc->state() != QProcess::Running) { + QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator(); +#if !defined(Q_OS_MAC) + app += QLatin1String("assistant"); +#else + app += QLatin1String("Assistant.app/Contents/MacOS/Assistant"); +#endif + + QStringList args; + args << QLatin1String("-collectionFile") + << QLatin1String("online-help.qhc") + << QLatin1String("-enableRemoteControl"); + + mProc->start(app, args); + + if (!mProc->waitForStarted()) { + QMessageBox::critical(nullptr, + tr("Cppcheck"), + tr("Unable to launch Qt Assistant (%1)").arg(app)); + return false; + } + } + return true; +} diff --git a/gui/assistant.h b/gui/assistant.h new file mode 100644 index 000000000..4ac5218b1 --- /dev/null +++ b/gui/assistant.h @@ -0,0 +1,23 @@ +#ifndef ASSISTANT_H +#define ASSISTANT_H + +#include +#include + +class QProcess; + +class Assistant +{ + Q_DECLARE_TR_FUNCTIONS(Assistant) + +public: + Assistant(); + ~Assistant(); + void showDocumentation(const QString &file); + +private: + bool startAssistant(); + QProcess *mProc; +}; + +#endif // ASSISTANT_H diff --git a/gui/gui.pro b/gui/gui.pro index 3fd8663fb..505329e98 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -68,7 +68,6 @@ FORMS = about.ui \ application.ui \ file.ui \ functioncontractdialog.ui \ - helpdialog.ui \ mainwindow.ui \ projectfiledialog.ui \ resultsview.ui \ @@ -106,6 +105,7 @@ HEADERS += aboutdialog.h \ application.h \ applicationdialog.h \ applicationlist.h \ + assistant.h \ checkstatistics.h \ checkthread.h \ codeeditstylecontrols.h \ @@ -118,7 +118,6 @@ HEADERS += aboutdialog.h \ filelist.h \ fileviewdialog.h \ functioncontractdialog.h \ - helpdialog.h \ mainwindow.h \ platforms.h \ printablereport.h \ @@ -147,6 +146,7 @@ SOURCES += aboutdialog.cpp \ application.cpp \ applicationdialog.cpp \ applicationlist.cpp \ + assistant.cpp \ checkstatistics.cpp \ checkthread.cpp \ codeeditorstyle.cpp \ @@ -159,7 +159,6 @@ SOURCES += aboutdialog.cpp \ filelist.cpp \ fileviewdialog.cpp \ functioncontractdialog.cpp \ - helpdialog.cpp \ main.cpp \ mainwindow.cpp\ platforms.cpp \ diff --git a/gui/help/online-help.qhcp b/gui/help/online-help.qhcp index 71d37674f..5730625db 100644 --- a/gui/help/online-help.qhcp +++ b/gui/help/online-help.qhcp @@ -1,5 +1,21 @@ + + Cppcheck GUI + ../cppcheck.ico + QtProject/Cppcheck + qthelp://cppcheck.sourceforge.net/doc/index.html + + About Cppcheck + + + about.txt + images/icon.png + + false + false + false + diff --git a/gui/helpdialog.cpp b/gui/helpdialog.cpp deleted file mode 100644 index 68b306509..000000000 --- a/gui/helpdialog.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "helpdialog.h" -#include "ui_helpdialog.h" - -#include -#include -#include - -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); -} - -HelpDialog::HelpDialog(QWidget *parent) : - QDialog(parent), - mUi(new Ui::HelpDialog) -{ - mUi->setupUi(this); - - mHelpEngine = new QHelpEngine(QApplication::applicationDirPath() + "/online-help.qhc"); - mHelpEngine->setupData(); - - mUi->contents->addWidget(mHelpEngine->contentWidget()); - mUi->index->addWidget(mHelpEngine->indexWidget()); - - mUi->textBrowser->setHelpEngine(mHelpEngine); - - mUi->textBrowser->setSource(QUrl("qthelp://cppcheck.sourceforge.net/doc/index.html")); - connect(mHelpEngine->contentWidget(), - SIGNAL(linkActivated(QUrl)), - mUi->textBrowser, - SLOT(setSource(QUrl))); - - connect(mHelpEngine->indexWidget(), - SIGNAL(linkActivated(QUrl, QString)), - mUi->textBrowser, - SLOT(setSource(QUrl))); -} - -HelpDialog::~HelpDialog() -{ - delete mUi; -} diff --git a/gui/helpdialog.h b/gui/helpdialog.h deleted file mode 100644 index e37784437..000000000 --- a/gui/helpdialog.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef HELPDIALOG_H -#define HELPDIALOG_H - -#include -#include - -namespace Ui { - class HelpDialog; -} - -class QHelpEngine; - -class HelpBrowser : public QTextBrowser { -public: - HelpBrowser(QWidget* parent = 0) : QTextBrowser(parent), mHelpEngine(nullptr) {} - void setHelpEngine(QHelpEngine *helpEngine); - QVariant loadResource(int type, const QUrl& name); -private: - QHelpEngine* mHelpEngine; -}; - -class HelpDialog : public QDialog { - Q_OBJECT - -public: - explicit HelpDialog(QWidget *parent = nullptr); - ~HelpDialog(); - -private: - Ui::HelpDialog *mUi; - QHelpEngine* mHelpEngine; -}; - -#endif // HELPDIALOG_H diff --git a/gui/helpdialog.ui b/gui/helpdialog.ui deleted file mode 100644 index 0fb74c6a1..000000000 --- a/gui/helpdialog.ui +++ /dev/null @@ -1,67 +0,0 @@ - - - HelpDialog - - - - 0 - 0 - 635 - 446 - - - - Cppcheck GUI help - - - - - - Qt::Horizontal - - - - - 200 - 16777215 - - - - 0 - - - - Contents - - - - - - - - - - Index - - - - - - - - - - - - - - - - HelpBrowser - QTextBrowser -
helpdialog.h
-
-
- - -
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5a1e8189f..c08361963 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -33,11 +33,11 @@ #include "applicationlist.h" #include "aboutdialog.h" +#include "assistant.h" #include "common.h" #include "filelist.h" #include "fileviewdialog.h" #include "functioncontractdialog.h" -#include "helpdialog.h" #include "librarydialog.h" #include "projectfile.h" #include "projectfiledialog.h" @@ -219,6 +219,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mUI.mActionEnforceCpp->setActionGroup(mSelectLanguageActions); mUI.mActionAutoDetectLanguage->setActionGroup(mSelectLanguageActions); + mAssistant = new Assistant; + // For Windows platforms default to Win32 checked platform. // For other platforms default to unspecified/default which means the // platform Cppcheck GUI was compiled on. @@ -235,6 +237,7 @@ MainWindow::~MainWindow() { delete mProjectFile; delete mScratchPad; + delete mAssistant; } void MainWindow::handleCLIParams(const QStringList ¶ms) @@ -1466,8 +1469,7 @@ void MainWindow::openHelpContents() void MainWindow::openOnlineHelp() { - HelpDialog *helpDialog = new HelpDialog; - helpDialog->showMaximized(); + mAssistant->showDocumentation("index.html"); } void MainWindow::openProjectFile() diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 2ea082d83..05e277265 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -35,6 +35,7 @@ class TranslationHandler; class ScratchPad; class ProjectFile; class QAction; +class Assistant; /// @addtogroup GUI /// @{ @@ -458,6 +459,8 @@ private: * List of MRU menu actions. Needs also to store the separator. */ QAction *mRecentProjectActs[MaxRecentProjects + 1]; + + Assistant *mAssistant; }; /// @} #endif // MAINWINDOW_H diff --git a/man/build-html.sh b/man/build-html.sh old mode 100644 new mode 100755 diff --git a/man/build-pdf.sh b/man/build-pdf.sh old mode 100644 new mode 100755 diff --git a/win_installer/cppcheck.wxs b/win_installer/cppcheck.wxs index efbd44960..c2b65b7a0 100644 --- a/win_installer/cppcheck.wxs +++ b/win_installer/cppcheck.wxs @@ -39,10 +39,12 @@
+ +