Extract makeResourceUrl lambda into separate static openableUrl method

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2022-12-16 15:28:31 +01:00 committed by Claudio Cambra
parent 37830c4bc4
commit 481298997c
2 changed files with 14 additions and 11 deletions

View file

@ -579,16 +579,6 @@ void UnifiedSearchResultsListModel::parseResultsForProvider(const QJsonObject &d
QVector<UnifiedSearchResult> newEntries; QVector<UnifiedSearchResult> newEntries;
const auto makeResourceUrl = [](const QUrl &resourceUrl, const QUrl &accountUrl) {
if (!resourceUrl.isRelative()) {
return resourceUrl;
}
QUrl finalResourceUrl(accountUrl);
finalResourceUrl.setPath(resourceUrl.toString());
return finalResourceUrl;
};
for (const auto &entry : entries) { for (const auto &entry : entries) {
const auto entryMap = entry.toMap(); const auto entryMap = entry.toMap();
if (entryMap.isEmpty()) { if (entryMap.isEmpty()) {
@ -605,7 +595,7 @@ void UnifiedSearchResultsListModel::parseResultsForProvider(const QJsonObject &d
const auto resourceUrl = entryMap.value(QStringLiteral("resourceUrl")).toUrl(); const auto resourceUrl = entryMap.value(QStringLiteral("resourceUrl")).toUrl();
const auto accountUrl = (_accountState && _accountState->account()) ? _accountState->account()->url() : QUrl(); const auto accountUrl = (_accountState && _accountState->account()) ? _accountState->account()->url() : QUrl();
result._resourceUrl = makeResourceUrl(resourceUrl, accountUrl); result._resourceUrl = openableResourceUrl(resourceUrl, accountUrl);
const auto darkIconsData = iconsFromThumbnailAndFallbackIcon(entryMap.value(QStringLiteral("thumbnailUrl")).toString(), const auto darkIconsData = iconsFromThumbnailAndFallbackIcon(entryMap.value(QStringLiteral("thumbnailUrl")).toString(),
entryMap.value(QStringLiteral("icon")).toString(), accountUrl, true); entryMap.value(QStringLiteral("icon")).toString(), accountUrl, true);
const auto lightIconsData = iconsFromThumbnailAndFallbackIcon(entryMap.value(QStringLiteral("thumbnailUrl")).toString(), const auto lightIconsData = iconsFromThumbnailAndFallbackIcon(entryMap.value(QStringLiteral("thumbnailUrl")).toString(),
@ -625,6 +615,17 @@ void UnifiedSearchResultsListModel::parseResultsForProvider(const QJsonObject &d
} }
} }
QUrl UnifiedSearchResultsListModel::openableResourceUrl(const QUrl &resourceUrl, const QUrl &accountUrl)
{
if (!resourceUrl.isRelative()) {
return resourceUrl;
}
QUrl finalResourceUrl(accountUrl);
finalResourceUrl.setPath(resourceUrl.toString());
return finalResourceUrl;
}
void UnifiedSearchResultsListModel::appendResults(QVector<UnifiedSearchResult> results, const UnifiedSearchProvider &provider) void UnifiedSearchResultsListModel::appendResults(QVector<UnifiedSearchResult> results, const UnifiedSearchProvider &provider)
{ {
if (provider._cursor > 0 && provider._isPaginated) { if (provider._cursor > 0 && provider._isPaginated) {

View file

@ -119,6 +119,8 @@ private slots:
void slotSearchForProviderFinished(const QJsonDocument &json, int statusCode); void slotSearchForProviderFinished(const QJsonDocument &json, int statusCode);
private: private:
static QUrl openableResourceUrl(const QUrl &resourceUrl, const QUrl &accountUrl);
QMap<QString, UnifiedSearchProvider> _providers; QMap<QString, UnifiedSearchProvider> _providers;
QVector<UnifiedSearchResult> _results; QVector<UnifiedSearchResult> _results;