Assistant.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <QDir>
00028 # include <QLibraryInfo>
00029 # include <QMessageBox>
00030 # include <QProcess>
00031 # include <QTextStream>
00032 #endif
00033
00034 #include "Assistant.h"
00035 #include <Base/Console.h>
00036 #include <App/Application.h>
00037
00038 using namespace Gui;
00039
00040 Assistant::Assistant()
00041 : proc(0)
00042 {
00043 }
00044
00045 Assistant::~Assistant()
00046 {
00047 if (proc && proc->state() == QProcess::Running) {
00048 proc->terminate();
00049 proc->waitForFinished(3000);
00050 }
00051 }
00052
00053 void Assistant::showDocumentation(const QString &page)
00054 {
00055 if (!startAssistant())
00056 return;
00057 if (!page.isEmpty()) {
00058 QTextStream str(proc);
00059 str << QLatin1String("SetSource qthelp://org.freecad.usermanual/doc/")
00060 << page << QLatin1Char('\0') << endl;
00061 }
00062 }
00063
00064 bool Assistant::startAssistant()
00065 {
00066 #if QT_VERSION < 0x040400
00067 QMessageBox::critical(0, QObject::tr("Help"),
00068 QObject::tr("Unable to load documentation.\n"
00069 "In order to load it Qt 4.4 or higher is required."));
00070 return false;
00071 #endif
00072
00073 if (!proc)
00074 proc = new QProcess();
00075
00076 if (proc->state() != QProcess::Running) {
00077 #ifdef Q_OS_WIN
00078 QString app;
00079 app = QDir::convertSeparators(QString::fromUtf8
00080 (App::GetApplication().GetHomePath()) + QLatin1String("bin/"));
00081 #else
00082 QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
00083 #endif
00084 #if !defined(Q_OS_MAC)
00085 app += QLatin1String("assistant");
00086 #else
00087 app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
00088 #endif
00089
00090
00091 QString exe = QString::fromUtf8(App::GetApplication().getExecutableName());
00092 QString doc = QString::fromUtf8(App::Application::getHelpDir().c_str());
00093 QString qhc = doc + exe.toLower() + QLatin1String(".qhc");
00094
00095 static bool first = true;
00096 if (first) {
00097 Base::Console().Log("Help file at %s\n", (const char*)qhc.toUtf8());
00098 first = false;
00099 }
00100
00101 QStringList args;
00102
00103 args << QLatin1String("-collectionFile") << qhc
00104 << QLatin1String("-enableRemoteControl");
00105
00106 proc->start(app, args);
00107
00108 if (!proc->waitForStarted()) {
00109 QMessageBox::critical(0, QObject::tr("%1 Help").arg(exe),
00110 QObject::tr("Unable to launch Qt Assistant (%1)").arg(app));
00111 return false;
00112 }
00113 }
00114
00115 return true;
00116 }