Commit 342e6212 authored by kh1's avatar kh1
Browse files

Quick fix to make the documentation work, needs a proper solution though.

Reviewed-by: kh
parent 2113669f
......@@ -44,6 +44,10 @@
using namespace Help::Internal;
QString HelpViewer::DocPath = QString::fromLatin1("qthelp://com."
"trolltech.qt.%1/").arg(QString(QLatin1String(QT_VERSION_STR))
.replace(QLatin1String("."), QLatin1String("")));
QString HelpViewer::AboutBlankPage =
QCoreApplication::translate("HelpViewer", "<title>about:blank</title>");
......@@ -52,6 +56,43 @@ QString HelpViewer::PageNotFoundMessage =
"align=\"center\"><br><br><h1>The page could not be found</h1><br><h3>'%1'"
"</h3></div>");
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 }
};
bool HelpViewer::isLocalUrl(const QUrl &url)
{
const QString &scheme = url.scheme();
......@@ -65,9 +106,21 @@ bool HelpViewer::isLocalUrl(const QUrl &url)
bool HelpViewer::canOpenPage(const QString &url)
{
return url.endsWith(QLatin1String(".html"), Qt::CaseInsensitive)
|| url.endsWith(QLatin1String(".htm"), Qt::CaseInsensitive)
|| url == Help::Constants::AboutBlank;
return !mimeFromUrl(url).isEmpty();
}
QString HelpViewer::mimeFromUrl(const QString &url)
{
const int index = url.lastIndexOf(QLatin1Char('.'));
const QByteArray &ext = url.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)
......
......@@ -85,11 +85,13 @@ public:
bool findText(const QString &text, Find::IFindSupport::FindFlags flags,
bool incremental, bool fromSearch);
static QString DocPath;
static QString AboutBlankPage;
static QString PageNotFoundMessage;
static bool isLocalUrl(const QUrl &url);
static bool canOpenPage(const QString &url);
static QString mimeFromUrl(const QString &url);
static bool launchWithExternalApp(const QUrl &url);
public slots:
......
......@@ -124,25 +124,28 @@ HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent)
QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
const QNetworkRequest &request, QIODevice* /*outgoingData*/)
{
const QUrl& url = request.url();
QString mimeType = url.toString();
if (mimeType.endsWith(QLatin1String(".svg"))
|| mimeType.endsWith(QLatin1String(".svgz"))) {
mimeType = QLatin1String("image/svg+xml");
} else if (mimeType.endsWith(QLatin1String(".css"))) {
mimeType = QLatin1String("text/css");
} else if (mimeType.endsWith(QLatin1String(".js"))) {
mimeType = QLatin1String("text/javascript");
} else if (mimeType.endsWith(QLatin1String(".txt"))) {
mimeType = QLatin1String("text/plain");
} else {
mimeType = QLatin1String("text/html");
QString url = request.url().toString();
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
// TODO: For some reason the url to load is already wrong (passed from webkit)
// though the css file and the references inside should work that way. One
// possible problem might be that the css is loaded at the same level as the
// html, thus a path inside the css like (../images/foo.png) might cd out of
// the virtual folder
if (!engine.findFile(url).isValid()) {
if (url.startsWith(HelpViewer::DocPath)) {
if (!url.startsWith(HelpViewer::DocPath + "qdoc/")) {
url = url.replace(HelpViewer::DocPath,
HelpViewer::DocPath + QLatin1String("qdoc/"));
}
}
}
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
const QString &mimeType = HelpViewer::mimeFromUrl(url);
const QByteArray &data = engine.findFile(url).isValid() ? engine.fileData(url)
: HelpViewer::PageNotFoundMessage.arg(url.toString()).toUtf8();
return new HelpNetworkReply(request, data, mimeType);
: HelpViewer::PageNotFoundMessage.arg(url).toUtf8();
return new HelpNetworkReply(request, data, mimeType.isEmpty()
? QLatin1String("application/octet-stream") : mimeType);
}
// -- HelpPage
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment