diff --git a/src/libs/registry/docset.cpp b/src/libs/registry/docset.cpp index ff469b4db..bbf9fb7e3 100644 --- a/src/libs/registry/docset.cpp +++ b/src/libs/registry/docset.cpp @@ -194,7 +194,7 @@ Docset::Docset(QString path) m_indexFilePath = QStringLiteral("index.html"); } - // Log if unable to determine the index page. + // Log if unable to determine the index page. Otherwise the path will be set in setBaseUrl(). if (m_indexFilePath.isEmpty()) { qWarning("Cannot determine index file for docset %s", qPrintable(m_name)); m_indexFileUrl.setUrl(NotFoundPageUrl); @@ -567,8 +567,9 @@ QUrl Docset::createPageUrl(const QString &path, const QString &fragment) const realPath.remove(dashEntryRegExp); realFragment.remove(dashEntryRegExp); - // Absolute file path is required here to handle relative path to the docset storage (see #806). - QUrl url = QUrl::fromLocalFile(QDir(documentPath()).absoluteFilePath(realPath)); + QUrl url = m_baseUrl; + url.setPath(m_baseUrl.path() + "/" + realPath, QUrl::TolerantMode); + if (!realFragment.isEmpty()) { if (realFragment.startsWith(QLatin1String("//apple_ref")) || realFragment.startsWith(QLatin1String("//dash_ref"))) { @@ -715,6 +716,20 @@ QString Docset::parseSymbolType(const QString &str) return aliases.value(str, str); } +QUrl Docset::baseUrl() const +{ + return m_baseUrl; +} + +void Docset::setBaseUrl(const QUrl &baseUrl) +{ + m_baseUrl = baseUrl; + + if (!m_indexFilePath.isEmpty()) { + m_indexFileUrl = createPageUrl(m_indexFilePath); + } +} + bool Docset::isFuzzySearchEnabled() const { return m_fuzzySearchEnabled; diff --git a/src/libs/registry/docset.h b/src/libs/registry/docset.h index e87a99e4d..2e672d422 100644 --- a/src/libs/registry/docset.h +++ b/src/libs/registry/docset.h @@ -77,6 +77,9 @@ class Docset final // FIXME: This is an ugly workaround before we have a proper docset sources implementation bool hasUpdate = false; + QUrl baseUrl() const; + void setBaseUrl(const QUrl &baseUrl); + bool isFuzzySearchEnabled() const; void setFuzzySearchEnabled(bool enabled); @@ -118,6 +121,8 @@ class Docset final Util::SQLiteDatabase *m_db = nullptr; bool m_fuzzySearchEnabled = false; bool m_javaScriptEnabled = false; + + QUrl m_baseUrl; }; } // namespace Registry diff --git a/src/libs/registry/docsetregistry.cpp b/src/libs/registry/docsetregistry.cpp index d63feae16..3cc562ed5 100644 --- a/src/libs/registry/docsetregistry.cpp +++ b/src/libs/registry/docsetregistry.cpp @@ -28,6 +28,9 @@ #include "searchquery.h" #include "searchresult.h" +#include +#include + #include #include @@ -139,7 +142,19 @@ void DocsetRegistry::loadDocset(const QString &path) unloadDocset(name); } + // Setup HTTP mount. + QUrl url = Core::Application::instance()->httpServer()->mount(name, docset->documentPath()); + if (url.isEmpty()) { + qWarning("Could not enable docset from '%s'. Reinstall the docset.", + qPrintable(docset->path())); + delete docset; + return; + } + + docset->setBaseUrl(url); + m_docsets[name] = docset; + emit docsetLoaded(name); });