diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index 2bff1236c1a..9c6c73d5378 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -376,6 +376,7 @@ static QUrl constructUrl(const QString &projectName, const QString &subPath, con static constexpr int httpStatusCodeOk = 200; constexpr char s_htmlContentType[] = "text/html"; +constexpr char s_plaintextContentType[] = "text/plain"; constexpr char s_jsonContentType[] = "application/json"; static bool isServerAccessEstablished() @@ -384,15 +385,17 @@ static bool isServerAccessEstablished() || (dd->m_serverAccess == ServerAccess::WithAuthorization && dd->m_apiToken); } -static Group fetchHtmlRecipe(const QUrl &url, const std::function &handler) +static Group fetchSimpleRecipe(const QUrl &url, + const QByteArray &expectedContentType, + const std::function &handler) { // TODO: Refactor so that it's a common code with fetchDataRecipe(). - const auto onQuerySetup = [url](NetworkQuery &query) { + const auto onQuerySetup = [url, expectedContentType](NetworkQuery &query) { if (!isServerAccessEstablished()) return SetupResult::StopWithError; // TODO: start authorizationRecipe()? QNetworkRequest request(url); - request.setRawHeader("Accept", s_htmlContentType); + request.setRawHeader("Accept", expectedContentType); if (dd->m_serverAccess == ServerAccess::WithAuthorization && dd->m_apiToken) request.setRawHeader("Authorization", "AxToken " + *dd->m_apiToken); const QByteArray ua = "Axivion" + QCoreApplication::applicationName().toUtf8() + @@ -402,7 +405,7 @@ static Group fetchHtmlRecipe(const QUrl &url, const std::functionm_networkAccessManager); return SetupResult::Continue; }; - const auto onQueryDone = [url, handler](const NetworkQuery &query, DoneWith doneWith) { + const auto onQueryDone = [url, expectedContentType, handler](const NetworkQuery &query, DoneWith doneWith) { QNetworkReply *reply = query.reply(); const int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader) @@ -412,7 +415,7 @@ static Group fetchHtmlRecipe(const QUrl &url, const std::functionreadAll()); return DoneResult::Success; } @@ -421,6 +424,16 @@ static Group fetchHtmlRecipe(const QUrl &url, const std::function &handler) +{ + return fetchSimpleRecipe(url, s_htmlContentType, handler); +} + +static Group fetchPlainTextRecipe(const QUrl &url, const std::function &handler) +{ + return fetchSimpleRecipe(url, s_plaintextContentType, handler); +} + template typename DtoStorageType> static Group dtoRecipe(const Storage> &dtoStorage) { @@ -801,6 +814,18 @@ Group lineMarkerRecipe(const FilePath &filePath, const LineMarkerHandler &handle return fetchDataRecipe(url, handler); } +Group fileSourceRecipe(const FilePath &filePath, const std::function &handler) +{ + QTC_ASSERT(dd->m_currentProjectInfo, return {}); // TODO: Call handler with unexpected + QTC_ASSERT(!filePath.isEmpty(), return {}); // TODO: Call handler with unexpected + QTC_ASSERT(dd->m_analysisVersion, return {}); // TODO: Call handler with unexpected + + const QString fileName = QString::fromUtf8(QUrl::toPercentEncoding(filePath.path())); + const QUrlQuery query({{"filename", fileName}, {"version", *dd->m_analysisVersion}}); + const QUrl url = constructUrl(dd->m_currentProjectInfo.value().name, "sourcecode", query); + return fetchPlainTextRecipe(url, handler); +} + Group issueHtmlRecipe(const QString &issueId, const HtmlHandler &handler) { QTC_ASSERT(dd->m_currentProjectInfo, return {}); // TODO: Call handler with unexpected?