summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-12-22 17:34:38 +0100
committerAleix Pol <[email protected]>2016-12-22 17:34:38 +0100
commit68bfd7227c1593d53f782d5bc5bc87870b2e2542 (patch)
tree810efff60915d67d2c91cf4d20719a46688ea428
parent31ab1bd58267cdbabcc295ce45927ab1127c5206 (diff)
Make sure we don't overlap kns searches
-rw-r--r--libdiscover/backends/KNSBackend/KNSBackend.cpp36
-rw-r--r--libdiscover/backends/KNSBackend/KNSBackend.h5
2 files changed, 30 insertions, 11 deletions
diff --git a/libdiscover/backends/KNSBackend/KNSBackend.cpp b/libdiscover/backends/KNSBackend/KNSBackend.cpp
index c8ceb91..9a2f3e3 100644
--- a/libdiscover/backends/KNSBackend/KNSBackend.cpp
+++ b/libdiscover/backends/KNSBackend/KNSBackend.cpp
@@ -23,6 +23,7 @@
#include <QDir>
#include <QFileInfo>
#include <QStandardPaths>
+#include <QTimer>
#include <QDirIterator>
// Attica includes
@@ -104,6 +105,7 @@ KNSBackend::KNSBackend(QObject* parent, const QString& iconName, const QString &
connect(m_manager, &KNS3::DownloadManager::entryStatusChanged, this, &KNSBackend::statusChanged);
m_page = -1;
m_manager->checkForInstalled();
+ m_responsePending = true;
const QVector<QPair<FilterType, QString>> filters = { {CategoryFilter, fileName } };
const QSet<QString> backendName = { name() };
@@ -152,6 +154,9 @@ bool KNSBackend::isValid() const
void KNSBackend::receivedEntries(const KNS3::Entry::List& entries)
{
+ m_responsePending = false;
+ QTimer::singleShot(0, this, &KNSBackend::availableForQueries);
+
if(entries.isEmpty()) {
Q_EMIT searchFinished();
setFetching(false);
@@ -173,6 +178,7 @@ void KNSBackend::receivedEntries(const KNS3::Entry::List& entries)
if (m_page >= 0) {
++m_page;
m_manager->search(m_page);
+ m_responsePending = true;
}
}
@@ -273,22 +279,32 @@ ResultsStream* KNSBackend::search(const AbstractResourcesBackend::Filters& filte
}
return new ResultsStream(QStringLiteral("KNS-installed"), ret);
} else if (filter.category && filter.category->matchesCategoryName(m_categories.first())) {
- m_manager->setSearchTerm(filter.search);
- return searchStream();
+ return searchStream(filter.search);
} else if (!filter.search.isEmpty()) {
- m_manager->setSearchTerm(filter.search);
- return searchStream();
+ return searchStream(filter.search);
}
return new ResultsStream(QStringLiteral("KNS-void"), {});
}
-ResultsStream * KNSBackend::searchStream()
+ResultsStream * KNSBackend::searchStream(const QString &searchText)
{
- m_manager->search(0);
- m_page = 0;
- auto stream = new ResultsStream(QStringLiteral("KNS-search"));
- connect(this, &KNSBackend::receivedResources, stream, &ResultsStream::resourcesFound);
- connect(this, &KNSBackend::searchFinished, stream, &ResultsStream::deleteLater);
+ Q_EMIT startingSearch();
+
+ auto stream = new ResultsStream(QStringLiteral("KNS-search-")+name());
+ auto start = [this, stream, searchText]() {
+ m_manager->setSearchTerm(searchText);
+ m_manager->search(0);
+ m_responsePending = true;
+ m_page = 0;
+ connect(this, &KNSBackend::receivedResources, stream, &ResultsStream::resourcesFound);
+ connect(this, &KNSBackend::searchFinished, stream, &ResultsStream::deleteLater);
+ connect(this, &KNSBackend::startingSearch, stream, &ResultsStream::deleteLater);
+ };
+ if (m_responsePending) {
+ connect(this, &KNSBackend::availableForQueries, stream, start);
+ } else {
+ start();
+ }
return stream;
}
diff --git a/libdiscover/backends/KNSBackend/KNSBackend.h b/libdiscover/backends/KNSBackend/KNSBackend.h
index 73d83ae..841308a 100644
--- a/libdiscover/backends/KNSBackend/KNSBackend.h
+++ b/libdiscover/backends/KNSBackend/KNSBackend.h
@@ -67,6 +67,8 @@ public:
Q_SIGNALS:
void receivedResources(const QVector<AbstractResource*> &resources);
void searchFinished();
+ void startingSearch();
+ void availableForQueries();
public Q_SLOTS:
void receivedEntries(const KNS3::Entry::List& entries);
@@ -75,8 +77,9 @@ public Q_SLOTS:
private:
void setFetching(bool f);
void markInvalid(const QString &message);
- ResultsStream* searchStream();
+ ResultsStream* searchStream(const QString &searchText);
+ bool m_responsePending = false;
bool m_fetching;
bool m_isValid;
KNS3::DownloadManager* m_manager;