summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2010-04-19 19:08:02 +0200
committercon <qtc-committer@nokia.com>2010-04-19 19:09:58 +0200
commitfb0b092872588c65da01ff5fc22597c955c44508 (patch)
tree0bbcdc30854ae151d03802038fd1e7c1e136ec92
parent04a5b9137ad790971691a29b6ab727d0246115bf (diff)
downloadqt-creator-fb0b092872588c65da01ff5fc22597c955c44508.tar.gz
Quick fix to make the documentation work, needs a proper solution though.
Reviewed-by: kh (cherry picked from commit 342e62125312b471a82f03b955c977ef4feb5371)
-rw-r--r--src/plugins/help/helpviewer.cpp59
-rw-r--r--src/plugins/help/helpviewer.h2
-rw-r--r--src/plugins/help/helpviewer_qwv.cpp35
3 files changed, 77 insertions, 19 deletions
diff --git a/src/plugins/help/helpviewer.cpp b/src/plugins/help/helpviewer.cpp
index a3a7bd2ecf..d8726a99cb 100644
--- a/src/plugins/help/helpviewer.cpp
+++ b/src/plugins/help/helpviewer.cpp
@@ -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)
diff --git a/src/plugins/help/helpviewer.h b/src/plugins/help/helpviewer.h
index 9ad9e516f0..d49f3d1e14 100644
--- a/src/plugins/help/helpviewer.h
+++ b/src/plugins/help/helpviewer.h
@@ -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:
diff --git a/src/plugins/help/helpviewer_qwv.cpp b/src/plugins/help/helpviewer_qwv.cpp
index e15f2136d0..7020a2b018 100644
--- a/src/plugins/help/helpviewer_qwv.cpp
+++ b/src/plugins/help/helpviewer_qwv.cpp
@@ -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