1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
27
# include <QCoreApplication>
30
# include <QLibraryInfo>
31
# include <QMessageBox>
33
# include <QTextStream>
36
#include <App/Application.h>
37
#include <Base/Console.h>
42
/* TRANSLATOR Gui::Assistant */
49
Assistant::~Assistant()
51
if (proc && proc->state() == QProcess::Running) {
53
proc->waitForFinished(3000);
57
void Assistant::showDocumentation(const QString &page)
59
if (!startAssistant())
61
if (!page.isEmpty()) {
62
QTextStream str(proc);
63
str << QLatin1String("setSource qthelp://org.freecad.usermanual/doc/")
64
<< page << QLatin1String("\n\n");
68
bool Assistant::startAssistant()
71
proc = new QProcess();
72
connect(proc, &QProcess::readyReadStandardOutput,
73
this, &Assistant::readyReadStandardOutput);
74
connect(proc, &QProcess::readyReadStandardError,
75
this, &Assistant::readyReadStandardError);
78
if (proc->state() != QProcess::Running) {
81
app = QDir::toNativeSeparators(QString::fromStdString
82
(App::Application::getHomePath()) + QLatin1String("bin/"));
83
#elif defined(Q_OS_MACOS)
84
QString app = QCoreApplication::applicationDirPath() + QDir::separator();
86
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
87
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
89
QString app = QLibraryInfo::path(QLibraryInfo::BinariesPath) + QDir::separator();
92
app += QLatin1String("assistant");
94
// get the name of the executable and the doc path
95
QString exe = QString::fromStdString(App::Application::getExecutableName());
96
QString doc = QString::fromStdString(App::Application::getHelpDir());
97
QString qhc = doc + exe.toLower() + QLatin1String(".qhc");
101
if (!fi.isReadable()) {
102
QMessageBox::critical(nullptr, tr("%1 Help").arg(exe),
103
tr("%1 help files not found (%2). You might need to install the %1 documentation package.").arg(exe, qhc));
107
static bool first = true;
109
Base::Console().Log("Help file at %s\n", (const char*)qhc.toUtf8());
114
// AppImage mount location changes on each start. Assistant caches freecad.qhc
115
// file and sets an absolute path. As a result embedded documentation only works
116
// on the first AppImage (help) run. Register the .gch file, to overcome the issue.
117
static bool start = true;
119
char* appimage = getenv("APPIMAGE");
121
QString qch = doc + exe.toLower() + QLatin1String(".qch");
123
if (fi.isReadable()) {
124
// Assume documentation is embedded
125
// Unregister qch file (path) from previous AppImage run
128
args << QLatin1String("-collectionFile") << qhc
129
<< QLatin1String("-unregister") << qch;
131
proc->start(app, args);
133
if (!proc->waitForFinished(50000)) {
134
QMessageBox::critical(nullptr, tr("%1 Help").arg(exe),
135
tr("Unable to launch Qt Assistant (%1)").arg(app));
139
// Register qch file (path) for current AppImage run
142
args << QLatin1String("-collectionFile") << qhc
143
<< QLatin1String("-register") << qch;
145
proc->start(app, args);
147
if (!proc->waitForFinished(50000)) {
148
QMessageBox::critical(nullptr, tr("%1 Help").arg(exe),
149
tr("Unable to launch Qt Assistant (%1)").arg(app));
160
args << QLatin1String("-collectionFile") << qhc
161
<< QLatin1String("-enableRemoteControl");
163
proc->start(app, args);
165
if (!proc->waitForStarted()) {
166
QMessageBox::critical(nullptr, tr("%1 Help").arg(exe),
167
tr("Unable to launch Qt Assistant (%1)").arg(app));
175
void Assistant::readyReadStandardOutput()
177
QByteArray data = proc->readAllStandardOutput();
178
Base::Console().Log("Help view: %s\n", data.constData());
181
void Assistant::readyReadStandardError()
183
QByteArray data = proc->readAllStandardError();
184
Base::Console().Log("Help view: %s\n", data.constData());
187
#include "moc_Assistant.cpp"