From dbb0a638de177131ec178c6ff7a42b7f1348ff49 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Sat, 18 Jun 2016 12:25:16 +0200 Subject: [PATCH] Integrate user manual into client and launcher UI. --- config-gammaray.h.cmake | 1 + launcher/ui/launcherwindow.cpp | 7 ++ launcher/ui/launcherwindow.h | 1 + launcher/ui/launcherwindow.ui | 2 +- ui/CMakeLists.txt | 1 + ui/helpcontroller.cpp | 128 +++++++++++++++++++++++++++++++++ ui/helpcontroller.h | 57 +++++++++++++++ ui/mainwindow.cpp | 10 +++ ui/mainwindow.h | 1 + ui/mainwindow.ui | 13 ++++ 10 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 ui/helpcontroller.cpp create mode 100644 ui/helpcontroller.h diff --git a/config-gammaray.h.cmake b/config-gammaray.h.cmake index c74b9ad230..499c521c7f 100644 --- a/config-gammaray.h.cmake +++ b/config-gammaray.h.cmake @@ -13,6 +13,7 @@ #define GAMMARAY_BIN_INSTALL_DIR "${BIN_INSTALL_DIR}" #define GAMMARAY_PROBE_INSTALL_DIR "${PROBE_INSTALL_DIR}" #define GAMMARAY_TRANSLATION_INSTALL_DIR "${TRANSLATION_INSTALL_DIR}" +#define GAMMARAY_QCH_INSTALL_DIR "${QCH_INSTALL_DIR}" #define GAMMARAY_PLUGIN_VERSION "${GAMMARAY_PLUGIN_VERSION}" #define GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}${GAMMARAY_PROBE_ABI_POSTFIX}" diff --git a/launcher/ui/launcherwindow.cpp b/launcher/ui/launcherwindow.cpp index 4157e815ee..dd02771871 100644 --- a/launcher/ui/launcherwindow.cpp +++ b/launcher/ui/launcherwindow.cpp @@ -31,6 +31,7 @@ #include "launchoptions.h" #include +#include #include #include @@ -50,6 +51,7 @@ LauncherWindow::LauncherWindow(QWidget *parent) ui->buttonBox->button(QDialogButtonBox::Ok), SLOT(click())); connect(ui->connectPage, SIGNAL(activate()), ui->buttonBox->button(QDialogButtonBox::Ok), SLOT(click())); + connect(ui->buttonBox, SIGNAL(helpRequested()), this, SLOT(help())); setWindowTitle(tr("GammaRay Launcher")); @@ -105,3 +107,8 @@ void LauncherWindow::accept() QDialog::accept(); } +void LauncherWindow::help() +{ + HelpController::openPage("doc/gammaray-launcher-gui.html"); +} + diff --git a/launcher/ui/launcherwindow.h b/launcher/ui/launcherwindow.h index bc8d1d0a18..cdd944f298 100644 --- a/launcher/ui/launcherwindow.h +++ b/launcher/ui/launcherwindow.h @@ -52,6 +52,7 @@ class LauncherWindow : public QDialog private slots: void tabChanged(); + void help(); private: Ui::LauncherWindow *ui; diff --git a/launcher/ui/launcherwindow.ui b/launcher/ui/launcherwindow.ui index e93c0cfd46..afbc62819a 100644 --- a/launcher/ui/launcherwindow.ui +++ b/launcher/ui/launcherwindow.ui @@ -119,7 +119,7 @@ Qt::Horizontal - QDialogButtonBox::Close|QDialogButtonBox::Ok + QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::Ok diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 84b13f8582..6a9029de3b 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -20,6 +20,7 @@ set(gammaray_ui_srcs uiintegration.cpp uistatemanager.cpp remoteviewwidget.cpp + helpcontroller.cpp paintanalyzerwidget.cpp paintbufferviewer.cpp diff --git a/ui/helpcontroller.cpp b/ui/helpcontroller.cpp new file mode 100644 index 0000000000..d96f7b2c00 --- /dev/null +++ b/ui/helpcontroller.cpp @@ -0,0 +1,128 @@ +/* + helpcontroller.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + Licensees holding valid commercial KDAB GammaRay licenses may use this file in + accordance with GammaRay Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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 . +*/ + +#include + +#include "helpcontroller.h" + +#include + +#include +#include +#include +#include +#include +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) +#include +#endif + +using namespace GammaRay; + +namespace GammaRay { + +struct HelpControllerPrivate +{ + HelpControllerPrivate() : proc(Q_NULLPTR) {} + + void startProcess(); + void sendCommand(const QByteArray &cmd); + + QString assistantPath; + QString qhcPath; + QProcess *proc; +}; + +} + +void HelpControllerPrivate::startProcess() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + if (proc) + return; + + proc = new QProcess(QCoreApplication::instance()); + QObject::connect(proc, static_cast(&QProcess::finished), [this](){ + proc->deleteLater(); + proc = Q_NULLPTR; + }); + proc->setProgram(assistantPath); + proc->setArguments(QStringList() << + QLatin1String("-collectionFile") << + qhcPath << + QLatin1String("-enableRemoteControl") + ); + proc->start(); + proc->waitForStarted(); + sendCommand("expandToc 2;"); +#endif +} + +void HelpControllerPrivate::sendCommand(const QByteArray &cmd) +{ + if (!proc) + return; + proc->write(cmd); +} + +Q_GLOBAL_STATIC(HelpControllerPrivate, s_helpController) + +bool HelpController::isAvailable() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + auto d = s_helpController(); + if (!d->assistantPath.isEmpty() && !d->qhcPath.isEmpty()) + return true; + + d->assistantPath = QStandardPaths::findExecutable(QStringLiteral("assistant")); + if (d->assistantPath.isEmpty()) + return false; + + const auto qhcPath = Paths::rootPath() + QLatin1String("/" GAMMARAY_QCH_INSTALL_DIR "/gammaray.qhc"); + if (QFileInfo::exists(qhcPath)) { + d->qhcPath = qhcPath; + return true; + } +#endif + return false; +} + +void HelpController::openContents() +{ + Q_ASSERT(isAvailable()); + auto d = s_helpController(); + d->startProcess(); + d->sendCommand("setSource qthelp://com.kdab.GammaRay." GAMMARAY_PLUGIN_VERSION "/doc/index.html;syncContents\n"); +} + +void HelpController::openPage(const QString &page) +{ + Q_ASSERT(isAvailable()); + auto d = s_helpController(); + d->startProcess(); + d->sendCommand(QByteArray("setSource qthelp://com.kdab.GammaRay." GAMMARAY_PLUGIN_VERSION "/") + page.toUtf8() + ";syncContents\n"); +} diff --git a/ui/helpcontroller.h b/ui/helpcontroller.h new file mode 100644 index 0000000000..65e3dc9ca5 --- /dev/null +++ b/ui/helpcontroller.h @@ -0,0 +1,57 @@ +/* + helpcontroller.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + Licensees holding valid commercial KDAB GammaRay licenses may use this file in + accordance with GammaRay Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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 . +*/ + +#ifndef GAMMARAY_HELPCONTROLLER_H +#define GAMMARAY_HELPCONTROLLER_H + +#include "gammaray_ui_export.h" + +#include + +QT_BEGIN_NAMESPACE +class QString; +QT_END_NAMESPACE + +namespace GammaRay { + +/*! Controls the Assistant-based help browser. */ +namespace HelpController +{ + /*! Returns @c true if Assistant and our help collection are found. */ + GAMMARAY_UI_EXPORT bool isAvailable(); + + /*! Open start page of the help collection. */ + GAMMARAY_UI_EXPORT void openContents(); + + /*! Opens the specified page of the help collection. */ + GAMMARAY_UI_EXPORT void openPage(const QString &page); +} + +} + +#endif // GAMMARAY_HELPCONTROLLER_H diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 82e31fe383..25289b07b6 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -34,6 +34,7 @@ #include "clienttoolmodel.h" #include "aboutdata.h" #include "uiintegration.h" +#include "helpcontroller.h" #include "common/objectbroker.h" #include "common/modelroles.h" @@ -146,6 +147,10 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->actionQuit, SIGNAL(triggered(bool)), this, SLOT(quitHost())); ui->actionQuit->setIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); + ui->actionHelp->setShortcut(QKeySequence::HelpContents); + ui->actionHelp->setEnabled(HelpController::isAvailable()); + + connect(ui->actionHelp, SIGNAL(triggered(bool)), this, SLOT(help())); connect(ui->actionPlugins, SIGNAL(triggered(bool)), this, SLOT(aboutPlugins())); connect(ui->actionMessageStatistics, SIGNAL(triggered(bool)), this, SLOT(showMessageStatistics())); @@ -238,6 +243,11 @@ MainWindow::~MainWindow() { } +void MainWindow::help() +{ + HelpController::openContents(); +} + void MainWindow::about() { AboutDialog dialog(this); diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 2846c5b7f4..cd1c8aa99e 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -66,6 +66,7 @@ class MainWindow : public QMainWindow void targetQuitRequested(); private slots: + void help(); void about(); void aboutPlugins(); void aboutKDAB(); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 04fbd2cea6..16e633fe41 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -129,6 +129,8 @@ background-position:bottom right; + + @@ -233,6 +235,17 @@ background-position:bottom right; Show GammaRay communication statistics. + + + + + + &Help... + + + Show help browser. + +