summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2010-04-07 16:40:33 +0200
committerkh1 <qt-info@nokia.com>2010-04-07 16:42:12 +0200
commit9e7aa36606bf8f407a3d9169e2253c550624f678 (patch)
tree254368c39bca45ba11fb8c078b1dc37f0af5987c
parentf6db7229b7be5d53e16abfe34ed98b772f1eeb7d (diff)
downloadqt4-tools-9e7aa36606bf8f407a3d9169e2253c550624f678.tar.gz
Fix missing natively supported mime types for help viewer.
Task-number: QTBUG-9651 Reviewed-by: ck
-rw-r--r--tools/assistant/tools/assistant/helpviewer.cpp58
-rw-r--r--tools/assistant/tools/assistant/helpviewer.h1
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.cpp21
3 files changed, 61 insertions, 19 deletions
diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp
index 9b06400bd9..0c51a02818 100644
--- a/tools/assistant/tools/assistant/helpviewer.cpp
+++ b/tools/assistant/tools/assistant/helpviewer.cpp
@@ -63,6 +63,45 @@ QString AbstractHelpViewer::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 }
+};
+
+// -- AbstractHelpViewer
+
AbstractHelpViewer::AbstractHelpViewer()
{
}
@@ -86,9 +125,22 @@ bool AbstractHelpViewer::isLocalUrl(const QUrl &url)
bool AbstractHelpViewer::canOpenPage(const QString &url)
{
TRACE_OBJ
- return url.endsWith(QLatin1String(".html"), Qt::CaseInsensitive)
- || url.endsWith(QLatin1String(".htm"), Qt::CaseInsensitive)
- || url == QLatin1String("about:blank");
+ return !mimeFromUrl(url).isEmpty();
+}
+
+QString AbstractHelpViewer::mimeFromUrl(const QString &url)
+{
+ TRACE_OBJ
+ 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 AbstractHelpViewer::launchWithExternalApp(const QUrl &url)
diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h
index 9e8f5f45f0..246700f7e0 100644
--- a/tools/assistant/tools/assistant/helpviewer.h
+++ b/tools/assistant/tools/assistant/helpviewer.h
@@ -70,6 +70,7 @@ public:
static bool isLocalUrl(const QUrl &url);
static bool canOpenPage(const QString &url);
+ static QString mimeFromUrl(const QString &url);
static bool launchWithExternalApp(const QUrl &url);
};
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
index 582d013b2e..18046a716f 100644
--- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp
+++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
@@ -129,26 +129,15 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
const QNetworkRequest &request, QIODevice* /*outgoingData*/)
{
TRACE_OBJ
- 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");
- }
-
+ const QUrl &url = request.url();
+ const QString &mimeType = AbstractHelpViewer::mimeFromUrl(url.toString());
+
HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
const QByteArray &data = helpEngine.findFile(url).isValid()
? helpEngine.fileData(url)
: AbstractHelpViewer::PageNotFoundMessage.arg(url.toString()).toUtf8();
- return new HelpNetworkReply(request, data, mimeType);
+ return new HelpNetworkReply(request, data, mimeType.isEmpty()
+ ? QLatin1String("application/octet-stream") : mimeType);
}
class HelpPage : public QWebPage