forked from qt-creator/qt-creator
And do not save the default page anywhere at all. This simplifies the logic, and makes the setting independent of help engine initialization. Change-Id: I264903229e274a0bf25c18b33734d36432aa525f Task-number: QTCREATORBUG-13198 Reviewed-by: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
175 lines
5.1 KiB
C++
175 lines
5.1 KiB
C++
/****************************************************************************
|
|
**
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
** Contact: http://www.qt-project.org/legal
|
|
**
|
|
** This file is part of Qt Creator.
|
|
**
|
|
** 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
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
** use the contact form at http://www.qt.io/contact-us.
|
|
**
|
|
** GNU Lesser General Public License Usage
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
** following information to ensure the GNU Lesser General Public License
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
**
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
**
|
|
****************************************************************************/
|
|
|
|
#include "helpviewer.h"
|
|
#include "helpconstants.h"
|
|
#include "localhelpmanager.h"
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
#include <QFileInfo>
|
|
#include <QStringBuilder>
|
|
#include <QDir>
|
|
#include <QUrl>
|
|
|
|
#include <QApplication>
|
|
#include <QDesktopServices>
|
|
#include <QMouseEvent>
|
|
|
|
#include <QHelpEngine>
|
|
|
|
using namespace Help::Internal;
|
|
|
|
struct ExtensionMap {
|
|
const char *extension;
|
|
const char *mimeType;
|
|
} extensionMap[] = {
|
|
{ ".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 }
|
|
};
|
|
|
|
HelpViewer::HelpViewer(QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
}
|
|
|
|
bool HelpViewer::isLocalUrl(const QUrl &url)
|
|
{
|
|
return url.scheme() == QLatin1String("about") // "No documenation available"
|
|
|| url.scheme() == QLatin1String("qthelp");
|
|
}
|
|
|
|
bool HelpViewer::canOpenPage(const QString &url)
|
|
{
|
|
return !mimeFromUrl(url).isEmpty();
|
|
}
|
|
|
|
QString HelpViewer::mimeFromUrl(const QUrl &url)
|
|
{
|
|
const QString &path = url.path();
|
|
const int index = path.lastIndexOf(QLatin1Char('.'));
|
|
const QByteArray &ext = path.mid(index).toUtf8().toLower();
|
|
|
|
const ExtensionMap *e = extensionMap;
|
|
while (e->extension) {
|
|
if (ext == e->extension)
|
|
return QLatin1String(e->mimeType);
|
|
++e;
|
|
}
|
|
return QLatin1String("");
|
|
}
|
|
|
|
bool HelpViewer::launchWithExternalApp(const QUrl &url)
|
|
{
|
|
if (isLocalUrl(url)) {
|
|
const QHelpEngineCore &helpEngine = LocalHelpManager::helpEngine();
|
|
const QUrl &resolvedUrl = helpEngine.findFile(url);
|
|
if (!resolvedUrl.isValid())
|
|
return false;
|
|
|
|
const QString& path = resolvedUrl.path();
|
|
if (!canOpenPage(path)) {
|
|
Utils::TempFileSaver saver(QDir::tempPath()
|
|
+ QLatin1String("/qtchelp_XXXXXX.") + QFileInfo(path).completeSuffix());
|
|
saver.setAutoRemove(false);
|
|
if (!saver.hasError())
|
|
saver.write(helpEngine.fileData(resolvedUrl));
|
|
if (saver.finalize(Core::ICore::mainWindow()))
|
|
QDesktopServices::openUrl(QUrl(saver.fileName()));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
QDesktopServices::openUrl(url);
|
|
return true;
|
|
}
|
|
|
|
void HelpViewer::home()
|
|
{
|
|
setSource(LocalHelpManager::homePage());
|
|
}
|
|
|
|
void HelpViewer::slotLoadStarted()
|
|
{
|
|
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
}
|
|
|
|
void HelpViewer::slotLoadFinished()
|
|
{
|
|
qApp->restoreOverrideCursor();
|
|
emit sourceChanged(source());
|
|
emit loadFinished();
|
|
}
|
|
|
|
bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::XButton1) {
|
|
backward();
|
|
return true;
|
|
}
|
|
if (event->button() == Qt::XButton2) {
|
|
forward();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|