Skip to content

Commit 14dfa03

Browse files
committed
GUI: Try to reuse Qt Assistant to show help
1 parent 69893fa commit 14dfa03

12 files changed

Lines changed: 113 additions & 160 deletions

File tree

gui/assistant.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "assistant.h"
2+
3+
#include <QByteArray>
4+
#include <QDir>
5+
#include <QLibraryInfo>
6+
#include <QMessageBox>
7+
#include <QProcess>
8+
9+
Assistant::Assistant()
10+
: mProc(nullptr)
11+
{
12+
}
13+
14+
Assistant::~Assistant()
15+
{
16+
if (mProc && mProc->state() == QProcess::Running) {
17+
mProc->terminate();
18+
mProc->waitForFinished(3000);
19+
}
20+
delete mProc;
21+
}
22+
23+
void Assistant::showDocumentation(const QString &page)
24+
{
25+
if (!startAssistant())
26+
return;
27+
28+
QByteArray ba("SetSource ");
29+
ba.append("qthelp://cppcheck.sourceforge.net/doc/");
30+
31+
mProc->write(ba + page.toLocal8Bit() + '\n');
32+
}
33+
34+
bool Assistant::startAssistant()
35+
{
36+
if (!mProc)
37+
mProc = new QProcess();
38+
39+
if (mProc->state() != QProcess::Running) {
40+
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
41+
#if !defined(Q_OS_MAC)
42+
app += QLatin1String("assistant");
43+
#else
44+
app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
45+
#endif
46+
47+
QStringList args;
48+
args << QLatin1String("-collectionFile")
49+
<< QLatin1String("online-help.qhc")
50+
<< QLatin1String("-enableRemoteControl");
51+
52+
mProc->start(app, args);
53+
54+
if (!mProc->waitForStarted()) {
55+
QMessageBox::critical(nullptr,
56+
tr("Cppcheck"),
57+
tr("Unable to launch Qt Assistant (%1)").arg(app));
58+
return false;
59+
}
60+
}
61+
return true;
62+
}

gui/assistant.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef ASSISTANT_H
2+
#define ASSISTANT_H
3+
4+
#include <QCoreApplication>
5+
#include <QString>
6+
7+
class QProcess;
8+
9+
class Assistant
10+
{
11+
Q_DECLARE_TR_FUNCTIONS(Assistant)
12+
13+
public:
14+
Assistant();
15+
~Assistant();
16+
void showDocumentation(const QString &file);
17+
18+
private:
19+
bool startAssistant();
20+
QProcess *mProc;
21+
};
22+
23+
#endif // ASSISTANT_H

gui/gui.pro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ FORMS = about.ui \
6868
application.ui \
6969
file.ui \
7070
functioncontractdialog.ui \
71-
helpdialog.ui \
7271
mainwindow.ui \
7372
projectfiledialog.ui \
7473
resultsview.ui \
@@ -106,6 +105,7 @@ HEADERS += aboutdialog.h \
106105
application.h \
107106
applicationdialog.h \
108107
applicationlist.h \
108+
assistant.h \
109109
checkstatistics.h \
110110
checkthread.h \
111111
codeeditstylecontrols.h \
@@ -118,7 +118,6 @@ HEADERS += aboutdialog.h \
118118
filelist.h \
119119
fileviewdialog.h \
120120
functioncontractdialog.h \
121-
helpdialog.h \
122121
mainwindow.h \
123122
platforms.h \
124123
printablereport.h \
@@ -147,6 +146,7 @@ SOURCES += aboutdialog.cpp \
147146
application.cpp \
148147
applicationdialog.cpp \
149148
applicationlist.cpp \
149+
assistant.cpp \
150150
checkstatistics.cpp \
151151
checkthread.cpp \
152152
codeeditorstyle.cpp \
@@ -159,7 +159,6 @@ SOURCES += aboutdialog.cpp \
159159
filelist.cpp \
160160
fileviewdialog.cpp \
161161
functioncontractdialog.cpp \
162-
helpdialog.cpp \
163162
main.cpp \
164163
mainwindow.cpp\
165164
platforms.cpp \

gui/help/online-help.qhcp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<QHelpCollectionProject version="1.0">
3+
<assistant>
4+
<title>Cppcheck GUI</title>
5+
<applicationIcon>../cppcheck.ico</applicationIcon>
6+
<cacheDirectory>QtProject/Cppcheck</cacheDirectory>
7+
<startPage>qthelp://cppcheck.sourceforge.net/doc/index.html</startPage>
8+
<aboutMenuText>
9+
<text>About Cppcheck</text>
10+
</aboutMenuText>
11+
<aboutDialog>
12+
<file>about.txt</file>
13+
<icon>images/icon.png</icon>
14+
</aboutDialog>
15+
<enableDocumentationManager>false</enableDocumentationManager>
16+
<enableAddressBar>false</enableAddressBar>
17+
<enableFilterFunctionality>false</enableFilterFunctionality>
18+
</assistant>
319
<docFiles>
420
<generate>
521
<file>

gui/helpdialog.cpp

Lines changed: 0 additions & 53 deletions
This file was deleted.

gui/helpdialog.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

gui/helpdialog.ui

Lines changed: 0 additions & 67 deletions
This file was deleted.

gui/mainwindow.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333

3434
#include "applicationlist.h"
3535
#include "aboutdialog.h"
36+
#include "assistant.h"
3637
#include "common.h"
3738
#include "filelist.h"
3839
#include "fileviewdialog.h"
3940
#include "functioncontractdialog.h"
40-
#include "helpdialog.h"
4141
#include "librarydialog.h"
4242
#include "projectfile.h"
4343
#include "projectfiledialog.h"
@@ -219,6 +219,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
219219
mUI.mActionEnforceCpp->setActionGroup(mSelectLanguageActions);
220220
mUI.mActionAutoDetectLanguage->setActionGroup(mSelectLanguageActions);
221221

222+
mAssistant = new Assistant;
223+
222224
// For Windows platforms default to Win32 checked platform.
223225
// For other platforms default to unspecified/default which means the
224226
// platform Cppcheck GUI was compiled on.
@@ -235,6 +237,7 @@ MainWindow::~MainWindow()
235237
{
236238
delete mProjectFile;
237239
delete mScratchPad;
240+
delete mAssistant;
238241
}
239242

240243
void MainWindow::handleCLIParams(const QStringList &params)
@@ -1466,8 +1469,7 @@ void MainWindow::openHelpContents()
14661469

14671470
void MainWindow::openOnlineHelp()
14681471
{
1469-
HelpDialog *helpDialog = new HelpDialog;
1470-
helpDialog->showMaximized();
1472+
mAssistant->showDocumentation("index.html");
14711473
}
14721474

14731475
void MainWindow::openProjectFile()

gui/mainwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TranslationHandler;
3535
class ScratchPad;
3636
class ProjectFile;
3737
class QAction;
38+
class Assistant;
3839

3940
/// @addtogroup GUI
4041
/// @{
@@ -458,6 +459,8 @@ protected slots:
458459
* List of MRU menu actions. Needs also to store the separator.
459460
*/
460461
QAction *mRecentProjectActs[MaxRecentProjects + 1];
462+
463+
Assistant *mAssistant;
461464
};
462465
/// @}
463466
#endif // MAINWINDOW_H

man/build-html.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)