2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-29 19:16:23 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-03-29 19:16:23 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: 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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QStringBuilder>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#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[] = {
|
|
|
|
|
{ ".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 }
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-02 16:54:28 +02:00
|
|
|
HelpViewer::HelpViewer(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-29 19:16:23 +02:00
|
|
|
bool HelpViewer::isLocalUrl(const QUrl &url)
|
|
|
|
|
{
|
2013-10-29 15:22:30 +01:00
|
|
|
return url.scheme() == QLatin1String("about") // "No documenation available"
|
|
|
|
|
|| url.scheme() == QLatin1String("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;
|
|
|
|
|
}
|
|
|
|
|
return QLatin1String("");
|
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)) {
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::TempFileSaver saver(QDir::tempPath()
|
|
|
|
|
+ QLatin1String("/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()
|
|
|
|
|
{
|
2010-06-11 13:11:37 +02:00
|
|
|
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
|
2010-03-29 19:16:23 +02:00
|
|
|
QString homepage = engine.customValue(QLatin1String("HomePage"),
|
|
|
|
|
QLatin1String("")).toString();
|
|
|
|
|
|
|
|
|
|
if (homepage.isEmpty()) {
|
|
|
|
|
homepage = engine.customValue(QLatin1String("DefaultHomePage"),
|
|
|
|
|
Help::Constants::AboutBlank).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSource(homepage);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|