Assistant.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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         // get the name of the executable and the doc path
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 }

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1