From 262d37fb476e2f5a3c82624ffac7662f556624df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 25 Aug 2020 19:58:52 +0200 Subject: [PATCH] windows installer: another attempt to make help work. the 'contents' are shown now but for some reason the 'index' is not. --- .github/workflows/release-windows.yml | 7 ++- gui/assistant.cpp | 62 ------------------- gui/assistant.h | 22 ------- gui/gui.pro | 5 +- gui/helpdialog.cpp | 87 +++++++++++++++++++++++++++ gui/helpdialog.h | 34 +++++++++++ gui/helpdialog.ui | 67 +++++++++++++++++++++ gui/mainwindow.cpp | 8 +-- gui/mainwindow.h | 3 - win_installer/cppcheck.wxs | 10 ++- win_installer/productInfo.wxi | 1 + 11 files changed, 209 insertions(+), 97 deletions(-) delete mode 100644 gui/assistant.cpp delete mode 100644 gui/assistant.h create mode 100644 gui/helpdialog.cpp create mode 100644 gui/helpdialog.h create mode 100644 gui/helpdialog.ui diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml index 49961914f..7a3a9b593 100644 --- a/.github/workflows/release-windows.yml +++ b/.github/workflows/release-windows.yml @@ -92,5 +92,10 @@ jobs: - uses: actions/upload-artifact@v2 with: - name: Build + name: installer path: win_installer/Build/ + + - uses: actions/upload-artifact@v2 + with: + name: deploy + path: Build\gui diff --git a/gui/assistant.cpp b/gui/assistant.cpp deleted file mode 100644 index 90d9b1aa2..000000000 --- a/gui/assistant.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#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 deleted file mode 100644 index a65913823..000000000 --- a/gui/assistant.h +++ /dev/null @@ -1,22 +0,0 @@ -#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 cfc4d921d..841fe4383 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -68,6 +68,7 @@ FORMS = about.ui \ application.ui \ file.ui \ functioncontractdialog.ui \ + helpdialog.ui \ mainwindow.ui \ projectfiledialog.ui \ resultsview.ui \ @@ -106,7 +107,6 @@ HEADERS += aboutdialog.h \ application.h \ applicationdialog.h \ applicationlist.h \ - assistant.h \ checkstatistics.h \ checkthread.h \ codeeditstylecontrols.h \ @@ -119,6 +119,7 @@ HEADERS += aboutdialog.h \ filelist.h \ fileviewdialog.h \ functioncontractdialog.h \ + helpdialog.h \ mainwindow.h \ platforms.h \ printablereport.h \ @@ -148,7 +149,6 @@ SOURCES += aboutdialog.cpp \ application.cpp \ applicationdialog.cpp \ applicationlist.cpp \ - assistant.cpp \ checkstatistics.cpp \ checkthread.cpp \ codeeditorstyle.cpp \ @@ -161,6 +161,7 @@ SOURCES += aboutdialog.cpp \ filelist.cpp \ fileviewdialog.cpp \ functioncontractdialog.cpp \ + helpdialog.cpp \ main.cpp \ mainwindow.cpp\ platforms.cpp \ diff --git a/gui/helpdialog.cpp b/gui/helpdialog.cpp new file mode 100644 index 000000000..dfa7cbde6 --- /dev/null +++ b/gui/helpdialog.cpp @@ -0,0 +1,87 @@ +#include "helpdialog.h" +#include "ui_helpdialog.h" + +#include +#include +#include +#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); +} + +static QString getHelpFile() +{ + QSettings settings; + const QString datadir = settings.value("DATADIR", QString()).toString(); + + QStringList paths; + paths << (datadir + "/help") + << datadir + << (QApplication::applicationDirPath() + "/help") + << QApplication::applicationDirPath(); + for (QString p: paths) { + 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); + 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 new file mode 100644 index 000000000..e37784437 --- /dev/null +++ b/gui/helpdialog.h @@ -0,0 +1,34 @@ +#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 new file mode 100644 index 000000000..025fa2b0f --- /dev/null +++ b/gui/helpdialog.ui @@ -0,0 +1,67 @@ + + + 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 39b812d5b..d7252bfb0 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" @@ -223,8 +223,6 @@ 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. @@ -241,7 +239,6 @@ MainWindow::~MainWindow() { delete mProjectFile; delete mScratchPad; - delete mAssistant; } void MainWindow::handleCLIParams(const QStringList ¶ms) @@ -1493,7 +1490,8 @@ void MainWindow::openHelpContents() void MainWindow::openOnlineHelp() { - mAssistant->showDocumentation("index.html"); + HelpDialog *helpDialog = new HelpDialog; + helpDialog->showMaximized(); } void MainWindow::openProjectFile() diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 913a464e9..006a6d720 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -35,7 +35,6 @@ class TranslationHandler; class ScratchPad; class ProjectFile; class QAction; -class Assistant; /// @addtogroup GUI /// @{ @@ -472,8 +471,6 @@ private: * List of MRU menu actions. Needs also to store the separator. */ QAction *mRecentProjectActs[MaxRecentProjects + 1]; - - Assistant *mAssistant; }; /// @} #endif // MAINWINDOW_H diff --git a/win_installer/cppcheck.wxs b/win_installer/cppcheck.wxs index c2b65b7a0..d163932d8 100644 --- a/win_installer/cppcheck.wxs +++ b/win_installer/cppcheck.wxs @@ -39,12 +39,10 @@ - - @@ -61,6 +59,13 @@ + + + + + + + @@ -183,6 +188,7 @@ + diff --git a/win_installer/productInfo.wxi b/win_installer/productInfo.wxi index 7c910c35e..cf513c7e2 100644 --- a/win_installer/productInfo.wxi +++ b/win_installer/productInfo.wxi @@ -15,6 +15,7 @@ +