diff options
author | Pierre Rossi <pierre.rossi@nokia.com> | 2012-08-15 11:38:00 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-15 13:53:41 (GMT) |
commit | bad264d4329a41402d5791e3ee8f8a0c83bb0c8c (patch) | |
tree | 57f2a57a24faaa8c90d12bfaeabe0e95f491a5ec | |
parent | 59d7bac9fb37178d9ec025dd91fb32f08e655d4d (diff) | |
download | Qt-bad264d4329a41402d5791e3ee8f8a0c83bb0c8c.zip Qt-bad264d4329a41402d5791e3ee8f8a0c83bb0c8c.tar.gz Qt-bad264d4329a41402d5791e3ee8f8a0c83bb0c8c.tar.bz2 |
Prepare QtHelp library for modularized documentation.
- Support ".." in QCH documentation file paths.
This essentially means that we stop using cleanPath, and where needed,
prepend the virtual folder name, followed by "/..", in front of the
original path.
- Remove com.trolltech default DocPath since this was not used anymore.
(Cherry picked from Qt5: I7309805000f343e2f58c74cd0655a936399fd939)
Change-Id: I6508529de756bad979356c63bfcf6c55a609e827
Done-with: Casper van Donderen <casper.vandonderen@nokia.com>
Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
-rw-r--r-- | tools/assistant/lib/qhelpcontentwidget.cpp | 3 | ||||
-rw-r--r-- | tools/assistant/lib/qhelpengine.h | 2 | ||||
-rw-r--r-- | tools/assistant/lib/qhelpengine_p.h | 2 | ||||
-rw-r--r-- | tools/assistant/lib/qhelpenginecore.cpp | 10 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpenginewrapper.cpp | 7 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpenginewrapper.h | 3 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.cpp | 29 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.h | 4 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer_qtb.cpp | 13 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer_qwv.cpp | 22 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/mainwindow.cpp | 1 |
11 files changed, 65 insertions, 31 deletions
diff --git a/tools/assistant/lib/qhelpcontentwidget.cpp b/tools/assistant/lib/qhelpcontentwidget.cpp index ab6f54b..a8f0a3f 100644 --- a/tools/assistant/lib/qhelpcontentwidget.cpp +++ b/tools/assistant/lib/qhelpcontentwidget.cpp @@ -44,7 +44,6 @@ #include "qhelpengine_p.h" #include "qhelpdbreader_p.h" -#include <QtCore/QDir> #include <QtCore/QStack> #include <QtCore/QThread> #include <QtCore/QMutex> @@ -557,7 +556,7 @@ bool QHelpContentWidget::searchContentItem(QHelpContentModel *model, if (!parentItem) return false; - if (QDir::cleanPath(parentItem->url().path()) == path) { + if (parentItem->url().path() == path) { m_syncIndex = parent; return true; } diff --git a/tools/assistant/lib/qhelpengine.h b/tools/assistant/lib/qhelpengine.h index f99cc41..3c34648 100644 --- a/tools/assistant/lib/qhelpengine.h +++ b/tools/assistant/lib/qhelpengine.h @@ -75,6 +75,8 @@ public: private: QHelpEnginePrivate *d; + + friend class HelpEngineWrapper; }; QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpengine_p.h b/tools/assistant/lib/qhelpengine_p.h index c8d9d06..48412a0 100644 --- a/tools/assistant/lib/qhelpengine_p.h +++ b/tools/assistant/lib/qhelpengine_p.h @@ -53,6 +53,7 @@ // We mean it. // +#include <QtCore/QHash> #include <QtCore/QMap> #include <QtCore/QStringList> #include <QtCore/QObject> @@ -88,6 +89,7 @@ public: QMap<QString, QHelpDBReader*> fileNameReaderMap; QMultiMap<QString, QHelpDBReader*> virtualFolderMap; QStringList orderedFileNameList; + QHash<QString, QString> nameSpaceVirtualFolderMap; QHelpCollectionHandler *collectionHandler; QString currentFilter; diff --git a/tools/assistant/lib/qhelpenginecore.cpp b/tools/assistant/lib/qhelpenginecore.cpp index 1f0635e..aa14707 100644 --- a/tools/assistant/lib/qhelpenginecore.cpp +++ b/tools/assistant/lib/qhelpenginecore.cpp @@ -88,6 +88,7 @@ void QHelpEngineCorePrivate::clearMaps() fileNameReaderMap.clear(); virtualFolderMap.clear(); orderedFileNameList.clear(); + nameSpaceVirtualFolderMap.clear(); } bool QHelpEngineCorePrivate::setup() @@ -128,6 +129,7 @@ bool QHelpEngineCorePrivate::setup() fileNameReaderMap.insert(absFileName, reader); virtualFolderMap.insert(info.folderName, reader); orderedFileNameList.append(absFileName); + nameSpaceVirtualFolderMap.insert(info.namespaceName, info.folderName); } q->currentFilter(); emit q->setupFinished(); @@ -365,11 +367,11 @@ QString QHelpEngineCore::documentationFileName(const QString &namespaceName) foreach(const QHelpCollectionHandler::DocInfo &info, docList) { if (info.namespaceName == namespaceName) { if (QDir::isAbsolutePath(info.fileName)) - return QDir::cleanPath(info.fileName); + return info.fileName; QFileInfo fi(d->collectionHandler->collectionFile()); fi.setFile(fi.absolutePath() + QDir::separator() + info.fileName); - return QDir::cleanPath(fi.absoluteFilePath()); + return fi.absoluteFilePath(); } } } @@ -553,7 +555,7 @@ QUrl QHelpEngineCore::findFile(const QUrl &url) const return res; QString ns = url.authority(); - QString filePath = QDir::cleanPath(url.path()); + QString filePath = url.path(); if (filePath.startsWith(QLatin1Char('/'))) filePath = filePath.mid(1); QString virtualFolder = filePath.mid(0, filePath.indexOf(QLatin1Char('/'), 1)); @@ -603,7 +605,7 @@ QByteArray QHelpEngineCore::fileData(const QUrl &url) const return QByteArray(); QString ns = url.authority(); - QString filePath = QDir::cleanPath(url.path()); + QString filePath = url.path(); if (filePath.startsWith(QLatin1Char('/'))) filePath = filePath.mid(1); QString virtualFolder = filePath.mid(0, filePath.indexOf(QLatin1Char('/'), 1)); diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp index b44a2ac..7865435 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.cpp +++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp @@ -42,6 +42,7 @@ #include "helpenginewrapper.h" #include "../shared/collectionconfiguration.h" +#include "../../lib/qhelpengine_p.h" #include <QtCore/QDateTime> #include <QtCore/QFileInfo> @@ -329,6 +330,12 @@ QString HelpEngineWrapper::error() const return d->m_helpEngine->error(); } +QString HelpEngineWrapper::virtualFolderForNameSpace(const QString &nameSpace) const +{ + TRACE_OBJ + return d->m_helpEngine->d->nameSpaceVirtualFolderMap.value(nameSpace, QString()); +} + const QStringList HelpEngineWrapper::qtDocInfo(const QString &component) const { TRACE_OBJ diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h index 5ee5e10..3951d5e 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.h +++ b/tools/assistant/tools/assistant/helpenginewrapper.h @@ -99,7 +99,8 @@ public: QMap<QString, QUrl> linksForIdentifier(const QString &id) const; const QStringList filterAttributes() const; const QStringList filterAttributes(const QString &filterName) const; - QString error() const; + QString error() const; + QString virtualFolderForNameSpace(const QString &nameSpace) const; /* * To be called after assistant has finished looking for new documentation. diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index 87ba49e..f739726 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -58,8 +58,6 @@ QT_BEGIN_NAMESPACE -const QString HelpViewer::DocPath = QLatin1String("qthelp://com.trolltech."); - const QString HelpViewer::AboutBlank = QCoreApplication::translate("HelpViewer", "<title>about:blank</title>"); @@ -68,7 +66,7 @@ const QString HelpViewer::LocalHelpFile = QLatin1String("qthelp://" const QString HelpViewer::PageNotFoundMessage = QCoreApplication::translate("HelpViewer", "<title>Error 404...</title><div " - "align=\"center\"><br><br><h1>The page could not be found</h1><br><h3>'%1'" + "align=\"center\"><br><br><h1>The page could not be found.</h1><br><h3>'%1'" "</h3></div>"); struct ExtensionMap { @@ -179,6 +177,31 @@ bool HelpViewer::launchWithExternalApp(const QUrl &url) return false; } +QString HelpViewer::fixupVirtualFolderForUrl(const HelpEngineWrapper *engine, const QUrl &url, bool *fixed) +{ + TRACE_OBJ + Q_ASSERT(engine); + + QString ret = url.toString(); + const QString virtualFolder = engine->virtualFolderForNameSpace(url.host()); + QString effectiveVirtualFolder = virtualFolder; + const QStringList tokens = url.path().split('/'); + Q_FOREACH (const QString& token, tokens) { + if (!token.isEmpty()) { + effectiveVirtualFolder = token; + break; + } + } + + if (QString::localeAwareCompare(effectiveVirtualFolder, virtualFolder)) { + ret = url.scheme() + QLatin1String("://") + url.host() + QLatin1Char('/') + + virtualFolder + QLatin1String("/..") + url.path(); + } + if (fixed && engine->findFile(ret).isValid()) + *fixed = true; + return ret; +} + // -- public slots void HelpViewer::home() diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h index 33adf80..ab608fc 100644 --- a/tools/assistant/tools/assistant/helpviewer.h +++ b/tools/assistant/tools/assistant/helpviewer.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE +class HelpEngineWrapper; + #if !defined(QT_NO_WEBKIT) class HelpViewer : public QWebView #else @@ -100,7 +102,6 @@ public: bool findText(const QString &text, FindFlags flags, bool incremental, bool fromSearch); - static const QString DocPath; static const QString AboutBlank; static const QString LocalHelpFile; static const QString PageNotFoundMessage; @@ -109,6 +110,7 @@ public: static bool canOpenPage(const QString &url); static QString mimeFromUrl(const QUrl &url); static bool launchWithExternalApp(const QUrl &url); + static QString fixupVirtualFolderForUrl(const HelpEngineWrapper *engine, const QUrl &url, bool *fixed = 0); public slots: void copy(); diff --git a/tools/assistant/tools/assistant/helpviewer_qtb.cpp b/tools/assistant/tools/assistant/helpviewer_qtb.cpp index 734674b..875692a 100644 --- a/tools/assistant/tools/assistant/helpviewer_qtb.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qtb.cpp @@ -163,10 +163,14 @@ void HelpViewer::setSource(const QUrl &url) emit loadStarted(); QString string = url.toString(); const HelpEngineWrapper &engine = HelpEngineWrapper::instance(); - const QUrl &resolvedUrl = (string == QLatin1String("help") ? LocalHelpFile : + QUrl resolvedUrl = (string == QLatin1String("help") ? LocalHelpFile : engine.findFile(string)); + bool fileFound = resolvedUrl.isValid(); + if (!fileFound && isLocalUrl(url)) + resolvedUrl = fixupVirtualFolderForUrl(&engine, url, &fileFound); + QTextBrowser::setSource(resolvedUrl); - if (!url.isValid()) { + if (!fileFound) { setHtml(string == QLatin1String("about:blank") ? AboutBlank : PageNotFoundMessage.arg(url.toString())); } @@ -370,8 +374,9 @@ QVariant HelpViewer::loadResource(int type, const QUrl &name) TRACE_OBJ QByteArray ba; if (type < 4) { - ba = HelpEngineWrapper::instance().fileData(name); - if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) { + QUrl url = fixupVirtualFolderForUrl(&HelpEngineWrapper::instance(), name); + ba = HelpEngineWrapper::instance().fileData(url); + if (url.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) { QImage image; image.loadFromData(ba, "svg"); if (!image.isNull()) diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp index 9862266..e37335a 100644 --- a/tools/assistant/tools/assistant/helpviewer_qwv.cpp +++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp @@ -95,6 +95,7 @@ HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request, setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen)); QTimer::singleShot(0, this, SIGNAL(metaDataChanged())); QTimer::singleShot(0, this, SIGNAL(readyRead())); + QTimer::singleShot(0, this, SIGNAL(finished())); } void HelpNetworkReply::abort() @@ -138,24 +139,15 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, { TRACE_OBJ QString url = request.url().toString(); + const HelpEngineWrapper &engine = HelpEngineWrapper::instance(); - // 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)) { - QUrl newUrl = request.url(); - if (!newUrl.path().startsWith(QLatin1String("/qdoc/"))) { - newUrl.setPath(QLatin1String("qdoc") + newUrl.path()); - url = newUrl.toString(); - } - } - } + + bool fileFound = engine.findFile(url).isValid(); + if (!fileFound && HelpViewer::isLocalUrl(request.url())) + url = HelpViewer::fixupVirtualFolderForUrl(&engine, request.url(), &fileFound); const QString &mimeType = HelpViewer::mimeFromUrl(url); - const QByteArray &data = engine.findFile(url).isValid() ? engine.fileData(url) + const QByteArray &data = fileFound ? engine.fileData(url) : HelpViewer::PageNotFoundMessage.arg(url).toUtf8(); return new HelpNetworkReply(request, data, mimeType.isEmpty() diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index 18df1cb..f0038e2 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -1029,7 +1029,6 @@ QString MainWindow::collectionFileDirectory(bool createDir, const QString &cache else collectionPath = collectionPath + QDir::separator() + cacheDir; } - collectionPath = QDir::cleanPath(collectionPath); if (createDir) { QDir dir; if (!dir.exists(collectionPath)) |