Commit e6a1cc15 authored by Julius Künzel's avatar Julius Künzel 💬
Browse files

Improve perfocmance of online resource search

- Use less instances of QNetworkAccessManager
- Run parsing of search result in different thread to not block the whole
UI
parent db528d58
......@@ -30,6 +30,8 @@ ProviderModel::ProviderModel(const QString &path)
QFile file(path);
QJsonParseError jsonError;
m_networkManager = new QNetworkAccessManager(this);
if (!file.exists()) {
qCWarning(KDENLIVE_LOG) << "WARNING, can not find provider configuration file at" << path << ".";
m_invalid = true;
......@@ -388,9 +390,6 @@ void ProviderModel::slotStartSearch(const QString &searchText, const int page)
QUrl uri = getSearchUrl(searchText, page);
if (m_search["req"].toObject()["method"].toString() == "GET") {
auto *manager = new QNetworkAccessManager(this);
QNetworkRequest request(uri);
if (m_search["req"].toObject()["header"].isArray()) {
......@@ -399,7 +398,7 @@ void ProviderModel::slotStartSearch(const QString &searchText, const int page)
replacePlaceholders(header.toObject()["value"].toString(), searchText, page).toUtf8());
}
}
QNetworkReply *reply = manager->get(request);
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, &QNetworkReply::finished, this, [=]() {
if (reply->error() == QNetworkReply::NoError) {
......@@ -539,8 +538,6 @@ void ProviderModel::slotFetchFiles(const QString &id)
if (m_download["req"].toObject()["method"].toString() == "GET") {
auto *manager = new QNetworkAccessManager(this);
QNetworkRequest request(uri);
if (m_download["req"].toObject()["header"].isArray()) {
......@@ -548,7 +545,7 @@ void ProviderModel::slotFetchFiles(const QString &id)
request.setRawHeader(header.toObject()["key"].toString().toUtf8(), replacePlaceholders(header.toObject()["value"].toString()).toUtf8());
}
}
QNetworkReply *reply = manager->get(request);
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, &QNetworkReply::finished, this, [=]() {
if (reply->error() == QNetworkReply::NoError) {
......
......@@ -73,6 +73,7 @@ protected:
QString m_apiroot;
QJsonObject m_search;
QJsonObject m_download;
QNetworkAccessManager *m_networkManager;
private:
void validate();
......
......@@ -24,6 +24,7 @@
#include <QMenu>
#include <QProgressDialog>
#include <QToolBar>
#include <QtConcurrent>
#include <kcompletion_version.h>
......@@ -184,7 +185,13 @@ void ResourceWidget::slotChangeProvider()
provider_info->setText(i18n("Media provided by %1", m_currentProvider->get()->name()));
provider_info->setUrl(m_currentProvider->get()->homepage());
connect(m_currentProvider->get(), &ProviderModel::searchDone, this, &ResourceWidget::slotSearchFinished);
connect(m_currentProvider->get(), &ProviderModel::searchDone, this, [this](QList<ResourceItemInfo> &list, const int pageCount) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QtConcurrent::run(this, &ResourceWidget::slotSearchFinished, list, pageCount);
#else
QtConcurrent::run(&ResourceWidget::slotSearchFinished, this, list, pageCount);
#endif
});
connect(m_currentProvider->get(), &ProviderModel::searchError, this, [&](const QString &msg) {
message_line->setText(i18n("Search failed! %1", msg));
message_line->setMessageType(KMessageWidget::Error);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment