- 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.
Done-with: Casper van Donderen <casper.vandonderen@nokia.com>
Change-Id: I7309805000f343e2f58c74cd0655a936399fd939
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
#include "helpenginewrapper.h"
#include "../shared/collectionconfiguration.h"
+#include "../help/qhelpengine_p.h"
#include <QtCore/QDateTime>
#include <QtCore/QFileInfo>
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
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.
QT_BEGIN_NAMESPACE
-const QString HelpViewer::DocPath = QLatin1String("qthelp://com.trolltech.");
-
const QString HelpViewer::AboutBlank =
QCoreApplication::translate("HelpViewer", "<title>about:blank</title>");
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 {
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()
QT_BEGIN_NAMESPACE
+class HelpEngineWrapper;
+
#if !defined(QT_NO_WEBKIT)
class HelpViewer : public QWebView
#else
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;
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:
#ifndef QT_NO_CLIPBOARD
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()));
}
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())
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()
{
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()
else
collectionPath = collectionPath + QDir::separator() + cacheDir;
}
- collectionPath = QDir::cleanPath(collectionPath);
if (createDir) {
QDir dir;
if (!dir.exists(collectionPath))
#include "qhelpengine_p.h"
#include "qhelpdbreader_p.h"
-#include <QtCore/QDir>
#include <QtCore/QStack>
#include <QtCore/QThread>
#include <QtCore/QMutex>
if (!parentItem)
return false;
- if (QDir::cleanPath(parentItem->url().path()) == path) {
+ if (parentItem->url().path() == path) {
m_syncIndex = parent;
return true;
}
private:
QHelpEnginePrivate *d;
+
+ friend class HelpEngineWrapper;
};
QT_END_NAMESPACE
// We mean it.
//
+#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QStringList>
#include <QtCore/QObject>
QMap<QString, QHelpDBReader*> fileNameReaderMap;
QMultiMap<QString, QHelpDBReader*> virtualFolderMap;
QStringList orderedFileNameList;
+ QHash<QString, QString> nameSpaceVirtualFolderMap;
QHelpCollectionHandler *collectionHandler;
QString currentFilter;
fileNameReaderMap.clear();
virtualFolderMap.clear();
orderedFileNameList.clear();
+ nameSpaceVirtualFolderMap.clear();
}
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();
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();
}
}
}
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));
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));