forked from cppcheck-opensource/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassistant.cpp
More file actions
62 lines (51 loc) · 1.44 KB
/
assistant.cpp
File metadata and controls
62 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "assistant.h"
#include <QByteArray>
#include <QDir>
#include <QLibraryInfo>
#include <QMessageBox>
#include <QProcess>
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;
}