2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-29 19:16:23 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-03-29 19:16:23 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-03-29 19:16:23 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-03-29 19:16:23 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-03-29 19:16:23 +02:00
|
|
|
|
|
|
|
|
#include "helpviewer.h"
|
|
|
|
|
#include "helpconstants.h"
|
2010-11-16 14:15:23 +01:00
|
|
|
#include "localhelpmanager.h"
|
2010-03-29 19:16:23 +02:00
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/fileutils.h>
|
2017-01-19 16:44:22 +01:00
|
|
|
#include <utils/temporarydirectory.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QUrl>
|
2010-03-29 19:16:23 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopServices>
|
|
|
|
|
#include <QMouseEvent>
|
2010-03-29 19:16:23 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHelpEngine>
|
2010-03-29 19:16:23 +02:00
|
|
|
|
|
|
|
|
using namespace Help::Internal;
|
|
|
|
|
|
2010-04-19 19:08:02 +02:00
|
|
|
struct ExtensionMap {
|
|
|
|
|
const char *extension;
|
|
|
|
|
const char *mimeType;
|
|
|
|
|
} extensionMap[] = {
|
2017-02-22 15:09:35 +01:00
|
|
|
{".bmp", "image/bmp"},
|
|
|
|
|
{".css", "text/css"},
|
|
|
|
|
{".gif", "image/gif"},
|
|
|
|
|
{".html", "text/html"},
|
|
|
|
|
{".htm", "text/html"},
|
|
|
|
|
{".ico", "image/x-icon"},
|
|
|
|
|
{".jpeg", "image/jpeg"},
|
|
|
|
|
{".jpg", "image/jpeg"},
|
|
|
|
|
{".js", "application/x-javascript"},
|
|
|
|
|
{".mng", "video/x-mng"},
|
|
|
|
|
{".pbm", "image/x-portable-bitmap"},
|
|
|
|
|
{".pgm", "image/x-portable-graymap"},
|
|
|
|
|
{".pdf", "application/pdf"},
|
|
|
|
|
{".png", "image/png"},
|
|
|
|
|
{".ppm", "image/x-portable-pixmap"},
|
|
|
|
|
{".rss", "application/rss+xml"},
|
|
|
|
|
{".svg", "image/svg+xml"},
|
|
|
|
|
{".svgz", "image/svg+xml"},
|
|
|
|
|
{".text", "text/plain"},
|
|
|
|
|
{".tif", "image/tiff"},
|
|
|
|
|
{".tiff", "image/tiff"},
|
|
|
|
|
{".txt", "text/plain"},
|
|
|
|
|
{".xbm", "image/x-xbitmap"},
|
|
|
|
|
{".xml", "text/xml"},
|
|
|
|
|
{".xpm", "image/x-xpm"},
|
|
|
|
|
{".xsl", "text/xsl"},
|
|
|
|
|
{".xhtml", "application/xhtml+xml"},
|
|
|
|
|
{".wml", "text/vnd.wap.wml"},
|
|
|
|
|
{".wmlc", "application/vnd.wap.wmlc"},
|
|
|
|
|
{"about:blank", 0},
|
|
|
|
|
{0, 0}
|
2010-04-19 19:08:02 +02:00
|
|
|
};
|
|
|
|
|
|
2014-05-02 16:54:28 +02:00
|
|
|
HelpViewer::HelpViewer(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 15:37:01 +02:00
|
|
|
void HelpViewer::setActionVisible(Action action, bool visible)
|
|
|
|
|
{
|
|
|
|
|
if (visible)
|
|
|
|
|
m_visibleActions |= Actions(action);
|
|
|
|
|
else
|
|
|
|
|
m_visibleActions &= ~Actions(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HelpViewer::isActionVisible(HelpViewer::Action action)
|
|
|
|
|
{
|
|
|
|
|
return (m_visibleActions & Actions(action)) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-29 19:16:23 +02:00
|
|
|
bool HelpViewer::isLocalUrl(const QUrl &url)
|
|
|
|
|
{
|
2016-07-20 10:11:35 +02:00
|
|
|
return url.scheme() == "about" // "No documenation available"
|
|
|
|
|
|| url.scheme() == "qthelp";
|
2010-03-29 19:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HelpViewer::canOpenPage(const QString &url)
|
|
|
|
|
{
|
2010-04-19 19:08:02 +02:00
|
|
|
return !mimeFromUrl(url).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-20 16:15:21 +02:00
|
|
|
QString HelpViewer::mimeFromUrl(const QUrl &url)
|
2010-04-19 19:08:02 +02:00
|
|
|
{
|
2010-04-20 16:15:21 +02:00
|
|
|
const QString &path = url.path();
|
|
|
|
|
const int index = path.lastIndexOf(QLatin1Char('.'));
|
|
|
|
|
const QByteArray &ext = path.mid(index).toUtf8().toLower();
|
2010-04-19 19:08:02 +02:00
|
|
|
|
|
|
|
|
const ExtensionMap *e = extensionMap;
|
|
|
|
|
while (e->extension) {
|
|
|
|
|
if (ext == e->extension)
|
|
|
|
|
return QLatin1String(e->mimeType);
|
|
|
|
|
++e;
|
|
|
|
|
}
|
2016-07-21 08:35:30 +02:00
|
|
|
return QString();
|
2010-03-29 19:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HelpViewer::launchWithExternalApp(const QUrl &url)
|
|
|
|
|
{
|
|
|
|
|
if (isLocalUrl(url)) {
|
2010-06-11 13:11:37 +02:00
|
|
|
const QHelpEngineCore &helpEngine = LocalHelpManager::helpEngine();
|
2010-03-29 19:16:23 +02:00
|
|
|
const QUrl &resolvedUrl = helpEngine.findFile(url);
|
|
|
|
|
if (!resolvedUrl.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const QString& path = resolvedUrl.path();
|
|
|
|
|
if (!canOpenPage(path)) {
|
2017-01-19 16:44:22 +01:00
|
|
|
Utils::TempFileSaver saver(Utils::TemporaryDirectory::masterDirectoryPath()
|
2016-07-20 10:11:35 +02:00
|
|
|
+ "/qtchelp_XXXXXX." + QFileInfo(path).completeSuffix());
|
2011-12-09 09:41:40 +01:00
|
|
|
saver.setAutoRemove(false);
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!saver.hasError())
|
|
|
|
|
saver.write(helpEngine.fileData(resolvedUrl));
|
2012-01-24 15:36:40 +01:00
|
|
|
if (saver.finalize(Core::ICore::mainWindow()))
|
2013-10-18 08:43:10 +02:00
|
|
|
QDesktopServices::openUrl(QUrl(saver.fileName()));
|
|
|
|
|
return true;
|
2010-03-29 19:16:23 +02:00
|
|
|
}
|
2013-10-18 08:43:10 +02:00
|
|
|
return false;
|
2010-03-29 19:16:23 +02:00
|
|
|
}
|
2013-10-18 08:43:10 +02:00
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
|
return true;
|
2010-03-29 19:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HelpViewer::home()
|
|
|
|
|
{
|
2014-10-22 14:47:04 +02:00
|
|
|
setSource(LocalHelpManager::homePage());
|
2010-03-29 19:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
2011-01-11 13:16:12 +01:00
|
|
|
void HelpViewer::slotLoadStarted()
|
|
|
|
|
{
|
|
|
|
|
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 16:54:28 +02:00
|
|
|
void HelpViewer::slotLoadFinished()
|
2011-01-11 13:16:12 +01:00
|
|
|
{
|
|
|
|
|
qApp->restoreOverrideCursor();
|
2014-05-02 16:54:28 +02:00
|
|
|
emit sourceChanged(source());
|
|
|
|
|
emit loadFinished();
|
2011-01-11 13:16:12 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-29 19:16:23 +02:00
|
|
|
bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->button() == Qt::XButton1) {
|
|
|
|
|
backward();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (event->button() == Qt::XButton2) {
|
|
|
|
|
forward();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|