From e75b55aede4f781b4c7536e1c068f0c77008dd79 Mon Sep 17 00:00:00 2001 From: Stephen Brennan Date: Fri, 23 Aug 2024 09:55:51 -0700 Subject: [PATCH] docs: Add custom docset logic This is a bit gross in order to avoid changing the existing code and indentation, so the patch will apply for longer. But essentially, once we've read the network/cached docset list, we then open a custom list, read and parse that, and re-run the logic so that we can add in the custom docsets too. Signed-off-by: Stephen Brennan --- docs/src/plugin.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/src/plugin.cpp b/docs/src/plugin.cpp index 1a03ae31..6e010d15 100644 --- a/docs/src/plugin.cpp +++ b/docs/src/plugin.cpp @@ -163,7 +163,9 @@ void Plugin::updateDocsetList() docsets_.clear(); QJsonParseError parse_error; - const QJsonDocument json_document = QJsonDocument::fromJson(replyData, &parse_error); + bool local = false; + QJsonDocument json_document = QJsonDocument::fromJson(replyData, &parse_error); + again: if (parse_error.error == QJsonParseError::NoError) { for (const QJsonValue &val : json_document.array()) @@ -183,7 +185,19 @@ void Plugin::updateDocsetList() if (dir.exists()) docsets_.back().path = dir.path(); } - debug(tr("Docset list updated.")); + if (local) + debug("Custom docsets have been added."); + else + debug(tr("Docset list updated.")); + + QFile customDocsetListFile(QDir(dataLocation()).filePath("custom_docsets.json")); + if (!local && customDocsetListFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QByteArray customData = customDocsetListFile.readAll(); + customDocsetListFile.close(); + json_document = QJsonDocument::fromJson(customData, &parse_error); + local = true; + goto again; + } if (reply->error() == QNetworkReply::NoError) {