diff options
author | kh1 <qt-info@nokia.com> | 2010-04-07 14:40:33 (GMT) |
---|---|---|
committer | kh1 <qt-info@nokia.com> | 2010-04-07 14:42:12 (GMT) |
commit | 9e7aa36606bf8f407a3d9169e2253c550624f678 (patch) | |
tree | 254368c39bca45ba11fb8c078b1dc37f0af5987c /tools | |
parent | f6db7229b7be5d53e16abfe34ed98b772f1eeb7d (diff) | |
download | Qt-9e7aa36606bf8f407a3d9169e2253c550624f678.zip Qt-9e7aa36606bf8f407a3d9169e2253c550624f678.tar.gz Qt-9e7aa36606bf8f407a3d9169e2253c550624f678.tar.bz2 |
Fix missing natively supported mime types for help viewer.
Task-number: QTBUG-9651
Reviewed-by: ck
Diffstat (limited to 'tools')
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.cpp | 58 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.h | 1 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer_qwv.cpp | 21 |
3 files changed, 61 insertions, 19 deletions
diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index 9b06400..0c51a02 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 9e8f5f4..246700f 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 582d013..18046a7 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 |