-
Notifications
You must be signed in to change notification settings - Fork 34
/
assistantcontroller.cpp
90 lines (77 loc) · 3.56 KB
/
assistantcontroller.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/***************************************************************************
* Copyright (C) 2010 by Glad Deschrijver *
* <[email protected]> *
* *
* 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 2 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/>. *
***************************************************************************/
#include "assistantcontroller.h"
#include <QtCore/QByteArray>
#include <QtCore/QDir>
#include <QtCore/QLibraryInfo>
#include <QtCore/QProcess>
#include <QtWidgets/QMessageBox>
#include "ktikzapplication.h"
AssistantController::AssistantController() : m_process(0) { }
AssistantController::~AssistantController()
{
if (m_process && m_process->state() == QProcess::Running) {
m_process->terminate();
m_process->waitForFinished(3000);
}
delete m_process;
}
bool AssistantController::startAssistant()
{
if (!m_process)
m_process = new QProcess();
if (m_process->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
const QString ktikzDocFile = QString::fromLocal8Bit(KTIKZ_DOCUMENTATION_INSTALL_DIR)
+ QLatin1String("/qtikz.qhc");
if (!QFileInfo(ktikzDocFile).isReadable()) {
QMessageBox::critical(0, KtikzApplication::applicationName(),
QCoreApplication::translate("AssistantController",
"Unable to open the help file (%1)")
.arg(ktikzDocFile));
return false;
}
QStringList args;
args << QLatin1String("-collectionFile") << ktikzDocFile
<< QLatin1String("-enableRemoteControl");
m_process->start(app, args);
if (!m_process->waitForStarted()) {
QMessageBox::critical(0, KtikzApplication::applicationName(),
QCoreApplication::translate("AssistantController",
"Unable to launch Qt Assistant (%1)")
.arg(app));
return false;
}
}
return true;
}
void AssistantController::showDocumentation(const QString &page)
{
if (!startAssistant())
return;
if (!page.isEmpty()) {
QByteArray ba;
ba.append("setSource qthelp://hackenberger.qtikz/doc/");
m_process->write(ba + page.toLocal8Bit() + '\0');
}
}